This commit is contained in:
tamat
2016-01-22 19:40:26 +01:00
parent 4d3e472a19
commit e960035dfe
4 changed files with 307 additions and 177 deletions

View File

@@ -33,8 +33,8 @@ var LiteGraph = {
debug: false,
throw_errors: true,
registered_node_types: {},
Nodes: {},
registered_node_types: {}, //nodetypes by string
Nodes: {}, //node types by classname
/**
* Register a node class so it can be listed when the user wants to create a new one
@@ -69,6 +69,19 @@ var LiteGraph = {
this.Nodes[ base_class.constructor.name ] = base_class;
},
/**
* Adds this method to all nodetypes, existing and to be created
* (You can add it to LGraphNode.prototype but then existing node types wont have it)
* @method addNodeMethod
* @param {Function} func
*/
addNodeMethod: function( name, func )
{
LGraphNode.prototype[name] = func;
for(var i in this.registered_node_types)
this.registered_node_types[i].prototype[name] = func;
},
/**
* Create a node of a given type with a name. The node is not attached to any graph yet.
* @method createNode
@@ -328,8 +341,12 @@ LGraph.prototype.attachCanvas = function(graphcanvas)
LGraph.prototype.detachCanvas = function(graphcanvas)
{
var pos = this.list_of_graphcanvas.indexOf(graphcanvas);
if(pos == -1) return;
if(!this.list_of_graphcanvas)
return;
var pos = this.list_of_graphcanvas.indexOf( graphcanvas );
if(pos == -1)
return;
graphcanvas.graph = null;
this.list_of_graphcanvas.splice(pos,1);
}
@@ -448,14 +465,14 @@ LGraph.prototype.computeExecutionOrder = function()
var remaining_links = {}; //to a
//search for the nodes without inputs (starting nodes)
for (var i in this._nodes)
for (var i = 0, l = this._nodes.length; i < l; ++i)
{
var n = this._nodes[i];
M[n.id] = n; //add to pending nodes
var num = 0; //num of input connections
if(n.inputs)
for(var j = 0, l = n.inputs.length; j < l; j++)
for(var j = 0, l2 = n.inputs.length; j < l2; j++)
if(n.inputs[j] && n.inputs[j].link != null)
num += 1;
@@ -568,17 +585,23 @@ LGraph.prototype.getElapsedTime = function()
LGraph.prototype.sendEventToAllNodes = function(eventname, params)
{
var M = this._nodes_in_order ? this._nodes_in_order : this._nodes;
for(var j in M)
if(M[j][eventname])
var nodes = this._nodes_in_order ? this._nodes_in_order : this._nodes;
if(!nodes)
return;
for( var j = 0, l = nodes.length; j < l; ++j )
{
var node = nodes[j];
if(node[eventname])
{
if(params === undefined)
M[j][eventname]();
node[eventname]();
else if(params && params.constructor === Array)
M[j][eventname].apply(M[j], params);
node[eventname].apply(M[j], params);
else
M[j][eventname](params);
node[eventname](params);
}
}
}
LGraph.prototype.sendActionToCanvas = function(action, params)
@@ -586,7 +609,7 @@ LGraph.prototype.sendActionToCanvas = function(action, params)
if(!this.list_of_graphcanvas)
return;
for(var i in this.list_of_graphcanvas)
for(var i = 0; i < this.list_of_graphcanvas.length; ++i)
{
var c = this.list_of_graphcanvas[i];
if( c[action] )
@@ -684,13 +707,16 @@ LGraph.prototype.remove = function(node)
node.graph = null;
//remove from canvas render
for(var i in this.list_of_graphcanvas)
if(this.list_of_graphcanvas)
{
var canvas = this.list_of_graphcanvas[i];
if(canvas.selected_nodes[node.id])
delete canvas.selected_nodes[node.id];
if(canvas.node_dragged == node)
canvas.node_dragged = null;
for(var i = 0; i < this.list_of_graphcanvas.length; ++i)
{
var canvas = this.list_of_graphcanvas[i];
if(canvas.selected_nodes[node.id])
delete canvas.selected_nodes[node.id];
if(canvas.node_dragged == node)
canvas.node_dragged = null;
}
}
//remove from containers
@@ -731,7 +757,7 @@ LGraph.prototype.getNodeById = function(id)
LGraph.prototype.findNodesByClass = function(classObject)
{
var r = [];
for(var i in this._nodes)
for(var i = 0, l = this._nodes.length; i < l; ++i)
if(this._nodes[i].constructor === classObject)
r.push(this._nodes[i]);
return r;
@@ -748,7 +774,7 @@ LGraph.prototype.findNodesByType = function(type)
{
var type = type.toLowerCase();
var r = [];
for(var i in this._nodes)
for(var i = 0, l = this._nodes.length; i < l; ++i)
if(this._nodes[i].type.toLowerCase() == type )
r.push(this._nodes[i]);
return r;
@@ -764,7 +790,7 @@ LGraph.prototype.findNodesByType = function(type)
LGraph.prototype.findNodesByTitle = function(title)
{
var result = [];
for (var i in this._nodes)
for(var i = 0, l = this._nodes.length; i < l; ++i)
if(this._nodes[i].title == title)
result.push(this._nodes[i]);
return result;
@@ -967,9 +993,9 @@ LGraph.prototype.removeGlobalOutput = function(name)
LGraph.prototype.setInputData = function(name,value)
{
var m = this.findNodesByName(name);
for(var i in m)
m[i].setValue(value);
var nodes = this.findNodesByName( name );
for(var i = 0, l = nodes.length; i < l; ++i)
nodes[i].setValue(value);
}
/**
@@ -991,22 +1017,25 @@ LGraph.prototype.getOutputData = function(name)
LGraph.prototype.triggerInput = function(name,value)
{
var m = this.findNodesByName(name);
for(var i in m)
m[i].onTrigger(value);
var nodes = this.findNodesByName(name);
for(var i = 0; i < nodes.length; ++i)
nodes[i].onTrigger(value);
}
LGraph.prototype.setCallback = function(name,func)
{
var m = this.findNodesByName(name);
for(var i in m)
m[i].setTrigger(func);
var nodes = this.findNodesByName(name);
for(var i = 0; i < nodes.length; ++i)
nodes[i].setTrigger(func);
}
LGraph.prototype.onConnectionChange = function()
LGraph.prototype.connectionChange = function( node )
{
this.updateExecutionOrder();
if( this.onConnectionChange )
this.onConnectionChange( node );
this.sendActionToCanvas("onConnectionChange");
}
/**
@@ -1016,10 +1045,14 @@ LGraph.prototype.onConnectionChange = function()
LGraph.prototype.isLive = function()
{
for(var i in this.list_of_graphcanvas)
if(!this.list_of_graphcanvas)
return false;
for(var i = 0; i < this.list_of_graphcanvas.length; ++i)
{
var c = this.list_of_graphcanvas[i];
if(c.live_mode) return true;
if(c.live_mode)
return true;
}
return false;
}
@@ -1050,11 +1083,11 @@ LGraph.prototype.setDirtyCanvas = function(fg,bg)
LGraph.prototype.serialize = function()
{
var nodes_info = [];
for (var i in this._nodes)
for(var i = 0, l = this._nodes.length; i < l; ++i)
nodes_info.push( this._nodes[i].serialize() );
//remove data from links, we dont want to store it
for (var i in this.links)
for(var i in this.links) //links is an OBJECT
this.links[i].data = null;
@@ -1095,7 +1128,7 @@ LGraph.prototype.configure = function(data, keep_old)
//create nodes
this._nodes = [];
for (var i in nodes)
for(var i = 0, l = nodes.length; i < l; ++i)
{
var n_info = nodes[i]; //stored info
var node = LiteGraph.createNode( n_info.type, n_info.title );
@@ -1504,7 +1537,7 @@ LGraphNode.prototype.addOutput = function(name,type,extra_info)
*/
LGraphNode.prototype.addOutputs = function(array)
{
for(var i in array)
for(var i = 0; i < array.length; ++i)
{
var info = array[i];
var o = {name:info[0],type:info[1],link:null};
@@ -1566,7 +1599,7 @@ LGraphNode.prototype.addInput = function(name,type,extra_info)
*/
LGraphNode.prototype.addInputs = function(array)
{
for(var i in array)
for(var i = 0; i < array.length; ++i)
{
var info = array[i];
var o = {name:info[0], type:info[1], link:null};
@@ -1818,8 +1851,9 @@ LGraphNode.prototype.connect = function(slot, node, target_slot)
if(target_slot != -1 && node.inputs[target_slot].link != null)
node.disconnectInput(target_slot);
//why here??
this.setDirtyCanvas(false,true);
this.graph.onConnectionChange();
this.graph.connectionChange( this );
//special case: -1 means node-connection, used for triggers
var output = this.outputs[slot];
@@ -1850,6 +1884,10 @@ LGraphNode.prototype.connect = function(slot, node, target_slot)
node.inputs[target_slot].link = link.id;
}
this.setDirtyCanvas(false,true);
this.graph.connectionChange( this );
return true;
}
@@ -1923,7 +1961,7 @@ LGraphNode.prototype.disconnectOutput = function(slot, target_node)
}
this.setDirtyCanvas(false,true);
this.graph.onConnectionChange();
this.graph.connectionChange( this );
return true;
}
@@ -1985,7 +2023,7 @@ LGraphNode.prototype.disconnectInput = function(slot)
}
this.setDirtyCanvas(false,true);
this.graph.onConnectionChange();
this.graph.connectionChange( this );
return true;
}
@@ -2109,7 +2147,7 @@ LGraphNode.prototype.captureInput = function(v)
var list = this.graph.list_of_graphcanvas;
for(var i in list)
for(var i = 0; i < list.length; ++i)
{
var c = list[i];
//releasing somebody elses capture?!
@@ -2161,14 +2199,18 @@ LGraphNode.prototype.localToScreen = function(x,y, graphcanvas)
/**
* The Global Scope. It contains all the registered node classes.
* Valid callbacks are: onNodeSelected, onNodeDeselected, onShowNodePanel, onNodeDblClicked
*
* @class LGraphCanvas
* @constructor
* @param {HTMLCanvas} canvas the canvas where you want to render (it accepts a selector in string format or the canvas itself)
* @param {LGraph} graph [optional]
* @param {Object} options [optional] { skip_rendering, autoresize }
*/
function LGraphCanvas( canvas, graph, skip_render )
function LGraphCanvas( canvas, graph, options )
{
options = options || {};
//if(graph === undefined)
// throw ("No graph assigned");
@@ -2185,8 +2227,10 @@ function LGraphCanvas( canvas, graph, skip_render )
this.setCanvas( canvas );
this.clear();
if(!skip_render)
if(!options.skip_render)
this.startRendering();
this.autoresize = options.autoresize;
}
LGraphCanvas.link_type_colors = {'number':"#AAC",'node':"#DCA"};
@@ -2791,12 +2835,20 @@ LGraphCanvas.prototype.processMouseDown = function(e)
if(!ref_window.document.activeElement || (ref_window.document.activeElement.nodeName.toLowerCase() != "input" && ref_window.document.activeElement.nodeName.toLowerCase() != "textarea"))
e.preventDefault();
e.stopPropagation();
if(this.onMouseDown)
this.onMouseDown(e);
return false;
}
LGraphCanvas.prototype.processMouseMove = function(e)
{
if(!this.graph) return;
if(this.autoresize)
this.resize();
if(!this.graph)
return;
this.adjustMouseEvent(e);
var mouse = [e.localX, e.localY];
@@ -2820,7 +2872,7 @@ LGraphCanvas.prototype.processMouseMove = function(e)
var n = this.graph.getNodeOnPos(e.canvasX, e.canvasY, this.visible_nodes);
//remove mouseover flag
for(var i in this.graph._nodes)
for(var i = 0, l = this.graph._nodes.length; i < l; ++i)
{
if(this.graph._nodes[i].mouseOver && n != this.graph._nodes[i])
{
@@ -3259,7 +3311,7 @@ LGraphCanvas.prototype.selectNode = function(node)
LGraphCanvas.prototype.selectAllNodes = function()
{
for(var i in this.graph._nodes)
for(var i = 0; i < this.graph._nodes.length; ++i)
{
var n = this.graph._nodes[i];
if(!n.selected && n.onSelected)
@@ -3381,7 +3433,7 @@ LGraphCanvas.prototype.sendToBack = function(n)
LGraphCanvas.prototype.computeVisibleNodes = function()
{
var visible_nodes = [];
for (var i in this.graph._nodes)
for(var i = 0, l = this.graph._nodes.length; i < l; ++i)
{
var n = this.graph._nodes[i];
@@ -3478,7 +3530,7 @@ LGraphCanvas.prototype.drawFrontCanvas = function()
var visible_nodes = this.computeVisibleNodes();
this.visible_nodes = visible_nodes;
for (var i in visible_nodes)
for (var i = 0; i < visible_nodes.length; ++i)
{
var node = visible_nodes[i];
@@ -3564,6 +3616,13 @@ LGraphCanvas.prototype.renderInfo = function( ctx, x, y )
LGraphCanvas.prototype.drawBackCanvas = function()
{
var canvas = this.bgcanvas;
if(canvas.width != this.canvas.width ||
canvas.height != this.canvas.height)
{
canvas.width = this.canvas.width;
canvas.height = this.canvas.height;
}
if(!this.bgctx)
this.bgctx = this.bgcanvas.getContext("2d");
var ctx = this.bgctx;
@@ -4028,12 +4087,12 @@ LGraphCanvas.prototype.drawConnections = function(ctx)
ctx.strokeStyle = "#AAA";
ctx.globalAlpha = this.editor_alpha;
//for every node
for (var n in this.graph._nodes)
for (var n = 0, l = this.graph._nodes.length; n < l; ++n)
{
var node = this.graph._nodes[n];
//for every input (we render just inputs because it is easier as every slot can only have one input)
if(node.inputs && node.inputs.length)
for(var i in node.inputs)
for(var i = 0; i < node.inputs.length; ++i)
{
var input = node.inputs[i];
if(!input || input.link == null)
@@ -7768,13 +7827,13 @@ if(typeof(LiteGraph) != "undefined")
function LGraphTexture()
{
this.addOutput("Texture","Texture");
this.properties = {name:""};
this.properties = { name:"", filter: true };
this.size = [LGraphTexture.image_preview_size, LGraphTexture.image_preview_size];
}
LGraphTexture.title = "Texture";
LGraphTexture.desc = "Texture";
LGraphTexture.widgets_info = {"name": { widget:"texture"} };
LGraphTexture.widgets_info = {"name": { widget:"texture"}, "filter": { widget:"checkbox"} };
//REPLACE THIS TO INTEGRATE WITH YOUR FRAMEWORK
LGraphTexture.loadTextureCallback = null; //function in charge of loading textures when not present in the container
@@ -7928,6 +7987,12 @@ if(typeof(LiteGraph) != "undefined")
return;
this._last_tex = tex;
if(this.properties.filter === false)
tex.setParameter( gl.TEXTURE_MAG_FILTER, gl.NEAREST );
else
tex.setParameter( gl.TEXTURE_MAG_FILTER, gl.LINEAR );
this.setOutputData(0, tex);
for(var i = 1; i < this.outputs.length; i++)

138
build/litegraph.min.js vendored
View File

@@ -1,32 +1,32 @@
var LiteGraph={NODE_TITLE_HEIGHT:16,NODE_SLOT_HEIGHT:15,NODE_WIDTH:140,NODE_MIN_WIDTH:50,NODE_COLLAPSED_RADIUS:10,NODE_COLLAPSED_WIDTH:80,CANVAS_GRID_SIZE:10,NODE_TITLE_COLOR:"#222",NODE_DEFAULT_COLOR:"#999",NODE_DEFAULT_BGCOLOR:"#444",NODE_DEFAULT_BOXCOLOR:"#AEF",NODE_DEFAULT_SHAPE:"box",MAX_NUMBER_OF_NODES:1E3,DEFAULT_POSITION:[100,100],node_images_path:"",proxy:null,debug:!1,throw_errors:!0,registered_node_types:{},Nodes:{},registerNodeType:function(a,b){if(!b.prototype)throw"Cannot register a simple object, it must be a class with a prototype";
b.type=a;LiteGraph.debug&&console.log("Node registered: "+a);a.split("/");var c=a.lastIndexOf("/");b.category=a.substr(0,c);if(b.prototype)for(var d in LGraphNode.prototype)b.prototype[d]||(b.prototype[d]=LGraphNode.prototype[d]);this.registered_node_types[a]=b;b.constructor.name&&(this.Nodes[b.constructor.name]=b)},createNode:function(a,b,c){var d=this.registered_node_types[a];if(!d)return LiteGraph.debug&&console.log('GraphNode type "'+a+'" not registered.'),null;b=b||d.title||a;d=new d(name);d.type=
a;d.title||(d.title=b);d.properties||(d.properties={});d.flags||(d.flags={});d.size||(d.size=d.computeSize());d.pos||(d.pos=LiteGraph.DEFAULT_POSITION.concat());if(c)for(var e in c)d[e]=c[e];return d},getNodeType:function(a){return this.registered_node_types[a]},getNodeTypesInCategory:function(a){var b=[],c;for(c in this.registered_node_types)""==a?null==this.registered_node_types[c].category&&b.push(this.registered_node_types[c]):this.registered_node_types[c].category==a&&b.push(this.registered_node_types[c]);
return b},getNodeTypesCategories:function(){var a={"":1},b;for(b in this.registered_node_types)this.registered_node_types[b].category&&!this.registered_node_types[b].skip_list&&(a[this.registered_node_types[b].category]=1);var c=[];for(b in a)c.push(b);return c},reloadNodes:function(a){var b=document.getElementsByTagName("script"),c=[],d;for(d in b)c.push(b[d]);b=document.getElementsByTagName("head")[0];a=document.location.href+a;for(d in c){var e=c[d].src;if(e&&e.substr(0,a.length)==a)try{LiteGraph.debug&&
console.log("Reloading: "+e);var f=document.createElement("script");f.type="text/javascript";f.src=e;b.appendChild(f);b.removeChild(c[d])}catch(g){if(LiteGraph.throw_errors)throw g;LiteGraph.debug&&console.log("Error while reloading "+e)}}LiteGraph.debug&&console.log("Nodes reloaded")},cloneObject:function(a,b){if(null==a)return null;var c=JSON.parse(JSON.stringify(a));if(!b)return c;for(var d in c)b[d]=c[d];return b}};
LiteGraph.getTime="undefined"!=typeof performance?function(){return performance.now()}:function(){return Date.now()};function LGraph(){LiteGraph.debug&&console.log("Graph created");this.list_of_graphcanvas=null;this.clear()}LGraph.supported_types=["number","string","boolean"];LGraph.prototype.getSupportedTypes=function(){return this.supported_types||LGraph.supported_types};LGraph.STATUS_STOPPED=1;LGraph.STATUS_RUNNING=2;
b.type=a;LiteGraph.debug&&console.log("Node registered: "+a);a.split("/");var c=a.lastIndexOf("/");b.category=a.substr(0,c);if(b.prototype)for(var d in LGraphNode.prototype)b.prototype[d]||(b.prototype[d]=LGraphNode.prototype[d]);this.registered_node_types[a]=b;b.constructor.name&&(this.Nodes[b.constructor.name]=b)},addNodeMethod:function(a,b){LGraphNode.prototype[a]=b;for(var c in this.registered_node_types)this.registered_node_types[c].prototype[a]=b},createNode:function(a,b,c){var d=this.registered_node_types[a];
if(!d)return LiteGraph.debug&&console.log('GraphNode type "'+a+'" not registered.'),null;b=b||d.title||a;d=new d(name);d.type=a;d.title||(d.title=b);d.properties||(d.properties={});d.flags||(d.flags={});d.size||(d.size=d.computeSize());d.pos||(d.pos=LiteGraph.DEFAULT_POSITION.concat());if(c)for(var e in c)d[e]=c[e];return d},getNodeType:function(a){return this.registered_node_types[a]},getNodeTypesInCategory:function(a){var b=[],c;for(c in this.registered_node_types)""==a?null==this.registered_node_types[c].category&&
b.push(this.registered_node_types[c]):this.registered_node_types[c].category==a&&b.push(this.registered_node_types[c]);return b},getNodeTypesCategories:function(){var a={"":1},b;for(b in this.registered_node_types)this.registered_node_types[b].category&&!this.registered_node_types[b].skip_list&&(a[this.registered_node_types[b].category]=1);var c=[];for(b in a)c.push(b);return c},reloadNodes:function(a){var b=document.getElementsByTagName("script"),c=[],d;for(d in b)c.push(b[d]);b=document.getElementsByTagName("head")[0];
a=document.location.href+a;for(d in c){var e=c[d].src;if(e&&e.substr(0,a.length)==a)try{LiteGraph.debug&&console.log("Reloading: "+e);var f=document.createElement("script");f.type="text/javascript";f.src=e;b.appendChild(f);b.removeChild(c[d])}catch(g){if(LiteGraph.throw_errors)throw g;LiteGraph.debug&&console.log("Error while reloading "+e)}}LiteGraph.debug&&console.log("Nodes reloaded")},cloneObject:function(a,b){if(null==a)return null;var c=JSON.parse(JSON.stringify(a));if(!b)return c;for(var d in c)b[d]=
c[d];return b}};LiteGraph.getTime="undefined"!=typeof performance?function(){return performance.now()}:function(){return Date.now()};function LGraph(){LiteGraph.debug&&console.log("Graph created");this.list_of_graphcanvas=null;this.clear()}LGraph.supported_types=["number","string","boolean"];LGraph.prototype.getSupportedTypes=function(){return this.supported_types||LGraph.supported_types};LGraph.STATUS_STOPPED=1;LGraph.STATUS_RUNNING=2;
LGraph.prototype.clear=function(){this.stop();this.status=LGraph.STATUS_STOPPED;this.last_node_id=0;this._nodes=[];this._nodes_by_id={};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.global_inputs={};this.global_outputs={};this.debug=!0;this.change();this.sendActionToCanvas("clear")};
LGraph.prototype.attachCanvas=function(a){if(a.constructor!=LGraphCanvas)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)};LGraph.prototype.detachCanvas=function(a){var b=this.list_of_graphcanvas.indexOf(a);-1!=b&&(a.graph=null,this.list_of_graphcanvas.splice(b,1))};
LGraph.prototype.attachCanvas=function(a){if(a.constructor!=LGraphCanvas)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)};LGraph.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))}};
LGraph.prototype.start=function(a){if(this.status!=LGraph.STATUS_RUNNING){this.status=LGraph.STATUS_RUNNING;if(this.onPlayEvent)this.onPlayEvent();this.sendEventToAllNodes("onStart");this.starttime=LiteGraph.getTime();var b=this;this.execution_timer_id=setInterval(function(){b.runStep(1)},a||1)}};
LGraph.prototype.stop=function(){if(this.status!=LGraph.STATUS_STOPPED){this.status=LGraph.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")}};
LGraph.prototype.runStep=function(a){a=a||1;var b=LiteGraph.getTime();this.globaltime=0.001*(b-this.starttime);try{for(var c=0;c<a;c++)if(this.sendEventToAllNodes("onExecute"),this.fixedtime+=this.fixedtime_lapse,this.onExecuteStep)this.onExecuteStep();if(this.onAfterExecute)this.onAfterExecute();this.errors_in_execution=!1}catch(d){this.errors_in_execution=!0;if(LiteGraph.throw_errors)throw d;LiteGraph.debug&&console.log("Error during execution: "+d);this.stop()}a=LiteGraph.getTime()-b;0==a&&(a=
1);this.elapsed_time=0.001*a;this.globaltime+=0.001*a;this.iteration+=1};LGraph.prototype.updateExecutionOrder=function(){this._nodes_in_order=this.computeExecutionOrder()};
LGraph.prototype.computeExecutionOrder=function(){var a=[],b=[],c={},d={},e={},f;for(f in this._nodes){var g=this._nodes[f];c[g.id]=g;var h=0;if(g.inputs)for(var k=0,l=g.inputs.length;k<l;k++)g.inputs[k]&&null!=g.inputs[k].link&&(h+=1);0==h?b.push(g):e[g.id]=h}for(;0!=b.length;)if(g=b.shift(),a.push(g),delete c[g.id],g.outputs)for(f=0;f<g.outputs.length;f++)if(h=g.outputs[f],null!=h&&null!=h.links&&0!=h.links.length)for(k=0;k<h.links.length;k++)if((l=this.links[h.links[k]])&&!d[l.id]){var p=this.getNodeById(l.target_id);
null==p?d[l.id]=!0:(d[l.id]=!0,e[p.id]-=1,0==e[p.id]&&b.push(p))}for(f in c)a.push(c[f]);a.length!=this._nodes.length&&LiteGraph.debug&&console.log("something went wrong, nodes missing");for(f in a)a[f].order=f;return a};LGraph.prototype.getTime=function(){return this.globaltime};LGraph.prototype.getFixedTime=function(){return this.fixedtime};LGraph.prototype.getElapsedTime=function(){return this.elapsed_time};
LGraph.prototype.sendEventToAllNodes=function(a,b){var c=this._nodes_in_order?this._nodes_in_order:this._nodes,d;for(d in c)if(c[d][a])if(void 0===b)c[d][a]();else if(b&&b.constructor===Array)c[d][a].apply(c[d],b);else c[d][a](b)};LGraph.prototype.sendActionToCanvas=function(a,b){if(this.list_of_graphcanvas)for(var c in this.list_of_graphcanvas){var d=this.list_of_graphcanvas[c];d[a]&&d[a].apply(d,b)}};
LGraph.prototype.computeExecutionOrder=function(){for(var a=[],b=[],c={},d={},e={},f=0,g=this._nodes.length;f<g;++f){var h=this._nodes[f];c[h.id]=h;var k=0;if(h.inputs)for(var l=0,n=h.inputs.length;l<n;l++)h.inputs[l]&&null!=h.inputs[l].link&&(k+=1);0==k?b.push(h):e[h.id]=k}for(;0!=b.length;)if(h=b.shift(),a.push(h),delete c[h.id],h.outputs)for(f=0;f<h.outputs.length;f++)if(g=h.outputs[f],null!=g&&null!=g.links&&0!=g.links.length)for(l=0;l<g.links.length;l++)(k=this.links[g.links[l]])&&!d[k.id]&&
(n=this.getNodeById(k.target_id),null==n?d[k.id]=!0:(d[k.id]=!0,e[n.id]-=1,0==e[n.id]&&b.push(n)));for(f in c)a.push(c[f]);a.length!=this._nodes.length&&LiteGraph.debug&&console.log("something went wrong, nodes missing");for(f in a)a[f].order=f;return a};LGraph.prototype.getTime=function(){return this.globaltime};LGraph.prototype.getFixedTime=function(){return this.fixedtime};LGraph.prototype.getElapsedTime=function(){return this.elapsed_time};
LGraph.prototype.sendEventToAllNodes=function(a,b){var c=this._nodes_in_order?this._nodes_in_order:this._nodes;if(c)for(var d=0,e=c.length;d<e;++d){var f=c[d];if(f[a])if(void 0===b)f[a]();else if(b&&b.constructor===Array)f[a].apply(M[d],b);else f[a](b)}};LGraph.prototype.sendActionToCanvas=function(a,b){if(this.list_of_graphcanvas)for(var c=0;c<this.list_of_graphcanvas.length;++c){var d=this.list_of_graphcanvas[c];d[a]&&d[a].apply(d,b)}};
LGraph.prototype.add=function(a,b){if(a&&(-1==a.id||null==this._nodes_by_id[a.id])){if(this._nodes.length>=LiteGraph.MAX_NUMBER_OF_NODES)throw"LiteGraph: max number of nodes in a graph reached";if(null==a.id||-1==a.id)a.id=this.last_node_id++;a.graph=this;this._nodes.push(a);this._nodes_by_id[a.id]=a;if(a.onAdded)a.onAdded();this.config.align_to_grid&&a.alignToGrid();b||this.updateExecutionOrder();if(this.onNodeAdded)this.onNodeAdded(a);this.setDirtyCanvas(!0);this.change();return a}};
LGraph.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 c=a.inputs[b];null!=c.link&&a.disconnectInput(b)}if(a.outputs)for(b=0;b<a.outputs.length;b++)c=a.outputs[b],null!=c.links&&c.links.length&&a.disconnectOutput(b);a.id=-1;if(a.onRemoved)a.onRemoved();a.graph=null;for(b in this.list_of_graphcanvas)c=this.list_of_graphcanvas[b],c.selected_nodes[a.id]&&delete c.selected_nodes[a.id],c.node_dragged==a&&(c.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()}};LGraph.prototype.getNodeById=function(a){return null==a?null:this._nodes_by_id[a]};LGraph.prototype.findNodesByClass=function(a){var b=[],c;for(c in this._nodes)this._nodes[c].constructor===a&&b.push(this._nodes[c]);return b};
LGraph.prototype.findNodesByType=function(a){a=a.toLowerCase();var b=[],c;for(c in this._nodes)this._nodes[c].type.toLowerCase()==a&&b.push(this._nodes[c]);return b};LGraph.prototype.findNodesByTitle=function(a){var b=[],c;for(c in this._nodes)this._nodes[c].title==a&&b.push(this._nodes[c]);return b};LGraph.prototype.getNodeOnPos=function(a,b,c){c=c||this._nodes;for(var d=c.length-1;0<=d;d--){var e=c[d];if(e.isPointInsideNode(a,b,2))return e}return null};
LGraph.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 c=a.inputs[b];null!=c.link&&a.disconnectInput(b)}if(a.outputs)for(b=0;b<a.outputs.length;b++)c=a.outputs[b],null!=c.links&&c.links.length&&a.disconnectOutput(b);a.id=-1;if(a.onRemoved)a.onRemoved();a.graph=null;if(this.list_of_graphcanvas)for(b=0;b<this.list_of_graphcanvas.length;++b)c=this.list_of_graphcanvas[b],c.selected_nodes[a.id]&&delete c.selected_nodes[a.id],
c.node_dragged==a&&(c.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()}};LGraph.prototype.getNodeById=function(a){return null==a?null:this._nodes_by_id[a]};LGraph.prototype.findNodesByClass=function(a){for(var b=[],c=0,d=this._nodes.length;c<d;++c)this._nodes[c].constructor===a&&b.push(this._nodes[c]);return b};
LGraph.prototype.findNodesByType=function(a){a=a.toLowerCase();for(var b=[],c=0,d=this._nodes.length;c<d;++c)this._nodes[c].type.toLowerCase()==a&&b.push(this._nodes[c]);return b};LGraph.prototype.findNodesByTitle=function(a){for(var b=[],c=0,d=this._nodes.length;c<d;++c)this._nodes[c].title==a&&b.push(this._nodes[c]);return b};LGraph.prototype.getNodeOnPos=function(a,b,c){c=c||this._nodes;for(var d=c.length-1;0<=d;d--){var e=c[d];if(e.isPointInsideNode(a,b,2))return e}return null};
LGraph.prototype.addGlobalInput=function(a,b,c){this.global_inputs[a]={name:a,type:b,value:c};if(this.onGlobalInputAdded)this.onGlobalInputAdded(a,b);if(this.onGlobalsChange)this.onGlobalsChange()};LGraph.prototype.setGlobalInputData=function(a,b){var c=this.global_inputs[a];c&&(c.value=b)};LGraph.prototype.getGlobalInputData=function(a){return(a=this.global_inputs[a])?a.value:null};
LGraph.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()}};
LGraph.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)};LGraph.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};
LGraph.prototype.addGlobalOutput=function(a,b,c){this.global_outputs[a]={name:a,type:b,value:c};if(this.onGlobalOutputAdded)this.onGlobalOutputAdded(a,b);if(this.onGlobalsChange)this.onGlobalsChange()};LGraph.prototype.setGlobalOutputData=function(a,b){var c=this.global_outputs[a];c&&(c.value=b)};LGraph.prototype.getGlobalOutputData=function(a){return(a=this.global_outputs[a])?a.value:null};
LGraph.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()};
LGraph.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)};LGraph.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};
LGraph.prototype.setInputData=function(a,b){var c=this.findNodesByName(a),d;for(d in c)c[d].setValue(b)};LGraph.prototype.getOutputData=function(a){return this.findNodesByName(a).length?m[0].getValue():null};LGraph.prototype.triggerInput=function(a,b){var c=this.findNodesByName(a),d;for(d in c)c[d].onTrigger(b)};LGraph.prototype.setCallback=function(a,b){var c=this.findNodesByName(a),d;for(d in c)c[d].setTrigger(b)};LGraph.prototype.onConnectionChange=function(){this.updateExecutionOrder()};
LGraph.prototype.isLive=function(){for(var a in this.list_of_graphcanvas)if(this.list_of_graphcanvas[a].live_mode)return!0;return!1};LGraph.prototype.change=function(){LiteGraph.debug&&console.log("Graph changed");this.sendActionToCanvas("setDirty",[!0,!0]);if(this.on_change)this.on_change(this)};LGraph.prototype.setDirtyCanvas=function(a,b){this.sendActionToCanvas("setDirty",[a,b])};
LGraph.prototype.serialize=function(){var a=[],b;for(b in this._nodes)a.push(this._nodes[b].serialize());for(b in this.links)this.links[b].data=null;return{iteration:this.iteration,frame:this.frame,last_node_id:this.last_node_id,last_link_id:this.last_link_id,links:LiteGraph.cloneObject(this.links),config:this.config,nodes:a}};
LGraph.prototype.configure=function(a,b){b||this.clear();var c=a.nodes,d;for(d in a)this[d]=a[d];var e=!1;this._nodes=[];for(d in c){var f=c[d],g=LiteGraph.createNode(f.type,f.title);g?(g.id=f.id,this.add(g,!0),g.configure(f)):(LiteGraph.debug&&console.log("Node not found: "+f.type),e=!0)}this.updateExecutionOrder();this.setDirtyCanvas(!0,!0);return e};LGraph.prototype.onNodeTrace=function(a,b,c){};function LGraphNode(a){this._ctor()}
LGraph.prototype.setInputData=function(a,b){for(var c=this.findNodesByName(a),d=0,e=c.length;d<e;++d)c[d].setValue(b)};LGraph.prototype.getOutputData=function(a){return this.findNodesByName(a).length?m[0].getValue():null};LGraph.prototype.triggerInput=function(a,b){for(var c=this.findNodesByName(a),d=0;d<c.length;++d)c[d].onTrigger(b)};LGraph.prototype.setCallback=function(a,b){for(var c=this.findNodesByName(a),d=0;d<c.length;++d)c[d].setTrigger(b)};
LGraph.prototype.connectionChange=function(a){this.updateExecutionOrder();if(this.onConnectionChange)this.onConnectionChange(a);this.sendActionToCanvas("onConnectionChange")};LGraph.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};LGraph.prototype.change=function(){LiteGraph.debug&&console.log("Graph changed");this.sendActionToCanvas("setDirty",[!0,!0]);if(this.on_change)this.on_change(this)};
LGraph.prototype.setDirtyCanvas=function(a,b){this.sendActionToCanvas("setDirty",[a,b])};LGraph.prototype.serialize=function(){for(var a=[],b=0,c=this._nodes.length;b<c;++b)a.push(this._nodes[b].serialize());for(b in this.links)this.links[b].data=null;return{iteration:this.iteration,frame:this.frame,last_node_id:this.last_node_id,last_link_id:this.last_link_id,links:LiteGraph.cloneObject(this.links),config:this.config,nodes:a}};
LGraph.prototype.configure=function(a,b){b||this.clear();var c=a.nodes,d;for(d in a)this[d]=a[d];var e=!1;this._nodes=[];d=0;for(var f=c.length;d<f;++d){var g=c[d],h=LiteGraph.createNode(g.type,g.title);h?(h.id=g.id,this.add(h,!0),h.configure(g)):(LiteGraph.debug&&console.log("Node not found: "+g.type),e=!0)}this.updateExecutionOrder();this.setDirtyCanvas(!0,!0);return e};LGraph.prototype.onNodeTrace=function(a,b,c){};function LGraphNode(a){this._ctor()}
LGraphNode.prototype._ctor=function(a){this.title=a||"Unnamed";this.size=[LiteGraph.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.data=null;this.flags={}};
LGraphNode.prototype.configure=function(a){for(var b in a)if("console"!=b)if("properties"==b)for(var c in a.properties)this.properties[c]=a.properties[c];else null!=a[b]&&("object"==typeof a[b]?this[b]&&this[b].configure?this[b].configure(a[b]):this[b]=LiteGraph.cloneObject(a[b],this[b]):this[b]=a[b]);for(var d in this.inputs)c=this.inputs[d],c.link&&c.link.length&&(a=c.link,"object"==typeof a&&(c.link=a[0],this.graph.links[a[0]]={id:a[0],origin_id:a[1],origin_slot:a[2],target_id:a[3],target_slot:a[4]}));
for(d in this.outputs)if(c=this.outputs[d],c.links&&0!=c.links.length)for(b in c.links)a=c.links[b],"object"==typeof a&&(c.links[b]=a[0])};
@@ -35,9 +35,9 @@ return a};LGraphNode.prototype.clone=function(){var a=LiteGraph.createNode(this.
LGraphNode.prototype.setOutputData=function(a,b){if(this.outputs&&-1<a&&a<this.outputs.length&&this.outputs[a]&&null!=this.outputs[a].links)for(var c=0;c<this.outputs[a].links.length;c++)this.graph.links[this.outputs[a].links[c]].data=b};LGraphNode.prototype.getInputData=function(a){if(this.inputs&&a<this.inputs.length&&null!=this.inputs[a].link)return this.graph.links[this.inputs[a].link].data};
LGraphNode.prototype.isInputConnected=function(a){return this.inputs?a<this.inputs.length&&null!=this.inputs[a].link:!1};LGraphNode.prototype.getInputInfo=function(a){return this.inputs?a<this.inputs.length?this.inputs[a]:null:null};LGraphNode.prototype.getOutputInfo=function(a){return this.outputs?a<this.outputs.length?this.outputs[a]:null:null};LGraphNode.prototype.isOutputConnected=function(a){return this.outputs?a<this.outputs.length&&this.outputs[a].links&&this.outputs[a].links.length:null};
LGraphNode.prototype.getOutputNodes=function(a){if(!this.outputs||0==this.outputs.length)return null;if(a<this.outputs.length){a=this.outputs[a];for(var b=[],c=0;c<a.length;c++)b.push(this.graph.getNodeById(a.links[c].target_id));return b}return null};LGraphNode.prototype.triggerOutput=function(a,b){var c=this.getOutputNode(a);if(c&&c.onTrigger)c.onTrigger(b)};
LGraphNode.prototype.addOutput=function(a,b,c){a={name:a,type:b,links:null};if(c)for(var d in c)a[d]=c[d];this.outputs||(this.outputs=[]);this.outputs.push(a);if(this.onOutputAdded)this.onOutputAdded(a);this.size=this.computeSize()};LGraphNode.prototype.addOutputs=function(a){for(var b in a){var c=a[b],d={name:c[0],type:c[1],link:null};if(a[2])for(var e in c[2])d[e]=c[2][e];this.outputs||(this.outputs=[]);this.outputs.push(d);if(this.onOutputAdded)this.onOutputAdded(d)}this.size=this.computeSize()};
LGraphNode.prototype.addOutput=function(a,b,c){a={name:a,type:b,links:null};if(c)for(var d in c)a[d]=c[d];this.outputs||(this.outputs=[]);this.outputs.push(a);if(this.onOutputAdded)this.onOutputAdded(a);this.size=this.computeSize()};LGraphNode.prototype.addOutputs=function(a){for(var b=0;b<a.length;++b){var c=a[b],d={name:c[0],type:c[1],link:null};if(a[2])for(var e in c[2])d[e]=c[2][e];this.outputs||(this.outputs=[]);this.outputs.push(d);if(this.onOutputAdded)this.onOutputAdded(d)}this.size=this.computeSize()};
LGraphNode.prototype.removeOutput=function(a){this.disconnectOutput(a);this.outputs.splice(a,1);this.size=this.computeSize();if(this.onOutputRemoved)this.onOutputRemoved(a)};LGraphNode.prototype.addInput=function(a,b,c){a={name:a,type:b||0,link:null};if(c)for(var d in c)a[d]=c[d];this.inputs||(this.inputs=[]);this.inputs.push(a);this.size=this.computeSize();if(this.onInputAdded)this.onInputAdded(a)};
LGraphNode.prototype.addInputs=function(a){for(var b in a){var c=a[b],d={name:c[0],type:c[1],link:null};if(a[2])for(var e in c[2])d[e]=c[2][e];this.inputs||(this.inputs=[]);this.inputs.push(d);if(this.onInputAdded)this.onInputAdded(d)}this.size=this.computeSize()};LGraphNode.prototype.removeInput=function(a){this.disconnectInput(a);this.inputs.splice(a,1);this.size=this.computeSize();if(this.onInputRemoved)this.onInputRemoved(a)};
LGraphNode.prototype.addInputs=function(a){for(var b=0;b<a.length;++b){var c=a[b],d={name:c[0],type:c[1],link:null};if(a[2])for(var e in c[2])d[e]=c[2][e];this.inputs||(this.inputs=[]);this.inputs.push(d);if(this.onInputAdded)this.onInputAdded(d)}this.size=this.computeSize()};LGraphNode.prototype.removeInput=function(a){this.disconnectInput(a);this.inputs.splice(a,1);this.size=this.computeSize();if(this.onInputRemoved)this.onInputRemoved(a)};
LGraphNode.prototype.addConnection=function(a,b,c,d){this.connections.push({name:a,type:b,pos:c,direction:d,links:null})};
LGraphNode.prototype.computeSize=function(a){function b(a){return a?d*a.length*0.6:0}var c=Math.max(this.inputs?this.inputs.length:1,this.outputs?this.outputs.length:1);a=new Float32Array([0,0]);c=Math.max(c,1);a[1]=14*c+6;var d=14,c=b(this.title),e=0,f=0;if(this.inputs)for(var g=0,h=this.inputs.length;g<h;++g){var k=this.inputs[g],k=k.label||k.name||"",k=b(k);e<k&&(e=k)}if(this.outputs)for(g=0,h=this.outputs.length;g<h;++g)k=this.outputs[g],k=k.label||k.name||"",k=b(k),f<k&&(f=k);a[0]=Math.max(e+
f+10,c);a[0]=Math.max(a[0],LiteGraph.NODE_WIDTH);return a};LGraphNode.prototype.getBounding=function(){return new Float32Array([this.pos[0]-4,this.pos[1]-LiteGraph.NODE_TITLE_HEIGHT,this.pos[0]+this.size[0]+4,this.pos[1]+this.size[1]+LGraph.NODE_TITLE_HEIGHT])};
@@ -45,18 +45,18 @@ LGraphNode.prototype.isPointInsideNode=function(a,b,c){c=c||0;var d=this.graph&&
LGraphNode.prototype.getSlotInPosition=function(a,b){if(this.inputs)for(var c=0,d=this.inputs.length;c<d;++c){var e=this.inputs[c],f=this.getConnectionPos(!0,c);if(isInsideRectangle(a,b,f[0]-10,f[1]-5,20,10))return{input:e,slot:c,link_pos:f,locked:e.locked}}if(this.outputs)for(c=0,d=this.outputs.length;c<d;++c)if(e=this.outputs[c],f=this.getConnectionPos(!1,c),isInsideRectangle(a,b,f[0]-10,f[1]-5,20,10))return{output:e,slot:c,link_pos:f,locked:e.locked};return null};
LGraphNode.prototype.findInputSlot=function(a){if(!this.inputs)return-1;for(var b=0,c=this.inputs.length;b<c;++b)if(a==this.inputs[b].name)return b;return-1};LGraphNode.prototype.findOutputSlot=function(a){if(!this.outputs)return-1;for(var b=0,c=this.outputs.length;b<c;++b)if(a==this.outputs[b].name)return b;return-1};
LGraphNode.prototype.connect=function(a,b,c){c=c||0;if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return LiteGraph.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.outputs||a>=this.outputs.length)return LiteGraph.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(c.constructor===String){if(c=b.findInputSlot(c),-1==c)return LiteGraph.debug&&
console.log("Connect: Error, no slot of name "+c),!1}else if(!b.inputs||c>=b.inputs.length)return LiteGraph.debug&&console.log("Connect: Error, slot number not found"),!1;-1!=c&&null!=b.inputs[c].link&&b.disconnectInput(c);this.setDirtyCanvas(!1,!0);this.graph.onConnectionChange();var d=this.outputs[a];if(b.onConnectInput&&!1===b.onConnectInput(c,d.type,d))return!1;-1==c?(null==d.links&&(d.links=[]),d.links.push({id:b.id,slot:-1})):d.type&&b.inputs[c].type&&d.type.toLowerCase()!=b.inputs[c].type.toLowerCase()||
(a={id:this.graph.last_link_id++,origin_id:this.id,origin_slot:a,target_id:b.id,target_slot:c},this.graph.links[a.id]=a,null==d.links&&(d.links=[]),d.links.push(a.id),b.inputs[c].link=a.id);return!0};
console.log("Connect: Error, no slot of name "+c),!1}else if(!b.inputs||c>=b.inputs.length)return LiteGraph.debug&&console.log("Connect: Error, slot number not found"),!1;-1!=c&&null!=b.inputs[c].link&&b.disconnectInput(c);this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this);var d=this.outputs[a];if(b.onConnectInput&&!1===b.onConnectInput(c,d.type,d))return!1;-1==c?(null==d.links&&(d.links=[]),d.links.push({id:b.id,slot:-1})):d.type&&b.inputs[c].type&&d.type.toLowerCase()!=b.inputs[c].type.toLowerCase()||
(a={id:this.graph.last_link_id++,origin_id:this.id,origin_slot:a,target_id:b.id,target_slot:c},this.graph.links[a.id]=a,null==d.links&&(d.links=[]),d.links.push(a.id),b.inputs[c].link=a.id);this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this);return!0};
LGraphNode.prototype.disconnectOutput=function(a,b){if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return LiteGraph.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.outputs||a>=this.outputs.length)return LiteGraph.debug&&console.log("Connect: Error, slot number not found"),!1;var c=this.outputs[a];if(!c.links||0==c.links.length)return!1;if(b){b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"Target Node not found";for(var d=0,e=c.links.length;d<
e;d++){var f=c.links[d],g=this.graph.links[f];if(g.target_id==b.id){c.links.splice(d,1);b.inputs[g.target_slot].link=null;delete this.graph.links[f];break}}}else{d=0;for(e=c.links.length;d<e;d++){f=c.links[d];g=this.graph.links[f];if(b=this.graph.getNodeById(g.target_id))b.inputs[g.target_slot].link=null;delete this.graph.links[f]}c.links=null}this.setDirtyCanvas(!1,!0);this.graph.onConnectionChange();return!0};
e;d++){var f=c.links[d],g=this.graph.links[f];if(g.target_id==b.id){c.links.splice(d,1);b.inputs[g.target_slot].link=null;delete this.graph.links[f];break}}}else{d=0;for(e=c.links.length;d<e;d++){f=c.links[d];g=this.graph.links[f];if(b=this.graph.getNodeById(g.target_id))b.inputs[g.target_slot].link=null;delete this.graph.links[f]}c.links=null}this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this);return!0};
LGraphNode.prototype.disconnectInput=function(a){if(a.constructor===String){if(a=this.findInputSlot(a),-1==a)return LiteGraph.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.inputs||a>=this.inputs.length)return LiteGraph.debug&&console.log("Connect: Error, slot number not found"),!1;if(!this.inputs[a])return!1;var b=this.inputs[a].link;this.inputs[a].link=null;if(b=this.graph.links[b]){a=this.graph.getNodeById(b.origin_id);if(!a)return!1;a=a.outputs[b.origin_slot];if(!a||
!a.links||0==a.links.length)return!1;for(var c=0,d=a.links.length;c<d;c++)if(b=a.links[c],b=this.graph.links[b],b.target_id==this.id){a.links.splice(c,1);break}}this.setDirtyCanvas(!1,!0);this.graph.onConnectionChange();return!0};
!a.links||0==a.links.length)return!1;for(var c=0,d=a.links.length;c<d;c++)if(b=a.links[c],b=this.graph.links[b],b.target_id==this.id){a.links.splice(c,1);break}}this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this);return!0};
LGraphNode.prototype.getConnectionPos=function(a,b){return this.flags.collapsed?a?[this.pos[0],this.pos[1]-0.5*LiteGraph.NODE_TITLE_HEIGHT]:[this.pos[0]+LiteGraph.NODE_COLLAPSED_WIDTH,this.pos[1]-0.5*LiteGraph.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*LiteGraph.NODE_SLOT_HEIGHT]:[this.pos[0]+this.size[0]+1,this.pos[1]+10+b*LiteGraph.NODE_SLOT_HEIGHT]};LGraphNode.prototype.alignToGrid=function(){this.pos[0]=LiteGraph.CANVAS_GRID_SIZE*Math.round(this.pos[0]/LiteGraph.CANVAS_GRID_SIZE);this.pos[1]=LiteGraph.CANVAS_GRID_SIZE*Math.round(this.pos[1]/LiteGraph.CANVAS_GRID_SIZE)};
LGraphNode.prototype.trace=function(a){this.console||(this.console=[]);this.console.push(a);this.console.length>LGraphNode.MAX_CONSOLE&&this.console.shift();this.graph.onNodeTrace(this,a)};LGraphNode.prototype.setDirtyCanvas=function(a,b){this.graph&&this.graph.sendActionToCanvas("setDirty",[a,b])};LGraphNode.prototype.loadImage=function(a){var b=new Image;b.src=LiteGraph.node_images_path+a;b.ready=!1;var c=this;b.onload=function(){this.ready=!0;c.setDirtyCanvas(!0)};return b};
LGraphNode.prototype.executeAction=function(a){if(""==a)return!1;if(-1!=a.indexOf(";")||-1!=a.indexOf("}"))return this.trace("Error: Action contains unsafe characters"),!1;var b=a.split("(")[0];if("function"!=typeof this[b])return this.trace("Error: Action not found on node: "+b),!1;try{b=eval,eval=null,(new Function("with(this) { "+a+"}")).call(this),eval=b}catch(c){return this.trace("Error executing action {"+a+"} :"+c),!1}return!0};
LGraphNode.prototype.captureInput=function(a){if(this.graph&&this.graph.list_of_graphcanvas){var b=this.graph.list_of_graphcanvas,c;for(c in b){var d=b[c];if(a||d.node_capturing_input==this)d.node_capturing_input=a?this:null}}};LGraphNode.prototype.collapse=function(){this.flags.collapsed=this.flags.collapsed?!1:!0;this.setDirtyCanvas(!0,!0)};LGraphNode.prototype.pin=function(a){this.flags.pinned=void 0===a?!this.flags.pinned:a};
LGraphNode.prototype.localToScreen=function(a,b,c){return[(a+this.pos[0])*c.scale+c.offset[0],(b+this.pos[1])*c.scale+c.offset[1]]};function LGraphCanvas(a,b,c){a&&a.constructor===String&&(a=document.querySelector(a));this.max_zoom=10;this.min_zoom=0.1;b&&b.attachCanvas(this);this.setCanvas(a);this.clear();c||this.startRendering()}LGraphCanvas.link_type_colors={number:"#AAC",node:"#DCA"};
LGraphNode.prototype.captureInput=function(a){if(this.graph&&this.graph.list_of_graphcanvas)for(var b=this.graph.list_of_graphcanvas,c=0;c<b.length;++c){var d=b[c];if(a||d.node_capturing_input==this)d.node_capturing_input=a?this:null}};LGraphNode.prototype.collapse=function(){this.flags.collapsed=this.flags.collapsed?!1:!0;this.setDirtyCanvas(!0,!0)};LGraphNode.prototype.pin=function(a){this.flags.pinned=void 0===a?!this.flags.pinned:a};
LGraphNode.prototype.localToScreen=function(a,b,c){return[(a+this.pos[0])*c.scale+c.offset[0],(b+this.pos[1])*c.scale+c.offset[1]]};function LGraphCanvas(a,b,c){c=c||{};a&&a.constructor===String&&(a=document.querySelector(a));this.max_zoom=10;this.min_zoom=0.1;b&&b.attachCanvas(this);this.setCanvas(a);this.clear();c.skip_render||this.startRendering();this.autoresize=c.autoresize}LGraphCanvas.link_type_colors={number:"#AAC",node:"#DCA"};
LGraphCanvas.prototype.clear=function(){this.fps=this.render_time=this.last_draw_time=this.frame=0;this.scale=1;this.offset=[0,0];this.selected_nodes={};this.connecting_node=this.node_capturing_input=this.node_over=this.node_dragged=null;this.highquality_render=!0;this.editor_alpha=1;this.pause_rendering=!1;this.render_only_selected=this.clear_background=this.render_shadows=!0;this.live_mode=!1;this.dirty_bgcanvas=this.dirty_canvas=this.allow_dragnodes=this.allow_dragcanvas=this.show_info=!0;this.node_in_panel=
this.dirty_area=null;this.last_mouse=[0,0];this.last_mouseclick=0;this.title_text_font="bold 14px Arial";this.inner_text_font="normal 12px Arial";this.render_connections_shadows=!1;this.render_connection_arrows=this.render_curved_connections=this.render_connections_border=!0;this.connections_width=4;if(this.onClear)this.onClear()};LGraphCanvas.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)))};
LGraphCanvas.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)};LGraphCanvas.prototype.closeSubgraph=function(){this._graph_stack&&0!=this._graph_stack.length&&(this._graph_stack.pop().attachCanvas(this),this.setDirty(!0,!0))};
@@ -74,12 +74,12 @@ LGraphCanvas.prototype.processMouseDown=function(a){if(this.graph){this.adjustMo
for(e in d)this.processNodeDeselected(d[e])}d=!1;if(c){this.live_mode||c.flags.pinned||this.bringToFront(c);var f=!1;if(!this.connecting_node&&!c.flags.collapsed&&!this.live_mode){if(c.outputs){e=0;for(var g=c.outputs.length;e<g;++e){var h=c.outputs[e],k=c.getConnectionPos(!1,e);if(isInsideRectangle(a.canvasX,a.canvasY,k[0]-10,k[1]-5,20,10)){this.connecting_node=c;this.connecting_output=h;this.connecting_pos=c.getConnectionPos(!1,e);this.connecting_slot=e;f=!0;break}}}if(c.inputs)for(e=0,g=c.inputs.length;e<
g;++e)h=c.inputs[e],k=c.getConnectionPos(!0,e),isInsideRectangle(a.canvasX,a.canvasY,k[0]-10,k[1]-5,20,10)&&null!==h.link&&(c.disconnectInput(e),f=this.dirty_bgcanvas=!0);!f&&isInsideRectangle(a.canvasX,a.canvasY,c.pos[0]+c.size[0]-5,c.pos[1]+c.size[1]-5,5,5)&&(this.resizing_node=c,this.canvas.style.cursor="se-resize",f=!0)}!f&&isInsideRectangle(a.canvasX,a.canvasY,c.pos[0],c.pos[1]-LiteGraph.NODE_TITLE_HEIGHT,LiteGraph.NODE_TITLE_HEIGHT,LiteGraph.NODE_TITLE_HEIGHT)&&(c.collapse(),f=!0);if(!f){e=
!1;if(300>LiteGraph.getTime()-this.last_mouseclick&&this.selected_nodes[c.id]){if(c.onDblClick)c.onDblClick(a);this.processNodeDblClicked(c);e=!0}c.onMouseDown&&c.onMouseDown(a)?e=!0:this.live_mode&&(e=d=!0);e||(this.allow_dragnodes&&(this.node_dragged=c),this.selected_nodes[c.id]||this.processNodeSelected(c,a));this.dirty_canvas=!0}}else d=!0;d&&this.allow_dragcanvas&&(this.dragging_canvas=!0)}else 2!=a.which&&3==a.which&&this.processContextualMenu(c,a);this.last_mouse[0]=a.localX;this.last_mouse[1]=
a.localY;this.last_mouseclick=LiteGraph.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();return!1}};
LGraphCanvas.prototype.processMouseMove=function(a){if(this.graph){this.adjustMouseEvent(a);var b=[a.localX,a.localY],c=[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_canvas)this.offset[0]+=c[0]/this.scale,this.offset[1]+=c[1]/this.scale,this.dirty_bgcanvas=this.dirty_canvas=!0;else{this.connecting_node&&(this.dirty_canvas=!0);var b=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes),d;for(d in this.graph._nodes)if(this.graph._nodes[d].mouseOver&&
b!=this.graph._nodes[d]){this.graph._nodes[d].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){var e=this._highlight_input||[0,0],f=this.isOverNodeInput(b,a.canvasX,a.canvasY,e);-1!=f&&b.inputs[f]?(f=b.inputs[f].type,this.connecting_output.type&&f&&
f.toLowerCase()!=this.connecting_output.type.toLowerCase()||(this._highlight_input=e)):this._highlight_input=null}isInsideRectangle(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(d in this.selected_nodes)b=
this.selected_nodes[d],b.pos[0]+=c[0]/this.scale,b.pos[1]+=c[1]/this.scale;this.dirty_bgcanvas=this.dirty_canvas=!0}this.resizing_node&&!this.live_mode&&(this.resizing_node.size[0]+=c[0]/this.scale,this.resizing_node.size[1]+=c[1]/this.scale,c=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]<c*LiteGraph.NODE_SLOT_HEIGHT+4&&(this.resizing_node.size[1]=c*LiteGraph.NODE_SLOT_HEIGHT+4),this.resizing_node.size[0]<
LiteGraph.NODE_MIN_WIDTH&&(this.resizing_node.size[0]=LiteGraph.NODE_MIN_WIDTH),this.canvas.style.cursor="se-resize",this.dirty_bgcanvas=this.dirty_canvas=!0)}a.preventDefault();return!1}};
a.localY;this.last_mouseclick=LiteGraph.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}};
LGraphCanvas.prototype.processMouseMove=function(a){this.autoresize&&this.resize();if(this.graph){this.adjustMouseEvent(a);var b=[a.localX,a.localY],c=[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_canvas)this.offset[0]+=c[0]/this.scale,this.offset[1]+=c[1]/this.scale,this.dirty_bgcanvas=this.dirty_canvas=!0;else{this.connecting_node&&(this.dirty_canvas=!0);for(var b=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes),
d=0,e=this.graph._nodes.length;d<e;++d)if(this.graph._nodes[d].mouseOver&&b!=this.graph._nodes[d]){this.graph._nodes[d].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){var e=this._highlight_input||[0,0],f=this.isOverNodeInput(b,a.canvasX,a.canvasY,
e);-1!=f&&b.inputs[f]?(f=b.inputs[f].type,this.connecting_output.type&&f&&f.toLowerCase()!=this.connecting_output.type.toLowerCase()||(this._highlight_input=e)):this._highlight_input=null}isInsideRectangle(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(d in this.selected_nodes)b=this.selected_nodes[d],b.pos[0]+=c[0]/this.scale,b.pos[1]+=c[1]/this.scale;this.dirty_bgcanvas=this.dirty_canvas=!0}this.resizing_node&&!this.live_mode&&(this.resizing_node.size[0]+=c[0]/this.scale,this.resizing_node.size[1]+=c[1]/this.scale,c=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]<c*LiteGraph.NODE_SLOT_HEIGHT+
4&&(this.resizing_node.size[1]=c*LiteGraph.NODE_SLOT_HEIGHT+4),this.resizing_node.size[0]<LiteGraph.NODE_MIN_WIDTH&&(this.resizing_node.size[0]=LiteGraph.NODE_MIN_WIDTH),this.canvas.style.cursor="se-resize",this.dirty_bgcanvas=this.dirty_canvas=!0)}a.preventDefault();return!1}};
LGraphCanvas.prototype.processMouseUp=function(a){if(this.graph){var b=this.getCanvasWindow().document;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);if(1==a.which)if(this.connecting_node){this.dirty_bgcanvas=this.dirty_canvas=!0;if(b=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes))if("node"==this.connecting_output.type)this.connecting_node.connect(this.connecting_slot,
b,-1);else{var c=this.isOverNodeInput(b,a.canvasX,a.canvasY);-1!=c?this.connecting_node.connect(this.connecting_slot,b,c):(c=b.getInputInfo(0))&&!c.link&&c.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{this.dirty_canvas=!0;this.dragging_canvas=!1;if(this.node_over&&this.node_over.onMouseUp)this.node_over.onMouseUp(a);if(this.node_capturing_input&&this.node_capturing_input.onMouseUp)this.node_capturing_input.onMouseUp(a)}else 2==a.which?(this.dirty_canvas=!0,this.dragging_canvas=!1):3==a.which&&(this.dirty_canvas=
@@ -90,22 +90,22 @@ LGraphCanvas.prototype.processKey=function(a){if(this.graph){var b=!1;if("keydow
LGraphCanvas.prototype.processDrop=function(a){a.preventDefault();this.adjustMouseEvent(a);var b=[a.canvasX,a.canvasY],c=this.graph.getNodeOnPos(b[0],b[1]);if(c){if(c.onDropFile&&(b=a.dataTransfer.files)&&b.length)for(var d=0;d<b.length;d++){var e=a.dataTransfer.files[0],f=e.name;LGraphCanvas.getFileExtension(f);var g=new FileReader;g.onload=function(a){c.onDropFile(a.target.result,f,e)};var h=e.type.split("/")[0];"text"==h||""==h?g.readAsText(e):"image"==h?g.readAsDataURL(e):g.readAsArrayBuffer(e)}return c.onDropItem&&c.onDropItem(event)?
!0:this.onDropItem?this.onDropItem(event):!1}if(this.onDropItem)this.onDropItem(event)};LGraphCanvas.prototype.processNodeSelected=function(a,b){a.selected=!0;if(a.onSelected)a.onSelected();b&&b.shiftKey||(this.selected_nodes={});this.selected_nodes[a.id]=a;this.dirty_canvas=!0;if(this.onNodeSelected)this.onNodeSelected(a)};
LGraphCanvas.prototype.processNodeDeselected=function(a){a.selected=!1;if(a.onDeselected)a.onDeselected();delete this.selected_nodes[a.id];if(this.onNodeDeselected)this.onNodeDeselected();this.dirty_canvas=!0};LGraphCanvas.prototype.processNodeDblClicked=function(a){if(this.onShowNodePanel)this.onShowNodePanel(a);if(this.onNodeDblClicked)this.onNodeDblClicked(a);this.setDirty(!0)};
LGraphCanvas.prototype.selectNode=function(a){this.deselectAllNodes();if(a){if(!a.selected&&a.onSelected)a.onSelected();a.selected=!0;this.selected_nodes[a.id]=a;this.setDirty(!0)}};LGraphCanvas.prototype.selectAllNodes=function(){for(var a in this.graph._nodes){var b=this.graph._nodes[a];if(!b.selected&&b.onSelected)b.onSelected();b.selected=!0;this.selected_nodes[this.graph._nodes[a].id]=b}this.setDirty(!0)};
LGraphCanvas.prototype.selectNode=function(a){this.deselectAllNodes();if(a){if(!a.selected&&a.onSelected)a.onSelected();a.selected=!0;this.selected_nodes[a.id]=a;this.setDirty(!0)}};LGraphCanvas.prototype.selectAllNodes=function(){for(var a=0;a<this.graph._nodes.length;++a){var b=this.graph._nodes[a];if(!b.selected&&b.onSelected)b.onSelected();b.selected=!0;this.selected_nodes[this.graph._nodes[a].id]=b}this.setDirty(!0)};
LGraphCanvas.prototype.deselectAllNodes=function(){for(var a in this.selected_nodes){var b=this.selected_nodes;if(b.onDeselected)b.onDeselected();b.selected=!1}this.selected_nodes={};this.setDirty(!0)};LGraphCanvas.prototype.deleteSelectedNodes=function(){for(var a in this.selected_nodes)this.graph.remove(this.selected_nodes[a]);this.selected_nodes={};this.setDirty(!0)};
LGraphCanvas.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)};LGraphCanvas.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]};
LGraphCanvas.prototype.setZoom=function(a,b){b||(b=[0.5*this.canvas.width,0.5*this.canvas.height]);var c=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 d=this.convertOffsetToCanvas(b),c=[d[0]-c[0],d[1]-c[1]];this.offset[0]+=c[0];this.offset[1]+=c[1];this.dirty_bgcanvas=this.dirty_canvas=!0};
LGraphCanvas.prototype.convertOffsetToCanvas=function(a){return[a[0]/this.scale-this.offset[0],a[1]/this.scale-this.offset[1]]};LGraphCanvas.prototype.convertCanvasToOffset=function(a){return[(a[0]+this.offset[0])*this.scale,(a[1]+this.offset[1])*this.scale]};LGraphCanvas.prototype.convertEventToCanvas=function(a){var b=this.canvas.getClientRects()[0];return this.convertOffsetToCanvas([a.pageX-b.left,a.pageY-b.top])};
LGraphCanvas.prototype.bringToFront=function(a){var b=this.graph._nodes.indexOf(a);-1!=b&&(this.graph._nodes.splice(b,1),this.graph._nodes.push(a))};LGraphCanvas.prototype.sendToBack=function(a){var b=this.graph._nodes.indexOf(a);-1!=b&&(this.graph._nodes.splice(b,1),this.graph._nodes.unshift(a))};
LGraphCanvas.prototype.computeVisibleNodes=function(){var a=[],b;for(b in this.graph._nodes){var c=this.graph._nodes[b];(!this.live_mode||c.onDrawBackground||c.onDrawForeground)&&overlapBounding(this.visible_area,c.getBounding())&&a.push(c)}return a};
LGraphCanvas.prototype.computeVisibleNodes=function(){for(var a=[],b=0,c=this.graph._nodes.length;b<c;++b){var d=this.graph._nodes[b];(!this.live_mode||d.onDrawBackground||d.onDrawForeground)&&overlapBounding(this.visible_area,d.getBounding())&&a.push(d)}return a};
LGraphCanvas.prototype.draw=function(a,b){var c=LiteGraph.getTime();this.render_time=0.001*(c-this.last_draw_time);this.last_draw_time=c;if(this.graph){var c=[-this.offset[0],-this.offset[1]],d=[c[0]+this.canvas.width/this.scale,c[1]+this.canvas.height/this.scale];this.visible_area=new Float32Array([c[0],c[1],d[0],d[1]])}(this.dirty_bgcanvas||b)&&this.drawBackCanvas();(this.dirty_canvas||a)&&this.drawFrontCanvas();this.fps=this.render_time?1/this.render_time:0;this.frame+=1};
LGraphCanvas.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]);this.visible_nodes=b=this.computeVisibleNodes();for(var c in b){var d=b[c];a.save();a.translate(d.pos[0],d.pos[1]);this.drawNode(d,a);a.restore()}this.graph.config.links_ontop&&(this.live_mode||this.drawConnections(a));null!=this.connecting_pos&&(a.lineWidth=this.connections_width,this.renderLink(a,this.connecting_pos,[this.canvas_mouse[0],this.canvas_mouse[1]],"node"==
this.connecting_output.type?"#F85":"#AFA"),a.beginPath(),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()));a.restore()}this.dirty_area&&a.restore();a.finish2D&&a.finish2D();this.dirty_canvas=!1}};
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]);this.visible_nodes=b=this.computeVisibleNodes();for(var c=0;c<b.length;++c){var d=b[c];a.save();a.translate(d.pos[0],d.pos[1]);this.drawNode(d,a);a.restore()}this.graph.config.links_ontop&&(this.live_mode||this.drawConnections(a));null!=this.connecting_pos&&(a.lineWidth=this.connections_width,this.renderLink(a,this.connecting_pos,[this.canvas_mouse[0],this.canvas_mouse[1]],
"node"==this.connecting_output.type?"#F85":"#AFA"),a.beginPath(),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()));a.restore()}this.dirty_area&&a.restore();a.finish2D&&a.finish2D();this.dirty_canvas=!1}};
LGraphCanvas.prototype.renderInfo=function(a,b,c){b=b||0;c=c||0;a.save();a.translate(b,c);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()};
LGraphCanvas.prototype.drawBackCanvas=function(){var a=this.bgcanvas;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);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=(1-0.5/this.scale)*this.editor_alpha;b.webkitImageSmoothingEnabled=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 c=this;this._bg_img.onload=function(){c.draw(!0,!0)}}var d=null;this._bg_img!=this._pattern_img&&0<this._bg_img.width?(d=b.createPattern(this._bg_img,"repeat"),this._pattern_img=this._bg_img,this._pattern=d):d=this._pattern;d&&(b.fillStyle=d,b.fillRect(this.visible_area[0],this.visible_area[1],this.visible_area[2]-
this.visible_area[0],this.visible_area[3]-this.visible_area[1]),b.fillStyle="transparent");b.globalAlpha=1;b.webkitImageSmoothingEnabled=b.mozImageSmoothingEnabled=b.imageSmoothingEnabled=!0}if(this.onBackgroundRender)this.onBackgroundRender(a,b);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};
LGraphCanvas.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);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=
(1-0.5/this.scale)*this.editor_alpha;b.webkitImageSmoothingEnabled=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 c=this;this._bg_img.onload=function(){c.draw(!0,!0)}}var d=null;this._bg_img!=this._pattern_img&&0<this._bg_img.width?(d=b.createPattern(this._bg_img,"repeat"),this._pattern_img=this._bg_img,this._pattern=d):d=this._pattern;
d&&(b.fillStyle=d,b.fillRect(this.visible_area[0],this.visible_area[1],this.visible_area[2]-this.visible_area[0],this.visible_area[3]-this.visible_area[1]),b.fillStyle="transparent");b.globalAlpha=1;b.webkitImageSmoothingEnabled=b.mozImageSmoothingEnabled=b.imageSmoothingEnabled=!0}if(this.onBackgroundRender)this.onBackgroundRender(a,b);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};
LGraphCanvas.prototype.drawNode=function(a,b){var c=a.color||LiteGraph.NODE_DEFAULT_COLOR,d=!0;if(a.flags.skip_title_render||a.graph.isLive())d=!1;a.mouseOver&&(d=!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 e=this.editor_alpha;b.globalAlpha=e;var f=a.shape||"box",g=new Float32Array(a.size);
a.flags.collapsed&&(g[0]=LiteGraph.NODE_COLLAPSED_WIDTH,g[1]=0);a.flags.clip_area&&(b.save(),"box"==f?(b.beginPath(),b.rect(0,0,g[0],g[1])):"round"==f?b.roundRect(0,0,g[0],g[1],10):"circle"==f&&(b.beginPath(),b.arc(0.5*g[0],0.5*g[1],0.5*g[0],0,2*Math.PI)),b.clip());this.drawNodeShape(a,b,g,c,a.bgcolor,!d,a.selected);b.shadowColor="transparent";b.textAlign="left";b.font=this.inner_text_font;d=0.6<this.scale;if(!a.flags.collapsed){if(a.inputs)for(f=0;f<a.inputs.length;f++){var h=a.inputs[f];b.globalAlpha=
e;null!=this.connecting_node&&this.connecting_output.type&&a.inputs[f].type&&this.connecting_output.type.toLowerCase()!=a.inputs[f].type.toLowerCase()&&(b.globalAlpha=0.4*e);b.fillStyle=null!=h.link?"#7F7":"#AAA";g=a.getConnectionPos(!0,f);g[0]-=a.pos[0];g[1]-=a.pos[1];b.beginPath();b.arc(g[0],g[1],4,0,2*Math.PI);b.fill();d&&(h=null!=h.label?h.label:h.name)&&(b.fillStyle=c,b.fillText(h,g[0]+10,g[1]+5))}this.connecting_node&&(b.globalAlpha=0.4*e);b.lineWidth=1;b.textAlign="right";b.strokeStyle="black";
@@ -115,8 +115,8 @@ b.arc(0.5*c[0],0.5*c[1],0.5*c[0],0,2*Math.PI),b.fill());b.shadowColor="transpare
a.boxcolor||LiteGraph.NODE_DEFAULT_BOXCOLOR,b.beginPath(),"round"==h?b.arc(0.5*e,-0.5*e,0.5*(e-6),0,2*Math.PI):b.rect(3,-e+3,e-6,e-6),b.fill(),b.globalAlpha=d,b.font=this.title_text_font,(a=a.getTitle())&&0.5<this.scale&&(b.fillStyle=LiteGraph.NODE_TITLE_COLOR,b.fillText(a,16,13-e)))};
LGraphCanvas.prototype.drawNodeCollapsed=function(a,b,c,d){b.strokeStyle=c||LiteGraph.NODE_DEFAULT_COLOR;b.fillStyle=d||LiteGraph.NODE_DEFAULT_BGCOLOR;c=LiteGraph.NODE_COLLAPSED_RADIUS;d=a.shape||"box";"circle"==d?(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||LiteGraph.NODE_DEFAULT_BOXCOLOR,b.beginPath(),b.arc(0.5*a.size[0],0.5*a.size[1],0.5*c,0,2*Math.PI)):"round"==d?(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||LiteGraph.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||LiteGraph.NODE_DEFAULT_BOXCOLOR,b.beginPath(),b.rect(0.5*c,0.5*c,c,c));b.fill()};LGraphCanvas.link_colors=["#AAC","#ACA","#CAA"];
LGraphCanvas.prototype.drawConnections=function(a){a.lineWidth=this.connections_width;a.fillStyle="#AAA";a.strokeStyle="#AAA";a.globalAlpha=this.editor_alpha;for(var b in this.graph._nodes){var c=this.graph._nodes[b];if(c.inputs&&c.inputs.length)for(var d in c.inputs){var e=c.inputs[d];if(e&&null!=e.link){var f=this.graph.links[e.link];if(f&&(e=this.graph.getNodeById(f.origin_id),null!=e)){var g=f.origin_slot,f=null,f=-1==g?[e.pos[0]+10,e.pos[1]+10]:e.getConnectionPos(!1,g),e=LGraphCanvas.link_type_colors[c.inputs[d].type];
null==e&&(e=LGraphCanvas.link_colors[c.id%LGraphCanvas.link_colors.length]);this.renderLink(a,f,c.getConnectionPos(!0,d),e)}}}}a.globalAlpha=1};
LGraphCanvas.prototype.drawConnections=function(a){a.lineWidth=this.connections_width;a.fillStyle="#AAA";a.strokeStyle="#AAA";a.globalAlpha=this.editor_alpha;for(var b=0,c=this.graph._nodes.length;b<c;++b){var d=this.graph._nodes[b];if(d.inputs&&d.inputs.length)for(var e=0;e<d.inputs.length;++e){var f=d.inputs[e];if(f&&null!=f.link){var g=this.graph.links[f.link];if(g&&(f=this.graph.getNodeById(g.origin_id),null!=f)){var h=g.origin_slot,g=null,g=-1==h?[f.pos[0]+10,f.pos[1]+10]:f.getConnectionPos(!1,
h),f=LGraphCanvas.link_type_colors[d.inputs[e].type];null==f&&(f=LGraphCanvas.link_colors[d.id%LGraphCanvas.link_colors.length]);this.renderLink(a,g,d.getConnectionPos(!0,e),f)}}}}a.globalAlpha=1};
LGraphCanvas.prototype.renderLink=function(a,b,c,d){if(this.highquality_render){var e=distance(b,c);this.render_connections_border&&0.6<this.scale&&(a.lineWidth=this.connections_width+4);a.beginPath();this.render_curved_connections?(a.moveTo(b[0],b[1]),a.bezierCurveTo(b[0]+0.25*e,b[1],c[0]-0.25*e,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&&(a.strokeStyle=
"rgba(0,0,0,0.5)",a.stroke());a.lineWidth=this.connections_width;a.fillStyle=a.strokeStyle=d;a.stroke();if(this.render_connection_arrows&&0.6<this.scale){d=this.computeConnectionPoint(b,c,0.5);var e=this.computeConnectionPoint(b,c,0.51),f=0,f=this.render_curved_connections?-Math.atan2(e[0]-d[0],e[1]-d[1]):c[1]>b[1]?0:Math.PI;a.save();a.translate(d[0],d[1]);a.rotate(f);a.beginPath();a.moveTo(-5,-5);a.lineTo(0,5);a.lineTo(5,-5);a.fill();a.restore()}}else a.beginPath(),a.moveTo(b[0],b[1]),a.lineTo(c[0],
c[1]),a.stroke()};LGraphCanvas.prototype.computeConnectionPoint=function(a,b,c){var d=distance(a,b),e=[a[0]+0.25*d,a[1]],d=[b[0]-0.25*d,b[1]],f=(1-c)*(1-c)*(1-c),g=3*(1-c)*(1-c)*c,h=3*(1-c)*c*c;c*=c*c;return[f*a[0]+g*e[0]+h*d[0]+c*b[0],f*a[1]+g*e[1]+h*d[1]+c*b[1]]};
@@ -183,7 +183,7 @@ c;return a}};a.prototype.onDrawBackground=function(a){};a.prototype.onGetOutputs
"number"]]};LiteGraph.registerNodeType("input/gamepad",a)})();
(function(){function a(){this.addInput("in","*");this.size=[60,20]}function b(){this.addInput("in");this.addOutput("out");this.size=[60,20]}function c(){this.addInput("in","number",{locked:!0});this.addOutput("out","number",{locked:!0});this.properties={"in":0,in_min:0,in_max:1,out_min:0,out_max:1}}function d(){this.addOutput("value","number");this.properties={min:0,max:1};this.size=[60,20]}function e(){this.addInput("in","number");this.addOutput("out","number");this.size=[60,20];this.properties=
{min:0,max:1}}function f(){this.addInput("in","number");this.addOutput("out","number");this.size=[60,20]}function g(){this.addInput("in","number");this.addOutput("out","number");this.size=[60,20]}function h(){this.addInput("in","number");this.addOutput("out","number");this.size=[60,20]}function k(){this.addInput("in","number");this.addOutput("out","number");this.size=[60,20];this.properties={A:0,B:1}}function l(){this.addInput("in","number",{label:""});this.addOutput("out","number",{label:""});this.size=
[60,20];this.properties={factor:1}}function p(){this.addInput("A","number");this.addInput("B","number");this.addOutput("=","number");this.properties={A:1,B:1,OP:"+"}}function q(){this.addInput("A","number");this.addInput("B","number");this.addOutput("A==B","boolean");this.addOutput("A!=B","boolean");this.properties={A:0,B:0}}function r(){this.addInput("A","number");this.addInput("B","number");this.addOutput("out","boolean");this.properties={A:0,B:1,OP:">"};this.size=[60,40]}function t(){this.addInput("inc",
[60,20];this.properties={factor:1}}function n(){this.addInput("A","number");this.addInput("B","number");this.addOutput("=","number");this.properties={A:1,B:1,OP:"+"}}function q(){this.addInput("A","number");this.addInput("B","number");this.addOutput("A==B","boolean");this.addOutput("A!=B","boolean");this.properties={A:0,B:0}}function r(){this.addInput("A","number");this.addInput("B","number");this.addOutput("out","boolean");this.properties={A:0,B:1,OP:">"};this.size=[60,40]}function t(){this.addInput("inc",
"number");this.addOutput("total","number");this.properties={increment:0,value:0}}function s(){this.addInput("v","number");this.addOutput("sin","number");this.properties={amplitude:1,offset:0};this.bgImageUrl="nodes/imgs/icon-sin.png"}function u(){this.addInput("vec2","vec2");this.addOutput("x","number");this.addOutput("y","number")}function v(){this.addInputs([["x","number"],["y","number"]]);this.addOutput("vec2","vec2");this.properties={x:0,y:0};this._data=new Float32Array(2)}function w(){this.addInput("vec3",
"vec3");this.addOutput("x","number");this.addOutput("y","number");this.addOutput("z","number")}function x(){this.addInputs([["x","number"],["y","number"],["z","number"]]);this.addOutput("vec3","vec3");this.properties={x:0,y:0,z:0};this._data=new Float32Array(3)}function y(){this.addInput("vec4","vec4");this.addOutput("x","number");this.addOutput("y","number");this.addOutput("z","number");this.addOutput("w","number")}function z(){this.addInputs([["x","number"],["y","number"],["z","number"],["w","number"]]);
this.addOutput("vec4","vec4");this.properties={x:0,y:0,z:0,w:0};this._data=new Float32Array(4)}a.title="Converter";a.desc="type A to type B";a.prototype.onExecute=function(){var a=this.getInputData(0);if(null!=a&&this.outputs)for(var b=0;b<this.outputs.length;b++){var c=this.outputs[b];if(c.links&&c.links.length){var d=null;switch(c.name){case "number":d=a.length?a[0]:parseFloat(a);break;case "vec2":case "vec3":case "vec4":d=1;switch(c.name){case "vec2":d=2;break;case "vec3":d=3;break;case "vec4":d=
@@ -193,21 +193,21 @@ c.prototype.onExecute=function(){if(this.inputs)for(var a=0;a<this.inputs.length
function(a){this.outputs[0].label=this._last_v?this._last_v.toFixed(3):"?"};d.prototype.onGetInputs=function(){return[["min","number"],["max","number"]]};LiteGraph.registerNodeType("math/rand",d);e.title="Clamp";e.desc="Clamp number between min and max";e.filter="shader";e.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&(a=Math.max(this.properties.min,a),a=Math.min(this.properties.max,a),this.setOutputData(0,a))};e.prototype.getCode=function(a){a="";this.isInputConnected(0)&&(a+=
"clamp({{0}},"+this.properties.min+","+this.properties.max+")");return a};LiteGraph.registerNodeType("math/clamp",e);f.title="Abs";f.desc="Absolute";f.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,Math.abs(a))};LiteGraph.registerNodeType("math/abs",f);g.title="Floor";g.desc="Floor number to remove fractional part";g.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,Math.floor(a))};LiteGraph.registerNodeType("math/floor",
g);h.title="Frac";h.desc="Returns fractional part";h.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,a%1)};LiteGraph.registerNodeType("math/frac",h);k.title="Smoothstep";k.desc="Smoothstep";k.prototype.onExecute=function(){var a=this.getInputData(0);if(void 0!==a){var b=this.properties.A,a=Math.clamp((a-b)/(this.properties.B-b),0,1);this.setOutputData(0,a*a*(3-2*a))}};LiteGraph.registerNodeType("math/smoothstep",k);l.title="Scale";l.desc="v * factor";l.prototype.onExecute=
function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,a*this.properties.factor)};LiteGraph.registerNodeType("math/scale",l);p.title="Operation";p.desc="Easy math operators";p["@OP"]={type:"enum",title:"operation",values:"+-*/%^".split("")};p.prototype.setValue=function(a){"string"==typeof a&&(a=parseFloat(a));this.properties.value=a};p.prototype.onExecute=function(){var a=this.getInputData(0),b=this.getInputData(1);null!=a?this.properties.A=a:a=this.properties.A;null!=b?this.properties.B=
b:b=this.properties.B;var c=0;switch(this.properties.OP){case "+":c=a+b;break;case "-":c=a-b;break;case "/":c=a/b;break;case "%":c=a%b;break;case "^":c=Math.pow(a,b)}this.setOutputData(0,c)};p.prototype.onDrawBackground=function(a){this.outputs[0].label="A"+this.properties.OP+"B"};LiteGraph.registerNodeType("math/operation",p);q.title="Compare";q.desc="compares between two values";q.prototype.onExecute=function(){var a=this.getInputData(0),b=this.getInputData(1);void 0!==a?this.properties.A=a:a=this.properties.A;
function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,a*this.properties.factor)};LiteGraph.registerNodeType("math/scale",l);n.title="Operation";n.desc="Easy math operators";n["@OP"]={type:"enum",title:"operation",values:"+-*/%^".split("")};n.prototype.setValue=function(a){"string"==typeof a&&(a=parseFloat(a));this.properties.value=a};n.prototype.onExecute=function(){var a=this.getInputData(0),b=this.getInputData(1);null!=a?this.properties.A=a:a=this.properties.A;null!=b?this.properties.B=
b:b=this.properties.B;var c=0;switch(this.properties.OP){case "+":c=a+b;break;case "-":c=a-b;break;case "/":c=a/b;break;case "%":c=a%b;break;case "^":c=Math.pow(a,b)}this.setOutputData(0,c)};n.prototype.onDrawBackground=function(a){this.outputs[0].label="A"+this.properties.OP+"B"};LiteGraph.registerNodeType("math/operation",n);q.title="Compare";q.desc="compares between two values";q.prototype.onExecute=function(){var a=this.getInputData(0),b=this.getInputData(1);void 0!==a?this.properties.A=a:a=this.properties.A;
void 0!==b?this.properties.B=b:b=this.properties.B;for(var c=0,d=this.outputs.length;c<d;++c){var e=this.outputs[c];if(e.links&&e.links.length){switch(e.name){case "A==B":value=a==b;break;case "A!=B":value=a!=b;break;case "A>B":value=a>b;break;case "A<B":value=a<b;break;case "A<=B":value=a<=b;break;case "A>=B":value=a>=b}this.setOutputData(c,value)}}};q.prototype.onGetOutputs=function(){return[["A==B","boolean"],["A!=B","boolean"],["A>B","boolean"],["A<B","boolean"],["A>=B","boolean"],["A<=B","boolean"]]};
LiteGraph.registerNodeType("math/compare",q);r["@OP"]={type:"enum",title:"operation",values:"> < == != <= >=".split(" ")};r.title="Condition";r.desc="evaluates condition between A and B";r.prototype.onExecute=function(){var a=this.getInputData(0);void 0===a?a=this.properties.A:this.properties.A=a;var b=this.getInputData(1);void 0===b?b=this.properties.B:this.properties.B=b;var c=!0;switch(this.properties.OP){case ">":c=a>b;break;case "<":c=a<b;break;case "==":c=a==b;break;case "!=":c=a!=b;break;case "<=":c=
a<=b;break;case ">=":c=a>=b}this.setOutputData(0,c)};LiteGraph.registerNodeType("math/condition",r);t.title="Accumulate";t.desc="Increments a value every time";t.prototype.onExecute=function(){var a=this.getInputData(0);this.properties.value=null!==a?this.properties.value+a:this.properties.value+this.properties.increment;this.setOutputData(0,this.properties.value)};LiteGraph.registerNodeType("math/accumulate",t);s.title="Trigonometry";s.desc="Sin Cos Tan";s.filter="shader";s.prototype.onExecute=function(){var a=
this.getInputData(0),b=this.properties.amplitude,c=this.findInputSlot("amplitude");-1!=c&&(b=this.getInputData(c));var d=this.properties.offset,c=this.findInputSlot("offset");-1!=c&&(d=this.getInputData(c));for(var c=0,e=this.outputs.length;c<e;++c){switch(this.outputs[c].name){case "sin":value=Math.sin(a);break;case "cos":value=Math.cos(a);break;case "tan":value=Math.tan(a);break;case "asin":value=Math.asin(a);break;case "acos":value=Math.acos(a);break;case "atan":value=Math.atan(a)}this.setOutputData(c,
b*value+d)}};s.prototype.onGetInputs=function(){return[["v","number"],["amplitude","number"],["offset","number"]]};s.prototype.onGetOutputs=function(){return[["sin","number"],["cos","number"],["tan","number"],["asin","number"],["acos","number"],["atan","number"]]};LiteGraph.registerNodeType("math/trigonometry",s);if(window.math){var n=function(){this.addInputs("x","number");this.addInputs("y","number");this.addOutputs("","number");this.properties={x:1,y:1,formula:"x+y"}};n.title="Formula";n.desc=
"Compute safe formula";n.prototype.onExecute=function(){var a=this.getInputData(0),b=this.getInputData(1);null!=a?this.properties.x=a:a=this.properties.x;null!=b?this.properties.y=b:b=this.properties.y;a=math.eval(this.properties.formula,{x:a,y:b,T:this.graph.globaltime});this.setOutputData(0,a)};n.prototype.onDrawBackground=function(){this.outputs[0].label=this.properties.formula};n.prototype.onGetOutputs=function(){return[["A-B","number"],["A*B","number"],["A/B","number"]]};LiteGraph.registerNodeType("math/formula",
n)}u.title="Vec2->XY";u.desc="vector 2 to components";u.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&(this.setOutputData(0,a[0]),this.setOutputData(1,a[1]))};LiteGraph.registerNodeType("math3d/vec2-to-xyz",u);v.title="XY->Vec2";v.desc="components to vector2";v.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=this.properties.x);var b=this.getInputData(1);null==b&&(b=this.properties.y);var c=this._data;c[0]=a;c[1]=b;this.setOutputData(0,c)};LiteGraph.registerNodeType("math3d/xy-to-vec2",
b*value+d)}};s.prototype.onGetInputs=function(){return[["v","number"],["amplitude","number"],["offset","number"]]};s.prototype.onGetOutputs=function(){return[["sin","number"],["cos","number"],["tan","number"],["asin","number"],["acos","number"],["atan","number"]]};LiteGraph.registerNodeType("math/trigonometry",s);if(window.math){var p=function(){this.addInputs("x","number");this.addInputs("y","number");this.addOutputs("","number");this.properties={x:1,y:1,formula:"x+y"}};p.title="Formula";p.desc=
"Compute safe formula";p.prototype.onExecute=function(){var a=this.getInputData(0),b=this.getInputData(1);null!=a?this.properties.x=a:a=this.properties.x;null!=b?this.properties.y=b:b=this.properties.y;a=math.eval(this.properties.formula,{x:a,y:b,T:this.graph.globaltime});this.setOutputData(0,a)};p.prototype.onDrawBackground=function(){this.outputs[0].label=this.properties.formula};p.prototype.onGetOutputs=function(){return[["A-B","number"],["A*B","number"],["A/B","number"]]};LiteGraph.registerNodeType("math/formula",
p)}u.title="Vec2->XY";u.desc="vector 2 to components";u.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&(this.setOutputData(0,a[0]),this.setOutputData(1,a[1]))};LiteGraph.registerNodeType("math3d/vec2-to-xyz",u);v.title="XY->Vec2";v.desc="components to vector2";v.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=this.properties.x);var b=this.getInputData(1);null==b&&(b=this.properties.y);var c=this._data;c[0]=a;c[1]=b;this.setOutputData(0,c)};LiteGraph.registerNodeType("math3d/xy-to-vec2",
v);w.title="Vec3->XYZ";w.desc="vector 3 to components";w.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&(this.setOutputData(0,a[0]),this.setOutputData(1,a[1]),this.setOutputData(2,a[2]))};LiteGraph.registerNodeType("math3d/vec3-to-xyz",w);x.title="XYZ->Vec3";x.desc="components to vector3";x.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=this.properties.x);var b=this.getInputData(1);null==b&&(b=this.properties.y);var c=this.getInputData(2);null==c&&(c=this.properties.z);
var d=this._data;d[0]=a;d[1]=b;d[2]=c;this.setOutputData(0,d)};LiteGraph.registerNodeType("math3d/xyz-to-vec3",x);y.title="Vec4->XYZW";y.desc="vector 4 to components";y.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&(this.setOutputData(0,a[0]),this.setOutputData(1,a[1]),this.setOutputData(2,a[2]),this.setOutputData(3,a[3]))};LiteGraph.registerNodeType("math3d/vec4-to-xyzw",y);z.title="XYZW->Vec4";z.desc="components to vector4";z.prototype.onExecute=function(){var a=this.getInputData(0);
null==a&&(a=this.properties.x);var b=this.getInputData(1);null==b&&(b=this.properties.y);var c=this.getInputData(2);null==c&&(c=this.properties.z);var d=this.getInputData(3);null==d&&(d=this.properties.w);var e=this._data;e[0]=a;e[1]=b;e[2]=c;e[3]=d;this.setOutputData(0,e)};LiteGraph.registerNodeType("math3d/xyzw-to-vec4",z);window.glMatrix&&(n=function(){this.addInputs([["degrees","number"],["axis","vec3"]]);this.addOutput("quat","quat");this.properties={angle:90,axis:vec3.fromValues(0,1,0)}},n.title=
"Rotation",n.desc="quaternion rotation",n.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=this.properties.angle);var b=this.getInputData(1);null==b&&(b=this.properties.axis);a=quat.setAxisAngle(quat.create(),b,0.0174532925*a);this.setOutputData(0,a)},LiteGraph.registerNodeType("math3d/rotation",n),n=function(){this.addInputs([["vec3","vec3"],["quat","quat"]]);this.addOutput("result","vec3");this.properties={vec:[0,0,1]}},n.title="Rot. Vec3",n.desc="rotate a point",n.prototype.onExecute=
function(){var a=this.getInputData(0);null==a&&(a=this.properties.vec);var b=this.getInputData(1);null==b?this.setOutputData(a):this.setOutputData(0,vec3.transformQuat(vec3.create(),a,b))},LiteGraph.registerNodeType("math3d/rotate_vec3",n),n=function(){this.addInputs([["A","quat"],["B","quat"]]);this.addOutput("A*B","quat")},n.title="Mult. Quat",n.desc="rotate quaternion",n.prototype.onExecute=function(){var a=this.getInputData(0);if(null!=a){var b=this.getInputData(1);null!=b&&(a=quat.multiply(quat.create(),
a,b),this.setOutputData(0,a))}},LiteGraph.registerNodeType("math3d/mult-quat",n))})();function Selector(){this.addInput("sel","boolean");this.addOutput("value","number");this.properties={A:0,B:1};this.size=[60,20]}Selector.title="Selector";Selector.desc="outputs A if selector is true, B if selector is false";
null==a&&(a=this.properties.x);var b=this.getInputData(1);null==b&&(b=this.properties.y);var c=this.getInputData(2);null==c&&(c=this.properties.z);var d=this.getInputData(3);null==d&&(d=this.properties.w);var e=this._data;e[0]=a;e[1]=b;e[2]=c;e[3]=d;this.setOutputData(0,e)};LiteGraph.registerNodeType("math3d/xyzw-to-vec4",z);window.glMatrix&&(p=function(){this.addInputs([["degrees","number"],["axis","vec3"]]);this.addOutput("quat","quat");this.properties={angle:90,axis:vec3.fromValues(0,1,0)}},p.title=
"Rotation",p.desc="quaternion rotation",p.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=this.properties.angle);var b=this.getInputData(1);null==b&&(b=this.properties.axis);a=quat.setAxisAngle(quat.create(),b,0.0174532925*a);this.setOutputData(0,a)},LiteGraph.registerNodeType("math3d/rotation",p),p=function(){this.addInputs([["vec3","vec3"],["quat","quat"]]);this.addOutput("result","vec3");this.properties={vec:[0,0,1]}},p.title="Rot. Vec3",p.desc="rotate a point",p.prototype.onExecute=
function(){var a=this.getInputData(0);null==a&&(a=this.properties.vec);var b=this.getInputData(1);null==b?this.setOutputData(a):this.setOutputData(0,vec3.transformQuat(vec3.create(),a,b))},LiteGraph.registerNodeType("math3d/rotate_vec3",p),p=function(){this.addInputs([["A","quat"],["B","quat"]]);this.addOutput("A*B","quat")},p.title="Mult. Quat",p.desc="rotate quaternion",p.prototype.onExecute=function(){var a=this.getInputData(0);if(null!=a){var b=this.getInputData(1);null!=b&&(a=quat.multiply(quat.create(),
a,b),this.setOutputData(0,a))}},LiteGraph.registerNodeType("math3d/mult-quat",p))})();function Selector(){this.addInput("sel","boolean");this.addOutput("value","number");this.properties={A:0,B:1};this.size=[60,20]}Selector.title="Selector";Selector.desc="outputs A if selector is true, B if selector is false";
Selector.prototype.onExecute=function(){var a=this.getInputData(0);if(void 0!==a){for(var b=1;b<this.inputs.length;b++){var c=this.inputs[b],d=this.getInputData(b);void 0!==d&&(this.properties[c.name]=d)}b=this.properties.A;c=this.properties.B;this.setOutputData(0,a?b:c)}};Selector.prototype.onGetInputs=function(){return[["A",0],["B",0]]};LiteGraph.registerNodeType("logic/selector",Selector);
(function(){function a(){this.inputs=[];this.addOutput("frame","image");this.properties={url:""}}function b(){this.addInput("f","number");this.addOutput("Color","color");this.properties={colorA:"#444444",colorB:"#44AAFF",colorC:"#44FFAA",colorD:"#FFFFFF"}}function c(){this.addInput("","image");this.size=[200,200]}function d(){this.addInputs([["img1","image"],["img2","image"],["fade","number"]]);this.addInput("","image");this.properties={fade:0.5,width:512,height:512}}function e(){this.addInput("",
"image");this.addOutputs("","image");this.properties={width:256,height:256,x:0,y:0,scale:1};this.size=[50,20]}function f(){this.addInput("t","number");this.addOutputs([["frame","image"],["t","number"],["d","number"]]);this.properties={url:""}}function g(){this.addOutput("Webcam","image");this.properties={}}a.title="Image";a.desc="Image loader";a.widgets=[{name:"load",text:"Load",type:"button"}];a.prototype.onAdded=function(){""!=this.properties.url&&null==this.img&&this.loadImage(this.properties.url)};
@@ -228,23 +228,23 @@ this._video.pause())};f.prototype.onWidget=function(a,b){};LiteGraph.registerNod
this.streamReady.bind(this),a);var b=this}};g.prototype.onRemoved=function(){this._webcam_stream&&(this._webcam_stream.stop(),this._video=this._webcam_stream=null)};g.prototype.streamReady=function(a){this._webcam_stream=a;var b=this._video;b||(b=document.createElement("video"),b.autoplay=!0,b.src=window.URL.createObjectURL(a),this._video=b,b.onloadedmetadata=function(a){console.log(a)})};g.prototype.onExecute=function(){null!=this._webcam_stream||this._waiting_confirmation||this.openStream();this._video&&
this._video.videoWidth&&(this._video.width=this._video.videoWidth,this._video.height=this._video.videoHeight,this.setOutputData(0,this._video))};g.prototype.getExtraMenuOptions=function(a){var b=this;return[{content:b.properties.show?"Hide Frame":"Show Frame",callback:function(){b.properties.show=!b.properties.show}}]};g.prototype.onDrawBackground=function(a){this.flags.collapsed||20>=this.size[1]||!this.properties.show||!this._video||(a.save(),a.drawImage(this._video,0,0,this.size[0],this.size[1]),
a.restore())};LiteGraph.registerNodeType("graphics/webcam",g)})();
if("undefined"!=typeof LiteGraph){var LGraphTexture=function(){this.addOutput("Texture","Texture");this.properties={name:""};this.size=[LGraphTexture.image_preview_size,LGraphTexture.image_preview_size]};LGraphTexture.title="Texture";LGraphTexture.desc="Texture";LGraphTexture.widgets_info={name:{widget:"texture"}};LGraphTexture.loadTextureCallback=null;LGraphTexture.image_preview_size=256;LGraphTexture.PASS_THROUGH=1;LGraphTexture.COPY=2;LGraphTexture.LOW=3;LGraphTexture.HIGH=4;LGraphTexture.REUSE=
5;LGraphTexture.DEFAULT=2;LGraphTexture.MODE_VALUES={"pass through":LGraphTexture.PASS_THROUGH,copy:LGraphTexture.COPY,low:LGraphTexture.LOW,high:LGraphTexture.HIGH,reuse:LGraphTexture.REUSE,"default":LGraphTexture.DEFAULT};LGraphTexture.getTexturesContainer=function(){return gl.textures};LGraphTexture.loadTexture=function(a,b){b=b||{};var c=a;"http://"==c.substr(0,7)&&LiteGraph.proxy&&(c=LiteGraph.proxy+c.substr(7));return LGraphTexture.getTexturesContainer()[a]=GL.Texture.fromURL(c,b)};LGraphTexture.getTexture=
function(a){var b=this.getTexturesContainer();if(!b)throw"Cannot load texture, container of textures not found";b=b[a];return!b&&a&&":"!=a[0]?(this.loadTexture(a),null):b};LGraphTexture.getTargetTexture=function(a,b,c){if(!a)throw"LGraphTexture.getTargetTexture expects a reference texture";var d=null;switch(c){case LGraphTexture.LOW:d=gl.UNSIGNED_BYTE;break;case LGraphTexture.HIGH:d=gl.HIGH_PRECISION_FORMAT;break;case LGraphTexture.REUSE:return a;default:d=a?a.type:gl.UNSIGNED_BYTE}b&&b.width==a.width&&
b.height==a.height&&b.type==d||(b=new GL.Texture(a.width,a.height,{type:d,format:gl.RGBA,filter:gl.LINEAR}));return b};LGraphTexture.getNoiseTexture=function(){if(this._noise_texture)return this._noise_texture;for(var a=new Uint8Array(1048576),b=0;1048576>b;++b)a[b]=255*Math.random();return this._noise_texture=a=GL.Texture.fromMemory(512,512,a,{format:gl.RGBA,wrap:gl.REPEAT,filter:gl.NEAREST})};LGraphTexture.prototype.onDropFile=function(a,b,c){if(a){var d=null;"string"==typeof a?d=GL.Texture.fromURL(a):
-1!=b.toLowerCase().indexOf(".dds")?d=GL.Texture.fromDDSInMemory(a):(a=new Blob([c]),a=URL.createObjectURL(a),d=GL.Texture.fromURL(a));this._drop_texture=d;this.properties.name=b}else this._drop_texture=null,this.properties.name=""};LGraphTexture.prototype.getExtraMenuOptions=function(a){var b=this;if(this._drop_texture)return[{content:"Clear",callback:function(){b._drop_texture=null;b.properties.name=""}}]};LGraphTexture.prototype.onExecute=function(){var a=null;this.isOutputConnected(1)&&(a=this.getInputData(0));
!a&&this._drop_texture&&(a=this._drop_texture);!a&&this.properties.name&&(a=LGraphTexture.getTexture(this.properties.name));if(a){this._last_tex=a;this.setOutputData(0,a);for(var b=1;b<this.outputs.length;b++){var c=this.outputs[b];if(c){var d=null;"width"==c.name?d=a.width:"height"==c.name?d=a.height:"aspect"==c.name&&(d=a.width/a.height);this.setOutputData(b,d)}}}};LGraphTexture.prototype.onResourceRenamed=function(a,b){this.properties.name==a&&(this.properties.name=b)};LGraphTexture.prototype.onDrawBackground=
function(a){if(!(this.flags.collapsed||20>=this.size[1]))if(this._drop_texture&&a.webgl)a.drawImage(this._drop_texture,0,0,this.size[0],this.size[1]);else{if(this._last_preview_tex!=this._last_tex)if(a.webgl)this._canvas=this._last_tex;else{var b=LGraphTexture.generateLowResTexturePreview(this._last_tex);if(!b)return;this._last_preview_tex=this._last_tex;this._canvas=cloneCanvas(b)}this._canvas&&(a.save(),a.webgl||(a.translate(0,this.size[1]),a.scale(1,-1)),a.drawImage(this._canvas,0,0,this.size[0],
this.size[1]),a.restore())}};LGraphTexture.generateLowResTexturePreview=function(a){if(!a)return null;var b=LGraphTexture.image_preview_size,c=a;if(a.format==gl.DEPTH_COMPONENT)return null;if(a.width>b||a.height>b)c=this._preview_temp_tex,this._preview_temp_tex||(this._preview_temp_tex=c=new GL.Texture(b,b,{minFilter:gl.NEAREST})),a.copyTo(c);a=this._preview_canvas;a||(this._preview_canvas=a=createCanvas(b,b));c&&c.toCanvas(a);return a};LGraphTexture.prototype.onGetInputs=function(){return[["in",
"Texture"]]};LGraphTexture.prototype.onGetOutputs=function(){return[["width","number"],["height","number"],["aspect","number"]]};LiteGraph.registerNodeType("texture/texture",LGraphTexture);var LGraphTexturePreview=function(){this.addInput("Texture","Texture");this.properties={flipY:!1};this.size=[LGraphTexture.image_preview_size,LGraphTexture.image_preview_size]};LGraphTexturePreview.title="Preview";LGraphTexturePreview.desc="Show a texture in the graph canvas";LGraphTexturePreview.prototype.onDrawBackground=
function(a){if(!this.flags.collapsed){var b=this.getInputData(0);if(b){var c=null,c=!b.handle&&a.webgl?b:LGraphTexture.generateLowResTexturePreview(b);a.save();this.properties.flipY&&(a.translate(0,this.size[1]),a.scale(1,-1));a.drawImage(c,0,0,this.size[0],this.size[1]);a.restore()}}};LiteGraph.registerNodeType("texture/preview",LGraphTexturePreview);var LGraphTextureSave=function(){this.addInput("Texture","Texture");this.addOutput("","Texture");this.properties={name:""}};LGraphTextureSave.title=
"Save";LGraphTextureSave.desc="Save a texture in the repository";LGraphTextureSave.prototype.onExecute=function(){var a=this.getInputData(0);a&&(this.properties.name&&(LGraphTexture.getTexturesContainer()[this.properties.name]=a),this.setOutputData(0,a))};LiteGraph.registerNodeType("texture/save",LGraphTextureSave);var LGraphTextureOperation=function(){this.addInput("Texture","Texture");this.addInput("TextureB","Texture");this.addInput("value","number");this.addOutput("Texture","Texture");this.help=
"<p>pixelcode must be vec3</p>\t\t\t<p>uvcode must be vec2, is optional</p>\t\t\t<p><strong>uv:</strong> tex. coords</p><p><strong>color:</strong> texture</p><p><strong>colorB:</strong> textureB</p><p><strong>time:</strong> scene time</p><p><strong>value:</strong> input value</p>";this.properties={value:1,uvcode:"",pixelcode:"color + colorB * value",precision:LGraphTexture.DEFAULT}};LGraphTextureOperation.widgets_info={uvcode:{widget:"textarea",height:100},pixelcode:{widget:"textarea",height:100},
precision:{widget:"combo",values:LGraphTexture.MODE_VALUES}};LGraphTextureOperation.title="Operation";LGraphTextureOperation.desc="Texture shader operation";LGraphTextureOperation.prototype.getExtraMenuOptions=function(a){var b=this;return[{content:b.properties.show?"Hide Texture":"Show Texture",callback:function(){b.properties.show=!b.properties.show}}]};LGraphTextureOperation.prototype.onDrawBackground=function(a){this.flags.collapsed||20>=this.size[1]||!this.properties.show||!this._tex||this._tex.gl!=
a||(a.save(),a.drawImage(this._tex,0,0,this.size[0],this.size[1]),a.restore())};LGraphTextureOperation.prototype.onExecute=function(){var a=this.getInputData(0);if(this.isOutputConnected(0))if(this.properties.precision===LGraphTexture.PASS_THROUGH)this.setOutputData(0,a);else{var b=this.getInputData(1);if(this.properties.uvcode||this.properties.pixelcode){var c=512,d=512;a?(c=a.width,d=a.height):b&&(c=b.width,d=b.height);this._tex=a||this._tex?LGraphTexture.getTargetTexture(a||this._tex,this._tex,
this.properties.precision):new GL.Texture(c,d,{type:this.precision===LGraphTexture.LOW?gl.UNSIGNED_BYTE:gl.HIGH_PRECISION_FORMAT,format:gl.RGBA,filter:gl.LINEAR});var e="";this.properties.uvcode&&(e="uv = "+this.properties.uvcode,-1!=this.properties.uvcode.indexOf(";")&&(e=this.properties.uvcode));var f="";this.properties.pixelcode&&(f="result = "+this.properties.pixelcode,-1!=this.properties.pixelcode.indexOf(";")&&(f=this.properties.pixelcode));var g=this._shader;if(!g||this._shader_code!=e+"|"+
f){try{this._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,LGraphTextureOperation.pixel_shader,{UV_CODE:e,PIXEL_CODE:f}),this.boxcolor="#00FF00"}catch(h){console.log("Error compiling shader: ",h);this.boxcolor="#FF0000";return}this._shader_code=e+"|"+f;g=this._shader}if(g){this.boxcolor="green";var k=this.getInputData(2);null!=k?this.properties.value=k:k=parseFloat(this.properties.value);var l=this.graph.getTime();this._tex.drawTo(function(){gl.disable(gl.DEPTH_TEST);gl.disable(gl.CULL_FACE);gl.disable(gl.BLEND);
a&&a.bind(0);b&&b.bind(1);var e=Mesh.getScreenQuad();g.uniforms({u_texture:0,u_textureB:1,value:k,texSize:[c,d],time:l}).draw(e)});this.setOutputData(0,this._tex)}else this.boxcolor="red"}}};LGraphTextureOperation.pixel_shader="precision highp float;\n\t\t\t\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform sampler2D u_textureB;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform vec2 texSize;\n\t\t\tuniform float time;\n\t\t\tuniform float value;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec2 uv = v_coord;\n\t\t\t\tUV_CODE;\n\t\t\t\tvec3 color = texture2D(u_texture, uv).rgb;\n\t\t\t\tvec3 colorB = texture2D(u_textureB, uv).rgb;\n\t\t\t\tvec3 result = color;\n\t\t\t\tfloat alpha = 1.0;\n\t\t\t\tPIXEL_CODE;\n\t\t\t\tgl_FragColor = vec4(result, alpha);\n\t\t\t}\n\t\t\t";
if("undefined"!=typeof LiteGraph){var LGraphTexture=function(){this.addOutput("Texture","Texture");this.properties={name:"",filter:!0};this.size=[LGraphTexture.image_preview_size,LGraphTexture.image_preview_size]};LGraphTexture.title="Texture";LGraphTexture.desc="Texture";LGraphTexture.widgets_info={name:{widget:"texture"},filter:{widget:"checkbox"}};LGraphTexture.loadTextureCallback=null;LGraphTexture.image_preview_size=256;LGraphTexture.PASS_THROUGH=1;LGraphTexture.COPY=2;LGraphTexture.LOW=3;LGraphTexture.HIGH=
4;LGraphTexture.REUSE=5;LGraphTexture.DEFAULT=2;LGraphTexture.MODE_VALUES={"pass through":LGraphTexture.PASS_THROUGH,copy:LGraphTexture.COPY,low:LGraphTexture.LOW,high:LGraphTexture.HIGH,reuse:LGraphTexture.REUSE,"default":LGraphTexture.DEFAULT};LGraphTexture.getTexturesContainer=function(){return gl.textures};LGraphTexture.loadTexture=function(a,b){b=b||{};var c=a;"http://"==c.substr(0,7)&&LiteGraph.proxy&&(c=LiteGraph.proxy+c.substr(7));return LGraphTexture.getTexturesContainer()[a]=GL.Texture.fromURL(c,
b)};LGraphTexture.getTexture=function(a){var b=this.getTexturesContainer();if(!b)throw"Cannot load texture, container of textures not found";b=b[a];return!b&&a&&":"!=a[0]?(this.loadTexture(a),null):b};LGraphTexture.getTargetTexture=function(a,b,c){if(!a)throw"LGraphTexture.getTargetTexture expects a reference texture";var d=null;switch(c){case LGraphTexture.LOW:d=gl.UNSIGNED_BYTE;break;case LGraphTexture.HIGH:d=gl.HIGH_PRECISION_FORMAT;break;case LGraphTexture.REUSE:return a;default:d=a?a.type:gl.UNSIGNED_BYTE}b&&
b.width==a.width&&b.height==a.height&&b.type==d||(b=new GL.Texture(a.width,a.height,{type:d,format:gl.RGBA,filter:gl.LINEAR}));return b};LGraphTexture.getNoiseTexture=function(){if(this._noise_texture)return this._noise_texture;for(var a=new Uint8Array(1048576),b=0;1048576>b;++b)a[b]=255*Math.random();return this._noise_texture=a=GL.Texture.fromMemory(512,512,a,{format:gl.RGBA,wrap:gl.REPEAT,filter:gl.NEAREST})};LGraphTexture.prototype.onDropFile=function(a,b,c){if(a){var d=null;"string"==typeof a?
d=GL.Texture.fromURL(a):-1!=b.toLowerCase().indexOf(".dds")?d=GL.Texture.fromDDSInMemory(a):(a=new Blob([c]),a=URL.createObjectURL(a),d=GL.Texture.fromURL(a));this._drop_texture=d;this.properties.name=b}else this._drop_texture=null,this.properties.name=""};LGraphTexture.prototype.getExtraMenuOptions=function(a){var b=this;if(this._drop_texture)return[{content:"Clear",callback:function(){b._drop_texture=null;b.properties.name=""}}]};LGraphTexture.prototype.onExecute=function(){var a=null;this.isOutputConnected(1)&&
(a=this.getInputData(0));!a&&this._drop_texture&&(a=this._drop_texture);!a&&this.properties.name&&(a=LGraphTexture.getTexture(this.properties.name));if(a){this._last_tex=a;!1===this.properties.filter?a.setParameter(gl.TEXTURE_MAG_FILTER,gl.NEAREST):a.setParameter(gl.TEXTURE_MAG_FILTER,gl.LINEAR);this.setOutputData(0,a);for(var b=1;b<this.outputs.length;b++){var c=this.outputs[b];if(c){var d=null;"width"==c.name?d=a.width:"height"==c.name?d=a.height:"aspect"==c.name&&(d=a.width/a.height);this.setOutputData(b,
d)}}}};LGraphTexture.prototype.onResourceRenamed=function(a,b){this.properties.name==a&&(this.properties.name=b)};LGraphTexture.prototype.onDrawBackground=function(a){if(!(this.flags.collapsed||20>=this.size[1]))if(this._drop_texture&&a.webgl)a.drawImage(this._drop_texture,0,0,this.size[0],this.size[1]);else{if(this._last_preview_tex!=this._last_tex)if(a.webgl)this._canvas=this._last_tex;else{var b=LGraphTexture.generateLowResTexturePreview(this._last_tex);if(!b)return;this._last_preview_tex=this._last_tex;
this._canvas=cloneCanvas(b)}this._canvas&&(a.save(),a.webgl||(a.translate(0,this.size[1]),a.scale(1,-1)),a.drawImage(this._canvas,0,0,this.size[0],this.size[1]),a.restore())}};LGraphTexture.generateLowResTexturePreview=function(a){if(!a)return null;var b=LGraphTexture.image_preview_size,c=a;if(a.format==gl.DEPTH_COMPONENT)return null;if(a.width>b||a.height>b)c=this._preview_temp_tex,this._preview_temp_tex||(this._preview_temp_tex=c=new GL.Texture(b,b,{minFilter:gl.NEAREST})),a.copyTo(c);a=this._preview_canvas;
a||(this._preview_canvas=a=createCanvas(b,b));c&&c.toCanvas(a);return a};LGraphTexture.prototype.onGetInputs=function(){return[["in","Texture"]]};LGraphTexture.prototype.onGetOutputs=function(){return[["width","number"],["height","number"],["aspect","number"]]};LiteGraph.registerNodeType("texture/texture",LGraphTexture);var LGraphTexturePreview=function(){this.addInput("Texture","Texture");this.properties={flipY:!1};this.size=[LGraphTexture.image_preview_size,LGraphTexture.image_preview_size]};LGraphTexturePreview.title=
"Preview";LGraphTexturePreview.desc="Show a texture in the graph canvas";LGraphTexturePreview.prototype.onDrawBackground=function(a){if(!this.flags.collapsed){var b=this.getInputData(0);if(b){var c=null,c=!b.handle&&a.webgl?b:LGraphTexture.generateLowResTexturePreview(b);a.save();this.properties.flipY&&(a.translate(0,this.size[1]),a.scale(1,-1));a.drawImage(c,0,0,this.size[0],this.size[1]);a.restore()}}};LiteGraph.registerNodeType("texture/preview",LGraphTexturePreview);var LGraphTextureSave=function(){this.addInput("Texture",
"Texture");this.addOutput("","Texture");this.properties={name:""}};LGraphTextureSave.title="Save";LGraphTextureSave.desc="Save a texture in the repository";LGraphTextureSave.prototype.onExecute=function(){var a=this.getInputData(0);a&&(this.properties.name&&(LGraphTexture.getTexturesContainer()[this.properties.name]=a),this.setOutputData(0,a))};LiteGraph.registerNodeType("texture/save",LGraphTextureSave);var LGraphTextureOperation=function(){this.addInput("Texture","Texture");this.addInput("TextureB",
"Texture");this.addInput("value","number");this.addOutput("Texture","Texture");this.help="<p>pixelcode must be vec3</p>\t\t\t<p>uvcode must be vec2, is optional</p>\t\t\t<p><strong>uv:</strong> tex. coords</p><p><strong>color:</strong> texture</p><p><strong>colorB:</strong> textureB</p><p><strong>time:</strong> scene time</p><p><strong>value:</strong> input value</p>";this.properties={value:1,uvcode:"",pixelcode:"color + colorB * value",precision:LGraphTexture.DEFAULT}};LGraphTextureOperation.widgets_info=
{uvcode:{widget:"textarea",height:100},pixelcode:{widget:"textarea",height:100},precision:{widget:"combo",values:LGraphTexture.MODE_VALUES}};LGraphTextureOperation.title="Operation";LGraphTextureOperation.desc="Texture shader operation";LGraphTextureOperation.prototype.getExtraMenuOptions=function(a){var b=this;return[{content:b.properties.show?"Hide Texture":"Show Texture",callback:function(){b.properties.show=!b.properties.show}}]};LGraphTextureOperation.prototype.onDrawBackground=function(a){this.flags.collapsed||
20>=this.size[1]||!this.properties.show||!this._tex||this._tex.gl!=a||(a.save(),a.drawImage(this._tex,0,0,this.size[0],this.size[1]),a.restore())};LGraphTextureOperation.prototype.onExecute=function(){var a=this.getInputData(0);if(this.isOutputConnected(0))if(this.properties.precision===LGraphTexture.PASS_THROUGH)this.setOutputData(0,a);else{var b=this.getInputData(1);if(this.properties.uvcode||this.properties.pixelcode){var c=512,d=512;a?(c=a.width,d=a.height):b&&(c=b.width,d=b.height);this._tex=
a||this._tex?LGraphTexture.getTargetTexture(a||this._tex,this._tex,this.properties.precision):new GL.Texture(c,d,{type:this.precision===LGraphTexture.LOW?gl.UNSIGNED_BYTE:gl.HIGH_PRECISION_FORMAT,format:gl.RGBA,filter:gl.LINEAR});var e="";this.properties.uvcode&&(e="uv = "+this.properties.uvcode,-1!=this.properties.uvcode.indexOf(";")&&(e=this.properties.uvcode));var f="";this.properties.pixelcode&&(f="result = "+this.properties.pixelcode,-1!=this.properties.pixelcode.indexOf(";")&&(f=this.properties.pixelcode));
var g=this._shader;if(!g||this._shader_code!=e+"|"+f){try{this._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,LGraphTextureOperation.pixel_shader,{UV_CODE:e,PIXEL_CODE:f}),this.boxcolor="#00FF00"}catch(h){console.log("Error compiling shader: ",h);this.boxcolor="#FF0000";return}this._shader_code=e+"|"+f;g=this._shader}if(g){this.boxcolor="green";var k=this.getInputData(2);null!=k?this.properties.value=k:k=parseFloat(this.properties.value);var l=this.graph.getTime();this._tex.drawTo(function(){gl.disable(gl.DEPTH_TEST);
gl.disable(gl.CULL_FACE);gl.disable(gl.BLEND);a&&a.bind(0);b&&b.bind(1);var e=Mesh.getScreenQuad();g.uniforms({u_texture:0,u_textureB:1,value:k,texSize:[c,d],time:l}).draw(e)});this.setOutputData(0,this._tex)}else this.boxcolor="red"}}};LGraphTextureOperation.pixel_shader="precision highp float;\n\t\t\t\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform sampler2D u_textureB;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform vec2 texSize;\n\t\t\tuniform float time;\n\t\t\tuniform float value;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec2 uv = v_coord;\n\t\t\t\tUV_CODE;\n\t\t\t\tvec3 color = texture2D(u_texture, uv).rgb;\n\t\t\t\tvec3 colorB = texture2D(u_textureB, uv).rgb;\n\t\t\t\tvec3 result = color;\n\t\t\t\tfloat alpha = 1.0;\n\t\t\t\tPIXEL_CODE;\n\t\t\t\tgl_FragColor = vec4(result, alpha);\n\t\t\t}\n\t\t\t";
LiteGraph.registerNodeType("texture/operation",LGraphTextureOperation);var LGraphTextureShader=function(){this.addOutput("Texture","Texture");this.properties={code:"",width:512,height:512};this.properties.code="\nvoid main() {\n vec2 uv = coord;\n vec3 color = vec3(0.0);\n//your code here\n\ngl_FragColor = vec4(color, 1.0);\n}\n"};LGraphTextureShader.title="Shader";LGraphTextureShader.desc="Texture shader";LGraphTextureShader.widgets_info={code:{type:"code"},precision:{widget:"combo",values:LGraphTexture.MODE_VALUES}};
LGraphTextureShader.prototype.onExecute=function(){if(this.isOutputConnected(0)){if(this._shader_code!=this.properties.code)if(this._shader_code=this.properties.code,this._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,LGraphTextureShader.pixel_shader+this.properties.code))this.boxcolor="green";else{this.boxcolor="red";return}this._tex&&this._tex.width==this.properties.width&&this._tex.height==this.properties.height||(this._tex=new GL.Texture(this.properties.width,this.properties.height,{format:gl.RGBA,
filter:gl.LINEAR}));var a=this._tex,b=this._shader,c=this.graph.getTime();a.drawTo(function(){b.uniforms({texSize:[a.width,a.height],time:c}).draw(Mesh.getScreenQuad())});this.setOutputData(0,this._tex)}};LGraphTextureShader.pixel_shader="precision highp float;\n\t\t\t\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform float time;\n\t\t\t";LiteGraph.registerNodeType("texture/shader",LGraphTextureShader);var LGraphTextureScaleOffset=function(){this.addInput("in","Texture");this.addInput("scale","vec2");this.addInput("offset",
@@ -304,8 +304,8 @@ LGraphFXLens.widgets_info={precision:{widget:"combo",values:LGraphTexture.MODE_V
LiteGraph.registerNodeType("fx/lens",LGraphFXLens);window.LGraphFXLens=LGraphFXLens;var LGraphFXBokeh=function(){this.addInput("Texture","Texture");this.addInput("Blurred","Texture");this.addInput("Mask","Texture");this.addInput("Threshold","number");this.addOutput("Texture","Texture");this.properties={shape:"",size:10,alpha:1,threshold:1,high_precision:!1}};LGraphFXBokeh.title="Bokeh";LGraphFXBokeh.desc="applies an Bokeh effect";LGraphFXBokeh.widgets_info={shape:{widget:"texture"}};LGraphFXBokeh.prototype.onExecute=
function(){var a=this.getInputData(0),b=this.getInputData(1),c=this.getInputData(2);if(a&&c&&this.properties.shape){b||(b=a);var d=LGraphTexture.getTexture(this.properties.shape);if(d){var e=this.properties.threshold;this.isInputConnected(3)&&(e=this.getInputData(3),this.properties.threshold=e);var f=gl.UNSIGNED_BYTE;this.properties.high_precision&&(f=gl.half_float_ext?gl.HALF_FLOAT_OES:gl.FLOAT);this._temp_texture&&this._temp_texture.type==f&&this._temp_texture.width==a.width&&this._temp_texture.height==
a.height||(this._temp_texture=new GL.Texture(a.width,a.height,{type:f,format:gl.RGBA,filter:gl.LINEAR}));var g=LGraphFXBokeh._first_shader;g||(g=LGraphFXBokeh._first_shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,LGraphFXBokeh._first_pixel_shader));var h=LGraphFXBokeh._second_shader;h||(h=LGraphFXBokeh._second_shader=new GL.Shader(LGraphFXBokeh._second_vertex_shader,LGraphFXBokeh._second_pixel_shader));var k=this._points_mesh;k&&k._width==a.width&&k._height==a.height&&2==k._spacing||(k=this.createPointsMesh(a.width,
a.height,2));var l=Mesh.getScreenQuad(),p=this.properties.size,q=this.properties.alpha;gl.disable(gl.DEPTH_TEST);gl.disable(gl.BLEND);this._temp_texture.drawTo(function(){a.bind(0);b.bind(1);c.bind(2);g.uniforms({u_texture:0,u_texture_blur:1,u_mask:2,u_texsize:[a.width,a.height]}).draw(l)});this._temp_texture.drawTo(function(){gl.enable(gl.BLEND);gl.blendFunc(gl.ONE,gl.ONE);a.bind(0);d.bind(3);h.uniforms({u_texture:0,u_mask:2,u_shape:3,u_alpha:q,u_threshold:e,u_pointSize:p,u_itexsize:[1/a.width,1/
a.height]}).draw(k,gl.POINTS)});this.setOutputData(0,this._temp_texture)}}else this.setOutputData(0,a)};LGraphFXBokeh.prototype.createPointsMesh=function(a,b,c){for(var d=Math.round(a/c),e=Math.round(b/c),f=new Float32Array(d*e*2),g=-1,h=2/a*c,k=2/b*c,l=0;l<e;++l){for(var p=-1,q=0;q<d;++q){var r=l*d*2+2*q;f[r]=p;f[r+1]=g;p+=h}g+=k}this._points_mesh=GL.Mesh.load({vertices2D:f});this._points_mesh._width=a;this._points_mesh._height=b;this._points_mesh._spacing=c;return this._points_mesh};LGraphFXBokeh._first_pixel_shader=
a.height,2));var l=Mesh.getScreenQuad(),n=this.properties.size,q=this.properties.alpha;gl.disable(gl.DEPTH_TEST);gl.disable(gl.BLEND);this._temp_texture.drawTo(function(){a.bind(0);b.bind(1);c.bind(2);g.uniforms({u_texture:0,u_texture_blur:1,u_mask:2,u_texsize:[a.width,a.height]}).draw(l)});this._temp_texture.drawTo(function(){gl.enable(gl.BLEND);gl.blendFunc(gl.ONE,gl.ONE);a.bind(0);d.bind(3);h.uniforms({u_texture:0,u_mask:2,u_shape:3,u_alpha:q,u_threshold:e,u_pointSize:n,u_itexsize:[1/a.width,1/
a.height]}).draw(k,gl.POINTS)});this.setOutputData(0,this._temp_texture)}}else this.setOutputData(0,a)};LGraphFXBokeh.prototype.createPointsMesh=function(a,b,c){for(var d=Math.round(a/c),e=Math.round(b/c),f=new Float32Array(d*e*2),g=-1,h=2/a*c,k=2/b*c,l=0;l<e;++l){for(var n=-1,q=0;q<d;++q){var r=l*d*2+2*q;f[r]=n;f[r+1]=g;n+=h}g+=k}this._points_mesh=GL.Mesh.load({vertices2D:f});this._points_mesh._width=a;this._points_mesh._height=b;this._points_mesh._spacing=c;return this._points_mesh};LGraphFXBokeh._first_pixel_shader=
"precision highp float;\n\t\t\tprecision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform sampler2D u_texture_blur;\n\t\t\tuniform sampler2D u_mask;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec4 color = texture2D(u_texture, v_coord);\n\t\t\t\tvec4 blurred_color = texture2D(u_texture_blur, v_coord);\n\t\t\t\tfloat mask = texture2D(u_mask, v_coord).x;\n\t\t\t gl_FragColor = mix(color, blurred_color, mask);\n\t\t\t}\n\t\t\t";LGraphFXBokeh._second_vertex_shader=
"precision highp float;\n\t\t\tattribute vec2 a_vertex2D;\n\t\t\tvarying vec4 v_color;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform sampler2D u_mask;\n\t\t\tuniform vec2 u_itexsize;\n\t\t\tuniform float u_pointSize;\n\t\t\tuniform float u_threshold;\n\t\t\tvoid main() {\n\t\t\t\tvec2 coord = a_vertex2D * 0.5 + 0.5;\n\t\t\t\tv_color = texture2D( u_texture, coord );\n\t\t\t\tv_color += texture2D( u_texture, coord + vec2(u_itexsize.x, 0.0) );\n\t\t\t\tv_color += texture2D( u_texture, coord + vec2(0.0, u_itexsize.y));\n\t\t\t\tv_color += texture2D( u_texture, coord + u_itexsize);\n\t\t\t\tv_color *= 0.25;\n\t\t\t\tfloat mask = texture2D(u_mask, coord).x;\n\t\t\t\tfloat luminance = length(v_color) * mask;\n\t\t\t\t/*luminance /= (u_pointSize*u_pointSize)*0.01 */;\n\t\t\t\tluminance -= u_threshold;\n\t\t\t\tif(luminance < 0.0)\n\t\t\t\t{\n\t\t\t\t\tgl_Position.x = -100.0;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tgl_PointSize = u_pointSize;\n\t\t\t\tgl_Position = vec4(a_vertex2D,0.0,1.0);\n\t\t\t}\n\t\t\t";
LGraphFXBokeh._second_pixel_shader="precision highp float;\n\t\t\tvarying vec4 v_color;\n\t\t\tuniform sampler2D u_shape;\n\t\t\tuniform float u_alpha;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec4 color = texture2D( u_shape, gl_PointCoord );\n\t\t\t\tcolor *= v_color * u_alpha;\n\t\t\t\tgl_FragColor = color;\n\t\t\t}\n";LiteGraph.registerNodeType("fx/bokeh",LGraphFXBokeh);window.LGraphFXBokeh=LGraphFXBokeh;var LGraphFXGeneric=function(){this.addInput("Texture","Texture");this.addInput("value1","number");

View File

@@ -32,8 +32,8 @@ var LiteGraph = {
debug: false,
throw_errors: true,
registered_node_types: {},
Nodes: {},
registered_node_types: {}, //nodetypes by string
Nodes: {}, //node types by classname
/**
* Register a node class so it can be listed when the user wants to create a new one
@@ -68,6 +68,19 @@ var LiteGraph = {
this.Nodes[ base_class.constructor.name ] = base_class;
},
/**
* Adds this method to all nodetypes, existing and to be created
* (You can add it to LGraphNode.prototype but then existing node types wont have it)
* @method addNodeMethod
* @param {Function} func
*/
addNodeMethod: function( name, func )
{
LGraphNode.prototype[name] = func;
for(var i in this.registered_node_types)
this.registered_node_types[i].prototype[name] = func;
},
/**
* Create a node of a given type with a name. The node is not attached to any graph yet.
* @method createNode
@@ -327,8 +340,12 @@ LGraph.prototype.attachCanvas = function(graphcanvas)
LGraph.prototype.detachCanvas = function(graphcanvas)
{
var pos = this.list_of_graphcanvas.indexOf(graphcanvas);
if(pos == -1) return;
if(!this.list_of_graphcanvas)
return;
var pos = this.list_of_graphcanvas.indexOf( graphcanvas );
if(pos == -1)
return;
graphcanvas.graph = null;
this.list_of_graphcanvas.splice(pos,1);
}
@@ -447,14 +464,14 @@ LGraph.prototype.computeExecutionOrder = function()
var remaining_links = {}; //to a
//search for the nodes without inputs (starting nodes)
for (var i in this._nodes)
for (var i = 0, l = this._nodes.length; i < l; ++i)
{
var n = this._nodes[i];
M[n.id] = n; //add to pending nodes
var num = 0; //num of input connections
if(n.inputs)
for(var j = 0, l = n.inputs.length; j < l; j++)
for(var j = 0, l2 = n.inputs.length; j < l2; j++)
if(n.inputs[j] && n.inputs[j].link != null)
num += 1;
@@ -567,17 +584,23 @@ LGraph.prototype.getElapsedTime = function()
LGraph.prototype.sendEventToAllNodes = function(eventname, params)
{
var M = this._nodes_in_order ? this._nodes_in_order : this._nodes;
for(var j in M)
if(M[j][eventname])
var nodes = this._nodes_in_order ? this._nodes_in_order : this._nodes;
if(!nodes)
return;
for( var j = 0, l = nodes.length; j < l; ++j )
{
var node = nodes[j];
if(node[eventname])
{
if(params === undefined)
M[j][eventname]();
node[eventname]();
else if(params && params.constructor === Array)
M[j][eventname].apply(M[j], params);
node[eventname].apply(M[j], params);
else
M[j][eventname](params);
node[eventname](params);
}
}
}
LGraph.prototype.sendActionToCanvas = function(action, params)
@@ -585,7 +608,7 @@ LGraph.prototype.sendActionToCanvas = function(action, params)
if(!this.list_of_graphcanvas)
return;
for(var i in this.list_of_graphcanvas)
for(var i = 0; i < this.list_of_graphcanvas.length; ++i)
{
var c = this.list_of_graphcanvas[i];
if( c[action] )
@@ -683,13 +706,16 @@ LGraph.prototype.remove = function(node)
node.graph = null;
//remove from canvas render
for(var i in this.list_of_graphcanvas)
if(this.list_of_graphcanvas)
{
var canvas = this.list_of_graphcanvas[i];
if(canvas.selected_nodes[node.id])
delete canvas.selected_nodes[node.id];
if(canvas.node_dragged == node)
canvas.node_dragged = null;
for(var i = 0; i < this.list_of_graphcanvas.length; ++i)
{
var canvas = this.list_of_graphcanvas[i];
if(canvas.selected_nodes[node.id])
delete canvas.selected_nodes[node.id];
if(canvas.node_dragged == node)
canvas.node_dragged = null;
}
}
//remove from containers
@@ -730,7 +756,7 @@ LGraph.prototype.getNodeById = function(id)
LGraph.prototype.findNodesByClass = function(classObject)
{
var r = [];
for(var i in this._nodes)
for(var i = 0, l = this._nodes.length; i < l; ++i)
if(this._nodes[i].constructor === classObject)
r.push(this._nodes[i]);
return r;
@@ -747,7 +773,7 @@ LGraph.prototype.findNodesByType = function(type)
{
var type = type.toLowerCase();
var r = [];
for(var i in this._nodes)
for(var i = 0, l = this._nodes.length; i < l; ++i)
if(this._nodes[i].type.toLowerCase() == type )
r.push(this._nodes[i]);
return r;
@@ -763,7 +789,7 @@ LGraph.prototype.findNodesByType = function(type)
LGraph.prototype.findNodesByTitle = function(title)
{
var result = [];
for (var i in this._nodes)
for(var i = 0, l = this._nodes.length; i < l; ++i)
if(this._nodes[i].title == title)
result.push(this._nodes[i]);
return result;
@@ -966,9 +992,9 @@ LGraph.prototype.removeGlobalOutput = function(name)
LGraph.prototype.setInputData = function(name,value)
{
var m = this.findNodesByName(name);
for(var i in m)
m[i].setValue(value);
var nodes = this.findNodesByName( name );
for(var i = 0, l = nodes.length; i < l; ++i)
nodes[i].setValue(value);
}
/**
@@ -990,22 +1016,25 @@ LGraph.prototype.getOutputData = function(name)
LGraph.prototype.triggerInput = function(name,value)
{
var m = this.findNodesByName(name);
for(var i in m)
m[i].onTrigger(value);
var nodes = this.findNodesByName(name);
for(var i = 0; i < nodes.length; ++i)
nodes[i].onTrigger(value);
}
LGraph.prototype.setCallback = function(name,func)
{
var m = this.findNodesByName(name);
for(var i in m)
m[i].setTrigger(func);
var nodes = this.findNodesByName(name);
for(var i = 0; i < nodes.length; ++i)
nodes[i].setTrigger(func);
}
LGraph.prototype.onConnectionChange = function()
LGraph.prototype.connectionChange = function( node )
{
this.updateExecutionOrder();
if( this.onConnectionChange )
this.onConnectionChange( node );
this.sendActionToCanvas("onConnectionChange");
}
/**
@@ -1015,10 +1044,14 @@ LGraph.prototype.onConnectionChange = function()
LGraph.prototype.isLive = function()
{
for(var i in this.list_of_graphcanvas)
if(!this.list_of_graphcanvas)
return false;
for(var i = 0; i < this.list_of_graphcanvas.length; ++i)
{
var c = this.list_of_graphcanvas[i];
if(c.live_mode) return true;
if(c.live_mode)
return true;
}
return false;
}
@@ -1049,11 +1082,11 @@ LGraph.prototype.setDirtyCanvas = function(fg,bg)
LGraph.prototype.serialize = function()
{
var nodes_info = [];
for (var i in this._nodes)
for(var i = 0, l = this._nodes.length; i < l; ++i)
nodes_info.push( this._nodes[i].serialize() );
//remove data from links, we dont want to store it
for (var i in this.links)
for(var i in this.links) //links is an OBJECT
this.links[i].data = null;
@@ -1094,7 +1127,7 @@ LGraph.prototype.configure = function(data, keep_old)
//create nodes
this._nodes = [];
for (var i in nodes)
for(var i = 0, l = nodes.length; i < l; ++i)
{
var n_info = nodes[i]; //stored info
var node = LiteGraph.createNode( n_info.type, n_info.title );
@@ -1503,7 +1536,7 @@ LGraphNode.prototype.addOutput = function(name,type,extra_info)
*/
LGraphNode.prototype.addOutputs = function(array)
{
for(var i in array)
for(var i = 0; i < array.length; ++i)
{
var info = array[i];
var o = {name:info[0],type:info[1],link:null};
@@ -1565,7 +1598,7 @@ LGraphNode.prototype.addInput = function(name,type,extra_info)
*/
LGraphNode.prototype.addInputs = function(array)
{
for(var i in array)
for(var i = 0; i < array.length; ++i)
{
var info = array[i];
var o = {name:info[0], type:info[1], link:null};
@@ -1817,8 +1850,9 @@ LGraphNode.prototype.connect = function(slot, node, target_slot)
if(target_slot != -1 && node.inputs[target_slot].link != null)
node.disconnectInput(target_slot);
//why here??
this.setDirtyCanvas(false,true);
this.graph.onConnectionChange();
this.graph.connectionChange( this );
//special case: -1 means node-connection, used for triggers
var output = this.outputs[slot];
@@ -1849,6 +1883,10 @@ LGraphNode.prototype.connect = function(slot, node, target_slot)
node.inputs[target_slot].link = link.id;
}
this.setDirtyCanvas(false,true);
this.graph.connectionChange( this );
return true;
}
@@ -1922,7 +1960,7 @@ LGraphNode.prototype.disconnectOutput = function(slot, target_node)
}
this.setDirtyCanvas(false,true);
this.graph.onConnectionChange();
this.graph.connectionChange( this );
return true;
}
@@ -1984,7 +2022,7 @@ LGraphNode.prototype.disconnectInput = function(slot)
}
this.setDirtyCanvas(false,true);
this.graph.onConnectionChange();
this.graph.connectionChange( this );
return true;
}
@@ -2108,7 +2146,7 @@ LGraphNode.prototype.captureInput = function(v)
var list = this.graph.list_of_graphcanvas;
for(var i in list)
for(var i = 0; i < list.length; ++i)
{
var c = list[i];
//releasing somebody elses capture?!
@@ -2160,14 +2198,18 @@ LGraphNode.prototype.localToScreen = function(x,y, graphcanvas)
/**
* The Global Scope. It contains all the registered node classes.
* Valid callbacks are: onNodeSelected, onNodeDeselected, onShowNodePanel, onNodeDblClicked
*
* @class LGraphCanvas
* @constructor
* @param {HTMLCanvas} canvas the canvas where you want to render (it accepts a selector in string format or the canvas itself)
* @param {LGraph} graph [optional]
* @param {Object} options [optional] { skip_rendering, autoresize }
*/
function LGraphCanvas( canvas, graph, skip_render )
function LGraphCanvas( canvas, graph, options )
{
options = options || {};
//if(graph === undefined)
// throw ("No graph assigned");
@@ -2184,8 +2226,10 @@ function LGraphCanvas( canvas, graph, skip_render )
this.setCanvas( canvas );
this.clear();
if(!skip_render)
if(!options.skip_render)
this.startRendering();
this.autoresize = options.autoresize;
}
LGraphCanvas.link_type_colors = {'number':"#AAC",'node':"#DCA"};
@@ -2790,12 +2834,20 @@ LGraphCanvas.prototype.processMouseDown = function(e)
if(!ref_window.document.activeElement || (ref_window.document.activeElement.nodeName.toLowerCase() != "input" && ref_window.document.activeElement.nodeName.toLowerCase() != "textarea"))
e.preventDefault();
e.stopPropagation();
if(this.onMouseDown)
this.onMouseDown(e);
return false;
}
LGraphCanvas.prototype.processMouseMove = function(e)
{
if(!this.graph) return;
if(this.autoresize)
this.resize();
if(!this.graph)
return;
this.adjustMouseEvent(e);
var mouse = [e.localX, e.localY];
@@ -2819,7 +2871,7 @@ LGraphCanvas.prototype.processMouseMove = function(e)
var n = this.graph.getNodeOnPos(e.canvasX, e.canvasY, this.visible_nodes);
//remove mouseover flag
for(var i in this.graph._nodes)
for(var i = 0, l = this.graph._nodes.length; i < l; ++i)
{
if(this.graph._nodes[i].mouseOver && n != this.graph._nodes[i])
{
@@ -3258,7 +3310,7 @@ LGraphCanvas.prototype.selectNode = function(node)
LGraphCanvas.prototype.selectAllNodes = function()
{
for(var i in this.graph._nodes)
for(var i = 0; i < this.graph._nodes.length; ++i)
{
var n = this.graph._nodes[i];
if(!n.selected && n.onSelected)
@@ -3380,7 +3432,7 @@ LGraphCanvas.prototype.sendToBack = function(n)
LGraphCanvas.prototype.computeVisibleNodes = function()
{
var visible_nodes = [];
for (var i in this.graph._nodes)
for(var i = 0, l = this.graph._nodes.length; i < l; ++i)
{
var n = this.graph._nodes[i];
@@ -3477,7 +3529,7 @@ LGraphCanvas.prototype.drawFrontCanvas = function()
var visible_nodes = this.computeVisibleNodes();
this.visible_nodes = visible_nodes;
for (var i in visible_nodes)
for (var i = 0; i < visible_nodes.length; ++i)
{
var node = visible_nodes[i];
@@ -3563,6 +3615,13 @@ LGraphCanvas.prototype.renderInfo = function( ctx, x, y )
LGraphCanvas.prototype.drawBackCanvas = function()
{
var canvas = this.bgcanvas;
if(canvas.width != this.canvas.width ||
canvas.height != this.canvas.height)
{
canvas.width = this.canvas.width;
canvas.height = this.canvas.height;
}
if(!this.bgctx)
this.bgctx = this.bgcanvas.getContext("2d");
var ctx = this.bgctx;
@@ -4027,12 +4086,12 @@ LGraphCanvas.prototype.drawConnections = function(ctx)
ctx.strokeStyle = "#AAA";
ctx.globalAlpha = this.editor_alpha;
//for every node
for (var n in this.graph._nodes)
for (var n = 0, l = this.graph._nodes.length; n < l; ++n)
{
var node = this.graph._nodes[n];
//for every input (we render just inputs because it is easier as every slot can only have one input)
if(node.inputs && node.inputs.length)
for(var i in node.inputs)
for(var i = 0; i < node.inputs.length; ++i)
{
var input = node.inputs[i];
if(!input || input.link == null)

View File

@@ -4,13 +4,13 @@ if(typeof(LiteGraph) != "undefined")
function LGraphTexture()
{
this.addOutput("Texture","Texture");
this.properties = {name:""};
this.properties = { name:"", filter: true };
this.size = [LGraphTexture.image_preview_size, LGraphTexture.image_preview_size];
}
LGraphTexture.title = "Texture";
LGraphTexture.desc = "Texture";
LGraphTexture.widgets_info = {"name": { widget:"texture"} };
LGraphTexture.widgets_info = {"name": { widget:"texture"}, "filter": { widget:"checkbox"} };
//REPLACE THIS TO INTEGRATE WITH YOUR FRAMEWORK
LGraphTexture.loadTextureCallback = null; //function in charge of loading textures when not present in the container
@@ -164,6 +164,12 @@ if(typeof(LiteGraph) != "undefined")
return;
this._last_tex = tex;
if(this.properties.filter === false)
tex.setParameter( gl.TEXTURE_MAG_FILTER, gl.NEAREST );
else
tex.setParameter( gl.TEXTURE_MAG_FILTER, gl.LINEAR );
this.setOutputData(0, tex);
for(var i = 1; i < this.outputs.length; i++)