little fixes in some nodes

This commit is contained in:
tamat
2018-06-21 14:54:25 +02:00
parent 77efe120f8
commit 1b14b8aa78
7 changed files with 203 additions and 200 deletions

View File

@@ -439,6 +439,7 @@ LGraph.prototype.clear = function()
this.fixedtime = 0;
this.fixedtime_lapse = 0.01;
this.elapsed_time = 0.01;
this.last_update_time = 0;
this.starttime = 0;
this.catch_errors = true;
@@ -511,6 +512,7 @@ LGraph.prototype.start = function(interval)
//launch
this.starttime = LiteGraph.getTime();
this.last_update_time = this.starttime;
interval = interval || 1;
var that = this;
@@ -613,12 +615,15 @@ LGraph.prototype.runStep = function( num, do_not_catch_errors )
}
}
var elapsed = LiteGraph.getTime() - start;
var now = LiteGraph.getTime();
var elapsed = now - start;
if (elapsed == 0)
elapsed = 1;
this.elapsed_time = 0.001 * elapsed;
this.execution_time = 0.001 * elapsed;
this.globaltime += 0.001 * elapsed;
this.iteration += 1;
this.elapsed_time = (now - this.last_update_time) * 0.001;
this.last_update_time = now;
}
/**
@@ -6987,12 +6992,7 @@ Watch.prototype.onDrawBackground = function(ctx)
if (this.properties["value"].constructor === Number )
this.inputs[0].label = this.properties["value"].toFixed(3);
else
{
var str = this.properties["value"];
if(str && str.length) //convert typed to array
str = Array.prototype.slice.call(str).join(",");
this.inputs[0].label = str;
}
this.inputs[0].label = String(this.properties.value);
}
}
@@ -7239,6 +7239,7 @@ DelayEvent.prototype.onAction = function(action, param)
DelayEvent.prototype.onExecute = function()
{
var dt = this.graph.elapsed_time * 1000; //in ms
console.log(this._pending);
for(var i = 0; i < this._pending.length; ++i)
{
@@ -7275,7 +7276,7 @@ var LiteGraph = global.LiteGraph;
{
this.addOutput( "clicked", LiteGraph.EVENT );
this.addProperty( "text","" );
this.addProperty( "font","40px Arial" );
this.addProperty( "font_size", 40 );
this.addProperty( "message", "" );
this.size = [64,84];
}
@@ -7283,6 +7284,7 @@ var LiteGraph = global.LiteGraph;
WidgetButton.title = "Button";
WidgetButton.desc = "Triggers an event";
WidgetButton.font = "Arial";
WidgetButton.prototype.onDrawForeground = function(ctx)
{
if(this.flags.collapsed)
@@ -7299,11 +7301,11 @@ var LiteGraph = global.LiteGraph;
if( this.properties.text || this.properties.text === 0 )
{
var font_size = this.properties.font_size || 30;
ctx.textAlign = "center";
ctx.fillStyle = this.clicked ? "black" : "white";
if( this.properties.font )
ctx.font = this.properties.font;
ctx.fillText(this.properties.text, this.size[0] * 0.5, this.size[1] * 0.85 );
ctx.font = font_size + "px " + WidgetButton.font;
ctx.fillText( this.properties.text, this.size[0] * 0.5, this.size[1] * 0.5 + font_size * 0.3 );
ctx.textAlign = "left";
}
}
@@ -7374,7 +7376,7 @@ var LiteGraph = global.LiteGraph;
if(local_pos[0] > 1 && local_pos[1] > 1 && local_pos[0] < (this.size[0] - 2) && local_pos[1] < (this.size[1] - 2) )
{
this.properties.value = !this.properties.value;
this.trigger( "clicked", this.properties.value );
this.trigger( "e", this.properties.value );
return true;
}
}

345
build/litegraph.min.js vendored
View File

@@ -15,148 +15,148 @@ this.registered_node_types[d].category==a&&b.push(this.registered_node_types[d])
a;for(c in d){var f=d[c].src;if(f&&f.substr(0,a.length)==a)try{l.debug&&console.log("Reloading: "+f);var m=document.createElement("script");m.type="text/javascript";m.src=f;b.appendChild(m);b.removeChild(d[c])}catch(k){if(l.throw_errors)throw k;l.debug&&console.log("Error while reloading "+f)}}l.debug&&console.log("Nodes reloaded")},cloneObject:function(a,b){if(null==a)return null;var d=JSON.parse(JSON.stringify(a));if(!b)return d;for(var c in d)b[c]=d[c];return b},isValidConnection:function(a,b){if(!a||
!b||a==b||a==l.EVENT&&b==l.ACTION)return!0;a=String(a);b=String(b);a=a.toLowerCase();b=b.toLowerCase();if(-1==a.indexOf(",")&&-1==b.indexOf(","))return a==b;for(var d=a.split(","),c=b.split(","),f=0;f<d.length;++f)for(var m=0;m<c.length;++m)if(d[f]==c[m])return!0;return!1}};l.getTime="undefined"!=typeof performance?performance.now.bind(performance):"undefined"!=typeof Date&&Date.now?Date.now.bind(Date):"undefined"!=typeof process?function(){var a=process.hrtime();return 0.001*a[0]+1E-6*a[1]}:function(){return(new Date).getTime()};
u.LGraph=l.LGraph=g;g.supported_types=["number","string","boolean"];g.prototype.getSupportedTypes=function(){return this.supported_types||g.supported_types};g.STATUS_STOPPED=1;g.STATUS_RUNNING=2;g.prototype.clear=function(){this.stop();this.status=g.STATUS_STOPPED;this.last_node_id=0;this._nodes=[];this._nodes_by_id={};this._nodes_executable=this._nodes_in_order=null;this.last_link_id=0;this.links={};this.iteration=0;this.config={};this.fixedtime=this.runningtime=this.globaltime=0;this.elapsed_time=
this.fixedtime_lapse=0.01;this.starttime=0;this.catch_errors=!0;this.global_inputs={};this.global_outputs={};this.debug=!0;this.change();this.sendActionToCanvas("clear")};g.prototype.attachCanvas=function(a){if(a.constructor!=h)throw"attachCanvas expects a LGraphCanvas instance";a.graph&&a.graph!=this&&a.graph.detachCanvas(a);a.graph=this;this.list_of_graphcanvas||(this.list_of_graphcanvas=[]);this.list_of_graphcanvas.push(a)};g.prototype.detachCanvas=function(a){if(this.list_of_graphcanvas){var b=
this.list_of_graphcanvas.indexOf(a);-1!=b&&(a.graph=null,this.list_of_graphcanvas.splice(b,1))}};g.prototype.start=function(a){if(this.status!=g.STATUS_RUNNING){this.status=g.STATUS_RUNNING;if(this.onPlayEvent)this.onPlayEvent();this.sendEventToAllNodes("onStart");this.starttime=l.getTime();var b=this;this.execution_timer_id=setInterval(function(){b.runStep(1,!this.catch_errors)},a||1)}};g.prototype.stop=function(){if(this.status!=g.STATUS_STOPPED){this.status=g.STATUS_STOPPED;if(this.onStopEvent)this.onStopEvent();
null!=this.execution_timer_id&&clearInterval(this.execution_timer_id);this.execution_timer_id=null;this.sendEventToAllNodes("onStop")}};g.prototype.runStep=function(a,b){a=a||1;var d=l.getTime();this.globaltime=0.001*(d-this.starttime);var c=this._nodes_executable?this._nodes_executable:this._nodes;if(c){if(b){for(var f=0;f<a;f++){for(var m=0,k=c.length;m<k;++m){var t=c[m];if(t.mode==l.ALWAYS&&t.onExecute)t.onExecute()}this.fixedtime+=this.fixedtime_lapse;if(this.onExecuteStep)this.onExecuteStep()}if(this.onAfterExecute)this.onAfterExecute()}else try{for(f=
0;f<a;f++){m=0;for(k=c.length;m<k;++m)if(t=c[m],t.mode==l.ALWAYS&&t.onExecute)t.onExecute();this.fixedtime+=this.fixedtime_lapse;if(this.onExecuteStep)this.onExecuteStep()}if(this.onAfterExecute)this.onAfterExecute();this.errors_in_execution=!1}catch(e){this.errors_in_execution=!0;if(l.throw_errors)throw e;l.debug&&console.log("Error during execution: "+e);this.stop()}d=l.getTime()-d;0==d&&(d=1);this.elapsed_time=0.001*d;this.globaltime+=0.001*d;this.iteration+=1}};g.prototype.updateExecutionOrder=
function(){this._nodes_in_order=this.computeExecutionOrder(!1);this._nodes_executable=[];for(var a=0;a<this._nodes_in_order.length;++a)this._nodes_in_order[a].onExecute&&this._nodes_executable.push(this._nodes_in_order[a])};g.prototype.computeExecutionOrder=function(a,b){for(var d=[],c=[],f={},m={},k={},t=0,e=this._nodes.length;t<e;++t){var h=this._nodes[t];if(!a||h.onExecute){f[h.id]=h;var g=0;if(h.inputs)for(var n=0,p=h.inputs.length;n<p;n++)h.inputs[n]&&null!=h.inputs[n].link&&(g+=1);0==g?(c.push(h),
b&&(h._level=1)):(b&&(h._level=0),k[h.id]=g)}}for(;0!=c.length;)if(h=c.shift(),d.push(h),delete f[h.id],h.outputs)for(t=0;t<h.outputs.length;t++)if(e=h.outputs[t],null!=e&&null!=e.links&&0!=e.links.length)for(n=0;n<e.links.length;n++)(g=this.links[e.links[n]])&&!m[g.id]&&(p=this.getNodeById(g.target_id),null==p?m[g.id]=!0:(b&&(!p._level||p._level<=h._level)&&(p._level=h._level+1),m[g.id]=!0,k[p.id]-=1,0==k[p.id]&&c.push(p)));for(t in f)d.push(f[t]);d.length!=this._nodes.length&&l.debug&&console.warn("something went wrong, nodes missing");
e=d.length;for(t=0;t<e;++t)d[t].order=t;d=d.sort(function(a,b){var d=a.constructor.priority||a.priority||0,c=b.constructor.priority||b.priority||0;return d==c?a.order-b.order:d-c});for(t=0;t<e;++t)d[t].order=t;return d};g.prototype.arrange=function(a){a=a||40;for(var b=this.computeExecutionOrder(!1,!0),d=[],c=0;c<b.length;++c){var f=b[c],m=f._level||1;d[m]||(d[m]=[]);d[m].push(f)}b=a;for(c=0;c<d.length;++c)if(m=d[c]){for(var k=100,h=a,e=0;e<m.length;++e)f=m[e],f.pos[0]=b,f.pos[1]=h,f.size[0]>k&&(k=
f.size[0]),h+=f.size[1]+a;b+=k+a}this.setDirtyCanvas(!0,!0)};g.prototype.getTime=function(){return this.globaltime};g.prototype.getFixedTime=function(){return this.fixedtime};g.prototype.getElapsedTime=function(){return this.elapsed_time};g.prototype.sendEventToAllNodes=function(a,b,d){d=d||l.ALWAYS;var c=this._nodes_in_order?this._nodes_in_order:this._nodes;if(c)for(var f=0,m=c.length;f<m;++f){var k=c[f];if(k[a]&&k.mode==d)if(void 0===b)k[a]();else if(b&&b.constructor===Array)k[a].apply(k,b);else k[a](b)}};
g.prototype.sendActionToCanvas=function(a,b){if(this.list_of_graphcanvas)for(var d=0;d<this.list_of_graphcanvas.length;++d){var c=this.list_of_graphcanvas[d];c[a]&&c[a].apply(c,b)}};g.prototype.add=function(a,b){if(a){-1!=a.id&&null!=this._nodes_by_id[a.id]&&(console.warn("LiteGraph: there is already a node with this ID, changing it"),a.id=++this.last_node_id);if(this._nodes.length>=l.MAX_NUMBER_OF_NODES)throw"LiteGraph: max number of nodes in a graph reached";null==a.id||-1==a.id?a.id=++this.last_node_id:
this.last_node_id<a.id&&(this.last_node_id=a.id);a.graph=this;this._nodes.push(a);this._nodes_by_id[a.id]=a;if(a.onAdded)a.onAdded(this);this.config.align_to_grid&&a.alignToGrid();b||this.updateExecutionOrder();if(this.onNodeAdded)this.onNodeAdded(a);this.setDirtyCanvas(!0);this.change();return a}};g.prototype.remove=function(a){if(null!=this._nodes_by_id[a.id]&&!a.ignore_remove){if(a.inputs)for(var b=0;b<a.inputs.length;b++){var d=a.inputs[b];null!=d.link&&a.disconnectInput(b)}if(a.outputs)for(b=
0;b<a.outputs.length;b++)d=a.outputs[b],null!=d.links&&d.links.length&&a.disconnectOutput(b);if(a.onRemoved)a.onRemoved();a.graph=null;if(this.list_of_graphcanvas)for(b=0;b<this.list_of_graphcanvas.length;++b)d=this.list_of_graphcanvas[b],d.selected_nodes[a.id]&&delete d.selected_nodes[a.id],d.node_dragged==a&&(d.node_dragged=null);b=this._nodes.indexOf(a);-1!=b&&this._nodes.splice(b,1);delete this._nodes_by_id[a.id];if(this.onNodeRemoved)this.onNodeRemoved(a);this.setDirtyCanvas(!0,!0);this.change();
this.updateExecutionOrder()}};g.prototype.getNodeById=function(a){return null==a?null:this._nodes_by_id[a]};g.prototype.findNodesByClass=function(a){for(var b=[],d=0,c=this._nodes.length;d<c;++d)this._nodes[d].constructor===a&&b.push(this._nodes[d]);return b};g.prototype.findNodesByType=function(a){a=a.toLowerCase();for(var b=[],d=0,c=this._nodes.length;d<c;++d)this._nodes[d].type.toLowerCase()==a&&b.push(this._nodes[d]);return b};g.prototype.findNodesByTitle=function(a){for(var b=[],d=0,c=this._nodes.length;d<
c;++d)this._nodes[d].title==a&&b.push(this._nodes[d]);return b};g.prototype.getNodeOnPos=function(a,b,d){d=d||this._nodes;for(var c=d.length-1;0<=c;c--){var f=d[c];if(f.isPointInsideNode(a,b,2))return f}return null};g.prototype.addGlobalInput=function(a,b,d){this.global_inputs[a]={name:a,type:b,value:d};if(this.onGlobalInputAdded)this.onGlobalInputAdded(a,b);if(this.onGlobalsChange)this.onGlobalsChange()};g.prototype.setGlobalInputData=function(a,b){var d=this.global_inputs[a];d&&(d.value=b)};g.prototype.setInputData=
g.prototype.setGlobalInputData;g.prototype.getGlobalInputData=function(a){return(a=this.global_inputs[a])?a.value:null};g.prototype.renameGlobalInput=function(a,b){if(b!=a){if(!this.global_inputs[a])return!1;if(this.global_inputs[b])return console.error("there is already one input with that name"),!1;this.global_inputs[b]=this.global_inputs[a];delete this.global_inputs[a];if(this.onGlobalInputRenamed)this.onGlobalInputRenamed(a,b);if(this.onGlobalsChange)this.onGlobalsChange()}};g.prototype.changeGlobalInputType=
function(a,b){if(!this.global_inputs[a])return!1;if(this.global_inputs[a].type.toLowerCase()!=b.toLowerCase()&&(this.global_inputs[a].type=b,this.onGlobalInputTypeChanged))this.onGlobalInputTypeChanged(a,b)};g.prototype.removeGlobalInput=function(a){if(!this.global_inputs[a])return!1;delete this.global_inputs[a];if(this.onGlobalInputRemoved)this.onGlobalInputRemoved(a);if(this.onGlobalsChange)this.onGlobalsChange();return!0};g.prototype.addGlobalOutput=function(a,b,d){this.global_outputs[a]={name:a,
type:b,value:d};if(this.onGlobalOutputAdded)this.onGlobalOutputAdded(a,b);if(this.onGlobalsChange)this.onGlobalsChange()};g.prototype.setGlobalOutputData=function(a,b){var d=this.global_outputs[a];d&&(d.value=b)};g.prototype.getGlobalOutputData=function(a){return(a=this.global_outputs[a])?a.value:null};g.prototype.getOutputData=g.prototype.getGlobalOutputData;g.prototype.renameGlobalOutput=function(a,b){if(!this.global_outputs[a])return!1;if(this.global_outputs[b])return console.error("there is already one output with that name"),
!1;this.global_outputs[b]=this.global_outputs[a];delete this.global_outputs[a];if(this.onGlobalOutputRenamed)this.onGlobalOutputRenamed(a,b);if(this.onGlobalsChange)this.onGlobalsChange()};g.prototype.changeGlobalOutputType=function(a,b){if(!this.global_outputs[a])return!1;if(this.global_outputs[a].type.toLowerCase()!=b.toLowerCase()&&(this.global_outputs[a].type=b,this.onGlobalOutputTypeChanged))this.onGlobalOutputTypeChanged(a,b)};g.prototype.removeGlobalOutput=function(a){if(!this.global_outputs[a])return!1;
delete this.global_outputs[a];if(this.onGlobalOutputRemoved)this.onGlobalOutputRemoved(a);if(this.onGlobalsChange)this.onGlobalsChange();return!0};g.prototype.triggerInput=function(a,b){for(var d=this.findNodesByTitle(a),c=0;c<d.length;++c)d[c].onTrigger(b)};g.prototype.setCallback=function(a,b){for(var d=this.findNodesByTitle(a),c=0;c<d.length;++c)d[c].setTrigger(b)};g.prototype.connectionChange=function(a){this.updateExecutionOrder();if(this.onConnectionChange)this.onConnectionChange(a);this.sendActionToCanvas("onConnectionChange")};
g.prototype.isLive=function(){if(!this.list_of_graphcanvas)return!1;for(var a=0;a<this.list_of_graphcanvas.length;++a)if(this.list_of_graphcanvas[a].live_mode)return!0;return!1};g.prototype.change=function(){l.debug&&console.log("Graph changed");this.sendActionToCanvas("setDirty",[!0,!0]);if(this.on_change)this.on_change(this)};g.prototype.setDirtyCanvas=function(a,b){this.sendActionToCanvas("setDirty",[a,b])};g.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 c=this.links[b];d.push([c.id,c.origin_id,c.origin_slot,c.target_id,c.target_slot,c.type])}return{iteration:this.iteration,frame:this.frame,last_node_id:this.last_node_id,last_link_id:this.last_link_id,links:d,config:this.config,nodes:a}};g.prototype.configure=function(a,b){b||this.clear();var d=a.nodes;if(a.links&&a.links.constructor===Array){for(var c={},f=0;f<a.links.length;++f){var m=a.links[f];c[m[0]]={id:m[0],origin_id:m[1],origin_slot:m[2],target_id:m[3],target_slot:m[4],
type:m[5]}}a.links=c}for(f in a)this[f]=a[f];c=!1;this._nodes=[];f=0;for(m=d.length;f<m;++f){var k=d[f],h=l.createNode(k.type,k.title);h?(h.id=k.id,this.add(h,!0)):(l.debug&&console.log("Node not found: "+k.type),c=!0)}f=0;for(m=d.length;f<m;++f)k=d[f],(h=this.getNodeById(k.id))&&h.configure(k);this.updateExecutionOrder();this.setDirtyCanvas(!0,!0);return c};g.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)}};g.prototype.onNodeTrace=function(a,b,d){};u.LGraphNode=l.LGraphNode=e;e.prototype._ctor=function(a){this.title=a||"Unnamed";this.size=[l.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.data=null;this.flags={}};e.prototype.configure=function(a){for(var b in a)if("console"!=b)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]=l.cloneObject(a[b],this[b]):this[b]=a[b]);a.title||(this.title=
this.constructor.title);if(this.onConnectionsChange){if(this.inputs)for(var c=0;c<this.inputs.length;++c){d=this.inputs[c];var f=this.graph.links[d.link];this.onConnectionsChange(l.INPUT,c,!0,f,d)}if(this.outputs)for(c=0;c<this.outputs.length;++c)if(d=this.outputs[c],d.links)for(b=0;b<d.links.length;++b)f=this.graph.links[d.links[b]],this.onConnectionsChange(l.OUTPUT,c,!0,f,d)}for(c in this.inputs)d=this.inputs[c],d.link&&d.link.length&&(f=d.link,"object"==typeof f&&(d.link=f[0],this.graph.links[f[0]]=
{id:f[0],origin_id:f[1],origin_slot:f[2],target_id:f[3],target_slot:f[4]}));for(c in this.outputs)if(d=this.outputs[c],d.links&&0!=d.links.length)for(b in d.links)f=d.links[b],"object"==typeof f&&(d.links[b]=f[0]);if(this.onConfigure)this.onConfigure(a)};e.prototype.serialize=function(){var a={id:this.id,type:this.type,pos:this.pos,size:this.size,data:this.data,flags:l.cloneObject(this.flags),mode:this.mode};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=l.cloneObject(this.properties));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);if(this.onSerialize)this.onSerialize(a);return a};e.prototype.clone=function(){var a=l.createNode(this.type),b=l.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};e.prototype.toString=function(){return JSON.stringify(this.serialize())};e.prototype.getTitle=function(){return this.title||this.constructor.title};e.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++)this.graph.links[this.outputs[a].links[d]].data=
b}};e.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 c=this.graph.getNodeById(d.origin_id);if(!c)return d.data;if(c.updateOutputData)c.updateOutputData(d.origin_slot);else if(c.onExecute)c.onExecute();return d.data}};e.prototype.getInputDataByName=function(a,b){var d=this.findInputSlot(a);return-1==d?null:this.getInputData(d,b)};e.prototype.isInputConnected=
function(a){return this.inputs?a<this.inputs.length&&null!=this.inputs[a].link:!1};e.prototype.getInputInfo=function(a){return this.inputs?a<this.inputs.length?this.inputs[a]:null:null};e.prototype.getInputNode=function(a){if(!this.inputs||a>=this.inputs.length)return null;a=this.inputs[a];return a&&a.link?(a=this.graph.links[a.link])?this.graph.getNodeById(a.origin_id):null:null};e.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)if(a==this.inputs[b].name)return(a=this.graph.links[this.inputs[b].link])?a.data:null;return this.properties[a]};e.prototype.getOutputData=function(a){return!this.outputs||a>=this.outputs.length?null:this.outputs[a]._data};e.prototype.getOutputInfo=function(a){return this.outputs?a<this.outputs.length?this.outputs[a]:null:null};e.prototype.isOutputConnected=function(a){return this.outputs?a<this.outputs.length&&this.outputs[a].links&&this.outputs[a].links.length:
!1};e.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};e.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 c=this.graph.links[a.links[d]];c&&(c=this.graph.getNodeById(c.target_id))&&b.push(c)}return b};
e.prototype.trigger=function(a,b){if(this.outputs&&this.outputs.length){this.graph&&(this.graph._last_trigger_time=l.getTime());for(var d=0;d<this.outputs.length;++d){var c=this.outputs[d];!c||c.type!==l.EVENT||a&&c.name!=a||this.triggerSlot(d,b)}}};e.prototype.triggerSlot=function(a,b){if(this.outputs){var d=this.outputs[a];if(d&&(d=d.links)&&d.length){this.graph&&(this.graph._last_trigger_time=l.getTime());for(var c=0;c<d.length;++c){var f=this.graph.links[d[c]];if(f){var m=this.graph.getNodeById(f.target_id);
if(m)if(f._last_time=l.getTime(),f=m.inputs[f.target_slot],m.onAction)m.onAction(f.name,b);else if(m.mode===l.ON_TRIGGER&&m.onExecute)m.onExecute(b)}}}}};e.prototype.addProperty=function(a,b,d,c){d={name:a,type:d,default_value:b};if(c)for(var f in c)d[f]=c[f];this.properties_info||(this.properties_info=[]);this.properties_info.push(d);this.properties||(this.properties={});this.properties[a]=b;return d};e.prototype.addOutput=function(a,b,d){a={name:a,type:b,links:null};if(d)for(var c in d)a[c]=d[c];
this.outputs||(this.outputs=[]);this.outputs.push(a);if(this.onOutputAdded)this.onOutputAdded(a);this.size=this.computeSize();return a};e.prototype.addOutputs=function(a){for(var b=0;b<a.length;++b){var d=a[b],c={name:d[0],type:d[1],link:null};if(a[2])for(var f in d[2])c[f]=d[2][f];this.outputs||(this.outputs=[]);this.outputs.push(c);if(this.onOutputAdded)this.onOutputAdded(c)}this.size=this.computeSize()};e.prototype.removeOutput=function(a){this.disconnectOutput(a);this.outputs.splice(a,1);this.size=
this.computeSize();if(this.onOutputRemoved)this.onOutputRemoved(a)};e.prototype.addInput=function(a,b,d){a={name:a,type:b||0,link:null};if(d)for(var c in d)a[c]=d[c];this.inputs||(this.inputs=[]);this.inputs.push(a);this.size=this.computeSize();if(this.onInputAdded)this.onInputAdded(a);return a};e.prototype.addInputs=function(a){for(var b=0;b<a.length;++b){var d=a[b],c={name:d[0],type:d[1],link:null};if(a[2])for(var f in d[2])c[f]=d[2][f];this.inputs||(this.inputs=[]);this.inputs.push(c);if(this.onInputAdded)this.onInputAdded(c)}this.size=
this.computeSize()};e.prototype.removeInput=function(a){this.disconnectInput(a);this.inputs.splice(a,1);this.size=this.computeSize();if(this.onInputRemoved)this.onInputRemoved(a)};e.prototype.addConnection=function(a,b,d,c){a={name:a,type:b,pos:d,direction:c,links:null};this.connections.push(a);return a};e.prototype.computeSize=function(a,b){function d(a){return a?m*a.length*0.6:0}var c=Math.max(this.inputs?this.inputs.length:1,this.outputs?this.outputs.length:1),f=b||new Float32Array([0,0]),c=Math.max(c,
1);f[1]=14*c+6;var m=14,c=d(this.title),k=0,h=0;if(this.inputs)for(var e=0,g=this.inputs.length;e<g;++e){var n=this.inputs[e],n=n.label||n.name||"",n=d(n);k<n&&(k=n)}if(this.outputs)for(e=0,g=this.outputs.length;e<g;++e)n=this.outputs[e],n=n.label||n.name||"",n=d(n),h<n&&(h=n);f[0]=Math.max(k+h+10,c);f[0]=Math.max(f[0],l.NODE_WIDTH);return f};e.prototype.getBounding=function(a){a=a||new Float32Array(4);a[0]=this.pos[0]-4;a[1]=this.pos[1]-l.NODE_TITLE_HEIGHT;a[2]=this.size[0]+4;a[3]=this.size[1]+l.NODE_TITLE_HEIGHT;
return a};e.prototype.isPointInsideNode=function(a,b,d){d=d||0;var c=this.graph&&this.graph.isLive()?0:20;if(this.flags.collapsed){if(p(a,b,this.pos[0]-d,this.pos[1]-l.NODE_TITLE_HEIGHT-d,l.NODE_COLLAPSED_WIDTH+2*d,l.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]-c-d<b&&this.pos[1]+this.size[1]+d>b)return!0;return!1};e.prototype.getSlotInPosition=function(a,b){if(this.inputs)for(var d=0,c=this.inputs.length;d<c;++d){var f=this.inputs[d],m=this.getConnectionPos(!0,
d);if(p(a,b,m[0]-10,m[1]-5,20,10))return{input:f,slot:d,link_pos:m,locked:f.locked}}if(this.outputs)for(d=0,c=this.outputs.length;d<c;++d)if(f=this.outputs[d],m=this.getConnectionPos(!1,d),p(a,b,m[0]-10,m[1]-5,20,10))return{output:f,slot:d,link_pos:m,locked:f.locked};return null};e.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};e.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};e.prototype.connect=function(a,b,d){d=d||0;if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return l.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.outputs||a>=this.outputs.length)return l.debug&&console.log("Connect: Error, slot number not found"),!1;b&&b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"Node not found";if(b==this)return!1;if(d.constructor===String){if(d=
b.findInputSlot(d),-1==d)return l.debug&&console.log("Connect: Error, no slot of name "+d),!1}else{if(d===l.EVENT)return!1;if(!b.inputs||d>=b.inputs.length)return l.debug&&console.log("Connect: Error, slot number not found"),!1}null!=b.inputs[d].link&&b.disconnectInput(d);this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this);var c=this.outputs[a];if(b.onConnectInput&&!1===b.onConnectInput(d,c.type,c))return!1;var f=b.inputs[d];if(l.isValidConnection(c.type,f.type)){var m={id:this.graph.last_link_id++,
type:f.type,origin_id:this.id,origin_slot:a,target_id:b.id,target_slot:d};this.graph.links[m.id]=m;null==c.links&&(c.links=[]);c.links.push(m.id);b.inputs[d].link=m.id;if(this.onConnectionsChange)this.onConnectionsChange(l.OUTPUT,a,!0,m,c);if(b.onConnectionsChange)b.onConnectionsChange(l.INPUT,d,!0,m,f)}this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this);return!0};e.prototype.disconnectOutput=function(a,b){if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return l.debug&&console.log("Connect: Error, no slot of name "+
a),!1}else if(!this.outputs||a>=this.outputs.length)return l.debug&&console.log("Connect: Error, slot number not found"),!1;var d=this.outputs[a];if(!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 c=0,f=d.links.length;c<f;c++){var m=d.links[c],k=this.graph.links[m];if(k.target_id==b.id){d.links.splice(c,1);var h=b.inputs[k.target_slot];h.link=null;delete this.graph.links[m];if(b.onConnectionsChange)b.onConnectionsChange(l.INPUT,
k.target_slot,!1,k,h);if(this.onConnectionsChange)this.onConnectionsChange(l.OUTPUT,a,!1,k,d);break}}}else{c=0;for(f=d.links.length;c<f;c++)if(m=d.links[c],k=this.graph.links[m]){if(b=this.graph.getNodeById(k.target_id))if(h=b.inputs[k.target_slot],h.link=null,b.onConnectionsChange)b.onConnectionsChange(l.INPUT,k.target_slot,!1,k,h);delete this.graph.links[m];if(this.onConnectionsChange)this.onConnectionsChange(l.OUTPUT,a,!1,k,d)}d.links=null}this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this);
return!0};e.prototype.disconnectInput=function(a){if(a.constructor===String){if(a=this.findInputSlot(a),-1==a)return l.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.inputs||a>=this.inputs.length)return l.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;this.inputs[a].link=null;var c=this.graph.links[d];if(c){var f=this.graph.getNodeById(c.origin_id);if(!f)return!1;var m=f.outputs[c.origin_slot];
if(!m||!m.links||0==m.links.length)return!1;for(var k=0,h=m.links.length;k<h;k++)if(m.links[k]==d){m.links.splice(k,1);break}delete this.graph.links[d];if(this.onConnectionsChange)this.onConnectionsChange(l.INPUT,a,!1,c,b);if(f.onConnectionsChange)f.onConnectionsChange(l.OUTPUT,k,!1,c,m)}this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this);return!0};e.prototype.getConnectionPos=function(a,b){return this.flags.collapsed?a?[this.pos[0],this.pos[1]-0.5*l.NODE_TITLE_HEIGHT]:[this.pos[0]+l.NODE_COLLAPSED_WIDTH,
this.pos[1]-0.5*l.NODE_TITLE_HEIGHT]:a&&-1==b?[this.pos[0]+10,this.pos[1]+10]:a&&this.inputs.length>b&&this.inputs[b].pos?[this.pos[0]+this.inputs[b].pos[0],this.pos[1]+this.inputs[b].pos[1]]:!a&&this.outputs.length>b&&this.outputs[b].pos?[this.pos[0]+this.outputs[b].pos[0],this.pos[1]+this.outputs[b].pos[1]]:a?[this.pos[0],this.pos[1]+10+b*l.NODE_SLOT_HEIGHT]:[this.pos[0]+this.size[0]+1,this.pos[1]+10+b*l.NODE_SLOT_HEIGHT]};e.prototype.alignToGrid=function(){this.pos[0]=l.CANVAS_GRID_SIZE*Math.round(this.pos[0]/
l.CANVAS_GRID_SIZE);this.pos[1]=l.CANVAS_GRID_SIZE*Math.round(this.pos[1]/l.CANVAS_GRID_SIZE)};e.prototype.trace=function(a){this.console||(this.console=[]);this.console.push(a);this.console.length>e.MAX_CONSOLE&&this.console.shift();this.graph.onNodeTrace(this,a)};e.prototype.setDirtyCanvas=function(a,b){this.graph&&this.graph.sendActionToCanvas("setDirty",[a,b])};e.prototype.loadImage=function(a){var b=new Image;b.src=l.node_images_path+a;b.ready=!1;var d=this;b.onload=function(){this.ready=!0;
d.setDirtyCanvas(!0)};return b};e.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 c=b[d];if(a||c.node_capturing_input==this)c.node_capturing_input=a?this:null}};e.prototype.collapse=function(){this.flags.collapsed=this.flags.collapsed?!1:!0;this.setDirtyCanvas(!0,!0)};e.prototype.pin=function(a){this.flags.pinned=void 0===a?!this.flags.pinned:a};e.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]]};u.LGraphCanvas=l.LGraphCanvas=h;h.link_type_colors={"-1":"#F85",number:"#AAC",node:"#DCA"};h.prototype.clear=function(){this.fps=this.render_time=this.last_draw_time=this.frame=0;this.scale=1;this.offset=[0,0];this.dragging_rectangle=null;this.selected_nodes={};this.visible_nodes=[];this.connecting_node=this.node_capturing_input=this.node_over=this.node_dragged=null;this.highlighted_links={};this.dirty_bgcanvas=this.dirty_canvas=!0;this.node_in_panel=
this.dirty_area=null;this.last_mouse=[0,0];this.last_mouseclick=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.setDirty(!0,!0)))};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.setDirty(!0,!0)};h.prototype.closeSubgraph=function(){if(this._graph_stack&&0!=this._graph_stack.length){var a=this._graph_stack.pop();this.selected_nodes={};this.highlighted_links={};a.attachCanvas(this);this.setDirty(!0,!0)}};h.prototype.setCanvas=function(a,b){if(a&&a.constructor===String&&(a=document.getElementById(a),!a))throw"Error creating LiteGraph canvas: Canvas not found";if(a!==this.canvas&&(!a&&this.canvas&&(b||this.unbindEvents()),this.canvas=a)){a.className+=" lgraphcanvas";a.data=
this;this.bgcanvas=null;this.bgcanvas||(this.bgcanvas=document.createElement("canvas"),this.bgcanvas.width=this.canvas.width,this.bgcanvas.height=this.canvas.height);if(null==a.getContext){if("canvas"!=a.localName)throw"Element supplied for LGraphCanvas must be a <canvas> element, you passed a "+a.localName;throw"This browser doesnt support Canvas";}null==(this.ctx=a.getContext("2d"))&&(console.warn("This canvas seems to be WebGL, enabling WebGL renderer"),this.enableWebGL());this._mousemove_callback=
this.processMouseMove.bind(this);this._mouseup_callback=this.processMouseUp.bind(this);b||this.bindEvents()}};h.prototype._doNothing=function(a){a.preventDefault();return!1};h.prototype._doReturnTrue=function(a){a.preventDefault();return!0};h.prototype.bindEvents=function(){if(this._events_binded)console.warn("LGraphCanvas: events already binded");else{var a=this.canvas,b=this.getCanvasWindow().document;this._mousedown_callback=this.processMouseDown.bind(this);this._mousewheel_callback=this.processMouseWheel.bind(this);
a.addEventListener("mousedown",this._mousedown_callback,!0);a.addEventListener("mousemove",this._mousemove_callback);a.addEventListener("mousewheel",this._mousewheel_callback,!1);a.addEventListener("contextmenu",this._doNothing);a.addEventListener("DOMMouseScroll",this._mousewheel_callback,!1);a.addEventListener("touchstart",this.touchHandler,!0);a.addEventListener("touchmove",this.touchHandler,!0);a.addEventListener("touchend",this.touchHandler,!0);a.addEventListener("touchcancel",this.touchHandler,
!0);this._key_callback=this.processKey.bind(this);a.addEventListener("keydown",this._key_callback,!0);b.addEventListener("keyup",this._key_callback,!0);this._ondrop_callback=this.processDrop.bind(this);a.addEventListener("dragover",this._doNothing,!1);a.addEventListener("dragend",this._doNothing,!1);a.addEventListener("drop",this._ondrop_callback,!1);a.addEventListener("dragenter",this._doReturnTrue,!1);this._events_binded=!0}};h.prototype.unbindEvents=function(){if(this._events_binded){var a=this.getCanvasWindow().document;
this.canvas.removeEventListener("mousedown",this._mousedown_callback);this.canvas.removeEventListener("mousewheel",this._mousewheel_callback);this.canvas.removeEventListener("DOMMouseScroll",this._mousewheel_callback);this.canvas.removeEventListener("keydown",this._key_callback);a.removeEventListener("keyup",this._key_callback);this.canvas.removeEventListener("contextmenu",this._doNothing);this.canvas.removeEventListener("drop",this._ondrop_callback);this.canvas.removeEventListener("dragenter",this._doReturnTrue);
this.canvas.removeEventListener("touchstart",this.touchHandler);this.canvas.removeEventListener("touchmove",this.touchHandler);this.canvas.removeEventListener("touchend",this.touchHandler);this.canvas.removeEventListener("touchcancel",this.touchHandler);this._ondrop_callback=this._key_callback=this._mousewheel_callback=this._mousedown_callback=null;this._events_binded=!1}else console.warn("LGraphCanvas: no events binded")};h.getFileExtension=function(a){var b=a.indexOf("?");-1!=b&&(a=a.substr(0,b));
b=a.lastIndexOf(".");return-1==b?"":a.substr(b+1).toLowerCase()};h.prototype.enableWebGL=function(){if(void 0===typeof GL)throw"litegl.js must be included to use a WebGL canvas";if(void 0===typeof enableWebGLCanvas)throw"webglCanvas.js must be included to use this feature";this.gl=this.ctx=enableWebGLCanvas(this.canvas);this.ctx.webgl=!0;this.bgcanvas=this.canvas;this.bgctx=this.gl};h.prototype.setDirty=function(a,b){a&&(this.dirty_canvas=!0);b&&(this.dirty_bgcanvas=!0)};h.prototype.getCanvasWindow=
function(){if(!this.canvas)return window;var a=this.canvas.ownerDocument;return a.defaultView||a.parentWindow};h.prototype.startRendering=function(){function a(){this.pause_rendering||this.draw();var b=this.getCanvasWindow();this.is_rendering&&b.requestAnimationFrame(a.bind(this))}this.is_rendering||(this.is_rendering=!0,a.call(this))};h.prototype.stopRendering=function(){this.is_rendering=!1};h.prototype.processMouseDown=function(a){if(this.graph){this.adjustMouseEvent(a);var b=this.getCanvasWindow();
h.active_canvas=this;this.canvas.removeEventListener("mousemove",this._mousemove_callback);b.document.addEventListener("mousemove",this._mousemove_callback,!0);b.document.addEventListener("mouseup",this._mouseup_callback,!0);var d=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes),c=!1;l.closeAllContextMenus(b);if(1==a.which){a.ctrlKey&&(this.dragging_rectangle=new Float32Array(4),this.dragging_rectangle[0]=a.canvasX,this.dragging_rectangle[1]=a.canvasY,this.dragging_rectangle[2]=1,this.dragging_rectangle[3]=
1,c=!0);var f=!1;if(d&&this.allow_interaction&&!c){this.live_mode||d.flags.pinned||this.bringToFront(d);if(!this.connecting_node&&!d.flags.collapsed&&!this.live_mode){if(d.outputs)for(var m=0,k=d.outputs.length;m<k;++m){var e=d.outputs[m],g=d.getConnectionPos(!1,m);if(p(a.canvasX,a.canvasY,g[0]-10,g[1]-5,20,10)){this.connecting_node=d;this.connecting_output=e;this.connecting_pos=d.getConnectionPos(!1,m);this.connecting_slot=m;c=!0;break}}if(d.inputs)for(m=0,k=d.inputs.length;m<k;++m)e=d.inputs[m],
g=d.getConnectionPos(!0,m),p(a.canvasX,a.canvasY,g[0]-10,g[1]-5,20,10)&&null!==e.link&&(d.disconnectInput(m),c=this.dirty_bgcanvas=!0);!c&&p(a.canvasX,a.canvasY,d.pos[0]+d.size[0]-5,d.pos[1]+d.size[1]-5,5,5)&&(this.resizing_node=d,this.canvas.style.cursor="se-resize",c=!0)}!c&&p(a.canvasX,a.canvasY,d.pos[0],d.pos[1]-l.NODE_TITLE_HEIGHT,l.NODE_TITLE_HEIGHT,l.NODE_TITLE_HEIGHT)&&(d.collapse(),c=!0);if(!c){m=!1;if(300>l.getTime()-this.last_mouseclick&&this.selected_nodes[d.id]){if(d.onDblClick)d.onDblClick(a);
this.processNodeDblClicked(d);m=!0}d.onMouseDown&&d.onMouseDown(a,[a.canvasX-d.pos[0],a.canvasY-d.pos[1]])?m=!0:this.live_mode&&(m=f=!0);m||(this.allow_dragnodes&&(this.node_dragged=d),this.selected_nodes[d.id]||this.processNodeSelected(d,a));this.dirty_canvas=!0}}else f=!0;!c&&f&&this.allow_dragcanvas&&(this.dragging_canvas=!0)}else 2!=a.which&&3==a.which&&this.processContextMenu(d,a);this.last_mouse[0]=a.localX;this.last_mouse[1]=a.localY;this.last_mouseclick=l.getTime();this.canvas_mouse=[a.canvasX,
a.canvasY];this.graph.change();(!b.document.activeElement||"input"!=b.document.activeElement.nodeName.toLowerCase()&&"textarea"!=b.document.activeElement.nodeName.toLowerCase())&&a.preventDefault();a.stopPropagation();if(this.onMouseDown)this.onMouseDown(a);return!1}};h.prototype.processMouseMove=function(a){this.autoresize&&this.resize();if(this.graph){h.active_canvas=this;this.adjustMouseEvent(a);var b=[a.localX,a.localY],d=[b[0]-this.last_mouse[0],b[1]-this.last_mouse[1]];this.last_mouse=b;this.canvas_mouse=
[a.canvasX,a.canvasY];if(this.dragging_rectangle)this.dragging_rectangle[2]=a.canvasX-this.dragging_rectangle[0],this.dragging_rectangle[3]=a.canvasY-this.dragging_rectangle[1],this.dirty_canvas=!0;else if(this.dragging_canvas)this.offset[0]+=d[0]/this.scale,this.offset[1]+=d[1]/this.scale,this.dirty_bgcanvas=this.dirty_canvas=!0;else if(this.allow_interaction){this.connecting_node&&(this.dirty_canvas=!0);for(var b=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes),c=0,f=this.graph._nodes.length;c<
f;++c)if(this.graph._nodes[c].mouseOver&&b!=this.graph._nodes[c]){this.graph._nodes[c].mouseOver=!1;if(this.node_over&&this.node_over.onMouseLeave)this.node_over.onMouseLeave(a);this.node_over=null;this.dirty_canvas=!0}if(b){if(!b.mouseOver&&(b.mouseOver=!0,this.node_over=b,this.dirty_canvas=!0,b.onMouseEnter))b.onMouseEnter(a);if(b.onMouseMove)b.onMouseMove(a);if(this.connecting_node&&(f=this._highlight_input||[0,0],!this.isOverNodeBox(b,a.canvasX,a.canvasY))){var m=this.isOverNodeInput(b,a.canvasX,
a.canvasY,f);-1!=m&&b.inputs[m]?l.isValidConnection(this.connecting_output.type,b.inputs[m].type)&&(this._highlight_input=f):this._highlight_input=null}p(a.canvasX,a.canvasY,b.pos[0]+b.size[0]-5,b.pos[1]+b.size[1]-5,5,5)?this.canvas.style.cursor="se-resize":this.canvas.style.cursor=null}else this.canvas.style.cursor=null;if(this.node_capturing_input&&this.node_capturing_input!=b&&this.node_capturing_input.onMouseMove)this.node_capturing_input.onMouseMove(a);if(this.node_dragged&&!this.live_mode){for(c in this.selected_nodes)b=
this.selected_nodes[c],b.pos[0]+=d[0]/this.scale,b.pos[1]+=d[1]/this.scale;this.dirty_bgcanvas=this.dirty_canvas=!0}this.resizing_node&&!this.live_mode&&(this.resizing_node.size[0]+=d[0]/this.scale,this.resizing_node.size[1]+=d[1]/this.scale,d=Math.max(this.resizing_node.inputs?this.resizing_node.inputs.length:0,this.resizing_node.outputs?this.resizing_node.outputs.length:0),this.resizing_node.size[1]<d*l.NODE_SLOT_HEIGHT+4&&(this.resizing_node.size[1]=d*l.NODE_SLOT_HEIGHT+4),this.resizing_node.size[0]<
l.NODE_MIN_WIDTH&&(this.resizing_node.size[0]=l.NODE_MIN_WIDTH),this.canvas.style.cursor="se-resize",this.dirty_bgcanvas=this.dirty_canvas=!0)}a.preventDefault();return!1}};h.prototype.processMouseUp=function(a){if(this.graph){var b=this.getCanvasWindow().document;h.active_canvas=this;b.removeEventListener("mousemove",this._mousemove_callback,!0);this.canvas.addEventListener("mousemove",this._mousemove_callback,!0);b.removeEventListener("mouseup",this._mouseup_callback,!0);this.adjustMouseEvent(a);
b=l.getTime();a.click_time=b-this.last_mouseclick;if(1==a.which)if(this.dragging_rectangle){if(this.graph){var d=this.graph._nodes,c=new Float32Array(4);this.deselectAllNodes();0>this.dragging_rectangle[2]&&(this.dragging_rectangle[0]+=this.dragging_rectangle[2]);0>this.dragging_rectangle[3]&&(this.dragging_rectangle[1]+=this.dragging_rectangle[3]);this.dragging_rectangle[2]=Math.abs(this.dragging_rectangle[2]*this.scale);this.dragging_rectangle[3]=Math.abs(this.dragging_rectangle[3]*this.scale);
for(var f=0;f<d.length;++f)b=d[f],b.getBounding(c),q(this.dragging_rectangle,c)&&this.selectNode(b,!0)}this.dragging_rectangle=null}else if(this.connecting_node){this.dirty_bgcanvas=this.dirty_canvas=!0;if(b=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes))this.connecting_output.type==l.EVENT&&this.isOverNodeBox(b,a.canvasX,a.canvasY)?this.connecting_node.connect(this.connecting_slot,b,l.EVENT):(d=this.isOverNodeInput(b,a.canvasX,a.canvasY),-1!=d?this.connecting_node.connect(this.connecting_slot,
b,d):(d=b.getInputInfo(0),this.connecting_output.type==l.EVENT?this.connecting_node.connect(this.connecting_slot,b,l.EVENT):d&&!d.link&&l.isValidConnection(d.type&&this.connecting_output.type)&&this.connecting_node.connect(this.connecting_slot,b,0)));this.connecting_node=this.connecting_pos=this.connecting_output=null;this.connecting_slot=-1}else if(this.resizing_node)this.dirty_bgcanvas=this.dirty_canvas=!0,this.resizing_node=null;else if(this.node_dragged)this.dirty_bgcanvas=this.dirty_canvas=!0,
this.node_dragged.pos[0]=Math.round(this.node_dragged.pos[0]),this.node_dragged.pos[1]=Math.round(this.node_dragged.pos[1]),this.graph.config.align_to_grid&&this.node_dragged.alignToGrid(),this.node_dragged=null;else{b=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes);!b&&300>a.click_time&&this.deselectAllNodes();this.dirty_canvas=!0;this.dragging_canvas=!1;if(this.node_over&&this.node_over.onMouseUp)this.node_over.onMouseUp(a,[a.canvasX-this.node_over.pos[0],a.canvasY-this.node_over.pos[1]]);
if(this.node_capturing_input&&this.node_capturing_input.onMouseUp)this.node_capturing_input.onMouseUp(a,[a.canvasX-this.node_capturing_input.pos[0],a.canvasY-this.node_capturing_input.pos[1]])}else 2==a.which?(this.dirty_canvas=!0,this.dragging_canvas=!1):3==a.which&&(this.dirty_canvas=!0,this.dragging_canvas=!1);this.graph.change();a.stopPropagation();a.preventDefault();return!1}};h.prototype.processMouseWheel=function(a){if(this.graph&&this.allow_dragcanvas){var b=null!=a.wheelDeltaY?a.wheelDeltaY:
-60*a.detail;this.adjustMouseEvent(a);var d=this.scale;0<b?d*=1.1:0>b&&(d*=1/1.1);this.setZoom(d,[a.localX,a.localY]);this.graph.change();a.preventDefault();return!1}};h.prototype.isOverNodeBox=function(a,b,d){var c=l.NODE_TITLE_HEIGHT;return p(b,d,a.pos[0]+2,a.pos[1]+2-c,c-4,c-4)?!0:!1};h.prototype.isOverNodeInput=function(a,b,d,c){if(a.inputs)for(var f=0,m=a.inputs.length;f<m;++f){var k=a.getConnectionPos(!0,f);if(p(b,d,k[0]-10,k[1]-5,20,10))return c&&(c[0]=k[0],c[1]=k[1]),f}return-1};h.prototype.processKey=
function(a){if(this.graph){var b=!1;if("input"!=a.target.localName){if("keydown"==a.type){32==a.keyCode&&(b=this.dragging_canvas=!0);65==a.keyCode&&a.ctrlKey&&(this.selectNodes(),b=!0);"KeyC"==a.code&&(a.metaKey||a.ctrlKey)&&!a.shiftKey&&this.selected_nodes&&(this.copyToClipboard(),b=!0);"KeyV"!=a.code||!a.metaKey&&!a.ctrlKey||a.shiftKey||this.pasteFromClipboard();if(46==a.keyCode||8==a.keyCode)this.deleteSelectedNodes(),b=!0;if(this.selected_nodes)for(var d in this.selected_nodes)if(this.selected_nodes[d].onKeyDown)this.selected_nodes[d].onKeyDown(a)}else if("keyup"==
a.type&&(32==a.keyCode&&(this.dragging_canvas=!1),this.selected_nodes))for(d in this.selected_nodes)if(this.selected_nodes[d].onKeyUp)this.selected_nodes[d].onKeyUp(a);this.graph.change();if(b)return a.preventDefault(),!1}}};h.prototype.copyToClipboard=function(){var a={nodes:[],links:[]},b=0,d=[],c;for(c in this.selected_nodes){var f=this.selected_nodes[c];f._relative_id=b;d.push(f);b+=1}for(c=0;c<d.length;++c)if(f=d[c],a.nodes.push(f.clone().serialize()),f.inputs&&f.inputs.length)for(b=0;b<f.inputs.length;++b){var m=
f.inputs[b];if(m&&null!=m.link&&(m=this.graph.links[m.link])){var k=this.graph.getNodeById(m.origin_id);k&&this.selected_nodes[k.id]&&a.links.push([k._relative_id,b,f._relative_id,m.target_slot])}}localStorage.setItem("litegrapheditor_clipboard",JSON.stringify(a))};h.prototype.pasteFromClipboard=function(){var a=localStorage.getItem("litegrapheditor_clipboard");if(a){for(var a=JSON.parse(a),b=[],d=0;d<a.nodes.length;++d){var c=a.nodes[d],f=l.createNode(c.type);f&&(f.configure(c),f.pos[0]+=5,f.pos[1]+=
5,this.graph.add(f),b.push(f))}for(d=0;d<a.links.length;++d)c=a.links[d],b[c[0]].connect(c[1],b[c[2]],c[3]);this.selectNodes(b)}};h.prototype.processDrop=function(a){a.preventDefault();this.adjustMouseEvent(a);var b=[a.canvasX,a.canvasY],d=this.graph.getNodeOnPos(b[0],b[1]);if(d){if((d.onDropFile||d.onDropData)&&(b=a.dataTransfer.files)&&b.length)for(var c=0;c<b.length;c++){var f=a.dataTransfer.files[0],m=f.name;h.getFileExtension(m);if(d.onDropFile)d.onDropFile(f);if(d.onDropData){var k=new FileReader;
k.onload=function(a){d.onDropData(a.target.result,m,f)};var e=f.type.split("/")[0];"text"==e||""==e?k.readAsText(f):"image"==e?k.readAsDataURL(f):k.readAsArrayBuffer(f)}}return d.onDropItem&&d.onDropItem(event)?!0:this.onDropItem?this.onDropItem(event):!1}b=null;this.onDropItem&&(b=this.onDropItem(event));b||this.checkDropItem(a)};h.prototype.checkDropItem=function(a){if(a.dataTransfer.files.length){var b=a.dataTransfer.files[0],d=h.getFileExtension(b.name).toLowerCase();if(d=l.node_types_by_file_extension[d])if(d=
l.createNode(d.type),d.pos=[a.canvasX,a.canvasY],this.graph.add(d),d.onDropFile)d.onDropFile(b)}};h.prototype.processNodeDblClicked=function(a){if(this.onShowNodePanel)this.onShowNodePanel(a);if(this.onNodeDblClicked)this.onNodeDblClicked(a);this.setDirty(!0)};h.prototype.processNodeSelected=function(a,b){this.selectNode(a,b&&b.shiftKey);if(this.onNodeSelected)this.onNodeSelected(a)};h.prototype.processNodeDeselected=function(a){this.deselectNode(a);if(this.onNodeDeselected)this.onNodeDeselected(a)};
h.prototype.selectNode=function(a,b){null==a?this.deselectAllNodes():this.selectNodes([a],b)};h.prototype.selectNodes=function(a,b){b||this.deselectAllNodes();a=a||this.graph._nodes;for(var d=0;d<a.length;++d){var c=a[d];if(!c.selected){if(!c.selected&&c.onSelected)c.onSelected();c.selected=!0;this.selected_nodes[c.id]=c;if(c.inputs)for(d=0;d<c.inputs.length;++d)this.highlighted_links[c.inputs[d].link]=!0;if(c.outputs)for(d=0;d<c.outputs.length;++d){var f=c.outputs[d];if(f.links)for(var m=0;m<f.links.length;++m)this.highlighted_links[f.links[m]]=
!0}}}this.setDirty(!0)};h.prototype.deselectNode=function(a){if(a.selected){if(a.onDeselected)a.onDeselected();a.selected=!1;if(a.inputs)for(var b=0;b<a.inputs.length;++b)delete this.highlighted_links[a.inputs[b].link];if(a.outputs)for(b=0;b<a.outputs.length;++b){var d=a.outputs[b];if(d.links)for(var c=0;c<d.links.length;++c)delete this.highlighted_links[d.links[c]]}}};h.prototype.deselectAllNodes=function(){if(this.graph){for(var a=this.graph._nodes,b=0,d=a.length;b<d;++b){var c=a[b];if(c.selected){if(c.onDeselected)c.onDeselected();
c.selected=!1}}this.selected_nodes={};this.highlighted_links={};this.setDirty(!0)}};h.prototype.deleteSelectedNodes=function(){for(var a in this.selected_nodes)this.graph.remove(this.selected_nodes[a]);this.selected_nodes={};this.highlighted_links={};this.setDirty(!0)};h.prototype.centerOnNode=function(a){this.offset[0]=-a.pos[0]-0.5*a.size[0]+0.5*this.canvas.width/this.scale;this.offset[1]=-a.pos[1]-0.5*a.size[1]+0.5*this.canvas.height/this.scale;this.setDirty(!0,!0)};h.prototype.adjustMouseEvent=
function(a){var b=this.canvas.getBoundingClientRect();a.localX=a.pageX-b.left;a.localY=a.pageY-b.top;a.canvasX=a.localX/this.scale-this.offset[0];a.canvasY=a.localY/this.scale-this.offset[1]};h.prototype.setZoom=function(a,b){b||(b=[0.5*this.canvas.width,0.5*this.canvas.height]);var d=this.convertOffsetToCanvas(b);this.scale=a;this.scale>this.max_zoom?this.scale=this.max_zoom:this.scale<this.min_zoom&&(this.scale=this.min_zoom);var c=this.convertOffsetToCanvas(b),d=[c[0]-d[0],c[1]-d[1]];this.offset[0]+=
d[0];this.offset[1]+=d[1];this.dirty_bgcanvas=this.dirty_canvas=!0};h.prototype.convertOffsetToCanvas=function(a,b){b=b||[];b[0]=a[0]/this.scale-this.offset[0];b[1]=a[1]/this.scale-this.offset[1];return b};h.prototype.convertCanvasToOffset=function(a,b){b=b||[];b[0]=(a[0]+this.offset[0])*this.scale;b[1]=(a[1]+this.offset[1])*this.scale;return b};h.prototype.convertEventToCanvas=function(a){var b=this.canvas.getBoundingClientRect();return this.convertOffsetToCanvas([a.pageX-b.left,a.pageY-b.top])};
h.prototype.bringToFront=function(a){var b=this.graph._nodes.indexOf(a);-1!=b&&(this.graph._nodes.splice(b,1),this.graph._nodes.push(a))};h.prototype.sendToBack=function(a){var b=this.graph._nodes.indexOf(a);-1!=b&&(this.graph._nodes.splice(b,1),this.graph._nodes.unshift(a))};var s=new Float32Array(4);h.prototype.computeVisibleNodes=function(a,b){var d=b||[];d.length=0;a=a||this.graph._nodes;for(var c=0,f=a.length;c<f;++c){var m=a[c];(!this.live_mode||m.onDrawBackground||m.onDrawForeground)&&q(this.visible_area,
m.getBounding(s))&&d.push(m)}return d};h.prototype.draw=function(a,b){if(this.canvas){var d=l.getTime();this.render_time=0.001*(d-this.last_draw_time);this.last_draw_time=d;if(this.graph){var c=[-this.offset[0],-this.offset[1]],f=[c[0]+this.canvas.width/this.scale,c[1]+this.canvas.height/this.scale];this.visible_area=new Float32Array([c[0],c[1],f[0]-c[0],f[1]-c[1]])}(this.dirty_bgcanvas||b||this.always_render_background||this.graph&&this.graph._last_trigger_time&&1E3>d-this.graph._last_trigger_time)&&
this.drawBackCanvas();(this.dirty_canvas||a)&&this.drawFrontCanvas();this.fps=this.render_time?1/this.render_time:0;this.frame+=1}};h.prototype.drawFrontCanvas=function(){this.ctx||(this.ctx=this.bgcanvas.getContext("2d"));var a=this.ctx;if(a){a.start2D&&a.start2D();var b=this.canvas;a.restore();a.setTransform(1,0,0,1,0,0);this.dirty_area&&(a.save(),a.beginPath(),a.rect(this.dirty_area[0],this.dirty_area[1],this.dirty_area[2],this.dirty_area[3]),a.clip());this.clear_background&&a.clearRect(0,0,b.width,
b.height);this.bgcanvas==this.canvas?this.drawBackCanvas():a.drawImage(this.bgcanvas,0,0);if(this.onRender)this.onRender(b,a);this.show_info&&this.renderInfo(a);if(this.graph){a.save();a.scale(this.scale,this.scale);a.translate(this.offset[0],this.offset[1]);for(var b=this.computeVisibleNodes(null,this.visible_nodes),d=0;d<b.length;++d){var c=b[d];a.save();a.translate(c.pos[0],c.pos[1]);this.drawNode(c,a);a.restore()}this.graph.config.links_ontop&&(this.live_mode||this.drawConnections(a));if(null!=
this.connecting_pos){a.lineWidth=this.connections_width;b=null;switch(this.connecting_output.type){case l.EVENT:b="#F85";break;default:b="#AFA"}this.renderLink(a,this.connecting_pos,[this.canvas_mouse[0],this.canvas_mouse[1]],null,!1,null,b);a.beginPath();this.connecting_output.type===l.EVENT?a.rect(this.connecting_pos[0]-6+0.5,this.connecting_pos[1]-5+0.5,14,10):a.arc(this.connecting_pos[0],this.connecting_pos[1],4,0,2*Math.PI);a.fill();a.fillStyle="#ffcc00";this._highlight_input&&(a.beginPath(),
a.arc(this._highlight_input[0],this._highlight_input[1],6,0,2*Math.PI),a.fill())}this.dragging_rectangle&&(a.strokeStyle="#FFF",a.strokeRect(this.dragging_rectangle[0],this.dragging_rectangle[1],this.dragging_rectangle[2],this.dragging_rectangle[3]));a.restore()}this.dirty_area&&a.restore();a.finish2D&&a.finish2D();this.dirty_canvas=!1}};h.prototype.renderInfo=function(a,b,d){b=b||0;d=d||0;a.save();a.translate(b,d);a.font="10px Arial";a.fillStyle="#888";this.graph?(a.fillText("T: "+this.graph.globaltime.toFixed(2)+
"s",5,13),a.fillText("I: "+this.graph.iteration,5,26),a.fillText("F: "+this.frame,5,39),a.fillText("FPS:"+this.fps.toFixed(2),5,52)):a.fillText("No graph selected",5,13);a.restore()};h.prototype.drawBackCanvas=function(){var a=this.bgcanvas;if(a.width!=this.canvas.width||a.height!=this.canvas.height)a.width=this.canvas.width,a.height=this.canvas.height;this.bgctx||(this.bgctx=this.bgcanvas.getContext("2d"));var b=this.bgctx;b.start&&b.start();this.clear_background&&b.clearRect(0,0,a.width,a.height);
this._graph_stack&&this._graph_stack.length&&(b.strokeStyle=this._graph_stack[this._graph_stack.length-1].bgcolor,b.lineWidth=10,b.strokeRect(1,1,a.width-2,a.height-2),b.lineWidth=1);b.restore();b.setTransform(1,0,0,1,0,0);if(this.graph){b.save();b.scale(this.scale,this.scale);b.translate(this.offset[0],this.offset[1]);if(this.background_image&&0.5<this.scale){b.globalAlpha=this.zoom_modify_alpha?(1-0.5/this.scale)*this.editor_alpha:this.editor_alpha;b.imageSmoothingEnabled=b.mozImageSmoothingEnabled=
b.imageSmoothingEnabled=!1;if(!this._bg_img||this._bg_img.name!=this.background_image){this._bg_img=new Image;this._bg_img.name=this.background_image;this._bg_img.src=this.background_image;var d=this;this._bg_img.onload=function(){d.draw(!0,!0)}}var c=null;null==this._pattern&&0<this._bg_img.width?(c=b.createPattern(this._bg_img,"repeat"),this._pattern_img=this._bg_img,this._pattern=c):c=this._pattern;c&&(b.fillStyle=c,b.fillRect(this.visible_area[0],this.visible_area[1],this.visible_area[2],this.visible_area[3]),
b.fillStyle="transparent");b.globalAlpha=1;b.imageSmoothingEnabled=b.mozImageSmoothingEnabled=b.imageSmoothingEnabled=!0}if(this.onBackgroundRender)this.onBackgroundRender(a,b);this.render_canvas_border&&(b.strokeStyle="#235",b.strokeRect(0,0,a.width,a.height));this.render_connections_shadows?(b.shadowColor="#000",b.shadowOffsetX=0,b.shadowOffsetY=0,b.shadowBlur=6):b.shadowColor="rgba(0,0,0,0)";this.live_mode||this.drawConnections(b);b.shadowColor="rgba(0,0,0,0)";b.restore()}b.finish&&b.finish();
this.dirty_bgcanvas=!1;this.dirty_canvas=!0};var c=new Float32Array(2);h.prototype.drawNode=function(a,b){var d=a.color||l.NODE_DEFAULT_COLOR,h=!0;if(a.flags.skip_title_render||a.graph.isLive())h=!1;a.mouseOver&&(h=!0);a.selected||(this.render_shadows?(b.shadowColor="rgba(0,0,0,0.5)",b.shadowOffsetX=2,b.shadowOffsetY=2,b.shadowBlur=3):b.shadowColor="transparent");if(this.live_mode){if(!a.flags.collapsed&&(b.shadowColor="transparent",a.onDrawForeground))a.onDrawForeground(b)}else{var f=this.editor_alpha;
b.globalAlpha=f;var m=a._shape||l.BOX_SHAPE;c.set(a.size);a.flags.collapsed&&(c[0]=l.NODE_COLLAPSED_WIDTH,c[1]=0);a.flags.clip_area&&(b.save(),m==l.BOX_SHAPE?(b.beginPath(),b.rect(0,0,c[0],c[1])):m==l.ROUND_SHAPE?b.roundRect(0,0,c[0],c[1],10):m==l.CIRCLE_SHAPE&&(b.beginPath(),b.arc(0.5*c[0],0.5*c[1],0.5*c[0],0,2*Math.PI)),b.clip());this.drawNodeShape(a,b,c,d,a.bgcolor,!h,a.selected);b.shadowColor="transparent";b.textAlign="left";b.font=this.inner_text_font;h=0.6<this.scale;m=this.connecting_output;
if(!a.flags.collapsed){if(a.inputs)for(var k=0;k<a.inputs.length;k++){var e=a.inputs[k];b.globalAlpha=f;this.connecting_node&&l.isValidConnection(e.type&&m.type)&&(b.globalAlpha=0.4*f);b.fillStyle=null!=e.link?this.default_connection_color.input_on:this.default_connection_color.input_off;var g=a.getConnectionPos(!0,k);g[0]-=a.pos[0];g[1]-=a.pos[1];b.beginPath();e.type===l.EVENT?b.rect(g[0]-6+0.5,g[1]-5+0.5,14,10):b.arc(g[0],g[1],4,0,2*Math.PI);b.fill();h&&(e=null!=e.label?e.label:e.name)&&(b.fillStyle=
d,b.fillText(e,g[0]+10,g[1]+5))}this.connecting_node&&(b.globalAlpha=0.4*f);b.lineWidth=1;b.textAlign="right";b.strokeStyle="black";if(a.outputs)for(k=0;k<a.outputs.length;k++)if(e=a.outputs[k],g=a.getConnectionPos(!1,k),g[0]-=a.pos[0],g[1]-=a.pos[1],b.fillStyle=e.links&&e.links.length?this.default_connection_color.output_on:this.default_connection_color.output_off,b.beginPath(),e.type===l.EVENT?b.rect(g[0]-6+0.5,g[1]-5+0.5,14,10):b.arc(g[0],g[1],4,0,2*Math.PI),b.fill(),b.stroke(),h&&(e=null!=e.label?
e.label:e.name))b.fillStyle=d,b.fillText(e,g[0]-10,g[1]+5);b.textAlign="left";b.globalAlpha=1;if(a.onDrawForeground)a.onDrawForeground(b)}a.flags.clip_area&&b.restore();b.globalAlpha=1}};h.prototype.drawNodeShape=function(a,b,d,c,f,e,k){b.strokeStyle=c||l.NODE_DEFAULT_COLOR;b.fillStyle=f||l.NODE_DEFAULT_BGCOLOR;f=l.NODE_TITLE_HEIGHT;var h=a._shape||l.BOX_SHAPE;h==l.BOX_SHAPE?(b.beginPath(),b.rect(0,e?0:-f,d[0]+1,e?d[1]:d[1]+f),b.fill(),b.shadowColor="transparent",k&&(b.strokeStyle="#CCC",b.strokeRect(-0.5,
e?-0.5:-f+-0.5,d[0]+2,e?d[1]+2:d[1]+f+2-1),b.strokeStyle=c)):h==l.ROUND_SHAPE?(b.roundRect(0,e?0:-f,d[0],e?d[1]:d[1]+f,10),b.fill()):h==l.CIRCLE_SHAPE&&(b.beginPath(),b.arc(0.5*d[0],0.5*d[1],0.5*d[0],0,2*Math.PI),b.fill());b.shadowColor="transparent";a.bgImage&&a.bgImage.width&&b.drawImage(a.bgImage,0.5*(d[0]-a.bgImage.width),0.5*(d[1]-a.bgImage.height));a.bgImageUrl&&!a.bgImage&&(a.bgImage=a.loadImage(a.bgImageUrl));if(a.onDrawBackground)a.onDrawBackground(b);e||(b.fillStyle=c||l.NODE_DEFAULT_COLOR,
c=b.globalAlpha,b.globalAlpha=0.5*c,h==l.BOX_SHAPE?(b.beginPath(),b.rect(0,-f,d[0]+1,f),b.fill()):h==l.ROUND_SHAPE&&(b.roundRect(0,-f,d[0],f,10,0),b.fill()),b.fillStyle=a.boxcolor||l.NODE_DEFAULT_BOXCOLOR,b.beginPath(),h==l.ROUND_SHAPE||h==l.CIRCLE_SHAPE?b.arc(0.5*f,-0.5*f,0.5*(f-6),0,2*Math.PI):b.rect(3,-f+3,f-6,f-6),b.fill(),b.globalAlpha=c,b.font=this.title_text_font,(a=a.getTitle())&&0.5<this.scale&&(b.fillStyle=this.node_title_color,b.fillText(a,16,13-f)))};h.prototype.drawNodeCollapsed=function(a,
b,c,e){b.strokeStyle=c||l.NODE_DEFAULT_COLOR;b.fillStyle=e||l.NODE_DEFAULT_BGCOLOR;c=l.NODE_COLLAPSED_RADIUS;e=a._shape||l.BOX_SHAPE;e==l.CIRCLE_SHAPE?(b.beginPath(),b.arc(0.5*a.size[0],0.5*a.size[1],c,0,2*Math.PI),b.fill(),b.shadowColor="rgba(0,0,0,0)",b.stroke(),b.fillStyle=a.boxcolor||l.NODE_DEFAULT_BOXCOLOR,b.beginPath(),b.arc(0.5*a.size[0],0.5*a.size[1],0.5*c,0,2*Math.PI)):e==l.ROUND_SHAPE?(b.beginPath(),b.roundRect(0.5*a.size[0]-c,0.5*a.size[1]-c,2*c,2*c,5),b.fill(),b.shadowColor="rgba(0,0,0,0)",
b.stroke(),b.fillStyle=a.boxcolor||l.NODE_DEFAULT_BOXCOLOR,b.beginPath(),b.roundRect(0.5*a.size[0]-0.5*c,0.5*a.size[1]-0.5*c,c,c,2)):(b.beginPath(),b.rect(0,0,a.size[0],2*c),b.fill(),b.shadowColor="rgba(0,0,0,0)",b.stroke(),b.fillStyle=a.boxcolor||l.NODE_DEFAULT_BOXCOLOR,b.beginPath(),b.rect(0.5*c,0.5*c,c,c));b.fill()};h.prototype.drawConnections=function(a){var b=l.getTime();a.lineWidth=this.connections_width;a.fillStyle="#AAA";a.strokeStyle="#AAA";a.globalAlpha=this.editor_alpha;for(var c=0,e=this.graph._nodes.length;c<
e;++c){var f=this.graph._nodes[c];if(f.inputs&&f.inputs.length)for(var h=0;h<f.inputs.length;++h){var k=f.inputs[h];if(k&&null!=k.link&&(k=this.graph.links[k.link])){var g=this.graph.getNodeById(k.origin_id);if(null!=g){var n=k.origin_slot,p=null,p=-1==n?[g.pos[0]+10,g.pos[1]+10]:g.getConnectionPos(!1,n);this.renderLink(a,p,f.getConnectionPos(!0,h),k);k&&k._last_time&&1E3>b-k._last_time&&(g=2-0.002*(b-k._last_time),n="rgba(255,255,255, "+g.toFixed(2)+")",this.renderLink(a,p,f.getConnectionPos(!0,
h),k,!0,g,n))}}}}a.globalAlpha=1};h.prototype.renderLink=function(a,b,c,e,f,m,k){if(this.highquality_render){var g=n(b,c);this.render_connections_border&&0.6<this.scale&&(a.lineWidth=this.connections_width+4);!k&&e&&(k=h.link_type_colors[e.type]);k||(k=this.default_link_color);null!=e&&this.highlighted_links[e.id]&&(k="#FFF");a.beginPath();this.render_curved_connections?(a.moveTo(b[0],b[1]),a.bezierCurveTo(b[0]+0.25*g,b[1],c[0]-0.25*g,c[1],c[0],c[1])):(a.moveTo(b[0]+10,b[1]),a.lineTo(0.5*(b[0]+10+
(c[0]-10)),b[1]),a.lineTo(0.5*(b[0]+10+(c[0]-10)),c[1]),a.lineTo(c[0]-10,c[1]));this.render_connections_border&&0.6<this.scale&&!f&&(a.strokeStyle="rgba(0,0,0,0.5)",a.stroke());a.lineWidth=this.connections_width;a.fillStyle=a.strokeStyle=k;a.stroke();this.render_connection_arrows&&0.6<=this.scale&&this.render_connection_arrows&&0.6<this.scale&&(e=this.computeConnectionPoint(b,c,0.5),f=this.computeConnectionPoint(b,c,0.51),k=0,k=this.render_curved_connections?-Math.atan2(f[0]-e[0],f[1]-e[1]):c[1]>
b[1]?0:Math.PI,a.save(),a.translate(e[0],e[1]),a.rotate(k),a.beginPath(),a.moveTo(-5,-5),a.lineTo(0,5),a.lineTo(5,-5),a.fill(),a.restore());if(m)for(m=0;5>m;++m)e=(0.001*l.getTime()+0.2*m)%1,e=this.computeConnectionPoint(b,c,e),a.beginPath(),a.arc(e[0],e[1],5,0,2*Math.PI),a.fill()}else a.beginPath(),a.moveTo(b[0],b[1]),a.lineTo(c[0],c[1]),a.stroke()};h.prototype.computeConnectionPoint=function(a,b,c){var e=n(a,b),f=[a[0]+0.25*e,a[1]],e=[b[0]-0.25*e,b[1]],h=(1-c)*(1-c)*(1-c),k=3*(1-c)*(1-c)*c,g=3*
(1-c)*c*c;c*=c*c;return[h*a[0]+k*f[0]+g*e[0]+c*b[0],h*a[1]+k*f[1]+g*e[1]+c*b[1]]};h.prototype.resize=function(a,b){if(!a&&!b){var c=this.canvas.parentNode;a=c.offsetWidth;b=c.offsetHeight}if(this.canvas.width!=a||this.canvas.height!=b)this.canvas.width=a,this.canvas.height=b,this.bgcanvas.width=this.canvas.width,this.bgcanvas.height=this.canvas.height,this.setDirty(!0,!0)};h.prototype.switchLiveMode=function(a){if(a){var b=this,c=this.live_mode?1.1:0.9;this.live_mode&&(this.live_mode=!1,this.editor_alpha=
0.1);var e=setInterval(function(){b.editor_alpha*=c;b.dirty_canvas=!0;b.dirty_bgcanvas=!0;1>c&&0.01>b.editor_alpha&&(clearInterval(e),1>c&&(b.live_mode=!0));1<c&&0.99<b.editor_alpha&&(clearInterval(e),b.editor_alpha=1)},1)}else this.live_mode=!this.live_mode,this.dirty_bgcanvas=this.dirty_canvas=!0};h.prototype.onNodeSelectionChange=function(a){};h.prototype.touchHandler=function(a){var b=a.changedTouches[0],c="";switch(a.type){case "touchstart":c="mousedown";break;case "touchmove":c="mousemove";
break;case "touchend":c="mouseup";break;default:return}var e=this.getCanvasWindow(),f=e.document.createEvent("MouseEvent");f.initMouseEvent(c,!0,!0,e,1,b.screenX,b.screenY,b.clientX,b.clientY,!1,!1,!1,!1,0,null);b.target.dispatchEvent(f);a.preventDefault()};h.onMenuAdd=function(a,b,c,e){function f(a,b){var c=e.getFirstEvent(),d=l.createNode(a.value);d&&(d.pos=g.convertEventToCanvas(c),g.graph.add(d))}var g=h.active_canvas,k=g.getCanvasWindow();a=l.getNodeTypesCategories();b=[];for(var n in a)a[n]&&
b.push({value:a[n],content:a[n],has_submenu:!0});var p=new l.ContextMenu(b,{event:c,callback:function(a,b,c){a=l.getNodeTypesInCategory(a.value);b=[];for(var d in a)b.push({content:a[d].title,value:a[d].type});new l.ContextMenu(b,{event:c,callback:f,parentMenu:p},k);return!1},parentMenu:e},k);return!1};h.onMenuCollapseAll=function(){};h.onMenuNodeEdit=function(){};h.showMenuNodeOptionalInputs=function(a,b,c,e,f){function g(a,b,c){f&&(a.callback&&a.callback.call(k,f,a,b,c),a.value&&(f.addInput(a.value[0],
a.value[1],a.value[2]),f.setDirtyCanvas(!0,!0)))}if(f){var k=this;a=h.active_canvas.getCanvasWindow();b=f.optional_inputs;f.onGetInputs&&(b=f.onGetInputs());var n=[];if(b)for(var p in b){var q=b[p];if(q){var r=q[0];q[2]&&q[2].label&&(r=q[2].label);r={content:r,value:q};q[1]==l.ACTION&&(r.className="event");n.push(r)}else n.push(null)}this.onMenuNodeInputs&&(n=this.onMenuNodeInputs(n));if(n.length)return new l.ContextMenu(n,{event:c,callback:g,parentMenu:e,node:f},a),!1}};h.showMenuNodeOptionalOutputs=
function(a,b,c,e,f){function g(a,b,c){if(f&&(a.callback&&a.callback.call(k,f,a,b,c),a.value))if(c=a.value[1],!c||c.constructor!==Object&&c.constructor!==Array)f.addOutput(a.value[0],a.value[1],a.value[2]),f.setDirtyCanvas(!0,!0);else{a=[];for(var d in c)a.push({content:d,value:c[d]});new l.ContextMenu(a,{event:b,callback:g,parentMenu:e,node:f});return!1}}if(f){var k=this;a=h.active_canvas.getCanvasWindow();b=f.optional_outputs;f.onGetOutputs&&(b=f.onGetOutputs());var n=[];if(b)for(var p in b){var q=
b[p];if(!q)n.push(null);else if(!f.flags||!f.flags.skip_repeated_outputs||-1==f.findOutputSlot(q[0])){var r=q[0];q[2]&&q[2].label&&(r=q[2].label);r={content:r,value:q};q[1]==l.EVENT&&(r.className="event");n.push(r)}}this.onMenuNodeOutputs&&(n=this.onMenuNodeOutputs(n));if(n.length)return new l.ContextMenu(n,{event:c,callback:g,parentMenu:e,node:f},a),!1}};h.onShowMenuNodeProperties=function(a,b,c,e,f){function g(a,b,c,d){f&&(b=this.getBoundingClientRect(),k.showEditPropertyValue(f,a.value,{position:[b.left,
b.top]}))}if(f&&f.properties){var k=h.active_canvas;b=k.getCanvasWindow();var n=[],p;for(p in f.properties)a=void 0!==f.properties[p]?f.properties[p]:" ",a=h.decodeHTML(a),n.push({content:"<span class='property_name'>"+p+"</span><span class='property_value'>"+a+"</span>",value:p});if(n.length)return new l.ContextMenu(n,{event:c,callback:g,parentMenu:e,allow_html:!0,node:f},b),!1}};h.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};h.onResizeNode=function(a,
b,c,e,f){f&&(f.size=f.computeSize(),f.setDirtyCanvas(!0,!0))};h.onShowTitleEditor=function(a,b,c,e,f){function g(){f.title=n.value;k.parentNode.removeChild(k);f.setDirtyCanvas(!0,!0)}var k=document.createElement("div");k.className="graphdialog";k.innerHTML="<span class='name'>Title</span><input autofocus type='text' class='value'/><button>OK</button>";var n=k.querySelector("input");n&&(n.value=f.title,n.addEventListener("keydown",function(a){13==a.keyCode&&(g(),a.preventDefault(),a.stopPropagation())}));
a=h.active_canvas.canvas;b=a.getBoundingClientRect();e=c=-20;b&&(c-=b.left,e-=b.top);event?(k.style.left=event.pageX+c+"px",k.style.top=event.pageY+e+"px"):(k.style.left=0.5*a.width+c+"px",k.style.top=0.5*a.height+e+"px");k.querySelector("button").addEventListener("click",g);a.parentNode.appendChild(k)};h.prototype.showEditPropertyValue=function(a,b,c){function e(){f(q.value)}function f(c){"number"==typeof a.properties[b]&&(c=Number(c));a.properties[b]=c;if(a.onPropertyChanged)a.onPropertyChanged(b,
c);p.close();a.setDirtyCanvas(!0,!0)}if(a&&void 0!==a.properties[b]){c=c||{};var h="string";null!==a.properties[b]&&(h=typeof a.properties[b]);var k=null;a.getPropertyInfo&&(k=a.getPropertyInfo(b));if(a.properties_info)for(var g=0;g<a.properties_info.length;++g)if(a.properties_info[g].name==b){k=a.properties_info[g];break}void 0!==k&&null!==k&&k.type&&(h=k.type);var n="";if("string"==h||"number"==h)n="<input autofocus type='text' class='value'/>";else if("enum"==h&&k.values){n="<select autofocus type='text' class='value'>";
for(g in k.values)var l=k.values.constructor===Array?k.values[g]:g,n=n+("<option value='"+l+"' "+(l==a.properties[b]?"selected":"")+">"+k.values[g]+"</option>");n+="</select>"}else"boolean"==h&&(n="<input autofocus type='checkbox' class='value' "+(a.properties[b]?"checked":"")+"/>");var p=this.createDialog("<span class='name'>"+b+"</span>"+n+"<button>OK</button>",c);if("enum"==h&&k.values){var q=p.querySelector("select");q.addEventListener("change",function(a){f(a.target.value)})}else if("boolean"==
h)(q=p.querySelector("input"))&&q.addEventListener("click",function(a){f(!!q.checked)});else if(q=p.querySelector("input"))q.value=void 0!==a.properties[b]?a.properties[b]:"",q.addEventListener("keydown",function(a){13==a.keyCode&&(e(),a.preventDefault(),a.stopPropagation())});p.querySelector("button").addEventListener("click",e)}};h.prototype.createDialog=function(a,b){b=b||{};var c=document.createElement("div");c.className="graphdialog";c.innerHTML=a;var e=this.canvas.getBoundingClientRect(),f=
-20,h=-20;e&&(f-=e.left,h-=e.top);b.position?(f+=b.position[0],h+=b.position[1]):b.event?(f+=b.event.pageX,h+=b.event.pageY):(f+=0.5*this.canvas.width,h+=0.5*this.canvas.height);c.style.left=f+"px";c.style.top=h+"px";this.canvas.parentNode.appendChild(c);c.close=function(){this.parentNode&&this.parentNode.removeChild(this)};return c};h.onMenuNodeCollapse=function(a,b,c,e,f){f.flags.collapsed=!f.flags.collapsed;f.setDirtyCanvas(!0,!0)};h.onMenuNodePin=function(a,b,c,e,f){f.pin()};h.onMenuNodeMode=
function(a,b,c,e,f){new l.ContextMenu(["Always","On Event","On Trigger","Never"],{event:c,callback:function(a){if(f)switch(a){case "On Event":f.mode=l.ON_EVENT;break;case "On Trigger":f.mode=l.ON_TRIGGER;break;case "Never":f.mode=l.NEVER;break;default:f.mode=l.ALWAYS}},parentMenu:e,node:f});return!1};h.onMenuNodeColors=function(a,b,c,e,f){if(!f)throw"no node for color";b=[];for(var g in h.node_colors)a=h.node_colors[g],a={value:g,content:"<span style='display: block; color:"+a.color+"; background-color:"+
a.bgcolor+"'>"+g+"</span>"},b.push(a);new l.ContextMenu(b,{event:c,callback:function(a){f&&(a=h.node_colors[a.value])&&(f.color=a.color,f.bgcolor=a.bgcolor,f.setDirtyCanvas(!0))},parentMenu:e,node:f});return!1};h.onMenuNodeShapes=function(a,b,c,e,f){if(!f)throw"no node passed";new l.ContextMenu(l.VALID_SHAPES,{event:c,callback:function(a){f&&(f.shape=a,f.setDirtyCanvas(!0))},parentMenu:e,node:f});return!1};h.onMenuNodeRemove=function(a,b,c,e,f){if(!f)throw"no node passed";!1!=f.removable&&(f.graph.remove(f),
f.setDirtyCanvas(!0,!0))};h.onMenuNodeClone=function(a,b,c,e,f){!1!=f.clonable&&(a=f.clone())&&(a.pos=[f.pos[0]+5,f.pos[1]+5],f.graph.add(a),f.setDirtyCanvas(!0,!0))};h.node_colors={red:{color:"#FAA",bgcolor:"#944"},green:{color:"#AFA",bgcolor:"#494"},blue:{color:"#AAF",bgcolor:"#449"},cyan:{color:"#AFF",bgcolor:"#499"},purple:{color:"#FAF",bgcolor:"#949"},yellow:{color:"#FFA",bgcolor:"#994"},black:{color:"#777",bgcolor:"#000"},white:{color:"#FFF",bgcolor:"#AAA"}};h.prototype.getCanvasMenuOptions=
function(){var a=null;this.getMenuOptions?a=this.getMenuOptions():(a=[{content:"Add Node",has_submenu:!0,callback:h.onMenuAdd}],this._graph_stack&&0<this._graph_stack.length&&(a=[{content:"Close subgraph",callback:this.closeSubgraph.bind(this)},null].concat(a)));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.onShowTitleEditor},{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.getExtraMenuOptions){var c=a.getExtraMenuOptions(this);c&&(c.push(null),b=c.concat(b))}!1!==a.clonable&&b.push({content:"Clone",callback:h.onMenuNodeClone});!1!==a.removable&&b.push(null,{content:"Remove",callback:h.onMenuNodeRemove});a.onGetInputs&&(c=a.onGetInputs())&&c.length&&(b[0].disabled=!1);a.onGetOutputs&&(c=a.onGetOutputs())&&c.length&&(b[1].disabled=!1);if(a.graph&&a.graph.onGetNodeMenuOptions)a.graph.onGetNodeMenuOptions(b,
a);return b};h.prototype.processContextMenu=function(a,b){var c=this,e=h.active_canvas.getCanvasWindow(),f=null,g={event:b,callback:function(b,f,e){if(b)if("Remove Slot"==b.content){var k=b.slot;k.input?a.removeInput(k.slot):k.output&&a.removeOutput(k.slot)}else if("Rename Slot"==b.content){var k=b.slot,h=c.createDialog("<span class='name'>Name</span><input type='text'/><button>OK</button>",f),g=h.querySelector("input");h.querySelector("button").addEventListener("click",function(b){if(g.value){if(b=
k.input?a.getInputInfo(k.slot):a.getOutputInfo(k.slot))b.label=g.value;c.setDirty(!0)}h.close()})}},node:a},k=null;a&&(k=a.getSlotInPosition(b.canvasX,b.canvasY),h.active_node=a);k?(f=[],f.push(k.locked?"Cannot remove":{content:"Remove Slot",slot:k}),f.push({content:"Rename Slot",slot:k}),g.title=(k.input?k.input.type:k.output.type)||"*",k.input&&k.input.type==l.ACTION&&(g.title="Action"),k.output&&k.output.type==l.EVENT&&(g.title="Event")):f=a?this.getNodeMenuOptions(a):this.getCanvasMenuOptions();
f&&new l.ContextMenu(f,g,e)};this.CanvasRenderingContext2D&&(CanvasRenderingContext2D.prototype.roundRect=function(a,b,c,e,f,h){void 0===f&&(f=5);void 0===h&&(h=f);this.beginPath();this.moveTo(a+f,b);this.lineTo(a+c-f,b);this.quadraticCurveTo(a+c,b,a+c,b+f);this.lineTo(a+c,b+e-h);this.quadraticCurveTo(a+c,b+e,a+c-h,b+e);this.lineTo(a+h,b+e);this.quadraticCurveTo(a,b+e,a,b+e-h);this.lineTo(a,b+f);this.quadraticCurveTo(a,b,a+f,b)});l.compareObjects=function(a,b){for(var c in a)if(a[c]!=b[c])return!1;
return!0};l.distance=n;l.colorToString=function(a){return"rgba("+Math.round(255*a[0]).toFixed()+","+Math.round(255*a[1]).toFixed()+","+Math.round(255*a[2]).toFixed()+","+(4==a.length?a[3].toFixed(2):"1.0")+")"};l.isInsideRectangle=p;l.growBounding=function(a,b,c){b<a[0]?a[0]=b:b>a[2]&&(a[2]=b);c<a[1]?a[1]=c:c>a[3]&&(a[3]=c)};l.isInsideBounding=function(a,b){return a[0]<b[0][0]||a[1]<b[0][1]||a[0]>b[1][0]||a[1]>b[1][1]?!1:!0};l.overlapBounding=q;l.hex2num=function(a){"#"==a.charAt(0)&&(a=a.slice(1));
a=a.toUpperCase();for(var b=Array(3),c=0,e,f,h=0;6>h;h+=2)e="0123456789ABCDEF".indexOf(a.charAt(h)),f="0123456789ABCDEF".indexOf(a.charAt(h+1)),b[c]=16*e+f,c++;return b};l.num2hex=function(a){for(var b="#",c,e,f=0;3>f;f++)c=a[f]/16,e=a[f]%16,b+="0123456789ABCDEF".charAt(c)+"0123456789ABCDEF".charAt(e);return b};r.prototype.addItem=function(a,b,c){function e(a){var b=this.value;b&&b.has_submenu&&f.call(this,a)}function f(a){var b=this.value,f=!0;h.current_submenu&&h.current_submenu.close(a);if(c.callback){var e=
c.callback.call(this,b,c,a,h,c.node);!0===e&&(f=!1)}if(b&&(b.callback&&!c.ignore_item_callbacks&&!0!==b.disabled&&(e=b.callback.call(this,b,c,a,h,c.node),!0===e&&(f=!1)),b.submenu)){if(!b.submenu.options)throw"ContextMenu submenu needs options";new h.constructor(b.submenu.options,{callback:b.submenu.callback,event:a,parentMenu:h,ignore_item_callbacks:b.submenu.ignore_item_callbacks,title:b.submenu.title,autoopen:c.autoopen});f=!1}f&&!h.lock&&h.close()}var h=this;c=c||{};var k=document.createElement("div");
k.className="litemenu-entry submenu";var g=!1;if(null===b)k.classList.add("separator");else{k.innerHTML=b&&b.title?b.title:a;if(k.value=b)b.disabled&&(g=!0,k.classList.add("disabled")),(b.submenu||b.has_submenu)&&k.classList.add("has_submenu");"function"==typeof b?(k.dataset.value=a,k.onclick_callback=b):k.dataset.value=b;b.className&&(k.className+=" "+b.className)}this.root.appendChild(k);g||k.addEventListener("click",f);c.autoopen&&k.addEventListener("mouseenter",e);return k};r.prototype.close=
function(a,b){this.root.parentNode&&this.root.parentNode.removeChild(this.root);this.parentMenu&&!b&&(this.parentMenu.lock=!1,this.parentMenu.current_submenu=null,void 0===a?this.parentMenu.close():a&&!r.isCursorOverElement(a,this.parentMenu.root)&&r.trigger(this.parentMenu.root,"mouseleave",a));this.current_submenu&&this.current_submenu.close(a,!0)};r.trigger=function(a,b,c,e){var f=document.createEvent("CustomEvent");f.initCustomEvent(b,!0,!0,c);f.srcElement=e;a.dispatchEvent?a.dispatchEvent(f):
a.__events&&a.__events.dispatchEvent(f);return f};r.prototype.getTopMenu=function(){return this.options.parentMenu?this.options.parentMenu.getTopMenu():this};r.prototype.getFirstEvent=function(){return this.options.parentMenu?this.options.parentMenu.getFirstEvent():this.options.event};r.isCursorOverElement=function(a,b){var c=a.pageX,e=a.pageY,f=b.getBoundingClientRect();return f?e>f.top&&e<f.top+f.height&&c>f.left&&c<f.left+f.width?!0:!1:!1};l.ContextMenu=r;l.closeAllContextMenus=function(a){a=a||
window;a=a.document.querySelectorAll(".litecontextmenu");if(a.length){for(var b=[],c=0;c<a.length;c++)b.push(a[c]);for(c in b)b[c].close?b[c].close():b[c].parentNode&&b[c].parentNode.removeChild(b[c])}};l.extendClass=function(a,b){for(var c in b)a.hasOwnProperty(c)||(a[c]=b[c]);if(b.prototype)for(c in b.prototype)b.prototype.hasOwnProperty(c)&&!a.prototype.hasOwnProperty(c)&&(b.prototype.__lookupGetter__(c)?a.prototype.__defineGetter__(c,b.prototype.__lookupGetter__(c)):a.prototype[c]=b.prototype[c],
b.prototype.__lookupSetter__(c)&&a.prototype.__defineSetter__(c,b.prototype.__lookupSetter__(c)))};l.getParameterNames=function(a){return(a+"").replace(/[/][/].*$/mg,"").replace(/\s+/g,"").replace(/[/][*][^/*]*[*][/]/g,"").split("){",1)[0].replace(/^[^(]*[(]/,"").replace(/=[^,]+/g,"").split(",").filter(Boolean)};Math.clamp=function(a,b,c){return b>a?b:c<a?c:a};"undefined"==typeof window||window.requestAnimationFrame||(window.requestAnimationFrame=window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||
function(a){window.setTimeout(a,1E3/60)})})(this);"undefined"!=typeof exports&&(exports.LiteGraph=this.LiteGraph);
this.fixedtime_lapse=0.01;this.starttime=this.last_update_time=0;this.catch_errors=!0;this.global_inputs={};this.global_outputs={};this.debug=!0;this.change();this.sendActionToCanvas("clear")};g.prototype.attachCanvas=function(a){if(a.constructor!=h)throw"attachCanvas expects a LGraphCanvas instance";a.graph&&a.graph!=this&&a.graph.detachCanvas(a);a.graph=this;this.list_of_graphcanvas||(this.list_of_graphcanvas=[]);this.list_of_graphcanvas.push(a)};g.prototype.detachCanvas=function(a){if(this.list_of_graphcanvas){var b=
this.list_of_graphcanvas.indexOf(a);-1!=b&&(a.graph=null,this.list_of_graphcanvas.splice(b,1))}};g.prototype.start=function(a){if(this.status!=g.STATUS_RUNNING){this.status=g.STATUS_RUNNING;if(this.onPlayEvent)this.onPlayEvent();this.sendEventToAllNodes("onStart");this.last_update_time=this.starttime=l.getTime();var b=this;this.execution_timer_id=setInterval(function(){b.runStep(1,!this.catch_errors)},a||1)}};g.prototype.stop=function(){if(this.status!=g.STATUS_STOPPED){this.status=g.STATUS_STOPPED;
if(this.onStopEvent)this.onStopEvent();null!=this.execution_timer_id&&clearInterval(this.execution_timer_id);this.execution_timer_id=null;this.sendEventToAllNodes("onStop")}};g.prototype.runStep=function(a,b){a=a||1;var d=l.getTime();this.globaltime=0.001*(d-this.starttime);var c=this._nodes_executable?this._nodes_executable:this._nodes;if(c){if(b){for(var f=0;f<a;f++){for(var m=0,k=c.length;m<k;++m){var t=c[m];if(t.mode==l.ALWAYS&&t.onExecute)t.onExecute()}this.fixedtime+=this.fixedtime_lapse;if(this.onExecuteStep)this.onExecuteStep()}if(this.onAfterExecute)this.onAfterExecute()}else try{for(f=
0;f<a;f++){m=0;for(k=c.length;m<k;++m)if(t=c[m],t.mode==l.ALWAYS&&t.onExecute)t.onExecute();this.fixedtime+=this.fixedtime_lapse;if(this.onExecuteStep)this.onExecuteStep()}if(this.onAfterExecute)this.onAfterExecute();this.errors_in_execution=!1}catch(e){this.errors_in_execution=!0;if(l.throw_errors)throw e;l.debug&&console.log("Error during execution: "+e);this.stop()}c=l.getTime();d=c-d;0==d&&(d=1);this.execution_time=0.001*d;this.globaltime+=0.001*d;this.iteration+=1;this.elapsed_time=0.001*(c-
this.last_update_time);this.last_update_time=c}};g.prototype.updateExecutionOrder=function(){this._nodes_in_order=this.computeExecutionOrder(!1);this._nodes_executable=[];for(var a=0;a<this._nodes_in_order.length;++a)this._nodes_in_order[a].onExecute&&this._nodes_executable.push(this._nodes_in_order[a])};g.prototype.computeExecutionOrder=function(a,b){for(var d=[],c=[],f={},m={},k={},t=0,e=this._nodes.length;t<e;++t){var h=this._nodes[t];if(!a||h.onExecute){f[h.id]=h;var g=0;if(h.inputs)for(var n=
0,p=h.inputs.length;n<p;n++)h.inputs[n]&&null!=h.inputs[n].link&&(g+=1);0==g?(c.push(h),b&&(h._level=1)):(b&&(h._level=0),k[h.id]=g)}}for(;0!=c.length;)if(h=c.shift(),d.push(h),delete f[h.id],h.outputs)for(t=0;t<h.outputs.length;t++)if(e=h.outputs[t],null!=e&&null!=e.links&&0!=e.links.length)for(n=0;n<e.links.length;n++)(g=this.links[e.links[n]])&&!m[g.id]&&(p=this.getNodeById(g.target_id),null==p?m[g.id]=!0:(b&&(!p._level||p._level<=h._level)&&(p._level=h._level+1),m[g.id]=!0,k[p.id]-=1,0==k[p.id]&&
c.push(p)));for(t in f)d.push(f[t]);d.length!=this._nodes.length&&l.debug&&console.warn("something went wrong, nodes missing");e=d.length;for(t=0;t<e;++t)d[t].order=t;d=d.sort(function(a,b){var d=a.constructor.priority||a.priority||0,c=b.constructor.priority||b.priority||0;return d==c?a.order-b.order:d-c});for(t=0;t<e;++t)d[t].order=t;return d};g.prototype.arrange=function(a){a=a||40;for(var b=this.computeExecutionOrder(!1,!0),d=[],c=0;c<b.length;++c){var f=b[c],m=f._level||1;d[m]||(d[m]=[]);d[m].push(f)}b=
a;for(c=0;c<d.length;++c)if(m=d[c]){for(var k=100,h=a,e=0;e<m.length;++e)f=m[e],f.pos[0]=b,f.pos[1]=h,f.size[0]>k&&(k=f.size[0]),h+=f.size[1]+a;b+=k+a}this.setDirtyCanvas(!0,!0)};g.prototype.getTime=function(){return this.globaltime};g.prototype.getFixedTime=function(){return this.fixedtime};g.prototype.getElapsedTime=function(){return this.elapsed_time};g.prototype.sendEventToAllNodes=function(a,b,d){d=d||l.ALWAYS;var c=this._nodes_in_order?this._nodes_in_order:this._nodes;if(c)for(var f=0,m=c.length;f<
m;++f){var k=c[f];if(k[a]&&k.mode==d)if(void 0===b)k[a]();else if(b&&b.constructor===Array)k[a].apply(k,b);else k[a](b)}};g.prototype.sendActionToCanvas=function(a,b){if(this.list_of_graphcanvas)for(var d=0;d<this.list_of_graphcanvas.length;++d){var c=this.list_of_graphcanvas[d];c[a]&&c[a].apply(c,b)}};g.prototype.add=function(a,b){if(a){-1!=a.id&&null!=this._nodes_by_id[a.id]&&(console.warn("LiteGraph: there is already a node with this ID, changing it"),a.id=++this.last_node_id);if(this._nodes.length>=
l.MAX_NUMBER_OF_NODES)throw"LiteGraph: max number of nodes in a graph reached";null==a.id||-1==a.id?a.id=++this.last_node_id:this.last_node_id<a.id&&(this.last_node_id=a.id);a.graph=this;this._nodes.push(a);this._nodes_by_id[a.id]=a;if(a.onAdded)a.onAdded(this);this.config.align_to_grid&&a.alignToGrid();b||this.updateExecutionOrder();if(this.onNodeAdded)this.onNodeAdded(a);this.setDirtyCanvas(!0);this.change();return a}};g.prototype.remove=function(a){if(null!=this._nodes_by_id[a.id]&&!a.ignore_remove){if(a.inputs)for(var b=
0;b<a.inputs.length;b++){var d=a.inputs[b];null!=d.link&&a.disconnectInput(b)}if(a.outputs)for(b=0;b<a.outputs.length;b++)d=a.outputs[b],null!=d.links&&d.links.length&&a.disconnectOutput(b);if(a.onRemoved)a.onRemoved();a.graph=null;if(this.list_of_graphcanvas)for(b=0;b<this.list_of_graphcanvas.length;++b)d=this.list_of_graphcanvas[b],d.selected_nodes[a.id]&&delete d.selected_nodes[a.id],d.node_dragged==a&&(d.node_dragged=null);b=this._nodes.indexOf(a);-1!=b&&this._nodes.splice(b,1);delete this._nodes_by_id[a.id];
if(this.onNodeRemoved)this.onNodeRemoved(a);this.setDirtyCanvas(!0,!0);this.change();this.updateExecutionOrder()}};g.prototype.getNodeById=function(a){return null==a?null:this._nodes_by_id[a]};g.prototype.findNodesByClass=function(a){for(var b=[],d=0,c=this._nodes.length;d<c;++d)this._nodes[d].constructor===a&&b.push(this._nodes[d]);return b};g.prototype.findNodesByType=function(a){a=a.toLowerCase();for(var b=[],d=0,c=this._nodes.length;d<c;++d)this._nodes[d].type.toLowerCase()==a&&b.push(this._nodes[d]);
return b};g.prototype.findNodesByTitle=function(a){for(var b=[],d=0,c=this._nodes.length;d<c;++d)this._nodes[d].title==a&&b.push(this._nodes[d]);return b};g.prototype.getNodeOnPos=function(a,b,d){d=d||this._nodes;for(var c=d.length-1;0<=c;c--){var f=d[c];if(f.isPointInsideNode(a,b,2))return f}return null};g.prototype.addGlobalInput=function(a,b,d){this.global_inputs[a]={name:a,type:b,value:d};if(this.onGlobalInputAdded)this.onGlobalInputAdded(a,b);if(this.onGlobalsChange)this.onGlobalsChange()};g.prototype.setGlobalInputData=
function(a,b){var d=this.global_inputs[a];d&&(d.value=b)};g.prototype.setInputData=g.prototype.setGlobalInputData;g.prototype.getGlobalInputData=function(a){return(a=this.global_inputs[a])?a.value:null};g.prototype.renameGlobalInput=function(a,b){if(b!=a){if(!this.global_inputs[a])return!1;if(this.global_inputs[b])return console.error("there is already one input with that name"),!1;this.global_inputs[b]=this.global_inputs[a];delete this.global_inputs[a];if(this.onGlobalInputRenamed)this.onGlobalInputRenamed(a,
b);if(this.onGlobalsChange)this.onGlobalsChange()}};g.prototype.changeGlobalInputType=function(a,b){if(!this.global_inputs[a])return!1;if(this.global_inputs[a].type.toLowerCase()!=b.toLowerCase()&&(this.global_inputs[a].type=b,this.onGlobalInputTypeChanged))this.onGlobalInputTypeChanged(a,b)};g.prototype.removeGlobalInput=function(a){if(!this.global_inputs[a])return!1;delete this.global_inputs[a];if(this.onGlobalInputRemoved)this.onGlobalInputRemoved(a);if(this.onGlobalsChange)this.onGlobalsChange();
return!0};g.prototype.addGlobalOutput=function(a,b,d){this.global_outputs[a]={name:a,type:b,value:d};if(this.onGlobalOutputAdded)this.onGlobalOutputAdded(a,b);if(this.onGlobalsChange)this.onGlobalsChange()};g.prototype.setGlobalOutputData=function(a,b){var d=this.global_outputs[a];d&&(d.value=b)};g.prototype.getGlobalOutputData=function(a){return(a=this.global_outputs[a])?a.value:null};g.prototype.getOutputData=g.prototype.getGlobalOutputData;g.prototype.renameGlobalOutput=function(a,b){if(!this.global_outputs[a])return!1;
if(this.global_outputs[b])return console.error("there is already one output with that name"),!1;this.global_outputs[b]=this.global_outputs[a];delete this.global_outputs[a];if(this.onGlobalOutputRenamed)this.onGlobalOutputRenamed(a,b);if(this.onGlobalsChange)this.onGlobalsChange()};g.prototype.changeGlobalOutputType=function(a,b){if(!this.global_outputs[a])return!1;if(this.global_outputs[a].type.toLowerCase()!=b.toLowerCase()&&(this.global_outputs[a].type=b,this.onGlobalOutputTypeChanged))this.onGlobalOutputTypeChanged(a,
b)};g.prototype.removeGlobalOutput=function(a){if(!this.global_outputs[a])return!1;delete this.global_outputs[a];if(this.onGlobalOutputRemoved)this.onGlobalOutputRemoved(a);if(this.onGlobalsChange)this.onGlobalsChange();return!0};g.prototype.triggerInput=function(a,b){for(var d=this.findNodesByTitle(a),c=0;c<d.length;++c)d[c].onTrigger(b)};g.prototype.setCallback=function(a,b){for(var d=this.findNodesByTitle(a),c=0;c<d.length;++c)d[c].setTrigger(b)};g.prototype.connectionChange=function(a){this.updateExecutionOrder();
if(this.onConnectionChange)this.onConnectionChange(a);this.sendActionToCanvas("onConnectionChange")};g.prototype.isLive=function(){if(!this.list_of_graphcanvas)return!1;for(var a=0;a<this.list_of_graphcanvas.length;++a)if(this.list_of_graphcanvas[a].live_mode)return!0;return!1};g.prototype.change=function(){l.debug&&console.log("Graph changed");this.sendActionToCanvas("setDirty",[!0,!0]);if(this.on_change)this.on_change(this)};g.prototype.setDirtyCanvas=function(a,b){this.sendActionToCanvas("setDirty",
[a,b])};g.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 c=this.links[b];d.push([c.id,c.origin_id,c.origin_slot,c.target_id,c.target_slot,c.type])}return{iteration:this.iteration,frame:this.frame,last_node_id:this.last_node_id,last_link_id:this.last_link_id,links:d,config:this.config,nodes:a}};g.prototype.configure=function(a,b){b||this.clear();var d=a.nodes;if(a.links&&a.links.constructor===Array){for(var c=
{},f=0;f<a.links.length;++f){var m=a.links[f];c[m[0]]={id:m[0],origin_id:m[1],origin_slot:m[2],target_id:m[3],target_slot:m[4],type:m[5]}}a.links=c}for(f in a)this[f]=a[f];c=!1;this._nodes=[];f=0;for(m=d.length;f<m;++f){var k=d[f],h=l.createNode(k.type,k.title);h?(h.id=k.id,this.add(h,!0)):(l.debug&&console.log("Node not found: "+k.type),c=!0)}f=0;for(m=d.length;f<m;++f)k=d[f],(h=this.getNodeById(k.id))&&h.configure(k);this.updateExecutionOrder();this.setDirtyCanvas(!0,!0);return c};g.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)}};g.prototype.onNodeTrace=function(a,b,d){};u.LGraphNode=l.LGraphNode=e;e.prototype._ctor=function(a){this.title=a||"Unnamed";this.size=[l.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.data=null;this.flags={}};e.prototype.configure=function(a){for(var b in a)if("console"!=b)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]=l.cloneObject(a[b],this[b]):this[b]=a[b]);a.title||(this.title=this.constructor.title);if(this.onConnectionsChange){if(this.inputs)for(var c=0;c<this.inputs.length;++c){d=this.inputs[c];var f=this.graph.links[d.link];this.onConnectionsChange(l.INPUT,c,!0,f,d)}if(this.outputs)for(c=0;c<this.outputs.length;++c)if(d=this.outputs[c],d.links)for(b=0;b<d.links.length;++b)f=this.graph.links[d.links[b]],this.onConnectionsChange(l.OUTPUT,
c,!0,f,d)}for(c in this.inputs)d=this.inputs[c],d.link&&d.link.length&&(f=d.link,"object"==typeof f&&(d.link=f[0],this.graph.links[f[0]]={id:f[0],origin_id:f[1],origin_slot:f[2],target_id:f[3],target_slot:f[4]}));for(c in this.outputs)if(d=this.outputs[c],d.links&&0!=d.links.length)for(b in d.links)f=d.links[b],"object"==typeof f&&(d.links[b]=f[0]);if(this.onConfigure)this.onConfigure(a)};e.prototype.serialize=function(){var a={id:this.id,type:this.type,pos:this.pos,size:this.size,data:this.data,
flags:l.cloneObject(this.flags),mode:this.mode};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=l.cloneObject(this.properties));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);
if(this.onSerialize)this.onSerialize(a);return a};e.prototype.clone=function(){var a=l.createNode(this.type),b=l.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};e.prototype.toString=function(){return JSON.stringify(this.serialize())};e.prototype.getTitle=function(){return this.title||this.constructor.title};e.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++)this.graph.links[this.outputs[a].links[d]].data=b}};e.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 c=this.graph.getNodeById(d.origin_id);if(!c)return d.data;if(c.updateOutputData)c.updateOutputData(d.origin_slot);
else if(c.onExecute)c.onExecute();return d.data}};e.prototype.getInputDataByName=function(a,b){var d=this.findInputSlot(a);return-1==d?null:this.getInputData(d,b)};e.prototype.isInputConnected=function(a){return this.inputs?a<this.inputs.length&&null!=this.inputs[a].link:!1};e.prototype.getInputInfo=function(a){return this.inputs?a<this.inputs.length?this.inputs[a]:null:null};e.prototype.getInputNode=function(a){if(!this.inputs||a>=this.inputs.length)return null;a=this.inputs[a];return a&&a.link?
(a=this.graph.links[a.link])?this.graph.getNodeById(a.origin_id):null:null};e.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)if(a==this.inputs[b].name)return(a=this.graph.links[this.inputs[b].link])?a.data:null;return this.properties[a]};e.prototype.getOutputData=function(a){return!this.outputs||a>=this.outputs.length?null:this.outputs[a]._data};e.prototype.getOutputInfo=function(a){return this.outputs?
a<this.outputs.length?this.outputs[a]:null:null};e.prototype.isOutputConnected=function(a){return this.outputs?a<this.outputs.length&&this.outputs[a].links&&this.outputs[a].links.length:!1};e.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};e.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 c=this.graph.links[a.links[d]];c&&(c=this.graph.getNodeById(c.target_id))&&b.push(c)}return b};e.prototype.trigger=function(a,b){if(this.outputs&&this.outputs.length){this.graph&&(this.graph._last_trigger_time=l.getTime());for(var d=0;d<this.outputs.length;++d){var c=this.outputs[d];!c||c.type!==l.EVENT||a&&c.name!=a||this.triggerSlot(d,b)}}};e.prototype.triggerSlot=function(a,b){if(this.outputs){var d=this.outputs[a];
if(d&&(d=d.links)&&d.length){this.graph&&(this.graph._last_trigger_time=l.getTime());for(var c=0;c<d.length;++c){var f=this.graph.links[d[c]];if(f){var m=this.graph.getNodeById(f.target_id);if(m)if(f._last_time=l.getTime(),f=m.inputs[f.target_slot],m.onAction)m.onAction(f.name,b);else if(m.mode===l.ON_TRIGGER&&m.onExecute)m.onExecute(b)}}}}};e.prototype.addProperty=function(a,b,d,c){d={name:a,type:d,default_value:b};if(c)for(var f in c)d[f]=c[f];this.properties_info||(this.properties_info=[]);this.properties_info.push(d);
this.properties||(this.properties={});this.properties[a]=b;return d};e.prototype.addOutput=function(a,b,d){a={name:a,type:b,links:null};if(d)for(var c in d)a[c]=d[c];this.outputs||(this.outputs=[]);this.outputs.push(a);if(this.onOutputAdded)this.onOutputAdded(a);this.size=this.computeSize();return a};e.prototype.addOutputs=function(a){for(var b=0;b<a.length;++b){var d=a[b],c={name:d[0],type:d[1],link:null};if(a[2])for(var f in d[2])c[f]=d[2][f];this.outputs||(this.outputs=[]);this.outputs.push(c);
if(this.onOutputAdded)this.onOutputAdded(c)}this.size=this.computeSize()};e.prototype.removeOutput=function(a){this.disconnectOutput(a);this.outputs.splice(a,1);this.size=this.computeSize();if(this.onOutputRemoved)this.onOutputRemoved(a)};e.prototype.addInput=function(a,b,d){a={name:a,type:b||0,link:null};if(d)for(var c in d)a[c]=d[c];this.inputs||(this.inputs=[]);this.inputs.push(a);this.size=this.computeSize();if(this.onInputAdded)this.onInputAdded(a);return a};e.prototype.addInputs=function(a){for(var b=
0;b<a.length;++b){var d=a[b],c={name:d[0],type:d[1],link:null};if(a[2])for(var f in d[2])c[f]=d[2][f];this.inputs||(this.inputs=[]);this.inputs.push(c);if(this.onInputAdded)this.onInputAdded(c)}this.size=this.computeSize()};e.prototype.removeInput=function(a){this.disconnectInput(a);this.inputs.splice(a,1);this.size=this.computeSize();if(this.onInputRemoved)this.onInputRemoved(a)};e.prototype.addConnection=function(a,b,d,c){a={name:a,type:b,pos:d,direction:c,links:null};this.connections.push(a);return a};
e.prototype.computeSize=function(a,b){function d(a){return a?m*a.length*0.6:0}var c=Math.max(this.inputs?this.inputs.length:1,this.outputs?this.outputs.length:1),f=b||new Float32Array([0,0]),c=Math.max(c,1);f[1]=14*c+6;var m=14,c=d(this.title),k=0,h=0;if(this.inputs)for(var e=0,g=this.inputs.length;e<g;++e){var n=this.inputs[e],n=n.label||n.name||"",n=d(n);k<n&&(k=n)}if(this.outputs)for(e=0,g=this.outputs.length;e<g;++e)n=this.outputs[e],n=n.label||n.name||"",n=d(n),h<n&&(h=n);f[0]=Math.max(k+h+10,
c);f[0]=Math.max(f[0],l.NODE_WIDTH);return f};e.prototype.getBounding=function(a){a=a||new Float32Array(4);a[0]=this.pos[0]-4;a[1]=this.pos[1]-l.NODE_TITLE_HEIGHT;a[2]=this.size[0]+4;a[3]=this.size[1]+l.NODE_TITLE_HEIGHT;return a};e.prototype.isPointInsideNode=function(a,b,d){d=d||0;var c=this.graph&&this.graph.isLive()?0:20;if(this.flags.collapsed){if(p(a,b,this.pos[0]-d,this.pos[1]-l.NODE_TITLE_HEIGHT-d,l.NODE_COLLAPSED_WIDTH+2*d,l.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]-c-d<b&&this.pos[1]+this.size[1]+d>b)return!0;return!1};e.prototype.getSlotInPosition=function(a,b){if(this.inputs)for(var d=0,c=this.inputs.length;d<c;++d){var f=this.inputs[d],m=this.getConnectionPos(!0,d);if(p(a,b,m[0]-10,m[1]-5,20,10))return{input:f,slot:d,link_pos:m,locked:f.locked}}if(this.outputs)for(d=0,c=this.outputs.length;d<c;++d)if(f=this.outputs[d],m=this.getConnectionPos(!1,d),p(a,b,m[0]-10,m[1]-5,20,10))return{output:f,slot:d,link_pos:m,locked:f.locked};
return null};e.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};e.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};e.prototype.connect=function(a,b,d){d=d||0;if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return l.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.outputs||
a>=this.outputs.length)return l.debug&&console.log("Connect: Error, slot number not found"),!1;b&&b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"Node not found";if(b==this)return!1;if(d.constructor===String){if(d=b.findInputSlot(d),-1==d)return l.debug&&console.log("Connect: Error, no slot of name "+d),!1}else{if(d===l.EVENT)return!1;if(!b.inputs||d>=b.inputs.length)return l.debug&&console.log("Connect: Error, slot number not found"),!1}null!=b.inputs[d].link&&b.disconnectInput(d);
this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this);var c=this.outputs[a];if(b.onConnectInput&&!1===b.onConnectInput(d,c.type,c))return!1;var f=b.inputs[d];if(l.isValidConnection(c.type,f.type)){var m={id:this.graph.last_link_id++,type:f.type,origin_id:this.id,origin_slot:a,target_id:b.id,target_slot:d};this.graph.links[m.id]=m;null==c.links&&(c.links=[]);c.links.push(m.id);b.inputs[d].link=m.id;if(this.onConnectionsChange)this.onConnectionsChange(l.OUTPUT,a,!0,m,c);if(b.onConnectionsChange)b.onConnectionsChange(l.INPUT,
d,!0,m,f)}this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this);return!0};e.prototype.disconnectOutput=function(a,b){if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return l.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.outputs||a>=this.outputs.length)return l.debug&&console.log("Connect: Error, slot number not found"),!1;var d=this.outputs[a];if(!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 c=0,f=d.links.length;c<f;c++){var m=d.links[c],k=this.graph.links[m];if(k.target_id==b.id){d.links.splice(c,1);var h=b.inputs[k.target_slot];h.link=null;delete this.graph.links[m];if(b.onConnectionsChange)b.onConnectionsChange(l.INPUT,k.target_slot,!1,k,h);if(this.onConnectionsChange)this.onConnectionsChange(l.OUTPUT,a,!1,k,d);break}}}else{c=0;for(f=d.links.length;c<f;c++)if(m=d.links[c],k=this.graph.links[m]){if(b=this.graph.getNodeById(k.target_id))if(h=b.inputs[k.target_slot],h.link=null,
b.onConnectionsChange)b.onConnectionsChange(l.INPUT,k.target_slot,!1,k,h);delete this.graph.links[m];if(this.onConnectionsChange)this.onConnectionsChange(l.OUTPUT,a,!1,k,d)}d.links=null}this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this);return!0};e.prototype.disconnectInput=function(a){if(a.constructor===String){if(a=this.findInputSlot(a),-1==a)return l.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.inputs||a>=this.inputs.length)return l.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;this.inputs[a].link=null;var c=this.graph.links[d];if(c){var f=this.graph.getNodeById(c.origin_id);if(!f)return!1;var m=f.outputs[c.origin_slot];if(!m||!m.links||0==m.links.length)return!1;for(var k=0,h=m.links.length;k<h;k++)if(m.links[k]==d){m.links.splice(k,1);break}delete this.graph.links[d];if(this.onConnectionsChange)this.onConnectionsChange(l.INPUT,a,!1,c,b);if(f.onConnectionsChange)f.onConnectionsChange(l.OUTPUT,k,!1,c,m)}this.setDirtyCanvas(!1,
!0);this.graph.connectionChange(this);return!0};e.prototype.getConnectionPos=function(a,b){return this.flags.collapsed?a?[this.pos[0],this.pos[1]-0.5*l.NODE_TITLE_HEIGHT]:[this.pos[0]+l.NODE_COLLAPSED_WIDTH,this.pos[1]-0.5*l.NODE_TITLE_HEIGHT]:a&&-1==b?[this.pos[0]+10,this.pos[1]+10]:a&&this.inputs.length>b&&this.inputs[b].pos?[this.pos[0]+this.inputs[b].pos[0],this.pos[1]+this.inputs[b].pos[1]]:!a&&this.outputs.length>b&&this.outputs[b].pos?[this.pos[0]+this.outputs[b].pos[0],this.pos[1]+this.outputs[b].pos[1]]:
a?[this.pos[0],this.pos[1]+10+b*l.NODE_SLOT_HEIGHT]:[this.pos[0]+this.size[0]+1,this.pos[1]+10+b*l.NODE_SLOT_HEIGHT]};e.prototype.alignToGrid=function(){this.pos[0]=l.CANVAS_GRID_SIZE*Math.round(this.pos[0]/l.CANVAS_GRID_SIZE);this.pos[1]=l.CANVAS_GRID_SIZE*Math.round(this.pos[1]/l.CANVAS_GRID_SIZE)};e.prototype.trace=function(a){this.console||(this.console=[]);this.console.push(a);this.console.length>e.MAX_CONSOLE&&this.console.shift();this.graph.onNodeTrace(this,a)};e.prototype.setDirtyCanvas=function(a,
b){this.graph&&this.graph.sendActionToCanvas("setDirty",[a,b])};e.prototype.loadImage=function(a){var b=new Image;b.src=l.node_images_path+a;b.ready=!1;var d=this;b.onload=function(){this.ready=!0;d.setDirtyCanvas(!0)};return b};e.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 c=b[d];if(a||c.node_capturing_input==this)c.node_capturing_input=a?this:null}};e.prototype.collapse=function(){this.flags.collapsed=
this.flags.collapsed?!1:!0;this.setDirtyCanvas(!0,!0)};e.prototype.pin=function(a){this.flags.pinned=void 0===a?!this.flags.pinned:a};e.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]]};u.LGraphCanvas=l.LGraphCanvas=h;h.link_type_colors={"-1":"#F85",number:"#AAC",node:"#DCA"};h.prototype.clear=function(){this.fps=this.render_time=this.last_draw_time=this.frame=0;this.scale=1;this.offset=[0,0];this.dragging_rectangle=null;this.selected_nodes=
{};this.visible_nodes=[];this.connecting_node=this.node_capturing_input=this.node_over=this.node_dragged=null;this.highlighted_links={};this.dirty_bgcanvas=this.dirty_canvas=!0;this.node_in_panel=this.dirty_area=null;this.last_mouse=[0,0];this.last_mouseclick=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.setDirty(!0,!0)))};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.setDirty(!0,!0)};h.prototype.closeSubgraph=function(){if(this._graph_stack&&0!=this._graph_stack.length){var a=this._graph_stack.pop();this.selected_nodes={};this.highlighted_links={};a.attachCanvas(this);this.setDirty(!0,!0)}};h.prototype.setCanvas=function(a,b){if(a&&a.constructor===String&&(a=document.getElementById(a),
!a))throw"Error creating LiteGraph canvas: Canvas not found";if(a!==this.canvas&&(!a&&this.canvas&&(b||this.unbindEvents()),this.canvas=a)){a.className+=" lgraphcanvas";a.data=this;this.bgcanvas=null;this.bgcanvas||(this.bgcanvas=document.createElement("canvas"),this.bgcanvas.width=this.canvas.width,this.bgcanvas.height=this.canvas.height);if(null==a.getContext){if("canvas"!=a.localName)throw"Element supplied for LGraphCanvas must be a <canvas> element, you passed a "+a.localName;throw"This browser doesnt support Canvas";
}null==(this.ctx=a.getContext("2d"))&&(console.warn("This canvas seems to be WebGL, enabling WebGL renderer"),this.enableWebGL());this._mousemove_callback=this.processMouseMove.bind(this);this._mouseup_callback=this.processMouseUp.bind(this);b||this.bindEvents()}};h.prototype._doNothing=function(a){a.preventDefault();return!1};h.prototype._doReturnTrue=function(a){a.preventDefault();return!0};h.prototype.bindEvents=function(){if(this._events_binded)console.warn("LGraphCanvas: events already binded");
else{var a=this.canvas,b=this.getCanvasWindow().document;this._mousedown_callback=this.processMouseDown.bind(this);this._mousewheel_callback=this.processMouseWheel.bind(this);a.addEventListener("mousedown",this._mousedown_callback,!0);a.addEventListener("mousemove",this._mousemove_callback);a.addEventListener("mousewheel",this._mousewheel_callback,!1);a.addEventListener("contextmenu",this._doNothing);a.addEventListener("DOMMouseScroll",this._mousewheel_callback,!1);a.addEventListener("touchstart",
this.touchHandler,!0);a.addEventListener("touchmove",this.touchHandler,!0);a.addEventListener("touchend",this.touchHandler,!0);a.addEventListener("touchcancel",this.touchHandler,!0);this._key_callback=this.processKey.bind(this);a.addEventListener("keydown",this._key_callback,!0);b.addEventListener("keyup",this._key_callback,!0);this._ondrop_callback=this.processDrop.bind(this);a.addEventListener("dragover",this._doNothing,!1);a.addEventListener("dragend",this._doNothing,!1);a.addEventListener("drop",
this._ondrop_callback,!1);a.addEventListener("dragenter",this._doReturnTrue,!1);this._events_binded=!0}};h.prototype.unbindEvents=function(){if(this._events_binded){var a=this.getCanvasWindow().document;this.canvas.removeEventListener("mousedown",this._mousedown_callback);this.canvas.removeEventListener("mousewheel",this._mousewheel_callback);this.canvas.removeEventListener("DOMMouseScroll",this._mousewheel_callback);this.canvas.removeEventListener("keydown",this._key_callback);a.removeEventListener("keyup",
this._key_callback);this.canvas.removeEventListener("contextmenu",this._doNothing);this.canvas.removeEventListener("drop",this._ondrop_callback);this.canvas.removeEventListener("dragenter",this._doReturnTrue);this.canvas.removeEventListener("touchstart",this.touchHandler);this.canvas.removeEventListener("touchmove",this.touchHandler);this.canvas.removeEventListener("touchend",this.touchHandler);this.canvas.removeEventListener("touchcancel",this.touchHandler);this._ondrop_callback=this._key_callback=
this._mousewheel_callback=this._mousedown_callback=null;this._events_binded=!1}else console.warn("LGraphCanvas: no events binded")};h.getFileExtension=function(a){var b=a.indexOf("?");-1!=b&&(a=a.substr(0,b));b=a.lastIndexOf(".");return-1==b?"":a.substr(b+1).toLowerCase()};h.prototype.enableWebGL=function(){if(void 0===typeof GL)throw"litegl.js must be included to use a WebGL canvas";if(void 0===typeof enableWebGLCanvas)throw"webglCanvas.js must be included to use this feature";this.gl=this.ctx=enableWebGLCanvas(this.canvas);
this.ctx.webgl=!0;this.bgcanvas=this.canvas;this.bgctx=this.gl};h.prototype.setDirty=function(a,b){a&&(this.dirty_canvas=!0);b&&(this.dirty_bgcanvas=!0)};h.prototype.getCanvasWindow=function(){if(!this.canvas)return window;var a=this.canvas.ownerDocument;return a.defaultView||a.parentWindow};h.prototype.startRendering=function(){function a(){this.pause_rendering||this.draw();var b=this.getCanvasWindow();this.is_rendering&&b.requestAnimationFrame(a.bind(this))}this.is_rendering||(this.is_rendering=
!0,a.call(this))};h.prototype.stopRendering=function(){this.is_rendering=!1};h.prototype.processMouseDown=function(a){if(this.graph){this.adjustMouseEvent(a);var b=this.getCanvasWindow();h.active_canvas=this;this.canvas.removeEventListener("mousemove",this._mousemove_callback);b.document.addEventListener("mousemove",this._mousemove_callback,!0);b.document.addEventListener("mouseup",this._mouseup_callback,!0);var d=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes),c=!1;l.closeAllContextMenus(b);
if(1==a.which){a.ctrlKey&&(this.dragging_rectangle=new Float32Array(4),this.dragging_rectangle[0]=a.canvasX,this.dragging_rectangle[1]=a.canvasY,this.dragging_rectangle[2]=1,this.dragging_rectangle[3]=1,c=!0);var f=!1;if(d&&this.allow_interaction&&!c){this.live_mode||d.flags.pinned||this.bringToFront(d);if(!this.connecting_node&&!d.flags.collapsed&&!this.live_mode){if(d.outputs)for(var m=0,k=d.outputs.length;m<k;++m){var e=d.outputs[m],g=d.getConnectionPos(!1,m);if(p(a.canvasX,a.canvasY,g[0]-10,g[1]-
5,20,10)){this.connecting_node=d;this.connecting_output=e;this.connecting_pos=d.getConnectionPos(!1,m);this.connecting_slot=m;c=!0;break}}if(d.inputs)for(m=0,k=d.inputs.length;m<k;++m)e=d.inputs[m],g=d.getConnectionPos(!0,m),p(a.canvasX,a.canvasY,g[0]-10,g[1]-5,20,10)&&null!==e.link&&(d.disconnectInput(m),c=this.dirty_bgcanvas=!0);!c&&p(a.canvasX,a.canvasY,d.pos[0]+d.size[0]-5,d.pos[1]+d.size[1]-5,5,5)&&(this.resizing_node=d,this.canvas.style.cursor="se-resize",c=!0)}!c&&p(a.canvasX,a.canvasY,d.pos[0],
d.pos[1]-l.NODE_TITLE_HEIGHT,l.NODE_TITLE_HEIGHT,l.NODE_TITLE_HEIGHT)&&(d.collapse(),c=!0);if(!c){m=!1;if(300>l.getTime()-this.last_mouseclick&&this.selected_nodes[d.id]){if(d.onDblClick)d.onDblClick(a);this.processNodeDblClicked(d);m=!0}d.onMouseDown&&d.onMouseDown(a,[a.canvasX-d.pos[0],a.canvasY-d.pos[1]])?m=!0:this.live_mode&&(m=f=!0);m||(this.allow_dragnodes&&(this.node_dragged=d),this.selected_nodes[d.id]||this.processNodeSelected(d,a));this.dirty_canvas=!0}}else f=!0;!c&&f&&this.allow_dragcanvas&&
(this.dragging_canvas=!0)}else 2!=a.which&&3==a.which&&this.processContextMenu(d,a);this.last_mouse[0]=a.localX;this.last_mouse[1]=a.localY;this.last_mouseclick=l.getTime();this.canvas_mouse=[a.canvasX,a.canvasY];this.graph.change();(!b.document.activeElement||"input"!=b.document.activeElement.nodeName.toLowerCase()&&"textarea"!=b.document.activeElement.nodeName.toLowerCase())&&a.preventDefault();a.stopPropagation();if(this.onMouseDown)this.onMouseDown(a);return!1}};h.prototype.processMouseMove=function(a){this.autoresize&&
this.resize();if(this.graph){h.active_canvas=this;this.adjustMouseEvent(a);var b=[a.localX,a.localY],d=[b[0]-this.last_mouse[0],b[1]-this.last_mouse[1]];this.last_mouse=b;this.canvas_mouse=[a.canvasX,a.canvasY];if(this.dragging_rectangle)this.dragging_rectangle[2]=a.canvasX-this.dragging_rectangle[0],this.dragging_rectangle[3]=a.canvasY-this.dragging_rectangle[1],this.dirty_canvas=!0;else if(this.dragging_canvas)this.offset[0]+=d[0]/this.scale,this.offset[1]+=d[1]/this.scale,this.dirty_bgcanvas=this.dirty_canvas=
!0;else if(this.allow_interaction){this.connecting_node&&(this.dirty_canvas=!0);for(var b=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes),c=0,f=this.graph._nodes.length;c<f;++c)if(this.graph._nodes[c].mouseOver&&b!=this.graph._nodes[c]){this.graph._nodes[c].mouseOver=!1;if(this.node_over&&this.node_over.onMouseLeave)this.node_over.onMouseLeave(a);this.node_over=null;this.dirty_canvas=!0}if(b){if(!b.mouseOver&&(b.mouseOver=!0,this.node_over=b,this.dirty_canvas=!0,b.onMouseEnter))b.onMouseEnter(a);
if(b.onMouseMove)b.onMouseMove(a);if(this.connecting_node&&(f=this._highlight_input||[0,0],!this.isOverNodeBox(b,a.canvasX,a.canvasY))){var m=this.isOverNodeInput(b,a.canvasX,a.canvasY,f);-1!=m&&b.inputs[m]?l.isValidConnection(this.connecting_output.type,b.inputs[m].type)&&(this._highlight_input=f):this._highlight_input=null}p(a.canvasX,a.canvasY,b.pos[0]+b.size[0]-5,b.pos[1]+b.size[1]-5,5,5)?this.canvas.style.cursor="se-resize":this.canvas.style.cursor=null}else this.canvas.style.cursor=null;if(this.node_capturing_input&&
this.node_capturing_input!=b&&this.node_capturing_input.onMouseMove)this.node_capturing_input.onMouseMove(a);if(this.node_dragged&&!this.live_mode){for(c in this.selected_nodes)b=this.selected_nodes[c],b.pos[0]+=d[0]/this.scale,b.pos[1]+=d[1]/this.scale;this.dirty_bgcanvas=this.dirty_canvas=!0}this.resizing_node&&!this.live_mode&&(this.resizing_node.size[0]+=d[0]/this.scale,this.resizing_node.size[1]+=d[1]/this.scale,d=Math.max(this.resizing_node.inputs?this.resizing_node.inputs.length:0,this.resizing_node.outputs?
this.resizing_node.outputs.length:0),this.resizing_node.size[1]<d*l.NODE_SLOT_HEIGHT+4&&(this.resizing_node.size[1]=d*l.NODE_SLOT_HEIGHT+4),this.resizing_node.size[0]<l.NODE_MIN_WIDTH&&(this.resizing_node.size[0]=l.NODE_MIN_WIDTH),this.canvas.style.cursor="se-resize",this.dirty_bgcanvas=this.dirty_canvas=!0)}a.preventDefault();return!1}};h.prototype.processMouseUp=function(a){if(this.graph){var b=this.getCanvasWindow().document;h.active_canvas=this;b.removeEventListener("mousemove",this._mousemove_callback,
!0);this.canvas.addEventListener("mousemove",this._mousemove_callback,!0);b.removeEventListener("mouseup",this._mouseup_callback,!0);this.adjustMouseEvent(a);b=l.getTime();a.click_time=b-this.last_mouseclick;if(1==a.which)if(this.dragging_rectangle){if(this.graph){var d=this.graph._nodes,c=new Float32Array(4);this.deselectAllNodes();0>this.dragging_rectangle[2]&&(this.dragging_rectangle[0]+=this.dragging_rectangle[2]);0>this.dragging_rectangle[3]&&(this.dragging_rectangle[1]+=this.dragging_rectangle[3]);
this.dragging_rectangle[2]=Math.abs(this.dragging_rectangle[2]*this.scale);this.dragging_rectangle[3]=Math.abs(this.dragging_rectangle[3]*this.scale);for(var f=0;f<d.length;++f)b=d[f],b.getBounding(c),q(this.dragging_rectangle,c)&&this.selectNode(b,!0)}this.dragging_rectangle=null}else if(this.connecting_node){this.dirty_bgcanvas=this.dirty_canvas=!0;if(b=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes))this.connecting_output.type==l.EVENT&&this.isOverNodeBox(b,a.canvasX,a.canvasY)?
this.connecting_node.connect(this.connecting_slot,b,l.EVENT):(d=this.isOverNodeInput(b,a.canvasX,a.canvasY),-1!=d?this.connecting_node.connect(this.connecting_slot,b,d):(d=b.getInputInfo(0),this.connecting_output.type==l.EVENT?this.connecting_node.connect(this.connecting_slot,b,l.EVENT):d&&!d.link&&l.isValidConnection(d.type&&this.connecting_output.type)&&this.connecting_node.connect(this.connecting_slot,b,0)));this.connecting_node=this.connecting_pos=this.connecting_output=null;this.connecting_slot=
-1}else if(this.resizing_node)this.dirty_bgcanvas=this.dirty_canvas=!0,this.resizing_node=null;else if(this.node_dragged)this.dirty_bgcanvas=this.dirty_canvas=!0,this.node_dragged.pos[0]=Math.round(this.node_dragged.pos[0]),this.node_dragged.pos[1]=Math.round(this.node_dragged.pos[1]),this.graph.config.align_to_grid&&this.node_dragged.alignToGrid(),this.node_dragged=null;else{b=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes);!b&&300>a.click_time&&this.deselectAllNodes();this.dirty_canvas=
!0;this.dragging_canvas=!1;if(this.node_over&&this.node_over.onMouseUp)this.node_over.onMouseUp(a,[a.canvasX-this.node_over.pos[0],a.canvasY-this.node_over.pos[1]]);if(this.node_capturing_input&&this.node_capturing_input.onMouseUp)this.node_capturing_input.onMouseUp(a,[a.canvasX-this.node_capturing_input.pos[0],a.canvasY-this.node_capturing_input.pos[1]])}else 2==a.which?(this.dirty_canvas=!0,this.dragging_canvas=!1):3==a.which&&(this.dirty_canvas=!0,this.dragging_canvas=!1);this.graph.change();a.stopPropagation();
a.preventDefault();return!1}};h.prototype.processMouseWheel=function(a){if(this.graph&&this.allow_dragcanvas){var b=null!=a.wheelDeltaY?a.wheelDeltaY:-60*a.detail;this.adjustMouseEvent(a);var d=this.scale;0<b?d*=1.1:0>b&&(d*=1/1.1);this.setZoom(d,[a.localX,a.localY]);this.graph.change();a.preventDefault();return!1}};h.prototype.isOverNodeBox=function(a,b,d){var c=l.NODE_TITLE_HEIGHT;return p(b,d,a.pos[0]+2,a.pos[1]+2-c,c-4,c-4)?!0:!1};h.prototype.isOverNodeInput=function(a,b,d,c){if(a.inputs)for(var f=
0,m=a.inputs.length;f<m;++f){var k=a.getConnectionPos(!0,f);if(p(b,d,k[0]-10,k[1]-5,20,10))return c&&(c[0]=k[0],c[1]=k[1]),f}return-1};h.prototype.processKey=function(a){if(this.graph){var b=!1;if("input"!=a.target.localName){if("keydown"==a.type){32==a.keyCode&&(b=this.dragging_canvas=!0);65==a.keyCode&&a.ctrlKey&&(this.selectNodes(),b=!0);"KeyC"==a.code&&(a.metaKey||a.ctrlKey)&&!a.shiftKey&&this.selected_nodes&&(this.copyToClipboard(),b=!0);"KeyV"!=a.code||!a.metaKey&&!a.ctrlKey||a.shiftKey||this.pasteFromClipboard();
if(46==a.keyCode||8==a.keyCode)this.deleteSelectedNodes(),b=!0;if(this.selected_nodes)for(var d in this.selected_nodes)if(this.selected_nodes[d].onKeyDown)this.selected_nodes[d].onKeyDown(a)}else if("keyup"==a.type&&(32==a.keyCode&&(this.dragging_canvas=!1),this.selected_nodes))for(d in this.selected_nodes)if(this.selected_nodes[d].onKeyUp)this.selected_nodes[d].onKeyUp(a);this.graph.change();if(b)return a.preventDefault(),!1}}};h.prototype.copyToClipboard=function(){var a={nodes:[],links:[]},b=0,
d=[],c;for(c in this.selected_nodes){var f=this.selected_nodes[c];f._relative_id=b;d.push(f);b+=1}for(c=0;c<d.length;++c)if(f=d[c],a.nodes.push(f.clone().serialize()),f.inputs&&f.inputs.length)for(b=0;b<f.inputs.length;++b){var m=f.inputs[b];if(m&&null!=m.link&&(m=this.graph.links[m.link])){var k=this.graph.getNodeById(m.origin_id);k&&this.selected_nodes[k.id]&&a.links.push([k._relative_id,b,f._relative_id,m.target_slot])}}localStorage.setItem("litegrapheditor_clipboard",JSON.stringify(a))};h.prototype.pasteFromClipboard=
function(){var a=localStorage.getItem("litegrapheditor_clipboard");if(a){for(var a=JSON.parse(a),b=[],d=0;d<a.nodes.length;++d){var c=a.nodes[d],f=l.createNode(c.type);f&&(f.configure(c),f.pos[0]+=5,f.pos[1]+=5,this.graph.add(f),b.push(f))}for(d=0;d<a.links.length;++d)c=a.links[d],b[c[0]].connect(c[1],b[c[2]],c[3]);this.selectNodes(b)}};h.prototype.processDrop=function(a){a.preventDefault();this.adjustMouseEvent(a);var b=[a.canvasX,a.canvasY],d=this.graph.getNodeOnPos(b[0],b[1]);if(d){if((d.onDropFile||
d.onDropData)&&(b=a.dataTransfer.files)&&b.length)for(var c=0;c<b.length;c++){var f=a.dataTransfer.files[0],m=f.name;h.getFileExtension(m);if(d.onDropFile)d.onDropFile(f);if(d.onDropData){var k=new FileReader;k.onload=function(a){d.onDropData(a.target.result,m,f)};var e=f.type.split("/")[0];"text"==e||""==e?k.readAsText(f):"image"==e?k.readAsDataURL(f):k.readAsArrayBuffer(f)}}return d.onDropItem&&d.onDropItem(event)?!0:this.onDropItem?this.onDropItem(event):!1}b=null;this.onDropItem&&(b=this.onDropItem(event));
b||this.checkDropItem(a)};h.prototype.checkDropItem=function(a){if(a.dataTransfer.files.length){var b=a.dataTransfer.files[0],d=h.getFileExtension(b.name).toLowerCase();if(d=l.node_types_by_file_extension[d])if(d=l.createNode(d.type),d.pos=[a.canvasX,a.canvasY],this.graph.add(d),d.onDropFile)d.onDropFile(b)}};h.prototype.processNodeDblClicked=function(a){if(this.onShowNodePanel)this.onShowNodePanel(a);if(this.onNodeDblClicked)this.onNodeDblClicked(a);this.setDirty(!0)};h.prototype.processNodeSelected=
function(a,b){this.selectNode(a,b&&b.shiftKey);if(this.onNodeSelected)this.onNodeSelected(a)};h.prototype.processNodeDeselected=function(a){this.deselectNode(a);if(this.onNodeDeselected)this.onNodeDeselected(a)};h.prototype.selectNode=function(a,b){null==a?this.deselectAllNodes():this.selectNodes([a],b)};h.prototype.selectNodes=function(a,b){b||this.deselectAllNodes();a=a||this.graph._nodes;for(var d=0;d<a.length;++d){var c=a[d];if(!c.selected){if(!c.selected&&c.onSelected)c.onSelected();c.selected=
!0;this.selected_nodes[c.id]=c;if(c.inputs)for(d=0;d<c.inputs.length;++d)this.highlighted_links[c.inputs[d].link]=!0;if(c.outputs)for(d=0;d<c.outputs.length;++d){var f=c.outputs[d];if(f.links)for(var m=0;m<f.links.length;++m)this.highlighted_links[f.links[m]]=!0}}}this.setDirty(!0)};h.prototype.deselectNode=function(a){if(a.selected){if(a.onDeselected)a.onDeselected();a.selected=!1;if(a.inputs)for(var b=0;b<a.inputs.length;++b)delete this.highlighted_links[a.inputs[b].link];if(a.outputs)for(b=0;b<
a.outputs.length;++b){var d=a.outputs[b];if(d.links)for(var c=0;c<d.links.length;++c)delete this.highlighted_links[d.links[c]]}}};h.prototype.deselectAllNodes=function(){if(this.graph){for(var a=this.graph._nodes,b=0,d=a.length;b<d;++b){var c=a[b];if(c.selected){if(c.onDeselected)c.onDeselected();c.selected=!1}}this.selected_nodes={};this.highlighted_links={};this.setDirty(!0)}};h.prototype.deleteSelectedNodes=function(){for(var a in this.selected_nodes)this.graph.remove(this.selected_nodes[a]);this.selected_nodes=
{};this.highlighted_links={};this.setDirty(!0)};h.prototype.centerOnNode=function(a){this.offset[0]=-a.pos[0]-0.5*a.size[0]+0.5*this.canvas.width/this.scale;this.offset[1]=-a.pos[1]-0.5*a.size[1]+0.5*this.canvas.height/this.scale;this.setDirty(!0,!0)};h.prototype.adjustMouseEvent=function(a){var b=this.canvas.getBoundingClientRect();a.localX=a.pageX-b.left;a.localY=a.pageY-b.top;a.canvasX=a.localX/this.scale-this.offset[0];a.canvasY=a.localY/this.scale-this.offset[1]};h.prototype.setZoom=function(a,
b){b||(b=[0.5*this.canvas.width,0.5*this.canvas.height]);var d=this.convertOffsetToCanvas(b);this.scale=a;this.scale>this.max_zoom?this.scale=this.max_zoom:this.scale<this.min_zoom&&(this.scale=this.min_zoom);var c=this.convertOffsetToCanvas(b),d=[c[0]-d[0],c[1]-d[1]];this.offset[0]+=d[0];this.offset[1]+=d[1];this.dirty_bgcanvas=this.dirty_canvas=!0};h.prototype.convertOffsetToCanvas=function(a,b){b=b||[];b[0]=a[0]/this.scale-this.offset[0];b[1]=a[1]/this.scale-this.offset[1];return b};h.prototype.convertCanvasToOffset=
function(a,b){b=b||[];b[0]=(a[0]+this.offset[0])*this.scale;b[1]=(a[1]+this.offset[1])*this.scale;return b};h.prototype.convertEventToCanvas=function(a){var b=this.canvas.getBoundingClientRect();return this.convertOffsetToCanvas([a.pageX-b.left,a.pageY-b.top])};h.prototype.bringToFront=function(a){var b=this.graph._nodes.indexOf(a);-1!=b&&(this.graph._nodes.splice(b,1),this.graph._nodes.push(a))};h.prototype.sendToBack=function(a){var b=this.graph._nodes.indexOf(a);-1!=b&&(this.graph._nodes.splice(b,
1),this.graph._nodes.unshift(a))};var s=new Float32Array(4);h.prototype.computeVisibleNodes=function(a,b){var d=b||[];d.length=0;a=a||this.graph._nodes;for(var c=0,f=a.length;c<f;++c){var m=a[c];(!this.live_mode||m.onDrawBackground||m.onDrawForeground)&&q(this.visible_area,m.getBounding(s))&&d.push(m)}return d};h.prototype.draw=function(a,b){if(this.canvas){var d=l.getTime();this.render_time=0.001*(d-this.last_draw_time);this.last_draw_time=d;if(this.graph){var c=[-this.offset[0],-this.offset[1]],
f=[c[0]+this.canvas.width/this.scale,c[1]+this.canvas.height/this.scale];this.visible_area=new Float32Array([c[0],c[1],f[0]-c[0],f[1]-c[1]])}(this.dirty_bgcanvas||b||this.always_render_background||this.graph&&this.graph._last_trigger_time&&1E3>d-this.graph._last_trigger_time)&&this.drawBackCanvas();(this.dirty_canvas||a)&&this.drawFrontCanvas();this.fps=this.render_time?1/this.render_time:0;this.frame+=1}};h.prototype.drawFrontCanvas=function(){this.ctx||(this.ctx=this.bgcanvas.getContext("2d"));
var a=this.ctx;if(a){a.start2D&&a.start2D();var b=this.canvas;a.restore();a.setTransform(1,0,0,1,0,0);this.dirty_area&&(a.save(),a.beginPath(),a.rect(this.dirty_area[0],this.dirty_area[1],this.dirty_area[2],this.dirty_area[3]),a.clip());this.clear_background&&a.clearRect(0,0,b.width,b.height);this.bgcanvas==this.canvas?this.drawBackCanvas():a.drawImage(this.bgcanvas,0,0);if(this.onRender)this.onRender(b,a);this.show_info&&this.renderInfo(a);if(this.graph){a.save();a.scale(this.scale,this.scale);a.translate(this.offset[0],
this.offset[1]);for(var b=this.computeVisibleNodes(null,this.visible_nodes),d=0;d<b.length;++d){var c=b[d];a.save();a.translate(c.pos[0],c.pos[1]);this.drawNode(c,a);a.restore()}this.graph.config.links_ontop&&(this.live_mode||this.drawConnections(a));if(null!=this.connecting_pos){a.lineWidth=this.connections_width;b=null;switch(this.connecting_output.type){case l.EVENT:b="#F85";break;default:b="#AFA"}this.renderLink(a,this.connecting_pos,[this.canvas_mouse[0],this.canvas_mouse[1]],null,!1,null,b);
a.beginPath();this.connecting_output.type===l.EVENT?a.rect(this.connecting_pos[0]-6+0.5,this.connecting_pos[1]-5+0.5,14,10):a.arc(this.connecting_pos[0],this.connecting_pos[1],4,0,2*Math.PI);a.fill();a.fillStyle="#ffcc00";this._highlight_input&&(a.beginPath(),a.arc(this._highlight_input[0],this._highlight_input[1],6,0,2*Math.PI),a.fill())}this.dragging_rectangle&&(a.strokeStyle="#FFF",a.strokeRect(this.dragging_rectangle[0],this.dragging_rectangle[1],this.dragging_rectangle[2],this.dragging_rectangle[3]));
a.restore()}this.dirty_area&&a.restore();a.finish2D&&a.finish2D();this.dirty_canvas=!1}};h.prototype.renderInfo=function(a,b,d){b=b||0;d=d||0;a.save();a.translate(b,d);a.font="10px Arial";a.fillStyle="#888";this.graph?(a.fillText("T: "+this.graph.globaltime.toFixed(2)+"s",5,13),a.fillText("I: "+this.graph.iteration,5,26),a.fillText("F: "+this.frame,5,39),a.fillText("FPS:"+this.fps.toFixed(2),5,52)):a.fillText("No graph selected",5,13);a.restore()};h.prototype.drawBackCanvas=function(){var a=this.bgcanvas;
if(a.width!=this.canvas.width||a.height!=this.canvas.height)a.width=this.canvas.width,a.height=this.canvas.height;this.bgctx||(this.bgctx=this.bgcanvas.getContext("2d"));var b=this.bgctx;b.start&&b.start();this.clear_background&&b.clearRect(0,0,a.width,a.height);this._graph_stack&&this._graph_stack.length&&(b.strokeStyle=this._graph_stack[this._graph_stack.length-1].bgcolor,b.lineWidth=10,b.strokeRect(1,1,a.width-2,a.height-2),b.lineWidth=1);b.restore();b.setTransform(1,0,0,1,0,0);if(this.graph){b.save();
b.scale(this.scale,this.scale);b.translate(this.offset[0],this.offset[1]);if(this.background_image&&0.5<this.scale){b.globalAlpha=this.zoom_modify_alpha?(1-0.5/this.scale)*this.editor_alpha:this.editor_alpha;b.imageSmoothingEnabled=b.mozImageSmoothingEnabled=b.imageSmoothingEnabled=!1;if(!this._bg_img||this._bg_img.name!=this.background_image){this._bg_img=new Image;this._bg_img.name=this.background_image;this._bg_img.src=this.background_image;var d=this;this._bg_img.onload=function(){d.draw(!0,!0)}}var c=
null;null==this._pattern&&0<this._bg_img.width?(c=b.createPattern(this._bg_img,"repeat"),this._pattern_img=this._bg_img,this._pattern=c):c=this._pattern;c&&(b.fillStyle=c,b.fillRect(this.visible_area[0],this.visible_area[1],this.visible_area[2],this.visible_area[3]),b.fillStyle="transparent");b.globalAlpha=1;b.imageSmoothingEnabled=b.mozImageSmoothingEnabled=b.imageSmoothingEnabled=!0}if(this.onBackgroundRender)this.onBackgroundRender(a,b);this.render_canvas_border&&(b.strokeStyle="#235",b.strokeRect(0,
0,a.width,a.height));this.render_connections_shadows?(b.shadowColor="#000",b.shadowOffsetX=0,b.shadowOffsetY=0,b.shadowBlur=6):b.shadowColor="rgba(0,0,0,0)";this.live_mode||this.drawConnections(b);b.shadowColor="rgba(0,0,0,0)";b.restore()}b.finish&&b.finish();this.dirty_bgcanvas=!1;this.dirty_canvas=!0};var c=new Float32Array(2);h.prototype.drawNode=function(a,b){var d=a.color||l.NODE_DEFAULT_COLOR,h=!0;if(a.flags.skip_title_render||a.graph.isLive())h=!1;a.mouseOver&&(h=!0);a.selected||(this.render_shadows?
(b.shadowColor="rgba(0,0,0,0.5)",b.shadowOffsetX=2,b.shadowOffsetY=2,b.shadowBlur=3):b.shadowColor="transparent");if(this.live_mode){if(!a.flags.collapsed&&(b.shadowColor="transparent",a.onDrawForeground))a.onDrawForeground(b)}else{var f=this.editor_alpha;b.globalAlpha=f;var m=a._shape||l.BOX_SHAPE;c.set(a.size);a.flags.collapsed&&(c[0]=l.NODE_COLLAPSED_WIDTH,c[1]=0);a.flags.clip_area&&(b.save(),m==l.BOX_SHAPE?(b.beginPath(),b.rect(0,0,c[0],c[1])):m==l.ROUND_SHAPE?b.roundRect(0,0,c[0],c[1],10):m==
l.CIRCLE_SHAPE&&(b.beginPath(),b.arc(0.5*c[0],0.5*c[1],0.5*c[0],0,2*Math.PI)),b.clip());this.drawNodeShape(a,b,c,d,a.bgcolor,!h,a.selected);b.shadowColor="transparent";b.textAlign="left";b.font=this.inner_text_font;h=0.6<this.scale;m=this.connecting_output;if(!a.flags.collapsed){if(a.inputs)for(var k=0;k<a.inputs.length;k++){var e=a.inputs[k];b.globalAlpha=f;this.connecting_node&&l.isValidConnection(e.type&&m.type)&&(b.globalAlpha=0.4*f);b.fillStyle=null!=e.link?this.default_connection_color.input_on:
this.default_connection_color.input_off;var g=a.getConnectionPos(!0,k);g[0]-=a.pos[0];g[1]-=a.pos[1];b.beginPath();e.type===l.EVENT?b.rect(g[0]-6+0.5,g[1]-5+0.5,14,10):b.arc(g[0],g[1],4,0,2*Math.PI);b.fill();h&&(e=null!=e.label?e.label:e.name)&&(b.fillStyle=d,b.fillText(e,g[0]+10,g[1]+5))}this.connecting_node&&(b.globalAlpha=0.4*f);b.lineWidth=1;b.textAlign="right";b.strokeStyle="black";if(a.outputs)for(k=0;k<a.outputs.length;k++)if(e=a.outputs[k],g=a.getConnectionPos(!1,k),g[0]-=a.pos[0],g[1]-=a.pos[1],
b.fillStyle=e.links&&e.links.length?this.default_connection_color.output_on:this.default_connection_color.output_off,b.beginPath(),e.type===l.EVENT?b.rect(g[0]-6+0.5,g[1]-5+0.5,14,10):b.arc(g[0],g[1],4,0,2*Math.PI),b.fill(),b.stroke(),h&&(e=null!=e.label?e.label:e.name))b.fillStyle=d,b.fillText(e,g[0]-10,g[1]+5);b.textAlign="left";b.globalAlpha=1;if(a.onDrawForeground)a.onDrawForeground(b)}a.flags.clip_area&&b.restore();b.globalAlpha=1}};h.prototype.drawNodeShape=function(a,b,d,c,f,e,k){b.strokeStyle=
c||l.NODE_DEFAULT_COLOR;b.fillStyle=f||l.NODE_DEFAULT_BGCOLOR;f=l.NODE_TITLE_HEIGHT;var h=a._shape||l.BOX_SHAPE;h==l.BOX_SHAPE?(b.beginPath(),b.rect(0,e?0:-f,d[0]+1,e?d[1]:d[1]+f),b.fill(),b.shadowColor="transparent",k&&(b.strokeStyle="#CCC",b.strokeRect(-0.5,e?-0.5:-f+-0.5,d[0]+2,e?d[1]+2:d[1]+f+2-1),b.strokeStyle=c)):h==l.ROUND_SHAPE?(b.roundRect(0,e?0:-f,d[0],e?d[1]:d[1]+f,10),b.fill()):h==l.CIRCLE_SHAPE&&(b.beginPath(),b.arc(0.5*d[0],0.5*d[1],0.5*d[0],0,2*Math.PI),b.fill());b.shadowColor="transparent";
a.bgImage&&a.bgImage.width&&b.drawImage(a.bgImage,0.5*(d[0]-a.bgImage.width),0.5*(d[1]-a.bgImage.height));a.bgImageUrl&&!a.bgImage&&(a.bgImage=a.loadImage(a.bgImageUrl));if(a.onDrawBackground)a.onDrawBackground(b);e||(b.fillStyle=c||l.NODE_DEFAULT_COLOR,c=b.globalAlpha,b.globalAlpha=0.5*c,h==l.BOX_SHAPE?(b.beginPath(),b.rect(0,-f,d[0]+1,f),b.fill()):h==l.ROUND_SHAPE&&(b.roundRect(0,-f,d[0],f,10,0),b.fill()),b.fillStyle=a.boxcolor||l.NODE_DEFAULT_BOXCOLOR,b.beginPath(),h==l.ROUND_SHAPE||h==l.CIRCLE_SHAPE?
b.arc(0.5*f,-0.5*f,0.5*(f-6),0,2*Math.PI):b.rect(3,-f+3,f-6,f-6),b.fill(),b.globalAlpha=c,b.font=this.title_text_font,(a=a.getTitle())&&0.5<this.scale&&(b.fillStyle=this.node_title_color,b.fillText(a,16,13-f)))};h.prototype.drawNodeCollapsed=function(a,b,c,e){b.strokeStyle=c||l.NODE_DEFAULT_COLOR;b.fillStyle=e||l.NODE_DEFAULT_BGCOLOR;c=l.NODE_COLLAPSED_RADIUS;e=a._shape||l.BOX_SHAPE;e==l.CIRCLE_SHAPE?(b.beginPath(),b.arc(0.5*a.size[0],0.5*a.size[1],c,0,2*Math.PI),b.fill(),b.shadowColor="rgba(0,0,0,0)",
b.stroke(),b.fillStyle=a.boxcolor||l.NODE_DEFAULT_BOXCOLOR,b.beginPath(),b.arc(0.5*a.size[0],0.5*a.size[1],0.5*c,0,2*Math.PI)):e==l.ROUND_SHAPE?(b.beginPath(),b.roundRect(0.5*a.size[0]-c,0.5*a.size[1]-c,2*c,2*c,5),b.fill(),b.shadowColor="rgba(0,0,0,0)",b.stroke(),b.fillStyle=a.boxcolor||l.NODE_DEFAULT_BOXCOLOR,b.beginPath(),b.roundRect(0.5*a.size[0]-0.5*c,0.5*a.size[1]-0.5*c,c,c,2)):(b.beginPath(),b.rect(0,0,a.size[0],2*c),b.fill(),b.shadowColor="rgba(0,0,0,0)",b.stroke(),b.fillStyle=a.boxcolor||
l.NODE_DEFAULT_BOXCOLOR,b.beginPath(),b.rect(0.5*c,0.5*c,c,c));b.fill()};h.prototype.drawConnections=function(a){var b=l.getTime();a.lineWidth=this.connections_width;a.fillStyle="#AAA";a.strokeStyle="#AAA";a.globalAlpha=this.editor_alpha;for(var c=0,e=this.graph._nodes.length;c<e;++c){var f=this.graph._nodes[c];if(f.inputs&&f.inputs.length)for(var h=0;h<f.inputs.length;++h){var k=f.inputs[h];if(k&&null!=k.link&&(k=this.graph.links[k.link])){var g=this.graph.getNodeById(k.origin_id);if(null!=g){var n=
k.origin_slot,p=null,p=-1==n?[g.pos[0]+10,g.pos[1]+10]:g.getConnectionPos(!1,n);this.renderLink(a,p,f.getConnectionPos(!0,h),k);k&&k._last_time&&1E3>b-k._last_time&&(g=2-0.002*(b-k._last_time),n="rgba(255,255,255, "+g.toFixed(2)+")",this.renderLink(a,p,f.getConnectionPos(!0,h),k,!0,g,n))}}}}a.globalAlpha=1};h.prototype.renderLink=function(a,b,c,e,f,m,k){if(this.highquality_render){var g=n(b,c);this.render_connections_border&&0.6<this.scale&&(a.lineWidth=this.connections_width+4);!k&&e&&(k=h.link_type_colors[e.type]);
k||(k=this.default_link_color);null!=e&&this.highlighted_links[e.id]&&(k="#FFF");a.beginPath();this.render_curved_connections?(a.moveTo(b[0],b[1]),a.bezierCurveTo(b[0]+0.25*g,b[1],c[0]-0.25*g,c[1],c[0],c[1])):(a.moveTo(b[0]+10,b[1]),a.lineTo(0.5*(b[0]+10+(c[0]-10)),b[1]),a.lineTo(0.5*(b[0]+10+(c[0]-10)),c[1]),a.lineTo(c[0]-10,c[1]));this.render_connections_border&&0.6<this.scale&&!f&&(a.strokeStyle="rgba(0,0,0,0.5)",a.stroke());a.lineWidth=this.connections_width;a.fillStyle=a.strokeStyle=k;a.stroke();
this.render_connection_arrows&&0.6<=this.scale&&this.render_connection_arrows&&0.6<this.scale&&(e=this.computeConnectionPoint(b,c,0.5),f=this.computeConnectionPoint(b,c,0.51),k=0,k=this.render_curved_connections?-Math.atan2(f[0]-e[0],f[1]-e[1]):c[1]>b[1]?0:Math.PI,a.save(),a.translate(e[0],e[1]),a.rotate(k),a.beginPath(),a.moveTo(-5,-5),a.lineTo(0,5),a.lineTo(5,-5),a.fill(),a.restore());if(m)for(m=0;5>m;++m)e=(0.001*l.getTime()+0.2*m)%1,e=this.computeConnectionPoint(b,c,e),a.beginPath(),a.arc(e[0],
e[1],5,0,2*Math.PI),a.fill()}else a.beginPath(),a.moveTo(b[0],b[1]),a.lineTo(c[0],c[1]),a.stroke()};h.prototype.computeConnectionPoint=function(a,b,c){var e=n(a,b),f=[a[0]+0.25*e,a[1]],e=[b[0]-0.25*e,b[1]],h=(1-c)*(1-c)*(1-c),k=3*(1-c)*(1-c)*c,g=3*(1-c)*c*c;c*=c*c;return[h*a[0]+k*f[0]+g*e[0]+c*b[0],h*a[1]+k*f[1]+g*e[1]+c*b[1]]};h.prototype.resize=function(a,b){if(!a&&!b){var c=this.canvas.parentNode;a=c.offsetWidth;b=c.offsetHeight}if(this.canvas.width!=a||this.canvas.height!=b)this.canvas.width=
a,this.canvas.height=b,this.bgcanvas.width=this.canvas.width,this.bgcanvas.height=this.canvas.height,this.setDirty(!0,!0)};h.prototype.switchLiveMode=function(a){if(a){var b=this,c=this.live_mode?1.1:0.9;this.live_mode&&(this.live_mode=!1,this.editor_alpha=0.1);var e=setInterval(function(){b.editor_alpha*=c;b.dirty_canvas=!0;b.dirty_bgcanvas=!0;1>c&&0.01>b.editor_alpha&&(clearInterval(e),1>c&&(b.live_mode=!0));1<c&&0.99<b.editor_alpha&&(clearInterval(e),b.editor_alpha=1)},1)}else this.live_mode=!this.live_mode,
this.dirty_bgcanvas=this.dirty_canvas=!0};h.prototype.onNodeSelectionChange=function(a){};h.prototype.touchHandler=function(a){var b=a.changedTouches[0],c="";switch(a.type){case "touchstart":c="mousedown";break;case "touchmove":c="mousemove";break;case "touchend":c="mouseup";break;default:return}var e=this.getCanvasWindow(),f=e.document.createEvent("MouseEvent");f.initMouseEvent(c,!0,!0,e,1,b.screenX,b.screenY,b.clientX,b.clientY,!1,!1,!1,!1,0,null);b.target.dispatchEvent(f);a.preventDefault()};h.onMenuAdd=
function(a,b,c,e){function f(a,b){var c=e.getFirstEvent(),d=l.createNode(a.value);d&&(d.pos=g.convertEventToCanvas(c),g.graph.add(d))}var g=h.active_canvas,k=g.getCanvasWindow();a=l.getNodeTypesCategories();b=[];for(var n in a)a[n]&&b.push({value:a[n],content:a[n],has_submenu:!0});var p=new l.ContextMenu(b,{event:c,callback:function(a,b,c){a=l.getNodeTypesInCategory(a.value);b=[];for(var d in a)b.push({content:a[d].title,value:a[d].type});new l.ContextMenu(b,{event:c,callback:f,parentMenu:p},k);return!1},
parentMenu:e},k);return!1};h.onMenuCollapseAll=function(){};h.onMenuNodeEdit=function(){};h.showMenuNodeOptionalInputs=function(a,b,c,e,f){function g(a,b,c){f&&(a.callback&&a.callback.call(k,f,a,b,c),a.value&&(f.addInput(a.value[0],a.value[1],a.value[2]),f.setDirtyCanvas(!0,!0)))}if(f){var k=this;a=h.active_canvas.getCanvasWindow();b=f.optional_inputs;f.onGetInputs&&(b=f.onGetInputs());var n=[];if(b)for(var p in b){var q=b[p];if(q){var r=q[0];q[2]&&q[2].label&&(r=q[2].label);r={content:r,value:q};
q[1]==l.ACTION&&(r.className="event");n.push(r)}else n.push(null)}this.onMenuNodeInputs&&(n=this.onMenuNodeInputs(n));if(n.length)return new l.ContextMenu(n,{event:c,callback:g,parentMenu:e,node:f},a),!1}};h.showMenuNodeOptionalOutputs=function(a,b,c,e,f){function g(a,b,c){if(f&&(a.callback&&a.callback.call(k,f,a,b,c),a.value))if(c=a.value[1],!c||c.constructor!==Object&&c.constructor!==Array)f.addOutput(a.value[0],a.value[1],a.value[2]),f.setDirtyCanvas(!0,!0);else{a=[];for(var d in c)a.push({content:d,
value:c[d]});new l.ContextMenu(a,{event:b,callback:g,parentMenu:e,node:f});return!1}}if(f){var k=this;a=h.active_canvas.getCanvasWindow();b=f.optional_outputs;f.onGetOutputs&&(b=f.onGetOutputs());var n=[];if(b)for(var p in b){var q=b[p];if(!q)n.push(null);else if(!f.flags||!f.flags.skip_repeated_outputs||-1==f.findOutputSlot(q[0])){var r=q[0];q[2]&&q[2].label&&(r=q[2].label);r={content:r,value:q};q[1]==l.EVENT&&(r.className="event");n.push(r)}}this.onMenuNodeOutputs&&(n=this.onMenuNodeOutputs(n));
if(n.length)return new l.ContextMenu(n,{event:c,callback:g,parentMenu:e,node:f},a),!1}};h.onShowMenuNodeProperties=function(a,b,c,e,f){function g(a,b,c,d){f&&(b=this.getBoundingClientRect(),k.showEditPropertyValue(f,a.value,{position:[b.left,b.top]}))}if(f&&f.properties){var k=h.active_canvas;b=k.getCanvasWindow();var n=[],p;for(p in f.properties)a=void 0!==f.properties[p]?f.properties[p]:" ",a=h.decodeHTML(a),n.push({content:"<span class='property_name'>"+p+"</span><span class='property_value'>"+
a+"</span>",value:p});if(n.length)return new l.ContextMenu(n,{event:c,callback:g,parentMenu:e,allow_html:!0,node:f},b),!1}};h.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};h.onResizeNode=function(a,b,c,e,f){f&&(f.size=f.computeSize(),f.setDirtyCanvas(!0,!0))};h.onShowTitleEditor=function(a,b,c,e,f){function g(){f.title=n.value;k.parentNode.removeChild(k);f.setDirtyCanvas(!0,!0)}var k=document.createElement("div");k.className="graphdialog";k.innerHTML=
"<span class='name'>Title</span><input autofocus type='text' class='value'/><button>OK</button>";var n=k.querySelector("input");n&&(n.value=f.title,n.addEventListener("keydown",function(a){13==a.keyCode&&(g(),a.preventDefault(),a.stopPropagation())}));a=h.active_canvas.canvas;b=a.getBoundingClientRect();e=c=-20;b&&(c-=b.left,e-=b.top);event?(k.style.left=event.pageX+c+"px",k.style.top=event.pageY+e+"px"):(k.style.left=0.5*a.width+c+"px",k.style.top=0.5*a.height+e+"px");k.querySelector("button").addEventListener("click",
g);a.parentNode.appendChild(k)};h.prototype.showEditPropertyValue=function(a,b,c){function e(){f(q.value)}function f(c){"number"==typeof a.properties[b]&&(c=Number(c));a.properties[b]=c;if(a.onPropertyChanged)a.onPropertyChanged(b,c);p.close();a.setDirtyCanvas(!0,!0)}if(a&&void 0!==a.properties[b]){c=c||{};var h="string";null!==a.properties[b]&&(h=typeof a.properties[b]);var k=null;a.getPropertyInfo&&(k=a.getPropertyInfo(b));if(a.properties_info)for(var g=0;g<a.properties_info.length;++g)if(a.properties_info[g].name==
b){k=a.properties_info[g];break}void 0!==k&&null!==k&&k.type&&(h=k.type);var n="";if("string"==h||"number"==h)n="<input autofocus type='text' class='value'/>";else if("enum"==h&&k.values){n="<select autofocus type='text' class='value'>";for(g in k.values)var l=k.values.constructor===Array?k.values[g]:g,n=n+("<option value='"+l+"' "+(l==a.properties[b]?"selected":"")+">"+k.values[g]+"</option>");n+="</select>"}else"boolean"==h&&(n="<input autofocus type='checkbox' class='value' "+(a.properties[b]?
"checked":"")+"/>");var p=this.createDialog("<span class='name'>"+b+"</span>"+n+"<button>OK</button>",c);if("enum"==h&&k.values){var q=p.querySelector("select");q.addEventListener("change",function(a){f(a.target.value)})}else if("boolean"==h)(q=p.querySelector("input"))&&q.addEventListener("click",function(a){f(!!q.checked)});else if(q=p.querySelector("input"))q.value=void 0!==a.properties[b]?a.properties[b]:"",q.addEventListener("keydown",function(a){13==a.keyCode&&(e(),a.preventDefault(),a.stopPropagation())});
p.querySelector("button").addEventListener("click",e)}};h.prototype.createDialog=function(a,b){b=b||{};var c=document.createElement("div");c.className="graphdialog";c.innerHTML=a;var e=this.canvas.getBoundingClientRect(),f=-20,h=-20;e&&(f-=e.left,h-=e.top);b.position?(f+=b.position[0],h+=b.position[1]):b.event?(f+=b.event.pageX,h+=b.event.pageY):(f+=0.5*this.canvas.width,h+=0.5*this.canvas.height);c.style.left=f+"px";c.style.top=h+"px";this.canvas.parentNode.appendChild(c);c.close=function(){this.parentNode&&
this.parentNode.removeChild(this)};return c};h.onMenuNodeCollapse=function(a,b,c,e,f){f.flags.collapsed=!f.flags.collapsed;f.setDirtyCanvas(!0,!0)};h.onMenuNodePin=function(a,b,c,e,f){f.pin()};h.onMenuNodeMode=function(a,b,c,e,f){new l.ContextMenu(["Always","On Event","On Trigger","Never"],{event:c,callback:function(a){if(f)switch(a){case "On Event":f.mode=l.ON_EVENT;break;case "On Trigger":f.mode=l.ON_TRIGGER;break;case "Never":f.mode=l.NEVER;break;default:f.mode=l.ALWAYS}},parentMenu:e,node:f});
return!1};h.onMenuNodeColors=function(a,b,c,e,f){if(!f)throw"no node for color";b=[];for(var g in h.node_colors)a=h.node_colors[g],a={value:g,content:"<span style='display: block; color:"+a.color+"; background-color:"+a.bgcolor+"'>"+g+"</span>"},b.push(a);new l.ContextMenu(b,{event:c,callback:function(a){f&&(a=h.node_colors[a.value])&&(f.color=a.color,f.bgcolor=a.bgcolor,f.setDirtyCanvas(!0))},parentMenu:e,node:f});return!1};h.onMenuNodeShapes=function(a,b,c,e,f){if(!f)throw"no node passed";new l.ContextMenu(l.VALID_SHAPES,
{event:c,callback:function(a){f&&(f.shape=a,f.setDirtyCanvas(!0))},parentMenu:e,node:f});return!1};h.onMenuNodeRemove=function(a,b,c,e,f){if(!f)throw"no node passed";!1!=f.removable&&(f.graph.remove(f),f.setDirtyCanvas(!0,!0))};h.onMenuNodeClone=function(a,b,c,e,f){!1!=f.clonable&&(a=f.clone())&&(a.pos=[f.pos[0]+5,f.pos[1]+5],f.graph.add(a),f.setDirtyCanvas(!0,!0))};h.node_colors={red:{color:"#FAA",bgcolor:"#944"},green:{color:"#AFA",bgcolor:"#494"},blue:{color:"#AAF",bgcolor:"#449"},cyan:{color:"#AFF",
bgcolor:"#499"},purple:{color:"#FAF",bgcolor:"#949"},yellow:{color:"#FFA",bgcolor:"#994"},black:{color:"#777",bgcolor:"#000"},white:{color:"#FFF",bgcolor:"#AAA"}};h.prototype.getCanvasMenuOptions=function(){var a=null;this.getMenuOptions?a=this.getMenuOptions():(a=[{content:"Add Node",has_submenu:!0,callback:h.onMenuAdd}],this._graph_stack&&0<this._graph_stack.length&&(a=[{content:"Close subgraph",callback:this.closeSubgraph.bind(this)},null].concat(a)));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.onShowTitleEditor},{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.getExtraMenuOptions){var c=a.getExtraMenuOptions(this);c&&(c.push(null),b=c.concat(b))}!1!==a.clonable&&b.push({content:"Clone",callback:h.onMenuNodeClone});!1!==a.removable&&b.push(null,{content:"Remove",callback:h.onMenuNodeRemove});a.onGetInputs&&
(c=a.onGetInputs())&&c.length&&(b[0].disabled=!1);a.onGetOutputs&&(c=a.onGetOutputs())&&c.length&&(b[1].disabled=!1);if(a.graph&&a.graph.onGetNodeMenuOptions)a.graph.onGetNodeMenuOptions(b,a);return b};h.prototype.processContextMenu=function(a,b){var c=this,e=h.active_canvas.getCanvasWindow(),f=null,g={event:b,callback:function(b,f,e){if(b)if("Remove Slot"==b.content){var k=b.slot;k.input?a.removeInput(k.slot):k.output&&a.removeOutput(k.slot)}else if("Rename Slot"==b.content){var k=b.slot,h=c.createDialog("<span class='name'>Name</span><input type='text'/><button>OK</button>",
f),g=h.querySelector("input");h.querySelector("button").addEventListener("click",function(b){if(g.value){if(b=k.input?a.getInputInfo(k.slot):a.getOutputInfo(k.slot))b.label=g.value;c.setDirty(!0)}h.close()})}},node:a},k=null;a&&(k=a.getSlotInPosition(b.canvasX,b.canvasY),h.active_node=a);k?(f=[],f.push(k.locked?"Cannot remove":{content:"Remove Slot",slot:k}),f.push({content:"Rename Slot",slot:k}),g.title=(k.input?k.input.type:k.output.type)||"*",k.input&&k.input.type==l.ACTION&&(g.title="Action"),
k.output&&k.output.type==l.EVENT&&(g.title="Event")):f=a?this.getNodeMenuOptions(a):this.getCanvasMenuOptions();f&&new l.ContextMenu(f,g,e)};this.CanvasRenderingContext2D&&(CanvasRenderingContext2D.prototype.roundRect=function(a,b,c,e,f,h){void 0===f&&(f=5);void 0===h&&(h=f);this.beginPath();this.moveTo(a+f,b);this.lineTo(a+c-f,b);this.quadraticCurveTo(a+c,b,a+c,b+f);this.lineTo(a+c,b+e-h);this.quadraticCurveTo(a+c,b+e,a+c-h,b+e);this.lineTo(a+h,b+e);this.quadraticCurveTo(a,b+e,a,b+e-h);this.lineTo(a,
b+f);this.quadraticCurveTo(a,b,a+f,b)});l.compareObjects=function(a,b){for(var c in a)if(a[c]!=b[c])return!1;return!0};l.distance=n;l.colorToString=function(a){return"rgba("+Math.round(255*a[0]).toFixed()+","+Math.round(255*a[1]).toFixed()+","+Math.round(255*a[2]).toFixed()+","+(4==a.length?a[3].toFixed(2):"1.0")+")"};l.isInsideRectangle=p;l.growBounding=function(a,b,c){b<a[0]?a[0]=b:b>a[2]&&(a[2]=b);c<a[1]?a[1]=c:c>a[3]&&(a[3]=c)};l.isInsideBounding=function(a,b){return a[0]<b[0][0]||a[1]<b[0][1]||
a[0]>b[1][0]||a[1]>b[1][1]?!1:!0};l.overlapBounding=q;l.hex2num=function(a){"#"==a.charAt(0)&&(a=a.slice(1));a=a.toUpperCase();for(var b=Array(3),c=0,e,f,h=0;6>h;h+=2)e="0123456789ABCDEF".indexOf(a.charAt(h)),f="0123456789ABCDEF".indexOf(a.charAt(h+1)),b[c]=16*e+f,c++;return b};l.num2hex=function(a){for(var b="#",c,e,f=0;3>f;f++)c=a[f]/16,e=a[f]%16,b+="0123456789ABCDEF".charAt(c)+"0123456789ABCDEF".charAt(e);return b};r.prototype.addItem=function(a,b,c){function e(a){var b=this.value;b&&b.has_submenu&&
f.call(this,a)}function f(a){var b=this.value,f=!0;h.current_submenu&&h.current_submenu.close(a);if(c.callback){var e=c.callback.call(this,b,c,a,h,c.node);!0===e&&(f=!1)}if(b&&(b.callback&&!c.ignore_item_callbacks&&!0!==b.disabled&&(e=b.callback.call(this,b,c,a,h,c.node),!0===e&&(f=!1)),b.submenu)){if(!b.submenu.options)throw"ContextMenu submenu needs options";new h.constructor(b.submenu.options,{callback:b.submenu.callback,event:a,parentMenu:h,ignore_item_callbacks:b.submenu.ignore_item_callbacks,
title:b.submenu.title,autoopen:c.autoopen});f=!1}f&&!h.lock&&h.close()}var h=this;c=c||{};var k=document.createElement("div");k.className="litemenu-entry submenu";var g=!1;if(null===b)k.classList.add("separator");else{k.innerHTML=b&&b.title?b.title:a;if(k.value=b)b.disabled&&(g=!0,k.classList.add("disabled")),(b.submenu||b.has_submenu)&&k.classList.add("has_submenu");"function"==typeof b?(k.dataset.value=a,k.onclick_callback=b):k.dataset.value=b;b.className&&(k.className+=" "+b.className)}this.root.appendChild(k);
g||k.addEventListener("click",f);c.autoopen&&k.addEventListener("mouseenter",e);return k};r.prototype.close=function(a,b){this.root.parentNode&&this.root.parentNode.removeChild(this.root);this.parentMenu&&!b&&(this.parentMenu.lock=!1,this.parentMenu.current_submenu=null,void 0===a?this.parentMenu.close():a&&!r.isCursorOverElement(a,this.parentMenu.root)&&r.trigger(this.parentMenu.root,"mouseleave",a));this.current_submenu&&this.current_submenu.close(a,!0)};r.trigger=function(a,b,c,e){var f=document.createEvent("CustomEvent");
f.initCustomEvent(b,!0,!0,c);f.srcElement=e;a.dispatchEvent?a.dispatchEvent(f):a.__events&&a.__events.dispatchEvent(f);return f};r.prototype.getTopMenu=function(){return this.options.parentMenu?this.options.parentMenu.getTopMenu():this};r.prototype.getFirstEvent=function(){return this.options.parentMenu?this.options.parentMenu.getFirstEvent():this.options.event};r.isCursorOverElement=function(a,b){var c=a.pageX,e=a.pageY,f=b.getBoundingClientRect();return f?e>f.top&&e<f.top+f.height&&c>f.left&&c<
f.left+f.width?!0:!1:!1};l.ContextMenu=r;l.closeAllContextMenus=function(a){a=a||window;a=a.document.querySelectorAll(".litecontextmenu");if(a.length){for(var b=[],c=0;c<a.length;c++)b.push(a[c]);for(c in b)b[c].close?b[c].close():b[c].parentNode&&b[c].parentNode.removeChild(b[c])}};l.extendClass=function(a,b){for(var c in b)a.hasOwnProperty(c)||(a[c]=b[c]);if(b.prototype)for(c in b.prototype)b.prototype.hasOwnProperty(c)&&!a.prototype.hasOwnProperty(c)&&(b.prototype.__lookupGetter__(c)?a.prototype.__defineGetter__(c,
b.prototype.__lookupGetter__(c)):a.prototype[c]=b.prototype[c],b.prototype.__lookupSetter__(c)&&a.prototype.__defineSetter__(c,b.prototype.__lookupSetter__(c)))};l.getParameterNames=function(a){return(a+"").replace(/[/][/].*$/mg,"").replace(/\s+/g,"").replace(/[/][*][^/*]*[*][/]/g,"").split("){",1)[0].replace(/^[^(]*[(]/,"").replace(/=[^,]+/g,"").split(",").filter(Boolean)};Math.clamp=function(a,b,c){return b>a?b:c<a?c:a};"undefined"==typeof window||window.requestAnimationFrame||(window.requestAnimationFrame=
window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(a){window.setTimeout(a,1E3/60)})})(this);"undefined"!=typeof exports&&(exports.LiteGraph=this.LiteGraph);
(function(u){function g(){this.addOutput("in ms","number");this.addOutput("in sec","number")}function e(){this.size=[120,60];this.subgraph=new LGraph;this.subgraph._subgraph_node=this;this.subgraph._is_subgraph=!0;this.subgraph.onGlobalInputAdded=this.onSubgraphNewGlobalInput.bind(this);this.subgraph.onGlobalInputRenamed=this.onSubgraphRenamedGlobalInput.bind(this);this.subgraph.onGlobalInputTypeChanged=this.onSubgraphTypeChangeGlobalInput.bind(this);this.subgraph.onGlobalOutputAdded=this.onSubgraphNewGlobalOutput.bind(this);
this.subgraph.onGlobalOutputRenamed=this.onSubgraphRenamedGlobalOutput.bind(this);this.subgraph.onGlobalOutputTypeChanged=this.onSubgraphTypeChangeGlobalOutput.bind(this);this.bgcolor="#663"}function h(){var a="input_"+(1E3*Math.random()).toFixed();this.addOutput(a,null);this.properties={name:a,type:null};var b=this;Object.defineProperty(this.properties,"name",{get:function(){return a},set:function(c){if(""!=c){var e=b.getOutputInfo(0);e.name!=c&&(e.name=c,b.graph&&b.graph.renameGlobalInput(a,c),
a=c)}},enumerable:!0});Object.defineProperty(this.properties,"type",{get:function(){return b.outputs[0].type},set:function(c){b.outputs[0].type=c;b.graph&&b.graph.changeGlobalInputType(a,b.outputs[0].type)},enumerable:!0})}function n(){var a="output_"+(1E3*Math.random()).toFixed();this.addInput(a,null);this._value=null;this.properties={name:a,type:null};var b=this;Object.defineProperty(this.properties,"name",{get:function(){return a},set:function(c){if(""!=c){var e=b.getInputInfo(0);e.name!=c&&(e.name=
@@ -167,39 +167,38 @@ b)};e.prototype.onSubgraphRenamedGlobalOutput=function(a,b){var c=this.findOutpu
this.subgraph.setGlobalInputData(b.name,c)}this.subgraph.runStep();if(this.outputs)for(a=0;a<this.outputs.length;a++)c=this.subgraph.getGlobalOutputData(this.outputs[a].name),this.setOutputData(a,c)};e.prototype.configure=function(a){LGraphNode.prototype.configure.call(this,a)};e.prototype.serialize=function(){var a=LGraphNode.prototype.serialize.call(this);a.subgraph=this.subgraph.serialize();return a};e.prototype.clone=function(){var a=c.createNode(this.type),b=this.serialize();delete b.id;delete b.inputs;
delete b.outputs;a.configure(b);return a};c.registerNodeType("graph/subgraph",e);h.title="Input";h.desc="Input of the graph";h.prototype.onAdded=function(){this.graph.addGlobalInput(this.properties.name,this.properties.type)};h.prototype.onExecute=function(){var a=this.graph.global_inputs[this.properties.name];a&&this.setOutputData(0,a.value)};c.registerNodeType("graph/input",h);n.title="Output";n.desc="Output of the graph";n.prototype.onAdded=function(){this.graph.addGlobalOutput(this.properties.name,
this.properties.type)};n.prototype.getValue=function(){return this._value};n.prototype.onExecute=function(){this._value=this.getInputData(0);this.graph.setGlobalOutputData(this.properties.name,this._value)};c.registerNodeType("graph/output",n);p.title="Const";p.desc="Constant value";p.prototype.setValue=function(a){"string"==typeof a&&(a=parseFloat(a));this.properties.value=a;this.setDirtyCanvas(!0)};p.prototype.onExecute=function(){this.setOutputData(0,parseFloat(this.properties.value))};p.prototype.onDrawBackground=
function(a){this.outputs[0].label=this.properties.value.toFixed(3)};p.prototype.onWidget=function(a,b){"value"==b.name&&this.setValue(b.value)};c.registerNodeType("basic/const",p);q.title="Watch";q.desc="Show value of input";q.prototype.onExecute=function(){this.properties.value=this.getInputData(0);this.setOutputData(0,this.properties.value)};q.prototype.onDrawBackground=function(a){this.inputs[0]&&null!=this.properties.value&&(this.properties.value.constructor===Number?this.inputs[0].label=this.properties.value.toFixed(3):
((a=this.properties.value)&&a.length&&(a=Array.prototype.slice.call(a).join(",")),this.inputs[0].label=a))};c.registerNodeType("basic/watch",q);r.title="Pass";r.desc="Allows to connect different types";r.prototype.onExecute=function(){this.setOutputData(0,this.getInputData(0))};c.registerNodeType("basic/pass",r);l.title="Console";l.desc="Show value inside the console";l.prototype.onAction=function(a,b){"log"==a?console.log(b):"warn"==a?console.warn(b):"error"==a&&console.error(b)};l.prototype.onExecute=
function(){var a=this.getInputData(1);null!==a&&(this.properties.msg=a);console.log(a)};l.prototype.onGetInputs=function(){return[["log",c.ACTION],["warn",c.ACTION],["error",c.ACTION]]};c.registerNodeType("basic/console",l);s.title="Script";s.desc="executes a code";s.widgets_info={onExecute:{type:"code"}};s.prototype.onPropertyChanged=function(a,b){if("onExecute"==a&&c.allow_scripts){this._func=null;try{this._func=new Function(b)}catch(d){console.error("Error parsing script"),console.error(d)}}};
s.prototype.onExecute=function(){if(this._func)try{this._func.call(this)}catch(a){console.error("Error in script"),console.error(a)}};c.registerNodeType("basic/script",s)})(this);
function(a){this.outputs[0].label=this.properties.value.toFixed(3)};p.prototype.onWidget=function(a,b){"value"==b.name&&this.setValue(b.value)};c.registerNodeType("basic/const",p);q.title="Watch";q.desc="Show value of input";q.prototype.onExecute=function(){this.properties.value=this.getInputData(0);this.setOutputData(0,this.properties.value)};q.prototype.onDrawBackground=function(a){this.inputs[0]&&null!=this.properties.value&&(this.inputs[0].label=this.properties.value.constructor===Number?this.properties.value.toFixed(3):
String(this.properties.value))};c.registerNodeType("basic/watch",q);r.title="Pass";r.desc="Allows to connect different types";r.prototype.onExecute=function(){this.setOutputData(0,this.getInputData(0))};c.registerNodeType("basic/pass",r);l.title="Console";l.desc="Show value inside the console";l.prototype.onAction=function(a,b){"log"==a?console.log(b):"warn"==a?console.warn(b):"error"==a&&console.error(b)};l.prototype.onExecute=function(){var a=this.getInputData(1);null!==a&&(this.properties.msg=
a);console.log(a)};l.prototype.onGetInputs=function(){return[["log",c.ACTION],["warn",c.ACTION],["error",c.ACTION]]};c.registerNodeType("basic/console",l);s.title="Script";s.desc="executes a code";s.widgets_info={onExecute:{type:"code"}};s.prototype.onPropertyChanged=function(a,b){if("onExecute"==a&&c.allow_scripts){this._func=null;try{this._func=new Function(b)}catch(d){console.error("Error parsing script"),console.error(d)}}};s.prototype.onExecute=function(){if(this._func)try{this._func.call(this)}catch(a){console.error("Error in script"),
console.error(a)}};c.registerNodeType("basic/script",s)})(this);
(function(u){function g(){this.size=[60,20];this.addInput("event",n.ACTION)}function e(){this.size=[60,20];this.addInput("event",n.ACTION);this.addOutput("event",n.EVENT);this.properties={equal_to:"",has_property:"",property_equal_to:""}}function h(){this.size=[60,20];this.addProperty("time",1E3);this.addInput("event",n.ACTION);this.addOutput("on_time",n.EVENT);this._pending=[]}var n=u.LiteGraph;g.title="Log Event";g.desc="Log event in console";g.prototype.onAction=function(e,h){console.log(e,h)};
n.registerNodeType("events/log",g);e.title="Filter Event";e.desc="Blocks events that do not match the filter";e.prototype.onAction=function(e,h){if(null!=h&&(!this.properties.equal_to||this.properties.equal_to==h)){if(this.properties.has_property){var g=h[this.properties.has_property];if(null==g||this.properties.property_equal_to&&this.properties.property_equal_to!=g)return}this.triggerSlot(0,h)}};n.registerNodeType("events/filter",e);h.title="Delay";h.desc="Delays one event";h.prototype.onAction=
function(e,h){this._pending.push([this.properties.time,h])};h.prototype.onExecute=function(){for(var e=1E3*this.graph.elapsed_time,h=0;h<this._pending.length;++h){var g=this._pending[h];g[0]-=e;0<g[0]||(this._pending.splice(h,1),--h,this.trigger(null,g[1]))}};h.prototype.onGetInputs=function(){return[["event",n.ACTION]]};n.registerNodeType("events/delay",h)})(this);
(function(u){function g(){this.addOutput("clicked",s.EVENT);this.addProperty("text","");this.addProperty("font","40px Arial");this.addProperty("message","");this.size=[64,84]}function e(){this.addInput("","boolean");this.addOutput("v","boolean");this.addOutput("e",s.EVENT);this.properties={font:"",value:!1};this.size=[124,64]}function h(){this.addOutput("","number");this.size=[74,54];this.properties={min:-1E3,max:1E3,value:1,step:1};this.old_y=-1;this._precision=this._remainder=0;this.mouse_captured=
!1}function n(){this.addOutput("","number");this.size=[64,84];this.properties={min:0,max:1,value:0.5,wcolor:"#7AF",size:50}}function p(){this.size=[160,26];this.addOutput("","number");this.properties={wcolor:"#7AF",min:0,max:1,value:0.5}}function q(){this.size=[160,26];this.addInput("","number");this.properties={min:0,max:1,value:0,wcolor:"#AAF"}}function r(){this.addInputs("",0);this.properties={value:"...",font:"Arial",fontsize:18,color:"#AAA",align:"left",glowSize:0,decimals:1}}function l(){this.size=
[200,100];this.properties={borderColor:"#ffffff",bgcolorTop:"#f0f0f0",bgcolorBottom:"#e0e0e0",shadowSize:2,borderRadius:3}}var s=u.LiteGraph;g.title="Button";g.desc="Triggers an event";g.prototype.onDrawForeground=function(c){!this.flags.collapsed&&(c.fillStyle="black",c.fillRect(1,1,this.size[0]-3,this.size[1]-3),c.fillStyle="#AAF",c.fillRect(0,0,this.size[0]-3,this.size[1]-3),c.fillStyle=this.clicked?"white":this.mouseOver?"#668":"#334",c.fillRect(1,1,this.size[0]-4,this.size[1]-4),this.properties.text||
0===this.properties.text)&&(c.textAlign="center",c.fillStyle=this.clicked?"black":"white",this.properties.font&&(c.font=this.properties.font),c.fillText(this.properties.text,0.5*this.size[0],0.85*this.size[1]),c.textAlign="left")};g.prototype.onMouseDown=function(c,a){if(1<a[0]&&1<a[1]&&a[0]<this.size[0]-2&&a[1]<this.size[1]-2)return this.clicked=!0,this.trigger("clicked",this.properties.message),!0};g.prototype.onMouseUp=function(c){this.clicked=!1};s.registerNodeType("widget/button",g);e.title=
"Toggle";e.desc="Toggles between true or false";e.prototype.onDrawForeground=function(c){if(!this.flags.collapsed){var a=0.5*this.size[1],b=0.8*this.size[1];c.fillStyle="#AAA";c.fillRect(10,b-a,a,a);c.fillStyle=this.properties.value?"#AEF":"#000";c.fillRect(10+0.25*a,b-a+0.25*a,0.5*a,0.5*a);c.textAlign="left";c.font=this.properties.font||(0.8*a).toFixed(0)+"px Arial";c.fillStyle="#AAA";c.fillText(this.title,a+20,0.85*b);c.textAlign="left"}};e.prototype.onExecute=function(){var c=this.getInputData(0);
null!=c&&(this.properties.value=c);this.setOutputData(0,this.properties.value)};e.prototype.onMouseDown=function(c,a){if(1<a[0]&&1<a[1]&&a[0]<this.size[0]-2&&a[1]<this.size[1]-2)return this.properties.value=!this.properties.value,this.trigger("clicked",this.properties.value),!0};s.registerNodeType("widget/toggle",e);h.title="Number";h.desc="Widget to select number value";h.pixels_threshold=10;h.markers_color="#666";h.prototype.onDrawForeground=function(c){var a=0.5*this.size[0],b=this.size[1];30<
b?(c.fillStyle=h.markers_color,c.beginPath(),c.moveTo(a,0.1*b),c.lineTo(a+0.1*b,0.2*b),c.lineTo(a+-0.1*b,0.2*b),c.fill(),c.beginPath(),c.moveTo(a,0.9*b),c.lineTo(a+0.1*b,0.8*b),c.lineTo(a+-0.1*b,0.8*b),c.fill(),c.font=(0.7*b).toFixed(1)+"px Arial"):c.font=(0.8*b).toFixed(1)+"px Arial";c.textAlign="center";c.font=(0.7*b).toFixed(1)+"px Arial";c.fillStyle="#EEE";c.fillText(this.properties.value.toFixed(this._precision),a,0.75*b)};h.prototype.onExecute=function(){this.setOutputData(0,this.properties.value)};
h.prototype.onPropertyChanged=function(c,a){var b=(this.properties.step+"").split(".");this._precision=1<b.length?b[1].length:0};h.prototype.onMouseDown=function(c,a){if(!(0>a[1]))return this.old_y=c.canvasY,this.captureInput(!0),this.mouse_captured=!0};h.prototype.onMouseMove=function(c){if(this.mouse_captured){var a=this.old_y-c.canvasY;c.shiftKey&&(a*=10);if(c.metaKey||c.altKey)a*=0.1;this.old_y=c.canvasY;c=this._remainder+a/h.pixels_threshold;this._remainder=c%1;c=Math.clamp(this.properties.value+
(c|0)*this.properties.step,this.properties.min,this.properties.max);this.properties.value=c;this.setDirtyCanvas(!0)}};h.prototype.onMouseUp=function(c,a){200>c.click_time&&(this.properties.value=Math.clamp(this.properties.value+(a[1]>0.5*this.size[1]?-1:1)*this.properties.step,this.properties.min,this.properties.max),this.setDirtyCanvas(!0));this.mouse_captured&&(this.mouse_captured=!1,this.captureInput(!1))};s.registerNodeType("widget/number",h);n.title="Knob";n.desc="Circular controller";n.widgets=
[{name:"increase",text:"+",type:"minibutton"},{name:"decrease",text:"-",type:"minibutton"}];n.prototype.onAdded=function(){this.value=(this.properties.value-this.properties.min)/(this.properties.max-this.properties.min);this.imgbg=this.loadImage("imgs/knob_bg.png");this.imgfg=this.loadImage("imgs/knob_fg.png")};n.prototype.onDrawImageKnob=function(c){if(this.imgfg&&this.imgfg.width){var a=0.5*this.imgbg.width,b=this.size[0]/this.imgfg.width;c.save();c.translate(0,20);c.scale(b,b);c.drawImage(this.imgbg,
0,0);c.translate(a,a);c.rotate(2*this.value*Math.PI*6/8+10*Math.PI/8);c.translate(-a,-a);c.drawImage(this.imgfg,0,0);c.restore();this.title&&(c.font="bold 16px Criticized,Tahoma",c.fillStyle="rgba(100,100,100,0.8)",c.textAlign="center",c.fillText(this.title.toUpperCase(),0.5*this.size[0],18),c.textAlign="left")}};n.prototype.onDrawVectorKnob=function(c){if(this.imgfg&&this.imgfg.width){c.lineWidth=1;c.strokeStyle=this.mouseOver?"#FFF":"#AAA";c.fillStyle="#000";c.beginPath();c.arc(0.5*this.size[0],
0.5*this.size[1]+10,0.5*this.properties.size,0,2*Math.PI,!0);c.stroke();0<this.value&&(c.strokeStyle=this.properties.wcolor,c.lineWidth=0.2*this.properties.size,c.beginPath(),c.arc(0.5*this.size[0],0.5*this.size[1]+10,0.35*this.properties.size,-0.5*Math.PI+2*Math.PI*this.value,-0.5*Math.PI,!0),c.stroke(),c.lineWidth=1);c.font=0.2*this.properties.size+"px Arial";c.fillStyle="#AAA";c.textAlign="center";var a=this.properties.value;"number"==typeof a&&(a=a.toFixed(2));c.fillText(a,0.5*this.size[0],0.65*
this.size[1]);c.textAlign="left"}};n.prototype.onDrawForeground=function(c){this.onDrawImageKnob(c)};n.prototype.onExecute=function(){this.setOutputData(0,this.properties.value);this.boxcolor=s.colorToString([this.value,this.value,this.value])};n.prototype.onMouseDown=function(c){if(this.imgfg&&this.imgfg.width){this.center=[0.5*this.size[0],0.5*this.size[1]+20];this.radius=0.5*this.size[0];if(20>c.canvasY-this.pos[1]||s.distance([c.canvasX,c.canvasY],[this.pos[0]+this.center[0],this.pos[1]+this.center[1]])>
this.radius)return!1;this.oldmouse=[c.canvasX-this.pos[0],c.canvasY-this.pos[1]];this.captureInput(!0);return!0}};n.prototype.onMouseMove=function(c){if(this.oldmouse){c=[c.canvasX-this.pos[0],c.canvasY-this.pos[1]];var a=this.value,a=a-0.01*(c[1]-this.oldmouse[1]);1<a?a=1:0>a&&(a=0);this.value=a;this.properties.value=this.properties.min+(this.properties.max-this.properties.min)*this.value;this.oldmouse=c;this.setDirtyCanvas(!0)}};n.prototype.onMouseUp=function(c){this.oldmouse&&(this.oldmouse=null,
this.captureInput(!1))};n.prototype.onMouseLeave=function(c){};n.prototype.onWidget=function(c,a){if("increase"==a.name)this.onPropertyChanged("size",this.properties.size+10);else if("decrease"==a.name)this.onPropertyChanged("size",this.properties.size-10)};n.prototype.onPropertyChanged=function(c,a){if("wcolor"==c)this.properties[c]=a;else if("size"==c)a=parseInt(a),this.properties[c]=a,this.size=[a+4,a+24],this.setDirtyCanvas(!0,!0);else if("min"==c||"max"==c||"value"==c)this.properties[c]=parseFloat(a);
else return!1;return!0};s.registerNodeType("widget/knob",n);p.title="H.Slider";p.desc="Linear slider controller";p.prototype.onAdded=function(){this.value=0.5;this.imgfg=this.loadImage("imgs/slider_fg.png")};p.prototype.onDrawVectorial=function(c){this.imgfg&&this.imgfg.width&&(c.lineWidth=1,c.strokeStyle=this.mouseOver?"#FFF":"#AAA",c.fillStyle="#000",c.beginPath(),c.rect(2,0,this.size[0]-4,20),c.stroke(),c.fillStyle=this.properties.wcolor,c.beginPath(),c.rect(2+(this.size[0]-4-20)*this.value,0,
20,20),c.fill())};p.prototype.onDrawImage=function(c){this.imgfg&&this.imgfg.width&&(c.lineWidth=1,c.fillStyle="#000",c.fillRect(2,9,this.size[0]-4,2),c.strokeStyle="#333",c.beginPath(),c.moveTo(2,9),c.lineTo(this.size[0]-4,9),c.stroke(),c.strokeStyle="#AAA",c.beginPath(),c.moveTo(2,11),c.lineTo(this.size[0]-4,11),c.stroke(),c.drawImage(this.imgfg,2+(this.size[0]-4)*this.value-0.5*this.imgfg.width,0.5*-this.imgfg.height+10))};p.prototype.onDrawForeground=function(c){this.onDrawImage(c)};p.prototype.onExecute=
function(){this.properties.value=this.properties.min+(this.properties.max-this.properties.min)*this.value;this.setOutputData(0,this.properties.value);this.boxcolor=s.colorToString([this.value,this.value,this.value])};p.prototype.onMouseDown=function(c){if(0>c.canvasY-this.pos[1])return!1;this.oldmouse=[c.canvasX-this.pos[0],c.canvasY-this.pos[1]];this.captureInput(!0);return!0};p.prototype.onMouseMove=function(c){if(this.oldmouse){c=[c.canvasX-this.pos[0],c.canvasY-this.pos[1]];var a=this.value,a=
a+(c[0]-this.oldmouse[0])/this.size[0];1<a?a=1:0>a&&(a=0);this.value=a;this.oldmouse=c;this.setDirtyCanvas(!0)}};p.prototype.onMouseUp=function(c){this.oldmouse=null;this.captureInput(!1)};p.prototype.onMouseLeave=function(c){};p.prototype.onPropertyChanged=function(c,a){if("wcolor"==c)this.properties[c]=a;else return!1;return!0};s.registerNodeType("widget/hslider",p);q.title="Progress";q.desc="Shows data in linear progress";q.prototype.onExecute=function(){var c=this.getInputData(0);void 0!=c&&(this.properties.value=
c)};q.prototype.onDrawForeground=function(c){c.lineWidth=1;c.fillStyle=this.properties.wcolor;var a=(this.properties.value-this.properties.min)/(this.properties.max-this.properties.min),a=Math.min(1,a),a=Math.max(0,a);c.fillRect(2,2,(this.size[0]-4)*a,this.size[1]-4)};s.registerNodeType("widget/progress",q);r.title="Text";r.desc="Shows the input value";r.widgets=[{name:"resize",text:"Resize box",type:"button"},{name:"led_text",text:"LED",type:"minibutton"},{name:"normal_text",text:"Normal",type:"minibutton"}];
r.prototype.onDrawForeground=function(c){c.fillStyle=this.properties.color;var a=this.properties.value;this.properties.glowSize?(c.shadowColor=this.properties.color,c.shadowOffsetX=0,c.shadowOffsetY=0,c.shadowBlur=this.properties.glowSize):c.shadowColor="transparent";var b=this.properties.fontsize;c.textAlign=this.properties.align;c.font=b.toString()+"px "+this.properties.font;this.str="number"==typeof a?a.toFixed(this.properties.decimals):a;if("string"==typeof this.str){var a=this.str.split("\\n"),
d;for(d in a)c.fillText(a[d],"left"==this.properties.align?15:this.size[0]-15,-0.15*b+b*(parseInt(d)+1))}c.shadowColor="transparent";this.last_ctx=c;c.textAlign="left"};r.prototype.onExecute=function(){var c=this.getInputData(0);null!=c&&(this.properties.value=c)};r.prototype.resize=function(){if(this.last_ctx){var c=this.str.split("\\n");this.last_ctx.font=this.properties.fontsize+"px "+this.properties.font;var a=0,b;for(b in c){var d=this.last_ctx.measureText(c[b]).width;a<d&&(a=d)}this.size[0]=
a+20;this.size[1]=4+c.length*this.properties.fontsize;this.setDirtyCanvas(!0)}};r.prototype.onWidget=function(c,a){"resize"==a.name?this.resize():"led_text"==a.name?(this.properties.font="Digital",this.properties.glowSize=4,this.setDirtyCanvas(!0)):"normal_text"==a.name&&(this.properties.font="Arial",this.setDirtyCanvas(!0))};r.prototype.onPropertyChanged=function(c,a){this.properties[c]=a;this.str="number"==typeof a?a.toFixed(3):a;return!0};s.registerNodeType("widget/text",r);l.title="Panel";l.desc=
"Non interactive panel";l.widgets=[{name:"update",text:"Update",type:"button"}];l.prototype.createGradient=function(c){""==this.properties.bgcolorTop||""==this.properties.bgcolorBottom?this.lineargradient=0:(this.lineargradient=c.createLinearGradient(0,0,0,this.size[1]),this.lineargradient.addColorStop(0,this.properties.bgcolorTop),this.lineargradient.addColorStop(1,this.properties.bgcolorBottom))};l.prototype.onDrawForeground=function(c){null==this.lineargradient&&this.createGradient(c);this.lineargradient&&
(c.lineWidth=1,c.strokeStyle=this.properties.borderColor,c.fillStyle=this.lineargradient,this.properties.shadowSize?(c.shadowColor="#000",c.shadowOffsetX=0,c.shadowOffsetY=0,c.shadowBlur=this.properties.shadowSize):c.shadowColor="transparent",c.roundRect(0,0,this.size[0]-1,this.size[1]-1,this.properties.shadowSize),c.fill(),c.shadowColor="transparent",c.stroke())};l.prototype.onWidget=function(c,a){"update"==a.name&&(this.lineargradient=null,this.setDirtyCanvas(!0))};s.registerNodeType("widget/panel",
l)})(this);
function(e,h){this._pending.push([this.properties.time,h])};h.prototype.onExecute=function(){var e=1E3*this.graph.elapsed_time;console.log(this._pending);for(var h=0;h<this._pending.length;++h){var g=this._pending[h];g[0]-=e;0<g[0]||(this._pending.splice(h,1),--h,this.trigger(null,g[1]))}};h.prototype.onGetInputs=function(){return[["event",n.ACTION]]};n.registerNodeType("events/delay",h)})(this);
(function(u){function g(){this.addOutput("clicked",s.EVENT);this.addProperty("text","");this.addProperty("font_size",40);this.addProperty("message","");this.size=[64,84]}function e(){this.addInput("","boolean");this.addOutput("v","boolean");this.addOutput("e",s.EVENT);this.properties={font:"",value:!1};this.size=[124,64]}function h(){this.addOutput("","number");this.size=[74,54];this.properties={min:-1E3,max:1E3,value:1,step:1};this.old_y=-1;this._precision=this._remainder=0;this.mouse_captured=!1}
function n(){this.addOutput("","number");this.size=[64,84];this.properties={min:0,max:1,value:0.5,wcolor:"#7AF",size:50}}function p(){this.size=[160,26];this.addOutput("","number");this.properties={wcolor:"#7AF",min:0,max:1,value:0.5}}function q(){this.size=[160,26];this.addInput("","number");this.properties={min:0,max:1,value:0,wcolor:"#AAF"}}function r(){this.addInputs("",0);this.properties={value:"...",font:"Arial",fontsize:18,color:"#AAA",align:"left",glowSize:0,decimals:1}}function l(){this.size=
[200,100];this.properties={borderColor:"#ffffff",bgcolorTop:"#f0f0f0",bgcolorBottom:"#e0e0e0",shadowSize:2,borderRadius:3}}var s=u.LiteGraph;g.title="Button";g.desc="Triggers an event";g.font="Arial";g.prototype.onDrawForeground=function(c){if(!this.flags.collapsed&&(c.fillStyle="black",c.fillRect(1,1,this.size[0]-3,this.size[1]-3),c.fillStyle="#AAF",c.fillRect(0,0,this.size[0]-3,this.size[1]-3),c.fillStyle=this.clicked?"white":this.mouseOver?"#668":"#334",c.fillRect(1,1,this.size[0]-4,this.size[1]-
4),this.properties.text||0===this.properties.text)){var a=this.properties.font_size||30;c.textAlign="center";c.fillStyle=this.clicked?"black":"white";c.font=a+"px "+g.font;c.fillText(this.properties.text,0.5*this.size[0],0.5*this.size[1]+0.3*a);c.textAlign="left"}};g.prototype.onMouseDown=function(c,a){if(1<a[0]&&1<a[1]&&a[0]<this.size[0]-2&&a[1]<this.size[1]-2)return this.clicked=!0,this.trigger("clicked",this.properties.message),!0};g.prototype.onMouseUp=function(c){this.clicked=!1};s.registerNodeType("widget/button",
g);e.title="Toggle";e.desc="Toggles between true or false";e.prototype.onDrawForeground=function(c){if(!this.flags.collapsed){var a=0.5*this.size[1],b=0.8*this.size[1];c.fillStyle="#AAA";c.fillRect(10,b-a,a,a);c.fillStyle=this.properties.value?"#AEF":"#000";c.fillRect(10+0.25*a,b-a+0.25*a,0.5*a,0.5*a);c.textAlign="left";c.font=this.properties.font||(0.8*a).toFixed(0)+"px Arial";c.fillStyle="#AAA";c.fillText(this.title,a+20,0.85*b);c.textAlign="left"}};e.prototype.onExecute=function(){var c=this.getInputData(0);
null!=c&&(this.properties.value=c);this.setOutputData(0,this.properties.value)};e.prototype.onMouseDown=function(c,a){if(1<a[0]&&1<a[1]&&a[0]<this.size[0]-2&&a[1]<this.size[1]-2)return this.properties.value=!this.properties.value,this.trigger("e",this.properties.value),!0};s.registerNodeType("widget/toggle",e);h.title="Number";h.desc="Widget to select number value";h.pixels_threshold=10;h.markers_color="#666";h.prototype.onDrawForeground=function(c){var a=0.5*this.size[0],b=this.size[1];30<b?(c.fillStyle=
h.markers_color,c.beginPath(),c.moveTo(a,0.1*b),c.lineTo(a+0.1*b,0.2*b),c.lineTo(a+-0.1*b,0.2*b),c.fill(),c.beginPath(),c.moveTo(a,0.9*b),c.lineTo(a+0.1*b,0.8*b),c.lineTo(a+-0.1*b,0.8*b),c.fill(),c.font=(0.7*b).toFixed(1)+"px Arial"):c.font=(0.8*b).toFixed(1)+"px Arial";c.textAlign="center";c.font=(0.7*b).toFixed(1)+"px Arial";c.fillStyle="#EEE";c.fillText(this.properties.value.toFixed(this._precision),a,0.75*b)};h.prototype.onExecute=function(){this.setOutputData(0,this.properties.value)};h.prototype.onPropertyChanged=
function(c,a){var b=(this.properties.step+"").split(".");this._precision=1<b.length?b[1].length:0};h.prototype.onMouseDown=function(c,a){if(!(0>a[1]))return this.old_y=c.canvasY,this.captureInput(!0),this.mouse_captured=!0};h.prototype.onMouseMove=function(c){if(this.mouse_captured){var a=this.old_y-c.canvasY;c.shiftKey&&(a*=10);if(c.metaKey||c.altKey)a*=0.1;this.old_y=c.canvasY;c=this._remainder+a/h.pixels_threshold;this._remainder=c%1;c=Math.clamp(this.properties.value+(c|0)*this.properties.step,
this.properties.min,this.properties.max);this.properties.value=c;this.setDirtyCanvas(!0)}};h.prototype.onMouseUp=function(c,a){200>c.click_time&&(this.properties.value=Math.clamp(this.properties.value+(a[1]>0.5*this.size[1]?-1:1)*this.properties.step,this.properties.min,this.properties.max),this.setDirtyCanvas(!0));this.mouse_captured&&(this.mouse_captured=!1,this.captureInput(!1))};s.registerNodeType("widget/number",h);n.title="Knob";n.desc="Circular controller";n.widgets=[{name:"increase",text:"+",
type:"minibutton"},{name:"decrease",text:"-",type:"minibutton"}];n.prototype.onAdded=function(){this.value=(this.properties.value-this.properties.min)/(this.properties.max-this.properties.min);this.imgbg=this.loadImage("imgs/knob_bg.png");this.imgfg=this.loadImage("imgs/knob_fg.png")};n.prototype.onDrawImageKnob=function(c){if(this.imgfg&&this.imgfg.width){var a=0.5*this.imgbg.width,b=this.size[0]/this.imgfg.width;c.save();c.translate(0,20);c.scale(b,b);c.drawImage(this.imgbg,0,0);c.translate(a,a);
c.rotate(2*this.value*Math.PI*6/8+10*Math.PI/8);c.translate(-a,-a);c.drawImage(this.imgfg,0,0);c.restore();this.title&&(c.font="bold 16px Criticized,Tahoma",c.fillStyle="rgba(100,100,100,0.8)",c.textAlign="center",c.fillText(this.title.toUpperCase(),0.5*this.size[0],18),c.textAlign="left")}};n.prototype.onDrawVectorKnob=function(c){if(this.imgfg&&this.imgfg.width){c.lineWidth=1;c.strokeStyle=this.mouseOver?"#FFF":"#AAA";c.fillStyle="#000";c.beginPath();c.arc(0.5*this.size[0],0.5*this.size[1]+10,0.5*
this.properties.size,0,2*Math.PI,!0);c.stroke();0<this.value&&(c.strokeStyle=this.properties.wcolor,c.lineWidth=0.2*this.properties.size,c.beginPath(),c.arc(0.5*this.size[0],0.5*this.size[1]+10,0.35*this.properties.size,-0.5*Math.PI+2*Math.PI*this.value,-0.5*Math.PI,!0),c.stroke(),c.lineWidth=1);c.font=0.2*this.properties.size+"px Arial";c.fillStyle="#AAA";c.textAlign="center";var a=this.properties.value;"number"==typeof a&&(a=a.toFixed(2));c.fillText(a,0.5*this.size[0],0.65*this.size[1]);c.textAlign=
"left"}};n.prototype.onDrawForeground=function(c){this.onDrawImageKnob(c)};n.prototype.onExecute=function(){this.setOutputData(0,this.properties.value);this.boxcolor=s.colorToString([this.value,this.value,this.value])};n.prototype.onMouseDown=function(c){if(this.imgfg&&this.imgfg.width){this.center=[0.5*this.size[0],0.5*this.size[1]+20];this.radius=0.5*this.size[0];if(20>c.canvasY-this.pos[1]||s.distance([c.canvasX,c.canvasY],[this.pos[0]+this.center[0],this.pos[1]+this.center[1]])>this.radius)return!1;
this.oldmouse=[c.canvasX-this.pos[0],c.canvasY-this.pos[1]];this.captureInput(!0);return!0}};n.prototype.onMouseMove=function(c){if(this.oldmouse){c=[c.canvasX-this.pos[0],c.canvasY-this.pos[1]];var a=this.value,a=a-0.01*(c[1]-this.oldmouse[1]);1<a?a=1:0>a&&(a=0);this.value=a;this.properties.value=this.properties.min+(this.properties.max-this.properties.min)*this.value;this.oldmouse=c;this.setDirtyCanvas(!0)}};n.prototype.onMouseUp=function(c){this.oldmouse&&(this.oldmouse=null,this.captureInput(!1))};
n.prototype.onMouseLeave=function(c){};n.prototype.onWidget=function(c,a){if("increase"==a.name)this.onPropertyChanged("size",this.properties.size+10);else if("decrease"==a.name)this.onPropertyChanged("size",this.properties.size-10)};n.prototype.onPropertyChanged=function(c,a){if("wcolor"==c)this.properties[c]=a;else if("size"==c)a=parseInt(a),this.properties[c]=a,this.size=[a+4,a+24],this.setDirtyCanvas(!0,!0);else if("min"==c||"max"==c||"value"==c)this.properties[c]=parseFloat(a);else return!1;
return!0};s.registerNodeType("widget/knob",n);p.title="H.Slider";p.desc="Linear slider controller";p.prototype.onAdded=function(){this.value=0.5;this.imgfg=this.loadImage("imgs/slider_fg.png")};p.prototype.onDrawVectorial=function(c){this.imgfg&&this.imgfg.width&&(c.lineWidth=1,c.strokeStyle=this.mouseOver?"#FFF":"#AAA",c.fillStyle="#000",c.beginPath(),c.rect(2,0,this.size[0]-4,20),c.stroke(),c.fillStyle=this.properties.wcolor,c.beginPath(),c.rect(2+(this.size[0]-4-20)*this.value,0,20,20),c.fill())};
p.prototype.onDrawImage=function(c){this.imgfg&&this.imgfg.width&&(c.lineWidth=1,c.fillStyle="#000",c.fillRect(2,9,this.size[0]-4,2),c.strokeStyle="#333",c.beginPath(),c.moveTo(2,9),c.lineTo(this.size[0]-4,9),c.stroke(),c.strokeStyle="#AAA",c.beginPath(),c.moveTo(2,11),c.lineTo(this.size[0]-4,11),c.stroke(),c.drawImage(this.imgfg,2+(this.size[0]-4)*this.value-0.5*this.imgfg.width,0.5*-this.imgfg.height+10))};p.prototype.onDrawForeground=function(c){this.onDrawImage(c)};p.prototype.onExecute=function(){this.properties.value=
this.properties.min+(this.properties.max-this.properties.min)*this.value;this.setOutputData(0,this.properties.value);this.boxcolor=s.colorToString([this.value,this.value,this.value])};p.prototype.onMouseDown=function(c){if(0>c.canvasY-this.pos[1])return!1;this.oldmouse=[c.canvasX-this.pos[0],c.canvasY-this.pos[1]];this.captureInput(!0);return!0};p.prototype.onMouseMove=function(c){if(this.oldmouse){c=[c.canvasX-this.pos[0],c.canvasY-this.pos[1]];var a=this.value,a=a+(c[0]-this.oldmouse[0])/this.size[0];
1<a?a=1:0>a&&(a=0);this.value=a;this.oldmouse=c;this.setDirtyCanvas(!0)}};p.prototype.onMouseUp=function(c){this.oldmouse=null;this.captureInput(!1)};p.prototype.onMouseLeave=function(c){};p.prototype.onPropertyChanged=function(c,a){if("wcolor"==c)this.properties[c]=a;else return!1;return!0};s.registerNodeType("widget/hslider",p);q.title="Progress";q.desc="Shows data in linear progress";q.prototype.onExecute=function(){var c=this.getInputData(0);void 0!=c&&(this.properties.value=c)};q.prototype.onDrawForeground=
function(c){c.lineWidth=1;c.fillStyle=this.properties.wcolor;var a=(this.properties.value-this.properties.min)/(this.properties.max-this.properties.min),a=Math.min(1,a),a=Math.max(0,a);c.fillRect(2,2,(this.size[0]-4)*a,this.size[1]-4)};s.registerNodeType("widget/progress",q);r.title="Text";r.desc="Shows the input value";r.widgets=[{name:"resize",text:"Resize box",type:"button"},{name:"led_text",text:"LED",type:"minibutton"},{name:"normal_text",text:"Normal",type:"minibutton"}];r.prototype.onDrawForeground=
function(c){c.fillStyle=this.properties.color;var a=this.properties.value;this.properties.glowSize?(c.shadowColor=this.properties.color,c.shadowOffsetX=0,c.shadowOffsetY=0,c.shadowBlur=this.properties.glowSize):c.shadowColor="transparent";var b=this.properties.fontsize;c.textAlign=this.properties.align;c.font=b.toString()+"px "+this.properties.font;this.str="number"==typeof a?a.toFixed(this.properties.decimals):a;if("string"==typeof this.str){var a=this.str.split("\\n"),d;for(d in a)c.fillText(a[d],
"left"==this.properties.align?15:this.size[0]-15,-0.15*b+b*(parseInt(d)+1))}c.shadowColor="transparent";this.last_ctx=c;c.textAlign="left"};r.prototype.onExecute=function(){var c=this.getInputData(0);null!=c&&(this.properties.value=c)};r.prototype.resize=function(){if(this.last_ctx){var c=this.str.split("\\n");this.last_ctx.font=this.properties.fontsize+"px "+this.properties.font;var a=0,b;for(b in c){var d=this.last_ctx.measureText(c[b]).width;a<d&&(a=d)}this.size[0]=a+20;this.size[1]=4+c.length*
this.properties.fontsize;this.setDirtyCanvas(!0)}};r.prototype.onWidget=function(c,a){"resize"==a.name?this.resize():"led_text"==a.name?(this.properties.font="Digital",this.properties.glowSize=4,this.setDirtyCanvas(!0)):"normal_text"==a.name&&(this.properties.font="Arial",this.setDirtyCanvas(!0))};r.prototype.onPropertyChanged=function(c,a){this.properties[c]=a;this.str="number"==typeof a?a.toFixed(3):a;return!0};s.registerNodeType("widget/text",r);l.title="Panel";l.desc="Non interactive panel";l.widgets=
[{name:"update",text:"Update",type:"button"}];l.prototype.createGradient=function(c){""==this.properties.bgcolorTop||""==this.properties.bgcolorBottom?this.lineargradient=0:(this.lineargradient=c.createLinearGradient(0,0,0,this.size[1]),this.lineargradient.addColorStop(0,this.properties.bgcolorTop),this.lineargradient.addColorStop(1,this.properties.bgcolorBottom))};l.prototype.onDrawForeground=function(c){null==this.lineargradient&&this.createGradient(c);this.lineargradient&&(c.lineWidth=1,c.strokeStyle=
this.properties.borderColor,c.fillStyle=this.lineargradient,this.properties.shadowSize?(c.shadowColor="#000",c.shadowOffsetX=0,c.shadowOffsetY=0,c.shadowBlur=this.properties.shadowSize):c.shadowColor="transparent",c.roundRect(0,0,this.size[0]-1,this.size[1]-1,this.properties.shadowSize),c.fill(),c.shadowColor="transparent",c.stroke())};l.prototype.onWidget=function(c,a){"update"==a.name&&(this.lineargradient=null,this.setDirtyCanvas(!0))};s.registerNodeType("widget/panel",l)})(this);
(function(u){function g(){this.addOutput("left_x_axis","number");this.addOutput("left_y_axis","number");this.addOutput("button_pressed",e.EVENT);this.properties={gamepad_index:0,threshold:0.1};this._left_axis=new Float32Array(2);this._right_axis=new Float32Array(2);this._triggers=new Float32Array(2);this._previous_buttons=new Uint8Array(17);this._current_buttons=new Uint8Array(17)}var e=u.LiteGraph;g.title="Gamepad";g.desc="gets the input of the gamepad";g.zero=new Float32Array(2);g.buttons="a b x y lb rb lt rt back start ls rs home".split(" ");
g.prototype.onExecute=function(){var e=this.getGamepad(),n=this.properties.threshold||0;e&&(this._left_axis[0]=Math.abs(e.xbox.axes.lx)>n?e.xbox.axes.lx:0,this._left_axis[1]=Math.abs(e.xbox.axes.ly)>n?e.xbox.axes.ly:0,this._right_axis[0]=Math.abs(e.xbox.axes.rx)>n?e.xbox.axes.rx:0,this._right_axis[1]=Math.abs(e.xbox.axes.ry)>n?e.xbox.axes.ry:0,this._triggers[0]=Math.abs(e.xbox.axes.ltrigger)>n?e.xbox.axes.ltrigger:0,this._triggers[1]=Math.abs(e.xbox.axes.rtrigger)>n?e.xbox.axes.rtrigger:0);if(this.outputs)for(n=
0;n<this.outputs.length;n++){var p=this.outputs[n];if(p.links&&p.links.length){var q=null;if(e)switch(p.name){case "left_axis":q=this._left_axis;break;case "right_axis":q=this._right_axis;break;case "left_x_axis":q=this._left_axis[0];break;case "left_y_axis":q=this._left_axis[1];break;case "right_x_axis":q=this._right_axis[0];break;case "right_y_axis":q=this._right_axis[1];break;case "trigger_left":q=this._triggers[0];break;case "trigger_right":q=this._triggers[1];break;case "a_button":q=e.xbox.buttons.a?

View File

@@ -55,7 +55,7 @@ Editor.prototype.addLoadCounter = function()
var self = this;
setInterval(function() {
meter.querySelector(".cpuload .fgload").style.width = ((2*self.graph.elapsed_time) * 90) + "px";
meter.querySelector(".cpuload .fgload").style.width = ((2*self.graph.execution_time) * 90) + "px";
if(self.graph.status == LGraph.STATUS_RUNNING)
meter.querySelector(".gpuload .fgload").style.width = ((self.graphcanvas.render_time*10) * 90) + "px";
else

View File

@@ -437,6 +437,7 @@ LGraph.prototype.clear = function()
this.fixedtime = 0;
this.fixedtime_lapse = 0.01;
this.elapsed_time = 0.01;
this.last_update_time = 0;
this.starttime = 0;
this.catch_errors = true;
@@ -509,6 +510,7 @@ LGraph.prototype.start = function(interval)
//launch
this.starttime = LiteGraph.getTime();
this.last_update_time = this.starttime;
interval = interval || 1;
var that = this;
@@ -611,12 +613,15 @@ LGraph.prototype.runStep = function( num, do_not_catch_errors )
}
}
var elapsed = LiteGraph.getTime() - start;
var now = LiteGraph.getTime();
var elapsed = now - start;
if (elapsed == 0)
elapsed = 1;
this.elapsed_time = 0.001 * elapsed;
this.execution_time = 0.001 * elapsed;
this.globaltime += 0.001 * elapsed;
this.iteration += 1;
this.elapsed_time = (now - this.last_update_time) * 0.001;
this.last_update_time = now;
}
/**

View File

@@ -359,12 +359,7 @@ Watch.prototype.onDrawBackground = function(ctx)
if (this.properties["value"].constructor === Number )
this.inputs[0].label = this.properties["value"].toFixed(3);
else
{
var str = this.properties["value"];
if(str && str.length) //convert typed to array
str = Array.prototype.slice.call(str).join(",");
this.inputs[0].label = str;
}
this.inputs[0].label = String(this.properties.value);
}
}

View File

@@ -122,6 +122,7 @@ DelayEvent.prototype.onAction = function(action, param)
DelayEvent.prototype.onExecute = function()
{
var dt = this.graph.elapsed_time * 1000; //in ms
console.log(this._pending);
for(var i = 0; i < this._pending.length; ++i)
{

View File

@@ -8,7 +8,7 @@ var LiteGraph = global.LiteGraph;
{
this.addOutput( "clicked", LiteGraph.EVENT );
this.addProperty( "text","" );
this.addProperty( "font","40px Arial" );
this.addProperty( "font_size", 40 );
this.addProperty( "message", "" );
this.size = [64,84];
}
@@ -16,6 +16,7 @@ var LiteGraph = global.LiteGraph;
WidgetButton.title = "Button";
WidgetButton.desc = "Triggers an event";
WidgetButton.font = "Arial";
WidgetButton.prototype.onDrawForeground = function(ctx)
{
if(this.flags.collapsed)
@@ -32,11 +33,11 @@ var LiteGraph = global.LiteGraph;
if( this.properties.text || this.properties.text === 0 )
{
var font_size = this.properties.font_size || 30;
ctx.textAlign = "center";
ctx.fillStyle = this.clicked ? "black" : "white";
if( this.properties.font )
ctx.font = this.properties.font;
ctx.fillText(this.properties.text, this.size[0] * 0.5, this.size[1] * 0.85 );
ctx.font = font_size + "px " + WidgetButton.font;
ctx.fillText( this.properties.text, this.size[0] * 0.5, this.size[1] * 0.5 + font_size * 0.3 );
ctx.textAlign = "left";
}
}
@@ -107,7 +108,7 @@ var LiteGraph = global.LiteGraph;
if(local_pos[0] > 1 && local_pos[1] > 1 && local_pos[0] < (this.size[0] - 2) && local_pos[1] < (this.size[1] - 2) )
{
this.properties.value = !this.properties.value;
this.trigger( "clicked", this.properties.value );
this.trigger( "e", this.properties.value );
return true;
}
}