mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-03-04 12:40:00 +00:00
chore: format codes
This commit is contained in:
@@ -12,12 +12,16 @@
|
||||
|
||||
Converter.prototype.onExecute = function() {
|
||||
var v = this.getInputData(0);
|
||||
if (v == null) return;
|
||||
if (v == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.outputs)
|
||||
if (this.outputs) {
|
||||
for (var i = 0; i < this.outputs.length; i++) {
|
||||
var output = this.outputs[i];
|
||||
if (!output.links || !output.links.length) continue;
|
||||
if (!output.links || !output.links.length) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var result = null;
|
||||
switch (output.name) {
|
||||
@@ -47,13 +51,17 @@
|
||||
var j = 0;
|
||||
j < v.length && j < result.length;
|
||||
j++
|
||||
)
|
||||
) {
|
||||
result[j] = v[j];
|
||||
} else result[0] = parseFloat(v);
|
||||
}
|
||||
} else {
|
||||
result[0] = parseFloat(v);
|
||||
}
|
||||
break;
|
||||
}
|
||||
this.setOutputData(i, result);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Converter.prototype.onGetOutputs = function() {
|
||||
@@ -116,21 +124,28 @@
|
||||
MathRange.desc = "Convert a number from one range to another";
|
||||
|
||||
MathRange.prototype.getTitle = function() {
|
||||
if (this.flags.collapsed) return (this._last_v || 0).toFixed(2);
|
||||
if (this.flags.collapsed) {
|
||||
return (this._last_v || 0).toFixed(2);
|
||||
}
|
||||
return this.title;
|
||||
};
|
||||
|
||||
MathRange.prototype.onExecute = function() {
|
||||
if (this.inputs)
|
||||
if (this.inputs) {
|
||||
for (var i = 0; i < this.inputs.length; i++) {
|
||||
var input = this.inputs[i];
|
||||
var v = this.getInputData(i);
|
||||
if (v === undefined) continue;
|
||||
if (v === undefined) {
|
||||
continue;
|
||||
}
|
||||
this.properties[input.name] = v;
|
||||
}
|
||||
}
|
||||
|
||||
var v = this.properties["in"];
|
||||
if (v === undefined || v === null || v.constructor !== Number) v = 0;
|
||||
if (v === undefined || v === null || v.constructor !== Number) {
|
||||
v = 0;
|
||||
}
|
||||
|
||||
var in_min = this.properties.in_min;
|
||||
var in_max = this.properties.in_max;
|
||||
@@ -144,8 +159,11 @@
|
||||
|
||||
MathRange.prototype.onDrawBackground = function(ctx) {
|
||||
//show the current value
|
||||
if (this._last_v) this.outputs[0].label = this._last_v.toFixed(3);
|
||||
else this.outputs[0].label = "?";
|
||||
if (this._last_v) {
|
||||
this.outputs[0].label = this._last_v.toFixed(3);
|
||||
} else {
|
||||
this.outputs[0].label = "?";
|
||||
}
|
||||
};
|
||||
|
||||
MathRange.prototype.onGetInputs = function() {
|
||||
@@ -170,13 +188,16 @@
|
||||
MathRand.desc = "Random number";
|
||||
|
||||
MathRand.prototype.onExecute = function() {
|
||||
if (this.inputs)
|
||||
if (this.inputs) {
|
||||
for (var i = 0; i < this.inputs.length; i++) {
|
||||
var input = this.inputs[i];
|
||||
var v = this.getInputData(i);
|
||||
if (v === undefined) continue;
|
||||
if (v === undefined) {
|
||||
continue;
|
||||
}
|
||||
this.properties[input.name] = v;
|
||||
}
|
||||
}
|
||||
|
||||
var min = this.properties.min;
|
||||
var max = this.properties.max;
|
||||
@@ -212,16 +233,21 @@
|
||||
MathNoise.getValue = function(f, smooth) {
|
||||
if (!MathNoise.data) {
|
||||
MathNoise.data = new Float32Array(1024);
|
||||
for (var i = 0; i < MathNoise.data.length; ++i)
|
||||
for (var i = 0; i < MathNoise.data.length; ++i) {
|
||||
MathNoise.data[i] = Math.random();
|
||||
}
|
||||
}
|
||||
f = f % 1024;
|
||||
if (f < 0) f += 1024;
|
||||
if (f < 0) {
|
||||
f += 1024;
|
||||
}
|
||||
var f_min = Math.floor(f);
|
||||
var f = f - f_min;
|
||||
var r1 = MathNoise.data[f_min];
|
||||
var r2 = MathNoise.data[f_min == 1023 ? 0 : f_min + 1];
|
||||
if (smooth) f = f * f * f * (f * (f * 6.0 - 15.0) + 10.0);
|
||||
if (smooth) {
|
||||
f = f * f * f * (f * (f * 6.0 - 15.0) + 10.0);
|
||||
}
|
||||
return r1 * (1 - f) + r2 * f;
|
||||
};
|
||||
|
||||
@@ -274,7 +300,9 @@
|
||||
this.properties.min_time;
|
||||
this._blink_time = this.properties.duration;
|
||||
this.boxcolor = "#FFF";
|
||||
} else this.boxcolor = "#000";
|
||||
} else {
|
||||
this.boxcolor = "#000";
|
||||
}
|
||||
this.setOutputData(0, v);
|
||||
};
|
||||
|
||||
@@ -295,7 +323,9 @@
|
||||
|
||||
MathClamp.prototype.onExecute = function() {
|
||||
var v = this.getInputData(0);
|
||||
if (v == null) return;
|
||||
if (v == null) {
|
||||
return;
|
||||
}
|
||||
v = Math.max(this.properties.min, v);
|
||||
v = Math.min(this.properties.max, v);
|
||||
this.setOutputData(0, v);
|
||||
@@ -303,13 +333,14 @@
|
||||
|
||||
MathClamp.prototype.getCode = function(lang) {
|
||||
var code = "";
|
||||
if (this.isInputConnected(0))
|
||||
if (this.isInputConnected(0)) {
|
||||
code +=
|
||||
"clamp({{0}}," +
|
||||
this.properties.min +
|
||||
"," +
|
||||
this.properties.max +
|
||||
")";
|
||||
}
|
||||
return code;
|
||||
};
|
||||
|
||||
@@ -329,14 +360,20 @@
|
||||
|
||||
MathLerp.prototype.onExecute = function() {
|
||||
var v1 = this.getInputData(0);
|
||||
if (v1 == null) v1 = 0;
|
||||
if (v1 == null) {
|
||||
v1 = 0;
|
||||
}
|
||||
var v2 = this.getInputData(1);
|
||||
if (v2 == null) v2 = 0;
|
||||
if (v2 == null) {
|
||||
v2 = 0;
|
||||
}
|
||||
|
||||
var f = this.properties.f;
|
||||
|
||||
var _f = this.getInputData(2);
|
||||
if (_f !== undefined) f = _f;
|
||||
if (_f !== undefined) {
|
||||
f = _f;
|
||||
}
|
||||
|
||||
this.setOutputData(0, v1 * (1 - f) + v2 * f);
|
||||
};
|
||||
@@ -359,7 +396,9 @@
|
||||
|
||||
MathAbs.prototype.onExecute = function() {
|
||||
var v = this.getInputData(0);
|
||||
if (v == null) return;
|
||||
if (v == null) {
|
||||
return;
|
||||
}
|
||||
this.setOutputData(0, Math.abs(v));
|
||||
};
|
||||
|
||||
@@ -377,7 +416,9 @@
|
||||
|
||||
MathFloor.prototype.onExecute = function() {
|
||||
var v = this.getInputData(0);
|
||||
if (v == null) return;
|
||||
if (v == null) {
|
||||
return;
|
||||
}
|
||||
this.setOutputData(0, Math.floor(v));
|
||||
};
|
||||
|
||||
@@ -395,7 +436,9 @@
|
||||
|
||||
MathFrac.prototype.onExecute = function() {
|
||||
var v = this.getInputData(0);
|
||||
if (v == null) return;
|
||||
if (v == null) {
|
||||
return;
|
||||
}
|
||||
this.setOutputData(0, v % 1);
|
||||
};
|
||||
|
||||
@@ -414,7 +457,9 @@
|
||||
|
||||
MathSmoothStep.prototype.onExecute = function() {
|
||||
var v = this.getInputData(0);
|
||||
if (v === undefined) return;
|
||||
if (v === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
var edge0 = this.properties.A;
|
||||
var edge1 = this.properties.B;
|
||||
@@ -442,8 +487,9 @@
|
||||
|
||||
MathScale.prototype.onExecute = function() {
|
||||
var value = this.getInputData(0);
|
||||
if (value != null)
|
||||
if (value != null) {
|
||||
this.setOutputData(0, value * this.properties.factor);
|
||||
}
|
||||
};
|
||||
|
||||
LiteGraph.registerNodeType("math/scale", MathScale);
|
||||
@@ -463,28 +509,39 @@
|
||||
|
||||
MathAverageFilter.prototype.onExecute = function() {
|
||||
var v = this.getInputData(0);
|
||||
if (v == null) v = 0;
|
||||
if (v == null) {
|
||||
v = 0;
|
||||
}
|
||||
|
||||
var num_samples = this._values.length;
|
||||
|
||||
this._values[this._current % num_samples] = v;
|
||||
this._current += 1;
|
||||
if (this._current > num_samples) this._current = 0;
|
||||
if (this._current > num_samples) {
|
||||
this._current = 0;
|
||||
}
|
||||
|
||||
var avr = 0;
|
||||
for (var i = 0; i < num_samples; ++i) avr += this._values[i];
|
||||
for (var i = 0; i < num_samples; ++i) {
|
||||
avr += this._values[i];
|
||||
}
|
||||
|
||||
this.setOutputData(0, avr / num_samples);
|
||||
};
|
||||
|
||||
MathAverageFilter.prototype.onPropertyChanged = function(name, value) {
|
||||
if (value < 1) value = 1;
|
||||
if (value < 1) {
|
||||
value = 1;
|
||||
}
|
||||
this.properties.samples = Math.round(value);
|
||||
var old = this._values;
|
||||
|
||||
this._values = new Float32Array(this.properties.samples);
|
||||
if (old.length <= this._values.length) this._values.set(old);
|
||||
else this._values.set(old.subarray(0, this._values.length));
|
||||
if (old.length <= this._values.length) {
|
||||
this._values.set(old);
|
||||
} else {
|
||||
this._values.set(old.subarray(0, this._values.length));
|
||||
}
|
||||
};
|
||||
|
||||
LiteGraph.registerNodeType("math/average", MathAverageFilter);
|
||||
@@ -503,10 +560,15 @@
|
||||
|
||||
MathTendTo.prototype.onExecute = function() {
|
||||
var v = this.getInputData(0);
|
||||
if (v == null) v = 0;
|
||||
if (v == null) {
|
||||
v = 0;
|
||||
}
|
||||
var f = this.properties.factor;
|
||||
if (this._value == null) this._value = v;
|
||||
else this._value = this._value * (1 - f) + v * f;
|
||||
if (this._value == null) {
|
||||
this._value = v;
|
||||
} else {
|
||||
this._value = this._value * (1 - f) + v * f;
|
||||
}
|
||||
this.setOutputData(0, this._value);
|
||||
};
|
||||
|
||||
@@ -538,18 +600,26 @@
|
||||
};
|
||||
|
||||
MathOperation.prototype.setValue = function(v) {
|
||||
if (typeof v == "string") v = parseFloat(v);
|
||||
if (typeof v == "string") {
|
||||
v = parseFloat(v);
|
||||
}
|
||||
this.properties["value"] = v;
|
||||
};
|
||||
|
||||
MathOperation.prototype.onExecute = function() {
|
||||
var A = this.getInputData(0);
|
||||
var B = this.getInputData(1);
|
||||
if (A != null) this.properties["A"] = A;
|
||||
else A = this.properties["A"];
|
||||
if (A != null) {
|
||||
this.properties["A"] = A;
|
||||
} else {
|
||||
A = this.properties["A"];
|
||||
}
|
||||
|
||||
if (B != null) this.properties["B"] = B;
|
||||
else B = this.properties["B"];
|
||||
if (B != null) {
|
||||
this.properties["B"] = B;
|
||||
} else {
|
||||
B = this.properties["B"];
|
||||
}
|
||||
|
||||
var result = 0;
|
||||
switch (this.properties.OP) {
|
||||
@@ -580,7 +650,9 @@
|
||||
};
|
||||
|
||||
MathOperation.prototype.onDrawBackground = function(ctx) {
|
||||
if (this.flags.collapsed) return;
|
||||
if (this.flags.collapsed) {
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.font = "40px Arial";
|
||||
ctx.fillStyle = "#666";
|
||||
@@ -611,15 +683,23 @@
|
||||
MathCompare.prototype.onExecute = function() {
|
||||
var A = this.getInputData(0);
|
||||
var B = this.getInputData(1);
|
||||
if (A !== undefined) this.properties["A"] = A;
|
||||
else A = this.properties["A"];
|
||||
if (A !== undefined) {
|
||||
this.properties["A"] = A;
|
||||
} else {
|
||||
A = this.properties["A"];
|
||||
}
|
||||
|
||||
if (B !== undefined) this.properties["B"] = B;
|
||||
else B = this.properties["B"];
|
||||
if (B !== undefined) {
|
||||
this.properties["B"] = B;
|
||||
} else {
|
||||
B = this.properties["B"];
|
||||
}
|
||||
|
||||
for (var i = 0, l = this.outputs.length; i < l; ++i) {
|
||||
var output = this.outputs[i];
|
||||
if (!output.links || !output.links.length) continue;
|
||||
if (!output.links || !output.links.length) {
|
||||
continue;
|
||||
}
|
||||
var value;
|
||||
switch (output.name) {
|
||||
case "A==B":
|
||||
@@ -706,12 +786,18 @@
|
||||
|
||||
MathCondition.prototype.onExecute = function() {
|
||||
var A = this.getInputData(0);
|
||||
if (A === undefined) A = this.properties.A;
|
||||
else this.properties.A = A;
|
||||
if (A === undefined) {
|
||||
A = this.properties.A;
|
||||
} else {
|
||||
this.properties.A = A;
|
||||
}
|
||||
|
||||
var B = this.getInputData(1);
|
||||
if (B === undefined) B = this.properties.B;
|
||||
else this.properties.B = B;
|
||||
if (B === undefined) {
|
||||
B = this.properties.B;
|
||||
} else {
|
||||
this.properties.B = B;
|
||||
}
|
||||
|
||||
var result = true;
|
||||
switch (this.properties.OP) {
|
||||
@@ -751,11 +837,16 @@
|
||||
MathAccumulate.desc = "Increments a value every time";
|
||||
|
||||
MathAccumulate.prototype.onExecute = function() {
|
||||
if (this.properties.value === null) this.properties.value = 0;
|
||||
if (this.properties.value === null) {
|
||||
this.properties.value = 0;
|
||||
}
|
||||
|
||||
var inc = this.getInputData(0);
|
||||
if (inc !== null) this.properties.value += inc;
|
||||
else this.properties.value += this.properties.increment;
|
||||
if (inc !== null) {
|
||||
this.properties.value += inc;
|
||||
} else {
|
||||
this.properties.value += this.properties.increment;
|
||||
}
|
||||
this.setOutputData(0, this.properties.value);
|
||||
};
|
||||
|
||||
@@ -777,13 +868,19 @@
|
||||
|
||||
MathTrigonometry.prototype.onExecute = function() {
|
||||
var v = this.getInputData(0);
|
||||
if (v == null) v = 0;
|
||||
if (v == null) {
|
||||
v = 0;
|
||||
}
|
||||
var amplitude = this.properties["amplitude"];
|
||||
var slot = this.findInputSlot("amplitude");
|
||||
if (slot != -1) amplitude = this.getInputData(slot);
|
||||
if (slot != -1) {
|
||||
amplitude = this.getInputData(slot);
|
||||
}
|
||||
var offset = this.properties["offset"];
|
||||
slot = this.findInputSlot("offset");
|
||||
if (slot != -1) offset = this.getInputData(slot);
|
||||
if (slot != -1) {
|
||||
offset = this.getInputData(slot);
|
||||
}
|
||||
|
||||
for (var i = 0, l = this.outputs.length; i < l; ++i) {
|
||||
var output = this.outputs[i];
|
||||
@@ -867,19 +964,29 @@
|
||||
MathFormula.size = [160, 100];
|
||||
|
||||
MathAverageFilter.prototype.onPropertyChanged = function(name, value) {
|
||||
if (name == "formula") this.code_widget.value = value;
|
||||
if (name == "formula") {
|
||||
this.code_widget.value = value;
|
||||
}
|
||||
};
|
||||
|
||||
MathFormula.prototype.onExecute = function() {
|
||||
if (!LiteGraph.allow_scripts) return;
|
||||
if (!LiteGraph.allow_scripts) {
|
||||
return;
|
||||
}
|
||||
|
||||
var x = this.getInputData(0);
|
||||
var y = this.getInputData(1);
|
||||
if (x != null) this.properties["x"] = x;
|
||||
else x = this.properties["x"];
|
||||
if (x != null) {
|
||||
this.properties["x"] = x;
|
||||
} else {
|
||||
x = this.properties["x"];
|
||||
}
|
||||
|
||||
if (y != null) this.properties["y"] = y;
|
||||
else y = this.properties["y"];
|
||||
if (y != null) {
|
||||
this.properties["y"] = y;
|
||||
} else {
|
||||
y = this.properties["y"];
|
||||
}
|
||||
|
||||
var f = this.properties["formula"];
|
||||
|
||||
@@ -908,7 +1015,9 @@
|
||||
|
||||
MathFormula.prototype.onDrawBackground = function() {
|
||||
var f = this.properties["formula"];
|
||||
if (this.outputs && this.outputs.length) this.outputs[0].label = f;
|
||||
if (this.outputs && this.outputs.length) {
|
||||
this.outputs[0].label = f;
|
||||
}
|
||||
};
|
||||
|
||||
LiteGraph.registerNodeType("math/formula", MathFormula);
|
||||
@@ -924,7 +1033,9 @@
|
||||
|
||||
Math3DVec2ToXYZ.prototype.onExecute = function() {
|
||||
var v = this.getInputData(0);
|
||||
if (v == null) return;
|
||||
if (v == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.setOutputData(0, v[0]);
|
||||
this.setOutputData(1, v[1]);
|
||||
@@ -944,9 +1055,13 @@
|
||||
|
||||
Math3DXYToVec2.prototype.onExecute = function() {
|
||||
var x = this.getInputData(0);
|
||||
if (x == null) x = this.properties.x;
|
||||
if (x == null) {
|
||||
x = this.properties.x;
|
||||
}
|
||||
var y = this.getInputData(1);
|
||||
if (y == null) y = this.properties.y;
|
||||
if (y == null) {
|
||||
y = this.properties.y;
|
||||
}
|
||||
|
||||
var data = this._data;
|
||||
data[0] = x;
|
||||
@@ -969,7 +1084,9 @@
|
||||
|
||||
Math3DVec3ToXYZ.prototype.onExecute = function() {
|
||||
var v = this.getInputData(0);
|
||||
if (v == null) return;
|
||||
if (v == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.setOutputData(0, v[0]);
|
||||
this.setOutputData(1, v[1]);
|
||||
@@ -990,11 +1107,17 @@
|
||||
|
||||
Math3DXYZToVec3.prototype.onExecute = function() {
|
||||
var x = this.getInputData(0);
|
||||
if (x == null) x = this.properties.x;
|
||||
if (x == null) {
|
||||
x = this.properties.x;
|
||||
}
|
||||
var y = this.getInputData(1);
|
||||
if (y == null) y = this.properties.y;
|
||||
if (y == null) {
|
||||
y = this.properties.y;
|
||||
}
|
||||
var z = this.getInputData(2);
|
||||
if (z == null) z = this.properties.z;
|
||||
if (z == null) {
|
||||
z = this.properties.z;
|
||||
}
|
||||
|
||||
var data = this._data;
|
||||
data[0] = x;
|
||||
@@ -1019,7 +1142,9 @@
|
||||
|
||||
Math3DVec4ToXYZW.prototype.onExecute = function() {
|
||||
var v = this.getInputData(0);
|
||||
if (v == null) return;
|
||||
if (v == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.setOutputData(0, v[0]);
|
||||
this.setOutputData(1, v[1]);
|
||||
@@ -1046,13 +1171,21 @@
|
||||
|
||||
Math3DXYZWToVec4.prototype.onExecute = function() {
|
||||
var x = this.getInputData(0);
|
||||
if (x == null) x = this.properties.x;
|
||||
if (x == null) {
|
||||
x = this.properties.x;
|
||||
}
|
||||
var y = this.getInputData(1);
|
||||
if (y == null) y = this.properties.y;
|
||||
if (y == null) {
|
||||
y = this.properties.y;
|
||||
}
|
||||
var z = this.getInputData(2);
|
||||
if (z == null) z = this.properties.z;
|
||||
if (z == null) {
|
||||
z = this.properties.z;
|
||||
}
|
||||
var w = this.getInputData(3);
|
||||
if (w == null) w = this.properties.w;
|
||||
if (w == null) {
|
||||
w = this.properties.w;
|
||||
}
|
||||
|
||||
var data = this._data;
|
||||
data[0] = x;
|
||||
@@ -1099,9 +1232,13 @@
|
||||
|
||||
Math3DRotation.prototype.onExecute = function() {
|
||||
var angle = this.getInputData(0);
|
||||
if (angle == null) angle = this.properties.angle;
|
||||
if (angle == null) {
|
||||
angle = this.properties.angle;
|
||||
}
|
||||
var axis = this.getInputData(1);
|
||||
if (axis == null) axis = this.properties.axis;
|
||||
if (axis == null) {
|
||||
axis = this.properties.axis;
|
||||
}
|
||||
|
||||
var R = quat.setAxisAngle(this._value, axis, angle * 0.0174532925);
|
||||
this.setOutputData(0, R);
|
||||
@@ -1121,14 +1258,18 @@
|
||||
|
||||
Math3DRotateVec3.prototype.onExecute = function() {
|
||||
var vec = this.getInputData(0);
|
||||
if (vec == null) vec = this.properties.vec;
|
||||
if (vec == null) {
|
||||
vec = this.properties.vec;
|
||||
}
|
||||
var quat = this.getInputData(1);
|
||||
if (quat == null) this.setOutputData(vec);
|
||||
else
|
||||
if (quat == null) {
|
||||
this.setOutputData(vec);
|
||||
} else {
|
||||
this.setOutputData(
|
||||
0,
|
||||
vec3.transformQuat(vec3.create(), vec, quat)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
LiteGraph.registerNodeType("math3d/rotate_vec3", Math3DRotateVec3);
|
||||
@@ -1145,9 +1286,13 @@
|
||||
|
||||
Math3DMultQuat.prototype.onExecute = function() {
|
||||
var A = this.getInputData(0);
|
||||
if (A == null) return;
|
||||
if (A == null) {
|
||||
return;
|
||||
}
|
||||
var B = this.getInputData(1);
|
||||
if (B == null) return;
|
||||
if (B == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
var R = quat.multiply(this._value, A, B);
|
||||
this.setOutputData(0, R);
|
||||
@@ -1172,11 +1317,17 @@
|
||||
|
||||
Math3DQuatSlerp.prototype.onExecute = function() {
|
||||
var A = this.getInputData(0);
|
||||
if (A == null) return;
|
||||
if (A == null) {
|
||||
return;
|
||||
}
|
||||
var B = this.getInputData(1);
|
||||
if (B == null) return;
|
||||
if (B == null) {
|
||||
return;
|
||||
}
|
||||
var factor = this.properties.factor;
|
||||
if (this.getInputData(2) != null) factor = this.getInputData(2);
|
||||
if (this.getInputData(2) != null) {
|
||||
factor = this.getInputData(2);
|
||||
}
|
||||
|
||||
var R = quat.slerp(this._value, A, B, factor);
|
||||
this.setOutputData(0, R);
|
||||
|
||||
Reference in New Issue
Block a user