mirror of
https://git.datalinker.icu/kijai/ComfyUI-KJNodes.git
synced 2025-12-09 21:04:41 +08:00
Some js optimization
This commit is contained in:
parent
8c5d9ae4ad
commit
0298e965d2
@ -45,6 +45,7 @@ loadScript('/kjweb_async/purify.min.js').catch((e) => {
|
|||||||
console.log(e)
|
console.log(e)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const categories = ["KJNodes", "SUPIR", "VoiceCraft", "Marigold"];
|
||||||
app.registerExtension({
|
app.registerExtension({
|
||||||
name: "KJNodes.HelpPopup",
|
name: "KJNodes.HelpPopup",
|
||||||
async beforeRegisterNodeDef(nodeType, nodeData) {
|
async beforeRegisterNodeDef(nodeType, nodeData) {
|
||||||
@ -52,13 +53,12 @@ app.registerExtension({
|
|||||||
if (app.ui.settings.getSettingValue("KJNodes.helpPopup") === false) {
|
if (app.ui.settings.getSettingValue("KJNodes.helpPopup") === false) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const categories = ["KJNodes", "SUPIR", "VoiceCraft", "Marigold"];
|
|
||||||
try {
|
try {
|
||||||
categories.forEach(category => {
|
categories.forEach(category => {
|
||||||
if (nodeData?.category?.startsWith(category)) {
|
if (nodeData?.category?.startsWith(category)) {
|
||||||
addDocumentation(nodeData, nodeType);
|
addDocumentation(nodeData, nodeType);
|
||||||
}
|
}
|
||||||
|
else return
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error in registering KJNodes.HelpPopup", error);
|
console.error("Error in registering KJNodes.HelpPopup", error);
|
||||||
|
|||||||
@ -3,6 +3,9 @@ import { app } from "../../../scripts/app.js";
|
|||||||
app.registerExtension({
|
app.registerExtension({
|
||||||
name: "KJNodes.jsnodes",
|
name: "KJNodes.jsnodes",
|
||||||
async beforeRegisterNodeDef(nodeType, nodeData, app) {
|
async beforeRegisterNodeDef(nodeType, nodeData, app) {
|
||||||
|
if(!nodeData?.category?.startsWith("KJNodes")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
switch (nodeData.name) {
|
switch (nodeData.name) {
|
||||||
case "ConditioningMultiCombine":
|
case "ConditioningMultiCombine":
|
||||||
nodeType.prototype.onNodeCreated = function () {
|
nodeType.prototype.onNodeCreated = function () {
|
||||||
@ -23,51 +26,51 @@ app.registerExtension({
|
|||||||
for(let i = this.inputs.length+1-this.inputs_offset; i <= target_number_of_inputs; ++i)
|
for(let i = this.inputs.length+1-this.inputs_offset; i <= target_number_of_inputs; ++i)
|
||||||
this.addInput(`conditioning_${i}`, this.cond_type)
|
this.addInput(`conditioning_${i}`, this.cond_type)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "ImageBatchMulti":
|
case "ImageBatchMulti":
|
||||||
nodeType.prototype.onNodeCreated = function () {
|
nodeType.prototype.onNodeCreated = function () {
|
||||||
this._type = "IMAGE"
|
this._type = "IMAGE"
|
||||||
this.inputs_offset = nodeData.name.includes("selective")?1:0
|
this.inputs_offset = nodeData.name.includes("selective")?1:0
|
||||||
this.addWidget("button", "Update inputs", null, () => {
|
this.addWidget("button", "Update inputs", null, () => {
|
||||||
if (!this.inputs) {
|
if (!this.inputs) {
|
||||||
this.inputs = [];
|
this.inputs = [];
|
||||||
}
|
|
||||||
const target_number_of_inputs = this.widgets.find(w => w.name === "inputcount")["value"];
|
|
||||||
if(target_number_of_inputs===this.inputs.length)return; // already set, do nothing
|
|
||||||
|
|
||||||
if(target_number_of_inputs < this.inputs.length){
|
|
||||||
for(let i = this.inputs.length; i>=this.inputs_offset+target_number_of_inputs; i--)
|
|
||||||
this.removeInput(i)
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
for(let i = this.inputs.length+1-this.inputs_offset; i <= target_number_of_inputs; ++i)
|
|
||||||
this.addInput(`image_${i}`, this._type)
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
break;
|
const target_number_of_inputs = this.widgets.find(w => w.name === "inputcount")["value"];
|
||||||
case "MaskBatchMulti":
|
if(target_number_of_inputs===this.inputs.length)return; // already set, do nothing
|
||||||
nodeType.prototype.onNodeCreated = function () {
|
|
||||||
this._type = "MASK"
|
if(target_number_of_inputs < this.inputs.length){
|
||||||
this.inputs_offset = nodeData.name.includes("selective")?1:0
|
for(let i = this.inputs.length; i>=this.inputs_offset+target_number_of_inputs; i--)
|
||||||
this.addWidget("button", "Update inputs", null, () => {
|
this.removeInput(i)
|
||||||
if (!this.inputs) {
|
}
|
||||||
this.inputs = [];
|
else{
|
||||||
|
for(let i = this.inputs.length+1-this.inputs_offset; i <= target_number_of_inputs; ++i)
|
||||||
|
this.addInput(`image_${i}`, this._type)
|
||||||
}
|
}
|
||||||
const target_number_of_inputs = this.widgets.find(w => w.name === "inputcount")["value"];
|
|
||||||
if(target_number_of_inputs===this.inputs.length)return; // already set, do nothing
|
|
||||||
|
|
||||||
if(target_number_of_inputs < this.inputs.length){
|
|
||||||
for(let i = this.inputs.length; i>=this.inputs_offset+target_number_of_inputs; i--)
|
|
||||||
this.removeInput(i)
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
for(let i = this.inputs.length+1-this.inputs_offset; i <= target_number_of_inputs; ++i)
|
|
||||||
this.addInput(`mask_${i}`, this._type)
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "MaskBatchMulti":
|
||||||
|
nodeType.prototype.onNodeCreated = function () {
|
||||||
|
this._type = "MASK"
|
||||||
|
this.inputs_offset = nodeData.name.includes("selective")?1:0
|
||||||
|
this.addWidget("button", "Update inputs", null, () => {
|
||||||
|
if (!this.inputs) {
|
||||||
|
this.inputs = [];
|
||||||
|
}
|
||||||
|
const target_number_of_inputs = this.widgets.find(w => w.name === "inputcount")["value"];
|
||||||
|
if(target_number_of_inputs===this.inputs.length)return; // already set, do nothing
|
||||||
|
|
||||||
|
if(target_number_of_inputs < this.inputs.length){
|
||||||
|
for(let i = this.inputs.length; i>=this.inputs_offset+target_number_of_inputs; i--)
|
||||||
|
this.removeInput(i)
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
for(let i = this.inputs.length+1-this.inputs_offset; i <= target_number_of_inputs; ++i)
|
||||||
|
this.addInput(`mask_${i}`, this._type)
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "SoundReactive":
|
case "SoundReactive":
|
||||||
|
|||||||
@ -101,7 +101,7 @@ app.registerExtension({
|
|||||||
name: 'KJNodes.SplineEditor',
|
name: 'KJNodes.SplineEditor',
|
||||||
|
|
||||||
async beforeRegisterNodeDef(nodeType, nodeData) {
|
async beforeRegisterNodeDef(nodeType, nodeData) {
|
||||||
if (nodeData?.name == 'SplineEditor') {
|
if (nodeData?.name === 'SplineEditor') {
|
||||||
chainCallback(nodeType.prototype, "onNodeCreated", function () {
|
chainCallback(nodeType.prototype, "onNodeCreated", function () {
|
||||||
hideWidgetForGood(this, this.widgets.find(w => w.name === "coordinates"))
|
hideWidgetForGood(this, this.widgets.find(w => w.name === "coordinates"))
|
||||||
|
|
||||||
@ -123,7 +123,7 @@ app.registerExtension({
|
|||||||
createSplineEditor(this, true)
|
createSplineEditor(this, true)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.setSize([550, 850])
|
this.setSize([550, 840])
|
||||||
this.splineEditor.parentEl = document.createElement("div");
|
this.splineEditor.parentEl = document.createElement("div");
|
||||||
this.splineEditor.parentEl.className = "spline-editor";
|
this.splineEditor.parentEl.className = "spline-editor";
|
||||||
this.splineEditor.parentEl.id = `spline-editor-${this.uuid}`
|
this.splineEditor.parentEl.id = `spline-editor-${this.uuid}`
|
||||||
@ -138,12 +138,11 @@ app.registerExtension({
|
|||||||
})
|
})
|
||||||
chainCallback(this, "onGraphConfigured", function() {
|
chainCallback(this, "onGraphConfigured", function() {
|
||||||
createSplineEditor(this)
|
createSplineEditor(this)
|
||||||
this.setSize([550, 800])
|
this.setSize([550, 840])
|
||||||
});
|
});
|
||||||
|
|
||||||
}); // onAfterGraphConfigured
|
}); // onAfterGraphConfigured
|
||||||
}//node created
|
}//node created
|
||||||
|
|
||||||
} //before register
|
} //before register
|
||||||
})//register
|
})//register
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user