Skip to content

Commit d46bc11

Browse files
author
tamat
committed
merge and build?
2 parents 0b5b1ad + ec83621 commit d46bc11

6 files changed

Lines changed: 792 additions & 754 deletions

File tree

build/litegraph.js

Lines changed: 63 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,24 @@
199199
if (prev && LiteGraph.onNodeTypeReplaced) {
200200
LiteGraph.onNodeTypeReplaced(type, base_class, prev);
201201
}
202+
203+
//warnings
204+
if (base_class.prototype.onPropertyChange) {
205+
console.warn(
206+
"LiteGraph node class " +
207+
type +
208+
" has onPropertyChange method, it must be called onPropertyChanged with d at the end"
209+
);
210+
}
211+
212+
//used to know which nodes create when dragging files to the canvas
213+
if (base_class.supported_extensions) {
214+
for (var i=0; i < base_class.supported_extensions.length; i++) {
215+
var ext = base_class.supported_extensions[i];
216+
if(ext && ext.constructor === String)
217+
this.node_types_by_file_extension[ ext.toLowerCase() ] = base_class;
218+
}
219+
}
202220
},
203221

204222
/**
@@ -430,14 +448,14 @@
430448
var tmp = document.getElementsByTagName("script");
431449
//weird, this array changes by its own, so we use a copy
432450
var script_files = [];
433-
for (var i in tmp) {
451+
for (var i=0; i < tmp.length; i++) {
434452
script_files.push(tmp[i]);
435453
}
436454

437455
var docHeadObj = document.getElementsByTagName("head")[0];
438456
folder_wildcard = document.location.href + folder_wildcard;
439457

440-
for (var i in script_files) {
458+
for (var i=0; i < script_files.length; i++) {
441459
var src = script_files[i].src;
442460
if (
443461
!src ||
@@ -1969,8 +1987,8 @@
19691987
"weird LLink bug, link info is not a LLink but a regular object"
19701988
);
19711989
var link2 = new LLink();
1972-
for (var i in link) {
1973-
link2[i] = link[i];
1990+
for (var j in link) {
1991+
link2[j] = link[j];
19741992
}
19751993
this.links[i] = link2;
19761994
link = link2;
@@ -8580,6 +8598,7 @@ LGraphNode.prototype.executeAction = function(action)
85808598
ctx.textAlign = "left";
85818599
if(w.disabled)
85828600
ctx.globalAlpha *= 0.5;
8601+
var widget_width = w.width || width;
85838602

85848603
switch (w.type) {
85858604
case "button":
@@ -8588,13 +8607,13 @@ LGraphNode.prototype.executeAction = function(action)
85888607
w.clicked = false;
85898608
this.dirty_canvas = true;
85908609
}
8591-
ctx.fillRect(margin, y, width - margin * 2, H);
8610+
ctx.fillRect(margin, y, widget_width - margin * 2, H);
85928611
if(show_text && !w.disabled)
8593-
ctx.strokeRect( margin, y, width - margin * 2, H );
8612+
ctx.strokeRect( margin, y, widget_width - margin * 2, H );
85948613
if (show_text) {
85958614
ctx.textAlign = "center";
85968615
ctx.fillStyle = text_color;
8597-
ctx.fillText(w.name, width * 0.5, y + H * 0.7);
8616+
ctx.fillText(w.name, widget_width * 0.5, y + H * 0.7);
85988617
}
85998618
break;
86008619
case "toggle":
@@ -8603,15 +8622,15 @@ LGraphNode.prototype.executeAction = function(action)
86038622
ctx.fillStyle = background_color;
86048623
ctx.beginPath();
86058624
if (show_text)
8606-
ctx.roundRect(margin, posY, width - margin * 2, H, H * 0.5);
8625+
ctx.roundRect(margin, posY, widget_width - margin * 2, H, H * 0.5);
86078626
else
8608-
ctx.rect(margin, posY, width - margin * 2, H );
8627+
ctx.rect(margin, posY, widget_width - margin * 2, H );
86098628
ctx.fill();
86108629
if(show_text && !w.disabled)
86118630
ctx.stroke();
86128631
ctx.fillStyle = w.value ? "#89A" : "#333";
86138632
ctx.beginPath();
8614-
ctx.arc( width - margin * 2, y + H * 0.5, H * 0.36, 0, Math.PI * 2 );
8633+
ctx.arc( widget_width - margin * 2, y + H * 0.5, H * 0.36, 0, Math.PI * 2 );
86158634
ctx.fill();
86168635
if (show_text) {
86178636
ctx.fillStyle = secondary_text_color;
@@ -8624,31 +8643,31 @@ LGraphNode.prototype.executeAction = function(action)
86248643
w.value
86258644
? w.options.on || "true"
86268645
: w.options.off || "false",
8627-
width - 40,
8646+
widget_width - 40,
86288647
y + H * 0.7
86298648
);
86308649
}
86318650
break;
86328651
case "slider":
86338652
ctx.fillStyle = background_color;
8634-
ctx.fillRect(margin, y, width - margin * 2, H);
8653+
ctx.fillRect(margin, y, widget_width - margin * 2, H);
86358654
var range = w.options.max - w.options.min;
86368655
var nvalue = (w.value - w.options.min) / range;
86378656
ctx.fillStyle = active_widget == w ? "#89A" : "#678";
8638-
ctx.fillRect(margin, y, nvalue * (width - margin * 2), H);
8657+
ctx.fillRect(margin, y, nvalue * (widget_width - margin * 2), H);
86398658
if(show_text && !w.disabled)
8640-
ctx.strokeRect(margin, y, width - margin * 2, H);
8659+
ctx.strokeRect(margin, y, widget_width - margin * 2, H);
86418660
if (w.marker) {
86428661
var marker_nvalue = (w.marker - w.options.min) / range;
86438662
ctx.fillStyle = "#AA9";
8644-
ctx.fillRect( margin + marker_nvalue * (width - margin * 2), y, 2, H );
8663+
ctx.fillRect( margin + marker_nvalue * (widget_width - margin * 2), y, 2, H );
86458664
}
86468665
if (show_text) {
86478666
ctx.textAlign = "center";
86488667
ctx.fillStyle = text_color;
86498668
ctx.fillText(
86508669
w.name + " " + Number(w.value).toFixed(3),
8651-
width * 0.5,
8670+
widget_width * 0.5,
86528671
y + H * 0.7
86538672
);
86548673
}
@@ -8660,9 +8679,9 @@ LGraphNode.prototype.executeAction = function(action)
86608679
ctx.fillStyle = background_color;
86618680
ctx.beginPath();
86628681
if(show_text)
8663-
ctx.roundRect(margin, posY, width - margin * 2, H, H * 0.5);
8682+
ctx.roundRect(margin, posY, widget_width - margin * 2, H, H * 0.5);
86648683
else
8665-
ctx.rect(margin, posY, width - margin * 2, H );
8684+
ctx.rect(margin, posY, widget_width - margin * 2, H );
86668685
ctx.fill();
86678686
if (show_text) {
86688687
if(!w.disabled)
@@ -8676,9 +8695,9 @@ LGraphNode.prototype.executeAction = function(action)
86768695
ctx.lineTo(margin + 16, posY + H - 5);
86778696
ctx.fill();
86788697
ctx.beginPath();
8679-
ctx.moveTo(width - margin - 16, posY + 5);
8680-
ctx.lineTo(width - margin - 6, posY + H * 0.5);
8681-
ctx.lineTo(width - margin - 16, posY + H - 5);
8698+
ctx.moveTo(widget_width - margin - 16, posY + 5);
8699+
ctx.lineTo(widget_width - margin - 6, posY + H * 0.5);
8700+
ctx.lineTo(widget_width - margin - 16, posY + H - 5);
86828701
ctx.fill();
86838702
}
86848703
ctx.fillStyle = secondary_text_color;
@@ -8692,7 +8711,7 @@ LGraphNode.prototype.executeAction = function(action)
86928711
? w.options.precision
86938712
: 3
86948713
),
8695-
width - margin * 2 - 20,
8714+
widget_width - margin * 2 - 20,
86968715
y + H * 0.7
86978716
);
86988717
} else {
@@ -8707,7 +8726,7 @@ LGraphNode.prototype.executeAction = function(action)
87078726
}
87088727
ctx.fillText(
87098728
v,
8710-
width - margin * 2 - 20,
8729+
widget_width - margin * 2 - 20,
87118730
y + H * 0.7
87128731
);
87138732
}
@@ -8720,14 +8739,14 @@ LGraphNode.prototype.executeAction = function(action)
87208739
ctx.fillStyle = background_color;
87218740
ctx.beginPath();
87228741
if (show_text)
8723-
ctx.roundRect(margin, posY, width - margin * 2, H, H * 0.5);
8742+
ctx.roundRect(margin, posY, widget_width - margin * 2, H, H * 0.5);
87248743
else
8725-
ctx.rect( margin, posY, width - margin * 2, H );
8744+
ctx.rect( margin, posY, widget_width - margin * 2, H );
87268745
ctx.fill();
87278746
if (show_text) {
87288747
ctx.save();
87298748
ctx.beginPath();
8730-
ctx.rect(margin, posY, width - margin * 2, H);
8749+
ctx.rect(margin, posY, widget_width - margin * 2, H);
87318750
ctx.clip();
87328751

87338752
ctx.stroke();
@@ -8737,17 +8756,17 @@ LGraphNode.prototype.executeAction = function(action)
87378756
}
87388757
ctx.fillStyle = text_color;
87398758
ctx.textAlign = "right";
8740-
ctx.fillText(String(w.value).substr(0,30), width - margin * 2, y + H * 0.7); //30 chars max
8759+
ctx.fillText(String(w.value).substr(0,30), widget_width - margin * 2, y + H * 0.7); //30 chars max
87418760
ctx.restore();
87428761
}
87438762
break;
87448763
default:
87458764
if (w.draw) {
8746-
w.draw(ctx, node, width, y, H);
8765+
w.draw(ctx, node, widget_width, y, H);
87478766
}
87488767
break;
87498768
}
8750-
posY += (w.computeSize ? w.computeSize(width)[1] : H) + 4;
8769+
posY += (w.computeSize ? w.computeSize(widget_width)[1] : H) + 4;
87518770
ctx.globalAlpha = this.editor_alpha;
87528771

87538772
}
@@ -8780,14 +8799,15 @@ LGraphNode.prototype.executeAction = function(action)
87808799
if(!w || w.disabled)
87818800
continue;
87828801
var widget_height = w.computeSize ? w.computeSize(width)[1] : LiteGraph.NODE_WIDGET_HEIGHT;
8802+
var widget_width = w.width || width;
87838803
//outside
87848804
if ( w != active_widget &&
8785-
(x < 6 || x > width - 12 || y < w.last_y || y > w.last_y + widget_height) )
8805+
(x < 6 || x > widget_width - 12 || y < w.last_y || y > w.last_y + widget_height) )
87868806
continue;
87878807

87888808
var old_value = w.value;
87898809

8790-
//if ( w == active_widget || (x > 6 && x < width - 12 && y > w.last_y && y < w.last_y + widget_height) ) {
8810+
//if ( w == active_widget || (x > 6 && x < widget_width - 12 && y > w.last_y && y < w.last_y + widget_height) ) {
87918811
//inside widget
87928812
switch (w.type) {
87938813
case "button":
@@ -8804,7 +8824,7 @@ LGraphNode.prototype.executeAction = function(action)
88048824
break;
88058825
case "slider":
88068826
var range = w.options.max - w.options.min;
8807-
var nvalue = Math.clamp((x - 10) / (width - 20), 0, 1);
8827+
var nvalue = Math.clamp((x - 10) / (widget_width - 20), 0, 1);
88088828
w.value =
88098829
w.options.min +
88108830
(w.options.max - w.options.min) * nvalue;
@@ -8836,7 +8856,7 @@ LGraphNode.prototype.executeAction = function(action)
88368856
if( w.type != "number")
88378857
values_list = values.constructor === Array ? values : Object.keys(values);
88388858

8839-
var delta = x < 40 ? -1 : x > width - 40 ? 1 : 0;
8859+
var delta = x < 40 ? -1 : x > widget_width - 40 ? 1 : 0;
88408860
if (w.type == "number") {
88418861
w.value += delta * 0.1 * (w.options.step || 1);
88428862
if ( w.options.min != null && w.value < w.options.min ) {
@@ -8883,7 +8903,7 @@ LGraphNode.prototype.executeAction = function(action)
88838903
} //end mousedown
88848904
else if(event.type == "mouseup" && w.type == "number")
88858905
{
8886-
var delta = x < 40 ? -1 : x > width - 40 ? 1 : 0;
8906+
var delta = x < 40 ? -1 : x > widget_width - 40 ? 1 : 0;
88878907
if (event.click_time < 200 && delta == 0) {
88888908
this.prompt("Value",w.value,function(v) {
88898909
this.value = Number(v);
@@ -9139,7 +9159,7 @@ LGraphNode.prototype.executeAction = function(action)
91399159

91409160
var values = LiteGraph.getNodeTypesCategories( canvas.filter || graph.filter );
91419161
var entries = [];
9142-
for (var i in values) {
9162+
for (var i=0; i < values.length; i++) {
91439163
if (values[i]) {
91449164
var name = values[i];
91459165
if(name.indexOf("::") != -1) //in case it has a namespace like "shader::math/rand" it hides the namespace
@@ -9155,7 +9175,7 @@ LGraphNode.prototype.executeAction = function(action)
91559175
var category = v.value;
91569176
var node_types = LiteGraph.getNodeTypesInCategory( category, canvas.filter || graph.filter );
91579177
var values = [];
9158-
for (var i in node_types) {
9178+
for (var i=0; i < node_types.length; i++) {
91599179
if (!node_types[i].skip_list) {
91609180
values.push({
91619181
content: node_types[i].title,
@@ -9210,7 +9230,7 @@ LGraphNode.prototype.executeAction = function(action)
92109230

92119231
var entries = [];
92129232
if (options) {
9213-
for (var i in options) {
9233+
for (var i=0; i < options.length; i++) {
92149234
var entry = options[i];
92159235
if (!entry) {
92169236
entries.push(null);
@@ -9290,7 +9310,7 @@ LGraphNode.prototype.executeAction = function(action)
92909310

92919311
var entries = [];
92929312
if (options) {
9293-
for (var i in options) {
9313+
for (var i=0; i < options.length; i++) {
92949314
var entry = options[i];
92959315
if (!entry) {
92969316
//separator?
@@ -11263,7 +11283,7 @@ LGraphNode.prototype.executeAction = function(action)
1126311283

1126411284
//entries
1126511285
var num = 0;
11266-
for (var i in values) {
11286+
for (var i=0; i < values.length; i++) {
1126711287
var name = values.constructor == Array ? values[i] : i;
1126811288
if (name != null && name.constructor !== String) {
1126911289
name = name.content === undefined ? String(name) : name.content;
@@ -11555,7 +11575,7 @@ LGraphNode.prototype.executeAction = function(action)
1155511575
result.push(elements[i]);
1155611576
}
1155711577

11558-
for (var i in result) {
11578+
for (var i=0; i < result.length; i++) {
1155911579
if (result[i].close) {
1156011580
result[i].close();
1156111581
} else if (result[i].parentNode) {
@@ -14241,7 +14261,7 @@ if (typeof exports != "undefined") {
1424114261

1424214262
if (typeof this.str == "string") {
1424314263
var lines = this.str.split("\\n");
14244-
for (var i in lines) {
14264+
for (var i=0; i < lines.length; i++) {
1424514265
ctx.fillText(
1424614266
lines[i],
1424714267
this.properties["align"] == "left" ? 15 : this.size[0] - 15,
@@ -14272,7 +14292,7 @@ if (typeof exports != "undefined") {
1427214292
this.last_ctx.font =
1427314293
this.properties["fontsize"] + "px " + this.properties["font"];
1427414294
var max = 0;
14275-
for (var i in lines) {
14295+
for (var i=0; i < lines.length; i++) {
1427614296
var w = this.last_ctx.measureText(lines[i]).width;
1427714297
if (max < w) {
1427814298
max = w;
@@ -17085,7 +17105,7 @@ if (typeof exports != "undefined") {
1708517105
c[2] = Math.abs( Math.sin( 0.01 * reModular.getTime() * Math.PI) );
1708617106
*/
1708717107

17088-
for (var i in result) {
17108+
for (var i=0; i < result.length; i++) {
1708917109
result[i] /= 255;
1709017110
}
1709117111

0 commit comments

Comments
 (0)