added support to load from file

This commit is contained in:
tamat
2020-09-09 17:53:41 +02:00
parent 8a4af6821c
commit 49d34fd5b3
3 changed files with 107 additions and 63 deletions

View File

@@ -2119,8 +2119,25 @@
return error;
};
LGraph.prototype.load = function(url) {
LGraph.prototype.load = function(url, callback) {
var that = this;
//from file
if(url.constructor === File || url.constructor === Blob)
{
var reader = new FileReader();
reader.addEventListener('load', function(event) {
var data = JSON.parse(event.target.result);
that.configure(data);
if(callback)
callback();
});
reader.readAsText(url);
return;
}
//is a string, then an URL
var req = new XMLHttpRequest();
req.open("GET", url, true);
req.send(null);
@@ -2129,8 +2146,10 @@
console.error("Error loading graph:", req.status, req.response);
return;
}
var data = JSON.parse(req.response);
var data = JSON.parse( req.response );
that.configure(data);
if(callback)
callback();
};
req.onerror = function(err) {
console.error("Error loading graph:", err);
@@ -10774,7 +10793,12 @@ LGraphNode.prototype.executeAction = function(action)
has_submenu: true,
callback: LGraphCanvas.onMenuNodeMode
},
{ content: "Resize", callback: LGraphCanvas.onResizeNode },
{
content: "Resize", callback: function() {
if(node.resizable)
return LGraphCanvas.onResizeNode;
}
},
{
content: "Collapse",
callback: LGraphCanvas.onMenuNodeCollapse

113
build/litegraph.min.js vendored
View File

@@ -50,57 +50,58 @@ a);this.sendActionToCanvas("onAfterChange",this)};c.prototype.connectionChange=f
b&&b._last_time&&(b._last_time=0)}};c.prototype.change=function(){e.debug&&console.log("Graph changed");this.sendActionToCanvas("setDirty",[!0,!0]);if(this.on_change)this.on_change(this)};c.prototype.setDirtyCanvas=function(a,b){this.sendActionToCanvas("setDirty",[a,b])};c.prototype.removeLink=function(a){if(a=this.links[a]){var b=this.getNodeById(a.target_id);b&&b.disconnectInput(a.target_slot)}};c.prototype.serialize=function(){for(var a=[],b=0,d=this._nodes.length;b<d;++b)a.push(this._nodes[b].serialize());
d=[];for(b in this.links){var f=this.links[b];if(!f.serialize){console.warn("weird LLink bug, link info is not a LLink but a regular object");var g=new m,t;for(t in f)g[t]=f[t];f=this.links[b]=g}d.push(f.serialize())}t=[];for(b=0;b<this._groups.length;++b)t.push(this._groups[b].serialize());a={last_node_id:this.last_node_id,last_link_id:this.last_link_id,nodes:a,links:d,groups:t,config:this.config,extra:this.extra,version:e.VERSION};if(this.onSerialize)this.onSerialize(a);return a};c.prototype.configure=
function(a,b){if(a){b||this.clear();var d=a.nodes;if(a.links&&a.links.constructor===Array){for(var f=[],g=0;g<a.links.length;++g){var t=a.links[g];if(t){var x=new m;x.configure(t);f[x.id]=x}else console.warn("serialized graph link data contains errors, skipping.")}a.links=f}for(g in a)"nodes"!=g&&"groups"!=g&&(this[g]=a[g]);f=!1;this._nodes=[];if(d){g=0;for(t=d.length;g<t;++g){var x=d[g],c=e.createNode(x.type,x.title);c||(e.debug&&console.log("Node not found or has errors: "+x.type),c=new s,c.last_serialization=
x,f=c.has_errors=!0);c.id=x.id;this.add(c,!0)}g=0;for(t=d.length;g<t;++g)x=d[g],(c=this.getNodeById(x.id))&&c.configure(x)}this._groups.length=0;if(a.groups)for(g=0;g<a.groups.length;++g)d=new e.LGraphGroup,d.configure(a.groups[g]),this.add(d);this.updateExecutionOrder();this.extra=a.extra||{};if(this.onConfigure)this.onConfigure(a);this._version++;this.setDirtyCanvas(!0,!0);return f}};c.prototype.load=function(a){var b=this,d=new XMLHttpRequest;d.open("GET",a,!0);d.send(null);d.onload=function(a){200!==
d.status?console.error("Error loading graph:",d.status,d.response):(a=JSON.parse(d.response),b.configure(a))};d.onerror=function(a){console.error("Error loading graph:",a)}};c.prototype.onNodeTrace=function(a,b,d){};m.prototype.configure=function(a){a.constructor===Array?(this.id=a[0],this.origin_id=a[1],this.origin_slot=a[2],this.target_id=a[3],this.target_slot=a[4],this.type=a[5]):(this.id=a.id,this.type=a.type,this.origin_id=a.origin_id,this.origin_slot=a.origin_slot,this.target_id=a.target_id,
this.target_slot=a.target_slot)};m.prototype.serialize=function(){return[this.id,this.origin_id,this.origin_slot,this.target_id,this.target_slot,this.type]};e.LLink=m;A.LGraphNode=e.LGraphNode=s;s.prototype._ctor=function(a){this.title=a||"Unnamed";this.size=[e.NODE_WIDTH,60];this.graph=null;this._pos=new Float32Array(10,10);Object.defineProperty(this,"pos",{set:function(a){!a||2>a.length||(this._pos[0]=a[0],this._pos[1]=a[1])},get:function(){return this._pos},enumerable:!0});this.id=-1;this.type=
null;this.inputs=[];this.outputs=[];this.connections=[];this.properties={};this.properties_info=[];this.flags={}};s.prototype.configure=function(a){this.graph&&this.graph._version++;for(var b in a)if("properties"==b)for(var d in a.properties){if(this.properties[d]=a.properties[d],this.onPropertyChanged)this.onPropertyChanged(d,a.properties[d])}else null!=a[b]&&("object"==typeof a[b]?this[b]&&this[b].configure?this[b].configure(a[b]):this[b]=e.cloneObject(a[b],this[b]):this[b]=a[b]);a.title||(this.title=
this.constructor.title);if(this.onConnectionsChange){if(this.inputs)for(d=0;d<this.inputs.length;++d){b=this.inputs[d];var f=this.graph?this.graph.links[b.link]:null;this.onConnectionsChange(e.INPUT,d,!0,f,b)}if(this.outputs)for(d=0;d<this.outputs.length;++d){var g=this.outputs[d];if(g.links)for(b=0;b<g.links.length;++b)f=this.graph?this.graph.links[g.links[b]]:null,this.onConnectionsChange(e.OUTPUT,d,!0,f,g)}}if(this.widgets){for(d=0;d<this.widgets.length;++d)(b=this.widgets[d])&&b.options&&b.options.property&&
this.properties[b.options.property]&&(b.value=JSON.parse(JSON.stringify(this.properties[b.options.property])));if(a.widgets_values)for(d=0;d<a.widgets_values.length;++d)this.widgets[d]&&(this.widgets[d].value=a.widgets_values[d])}if(this.onConfigure)this.onConfigure(a)};s.prototype.serialize=function(){var a={id:this.id,type:this.type,pos:this.pos,size:this.size,flags:e.cloneObject(this.flags),order:this.order,mode:this.mode};if(this.constructor===s&&this.last_serialization)return this.last_serialization;
this.inputs&&(a.inputs=this.inputs);if(this.outputs){for(var b=0;b<this.outputs.length;b++)delete this.outputs[b]._data;a.outputs=this.outputs}this.title&&this.title!=this.constructor.title&&(a.title=this.title);this.properties&&(a.properties=e.cloneObject(this.properties));if(this.widgets&&this.serialize_widgets)for(a.widgets_values=[],b=0;b<this.widgets.length;++b)a.widgets_values[b]=this.widgets[b]?this.widgets[b].value:null;a.type||(a.type=this.constructor.type);this.color&&(a.color=this.color);
this.bgcolor&&(a.bgcolor=this.bgcolor);this.boxcolor&&(a.boxcolor=this.boxcolor);this.shape&&(a.shape=this.shape);this.onSerialize&&this.onSerialize(a)&&console.warn("node onSerialize shouldnt return anything, data should be stored in the object pass in the first parameter");return a};s.prototype.clone=function(){var a=e.createNode(this.type);if(!a)return null;var b=e.cloneObject(this.serialize());if(b.inputs)for(var d=0;d<b.inputs.length;++d)b.inputs[d].link=null;if(b.outputs)for(d=0;d<b.outputs.length;++d)b.outputs[d].links&&
(b.outputs[d].links.length=0);delete b.id;a.configure(b);return a};s.prototype.toString=function(){return JSON.stringify(this.serialize())};s.prototype.getTitle=function(){return this.title||this.constructor.title};s.prototype.setProperty=function(a,b){this.properties||(this.properties={});if(b!==this.properties[a]){var d=this.properties[a];this.properties[a]=b;this.onPropertyChanged&&!1===this.onPropertyChanged(a,b,d)&&(this.properties[a]=d);if(this.widgets)for(d=0;d<this.widgets.length;++d){var f=
this.widgets[d];if(f&&f.options.property==a){f.value=b;break}}}};s.prototype.setOutputData=function(a,b){if(this.outputs&&!(-1==a||a>=this.outputs.length)){var d=this.outputs[a];if(d&&(d._data=b,this.outputs[a].links))for(d=0;d<this.outputs[a].links.length;d++){var f=this.graph.links[this.outputs[a].links[d]];f&&(f.data=b)}}};s.prototype.setOutputDataType=function(a,b){if(this.outputs&&!(-1==a||a>=this.outputs.length)){var d=this.outputs[a];if(d&&(d.type=b,this.outputs[a].links))for(d=0;d<this.outputs[a].links.length;d++)this.graph.links[this.outputs[a].links[d]].type=
b}};s.prototype.getInputData=function(a,b){if(this.inputs&&!(a>=this.inputs.length||null==this.inputs[a].link)){var d=this.graph.links[this.inputs[a].link];if(!d)return null;if(!b)return d.data;var f=this.graph.getNodeById(d.origin_id);if(!f)return d.data;if(f.updateOutputData)f.updateOutputData(d.origin_slot);else if(f.onExecute)f.onExecute();return d.data}};s.prototype.getInputDataType=function(a){if(!this.inputs||a>=this.inputs.length||null==this.inputs[a].link)return null;a=this.graph.links[this.inputs[a].link];
if(!a)return null;var b=this.graph.getNodeById(a.origin_id);return b?(a=b.outputs[a.origin_slot])?a.type:null:a.type};s.prototype.getInputDataByName=function(a,b){var d=this.findInputSlot(a);return-1==d?null:this.getInputData(d,b)};s.prototype.isInputConnected=function(a){return this.inputs?a<this.inputs.length&&null!=this.inputs[a].link:!1};s.prototype.getInputInfo=function(a){return this.inputs?a<this.inputs.length?this.inputs[a]:null:null};s.prototype.getInputLink=function(a){return this.inputs?
a<this.inputs.length?this.graph.links[this.inputs[a].link]:null:null};s.prototype.getInputNode=function(a){if(!this.inputs||a>=this.inputs.length)return null;a=this.inputs[a];return a&&null!==a.link?(a=this.graph.links[a.link])?this.graph.getNodeById(a.origin_id):null:null};s.prototype.getInputOrProperty=function(a){if(!this.inputs||!this.inputs.length)return this.properties?this.properties[a]:null;for(var b=0,d=this.inputs.length;b<d;++b){var f=this.inputs[b];if(a==f.name&&null!=f.link&&(f=this.graph.links[f.link]))return f.data}return this.properties[a]};
s.prototype.getOutputData=function(a){return!this.outputs||a>=this.outputs.length?null:this.outputs[a]._data};s.prototype.getOutputInfo=function(a){return this.outputs?a<this.outputs.length?this.outputs[a]:null:null};s.prototype.isOutputConnected=function(a){return this.outputs?a<this.outputs.length&&this.outputs[a].links&&this.outputs[a].links.length:!1};s.prototype.isAnyOutputConnected=function(){if(!this.outputs)return!1;for(var a=0;a<this.outputs.length;++a)if(this.outputs[a].links&&this.outputs[a].links.length)return!0;
return!1};s.prototype.getOutputNodes=function(a){if(!this.outputs||0==this.outputs.length||a>=this.outputs.length)return null;a=this.outputs[a];if(!a.links||0==a.links.length)return null;for(var b=[],d=0;d<a.links.length;d++){var f=this.graph.links[a.links[d]];f&&(f=this.graph.getNodeById(f.target_id))&&b.push(f)}return b};s.prototype.trigger=function(a,b){if(this.outputs&&this.outputs.length){this.graph&&(this.graph._last_trigger_time=e.getTime());for(var d=0;d<this.outputs.length;++d){var f=this.outputs[d];
!f||f.type!==e.EVENT||a&&f.name!=a||this.triggerSlot(d,b)}}};s.prototype.triggerSlot=function(a,b,d){if(this.outputs&&(a=this.outputs[a])&&(a=a.links)&&a.length){this.graph&&(this.graph._last_trigger_time=e.getTime());for(var f=0;f<a.length;++f){var g=a[f];if(null==d||d==g){var t=this.graph.links[a[f]];if(t&&(t._last_time=e.getTime(),g=this.graph.getNodeById(t.target_id)))if(t=g.inputs[t.target_slot],g.mode===e.ON_TRIGGER){if(g.onExecute)g.onExecute(b)}else if(g.onAction)g.onAction(t.name,b)}}}};
s.prototype.clearTriggeredSlot=function(a,b){if(this.outputs){var d=this.outputs[a];if(d&&(d=d.links)&&d.length)for(var f=0;f<d.length;++f){var g=d[f];if(null==b||b==g)if(g=this.graph.links[d[f]])g._last_time=0}}};s.prototype.setSize=function(a){this.size=a;if(this.onResize)this.onResize(this.size)};s.prototype.addProperty=function(a,b,d,f){d={name:a,type:d,default_value:b};if(f)for(var g in f)d[g]=f[g];this.properties_info||(this.properties_info=[]);this.properties_info.push(d);this.properties||
(this.properties={});this.properties[a]=b;return d};s.prototype.addOutput=function(a,b,d){a={name:a,type:b,links:null};if(d)for(var f in d)a[f]=d[f];this.outputs||(this.outputs=[]);this.outputs.push(a);if(this.onOutputAdded)this.onOutputAdded(a);this.setSize(this.computeSize());this.setDirtyCanvas(!0,!0);return a};s.prototype.addOutputs=function(a){for(var b=0;b<a.length;++b){var d=a[b],f={name:d[0],type:d[1],link:null};if(a[2])for(var g in d[2])f[g]=d[2][g];this.outputs||(this.outputs=[]);this.outputs.push(f);
if(this.onOutputAdded)this.onOutputAdded(f)}this.setSize(this.computeSize());this.setDirtyCanvas(!0,!0)};s.prototype.removeOutput=function(a){this.disconnectOutput(a);this.outputs.splice(a,1);for(var b=a;b<this.outputs.length;++b)if(this.outputs[b]&&this.outputs[b].links)for(var d=this.outputs[b].links,f=0;f<d.length;++f){var g=this.graph.links[d[f]];g&&(g.origin_slot-=1)}this.setSize(this.computeSize());if(this.onOutputRemoved)this.onOutputRemoved(a);this.setDirtyCanvas(!0,!0)};s.prototype.addInput=
function(a,b,d){a={name:a,type:b||0,link:null};if(d)for(var f in d)a[f]=d[f];this.inputs||(this.inputs=[]);this.inputs.push(a);this.setSize(this.computeSize());if(this.onInputAdded)this.onInputAdded(a);this.setDirtyCanvas(!0,!0);return a};s.prototype.addInputs=function(a){for(var b=0;b<a.length;++b){var d=a[b],f={name:d[0],type:d[1],link:null};if(a[2])for(var g in d[2])f[g]=d[2][g];this.inputs||(this.inputs=[]);this.inputs.push(f);if(this.onInputAdded)this.onInputAdded(f)}this.setSize(this.computeSize());
this.setDirtyCanvas(!0,!0)};s.prototype.removeInput=function(a){this.disconnectInput(a);for(var b=this.inputs.splice(a,1),d=a;d<this.inputs.length;++d)if(this.inputs[d]){var f=this.graph.links[this.inputs[d].link];f&&(f.target_slot-=1)}this.setSize(this.computeSize());if(this.onInputRemoved)this.onInputRemoved(a,b[0]);this.setDirtyCanvas(!0,!0)};s.prototype.addConnection=function(a,b,d,f){a={name:a,type:b,pos:d,direction:f,links:null};this.connections.push(a);return a};s.prototype.computeSize=function(a){function b(a){return a?
f*a.length*0.6:0}if(this.constructor.size)return this.constructor.size.concat();var d=Math.max(this.inputs?this.inputs.length:1,this.outputs?this.outputs.length:1);a=a||new Float32Array([0,0]);var d=Math.max(d,1),f=e.NODE_TEXT_SIZE,g=b(this.title),t=0,x=0;if(this.inputs)for(var c=0,k=this.inputs.length;c<k;++c){var h=this.inputs[c],h=h.label||h.name||"",h=b(h);t<h&&(t=h)}if(this.outputs)for(c=0,k=this.outputs.length;c<k;++c)h=this.outputs[c],h=h.label||h.name||"",h=b(h),x<h&&(x=h);a[0]=Math.max(t+
x+10,g);a[0]=Math.max(a[0],e.NODE_WIDTH);this.widgets&&this.widgets.length&&(a[0]=Math.max(a[0],1.5*e.NODE_WIDTH));a[1]=(this.constructor.slot_start_y||0)+d*e.NODE_SLOT_HEIGHT;d=0;if(this.widgets&&this.widgets.length){c=0;for(k=this.widgets.length;c<k;++c)d=this.widgets[c].computeSize?d+(this.widgets[c].computeSize(a[0])[1]+4):d+(e.NODE_WIDGET_HEIGHT+4);d+=8}a[1]=this.widgets_up?Math.max(a[1],d):null!=this.widgets_start_y?Math.max(a[1],d+this.widgets_start_y):a[1]+d;this.constructor.min_height&&a[1]<
this.constructor.min_height&&(a[1]=this.constructor.min_height);a[1]+=6;return a};s.prototype.getPropertyInfo=function(a){var b=null;if(this.properties_info)for(var d=0;d<this.properties_info.length;++d)if(this.properties_info[d].name==a){b=this.properties_info[d];break}this.constructor["@"+a]&&(b=this.constructor["@"+a]);this.constructor.widgets_info&&this.constructor.widgets_info[a]&&(b=this.constructor.widgets_info[a]);!b&&this.onGetPropertyInfo&&(b=this.onGetPropertyInfo(a));b||(b={});b.type||
(b.type=typeof this.properties[a]);"combo"==b.widget&&(b.type="enum");return b};s.prototype.addWidget=function(a,b,d,f,g){this.widgets||(this.widgets=[]);!g&&f&&f.constructor===Object&&(g=f,f=null);g&&g.constructor===String&&(g={property:g});f&&f.constructor===String&&(g||(g={}),g.property=f,f=null);f&&f.constructor!==Function&&(console.warn("addWidget: callback must be a function"),f=null);b={type:a.toLowerCase(),name:b,value:d,callback:f,options:g||{}};void 0!==b.options.y&&(b.y=b.options.y);f||
b.options.callback||b.options.property||console.warn("LiteGraph addWidget(...) without a callback or property assigned");if("combo"==a&&!b.options.values)throw"LiteGraph addWidget('combo',...) requires to pass values in options: { values:['red','blue'] }";this.widgets.push(b);this.setSize(this.computeSize());return b};s.prototype.addCustomWidget=function(a){this.widgets||(this.widgets=[]);this.widgets.push(a);return a};s.prototype.getBounding=function(a){a=a||new Float32Array(4);a[0]=this.pos[0]-
4;a[1]=this.pos[1]-e.NODE_TITLE_HEIGHT;a[2]=this.size[0]+4;a[3]=this.size[1]+e.NODE_TITLE_HEIGHT;if(this.onBounding)this.onBounding(a);return a};s.prototype.isPointInside=function(a,b,d,f){d=d||0;var g=this.graph&&this.graph.isLive()?0:e.NODE_TITLE_HEIGHT;f&&(g=0);if(this.flags&&this.flags.collapsed){if(v(a,b,this.pos[0]-d,this.pos[1]-e.NODE_TITLE_HEIGHT-d,(this._collapsed_width||e.NODE_COLLAPSED_WIDTH)+2*d,e.NODE_TITLE_HEIGHT+2*d))return!0}else if(this.pos[0]-4-d<a&&this.pos[0]+this.size[0]+4+d>
a&&this.pos[1]-g-d<b&&this.pos[1]+this.size[1]+d>b)return!0;return!1};s.prototype.getSlotInPosition=function(a,b){var d=new Float32Array(2);if(this.inputs)for(var f=0,g=this.inputs.length;f<g;++f){var t=this.inputs[f];this.getConnectionPos(!0,f,d);if(v(a,b,d[0]-10,d[1]-5,20,10))return{input:t,slot:f,link_pos:d}}if(this.outputs)for(f=0,g=this.outputs.length;f<g;++f)if(t=this.outputs[f],this.getConnectionPos(!1,f,d),v(a,b,d[0]-10,d[1]-5,20,10))return{output:t,slot:f,link_pos:d};return null};s.prototype.findInputSlot=
function(a){if(!this.inputs)return-1;for(var b=0,d=this.inputs.length;b<d;++b)if(a==this.inputs[b].name)return b;return-1};s.prototype.findOutputSlot=function(a){if(!this.outputs)return-1;for(var b=0,d=this.outputs.length;b<d;++b)if(a==this.outputs[b].name)return b;return-1};s.prototype.connect=function(a,b,d){d=d||0;if(!this.graph)return console.log("Connect: Error, node doesn't belong to any graph. Nodes must be added first to a graph before connecting them."),null;if(a.constructor===String){if(a=
this.findOutputSlot(a),-1==a)return e.debug&&console.log("Connect: Error, no slot of name "+a),null}else if(!this.outputs||a>=this.outputs.length)return e.debug&&console.log("Connect: Error, slot number not found"),null;b&&b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"target node is null";if(b==this)return null;if(d.constructor===String){if(d=b.findInputSlot(d),-1==d)return e.debug&&console.log("Connect: Error, no slot of name "+d),null}else{if(d===e.EVENT)return null;if(!b.inputs||
d>=b.inputs.length)return e.debug&&console.log("Connect: Error, slot number not found"),null}var f=!1;null!=b.inputs[d].link&&(this.graph.beforeChange(),b.disconnectInput(d),f=!0);var g=this.outputs[a];if(b.onConnectInput&&!1===b.onConnectInput(d,g.type,g,this,a))return null;var t=b.inputs[d],x=null;if(!e.isValidConnection(g.type,t.type))return this.setDirtyCanvas(!1,!0),f&&this.graph.connectionChange(this,x),null;f||this.graph.beforeChange();x=new m(++this.graph.last_link_id,t.type,this.id,a,b.id,
d);this.graph.links[x.id]=x;null==g.links&&(g.links=[]);g.links.push(x.id);b.inputs[d].link=x.id;this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(e.OUTPUT,a,!0,x,g);if(b.onConnectionsChange)b.onConnectionsChange(e.INPUT,d,!0,x,t);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(e.INPUT,b,d,this,a),this.graph.onNodeConnectionChange(e.OUTPUT,this,a,b,d));this.setDirtyCanvas(!1,!0);this.graph.afterChange();this.graph.connectionChange(this,
x);return x};s.prototype.disconnectOutput=function(a,b){if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return e.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.outputs||a>=this.outputs.length)return e.debug&&console.log("Connect: Error, slot number not found"),!1;var d=this.outputs[a];if(!d||!d.links||0==d.links.length)return!1;if(b){b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"Target Node not found";for(var f=0,g=d.links.length;f<g;f++){var t=
d.links[f],x=this.graph.links[t];if(x.target_id==b.id){d.links.splice(f,1);var c=b.inputs[x.target_slot];c.link=null;delete this.graph.links[t];this.graph&&this.graph._version++;if(b.onConnectionsChange)b.onConnectionsChange(e.INPUT,x.target_slot,!1,x,c);if(this.onConnectionsChange)this.onConnectionsChange(e.OUTPUT,a,!1,x,d);if(this.graph&&this.graph.onNodeConnectionChange)this.graph.onNodeConnectionChange(e.OUTPUT,this,a);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(e.OUTPUT,
this,a),this.graph.onNodeConnectionChange(e.INPUT,b,x.target_slot));break}}}else{f=0;for(g=d.links.length;f<g;f++)if(t=d.links[f],x=this.graph.links[t]){b=this.graph.getNodeById(x.target_id);this.graph&&this.graph._version++;if(b){c=b.inputs[x.target_slot];c.link=null;if(b.onConnectionsChange)b.onConnectionsChange(e.INPUT,x.target_slot,!1,x,c);if(this.graph&&this.graph.onNodeConnectionChange)this.graph.onNodeConnectionChange(e.INPUT,b,x.target_slot)}delete this.graph.links[t];if(this.onConnectionsChange)this.onConnectionsChange(e.OUTPUT,
a,!1,x,d);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(e.OUTPUT,this,a),this.graph.onNodeConnectionChange(e.INPUT,b,x.target_slot))}d.links=null}this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this);return!0};s.prototype.disconnectInput=function(a){if(a.constructor===String){if(a=this.findInputSlot(a),-1==a)return e.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.inputs||a>=this.inputs.length)return e.debug&&console.log("Connect: Error, slot number not found"),
!1;var b=this.inputs[a];if(!b)return!1;var d=this.inputs[a].link;if(null!=d){this.inputs[a].link=null;var f=this.graph.links[d];if(f){var g=this.graph.getNodeById(f.origin_id);if(!g)return!1;var t=g.outputs[f.origin_slot];if(!t||!t.links||0==t.links.length)return!1;for(var x=0,c=t.links.length;x<c;x++)if(t.links[x]==d){t.links.splice(x,1);break}delete this.graph.links[d];this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(e.INPUT,a,!1,f,b);if(g.onConnectionsChange)g.onConnectionsChange(e.OUTPUT,
x,!1,f,t);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(e.OUTPUT,g,x),this.graph.onNodeConnectionChange(e.INPUT,this,a))}}this.setDirtyCanvas(!1,!0);this.graph&&this.graph.connectionChange(this);return!0};s.prototype.getConnectionPos=function(a,b,d){d=d||new Float32Array(2);var f=0;a&&this.inputs&&(f=this.inputs.length);!a&&this.outputs&&(f=this.outputs.length);var g=0.5*e.NODE_SLOT_HEIGHT;if(this.flags.collapsed)return b=this._collapsed_width||e.NODE_COLLAPSED_WIDTH,
this.horizontal?(d[0]=this.pos[0]+0.5*b,d[1]=a?this.pos[1]-e.NODE_TITLE_HEIGHT:this.pos[1]):(d[0]=a?this.pos[0]:this.pos[0]+b,d[1]=this.pos[1]-0.5*e.NODE_TITLE_HEIGHT),d;if(a&&-1==b)return d[0]=this.pos[0]+0.5*e.NODE_TITLE_HEIGHT,d[1]=this.pos[1]+0.5*e.NODE_TITLE_HEIGHT,d;if(a&&f>b&&this.inputs[b].pos)return d[0]=this.pos[0]+this.inputs[b].pos[0],d[1]=this.pos[1]+this.inputs[b].pos[1],d;if(!a&&f>b&&this.outputs[b].pos)return d[0]=this.pos[0]+this.outputs[b].pos[0],d[1]=this.pos[1]+this.outputs[b].pos[1],
d;if(this.horizontal)return d[0]=this.pos[0]+this.size[0]/f*(b+0.5),d[1]=a?this.pos[1]-e.NODE_TITLE_HEIGHT:this.pos[1]+this.size[1],d;d[0]=a?this.pos[0]+g:this.pos[0]+this.size[0]+1-g;d[1]=this.pos[1]+(b+0.7)*e.NODE_SLOT_HEIGHT+(this.constructor.slot_start_y||0);return d};s.prototype.alignToGrid=function(){this.pos[0]=e.CANVAS_GRID_SIZE*Math.round(this.pos[0]/e.CANVAS_GRID_SIZE);this.pos[1]=e.CANVAS_GRID_SIZE*Math.round(this.pos[1]/e.CANVAS_GRID_SIZE)};s.prototype.trace=function(a){this.console||
(this.console=[]);this.console.push(a);this.console.length>s.MAX_CONSOLE&&this.console.shift();if(this.graph.onNodeTrace)this.graph.onNodeTrace(this,a)};s.prototype.setDirtyCanvas=function(a,b){this.graph&&this.graph.sendActionToCanvas("setDirty",[a,b])};s.prototype.loadImage=function(a){var b=new Image;b.src=e.node_images_path+a;b.ready=!1;var d=this;b.onload=function(){this.ready=!0;d.setDirtyCanvas(!0)};return b};s.prototype.captureInput=function(a){if(this.graph&&this.graph.list_of_graphcanvas)for(var b=
this.graph.list_of_graphcanvas,d=0;d<b.length;++d){var f=b[d];if(a||f.node_capturing_input==this)f.node_capturing_input=a?this:null}};s.prototype.collapse=function(a){this.graph._version++;if(!1!==this.constructor.collapsable||a)this.flags.collapsed=this.flags.collapsed?!1:!0,this.setDirtyCanvas(!0,!0)};s.prototype.pin=function(a){this.graph._version++;this.flags.pinned=void 0===a?!this.flags.pinned:a};s.prototype.localToScreen=function(a,b,d){return[(a+this.pos[0])*d.scale+d.offset[0],(b+this.pos[1])*
d.scale+d.offset[1]]};A.LGraphGroup=e.LGraphGroup=l;l.prototype._ctor=function(a){this.title=a||"Group";this.font_size=24;this.color=h.node_colors.pale_blue?h.node_colors.pale_blue.groupcolor:"#AAA";this._bounding=new Float32Array([10,10,140,80]);this._pos=this._bounding.subarray(0,2);this._size=this._bounding.subarray(2,4);this._nodes=[];this.graph=null;Object.defineProperty(this,"pos",{set:function(a){!a||2>a.length||(this._pos[0]=a[0],this._pos[1]=a[1])},get:function(){return this._pos},enumerable:!0});
Object.defineProperty(this,"size",{set:function(a){!a||2>a.length||(this._size[0]=Math.max(140,a[0]),this._size[1]=Math.max(80,a[1]))},get:function(){return this._size},enumerable:!0})};l.prototype.configure=function(a){this.title=a.title;this._bounding.set(a.bounding);this.color=a.color;this.font=a.font};l.prototype.serialize=function(){var a=this._bounding;return{title:this.title,bounding:[Math.round(a[0]),Math.round(a[1]),Math.round(a[2]),Math.round(a[3])],color:this.color,font:this.font}};l.prototype.move=
function(a,b,d){this._pos[0]+=a;this._pos[1]+=b;if(!d)for(d=0;d<this._nodes.length;++d){var f=this._nodes[d];f.pos[0]+=a;f.pos[1]+=b}};l.prototype.recomputeInsideNodes=function(){this._nodes.length=0;for(var a=this.graph._nodes,b=new Float32Array(4),d=0;d<a.length;++d){var f=a[d];f.getBounding(b);E(this._bounding,b)&&this._nodes.push(f)}};l.prototype.isPointInside=s.prototype.isPointInside;l.prototype.setDirtyCanvas=s.prototype.setDirtyCanvas;e.DragAndScale=w;w.prototype.bindEvents=function(a){this.last_mouse=
new Float32Array(2);this._binded_mouse_callback=this.onMouse.bind(this);a.addEventListener("mousedown",this._binded_mouse_callback);a.addEventListener("mousemove",this._binded_mouse_callback);a.addEventListener("mousewheel",this._binded_mouse_callback,!1);a.addEventListener("wheel",this._binded_mouse_callback,!1)};w.prototype.computeVisibleArea=function(){if(this.element){var a=-this.offset[0],b=-this.offset[1],d=a+this.element.width/this.scale,f=b+this.element.height/this.scale;this.visible_area[0]=
a;this.visible_area[1]=b;this.visible_area[2]=d-a;this.visible_area[3]=f-b}else this.visible_area[0]=this.visible_area[1]=this.visible_area[2]=this.visible_area[3]=0};w.prototype.onMouse=function(a){if(this.enabled){var b=this.element,d=b.getBoundingClientRect(),f=a.clientX-d.left,d=a.clientY-d.top;a.canvasx=f;a.canvasy=d;a.dragging=this.dragging;var g=!1;this.onmouse&&(g=this.onmouse(a));if("mousedown"==a.type)this.dragging=!0,b.removeEventListener("mousemove",this._binded_mouse_callback),document.body.addEventListener("mousemove",
this._binded_mouse_callback),document.body.addEventListener("mouseup",this._binded_mouse_callback);else if("mousemove"==a.type)g||(b=f-this.last_mouse[0],g=d-this.last_mouse[1],this.dragging&&this.mouseDrag(b,g));else if("mouseup"==a.type)this.dragging=!1,document.body.removeEventListener("mousemove",this._binded_mouse_callback),document.body.removeEventListener("mouseup",this._binded_mouse_callback),b.addEventListener("mousemove",this._binded_mouse_callback);else if("mousewheel"==a.type||"wheel"==
a.type||"DOMMouseScroll"==a.type)a.eventType="mousewheel",a.wheel="wheel"==a.type?-a.deltaY:null!=a.wheelDeltaY?a.wheelDeltaY:-60*a.detail,a.delta=a.wheelDelta?a.wheelDelta/40:a.deltaY?-a.deltaY/3:0,this.changeDeltaScale(1+0.05*a.delta);this.last_mouse[0]=f;this.last_mouse[1]=d;a.preventDefault();a.stopPropagation();return!1}};w.prototype.toCanvasContext=function(a){a.scale(this.scale,this.scale);a.translate(this.offset[0],this.offset[1])};w.prototype.convertOffsetToCanvas=function(a){return[(a[0]+
this.offset[0])*this.scale,(a[1]+this.offset[1])*this.scale]};w.prototype.convertCanvasToOffset=function(a,b){b=b||[0,0];b[0]=a[0]/this.scale-this.offset[0];b[1]=a[1]/this.scale-this.offset[1];return b};w.prototype.mouseDrag=function(a,b){this.offset[0]+=a/this.scale;this.offset[1]+=b/this.scale;if(this.onredraw)this.onredraw(this)};w.prototype.changeScale=function(a,b){a<this.min_scale?a=this.min_scale:a>this.max_scale&&(a=this.max_scale);if(a!=this.scale&&this.element){var d=this.element.getBoundingClientRect();
if(d){b=b||[0.5*d.width,0.5*d.height];d=this.convertCanvasToOffset(b);this.scale=a;0.01>Math.abs(this.scale-1)&&(this.scale=1);var f=this.convertCanvasToOffset(b),d=[f[0]-d[0],f[1]-d[1]];this.offset[0]+=d[0];this.offset[1]+=d[1];if(this.onredraw)this.onredraw(this)}}};w.prototype.changeDeltaScale=function(a,b){this.changeScale(this.scale*a,b)};w.prototype.reset=function(){this.scale=1;this.offset[0]=0;this.offset[1]=0};A.LGraphCanvas=e.LGraphCanvas=h;h.DEFAULT_BACKGROUND_IMAGE="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQBJREFUeNrs1rEKwjAUhlETUkj3vP9rdmr1Ysammk2w5wdxuLgcMHyptfawuZX4pJSWZTnfnu/lnIe/jNNxHHGNn//HNbbv+4dr6V+11uF527arU7+u63qfa/bnmh8sWLBgwYJlqRf8MEptXPBXJXa37BSl3ixYsGDBMliwFLyCV/DeLIMFCxYsWLBMwSt4Be/NggXLYMGCBUvBK3iNruC9WbBgwYJlsGApeAWv4L1ZBgsWLFiwYJmCV/AK3psFC5bBggULloJX8BpdwXuzYMGCBctgwVLwCl7Be7MMFixYsGDBsu8FH1FaSmExVfAxBa/gvVmwYMGCZbBg/W4vAQYA5tRF9QYlv/QAAAAASUVORK5CYII=";
x,f=c.has_errors=!0);c.id=x.id;this.add(c,!0)}g=0;for(t=d.length;g<t;++g)x=d[g],(c=this.getNodeById(x.id))&&c.configure(x)}this._groups.length=0;if(a.groups)for(g=0;g<a.groups.length;++g)d=new e.LGraphGroup,d.configure(a.groups[g]),this.add(d);this.updateExecutionOrder();this.extra=a.extra||{};if(this.onConfigure)this.onConfigure(a);this._version++;this.setDirtyCanvas(!0,!0);return f}};c.prototype.load=function(a,b){var d=this;if(a.constructor===File||a.constructor===Blob){var f=new FileReader;f.addEventListener("load",
function(a){a=JSON.parse(a.target.result);d.configure(a);b&&b()});f.readAsText(a)}else{var g=new XMLHttpRequest;g.open("GET",a,!0);g.send(null);g.onload=function(a){200!==g.status?console.error("Error loading graph:",g.status,g.response):(a=JSON.parse(g.response),d.configure(a),b&&b())};g.onerror=function(a){console.error("Error loading graph:",a)}}};c.prototype.onNodeTrace=function(a,b,d){};m.prototype.configure=function(a){a.constructor===Array?(this.id=a[0],this.origin_id=a[1],this.origin_slot=
a[2],this.target_id=a[3],this.target_slot=a[4],this.type=a[5]):(this.id=a.id,this.type=a.type,this.origin_id=a.origin_id,this.origin_slot=a.origin_slot,this.target_id=a.target_id,this.target_slot=a.target_slot)};m.prototype.serialize=function(){return[this.id,this.origin_id,this.origin_slot,this.target_id,this.target_slot,this.type]};e.LLink=m;A.LGraphNode=e.LGraphNode=s;s.prototype._ctor=function(a){this.title=a||"Unnamed";this.size=[e.NODE_WIDTH,60];this.graph=null;this._pos=new Float32Array(10,
10);Object.defineProperty(this,"pos",{set:function(a){!a||2>a.length||(this._pos[0]=a[0],this._pos[1]=a[1])},get:function(){return this._pos},enumerable:!0});this.id=-1;this.type=null;this.inputs=[];this.outputs=[];this.connections=[];this.properties={};this.properties_info=[];this.flags={}};s.prototype.configure=function(a){this.graph&&this.graph._version++;for(var b in a)if("properties"==b)for(var d in a.properties){if(this.properties[d]=a.properties[d],this.onPropertyChanged)this.onPropertyChanged(d,
a.properties[d])}else null!=a[b]&&("object"==typeof a[b]?this[b]&&this[b].configure?this[b].configure(a[b]):this[b]=e.cloneObject(a[b],this[b]):this[b]=a[b]);a.title||(this.title=this.constructor.title);if(this.onConnectionsChange){if(this.inputs)for(d=0;d<this.inputs.length;++d){b=this.inputs[d];var f=this.graph?this.graph.links[b.link]:null;this.onConnectionsChange(e.INPUT,d,!0,f,b)}if(this.outputs)for(d=0;d<this.outputs.length;++d){var g=this.outputs[d];if(g.links)for(b=0;b<g.links.length;++b)f=
this.graph?this.graph.links[g.links[b]]:null,this.onConnectionsChange(e.OUTPUT,d,!0,f,g)}}if(this.widgets){for(d=0;d<this.widgets.length;++d)(b=this.widgets[d])&&b.options&&b.options.property&&this.properties[b.options.property]&&(b.value=JSON.parse(JSON.stringify(this.properties[b.options.property])));if(a.widgets_values)for(d=0;d<a.widgets_values.length;++d)this.widgets[d]&&(this.widgets[d].value=a.widgets_values[d])}if(this.onConfigure)this.onConfigure(a)};s.prototype.serialize=function(){var a=
{id:this.id,type:this.type,pos:this.pos,size:this.size,flags:e.cloneObject(this.flags),order:this.order,mode:this.mode};if(this.constructor===s&&this.last_serialization)return this.last_serialization;this.inputs&&(a.inputs=this.inputs);if(this.outputs){for(var b=0;b<this.outputs.length;b++)delete this.outputs[b]._data;a.outputs=this.outputs}this.title&&this.title!=this.constructor.title&&(a.title=this.title);this.properties&&(a.properties=e.cloneObject(this.properties));if(this.widgets&&this.serialize_widgets)for(a.widgets_values=
[],b=0;b<this.widgets.length;++b)a.widgets_values[b]=this.widgets[b]?this.widgets[b].value:null;a.type||(a.type=this.constructor.type);this.color&&(a.color=this.color);this.bgcolor&&(a.bgcolor=this.bgcolor);this.boxcolor&&(a.boxcolor=this.boxcolor);this.shape&&(a.shape=this.shape);this.onSerialize&&this.onSerialize(a)&&console.warn("node onSerialize shouldnt return anything, data should be stored in the object pass in the first parameter");return a};s.prototype.clone=function(){var a=e.createNode(this.type);
if(!a)return null;var b=e.cloneObject(this.serialize());if(b.inputs)for(var d=0;d<b.inputs.length;++d)b.inputs[d].link=null;if(b.outputs)for(d=0;d<b.outputs.length;++d)b.outputs[d].links&&(b.outputs[d].links.length=0);delete b.id;a.configure(b);return a};s.prototype.toString=function(){return JSON.stringify(this.serialize())};s.prototype.getTitle=function(){return this.title||this.constructor.title};s.prototype.setProperty=function(a,b){this.properties||(this.properties={});if(b!==this.properties[a]){var d=
this.properties[a];this.properties[a]=b;this.onPropertyChanged&&!1===this.onPropertyChanged(a,b,d)&&(this.properties[a]=d);if(this.widgets)for(d=0;d<this.widgets.length;++d){var f=this.widgets[d];if(f&&f.options.property==a){f.value=b;break}}}};s.prototype.setOutputData=function(a,b){if(this.outputs&&!(-1==a||a>=this.outputs.length)){var d=this.outputs[a];if(d&&(d._data=b,this.outputs[a].links))for(d=0;d<this.outputs[a].links.length;d++){var f=this.graph.links[this.outputs[a].links[d]];f&&(f.data=
b)}}};s.prototype.setOutputDataType=function(a,b){if(this.outputs&&!(-1==a||a>=this.outputs.length)){var d=this.outputs[a];if(d&&(d.type=b,this.outputs[a].links))for(d=0;d<this.outputs[a].links.length;d++)this.graph.links[this.outputs[a].links[d]].type=b}};s.prototype.getInputData=function(a,b){if(this.inputs&&!(a>=this.inputs.length||null==this.inputs[a].link)){var d=this.graph.links[this.inputs[a].link];if(!d)return null;if(!b)return d.data;var f=this.graph.getNodeById(d.origin_id);if(!f)return d.data;
if(f.updateOutputData)f.updateOutputData(d.origin_slot);else if(f.onExecute)f.onExecute();return d.data}};s.prototype.getInputDataType=function(a){if(!this.inputs||a>=this.inputs.length||null==this.inputs[a].link)return null;a=this.graph.links[this.inputs[a].link];if(!a)return null;var b=this.graph.getNodeById(a.origin_id);return b?(a=b.outputs[a.origin_slot])?a.type:null:a.type};s.prototype.getInputDataByName=function(a,b){var d=this.findInputSlot(a);return-1==d?null:this.getInputData(d,b)};s.prototype.isInputConnected=
function(a){return this.inputs?a<this.inputs.length&&null!=this.inputs[a].link:!1};s.prototype.getInputInfo=function(a){return this.inputs?a<this.inputs.length?this.inputs[a]:null:null};s.prototype.getInputLink=function(a){return this.inputs?a<this.inputs.length?this.graph.links[this.inputs[a].link]:null:null};s.prototype.getInputNode=function(a){if(!this.inputs||a>=this.inputs.length)return null;a=this.inputs[a];return a&&null!==a.link?(a=this.graph.links[a.link])?this.graph.getNodeById(a.origin_id):
null:null};s.prototype.getInputOrProperty=function(a){if(!this.inputs||!this.inputs.length)return this.properties?this.properties[a]:null;for(var b=0,d=this.inputs.length;b<d;++b){var f=this.inputs[b];if(a==f.name&&null!=f.link&&(f=this.graph.links[f.link]))return f.data}return this.properties[a]};s.prototype.getOutputData=function(a){return!this.outputs||a>=this.outputs.length?null:this.outputs[a]._data};s.prototype.getOutputInfo=function(a){return this.outputs?a<this.outputs.length?this.outputs[a]:
null:null};s.prototype.isOutputConnected=function(a){return this.outputs?a<this.outputs.length&&this.outputs[a].links&&this.outputs[a].links.length:!1};s.prototype.isAnyOutputConnected=function(){if(!this.outputs)return!1;for(var a=0;a<this.outputs.length;++a)if(this.outputs[a].links&&this.outputs[a].links.length)return!0;return!1};s.prototype.getOutputNodes=function(a){if(!this.outputs||0==this.outputs.length||a>=this.outputs.length)return null;a=this.outputs[a];if(!a.links||0==a.links.length)return null;
for(var b=[],d=0;d<a.links.length;d++){var f=this.graph.links[a.links[d]];f&&(f=this.graph.getNodeById(f.target_id))&&b.push(f)}return b};s.prototype.trigger=function(a,b){if(this.outputs&&this.outputs.length){this.graph&&(this.graph._last_trigger_time=e.getTime());for(var d=0;d<this.outputs.length;++d){var f=this.outputs[d];!f||f.type!==e.EVENT||a&&f.name!=a||this.triggerSlot(d,b)}}};s.prototype.triggerSlot=function(a,b,d){if(this.outputs&&(a=this.outputs[a])&&(a=a.links)&&a.length){this.graph&&
(this.graph._last_trigger_time=e.getTime());for(var f=0;f<a.length;++f){var g=a[f];if(null==d||d==g){var t=this.graph.links[a[f]];if(t&&(t._last_time=e.getTime(),g=this.graph.getNodeById(t.target_id)))if(t=g.inputs[t.target_slot],g.mode===e.ON_TRIGGER){if(g.onExecute)g.onExecute(b)}else if(g.onAction)g.onAction(t.name,b)}}}};s.prototype.clearTriggeredSlot=function(a,b){if(this.outputs){var d=this.outputs[a];if(d&&(d=d.links)&&d.length)for(var f=0;f<d.length;++f){var g=d[f];if(null==b||b==g)if(g=this.graph.links[d[f]])g._last_time=
0}}};s.prototype.setSize=function(a){this.size=a;if(this.onResize)this.onResize(this.size)};s.prototype.addProperty=function(a,b,d,f){d={name:a,type:d,default_value:b};if(f)for(var g in f)d[g]=f[g];this.properties_info||(this.properties_info=[]);this.properties_info.push(d);this.properties||(this.properties={});this.properties[a]=b;return d};s.prototype.addOutput=function(a,b,d){a={name:a,type:b,links:null};if(d)for(var f in d)a[f]=d[f];this.outputs||(this.outputs=[]);this.outputs.push(a);if(this.onOutputAdded)this.onOutputAdded(a);
this.setSize(this.computeSize());this.setDirtyCanvas(!0,!0);return a};s.prototype.addOutputs=function(a){for(var b=0;b<a.length;++b){var d=a[b],f={name:d[0],type:d[1],link:null};if(a[2])for(var g in d[2])f[g]=d[2][g];this.outputs||(this.outputs=[]);this.outputs.push(f);if(this.onOutputAdded)this.onOutputAdded(f)}this.setSize(this.computeSize());this.setDirtyCanvas(!0,!0)};s.prototype.removeOutput=function(a){this.disconnectOutput(a);this.outputs.splice(a,1);for(var b=a;b<this.outputs.length;++b)if(this.outputs[b]&&
this.outputs[b].links)for(var d=this.outputs[b].links,f=0;f<d.length;++f){var g=this.graph.links[d[f]];g&&(g.origin_slot-=1)}this.setSize(this.computeSize());if(this.onOutputRemoved)this.onOutputRemoved(a);this.setDirtyCanvas(!0,!0)};s.prototype.addInput=function(a,b,d){a={name:a,type:b||0,link:null};if(d)for(var f in d)a[f]=d[f];this.inputs||(this.inputs=[]);this.inputs.push(a);this.setSize(this.computeSize());if(this.onInputAdded)this.onInputAdded(a);this.setDirtyCanvas(!0,!0);return a};s.prototype.addInputs=
function(a){for(var b=0;b<a.length;++b){var d=a[b],f={name:d[0],type:d[1],link:null};if(a[2])for(var g in d[2])f[g]=d[2][g];this.inputs||(this.inputs=[]);this.inputs.push(f);if(this.onInputAdded)this.onInputAdded(f)}this.setSize(this.computeSize());this.setDirtyCanvas(!0,!0)};s.prototype.removeInput=function(a){this.disconnectInput(a);for(var b=this.inputs.splice(a,1),d=a;d<this.inputs.length;++d)if(this.inputs[d]){var f=this.graph.links[this.inputs[d].link];f&&(f.target_slot-=1)}this.setSize(this.computeSize());
if(this.onInputRemoved)this.onInputRemoved(a,b[0]);this.setDirtyCanvas(!0,!0)};s.prototype.addConnection=function(a,b,d,f){a={name:a,type:b,pos:d,direction:f,links:null};this.connections.push(a);return a};s.prototype.computeSize=function(a){function b(a){return a?f*a.length*0.6:0}if(this.constructor.size)return this.constructor.size.concat();var d=Math.max(this.inputs?this.inputs.length:1,this.outputs?this.outputs.length:1);a=a||new Float32Array([0,0]);var d=Math.max(d,1),f=e.NODE_TEXT_SIZE,g=b(this.title),
t=0,x=0;if(this.inputs)for(var c=0,k=this.inputs.length;c<k;++c){var h=this.inputs[c],h=h.label||h.name||"",h=b(h);t<h&&(t=h)}if(this.outputs)for(c=0,k=this.outputs.length;c<k;++c)h=this.outputs[c],h=h.label||h.name||"",h=b(h),x<h&&(x=h);a[0]=Math.max(t+x+10,g);a[0]=Math.max(a[0],e.NODE_WIDTH);this.widgets&&this.widgets.length&&(a[0]=Math.max(a[0],1.5*e.NODE_WIDTH));a[1]=(this.constructor.slot_start_y||0)+d*e.NODE_SLOT_HEIGHT;d=0;if(this.widgets&&this.widgets.length){c=0;for(k=this.widgets.length;c<
k;++c)d=this.widgets[c].computeSize?d+(this.widgets[c].computeSize(a[0])[1]+4):d+(e.NODE_WIDGET_HEIGHT+4);d+=8}a[1]=this.widgets_up?Math.max(a[1],d):null!=this.widgets_start_y?Math.max(a[1],d+this.widgets_start_y):a[1]+d;this.constructor.min_height&&a[1]<this.constructor.min_height&&(a[1]=this.constructor.min_height);a[1]+=6;return a};s.prototype.getPropertyInfo=function(a){var b=null;if(this.properties_info)for(var d=0;d<this.properties_info.length;++d)if(this.properties_info[d].name==a){b=this.properties_info[d];
break}this.constructor["@"+a]&&(b=this.constructor["@"+a]);this.constructor.widgets_info&&this.constructor.widgets_info[a]&&(b=this.constructor.widgets_info[a]);!b&&this.onGetPropertyInfo&&(b=this.onGetPropertyInfo(a));b||(b={});b.type||(b.type=typeof this.properties[a]);"combo"==b.widget&&(b.type="enum");return b};s.prototype.addWidget=function(a,b,d,f,g){this.widgets||(this.widgets=[]);!g&&f&&f.constructor===Object&&(g=f,f=null);g&&g.constructor===String&&(g={property:g});f&&f.constructor===String&&
(g||(g={}),g.property=f,f=null);f&&f.constructor!==Function&&(console.warn("addWidget: callback must be a function"),f=null);b={type:a.toLowerCase(),name:b,value:d,callback:f,options:g||{}};void 0!==b.options.y&&(b.y=b.options.y);f||b.options.callback||b.options.property||console.warn("LiteGraph addWidget(...) without a callback or property assigned");if("combo"==a&&!b.options.values)throw"LiteGraph addWidget('combo',...) requires to pass values in options: { values:['red','blue'] }";this.widgets.push(b);
this.setSize(this.computeSize());return b};s.prototype.addCustomWidget=function(a){this.widgets||(this.widgets=[]);this.widgets.push(a);return a};s.prototype.getBounding=function(a){a=a||new Float32Array(4);a[0]=this.pos[0]-4;a[1]=this.pos[1]-e.NODE_TITLE_HEIGHT;a[2]=this.size[0]+4;a[3]=this.size[1]+e.NODE_TITLE_HEIGHT;if(this.onBounding)this.onBounding(a);return a};s.prototype.isPointInside=function(a,b,d,f){d=d||0;var g=this.graph&&this.graph.isLive()?0:e.NODE_TITLE_HEIGHT;f&&(g=0);if(this.flags&&
this.flags.collapsed){if(v(a,b,this.pos[0]-d,this.pos[1]-e.NODE_TITLE_HEIGHT-d,(this._collapsed_width||e.NODE_COLLAPSED_WIDTH)+2*d,e.NODE_TITLE_HEIGHT+2*d))return!0}else if(this.pos[0]-4-d<a&&this.pos[0]+this.size[0]+4+d>a&&this.pos[1]-g-d<b&&this.pos[1]+this.size[1]+d>b)return!0;return!1};s.prototype.getSlotInPosition=function(a,b){var d=new Float32Array(2);if(this.inputs)for(var f=0,g=this.inputs.length;f<g;++f){var t=this.inputs[f];this.getConnectionPos(!0,f,d);if(v(a,b,d[0]-10,d[1]-5,20,10))return{input:t,
slot:f,link_pos:d}}if(this.outputs)for(f=0,g=this.outputs.length;f<g;++f)if(t=this.outputs[f],this.getConnectionPos(!1,f,d),v(a,b,d[0]-10,d[1]-5,20,10))return{output:t,slot:f,link_pos:d};return null};s.prototype.findInputSlot=function(a){if(!this.inputs)return-1;for(var b=0,d=this.inputs.length;b<d;++b)if(a==this.inputs[b].name)return b;return-1};s.prototype.findOutputSlot=function(a){if(!this.outputs)return-1;for(var b=0,d=this.outputs.length;b<d;++b)if(a==this.outputs[b].name)return b;return-1};
s.prototype.connect=function(a,b,d){d=d||0;if(!this.graph)return console.log("Connect: Error, node doesn't belong to any graph. Nodes must be added first to a graph before connecting them."),null;if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return e.debug&&console.log("Connect: Error, no slot of name "+a),null}else if(!this.outputs||a>=this.outputs.length)return e.debug&&console.log("Connect: Error, slot number not found"),null;b&&b.constructor===Number&&(b=this.graph.getNodeById(b));
if(!b)throw"target node is null";if(b==this)return null;if(d.constructor===String){if(d=b.findInputSlot(d),-1==d)return e.debug&&console.log("Connect: Error, no slot of name "+d),null}else{if(d===e.EVENT)return null;if(!b.inputs||d>=b.inputs.length)return e.debug&&console.log("Connect: Error, slot number not found"),null}var f=!1;null!=b.inputs[d].link&&(this.graph.beforeChange(),b.disconnectInput(d),f=!0);var g=this.outputs[a];if(b.onConnectInput&&!1===b.onConnectInput(d,g.type,g,this,a))return null;
var t=b.inputs[d],x=null;if(!e.isValidConnection(g.type,t.type))return this.setDirtyCanvas(!1,!0),f&&this.graph.connectionChange(this,x),null;f||this.graph.beforeChange();x=new m(++this.graph.last_link_id,t.type,this.id,a,b.id,d);this.graph.links[x.id]=x;null==g.links&&(g.links=[]);g.links.push(x.id);b.inputs[d].link=x.id;this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(e.OUTPUT,a,!0,x,g);if(b.onConnectionsChange)b.onConnectionsChange(e.INPUT,d,!0,x,t);this.graph&&
this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(e.INPUT,b,d,this,a),this.graph.onNodeConnectionChange(e.OUTPUT,this,a,b,d));this.setDirtyCanvas(!1,!0);this.graph.afterChange();this.graph.connectionChange(this,x);return x};s.prototype.disconnectOutput=function(a,b){if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return e.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.outputs||a>=this.outputs.length)return e.debug&&console.log("Connect: Error, slot number not found"),
!1;var d=this.outputs[a];if(!d||!d.links||0==d.links.length)return!1;if(b){b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"Target Node not found";for(var f=0,g=d.links.length;f<g;f++){var t=d.links[f],x=this.graph.links[t];if(x.target_id==b.id){d.links.splice(f,1);var c=b.inputs[x.target_slot];c.link=null;delete this.graph.links[t];this.graph&&this.graph._version++;if(b.onConnectionsChange)b.onConnectionsChange(e.INPUT,x.target_slot,!1,x,c);if(this.onConnectionsChange)this.onConnectionsChange(e.OUTPUT,
a,!1,x,d);if(this.graph&&this.graph.onNodeConnectionChange)this.graph.onNodeConnectionChange(e.OUTPUT,this,a);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(e.OUTPUT,this,a),this.graph.onNodeConnectionChange(e.INPUT,b,x.target_slot));break}}}else{f=0;for(g=d.links.length;f<g;f++)if(t=d.links[f],x=this.graph.links[t]){b=this.graph.getNodeById(x.target_id);this.graph&&this.graph._version++;if(b){c=b.inputs[x.target_slot];c.link=null;if(b.onConnectionsChange)b.onConnectionsChange(e.INPUT,
x.target_slot,!1,x,c);if(this.graph&&this.graph.onNodeConnectionChange)this.graph.onNodeConnectionChange(e.INPUT,b,x.target_slot)}delete this.graph.links[t];if(this.onConnectionsChange)this.onConnectionsChange(e.OUTPUT,a,!1,x,d);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(e.OUTPUT,this,a),this.graph.onNodeConnectionChange(e.INPUT,b,x.target_slot))}d.links=null}this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this);return!0};s.prototype.disconnectInput=function(a){if(a.constructor===
String){if(a=this.findInputSlot(a),-1==a)return e.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.inputs||a>=this.inputs.length)return e.debug&&console.log("Connect: Error, slot number not found"),!1;var b=this.inputs[a];if(!b)return!1;var d=this.inputs[a].link;if(null!=d){this.inputs[a].link=null;var f=this.graph.links[d];if(f){var g=this.graph.getNodeById(f.origin_id);if(!g)return!1;var t=g.outputs[f.origin_slot];if(!t||!t.links||0==t.links.length)return!1;for(var x=0,
c=t.links.length;x<c;x++)if(t.links[x]==d){t.links.splice(x,1);break}delete this.graph.links[d];this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(e.INPUT,a,!1,f,b);if(g.onConnectionsChange)g.onConnectionsChange(e.OUTPUT,x,!1,f,t);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(e.OUTPUT,g,x),this.graph.onNodeConnectionChange(e.INPUT,this,a))}}this.setDirtyCanvas(!1,!0);this.graph&&this.graph.connectionChange(this);return!0};s.prototype.getConnectionPos=
function(a,b,d){d=d||new Float32Array(2);var f=0;a&&this.inputs&&(f=this.inputs.length);!a&&this.outputs&&(f=this.outputs.length);var g=0.5*e.NODE_SLOT_HEIGHT;if(this.flags.collapsed)return b=this._collapsed_width||e.NODE_COLLAPSED_WIDTH,this.horizontal?(d[0]=this.pos[0]+0.5*b,d[1]=a?this.pos[1]-e.NODE_TITLE_HEIGHT:this.pos[1]):(d[0]=a?this.pos[0]:this.pos[0]+b,d[1]=this.pos[1]-0.5*e.NODE_TITLE_HEIGHT),d;if(a&&-1==b)return d[0]=this.pos[0]+0.5*e.NODE_TITLE_HEIGHT,d[1]=this.pos[1]+0.5*e.NODE_TITLE_HEIGHT,
d;if(a&&f>b&&this.inputs[b].pos)return d[0]=this.pos[0]+this.inputs[b].pos[0],d[1]=this.pos[1]+this.inputs[b].pos[1],d;if(!a&&f>b&&this.outputs[b].pos)return d[0]=this.pos[0]+this.outputs[b].pos[0],d[1]=this.pos[1]+this.outputs[b].pos[1],d;if(this.horizontal)return d[0]=this.pos[0]+this.size[0]/f*(b+0.5),d[1]=a?this.pos[1]-e.NODE_TITLE_HEIGHT:this.pos[1]+this.size[1],d;d[0]=a?this.pos[0]+g:this.pos[0]+this.size[0]+1-g;d[1]=this.pos[1]+(b+0.7)*e.NODE_SLOT_HEIGHT+(this.constructor.slot_start_y||0);
return d};s.prototype.alignToGrid=function(){this.pos[0]=e.CANVAS_GRID_SIZE*Math.round(this.pos[0]/e.CANVAS_GRID_SIZE);this.pos[1]=e.CANVAS_GRID_SIZE*Math.round(this.pos[1]/e.CANVAS_GRID_SIZE)};s.prototype.trace=function(a){this.console||(this.console=[]);this.console.push(a);this.console.length>s.MAX_CONSOLE&&this.console.shift();if(this.graph.onNodeTrace)this.graph.onNodeTrace(this,a)};s.prototype.setDirtyCanvas=function(a,b){this.graph&&this.graph.sendActionToCanvas("setDirty",[a,b])};s.prototype.loadImage=
function(a){var b=new Image;b.src=e.node_images_path+a;b.ready=!1;var d=this;b.onload=function(){this.ready=!0;d.setDirtyCanvas(!0)};return b};s.prototype.captureInput=function(a){if(this.graph&&this.graph.list_of_graphcanvas)for(var b=this.graph.list_of_graphcanvas,d=0;d<b.length;++d){var f=b[d];if(a||f.node_capturing_input==this)f.node_capturing_input=a?this:null}};s.prototype.collapse=function(a){this.graph._version++;if(!1!==this.constructor.collapsable||a)this.flags.collapsed=this.flags.collapsed?
!1:!0,this.setDirtyCanvas(!0,!0)};s.prototype.pin=function(a){this.graph._version++;this.flags.pinned=void 0===a?!this.flags.pinned:a};s.prototype.localToScreen=function(a,b,d){return[(a+this.pos[0])*d.scale+d.offset[0],(b+this.pos[1])*d.scale+d.offset[1]]};A.LGraphGroup=e.LGraphGroup=l;l.prototype._ctor=function(a){this.title=a||"Group";this.font_size=24;this.color=h.node_colors.pale_blue?h.node_colors.pale_blue.groupcolor:"#AAA";this._bounding=new Float32Array([10,10,140,80]);this._pos=this._bounding.subarray(0,
2);this._size=this._bounding.subarray(2,4);this._nodes=[];this.graph=null;Object.defineProperty(this,"pos",{set:function(a){!a||2>a.length||(this._pos[0]=a[0],this._pos[1]=a[1])},get:function(){return this._pos},enumerable:!0});Object.defineProperty(this,"size",{set:function(a){!a||2>a.length||(this._size[0]=Math.max(140,a[0]),this._size[1]=Math.max(80,a[1]))},get:function(){return this._size},enumerable:!0})};l.prototype.configure=function(a){this.title=a.title;this._bounding.set(a.bounding);this.color=
a.color;this.font=a.font};l.prototype.serialize=function(){var a=this._bounding;return{title:this.title,bounding:[Math.round(a[0]),Math.round(a[1]),Math.round(a[2]),Math.round(a[3])],color:this.color,font:this.font}};l.prototype.move=function(a,b,d){this._pos[0]+=a;this._pos[1]+=b;if(!d)for(d=0;d<this._nodes.length;++d){var f=this._nodes[d];f.pos[0]+=a;f.pos[1]+=b}};l.prototype.recomputeInsideNodes=function(){this._nodes.length=0;for(var a=this.graph._nodes,b=new Float32Array(4),d=0;d<a.length;++d){var f=
a[d];f.getBounding(b);E(this._bounding,b)&&this._nodes.push(f)}};l.prototype.isPointInside=s.prototype.isPointInside;l.prototype.setDirtyCanvas=s.prototype.setDirtyCanvas;e.DragAndScale=w;w.prototype.bindEvents=function(a){this.last_mouse=new Float32Array(2);this._binded_mouse_callback=this.onMouse.bind(this);a.addEventListener("mousedown",this._binded_mouse_callback);a.addEventListener("mousemove",this._binded_mouse_callback);a.addEventListener("mousewheel",this._binded_mouse_callback,!1);a.addEventListener("wheel",
this._binded_mouse_callback,!1)};w.prototype.computeVisibleArea=function(){if(this.element){var a=-this.offset[0],b=-this.offset[1],d=a+this.element.width/this.scale,f=b+this.element.height/this.scale;this.visible_area[0]=a;this.visible_area[1]=b;this.visible_area[2]=d-a;this.visible_area[3]=f-b}else this.visible_area[0]=this.visible_area[1]=this.visible_area[2]=this.visible_area[3]=0};w.prototype.onMouse=function(a){if(this.enabled){var b=this.element,d=b.getBoundingClientRect(),f=a.clientX-d.left,
d=a.clientY-d.top;a.canvasx=f;a.canvasy=d;a.dragging=this.dragging;var g=!1;this.onmouse&&(g=this.onmouse(a));if("mousedown"==a.type)this.dragging=!0,b.removeEventListener("mousemove",this._binded_mouse_callback),document.body.addEventListener("mousemove",this._binded_mouse_callback),document.body.addEventListener("mouseup",this._binded_mouse_callback);else if("mousemove"==a.type)g||(b=f-this.last_mouse[0],g=d-this.last_mouse[1],this.dragging&&this.mouseDrag(b,g));else if("mouseup"==a.type)this.dragging=
!1,document.body.removeEventListener("mousemove",this._binded_mouse_callback),document.body.removeEventListener("mouseup",this._binded_mouse_callback),b.addEventListener("mousemove",this._binded_mouse_callback);else if("mousewheel"==a.type||"wheel"==a.type||"DOMMouseScroll"==a.type)a.eventType="mousewheel",a.wheel="wheel"==a.type?-a.deltaY:null!=a.wheelDeltaY?a.wheelDeltaY:-60*a.detail,a.delta=a.wheelDelta?a.wheelDelta/40:a.deltaY?-a.deltaY/3:0,this.changeDeltaScale(1+0.05*a.delta);this.last_mouse[0]=
f;this.last_mouse[1]=d;a.preventDefault();a.stopPropagation();return!1}};w.prototype.toCanvasContext=function(a){a.scale(this.scale,this.scale);a.translate(this.offset[0],this.offset[1])};w.prototype.convertOffsetToCanvas=function(a){return[(a[0]+this.offset[0])*this.scale,(a[1]+this.offset[1])*this.scale]};w.prototype.convertCanvasToOffset=function(a,b){b=b||[0,0];b[0]=a[0]/this.scale-this.offset[0];b[1]=a[1]/this.scale-this.offset[1];return b};w.prototype.mouseDrag=function(a,b){this.offset[0]+=
a/this.scale;this.offset[1]+=b/this.scale;if(this.onredraw)this.onredraw(this)};w.prototype.changeScale=function(a,b){a<this.min_scale?a=this.min_scale:a>this.max_scale&&(a=this.max_scale);if(a!=this.scale&&this.element){var d=this.element.getBoundingClientRect();if(d){b=b||[0.5*d.width,0.5*d.height];d=this.convertCanvasToOffset(b);this.scale=a;0.01>Math.abs(this.scale-1)&&(this.scale=1);var f=this.convertCanvasToOffset(b),d=[f[0]-d[0],f[1]-d[1]];this.offset[0]+=d[0];this.offset[1]+=d[1];if(this.onredraw)this.onredraw(this)}}};
w.prototype.changeDeltaScale=function(a,b){this.changeScale(this.scale*a,b)};w.prototype.reset=function(){this.scale=1;this.offset[0]=0;this.offset[1]=0};A.LGraphCanvas=e.LGraphCanvas=h;h.DEFAULT_BACKGROUND_IMAGE="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQBJREFUeNrs1rEKwjAUhlETUkj3vP9rdmr1Ysammk2w5wdxuLgcMHyptfawuZX4pJSWZTnfnu/lnIe/jNNxHHGNn//HNbbv+4dr6V+11uF527arU7+u63qfa/bnmh8sWLBgwYJlqRf8MEptXPBXJXa37BSl3ixYsGDBMliwFLyCV/DeLIMFCxYsWLBMwSt4Be/NggXLYMGCBUvBK3iNruC9WbBgwYJlsGApeAWv4L1ZBgsWLFiwYJmCV/AK3psFC5bBggULloJX8BpdwXuzYMGCBctgwVLwCl7Be7MMFixYsGDBsu8FH1FaSmExVfAxBa/gvVmwYMGCZbBg/W4vAQYA5tRF9QYlv/QAAAAASUVORK5CYII=";
h.link_type_colors={"-1":e.EVENT_LINK_COLOR,number:"#AAA",node:"#DCA"};h.gradients={};h.prototype.clear=function(){this.fps=this.render_time=this.last_draw_time=this.frame=0;this.dragging_rectangle=null;this.selected_nodes={};this.selected_group=null;this.visible_nodes=[];this.connecting_node=this.node_capturing_input=this.node_over=this.node_dragged=null;this.highlighted_links={};this.dragging_canvas=!1;this.dirty_bgcanvas=this.dirty_canvas=!0;this.node_widget=this.node_in_panel=this.dirty_area=
null;this.last_mouse=[0,0];this.last_mouseclick=0;this.visible_area.set([0,0,0,0]);if(this.onClear)this.onClear()};h.prototype.setGraph=function(a,b){this.graph!=a&&(b||this.clear(),!a&&this.graph?this.graph.detachCanvas(this):(a.attachCanvas(this),this._graph_stack&&(this._graph_stack=null),this.setDirty(!0,!0)))};h.prototype.getTopGraph=function(){return this._graph_stack.length?this._graph_stack[0]:this.graph};h.prototype.openSubgraph=function(a){if(!a)throw"graph cannot be null";if(this.graph==
a)throw"graph cannot be the same";this.clear();this.graph&&(this._graph_stack||(this._graph_stack=[]),this._graph_stack.push(this.graph));a.attachCanvas(this);this.checkPanels();this.setDirty(!0,!0)};h.prototype.closeSubgraph=function(){if(this._graph_stack&&0!=this._graph_stack.length){var a=this.graph._subgraph_node,b=this._graph_stack.pop();this.selected_nodes={};this.highlighted_links={};b.attachCanvas(this);this.setDirty(!0,!0);a&&(this.centerOnNode(a),this.selectNodes([a]))}};h.prototype.getCurrentGraph=
@@ -246,10 +247,10 @@ g.constructor===e.LGraphGroup?g.color=a.groupcolor:(g.color=a.color,g.bgcolor=a.
(a=g.graph,a.beforeChange(),a.remove(g),a.afterChange(),g.setDirtyCanvas(!0,!0))};h.onMenuNodeToSubgraph=function(a,b,d,f,g){a=g.graph;if(b=h.active_canvas)d=Object.values(b.selected_nodes||{}),d.length||(d=[g]),f=e.createNode("graph/subgraph"),f.pos=g.pos.concat(),a.add(f),f.buildFromNodes(d),b.deselectAllNodes(),g.setDirtyCanvas(!0,!0)};h.onMenuNodeClone=function(a,b,d,f,g){!1!=g.clonable&&(a=g.clone())&&(a.pos=[g.pos[0]+5,g.pos[1]+5],g.graph.beforeChange(),g.graph.add(a),g.graph.afterChange(),
g.setDirtyCanvas(!0,!0))};h.node_colors={red:{color:"#322",bgcolor:"#533",groupcolor:"#A88"},brown:{color:"#332922",bgcolor:"#593930",groupcolor:"#b06634"},green:{color:"#232",bgcolor:"#353",groupcolor:"#8A8"},blue:{color:"#223",bgcolor:"#335",groupcolor:"#88A"},pale_blue:{color:"#2a363b",bgcolor:"#3f5159",groupcolor:"#3f789e"},cyan:{color:"#233",bgcolor:"#355",groupcolor:"#8AA"},purple:{color:"#323",bgcolor:"#535",groupcolor:"#a1309b"},yellow:{color:"#432",bgcolor:"#653",groupcolor:"#b58b2a"},black:{color:"#222",
bgcolor:"#000",groupcolor:"#444"}};h.prototype.getCanvasMenuOptions=function(){var a=null;this.getMenuOptions?a=this.getMenuOptions():(a=[{content:"Add Node",has_submenu:!0,callback:h.onMenuAdd},{content:"Add Group",callback:h.onGroupAdd}],this._graph_stack&&0<this._graph_stack.length&&a.push(null,{content:"Close subgraph",callback:this.closeSubgraph.bind(this)}));if(this.getExtraMenuOptions){var b=this.getExtraMenuOptions(this,a);b&&(a=a.concat(b))}return a};h.prototype.getNodeMenuOptions=function(a){var b=
null,b=a.getMenuOptions?a.getMenuOptions(this):[{content:"Inputs",has_submenu:!0,disabled:!0,callback:h.showMenuNodeOptionalInputs},{content:"Outputs",has_submenu:!0,disabled:!0,callback:h.showMenuNodeOptionalOutputs},null,{content:"Properties",has_submenu:!0,callback:h.onShowMenuNodeProperties},null,{content:"Title",callback:h.onShowPropertyEditor},{content:"Mode",has_submenu:!0,callback:h.onMenuNodeMode},{content:"Resize",callback:h.onResizeNode},{content:"Collapse",callback:h.onMenuNodeCollapse},
{content:"Pin",callback:h.onMenuNodePin},{content:"Colors",has_submenu:!0,callback:h.onMenuNodeColors},{content:"Shapes",has_submenu:!0,callback:h.onMenuNodeShapes},null];if(a.onGetInputs){var d=a.onGetInputs();d&&d.length&&(b[0].disabled=!1)}a.onGetOutputs&&(d=a.onGetOutputs())&&d.length&&(b[1].disabled=!1);a.getExtraMenuOptions&&(d=a.getExtraMenuOptions(this,b))&&(d.push(null),b=d.concat(b));!1!==a.clonable&&b.push({content:"Clone",callback:h.onMenuNodeClone});b.push(null,{content:"Remove",disabled:!(!1!==
a.removable&&!a.block_delete),callback:h.onMenuNodeRemove});if(a.graph&&a.graph.onGetNodeMenuOptions)a.graph.onGetNodeMenuOptions(b,a);return b};h.prototype.getGroupMenuOptions=function(a){return[{content:"Title",callback:h.onShowPropertyEditor},{content:"Color",has_submenu:!0,callback:h.onMenuNodeColors},{content:"Font size",property:"font_size",type:"Number",callback:h.onShowPropertyEditor},null,{content:"Remove",callback:h.onMenuNodeRemove}]};h.prototype.processContextMenu=function(a,b){var d=
this,f=h.active_canvas.getCanvasWindow(),g=null,c={event:b,callback:function(b,g,f){if(b)if("Remove Slot"==b.content)b=b.slot,b.input?a.removeInput(b.slot):b.output&&a.removeOutput(b.slot);else if("Disconnect Links"==b.content)b=b.slot,b.output?a.disconnectOutput(b.slot):b.input&&a.disconnectInput(b.slot);else if("Rename Slot"==b.content){b=b.slot;var c=b.input?a.getInputInfo(b.slot):a.getOutputInfo(b.slot),e=d.createDialog("<span class='name'>Name</span><input autofocus type='text'/><button>OK</button>",
null,b=a.getMenuOptions?a.getMenuOptions(this):[{content:"Inputs",has_submenu:!0,disabled:!0,callback:h.showMenuNodeOptionalInputs},{content:"Outputs",has_submenu:!0,disabled:!0,callback:h.showMenuNodeOptionalOutputs},null,{content:"Properties",has_submenu:!0,callback:h.onShowMenuNodeProperties},null,{content:"Title",callback:h.onShowPropertyEditor},{content:"Mode",has_submenu:!0,callback:h.onMenuNodeMode},{content:"Resize",callback:function(){if(a.resizable)return h.onResizeNode}},{content:"Collapse",
callback:h.onMenuNodeCollapse},{content:"Pin",callback:h.onMenuNodePin},{content:"Colors",has_submenu:!0,callback:h.onMenuNodeColors},{content:"Shapes",has_submenu:!0,callback:h.onMenuNodeShapes},null];if(a.onGetInputs){var d=a.onGetInputs();d&&d.length&&(b[0].disabled=!1)}a.onGetOutputs&&(d=a.onGetOutputs())&&d.length&&(b[1].disabled=!1);a.getExtraMenuOptions&&(d=a.getExtraMenuOptions(this,b))&&(d.push(null),b=d.concat(b));!1!==a.clonable&&b.push({content:"Clone",callback:h.onMenuNodeClone});b.push(null,
{content:"Remove",disabled:!(!1!==a.removable&&!a.block_delete),callback:h.onMenuNodeRemove});if(a.graph&&a.graph.onGetNodeMenuOptions)a.graph.onGetNodeMenuOptions(b,a);return b};h.prototype.getGroupMenuOptions=function(a){return[{content:"Title",callback:h.onShowPropertyEditor},{content:"Color",has_submenu:!0,callback:h.onMenuNodeColors},{content:"Font size",property:"font_size",type:"Number",callback:h.onShowPropertyEditor},null,{content:"Remove",callback:h.onMenuNodeRemove}]};h.prototype.processContextMenu=
function(a,b){var d=this,f=h.active_canvas.getCanvasWindow(),g=null,c={event:b,callback:function(b,g,f){if(b)if("Remove Slot"==b.content)b=b.slot,b.input?a.removeInput(b.slot):b.output&&a.removeOutput(b.slot);else if("Disconnect Links"==b.content)b=b.slot,b.output?a.disconnectOutput(b.slot):b.input&&a.disconnectInput(b.slot);else if("Rename Slot"==b.content){b=b.slot;var c=b.input?a.getInputInfo(b.slot):a.getOutputInfo(b.slot),e=d.createDialog("<span class='name'>Name</span><input autofocus type='text'/><button>OK</button>",
g),k=e.querySelector("input");k&&c&&(k.value=c.label||"");e.querySelector("button").addEventListener("click",function(a){k.value&&(c&&(c.label=k.value),d.setDirty(!0));e.close()})}},extra:a};a&&(c.title=a.type);var k=null;a&&(k=a.getSlotInPosition(b.canvasX,b.canvasY),h.active_node=a);if(k){g=[];if(a.getSlotMenuOptions)g=a.getSlotMenuOptions(k);else{k&&k.output&&k.output.links&&k.output.links.length&&g.push({content:"Disconnect Links",slot:k});var n=k.input||k.output;g.push(n.locked?"Cannot remove":
{content:"Remove Slot",slot:k});g.push(n.nameLocked?"Cannot rename":{content:"Rename Slot",slot:k})}c.title=(k.input?k.input.type:k.output.type)||"*";k.input&&k.input.type==e.ACTION&&(c.title="Action");k.output&&k.output.type==e.EVENT&&(c.title="Event")}else a?g=this.getNodeMenuOptions(a):(g=this.getCanvasMenuOptions(),(k=this.graph.getGroupOnPos(b.canvasX,b.canvasY))&&g.push(null,{content:"Edit Group",has_submenu:!0,submenu:{title:"Group",extra:k,options:this.getGroupMenuOptions(k)}}));g&&new e.ContextMenu(g,
c,f)};"undefined"!=typeof window&&window.CanvasRenderingContext2D&&(window.CanvasRenderingContext2D.prototype.roundRect=function(a,b,d,f,g,c){void 0===g&&(g=5);void 0===c&&(c=g);this.moveTo(a+g,b);this.lineTo(a+d-g,b);this.quadraticCurveTo(a+d,b,a+d,b+g);this.lineTo(a+d,b+f-c);this.quadraticCurveTo(a+d,b+f,a+d-c,b+f);this.lineTo(a+c,b+f);this.quadraticCurveTo(a,b+f,a,b+f-c);this.lineTo(a,b+g);this.quadraticCurveTo(a,b,a+g,b)});e.compareObjects=function(a,b){for(var d in a)if(a[d]!=b[d])return!1;return!0};
@@ -800,7 +801,7 @@ e);q.prototype.onExecute=function(){this._last_buffer=this.getInputData(0);var c
void 0!==a&&(c=a);a=n.getAudioContext().sampleRate/this._freqs.length;a=c/a*2;a>=this._freqs.length?a=this._freqs[this._freqs.length-1]:(c=a|0,a-=c,a=this._freqs[c]*(1-a)+this._freqs[c+1]*a);this.setOutputData(0,a/255*this.properties.amplitude)}};D.prototype.onGetInputs=function(){return[["band","number"]]};D.title="Signal";D.desc="extract the signal of some frequency";r.registerNodeType("audio/signal",D);u.prototype.onAdded=function(c){c.status==LGraph.STATUS_RUNNING&&(this.audionode.onaudioprocess=
this._callback)};u["@code"]={widget:"code",type:"code"};u.prototype.onStart=function(){this.audionode.onaudioprocess=this._callback};u.prototype.onStop=function(){this.audionode.onaudioprocess=u._bypass_function};u.prototype.onPause=function(){this.audionode.onaudioprocess=u._bypass_function};u.prototype.onUnpause=function(){this.audionode.onaudioprocess=this._callback};u.prototype.onExecute=function(){};u.prototype.onRemoved=function(){this.audionode.onaudioprocess=u._bypass_function};u.prototype.processCode=
function(){try{this._script=new new Function("properties",this.properties.code)(this.properties),this._old_code=this.properties.code,this._callback=this._script.onaudioprocess}catch(c){console.error("Error in onaudioprocess code",c),this._callback=u._bypass_function,this.audionode.onaudioprocess=this._callback}};u.prototype.onPropertyChanged=function(c,a){"code"==c&&(this.properties.code=a,this.processCode(),this.graph&&this.graph.status==LGraph.STATUS_RUNNING&&(this.audionode.onaudioprocess=this._callback))};
u.default_function=function(){this.onaudioprocess=function(c){var a=c.inputBuffer;c=c.outputBuffer;for(var b=0;b<c.numberOfChannels;b++)for(var d=a.getChannelData(b),e=c.getChannelData(b),g=0;g<a.length;g++)e[g]=d[g]}};n.createAudioNodeWrapper(u);u.title="Script";u.desc="apply script to signal";r.registerNodeType("audio/script",u);I.title="Destination";I.desc="Audio output";r.registerNodeType("audio/destination",I)})(this);
u.default_function=function(){this.onaudioprocess=function(c){var a=c.inputBuffer;c=c.outputBuffer;for(var b=0;b<c.numberOfChannels;b++)for(var d=a.getChannelData(b),f=c.getChannelData(b),e=0;e<a.length;e++)f[e]=d[e]}};n.createAudioNodeWrapper(u);u.title="Script";u.desc="apply script to signal";r.registerNodeType("audio/script",u);I.title="Destination";I.desc="Audio output";r.registerNodeType("audio/destination",I)})(this);
(function(A){function c(){this.size=[60,20];this.addInput("send",s.ACTION);this.addOutput("received",s.EVENT);this.addInput("in",0);this.addOutput("out",0);this.properties={url:"",room:"lgraph",only_send_changes:!0};this._ws=null;this._last_sent_data=[];this._last_received_data=[]}function m(){this.room_widget=this.addWidget("text","Room","lgraph",this.setRoom.bind(this));this.addWidget("button","Reconnect",null,this.connectSocket.bind(this));this.addInput("send",s.ACTION);this.addOutput("received",
s.EVENT);this.addInput("in",0);this.addOutput("out",0);this.properties={url:"tamats.com:55000",room:"lgraph",only_send_changes:!0};this._server=null;this.connectSocket();this._last_sent_data=[];this._last_received_data=[];"undefined"==typeof SillyClient&&console.warn("remember to add SillyClient.js to your project: https://tamats.com/projects/sillyserver/src/sillyclient.js")}var s=A.LiteGraph;c.title="WebSocket";c.desc="Send data through a websocket";c.prototype.onPropertyChanged=function(c,m){"url"==
c&&this.connectSocket()};c.prototype.onExecute=function(){!this._ws&&this.properties.url&&this.connectSocket();if(this._ws&&this._ws.readyState==WebSocket.OPEN){for(var c=this.properties.room,m=this.properties.only_send_changes,h=1;h<this.inputs.length;++h){var s=this.getInputData(h);if(null!=s){var v;try{v=JSON.stringify({type:0,room:c,channel:h,data:s})}catch(A){continue}m&&this._last_sent_data[h]==v||(this._last_sent_data[h]=v,this._ws.send(v))}}for(h=1;h<this.outputs.length;++h)this.setOutputData(h,

View File

@@ -2117,8 +2117,25 @@
return error;
};
LGraph.prototype.load = function(url) {
LGraph.prototype.load = function(url, callback) {
var that = this;
//from file
if(url.constructor === File || url.constructor === Blob)
{
var reader = new FileReader();
reader.addEventListener('load', function(event) {
var data = JSON.parse(event.target.result);
that.configure(data);
if(callback)
callback();
});
reader.readAsText(url);
return;
}
//is a string, then an URL
var req = new XMLHttpRequest();
req.open("GET", url, true);
req.send(null);
@@ -2127,8 +2144,10 @@
console.error("Error loading graph:", req.status, req.response);
return;
}
var data = JSON.parse(req.response);
var data = JSON.parse( req.response );
that.configure(data);
if(callback)
callback();
};
req.onerror = function(err) {
console.error("Error loading graph:", err);
@@ -10773,9 +10792,9 @@ LGraphNode.prototype.executeAction = function(action)
callback: LGraphCanvas.onMenuNodeMode
},
{
content: "Resize", callback: () => {
content: "Resize", callback: function() {
if(node.resizable)
LGraphCanvas.onResizeNode
return LGraphCanvas.onResizeNode;
}
},
{