fixes in serialization

This commit is contained in:
tamat
2016-11-23 11:34:52 +01:00
parent 85ea3e9cdc
commit e287521410
5 changed files with 425 additions and 405 deletions

View File

@@ -1,5 +1,5 @@
//packer version
(function(global){
// *************************************************************
// LiteGraph CLASS *******
// *************************************************************
@@ -11,7 +11,7 @@
* @constructor
*/
var LiteGraph = {
var LiteGraph = global.LiteGraph = {
NODE_TITLE_HEIGHT: 16,
NODE_SLOT_HEIGHT: 15,
@@ -101,7 +101,12 @@ var LiteGraph = {
{
LGraphNode.prototype[name] = func;
for(var i in this.registered_node_types)
this.registered_node_types[i].prototype[name] = func;
{
var type = this.registered_node_types[i];
if(type.prototype[name])
type.prototype["_" + name] = type.prototype[name]; //keep old in case of replacing
type.prototype[name] = func;
}
},
/**
@@ -286,7 +291,7 @@ else
* @constructor
*/
function LGraph()
global.LGraph = LiteGraph.LGraph = function LGraph()
{
if (LiteGraph.debug)
console.log("Graph created");
@@ -1284,7 +1289,7 @@ LGraph.prototype.onNodeTrace = function(node, msg, color)
* @param {String} name a name for the node
*/
function LGraphNode(title)
global.LGraphNode = LiteGraph.LGraphNode = function LGraphNode(title)
{
this._ctor();
}
@@ -1415,8 +1420,8 @@ LGraphNode.prototype.configure = function(info)
}
}
if( this.onConfigured )
this.onConfigured( info );
if( this.onConfigure )
this.onConfigure( info );
}
/**
@@ -1539,6 +1544,7 @@ LGraphNode.prototype.setOutputData = function(slot,data)
* retrieves the input data (data traveling through the connection) from one slot
* @method getInputData
* @param {number} slot
* @param {boolean} force_update if set to true it will force the connected node of this slot to output data into this link
* @return {*} data or if it is not connected returns undefined
*/
LGraphNode.prototype.getInputData = function( slot, force_update )
@@ -1552,6 +1558,7 @@ LGraphNode.prototype.getInputData = function( slot, force_update )
var link_id = this.inputs[slot].link;
var link = this.graph.links[ link_id ];
//used to extract data from the incomming connection
if(!force_update)
return link.data;
@@ -2484,7 +2491,7 @@ LGraphNode.prototype.localToScreen = function(x,y, graphcanvas)
* @param {LGraph} graph [optional]
* @param {Object} options [optional] { skip_rendering, autoresize }
*/
function LGraphCanvas( canvas, graph, options )
global.LGraphCanvas = LiteGraph.LGraphCanvas = function LGraphCanvas( canvas, graph, options )
{
options = options || {};
@@ -5318,6 +5325,7 @@ LGraphCanvas.prototype.processContextMenu = function(node, event)
//API *************************************************
//function roundRect(ctx, x, y, width, height, radius, radius_low) {
if(this.CanvasRenderingContext2D)
CanvasRenderingContext2D.prototype.roundRect = function (x, y, width, height, radius, radius_low) {
if ( radius === undefined ) {
radius = 5;
@@ -5346,27 +5354,31 @@ function compareObjects(a,b)
return false;
return true;
}
LiteGraph.compareObjects = compareObjects;
function distance(a,b)
{
return Math.sqrt( (b[0] - a[0]) * (b[0] - a[0]) + (b[1] - a[1]) * (b[1] - a[1]) );
}
LiteGraph.distance = distance;
function colorToString(c)
{
return "rgba(" + Math.round(c[0] * 255).toFixed() + "," + Math.round(c[1] * 255).toFixed() + "," + Math.round(c[2] * 255).toFixed() + "," + (c.length == 4 ? c[3].toFixed(2) : "1.0") + ")";
}
LiteGraph.colorToString = colorToString;
function isInsideRectangle(x,y, left, top, width, height)
function isInsideRectangle( x,y, left, top, width, height)
{
if (left < x && (left + width) > x &&
top < y && (top + height) > y)
return true;
return false;
}
LiteGraph.isInsideRectangle = isInsideRectangle;
//[minx,miny,maxx,maxy]
function growBounding(bounding, x,y)
function growBounding( bounding, x,y)
{
if(x < bounding[0])
bounding[0] = x;
@@ -5378,6 +5390,7 @@ function growBounding(bounding, x,y)
else if(y > bounding[3])
bounding[3] = y;
}
LiteGraph.growBounding = growBounding;
//point inside boundin box
function isInsideBounding(p,bb)
@@ -5389,6 +5402,7 @@ function isInsideBounding(p,bb)
return false;
return true;
}
LiteGraph.isInsideBounding = isInsideBounding;
//boundings overlap, format: [start,end]
function overlapBounding(a,b)
@@ -5400,6 +5414,7 @@ function overlapBounding(a,b)
return false;
return true;
}
LiteGraph.overlapBounding = overlapBounding;
//Convert a hex value to its decimal value - the inputted hex must be in the
// format of a hex triplet - the kind we use for HTML colours. The function
@@ -5419,6 +5434,9 @@ function hex2num(hex) {
}
return(value);
}
LiteGraph.hex2num = hex2num;
//Give a array with three values as the argument and the function will return
// the corresponding hex triplet.
function num2hex(triplet) {
@@ -5434,6 +5452,8 @@ function num2hex(triplet) {
return(hex);
}
LiteGraph.num2hex = num2hex;
/* LiteGraph GUI elements *************************************/
LiteGraph.createContextMenu = function(values, options, ref_window)
@@ -5663,7 +5683,7 @@ LiteGraph.createNodetypeWrapper = function( class_object )
//LiteGraph.registerNodeType("scene/global", LGraphGlobal );
*/
if( !window["requestAnimationFrame"] )
if(typeof(window) !== undefined && !window["requestAnimationFrame"] )
{
window.requestAnimationFrame = window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
@@ -5672,7 +5692,7 @@ if( !window["requestAnimationFrame"] )
});
}
})(this);
//basic nodes
(function(){
@@ -6287,7 +6307,7 @@ LiteGraph.registerNodeType("events/delay", DelayEvent );
{
this.setOutputData(0, this.properties["value"] );
this.boxcolor = colorToString([this.value,this.value,this.value]);
this.boxcolor = LiteGraph.colorToString([this.value,this.value,this.value]);
}
WidgetKnob.prototype.onMouseDown = function(e)
@@ -6299,7 +6319,7 @@ LiteGraph.registerNodeType("events/delay", DelayEvent );
this.center = [this.size[0] * 0.5, this.size[1] * 0.5 + 20];
this.radius = this.size[0] * 0.5;
if(e.canvasY - this.pos[1] < 20 || distance([e.canvasX,e.canvasY],[this.pos[0] + this.center[0],this.pos[1] + this.center[1]]) > this.radius)
if(e.canvasY - this.pos[1] < 20 || LiteGraph.distance([e.canvasX,e.canvasY],[this.pos[0] + this.center[0],this.pos[1] + this.center[1]]) > this.radius)
return false;
this.oldmouse = [ e.canvasX - this.pos[0], e.canvasY - this.pos[1] ];
@@ -6442,7 +6462,7 @@ LiteGraph.registerNodeType("events/delay", DelayEvent );
{
this.properties["value"] = this.properties["min"] + (this.properties["max"] - this.properties["min"]) * this.value;
this.setOutputData(0, this.properties["value"] );
this.boxcolor = colorToString([this.value,this.value,this.value]);
this.boxcolor = LiteGraph.colorToString([this.value,this.value,this.value]);
}
WidgetHSlider.prototype.onMouseDown = function(e)
@@ -8929,10 +8949,7 @@ if(typeof(LiteGraph) != "undefined")
var tex = container[ name ];
if(!tex && name && name[0] != ":")
{
this.loadTexture(name);
return null;
}
return this.loadTexture(name);
return tex;
}
@@ -9145,6 +9162,12 @@ if(typeof(LiteGraph) != "undefined")
return tex_canvas;
}
LGraphTexture.prototype.getResources = function(res)
{
res[ this.properties.name ] = GL.Texture;
return res;
}
LGraphTexture.prototype.onGetInputs = function()
{
return [["in","Texture"]];

710
build/litegraph.min.js vendored
View File

@@ -1,396 +1,372 @@
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:"",INPUT:1,OUTPUT:2,EVENT:-1,ACTION:-1,ALWAYS:0,ON_EVENT:1,NEVER:2,proxy:null,debug:!1,throw_errors:!0,registered_node_types:{},node_types_by_file_extension:{},
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);b.prototype.onPropertyChange&&console.warn("LiteGraph node class "+
a+" has onPropertyChange method, it must be called onPropertyChanged with d at the end");if(b.supported_extensions)for(d in b.supported_extensions)this.node_types_by_file_extension[b.supported_extensions[d].toLowerCase()]=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.properties_info||(d.properties_info=[]);d.flags||(d.flags={});d.size||(d.size=d.computeSize());d.pos||(d.pos=LiteGraph.DEFAULT_POSITION.concat());d.mode||(d.mode=LiteGraph.ALWAYS);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},isValidConnection:function(a,b){return!a||!b||a==a||a!==LiteGraph.EVENT&&b!==LiteGraph.EVENT&&a.toLowerCase()==b.toLowerCase()?!0:!1}};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){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);var c=this._nodes_in_order?this._nodes_in_order:this._nodes;if(c){try{for(var d=0;d<a;d++){for(var e=0,f=c.length;e<f;++e){var g=c[e];if(g.mode==LiteGraph.ALWAYS&&g.onExecute)g.onExecute()}this.fixedtime+=this.fixedtime_lapse;if(this.onExecuteStep)this.onExecuteStep()}if(this.onAfterExecute)this.onAfterExecute();this.errors_in_execution=!1}catch(h){this.errors_in_execution=!0;if(LiteGraph.throw_errors)throw h;
LiteGraph.debug&&console.log("Error during execution: "+h);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(){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 n=0,l=h.inputs.length;n<l;n++)h.inputs[n]&&null!=h.inputs[n].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(n=0;n<g.links.length;n++)(k=this.links[g.links[n]])&&!d[k.id]&&
(l=this.getNodeById(k.target_id),null==l?d[k.id]=!0:(d[k.id]=!0,e[l.id]-=1,0==e[l.id]&&b.push(l)));for(f in c)a.push(c[f]);a.length!=this._nodes.length&&LiteGraph.debug&&console.warn("something went wrong, nodes missing");for(f=0;f<a.length;++f)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,c){c=c||LiteGraph.ALWAYS;var d=this._nodes_in_order?this._nodes_in_order:this._nodes;if(d)for(var e=0,f=d.length;e<f;++e){var g=d[e];if(g[a]&&g.mode==c)if(void 0===b)g[a]();else if(b&&b.constructor===Array)g[a].apply(g,b);else g[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);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);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){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)c=this.links[b],c.data=null,delete c._last_time;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)):(LiteGraph.debug&&console.log("Node not found: "+g.type),e=!0)}d=0;for(f=c.length;d<f;++d)g=c[d],(h=this.getNodeById(g.id))&&h.configure(g);this.updateExecutionOrder();this.setDirtyCanvas(!0,!0);return e};
LGraph.prototype.load=function(a){var b=this,c=new XMLHttpRequest;c.open("GET",a,!0);c.send(null);c.onload=function(a){200!==c.status?console.error("Error loading graph:",c.status,c.response):(a=JSON.parse(c.response),b.configure(a))};c.onerror=function(a){console.error("Error loading graph:",a)}};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.properties_info=[];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){if(this.properties[c]=a.properties[c],this.onPropertyChanged)this.onPropertyChanged(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]);if(this.onConnectionsChange){if(this.inputs)for(var d=0;d<this.inputs.length;++d){c=this.inputs[d];var e=this.graph.links[c.link];
this.onConnectionsChange(LiteGraph.INPUT,d,!0,e)}if(this.outputs)for(d=0;d<this.outputs.length;++d)for(c=this.outputs[d],b=0;b<c.links.length;++b)e=this.graph.links[c.links[b]],this.onConnectionsChange(LiteGraph.OUTPUT,d,!0,e)}for(d in this.inputs)c=this.inputs[d],c.link&&c.link.length&&(e=c.link,"object"==typeof e&&(c.link=e[0],this.graph.links[e[0]]={id:e[0],origin_id:e[1],origin_slot:e[2],target_id:e[3],target_slot:e[4]}));for(d in this.outputs)if(c=this.outputs[d],c.links&&0!=c.links.length)for(b in c.links)e=
c.links[b],"object"==typeof e&&(c.links[b]=e[0]);if(this.onConfigured)this.onConfigured(a)};
LGraphNode.prototype.serialize=function(){var a={id:this.id,title:this.title,type:this.type,pos:this.pos,size:this.size,data:this.data,flags:LiteGraph.cloneObject(this.flags),inputs:this.inputs,outputs:this.outputs,mode:this.mode};this.properties&&(a.properties=LiteGraph.cloneObject(this.properties));a.type||(a.type=this.constructor.type);this.color&&(a.color=this.color);this.bgcolor&&(a.bgcolor=this.bgcolor);this.boxcolor&&(a.boxcolor=this.boxcolor);this.shape&&(a.shape=this.shape);if(this.onSerialize)this.onSerialize(a);
return a};LGraphNode.prototype.clone=function(){var a=LiteGraph.createNode(this.type),b=LiteGraph.cloneObject(this.serialize());if(b.inputs)for(var c=0;c<b.inputs.length;++c)b.inputs[c].link=null;if(b.outputs)for(c=0;c<b.outputs.length;++c)b.outputs[c].links&&(b.outputs[c].links.length=0);delete b.id;a.configure(b);return a};LGraphNode.prototype.toString=function(){return JSON.stringify(this.serialize())};LGraphNode.prototype.getTitle=function(){return this.title||this.constructor.title};
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,b){if(this.inputs&&!(a>=this.inputs.length||null==this.inputs[a].link)){var c=this.graph.links[this.inputs[a].link];if(!b)return c.data;var d=this.graph.getNodeById(c.origin_id);if(!d)return c.data;if(d.updateOutputData)d.updateOutputData(c.origin_slot);else if(d.onExecute)d.onExecute();return c.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.getInputNode=function(a){if(!this.inputs||a>=this.inputs.length)return null;a=this.inputs[a];return a&&a.link?(a=this.graph.links[a.link])?this.graph.getNodeById(a.origin_id):null:null};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.trigger=function(a,b){if(this.outputs&&this.outputs.length){this.graph&&(this.graph._last_trigger_time=LiteGraph.getTime());for(var c=0;c<this.outputs.length;++c){var d=this.outputs[c];if(!(d.type!==LiteGraph.EVENT||a&&d.name!=a)&&(d=d.links)&&d.length)for(var e=0;e<d.length;++e){var f=this.graph.links[d[e]];if(f){var g=this.graph.getNodeById(f.target_id);if(g)if(f._last_time=LiteGraph.getTime(),f=g.inputs[f.target_slot],g.onAction)g.onAction(f.name,b);else if(g.mode===LiteGraph.ON_TRIGGER&&
g.onExecute)g.onExecute(b)}}}}};LGraphNode.prototype.addProperty=function(a,b,c,d){c={name:a,type:c,default_value:b};if(d)for(var e in d)c[e]=d[e];this.properties_info||(this.properties_info=[]);this.properties_info.push(c);this.properties||(this.properties={});this.properties[a]=b;return c};
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();return a};
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);return 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){a={name:a,type:b,pos:c,direction:d,links:null};this.connections.push(a);return a};
LGraphNode.prototype.computeSize=function(a,b){function c(a){return a?f*a.length*0.6:0}var d=Math.max(this.inputs?this.inputs.length:1,this.outputs?this.outputs.length:1),e=b||new Float32Array([0,0]),d=Math.max(d,1);e[1]=14*d+6;var f=14,d=c(this.title),g=0,h=0;if(this.inputs)for(var k=0,n=this.inputs.length;k<n;++k){var l=this.inputs[k],l=l.label||l.name||"",l=c(l);g<l&&(g=l)}if(this.outputs)for(k=0,n=this.outputs.length;k<n;++k)l=this.outputs[k],l=l.label||l.name||"",l=c(l),h<l&&(h=l);e[0]=Math.max(g+
h+10,d);e[0]=Math.max(e[0],LiteGraph.NODE_WIDTH);return e};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])};
LGraphNode.prototype.isPointInsideNode=function(a,b,c){c=c||0;var d=this.graph&&this.graph.isLive()?0:20;if(this.flags.collapsed){if(isInsideRectangle(a,b,this.pos[0]-c,this.pos[1]-LiteGraph.NODE_TITLE_HEIGHT-c,LiteGraph.NODE_COLLAPSED_WIDTH+2*c,LiteGraph.NODE_TITLE_HEIGHT+2*c))return!0}else if(this.pos[0]-4-c<a&&this.pos[0]+this.size[0]+4+c>a&&this.pos[1]-d-c<b&&this.pos[1]+this.size[1]+c>b)return!0;return!1};
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(c===LiteGraph.EVENT)return!1;if(!b.inputs||c>=b.inputs.length)return LiteGraph.debug&&console.log("Connect: Error, slot number not found"),!1}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;if(LiteGraph.isValidConnection(d.type,b.inputs[c].type)){var e={id:this.graph.last_link_id++,origin_id:this.id,
origin_slot:a,target_id:b.id,target_slot:c};this.graph.links[e.id]=e;null==d.links&&(d.links=[]);d.links.push(e.id);b.inputs[c].link=e.id;if(this.onConnectionsChange)this.onConnectionsChange(LiteGraph.OUTPUT,a,!0,e);if(b.onConnectionsChange)b.onConnectionsChange(LiteGraph.INPUT,c,!0,e)}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];if(b.onConnectionsChange)b.onConnectionsChange(LiteGraph.INPUT,g.target_slot,!1,g);if(this.onConnectionsChange)this.onConnectionsChange(LiteGraph.OUTPUT,a,!1,g);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];if(b.onConnectionsChange)b.onConnectionsChange(LiteGraph.INPUT,
g.target_slot,!1,g);if(this.onConnectionsChange)this.onConnectionsChange(LiteGraph.OUTPUT,a,!1,g)}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]){var c=this.graph.getNodeById(b.origin_id);if(!c)return!1;var d=c.outputs[b.origin_slot];
if(!d||!d.links||0==d.links.length)return!1;for(var e=0,f=d.links.length;e<f;e++)if(b=d.links[e],b=this.graph.links[b],b.target_id==this.id){d.links.splice(e,1);break}if(this.onConnectionsChange)this.onConnectionsChange(LiteGraph.INPUT,a,!1,b);if(c.onConnectionsChange)c.onConnectionsChange(LiteGraph.OUTPUT,e,!1,b)}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.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;this.title_text_font="bold 14px Arial";this.inner_text_font="normal 12px Arial";this.default_link_color="#AAC";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.allow_dragnodes=this.allow_dragcanvas=this.show_info=!0;this.render_connections_shadows=this.always_render_background=
!1;this.render_connection_arrows=this.render_curved_connections=this.render_connections_border=!0;this.connections_width=4;b&&b.attachCanvas(this);this.setCanvas(a);this.clear();c.skip_render||this.startRendering();this.autoresize=c.autoresize}LGraphCanvas.link_type_colors={"-1":"#F85",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.dirty_bgcanvas=this.dirty_canvas=!0;this.node_in_panel=this.dirty_area=null;this.last_mouse=[0,0];this.last_mouseclick=0;if(this.onClear)this.onClear()};
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))};
LGraphCanvas.prototype.setCanvas=function(a,b){if(a&&a.constructor===String&&(a=document.getElementById(a),!a))throw"Error creating LiteGraph canvas: Canvas not found";if(a!==this.canvas&&(!a&&this.canvas&&(b||this.unbindEvents()),this.canvas=a)){a.className+=" lgraphcanvas";a.data=this;this.bgcanvas=null;this.bgcanvas||(this.bgcanvas=document.createElement("canvas"),this.bgcanvas.width=this.canvas.width,this.bgcanvas.height=this.canvas.height);if(null==a.getContext)throw"This browser doesnt support Canvas";
null==(this.ctx=a.getContext("2d"))&&(console.warn("This canvas seems to be WebGL, enabling WebGL renderer"),this.enableWebGL());this._mousemove_callback=this.processMouseMove.bind(this);this._mouseup_callback=this.processMouseUp.bind(this);b||this.bindEvents()}};LGraphCanvas.prototype._doNothing=function(a){a.preventDefault();return!1};LGraphCanvas.prototype._doReturnTrue=function(a){a.preventDefault();return!0};
LGraphCanvas.prototype.bindEvents=function(){if(this._events_binded)console.warn("LGraphCanvas: events already binded");else{var a=this.canvas;this._mousedown_callback=this.processMouseDown.bind(this);this._mousewheel_callback=this.processMouseWheel.bind(this);a.addEventListener("mousedown",this._mousedown_callback,!0);a.addEventListener("mousemove",this._mousemove_callback);a.addEventListener("mousewheel",this._mousewheel_callback,!1);a.addEventListener("contextmenu",this._doNothing);a.addEventListener("DOMMouseScroll",
this._mousewheel_callback,!1);a.addEventListener("touchstart",this.touchHandler,!0);a.addEventListener("touchmove",this.touchHandler,!0);a.addEventListener("touchend",this.touchHandler,!0);a.addEventListener("touchcancel",this.touchHandler,!0);this._key_callback=this.processKey.bind(this);a.addEventListener("keydown",this._key_callback);a.addEventListener("keyup",this._key_callback);this._ondrop_callback=this.processDrop.bind(this);a.addEventListener("dragover",this._doNothing,!1);a.addEventListener("dragend",
this._doNothing,!1);a.addEventListener("drop",this._ondrop_callback,!1);a.addEventListener("dragenter",this._doReturnTrue,!1);this._events_binded=!0}};
LGraphCanvas.prototype.unbindEvents=function(){this._events_binded?(this.canvas.removeEventListener("mousedown",this._mousedown_callback),this.canvas.removeEventListener("mousewheel",this._mousewheel_callback),this.canvas.removeEventListener("DOMMouseScroll",this._mousewheel_callback),this.canvas.removeEventListener("keydown",this._key_callback),this.canvas.removeEventListener("keyup",this._key_callback),this.canvas.removeEventListener("contextmenu",this._doNothing),this.canvas.removeEventListener("drop",
this._ondrop_callback),this.canvas.removeEventListener("dragenter",this._doReturnTrue),this.canvas.removeEventListener("touchstart",this.touchHandler),this.canvas.removeEventListener("touchmove",this.touchHandler),this.canvas.removeEventListener("touchend",this.touchHandler),this.canvas.removeEventListener("touchcancel",this.touchHandler),this._ondrop_callback=this._key_callback=this._mousewheel_callback=this._mousedown_callback=null,this._events_binded=!1):console.warn("LGraphCanvas: no events binded")};
LGraphCanvas.getFileExtension=function(a){var b=a.indexOf("?");-1!=b&&(a=a.substr(0,b));b=a.lastIndexOf(".");return-1==b?"":a.substr(b+1).toLowerCase()};LGraphCanvas.prototype.enableWebGL=function(){if(void 0===typeof GL)throw"litegl.js must be included to use a WebGL canvas";if(void 0===typeof enableWebGLCanvas)throw"webglCanvas.js must be included to use this feature";this.gl=this.ctx=enableWebGLCanvas(this.canvas);this.ctx.webgl=!0;this.bgcanvas=this.canvas;this.bgctx=this.gl};
LGraphCanvas.prototype.setDirty=function(a,b){a&&(this.dirty_canvas=!0);b&&(this.dirty_bgcanvas=!0)};LGraphCanvas.prototype.getCanvasWindow=function(){if(!this.canvas)return window;var a=this.canvas.ownerDocument;return a.defaultView||a.parentWindow};LGraphCanvas.prototype.startRendering=function(){function a(){this.pause_rendering||this.draw();var b=this.getCanvasWindow();this.is_rendering&&b.requestAnimationFrame(a.bind(this))}this.is_rendering||(this.is_rendering=!0,a.call(this))};
LGraphCanvas.prototype.stopRendering=function(){this.is_rendering=!1};
LGraphCanvas.prototype.processMouseDown=function(a){if(this.graph){this.adjustMouseEvent(a);var b=this.getCanvasWindow();this.canvas.removeEventListener("mousemove",this._mousemove_callback);b.document.addEventListener("mousemove",this._mousemove_callback,!0);b.document.addEventListener("mouseup",this._mouseup_callback,!0);var c=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes);LiteGraph.closeAllContextMenus(b);if(1==a.which){if(!(a.shiftKey||c&&this.selected_nodes[c.id])){var d=[],
e;for(e in this.selected_nodes)this.selected_nodes[e]!=c&&d.push(this.selected_nodes[e]);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,[a.canvasX-c.pos[0],a.canvasY-c.pos[1]])?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.processContextMenu(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();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&&(e=this._highlight_input||[0,0],!this.isOverNodeBox(b,a.canvasX,a.canvasY))){var f=
this.isOverNodeInput(b,a.canvasX,a.canvasY,e);-1!=f&&b.inputs[f]?LiteGraph.isValidConnection(this.connecting_output.type,b.inputs[f].type)&&(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(this.connecting_output.type==
LiteGraph.EVENT&&this.isOverNodeBox(b,a.canvasX,a.canvasY))this.connecting_node.connect(this.connecting_slot,b,LiteGraph.EVENT);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),this.connecting_output.type==LiteGraph.EVENT?this.connecting_node.connect(this.connecting_slot,b,LiteGraph.EVENT):c&&!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,[a.canvasX-this.node_over.pos[0],a.canvasY-this.node_over.pos[1]]);if(this.node_capturing_input&&this.node_capturing_input.onMouseUp)this.node_capturing_input.onMouseUp(a,[a.canvasX-this.node_capturing_input.pos[0],a.canvasY-this.node_capturing_input.pos[1]])}else 2==a.which?(this.dirty_canvas=!0,this.dragging_canvas=!1):3==a.which&&(this.dirty_canvas=!0,this.dragging_canvas=!1);this.graph.change();a.stopPropagation();a.preventDefault();return!1}};
LGraphCanvas.prototype.processMouseWheel=function(a){if(this.graph&&this.allow_dragcanvas){var b=null!=a.wheelDeltaY?a.wheelDeltaY:-60*a.detail;this.adjustMouseEvent(a);var c=this.scale;0<b?c*=1.1:0>b&&(c*=1/1.1);this.setZoom(c,[a.localX,a.localY]);this.graph.change();a.preventDefault();return!1}};LGraphCanvas.prototype.isOverNodeBox=function(a,b,c){var d=LiteGraph.NODE_TITLE_HEIGHT;return isInsideRectangle(b,c,a.pos[0]+2,a.pos[1]+2-d,d-4,d-4)?!0:!1};
LGraphCanvas.prototype.isOverNodeInput=function(a,b,c,d){if(a.inputs)for(var e=0,f=a.inputs.length;e<f;++e){var g=a.getConnectionPos(!0,e);if(isInsideRectangle(b,c,g[0]-10,g[1]-5,20,10))return d&&(d[0]=g[0],d[1]=g[1]),e}return-1};
LGraphCanvas.prototype.processKey=function(a){if(this.graph){var b=!1;if("keydown"==a.type){65==a.keyCode&&a.ctrlKey&&(this.selectAllNodes(),b=!0);if(46==a.keyCode||8==a.keyCode)this.deleteSelectedNodes(),b=!0;if(this.selected_nodes)for(var c in this.selected_nodes)if(this.selected_nodes[c].onKeyDown)this.selected_nodes[c].onKeyDown(a)}else if("keyup"==a.type&&this.selected_nodes)for(c in this.selected_nodes)if(this.selected_nodes[c].onKeyUp)this.selected_nodes[c].onKeyUp(a);this.graph.change();if(b)return a.preventDefault(),
!1}};
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}b=null;this.onDropItem&&(b=this.onDropItem(event));b||this.checkDropItem(a)};LGraphCanvas.prototype.checkDropItem=function(a){if(a.dataTransfer.files.length){var b=a.dataTransfer.files[0],c=LGraphCanvas.getFileExtension(b.name).toLowerCase();if(c=LiteGraph.node_types_by_file_extension[c])if(c=LiteGraph.createNode(c.type),c.pos=[a.canvasX,a.canvasY],this.graph.add(c),c.onDropFile)c.onDropFile(b)}};
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(a);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=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(){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){if(this.canvas){var c=LiteGraph.getTime();this.render_time=0.001*(c-this.last_draw_time);this.last_draw_time=c;if(this.graph){var d=[-this.offset[0],-this.offset[1]],e=[d[0]+this.canvas.width/this.scale,d[1]+this.canvas.height/this.scale];this.visible_area=new Float32Array([d[0],d[1],e[0],e[1]])}(this.dirty_bgcanvas||b||this.always_render_background||this.graph&&this.graph._last_trigger_time&&1E3>c-this.graph._last_trigger_time)&&this.drawBackCanvas();(this.dirty_canvas||
a)&&this.drawFrontCanvas();this.fps=this.render_time?1/this.render_time:0;this.frame+=1}};
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=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));if(null!=this.connecting_pos){a.lineWidth=this.connections_width;b=null;switch(this.connecting_output.type){case LiteGraph.EVENT:b="#F85";
break;default:b="#AFA"}this.renderLink(a,this.connecting_pos,[this.canvas_mouse[0],this.canvas_mouse[1]],b);a.beginPath();this.connecting_output.type===LiteGraph.EVENT?a.rect(this.connecting_pos[0]-6+0.5,this.connecting_pos[1]-5+0.5,14,10):a.arc(this.connecting_pos[0],this.connecting_pos[1],4,0,2*Math.PI);a.fill();a.fillStyle="#ffcc00";this._highlight_input&&(a.beginPath(),a.arc(this._highlight_input[0],this._highlight_input[1],6,0,2*Math.PI),a.fill())}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;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;null==this._pattern&&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;f=this.connecting_output;if(!a.flags.collapsed){if(a.inputs)for(g=0;g<a.inputs.length;g++){var h=
a.inputs[g];b.globalAlpha=e;this.connecting_node&&LiteGraph.isValidConnection(h.type&&f.type)&&(b.globalAlpha=0.4*e);b.fillStyle=null!=h.link?"#7F7":"#AAA";var k=a.getConnectionPos(!0,g);k[0]-=a.pos[0];k[1]-=a.pos[1];b.beginPath();h.type===LiteGraph.EVENT?b.rect(k[0]-6+0.5,k[1]-5+0.5,14,10):b.arc(k[0],k[1],4,0,2*Math.PI);b.fill();d&&(h=null!=h.label?h.label:h.name)&&(b.fillStyle=c,b.fillText(h,k[0]+10,k[1]+5))}this.connecting_node&&(b.globalAlpha=0.4*e);b.lineWidth=1;b.textAlign="right";b.strokeStyle=
"black";if(a.outputs)for(g=0;g<a.outputs.length;g++)if(h=a.outputs[g],k=a.getConnectionPos(!1,g),k[0]-=a.pos[0],k[1]-=a.pos[1],b.fillStyle=h.links&&h.links.length?"#7F7":"#AAA",b.beginPath(),h.type===LiteGraph.EVENT?b.rect(k[0]-6+0.5,k[1]-5+0.5,14,10):b.arc(k[0],k[1],4,0,2*Math.PI),b.fill(),b.stroke(),d&&(h=null!=h.label?h.label:h.name))b.fillStyle=c,b.fillText(h,k[0]-10,k[1]+5);b.textAlign="left";b.globalAlpha=1;if(a.onDrawForeground)a.onDrawForeground(b)}a.flags.clip_area&&b.restore();b.globalAlpha=
1}};
LGraphCanvas.prototype.drawNodeShape=function(a,b,c,d,e,f,g){b.strokeStyle=d||LiteGraph.NODE_DEFAULT_COLOR;b.fillStyle=e||LiteGraph.NODE_DEFAULT_BGCOLOR;e=LiteGraph.NODE_TITLE_HEIGHT;var h=a.shape||"box";"box"==h?(b.beginPath(),b.rect(0,f?0:-e,c[0]+1,f?c[1]:c[1]+e),b.fill(),b.shadowColor="transparent",g&&(b.strokeStyle="#CCC",b.strokeRect(-0.5,f?-0.5:-e+-0.5,c[0]+2,f?c[1]+2:c[1]+e+2-1),b.strokeStyle=d)):"round"==a.shape?(b.roundRect(0,f?0:-e,c[0],f?c[1]:c[1]+e,10),b.fill()):"circle"==a.shape&&(b.beginPath(),
b.arc(0.5*c[0],0.5*c[1],0.5*c[0],0,2*Math.PI),b.fill());b.shadowColor="transparent";a.bgImage&&a.bgImage.width&&b.drawImage(a.bgImage,0.5*(c[0]-a.bgImage.width),0.5*(c[1]-a.bgImage.height));a.bgImageUrl&&!a.bgImage&&(a.bgImage=a.loadImage(a.bgImageUrl));if(a.onDrawBackground)a.onDrawBackground(b);f||(b.fillStyle=d||LiteGraph.NODE_DEFAULT_COLOR,d=b.globalAlpha,b.globalAlpha=0.5*d,"box"==h?(b.beginPath(),b.rect(0,-e,c[0]+1,e),b.fill()):"round"==h&&(b.roundRect(0,-e,c[0],e,10,0),b.fill()),b.fillStyle=
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.prototype.drawConnections=function(a){var b=LiteGraph.getTime();a.lineWidth=this.connections_width;a.fillStyle="#AAA";a.strokeStyle="#AAA";a.globalAlpha=this.editor_alpha;for(var c=0,d=this.graph._nodes.length;c<d;++c){var e=this.graph._nodes[c];if(e.inputs&&e.inputs.length)for(var f=0;f<e.inputs.length;++f){var g=e.inputs[f];if(g&&null!=g.link){var h=this.graph.links[g.link];if(h){var k=this.graph.getNodeById(h.origin_id);if(null!=k){var n=h.origin_slot,g=null,g=-1==n?[k.pos[0]+10,k.pos[1]+
10]:k.getConnectionPos(!1,n),k=LGraphCanvas.link_type_colors[e.inputs[f].type]||this.default_link_color;this.renderLink(a,g,e.getConnectionPos(!0,f),k);h&&h._last_time&&1E3>b-h._last_time&&(h=2-0.002*(b-h._last_time),k="rgba(255,255,255, "+h.toFixed(2)+")",this.renderLink(a,g,e.getConnectionPos(!0,f),k,!0,h))}}}}}a.globalAlpha=1};
LGraphCanvas.prototype.renderLink=function(a,b,c,d,e,f){if(this.highquality_render){var g=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*g,b[1],c[0]-0.25*g,c[1],c[0],c[1])):(a.moveTo(b[0]+10,b[1]),a.lineTo(0.5*(b[0]+10+(c[0]-10)),b[1]),a.lineTo(0.5*(b[0]+10+(c[0]-10)),c[1]),a.lineTo(c[0]-10,c[1]));this.render_connections_border&&0.6<this.scale&&!e&&(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)&&(this.render_connection_arrows&&0.6<this.scale&&(d=this.computeConnectionPoint(b,c,0.5),e=this.computeConnectionPoint(b,c,0.51),g=0,g=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(g),a.beginPath(),a.moveTo(-5,-5),a.lineTo(0,5),a.lineTo(5,-5),a.fill(),a.restore()),f))for(f=
0;5>f;++f)d=(0.001*LiteGraph.getTime()+0.2*f)%1,d=this.computeConnectionPoint(b,c,d),a.beginPath(),a.arc(d[0],d[1],5,0,2*Math.PI),a.fill()}else a.beginPath(),a.moveTo(b[0],b[1]),a.lineTo(c[0],c[1]),a.stroke()};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]]};
LGraphCanvas.prototype.resize=function(a,b){if(!a&&!b){var c=this.canvas.parentNode;a=c.offsetWidth;b=c.offsetHeight}if(this.canvas.width!=a||this.canvas.height!=b)this.canvas.width=a,this.canvas.height=b,this.bgcanvas.width=this.canvas.width,this.bgcanvas.height=this.canvas.height,this.setDirty(!0,!0)};
LGraphCanvas.prototype.switchLiveMode=function(a){if(a){var b=this,c=this.live_mode?1.1:0.9;this.live_mode&&(this.live_mode=!1,this.editor_alpha=0.1);var d=setInterval(function(){b.editor_alpha*=c;b.dirty_canvas=!0;b.dirty_bgcanvas=!0;1>c&&0.01>b.editor_alpha&&(clearInterval(d),1>c&&(b.live_mode=!0));1<c&&0.99<b.editor_alpha&&(clearInterval(d),b.editor_alpha=1)},1)}else this.live_mode=!this.live_mode,this.dirty_bgcanvas=this.dirty_canvas=!0};LGraphCanvas.prototype.onNodeSelectionChange=function(a){};
LGraphCanvas.prototype.touchHandler=function(a){var b=a.changedTouches[0],c="";switch(a.type){case "touchstart":c="mousedown";break;case "touchmove":c="mousemove";break;case "touchend":c="mouseup";break;default:return}var d=this.getCanvasWindow(),e=d.document.createEvent("MouseEvent");e.initMouseEvent(c,!0,!0,d,1,b.screenX,b.screenY,b.clientX,b.clientY,!1,!1,!1,!1,0,null);b.target.dispatchEvent(e);a.preventDefault()};
LGraphCanvas.onMenuAdd=function(a,b,c,d,e){function f(a,b){var c=LiteGraph.createNode(a.value);c&&(c.pos=d.convertEventToCanvas(e),d.graph.add(c))}var g=d.getCanvasWindow();a=LiteGraph.getNodeTypesCategories();var h={},k;for(k in a)a[k]&&(h[k]={value:a[k],content:a[k],is_menu:!0});var n=LiteGraph.createContextMenu(h,{event:b,callback:function(a,b){var c=LiteGraph.getNodeTypesInCategory(a.value),d=[],e;for(e in c)d.push({content:c[e].title,value:c[e].type});LiteGraph.createContextMenu(d,{event:b,callback:f,
from:n},g);return!1},from:c},g);return!1};LGraphCanvas.onMenuCollapseAll=function(){};LGraphCanvas.onMenuNodeEdit=function(){};
LGraphCanvas.showMenuNodeInputs=function(a,b,c){function d(b,c,d){a&&(b.callback&&b.callback.call(e,a,b,c,d),b.value&&a.addInput(b.value[0],b.value[1],b.value[2]))}if(a){var e=this,f=this.getCanvasWindow(),g=a.optional_inputs;a.onGetInputs&&(g=a.onGetInputs());var h=[];if(g)for(var k in g){var n=g[k],l=n[0];n[2]&&n[2].label&&(l=n[2].label);h.push({content:l,value:n})}this.onMenuNodeInputs&&(h=this.onMenuNodeInputs(h));if(h.length)return LiteGraph.createContextMenu(h,{event:b,callback:d,from:c},f),
!1}};
LGraphCanvas.showMenuNodeOutputs=function(a,b,c){function d(b,g,h){if(a&&(b.callback&&b.callback.call(e,a,b,g,h),b.value))if(h=b.value[1],!h||h.constructor!==Object&&h.constructor!==Array)a.addOutput(b.value[0],b.value[1],b.value[2]);else{b=[];for(var k in h)b.push({content:k,value:h[k]});LiteGraph.createContextMenu(b,{event:g,callback:d,from:c});return!1}}if(a){var e=this,f=this.getCanvasWindow(),g=a.optional_outputs;a.onGetOutputs&&(g=a.onGetOutputs());var h=[];if(g)for(var k in g){var n=g[k];if(!n)h.push(null);
else if(-1==a.findOutputSlot(n[0])){var l=n[0];n[2]&&n[2].label&&(l=n[2].label);l={content:l,value:n};n[1]==LiteGraph.EVENT&&(l.className="event");h.push(l)}}this.onMenuNodeOutputs&&(h=this.onMenuNodeOutputs(h));if(h.length)return LiteGraph.createContextMenu(h,{event:b,callback:d,from:c},f),!1}};
LGraphCanvas.onShowMenuNodeProperties=function(a,b,c){function d(b,c,d){a&&e.showEditPropertyValue(a,b.value,{event:c})}if(a&&a.properties){var e=this,f=this.getCanvasWindow(),g=[],h;for(h in a.properties)g.push({content:"<span class='property_name'>"+h+"</span><span class='property_value'>"+(void 0!==a.properties[h]?a.properties[h]:" ")+"</span>",value:h});if(g.length)return LiteGraph.createContextMenu(g,{event:b,callback:d,from:c},f),!1}};
LGraphCanvas.prototype.showEditPropertyValue=function(a,b,c){function d(){e(p.value)}function e(c){"number"==typeof a.properties[b]&&(c=Number(c));a.properties[b]=c;if(a.onPropertyChanged)a.onPropertyChanged(b,c);l.parentNode.removeChild(l);a.setDirtyCanvas(!0,!0)}if(a&&void 0!==a.properties[b]){c=c||{};var f="string";null!==a.properties[b]&&(f=typeof a.properties[b]);var g=null;a.getPropertyInfo&&(g=a.getPropertyInfo(b));if(a.properties_info)for(var h=0;h<a.properties_info.length;++h)if(a.properties_info[h].name==
b){g=a.properties_info[h];break}void 0!==g&&null!==g&&g.type&&(f=g.type);var k="";if("string"==f||"number"==f)k="<input autofocus type='text' class='value'/>";else if("enum"==f&&g.values){k="<select autofocus type='text' class='value'>";for(h in g.values)var n=g.values.constructor===Array?g.values[h]:h,k=k+("<option value='"+n+"' "+(n==a.properties[b]?"selected":"")+">"+g.values[h]+"</option>");k+="</select>"}else"boolean"==f&&(k="<input autofocus type='checkbox' class='value' "+(a.properties[b]?
"checked":"")+"/>");var l=document.createElement("div");l.className="graphdialog";l.innerHTML="<span class='name'>"+b+"</span>"+k+"<button>OK</button>";if("enum"==f&&g.values){var p=l.querySelector("select");p.addEventListener("change",function(a){e(a.target.value)})}else if("boolean"==f)(p=l.querySelector("input"))&&p.addEventListener("click",function(a){e(!!p.checked)});else if(p=l.querySelector("input"))p.value=void 0!==a.properties[b]?a.properties[b]:"",p.addEventListener("keydown",function(a){13==
a.keyCode&&(d(),a.preventDefault(),a.stopPropagation())});f=this.canvas.getClientRects()[0];h=g=-20;f&&(g-=f.left,h-=f.top);c.event?(l.style.left=c.event.pageX+g+"px",l.style.top=c.event.pageY+h+"px"):(l.style.left=0.5*this.canvas.width+g+"px",l.style.top=0.5*this.canvas.height+h+"px");l.querySelector("button").addEventListener("click",d);this.canvas.parentNode.appendChild(l)}};LGraphCanvas.onMenuNodeCollapse=function(a){a.flags.collapsed=!a.flags.collapsed;a.setDirtyCanvas(!0,!0)};
LGraphCanvas.onMenuNodePin=function(a){a.pin()};LGraphCanvas.onMenuNodeMode=function(a,b,c){LiteGraph.createContextMenu(["Always","On Event","Never"],{event:b,callback:function(b){if(a)switch(b){case "On Event":a.mode=LiteGraph.ON_EVENT;break;case "Never":a.mode=LiteGraph.NEVER;break;default:a.mode=LiteGraph.ALWAYS}},from:c});return!1};
LGraphCanvas.onMenuNodeColors=function(a,b,c){var d=[],e;for(e in LGraphCanvas.node_colors){var f=LGraphCanvas.node_colors[e];d.push({value:e,content:"<span style='display: block; color:"+f.color+"; background-color:"+f.bgcolor+"'>"+e+"</span>"})}LiteGraph.createContextMenu(d,{event:b,callback:function(b){a&&(b=LGraphCanvas.node_colors[b.value])&&(a.color=b.color,a.bgcolor=b.bgcolor,a.setDirtyCanvas(!0))},from:c});return!1};
LGraphCanvas.onMenuNodeShapes=function(a,b){LiteGraph.createContextMenu(["box","round"],{event:b,callback:function(b){a&&(a.shape=b,a.setDirtyCanvas(!0))}});return!1};LGraphCanvas.onMenuNodeRemove=function(a){!1!=a.removable&&(a.graph.remove(a),a.setDirtyCanvas(!0,!0))};LGraphCanvas.onMenuNodeClone=function(a){if(!1!=a.clonable){var b=a.clone();b&&(b.pos=[a.pos[0]+5,a.pos[1]+5],a.graph.add(b),a.setDirtyCanvas(!0,!0))}};
LGraphCanvas.node_colors={red:{color:"#FAA",bgcolor:"#A44"},green:{color:"#AFA",bgcolor:"#4A4"},blue:{color:"#AAF",bgcolor:"#44A"},white:{color:"#FFF",bgcolor:"#AAA"}};
LGraphCanvas.prototype.getCanvasMenuOptions=function(){var a=null;this.getMenuOptions?a=this.getMenuOptions():(a=[{content:"Add Node",is_menu:!0,callback:LGraphCanvas.onMenuAdd}],this._graph_stack&&0<this._graph_stack.length&&(a=[{content:"Close subgraph",callback:this.closeSubgraph.bind(this)},null].concat(a)));if(this.getExtraMenuOptions){var b=this.getExtraMenuOptions(this,a);b&&(a=a.concat(b))}return a};
LGraphCanvas.prototype.getNodeMenuOptions=function(a){var b=null,b=a.getMenuOptions?a.getMenuOptions(this):[{content:"Inputs",is_menu:!0,disabled:!0,callback:LGraphCanvas.showMenuNodeInputs},{content:"Outputs",is_menu:!0,disabled:!0,callback:LGraphCanvas.showMenuNodeOutputs},null,{content:"Properties",is_menu:!0,callback:LGraphCanvas.onShowMenuNodeProperties},null,{content:"Mode",is_menu:!0,callback:LGraphCanvas.onMenuNodeMode},{content:"Collapse",callback:LGraphCanvas.onMenuNodeCollapse},{content:"Pin",
callback:LGraphCanvas.onMenuNodePin},{content:"Colors",is_menu:!0,callback:LGraphCanvas.onMenuNodeColors},{content:"Shapes",is_menu:!0,callback:LGraphCanvas.onMenuNodeShapes},null];if(a.getExtraMenuOptions){var c=a.getExtraMenuOptions(this);c&&(c.push(null),b=c.concat(b))}!1!==a.clonable&&b.push({content:"Clone",callback:LGraphCanvas.onMenuNodeClone});!1!==a.removable&&b.push(null,{content:"Remove",callback:LGraphCanvas.onMenuNodeRemove});a.onGetInputs&&(c=a.onGetInputs())&&c.length&&(b[0].disabled=
!1);a.onGetOutputs&&(a=a.onGetOutputs())&&a.length&&(b[1].disabled=!1);return b};
LGraphCanvas.prototype.processContextMenu=function(a,b){var c=this,d=this.getCanvasWindow(),e=null,f={event:b,callback:function(d,e){if(d)if(d==g)d.input?a.removeInput(g.slot):d.output&&a.removeOutput(g.slot);else if(d.callback)return d.callback.call(c,a,e,h,c,b)}},g=null;a&&(g=a.getSlotInPosition(b.canvasX,b.canvasY));g?(e=g.locked?["Cannot remove"]:{"Remove Slot":g},f.title=g.input?g.input.type:g.output.type,g.input&&g.input.type==LiteGraph.EVENT&&(f.title="Event")):e=a?this.getNodeMenuOptions(a):
this.getCanvasMenuOptions();if(e)var h=LiteGraph.createContextMenu(e,f,d)};CanvasRenderingContext2D.prototype.roundRect=function(a,b,c,d,e,f){void 0===e&&(e=5);void 0===f&&(f=e);this.beginPath();this.moveTo(a+e,b);this.lineTo(a+c-e,b);this.quadraticCurveTo(a+c,b,a+c,b+e);this.lineTo(a+c,b+d-f);this.quadraticCurveTo(a+c,b+d,a+c-f,b+d);this.lineTo(a+f,b+d);this.quadraticCurveTo(a,b+d,a,b+d-f);this.lineTo(a,b+e);this.quadraticCurveTo(a,b,a+e,b)};
function compareObjects(a,b){for(var c in a)if(a[c]!=b[c])return!1;return!0}function distance(a,b){return Math.sqrt((b[0]-a[0])*(b[0]-a[0])+(b[1]-a[1])*(b[1]-a[1]))}function colorToString(a){return"rgba("+Math.round(255*a[0]).toFixed()+","+Math.round(255*a[1]).toFixed()+","+Math.round(255*a[2]).toFixed()+","+(4==a.length?a[3].toFixed(2):"1.0")+")"}function isInsideRectangle(a,b,c,d,e,f){return c<a&&c+e>a&&d<b&&d+f>b?!0:!1}
function growBounding(a,b,c){b<a[0]?a[0]=b:b>a[2]&&(a[2]=b);c<a[1]?a[1]=c:c>a[3]&&(a[3]=c)}function isInsideBounding(a,b){return a[0]<b[0][0]||a[1]<b[0][1]||a[0]>b[1][0]||a[1]>b[1][1]?!1:!0}function overlapBounding(a,b){return a[0]>b[2]||a[1]>b[3]||a[2]<b[0]||a[3]<b[1]?!1:!0}function hex2num(a){"#"==a.charAt(0)&&(a=a.slice(1));a=a.toUpperCase();for(var b=Array(3),c=0,d,e,f=0;6>f;f+=2)d="0123456789ABCDEF".indexOf(a.charAt(f)),e="0123456789ABCDEF".indexOf(a.charAt(f+1)),b[c]=16*d+e,c++;return b}
function num2hex(a){for(var b="#",c,d,e=0;3>e;e++)c=a[e]/16,d=a[e]%16,b+="0123456789ABCDEF".charAt(c)+"0123456789ABCDEF".charAt(d);return b}
LiteGraph.createContextMenu=function(a,b,c){function d(a){var d=!0;b.callback&&(a=b.callback.call(g,this.data,a),void 0!==a&&(d=a));d&&LiteGraph.closeAllContextMenus(c)}this.options=b=b||{};c=c||window;if(b.from){var e=document.querySelectorAll(".graphcontextmenu"),f;for(f in e)e[f].previousSibling==b.from&&e[f].closeMenu()}else LiteGraph.closeAllContextMenus(c);var g=c.document.createElement("div");g.className="graphcontextmenu graphmenubar-panel";this.root=g;e=g.style;e.minWidth="100px";e.minHeight=
"20px";e.position="fixed";e.top="100px";e.left="100px";e.color="#AAF";e.padding="2px";e.borderBottom="2px solid #AAF";e.backgroundColor="#444";e.zIndex=10;b.title&&(e=document.createElement("div"),e.className="graphcontextmenu-title",e.innerHTML=b.title,g.appendChild(e));g.addEventListener("contextmenu",function(a){a.preventDefault();return!1});for(var h in a)f=a[h],e=c.document.createElement("div"),e.className="graphmenu-entry",null==f?e.className+=" separator":(f.is_menu&&(e.className+=" submenu"),
f.disabled&&(e.className+=" disabled"),f.className&&(e.className+=" "+f.className),e.style.cursor="pointer",e.dataset.value="string"==typeof f?f:f.value,e.data=f,e.innerHTML="string"==typeof f?a.constructor==Array?a[h]:h:f.content?f.content:h,e.addEventListener("click",d)),g.appendChild(e);g.addEventListener("mouseover",function(a){this.mouse_inside=!0});g.addEventListener("mouseout",function(a){for(a=a.relatedTarget||a.toElement;a!=this&&a!=c.document;)a=a.parentNode;a!=this&&(this.mouse_inside=
!1,this.block_close||this.closeMenu())});c.document.body.appendChild(g);a=g.getClientRects()[0];b.from&&(b.from.block_close=!0);f=b.left||0;h=b.top||0;b.event&&(f=b.event.pageX-10,h=b.event.pageY-10,b.left&&(f=b.left),e=c.document.body.getClientRects()[0],b.from&&(f=b.from.getClientRects()[0],f=f.left+f.width),f>e.width-a.width-10&&(f=e.width-a.width-10),h>e.height-a.height-10&&(h=e.height-a.height-10));g.style.left=f+"px";g.style.top=h+"px";g.closeMenu=function(){b.from&&(b.from.block_close=!1,b.from.mouse_inside||
b.from.closeMenu());this.parentNode&&c.document.body.removeChild(this)};return g};LiteGraph.closeAllContextMenus=function(a){a=a||window;a=a.document.querySelectorAll(".graphcontextmenu");if(a.length){for(var b=[],c=0;c<a.length;c++)b.push(a[c]);for(c in b)b[c].parentNode&&b[c].parentNode.removeChild(b[c])}};
LiteGraph.extendClass=function(a,b){for(var c in b)a.hasOwnProperty(c)||(a[c]=b[c]);if(b.prototype)for(c in b.prototype)b.prototype.hasOwnProperty(c)&&!a.prototype.hasOwnProperty(c)&&(b.prototype.__lookupGetter__(c)?a.prototype.__defineGetter__(c,b.prototype.__lookupGetter__(c)):a.prototype[c]=b.prototype[c],b.prototype.__lookupSetter__(c)&&a.prototype.__defineSetter__(c,b.prototype.__lookupSetter__(c)))};
window.requestAnimationFrame||(window.requestAnimationFrame=window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(a){window.setTimeout(a,1E3/60)});
(function(){function a(){this.addOutput("in ms","number");this.addOutput("in sec","number")}function b(){this.size=[120,60];this.subgraph=new LGraph;this.subgraph._subgraph_node=this;this.subgraph._is_subgraph=!0;this.subgraph.onGlobalInputAdded=this.onSubgraphNewGlobalInput.bind(this);this.subgraph.onGlobalInputRenamed=this.onSubgraphRenamedGlobalInput.bind(this);this.subgraph.onGlobalInputTypeChanged=this.onSubgraphTypeChangeGlobalInput.bind(this);this.subgraph.onGlobalOutputAdded=this.onSubgraphNewGlobalOutput.bind(this);
this.subgraph.onGlobalOutputRenamed=this.onSubgraphRenamedGlobalOutput.bind(this);this.subgraph.onGlobalOutputTypeChanged=this.onSubgraphTypeChangeGlobalOutput.bind(this);this.bgcolor="#940"}function c(){var a="input_"+(1E3*Math.random()).toFixed();this.addOutput(a,null);this.properties={name:a,type:null};var b=this;Object.defineProperty(this.properties,"name",{get:function(){return a},set:function(c){if(""!=c){var d=b.getOutputInfo(0);d.name!=c&&(d.name=c,b.graph&&b.graph.renameGlobalInput(a,c),
a=c)}},enumerable:!0});Object.defineProperty(this.properties,"type",{get:function(){return b.outputs[0].type},set:function(c){b.outputs[0].type=c;b.graph&&b.graph.changeGlobalInputType(a,b.outputs[0].type)},enumerable:!0})}function d(){var a="output_"+(1E3*Math.random()).toFixed();this.addInput(a,null);this.properties={name:a,type:null};var b=this;Object.defineProperty(this.properties,"name",{get:function(){return a},set:function(c){if(""!=c){var d=b.getInputInfo(0);d.name!=c&&(d.name=c,b.graph&&
b.graph.renameGlobalOutput(a,c),a=c)}},enumerable:!0});Object.defineProperty(this.properties,"type",{get:function(){return b.inputs[0].type},set:function(c){b.inputs[0].type=c;b.graph&&b.graph.changeGlobalInputType(a,b.inputs[0].type)},enumerable:!0})}function e(){this.addOutput("value","number");this.addProperty("value",1);this.editable={property:"value",type:"number"}}function f(){this.size=[60,20];this.addInput("value",0,{label:""});this.addOutput("value",0,{label:""});this.addProperty("value",
"")}function g(){this.mode=LiteGraph.ON_EVENT;this.size=[60,20];this.addProperty("msg","");this.addInput("log",LiteGraph.EVENT);this.addInput("msg",0)}a.title="Time";a.desc="Time";a.prototype.onExecute=function(){this.setOutputData(0,1E3*this.graph.globaltime);this.setOutputData(1,this.graph.globaltime)};LiteGraph.registerNodeType("basic/time",a);b.title="Subgraph";b.desc="Graph inside a node";b.prototype.onSubgraphNewGlobalInput=function(a,b){this.addInput(a,b)};b.prototype.onSubgraphRenamedGlobalInput=
function(a,b){var c=this.findInputSlot(a);-1!=c&&(this.getInputInfo(c).name=b)};b.prototype.onSubgraphTypeChangeGlobalInput=function(a,b){var c=this.findInputSlot(a);-1!=c&&(this.getInputInfo(c).type=b)};b.prototype.onSubgraphNewGlobalOutput=function(a,b){this.addOutput(a,b)};b.prototype.onSubgraphRenamedGlobalOutput=function(a,b){var c=this.findOutputSlot(a);-1!=c&&(this.getOutputInfo(c).name=b)};b.prototype.onSubgraphTypeChangeGlobalOutput=function(a,b){var c=this.findOutputSlot(a);-1!=c&&(this.getOutputInfo(c).type=
b)};b.prototype.getExtraMenuOptions=function(a){var b=this;return[{content:"Open",callback:function(){a.openSubgraph(b.subgraph)}}]};b.prototype.onExecute=function(){if(this.inputs)for(var a=0;a<this.inputs.length;a++){var b=this.inputs[a],c=this.getInputData(a);this.subgraph.setGlobalInputData(b.name,c)}this.subgraph.runStep();if(this.outputs)for(a=0;a<this.outputs.length;a++)c=this.subgraph.getGlobalOutputData(this.outputs[a].name),this.setOutputData(a,c)};b.prototype.configure=function(a){LGraphNode.prototype.configure.call(this,
a)};b.prototype.serialize=function(){var a=LGraphNode.prototype.serialize.call(this);a.subgraph=this.subgraph.serialize();return a};b.prototype.clone=function(){var a=LiteGraph.createNode(this.type),b=this.serialize();delete b.id;delete b.inputs;delete b.outputs;a.configure(b);return a};LiteGraph.registerNodeType("graph/subgraph",b);c.title="Input";c.desc="Input of the graph";c.prototype.onAdded=function(){this.graph.addGlobalInput(this.properties.name,this.properties.type)};c.prototype.onExecute=
function(){var a=this.graph.global_inputs[this.properties.name];a&&this.setOutputData(0,a.value)};LiteGraph.registerNodeType("graph/input",c);d.title="Ouput";d.desc="Output of the graph";d.prototype.onAdded=function(){this.graph.addGlobalOutput(this.properties.name,this.properties.type)};d.prototype.onExecute=function(){this.graph.setGlobalOutputData(this.properties.name,this.getInputData(0))};LiteGraph.registerNodeType("graph/output",d);e.title="Const";e.desc="Constant value";e.prototype.setValue=
function(a){"string"==typeof a&&(a=parseFloat(a));this.properties.value=a;this.setDirtyCanvas(!0)};e.prototype.onExecute=function(){this.setOutputData(0,parseFloat(this.properties.value))};e.prototype.onDrawBackground=function(a){this.outputs[0].label=this.properties.value.toFixed(3)};e.prototype.onWidget=function(a,b){"value"==b.name&&this.setValue(b.value)};LiteGraph.registerNodeType("basic/const",e);f.title="Watch";f.desc="Show value of input";f.prototype.onExecute=function(){this.properties.value=
this.getInputData(0);this.setOutputData(0,this.properties.value)};f.prototype.onDrawBackground=function(a){this.inputs[0]&&null!=this.properties.value&&(this.properties.value.constructor===Number?this.inputs[0].label=this.properties.value.toFixed(3):((a=this.properties.value)&&a.length&&(a=Array.prototype.slice.call(a).join(",")),this.inputs[0].label=a))};LiteGraph.registerNodeType("basic/watch",f);g.title="Console";g.desc="Show value inside the console";g.prototype.onAction=function(a,b){"log"==
a?console.log(b):"warn"==a?console.warn(b):"error"==a&&console.error(b)};g.prototype.onExecute=function(){var a=this.getInputData(0);null!==a&&(this.properties.msg=a);console.log(a)};g.prototype.onGetInputs=function(){return[["log",LiteGraph.ACTION],["warn",LiteGraph.ACTION],["error",LiteGraph.ACTION]]};LiteGraph.registerNodeType("basic/console",g)})();
(function(){function a(){this.size=[60,20];this.addProperty("time",1E3);this.addInput("event",LiteGraph.ACTION);this.addOutput("on_time",LiteGraph.EVENT);this._pending=[]}a.title="Delay";a.desc="Delays one event";a.prototype.onAction=function(a,c){this._pending.push([this.properties.time,c])};a.prototype.onExecute=function(){for(var a=1E3*this.graph.elapsed_time,c=0;c<this._pending.length;++c){var d=this._pending[c];d[0]-=a;0<d[0]||(this._pending.splice(c,1),--c,this.trigger(null,d[1]))}};a.prototype.onGetInputs=
function(){return[["event",LiteGraph.ACTION]]};LiteGraph.registerNodeType("events/delay",a)})();
(function(){function a(){this.addOutput("clicked",LiteGraph.EVENT);this.addProperty("text","");this.addProperty("font","40px Arial");this.addProperty("message","");this.size=[64,84]}function b(){this.addOutput("","number");this.size=[64,84];this.properties={min:0,max:1,value:0.5,wcolor:"#7AF",size:50}}function c(){this.size=[160,26];this.addOutput("","number");this.properties={wcolor:"#7AF",min:0,max:1,value:0.5}}function d(){this.size=[160,26];this.addInput("","number");this.properties={min:0,max:1,
value:0,wcolor:"#AAF"}}function e(){this.addInputs("",0);this.properties={value:"...",font:"Arial",fontsize:18,color:"#AAA",align:"left",glowSize:0,decimals:1}}function f(){this.size=[200,100];this.properties={borderColor:"#ffffff",bgcolorTop:"#f0f0f0",bgcolorBottom:"#e0e0e0",shadowSize:2,borderRadius:3}}a.title="Button";a.desc="Triggers an event";a.prototype.onDrawForeground=function(a){!this.flags.collapsed&&(a.fillStyle="black",a.fillRect(1,1,this.size[0]-3,this.size[1]-3),a.fillStyle="#AAF",a.fillRect(0,
0,this.size[0]-3,this.size[1]-3),a.fillStyle=this.clicked?"white":this.mouseOver?"#668":"#334",a.fillRect(1,1,this.size[0]-4,this.size[1]-4),this.properties.text||0===this.properties.text)&&(a.textAlign="center",a.fillStyle=this.clicked?"black":"white",this.properties.font&&(a.font=this.properties.font),a.fillText(this.properties.text,0.5*this.size[0],0.85*this.size[1]),a.textAlign="left")};a.prototype.onMouseDown=function(a,b){if(1<b[0]&&1<b[1]&&b[0]<this.size[0]-2&&b[1]<this.size[1]-2)return this.clicked=
!0,this.trigger("clicked",this.properties.message),!0};a.prototype.onMouseUp=function(a){this.clicked=!1};LiteGraph.registerNodeType("widget/button",a);b.title="Knob";b.desc="Circular controller";b.widgets=[{name:"increase",text:"+",type:"minibutton"},{name:"decrease",text:"-",type:"minibutton"}];b.prototype.onAdded=function(){this.value=(this.properties.value-this.properties.min)/(this.properties.max-this.properties.min);this.imgbg=this.loadImage("imgs/knob_bg.png");this.imgfg=this.loadImage("imgs/knob_fg.png")};
b.prototype.onDrawImageKnob=function(a){if(this.imgfg&&this.imgfg.width){var b=0.5*this.imgbg.width,c=this.size[0]/this.imgfg.width;a.save();a.translate(0,20);a.scale(c,c);a.drawImage(this.imgbg,0,0);a.translate(b,b);a.rotate(2*this.value*Math.PI*6/8+10*Math.PI/8);a.translate(-b,-b);a.drawImage(this.imgfg,0,0);a.restore();this.title&&(a.font="bold 16px Criticized,Tahoma",a.fillStyle="rgba(100,100,100,0.8)",a.textAlign="center",a.fillText(this.title.toUpperCase(),0.5*this.size[0],18),a.textAlign="left")}};
b.prototype.onDrawVectorKnob=function(a){if(this.imgfg&&this.imgfg.width){a.lineWidth=1;a.strokeStyle=this.mouseOver?"#FFF":"#AAA";a.fillStyle="#000";a.beginPath();a.arc(0.5*this.size[0],0.5*this.size[1]+10,0.5*this.properties.size,0,2*Math.PI,!0);a.stroke();0<this.value&&(a.strokeStyle=this.properties.wcolor,a.lineWidth=0.2*this.properties.size,a.beginPath(),a.arc(0.5*this.size[0],0.5*this.size[1]+10,0.35*this.properties.size,-0.5*Math.PI+2*Math.PI*this.value,-0.5*Math.PI,!0),a.stroke(),a.lineWidth=
1);a.font=0.2*this.properties.size+"px Arial";a.fillStyle="#AAA";a.textAlign="center";var b=this.properties.value;"number"==typeof b&&(b=b.toFixed(2));a.fillText(b,0.5*this.size[0],0.65*this.size[1]);a.textAlign="left"}};b.prototype.onDrawForeground=function(a){this.onDrawImageKnob(a)};b.prototype.onExecute=function(){this.setOutputData(0,this.properties.value);this.boxcolor=colorToString([this.value,this.value,this.value])};b.prototype.onMouseDown=function(a){if(this.imgfg&&this.imgfg.width){this.center=
[0.5*this.size[0],0.5*this.size[1]+20];this.radius=0.5*this.size[0];if(20>a.canvasY-this.pos[1]||distance([a.canvasX,a.canvasY],[this.pos[0]+this.center[0],this.pos[1]+this.center[1]])>this.radius)return!1;this.oldmouse=[a.canvasX-this.pos[0],a.canvasY-this.pos[1]];this.captureInput(!0);return!0}};b.prototype.onMouseMove=function(a){if(this.oldmouse){a=[a.canvasX-this.pos[0],a.canvasY-this.pos[1]];var b=this.value,b=b-0.01*(a[1]-this.oldmouse[1]);1<b?b=1:0>b&&(b=0);this.value=b;this.properties.value=
this.properties.min+(this.properties.max-this.properties.min)*this.value;this.oldmouse=a;this.setDirtyCanvas(!0)}};b.prototype.onMouseUp=function(a){this.oldmouse&&(this.oldmouse=null,this.captureInput(!1))};b.prototype.onMouseLeave=function(a){};b.prototype.onWidget=function(a,b){if("increase"==b.name)this.onPropertyChanged("size",this.properties.size+10);else if("decrease"==b.name)this.onPropertyChanged("size",this.properties.size-10)};b.prototype.onPropertyChanged=function(a,b){if("wcolor"==a)this.properties[a]=
b;else if("size"==a)b=parseInt(b),this.properties[a]=b,this.size=[b+4,b+24],this.setDirtyCanvas(!0,!0);else if("min"==a||"max"==a||"value"==a)this.properties[a]=parseFloat(b);else return!1;return!0};LiteGraph.registerNodeType("widget/knob",b);c.title="H.Slider";c.desc="Linear slider controller";c.prototype.onInit=function(){this.value=0.5;this.imgfg=this.loadImage("imgs/slider_fg.png")};c.prototype.onDrawVectorial=function(a){this.imgfg&&this.imgfg.width&&(a.lineWidth=1,a.strokeStyle=this.mouseOver?
"#FFF":"#AAA",a.fillStyle="#000",a.beginPath(),a.rect(2,0,this.size[0]-4,20),a.stroke(),a.fillStyle=this.properties.wcolor,a.beginPath(),a.rect(2+(this.size[0]-4-20)*this.value,0,20,20),a.fill())};c.prototype.onDrawImage=function(a){this.imgfg&&this.imgfg.width&&(a.lineWidth=1,a.fillStyle="#000",a.fillRect(2,9,this.size[0]-4,2),a.strokeStyle="#333",a.beginPath(),a.moveTo(2,9),a.lineTo(this.size[0]-4,9),a.stroke(),a.strokeStyle="#AAA",a.beginPath(),a.moveTo(2,11),a.lineTo(this.size[0]-4,11),a.stroke(),
a.drawImage(this.imgfg,2+(this.size[0]-4)*this.value-0.5*this.imgfg.width,0.5*-this.imgfg.height+10))};c.prototype.onDrawForeground=function(a){this.onDrawImage(a)};c.prototype.onExecute=function(){this.properties.value=this.properties.min+(this.properties.max-this.properties.min)*this.value;this.setOutputData(0,this.properties.value);this.boxcolor=colorToString([this.value,this.value,this.value])};c.prototype.onMouseDown=function(a){if(0>a.canvasY-this.pos[1])return!1;this.oldmouse=[a.canvasX-this.pos[0],
a.canvasY-this.pos[1]];this.captureInput(!0);return!0};c.prototype.onMouseMove=function(a){if(this.oldmouse){a=[a.canvasX-this.pos[0],a.canvasY-this.pos[1]];var b=this.value,b=b+(a[0]-this.oldmouse[0])/this.size[0];1<b?b=1:0>b&&(b=0);this.value=b;this.oldmouse=a;this.setDirtyCanvas(!0)}};c.prototype.onMouseUp=function(a){this.oldmouse=null;this.captureInput(!1)};c.prototype.onMouseLeave=function(a){};c.prototype.onPropertyChanged=function(a,b){if("wcolor"==a)this.properties[a]=b;else return!1;return!0};
LiteGraph.registerNodeType("widget/hslider",c);d.title="Progress";d.desc="Shows data in linear progress";d.prototype.onExecute=function(){var a=this.getInputData(0);void 0!=a&&(this.properties.value=a)};d.prototype.onDrawForeground=function(a){a.lineWidth=1;a.fillStyle=this.properties.wcolor;var b=(this.properties.value-this.properties.min)/(this.properties.max-this.properties.min),b=Math.min(1,b),b=Math.max(0,b);a.fillRect(2,2,(this.size[0]-4)*b,this.size[1]-4)};LiteGraph.registerNodeType("widget/progress",
d);e.title="Text";e.desc="Shows the input value";e.widgets=[{name:"resize",text:"Resize box",type:"button"},{name:"led_text",text:"LED",type:"minibutton"},{name:"normal_text",text:"Normal",type:"minibutton"}];e.prototype.onDrawForeground=function(a){a.fillStyle=this.properties.color;var b=this.properties.value;this.properties.glowSize?(a.shadowColor=this.properties.color,a.shadowOffsetX=0,a.shadowOffsetY=0,a.shadowBlur=this.properties.glowSize):a.shadowColor="transparent";var c=this.properties.fontsize;
a.textAlign=this.properties.align;a.font=c.toString()+"px "+this.properties.font;this.str="number"==typeof b?b.toFixed(this.properties.decimals):b;if("string"==typeof this.str){var b=this.str.split("\\n"),d;for(d in b)a.fillText(b[d],"left"==this.properties.align?15:this.size[0]-15,-0.15*c+c*(parseInt(d)+1))}a.shadowColor="transparent";this.last_ctx=a;a.textAlign="left"};e.prototype.onExecute=function(){var a=this.getInputData(0);this.properties.value=null!=a?a:"";this.setDirtyCanvas(!0)};e.prototype.resize=
function(){if(this.last_ctx){var a=this.str.split("\\n");this.last_ctx.font=this.properties.fontsize+"px "+this.properties.font;var b=0,c;for(c in a){var d=this.last_ctx.measureText(a[c]).width;b<d&&(b=d)}this.size[0]=b+20;this.size[1]=4+a.length*this.properties.fontsize;this.setDirtyCanvas(!0)}};e.prototype.onWidget=function(a,b){"resize"==b.name?this.resize():"led_text"==b.name?(this.properties.font="Digital",this.properties.glowSize=4,this.setDirtyCanvas(!0)):"normal_text"==b.name&&(this.properties.font=
"Arial",this.setDirtyCanvas(!0))};e.prototype.onPropertyChanged=function(a,b){this.properties[a]=b;this.str="number"==typeof b?b.toFixed(3):b;return!0};LiteGraph.registerNodeType("widget/text",e);f.title="Panel";f.desc="Non interactive panel";f.widgets=[{name:"update",text:"Update",type:"button"}];f.prototype.createGradient=function(a){""==this.properties.bgcolorTop||""==this.properties.bgcolorBottom?this.lineargradient=0:(this.lineargradient=a.createLinearGradient(0,0,0,this.size[1]),this.lineargradient.addColorStop(0,
this.properties.bgcolorTop),this.lineargradient.addColorStop(1,this.properties.bgcolorBottom))};f.prototype.onDrawForeground=function(a){null==this.lineargradient&&this.createGradient(a);this.lineargradient&&(a.lineWidth=1,a.strokeStyle=this.properties.borderColor,a.fillStyle=this.lineargradient,this.properties.shadowSize?(a.shadowColor="#000",a.shadowOffsetX=0,a.shadowOffsetY=0,a.shadowBlur=this.properties.shadowSize):a.shadowColor="transparent",a.roundRect(0,0,this.size[0]-1,this.size[1]-1,this.properties.shadowSize),
a.fill(),a.shadowColor="transparent",a.stroke())};f.prototype.onWidget=function(a,b){"update"==b.name&&(this.lineargradient=null,this.setDirtyCanvas(!0))};LiteGraph.registerNodeType("widget/panel",f)})();
(function(){function a(){this.addOutput("left_x_axis","number");this.addOutput("left_y_axis","number");this.properties={}}a.title="Gamepad";a.desc="gets the input of the gamepad";a.prototype.onExecute=function(){var a=this.getGamepad();if(this.outputs)for(var c=0;c<this.outputs.length;c++){var d=this.outputs[c],e=null;if(a)switch(d.name){case "left_axis":e=[a.xbox.axes.lx,a.xbox.axes.ly];break;case "right_axis":e=[a.xbox.axes.rx,a.xbox.axes.ry];break;case "left_x_axis":e=a.xbox.axes.lx;break;case "left_y_axis":e=
a.xbox.axes.ly;break;case "right_x_axis":e=a.xbox.axes.rx;break;case "right_y_axis":e=a.xbox.axes.ry;break;case "trigger_left":e=a.xbox.axes.ltrigger;break;case "trigger_right":e=a.xbox.axes.rtrigger;break;case "a_button":e=a.xbox.buttons.a?1:0;break;case "b_button":e=a.xbox.buttons.b?1:0;break;case "x_button":e=a.xbox.buttons.x?1:0;break;case "y_button":e=a.xbox.buttons.y?1:0;break;case "lb_button":e=a.xbox.buttons.lb?1:0;break;case "rb_button":e=a.xbox.buttons.rb?1:0;break;case "ls_button":e=a.xbox.buttons.ls?
1:0;break;case "rs_button":e=a.xbox.buttons.rs?1:0;break;case "start_button":e=a.xbox.buttons.start?1:0;break;case "back_button":e=a.xbox.buttons.back?1:0}else switch(d.name){case "left_axis":case "right_axis":e=[0,0];break;default:e=0}this.setOutputData(c,e)}};a.prototype.getGamepad=function(){var a=navigator.getGamepads||navigator.webkitGetGamepads||navigator.mozGetGamepads;if(!a)return null;for(var c=a.call(navigator),a=null,d=0;4>d;d++)if(c[d]){a=c[d];c=this.xbox_mapping;c||(c=this.xbox_mapping=
{axes:[],buttons:{},hat:""});c.axes.lx=a.axes[0];c.axes.ly=a.axes[1];c.axes.rx=a.axes[2];c.axes.ry=a.axes[3];c.axes.ltrigger=a.buttons[6].value;c.axes.rtrigger=a.buttons[7].value;for(d=0;d<a.buttons.length;d++)switch(d){case 0:c.buttons.a=a.buttons[d].pressed;break;case 1:c.buttons.b=a.buttons[d].pressed;break;case 2:c.buttons.x=a.buttons[d].pressed;break;case 3:c.buttons.y=a.buttons[d].pressed;break;case 4:c.buttons.lb=a.buttons[d].pressed;break;case 5:c.buttons.rb=a.buttons[d].pressed;break;case 6:c.buttons.lt=
a.buttons[d].pressed;break;case 7:c.buttons.rt=a.buttons[d].pressed;break;case 8:c.buttons.back=a.buttons[d].pressed;break;case 9:c.buttons.start=a.buttons[d].pressed;break;case 10:c.buttons.ls=a.buttons[d].pressed;break;case 11:c.buttons.rs=a.buttons[d].pressed;break;case 12:a.buttons[d].pressed&&(c.hat+="up");break;case 13:a.buttons[d].pressed&&(c.hat+="down");break;case 14:a.buttons[d].pressed&&(c.hat+="left");break;case 15:a.buttons[d].pressed&&(c.hat+="right");break;case 16:c.buttons.home=a.buttons[d].pressed}a.xbox=
c;return a}};a.prototype.onDrawBackground=function(a){};a.prototype.onGetOutputs=function(){return[["left_axis","vec2"],["right_axis","vec2"],["left_x_axis","number"],["left_y_axis","number"],["right_x_axis","number"],["right_y_axis","number"],["trigger_left","number"],["trigger_right","number"],["a_button","number"],["b_button","number"],["x_button","number"],["y_button","number"],["lb_button","number"],["rb_button","number"],["ls_button","number"],["rs_button","number"],["start","number"],["back",
"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.addProperty("in",0);this.addProperty("in_min",0);this.addProperty("in_max",1);this.addProperty("out_min",0);this.addProperty("out_max",1)}function d(){this.addOutput("value","number");this.addProperty("min",0);this.addProperty("max",1);this.size=[60,20]}function e(){this.addInput("in",
"number");this.addOutput("out","number");this.size=[60,20];this.addProperty("min",0);this.addProperty("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 n(){this.addInput("in","number",{label:""});this.addOutput("out","number",{label:""});this.size=[60,20];this.addProperty("factor",1)}function l(){this.addInput("in","number");this.addOutput("out","number");this.size=[60,20];this.addProperty("samples",10);this._values=new Float32Array(10);this._current=0}function p(){this.addInput("A","number");this.addInput("B","number");this.addOutput("=","number");this.addProperty("A",1);this.addProperty("B",1);this.addProperty("OP","+","string",{values:p.values})}
function r(){this.addInput("A","number");this.addInput("B","number");this.addOutput("A==B","boolean");this.addOutput("A!=B","boolean");this.addProperty("A",0);this.addProperty("B",0)}function s(){this.addInput("A","number");this.addInput("B","number");this.addOutput("out","boolean");this.addProperty("A",1);this.addProperty("B",1);this.addProperty("OP",">","string",{values:s.values});this.size=[60,40]}function u(){this.addInput("inc","number");this.addOutput("total","number");this.addProperty("increment",
1);this.addProperty("value",0)}function t(){this.addInput("v","number");this.addOutput("sin","number");this.addProperty("amplitude",1);this.addProperty("offset",0);this.bgImageUrl="nodes/imgs/icon-sin.png"}function v(){this.addInput("vec2","vec2");this.addOutput("x","number");this.addOutput("y","number")}function w(){this.addInputs([["x","number"],["y","number"]]);this.addOutput("vec2","vec2");this.properties={x:0,y:0};this._data=new Float32Array(2)}function x(){this.addInput("vec3","vec3");this.addOutput("x",
"number");this.addOutput("y","number");this.addOutput("z","number")}function y(){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 z(){this.addInput("vec4","vec4");this.addOutput("x","number");this.addOutput("y","number");this.addOutput("z","number");this.addOutput("w","number")}function A(){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=4}d=new Float32Array(d);
if(a.length)for(c=0;c<a.length&&c<d.length;c++)d[c]=a[c];else d[0]=parseFloat(a)}this.setOutputData(b,d)}}};a.prototype.onGetOutputs=function(){return[["number","number"],["vec2","vec2"],["vec3","vec3"],["vec4","vec4"]]};LiteGraph.registerNodeType("math/converter",a);b.title="Bypass";b.desc="removes the type";b.prototype.onExecute=function(){var a=this.getInputData(0);this.setOutputData(0,a)};LiteGraph.registerNodeType("math/bypass",b);c.title="Range";c.desc="Convert a number from one range to another";
c.prototype.onExecute=function(){if(this.inputs)for(var a=0;a<this.inputs.length;a++){var b=this.inputs[a],c=this.getInputData(a);void 0!==c&&(this.properties[b.name]=c)}c=this.properties["in"];if(void 0===c||null===c||c.constructor!==Number)c=0;a=this.properties.in_min;b=this.properties.out_min;this._last_v=(c-a)/(this.properties.in_max-a)*(this.properties.out_max-b)+b;this.setOutputData(0,this._last_v)};c.prototype.onDrawBackground=function(a){this.outputs[0].label=this._last_v?this._last_v.toFixed(3):
"?"};c.prototype.onGetInputs=function(){return[["in_min","number"],["in_max","number"],["out_min","number"],["out_max","number"]]};LiteGraph.registerNodeType("math/range",c);d.title="Rand";d.desc="Random number";d.prototype.onExecute=function(){if(this.inputs)for(var a=0;a<this.inputs.length;a++){var b=this.inputs[a],c=this.getInputData(a);void 0!==c&&(this.properties[b.name]=c)}a=this.properties.min;b=this.properties.max;this._last_v=Math.random()*(b-a)+a;this.setOutputData(0,this._last_v)};d.prototype.onDrawBackground=
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);n.title="Scale";n.desc="v * factor";n.prototype.onExecute=
function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,a*this.properties.factor)};LiteGraph.registerNodeType("math/scale",n);l.title="Average";l.desc="Average Filter";l.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=0);var b=this._values.length;this._values[this._current%b]=a;this._current+=1;this._current>b&&(this._current=0);for(var c=a=0;c<b;++c)a+=this._values[c];this.setOutputData(0,a/b)};l.prototype.onPropertyChanged=function(a,b){1>b&&(b=1);this.properties.samples=
Math.round(b);var c=this._values;this._values=new Float32Array(this.properties.samples);c.length<=this._values.length?this._values.set(c):this._values.set(c.subarray(0,this._values.length))};LiteGraph.registerNodeType("math/average",l);p.values="+-*/%^".split("");p.title="Operation";p.desc="Easy math operators";p["@OP"]={type:"enum",title:"operation",values:p.values};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 "x":case "X":case "*":c=a*b;break;case "/":c=a/b;break;case "%":c=a%b;break;case "^":c=Math.pow(a,b);break;default:console.warn("Unknown operation: "+this.properties.OP)}this.setOutputData(0,c)};p.prototype.onDrawBackground=function(a){this.flags.collapsed||(a.font="40px Arial",
a.fillStyle="black",a.textAlign="center",a.fillText(this.properties.OP,0.5*this.size[0],0.5*this.size[1]+LiteGraph.NODE_TITLE_HEIGHT),a.textAlign="left")};LiteGraph.registerNodeType("math/operation",p);r.title="Compare";r.desc="compares between two values";r.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)}}};r.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",r);s.values="> < == != <= >=".split(" ");s["@OP"]={type:"enum",title:"operation",
values:s.values};s.title="Condition";s.desc="evaluates condition between A and B";s.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",
s);u.title="Accumulate";u.desc="Increments a value every time";u.prototype.onExecute=function(){null===this.properties.value&&(this.properties.value=0);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",u);t.title="Trigonometry";t.desc="Sin Cos Tan";t.filter="shader";t.prototype.onExecute=function(){var a=this.getInputData(0);null==
a&&(a=0);var 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)}};t.prototype.onGetInputs=function(){return[["v","number"],["amplitude","number"],["offset","number"]]};t.prototype.onGetOutputs=function(){return[["sin","number"],["cos","number"],["tan","number"],["asin","number"],["acos","number"],["atan","number"]]};LiteGraph.registerNodeType("math/trigonometry",t);if(window.math){var q=function(){this.addInputs("x","number");this.addInputs("y","number");this.addOutputs("","number");this.properties={x:1,y:1,formula:"x+y"}};q.title="Formula";q.desc=
"Compute safe formula";q.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)};q.prototype.onDrawBackground=function(){this.outputs[0].label=this.properties.formula};q.prototype.onGetOutputs=function(){return[["A-B","number"],["A*B","number"],["A/B","number"]]};LiteGraph.registerNodeType("math/formula",
q)}v.title="Vec2->XY";v.desc="vector 2 to components";v.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",v);w.title="XY->Vec2";w.desc="components to vector2";w.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",
w);x.title="Vec3->XYZ";x.desc="vector 3 to components";x.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",x);y.title="XYZ->Vec3";y.desc="components to vector3";y.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",y);z.title="Vec4->XYZW";z.desc="vector 4 to components";z.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",z);A.title="XYZW->Vec4";A.desc="components to vector4";A.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",A);window.glMatrix&&(q=function(){this.addOutput("quat","quat");this.properties={x:0,y:0,z:0,w:1};this._value=quat.create()},q.title="Quaternion",q.desc="quaternion",q.prototype.onExecute=
function(){this._value[0]=this.properties.x;this._value[1]=this.properties.y;this._value[2]=this.properties.z;this._value[3]=this.properties.w;this.setOutputData(0,this._value)},LiteGraph.registerNodeType("math3d/quaternion",q),q=function(){this.addInputs([["degrees","number"],["axis","vec3"]]);this.addOutput("quat","quat");this.properties={angle:90,axis:vec3.fromValues(0,1,0)};this._value=quat.create()},q.title="Rotation",q.desc="quaternion rotation",q.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(this._value,b,0.0174532925*a);this.setOutputData(0,a)},LiteGraph.registerNodeType("math3d/rotation",q),q=function(){this.addInputs([["vec3","vec3"],["quat","quat"]]);this.addOutput("result","vec3");this.properties={vec:[0,0,1]}},q.title="Rot. Vec3",q.desc="rotate a point",q.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",q),q=function(){this.addInputs([["A","quat"],["B","quat"]]);this.addOutput("A*B","quat");this._value=quat.create()},q.title="Mult. Quat",q.desc="rotate quaternion",q.prototype.onExecute=function(){var a=this.getInputData(0);if(null!=a){var b=this.getInputData(1);null!=b&&(a=quat.multiply(this._value,a,b),this.setOutputData(0,a))}},LiteGraph.registerNodeType("math3d/mult-quat",
q),q=function(){this.addInputs([["A","quat"],["B","quat"],["factor","number"]]);this.addOutput("slerp","quat");this.addProperty("factor",0.5);this._value=quat.create()},q.title="Quat Slerp",q.desc="quaternion spherical interpolation",q.prototype.onExecute=function(){var a=this.getInputData(0);if(null!=a){var b=this.getInputData(1);if(null!=b){var c=this.properties.factor;null!=this.getInputData(2)&&(c=this.getInputData(2));a=quat.slerp(this._value,a,b,c);this.setOutputData(0,a)}}},LiteGraph.registerNodeType("math3d/quat-slerp",
q))})();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.addOutput("","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.supported_extensions=["jpg","jpeg","png","gif"];a.prototype.onAdded=function(){""!=this.properties.url&&
null==this.img&&this.loadImage(this.properties.url)};a.prototype.onDrawBackground=function(a){this.img&&5<this.size[0]&&5<this.size[1]&&a.drawImage(this.img,0,0,this.size[0],this.size[1])};a.prototype.onExecute=function(){this.img||(this.boxcolor="#000");this.img&&this.img.width?this.setOutputData(0,this.img):this.setOutputData(0,null);this.img&&this.img.dirty&&(this.img.dirty=!1)};a.prototype.onPropertyChanged=function(a,b){this.properties[a]=b;"url"==a&&""!=b&&this.loadImage(b);return!0};a.prototype.loadImage=
function(a,b){if(""==a)this.img=null;else{this.img=document.createElement("img");"http://"==a.substr(0,7)&&LiteGraph.proxy&&(a=LiteGraph.proxy+a.substr(7));this.img.src=a;this.boxcolor="#F95";var c=this;this.img.onload=function(){b&&b(this);c.trace("Image loaded, size: "+c.img.width+"x"+c.img.height);this.dirty=!0;c.boxcolor="#9F9";c.setDirtyCanvas(!0)}}};a.prototype.onWidget=function(a,b){"load"==b.name&&this.loadImage(this.properties.url)};a.prototype.onDropFile=function(a){var b=this;this._url&&
URL.revokeObjectURL(this._url);this._url=URL.createObjectURL(a);this.properties.url=this._url;this.loadImage(this._url,function(a){b.size[1]=a.height/a.width*b.size[0]})};LiteGraph.registerNodeType("graphics/image",a);b.title="Palette";b.desc="Generates a color";b.prototype.onExecute=function(){var a=[];null!=this.properties.colorA&&a.push(hex2num(this.properties.colorA));null!=this.properties.colorB&&a.push(hex2num(this.properties.colorB));null!=this.properties.colorC&&a.push(hex2num(this.properties.colorC));
null!=this.properties.colorD&&a.push(hex2num(this.properties.colorD));var b=this.getInputData(0);null==b&&(b=0.5);1<b?b=1:0>b&&(b=0);if(0!=a.length){var c=[0,0,0];if(0==b)c=a[0];else if(1==b)c=a[a.length-1];else{var d=(a.length-1)*b,b=a[Math.floor(d)],a=a[Math.floor(d)+1],d=d-Math.floor(d);c[0]=b[0]*(1-d)+a[0]*d;c[1]=b[1]*(1-d)+a[1]*d;c[2]=b[2]*(1-d)+a[2]*d}for(var e in c)c[e]/=255;this.boxcolor=colorToString(c);this.setOutputData(0,c)}};LiteGraph.registerNodeType("color/palette",b);c.title="Frame";
c.desc="Frame viewerew";c.widgets=[{name:"resize",text:"Resize box",type:"button"},{name:"view",text:"View Image",type:"button"}];c.prototype.onDrawBackground=function(a){this.frame&&a.drawImage(this.frame,0,0,this.size[0],this.size[1])};c.prototype.onExecute=function(){this.frame=this.getInputData(0);this.setDirtyCanvas(!0)};c.prototype.onWidget=function(a,b){if("resize"==b.name&&this.frame){var c=this.frame.width,d=this.frame.height;c||null==this.frame.videoWidth||(c=this.frame.videoWidth,d=this.frame.videoHeight);
c&&d&&(this.size=[c,d]);this.setDirtyCanvas(!0,!0)}else"view"==b.name&&this.show()};c.prototype.show=function(){showElement&&this.frame&&showElement(this.frame)};LiteGraph.registerNodeType("graphics/frame",c);d.title="Image fade";d.desc="Fades between images";d.widgets=[{name:"resizeA",text:"Resize to A",type:"button"},{name:"resizeB",text:"Resize to B",type:"button"}];d.prototype.onAdded=function(){this.createCanvas();var a=this.canvas.getContext("2d");a.fillStyle="#000";a.fillRect(0,0,this.properties.width,
this.properties.height)};d.prototype.createCanvas=function(){this.canvas=document.createElement("canvas");this.canvas.width=this.properties.width;this.canvas.height=this.properties.height};d.prototype.onExecute=function(){var a=this.canvas.getContext("2d");this.canvas.width=this.canvas.width;var b=this.getInputData(0);null!=b&&a.drawImage(b,0,0,this.canvas.width,this.canvas.height);b=this.getInputData(2);null==b?b=this.properties.fade:this.properties.fade=b;a.globalAlpha=b;b=this.getInputData(1);
null!=b&&a.drawImage(b,0,0,this.canvas.width,this.canvas.height);a.globalAlpha=1;this.setOutputData(0,this.canvas);this.setDirtyCanvas(!0)};LiteGraph.registerNodeType("graphics/imagefade",d);e.title="Crop";e.desc="Crop Image";e.prototype.onAdded=function(){this.createCanvas()};e.prototype.createCanvas=function(){this.canvas=document.createElement("canvas");this.canvas.width=this.properties.width;this.canvas.height=this.properties.height};e.prototype.onExecute=function(){var a=this.getInputData(0);
a&&(a.width?(this.canvas.getContext("2d").drawImage(a,-this.properties.x,-this.properties.y,a.width*this.properties.scale,a.height*this.properties.scale),this.setOutputData(0,this.canvas)):this.setOutputData(0,null))};e.prototype.onDrawBackground=function(a){this.flags.collapsed||this.canvas&&a.drawImage(this.canvas,0,0,this.canvas.width,this.canvas.height,0,0,this.size[0],this.size[1])};e.prototype.onPropertyChanged=function(a,b){this.properties[a]=b;"scale"==a?(this.properties[a]=parseFloat(b),
0==this.properties[a]&&(this.trace("Error in scale"),this.properties[a]=1)):this.properties[a]=parseInt(b);this.createCanvas();return!0};LiteGraph.registerNodeType("graphics/cropImage",e);f.title="Video";f.desc="Video playback";f.widgets=[{name:"play",text:"PLAY",type:"minibutton"},{name:"stop",text:"STOP",type:"minibutton"},{name:"demo",text:"Demo video",type:"button"},{name:"mute",text:"Mute video",type:"button"}];f.prototype.onExecute=function(){if(this.properties.url&&(this.properties.url!=this._video_url&&
this.loadVideo(this.properties.url),this._video&&0!=this._video.width)){var a=this.getInputData(0);a&&0<=a&&1>=a&&(this._video.currentTime=a*this._video.duration,this._video.pause());this._video.dirty=!0;this.setOutputData(0,this._video);this.setOutputData(1,this._video.currentTime);this.setOutputData(2,this._video.duration);this.setDirtyCanvas(!0)}};f.prototype.onStart=function(){this.play()};f.prototype.onStop=function(){this.stop()};f.prototype.loadVideo=function(a){this._video_url=a;this._video=
(function(e){function d(a,b){return Math.sqrt((b[0]-a[0])*(b[0]-a[0])+(b[1]-a[1])*(b[1]-a[1]))}function g(a,b,c,f,l,d){return c<a&&c+l>a&&f<b&&f+d>b?!0:!1}function k(a,b){return a[0]>b[2]||a[1]>b[3]||a[2]<b[0]||a[3]<b[1]?!1:!0}var h=e.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:"",INPUT:1,OUTPUT:2,EVENT:-1,ACTION:-1,ALWAYS:0,ON_EVENT:1,NEVER:2,proxy:null,debug:!1,throw_errors:!0,registered_node_types:{},node_types_by_file_extension:{},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;h.debug&&console.log("Node registered: "+a);a.split("/");var c=a.lastIndexOf("/");b.category=a.substr(0,c);if(b.prototype)for(var f in LGraphNode.prototype)b.prototype[f]||
(b.prototype[f]=LGraphNode.prototype[f]);this.registered_node_types[a]=b;b.constructor.name&&(this.Nodes[b.constructor.name]=b);b.prototype.onPropertyChange&&console.warn("LiteGraph node class "+a+" has onPropertyChange method, it must be called onPropertyChanged with d at the end");if(b.supported_extensions)for(f in b.supported_extensions)this.node_types_by_file_extension[b.supported_extensions[f].toLowerCase()]=b},addNodeMethod:function(a,b){LGraphNode.prototype[a]=b;for(var c in this.registered_node_types){var f=
this.registered_node_types[c];f.prototype[a]&&(f.prototype["_"+a]=f.prototype[a]);f.prototype[a]=b}},createNode:function(a,b,c){var f=this.registered_node_types[a];if(!f)return h.debug&&console.log('GraphNode type "'+a+'" not registered.'),null;b=b||f.title||a;f=new f(name);f.type=a;f.title||(f.title=b);f.properties||(f.properties={});f.properties_info||(f.properties_info=[]);f.flags||(f.flags={});f.size||(f.size=f.computeSize());f.pos||(f.pos=h.DEFAULT_POSITION.concat());f.mode||(f.mode=h.ALWAYS);
if(c)for(var l in c)f[l]=c[l];return f},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=[],f;for(f in b)c.push(b[f]);b=document.getElementsByTagName("head")[0];a=document.location.href+a;for(f in c){var l=c[f].src;if(l&&l.substr(0,a.length)==a)try{h.debug&&console.log("Reloading: "+l);var d=document.createElement("script");d.type="text/javascript";d.src=l;b.appendChild(d);b.removeChild(c[f])}catch(e){if(h.throw_errors)throw e;h.debug&&
console.log("Error while reloading "+l)}}h.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 f in c)b[f]=c[f];return b},isValidConnection:function(a,b){return!a||!b||a==a||a!==h.EVENT&&b!==h.EVENT&&a.toLowerCase()==b.toLowerCase()?!0:!1}};h.getTime="undefined"!=typeof performance?function(){return performance.now()}:function(){return Date.now()};e.LGraph=h.LGraph=function(){h.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){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=h.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=h.getTime();this.globaltime=0.001*(b-this.starttime);var c=this._nodes_in_order?this._nodes_in_order:this._nodes;if(c){try{for(var f=0;f<a;f++){for(var l=0,d=c.length;l<d;++l){var e=c[l];if(e.mode==h.ALWAYS&&e.onExecute)e.onExecute()}this.fixedtime+=this.fixedtime_lapse;if(this.onExecuteStep)this.onExecuteStep()}if(this.onAfterExecute)this.onAfterExecute();
this.errors_in_execution=!1}catch(g){this.errors_in_execution=!0;if(h.throw_errors)throw g;h.debug&&console.log("Error during execution: "+g);this.stop()}a=h.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(){for(var a=[],b=[],c={},f={},l={},d=0,e=this._nodes.length;d<e;++d){var g=this._nodes[d];c[g.id]=g;
var k=0;if(g.inputs)for(var q=0,p=g.inputs.length;q<p;q++)g.inputs[q]&&null!=g.inputs[q].link&&(k+=1);0==k?b.push(g):l[g.id]=k}for(;0!=b.length;)if(g=b.shift(),a.push(g),delete c[g.id],g.outputs)for(d=0;d<g.outputs.length;d++)if(e=g.outputs[d],null!=e&&null!=e.links&&0!=e.links.length)for(q=0;q<e.links.length;q++)(k=this.links[e.links[q]])&&!f[k.id]&&(p=this.getNodeById(k.target_id),null==p?f[k.id]=!0:(f[k.id]=!0,l[p.id]-=1,0==l[p.id]&&b.push(p)));for(d in c)a.push(c[d]);a.length!=this._nodes.length&&
h.debug&&console.warn("something went wrong, nodes missing");for(d=0;d<a.length;++d)a[d].order=d;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,c){c=c||h.ALWAYS;var f=this._nodes_in_order?this._nodes_in_order:this._nodes;if(f)for(var l=0,d=f.length;l<d;++l){var e=f[l];if(e[a]&&e.mode==c)if(void 0===
b)e[a]();else if(b&&b.constructor===Array)e[a].apply(e,b);else e[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 f=this.list_of_graphcanvas[c];f[a]&&f[a].apply(f,b)}};LGraph.prototype.add=function(a,b){if(a&&(-1==a.id||null==this._nodes_by_id[a.id])){if(this._nodes.length>=h.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);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);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,f=this._nodes.length;c<f;++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,f=this._nodes.length;c<f;++c)this._nodes[c].type.toLowerCase()==a&&b.push(this._nodes[c]);return b};LGraph.prototype.findNodesByTitle=function(a){for(var b=[],c=0,f=this._nodes.length;c<f;++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 f=c.length-1;0<=f;f--){var l=c[f];if(l.isPointInsideNode(a,b,2))return l}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){for(var c=this.findNodesByName(a),f=0,l=c.length;f<l;++f)c[f].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),f=0;f<c.length;++f)c[f].onTrigger(b)};LGraph.prototype.setCallback=function(a,b){for(var c=this.findNodesByName(a),f=0;f<c.length;++f)c[f].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(){h.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)c=this.links[b],c.data=null,delete c._last_time;return{iteration:this.iteration,frame:this.frame,last_node_id:this.last_node_id,last_link_id:this.last_link_id,links:h.cloneObject(this.links),config:this.config,nodes:a}};LGraph.prototype.configure=function(a,b){b||this.clear();
var c=a.nodes,f;for(f in a)this[f]=a[f];var l=!1;this._nodes=[];f=0;for(var d=c.length;f<d;++f){var e=c[f],g=h.createNode(e.type,e.title);g?(g.id=e.id,this.add(g,!0)):(h.debug&&console.log("Node not found: "+e.type),l=!0)}f=0;for(d=c.length;f<d;++f)e=c[f],(g=this.getNodeById(e.id))&&g.configure(e);this.updateExecutionOrder();this.setDirtyCanvas(!0,!0);return l};LGraph.prototype.load=function(a){var b=this,c=new XMLHttpRequest;c.open("GET",a,!0);c.send(null);c.onload=function(a){200!==c.status?console.error("Error loading graph:",
c.status,c.response):(a=JSON.parse(c.response),b.configure(a))};c.onerror=function(a){console.error("Error loading graph:",a)}};LGraph.prototype.onNodeTrace=function(a,b,c){};e.LGraphNode=h.LGraphNode=function(a){this._ctor()};LGraphNode.prototype._ctor=function(a){this.title=a||"Unnamed";this.size=[h.NODE_WIDTH,60];this.graph=null;this._pos=new Float32Array(10,10);Object.defineProperty(this,"pos",{set:function(a){!a||2>!a.length||(this._pos[0]=a[0],this._pos[1]=a[1])},get:function(){return this._pos},
enumerable:!0});this.id=-1;this.type=null;this.inputs=[];this.outputs=[];this.connections=[];this.properties={};this.properties_info=[];this.data=null;this.flags={}};LGraphNode.prototype.configure=function(a){for(var b in a)if("console"!=b)if("properties"==b)for(var c in a.properties){if(this.properties[c]=a.properties[c],this.onPropertyChanged)this.onPropertyChanged(c,a.properties[c])}else null!=a[b]&&("object"==typeof a[b]?this[b]&&this[b].configure?this[b].configure(a[b]):this[b]=h.cloneObject(a[b],
this[b]):this[b]=a[b]);if(this.onConnectionsChange){if(this.inputs)for(var f=0;f<this.inputs.length;++f){c=this.inputs[f];var l=this.graph.links[c.link];this.onConnectionsChange(h.INPUT,f,!0,l)}if(this.outputs)for(f=0;f<this.outputs.length;++f)for(c=this.outputs[f],b=0;b<c.links.length;++b)l=this.graph.links[c.links[b]],this.onConnectionsChange(h.OUTPUT,f,!0,l)}for(f in this.inputs)c=this.inputs[f],c.link&&c.link.length&&(l=c.link,"object"==typeof l&&(c.link=l[0],this.graph.links[l[0]]={id:l[0],origin_id:l[1],
origin_slot:l[2],target_id:l[3],target_slot:l[4]}));for(f in this.outputs)if(c=this.outputs[f],c.links&&0!=c.links.length)for(b in c.links)l=c.links[b],"object"==typeof l&&(c.links[b]=l[0]);if(this.onConfigure)this.onConfigure(a)};LGraphNode.prototype.serialize=function(){var a={id:this.id,title:this.title,type:this.type,pos:this.pos,size:this.size,data:this.data,flags:h.cloneObject(this.flags),inputs:this.inputs,outputs:this.outputs,mode:this.mode};this.properties&&(a.properties=h.cloneObject(this.properties));
a.type||(a.type=this.constructor.type);this.color&&(a.color=this.color);this.bgcolor&&(a.bgcolor=this.bgcolor);this.boxcolor&&(a.boxcolor=this.boxcolor);this.shape&&(a.shape=this.shape);if(this.onSerialize)this.onSerialize(a);return a};LGraphNode.prototype.clone=function(){var a=h.createNode(this.type),b=h.cloneObject(this.serialize());if(b.inputs)for(var c=0;c<b.inputs.length;++c)b.inputs[c].link=null;if(b.outputs)for(c=0;c<b.outputs.length;++c)b.outputs[c].links&&(b.outputs[c].links.length=0);delete b.id;
a.configure(b);return a};LGraphNode.prototype.toString=function(){return JSON.stringify(this.serialize())};LGraphNode.prototype.getTitle=function(){return this.title||this.constructor.title};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,b){if(this.inputs&&!(a>=this.inputs.length||
null==this.inputs[a].link)){var c=this.graph.links[this.inputs[a].link];if(!b)return c.data;var f=this.graph.getNodeById(c.origin_id);if(!f)return c.data;if(f.updateOutputData)f.updateOutputData(c.origin_slot);else if(f.onExecute)f.onExecute();return c.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.getInputNode=
function(a){if(!this.inputs||a>=this.inputs.length)return null;a=this.inputs[a];return a&&a.link?(a=this.graph.links[a.link])?this.graph.getNodeById(a.origin_id):null:null};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.trigger=function(a,b){if(this.outputs&&this.outputs.length){this.graph&&(this.graph._last_trigger_time=h.getTime());for(var c=0;c<this.outputs.length;++c){var f=this.outputs[c];if(!(f.type!==h.EVENT||a&&f.name!=a)&&(f=f.links)&&f.length)for(var l=0;l<f.length;++l){var d=this.graph.links[f[l]];
if(d){var e=this.graph.getNodeById(d.target_id);if(e)if(d._last_time=h.getTime(),d=e.inputs[d.target_slot],e.onAction)e.onAction(d.name,b);else if(e.mode===h.ON_TRIGGER&&e.onExecute)e.onExecute(b)}}}}};LGraphNode.prototype.addProperty=function(a,b,c,f){c={name:a,type:c,default_value:b};if(f)for(var l in f)c[l]=f[l];this.properties_info||(this.properties_info=[]);this.properties_info.push(c);this.properties||(this.properties={});this.properties[a]=b;return c};LGraphNode.prototype.addOutput=function(a,
b,c){a={name:a,type:b,links:null};if(c)for(var f in c)a[f]=c[f];this.outputs||(this.outputs=[]);this.outputs.push(a);if(this.onOutputAdded)this.onOutputAdded(a);this.size=this.computeSize();return a};LGraphNode.prototype.addOutputs=function(a){for(var b=0;b<a.length;++b){var c=a[b],f={name:c[0],type:c[1],link:null};if(a[2])for(var l in c[2])f[l]=c[2][l];this.outputs||(this.outputs=[]);this.outputs.push(f);if(this.onOutputAdded)this.onOutputAdded(f)}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 f in c)a[f]=c[f];this.inputs||(this.inputs=[]);this.inputs.push(a);this.size=this.computeSize();if(this.onInputAdded)this.onInputAdded(a);return a};LGraphNode.prototype.addInputs=function(a){for(var b=0;b<a.length;++b){var c=a[b],f={name:c[0],type:c[1],link:null};if(a[2])for(var l in c[2])f[l]=
c[2][l];this.inputs||(this.inputs=[]);this.inputs.push(f);if(this.onInputAdded)this.onInputAdded(f)}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,f){a={name:a,type:b,pos:c,direction:f,links:null};this.connections.push(a);return a};LGraphNode.prototype.computeSize=function(a,b){function c(a){return a?
d*a.length*0.6:0}var f=Math.max(this.inputs?this.inputs.length:1,this.outputs?this.outputs.length:1),l=b||new Float32Array([0,0]),f=Math.max(f,1);l[1]=14*f+6;var d=14,f=c(this.title),e=0,g=0;if(this.inputs)for(var k=0,q=this.inputs.length;k<q;++k){var p=this.inputs[k],p=p.label||p.name||"",p=c(p);e<p&&(e=p)}if(this.outputs)for(k=0,q=this.outputs.length;k<q;++k)p=this.outputs[k],p=p.label||p.name||"",p=c(p),g<p&&(g=p);l[0]=Math.max(e+g+10,f);l[0]=Math.max(l[0],h.NODE_WIDTH);return l};LGraphNode.prototype.getBounding=
function(){return new Float32Array([this.pos[0]-4,this.pos[1]-h.NODE_TITLE_HEIGHT,this.pos[0]+this.size[0]+4,this.pos[1]+this.size[1]+LGraph.NODE_TITLE_HEIGHT])};LGraphNode.prototype.isPointInsideNode=function(a,b,c){c=c||0;var f=this.graph&&this.graph.isLive()?0:20;if(this.flags.collapsed){if(g(a,b,this.pos[0]-c,this.pos[1]-h.NODE_TITLE_HEIGHT-c,h.NODE_COLLAPSED_WIDTH+2*c,h.NODE_TITLE_HEIGHT+2*c))return!0}else if(this.pos[0]-4-c<a&&this.pos[0]+this.size[0]+4+c>a&&this.pos[1]-f-c<b&&this.pos[1]+this.size[1]+
c>b)return!0;return!1};LGraphNode.prototype.getSlotInPosition=function(a,b){if(this.inputs)for(var c=0,f=this.inputs.length;c<f;++c){var l=this.inputs[c],d=this.getConnectionPos(!0,c);if(g(a,b,d[0]-10,d[1]-5,20,10))return{input:l,slot:c,link_pos:d,locked:l.locked}}if(this.outputs)for(c=0,f=this.outputs.length;c<f;++c)if(l=this.outputs[c],d=this.getConnectionPos(!1,c),g(a,b,d[0]-10,d[1]-5,20,10))return{output:l,slot:c,link_pos:d,locked:l.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 h.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.outputs||a>=this.outputs.length)return h.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 h.debug&&console.log("Connect: Error, no slot of name "+c),!1}else{if(c===h.EVENT)return!1;if(!b.inputs||c>=b.inputs.length)return h.debug&&console.log("Connect: Error, slot number not found"),!1}null!=b.inputs[c].link&&b.disconnectInput(c);this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this);var f=this.outputs[a];if(b.onConnectInput&&
!1===b.onConnectInput(c,f.type,f))return!1;if(h.isValidConnection(f.type,b.inputs[c].type)){var l={id:this.graph.last_link_id++,origin_id:this.id,origin_slot:a,target_id:b.id,target_slot:c};this.graph.links[l.id]=l;null==f.links&&(f.links=[]);f.links.push(l.id);b.inputs[c].link=l.id;if(this.onConnectionsChange)this.onConnectionsChange(h.OUTPUT,a,!0,l);if(b.onConnectionsChange)b.onConnectionsChange(h.INPUT,c,!0,l)}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 h.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.outputs||a>=this.outputs.length)return h.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 f=0,l=c.links.length;f<l;f++){var d=c.links[f],e=this.graph.links[d];if(e.target_id==
b.id){c.links.splice(f,1);b.inputs[e.target_slot].link=null;delete this.graph.links[d];if(b.onConnectionsChange)b.onConnectionsChange(h.INPUT,e.target_slot,!1,e);if(this.onConnectionsChange)this.onConnectionsChange(h.OUTPUT,a,!1,e);break}}}else{f=0;for(l=c.links.length;f<l;f++){d=c.links[f];e=this.graph.links[d];if(b=this.graph.getNodeById(e.target_id))b.inputs[e.target_slot].link=null;delete this.graph.links[d];if(b.onConnectionsChange)b.onConnectionsChange(h.INPUT,e.target_slot,!1,e);if(this.onConnectionsChange)this.onConnectionsChange(h.OUTPUT,
a,!1,e)}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 h.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.inputs||a>=this.inputs.length)return h.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]){var c=this.graph.getNodeById(b.origin_id);
if(!c)return!1;var f=c.outputs[b.origin_slot];if(!f||!f.links||0==f.links.length)return!1;for(var l=0,d=f.links.length;l<d;l++)if(b=f.links[l],b=this.graph.links[b],b.target_id==this.id){f.links.splice(l,1);break}if(this.onConnectionsChange)this.onConnectionsChange(h.INPUT,a,!1,b);if(c.onConnectionsChange)c.onConnectionsChange(h.OUTPUT,l,!1,b)}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*h.NODE_TITLE_HEIGHT]:[this.pos[0]+h.NODE_COLLAPSED_WIDTH,this.pos[1]-0.5*h.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*h.NODE_SLOT_HEIGHT]:[this.pos[0]+this.size[0]+1,this.pos[1]+10+b*h.NODE_SLOT_HEIGHT]};
LGraphNode.prototype.alignToGrid=function(){this.pos[0]=h.CANVAS_GRID_SIZE*Math.round(this.pos[0]/h.CANVAS_GRID_SIZE);this.pos[1]=h.CANVAS_GRID_SIZE*Math.round(this.pos[1]/h.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=h.node_images_path+a;b.ready=!1;var c=this;b.onload=function(){this.ready=!0;c.setDirtyCanvas(!0)};return b};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 f=b[c];if(a||f.node_capturing_input==this)f.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]]};e.LGraphCanvas=h.LGraphCanvas=function(a,b,c){c=c||{};a&&a.constructor===String&&(a=document.querySelector(a));this.max_zoom=10;this.min_zoom=0.1;this.title_text_font="bold 14px Arial";this.inner_text_font="normal 12px Arial";this.default_link_color="#AAC";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.allow_interaction=this.allow_dragnodes=this.allow_dragcanvas=this.show_info=!0;this.render_connections_shadows=this.always_render_background=!1;this.render_connection_arrows=this.render_curved_connections=this.render_connections_border=!0;this.connections_width=4;b&&b.attachCanvas(this);this.setCanvas(a);this.clear();c.skip_render||this.startRendering();this.autoresize=c.autoresize};LGraphCanvas.link_type_colors=
{"-1":"#F85",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.dirty_bgcanvas=this.dirty_canvas=!0;this.node_in_panel=this.dirty_area=null;this.last_mouse=[0,0];this.last_mouseclick=0;if(this.onClear)this.onClear()};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))};LGraphCanvas.prototype.setCanvas=function(a,b){if(a&&a.constructor===String&&(a=document.getElementById(a),!a))throw"Error creating LiteGraph canvas: Canvas not found";if(a!==this.canvas&&(!a&&this.canvas&&(b||this.unbindEvents()),this.canvas=a)){a.className+=" lgraphcanvas";a.data=this;this.bgcanvas=null;this.bgcanvas||(this.bgcanvas=document.createElement("canvas"),this.bgcanvas.width=this.canvas.width,this.bgcanvas.height=this.canvas.height);if(null==a.getContext)throw"This browser doesnt support Canvas";
null==(this.ctx=a.getContext("2d"))&&(console.warn("This canvas seems to be WebGL, enabling WebGL renderer"),this.enableWebGL());this._mousemove_callback=this.processMouseMove.bind(this);this._mouseup_callback=this.processMouseUp.bind(this);b||this.bindEvents()}};LGraphCanvas.prototype._doNothing=function(a){a.preventDefault();return!1};LGraphCanvas.prototype._doReturnTrue=function(a){a.preventDefault();return!0};LGraphCanvas.prototype.bindEvents=function(){if(this._events_binded)console.warn("LGraphCanvas: events already binded");
else{var a=this.canvas;this._mousedown_callback=this.processMouseDown.bind(this);this._mousewheel_callback=this.processMouseWheel.bind(this);a.addEventListener("mousedown",this._mousedown_callback,!0);a.addEventListener("mousemove",this._mousemove_callback);a.addEventListener("mousewheel",this._mousewheel_callback,!1);a.addEventListener("contextmenu",this._doNothing);a.addEventListener("DOMMouseScroll",this._mousewheel_callback,!1);a.addEventListener("touchstart",this.touchHandler,!0);a.addEventListener("touchmove",
this.touchHandler,!0);a.addEventListener("touchend",this.touchHandler,!0);a.addEventListener("touchcancel",this.touchHandler,!0);this._key_callback=this.processKey.bind(this);a.addEventListener("keydown",this._key_callback);a.addEventListener("keyup",this._key_callback);this._ondrop_callback=this.processDrop.bind(this);a.addEventListener("dragover",this._doNothing,!1);a.addEventListener("dragend",this._doNothing,!1);a.addEventListener("drop",this._ondrop_callback,!1);a.addEventListener("dragenter",
this._doReturnTrue,!1);this._events_binded=!0}};LGraphCanvas.prototype.unbindEvents=function(){this._events_binded?(this.canvas.removeEventListener("mousedown",this._mousedown_callback),this.canvas.removeEventListener("mousewheel",this._mousewheel_callback),this.canvas.removeEventListener("DOMMouseScroll",this._mousewheel_callback),this.canvas.removeEventListener("keydown",this._key_callback),this.canvas.removeEventListener("keyup",this._key_callback),this.canvas.removeEventListener("contextmenu",
this._doNothing),this.canvas.removeEventListener("drop",this._ondrop_callback),this.canvas.removeEventListener("dragenter",this._doReturnTrue),this.canvas.removeEventListener("touchstart",this.touchHandler),this.canvas.removeEventListener("touchmove",this.touchHandler),this.canvas.removeEventListener("touchend",this.touchHandler),this.canvas.removeEventListener("touchcancel",this.touchHandler),this._ondrop_callback=this._key_callback=this._mousewheel_callback=this._mousedown_callback=null,this._events_binded=
!1):console.warn("LGraphCanvas: no events binded")};LGraphCanvas.getFileExtension=function(a){var b=a.indexOf("?");-1!=b&&(a=a.substr(0,b));b=a.lastIndexOf(".");return-1==b?"":a.substr(b+1).toLowerCase()};LGraphCanvas.prototype.enableWebGL=function(){if(void 0===typeof GL)throw"litegl.js must be included to use a WebGL canvas";if(void 0===typeof enableWebGLCanvas)throw"webglCanvas.js must be included to use this feature";this.gl=this.ctx=enableWebGLCanvas(this.canvas);this.ctx.webgl=!0;this.bgcanvas=
this.canvas;this.bgctx=this.gl};LGraphCanvas.prototype.setDirty=function(a,b){a&&(this.dirty_canvas=!0);b&&(this.dirty_bgcanvas=!0)};LGraphCanvas.prototype.getCanvasWindow=function(){if(!this.canvas)return window;var a=this.canvas.ownerDocument;return a.defaultView||a.parentWindow};LGraphCanvas.prototype.startRendering=function(){function a(){this.pause_rendering||this.draw();var b=this.getCanvasWindow();this.is_rendering&&b.requestAnimationFrame(a.bind(this))}this.is_rendering||(this.is_rendering=
!0,a.call(this))};LGraphCanvas.prototype.stopRendering=function(){this.is_rendering=!1};LGraphCanvas.prototype.processMouseDown=function(a){if(this.graph){this.adjustMouseEvent(a);var b=this.getCanvasWindow();this.canvas.removeEventListener("mousemove",this._mousemove_callback);b.document.addEventListener("mousemove",this._mousemove_callback,!0);b.document.addEventListener("mouseup",this._mouseup_callback,!0);var c=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes);h.closeAllContextMenus(b);
if(1==a.which){if(!(a.shiftKey||c&&this.selected_nodes[c.id])){var f=[],l;for(l in this.selected_nodes)this.selected_nodes[l]!=c&&f.push(this.selected_nodes[l]);for(l in f)this.processNodeDeselected(f[l])}f=!1;if(c&&this.allow_interaction){this.live_mode||c.flags.pinned||this.bringToFront(c);var d=!1;if(!this.connecting_node&&!c.flags.collapsed&&!this.live_mode){if(c.outputs){l=0;for(var e=c.outputs.length;l<e;++l){var k=c.outputs[l],n=c.getConnectionPos(!1,l);if(g(a.canvasX,a.canvasY,n[0]-10,n[1]-
5,20,10)){this.connecting_node=c;this.connecting_output=k;this.connecting_pos=c.getConnectionPos(!1,l);this.connecting_slot=l;d=!0;break}}}if(c.inputs)for(l=0,e=c.inputs.length;l<e;++l)k=c.inputs[l],n=c.getConnectionPos(!0,l),g(a.canvasX,a.canvasY,n[0]-10,n[1]-5,20,10)&&null!==k.link&&(c.disconnectInput(l),d=this.dirty_bgcanvas=!0);!d&&g(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",d=!0)}!d&&g(a.canvasX,a.canvasY,c.pos[0],
c.pos[1]-h.NODE_TITLE_HEIGHT,h.NODE_TITLE_HEIGHT,h.NODE_TITLE_HEIGHT)&&(c.collapse(),d=!0);if(!d){l=!1;if(300>h.getTime()-this.last_mouseclick&&this.selected_nodes[c.id]){if(c.onDblClick)c.onDblClick(a);this.processNodeDblClicked(c);l=!0}c.onMouseDown&&c.onMouseDown(a,[a.canvasX-c.pos[0],a.canvasY-c.pos[1]])?l=!0:this.live_mode&&(l=f=!0);l||(this.allow_dragnodes&&(this.node_dragged=c),this.selected_nodes[c.id]||this.processNodeSelected(c,a));this.dirty_canvas=!0}}else f=!0;f&&this.allow_dragcanvas&&
(this.dragging_canvas=!0)}else 2!=a.which&&3==a.which&&this.processContextMenu(c,a);this.last_mouse[0]=a.localX;this.last_mouse[1]=a.localY;this.last_mouseclick=h.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 if(this.allow_interaction){this.connecting_node&&(this.dirty_canvas=!0);for(var b=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes),f=
0,l=this.graph._nodes.length;f<l;++f)if(this.graph._nodes[f].mouseOver&&b!=this.graph._nodes[f]){this.graph._nodes[f].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&&(l=this._highlight_input||[0,0],!this.isOverNodeBox(b,a.canvasX,a.canvasY))){var d=
this.isOverNodeInput(b,a.canvasX,a.canvasY,l);-1!=d&&b.inputs[d]?h.isValidConnection(this.connecting_output.type,b.inputs[d].type)&&(this._highlight_input=l):this._highlight_input=null}g(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(f in this.selected_nodes)b=this.selected_nodes[f],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*h.NODE_SLOT_HEIGHT+4&&(this.resizing_node.size[1]=
c*h.NODE_SLOT_HEIGHT+4),this.resizing_node.size[0]<h.NODE_MIN_WIDTH&&(this.resizing_node.size[0]=h.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(this.connecting_output.type==h.EVENT&&this.isOverNodeBox(b,a.canvasX,a.canvasY))this.connecting_node.connect(this.connecting_slot,b,h.EVENT);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),this.connecting_output.type==h.EVENT?this.connecting_node.connect(this.connecting_slot,
b,h.EVENT):c&&!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,[a.canvasX-this.node_over.pos[0],a.canvasY-this.node_over.pos[1]]);if(this.node_capturing_input&&this.node_capturing_input.onMouseUp)this.node_capturing_input.onMouseUp(a,[a.canvasX-this.node_capturing_input.pos[0],a.canvasY-this.node_capturing_input.pos[1]])}else 2==a.which?(this.dirty_canvas=!0,this.dragging_canvas=!1):3==
a.which&&(this.dirty_canvas=!0,this.dragging_canvas=!1);this.graph.change();a.stopPropagation();a.preventDefault();return!1}};LGraphCanvas.prototype.processMouseWheel=function(a){if(this.graph&&this.allow_dragcanvas){var b=null!=a.wheelDeltaY?a.wheelDeltaY:-60*a.detail;this.adjustMouseEvent(a);var c=this.scale;0<b?c*=1.1:0>b&&(c*=1/1.1);this.setZoom(c,[a.localX,a.localY]);this.graph.change();a.preventDefault();return!1}};LGraphCanvas.prototype.isOverNodeBox=function(a,b,c){var f=h.NODE_TITLE_HEIGHT;
return g(b,c,a.pos[0]+2,a.pos[1]+2-f,f-4,f-4)?!0:!1};LGraphCanvas.prototype.isOverNodeInput=function(a,b,c,f){if(a.inputs)for(var l=0,d=a.inputs.length;l<d;++l){var e=a.getConnectionPos(!0,l);if(g(b,c,e[0]-10,e[1]-5,20,10))return f&&(f[0]=e[0],f[1]=e[1]),l}return-1};LGraphCanvas.prototype.processKey=function(a){if(this.graph){var b=!1;if("keydown"==a.type){65==a.keyCode&&a.ctrlKey&&(this.selectAllNodes(),b=!0);if(46==a.keyCode||8==a.keyCode)this.deleteSelectedNodes(),b=!0;if(this.selected_nodes)for(var c in this.selected_nodes)if(this.selected_nodes[c].onKeyDown)this.selected_nodes[c].onKeyDown(a)}else if("keyup"==
a.type&&this.selected_nodes)for(c in this.selected_nodes)if(this.selected_nodes[c].onKeyUp)this.selected_nodes[c].onKeyUp(a);this.graph.change();if(b)return a.preventDefault(),!1}};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||c.onDropData)&&(b=a.dataTransfer.files)&&b.length)for(var f=0;f<b.length;f++){var l=a.dataTransfer.files[0],d=l.name;LGraphCanvas.getFileExtension(d);
if(c.onDropFile)c.onDropFile(l);if(c.onDropData){var e=new FileReader;e.onload=function(a){c.onDropData(a.target.result,d,l)};var g=l.type.split("/")[0];"text"==g||""==g?e.readAsText(l):"image"==g?e.readAsDataURL(l):e.readAsArrayBuffer(l)}}return c.onDropItem&&c.onDropItem(event)?!0:this.onDropItem?this.onDropItem(event):!1}b=null;this.onDropItem&&(b=this.onDropItem(event));b||this.checkDropItem(a)};LGraphCanvas.prototype.checkDropItem=function(a){if(a.dataTransfer.files.length){var b=a.dataTransfer.files[0],
c=LGraphCanvas.getFileExtension(b.name).toLowerCase();if(c=h.node_types_by_file_extension[c])if(c=h.createNode(c.type),c.pos=[a.canvasX,a.canvasY],this.graph.add(c),c.onDropFile)c.onDropFile(b)}};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(a);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=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 f=this.convertOffsetToCanvas(b),c=[f[0]-c[0],f[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(){for(var a=[],b=0,c=this.graph._nodes.length;b<c;++b){var f=this.graph._nodes[b];(!this.live_mode||f.onDrawBackground||f.onDrawForeground)&&k(this.visible_area,f.getBounding())&&a.push(f)}return a};LGraphCanvas.prototype.draw=function(a,b){if(this.canvas){var c=h.getTime();this.render_time=0.001*(c-this.last_draw_time);this.last_draw_time=c;if(this.graph){var f=[-this.offset[0],-this.offset[1]],l=[f[0]+this.canvas.width/
this.scale,f[1]+this.canvas.height/this.scale];this.visible_area=new Float32Array([f[0],f[1],l[0],l[1]])}(this.dirty_bgcanvas||b||this.always_render_background||this.graph&&this.graph._last_trigger_time&&1E3>c-this.graph._last_trigger_time)&&this.drawBackCanvas();(this.dirty_canvas||a)&&this.drawFrontCanvas();this.fps=this.render_time?1/this.render_time:0;this.frame+=1}};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=0;c<b.length;++c){var f=b[c];a.save();a.translate(f.pos[0],f.pos[1]);this.drawNode(f,a);a.restore()}this.graph.config.links_ontop&&(this.live_mode||this.drawConnections(a));if(null!=this.connecting_pos){a.lineWidth=this.connections_width;b=null;switch(this.connecting_output.type){case h.EVENT:b="#F85";break;default:b="#AFA"}this.renderLink(a,this.connecting_pos,[this.canvas_mouse[0],this.canvas_mouse[1]],b);a.beginPath();this.connecting_output.type===
h.EVENT?a.rect(this.connecting_pos[0]-6+0.5,this.connecting_pos[1]-5+0.5,14,10):a.arc(this.connecting_pos[0],this.connecting_pos[1],4,0,2*Math.PI);a.fill();a.fillStyle="#ffcc00";this._highlight_input&&(a.beginPath(),a.arc(this._highlight_input[0],this._highlight_input[1],6,0,2*Math.PI),a.fill())}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;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.imageSmoothingEnabled=b.mozImageSmoothingEnabled=b.imageSmoothingEnabled=!1;if(!this._bg_img||this._bg_img.name!=this.background_image){this._bg_img=new Image;this._bg_img.name=this.background_image;
this._bg_img.src=this.background_image;var c=this;this._bg_img.onload=function(){c.draw(!0,!0)}}var f=null;null==this._pattern&&0<this._bg_img.width?(f=b.createPattern(this._bg_img,"repeat"),this._pattern_img=this._bg_img,this._pattern=f):f=this._pattern;f&&(b.fillStyle=f,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.imageSmoothingEnabled=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||h.NODE_DEFAULT_COLOR,
f=!0;if(a.flags.skip_title_render||a.graph.isLive())f=!1;a.mouseOver&&(f=!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 l=this.editor_alpha;b.globalAlpha=l;var d=a.shape||"box",e=new Float32Array(a.size);a.flags.collapsed&&(e[0]=h.NODE_COLLAPSED_WIDTH,e[1]=0);a.flags.clip_area&&
(b.save(),"box"==d?(b.beginPath(),b.rect(0,0,e[0],e[1])):"round"==d?b.roundRect(0,0,e[0],e[1],10):"circle"==d&&(b.beginPath(),b.arc(0.5*e[0],0.5*e[1],0.5*e[0],0,2*Math.PI)),b.clip());this.drawNodeShape(a,b,e,c,a.bgcolor,!f,a.selected);b.shadowColor="transparent";b.textAlign="left";b.font=this.inner_text_font;f=0.6<this.scale;d=this.connecting_output;if(!a.flags.collapsed){if(a.inputs)for(e=0;e<a.inputs.length;e++){var g=a.inputs[e];b.globalAlpha=l;this.connecting_node&&h.isValidConnection(g.type&&
d.type)&&(b.globalAlpha=0.4*l);b.fillStyle=null!=g.link?"#7F7":"#AAA";var k=a.getConnectionPos(!0,e);k[0]-=a.pos[0];k[1]-=a.pos[1];b.beginPath();g.type===h.EVENT?b.rect(k[0]-6+0.5,k[1]-5+0.5,14,10):b.arc(k[0],k[1],4,0,2*Math.PI);b.fill();f&&(g=null!=g.label?g.label:g.name)&&(b.fillStyle=c,b.fillText(g,k[0]+10,k[1]+5))}this.connecting_node&&(b.globalAlpha=0.4*l);b.lineWidth=1;b.textAlign="right";b.strokeStyle="black";if(a.outputs)for(e=0;e<a.outputs.length;e++)if(g=a.outputs[e],k=a.getConnectionPos(!1,
e),k[0]-=a.pos[0],k[1]-=a.pos[1],b.fillStyle=g.links&&g.links.length?"#7F7":"#AAA",b.beginPath(),g.type===h.EVENT?b.rect(k[0]-6+0.5,k[1]-5+0.5,14,10):b.arc(k[0],k[1],4,0,2*Math.PI),b.fill(),b.stroke(),f&&(g=null!=g.label?g.label:g.name))b.fillStyle=c,b.fillText(g,k[0]-10,k[1]+5);b.textAlign="left";b.globalAlpha=1;if(a.onDrawForeground)a.onDrawForeground(b)}a.flags.clip_area&&b.restore();b.globalAlpha=1}};LGraphCanvas.prototype.drawNodeShape=function(a,b,c,f,l,d,e){b.strokeStyle=f||h.NODE_DEFAULT_COLOR;
b.fillStyle=l||h.NODE_DEFAULT_BGCOLOR;l=h.NODE_TITLE_HEIGHT;var g=a.shape||"box";"box"==g?(b.beginPath(),b.rect(0,d?0:-l,c[0]+1,d?c[1]:c[1]+l),b.fill(),b.shadowColor="transparent",e&&(b.strokeStyle="#CCC",b.strokeRect(-0.5,d?-0.5:-l+-0.5,c[0]+2,d?c[1]+2:c[1]+l+2-1),b.strokeStyle=f)):"round"==a.shape?(b.roundRect(0,d?0:-l,c[0],d?c[1]:c[1]+l,10),b.fill()):"circle"==a.shape&&(b.beginPath(),b.arc(0.5*c[0],0.5*c[1],0.5*c[0],0,2*Math.PI),b.fill());b.shadowColor="transparent";a.bgImage&&a.bgImage.width&&
b.drawImage(a.bgImage,0.5*(c[0]-a.bgImage.width),0.5*(c[1]-a.bgImage.height));a.bgImageUrl&&!a.bgImage&&(a.bgImage=a.loadImage(a.bgImageUrl));if(a.onDrawBackground)a.onDrawBackground(b);d||(b.fillStyle=f||h.NODE_DEFAULT_COLOR,f=b.globalAlpha,b.globalAlpha=0.5*f,"box"==g?(b.beginPath(),b.rect(0,-l,c[0]+1,l),b.fill()):"round"==g&&(b.roundRect(0,-l,c[0],l,10,0),b.fill()),b.fillStyle=a.boxcolor||h.NODE_DEFAULT_BOXCOLOR,b.beginPath(),"round"==g?b.arc(0.5*l,-0.5*l,0.5*(l-6),0,2*Math.PI):b.rect(3,-l+3,l-
6,l-6),b.fill(),b.globalAlpha=f,b.font=this.title_text_font,(a=a.getTitle())&&0.5<this.scale&&(b.fillStyle=h.NODE_TITLE_COLOR,b.fillText(a,16,13-l)))};LGraphCanvas.prototype.drawNodeCollapsed=function(a,b,c,f){b.strokeStyle=c||h.NODE_DEFAULT_COLOR;b.fillStyle=f||h.NODE_DEFAULT_BGCOLOR;c=h.NODE_COLLAPSED_RADIUS;f=a.shape||"box";"circle"==f?(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||h.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"==f?(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||h.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||h.NODE_DEFAULT_BOXCOLOR,b.beginPath(),b.rect(0.5*c,0.5*c,c,c));b.fill()};
LGraphCanvas.prototype.drawConnections=function(a){var b=h.getTime();a.lineWidth=this.connections_width;a.fillStyle="#AAA";a.strokeStyle="#AAA";a.globalAlpha=this.editor_alpha;for(var c=0,f=this.graph._nodes.length;c<f;++c){var l=this.graph._nodes[c];if(l.inputs&&l.inputs.length)for(var d=0;d<l.inputs.length;++d){var e=l.inputs[d];if(e&&null!=e.link){var g=this.graph.links[e.link];if(g){var k=this.graph.getNodeById(g.origin_id);if(null!=k){var q=g.origin_slot,e=null,e=-1==q?[k.pos[0]+10,k.pos[1]+
10]:k.getConnectionPos(!1,q),k=LGraphCanvas.link_type_colors[l.inputs[d].type]||this.default_link_color;this.renderLink(a,e,l.getConnectionPos(!0,d),k);g&&g._last_time&&1E3>b-g._last_time&&(g=2-0.002*(b-g._last_time),k="rgba(255,255,255, "+g.toFixed(2)+")",this.renderLink(a,e,l.getConnectionPos(!0,d),k,!0,g))}}}}}a.globalAlpha=1};LGraphCanvas.prototype.renderLink=function(a,b,c,f,l,e){if(this.highquality_render){var g=d(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*g,b[1],c[0]-0.25*g,c[1],c[0],c[1])):(a.moveTo(b[0]+10,b[1]),a.lineTo(0.5*(b[0]+10+(c[0]-10)),b[1]),a.lineTo(0.5*(b[0]+10+(c[0]-10)),c[1]),a.lineTo(c[0]-10,c[1]));this.render_connections_border&&0.6<this.scale&&!l&&(a.strokeStyle="rgba(0,0,0,0.5)",a.stroke());a.lineWidth=this.connections_width;a.fillStyle=a.strokeStyle=f;a.stroke();if(this.render_connection_arrows&&!(0.6>this.scale)&&(this.render_connection_arrows&&
0.6<this.scale&&(f=this.computeConnectionPoint(b,c,0.5),l=this.computeConnectionPoint(b,c,0.51),g=0,g=this.render_curved_connections?-Math.atan2(l[0]-f[0],l[1]-f[1]):c[1]>b[1]?0:Math.PI,a.save(),a.translate(f[0],f[1]),a.rotate(g),a.beginPath(),a.moveTo(-5,-5),a.lineTo(0,5),a.lineTo(5,-5),a.fill(),a.restore()),e))for(e=0;5>e;++e)f=(0.001*h.getTime()+0.2*e)%1,f=this.computeConnectionPoint(b,c,f),a.beginPath(),a.arc(f[0],f[1],5,0,2*Math.PI),a.fill()}else a.beginPath(),a.moveTo(b[0],b[1]),a.lineTo(c[0],
c[1]),a.stroke()};LGraphCanvas.prototype.computeConnectionPoint=function(a,b,c){var f=d(a,b),l=[a[0]+0.25*f,a[1]],f=[b[0]-0.25*f,b[1]],e=(1-c)*(1-c)*(1-c),g=3*(1-c)*(1-c)*c,h=3*(1-c)*c*c;c*=c*c;return[e*a[0]+g*l[0]+h*f[0]+c*b[0],e*a[1]+g*l[1]+h*f[1]+c*b[1]]};LGraphCanvas.prototype.resize=function(a,b){if(!a&&!b){var c=this.canvas.parentNode;a=c.offsetWidth;b=c.offsetHeight}if(this.canvas.width!=a||this.canvas.height!=b)this.canvas.width=a,this.canvas.height=b,this.bgcanvas.width=this.canvas.width,
this.bgcanvas.height=this.canvas.height,this.setDirty(!0,!0)};LGraphCanvas.prototype.switchLiveMode=function(a){if(a){var b=this,c=this.live_mode?1.1:0.9;this.live_mode&&(this.live_mode=!1,this.editor_alpha=0.1);var f=setInterval(function(){b.editor_alpha*=c;b.dirty_canvas=!0;b.dirty_bgcanvas=!0;1>c&&0.01>b.editor_alpha&&(clearInterval(f),1>c&&(b.live_mode=!0));1<c&&0.99<b.editor_alpha&&(clearInterval(f),b.editor_alpha=1)},1)}else this.live_mode=!this.live_mode,this.dirty_bgcanvas=this.dirty_canvas=
!0};LGraphCanvas.prototype.onNodeSelectionChange=function(a){};LGraphCanvas.prototype.touchHandler=function(a){var b=a.changedTouches[0],c="";switch(a.type){case "touchstart":c="mousedown";break;case "touchmove":c="mousemove";break;case "touchend":c="mouseup";break;default:return}var f=this.getCanvasWindow(),l=f.document.createEvent("MouseEvent");l.initMouseEvent(c,!0,!0,f,1,b.screenX,b.screenY,b.clientX,b.clientY,!1,!1,!1,!1,0,null);b.target.dispatchEvent(l);a.preventDefault()};LGraphCanvas.onMenuAdd=
function(a,b,c,f,l){function d(a,b){var c=h.createNode(a.value);c&&(c.pos=f.convertEventToCanvas(l),f.graph.add(c))}var e=f.getCanvasWindow();a=h.getNodeTypesCategories();var g={},k;for(k in a)a[k]&&(g[k]={value:a[k],content:a[k],is_menu:!0});var q=h.createContextMenu(g,{event:b,callback:function(a,b){var c=h.getNodeTypesInCategory(a.value),f=[],l;for(l in c)f.push({content:c[l].title,value:c[l].type});h.createContextMenu(f,{event:b,callback:d,from:q},e);return!1},from:c},e);return!1};LGraphCanvas.onMenuCollapseAll=
function(){};LGraphCanvas.onMenuNodeEdit=function(){};LGraphCanvas.showMenuNodeInputs=function(a,b,c){function f(b,c,f){a&&(b.callback&&b.callback.call(l,a,b,c,f),b.value&&a.addInput(b.value[0],b.value[1],b.value[2]))}if(a){var l=this,d=this.getCanvasWindow(),e=a.optional_inputs;a.onGetInputs&&(e=a.onGetInputs());var g=[];if(e)for(var k in e){var q=e[k],p=q[0];q[2]&&q[2].label&&(p=q[2].label);g.push({content:p,value:q})}this.onMenuNodeInputs&&(g=this.onMenuNodeInputs(g));if(g.length)return h.createContextMenu(g,
{event:b,callback:f,from:c},d),!1}};LGraphCanvas.showMenuNodeOutputs=function(a,b,c){function f(b,d,e){if(a&&(b.callback&&b.callback.call(l,a,b,d,e),b.value))if(e=b.value[1],!e||e.constructor!==Object&&e.constructor!==Array)a.addOutput(b.value[0],b.value[1],b.value[2]);else{b=[];for(var g in e)b.push({content:g,value:e[g]});h.createContextMenu(b,{event:d,callback:f,from:c});return!1}}if(a){var l=this,e=this.getCanvasWindow(),d=a.optional_outputs;a.onGetOutputs&&(d=a.onGetOutputs());var g=[];if(d)for(var k in d){var q=
d[k];if(!q)g.push(null);else if(-1==a.findOutputSlot(q[0])){var p=q[0];q[2]&&q[2].label&&(p=q[2].label);p={content:p,value:q};q[1]==h.EVENT&&(p.className="event");g.push(p)}}this.onMenuNodeOutputs&&(g=this.onMenuNodeOutputs(g));if(g.length)return h.createContextMenu(g,{event:b,callback:f,from:c},e),!1}};LGraphCanvas.onShowMenuNodeProperties=function(a,b,c){function f(b,c,f){a&&e.showEditPropertyValue(a,b.value,{event:c})}if(a&&a.properties){var e=this,d=this.getCanvasWindow(),g=[],k;for(k in a.properties){var n=
void 0!==a.properties[k]?a.properties[k]:" ",n=LGraphCanvas.decodeHTML(n);g.push({content:"<span class='property_name'>"+k+"</span><span class='property_value'>"+n+"</span>",value:k})}if(g.length)return h.createContextMenu(g,{event:b,callback:f,from:c,allow_html:!0},d),!1}};LGraphCanvas.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};LGraphCanvas.onShowTitleEditor=function(a,b){function c(){a.title=e.value;f.parentNode.removeChild(f);a.setDirtyCanvas(!0,
!0)}var f=document.createElement("div");f.className="graphdialog";f.innerHTML="<span class='name'>Title</span><input autofocus type='text' class='value'/><button>OK</button>";var e=f.querySelector("input");e&&(e.value=a.title,e.addEventListener("keydown",function(a){13==a.keyCode&&(c(),a.preventDefault(),a.stopPropagation())}));var d=this.canvas.getClientRects()[0],g=-20,h=-20;d&&(g-=d.left,h-=d.top);b?(f.style.left=b.pageX+g+"px",f.style.top=b.pageY+h+"px"):(f.style.left=0.5*this.canvas.width+g+
"px",f.style.top=0.5*this.canvas.height+h+"px");f.querySelector("button").addEventListener("click",c);this.canvas.parentNode.appendChild(f)};LGraphCanvas.prototype.showEditPropertyValue=function(a,b,c){function f(){e(v.value)}function e(c){"number"==typeof a.properties[b]&&(c=Number(c));a.properties[b]=c;if(a.onPropertyChanged)a.onPropertyChanged(b,c);p.parentNode.removeChild(p);a.setDirtyCanvas(!0,!0)}if(a&&void 0!==a.properties[b]){c=c||{};var d="string";null!==a.properties[b]&&(d=typeof a.properties[b]);
var g=null;a.getPropertyInfo&&(g=a.getPropertyInfo(b));if(a.properties_info)for(var h=0;h<a.properties_info.length;++h)if(a.properties_info[h].name==b){g=a.properties_info[h];break}void 0!==g&&null!==g&&g.type&&(d=g.type);var k="";if("string"==d||"number"==d)k="<input autofocus type='text' class='value'/>";else if("enum"==d&&g.values){k="<select autofocus type='text' class='value'>";for(h in g.values)var q=g.values.constructor===Array?g.values[h]:h,k=k+("<option value='"+q+"' "+(q==a.properties[b]?
"selected":"")+">"+g.values[h]+"</option>");k+="</select>"}else"boolean"==d&&(k="<input autofocus type='checkbox' class='value' "+(a.properties[b]?"checked":"")+"/>");var p=document.createElement("div");p.className="graphdialog";p.innerHTML="<span class='name'>"+b+"</span>"+k+"<button>OK</button>";if("enum"==d&&g.values){var v=p.querySelector("select");v.addEventListener("change",function(a){e(a.target.value)})}else if("boolean"==d)(v=p.querySelector("input"))&&v.addEventListener("click",function(a){e(!!v.checked)});
else if(v=p.querySelector("input"))v.value=void 0!==a.properties[b]?a.properties[b]:"",v.addEventListener("keydown",function(a){13==a.keyCode&&(f(),a.preventDefault(),a.stopPropagation())});d=this.canvas.getClientRects()[0];h=g=-20;d&&(g-=d.left,h-=d.top);c.event?(p.style.left=c.event.pageX+g+"px",p.style.top=c.event.pageY+h+"px"):(p.style.left=0.5*this.canvas.width+g+"px",p.style.top=0.5*this.canvas.height+h+"px");p.querySelector("button").addEventListener("click",f);this.canvas.parentNode.appendChild(p)}};
LGraphCanvas.onMenuNodeCollapse=function(a){a.flags.collapsed=!a.flags.collapsed;a.setDirtyCanvas(!0,!0)};LGraphCanvas.onMenuNodePin=function(a){a.pin()};LGraphCanvas.onMenuNodeMode=function(a,b,c){h.createContextMenu(["Always","On Event","Never"],{event:b,callback:function(b){if(a)switch(b){case "On Event":a.mode=h.ON_EVENT;break;case "Never":a.mode=h.NEVER;break;default:a.mode=h.ALWAYS}},from:c});return!1};LGraphCanvas.onMenuNodeColors=function(a,b,c){var f=[],d;for(d in LGraphCanvas.node_colors){var e=
LGraphCanvas.node_colors[d];f.push({value:d,content:"<span style='display: block; color:"+e.color+"; background-color:"+e.bgcolor+"'>"+d+"</span>"})}h.createContextMenu(f,{event:b,callback:function(b){a&&(b=LGraphCanvas.node_colors[b.value])&&(a.color=b.color,a.bgcolor=b.bgcolor,a.setDirtyCanvas(!0))},from:c});return!1};LGraphCanvas.onMenuNodeShapes=function(a,b){h.createContextMenu(["box","round"],{event:b,callback:function(b){a&&(a.shape=b,a.setDirtyCanvas(!0))}});return!1};LGraphCanvas.onMenuNodeRemove=
function(a){!1!=a.removable&&(a.graph.remove(a),a.setDirtyCanvas(!0,!0))};LGraphCanvas.onMenuNodeClone=function(a){if(!1!=a.clonable){var b=a.clone();b&&(b.pos=[a.pos[0]+5,a.pos[1]+5],a.graph.add(b),a.setDirtyCanvas(!0,!0))}};LGraphCanvas.node_colors={red:{color:"#FAA",bgcolor:"#A44"},green:{color:"#AFA",bgcolor:"#4A4"},blue:{color:"#AAF",bgcolor:"#44A"},white:{color:"#FFF",bgcolor:"#AAA"}};LGraphCanvas.prototype.getCanvasMenuOptions=function(){var a=null;this.getMenuOptions?a=this.getMenuOptions():
(a=[{content:"Add Node",is_menu:!0,callback:LGraphCanvas.onMenuAdd}],this._graph_stack&&0<this._graph_stack.length&&(a=[{content:"Close subgraph",callback:this.closeSubgraph.bind(this)},null].concat(a)));if(this.getExtraMenuOptions){var b=this.getExtraMenuOptions(this,a);b&&(a=a.concat(b))}return a};LGraphCanvas.prototype.getNodeMenuOptions=function(a){var b=null,b=a.getMenuOptions?a.getMenuOptions(this):[{content:"Inputs",is_menu:!0,disabled:!0,callback:LGraphCanvas.showMenuNodeInputs},{content:"Outputs",
is_menu:!0,disabled:!0,callback:LGraphCanvas.showMenuNodeOutputs},null,{content:"Properties",is_menu:!0,callback:LGraphCanvas.onShowMenuNodeProperties},null,{content:"Title",callback:LGraphCanvas.onShowTitleEditor},{content:"Mode",is_menu:!0,callback:LGraphCanvas.onMenuNodeMode},{content:"Collapse",callback:LGraphCanvas.onMenuNodeCollapse},{content:"Pin",callback:LGraphCanvas.onMenuNodePin},{content:"Colors",is_menu:!0,callback:LGraphCanvas.onMenuNodeColors},{content:"Shapes",is_menu:!0,callback:LGraphCanvas.onMenuNodeShapes},
null];if(a.getExtraMenuOptions){var c=a.getExtraMenuOptions(this);c&&(c.push(null),b=c.concat(b))}!1!==a.clonable&&b.push({content:"Clone",callback:LGraphCanvas.onMenuNodeClone});!1!==a.removable&&b.push(null,{content:"Remove",callback:LGraphCanvas.onMenuNodeRemove});a.onGetInputs&&(c=a.onGetInputs())&&c.length&&(b[0].disabled=!1);a.onGetOutputs&&(a=a.onGetOutputs())&&a.length&&(b[1].disabled=!1);return b};LGraphCanvas.prototype.processContextMenu=function(a,b){var c=this,f=this.getCanvasWindow(),
d=null,e={event:b,callback:function(f,d){if(f)if(f==g)f.input?a.removeInput(g.slot):f.output&&a.removeOutput(g.slot);else if(f.callback)return f.callback.call(c,a,d,k,c,b)}},g=null;a&&(g=a.getSlotInPosition(b.canvasX,b.canvasY));g?(d=g.locked?["Cannot remove"]:{"Remove Slot":g},e.title=g.input?g.input.type:g.output.type,g.input&&g.input.type==h.EVENT&&(e.title="Event")):d=a?this.getNodeMenuOptions(a):this.getCanvasMenuOptions();if(d)var k=h.createContextMenu(d,e,f)};this.CanvasRenderingContext2D&&
(CanvasRenderingContext2D.prototype.roundRect=function(a,b,c,f,d,e){void 0===d&&(d=5);void 0===e&&(e=d);this.beginPath();this.moveTo(a+d,b);this.lineTo(a+c-d,b);this.quadraticCurveTo(a+c,b,a+c,b+d);this.lineTo(a+c,b+f-e);this.quadraticCurveTo(a+c,b+f,a+c-e,b+f);this.lineTo(a+e,b+f);this.quadraticCurveTo(a,b+f,a,b+f-e);this.lineTo(a,b+d);this.quadraticCurveTo(a,b,a+d,b)});h.compareObjects=function(a,b){for(var c in a)if(a[c]!=b[c])return!1;return!0};h.distance=d;h.colorToString=function(a){return"rgba("+
Math.round(255*a[0]).toFixed()+","+Math.round(255*a[1]).toFixed()+","+Math.round(255*a[2]).toFixed()+","+(4==a.length?a[3].toFixed(2):"1.0")+")"};h.isInsideRectangle=g;h.growBounding=function(a,b,c){b<a[0]?a[0]=b:b>a[2]&&(a[2]=b);c<a[1]?a[1]=c:c>a[3]&&(a[3]=c)};h.isInsideBounding=function(a,b){return a[0]<b[0][0]||a[1]<b[0][1]||a[0]>b[1][0]||a[1]>b[1][1]?!1:!0};h.overlapBounding=k;h.hex2num=function(a){"#"==a.charAt(0)&&(a=a.slice(1));a=a.toUpperCase();for(var b=Array(3),c=0,f,d,e=0;6>e;e+=2)f="0123456789ABCDEF".indexOf(a.charAt(e)),
d="0123456789ABCDEF".indexOf(a.charAt(e+1)),b[c]=16*f+d,c++;return b};h.num2hex=function(a){for(var b="#",c,f,d=0;3>d;d++)c=a[d]/16,f=a[d]%16,b+="0123456789ABCDEF".charAt(c)+"0123456789ABCDEF".charAt(f);return b};h.createContextMenu=function(a,b,c){function f(a){var f=!0;b.callback&&(a=b.callback.call(g,this.data,a),void 0!==a&&(f=a));f&&h.closeAllContextMenus(c)}this.options=b=b||{};c=c||window;if(b.from){var d=document.querySelectorAll(".graphcontextmenu"),e;for(e in d)d[e].previousSibling==b.from&&
d[e].closeMenu()}else h.closeAllContextMenus(c);var g=c.document.createElement("div");g.className="graphcontextmenu graphmenubar-panel";this.root=g;d=g.style;d.minWidth="100px";d.minHeight="20px";d.position="fixed";d.top="100px";d.left="100px";d.color="#AAF";d.padding="2px";d.borderBottom="2px solid #AAF";d.backgroundColor="#444";d.zIndex=10;b.title&&(d=document.createElement("div"),d.className="graphcontextmenu-title",d.innerHTML=b.title,g.appendChild(d));g.addEventListener("contextmenu",function(a){a.preventDefault();
return!1});for(var k in a){e=a[k];d=c.document.createElement("div");d.className="graphmenu-entry";if(null==e)d.className+=" separator";else{e.is_menu&&(d.className+=" submenu");e.disabled&&(d.className+=" disabled");e.className&&(d.className+=" "+e.className);d.style.cursor="pointer";d.dataset.value="string"==typeof e?e:e.value;d.data=e;var n="",n="string"==typeof e?a.constructor==Array?a[k]:k:e.content?e.content:k;b.allow_html?d.innerHTML=n:d.innerText=n;d.addEventListener("click",f)}g.appendChild(d)}g.addEventListener("mouseover",
function(a){this.mouse_inside=!0});g.addEventListener("mouseout",function(a){for(a=a.relatedTarget||a.toElement;a!=this&&a!=c.document;)a=a.parentNode;a!=this&&(this.mouse_inside=!1,this.block_close||this.closeMenu())});c.document.body.appendChild(g);a=g.getClientRects()[0];b.from&&(b.from.block_close=!0);e=b.left||0;k=b.top||0;b.event&&(e=b.event.pageX-10,k=b.event.pageY-10,b.left&&(e=b.left),d=c.document.body.getClientRects()[0],b.from&&(e=b.from.getClientRects()[0],e=e.left+e.width),e>d.width-
a.width-10&&(e=d.width-a.width-10),k>d.height-a.height-10&&(k=d.height-a.height-10));g.style.left=e+"px";g.style.top=k+"px";g.closeMenu=function(){b.from&&(b.from.block_close=!1,b.from.mouse_inside||b.from.closeMenu());this.parentNode&&c.document.body.removeChild(this)};return g};h.closeAllContextMenus=function(a){a=a||window;a=a.document.querySelectorAll(".graphcontextmenu");if(a.length){for(var b=[],c=0;c<a.length;c++)b.push(a[c]);for(c in b)b[c].parentNode&&b[c].parentNode.removeChild(b[c])}};
h.extendClass=function(a,b){for(var c in b)a.hasOwnProperty(c)||(a[c]=b[c]);if(b.prototype)for(c in b.prototype)b.prototype.hasOwnProperty(c)&&!a.prototype.hasOwnProperty(c)&&(b.prototype.__lookupGetter__(c)?a.prototype.__defineGetter__(c,b.prototype.__lookupGetter__(c)):a.prototype[c]=b.prototype[c],b.prototype.__lookupSetter__(c)&&a.prototype.__defineSetter__(c,b.prototype.__lookupSetter__(c)))};void 0===typeof window||window.requestAnimationFrame||(window.requestAnimationFrame=window.webkitRequestAnimationFrame||
window.mozRequestAnimationFrame||function(a){window.setTimeout(a,1E3/60)})})(this);
(function(){function e(){this.addOutput("in ms","number");this.addOutput("in sec","number")}function d(){this.size=[120,60];this.subgraph=new LGraph;this.subgraph._subgraph_node=this;this.subgraph._is_subgraph=!0;this.subgraph.onGlobalInputAdded=this.onSubgraphNewGlobalInput.bind(this);this.subgraph.onGlobalInputRenamed=this.onSubgraphRenamedGlobalInput.bind(this);this.subgraph.onGlobalInputTypeChanged=this.onSubgraphTypeChangeGlobalInput.bind(this);this.subgraph.onGlobalOutputAdded=this.onSubgraphNewGlobalOutput.bind(this);
this.subgraph.onGlobalOutputRenamed=this.onSubgraphRenamedGlobalOutput.bind(this);this.subgraph.onGlobalOutputTypeChanged=this.onSubgraphTypeChangeGlobalOutput.bind(this);this.bgcolor="#940"}function g(){var a="input_"+(1E3*Math.random()).toFixed();this.addOutput(a,null);this.properties={name:a,type:null};var b=this;Object.defineProperty(this.properties,"name",{get:function(){return a},set:function(d){if(""!=d){var e=b.getOutputInfo(0);e.name!=d&&(e.name=d,b.graph&&b.graph.renameGlobalInput(a,d),
a=d)}},enumerable:!0});Object.defineProperty(this.properties,"type",{get:function(){return b.outputs[0].type},set:function(d){b.outputs[0].type=d;b.graph&&b.graph.changeGlobalInputType(a,b.outputs[0].type)},enumerable:!0})}function k(){var a="output_"+(1E3*Math.random()).toFixed();this.addInput(a,null);this.properties={name:a,type:null};var b=this;Object.defineProperty(this.properties,"name",{get:function(){return a},set:function(d){if(""!=d){var e=b.getInputInfo(0);e.name!=d&&(e.name=d,b.graph&&
b.graph.renameGlobalOutput(a,d),a=d)}},enumerable:!0});Object.defineProperty(this.properties,"type",{get:function(){return b.inputs[0].type},set:function(d){b.inputs[0].type=d;b.graph&&b.graph.changeGlobalInputType(a,b.inputs[0].type)},enumerable:!0})}function h(){this.addOutput("value","number");this.addProperty("value",1);this.editable={property:"value",type:"number"}}function a(){this.size=[60,20];this.addInput("value",0,{label:""});this.addOutput("value",0,{label:""});this.addProperty("value",
"")}function b(){this.mode=LiteGraph.ON_EVENT;this.size=[60,20];this.addProperty("msg","");this.addInput("log",LiteGraph.EVENT);this.addInput("msg",0)}e.title="Time";e.desc="Time";e.prototype.onExecute=function(){this.setOutputData(0,1E3*this.graph.globaltime);this.setOutputData(1,this.graph.globaltime)};LiteGraph.registerNodeType("basic/time",e);d.title="Subgraph";d.desc="Graph inside a node";d.prototype.onSubgraphNewGlobalInput=function(a,b){this.addInput(a,b)};d.prototype.onSubgraphRenamedGlobalInput=
function(a,b){var d=this.findInputSlot(a);-1!=d&&(this.getInputInfo(d).name=b)};d.prototype.onSubgraphTypeChangeGlobalInput=function(a,b){var d=this.findInputSlot(a);-1!=d&&(this.getInputInfo(d).type=b)};d.prototype.onSubgraphNewGlobalOutput=function(a,b){this.addOutput(a,b)};d.prototype.onSubgraphRenamedGlobalOutput=function(a,b){var d=this.findOutputSlot(a);-1!=d&&(this.getOutputInfo(d).name=b)};d.prototype.onSubgraphTypeChangeGlobalOutput=function(a,b){var d=this.findOutputSlot(a);-1!=d&&(this.getOutputInfo(d).type=
b)};d.prototype.getExtraMenuOptions=function(a){var b=this;return[{content:"Open",callback:function(){a.openSubgraph(b.subgraph)}}]};d.prototype.onExecute=function(){if(this.inputs)for(var a=0;a<this.inputs.length;a++){var b=this.inputs[a],d=this.getInputData(a);this.subgraph.setGlobalInputData(b.name,d)}this.subgraph.runStep();if(this.outputs)for(a=0;a<this.outputs.length;a++)d=this.subgraph.getGlobalOutputData(this.outputs[a].name),this.setOutputData(a,d)};d.prototype.configure=function(a){LGraphNode.prototype.configure.call(this,
a)};d.prototype.serialize=function(){var a=LGraphNode.prototype.serialize.call(this);a.subgraph=this.subgraph.serialize();return a};d.prototype.clone=function(){var a=LiteGraph.createNode(this.type),b=this.serialize();delete b.id;delete b.inputs;delete b.outputs;a.configure(b);return a};LiteGraph.registerNodeType("graph/subgraph",d);g.title="Input";g.desc="Input of the graph";g.prototype.onAdded=function(){this.graph.addGlobalInput(this.properties.name,this.properties.type)};g.prototype.onExecute=
function(){var a=this.graph.global_inputs[this.properties.name];a&&this.setOutputData(0,a.value)};LiteGraph.registerNodeType("graph/input",g);k.title="Ouput";k.desc="Output of the graph";k.prototype.onAdded=function(){this.graph.addGlobalOutput(this.properties.name,this.properties.type)};k.prototype.onExecute=function(){this.graph.setGlobalOutputData(this.properties.name,this.getInputData(0))};LiteGraph.registerNodeType("graph/output",k);h.title="Const";h.desc="Constant value";h.prototype.setValue=
function(a){"string"==typeof a&&(a=parseFloat(a));this.properties.value=a;this.setDirtyCanvas(!0)};h.prototype.onExecute=function(){this.setOutputData(0,parseFloat(this.properties.value))};h.prototype.onDrawBackground=function(a){this.outputs[0].label=this.properties.value.toFixed(3)};h.prototype.onWidget=function(a,b){"value"==b.name&&this.setValue(b.value)};LiteGraph.registerNodeType("basic/const",h);a.title="Watch";a.desc="Show value of input";a.prototype.onExecute=function(){this.properties.value=
this.getInputData(0);this.setOutputData(0,this.properties.value)};a.prototype.onDrawBackground=function(a){this.inputs[0]&&null!=this.properties.value&&(this.properties.value.constructor===Number?this.inputs[0].label=this.properties.value.toFixed(3):((a=this.properties.value)&&a.length&&(a=Array.prototype.slice.call(a).join(",")),this.inputs[0].label=a))};LiteGraph.registerNodeType("basic/watch",a);b.title="Console";b.desc="Show value inside the console";b.prototype.onAction=function(a,b){"log"==
a?console.log(b):"warn"==a?console.warn(b):"error"==a&&console.error(b)};b.prototype.onExecute=function(){var a=this.getInputData(0);null!==a&&(this.properties.msg=a);console.log(a)};b.prototype.onGetInputs=function(){return[["log",LiteGraph.ACTION],["warn",LiteGraph.ACTION],["error",LiteGraph.ACTION]]};LiteGraph.registerNodeType("basic/console",b)})();
(function(){function e(){this.size=[60,20];this.addProperty("time",1E3);this.addInput("event",LiteGraph.ACTION);this.addOutput("on_time",LiteGraph.EVENT);this._pending=[]}e.title="Delay";e.desc="Delays one event";e.prototype.onAction=function(d,e){this._pending.push([this.properties.time,e])};e.prototype.onExecute=function(){for(var d=1E3*this.graph.elapsed_time,e=0;e<this._pending.length;++e){var k=this._pending[e];k[0]-=d;0<k[0]||(this._pending.splice(e,1),--e,this.trigger(null,k[1]))}};e.prototype.onGetInputs=
function(){return[["event",LiteGraph.ACTION]]};LiteGraph.registerNodeType("events/delay",e)})();
(function(){function e(){this.addOutput("clicked",LiteGraph.EVENT);this.addProperty("text","");this.addProperty("font","40px Arial");this.addProperty("message","");this.size=[64,84]}function d(){this.addOutput("","number");this.size=[64,84];this.properties={min:0,max:1,value:0.5,wcolor:"#7AF",size:50}}function g(){this.size=[160,26];this.addOutput("","number");this.properties={wcolor:"#7AF",min:0,max:1,value:0.5}}function k(){this.size=[160,26];this.addInput("","number");this.properties={min:0,max:1,
value:0,wcolor:"#AAF"}}function h(){this.addInputs("",0);this.properties={value:"...",font:"Arial",fontsize:18,color:"#AAA",align:"left",glowSize:0,decimals:1}}function a(){this.size=[200,100];this.properties={borderColor:"#ffffff",bgcolorTop:"#f0f0f0",bgcolorBottom:"#e0e0e0",shadowSize:2,borderRadius:3}}e.title="Button";e.desc="Triggers an event";e.prototype.onDrawForeground=function(a){!this.flags.collapsed&&(a.fillStyle="black",a.fillRect(1,1,this.size[0]-3,this.size[1]-3),a.fillStyle="#AAF",a.fillRect(0,
0,this.size[0]-3,this.size[1]-3),a.fillStyle=this.clicked?"white":this.mouseOver?"#668":"#334",a.fillRect(1,1,this.size[0]-4,this.size[1]-4),this.properties.text||0===this.properties.text)&&(a.textAlign="center",a.fillStyle=this.clicked?"black":"white",this.properties.font&&(a.font=this.properties.font),a.fillText(this.properties.text,0.5*this.size[0],0.85*this.size[1]),a.textAlign="left")};e.prototype.onMouseDown=function(a,c){if(1<c[0]&&1<c[1]&&c[0]<this.size[0]-2&&c[1]<this.size[1]-2)return this.clicked=
!0,this.trigger("clicked",this.properties.message),!0};e.prototype.onMouseUp=function(a){this.clicked=!1};LiteGraph.registerNodeType("widget/button",e);d.title="Knob";d.desc="Circular controller";d.widgets=[{name:"increase",text:"+",type:"minibutton"},{name:"decrease",text:"-",type:"minibutton"}];d.prototype.onAdded=function(){this.value=(this.properties.value-this.properties.min)/(this.properties.max-this.properties.min);this.imgbg=this.loadImage("imgs/knob_bg.png");this.imgfg=this.loadImage("imgs/knob_fg.png")};
d.prototype.onDrawImageKnob=function(a){if(this.imgfg&&this.imgfg.width){var c=0.5*this.imgbg.width,d=this.size[0]/this.imgfg.width;a.save();a.translate(0,20);a.scale(d,d);a.drawImage(this.imgbg,0,0);a.translate(c,c);a.rotate(2*this.value*Math.PI*6/8+10*Math.PI/8);a.translate(-c,-c);a.drawImage(this.imgfg,0,0);a.restore();this.title&&(a.font="bold 16px Criticized,Tahoma",a.fillStyle="rgba(100,100,100,0.8)",a.textAlign="center",a.fillText(this.title.toUpperCase(),0.5*this.size[0],18),a.textAlign="left")}};
d.prototype.onDrawVectorKnob=function(a){if(this.imgfg&&this.imgfg.width){a.lineWidth=1;a.strokeStyle=this.mouseOver?"#FFF":"#AAA";a.fillStyle="#000";a.beginPath();a.arc(0.5*this.size[0],0.5*this.size[1]+10,0.5*this.properties.size,0,2*Math.PI,!0);a.stroke();0<this.value&&(a.strokeStyle=this.properties.wcolor,a.lineWidth=0.2*this.properties.size,a.beginPath(),a.arc(0.5*this.size[0],0.5*this.size[1]+10,0.35*this.properties.size,-0.5*Math.PI+2*Math.PI*this.value,-0.5*Math.PI,!0),a.stroke(),a.lineWidth=
1);a.font=0.2*this.properties.size+"px Arial";a.fillStyle="#AAA";a.textAlign="center";var c=this.properties.value;"number"==typeof c&&(c=c.toFixed(2));a.fillText(c,0.5*this.size[0],0.65*this.size[1]);a.textAlign="left"}};d.prototype.onDrawForeground=function(a){this.onDrawImageKnob(a)};d.prototype.onExecute=function(){this.setOutputData(0,this.properties.value);this.boxcolor=LiteGraph.colorToString([this.value,this.value,this.value])};d.prototype.onMouseDown=function(a){if(this.imgfg&&this.imgfg.width){this.center=
[0.5*this.size[0],0.5*this.size[1]+20];this.radius=0.5*this.size[0];if(20>a.canvasY-this.pos[1]||LiteGraph.distance([a.canvasX,a.canvasY],[this.pos[0]+this.center[0],this.pos[1]+this.center[1]])>this.radius)return!1;this.oldmouse=[a.canvasX-this.pos[0],a.canvasY-this.pos[1]];this.captureInput(!0);return!0}};d.prototype.onMouseMove=function(a){if(this.oldmouse){a=[a.canvasX-this.pos[0],a.canvasY-this.pos[1]];var c=this.value,c=c-0.01*(a[1]-this.oldmouse[1]);1<c?c=1:0>c&&(c=0);this.value=c;this.properties.value=
this.properties.min+(this.properties.max-this.properties.min)*this.value;this.oldmouse=a;this.setDirtyCanvas(!0)}};d.prototype.onMouseUp=function(a){this.oldmouse&&(this.oldmouse=null,this.captureInput(!1))};d.prototype.onMouseLeave=function(a){};d.prototype.onWidget=function(a,c){if("increase"==c.name)this.onPropertyChanged("size",this.properties.size+10);else if("decrease"==c.name)this.onPropertyChanged("size",this.properties.size-10)};d.prototype.onPropertyChanged=function(a,c){if("wcolor"==a)this.properties[a]=
c;else if("size"==a)c=parseInt(c),this.properties[a]=c,this.size=[c+4,c+24],this.setDirtyCanvas(!0,!0);else if("min"==a||"max"==a||"value"==a)this.properties[a]=parseFloat(c);else return!1;return!0};LiteGraph.registerNodeType("widget/knob",d);g.title="H.Slider";g.desc="Linear slider controller";g.prototype.onInit=function(){this.value=0.5;this.imgfg=this.loadImage("imgs/slider_fg.png")};g.prototype.onDrawVectorial=function(a){this.imgfg&&this.imgfg.width&&(a.lineWidth=1,a.strokeStyle=this.mouseOver?
"#FFF":"#AAA",a.fillStyle="#000",a.beginPath(),a.rect(2,0,this.size[0]-4,20),a.stroke(),a.fillStyle=this.properties.wcolor,a.beginPath(),a.rect(2+(this.size[0]-4-20)*this.value,0,20,20),a.fill())};g.prototype.onDrawImage=function(a){this.imgfg&&this.imgfg.width&&(a.lineWidth=1,a.fillStyle="#000",a.fillRect(2,9,this.size[0]-4,2),a.strokeStyle="#333",a.beginPath(),a.moveTo(2,9),a.lineTo(this.size[0]-4,9),a.stroke(),a.strokeStyle="#AAA",a.beginPath(),a.moveTo(2,11),a.lineTo(this.size[0]-4,11),a.stroke(),
a.drawImage(this.imgfg,2+(this.size[0]-4)*this.value-0.5*this.imgfg.width,0.5*-this.imgfg.height+10))};g.prototype.onDrawForeground=function(a){this.onDrawImage(a)};g.prototype.onExecute=function(){this.properties.value=this.properties.min+(this.properties.max-this.properties.min)*this.value;this.setOutputData(0,this.properties.value);this.boxcolor=LiteGraph.colorToString([this.value,this.value,this.value])};g.prototype.onMouseDown=function(a){if(0>a.canvasY-this.pos[1])return!1;this.oldmouse=[a.canvasX-
this.pos[0],a.canvasY-this.pos[1]];this.captureInput(!0);return!0};g.prototype.onMouseMove=function(a){if(this.oldmouse){a=[a.canvasX-this.pos[0],a.canvasY-this.pos[1]];var c=this.value,c=c+(a[0]-this.oldmouse[0])/this.size[0];1<c?c=1:0>c&&(c=0);this.value=c;this.oldmouse=a;this.setDirtyCanvas(!0)}};g.prototype.onMouseUp=function(a){this.oldmouse=null;this.captureInput(!1)};g.prototype.onMouseLeave=function(a){};g.prototype.onPropertyChanged=function(a,c){if("wcolor"==a)this.properties[a]=c;else return!1;
return!0};LiteGraph.registerNodeType("widget/hslider",g);k.title="Progress";k.desc="Shows data in linear progress";k.prototype.onExecute=function(){var a=this.getInputData(0);void 0!=a&&(this.properties.value=a)};k.prototype.onDrawForeground=function(a){a.lineWidth=1;a.fillStyle=this.properties.wcolor;var c=(this.properties.value-this.properties.min)/(this.properties.max-this.properties.min),c=Math.min(1,c),c=Math.max(0,c);a.fillRect(2,2,(this.size[0]-4)*c,this.size[1]-4)};LiteGraph.registerNodeType("widget/progress",
k);h.title="Text";h.desc="Shows the input value";h.widgets=[{name:"resize",text:"Resize box",type:"button"},{name:"led_text",text:"LED",type:"minibutton"},{name:"normal_text",text:"Normal",type:"minibutton"}];h.prototype.onDrawForeground=function(a){a.fillStyle=this.properties.color;var c=this.properties.value;this.properties.glowSize?(a.shadowColor=this.properties.color,a.shadowOffsetX=0,a.shadowOffsetY=0,a.shadowBlur=this.properties.glowSize):a.shadowColor="transparent";var d=this.properties.fontsize;
a.textAlign=this.properties.align;a.font=d.toString()+"px "+this.properties.font;this.str="number"==typeof c?c.toFixed(this.properties.decimals):c;if("string"==typeof this.str){var c=this.str.split("\\n"),e;for(e in c)a.fillText(c[e],"left"==this.properties.align?15:this.size[0]-15,-0.15*d+d*(parseInt(e)+1))}a.shadowColor="transparent";this.last_ctx=a;a.textAlign="left"};h.prototype.onExecute=function(){var a=this.getInputData(0);this.properties.value=null!=a?a:"";this.setDirtyCanvas(!0)};h.prototype.resize=
function(){if(this.last_ctx){var a=this.str.split("\\n");this.last_ctx.font=this.properties.fontsize+"px "+this.properties.font;var c=0,d;for(d in a){var e=this.last_ctx.measureText(a[d]).width;c<e&&(c=e)}this.size[0]=c+20;this.size[1]=4+a.length*this.properties.fontsize;this.setDirtyCanvas(!0)}};h.prototype.onWidget=function(a,c){"resize"==c.name?this.resize():"led_text"==c.name?(this.properties.font="Digital",this.properties.glowSize=4,this.setDirtyCanvas(!0)):"normal_text"==c.name&&(this.properties.font=
"Arial",this.setDirtyCanvas(!0))};h.prototype.onPropertyChanged=function(a,c){this.properties[a]=c;this.str="number"==typeof c?c.toFixed(3):c;return!0};LiteGraph.registerNodeType("widget/text",h);a.title="Panel";a.desc="Non interactive panel";a.widgets=[{name:"update",text:"Update",type:"button"}];a.prototype.createGradient=function(a){""==this.properties.bgcolorTop||""==this.properties.bgcolorBottom?this.lineargradient=0:(this.lineargradient=a.createLinearGradient(0,0,0,this.size[1]),this.lineargradient.addColorStop(0,
this.properties.bgcolorTop),this.lineargradient.addColorStop(1,this.properties.bgcolorBottom))};a.prototype.onDrawForeground=function(a){null==this.lineargradient&&this.createGradient(a);this.lineargradient&&(a.lineWidth=1,a.strokeStyle=this.properties.borderColor,a.fillStyle=this.lineargradient,this.properties.shadowSize?(a.shadowColor="#000",a.shadowOffsetX=0,a.shadowOffsetY=0,a.shadowBlur=this.properties.shadowSize):a.shadowColor="transparent",a.roundRect(0,0,this.size[0]-1,this.size[1]-1,this.properties.shadowSize),
a.fill(),a.shadowColor="transparent",a.stroke())};a.prototype.onWidget=function(a,c){"update"==c.name&&(this.lineargradient=null,this.setDirtyCanvas(!0))};LiteGraph.registerNodeType("widget/panel",a)})();
(function(){function e(){this.addOutput("left_x_axis","number");this.addOutput("left_y_axis","number");this.properties={}}e.title="Gamepad";e.desc="gets the input of the gamepad";e.prototype.onExecute=function(){var d=this.getGamepad();if(this.outputs)for(var e=0;e<this.outputs.length;e++){var k=this.outputs[e],h=null;if(d)switch(k.name){case "left_axis":h=[d.xbox.axes.lx,d.xbox.axes.ly];break;case "right_axis":h=[d.xbox.axes.rx,d.xbox.axes.ry];break;case "left_x_axis":h=d.xbox.axes.lx;break;case "left_y_axis":h=
d.xbox.axes.ly;break;case "right_x_axis":h=d.xbox.axes.rx;break;case "right_y_axis":h=d.xbox.axes.ry;break;case "trigger_left":h=d.xbox.axes.ltrigger;break;case "trigger_right":h=d.xbox.axes.rtrigger;break;case "a_button":h=d.xbox.buttons.a?1:0;break;case "b_button":h=d.xbox.buttons.b?1:0;break;case "x_button":h=d.xbox.buttons.x?1:0;break;case "y_button":h=d.xbox.buttons.y?1:0;break;case "lb_button":h=d.xbox.buttons.lb?1:0;break;case "rb_button":h=d.xbox.buttons.rb?1:0;break;case "ls_button":h=d.xbox.buttons.ls?
1:0;break;case "rs_button":h=d.xbox.buttons.rs?1:0;break;case "start_button":h=d.xbox.buttons.start?1:0;break;case "back_button":h=d.xbox.buttons.back?1:0}else switch(k.name){case "left_axis":case "right_axis":h=[0,0];break;default:h=0}this.setOutputData(e,h)}};e.prototype.getGamepad=function(){var d=navigator.getGamepads||navigator.webkitGetGamepads||navigator.mozGetGamepads;if(!d)return null;for(var e=d.call(navigator),d=null,k=0;4>k;k++)if(e[k]){d=e[k];e=this.xbox_mapping;e||(e=this.xbox_mapping=
{axes:[],buttons:{},hat:""});e.axes.lx=d.axes[0];e.axes.ly=d.axes[1];e.axes.rx=d.axes[2];e.axes.ry=d.axes[3];e.axes.ltrigger=d.buttons[6].value;e.axes.rtrigger=d.buttons[7].value;for(k=0;k<d.buttons.length;k++)switch(k){case 0:e.buttons.a=d.buttons[k].pressed;break;case 1:e.buttons.b=d.buttons[k].pressed;break;case 2:e.buttons.x=d.buttons[k].pressed;break;case 3:e.buttons.y=d.buttons[k].pressed;break;case 4:e.buttons.lb=d.buttons[k].pressed;break;case 5:e.buttons.rb=d.buttons[k].pressed;break;case 6:e.buttons.lt=
d.buttons[k].pressed;break;case 7:e.buttons.rt=d.buttons[k].pressed;break;case 8:e.buttons.back=d.buttons[k].pressed;break;case 9:e.buttons.start=d.buttons[k].pressed;break;case 10:e.buttons.ls=d.buttons[k].pressed;break;case 11:e.buttons.rs=d.buttons[k].pressed;break;case 12:d.buttons[k].pressed&&(e.hat+="up");break;case 13:d.buttons[k].pressed&&(e.hat+="down");break;case 14:d.buttons[k].pressed&&(e.hat+="left");break;case 15:d.buttons[k].pressed&&(e.hat+="right");break;case 16:e.buttons.home=d.buttons[k].pressed}d.xbox=
e;return d}};e.prototype.onDrawBackground=function(d){};e.prototype.onGetOutputs=function(){return[["left_axis","vec2"],["right_axis","vec2"],["left_x_axis","number"],["left_y_axis","number"],["right_x_axis","number"],["right_y_axis","number"],["trigger_left","number"],["trigger_right","number"],["a_button","number"],["b_button","number"],["x_button","number"],["y_button","number"],["lb_button","number"],["rb_button","number"],["ls_button","number"],["rs_button","number"],["start","number"],["back",
"number"]]};LiteGraph.registerNodeType("input/gamepad",e)})();
(function(){function e(){this.addInput("in","*");this.size=[60,20]}function d(){this.addInput("in");this.addOutput("out");this.size=[60,20]}function g(){this.addInput("in","number",{locked:!0});this.addOutput("out","number",{locked:!0});this.addProperty("in",0);this.addProperty("in_min",0);this.addProperty("in_max",1);this.addProperty("out_min",0);this.addProperty("out_max",1)}function k(){this.addOutput("value","number");this.addProperty("min",0);this.addProperty("max",1);this.size=[60,20]}function h(){this.addInput("in",
"number");this.addOutput("out","number");this.size=[60,20];this.addProperty("min",0);this.addProperty("max",1)}function a(){this.properties={f:0.5};this.addInput("A","number");this.addInput("B","number");this.addOutput("out","number")}function b(){this.addInput("in","number");this.addOutput("out","number");this.size=[60,20]}function c(){this.addInput("in","number");this.addOutput("out","number");this.size=[60,20]}function f(){this.addInput("in","number");this.addOutput("out","number");this.size=[60,
20]}function l(){this.addInput("in","number");this.addOutput("out","number");this.size=[60,20];this.properties={A:0,B:1}}function u(){this.addInput("in","number",{label:""});this.addOutput("out","number",{label:""});this.size=[60,20];this.addProperty("factor",1)}function s(){this.addInput("in","number");this.addOutput("out","number");this.size=[60,20];this.addProperty("samples",10);this._values=new Float32Array(10);this._current=0}function t(){this.addInput("A","number");this.addInput("B","number");
this.addOutput("=","number");this.addProperty("A",1);this.addProperty("B",1);this.addProperty("OP","+","string",{values:t.values})}function n(){this.addInput("A","number");this.addInput("B","number");this.addOutput("A==B","boolean");this.addOutput("A!=B","boolean");this.addProperty("A",0);this.addProperty("B",0)}function q(){this.addInput("A","number");this.addInput("B","number");this.addOutput("out","boolean");this.addProperty("A",1);this.addProperty("B",1);this.addProperty("OP",">","string",{values:q.values});
this.size=[60,40]}function p(){this.addInput("inc","number");this.addOutput("total","number");this.addProperty("increment",1);this.addProperty("value",0)}function v(){this.addInput("v","number");this.addOutput("sin","number");this.addProperty("amplitude",1);this.addProperty("offset",0);this.bgImageUrl="nodes/imgs/icon-sin.png"}function w(){this.addInput("vec2","vec2");this.addOutput("x","number");this.addOutput("y","number")}function x(){this.addInputs([["x","number"],["y","number"]]);this.addOutput("vec2",
"vec2");this.properties={x:0,y:0};this._data=new Float32Array(2)}function y(){this.addInput("vec3","vec3");this.addOutput("x","number");this.addOutput("y","number");this.addOutput("z","number")}function z(){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 A(){this.addInput("vec4","vec4");this.addOutput("x","number");this.addOutput("y","number");this.addOutput("z","number");this.addOutput("w",
"number")}function B(){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)}e.title="Converter";e.desc="type A to type B";e.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=4}d=new Float32Array(d);if(a.length)for(c=0;c<a.length&&c<d.length;c++)d[c]=a[c];else d[0]=parseFloat(a)}this.setOutputData(b,d)}}};e.prototype.onGetOutputs=function(){return[["number","number"],["vec2","vec2"],["vec3","vec3"],["vec4","vec4"]]};LiteGraph.registerNodeType("math/converter",e);d.title="Bypass";d.desc="removes the type";d.prototype.onExecute=function(){var a=this.getInputData(0);this.setOutputData(0,a)};LiteGraph.registerNodeType("math/bypass",
d);g.title="Range";g.desc="Convert a number from one range to another";g.prototype.onExecute=function(){if(this.inputs)for(var a=0;a<this.inputs.length;a++){var b=this.inputs[a],c=this.getInputData(a);void 0!==c&&(this.properties[b.name]=c)}c=this.properties["in"];if(void 0===c||null===c||c.constructor!==Number)c=0;a=this.properties.in_min;b=this.properties.out_min;this._last_v=(c-a)/(this.properties.in_max-a)*(this.properties.out_max-b)+b;this.setOutputData(0,this._last_v)};g.prototype.onDrawBackground=
function(a){this.outputs[0].label=this._last_v?this._last_v.toFixed(3):"?"};g.prototype.onGetInputs=function(){return[["in_min","number"],["in_max","number"],["out_min","number"],["out_max","number"]]};LiteGraph.registerNodeType("math/range",g);k.title="Rand";k.desc="Random number";k.prototype.onExecute=function(){if(this.inputs)for(var a=0;a<this.inputs.length;a++){var b=this.inputs[a],c=this.getInputData(a);void 0!==c&&(this.properties[b.name]=c)}a=this.properties.min;b=this.properties.max;this._last_v=
Math.random()*(b-a)+a;this.setOutputData(0,this._last_v)};k.prototype.onDrawBackground=function(a){this.outputs[0].label=this._last_v?this._last_v.toFixed(3):"?"};k.prototype.onGetInputs=function(){return[["min","number"],["max","number"]]};LiteGraph.registerNodeType("math/rand",k);h.title="Clamp";h.desc="Clamp number between min and max";h.filter="shader";h.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))};h.prototype.getCode=function(a){a="";this.isInputConnected(0)&&(a+="clamp({{0}},"+this.properties.min+","+this.properties.max+")");return a};LiteGraph.registerNodeType("math/clamp",h);a.title="Lerp";a.desc="Linear Interpolation";a.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=0);var b=this.getInputData(1);null==b&&(b=0);var c=this.properties.f,d=this.getInputData(2);void 0!==d&&(c=d);this.setOutputData(0,a*(1-c)+b*c)};a.prototype.onGetInputs=function(){return[["f","number"]]};
LiteGraph.registerNodeType("math/lerp",a);b.title="Abs";b.desc="Absolute";b.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,Math.abs(a))};LiteGraph.registerNodeType("math/abs",b);c.title="Floor";c.desc="Floor number to remove fractional part";c.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,Math.floor(a))};LiteGraph.registerNodeType("math/floor",c);f.title="Frac";f.desc="Returns fractional part";f.prototype.onExecute=
function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,a%1)};LiteGraph.registerNodeType("math/frac",f);l.title="Smoothstep";l.desc="Smoothstep";l.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",l);u.title="Scale";u.desc="v * factor";u.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,
a*this.properties.factor)};LiteGraph.registerNodeType("math/scale",u);s.title="Average";s.desc="Average Filter";s.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=0);var b=this._values.length;this._values[this._current%b]=a;this._current+=1;this._current>b&&(this._current=0);for(var c=a=0;c<b;++c)a+=this._values[c];this.setOutputData(0,a/b)};s.prototype.onPropertyChanged=function(a,b){1>b&&(b=1);this.properties.samples=Math.round(b);var c=this._values;this._values=new Float32Array(this.properties.samples);
c.length<=this._values.length?this._values.set(c):this._values.set(c.subarray(0,this._values.length))};LiteGraph.registerNodeType("math/average",s);t.values="+-*/%^".split("");t.title="Operation";t.desc="Easy math operators";t["@OP"]={type:"enum",title:"operation",values:t.values};t.prototype.setValue=function(a){"string"==typeof a&&(a=parseFloat(a));this.properties.value=a};t.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 "x":case "X":case "*":c=a*b;break;case "/":c=a/b;break;case "%":c=a%b;break;case "^":c=Math.pow(a,b);break;default:console.warn("Unknown operation: "+this.properties.OP)}this.setOutputData(0,c)};t.prototype.onDrawBackground=function(a){this.flags.collapsed||(a.font="40px Arial",a.fillStyle="black",a.textAlign="center",a.fillText(this.properties.OP,0.5*this.size[0],0.5*
this.size[1]+LiteGraph.NODE_TITLE_HEIGHT),a.textAlign="left")};LiteGraph.registerNodeType("math/operation",t);n.title="Compare";n.desc="compares between two values";n.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)}}};n.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",n);q.values="> < == != <= >=".split(" ");q["@OP"]={type:"enum",title:"operation",values:q.values};q.title="Condition";q.desc="evaluates condition between A and B";
q.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",q);p.title="Accumulate";p.desc="Increments a value every time";p.prototype.onExecute=
function(){null===this.properties.value&&(this.properties.value=0);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",p);v.title="Trigonometry";v.desc="Sin Cos Tan";v.filter="shader";v.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=0);var 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)}};v.prototype.onGetInputs=function(){return[["v","number"],["amplitude","number"],
["offset","number"]]};v.prototype.onGetOutputs=function(){return[["sin","number"],["cos","number"],["tan","number"],["asin","number"],["acos","number"],["atan","number"]]};LiteGraph.registerNodeType("math/trigonometry",v);if(window.math){var r=function(){this.addInputs("x","number");this.addInputs("y","number");this.addOutputs("","number");this.properties={x:1,y:1,formula:"x+y"}};r.title="Formula";r.desc="Compute safe formula";r.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)};r.prototype.onDrawBackground=function(){this.outputs[0].label=this.properties.formula};r.prototype.onGetOutputs=function(){return[["A-B","number"],["A*B","number"],["A/B","number"]]};LiteGraph.registerNodeType("math/formula",r)}w.title="Vec2->XY";w.desc="vector 2 to components";w.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",w);x.title="XY->Vec2";x.desc="components to vector2";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._data;c[0]=a;c[1]=b;this.setOutputData(0,c)};LiteGraph.registerNodeType("math3d/xy-to-vec2",x);y.title="Vec3->XYZ";y.desc="vector 3 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]))};LiteGraph.registerNodeType("math3d/vec3-to-xyz",y);z.title="XYZ->Vec3";z.desc="components to vector3";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._data;d[0]=a;d[1]=b;d[2]=c;this.setOutputData(0,d)};
LiteGraph.registerNodeType("math3d/xyz-to-vec3",z);A.title="Vec4->XYZW";A.desc="vector 4 to components";A.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",A);B.title="XYZW->Vec4";B.desc="components to vector4";B.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",B);window.glMatrix&&(r=function(){this.addOutput("quat","quat");this.properties={x:0,y:0,z:0,w:1};this._value=quat.create()},r.title="Quaternion",r.desc="quaternion",r.prototype.onExecute=function(){this._value[0]=this.properties.x;this._value[1]=
this.properties.y;this._value[2]=this.properties.z;this._value[3]=this.properties.w;this.setOutputData(0,this._value)},LiteGraph.registerNodeType("math3d/quaternion",r),r=function(){this.addInputs([["degrees","number"],["axis","vec3"]]);this.addOutput("quat","quat");this.properties={angle:90,axis:vec3.fromValues(0,1,0)};this._value=quat.create()},r.title="Rotation",r.desc="quaternion rotation",r.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(this._value,b,0.0174532925*a);this.setOutputData(0,a)},LiteGraph.registerNodeType("math3d/rotation",r),r=function(){this.addInputs([["vec3","vec3"],["quat","quat"]]);this.addOutput("result","vec3");this.properties={vec:[0,0,1]}},r.title="Rot. Vec3",r.desc="rotate a point",r.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",r),r=function(){this.addInputs([["A","quat"],["B","quat"]]);this.addOutput("A*B","quat");this._value=quat.create()},r.title="Mult. Quat",r.desc="rotate quaternion",r.prototype.onExecute=function(){var a=this.getInputData(0);if(null!=a){var b=this.getInputData(1);null!=b&&(a=quat.multiply(this._value,a,b),this.setOutputData(0,a))}},LiteGraph.registerNodeType("math3d/mult-quat",r),r=function(){this.addInputs([["A","quat"],["B","quat"],["factor",
"number"]]);this.addOutput("slerp","quat");this.addProperty("factor",0.5);this._value=quat.create()},r.title="Quat Slerp",r.desc="quaternion spherical interpolation",r.prototype.onExecute=function(){var a=this.getInputData(0);if(null!=a){var b=this.getInputData(1);if(null!=b){var c=this.properties.factor;null!=this.getInputData(2)&&(c=this.getInputData(2));a=quat.slerp(this._value,a,b,c);this.setOutputData(0,a)}}},LiteGraph.registerNodeType("math3d/quat-slerp",r))})();
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 e=this.getInputData(0);if(void 0!==e){for(var d=1;d<this.inputs.length;d++){var g=this.inputs[d],k=this.getInputData(d);void 0!==k&&(this.properties[g.name]=k)}d=this.properties.A;g=this.properties.B;this.setOutputData(0,e?d:g)}};
Selector.prototype.onGetInputs=function(){return[["A",0],["B",0]]};LiteGraph.registerNodeType("logic/selector",Selector);
(function(){function e(){this.inputs=[];this.addOutput("frame","image");this.properties={url:""}}function d(){this.addInput("f","number");this.addOutput("Color","color");this.properties={colorA:"#444444",colorB:"#44AAFF",colorC:"#44FFAA",colorD:"#FFFFFF"}}function g(){this.addInput("","image");this.size=[200,200]}function k(){this.addInputs([["img1","image"],["img2","image"],["fade","number"]]);this.addInput("","image");this.properties={fade:0.5,width:512,height:512}}function h(){this.addInput("",
"image");this.addOutput("","image");this.properties={width:256,height:256,x:0,y:0,scale:1};this.size=[50,20]}function a(){this.addInput("t","number");this.addOutputs([["frame","image"],["t","number"],["d","number"]]);this.properties={url:""}}function b(){this.addOutput("Webcam","image");this.properties={}}e.title="Image";e.desc="Image loader";e.widgets=[{name:"load",text:"Load",type:"button"}];e.supported_extensions=["jpg","jpeg","png","gif"];e.prototype.onAdded=function(){""!=this.properties.url&&
null==this.img&&this.loadImage(this.properties.url)};e.prototype.onDrawBackground=function(a){this.img&&5<this.size[0]&&5<this.size[1]&&a.drawImage(this.img,0,0,this.size[0],this.size[1])};e.prototype.onExecute=function(){this.img||(this.boxcolor="#000");this.img&&this.img.width?this.setOutputData(0,this.img):this.setOutputData(0,null);this.img&&this.img.dirty&&(this.img.dirty=!1)};e.prototype.onPropertyChanged=function(a,b){this.properties[a]=b;"url"==a&&""!=b&&this.loadImage(b);return!0};e.prototype.loadImage=
function(a,b){if(""==a)this.img=null;else{this.img=document.createElement("img");"http://"==a.substr(0,7)&&LiteGraph.proxy&&(a=LiteGraph.proxy+a.substr(7));this.img.src=a;this.boxcolor="#F95";var d=this;this.img.onload=function(){b&&b(this);d.trace("Image loaded, size: "+d.img.width+"x"+d.img.height);this.dirty=!0;d.boxcolor="#9F9";d.setDirtyCanvas(!0)}}};e.prototype.onWidget=function(a,b){"load"==b.name&&this.loadImage(this.properties.url)};e.prototype.onDropFile=function(a){var b=this;this._url&&
URL.revokeObjectURL(this._url);this._url=URL.createObjectURL(a);this.properties.url=this._url;this.loadImage(this._url,function(a){b.size[1]=a.height/a.width*b.size[0]})};LiteGraph.registerNodeType("graphics/image",e);d.title="Palette";d.desc="Generates a color";d.prototype.onExecute=function(){var a=[];null!=this.properties.colorA&&a.push(hex2num(this.properties.colorA));null!=this.properties.colorB&&a.push(hex2num(this.properties.colorB));null!=this.properties.colorC&&a.push(hex2num(this.properties.colorC));
null!=this.properties.colorD&&a.push(hex2num(this.properties.colorD));var b=this.getInputData(0);null==b&&(b=0.5);1<b?b=1:0>b&&(b=0);if(0!=a.length){var d=[0,0,0];if(0==b)d=a[0];else if(1==b)d=a[a.length-1];else{var e=(a.length-1)*b,b=a[Math.floor(e)],a=a[Math.floor(e)+1],e=e-Math.floor(e);d[0]=b[0]*(1-e)+a[0]*e;d[1]=b[1]*(1-e)+a[1]*e;d[2]=b[2]*(1-e)+a[2]*e}for(var g in d)d[g]/=255;this.boxcolor=colorToString(d);this.setOutputData(0,d)}};LiteGraph.registerNodeType("color/palette",d);g.title="Frame";
g.desc="Frame viewerew";g.widgets=[{name:"resize",text:"Resize box",type:"button"},{name:"view",text:"View Image",type:"button"}];g.prototype.onDrawBackground=function(a){this.frame&&a.drawImage(this.frame,0,0,this.size[0],this.size[1])};g.prototype.onExecute=function(){this.frame=this.getInputData(0);this.setDirtyCanvas(!0)};g.prototype.onWidget=function(a,b){if("resize"==b.name&&this.frame){var d=this.frame.width,e=this.frame.height;d||null==this.frame.videoWidth||(d=this.frame.videoWidth,e=this.frame.videoHeight);
d&&e&&(this.size=[d,e]);this.setDirtyCanvas(!0,!0)}else"view"==b.name&&this.show()};g.prototype.show=function(){showElement&&this.frame&&showElement(this.frame)};LiteGraph.registerNodeType("graphics/frame",g);k.title="Image fade";k.desc="Fades between images";k.widgets=[{name:"resizeA",text:"Resize to A",type:"button"},{name:"resizeB",text:"Resize to B",type:"button"}];k.prototype.onAdded=function(){this.createCanvas();var a=this.canvas.getContext("2d");a.fillStyle="#000";a.fillRect(0,0,this.properties.width,
this.properties.height)};k.prototype.createCanvas=function(){this.canvas=document.createElement("canvas");this.canvas.width=this.properties.width;this.canvas.height=this.properties.height};k.prototype.onExecute=function(){var a=this.canvas.getContext("2d");this.canvas.width=this.canvas.width;var b=this.getInputData(0);null!=b&&a.drawImage(b,0,0,this.canvas.width,this.canvas.height);b=this.getInputData(2);null==b?b=this.properties.fade:this.properties.fade=b;a.globalAlpha=b;b=this.getInputData(1);
null!=b&&a.drawImage(b,0,0,this.canvas.width,this.canvas.height);a.globalAlpha=1;this.setOutputData(0,this.canvas);this.setDirtyCanvas(!0)};LiteGraph.registerNodeType("graphics/imagefade",k);h.title="Crop";h.desc="Crop Image";h.prototype.onAdded=function(){this.createCanvas()};h.prototype.createCanvas=function(){this.canvas=document.createElement("canvas");this.canvas.width=this.properties.width;this.canvas.height=this.properties.height};h.prototype.onExecute=function(){var a=this.getInputData(0);
a&&(a.width?(this.canvas.getContext("2d").drawImage(a,-this.properties.x,-this.properties.y,a.width*this.properties.scale,a.height*this.properties.scale),this.setOutputData(0,this.canvas)):this.setOutputData(0,null))};h.prototype.onDrawBackground=function(a){this.flags.collapsed||this.canvas&&a.drawImage(this.canvas,0,0,this.canvas.width,this.canvas.height,0,0,this.size[0],this.size[1])};h.prototype.onPropertyChanged=function(a,b){this.properties[a]=b;"scale"==a?(this.properties[a]=parseFloat(b),
0==this.properties[a]&&(this.trace("Error in scale"),this.properties[a]=1)):this.properties[a]=parseInt(b);this.createCanvas();return!0};LiteGraph.registerNodeType("graphics/cropImage",h);a.title="Video";a.desc="Video playback";a.widgets=[{name:"play",text:"PLAY",type:"minibutton"},{name:"stop",text:"STOP",type:"minibutton"},{name:"demo",text:"Demo video",type:"button"},{name:"mute",text:"Mute video",type:"button"}];a.prototype.onExecute=function(){if(this.properties.url&&(this.properties.url!=this._video_url&&
this.loadVideo(this.properties.url),this._video&&0!=this._video.width)){var a=this.getInputData(0);a&&0<=a&&1>=a&&(this._video.currentTime=a*this._video.duration,this._video.pause());this._video.dirty=!0;this.setOutputData(0,this._video);this.setOutputData(1,this._video.currentTime);this.setOutputData(2,this._video.duration);this.setDirtyCanvas(!0)}};a.prototype.onStart=function(){this.play()};a.prototype.onStop=function(){this.stop()};a.prototype.loadVideo=function(a){this._video_url=a;this._video=
document.createElement("video");this._video.src=a;this._video.type="type=video/mp4";this._video.muted=!0;this._video.autoplay=!0;var b=this;this._video.addEventListener("loadedmetadata",function(a){b.trace("Duration: "+this.duration+" seconds");b.trace("Size: "+this.videoWidth+","+this.videoHeight);b.setDirtyCanvas(!0);this.width=this.videoWidth;this.height=this.videoHeight});this._video.addEventListener("progress",function(a){});this._video.addEventListener("error",function(a){console.log("Error loading video: "+
this.src);b.trace("Error loading video: "+this.src);if(this.error)switch(this.error.code){case this.error.MEDIA_ERR_ABORTED:b.trace("You stopped the video.");break;case this.error.MEDIA_ERR_NETWORK:b.trace("Network error - please try again later.");break;case this.error.MEDIA_ERR_DECODE:b.trace("Video is broken..");break;case this.error.MEDIA_ERR_SRC_NOT_SUPPORTED:b.trace("Sorry, your browser can't play this video.")}});this._video.addEventListener("ended",function(a){b.trace("Ended.");this.play()})};
f.prototype.onPropertyChanged=function(a,b){this.properties[a]=b;"url"==a&&""!=b&&this.loadVideo(b);return!0};f.prototype.play=function(){this._video&&this._video.play()};f.prototype.playPause=function(){this._video&&(this._video.paused?this.play():this.pause())};f.prototype.stop=function(){this._video&&(this._video.pause(),this._video.currentTime=0)};f.prototype.pause=function(){this._video&&(this.trace("Video paused"),this._video.pause())};f.prototype.onWidget=function(a,b){};LiteGraph.registerNodeType("graphics/video",
f);g.title="Webcam";g.desc="Webcam image";g.prototype.openStream=function(){function a(c){console.log("Webcam rejected",c);b._webcam_stream=!1;b.box_color="red"}navigator.getUserMedia=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia;window.URL=window.URL||window.webkitURL;if(navigator.getUserMedia){this._waiting_confirmation=!0;navigator.getUserMedia({video:!0},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)})();
a.prototype.onPropertyChanged=function(a,b){this.properties[a]=b;"url"==a&&""!=b&&this.loadVideo(b);return!0};a.prototype.play=function(){this._video&&this._video.play()};a.prototype.playPause=function(){this._video&&(this._video.paused?this.play():this.pause())};a.prototype.stop=function(){this._video&&(this._video.pause(),this._video.currentTime=0)};a.prototype.pause=function(){this._video&&(this.trace("Video paused"),this._video.pause())};a.prototype.onWidget=function(a,b){};LiteGraph.registerNodeType("graphics/video",
a);b.title="Webcam";b.desc="Webcam image";b.prototype.openStream=function(){function a(c){console.log("Webcam rejected",c);b._webcam_stream=!1;b.box_color="red"}navigator.getUserMedia=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia;window.URL=window.URL||window.webkitURL;if(navigator.getUserMedia){this._waiting_confirmation=!0;navigator.getUserMedia({video:!0},this.streamReady.bind(this),a);var b=this}};b.prototype.onRemoved=function(){this._webcam_stream&&
(this._webcam_stream.stop(),this._video=this._webcam_stream=null)};b.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)})};b.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))};b.prototype.getExtraMenuOptions=function(a){var b=this;return[{content:b.properties.show?"Hide Frame":"Show Frame",callback:function(){b.properties.show=!b.properties.show}}]};b.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",b)})();
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&&a.webgl){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.boxcolor="#FF0000";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 n=
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:n}).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\tvec4 color4 = texture2D(u_texture, uv);\n\t\t\t\tvec3 color = color4.rgb;\n\t\t\t\tvec4 color4B = texture2D(u_textureB, uv);\n\t\t\t\tvec3 colorB = color4B.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";
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(e,d){d=d||{};var g=e;"http://"==g.substr(0,7)&&LiteGraph.proxy&&(g=LiteGraph.proxy+g.substr(7));return LGraphTexture.getTexturesContainer()[e]=GL.Texture.fromURL(g,
d)};LGraphTexture.getTexture=function(e){var d=this.getTexturesContainer();if(!d)throw"Cannot load texture, container of textures not found";d=d[e];return!d&&e&&":"!=e[0]?this.loadTexture(e):d};LGraphTexture.getTargetTexture=function(e,d,g){if(!e)throw"LGraphTexture.getTargetTexture expects a reference texture";var k=null;switch(g){case LGraphTexture.LOW:k=gl.UNSIGNED_BYTE;break;case LGraphTexture.HIGH:k=gl.HIGH_PRECISION_FORMAT;break;case LGraphTexture.REUSE:return e;default:k=e?e.type:gl.UNSIGNED_BYTE}d&&
d.width==e.width&&d.height==e.height&&d.type==k||(d=new GL.Texture(e.width,e.height,{type:k,format:gl.RGBA,filter:gl.LINEAR}));return d};LGraphTexture.getNoiseTexture=function(){if(this._noise_texture)return this._noise_texture;for(var e=new Uint8Array(1048576),d=0;1048576>d;++d)e[d]=255*Math.random();return this._noise_texture=e=GL.Texture.fromMemory(512,512,e,{format:gl.RGBA,wrap:gl.REPEAT,filter:gl.NEAREST})};LGraphTexture.prototype.onDropFile=function(e,d,g){if(e){var k=null;"string"==typeof e?
k=GL.Texture.fromURL(e):-1!=d.toLowerCase().indexOf(".dds")?k=GL.Texture.fromDDSInMemory(e):(e=new Blob([g]),e=URL.createObjectURL(e),k=GL.Texture.fromURL(e));this._drop_texture=k;this.properties.name=d}else this._drop_texture=null,this.properties.name=""};LGraphTexture.prototype.getExtraMenuOptions=function(e){var d=this;if(this._drop_texture)return[{content:"Clear",callback:function(){d._drop_texture=null;d.properties.name=""}}]};LGraphTexture.prototype.onExecute=function(){var e=null;this.isOutputConnected(1)&&
(e=this.getInputData(0));!e&&this._drop_texture&&(e=this._drop_texture);!e&&this.properties.name&&(e=LGraphTexture.getTexture(this.properties.name));if(e){this._last_tex=e;!1===this.properties.filter?e.setParameter(gl.TEXTURE_MAG_FILTER,gl.NEAREST):e.setParameter(gl.TEXTURE_MAG_FILTER,gl.LINEAR);this.setOutputData(0,e);for(var d=1;d<this.outputs.length;d++){var g=this.outputs[d];if(g){var k=null;"width"==g.name?k=e.width:"height"==g.name?k=e.height:"aspect"==g.name&&(k=e.width/e.height);this.setOutputData(d,
k)}}}};LGraphTexture.prototype.onResourceRenamed=function(e,d){this.properties.name==e&&(this.properties.name=d)};LGraphTexture.prototype.onDrawBackground=function(e){if(!(this.flags.collapsed||20>=this.size[1]))if(this._drop_texture&&e.webgl)e.drawImage(this._drop_texture,0,0,this.size[0],this.size[1]);else{if(this._last_preview_tex!=this._last_tex)if(e.webgl)this._canvas=this._last_tex;else{var d=LGraphTexture.generateLowResTexturePreview(this._last_tex);if(!d)return;this._last_preview_tex=this._last_tex;
this._canvas=cloneCanvas(d)}this._canvas&&(e.save(),e.webgl||(e.translate(0,this.size[1]),e.scale(1,-1)),e.drawImage(this._canvas,0,0,this.size[0],this.size[1]),e.restore())}};LGraphTexture.generateLowResTexturePreview=function(e){if(!e)return null;var d=LGraphTexture.image_preview_size,g=e;if(e.format==gl.DEPTH_COMPONENT)return null;if(e.width>d||e.height>d)g=this._preview_temp_tex,this._preview_temp_tex||(this._preview_temp_tex=g=new GL.Texture(d,d,{minFilter:gl.NEAREST})),e.copyTo(g);e=this._preview_canvas;
e||(this._preview_canvas=e=createCanvas(d,d));g&&g.toCanvas(e);return e};LGraphTexture.prototype.getResources=function(e){e[this.properties.name]=GL.Texture;return e};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(e){if(!this.flags.collapsed&&e.webgl){var d=this.getInputData(0);if(d){var g=null,g=!d.handle&&e.webgl?d:LGraphTexture.generateLowResTexturePreview(d);e.save();this.properties.flipY&&(e.translate(0,this.size[1]),e.scale(1,-1));e.drawImage(g,0,0,this.size[0],
this.size[1]);e.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 e=this.getInputData(0);e&&(this.properties.name&&(LGraphTexture.getTexturesContainer()[this.properties.name]=e),this.setOutputData(0,e))};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(e){var d=this;return[{content:d.properties.show?"Hide Texture":"Show Texture",
callback:function(){d.properties.show=!d.properties.show}}]};LGraphTextureOperation.prototype.onDrawBackground=function(e){this.flags.collapsed||20>=this.size[1]||!this.properties.show||!this._tex||this._tex.gl!=e||(e.save(),e.drawImage(this._tex,0,0,this.size[0],this.size[1]),e.restore())};LGraphTextureOperation.prototype.onExecute=function(){var e=this.getInputData(0);if(this.isOutputConnected(0))if(this.properties.precision===LGraphTexture.PASS_THROUGH)this.setOutputData(0,e);else{var d=this.getInputData(1);
if(this.properties.uvcode||this.properties.pixelcode){var g=512,k=512;e?(g=e.width,k=e.height):d&&(g=d.width,k=d.height);this._tex=e||this._tex?LGraphTexture.getTargetTexture(e||this._tex,this._tex,this.properties.precision):new GL.Texture(g,k,{type:this.precision===LGraphTexture.LOW?gl.UNSIGNED_BYTE:gl.HIGH_PRECISION_FORMAT,format:gl.RGBA,filter:gl.LINEAR});var h="";this.properties.uvcode&&(h="uv = "+this.properties.uvcode,-1!=this.properties.uvcode.indexOf(";")&&(h=this.properties.uvcode));var a=
"";this.properties.pixelcode&&(a="result = "+this.properties.pixelcode,-1!=this.properties.pixelcode.indexOf(";")&&(a=this.properties.pixelcode));var b=this._shader;if(!b||this._shader_code!=h+"|"+a){try{this._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,LGraphTextureOperation.pixel_shader,{UV_CODE:h,PIXEL_CODE:a}),this.boxcolor="#00FF00"}catch(c){console.log("Error compiling shader: ",c);this.boxcolor="#FF0000";return}this.boxcolor="#FF0000";this._shader_code=h+"|"+a;b=this._shader}if(b){this.boxcolor=
"green";var f=this.getInputData(2);null!=f?this.properties.value=f:f=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);e&&e.bind(0);d&&d.bind(1);var a=Mesh.getScreenQuad();b.uniforms({u_texture:0,u_textureB:1,value:f,texSize:[g,k],time:l}).draw(a)});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\tvec4 color4 = texture2D(u_texture, uv);\n\t\t\t\tvec3 color = color4.rgb;\n\t\t\t\tvec4 color4B = texture2D(u_textureB, uv);\n\t\t\t\tvec3 colorB = color4B.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",
"vec2");this.addOutput("out","Texture");this.properties={offset:vec2.fromValues(0,0),scale:vec2.fromValues(1,1),precision:LGraphTexture.DEFAULT}};LGraphTextureScaleOffset.widgets_info={precision:{widget:"combo",values:LGraphTexture.MODE_VALUES}};LGraphTextureScaleOffset.title="Scale/Offset";LGraphTextureScaleOffset.desc="Applies an scaling and offseting";LGraphTextureScaleOffset.prototype.onExecute=function(){var a=this.getInputData(0);if(this.isOutputConnected(0)&&a)if(this.properties.precision===
LGraphTexture.PASS_THROUGH)this.setOutputData(0,a);else{var b=a.width,c=a.height,d=this.precision===LGraphTexture.LOW?gl.UNSIGNED_BYTE:gl.HIGH_PRECISION_FORMAT;this.precision===LGraphTexture.DEFAULT&&(d=a.type);this._tex&&this._tex.width==b&&this._tex.height==c&&this._tex.type==d||(this._tex=new GL.Texture(b,c,{type:d,format:gl.RGBA,filter:gl.LINEAR}));var e=this._shader;e||(e=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,LGraphTextureScaleOffset.pixel_shader));var f=this.getInputData(1);f?(this.properties.scale[0]=
f[0],this.properties.scale[1]=f[1]):f=this.properties.scale;var g=this.getInputData(2);g?(this.properties.offset[0]=g[0],this.properties.offset[1]=g[1]):g=this.properties.offset;this._tex.drawTo(function(){gl.disable(gl.DEPTH_TEST);gl.disable(gl.CULL_FACE);gl.disable(gl.BLEND);a.bind(0);var b=Mesh.getScreenQuad();e.uniforms({u_texture:0,u_scale:f,u_offset:g}).draw(b)});this.setOutputData(0,this._tex)}};LGraphTextureScaleOffset.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 u_scale;\n\t\t\tuniform vec2 u_offset;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec2 uv = v_coord;\n\t\t\t\tuv = uv / u_scale - u_offset;\n\t\t\t\tgl_FragColor = texture2D(u_texture, uv);\n\t\t\t}\n\t\t\t";
filter:gl.LINEAR}));var e=this._tex,d=this._shader,g=this.graph.getTime();e.drawTo(function(){d.uniforms({texSize:[e.width,e.height],time:g}).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",
"vec2");this.addOutput("out","Texture");this.properties={offset:vec2.fromValues(0,0),scale:vec2.fromValues(1,1),precision:LGraphTexture.DEFAULT}};LGraphTextureScaleOffset.widgets_info={precision:{widget:"combo",values:LGraphTexture.MODE_VALUES}};LGraphTextureScaleOffset.title="Scale/Offset";LGraphTextureScaleOffset.desc="Applies an scaling and offseting";LGraphTextureScaleOffset.prototype.onExecute=function(){var e=this.getInputData(0);if(this.isOutputConnected(0)&&e)if(this.properties.precision===
LGraphTexture.PASS_THROUGH)this.setOutputData(0,e);else{var d=e.width,g=e.height,k=this.precision===LGraphTexture.LOW?gl.UNSIGNED_BYTE:gl.HIGH_PRECISION_FORMAT;this.precision===LGraphTexture.DEFAULT&&(k=e.type);this._tex&&this._tex.width==d&&this._tex.height==g&&this._tex.type==k||(this._tex=new GL.Texture(d,g,{type:k,format:gl.RGBA,filter:gl.LINEAR}));var h=this._shader;h||(h=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,LGraphTextureScaleOffset.pixel_shader));var a=this.getInputData(1);a?(this.properties.scale[0]=
a[0],this.properties.scale[1]=a[1]):a=this.properties.scale;var b=this.getInputData(2);b?(this.properties.offset[0]=b[0],this.properties.offset[1]=b[1]):b=this.properties.offset;this._tex.drawTo(function(){gl.disable(gl.DEPTH_TEST);gl.disable(gl.CULL_FACE);gl.disable(gl.BLEND);e.bind(0);var c=Mesh.getScreenQuad();h.uniforms({u_texture:0,u_scale:a,u_offset:b}).draw(c)});this.setOutputData(0,this._tex)}};LGraphTextureScaleOffset.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 u_scale;\n\t\t\tuniform vec2 u_offset;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec2 uv = v_coord;\n\t\t\t\tuv = uv / u_scale - u_offset;\n\t\t\t\tgl_FragColor = texture2D(u_texture, uv);\n\t\t\t}\n\t\t\t";
LiteGraph.registerNodeType("texture/scaleOffset",LGraphTextureScaleOffset);var LGraphTextureWarp=function(){this.addInput("in","Texture");this.addInput("warp","Texture");this.addInput("factor","number");this.addOutput("out","Texture");this.properties={factor:0.01,precision:LGraphTexture.DEFAULT}};LGraphTextureWarp.widgets_info={precision:{widget:"combo",values:LGraphTexture.MODE_VALUES}};LGraphTextureWarp.title="Warp";LGraphTextureWarp.desc="Texture warp operation";LGraphTextureWarp.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),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._shader;
e||(e=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,LGraphTextureWarp.pixel_shader));var f=this.getInputData(2);null!=f?this.properties.factor=f:f=parseFloat(this.properties.factor);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 c=Mesh.getScreenQuad();e.uniforms({u_texture:0,u_textureB:1,u_factor:f}).draw(c)});this.setOutputData(0,this._tex)}};LGraphTextureWarp.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 float u_factor;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec2 uv = v_coord;\n\t\t\t\tuv += texture2D(u_textureB, uv).rg * u_factor;\n\t\t\t\tgl_FragColor = texture2D(u_texture, uv);\n\t\t\t}\n\t\t\t";
LiteGraph.registerNodeType("texture/warp",LGraphTextureWarp);var LGraphTextureToViewport=function(){this.addInput("Texture","Texture");this.properties={additive:!1,antialiasing:!1,filter:!0,disable_alpha:!1,gamma:1};this.size[0]=130};LGraphTextureToViewport.title="to Viewport";LGraphTextureToViewport.desc="Texture to viewport";LGraphTextureToViewport.prototype.onExecute=function(){var a=this.getInputData(0);if(a){this.properties.disable_alpha?gl.disable(gl.BLEND):(gl.enable(gl.BLEND),this.properties.additive?
gl.blendFunc(gl.SRC_ALPHA,gl.ONE):gl.blendFunc(gl.SRC_ALPHA,gl.ONE_MINUS_SRC_ALPHA));gl.disable(gl.DEPTH_TEST);var b=this.properties.gamma||1;this.isInputConnected(1)&&(b=this.getInputData(1));a.setParameter(gl.TEXTURE_MAG_FILTER,this.properties.filter?gl.LINEAR:gl.NEAREST);if(this.properties.antialiasing){LGraphTextureToViewport._shader||(LGraphTextureToViewport._shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,LGraphTextureToViewport.aa_pixel_shader));gl.getViewport();var c=Mesh.getScreenQuad();
a.bind(0);LGraphTextureToViewport._shader.uniforms({u_texture:0,uViewportSize:[a.width,a.height],u_igamma:1/b,inverseVP:[1/a.width,1/a.height]}).draw(c)}else 1!=b?(LGraphTextureToViewport._gamma_shader||(LGraphTextureToViewport._gamma_shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,LGraphTextureToViewport.gamma_pixel_shader)),a.toViewport(LGraphTextureToViewport._gamma_shader,{u_texture:0,u_igamma:1/b})):a.toViewport()}};LGraphTextureToViewport.prototype.onGetInputs=function(){return[["gamma","number"]]};
function(){var e=this.getInputData(0);if(this.isOutputConnected(0))if(this.properties.precision===LGraphTexture.PASS_THROUGH)this.setOutputData(0,e);else{var d=this.getInputData(1),g=512,k=512;e?(g=e.width,k=e.height):d&&(g=d.width,k=d.height);this._tex=e||this._tex?LGraphTexture.getTargetTexture(e||this._tex,this._tex,this.properties.precision):new GL.Texture(g,k,{type:this.precision===LGraphTexture.LOW?gl.UNSIGNED_BYTE:gl.HIGH_PRECISION_FORMAT,format:gl.RGBA,filter:gl.LINEAR});var h=this._shader;
h||(h=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,LGraphTextureWarp.pixel_shader));var a=this.getInputData(2);null!=a?this.properties.factor=a:a=parseFloat(this.properties.factor);this._tex.drawTo(function(){gl.disable(gl.DEPTH_TEST);gl.disable(gl.CULL_FACE);gl.disable(gl.BLEND);e&&e.bind(0);d&&d.bind(1);var b=Mesh.getScreenQuad();h.uniforms({u_texture:0,u_textureB:1,u_factor:a}).draw(b)});this.setOutputData(0,this._tex)}};LGraphTextureWarp.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 float u_factor;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec2 uv = v_coord;\n\t\t\t\tuv += texture2D(u_textureB, uv).rg * u_factor;\n\t\t\t\tgl_FragColor = texture2D(u_texture, uv);\n\t\t\t}\n\t\t\t";
LiteGraph.registerNodeType("texture/warp",LGraphTextureWarp);var LGraphTextureToViewport=function(){this.addInput("Texture","Texture");this.properties={additive:!1,antialiasing:!1,filter:!0,disable_alpha:!1,gamma:1};this.size[0]=130};LGraphTextureToViewport.title="to Viewport";LGraphTextureToViewport.desc="Texture to viewport";LGraphTextureToViewport.prototype.onExecute=function(){var e=this.getInputData(0);if(e){this.properties.disable_alpha?gl.disable(gl.BLEND):(gl.enable(gl.BLEND),this.properties.additive?
gl.blendFunc(gl.SRC_ALPHA,gl.ONE):gl.blendFunc(gl.SRC_ALPHA,gl.ONE_MINUS_SRC_ALPHA));gl.disable(gl.DEPTH_TEST);var d=this.properties.gamma||1;this.isInputConnected(1)&&(d=this.getInputData(1));e.setParameter(gl.TEXTURE_MAG_FILTER,this.properties.filter?gl.LINEAR:gl.NEAREST);if(this.properties.antialiasing){LGraphTextureToViewport._shader||(LGraphTextureToViewport._shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,LGraphTextureToViewport.aa_pixel_shader));gl.getViewport();var g=Mesh.getScreenQuad();
e.bind(0);LGraphTextureToViewport._shader.uniforms({u_texture:0,uViewportSize:[e.width,e.height],u_igamma:1/d,inverseVP:[1/e.width,1/e.height]}).draw(g)}else 1!=d?(LGraphTextureToViewport._gamma_shader||(LGraphTextureToViewport._gamma_shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,LGraphTextureToViewport.gamma_pixel_shader)),e.toViewport(LGraphTextureToViewport._gamma_shader,{u_texture:0,u_igamma:1/d})):e.toViewport()}};LGraphTextureToViewport.prototype.onGetInputs=function(){return[["gamma","number"]]};
LGraphTextureToViewport.aa_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 vec2 uViewportSize;\n\t\t\tuniform vec2 inverseVP;\n\t\t\tuniform float u_igamma;\n\t\t\t#define FXAA_REDUCE_MIN (1.0/ 128.0)\n\t\t\t#define FXAA_REDUCE_MUL (1.0 / 8.0)\n\t\t\t#define FXAA_SPAN_MAX 8.0\n\t\t\t\n\t\t\t/* from mitsuhiko/webgl-meincraft based on the code on geeks3d.com */\n\t\t\tvec4 applyFXAA(sampler2D tex, vec2 fragCoord)\n\t\t\t{\n\t\t\t\tvec4 color = vec4(0.0);\n\t\t\t\t/*vec2 inverseVP = vec2(1.0 / uViewportSize.x, 1.0 / uViewportSize.y);*/\n\t\t\t\tvec3 rgbNW = texture2D(tex, (fragCoord + vec2(-1.0, -1.0)) * inverseVP).xyz;\n\t\t\t\tvec3 rgbNE = texture2D(tex, (fragCoord + vec2(1.0, -1.0)) * inverseVP).xyz;\n\t\t\t\tvec3 rgbSW = texture2D(tex, (fragCoord + vec2(-1.0, 1.0)) * inverseVP).xyz;\n\t\t\t\tvec3 rgbSE = texture2D(tex, (fragCoord + vec2(1.0, 1.0)) * inverseVP).xyz;\n\t\t\t\tvec3 rgbM = texture2D(tex, fragCoord * inverseVP).xyz;\n\t\t\t\tvec3 luma = vec3(0.299, 0.587, 0.114);\n\t\t\t\tfloat lumaNW = dot(rgbNW, luma);\n\t\t\t\tfloat lumaNE = dot(rgbNE, luma);\n\t\t\t\tfloat lumaSW = dot(rgbSW, luma);\n\t\t\t\tfloat lumaSE = dot(rgbSE, luma);\n\t\t\t\tfloat lumaM = dot(rgbM, luma);\n\t\t\t\tfloat lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));\n\t\t\t\tfloat lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));\n\t\t\t\t\n\t\t\t\tvec2 dir;\n\t\t\t\tdir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));\n\t\t\t\tdir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));\n\t\t\t\t\n\t\t\t\tfloat dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * FXAA_REDUCE_MUL), FXAA_REDUCE_MIN);\n\t\t\t\t\n\t\t\t\tfloat rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce);\n\t\t\t\tdir = min(vec2(FXAA_SPAN_MAX, FXAA_SPAN_MAX), max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX), dir * rcpDirMin)) * inverseVP;\n\t\t\t\t\n\t\t\t\tvec3 rgbA = 0.5 * (texture2D(tex, fragCoord * inverseVP + dir * (1.0 / 3.0 - 0.5)).xyz + \n\t\t\t\t\ttexture2D(tex, fragCoord * inverseVP + dir * (2.0 / 3.0 - 0.5)).xyz);\n\t\t\t\tvec3 rgbB = rgbA * 0.5 + 0.25 * (texture2D(tex, fragCoord * inverseVP + dir * -0.5).xyz + \n\t\t\t\t\ttexture2D(tex, fragCoord * inverseVP + dir * 0.5).xyz);\n\t\t\t\t\n\t\t\t\t//return vec4(rgbA,1.0);\n\t\t\t\tfloat lumaB = dot(rgbB, luma);\n\t\t\t\tif ((lumaB < lumaMin) || (lumaB > lumaMax))\n\t\t\t\t\tcolor = vec4(rgbA, 1.0);\n\t\t\t\telse\n\t\t\t\t\tcolor = vec4(rgbB, 1.0);\n\t\t\t\tif(u_igamma != 1.0)\n\t\t\t\t\tcolor.xyz = pow( color.xyz, vec3(u_igamma) );\n\t\t\t\treturn color;\n\t\t\t}\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t gl_FragColor = applyFXAA( u_texture, v_coord * uViewportSize) ;\n\t\t\t}\n\t\t\t";
LGraphTextureToViewport.gamma_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 float u_igamma;\n\t\t\tvoid main() {\n\t\t\t\tvec4 color = texture2D( u_texture, v_coord);\n\t\t\t\tcolor.xyz = pow(color.xyz, vec3(u_igamma) );\n\t\t\t gl_FragColor = color;\n\t\t\t}\n\t\t\t";LiteGraph.registerNodeType("texture/toviewport",LGraphTextureToViewport);var LGraphTextureCopy=function(){this.addInput("Texture",
"Texture");this.addOutput("","Texture");this.properties={size:0,generate_mipmaps:!1,precision:LGraphTexture.DEFAULT}};LGraphTextureCopy.title="Copy";LGraphTextureCopy.desc="Copy Texture";LGraphTextureCopy.widgets_info={size:{widget:"combo",values:[0,32,64,128,256,512,1024,2048]},precision:{widget:"combo",values:LGraphTexture.MODE_VALUES}};LGraphTextureCopy.prototype.onExecute=function(){var a=this.getInputData(0);if((a||this._temp_texture)&&this.isOutputConnected(0)){if(a){var b=a.width,c=a.height;
0!=this.properties.size&&(c=b=this.properties.size);var d=this._temp_texture,e=a.type;this.properties.precision===LGraphTexture.LOW?e=gl.UNSIGNED_BYTE:this.properties.precision===LGraphTexture.HIGH&&(e=gl.HIGH_PRECISION_FORMAT);d&&d.width==b&&d.height==c&&d.type==e||(d=gl.LINEAR,this.properties.generate_mipmaps&&isPowerOfTwo(b)&&isPowerOfTwo(c)&&(d=gl.LINEAR_MIPMAP_LINEAR),this._temp_texture=new GL.Texture(b,c,{type:e,format:gl.RGBA,minFilter:d,magFilter:gl.LINEAR}));a.copyTo(this._temp_texture);
"Texture");this.addOutput("","Texture");this.properties={size:0,generate_mipmaps:!1,precision:LGraphTexture.DEFAULT}};LGraphTextureCopy.title="Copy";LGraphTextureCopy.desc="Copy Texture";LGraphTextureCopy.widgets_info={size:{widget:"combo",values:[0,32,64,128,256,512,1024,2048]},precision:{widget:"combo",values:LGraphTexture.MODE_VALUES}};LGraphTextureCopy.prototype.onExecute=function(){var e=this.getInputData(0);if((e||this._temp_texture)&&this.isOutputConnected(0)){if(e){var d=e.width,g=e.height;
0!=this.properties.size&&(g=d=this.properties.size);var k=this._temp_texture,h=e.type;this.properties.precision===LGraphTexture.LOW?h=gl.UNSIGNED_BYTE:this.properties.precision===LGraphTexture.HIGH&&(h=gl.HIGH_PRECISION_FORMAT);k&&k.width==d&&k.height==g&&k.type==h||(k=gl.LINEAR,this.properties.generate_mipmaps&&isPowerOfTwo(d)&&isPowerOfTwo(g)&&(k=gl.LINEAR_MIPMAP_LINEAR),this._temp_texture=new GL.Texture(d,g,{type:h,format:gl.RGBA,minFilter:k,magFilter:gl.LINEAR}));e.copyTo(this._temp_texture);
this.properties.generate_mipmaps&&(this._temp_texture.bind(0),gl.generateMipmap(this._temp_texture.texture_type),this._temp_texture.unbind(0))}this.setOutputData(0,this._temp_texture)}};LiteGraph.registerNodeType("texture/copy",LGraphTextureCopy);var LGraphTextureAverage=function(){this.addInput("Texture","Texture");this.addOutput("","Texture");this.properties={low_precision:!1}};LGraphTextureAverage.title="Average";LGraphTextureAverage.desc="Compute the total average of a texture and stores it as a 1x1 pixel texture";
LGraphTextureAverage.prototype.onExecute=function(){var a=this.getInputData(0);if(a&&this.isOutputConnected(0)){if(!LGraphTextureAverage._shader){LGraphTextureAverage._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,LGraphTextureAverage.pixel_shader);for(var b=new Float32Array(32),c=0;32>c;++c)b[c]=Math.random();LGraphTextureAverage._shader.uniforms({u_samples_a:b.subarray(0,16),u_samples_b:b.subarray(16,32)})}b=this._temp_texture;c=this.properties.low_precision?gl.UNSIGNED_BYTE:a.type;b&&b.type==
c||(this._temp_texture=new GL.Texture(1,1,{type:c,format:gl.RGBA,filter:gl.NEAREST}));var d=LGraphTextureAverage._shader;this._temp_texture.drawTo(function(){a.toViewport(d,{u_texture:0})});this.setOutputData(0,this._temp_texture)}};LGraphTextureAverage.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tuniform mat4 u_samples_a;\n\t\t\tuniform mat4 u_samples_b;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tvarying vec2 v_coord;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec4 color = vec4(0.0);\n\t\t\t\tfor(int i = 0; i < 4; ++i)\n\t\t\t\t\tfor(int j = 0; j < 4; ++j)\n\t\t\t\t\t{\n\t\t\t\t\t\tcolor += texture2D(u_texture, vec2( u_samples_a[i][j], u_samples_b[i][j] ) );\n\t\t\t\t\t\tcolor += texture2D(u_texture, vec2( 1.0 - u_samples_a[i][j], u_samples_b[i][j] ) );\n\t\t\t\t\t}\n\t\t\t gl_FragColor = color * 0.03125;\n\t\t\t}\n\t\t\t";
LiteGraph.registerNodeType("texture/average",LGraphTextureAverage);var LGraphImageToTexture=function(){this.addInput("Image","image");this.addOutput("","Texture");this.properties={}};LGraphImageToTexture.title="Image to Texture";LGraphImageToTexture.desc="Uploads an image to the GPU";LGraphImageToTexture.prototype.onExecute=function(){var a=this.getInputData(0);if(a){var b=a.videoWidth||a.width,c=a.videoHeight||a.height;if(a.gltexture)this.setOutputData(0,a.gltexture);else{var d=this._temp_texture;
d&&d.width==b&&d.height==c||(this._temp_texture=new GL.Texture(b,c,{format:gl.RGBA,filter:gl.LINEAR}));try{this._temp_texture.uploadImage(a)}catch(e){console.error("image comes from an unsafe location, cannot be uploaded to webgl");return}this.setOutputData(0,this._temp_texture)}}};LiteGraph.registerNodeType("texture/imageToTexture",LGraphImageToTexture);var LGraphTextureLUT=function(){this.addInput("Texture","Texture");this.addInput("LUT","Texture");this.addInput("Intensity","number");this.addOutput("",
"Texture");this.properties={intensity:1,precision:LGraphTexture.DEFAULT,texture:null};LGraphTextureLUT._shader||(LGraphTextureLUT._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,LGraphTextureLUT.pixel_shader))};LGraphTextureLUT.widgets_info={precision:{widget:"combo",values:LGraphTexture.MODE_VALUES}};LGraphTextureLUT.title="LUT";LGraphTextureLUT.desc="Apply LUT to Texture";LGraphTextureLUT.widgets_info={texture:{widget:"texture"}};LGraphTextureLUT.prototype.onExecute=function(){if(this.isOutputConnected(0)){var a=
this.getInputData(0);if(this.properties.precision===LGraphTexture.PASS_THROUGH)this.setOutputData(0,a);else if(a){var b=this.getInputData(1);b||(b=LGraphTexture.getTexture(this.properties.texture));if(b){b.bind(0);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,gl.LINEAR);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,gl.CLAMP_TO_EDGE);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,gl.CLAMP_TO_EDGE);gl.bindTexture(gl.TEXTURE_2D,null);var c=this.properties.intensity;this.isInputConnected(2)&&
(this.properties.intensity=c=this.getInputData(2));this._tex=LGraphTexture.getTargetTexture(a,this._tex,this.properties.precision);this._tex.drawTo(function(){b.bind(1);a.toViewport(LGraphTextureLUT._shader,{u_texture:0,u_textureB:1,u_amount:c})});this.setOutputData(0,this._tex)}else this.setOutputData(0,a)}}};LGraphTextureLUT.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_textureB;\n\t\t\tuniform float u_amount;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\t lowp vec4 textureColor = clamp( texture2D(u_texture, v_coord), vec4(0.0), vec4(1.0) );\n\t\t\t\t mediump float blueColor = textureColor.b * 63.0;\n\t\t\t\t mediump vec2 quad1;\n\t\t\t\t quad1.y = floor(floor(blueColor) / 8.0);\n\t\t\t\t quad1.x = floor(blueColor) - (quad1.y * 8.0);\n\t\t\t\t mediump vec2 quad2;\n\t\t\t\t quad2.y = floor(ceil(blueColor) / 8.0);\n\t\t\t\t quad2.x = ceil(blueColor) - (quad2.y * 8.0);\n\t\t\t\t highp vec2 texPos1;\n\t\t\t\t texPos1.x = (quad1.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.r);\n\t\t\t\t texPos1.y = 1.0 - ((quad1.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.g));\n\t\t\t\t highp vec2 texPos2;\n\t\t\t\t texPos2.x = (quad2.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.r);\n\t\t\t\t texPos2.y = 1.0 - ((quad2.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.g));\n\t\t\t\t lowp vec4 newColor1 = texture2D(u_textureB, texPos1);\n\t\t\t\t lowp vec4 newColor2 = texture2D(u_textureB, texPos2);\n\t\t\t\t lowp vec4 newColor = mix(newColor1, newColor2, fract(blueColor));\n\t\t\t\t gl_FragColor = vec4( mix( textureColor.rgb, newColor.rgb, u_amount), textureColor.w);\n\t\t\t}\n\t\t\t";
LGraphTextureAverage.prototype.onExecute=function(){var e=this.getInputData(0);if(e&&this.isOutputConnected(0)){if(!LGraphTextureAverage._shader){LGraphTextureAverage._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,LGraphTextureAverage.pixel_shader);for(var d=new Float32Array(32),g=0;32>g;++g)d[g]=Math.random();LGraphTextureAverage._shader.uniforms({u_samples_a:d.subarray(0,16),u_samples_b:d.subarray(16,32)})}d=this._temp_texture;g=this.properties.low_precision?gl.UNSIGNED_BYTE:e.type;d&&d.type==
g||(this._temp_texture=new GL.Texture(1,1,{type:g,format:gl.RGBA,filter:gl.NEAREST}));var k=LGraphTextureAverage._shader;this._temp_texture.drawTo(function(){e.toViewport(k,{u_texture:0})});this.setOutputData(0,this._temp_texture)}};LGraphTextureAverage.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tuniform mat4 u_samples_a;\n\t\t\tuniform mat4 u_samples_b;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tvarying vec2 v_coord;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec4 color = vec4(0.0);\n\t\t\t\tfor(int i = 0; i < 4; ++i)\n\t\t\t\t\tfor(int j = 0; j < 4; ++j)\n\t\t\t\t\t{\n\t\t\t\t\t\tcolor += texture2D(u_texture, vec2( u_samples_a[i][j], u_samples_b[i][j] ) );\n\t\t\t\t\t\tcolor += texture2D(u_texture, vec2( 1.0 - u_samples_a[i][j], u_samples_b[i][j] ) );\n\t\t\t\t\t}\n\t\t\t gl_FragColor = color * 0.03125;\n\t\t\t}\n\t\t\t";
LiteGraph.registerNodeType("texture/average",LGraphTextureAverage);var LGraphImageToTexture=function(){this.addInput("Image","image");this.addOutput("","Texture");this.properties={}};LGraphImageToTexture.title="Image to Texture";LGraphImageToTexture.desc="Uploads an image to the GPU";LGraphImageToTexture.prototype.onExecute=function(){var e=this.getInputData(0);if(e){var d=e.videoWidth||e.width,g=e.videoHeight||e.height;if(e.gltexture)this.setOutputData(0,e.gltexture);else{var k=this._temp_texture;
k&&k.width==d&&k.height==g||(this._temp_texture=new GL.Texture(d,g,{format:gl.RGBA,filter:gl.LINEAR}));try{this._temp_texture.uploadImage(e)}catch(h){console.error("image comes from an unsafe location, cannot be uploaded to webgl");return}this.setOutputData(0,this._temp_texture)}}};LiteGraph.registerNodeType("texture/imageToTexture",LGraphImageToTexture);var LGraphTextureLUT=function(){this.addInput("Texture","Texture");this.addInput("LUT","Texture");this.addInput("Intensity","number");this.addOutput("",
"Texture");this.properties={intensity:1,precision:LGraphTexture.DEFAULT,texture:null};LGraphTextureLUT._shader||(LGraphTextureLUT._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,LGraphTextureLUT.pixel_shader))};LGraphTextureLUT.widgets_info={precision:{widget:"combo",values:LGraphTexture.MODE_VALUES}};LGraphTextureLUT.title="LUT";LGraphTextureLUT.desc="Apply LUT to Texture";LGraphTextureLUT.widgets_info={texture:{widget:"texture"}};LGraphTextureLUT.prototype.onExecute=function(){if(this.isOutputConnected(0)){var e=
this.getInputData(0);if(this.properties.precision===LGraphTexture.PASS_THROUGH)this.setOutputData(0,e);else if(e){var d=this.getInputData(1);d||(d=LGraphTexture.getTexture(this.properties.texture));if(d){d.bind(0);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,gl.LINEAR);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,gl.CLAMP_TO_EDGE);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,gl.CLAMP_TO_EDGE);gl.bindTexture(gl.TEXTURE_2D,null);var g=this.properties.intensity;this.isInputConnected(2)&&
(this.properties.intensity=g=this.getInputData(2));this._tex=LGraphTexture.getTargetTexture(e,this._tex,this.properties.precision);this._tex.drawTo(function(){d.bind(1);e.toViewport(LGraphTextureLUT._shader,{u_texture:0,u_textureB:1,u_amount:g})});this.setOutputData(0,this._tex)}else this.setOutputData(0,e)}}};LGraphTextureLUT.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_textureB;\n\t\t\tuniform float u_amount;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\t lowp vec4 textureColor = clamp( texture2D(u_texture, v_coord), vec4(0.0), vec4(1.0) );\n\t\t\t\t mediump float blueColor = textureColor.b * 63.0;\n\t\t\t\t mediump vec2 quad1;\n\t\t\t\t quad1.y = floor(floor(blueColor) / 8.0);\n\t\t\t\t quad1.x = floor(blueColor) - (quad1.y * 8.0);\n\t\t\t\t mediump vec2 quad2;\n\t\t\t\t quad2.y = floor(ceil(blueColor) / 8.0);\n\t\t\t\t quad2.x = ceil(blueColor) - (quad2.y * 8.0);\n\t\t\t\t highp vec2 texPos1;\n\t\t\t\t texPos1.x = (quad1.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.r);\n\t\t\t\t texPos1.y = 1.0 - ((quad1.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.g));\n\t\t\t\t highp vec2 texPos2;\n\t\t\t\t texPos2.x = (quad2.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.r);\n\t\t\t\t texPos2.y = 1.0 - ((quad2.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.g));\n\t\t\t\t lowp vec4 newColor1 = texture2D(u_textureB, texPos1);\n\t\t\t\t lowp vec4 newColor2 = texture2D(u_textureB, texPos2);\n\t\t\t\t lowp vec4 newColor = mix(newColor1, newColor2, fract(blueColor));\n\t\t\t\t gl_FragColor = vec4( mix( textureColor.rgb, newColor.rgb, u_amount), textureColor.w);\n\t\t\t}\n\t\t\t";
LiteGraph.registerNodeType("texture/LUT",LGraphTextureLUT);var LGraphTextureChannels=function(){this.addInput("Texture","Texture");this.addOutput("R","Texture");this.addOutput("G","Texture");this.addOutput("B","Texture");this.addOutput("A","Texture");this.properties={};LGraphTextureChannels._shader||(LGraphTextureChannels._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,LGraphTextureChannels.pixel_shader))};LGraphTextureChannels.title="Texture to Channels";LGraphTextureChannels.desc="Split texture channels";
LGraphTextureChannels.prototype.onExecute=function(){var a=this.getInputData(0);if(a){this._channels||(this._channels=Array(4));for(var b=0,c=0;4>c;c++)this.isOutputConnected(c)?(this._channels[c]&&this._channels[c].width==a.width&&this._channels[c].height==a.height&&this._channels[c].type==a.type||(this._channels[c]=new GL.Texture(a.width,a.height,{type:a.type,format:gl.RGBA,filter:gl.LINEAR})),b++):this._channels[c]=null;if(b){gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);for(var d=Mesh.getScreenQuad(),
e=LGraphTextureChannels._shader,f=[[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]],c=0;4>c;c++)this._channels[c]&&(this._channels[c].drawTo(function(){a.bind(0);e.uniforms({u_texture:0,u_mask:f[c]}).draw(d)}),this.setOutputData(c,this._channels[c]))}}};LGraphTextureChannels.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 vec4 u_mask;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t gl_FragColor = vec4( vec3( length( texture2D(u_texture, v_coord) * u_mask )), 1.0 );\n\t\t\t}\n\t\t\t";
LGraphTextureChannels.prototype.onExecute=function(){var e=this.getInputData(0);if(e){this._channels||(this._channels=Array(4));for(var d=0,g=0;4>g;g++)this.isOutputConnected(g)?(this._channels[g]&&this._channels[g].width==e.width&&this._channels[g].height==e.height&&this._channels[g].type==e.type||(this._channels[g]=new GL.Texture(e.width,e.height,{type:e.type,format:gl.RGBA,filter:gl.LINEAR})),d++):this._channels[g]=null;if(d){gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);for(var k=Mesh.getScreenQuad(),
h=LGraphTextureChannels._shader,a=[[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]],g=0;4>g;g++)this._channels[g]&&(this._channels[g].drawTo(function(){e.bind(0);h.uniforms({u_texture:0,u_mask:a[g]}).draw(k)}),this.setOutputData(g,this._channels[g]))}}};LGraphTextureChannels.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 vec4 u_mask;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t gl_FragColor = vec4( vec3( length( texture2D(u_texture, v_coord) * u_mask )), 1.0 );\n\t\t\t}\n\t\t\t";
LiteGraph.registerNodeType("texture/textureChannels",LGraphTextureChannels);var LGraphChannelsTexture=function(){this.addInput("R","Texture");this.addInput("G","Texture");this.addInput("B","Texture");this.addInput("A","Texture");this.addOutput("Texture","Texture");this.properties={};LGraphChannelsTexture._shader||(LGraphChannelsTexture._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,LGraphChannelsTexture.pixel_shader))};LGraphChannelsTexture.title="Channels to Texture";LGraphChannelsTexture.desc=
"Split texture channels";LGraphChannelsTexture.prototype.onExecute=function(){var a=[this.getInputData(0),this.getInputData(1),this.getInputData(2),this.getInputData(3)];if(a[0]&&a[1]&&a[2]&&a[3]){gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var b=Mesh.getScreenQuad(),c=LGraphChannelsTexture._shader;this._tex=LGraphTexture.getTargetTexture(a[0],this._tex);this._tex.drawTo(function(){a[0].bind(0);a[1].bind(1);a[2].bind(2);a[3].bind(3);c.uniforms({u_textureR:0,u_textureG:1,u_textureB:2,u_textureA:3}).draw(b)});
"Split texture channels";LGraphChannelsTexture.prototype.onExecute=function(){var e=[this.getInputData(0),this.getInputData(1),this.getInputData(2),this.getInputData(3)];if(e[0]&&e[1]&&e[2]&&e[3]){gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var d=Mesh.getScreenQuad(),g=LGraphChannelsTexture._shader;this._tex=LGraphTexture.getTargetTexture(e[0],this._tex);this._tex.drawTo(function(){e[0].bind(0);e[1].bind(1);e[2].bind(2);e[3].bind(3);g.uniforms({u_textureR:0,u_textureG:1,u_textureB:2,u_textureA:3}).draw(d)});
this.setOutputData(0,this._tex)}};LGraphChannelsTexture.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_textureR;\n\t\t\tuniform sampler2D u_textureG;\n\t\t\tuniform sampler2D u_textureB;\n\t\t\tuniform sampler2D u_textureA;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t gl_FragColor = vec4( \t\t\t\t\t\ttexture2D(u_textureR, v_coord).r,\t\t\t\t\t\ttexture2D(u_textureG, v_coord).r,\t\t\t\t\t\ttexture2D(u_textureB, v_coord).r,\t\t\t\t\t\ttexture2D(u_textureA, v_coord).r);\n\t\t\t}\n\t\t\t";
LiteGraph.registerNodeType("texture/channelsTexture",LGraphChannelsTexture);var LGraphTextureGradient=function(){this.addInput("A","color");this.addInput("B","color");this.addOutput("Texture","Texture");this.properties={angle:0,scale:1,A:[0,0,0],B:[1,1,1],texture_size:32};LGraphTextureGradient._shader||(LGraphTextureGradient._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,LGraphTextureGradient.pixel_shader));this._uniforms={u_angle:0,u_colorA:vec3.create(),u_colorB:vec3.create()}};LGraphTextureGradient.title=
"Gradient";LGraphTextureGradient.desc="Generates a gradient";LGraphTextureGradient["@A"]={type:"color"};LGraphTextureGradient["@B"]={type:"color"};LGraphTextureGradient["@texture_size"]={type:"enum",values:[32,64,128,256,512]};LGraphTextureGradient.prototype.onExecute=function(){gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var a=GL.Mesh.getScreenQuad(),b=LGraphTextureGradient._shader,c=this.getInputData(0);c||(c=this.properties.A);var d=this.getInputData(1);d||(d=this.properties.B);for(var e=2;e<
this.inputs.length;e++){var f=this.inputs[e],g=this.getInputData(e);void 0!==g&&(this.properties[f.name]=g)}var h=this._uniforms;this._uniforms.u_angle=this.properties.angle*DEG2RAD;this._uniforms.u_scale=this.properties.scale;vec3.copy(h.u_colorA,c);vec3.copy(h.u_colorB,d);c=parseInt(this.properties.texture_size);this._tex&&this._tex.width==c||(this._tex=new GL.Texture(c,c,{format:gl.RGB,filter:gl.LINEAR}));this._tex.drawTo(function(){b.uniforms(h).draw(a)});this.setOutputData(0,this._tex)};LGraphTextureGradient.prototype.onGetInputs=
"Gradient";LGraphTextureGradient.desc="Generates a gradient";LGraphTextureGradient["@A"]={type:"color"};LGraphTextureGradient["@B"]={type:"color"};LGraphTextureGradient["@texture_size"]={type:"enum",values:[32,64,128,256,512]};LGraphTextureGradient.prototype.onExecute=function(){gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var e=GL.Mesh.getScreenQuad(),d=LGraphTextureGradient._shader,g=this.getInputData(0);g||(g=this.properties.A);var k=this.getInputData(1);k||(k=this.properties.B);for(var h=2;h<
this.inputs.length;h++){var a=this.inputs[h],b=this.getInputData(h);void 0!==b&&(this.properties[a.name]=b)}var c=this._uniforms;this._uniforms.u_angle=this.properties.angle*DEG2RAD;this._uniforms.u_scale=this.properties.scale;vec3.copy(c.u_colorA,g);vec3.copy(c.u_colorB,k);g=parseInt(this.properties.texture_size);this._tex&&this._tex.width==g||(this._tex=new GL.Texture(g,g,{format:gl.RGB,filter:gl.LINEAR}));this._tex.drawTo(function(){d.uniforms(c).draw(e)});this.setOutputData(0,this._tex)};LGraphTextureGradient.prototype.onGetInputs=
function(){return[["angle","number"],["scale","number"]]};LGraphTextureGradient.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform float u_angle;\n\t\t\tuniform float u_scale;\n\t\t\tuniform vec3 u_colorA;\n\t\t\tuniform vec3 u_colorB;\n\t\t\t\n\t\t\tvec2 rotate(vec2 v, float angle)\n\t\t\t{\n\t\t\t\tvec2 result;\n\t\t\t\tfloat _cos = cos(angle);\n\t\t\t\tfloat _sin = sin(angle);\n\t\t\t\tresult.x = v.x * _cos - v.y * _sin;\n\t\t\t\tresult.y = v.x * _sin + v.y * _cos;\n\t\t\t\treturn result;\n\t\t\t}\n\t\t\tvoid main() {\n\t\t\t\tfloat f = (rotate(u_scale * (v_coord - vec2(0.5)), u_angle) + vec2(0.5)).x;\n\t\t\t\tvec3 color = mix(u_colorA,u_colorB,clamp(f,0.0,1.0));\n\t\t\t gl_FragColor = vec4(color,1.0);\n\t\t\t}\n\t\t\t";
LiteGraph.registerNodeType("texture/gradient",LGraphTextureGradient);var LGraphTextureMix=function(){this.addInput("A","Texture");this.addInput("B","Texture");this.addInput("Mixer","Texture");this.addOutput("Texture","Texture");this.properties={precision:LGraphTexture.DEFAULT};LGraphTextureMix._shader||(LGraphTextureMix._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,LGraphTextureMix.pixel_shader))};LGraphTextureMix.title="Mix";LGraphTextureMix.desc="Generates a texture mixing two textures";LGraphTextureMix.widgets_info=
{precision:{widget:"combo",values:LGraphTexture.MODE_VALUES}};LGraphTextureMix.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),c=this.getInputData(2);if(a&&b&&c){this._tex=LGraphTexture.getTargetTexture(a,this._tex,this.properties.precision);gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var d=Mesh.getScreenQuad(),e=LGraphTextureMix._shader;this._tex.drawTo(function(){a.bind(0);
b.bind(1);c.bind(2);e.uniforms({u_textureA:0,u_textureB:1,u_textureMix:2}).draw(d)});this.setOutputData(0,this._tex)}}};LGraphTextureMix.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_textureA;\n\t\t\tuniform sampler2D u_textureB;\n\t\t\tuniform sampler2D u_textureMix;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t gl_FragColor = mix( texture2D(u_textureA, v_coord), texture2D(u_textureB, v_coord), texture2D(u_textureMix, v_coord) );\n\t\t\t}\n\t\t\t";
{precision:{widget:"combo",values:LGraphTexture.MODE_VALUES}};LGraphTextureMix.prototype.onExecute=function(){var e=this.getInputData(0);if(this.isOutputConnected(0))if(this.properties.precision===LGraphTexture.PASS_THROUGH)this.setOutputData(0,e);else{var d=this.getInputData(1),g=this.getInputData(2);if(e&&d&&g){this._tex=LGraphTexture.getTargetTexture(e,this._tex,this.properties.precision);gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var k=Mesh.getScreenQuad(),h=LGraphTextureMix._shader;this._tex.drawTo(function(){e.bind(0);
d.bind(1);g.bind(2);h.uniforms({u_textureA:0,u_textureB:1,u_textureMix:2}).draw(k)});this.setOutputData(0,this._tex)}}};LGraphTextureMix.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_textureA;\n\t\t\tuniform sampler2D u_textureB;\n\t\t\tuniform sampler2D u_textureMix;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t gl_FragColor = mix( texture2D(u_textureA, v_coord), texture2D(u_textureB, v_coord), texture2D(u_textureMix, v_coord) );\n\t\t\t}\n\t\t\t";
LiteGraph.registerNodeType("texture/mix",LGraphTextureMix);var LGraphTextureEdges=function(){this.addInput("Tex.","Texture");this.addOutput("Edges","Texture");this.properties={invert:!0,factor:1,precision:LGraphTexture.DEFAULT};LGraphTextureEdges._shader||(LGraphTextureEdges._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,LGraphTextureEdges.pixel_shader))};LGraphTextureEdges.title="Edges";LGraphTextureEdges.desc="Detects edges";LGraphTextureEdges.widgets_info={precision:{widget:"combo",values:LGraphTexture.MODE_VALUES}};
LGraphTextureEdges.prototype.onExecute=function(){if(this.isOutputConnected(0)){var a=this.getInputData(0);if(this.properties.precision===LGraphTexture.PASS_THROUGH)this.setOutputData(0,a);else if(a){this._tex=LGraphTexture.getTargetTexture(a,this._tex,this.properties.precision);gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var b=Mesh.getScreenQuad(),c=LGraphTextureEdges._shader,d=this.properties.invert,e=this.properties.factor;this._tex.drawTo(function(){a.bind(0);c.uniforms({u_texture:0,u_isize:[1/
a.width,1/a.height],u_factor:e,u_invert:d?1:0}).draw(b)});this.setOutputData(0,this._tex)}}};LGraphTextureEdges.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 vec2 u_isize;\n\t\t\tuniform int u_invert;\n\t\t\tuniform float u_factor;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec4 center = texture2D(u_texture, v_coord);\n\t\t\t\tvec4 up = texture2D(u_texture, v_coord + u_isize * vec2(0.0,1.0) );\n\t\t\t\tvec4 down = texture2D(u_texture, v_coord + u_isize * vec2(0.0,-1.0) );\n\t\t\t\tvec4 left = texture2D(u_texture, v_coord + u_isize * vec2(1.0,0.0) );\n\t\t\t\tvec4 right = texture2D(u_texture, v_coord + u_isize * vec2(-1.0,0.0) );\n\t\t\t\tvec4 diff = abs(center - up) + abs(center - down) + abs(center - left) + abs(center - right);\n\t\t\t\tdiff *= u_factor;\n\t\t\t\tif(u_invert == 1)\n\t\t\t\t\tdiff.xyz = vec3(1.0) - diff.xyz;\n\t\t\t gl_FragColor = vec4( diff.xyz, center.a );\n\t\t\t}\n\t\t\t";
LGraphTextureEdges.prototype.onExecute=function(){if(this.isOutputConnected(0)){var e=this.getInputData(0);if(this.properties.precision===LGraphTexture.PASS_THROUGH)this.setOutputData(0,e);else if(e){this._tex=LGraphTexture.getTargetTexture(e,this._tex,this.properties.precision);gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var d=Mesh.getScreenQuad(),g=LGraphTextureEdges._shader,k=this.properties.invert,h=this.properties.factor;this._tex.drawTo(function(){e.bind(0);g.uniforms({u_texture:0,u_isize:[1/
e.width,1/e.height],u_factor:h,u_invert:k?1:0}).draw(d)});this.setOutputData(0,this._tex)}}};LGraphTextureEdges.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 vec2 u_isize;\n\t\t\tuniform int u_invert;\n\t\t\tuniform float u_factor;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec4 center = texture2D(u_texture, v_coord);\n\t\t\t\tvec4 up = texture2D(u_texture, v_coord + u_isize * vec2(0.0,1.0) );\n\t\t\t\tvec4 down = texture2D(u_texture, v_coord + u_isize * vec2(0.0,-1.0) );\n\t\t\t\tvec4 left = texture2D(u_texture, v_coord + u_isize * vec2(1.0,0.0) );\n\t\t\t\tvec4 right = texture2D(u_texture, v_coord + u_isize * vec2(-1.0,0.0) );\n\t\t\t\tvec4 diff = abs(center - up) + abs(center - down) + abs(center - left) + abs(center - right);\n\t\t\t\tdiff *= u_factor;\n\t\t\t\tif(u_invert == 1)\n\t\t\t\t\tdiff.xyz = vec3(1.0) - diff.xyz;\n\t\t\t gl_FragColor = vec4( diff.xyz, center.a );\n\t\t\t}\n\t\t\t";
LiteGraph.registerNodeType("texture/edges",LGraphTextureEdges);var LGraphTextureDepthRange=function(){this.addInput("Texture","Texture");this.addInput("Distance","number");this.addInput("Range","number");this.addOutput("Texture","Texture");this.properties={distance:100,range:50,high_precision:!1};LGraphTextureDepthRange._shader||(LGraphTextureDepthRange._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,LGraphTextureDepthRange.pixel_shader))};LGraphTextureDepthRange.title="Depth Range";LGraphTextureDepthRange.desc=
"Generates a texture with a depth range";LGraphTextureDepthRange.prototype.onExecute=function(){if(this.isOutputConnected(0)){var a=this.getInputData(0);if(a){var b=gl.UNSIGNED_BYTE;this.properties.high_precision&&(b=gl.half_float_ext?gl.HALF_FLOAT_OES:gl.FLOAT);this._temp_texture&&this._temp_texture.type==b&&this._temp_texture.width==a.width&&this._temp_texture.height==a.height||(this._temp_texture=new GL.Texture(a.width,a.height,{type:b,format:gl.RGBA,filter:gl.LINEAR}));var c=this.properties.distance;
this.isInputConnected(1)&&(c=this.getInputData(1),this.properties.distance=c);var d=this.properties.range;this.isInputConnected(2)&&(d=this.getInputData(2),this.properties.range=d);gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var e=Mesh.getScreenQuad(),f=LGraphTextureDepthRange._shader,g=[LS.Renderer._current_camera.near,LS.Renderer._current_camera.far];this._temp_texture.drawTo(function(){a.bind(0);f.uniforms({u_texture:0,u_distance:c,u_range:d,u_camera_planes:g}).draw(e)});this.setOutputData(0,
"Generates a texture with a depth range";LGraphTextureDepthRange.prototype.onExecute=function(){if(this.isOutputConnected(0)){var e=this.getInputData(0);if(e){var d=gl.UNSIGNED_BYTE;this.properties.high_precision&&(d=gl.half_float_ext?gl.HALF_FLOAT_OES:gl.FLOAT);this._temp_texture&&this._temp_texture.type==d&&this._temp_texture.width==e.width&&this._temp_texture.height==e.height||(this._temp_texture=new GL.Texture(e.width,e.height,{type:d,format:gl.RGBA,filter:gl.LINEAR}));var g=this.properties.distance;
this.isInputConnected(1)&&(g=this.getInputData(1),this.properties.distance=g);var k=this.properties.range;this.isInputConnected(2)&&(k=this.getInputData(2),this.properties.range=k);gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var h=Mesh.getScreenQuad(),a=LGraphTextureDepthRange._shader,b=[LS.Renderer._current_camera.near,LS.Renderer._current_camera.far];this._temp_texture.drawTo(function(){e.bind(0);a.uniforms({u_texture:0,u_distance:g,u_range:k,u_camera_planes:b}).draw(h)});this.setOutputData(0,
this._temp_texture)}}};LGraphTextureDepthRange.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 vec2 u_camera_planes;\n\t\t\tuniform float u_distance;\n\t\t\tuniform float u_range;\n\t\t\t\n\t\t\tfloat LinearDepth()\n\t\t\t{\n\t\t\t\tfloat n = u_camera_planes.x;\n\t\t\t\tfloat f = u_camera_planes.y;\n\t\t\t\treturn (2.0 * n) / (f + n - texture2D(u_texture, v_coord).x * (f - n));\n\t\t\t}\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tfloat diff = abs(LinearDepth() * u_camera_planes.y - u_distance);\n\t\t\t\tfloat dof = 1.0;\n\t\t\t\tif(diff <= u_range)\n\t\t\t\t\tdof = diff / u_range;\n\t\t\t gl_FragColor = vec4(dof);\n\t\t\t}\n\t\t\t";
LiteGraph.registerNodeType("texture/depth_range",LGraphTextureDepthRange);var LGraphTextureBlur=function(){this.addInput("Texture","Texture");this.addInput("Iterations","number");this.addInput("Intensity","number");this.addOutput("Blurred","Texture");this.properties={intensity:1,iterations:1,preserve_aspect:!1,scale:[1,1]};LGraphTextureBlur._shader||(LGraphTextureBlur._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,LGraphTextureBlur.pixel_shader))};LGraphTextureBlur.title="Blur";LGraphTextureBlur.desc=
"Blur a texture";LGraphTextureBlur.max_iterations=20;LGraphTextureBlur.prototype.onExecute=function(){var a=this.getInputData(0);if(a&&this.isOutputConnected(0)){var b=this._temp_texture;b&&b.width==a.width&&b.height==a.height&&b.type==a.type||(this._temp_texture=new GL.Texture(a.width,a.height,{type:a.type,format:gl.RGBA,filter:gl.LINEAR}),this._final_texture=new GL.Texture(a.width,a.height,{type:a.type,format:gl.RGBA,filter:gl.LINEAR}));b=this.properties.iterations;this.isInputConnected(1)&&(b=
this.getInputData(1),this.properties.iterations=b);b=Math.min(Math.floor(b),LGraphTextureBlur.max_iterations);if(0==b)this.setOutputData(0,a);else{var c=this.properties.intensity;this.isInputConnected(2)&&(c=this.getInputData(2),this.properties.intensity=c);var d=LiteGraph.camera_aspect;d||void 0===window.gl||(d=gl.canvas.height/gl.canvas.width);d||(d=1);for(var d=this.properties.preserve_aspect?d:1,e=this.properties.scale||[1,1],f=0;f<b;++f)a.applyBlur(d*e[0]*f,e[1]*f,c,this._temp_texture,this._final_texture),
a=this._final_texture;this.setOutputData(0,this._final_texture)}}};LGraphTextureBlur.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 vec2 u_offset;\n\t\t\tuniform float u_intensity;\n\t\t\tvoid main() {\n\t\t\t vec4 sum = vec4(0.0);\n\t\t\t vec4 center = texture2D(u_texture, v_coord);\n\t\t\t sum += texture2D(u_texture, v_coord + u_offset * -4.0) * 0.05/0.98;\n\t\t\t sum += texture2D(u_texture, v_coord + u_offset * -3.0) * 0.09/0.98;\n\t\t\t sum += texture2D(u_texture, v_coord + u_offset * -2.0) * 0.12/0.98;\n\t\t\t sum += texture2D(u_texture, v_coord + u_offset * -1.0) * 0.15/0.98;\n\t\t\t sum += center * 0.16/0.98;\n\t\t\t sum += texture2D(u_texture, v_coord + u_offset * 4.0) * 0.05/0.98;\n\t\t\t sum += texture2D(u_texture, v_coord + u_offset * 3.0) * 0.09/0.98;\n\t\t\t sum += texture2D(u_texture, v_coord + u_offset * 2.0) * 0.12/0.98;\n\t\t\t sum += texture2D(u_texture, v_coord + u_offset * 1.0) * 0.15/0.98;\n\t\t\t gl_FragColor = u_intensity * sum;\n\t\t\t /*gl_FragColor.a = center.a*/;\n\t\t\t}\n\t\t\t";
LiteGraph.registerNodeType("texture/blur",LGraphTextureBlur);var LGraphTextureWebcam=function(){this.addOutput("Webcam","Texture");this.properties={texture_name:""}};LGraphTextureWebcam.title="Webcam";LGraphTextureWebcam.desc="Webcam texture";LGraphTextureWebcam.prototype.openStream=function(){function a(a){console.log("Webcam rejected",a);b._webcam_stream=!1;b.box_color="red"}navigator.getUserMedia=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia;
window.URL=window.URL||window.webkitURL;if(navigator.getUserMedia){this._waiting_confirmation=!0;var b=this;navigator.getUserMedia({video:!0},this.streamReady.bind(this),a)}};LGraphTextureWebcam.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)})};LGraphTextureWebcam.prototype.onRemoved=function(){this._webcam_stream&&(this._webcam_stream.stop(),
this._video=this._webcam_stream=null)};LGraphTextureWebcam.prototype.onDrawBackground=function(a){this.flags.collapsed||20>=this.size[1]||!this._video||(a.save(),a.webgl?this._temp_texture&&a.drawImage(this._temp_texture,0,0,this.size[0],this.size[1]):(a.translate(0,this.size[1]),a.scale(1,-1),a.drawImage(this._video,0,0,this.size[0],this.size[1])),a.restore())};LGraphTextureWebcam.prototype.onExecute=function(){null!=this._webcam_stream||this._waiting_confirmation||this.openStream();if(this._video&&
this._video.videoWidth){var a=this._video.videoWidth,b=this._video.videoHeight,c=this._temp_texture;c&&c.width==a&&c.height==b||(this._temp_texture=new GL.Texture(a,b,{format:gl.RGB,filter:gl.LINEAR}));this._temp_texture.uploadImage(this._video);this.properties.texture_name&&(LGraphTexture.getTexturesContainer()[this.properties.texture_name]=this._temp_texture);this.setOutputData(0,this._temp_texture)}};LiteGraph.registerNodeType("texture/webcam",LGraphTextureWebcam);var LGraphTextureMatte=function(){this.addInput("in",
"Blur a texture";LGraphTextureBlur.max_iterations=20;LGraphTextureBlur.prototype.onExecute=function(){var e=this.getInputData(0);if(e&&this.isOutputConnected(0)){var d=this._temp_texture;d&&d.width==e.width&&d.height==e.height&&d.type==e.type||(this._temp_texture=new GL.Texture(e.width,e.height,{type:e.type,format:gl.RGBA,filter:gl.LINEAR}),this._final_texture=new GL.Texture(e.width,e.height,{type:e.type,format:gl.RGBA,filter:gl.LINEAR}));d=this.properties.iterations;this.isInputConnected(1)&&(d=
this.getInputData(1),this.properties.iterations=d);d=Math.min(Math.floor(d),LGraphTextureBlur.max_iterations);if(0==d)this.setOutputData(0,e);else{var g=this.properties.intensity;this.isInputConnected(2)&&(g=this.getInputData(2),this.properties.intensity=g);var k=LiteGraph.camera_aspect;k||void 0===window.gl||(k=gl.canvas.height/gl.canvas.width);k||(k=1);for(var k=this.properties.preserve_aspect?k:1,h=this.properties.scale||[1,1],a=0;a<d;++a)e.applyBlur(k*h[0]*a,h[1]*a,g,this._temp_texture,this._final_texture),
e=this._final_texture;this.setOutputData(0,this._final_texture)}}};LGraphTextureBlur.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 vec2 u_offset;\n\t\t\tuniform float u_intensity;\n\t\t\tvoid main() {\n\t\t\t vec4 sum = vec4(0.0);\n\t\t\t vec4 center = texture2D(u_texture, v_coord);\n\t\t\t sum += texture2D(u_texture, v_coord + u_offset * -4.0) * 0.05/0.98;\n\t\t\t sum += texture2D(u_texture, v_coord + u_offset * -3.0) * 0.09/0.98;\n\t\t\t sum += texture2D(u_texture, v_coord + u_offset * -2.0) * 0.12/0.98;\n\t\t\t sum += texture2D(u_texture, v_coord + u_offset * -1.0) * 0.15/0.98;\n\t\t\t sum += center * 0.16/0.98;\n\t\t\t sum += texture2D(u_texture, v_coord + u_offset * 4.0) * 0.05/0.98;\n\t\t\t sum += texture2D(u_texture, v_coord + u_offset * 3.0) * 0.09/0.98;\n\t\t\t sum += texture2D(u_texture, v_coord + u_offset * 2.0) * 0.12/0.98;\n\t\t\t sum += texture2D(u_texture, v_coord + u_offset * 1.0) * 0.15/0.98;\n\t\t\t gl_FragColor = u_intensity * sum;\n\t\t\t /*gl_FragColor.a = center.a*/;\n\t\t\t}\n\t\t\t";
LiteGraph.registerNodeType("texture/blur",LGraphTextureBlur);var LGraphTextureWebcam=function(){this.addOutput("Webcam","Texture");this.properties={texture_name:""}};LGraphTextureWebcam.title="Webcam";LGraphTextureWebcam.desc="Webcam texture";LGraphTextureWebcam.prototype.openStream=function(){function e(e){console.log("Webcam rejected",e);d._webcam_stream=!1;d.box_color="red"}navigator.getUserMedia=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia;
window.URL=window.URL||window.webkitURL;if(navigator.getUserMedia){this._waiting_confirmation=!0;var d=this;navigator.getUserMedia({video:!0},this.streamReady.bind(this),e)}};LGraphTextureWebcam.prototype.streamReady=function(e){this._webcam_stream=e;var d=this._video;d||(d=document.createElement("video"),d.autoplay=!0,d.src=window.URL.createObjectURL(e),this._video=d,d.onloadedmetadata=function(d){console.log(d)})};LGraphTextureWebcam.prototype.onRemoved=function(){this._webcam_stream&&(this._webcam_stream.stop(),
this._video=this._webcam_stream=null)};LGraphTextureWebcam.prototype.onDrawBackground=function(e){this.flags.collapsed||20>=this.size[1]||!this._video||(e.save(),e.webgl?this._temp_texture&&e.drawImage(this._temp_texture,0,0,this.size[0],this.size[1]):(e.translate(0,this.size[1]),e.scale(1,-1),e.drawImage(this._video,0,0,this.size[0],this.size[1])),e.restore())};LGraphTextureWebcam.prototype.onExecute=function(){null!=this._webcam_stream||this._waiting_confirmation||this.openStream();if(this._video&&
this._video.videoWidth){var e=this._video.videoWidth,d=this._video.videoHeight,g=this._temp_texture;g&&g.width==e&&g.height==d||(this._temp_texture=new GL.Texture(e,d,{format:gl.RGB,filter:gl.LINEAR}));this._temp_texture.uploadImage(this._video);this.properties.texture_name&&(LGraphTexture.getTexturesContainer()[this.properties.texture_name]=this._temp_texture);this.setOutputData(0,this._temp_texture)}};LiteGraph.registerNodeType("texture/webcam",LGraphTextureWebcam);var LGraphTextureMatte=function(){this.addInput("in",
"Texture");this.addOutput("out","Texture");this.properties={key_color:vec3.fromValues(0,1,0),threshold:0.8,slope:0.2,precision:LGraphTexture.DEFAULT};LGraphTextureMatte._shader||(LGraphTextureMatte._shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,LGraphTextureMatte.pixel_shader))};LGraphTextureMatte.title="Matte";LGraphTextureMatte.desc="Extracts background";LGraphTextureMatte.widgets_info={key_color:{widget:"color"},precision:{widget:"combo",values:LGraphTexture.MODE_VALUES}};LGraphTextureMatte.prototype.onExecute=
function(){if(this.isOutputConnected(0)){var a=this.getInputData(0);if(this.properties.precision===LGraphTexture.PASS_THROUGH)this.setOutputData(0,a);else if(a){this._tex=LGraphTexture.getTargetTexture(a,this._tex,this.properties.precision);gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);this._uniforms||(this._uniforms={u_texture:0,u_key_color:this.properties.key_color,u_threshold:1,u_slope:1});var b=this._uniforms,c=Mesh.getScreenQuad(),d=LGraphTextureMatte._shader;b.u_key_color=this.properties.key_color;
b.u_threshold=this.properties.threshold;b.u_slope=this.properties.slope;this._tex.drawTo(function(){a.bind(0);d.uniforms(b).draw(c)});this.setOutputData(0,this._tex)}}};LGraphTextureMatte.pixel_shader="precision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform vec3 u_key_color;\n\t\t\tuniform float u_threshold;\n\t\t\tuniform float u_slope;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec3 color = texture2D( u_texture, v_coord ).xyz;\n\t\t\t\tfloat diff = length( normalize(color) - normalize(u_key_color) );\n\t\t\t\tfloat edge = u_threshold * (1.0 - u_slope);\n\t\t\t\tfloat alpha = smoothstep( edge, u_threshold, diff);\n\t\t\t\tgl_FragColor = vec4( color, alpha );\n\t\t\t}";
LiteGraph.registerNodeType("texture/matte",LGraphTextureMatte);var LGraphCubemap=function(){this.addOutput("Cubemap","Cubemap");this.properties={name:""};this.size=[LGraphTexture.image_preview_size,LGraphTexture.image_preview_size]};LGraphCubemap.prototype.onDropFile=function(a,b,c){a?(this._drop_texture="string"==typeof a?GL.Texture.fromURL(a):GL.Texture.fromDDSInMemory(a),this.properties.name=b):(this._drop_texture=null,this.properties.name="")};LGraphCubemap.prototype.onExecute=function(){if(this._drop_texture)this.setOutputData(0,
this._drop_texture);else if(this.properties.name){var a=LGraphTexture.getTexture(this.properties.name);a&&(this._last_tex=a,this.setOutputData(0,a))}};LGraphCubemap.prototype.onDrawBackground=function(a){this.flags.collapsed||20>=this.size[1]||a.webgl&&(gl.meshes.cube||(gl.meshes.cube=GL.Mesh.cube({size:1})))};LiteGraph.registerNodeType("texture/cubemap",LGraphCubemap)}
function(){if(this.isOutputConnected(0)){var e=this.getInputData(0);if(this.properties.precision===LGraphTexture.PASS_THROUGH)this.setOutputData(0,e);else if(e){this._tex=LGraphTexture.getTargetTexture(e,this._tex,this.properties.precision);gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);this._uniforms||(this._uniforms={u_texture:0,u_key_color:this.properties.key_color,u_threshold:1,u_slope:1});var d=this._uniforms,g=Mesh.getScreenQuad(),k=LGraphTextureMatte._shader;d.u_key_color=this.properties.key_color;
d.u_threshold=this.properties.threshold;d.u_slope=this.properties.slope;this._tex.drawTo(function(){e.bind(0);k.uniforms(d).draw(g)});this.setOutputData(0,this._tex)}}};LGraphTextureMatte.pixel_shader="precision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform vec3 u_key_color;\n\t\t\tuniform float u_threshold;\n\t\t\tuniform float u_slope;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec3 color = texture2D( u_texture, v_coord ).xyz;\n\t\t\t\tfloat diff = length( normalize(color) - normalize(u_key_color) );\n\t\t\t\tfloat edge = u_threshold * (1.0 - u_slope);\n\t\t\t\tfloat alpha = smoothstep( edge, u_threshold, diff);\n\t\t\t\tgl_FragColor = vec4( color, alpha );\n\t\t\t}";
LiteGraph.registerNodeType("texture/matte",LGraphTextureMatte);var LGraphCubemap=function(){this.addOutput("Cubemap","Cubemap");this.properties={name:""};this.size=[LGraphTexture.image_preview_size,LGraphTexture.image_preview_size]};LGraphCubemap.prototype.onDropFile=function(e,d,g){e?(this._drop_texture="string"==typeof e?GL.Texture.fromURL(e):GL.Texture.fromDDSInMemory(e),this.properties.name=d):(this._drop_texture=null,this.properties.name="")};LGraphCubemap.prototype.onExecute=function(){if(this._drop_texture)this.setOutputData(0,
this._drop_texture);else if(this.properties.name){var e=LGraphTexture.getTexture(this.properties.name);e&&(this._last_tex=e,this.setOutputData(0,e))}};LGraphCubemap.prototype.onDrawBackground=function(e){this.flags.collapsed||20>=this.size[1]||e.webgl&&(gl.meshes.cube||(gl.meshes.cube=GL.Mesh.cube({size:1})))};LiteGraph.registerNodeType("texture/cubemap",LGraphCubemap)}
if("undefined"!=typeof LiteGraph){var LGraphFXLens=function(){this.addInput("Texture","Texture");this.addInput("Aberration","number");this.addInput("Distortion","number");this.addInput("Blur","number");this.addOutput("Texture","Texture");this.properties={aberration:1,distortion:1,blur:1,precision:LGraphTexture.DEFAULT};LGraphFXLens._shader||(LGraphFXLens._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,LGraphFXLens.pixel_shader))};LGraphFXLens.title="Lens";LGraphFXLens.desc="Camera Lens distortion";
LGraphFXLens.widgets_info={precision:{widget:"combo",values:LGraphTexture.MODE_VALUES}};LGraphFXLens.prototype.onExecute=function(){var a=this.getInputData(0);if(this.properties.precision===LGraphTexture.PASS_THROUGH)this.setOutputData(0,a);else if(a){this._tex=LGraphTexture.getTargetTexture(a,this._tex,this.properties.precision);var b=this.properties.aberration;this.isInputConnected(1)&&(b=this.getInputData(1),this.properties.aberration=b);var c=this.properties.distortion;this.isInputConnected(2)&&
(c=this.getInputData(2),this.properties.distortion=c);var d=this.properties.blur;this.isInputConnected(3)&&(d=this.getInputData(3),this.properties.blur=d);gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var e=Mesh.getScreenQuad(),f=LGraphFXLens._shader;this._tex.drawTo(function(){a.bind(0);f.uniforms({u_texture:0,u_aberration:b,u_distortion:c,u_blur:d}).draw(e)});this.setOutputData(0,this._tex)}};LGraphFXLens.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 vec2 u_camera_planes;\n\t\t\tuniform float u_aberration;\n\t\t\tuniform float u_distortion;\n\t\t\tuniform float u_blur;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec2 coord = v_coord;\n\t\t\t\tfloat dist = distance(vec2(0.5), coord);\n\t\t\t\tvec2 dist_coord = coord - vec2(0.5);\n\t\t\t\tfloat percent = 1.0 + ((0.5 - dist) / 0.5) * u_distortion;\n\t\t\t\tdist_coord *= percent;\n\t\t\t\tcoord = dist_coord + vec2(0.5);\n\t\t\t\tvec4 color = texture2D(u_texture,coord, u_blur * dist);\n\t\t\t\tcolor.r = texture2D(u_texture,vec2(0.5) + dist_coord * (1.0+0.01*u_aberration), u_blur * dist ).r;\n\t\t\t\tcolor.b = texture2D(u_texture,vec2(0.5) + dist_coord * (1.0-0.01*u_aberration), u_blur * dist ).b;\n\t\t\t\tgl_FragColor = color;\n\t\t\t}\n\t\t\t";
LGraphFXLens.widgets_info={precision:{widget:"combo",values:LGraphTexture.MODE_VALUES}};LGraphFXLens.prototype.onExecute=function(){var e=this.getInputData(0);if(this.properties.precision===LGraphTexture.PASS_THROUGH)this.setOutputData(0,e);else if(e){this._tex=LGraphTexture.getTargetTexture(e,this._tex,this.properties.precision);var d=this.properties.aberration;this.isInputConnected(1)&&(d=this.getInputData(1),this.properties.aberration=d);var g=this.properties.distortion;this.isInputConnected(2)&&
(g=this.getInputData(2),this.properties.distortion=g);var k=this.properties.blur;this.isInputConnected(3)&&(k=this.getInputData(3),this.properties.blur=k);gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var h=Mesh.getScreenQuad(),a=LGraphFXLens._shader;this._tex.drawTo(function(){e.bind(0);a.uniforms({u_texture:0,u_aberration:d,u_distortion:g,u_blur:k}).draw(h)});this.setOutputData(0,this._tex)}};LGraphFXLens.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 vec2 u_camera_planes;\n\t\t\tuniform float u_aberration;\n\t\t\tuniform float u_distortion;\n\t\t\tuniform float u_blur;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec2 coord = v_coord;\n\t\t\t\tfloat dist = distance(vec2(0.5), coord);\n\t\t\t\tvec2 dist_coord = coord - vec2(0.5);\n\t\t\t\tfloat percent = 1.0 + ((0.5 - dist) / 0.5) * u_distortion;\n\t\t\t\tdist_coord *= percent;\n\t\t\t\tcoord = dist_coord + vec2(0.5);\n\t\t\t\tvec4 color = texture2D(u_texture,coord, u_blur * dist);\n\t\t\t\tcolor.r = texture2D(u_texture,vec2(0.5) + dist_coord * (1.0+0.01*u_aberration), u_blur * dist ).r;\n\t\t\t\tcolor.b = texture2D(u_texture,vec2(0.5) + dist_coord * (1.0-0.01*u_aberration), u_blur * dist ).b;\n\t\t\t\tgl_FragColor = color;\n\t\t\t}\n\t\t\t";
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 n=Mesh.getScreenQuad(),l=this.properties.size,p=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(n)});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:p,u_threshold:e,u_pointSize:l,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,n=0;n<e;++n){for(var l=-1,p=0;p<d;++p){var r=n*d*2+2*p;f[r]=l;f[r+1]=g;l+=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=
function(){var e=this.getInputData(0),d=this.getInputData(1),g=this.getInputData(2);if(e&&g&&this.properties.shape){d||(d=e);var k=LGraphTexture.getTexture(this.properties.shape);if(k){var h=this.properties.threshold;this.isInputConnected(3)&&(h=this.getInputData(3),this.properties.threshold=h);var a=gl.UNSIGNED_BYTE;this.properties.high_precision&&(a=gl.half_float_ext?gl.HALF_FLOAT_OES:gl.FLOAT);this._temp_texture&&this._temp_texture.type==a&&this._temp_texture.width==e.width&&this._temp_texture.height==
e.height||(this._temp_texture=new GL.Texture(e.width,e.height,{type:a,format:gl.RGBA,filter:gl.LINEAR}));var b=LGraphFXBokeh._first_shader;b||(b=LGraphFXBokeh._first_shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,LGraphFXBokeh._first_pixel_shader));var c=LGraphFXBokeh._second_shader;c||(c=LGraphFXBokeh._second_shader=new GL.Shader(LGraphFXBokeh._second_vertex_shader,LGraphFXBokeh._second_pixel_shader));var f=this._points_mesh;f&&f._width==e.width&&f._height==e.height&&2==f._spacing||(f=this.createPointsMesh(e.width,
e.height,2));var l=Mesh.getScreenQuad(),u=this.properties.size,s=this.properties.alpha;gl.disable(gl.DEPTH_TEST);gl.disable(gl.BLEND);this._temp_texture.drawTo(function(){e.bind(0);d.bind(1);g.bind(2);b.uniforms({u_texture:0,u_texture_blur:1,u_mask:2,u_texsize:[e.width,e.height]}).draw(l)});this._temp_texture.drawTo(function(){gl.enable(gl.BLEND);gl.blendFunc(gl.ONE,gl.ONE);e.bind(0);k.bind(3);c.uniforms({u_texture:0,u_mask:2,u_shape:3,u_alpha:s,u_threshold:h,u_pointSize:u,u_itexsize:[1/e.width,1/
e.height]}).draw(f,gl.POINTS)});this.setOutputData(0,this._temp_texture)}}else this.setOutputData(0,e)};LGraphFXBokeh.prototype.createPointsMesh=function(e,d,g){for(var k=Math.round(e/g),h=Math.round(d/g),a=new Float32Array(k*h*2),b=-1,c=2/e*g,f=2/d*g,l=0;l<h;++l){for(var u=-1,s=0;s<k;++s){var t=l*k*2+2*s;a[t]=u;a[t+1]=b;u+=c}b+=f}this._points_mesh=GL.Mesh.load({vertices2D:a});this._points_mesh._width=e;this._points_mesh._height=d;this._points_mesh._spacing=g;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");
this.addInput("value2","number");this.addOutput("Texture","Texture");this.properties={fx:"halftone",value1:1,value2:1,precision:LGraphTexture.DEFAULT}};LGraphFXGeneric.title="FX";LGraphFXGeneric.desc="applies an FX from a list";LGraphFXGeneric.widgets_info={fx:{widget:"combo",values:["halftone","pixelate","lowpalette","noise","gamma"]},precision:{widget:"combo",values:LGraphTexture.MODE_VALUES}};LGraphFXGeneric.shaders={};LGraphFXGeneric.prototype.onExecute=function(){if(this.isOutputConnected(0)){var a=
this.getInputData(0);if(this.properties.precision===LGraphTexture.PASS_THROUGH)this.setOutputData(0,a);else if(a){this._tex=LGraphTexture.getTargetTexture(a,this._tex,this.properties.precision);var b=this.properties.value1;this.isInputConnected(1)&&(b=this.getInputData(1),this.properties.value1=b);var c=this.properties.value2;this.isInputConnected(2)&&(c=this.getInputData(2),this.properties.value2=c);var d=this.properties.fx,e=LGraphFXGeneric.shaders[d];if(!e){var f=LGraphFXGeneric["pixel_shader_"+
d];if(!f)return;e=LGraphFXGeneric.shaders[d]=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,f)}gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var g=Mesh.getScreenQuad();camera_planes=window.LS&&LS.Renderer._current_camera?[LS.Renderer._current_camera.near,LS.Renderer._current_camera.far]:[1,100];var h=null;"noise"==d&&(h=LGraphTexture.getNoiseTexture());this._tex.drawTo(function(){a.bind(0);"noise"==d&&h.bind(1);e.uniforms({u_texture:0,u_noise:1,u_size:[a.width,a.height],u_rand:[Math.random(),Math.random()],
u_value1:b,u_value2:c,u_camera_planes:camera_planes}).draw(g)});this.setOutputData(0,this._tex)}}};LGraphFXGeneric.pixel_shader_halftone="precision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform vec2 u_camera_planes;\n\t\t\tuniform vec2 u_size;\n\t\t\tuniform float u_value1;\n\t\t\tuniform float u_value2;\n\t\t\t\n\t\t\tfloat pattern() {\n\t\t\t\tfloat s = sin(u_value1 * 3.1415), c = cos(u_value1 * 3.1415);\n\t\t\t\tvec2 tex = v_coord * u_size.xy;\n\t\t\t\tvec2 point = vec2(\n\t\t\t\t c * tex.x - s * tex.y ,\n\t\t\t\t s * tex.x + c * tex.y \n\t\t\t\t) * u_value2;\n\t\t\t\treturn (sin(point.x) * sin(point.y)) * 4.0;\n\t\t\t}\n\t\t\tvoid main() {\n\t\t\t\tvec4 color = texture2D(u_texture, v_coord);\n\t\t\t\tfloat average = (color.r + color.g + color.b) / 3.0;\n\t\t\t\tgl_FragColor = vec4(vec3(average * 10.0 - 5.0 + pattern()), color.a);\n\t\t\t}\n";
this.addInput("value2","number");this.addOutput("Texture","Texture");this.properties={fx:"halftone",value1:1,value2:1,precision:LGraphTexture.DEFAULT}};LGraphFXGeneric.title="FX";LGraphFXGeneric.desc="applies an FX from a list";LGraphFXGeneric.widgets_info={fx:{widget:"combo",values:["halftone","pixelate","lowpalette","noise","gamma"]},precision:{widget:"combo",values:LGraphTexture.MODE_VALUES}};LGraphFXGeneric.shaders={};LGraphFXGeneric.prototype.onExecute=function(){if(this.isOutputConnected(0)){var e=
this.getInputData(0);if(this.properties.precision===LGraphTexture.PASS_THROUGH)this.setOutputData(0,e);else if(e){this._tex=LGraphTexture.getTargetTexture(e,this._tex,this.properties.precision);var d=this.properties.value1;this.isInputConnected(1)&&(d=this.getInputData(1),this.properties.value1=d);var g=this.properties.value2;this.isInputConnected(2)&&(g=this.getInputData(2),this.properties.value2=g);var k=this.properties.fx,h=LGraphFXGeneric.shaders[k];if(!h){var a=LGraphFXGeneric["pixel_shader_"+
k];if(!a)return;h=LGraphFXGeneric.shaders[k]=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,a)}gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var b=Mesh.getScreenQuad();camera_planes=window.LS&&LS.Renderer._current_camera?[LS.Renderer._current_camera.near,LS.Renderer._current_camera.far]:[1,100];var c=null;"noise"==k&&(c=LGraphTexture.getNoiseTexture());this._tex.drawTo(function(){e.bind(0);"noise"==k&&c.bind(1);h.uniforms({u_texture:0,u_noise:1,u_size:[e.width,e.height],u_rand:[Math.random(),Math.random()],
u_value1:d,u_value2:g,u_camera_planes:camera_planes}).draw(b)});this.setOutputData(0,this._tex)}}};LGraphFXGeneric.pixel_shader_halftone="precision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform vec2 u_camera_planes;\n\t\t\tuniform vec2 u_size;\n\t\t\tuniform float u_value1;\n\t\t\tuniform float u_value2;\n\t\t\t\n\t\t\tfloat pattern() {\n\t\t\t\tfloat s = sin(u_value1 * 3.1415), c = cos(u_value1 * 3.1415);\n\t\t\t\tvec2 tex = v_coord * u_size.xy;\n\t\t\t\tvec2 point = vec2(\n\t\t\t\t c * tex.x - s * tex.y ,\n\t\t\t\t s * tex.x + c * tex.y \n\t\t\t\t) * u_value2;\n\t\t\t\treturn (sin(point.x) * sin(point.y)) * 4.0;\n\t\t\t}\n\t\t\tvoid main() {\n\t\t\t\tvec4 color = texture2D(u_texture, v_coord);\n\t\t\t\tfloat average = (color.r + color.g + color.b) / 3.0;\n\t\t\t\tgl_FragColor = vec4(vec3(average * 10.0 - 5.0 + pattern()), color.a);\n\t\t\t}\n";
LGraphFXGeneric.pixel_shader_pixelate="precision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform vec2 u_camera_planes;\n\t\t\tuniform vec2 u_size;\n\t\t\tuniform float u_value1;\n\t\t\tuniform float u_value2;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec2 coord = vec2( floor(v_coord.x * u_value1) / u_value1, floor(v_coord.y * u_value2) / u_value2 );\n\t\t\t\tvec4 color = texture2D(u_texture, coord);\n\t\t\t\tgl_FragColor = color;\n\t\t\t}\n";LGraphFXGeneric.pixel_shader_lowpalette=
"precision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform vec2 u_camera_planes;\n\t\t\tuniform vec2 u_size;\n\t\t\tuniform float u_value1;\n\t\t\tuniform float u_value2;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec4 color = texture2D(u_texture, v_coord);\n\t\t\t\tgl_FragColor = floor(color * u_value1) / u_value1;\n\t\t\t}\n";LGraphFXGeneric.pixel_shader_noise="precision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform sampler2D u_noise;\n\t\t\tuniform vec2 u_size;\n\t\t\tuniform float u_value1;\n\t\t\tuniform float u_value2;\n\t\t\tuniform vec2 u_rand;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec4 color = texture2D(u_texture, v_coord);\n\t\t\t\tvec3 noise = texture2D(u_noise, v_coord * vec2(u_size.x / 512.0, u_size.y / 512.0) + u_rand).xyz - vec3(0.5);\n\t\t\t\tgl_FragColor = vec4( color.xyz + noise * u_value1, color.a );\n\t\t\t}\n";
LGraphFXGeneric.pixel_shader_gamma="precision highp float;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform float u_value1;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec4 color = texture2D(u_texture, v_coord);\n\t\t\t\tfloat gamma = 1.0 / u_value1;\n\t\t\t\tgl_FragColor = vec4( pow( color.xyz, vec3(gamma) ), color.a );\n\t\t\t}\n";LiteGraph.registerNodeType("fx/generic",LGraphFXGeneric);window.LGraphFXGeneric=LGraphFXGeneric;var LGraphFXVigneting=function(){this.addInput("Tex.",
"Texture");this.addInput("intensity","number");this.addOutput("Texture","Texture");this.properties={intensity:1,invert:!1,precision:LGraphTexture.DEFAULT};LGraphFXVigneting._shader||(LGraphFXVigneting._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,LGraphFXVigneting.pixel_shader))};LGraphFXVigneting.title="Vigneting";LGraphFXVigneting.desc="Vigneting";LGraphFXVigneting.widgets_info={precision:{widget:"combo",values:LGraphTexture.MODE_VALUES}};LGraphFXVigneting.prototype.onExecute=function(){var a=
this.getInputData(0);if(this.properties.precision===LGraphTexture.PASS_THROUGH)this.setOutputData(0,a);else if(a){this._tex=LGraphTexture.getTargetTexture(a,this._tex,this.properties.precision);var b=this.properties.intensity;this.isInputConnected(1)&&(b=this.getInputData(1),this.properties.intensity=b);gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var c=Mesh.getScreenQuad(),d=LGraphFXVigneting._shader,e=this.properties.invert;this._tex.drawTo(function(){a.bind(0);d.uniforms({u_texture:0,u_intensity:b,
u_isize:[1/a.width,1/a.height],u_invert:e?1:0}).draw(c)});this.setOutputData(0,this._tex)}};LGraphFXVigneting.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 float u_intensity;\n\t\t\tuniform int u_invert;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tfloat luminance = 1.0 - length( v_coord - vec2(0.5) ) * 1.414;\n\t\t\t\tvec4 color = texture2D(u_texture, v_coord);\n\t\t\t\tif(u_invert == 1)\n\t\t\t\t\tluminance = 1.0 - luminance;\n\t\t\t\tluminance = mix(1.0, luminance, u_intensity);\n\t\t\t gl_FragColor = vec4( luminance * color.xyz, color.a);\n\t\t\t}\n\t\t\t";
"Texture");this.addInput("intensity","number");this.addOutput("Texture","Texture");this.properties={intensity:1,invert:!1,precision:LGraphTexture.DEFAULT};LGraphFXVigneting._shader||(LGraphFXVigneting._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,LGraphFXVigneting.pixel_shader))};LGraphFXVigneting.title="Vigneting";LGraphFXVigneting.desc="Vigneting";LGraphFXVigneting.widgets_info={precision:{widget:"combo",values:LGraphTexture.MODE_VALUES}};LGraphFXVigneting.prototype.onExecute=function(){var e=
this.getInputData(0);if(this.properties.precision===LGraphTexture.PASS_THROUGH)this.setOutputData(0,e);else if(e){this._tex=LGraphTexture.getTargetTexture(e,this._tex,this.properties.precision);var d=this.properties.intensity;this.isInputConnected(1)&&(d=this.getInputData(1),this.properties.intensity=d);gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var g=Mesh.getScreenQuad(),k=LGraphFXVigneting._shader,h=this.properties.invert;this._tex.drawTo(function(){e.bind(0);k.uniforms({u_texture:0,u_intensity:d,
u_isize:[1/e.width,1/e.height],u_invert:h?1:0}).draw(g)});this.setOutputData(0,this._tex)}};LGraphFXVigneting.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 float u_intensity;\n\t\t\tuniform int u_invert;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tfloat luminance = 1.0 - length( v_coord - vec2(0.5) ) * 1.414;\n\t\t\t\tvec4 color = texture2D(u_texture, v_coord);\n\t\t\t\tif(u_invert == 1)\n\t\t\t\t\tluminance = 1.0 - luminance;\n\t\t\t\tluminance = mix(1.0, luminance, u_intensity);\n\t\t\t gl_FragColor = vec4( luminance * color.xyz, color.a);\n\t\t\t}\n\t\t\t";
LiteGraph.registerNodeType("fx/vigneting",LGraphFXVigneting);window.LGraphFXVigneting=LGraphFXVigneting}
(function(a){function b(a){this.cmd=this.channel=0;a?this.setup(a):this.data=[0,0,0]}function c(a,b){navigator.requestMIDIAccess?(this.on_ready=a,navigator.requestMIDIAccess().then(this.onMIDISuccess.bind(this),this.onMIDIFailure.bind(this))):(this.error="not suppoorted",b?b("Not supported"):console.error("MIDI NOT SUPPORTED, enable by chrome://flags"))}function d(){this.addOutput("on_midi",LiteGraph.EVENT);this.addOutput("out","midi");this.properties={port:0};this._current_midi_event=this._last_midi_event=
null;var a=this;new c(function(b){a._midi=b;if(a._waiting)a.onStart();a._waiting=!1})}function e(){this.addInput("send",LiteGraph.EVENT);this.properties={port:0};var a=this;new c(function(b){a._midi=b})}function f(){this.addInput("on_midi",LiteGraph.EVENT);this._str="";this.size=[200,40]}function g(){this.properties={channel:-1,cmd:-1,min_value:-1,max_value:-1};this.addInput("in",LiteGraph.EVENT);this.addOutput("on_midi",LiteGraph.EVENT)}function h(){this.properties={channel:0,cmd:"CC",value1:1,value2:1};
this.addInput("send",LiteGraph.EVENT);this.addInput("assign",LiteGraph.EVENT);this.addOutput("on_midi",LiteGraph.EVENT)}b.prototype.setup=function(a){this.data=a;this.status=a=a[0];var c=a&240;this.cmd=240<=a?a:c;this.cmd==b.NOTEON&&0==this.velocity&&(this.cmd=b.NOTEOFF);this.cmd_str=b.commands[this.cmd]||"";if(c>=b.NOTEON||c<=b.NOTEOFF)this.channel=a&15};Object.defineProperty(b.prototype,"velocity",{get:function(){return this.cmd==b.NOTEON?this.data[2]:-1},set:function(a){this.data[2]=a},enumerable:!0});
b.notes="A A# B C C# D D# E F F# G G#".split(" ");b.prototype.getPitch=function(){return 440*Math.pow(2,(this.data[1]-69)/12)};b.computePitch=function(a){return 440*Math.pow(2,(a-69)/12)};b.prototype.getPitchBend=function(){return this.data[1]+(this.data[2]<<7)-8192};b.computePitchBend=function(a,b){return a+(b<<7)-8192};b.prototype.setCommandFromString=function(a){this.cmd=b.computeCommandFromString(a)};b.computeCommandFromString=function(a){if(!a)return 0;if(a&&a.constructor===Number)return a;a=
a.toUpperCase();switch(a){case "NOTE ON":case "NOTEON":return b.NOTEON;case "NOTE OFF":case "NOTEOFF":return b.NOTEON;case "KEY PRESSURE":case "KEYPRESSURE":return b.KEYPRESSURE;case "CONTROLLER CHANGE":case "CONTROLLERCHANGE":case "CC":return b.CONTROLLERCHANGE;case "PROGRAM CHANGE":case "PROGRAMCHANGE":case "PC":return b.PROGRAMCHANGE;case "CHANNEL PRESSURE":case "CHANNELPRESSURE":return b.CHANNELPRESSURE;case "PITCH BEND":case "PITCHBEND":return b.PITCHBEND;case "TIME TICK":case "TIMETICK":return b.TIMETICK;
default:return Number(a)}};b.toNoteString=function(a){var c;c=(a-21)%12;0>c&&(c=12+c);return b.notes[c]+Math.floor((a-24)/12+1)};b.prototype.toString=function(){var a=""+this.channel+". ";switch(this.cmd){case b.NOTEON:a+="NOTEON "+b.toNoteString(this.data[1]);break;case b.NOTEOFF:a+="NOTEOFF "+b.toNoteString(this.data[1]);break;case b.CONTROLLERCHANGE:a+="CC "+this.data[1]+" "+this.data[2];break;case b.PROGRAMCHANGE:a+="PC "+this.data[1];break;case b.PITCHBEND:a+="PITCHBEND "+this.getPitchBend();
break;case b.KEYPRESSURE:a+="KEYPRESS "+this.data[1]}return a};b.prototype.toHexString=function(){for(var a="",b=0;b<this.data.length;b++)a+=this.data[b].toString(16)+" "};b.NOTEOFF=128;b.NOTEON=144;b.KEYPRESSURE=160;b.CONTROLLERCHANGE=176;b.PROGRAMCHANGE=192;b.CHANNELPRESSURE=208;b.PITCHBEND=224;b.TIMETICK=248;b.commands={128:"note off",144:"note on",160:"key pressure",176:"controller change",192:"program change",208:"channel pressure",224:"pitch bend",240:"system",242:"Song pos",243:"Song select",
246:"Tune request",248:"time tick",250:"Start Song",251:"Continue Song",252:"Stop Song",254:"Sensing",255:"Reset"};c.MIDIEvent=b;c.prototype.onMIDISuccess=function(a){console.log("MIDI ready!");console.log(a);this.midi=a;this.updatePorts();if(this.on_ready)this.on_ready(this)};c.prototype.updatePorts=function(){var a=this.midi;this.input_ports=a.inputs;for(var b=0,c=0;c<this.input_ports.size;++c){var d=this.input_ports.get(c);console.log("Input port [type:'"+d.type+"'] id:'"+d.id+"' manufacturer:'"+
d.manufacturer+"' name:'"+d.name+"' version:'"+d.version+"'");b++}this.num_input_ports=b;b=0;this.output_ports=a.outputs;for(c=0;c<this.output_ports.size;++c)a=this.output_ports.get(c),console.log("Output port [type:'"+a.type+"'] id:'"+a.id+"' manufacturer:'"+a.manufacturer+"' name:'"+a.name+"' version:'"+a.version+"'"),b++;this.num_output_ports=b};c.prototype.onMIDIFailure=function(a){console.error("Failed to get MIDI access - "+a)};c.prototype.openInputPort=function(a,d){var e=this.input_ports.get(a);
if(!e)return!1;e.onmidimessage=function(a){var e=new b(a.data);d&&d(a.data,e);if(c.on_message)c.on_message(a.data,e)};console.log("port open: ",e);return!0};c.parseMsg=function(a){};c.prototype.sendMIDI=function(a,c){if(c){var d=this.output_ports.get(a);d&&(c.constructor===b?d.send(c.data):d.send(c))}};d.MIDIInterface=c;d.title="MIDI Input";d.desc="Reads MIDI from a input port";d.prototype.getPropertyInfo=function(a){if(this._midi&&"port"==a){a={};for(var b=0;b<this._midi.input_ports.size;++b){var c=
this._midi.input_ports.get(b);a[b]=b+".- "+c.name+" version:"+c.version}return{type:"enum",values:a}}};d.prototype.onStart=function(){this._midi?this._midi.openInputPort(this.properties.port,this.onMIDIEvent.bind(this)):this._waiting=!0};d.prototype.onMIDIEvent=function(a,c){this._last_midi_event=c;this.trigger("on_midi",c);c.cmd==b.NOTEON?this.trigger("on_noteon",c):c.cmd==b.NOTEOFF?this.trigger("on_noteoff",c):c.cmd==b.CONTROLLERCHANGE?this.trigger("on_cc",c):c.cmd==b.PROGRAMCHANGE?this.trigger("on_pc",
c):c.cmd==b.PITCHBEND&&this.trigger("on_pitchbend",c)};d.prototype.onExecute=function(){if(this.outputs)for(var a=this._last_midi_event,b=0;b<this.outputs.length;++b){var c=null;switch(this.outputs[b].name){case "last_midi":c=a;break;default:continue}this.setOutputData(b,c)}};d.prototype.onGetOutputs=function(){return[["last_midi","midi"],["on_midi",LiteGraph.EVENT],["on_noteon",LiteGraph.EVENT],["on_noteoff",LiteGraph.EVENT],["on_cc",LiteGraph.EVENT],["on_pc",LiteGraph.EVENT],["on_pitchbend",LiteGraph.EVENT]]};
LiteGraph.registerNodeType("midi/input",d);e.MIDIInterface=c;e.title="MIDI Output";e.desc="Sends MIDI to output channel";e.prototype.getPropertyInfo=function(a){if(this._midi&&"port"==a){a={};for(var b=0;b<this._midi.output_ports.size;++b){var c=this._midi.output_ports.get(b);a[b]=b+".- "+c.name+" version:"+c.version}return{type:"enum",values:a}}};e.prototype.onAction=function(a,b){console.log(b);this._midi&&("send"==a&&this._midi.sendMIDI(this.port,b),this.trigger("midi",b))};e.prototype.onGetInputs=
function(){return[["send",LiteGraph.ACTION]]};e.prototype.onGetOutputs=function(){return[["on_midi",LiteGraph.EVENT]]};LiteGraph.registerNodeType("midi/output",e);f.title="MIDI Show";f.desc="Shows MIDI in the graph";f.prototype.onAction=function(a,c){c&&(this._str=c.constructor===b?c.toString():"???")};f.prototype.onDrawForeground=function(a){this._str&&(a.font="30px Arial",a.fillText(this._str,10,0.8*this.size[1]))};f.prototype.onGetInputs=function(){return[["in",LiteGraph.ACTION]]};f.prototype.onGetOutputs=
function(){return[["on_midi",LiteGraph.EVENT]]};LiteGraph.registerNodeType("midi/show",f);g.title="MIDI Filter";g.desc="Filters MIDI messages";g.prototype.onAction=function(a,c){!c||c.constructor!==b||-1!=this.properties.channel&&c.channel!=this.properties.channel||-1!=this.properties.cmd&&c.cmd!=this.properties.cmd||-1!=this.properties.min_value&&c.data[1]<this.properties.min_value||-1!=this.properties.max_value&&c.data[1]>this.properties.max_value||this.trigger("on_midi",c)};LiteGraph.registerNodeType("midi/filter",
g);h.title="MIDIEvent";h.desc="Create a MIDI Event";h.prototype.onAction=function(a,c){"assign"==a?(this.properties.channel=c.channel,this.properties.cmd=c.cmd,this.properties.value1=c.data[1],this.properties.value2=c.data[2]):(c=new b,c.channel=this.properties.channel,this.properties.cmd&&this.properties.cmd.constructor===String?c.setCommandFromString(this.properties.cmd):c.cmd=this.properties.cmd,c.data[0]=c.cmd|c.channel,c.data[1]=Number(this.properties.value1),c.data[2]=Number(this.properties.value2),
this.trigger("on_midi",c))};h.prototype.onExecute=function(){var a=this.properties;if(this.outputs)for(var c=0;c<this.outputs.length;++c){var d=null;switch(this.outputs[c].name){case "midi":d=new b;d.setup([a.cmd,a.value1,a.value2]);d.channel=a.channel;break;case "command":d=a.cmd;break;case "note":d=a.cmd==b.NOTEON||a.cmd==b.NOTEOFF?a.value1:NULL;break;case "velocity":d=a.cmd==b.NOTEON?a.value2:NULL;break;case "pitch":d=a.cmd==b.NOTEON?b.computePitch(a.value1):null;break;case "pitchbend":d=a.cmd==
b.PITCHBEND?b.computePitchBend(a.value1,a.value2):null;break;default:continue}null!==d&&this.setOutputData(c,d)}};h.prototype.onPropertyChanged=function(a,c){"cmd"==a&&(this.properties.cmd=b.computeCommandFromString(c))};h.prototype.onGetOutputs=function(){return[["midi","midi"],["on_midi",LiteGraph.EVENT],["command","number"],["note","number"],["velocity","number"],["pitch","number"],["pitchbend","number"]]};LiteGraph.registerNodeType("midi/event",h)})(window);
(function(a){function b(){this.properties={src:"demodata/audio.wav",gain:0.5,loop:!0,autoplay:!0,playbackRate:1};this._loading_audio=!1;this._audio_buffer=null;this._audionodes=[];this.addOutput("out","audio");this.addInput("gain","number");this.audionode=p.getAudioContext().createGain();this.audionode.graphnode=this;this.audionode.gain.value=this.properties.gain;this.properties.src&&this.loadSound(this.properties.src)}function c(){this.properties={fftSize:2048,minDecibels:-100,maxDecibels:-10,smoothingTimeConstant:0.5};
this.audionode=p.getAudioContext().createAnalyser();this.audionode.graphnode=this;this.audionode.fftSize=this.properties.fftSize;this.audionode.minDecibels=this.properties.minDecibels;this.audionode.maxDecibels=this.properties.maxDecibels;this.audionode.smoothingTimeConstant=this.properties.smoothingTimeConstant;this.addInput("in","audio");this.addOutput("freqs","array");this._time_bin=this._freq_bin=null}function d(a){a.prototype.onPropertyChanged=function(a,b){void 0!==this.audionode[a]&&(void 0!==
this.audionode[a].value?this.audionode[a].value=b:this.audionode[a]=b)};a.prototype.onConnectionsChange=p.onConnectionsChange}function e(){this.properties={gain:1};this.audionode=p.getAudioContext().createGain();this.addInput("in","audio");this.addInput("gain","number");this.addOutput("out","audio")}function f(){this.properties={};this.audionode=p.getAudioContext().createWaveShaper();this.addInput("in","audio");this.addInput("shape","waveshape");this.addOutput("out","audio")}function g(){this.properties=
{gain1:0.5,gain2:0.5};this.audionode=p.getAudioContext().createGain();this.audionode1=p.getAudioContext().createGain();this.audionode1.gain.value=this.properties.gain1;this.audionode2=p.getAudioContext().createGain();this.audionode2.gain.value=this.properties.gain2;this.audionode1.connect(this.audionode);this.audionode2.connect(this.audionode);this.addInput("in1","audio");this.addInput("in1 gain","number");this.addInput("in2","audio");this.addInput("in2 gain","number");this.addOutput("out","audio")}
function h(){this.properties={delayTime:0.5};this.audionode=p.getAudioContext().createDelay(10);this.audionode.delayTime.value=this.properties.delayTime;this.addInput("in","audio");this.addInput("time","number");this.addOutput("out","audio")}function k(){this.properties={frequency:350,detune:0,Q:1};this.addProperty("type","lowpass","enum",{values:"lowpass highpass bandpass lowshelf highshelf peaking notch allpass".split(" ")});this.audionode=p.getAudioContext().createBiquadFilter();this.addInput("in",
"audio");this.addOutput("out","audio")}function n(){this.properties={continuous:!0};this.addInput("freqs","array");this.size=[300,200];this._last_buffer=null}function l(){this.audionode=p.getAudioContext().destination;this.addInput("in","audio")}var p={};a.LGAudio=p;p.getAudioContext=function(){if(!this._audio_context){window.AudioContext=window.AudioContext||window.webkitAudioContext;if(!window.AudioContext)return console.error("AudioContext not supported by browser"),null;this._audio_context=new AudioContext;
this._audio_context.onmessage=function(a){console.log("msg",a)};this._audio_context.onended=function(a){console.log("ended",a)};this._audio_context.oncomplete=function(a){console.log("complete",a)}}"suspended"==this._audio_context.state&&this._audio_context.resume();return this._audio_context};p.connect=function(a,b){try{a.connect(b)}catch(c){console.warn("LGraphAudio:",c)}};p.disconnect=function(a,b){try{a.disconnect(b)}catch(c){console.warn("LGraphAudio:",c)}};p.changeAllAudiosConnections=function(a,
b){if(a.inputs)for(var c=0;c<a.inputs.length;++c){var d=a.graph.links[a.inputs[c].link];if(d){var e=a.graph.getNodeById(d.origin_id),f=null,f=e.getAudioNodeInOutputSlot?e.getAudioNodeInOutputSlot(d.origin_slot):e.audionode,d=null,d=a.getAudioNodeInInputSlot?a.getAudioNodeInInputSlot(c):a.audionode;b?p.connect(f,d):p.disconnect(f,d)}}if(a.outputs)for(c=0;c<a.outputs.length;++c)for(var e=a.outputs[c],g=0;g<e.links.length;++g)if(d=a.graph.links[e.links[g]]){var f=a.getAudioNodeInOutputSlot?a.getAudioNodeInOutputSlot(c):
a.audionode,h=a.graph.getNodeById(d.target_id),d=h.getAudioNodeInInputSlot?h.getAudioNodeInInputSlot(d.target_slot):h.audionode;b?p.connect(f,d):p.disconnect(f,d)}};p.onConnectionsChange=function(a,b,c,d){if(a==LiteGraph.OUTPUT&&(a=null,d&&(a=this.graph.getNodeById(d.target_id)),a)){var e=null,e=this.getAudioNodeInOutputSlot?this.getAudioNodeInOutputSlot(b):this.audionode;b=null;b=a.getAudioNodeInInputSlot?a.getAudioNodeInInputSlot(d.target_slot):a.audionode;c?p.connect(e,b):p.disconnect(e,b)}};b.supported_extensions=
["wav","ogg","mp3"];b.prototype.onAdded=function(a){if(a.status===LGraph.STATUS_RUNNING)this.onStart()};b.prototype.onStart=function(){this._audio_buffer&&this.properties.autoplay&&this.playBuffer(this._audio_buffer)};b.prototype.onStop=function(){this.stopAllSounds()};b.prototype.onRemoved=function(){this.stopAllSounds()};b.prototype.stopAllSounds=function(){for(var a=0;a<this._audionodes.length;++a)this._audionodes[a].stop();this._audionodes.length=0};b.prototype.onExecute=function(){if(this.inputs)for(var a=
0;a<this.inputs.length;++a){var b=this.inputs[a];if(b.link){var c=this.getInputData(a);void 0!==c&&("gain"==b.name?this.audionode.gain.value=c:"playbackRate"==b.name&&(this.properties.playbackRate=c))}}};b.prototype.onAction=function(a){this._audio_buffer&&("Play"==a?this.playBuffer(this._audio_buffer):"Stop"==a&&this.stopAllSounds())};b.prototype.onPropertyChanged=function(a,b){"src"==a?this.loadSound(b):"gain"==a&&(this.audionode.gain.value=b)};b.prototype.playBuffer=function(a){var b=this,c=p.getAudioContext().createBufferSource();
c.graphnode=this;c.buffer=a;c.loop=this.properties.loop;c.playbackRate.value=this.properties.playbackRate;this._audionodes.push(c);c.connect(this.audionode);this._audionodes.push(c);c.onended=function(){b.trigger("ended");var a=b._audionodes.indexOf(c);-1!=a&&b._audionodes.splice(a,1)};c.start();return c};b.prototype.loadSound=function(a){function b(a){console.log("Audio loading sample error:",a)}var c=this;this._request&&(this._request.abort(),this._request=null);this._audio_buffer=null;this._loading_audio=
!1;if(a){var d=new XMLHttpRequest;d.open("GET",a,!0);d.responseType="arraybuffer";this._loading_audio=!0;this._request=d;var e=p.getAudioContext();d.onload=function(){e.decodeAudioData(d.response,function(a){c._audio_buffer=a;c._url&&(URL.revokeObjectURL(c._url),c._url=null);c._loading_audio=!1;if(c.graph&&c.graph.status===LGraph.STATUS_RUNNING)c.onStart()},b)};d.send()}};b.prototype.onConnectionsChange=p.onConnectionsChange;b.prototype.onGetInputs=function(){return[["playbackRate","number"],["Play",
LiteGraph.ACTION],["Stop",LiteGraph.ACTION]]};b.prototype.onGetOutputs=function(){return[["ended",LiteGraph.EVENT]]};b.prototype.onDropFile=function(a){this._url&&URL.revokeObjectURL(this._url);this._url=URL.createObjectURL(a);this.properties.src=this._url;this.loadSound(this._url)};b.title="Source";b.desc="Plays audio";LiteGraph.registerNodeType("audio/source",b);c.prototype.onPropertyChanged=function(a,b){this.audionode[a]=b};c.prototype.onExecute=function(){if(this.isOutputConnected(0)){var a=
this.audionode.frequencyBinCount;this._freq_bin&&this._freq_bin.length==a||(this._freq_bin=new Uint8Array(a));this.audionode.getByteFrequencyData(this._freq_bin);this.setOutputData(0,this._freq_bin)}for(a=1;a<this.inputs.length;++a){var b=this.inputs[a],c=this.getInputData(a);void 0!==c&&(this.audionode[b.name].value=c)}};c.prototype.onGetInputs=function(){return[["minDecibels","number"],["maxDecibels","number"],["smoothingTimeConstant","number"]]};c.title="Analyser";c.desc="Audio Analyser";LiteGraph.registerNodeType("audio/analyser",
c);e.prototype.onExecute=function(){if(this.inputs&&this.inputs.length)for(var a=1;a<this.inputs.length;++a){var b=this.inputs[a],c=this.getInputData(a);void 0!==c&&(this.audionode[b.name].value=c)}};d(e);e.title="Gain";e.desc="Audio gain";LiteGraph.registerNodeType("audio/gain",e);f.prototype.onExecute=function(){if(this.inputs&&this.inputs.length){var a=this.getInputData(1);void 0!==a&&(this.audionode.curve=a)}};f.prototype.setWaveShape=function(a){this.audionode.curve=a};d(f);g.prototype.getAudioNodeInInputSlot=
function(a){if(0==a)return this.audionode1;if(2==a)return this.audionode2};g.prototype.onExecute=function(){if(this.inputs&&this.inputs.length)for(var a=1;a<this.inputs.length;++a)if("audio"!=this.inputs[a].type){var b=this.getInputData(a);void 0!==b&&(1==a?this.audionode1.gain.value=b:3==a&&(this.audionode2.gain.value=b))}};d(g);g.title="Mixer";g.desc="Audio mixer";LiteGraph.registerNodeType("audio/mixer",g);d(h);h.prototype.onExecute=function(){var a=this.getInputData(1);void 0!==a&&(this.audionode.delayTime.value=
a)};h.title="Delay";h.desc="Audio delay";LiteGraph.registerNodeType("audio/delay",h);k.prototype.onExecute=function(){if(this.inputs&&this.inputs.length)for(var a=1;a<this.inputs.length;++a){var b=this.inputs[a],c=this.getInputData(a);void 0!==c&&(this.audionode[b.name].value=c)}};k.prototype.onGetInputs=function(){return[["frequency","number"],["detune","number"],["Q","number"]]};d(k);k.title="BiquadFilter";k.desc="Audio filter";LiteGraph.registerNodeType("audio/biquadfilter",k);n.prototype.onExecute=
function(){this._last_buffer=this.getInputData(0)};n.prototype.onDrawForeground=function(a){if(this._last_buffer){var b=this._last_buffer,c=b.length/this.size[0],d=this.size[1];a.fillStyle="black";a.fillRect(0,0,this.size[0],this.size[1]);a.strokeStyle="white";a.beginPath();var e=0;if(this.properties.continuous){a.moveTo(e,d);for(var f=0;f<b.length;f+=c)a.lineTo(e,d-b[f|0]/255*d),e++}else for(f=0;f<b.length;f+=c)a.moveTo(e,d),a.lineTo(e,d-b[f|0]/255*d),e++;a.stroke()}};n.title="Visualization";n.desc=
"Audio Visualization";LiteGraph.registerNodeType("audio/visualization",n);l.title="Destination";l.desc="Audio output";LiteGraph.registerNodeType("audio/destination",l)})(window);
(function(e){function d(a){this.cmd=this.channel=0;a?this.setup(a):this.data=[0,0,0]}function g(a,b){navigator.requestMIDIAccess?(this.on_ready=a,navigator.requestMIDIAccess().then(this.onMIDISuccess.bind(this),this.onMIDIFailure.bind(this))):(this.error="not suppoorted",b?b("Not supported"):console.error("MIDI NOT SUPPORTED, enable by chrome://flags"))}function k(){this.addOutput("on_midi",LiteGraph.EVENT);this.addOutput("out","midi");this.properties={port:0};this._current_midi_event=this._last_midi_event=
null;var a=this;new g(function(b){a._midi=b;if(a._waiting)a.onStart();a._waiting=!1})}function h(){this.addInput("send",LiteGraph.EVENT);this.properties={port:0};var a=this;new g(function(b){a._midi=b})}function a(){this.addInput("on_midi",LiteGraph.EVENT);this._str="";this.size=[200,40]}function b(){this.properties={channel:-1,cmd:-1,min_value:-1,max_value:-1};this.addInput("in",LiteGraph.EVENT);this.addOutput("on_midi",LiteGraph.EVENT)}function c(){this.properties={channel:0,cmd:"CC",value1:1,value2:1};
this.addInput("send",LiteGraph.EVENT);this.addInput("assign",LiteGraph.EVENT);this.addOutput("on_midi",LiteGraph.EVENT)}d.prototype.setup=function(a){this.data=a;this.status=a=a[0];var b=a&240;this.cmd=240<=a?a:b;this.cmd==d.NOTEON&&0==this.velocity&&(this.cmd=d.NOTEOFF);this.cmd_str=d.commands[this.cmd]||"";if(b>=d.NOTEON||b<=d.NOTEOFF)this.channel=a&15};Object.defineProperty(d.prototype,"velocity",{get:function(){return this.cmd==d.NOTEON?this.data[2]:-1},set:function(a){this.data[2]=a},enumerable:!0});
d.notes="A A# B C C# D D# E F F# G G#".split(" ");d.prototype.getPitch=function(){return 440*Math.pow(2,(this.data[1]-69)/12)};d.computePitch=function(a){return 440*Math.pow(2,(a-69)/12)};d.prototype.getPitchBend=function(){return this.data[1]+(this.data[2]<<7)-8192};d.computePitchBend=function(a,b){return a+(b<<7)-8192};d.prototype.setCommandFromString=function(a){this.cmd=d.computeCommandFromString(a)};d.computeCommandFromString=function(a){if(!a)return 0;if(a&&a.constructor===Number)return a;a=
a.toUpperCase();switch(a){case "NOTE ON":case "NOTEON":return d.NOTEON;case "NOTE OFF":case "NOTEOFF":return d.NOTEON;case "KEY PRESSURE":case "KEYPRESSURE":return d.KEYPRESSURE;case "CONTROLLER CHANGE":case "CONTROLLERCHANGE":case "CC":return d.CONTROLLERCHANGE;case "PROGRAM CHANGE":case "PROGRAMCHANGE":case "PC":return d.PROGRAMCHANGE;case "CHANNEL PRESSURE":case "CHANNELPRESSURE":return d.CHANNELPRESSURE;case "PITCH BEND":case "PITCHBEND":return d.PITCHBEND;case "TIME TICK":case "TIMETICK":return d.TIMETICK;
default:return Number(a)}};d.toNoteString=function(a){var b;b=(a-21)%12;0>b&&(b=12+b);return d.notes[b]+Math.floor((a-24)/12+1)};d.prototype.toString=function(){var a=""+this.channel+". ";switch(this.cmd){case d.NOTEON:a+="NOTEON "+d.toNoteString(this.data[1]);break;case d.NOTEOFF:a+="NOTEOFF "+d.toNoteString(this.data[1]);break;case d.CONTROLLERCHANGE:a+="CC "+this.data[1]+" "+this.data[2];break;case d.PROGRAMCHANGE:a+="PC "+this.data[1];break;case d.PITCHBEND:a+="PITCHBEND "+this.getPitchBend();
break;case d.KEYPRESSURE:a+="KEYPRESS "+this.data[1]}return a};d.prototype.toHexString=function(){for(var a="",b=0;b<this.data.length;b++)a+=this.data[b].toString(16)+" "};d.NOTEOFF=128;d.NOTEON=144;d.KEYPRESSURE=160;d.CONTROLLERCHANGE=176;d.PROGRAMCHANGE=192;d.CHANNELPRESSURE=208;d.PITCHBEND=224;d.TIMETICK=248;d.commands={128:"note off",144:"note on",160:"key pressure",176:"controller change",192:"program change",208:"channel pressure",224:"pitch bend",240:"system",242:"Song pos",243:"Song select",
246:"Tune request",248:"time tick",250:"Start Song",251:"Continue Song",252:"Stop Song",254:"Sensing",255:"Reset"};g.MIDIEvent=d;g.prototype.onMIDISuccess=function(a){console.log("MIDI ready!");console.log(a);this.midi=a;this.updatePorts();if(this.on_ready)this.on_ready(this)};g.prototype.updatePorts=function(){var a=this.midi;this.input_ports=a.inputs;for(var b=0,c=0;c<this.input_ports.size;++c){var d=this.input_ports.get(c);console.log("Input port [type:'"+d.type+"'] id:'"+d.id+"' manufacturer:'"+
d.manufacturer+"' name:'"+d.name+"' version:'"+d.version+"'");b++}this.num_input_ports=b;b=0;this.output_ports=a.outputs;for(c=0;c<this.output_ports.size;++c)a=this.output_ports.get(c),console.log("Output port [type:'"+a.type+"'] id:'"+a.id+"' manufacturer:'"+a.manufacturer+"' name:'"+a.name+"' version:'"+a.version+"'"),b++;this.num_output_ports=b};g.prototype.onMIDIFailure=function(a){console.error("Failed to get MIDI access - "+a)};g.prototype.openInputPort=function(a,b){var c=this.input_ports.get(a);
if(!c)return!1;c.onmidimessage=function(a){var c=new d(a.data);b&&b(a.data,c);if(g.on_message)g.on_message(a.data,c)};console.log("port open: ",c);return!0};g.parseMsg=function(a){};g.prototype.sendMIDI=function(a,b){if(b){var c=this.output_ports.get(a);c&&(b.constructor===d?c.send(b.data):c.send(b))}};k.MIDIInterface=g;k.title="MIDI Input";k.desc="Reads MIDI from a input port";k.prototype.getPropertyInfo=function(a){if(this._midi&&"port"==a){a={};for(var b=0;b<this._midi.input_ports.size;++b){var c=
this._midi.input_ports.get(b);a[b]=b+".- "+c.name+" version:"+c.version}return{type:"enum",values:a}}};k.prototype.onStart=function(){this._midi?this._midi.openInputPort(this.properties.port,this.onMIDIEvent.bind(this)):this._waiting=!0};k.prototype.onMIDIEvent=function(a,b){this._last_midi_event=b;this.trigger("on_midi",b);b.cmd==d.NOTEON?this.trigger("on_noteon",b):b.cmd==d.NOTEOFF?this.trigger("on_noteoff",b):b.cmd==d.CONTROLLERCHANGE?this.trigger("on_cc",b):b.cmd==d.PROGRAMCHANGE?this.trigger("on_pc",
b):b.cmd==d.PITCHBEND&&this.trigger("on_pitchbend",b)};k.prototype.onExecute=function(){if(this.outputs)for(var a=this._last_midi_event,b=0;b<this.outputs.length;++b){var c=null;switch(this.outputs[b].name){case "last_midi":c=a;break;default:continue}this.setOutputData(b,c)}};k.prototype.onGetOutputs=function(){return[["last_midi","midi"],["on_midi",LiteGraph.EVENT],["on_noteon",LiteGraph.EVENT],["on_noteoff",LiteGraph.EVENT],["on_cc",LiteGraph.EVENT],["on_pc",LiteGraph.EVENT],["on_pitchbend",LiteGraph.EVENT]]};
LiteGraph.registerNodeType("midi/input",k);h.MIDIInterface=g;h.title="MIDI Output";h.desc="Sends MIDI to output channel";h.prototype.getPropertyInfo=function(a){if(this._midi&&"port"==a){a={};for(var b=0;b<this._midi.output_ports.size;++b){var c=this._midi.output_ports.get(b);a[b]=b+".- "+c.name+" version:"+c.version}return{type:"enum",values:a}}};h.prototype.onAction=function(a,b){console.log(b);this._midi&&("send"==a&&this._midi.sendMIDI(this.port,b),this.trigger("midi",b))};h.prototype.onGetInputs=
function(){return[["send",LiteGraph.ACTION]]};h.prototype.onGetOutputs=function(){return[["on_midi",LiteGraph.EVENT]]};LiteGraph.registerNodeType("midi/output",h);a.title="MIDI Show";a.desc="Shows MIDI in the graph";a.prototype.onAction=function(a,b){b&&(this._str=b.constructor===d?b.toString():"???")};a.prototype.onDrawForeground=function(a){this._str&&(a.font="30px Arial",a.fillText(this._str,10,0.8*this.size[1]))};a.prototype.onGetInputs=function(){return[["in",LiteGraph.ACTION]]};a.prototype.onGetOutputs=
function(){return[["on_midi",LiteGraph.EVENT]]};LiteGraph.registerNodeType("midi/show",a);b.title="MIDI Filter";b.desc="Filters MIDI messages";b.prototype.onAction=function(a,b){!b||b.constructor!==d||-1!=this.properties.channel&&b.channel!=this.properties.channel||-1!=this.properties.cmd&&b.cmd!=this.properties.cmd||-1!=this.properties.min_value&&b.data[1]<this.properties.min_value||-1!=this.properties.max_value&&b.data[1]>this.properties.max_value||this.trigger("on_midi",b)};LiteGraph.registerNodeType("midi/filter",
b);c.title="MIDIEvent";c.desc="Create a MIDI Event";c.prototype.onAction=function(a,b){"assign"==a?(this.properties.channel=b.channel,this.properties.cmd=b.cmd,this.properties.value1=b.data[1],this.properties.value2=b.data[2]):(b=new d,b.channel=this.properties.channel,this.properties.cmd&&this.properties.cmd.constructor===String?b.setCommandFromString(this.properties.cmd):b.cmd=this.properties.cmd,b.data[0]=b.cmd|b.channel,b.data[1]=Number(this.properties.value1),b.data[2]=Number(this.properties.value2),
this.trigger("on_midi",b))};c.prototype.onExecute=function(){var a=this.properties;if(this.outputs)for(var b=0;b<this.outputs.length;++b){var c=null;switch(this.outputs[b].name){case "midi":c=new d;c.setup([a.cmd,a.value1,a.value2]);c.channel=a.channel;break;case "command":c=a.cmd;break;case "note":c=a.cmd==d.NOTEON||a.cmd==d.NOTEOFF?a.value1:NULL;break;case "velocity":c=a.cmd==d.NOTEON?a.value2:NULL;break;case "pitch":c=a.cmd==d.NOTEON?d.computePitch(a.value1):null;break;case "pitchbend":c=a.cmd==
d.PITCHBEND?d.computePitchBend(a.value1,a.value2):null;break;default:continue}null!==c&&this.setOutputData(b,c)}};c.prototype.onPropertyChanged=function(a,b){"cmd"==a&&(this.properties.cmd=d.computeCommandFromString(b))};c.prototype.onGetOutputs=function(){return[["midi","midi"],["on_midi",LiteGraph.EVENT],["command","number"],["note","number"],["velocity","number"],["pitch","number"],["pitchbend","number"]]};LiteGraph.registerNodeType("midi/event",c)})(window);
(function(e){function d(){this.properties={src:"",gain:0.5,loop:!0,autoplay:!0,playbackRate:1};this._loading_audio=!1;this._audio_buffer=null;this._audionodes=[];this.addOutput("out","audio");this.addInput("gain","number");this.audionode=n.getAudioContext().createGain();this.audionode.graphnode=this;this.audionode.gain.value=this.properties.gain;this.properties.src&&this.loadSound(this.properties.src)}function g(){this.properties={fftSize:2048,minDecibels:-100,maxDecibels:-10,smoothingTimeConstant:0.5};
this.audionode=n.getAudioContext().createAnalyser();this.audionode.graphnode=this;this.audionode.fftSize=this.properties.fftSize;this.audionode.minDecibels=this.properties.minDecibels;this.audionode.maxDecibels=this.properties.maxDecibels;this.audionode.smoothingTimeConstant=this.properties.smoothingTimeConstant;this.addInput("in","audio");this.addOutput("freqs","array");this._time_bin=this._freq_bin=null}function k(){this.properties={gain:1};this.audionode=n.getAudioContext().createGain();this.addInput("in",
"audio");this.addInput("gain","number");this.addOutput("out","audio")}function h(){this.properties={impulse_src:"",normalize:!0};this.audionode=n.getAudioContext().createConvolver();this.addInput("in","audio");this.addOutput("out","audio")}function a(){this.properties={threshold:-50,knee:40,ratio:12,reduction:-20,attack:0,release:0.25};this.audionode=n.getAudioContext().createDynamicsCompressor();this.addInput("in","audio");this.addOutput("out","audio")}function b(){this.properties={};this.audionode=
n.getAudioContext().createWaveShaper();this.addInput("in","audio");this.addInput("shape","waveshape");this.addOutput("out","audio")}function c(){this.properties={gain1:0.5,gain2:0.5};this.audionode=n.getAudioContext().createGain();this.audionode1=n.getAudioContext().createGain();this.audionode1.gain.value=this.properties.gain1;this.audionode2=n.getAudioContext().createGain();this.audionode2.gain.value=this.properties.gain2;this.audionode1.connect(this.audionode);this.audionode2.connect(this.audionode);
this.addInput("in1","audio");this.addInput("in1 gain","number");this.addInput("in2","audio");this.addInput("in2 gain","number");this.addOutput("out","audio")}function f(){this.properties={delayTime:0.5};this.audionode=n.getAudioContext().createDelay(10);this.audionode.delayTime.value=this.properties.delayTime;this.addInput("in","audio");this.addInput("time","number");this.addOutput("out","audio")}function l(){this.properties={frequency:350,detune:0,Q:1};this.addProperty("type","lowpass","enum",{values:"lowpass highpass bandpass lowshelf highshelf peaking notch allpass".split(" ")});
this.audionode=n.getAudioContext().createBiquadFilter();this.addInput("in","audio");this.addOutput("out","audio")}function u(){this.properties={continuous:!0,mark:-1};this.addInput("freqs","array");this.addInput("mark","number");this.size=[300,200];this._last_buffer=null}function s(){this.properties={band:440,amplitude:1};this.addInput("freqs","array");this.addOutput("signal","number")}function t(){this.audionode=n.getAudioContext().destination;this.addInput("in","audio")}var n={};e.LGAudio=n;n.getAudioContext=
function(){if(!this._audio_context){window.AudioContext=window.AudioContext||window.webkitAudioContext;if(!window.AudioContext)return console.error("AudioContext not supported by browser"),null;this._audio_context=new AudioContext;this._audio_context.onmessage=function(a){console.log("msg",a)};this._audio_context.onended=function(a){console.log("ended",a)};this._audio_context.oncomplete=function(a){console.log("complete",a)}}"suspended"==this._audio_context.state&&this._audio_context.resume();return this._audio_context};
n.connect=function(a,b){try{a.connect(b)}catch(c){console.warn("LGraphAudio:",c)}};n.disconnect=function(a,b){try{a.disconnect(b)}catch(c){console.warn("LGraphAudio:",c)}};n.changeAllAudiosConnections=function(a,b){if(a.inputs)for(var c=0;c<a.inputs.length;++c){var d=a.graph.links[a.inputs[c].link];if(d){var e=a.graph.getNodeById(d.origin_id),f=null,f=e.getAudioNodeInOutputSlot?e.getAudioNodeInOutputSlot(d.origin_slot):e.audionode,d=null,d=a.getAudioNodeInInputSlot?a.getAudioNodeInInputSlot(c):a.audionode;
b?n.connect(f,d):n.disconnect(f,d)}}if(a.outputs)for(c=0;c<a.outputs.length;++c)for(var e=a.outputs[c],g=0;g<e.links.length;++g)if(d=a.graph.links[e.links[g]]){var f=a.getAudioNodeInOutputSlot?a.getAudioNodeInOutputSlot(c):a.audionode,h=a.graph.getNodeById(d.target_id),d=h.getAudioNodeInInputSlot?h.getAudioNodeInInputSlot(d.target_slot):h.audionode;b?n.connect(f,d):n.disconnect(f,d)}};n.onConnectionsChange=function(a,b,c,d){if(a==LiteGraph.OUTPUT&&(a=null,d&&(a=this.graph.getNodeById(d.target_id)),
a)){var e=null,e=this.getAudioNodeInOutputSlot?this.getAudioNodeInOutputSlot(b):this.audionode;b=null;b=a.getAudioNodeInInputSlot?a.getAudioNodeInInputSlot(d.target_slot):a.audionode;c?n.connect(e,b):n.disconnect(e,b)}};n.createAudioNodeWrapper=function(a){a.prototype.onPropertyChanged=function(a,b){this.audionode&&void 0!==this.audionode[a]&&(void 0!==this.audionode[a].value?this.audionode[a].value=b:this.audionode[a]=b)};a.prototype.onConnectionsChange=n.onConnectionsChange};n.cached_audios={};
n.loadSound=function(a,b,c){function d(a){console.log("Audio loading sample error:",a);c&&c(a)}if(n.cached_audios[a]&&-1==a.indexOf("blob:"))b&&b(n.cached_audios[a]);else{var e=new XMLHttpRequest;e.open("GET",a,!0);e.responseType="arraybuffer";var f=n.getAudioContext();e.onload=function(){console.log("AudioSource loaded");f.decodeAudioData(e.response,function(c){console.log("AudioSource decoded");n.cached_audios[a]=c;b&&b(c)},d)};e.send();return e}};d.supported_extensions=["wav","ogg","mp3"];d.prototype.onAdded=
function(a){if(a.status===LGraph.STATUS_RUNNING)this.onStart()};d.prototype.onStart=function(){this._audio_buffer&&this.properties.autoplay&&this.playBuffer(this._audio_buffer)};d.prototype.onStop=function(){this.stopAllSounds()};d.prototype.onRemoved=function(){this.stopAllSounds();this._dropped_url&&URL.revokeObjectURL(this._url)};d.prototype.stopAllSounds=function(){for(var a=0;a<this._audionodes.length;++a)this._audionodes[a].stop();this._audionodes.length=0};d.prototype.onExecute=function(){if(this.inputs)for(var a=
0;a<this.inputs.length;++a){var b=this.inputs[a];if(b.link){var c=this.getInputData(a);void 0!==c&&("gain"==b.name?this.audionode.gain.value=c:"playbackRate"==b.name&&(this.properties.playbackRate=c))}}};d.prototype.onAction=function(a){this._audio_buffer&&("Play"==a?this.playBuffer(this._audio_buffer):"Stop"==a&&this.stopAllSounds())};d.prototype.onPropertyChanged=function(a,b){"src"==a?this.loadSound(b):"gain"==a&&(this.audionode.gain.value=b)};d.prototype.playBuffer=function(a){var b=this,c=n.getAudioContext().createBufferSource();
c.graphnode=this;c.buffer=a;c.loop=this.properties.loop;c.playbackRate.value=this.properties.playbackRate;this._audionodes.push(c);c.connect(this.audionode);this._audionodes.push(c);c.onended=function(){b.trigger("ended");var a=b._audionodes.indexOf(c);-1!=a&&b._audionodes.splice(a,1)};c.start();return c};d.prototype.loadSound=function(a){function b(a){this.boxcolor=LiteGraph.NODE_DEFAULT_BOXCOLOR;c._audio_buffer=a;c._loading_audio=!1;if(c.graph&&c.graph.status===LGraph.STATUS_RUNNING)c.onStart()}
var c=this;this._request&&(this._request.abort(),this._request=null);this._audio_buffer=null;this._loading_audio=!1;a&&(this._request=n.loadSound(a,b),this._loading_audio=!0,this.boxcolor="#AA4")};d.prototype.onConnectionsChange=n.onConnectionsChange;d.prototype.onGetInputs=function(){return[["playbackRate","number"],["Play",LiteGraph.ACTION],["Stop",LiteGraph.ACTION]]};d.prototype.onGetOutputs=function(){return[["ended",LiteGraph.EVENT]]};d.prototype.onDropFile=function(a){this._dropped_url&&URL.revokeObjectURL(this._dropped_url);
a=URL.createObjectURL(a);this.properties.src=a;this.loadSound(a);this._dropped_url=a};d.title="Source";d.desc="Plays audio";LiteGraph.registerNodeType("audio/source",d);g.prototype.onPropertyChanged=function(a,b){this.audionode[a]=b};g.prototype.onExecute=function(){if(this.isOutputConnected(0)){var a=this.audionode.frequencyBinCount;this._freq_bin&&this._freq_bin.length==a||(this._freq_bin=new Uint8Array(a));this.audionode.getByteFrequencyData(this._freq_bin);this.setOutputData(0,this._freq_bin)}this.isOutputConnected(1)&&
this.setOutputData(1,this.audionode);for(a=1;a<this.inputs.length;++a){var b=this.inputs[a];if(b.link){var c=this.getInputData(a);void 0!==c&&(this.audionode[b.name].value=c)}}};g.prototype.onGetInputs=function(){return[["minDecibels","number"],["maxDecibels","number"],["smoothingTimeConstant","number"]]};g.title="Analyser";g.desc="Audio Analyser";LiteGraph.registerNodeType("audio/analyser",g);k.prototype.onExecute=function(){if(this.inputs&&this.inputs.length)for(var a=1;a<this.inputs.length;++a){var b=
this.inputs[a],c=this.getInputData(a);void 0!==c&&(this.audionode[b.name].value=c)}};n.createAudioNodeWrapper(k);k.title="Gain";k.desc="Audio gain";LiteGraph.registerNodeType("audio/gain",k);n.createAudioNodeWrapper(h);h.prototype.onRemove=function(){this._dropped_url&&URL.revokeObjectURL(this._dropped_url)};h.prototype.onPropertyChanged=function(a,b){"impulse_src"==a?this.loadImpulse(b):"normalize"==a&&(this.audionode.normalize=b)};h.prototype.onDropFile=function(a){this._dropped_url&&URL.revokeObjectURL(this._dropped_url);
this._dropped_url=URL.createObjectURL(a);this.properties.impulse_src=this._dropped_url;this.loadImpulse(this._dropped_url)};h.prototype.loadImpulse=function(a){function b(a){c._impulse_buffer=a;c.audionode.buffer=a;console.log("Impulse signal set");c._loading_impulse=!1}var c=this;this._request&&(this._request.abort(),this._request=null);this._impulse_buffer=null;this._loading_impulse=!1;a&&(this._request=n.loadSound(a,b),this._loading_impulse=!0)};h.title="Convolver";h.desc="Convolves the signal (used for reverb)";
LiteGraph.registerNodeType("audio/convolver",h);n.createAudioNodeWrapper(a);a.prototype.onExecute=function(){if(this.inputs&&this.inputs.length)for(var a=1;a<this.inputs.length;++a){var b=this.inputs[a];if(b.link){var c=this.getInputData(a);void 0!==c&&(this.audionode[b.name].value=c)}}};a.prototype.onGetInputs=function(){return[["threshold","number"],["knee","number"],["ratio","number"],["reduction","number"],["attack","number"],["release","number"]]};a.title="DynamicsCompressor";a.desc="Dynamics Compressor";
LiteGraph.registerNodeType("audio/dynamicsCompressor",a);b.prototype.onExecute=function(){if(this.inputs&&this.inputs.length){var a=this.getInputData(1);void 0!==a&&(this.audionode.curve=a)}};b.prototype.setWaveShape=function(a){this.audionode.curve=a};n.createAudioNodeWrapper(b);c.prototype.getAudioNodeInInputSlot=function(a){if(0==a)return this.audionode1;if(2==a)return this.audionode2};c.prototype.onExecute=function(){if(this.inputs&&this.inputs.length)for(var a=1;a<this.inputs.length;++a){var b=
this.inputs[a];b.link&&"audio"!=b.type&&(b=this.getInputData(a),void 0!==b&&(1==a?this.audionode1.gain.value=b:3==a&&(this.audionode2.gain.value=b)))}};n.createAudioNodeWrapper(c);c.title="Mixer";c.desc="Audio mixer";LiteGraph.registerNodeType("audio/mixer",c);n.createAudioNodeWrapper(f);f.prototype.onExecute=function(){var a=this.getInputData(1);void 0!==a&&(this.audionode.delayTime.value=a)};f.title="Delay";f.desc="Audio delay";LiteGraph.registerNodeType("audio/delay",f);l.prototype.onExecute=function(){if(this.inputs&&
this.inputs.length)for(var a=1;a<this.inputs.length;++a){var b=this.inputs[a];if(b.link){var c=this.getInputData(a);void 0!==c&&(this.audionode[b.name].value=c)}}};l.prototype.onGetInputs=function(){return[["frequency","number"],["detune","number"],["Q","number"]]};n.createAudioNodeWrapper(l);l.title="BiquadFilter";l.desc="Audio filter";LiteGraph.registerNodeType("audio/biquadfilter",l);u.prototype.onExecute=function(){this._last_buffer=this.getInputData(0);var a=this.getInputData(1);void 0!==a&&
(this.properties.mark=a);this.setDirtyCanvas(!0,!1)};u.prototype.onDrawForeground=function(a){if(this._last_buffer){var b=this._last_buffer,c=b.length/this.size[0],d=this.size[1];a.fillStyle="black";a.fillRect(0,0,this.size[0],this.size[1]);a.strokeStyle="white";a.beginPath();var e=0;if(this.properties.continuous){a.moveTo(e,d);for(var f=0;f<b.length;f+=c)a.lineTo(e,d-b[f|0]/255*d),e++}else for(f=0;f<b.length;f+=c)a.moveTo(e+0.5,d),a.lineTo(e+0.5,d-b[f|0]/255*d),e++;a.stroke();0<=this.properties.mark&&
(b=n.getAudioContext().sampleRate/b.length,e=this.properties.mark/b*2/c,e>=this.size[0]&&(e=this.size[0]-1),a.strokeStyle="red",a.beginPath(),a.moveTo(e,d),a.lineTo(e,0),a.stroke())}};u.title="Visualization";u.desc="Audio Visualization";LiteGraph.registerNodeType("audio/visualization",u);s.prototype.onExecute=function(){if(this._freqs=this.getInputData(0)){var a=this.properties.band,b=this.getInputData(1);void 0!==b&&(a=b);b=n.getAudioContext().sampleRate/this._freqs.length;b=a/b*2;b>=this._freqs.length?
b=this._freqs[this._freqs.length-1]:(a=b|0,b-=a,b=this._freqs[a]*(1-b)+this._freqs[a+1]*b);this.setOutputData(0,b/255*this.properties.amplitude)}};s.prototype.onGetInputs=function(){return[["band","number"]]};s.title="Signal";s.desc="extract the signal of some frequency";LiteGraph.registerNodeType("audio/signal",s);t.title="Destination";t.desc="Audio output";LiteGraph.registerNodeType("audio/destination",t)})(window);

View File

@@ -1,4 +1,4 @@
(function(global){
// *************************************************************
// LiteGraph CLASS *******
// *************************************************************
@@ -10,7 +10,7 @@
* @constructor
*/
var LiteGraph = {
var LiteGraph = global.LiteGraph = {
NODE_TITLE_HEIGHT: 16,
NODE_SLOT_HEIGHT: 15,
@@ -100,7 +100,12 @@ var LiteGraph = {
{
LGraphNode.prototype[name] = func;
for(var i in this.registered_node_types)
this.registered_node_types[i].prototype[name] = func;
{
var type = this.registered_node_types[i];
if(type.prototype[name])
type.prototype["_" + name] = type.prototype[name]; //keep old in case of replacing
type.prototype[name] = func;
}
},
/**
@@ -285,7 +290,7 @@ else
* @constructor
*/
function LGraph()
global.LGraph = LiteGraph.LGraph = function LGraph()
{
if (LiteGraph.debug)
console.log("Graph created");
@@ -1283,7 +1288,7 @@ LGraph.prototype.onNodeTrace = function(node, msg, color)
* @param {String} name a name for the node
*/
function LGraphNode(title)
global.LGraphNode = LiteGraph.LGraphNode = function LGraphNode(title)
{
this._ctor();
}
@@ -1414,8 +1419,8 @@ LGraphNode.prototype.configure = function(info)
}
}
if( this.onConfigured )
this.onConfigured( info );
if( this.onConfigure )
this.onConfigure( info );
}
/**
@@ -2485,7 +2490,7 @@ LGraphNode.prototype.localToScreen = function(x,y, graphcanvas)
* @param {LGraph} graph [optional]
* @param {Object} options [optional] { skip_rendering, autoresize }
*/
function LGraphCanvas( canvas, graph, options )
global.LGraphCanvas = LiteGraph.LGraphCanvas = function LGraphCanvas( canvas, graph, options )
{
options = options || {};
@@ -5319,6 +5324,7 @@ LGraphCanvas.prototype.processContextMenu = function(node, event)
//API *************************************************
//function roundRect(ctx, x, y, width, height, radius, radius_low) {
if(this.CanvasRenderingContext2D)
CanvasRenderingContext2D.prototype.roundRect = function (x, y, width, height, radius, radius_low) {
if ( radius === undefined ) {
radius = 5;
@@ -5347,27 +5353,31 @@ function compareObjects(a,b)
return false;
return true;
}
LiteGraph.compareObjects = compareObjects;
function distance(a,b)
{
return Math.sqrt( (b[0] - a[0]) * (b[0] - a[0]) + (b[1] - a[1]) * (b[1] - a[1]) );
}
LiteGraph.distance = distance;
function colorToString(c)
{
return "rgba(" + Math.round(c[0] * 255).toFixed() + "," + Math.round(c[1] * 255).toFixed() + "," + Math.round(c[2] * 255).toFixed() + "," + (c.length == 4 ? c[3].toFixed(2) : "1.0") + ")";
}
LiteGraph.colorToString = colorToString;
function isInsideRectangle(x,y, left, top, width, height)
function isInsideRectangle( x,y, left, top, width, height)
{
if (left < x && (left + width) > x &&
top < y && (top + height) > y)
return true;
return false;
}
LiteGraph.isInsideRectangle = isInsideRectangle;
//[minx,miny,maxx,maxy]
function growBounding(bounding, x,y)
function growBounding( bounding, x,y)
{
if(x < bounding[0])
bounding[0] = x;
@@ -5379,6 +5389,7 @@ function growBounding(bounding, x,y)
else if(y > bounding[3])
bounding[3] = y;
}
LiteGraph.growBounding = growBounding;
//point inside boundin box
function isInsideBounding(p,bb)
@@ -5390,6 +5401,7 @@ function isInsideBounding(p,bb)
return false;
return true;
}
LiteGraph.isInsideBounding = isInsideBounding;
//boundings overlap, format: [start,end]
function overlapBounding(a,b)
@@ -5401,6 +5413,7 @@ function overlapBounding(a,b)
return false;
return true;
}
LiteGraph.overlapBounding = overlapBounding;
//Convert a hex value to its decimal value - the inputted hex must be in the
// format of a hex triplet - the kind we use for HTML colours. The function
@@ -5420,6 +5433,9 @@ function hex2num(hex) {
}
return(value);
}
LiteGraph.hex2num = hex2num;
//Give a array with three values as the argument and the function will return
// the corresponding hex triplet.
function num2hex(triplet) {
@@ -5435,6 +5451,8 @@ function num2hex(triplet) {
return(hex);
}
LiteGraph.num2hex = num2hex;
/* LiteGraph GUI elements *************************************/
LiteGraph.createContextMenu = function(values, options, ref_window)
@@ -5664,7 +5682,7 @@ LiteGraph.createNodetypeWrapper = function( class_object )
//LiteGraph.registerNodeType("scene/global", LGraphGlobal );
*/
if( !window["requestAnimationFrame"] )
if(typeof(window) !== undefined && !window["requestAnimationFrame"] )
{
window.requestAnimationFrame = window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
@@ -5673,4 +5691,4 @@ if( !window["requestAnimationFrame"] )
});
}
})(this);

View File

@@ -64,10 +64,7 @@ if(typeof(LiteGraph) != "undefined")
var tex = container[ name ];
if(!tex && name && name[0] != ":")
{
this.loadTexture(name);
return null;
}
return this.loadTexture(name);
return tex;
}
@@ -280,6 +277,12 @@ if(typeof(LiteGraph) != "undefined")
return tex_canvas;
}
LGraphTexture.prototype.getResources = function(res)
{
res[ this.properties.name ] = GL.Texture;
return res;
}
LGraphTexture.prototype.onGetInputs = function()
{
return [["in","Texture"]];

View File

@@ -154,7 +154,7 @@
{
this.setOutputData(0, this.properties["value"] );
this.boxcolor = colorToString([this.value,this.value,this.value]);
this.boxcolor = LiteGraph.colorToString([this.value,this.value,this.value]);
}
WidgetKnob.prototype.onMouseDown = function(e)
@@ -166,7 +166,7 @@
this.center = [this.size[0] * 0.5, this.size[1] * 0.5 + 20];
this.radius = this.size[0] * 0.5;
if(e.canvasY - this.pos[1] < 20 || distance([e.canvasX,e.canvasY],[this.pos[0] + this.center[0],this.pos[1] + this.center[1]]) > this.radius)
if(e.canvasY - this.pos[1] < 20 || LiteGraph.distance([e.canvasX,e.canvasY],[this.pos[0] + this.center[0],this.pos[1] + this.center[1]]) > this.radius)
return false;
this.oldmouse = [ e.canvasX - this.pos[0], e.canvasY - this.pos[1] ];
@@ -309,7 +309,7 @@
{
this.properties["value"] = this.properties["min"] + (this.properties["max"] - this.properties["min"]) * this.value;
this.setOutputData(0, this.properties["value"] );
this.boxcolor = colorToString([this.value,this.value,this.value]);
this.boxcolor = LiteGraph.colorToString([this.value,this.value,this.value]);
}
WidgetHSlider.prototype.onMouseDown = function(e)