From 0298e965d267977993715daa226fd2591d824ed8 Mon Sep 17 00:00:00 2001 From: kijai <40791699+kijai@users.noreply.github.com> Date: Fri, 26 Apr 2024 01:38:40 +0300 Subject: [PATCH] Some js optimization --- web/js/help_popup.js | 4 +- web/js/jsnodes.js | 83 +++++++++++++++++++++-------------------- web/js/spline_editor.js | 7 ++-- 3 files changed, 48 insertions(+), 46 deletions(-) diff --git a/web/js/help_popup.js b/web/js/help_popup.js index 9567222..c4620e5 100644 --- a/web/js/help_popup.js +++ b/web/js/help_popup.js @@ -45,6 +45,7 @@ loadScript('/kjweb_async/purify.min.js').catch((e) => { console.log(e) }) +const categories = ["KJNodes", "SUPIR", "VoiceCraft", "Marigold"]; app.registerExtension({ name: "KJNodes.HelpPopup", async beforeRegisterNodeDef(nodeType, nodeData) { @@ -52,13 +53,12 @@ app.registerExtension({ if (app.ui.settings.getSettingValue("KJNodes.helpPopup") === false) { return; } - - const categories = ["KJNodes", "SUPIR", "VoiceCraft", "Marigold"]; try { categories.forEach(category => { if (nodeData?.category?.startsWith(category)) { addDocumentation(nodeData, nodeType); } + else return }); } catch (error) { console.error("Error in registering KJNodes.HelpPopup", error); diff --git a/web/js/jsnodes.js b/web/js/jsnodes.js index 02fdc43..a20a7a7 100644 --- a/web/js/jsnodes.js +++ b/web/js/jsnodes.js @@ -3,6 +3,9 @@ import { app } from "../../../scripts/app.js"; app.registerExtension({ name: "KJNodes.jsnodes", async beforeRegisterNodeDef(nodeType, nodeData, app) { + if(!nodeData?.category?.startsWith("KJNodes")) { + return; + } switch (nodeData.name) { case "ConditioningMultiCombine": 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) this.addInput(`conditioning_${i}`, this.cond_type) } - }); + }); } break; - case "ImageBatchMulti": - nodeType.prototype.onNodeCreated = function () { - this._type = "IMAGE" - 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(`image_${i}`, this._type) - } - }); + case "ImageBatchMulti": + nodeType.prototype.onNodeCreated = function () { + this._type = "IMAGE" + this.inputs_offset = nodeData.name.includes("selective")?1:0 + this.addWidget("button", "Update inputs", null, () => { + if (!this.inputs) { + this.inputs = []; } - 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(`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; case "SoundReactive": diff --git a/web/js/spline_editor.js b/web/js/spline_editor.js index a1c966d..ad12cad 100644 --- a/web/js/spline_editor.js +++ b/web/js/spline_editor.js @@ -101,7 +101,7 @@ app.registerExtension({ name: 'KJNodes.SplineEditor', async beforeRegisterNodeDef(nodeType, nodeData) { - if (nodeData?.name == 'SplineEditor') { + if (nodeData?.name === 'SplineEditor') { chainCallback(nodeType.prototype, "onNodeCreated", function () { hideWidgetForGood(this, this.widgets.find(w => w.name === "coordinates")) @@ -123,7 +123,7 @@ app.registerExtension({ createSplineEditor(this, true) } }); - this.setSize([550, 850]) + this.setSize([550, 840]) this.splineEditor.parentEl = document.createElement("div"); this.splineEditor.parentEl.className = "spline-editor"; this.splineEditor.parentEl.id = `spline-editor-${this.uuid}` @@ -138,12 +138,11 @@ app.registerExtension({ }) chainCallback(this, "onGraphConfigured", function() { createSplineEditor(this) - this.setSize([550, 800]) + this.setSize([550, 840]) }); }); // onAfterGraphConfigured }//node created - } //before register })//register