mirror of
https://github.com/justUmen/Bjornulf_custom_nodes.git
synced 2026-03-21 20:52:11 -03:00
...
This commit is contained in:
29
web/js/BJORNULF_TYPES.js.txt
Normal file
29
web/js/BJORNULF_TYPES.js.txt
Normal file
@@ -0,0 +1,29 @@
|
||||
import { app } from "../../../scripts/app.js";
|
||||
|
||||
app.registerExtension({
|
||||
name: "Bjornulf.CustomBjornulfType",
|
||||
async beforeRegisterNodeDef(nodeType, nodeData, app) {
|
||||
if (nodeData.name === "Bjornulf_WriteImageCharacters") {
|
||||
const onNodeCreated = nodeType.prototype.onNodeCreated;
|
||||
nodeType.prototype.onNodeCreated = function () {
|
||||
onNodeCreated?.apply(this, arguments);
|
||||
const myInput = this.inputs.find(input => input.name === "BJORNULF_CHARACTER");
|
||||
if (myInput) {
|
||||
myInput.type = "BJORNULF_CHARACTER";
|
||||
}
|
||||
};
|
||||
}
|
||||
else if (nodeData.name === "Bjornulf_WriteImageCharacter") {
|
||||
|
||||
}
|
||||
},
|
||||
async setup(app) {
|
||||
app.registerCustomNodeType("BJORNULF_CHARACTER", (value) => {
|
||||
return {
|
||||
type: "BJORNULF_CHARACTER",
|
||||
data: { value: value || "" },
|
||||
name: "BJORNULF_CHARACTER"
|
||||
};
|
||||
});
|
||||
}
|
||||
});
|
||||
52
web/js/CUSTOM_STRING.js.txt
Normal file
52
web/js/CUSTOM_STRING.js.txt
Normal file
@@ -0,0 +1,52 @@
|
||||
import { app } from "../../../scripts/app.js";
|
||||
|
||||
app.registerExtension({
|
||||
name: "Bjornulf.CustomStringType",
|
||||
async beforeRegisterNodeDef(nodeType, nodeData, app) {
|
||||
if (nodeData.name === "Bjornulf_WriteImageAllInOne") {
|
||||
const onNodeCreated = nodeType.prototype.onNodeCreated;
|
||||
nodeType.prototype.onNodeCreated = function () {
|
||||
onNodeCreated?.apply(this, arguments);
|
||||
const locationInput = this.inputs.find(input => input.name === "location");
|
||||
if (locationInput) {
|
||||
locationInput.type = "CUSTOM_STRING";
|
||||
}
|
||||
};
|
||||
}
|
||||
},
|
||||
async setup(app) {
|
||||
app.registerCustomNodeType("CUSTOM_STRING", (value) => {
|
||||
return {
|
||||
type: "CustomStringType",
|
||||
data: { value: value || "" },
|
||||
name: "CustomStringType"
|
||||
};
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Override the default onConnectionCreated method
|
||||
const originalOnConnectionCreated = LGraphCanvas.prototype.onConnectionCreated;
|
||||
LGraphCanvas.prototype.onConnectionCreated = function(connection, e, node_for_click) {
|
||||
if (node_for_click && node_for_click.type === "WriteImageAllInOne" && connection.targetInput.name === "location") {
|
||||
// Check if the connected node is not already a CustomString
|
||||
if (connection.origin_node.type !== "CustomString") {
|
||||
// Create a new CustomString node
|
||||
const customStringNode = LiteGraph.createNode("CustomString");
|
||||
// Position the new node
|
||||
customStringNode.pos = [connection.origin_node.pos[0] + 200, connection.origin_node.pos[1]];
|
||||
this.graph.add(customStringNode);
|
||||
|
||||
// Connect the new CustomString node
|
||||
connection.origin_node.connect(connection.origin_slot, customStringNode, 0);
|
||||
customStringNode.connect(0, node_for_click, connection.target_slot);
|
||||
|
||||
// Remove the original connection
|
||||
connection.origin_node.disconnectOutput(connection.origin_slot, node_for_click);
|
||||
|
||||
return true; // Prevent the original connection
|
||||
}
|
||||
}
|
||||
return originalOnConnectionCreated.apply(this, arguments);
|
||||
};
|
||||
34
web/js/character_description.js.txt
Normal file
34
web/js/character_description.js.txt
Normal file
@@ -0,0 +1,34 @@
|
||||
import { app } from "../../../scripts/app.js";
|
||||
|
||||
console.log("Bjornulf.CharacterDescriptionGenerator extension loaded");
|
||||
|
||||
app.registerExtension({
|
||||
name: "Bjornulf.CharacterDescriptionGenerator",
|
||||
async nodeCreated(node) {
|
||||
console.log("nodeCreated called for", node.comfyClass);
|
||||
if (node.comfyClass === "Bjornulf_CharacterDescriptionGenerator") {
|
||||
console.log("Creating custom UI for Bjornulf_CharacterDescriptionGenerator");
|
||||
|
||||
// Create a simple text element instead of an image
|
||||
const textElement = document.createElement("div");
|
||||
textElement.textContent = "Custom UI Test";
|
||||
textElement.style.padding = "10px";
|
||||
textElement.style.backgroundColor = "red";
|
||||
textElement.style.color = "white";
|
||||
textElement.style.margin = "10px";
|
||||
|
||||
// Add the text element to the node's DOM
|
||||
node.widgets.push({
|
||||
type: "html",
|
||||
name: "customUI",
|
||||
element: textElement
|
||||
});
|
||||
|
||||
console.log("Custom UI element added");
|
||||
|
||||
// Ensure the node is redrawn to show the new widget
|
||||
node.setSize([node.size[0], node.size[1] + 50]);
|
||||
console.log("Node size adjusted");
|
||||
}
|
||||
}
|
||||
});
|
||||
9
web/js/loop_images_from_folder.js.txt
Normal file
9
web/js/loop_images_from_folder.js.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
// import { app } from "../../../scripts/app.js";
|
||||
|
||||
// app.registerExtension({
|
||||
// name: "Bjornulf.LoadImagesFromSelectedFolder",
|
||||
// async beforeRegisterNodeDef(nodeType, nodeData, app) {
|
||||
// if (nodeData.name === "Bjornulf_LoadImagesFromSelectedFolder") {
|
||||
// }
|
||||
// },
|
||||
// });
|
||||
72
web/js/pass_preview_image.js.txt
Normal file
72
web/js/pass_preview_image.js.txt
Normal file
@@ -0,0 +1,72 @@
|
||||
import { app } from "../../../scripts/app.js";
|
||||
import { api } from "../../../scripts/api.js";
|
||||
|
||||
app.registerExtension({
|
||||
name: "Bjornulf.PassPreviewImage",
|
||||
async nodeCreated(node) {
|
||||
if (node.comfyClass === "Bjornulf_PassPreviewImage") {
|
||||
const showImage = (name) => {
|
||||
console.log("name:" + name);
|
||||
const img = new Image();
|
||||
img.onload = () => {
|
||||
node.imgs = [img];
|
||||
imageWidget.value = img.src;
|
||||
app.graph.setDirtyCanvas(true);
|
||||
};
|
||||
img.src = api.apiURL(`/view?filename=output/tmp_preview.png&type=output&rand=${Math.random()}`);
|
||||
node.setSizeForImage?.();
|
||||
};
|
||||
showImage();
|
||||
|
||||
// Set up a method to update the image
|
||||
node.updatePreviewImage = showImage;
|
||||
|
||||
// Override the onExecuted method to update the image after each execution
|
||||
const originalOnExecuted = node.onExecuted;
|
||||
node.onExecuted = function(message) {
|
||||
if (originalOnExecuted) {
|
||||
originalOnExecuted.call(this, message);
|
||||
}
|
||||
this.updatePreviewImage();
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
// app.registerExtension({
|
||||
// name: "Bjornulf.PassPreviewImage",
|
||||
// async nodeCreated(node) {
|
||||
// if (node.comfyClass === "Bjornulf_PassPreviewImage") {
|
||||
// const showImage = () => {
|
||||
// const img = new Image();
|
||||
// img.onload = () => {
|
||||
// node.imgs = [img];
|
||||
// if (node.widgets) {
|
||||
// const imageWidget = node.widgets.find(w => w.name === "image");
|
||||
// if (imageWidget) {
|
||||
// imageWidget.value = img.src;
|
||||
// }
|
||||
// }
|
||||
// app.graph.setDirtyCanvas(true);
|
||||
// };
|
||||
// // img.src = api.apiURL(`/view?filename=output/tmp_preview.png&rand=${Math.random()}`);
|
||||
// img.src = api.apiURL(`/view?filename=output/tmp_preview.png&type=output&rand=${Math.random()}`);
|
||||
// // node.setSizeForImage?.();
|
||||
// };
|
||||
|
||||
// // Initial image load
|
||||
// showImage();
|
||||
|
||||
// Set up a method to update the image
|
||||
// node.updatePreviewImage = showImage;
|
||||
|
||||
// // Override the onExecuted method to update the image after each execution
|
||||
// const originalOnExecuted = node.onExecuted;
|
||||
// node.onExecuted = function(message) {
|
||||
// if (originalOnExecuted) {
|
||||
// originalOnExecuted.call(this, message);
|
||||
// }
|
||||
// this.updatePreviewImage();
|
||||
// };
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
14
web/js/random_line_from_input.js.txt
Normal file
14
web/js/random_line_from_input.js.txt
Normal file
@@ -0,0 +1,14 @@
|
||||
import { app } from "../../../scripts/app.js";
|
||||
|
||||
app.registerExtension({
|
||||
name: "Bjornulf.RandomLineFromInput",
|
||||
async nodeCreated(node) {
|
||||
if (node.comfyClass === "Bjornulf_RandomLineFromInput") {
|
||||
// Set seed widget to hidden input
|
||||
const seedWidget = node.widgets.find(w => w.name === "seed");
|
||||
if (seedWidget) {
|
||||
seedWidget.type = "HIDDEN";
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
19
web/js/random_seed_with_text.js.txt
Normal file
19
web/js/random_seed_with_text.js.txt
Normal file
@@ -0,0 +1,19 @@
|
||||
import { app } from "../../../scripts/app.js";
|
||||
|
||||
app.registerExtension({
|
||||
name: "Bjornulf.TextToStringAndSeed",
|
||||
async nodeCreated(node) {
|
||||
if (node.comfyClass === "Bjornulf_TextToStringAndSeed") {
|
||||
// Set seed widget to hidden input
|
||||
const seedWidget = node.widgets.find(w => w.name === "seed");
|
||||
if (seedWidget) {
|
||||
seedWidget.type = "HIDDEN";
|
||||
}
|
||||
// Set seed widget to hidden input
|
||||
const controlWidget = node.widgets.find(w => w.name === "control_after_generate");
|
||||
if (controlWidget) {
|
||||
controlWidget.type = "HIDDEN";
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
76
web/js/show_float.js
Normal file
76
web/js/show_float.js
Normal file
@@ -0,0 +1,76 @@
|
||||
import { app } from "../../../scripts/app.js";
|
||||
import { ComfyWidgets } from "../../../scripts/widgets.js";
|
||||
|
||||
// Styles for the text area
|
||||
const textAreaStyles = {
|
||||
readOnly: true,
|
||||
opacity: 1,
|
||||
padding: '10px',
|
||||
border: '1px solid #ccc',
|
||||
borderRadius: '5px',
|
||||
backgroundColor: '#222',
|
||||
color: 'Lime',
|
||||
fontFamily: 'Arial, sans-serif',
|
||||
fontSize: '14px',
|
||||
lineHeight: '1.4',
|
||||
resize: 'vertical',
|
||||
overflowY: 'auto',
|
||||
};
|
||||
|
||||
// Displays input text on a node
|
||||
app.registerExtension({
|
||||
name: "Bjornulf.ShowFloat",
|
||||
async beforeRegisterNodeDef(nodeType, nodeData, app) {
|
||||
if (nodeData.name === "Bjornulf_ShowFloat") {
|
||||
function createStyledTextArea(text) {
|
||||
const widget = ComfyWidgets["STRING"](this, "text", ["STRING", { multiline: true }], app).widget;
|
||||
widget.inputEl.readOnly = true;
|
||||
const textArea = widget.inputEl;
|
||||
|
||||
Object.assign(textArea.style, textAreaStyles);
|
||||
textArea.classList.add('bjornulf-show-text');
|
||||
widget.value = text;
|
||||
return widget;
|
||||
}
|
||||
|
||||
function populate(text) {
|
||||
if (this.widgets) {
|
||||
for (let i = 1; i < this.widgets.length; i++) {
|
||||
this.widgets[i].onRemove?.();
|
||||
}
|
||||
this.widgets.length = 1;
|
||||
}
|
||||
|
||||
const v = Array.isArray(text) ? text : [text];
|
||||
for (const list of v) {
|
||||
if (list) {
|
||||
createStyledTextArea.call(this, list);
|
||||
}
|
||||
}
|
||||
|
||||
requestAnimationFrame(() => {
|
||||
const sz = this.computeSize();
|
||||
if (sz[0] < this.size[0]) sz[0] = this.size[0];
|
||||
if (sz[1] < this.size[1]) sz[1] = this.size[1];
|
||||
this.onResize?.(sz);
|
||||
app.graph.setDirtyCanvas(true, false);
|
||||
});
|
||||
}
|
||||
|
||||
// When the node is executed we will be sent the input text, display this in the widget
|
||||
const onExecuted = nodeType.prototype.onExecuted;
|
||||
nodeType.prototype.onExecuted = function (message) {
|
||||
onExecuted?.apply(this, arguments);
|
||||
populate.call(this, message.text);
|
||||
};
|
||||
|
||||
const onConfigure = nodeType.prototype.onConfigure;
|
||||
nodeType.prototype.onConfigure = function () {
|
||||
onConfigure?.apply(this, arguments);
|
||||
if (this.widgets_values?.length) {
|
||||
populate.call(this, this.widgets_values);
|
||||
}
|
||||
};
|
||||
}
|
||||
},
|
||||
});
|
||||
76
web/js/show_int.js
Normal file
76
web/js/show_int.js
Normal file
@@ -0,0 +1,76 @@
|
||||
import { app } from "../../../scripts/app.js";
|
||||
import { ComfyWidgets } from "../../../scripts/widgets.js";
|
||||
|
||||
// Styles for the text area
|
||||
const textAreaStyles = {
|
||||
readOnly: true,
|
||||
opacity: 1,
|
||||
padding: '10px',
|
||||
border: '1px solid #ccc',
|
||||
borderRadius: '5px',
|
||||
backgroundColor: '#222',
|
||||
color: 'Lime',
|
||||
fontFamily: 'Arial, sans-serif',
|
||||
fontSize: '14px',
|
||||
lineHeight: '1.4',
|
||||
resize: 'vertical',
|
||||
overflowY: 'auto',
|
||||
};
|
||||
|
||||
// Displays input text on a node
|
||||
app.registerExtension({
|
||||
name: "Bjornulf.ShowInt",
|
||||
async beforeRegisterNodeDef(nodeType, nodeData, app) {
|
||||
if (nodeData.name === "Bjornulf_ShowInt") {
|
||||
function createStyledTextArea(text) {
|
||||
const widget = ComfyWidgets["STRING"](this, "text", ["STRING", { multiline: true }], app).widget;
|
||||
widget.inputEl.readOnly = true;
|
||||
const textArea = widget.inputEl;
|
||||
|
||||
Object.assign(textArea.style, textAreaStyles);
|
||||
textArea.classList.add('bjornulf-show-text');
|
||||
widget.value = text;
|
||||
return widget;
|
||||
}
|
||||
|
||||
function populate(text) {
|
||||
if (this.widgets) {
|
||||
for (let i = 1; i < this.widgets.length; i++) {
|
||||
this.widgets[i].onRemove?.();
|
||||
}
|
||||
this.widgets.length = 1;
|
||||
}
|
||||
|
||||
const v = Array.isArray(text) ? text : [text];
|
||||
for (const list of v) {
|
||||
if (list) {
|
||||
createStyledTextArea.call(this, list);
|
||||
}
|
||||
}
|
||||
|
||||
requestAnimationFrame(() => {
|
||||
const sz = this.computeSize();
|
||||
if (sz[0] < this.size[0]) sz[0] = this.size[0];
|
||||
if (sz[1] < this.size[1]) sz[1] = this.size[1];
|
||||
this.onResize?.(sz);
|
||||
app.graph.setDirtyCanvas(true, false);
|
||||
});
|
||||
}
|
||||
|
||||
// When the node is executed we will be sent the input text, display this in the widget
|
||||
const onExecuted = nodeType.prototype.onExecuted;
|
||||
nodeType.prototype.onExecuted = function (message) {
|
||||
onExecuted?.apply(this, arguments);
|
||||
populate.call(this, message.text);
|
||||
};
|
||||
|
||||
const onConfigure = nodeType.prototype.onConfigure;
|
||||
nodeType.prototype.onConfigure = function () {
|
||||
onConfigure?.apply(this, arguments);
|
||||
if (this.widgets_values?.length) {
|
||||
populate.call(this, this.widgets_values);
|
||||
}
|
||||
};
|
||||
}
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user