added timeout to context menu so it takes 500 ms to close when the mouse is out

This commit is contained in:
tamat
2018-12-17 17:24:50 +01:00
parent f22f2c965e
commit 6c810d3ca8
3 changed files with 224 additions and 206 deletions

View File

@@ -7853,7 +7853,15 @@ function ContextMenu( values, options )
root.addEventListener("mouseleave", function(e) {
if(that.lock)
return;
that.close(e);
if(root.closing_timer)
clearTimeout( root.closing_timer );
root.closing_timer = setTimeout( that.close.bind(that), 500 );
//that.close(e);
});
root.addEventListener("mouseenter", function(e) {
if(root.closing_timer)
clearTimeout( root.closing_timer );
});
//insert before checking position
@@ -7949,6 +7957,7 @@ ContextMenu.prototype.addItem = function( name, value, options )
var value = this.value;
if(!value || !value.has_submenu)
return;
//if it is a submenu, autoopen like the item was clicked
inner_onclick.call(this,e);
}

408
build/litegraph.min.js vendored
View File

@@ -5,207 +5,207 @@ a&&a.constructor===String&&(a=document.querySelector(a));this.max_zoom=10;this.m
a[1]))}function r(a,b,e,c,f,n){return e<a&&e+f>a&&c<b&&c+n>b?!0:!1}function s(a,b){var e=a[0]+a[2],c=a[1]+a[3],f=b[1]+b[3];return a[0]>b[0]+b[2]||a[1]>f||e<b[0]||c<b[1]?!1:!0}function t(a,b){function e(a){var b=parseInt(f.style.top);f.style.top=(b+0.1*a.deltaY).toFixed()+"px";a.preventDefault();return!0}this.options=b=b||{};var c=this;b.parentMenu&&(b.parentMenu.constructor!==this.constructor?(console.error("parentMenu must be of class ContextMenu, ignoring it"),b.parentMenu=null):(this.parentMenu=
b.parentMenu,this.parentMenu.lock=!0,this.parentMenu.current_submenu=this));b.event&&b.event.constructor!==MouseEvent&&b.event.constructor!==CustomEvent&&(console.error("Event passed to ContextMenu is not of type MouseEvent or CustomEvent. Ignoring it."),b.event=null);var f=document.createElement("div");f.className="litegraph litecontextmenu litemenubar-panel";b.className&&(f.className+=" "+b.className);f.style.minWidth=100;f.style.minHeight=100;f.style.pointerEvents="none";setTimeout(function(){f.style.pointerEvents=
"auto"},100);f.addEventListener("mouseup",function(a){a.preventDefault();return!0},!0);f.addEventListener("contextmenu",function(a){if(2!=a.button)return!1;a.preventDefault();return!1},!0);f.addEventListener("mousedown",function(a){if(2==a.button)return c.close(),a.preventDefault(),!0},!0);f.addEventListener("wheel",e,!0);f.addEventListener("mousewheel",e,!0);this.root=f;if(b.title){var n=document.createElement("div");n.className="litemenu-title";n.innerHTML=b.title;f.appendChild(n)}var n=0,l;for(l in a){var k=
a.constructor==Array?a[l]:l;null!=k&&k.constructor!==String&&(k=void 0===k.content?String(k):k.content);this.addItem(k,a[l],b);n++}f.addEventListener("mouseleave",function(a){c.lock||c.close(a)});l=document;b.event&&(l=b.event.target.ownerDocument);l||(l=document);l.body.appendChild(f);n=b.left||0;l=b.top||0;if(b.event){n=b.event.pageX-10;l=b.event.pageY-10;b.title&&(l-=20);b.parentMenu&&(n=b.parentMenu.root.getBoundingClientRect(),n=n.left+n.width);var k=document.body.getBoundingClientRect(),g=f.getBoundingClientRect();
n>k.width-g.width-10&&(n=k.width-g.width-10);l>k.height-g.height-10&&(l=k.height-g.height-10)}f.style.left=n+"px";f.style.top=l+"px"}var k=u.LiteGraph={CANVAS_GRID_SIZE:10,NODE_TITLE_HEIGHT:20,NODE_SLOT_HEIGHT:15,NODE_WIDGET_HEIGHT:20,NODE_WIDTH:140,NODE_MIN_WIDTH:50,NODE_COLLAPSED_RADIUS:10,NODE_COLLAPSED_WIDTH:80,NODE_TITLE_COLOR:"#999",NODE_TEXT_SIZE:14,NODE_TEXT_COLOR:"#AAA",NODE_SUBTEXT_SIZE:12,NODE_DEFAULT_COLOR:"#333",NODE_DEFAULT_BGCOLOR:"#444",NODE_DEFAULT_BOXCOLOR:"#666",NODE_DEFAULT_SHAPE:"box",
DEFAULT_SHADOW_COLOR:"rgba(0,0,0,0.5)",DEFAULT_GROUP_FONT:24,LINK_COLOR:"#AAD",EVENT_LINK_COLOR:"#F85",CONNECTING_LINK_COLOR:"#AFA",MAX_NUMBER_OF_NODES:1E3,DEFAULT_POSITION:[100,100],VALID_SHAPES:["default","box","round","card"],BOX_SHAPE:1,ROUND_SHAPE:2,CIRCLE_SHAPE:3,CARD_SHAPE:4,ARROW_SHAPE:5,INPUT:1,OUTPUT:2,EVENT:-1,ACTION:-1,ALWAYS:0,ON_EVENT:1,NEVER:2,ON_TRIGGER:3,UP:1,DOWN:2,LEFT:3,RIGHT:4,CENTER:5,NORMAL_TITLE:0,NO_TITLE:1,TRANSPARENT_TITLE:2,AUTOHIDE_TITLE:3,proxy:null,node_images_path:"",
debug:!1,throw_errors:!0,allow_scripts:!1,registered_node_types:{},node_types_by_file_extension:{},Nodes:{},searchbox_extras:{},registerNodeType:function(a,b){if(!b.prototype)throw"Cannot register a simple object, it must be a class with a prototype";b.type=a;k.debug&&console.log("Node registered: "+a);a.split("/");var e=b.name,c=a.lastIndexOf("/");b.category=a.substr(0,c);b.title||(b.title=e);if(b.prototype)for(var f in d.prototype)b.prototype[f]||(b.prototype[f]=d.prototype[f]);Object.defineProperty(b.prototype,
"shape",{set:function(a){switch(a){case "default":delete this._shape;break;case "box":this._shape=k.BOX_SHAPE;break;case "round":this._shape=k.ROUND_SHAPE;break;case "circle":this._shape=k.CIRCLE_SHAPE;break;case "card":this._shape=k.CARD_SHAPE;break;default:this._shape=a}},get:function(a){return this._shape},enumerable:!0});this.registered_node_types[a]=b;b.constructor.name&&(this.Nodes[e]=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},wrapFunctionAsNode:function(a,b,e,c){for(var f=Array(b.length),n="",l=k.getParameterNames(b),w=0;w<l.length;++w)n+="this.addInput('"+l[w]+"',"+(e&&e[w]?"'"+e[w]+"'":"0")+");\n";e=Function(n+("this.addOutput('out',"+(c?"'"+c+"'":0)+");\n"));e.title=a.split("/").pop();e.desc="Generated from "+b.name;e.prototype.onExecute=function(){for(var a=0;a<f.length;++a)f[a]=this.getInputData(a);
a=b.apply(this,f);this.setOutputData(0,a)};this.registerNodeType(a,e)},addNodeMethod:function(a,b){d.prototype[a]=b;for(var e in this.registered_node_types){var c=this.registered_node_types[e];c.prototype[a]&&(c.prototype["_"+a]=c.prototype[a]);c.prototype[a]=b}},createNode:function(a,b,e){var c=this.registered_node_types[a];if(!c)return k.debug&&console.log('GraphNode type "'+a+'" not registered.'),null;b=b||c.title||a;c=new c(b);c.type=a;!c.title&&b&&(c.title=b);c.properties||(c.properties={});
c.properties_info||(c.properties_info=[]);c.flags||(c.flags={});c.size||(c.size=c.computeSize());c.pos||(c.pos=k.DEFAULT_POSITION.concat());c.mode||(c.mode=k.ALWAYS);if(e)for(var f in e)c[f]=e[f];return c},getNodeType:function(a){return this.registered_node_types[a]},getNodeTypesInCategory:function(a,b){var e=[],c;for(c in this.registered_node_types){var f=this.registered_node_types[c];b&&f.filter&&f.filter!=b||(""==a?null==f.category&&e.push(f):f.category==a&&e.push(f))}return e},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 e=[];for(b in a)e.push(b);return e},reloadNodes:function(a){var b=document.getElementsByTagName("script"),e=[],c;for(c in b)e.push(b[c]);b=document.getElementsByTagName("head")[0];a=document.location.href+a;for(c in e){var f=e[c].src;if(f&&f.substr(0,a.length)==a)try{k.debug&&console.log("Reloading: "+f);var n=document.createElement("script");
n.type="text/javascript";n.src=f;b.appendChild(n);b.removeChild(e[c])}catch(l){if(k.throw_errors)throw l;k.debug&&console.log("Error while reloading "+f)}}k.debug&&console.log("Nodes reloaded")},cloneObject:function(a,b){if(null==a)return null;var e=JSON.parse(JSON.stringify(a));if(!b)return e;for(var c in e)b[c]=e[c];return b},isValidConnection:function(a,b){if(!a||!b||a==b||a==k.EVENT&&b==k.ACTION)return!0;a=String(a);b=String(b);a=a.toLowerCase();b=b.toLowerCase();if(-1==a.indexOf(",")&&-1==b.indexOf(","))return a==
b;for(var e=a.split(","),c=b.split(","),f=0;f<e.length;++f)for(var n=0;n<c.length;++n)if(e[f]==c[n])return!0;return!1},registerSearchboxExtra:function(a,b,e){this.searchbox_extras[b]={type:a,desc:b,data:e}}};k.getTime="undefined"!=typeof performance?performance.now.bind(performance):"undefined"!=typeof Date&&Date.now?Date.now.bind(Date):"undefined"!=typeof process?function(){var a=process.hrtime();return 0.001*a[0]+1E-6*a[1]}:function(){return(new Date).getTime()};u.LGraph=k.LGraph=h;h.supported_types=
["number","string","boolean"];h.prototype.getSupportedTypes=function(){return this.supported_types||h.supported_types};h.STATUS_STOPPED=1;h.STATUS_RUNNING=2;h.prototype.clear=function(){this.stop();this.status=h.STATUS_STOPPED;this.last_link_id=this.last_node_id=1;this._version=-1;if(this._nodes)for(var a=0;a<this._nodes.length;++a){var b=this._nodes[a];if(b.onRemoved)b.onRemoved()}this._nodes=[];this._nodes_by_id={};this._nodes_in_order=[];this._nodes_executable=null;this._groups=[];this.links={};
this.iteration=0;this.config={};this.fixedtime=this.runningtime=this.globaltime=0;this.elapsed_time=this.fixedtime_lapse=0.01;this.starttime=this.last_update_time=0;this.catch_errors=!0;this.global_inputs={};this.global_outputs={};this.change();this.sendActionToCanvas("clear")};h.prototype.attachCanvas=function(a){if(a.constructor!=g)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)};h.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))}};h.prototype.start=function(a){if(this.status!=h.STATUS_RUNNING){this.status=h.STATUS_RUNNING;if(this.onPlayEvent)this.onPlayEvent();this.sendEventToAllNodes("onStart");this.last_update_time=this.starttime=k.getTime();a=a||0;var b=this;if(0==a&&"undefined"!=typeof window&&window.requestAnimationFrame){var e=
function(){-1==b.execution_timer_id&&(window.requestAnimationFrame(e),b.runStep(1,!this.catch_errors))};this.execution_timer_id=-1;e()}else this.execution_timer_id=setInterval(function(){b.runStep(1,!this.catch_errors)},a)}};h.prototype.stop=function(){if(this.status!=h.STATUS_STOPPED){this.status=h.STATUS_STOPPED;if(this.onStopEvent)this.onStopEvent();null!=this.execution_timer_id&&(-1!=this.execution_timer_id&&clearInterval(this.execution_timer_id),this.execution_timer_id=null);this.sendEventToAllNodes("onStop")}};
h.prototype.runStep=function(a,b){a=a||1;var e=k.getTime();this.globaltime=0.001*(e-this.starttime);var c=this._nodes_executable?this._nodes_executable:this._nodes;if(c){if(b){for(var f=0;f<a;f++){for(var n=0,l=c.length;n<l;++n){var w=c[n];if(w.mode==k.ALWAYS&&w.onExecute)w.onExecute()}this.fixedtime+=this.fixedtime_lapse;if(this.onExecuteStep)this.onExecuteStep()}if(this.onAfterExecute)this.onAfterExecute()}else try{for(f=0;f<a;f++){n=0;for(l=c.length;n<l;++n)if(w=c[n],w.mode==k.ALWAYS&&w.onExecute)w.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(k.throw_errors)throw g;k.debug&&console.log("Error during execution: "+g);this.stop()}c=k.getTime();e=c-e;0==e&&(e=1);this.execution_time=0.001*e;this.globaltime+=0.001*e;this.iteration+=1;this.elapsed_time=0.001*(c-this.last_update_time);this.last_update_time=c}};h.prototype.updateExecutionOrder=function(){this._nodes_in_order=
this.computeExecutionOrder(!1);this._nodes_executable=[];for(var a=0;a<this._nodes_in_order.length;++a)this._nodes_in_order[a].onExecute&&this._nodes_executable.push(this._nodes_in_order[a])};h.prototype.computeExecutionOrder=function(a,b){for(var e=[],c=[],f={},n={},l={},g=0,m=this._nodes.length;g<m;++g){var d=this._nodes[g];if(!a||d.onExecute){f[d.id]=d;var h=0;if(d.inputs)for(var p=0,q=d.inputs.length;p<q;p++)d.inputs[p]&&null!=d.inputs[p].link&&(h+=1);0==h?(c.push(d),b&&(d._level=1)):(b&&(d._level=
0),l[d.id]=h)}}for(;0!=c.length;)if(d=c.shift(),e.push(d),delete f[d.id],d.outputs)for(g=0;g<d.outputs.length;g++)if(m=d.outputs[g],null!=m&&null!=m.links&&0!=m.links.length)for(p=0;p<m.links.length;p++)(h=this.links[m.links[p]])&&!n[h.id]&&(q=this.getNodeById(h.target_id),null==q?n[h.id]=!0:(b&&(!q._level||q._level<=d._level)&&(q._level=d._level+1),n[h.id]=!0,l[q.id]-=1,0==l[q.id]&&c.push(q)));for(g in f)e.push(f[g]);e.length!=this._nodes.length&&k.debug&&console.warn("something went wrong, nodes missing");
m=e.length;for(g=0;g<m;++g)e[g].order=g;e=e.sort(function(a,b){var e=a.constructor.priority||a.priority||0,c=b.constructor.priority||b.priority||0;return e==c?a.order-b.order:e-c});for(g=0;g<m;++g)e[g].order=g;return e};h.prototype.getAncestors=function(a){for(var b=[],e=[a],c={};e.length;){var f=e.shift();if(f.inputs){c[f.id]||f==a||(c[f.id]=!0,b.push(f));for(var n=0;n<f.inputs.length;++n){var l=f.getInputNode(n);l&&-1==b.indexOf(l)&&e.push(l)}}}b.sort(function(a,b){return a.order-b.order});return b};
h.prototype.arrange=function(a){a=a||40;for(var b=this.computeExecutionOrder(!1,!0),e=[],c=0;c<b.length;++c){var f=b[c],n=f._level||1;e[n]||(e[n]=[]);e[n].push(f)}b=a;for(c=0;c<e.length;++c)if(n=e[c]){for(var l=100,k=a,g=0;g<n.length;++g)f=n[g],f.pos[0]=b,f.pos[1]=k,f.size[0]>l&&(l=f.size[0]),k+=f.size[1]+a;b+=l+a}this.setDirtyCanvas(!0,!0)};h.prototype.getTime=function(){return this.globaltime};h.prototype.getFixedTime=function(){return this.fixedtime};h.prototype.getElapsedTime=function(){return this.elapsed_time};
h.prototype.sendEventToAllNodes=function(a,b,e){e=e||k.ALWAYS;var c=this._nodes_in_order?this._nodes_in_order:this._nodes;if(c)for(var f=0,n=c.length;f<n;++f){var l=c[f];if(l[a]&&l.mode==e)if(void 0===b)l[a]();else if(b&&b.constructor===Array)l[a].apply(l,b);else l[a](b)}};h.prototype.sendActionToCanvas=function(a,b){if(this.list_of_graphcanvas)for(var e=0;e<this.list_of_graphcanvas.length;++e){var c=this.list_of_graphcanvas[e];c[a]&&c[a].apply(c,b)}};h.prototype.add=function(a,b){if(a)if(a.constructor===
p)this._groups.push(a),this.setDirtyCanvas(!0),this.change(),a.graph=this,this._version++;else{-1!=a.id&&null!=this._nodes_by_id[a.id]&&(console.warn("LiteGraph: there is already a node with this ID, changing it"),a.id=++this.last_node_id);if(this._nodes.length>=k.MAX_NUMBER_OF_NODES)throw"LiteGraph: max number of nodes in a graph reached";null==a.id||-1==a.id?a.id=++this.last_node_id:this.last_node_id<a.id&&(this.last_node_id=a.id);a.graph=this;this._version++;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}};h.prototype.remove=function(a){if(a.constructor===k.LGraphGroup){var b=this._groups.indexOf(a);-1!=b&&this._groups.splice(b,1);a.graph=null;this._version++;this.setDirtyCanvas(!0,!0);this.change()}else if(null!=this._nodes_by_id[a.id]&&!a.ignore_remove){if(a.inputs)for(b=0;b<a.inputs.length;b++){var e=a.inputs[b];
null!=e.link&&a.disconnectInput(b)}if(a.outputs)for(b=0;b<a.outputs.length;b++)e=a.outputs[b],null!=e.links&&e.links.length&&a.disconnectOutput(b);if(a.onRemoved)a.onRemoved();a.graph=null;this._version++;if(this.list_of_graphcanvas)for(b=0;b<this.list_of_graphcanvas.length;++b)e=this.list_of_graphcanvas[b],e.selected_nodes[a.id]&&delete e.selected_nodes[a.id],e.node_dragged==a&&(e.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()}};h.prototype.getNodeById=function(a){return null==a?null:this._nodes_by_id[a]};h.prototype.findNodesByClass=function(a){for(var b=[],e=0,c=this._nodes.length;e<c;++e)this._nodes[e].constructor===a&&b.push(this._nodes[e]);return b};h.prototype.findNodesByType=function(a){a=a.toLowerCase();for(var b=[],e=0,c=this._nodes.length;e<c;++e)this._nodes[e].type.toLowerCase()==a&&b.push(this._nodes[e]);return b};h.prototype.findNodesByTitle=
function(a){for(var b=[],e=0,c=this._nodes.length;e<c;++e)this._nodes[e].title==a&&b.push(this._nodes[e]);return b};h.prototype.getNodeOnPos=function(a,b,e,c){e=e||this._nodes;for(var f=e.length-1;0<=f;f--){var n=e[f];if(n.isPointInside(a,b,c))return n}return null};h.prototype.getGroupOnPos=function(a,b){for(var e=this._groups.length-1;0<=e;e--){var c=this._groups[e];if(c.isPointInside(a,b,2,!0))return c}return null};h.prototype.addGlobalInput=function(a,b,e){this.global_inputs[a]={name:a,type:b,
value:e};this._version++;if(this.onGlobalInputAdded)this.onGlobalInputAdded(a,b);if(this.onGlobalsChange)this.onGlobalsChange()};h.prototype.setGlobalInputData=function(a,b){var e=this.global_inputs[a];e&&(e.value=b)};h.prototype.setInputData=h.prototype.setGlobalInputData;h.prototype.getGlobalInputData=function(a){return(a=this.global_inputs[a])?a.value:null};h.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];this._version++;if(this.onGlobalInputRenamed)this.onGlobalInputRenamed(a,b);if(this.onGlobalsChange)this.onGlobalsChange()}};h.prototype.changeGlobalInputType=function(a,b){if(!this.global_inputs[a])return!1;if(!this.global_inputs[a].type||this.global_inputs[a].type.toLowerCase()!=b.toLowerCase())if(this.global_inputs[a].type=b,this._version++,this.onGlobalInputTypeChanged)this.onGlobalInputTypeChanged(a,b)};h.prototype.removeGlobalInput=
function(a){if(!this.global_inputs[a])return!1;delete this.global_inputs[a];this._version++;if(this.onGlobalInputRemoved)this.onGlobalInputRemoved(a);if(this.onGlobalsChange)this.onGlobalsChange();return!0};h.prototype.addGlobalOutput=function(a,b,e){this.global_outputs[a]={name:a,type:b,value:e};this._version++;if(this.onGlobalOutputAdded)this.onGlobalOutputAdded(a,b);if(this.onGlobalsChange)this.onGlobalsChange()};h.prototype.setGlobalOutputData=function(a,b){var e=this.global_outputs[a];e&&(e.value=
b)};h.prototype.getGlobalOutputData=function(a){return(a=this.global_outputs[a])?a.value:null};h.prototype.getOutputData=h.prototype.getGlobalOutputData;h.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];this._version++;if(this.onGlobalOutputRenamed)this.onGlobalOutputRenamed(a,b);if(this.onGlobalsChange)this.onGlobalsChange()};
h.prototype.changeGlobalOutputType=function(a,b){if(!this.global_outputs[a])return!1;if(!this.global_outputs[a].type||this.global_outputs[a].type.toLowerCase()!=b.toLowerCase())if(this.global_outputs[a].type=b,this._version++,this.onGlobalOutputTypeChanged)this.onGlobalOutputTypeChanged(a,b)};h.prototype.removeGlobalOutput=function(a){if(!this.global_outputs[a])return!1;delete this.global_outputs[a];this._version++;if(this.onGlobalOutputRemoved)this.onGlobalOutputRemoved(a);if(this.onGlobalsChange)this.onGlobalsChange();
return!0};h.prototype.triggerInput=function(a,b){for(var e=this.findNodesByTitle(a),c=0;c<e.length;++c)e[c].onTrigger(b)};h.prototype.setCallback=function(a,b){for(var e=this.findNodesByTitle(a),c=0;c<e.length;++c)e[c].setTrigger(b)};h.prototype.connectionChange=function(a){this.updateExecutionOrder();if(this.onConnectionChange)this.onConnectionChange(a);this._version++;this.sendActionToCanvas("onConnectionChange")};h.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};h.prototype.change=function(){k.debug&&console.log("Graph changed");this.sendActionToCanvas("setDirty",[!0,!0]);if(this.on_change)this.on_change(this)};h.prototype.setDirtyCanvas=function(a,b){this.sendActionToCanvas("setDirty",[a,b])};h.prototype.serialize=function(){for(var a=[],b=0,e=this._nodes.length;b<e;++b)a.push(this._nodes[b].serialize());e=[];for(b in this.links){var c=this.links[b];e.push([c.id,
c.origin_id,c.origin_slot,c.target_id,c.target_slot,c.type])}c=[];for(b=0;b<this._groups.length;++b)c.push(this._groups[b].serialize());return{last_node_id:this.last_node_id,last_link_id:this.last_link_id,nodes:a,links:e,groups:c,config:this.config}};h.prototype.configure=function(a,b){if(a){b||this.clear();var e=a.nodes;if(a.links&&a.links.constructor===Array){for(var c=[],f=0;f<a.links.length;++f){var n=a.links[f];c[n[0]]={id:n[0],origin_id:n[1],origin_slot:n[2],target_id:n[3],target_slot:n[4],
type:n[5]}}a.links=c}for(f in a)this[f]=a[f];c=!1;this._nodes=[];if(e){f=0;for(n=e.length;f<n;++f){var l=e[f],g=k.createNode(l.type,l.title);g?(g.id=l.id,this.add(g,!0)):(k.debug&&console.log("Node not found: "+l.type),c=!0)}f=0;for(n=e.length;f<n;++f)l=e[f],(g=this.getNodeById(l.id))&&g.configure(l)}this._groups.length=0;if(a.groups)for(f=0;f<a.groups.length;++f)e=new k.LGraphGroup,e.configure(a.groups[f]),this.add(e);this.updateExecutionOrder();this._version++;this.setDirtyCanvas(!0,!0);return c}};
h.prototype.load=function(a){var b=this,e=new XMLHttpRequest;e.open("GET",a,!0);e.send(null);e.onload=function(a){200!==e.status?console.error("Error loading graph:",e.status,e.response):(a=JSON.parse(e.response),b.configure(a))};e.onerror=function(a){console.error("Error loading graph:",a)}};h.prototype.onNodeTrace=function(a,b,e){};u.LGraphNode=k.LGraphNode=d;d.prototype._ctor=function(a){this.title=a||"Unnamed";this.size=[k.NODE_WIDTH,60];this.graph=null;this._pos=new Float32Array(10,10);Object.defineProperty(this,
"pos",{set:function(a){!a||2>a.length||(this._pos[0]=a[0],this._pos[1]=a[1])},get:function(){return this._pos},enumerable:!0});this.id=-1;this.type=null;this.inputs=[];this.outputs=[];this.connections=[];this.properties={};this.properties_info=[];this.flags={}};d.prototype.configure=function(a){this.graph&&this.graph._version++;for(var b in a)if("console"!=b)if("properties"==b)for(var e in a.properties){if(this.properties[e]=a.properties[e],this.onPropertyChanged)this.onPropertyChanged(e,a.properties[e])}else null!=
a[b]&&("object"==typeof a[b]?this[b]&&this[b].configure?this[b].configure(a[b]):this[b]=k.cloneObject(a[b],this[b]):this[b]=a[b]);a.title||(this.title=this.constructor.title);if(this.onConnectionsChange){if(this.inputs)for(var c=0;c<this.inputs.length;++c){e=this.inputs[c];var f=this.graph?this.graph.links[e.link]:null;this.onConnectionsChange(k.INPUT,c,!0,f,e)}if(this.outputs)for(c=0;c<this.outputs.length;++c)if(e=this.outputs[c],e.links)for(b=0;b<e.links.length;++b)f=this.graph?this.graph.links[e.links[b]]:
null,this.onConnectionsChange(k.OUTPUT,c,!0,f,e)}for(c in this.inputs)e=this.inputs[c],e.link&&e.link.length&&(f=e.link,"object"==typeof f&&(e.link=f[0],this.graph&&(this.graph.links[f[0]]={id:f[0],origin_id:f[1],origin_slot:f[2],target_id:f[3],target_slot:f[4]})));for(c in this.outputs)if(e=this.outputs[c],e.links&&0!=e.links.length)for(b in e.links)f=e.links[b],"object"==typeof f&&(e.links[b]=f[0]);if(this.onConfigure)this.onConfigure(a)};d.prototype.serialize=function(){var a={id:this.id,type:this.type,
pos:this.pos,size:this.size,flags:k.cloneObject(this.flags),mode:this.mode};this.inputs&&(a.inputs=this.inputs);if(this.outputs){for(var b=0;b<this.outputs.length;b++)delete this.outputs[b]._data;a.outputs=this.outputs}this.title&&this.title!=this.constructor.title&&(a.title=this.title);this.properties&&(a.properties=k.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);this.onSerialize&&this.onSerialize(a)&&console.warn("node onSerialize shouldnt return anything, data should be stored in the object pass in the first parameter");return a};d.prototype.clone=function(){var a=k.createNode(this.type),b=k.cloneObject(this.serialize());if(b.inputs)for(var e=0;e<b.inputs.length;++e)b.inputs[e].link=null;if(b.outputs)for(e=0;e<b.outputs.length;++e)b.outputs[e].links&&(b.outputs[e].links.length=0);delete b.id;a.configure(b);return a};d.prototype.toString=
function(){return JSON.stringify(this.serialize())};d.prototype.getTitle=function(){return this.title||this.constructor.title};d.prototype.setOutputData=function(a,b){if(this.outputs&&!(-1==a||a>=this.outputs.length)){var e=this.outputs[a];if(e&&(e._data=b,this.outputs[a].links))for(e=0;e<this.outputs[a].links.length;e++)this.graph.links[this.outputs[a].links[e]].data=b}};d.prototype.getInputData=function(a,b){if(this.inputs&&!(a>=this.inputs.length||null==this.inputs[a].link)){var e=this.graph.links[this.inputs[a].link];
if(!e)return null;if(!b)return e.data;var c=this.graph.getNodeById(e.origin_id);if(!c)return e.data;if(c.updateOutputData)c.updateOutputData(e.origin_slot);else if(c.onExecute)c.onExecute();return e.data}};d.prototype.getInputDataByName=function(a,b){var e=this.findInputSlot(a);return-1==e?null:this.getInputData(e,b)};d.prototype.isInputConnected=function(a){return this.inputs?a<this.inputs.length&&null!=this.inputs[a].link:!1};d.prototype.getInputInfo=function(a){return this.inputs?a<this.inputs.length?
this.inputs[a]:null:null};d.prototype.getInputNode=function(a){if(!this.inputs||a>=this.inputs.length)return null;a=this.inputs[a];return a&&null!==a.link?(a=this.graph.links[a.link])?this.graph.getNodeById(a.origin_id):null:null};d.prototype.getInputOrProperty=function(a){if(!this.inputs||!this.inputs.length)return this.properties?this.properties[a]:null;for(var b=0,e=this.inputs.length;b<e;++b)if(a==this.inputs[b].name)return(a=this.graph.links[this.inputs[b].link])?a.data:null;return this.properties[a]};
d.prototype.getOutputData=function(a){return!this.outputs||a>=this.outputs.length?null:this.outputs[a]._data};d.prototype.getOutputInfo=function(a){return this.outputs?a<this.outputs.length?this.outputs[a]:null:null};d.prototype.isOutputConnected=function(a){return this.outputs?a<this.outputs.length&&this.outputs[a].links&&this.outputs[a].links.length:!1};d.prototype.isAnyOutputConnected=function(){if(!this.outputs)return!1;for(var a=0;a<this.outputs.length;++a)if(this.outputs[a].links&&this.outputs[a].links.length)return!0;
return!1};d.prototype.getOutputNodes=function(a){if(!this.outputs||0==this.outputs.length||a>=this.outputs.length)return null;a=this.outputs[a];if(!a.links||0==a.links.length)return null;for(var b=[],e=0;e<a.links.length;e++){var c=this.graph.links[a.links[e]];c&&(c=this.graph.getNodeById(c.target_id))&&b.push(c)}return b};d.prototype.trigger=function(a,b){if(this.outputs&&this.outputs.length){this.graph&&(this.graph._last_trigger_time=k.getTime());for(var e=0;e<this.outputs.length;++e){var c=this.outputs[e];
!c||c.type!==k.EVENT||a&&c.name!=a||this.triggerSlot(e,b)}}};d.prototype.triggerSlot=function(a,b,e){if(this.outputs&&(a=this.outputs[a])&&(a=a.links)&&a.length){this.graph&&(this.graph._last_trigger_time=k.getTime());for(var c=0;c<a.length;++c){var f=a[c];if(null==e||e==f){var n=this.graph.links[a[c]];if(n&&(n._last_time=k.getTime(),f=this.graph.getNodeById(n.target_id)))if(n=f.inputs[n.target_slot],f.onAction)f.onAction(n.name,b);else if(f.mode===k.ON_TRIGGER&&f.onExecute)f.onExecute(b)}}}};d.prototype.addProperty=
function(a,b,e,c){e={name:a,type:e,default_value:b};if(c)for(var f in c)e[f]=c[f];this.properties_info||(this.properties_info=[]);this.properties_info.push(e);this.properties||(this.properties={});this.properties[a]=b;return e};d.prototype.addOutput=function(a,b,e){a={name:a,type:b,links:null};if(e)for(var c in e)a[c]=e[c];this.outputs||(this.outputs=[]);this.outputs.push(a);if(this.onOutputAdded)this.onOutputAdded(a);this.size=this.computeSize();this.setDirtyCanvas(!0,!0);return a};d.prototype.addOutputs=
function(a){for(var b=0;b<a.length;++b){var e=a[b],c={name:e[0],type:e[1],link:null};if(a[2])for(var f in e[2])c[f]=e[2][f];this.outputs||(this.outputs=[]);this.outputs.push(c);if(this.onOutputAdded)this.onOutputAdded(c)}this.size=this.computeSize();this.setDirtyCanvas(!0,!0)};d.prototype.removeOutput=function(a){this.disconnectOutput(a);this.outputs.splice(a,1);for(var b=a;b<this.outputs.length;++b)if(this.outputs[b]&&this.outputs[b].links)for(var e=this.outputs[b].links,c=0;c<e.length;++c){var f=
this.graph.links[e[c]];f&&(f.origin_slot-=1)}this.size=this.computeSize();if(this.onOutputRemoved)this.onOutputRemoved(a);this.setDirtyCanvas(!0,!0)};d.prototype.addInput=function(a,b,e){a={name:a,type:b||0,link:null};if(e)for(var c in e)a[c]=e[c];this.inputs||(this.inputs=[]);this.inputs.push(a);this.size=this.computeSize();if(this.onInputAdded)this.onInputAdded(a);this.setDirtyCanvas(!0,!0);return a};d.prototype.addInputs=function(a){for(var b=0;b<a.length;++b){var e=a[b],c={name:e[0],type:e[1],
link:null};if(a[2])for(var f in e[2])c[f]=e[2][f];this.inputs||(this.inputs=[]);this.inputs.push(c);if(this.onInputAdded)this.onInputAdded(c)}this.size=this.computeSize();this.setDirtyCanvas(!0,!0)};d.prototype.removeInput=function(a){this.disconnectInput(a);this.inputs.splice(a,1);for(var b=a;b<this.inputs.length;++b)if(this.inputs[b]){var e=this.graph.links[this.inputs[b].link];e&&(e.target_slot-=1)}this.size=this.computeSize();if(this.onInputRemoved)this.onInputRemoved(a);this.setDirtyCanvas(!0,
!0)};d.prototype.addConnection=function(a,b,e,c){a={name:a,type:b,pos:e,direction:c,links:null};this.connections.push(a);return a};d.prototype.computeSize=function(a,b){function e(a){return a?n*a.length*0.6:0}var c=Math.max(this.inputs?this.inputs.length:1,this.outputs?this.outputs.length:1),f=b||new Float32Array([0,0]),c=Math.max(c,1),n=k.NODE_TEXT_SIZE;f[1]=(this.constructor.slot_start_y||0)+c*(n+1)+4;this.widgets&&this.widgets.length&&(f[1]+=this.widgets.length*(k.NODE_WIDGET_HEIGHT+4)+8);var c=
e(this.title),l=0,g=0;if(this.inputs)for(var d=0,m=this.inputs.length;d<m;++d){var h=this.inputs[d],h=h.label||h.name||"",h=e(h);l<h&&(l=h)}if(this.outputs)for(d=0,m=this.outputs.length;d<m;++d)h=this.outputs[d],h=h.label||h.name||"",h=e(h),g<h&&(g=h);f[0]=Math.max(l+g+10,c);f[0]=Math.max(f[0],k.NODE_WIDTH);this.widgets&&this.widgets.length&&(f[0]=Math.max(f[0],1.5*k.NODE_WIDTH));if(this.onResize)this.onResize(f);return f};d.prototype.addWidget=function(a,b,e,c,f){this.widgets||(this.widgets=[]);
b={type:a.toLowerCase(),name:b,value:e,callback:c,options:f||{}};void 0!==b.options.y&&(b.y=b.options.y);c||console.warn("LiteGraph addWidget('button',...) without a callback");if("combo"==a&&!b.options.values)throw"LiteGraph addWidget('combo',...) requires to pass values in options: { values:['red','blue'] }";this.widgets.push(b);return b};d.prototype.getBounding=function(a){a=a||new Float32Array(4);a[0]=this.pos[0]-4;a[1]=this.pos[1]-k.NODE_TITLE_HEIGHT;a[2]=this.size[0]+4;a[3]=this.size[1]+k.NODE_TITLE_HEIGHT;
return a};d.prototype.isPointInside=function(a,b,e,c){e=e||0;var f=this.graph&&this.graph.isLive()?0:20;c&&(f=0);if(this.flags&&this.flags.collapsed){if(r(a,b,this.pos[0]-e,this.pos[1]-k.NODE_TITLE_HEIGHT-e,(this._collapsed_width||k.NODE_COLLAPSED_WIDTH)+2*e,k.NODE_TITLE_HEIGHT+2*e))return!0}else if(this.pos[0]-4-e<a&&this.pos[0]+this.size[0]+4+e>a&&this.pos[1]-f-e<b&&this.pos[1]+this.size[1]+e>b)return!0;return!1};d.prototype.getSlotInPosition=function(a,b){if(this.inputs)for(var e=0,c=this.inputs.length;e<
c;++e){var f=this.inputs[e],n=this.getConnectionPos(!0,e);if(r(a,b,n[0]-10,n[1]-5,20,10))return{input:f,slot:e,link_pos:n,locked:f.locked}}if(this.outputs)for(e=0,c=this.outputs.length;e<c;++e)if(f=this.outputs[e],n=this.getConnectionPos(!1,e),r(a,b,n[0]-10,n[1]-5,20,10))return{output:f,slot:e,link_pos:n,locked:f.locked};return null};d.prototype.findInputSlot=function(a){if(!this.inputs)return-1;for(var b=0,e=this.inputs.length;b<e;++b)if(a==this.inputs[b].name)return b;return-1};d.prototype.findOutputSlot=
function(a){if(!this.outputs)return-1;for(var b=0,e=this.outputs.length;b<e;++b)if(a==this.outputs[b].name)return b;return-1};d.prototype.connect=function(a,b,e){e=e||0;if(!this.graph)return console.log("Connect: Error, node doesnt belong to any graph. Nodes must be added first to a graph before connecting them."),!1;if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return k.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.outputs||a>=this.outputs.length)return k.debug&&
console.log("Connect: Error, slot number not found"),!1;b&&b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"target node is null";if(b==this)return!1;if(e.constructor===String){if(e=b.findInputSlot(e),-1==e)return k.debug&&console.log("Connect: Error, no slot of name "+e),!1}else{if(e===k.EVENT)return!1;if(!b.inputs||e>=b.inputs.length)return k.debug&&console.log("Connect: Error, slot number not found"),!1}null!=b.inputs[e].link&&b.disconnectInput(e);var c=this.outputs[a];if(b.onConnectInput&&
!1===b.onConnectInput(e,c.type,c))return!1;var f=b.inputs[e];if(k.isValidConnection(c.type,f.type)){var n={id:this.graph.last_link_id++,type:f.type,origin_id:this.id,origin_slot:a,target_id:b.id,target_slot:e};this.graph.links[n.id]=n;null==c.links&&(c.links=[]);c.links.push(n.id);b.inputs[e].link=n.id;this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(k.OUTPUT,a,!0,n,c);if(b.onConnectionsChange)b.onConnectionsChange(k.INPUT,e,!0,n,f);this.graph&&this.graph.onNodeConnectionChange&&
(this.graph.onNodeConnectionChange(k.INPUT,b,e,this,a),this.graph.onNodeConnectionChange(k.OUTPUT,this,a,b,e))}this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this);return!0};d.prototype.disconnectOutput=function(a,b){if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return k.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.outputs||a>=this.outputs.length)return k.debug&&console.log("Connect: Error, slot number not found"),!1;var e=this.outputs[a];if(!e||
!e.links||0==e.links.length)return!1;if(b){b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"Target Node not found";for(var c=0,f=e.links.length;c<f;c++){var n=e.links[c],l=this.graph.links[n];if(l.target_id==b.id){e.links.splice(c,1);var g=b.inputs[l.target_slot];g.link=null;delete this.graph.links[n];this.graph&&this.graph._version++;if(b.onConnectionsChange)b.onConnectionsChange(k.INPUT,l.target_slot,!1,l,g);if(this.onConnectionsChange)this.onConnectionsChange(k.OUTPUT,a,!1,l,e);
if(this.graph&&this.graph.onNodeConnectionChange)this.graph.onNodeConnectionChange(k.OUTPUT,this,a);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(k.OUTPUT,this,a),this.graph.onNodeConnectionChange(k.INPUT,b,l.target_slot));break}}}else{c=0;for(f=e.links.length;c<f;c++)if(n=e.links[c],l=this.graph.links[n]){b=this.graph.getNodeById(l.target_id);this.graph&&this.graph._version++;if(b){g=b.inputs[l.target_slot];g.link=null;if(b.onConnectionsChange)b.onConnectionsChange(k.INPUT,
l.target_slot,!1,l,g);if(this.graph&&this.graph.onNodeConnectionChange)this.graph.onNodeConnectionChange(k.INPUT,b,l.target_slot)}delete this.graph.links[n];if(this.onConnectionsChange)this.onConnectionsChange(k.OUTPUT,a,!1,l,e);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(k.OUTPUT,this,a),this.graph.onNodeConnectionChange(k.INPUT,b,l.target_slot))}e.links=null}this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this);return!0};d.prototype.disconnectInput=function(a){if(a.constructor===
String){if(a=this.findInputSlot(a),-1==a)return k.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.inputs||a>=this.inputs.length)return k.debug&&console.log("Connect: Error, slot number not found"),!1;var b=this.inputs[a];if(!b)return!1;var e=this.inputs[a].link;this.inputs[a].link=null;var c=this.graph.links[e];if(c){var f=this.graph.getNodeById(c.origin_id);if(!f)return!1;var n=f.outputs[c.origin_slot];if(!n||!n.links||0==n.links.length)return!1;for(var l=0,g=n.links.length;l<
g;l++)if(n.links[l]==e){n.links.splice(l,1);break}delete this.graph.links[e];this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(k.INPUT,a,!1,c,b);if(f.onConnectionsChange)f.onConnectionsChange(k.OUTPUT,l,!1,c,n);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(k.OUTPUT,f,l),this.graph.onNodeConnectionChange(k.INPUT,this,a))}this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this);return!0};d.prototype.getConnectionPos=function(a,
b){return this.flags.collapsed?a?[this.pos[0],this.pos[1]-0.5*k.NODE_TITLE_HEIGHT]:[this.pos[0]+(this._collapsed_width||k.NODE_COLLAPSED_WIDTH),this.pos[1]-0.5*k.NODE_TITLE_HEIGHT]:a&&-1==b?[this.pos[0]+10,this.pos[1]+10]:a&&this.inputs&&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&&this.outputs.length>b&&this.outputs[b].pos?[this.pos[0]+this.outputs[b].pos[0],this.pos[1]+this.outputs[b].pos[1]]:this.flags.horizontal?
a?[this.pos[0]+this.size[0]/this.inputs.length*(b+0.5),this.pos[1]-k.NODE_TITLE_HEIGHT]:[this.pos[0]+this.size[0]/this.outputs.length*(b+0.5),this.pos[1]+this.size[1]]:a?[this.pos[0],this.pos[1]+10+b*k.NODE_SLOT_HEIGHT+(this.constructor.slot_start_y||0)]:[this.pos[0]+this.size[0]+1,this.pos[1]+10+b*k.NODE_SLOT_HEIGHT+(this.constructor.slot_start_y||0)]};d.prototype.alignToGrid=function(){this.pos[0]=k.CANVAS_GRID_SIZE*Math.round(this.pos[0]/k.CANVAS_GRID_SIZE);this.pos[1]=k.CANVAS_GRID_SIZE*Math.round(this.pos[1]/
k.CANVAS_GRID_SIZE)};d.prototype.trace=function(a){this.console||(this.console=[]);this.console.push(a);this.console.length>d.MAX_CONSOLE&&this.console.shift();this.graph.onNodeTrace(this,a)};d.prototype.setDirtyCanvas=function(a,b){this.graph&&this.graph.sendActionToCanvas("setDirty",[a,b])};d.prototype.loadImage=function(a){var b=new Image;b.src=k.node_images_path+a;b.ready=!1;var e=this;b.onload=function(){this.ready=!0;e.setDirtyCanvas(!0)};return b};d.prototype.captureInput=function(a){if(this.graph&&
this.graph.list_of_graphcanvas)for(var b=this.graph.list_of_graphcanvas,e=0;e<b.length;++e){var c=b[e];if(a||c.node_capturing_input==this)c.node_capturing_input=a?this:null}};d.prototype.collapse=function(a){this.graph._version++;if(!1!==this.constructor.collapsable||a)this.flags.collapsed=this.flags.collapsed?!1:!0,this.setDirtyCanvas(!0,!0)};d.prototype.pin=function(a){this.graph._version++;this.flags.pinned=void 0===a?!this.flags.pinned:a};d.prototype.localToScreen=function(a,b,e){return[(a+this.pos[0])*
e.scale+e.offset[0],(b+this.pos[1])*e.scale+e.offset[1]]};u.LGraphGroup=k.LGraphGroup=p;p.prototype._ctor=function(a){this.title=a||"Group";this.font_size=24;this.color=g.node_colors.pale_blue?g.node_colors.pale_blue.groupcolor:"#AAA";this._bounding=new Float32Array([10,10,140,80]);this._pos=this._bounding.subarray(0,2);this._size=this._bounding.subarray(2,4);this._nodes=[];this.graph=null;Object.defineProperty(this,"pos",{set:function(a){!a||2>a.length||(this._pos[0]=a[0],this._pos[1]=a[1])},get:function(){return this._pos},
enumerable:!0});Object.defineProperty(this,"size",{set:function(a){!a||2>a.length||(this._size[0]=Math.max(140,a[0]),this._size[1]=Math.max(80,a[1]))},get:function(){return this._size},enumerable:!0})};p.prototype.configure=function(a){this.title=a.title;this._bounding.set(a.bounding);this.color=a.color;this.font=a.font};p.prototype.serialize=function(){var a=this._bounding;return{title:this.title,bounding:[Math.round(a[0]),Math.round(a[1]),Math.round(a[2]),Math.round(a[3])],color:this.color,font:this.font}};
p.prototype.move=function(a,b,e){this._pos[0]+=a;this._pos[1]+=b;if(!e)for(e=0;e<this._nodes.length;++e){var c=this._nodes[e];c.pos[0]+=a;c.pos[1]+=b}};p.prototype.recomputeInsideNodes=function(){this._nodes.length=0;for(var a=this.graph._nodes,b=new Float32Array(4),e=0;e<a.length;++e){var c=a[e];c.getBounding(b);s(this._bounding,b)&&this._nodes.push(c)}};p.prototype.isPointInside=d.prototype.isPointInside;p.prototype.setDirtyCanvas=d.prototype.setDirtyCanvas;u.LGraphCanvas=k.LGraphCanvas=g;g.link_type_colors=
{"-1":"#F85",number:"#AAA",node:"#DCA"};g.gradients={};g.prototype.clear=function(){this.fps=this.render_time=this.last_draw_time=this.frame=0;this.scale=1;this.offset=[0,0];this.dragging_rectangle=null;this.selected_nodes={};this.selected_group=null;this.visible_nodes=[];this.connecting_node=this.node_capturing_input=this.node_over=this.node_dragged=null;this.highlighted_links={};this.dirty_bgcanvas=this.dirty_canvas=!0;this.node_widget=this.node_in_panel=this.dirty_area=null;this.last_mouse=[0,
0];this.last_mouseclick=0;this.visible_area.set([0,0,0,0]);if(this.onClear)this.onClear()};g.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)))};g.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)};g.prototype.closeSubgraph=function(){if(this._graph_stack&&0!=this._graph_stack.length){var a=this._graph_stack.pop();this.selected_nodes={};this.highlighted_links={};a.attachCanvas(this);this.setDirty(!0,!0)}};g.prototype.setCanvas=function(a,b){if(a&&a.constructor===String&&(a=document.getElementById(a),!a))throw"Error creating LiteGraph canvas: Canvas not found";if(a!==this.canvas&&(!a&&this.canvas&&(b||this.unbindEvents()),this.canvas=a)){a.className+=" lgraphcanvas";a.data=this;this.bgcanvas=
null;this.bgcanvas||(this.bgcanvas=document.createElement("canvas"),this.bgcanvas.width=this.canvas.width,this.bgcanvas.height=this.canvas.height);if(null==a.getContext){if("canvas"!=a.localName)throw"Element supplied for LGraphCanvas must be a <canvas> element, you passed a "+a.localName;throw"This browser doesnt support Canvas";}null==(this.ctx=a.getContext("2d"))&&(a.webgl_enabled||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()}};g.prototype._doNothing=function(a){a.preventDefault();return!1};g.prototype._doReturnTrue=function(a){a.preventDefault();return!0};g.prototype.bindEvents=function(){if(this._events_binded)console.warn("LGraphCanvas: events already binded");else{var a=this.canvas,b=this.getCanvasWindow().document;this._mousedown_callback=this.processMouseDown.bind(this);this._mousewheel_callback=this.processMouseWheel.bind(this);
a.addEventListener("mousedown",this._mousedown_callback,!0);a.addEventListener("mousemove",this._mousemove_callback);a.addEventListener("mousewheel",this._mousewheel_callback,!1);a.addEventListener("contextmenu",this._doNothing);a.addEventListener("DOMMouseScroll",this._mousewheel_callback,!1);a.addEventListener("touchstart",this.touchHandler,!0);a.addEventListener("touchmove",this.touchHandler,!0);a.addEventListener("touchend",this.touchHandler,!0);a.addEventListener("touchcancel",this.touchHandler,
!0);this._key_callback=this.processKey.bind(this);a.addEventListener("keydown",this._key_callback,!0);b.addEventListener("keyup",this._key_callback,!0);this._ondrop_callback=this.processDrop.bind(this);a.addEventListener("dragover",this._doNothing,!1);a.addEventListener("dragend",this._doNothing,!1);a.addEventListener("drop",this._ondrop_callback,!1);a.addEventListener("dragenter",this._doReturnTrue,!1);this._events_binded=!0}};g.prototype.unbindEvents=function(){if(this._events_binded){var a=this.getCanvasWindow().document;
this.canvas.removeEventListener("mousedown",this._mousedown_callback);this.canvas.removeEventListener("mousewheel",this._mousewheel_callback);this.canvas.removeEventListener("DOMMouseScroll",this._mousewheel_callback);this.canvas.removeEventListener("keydown",this._key_callback);a.removeEventListener("keyup",this._key_callback);this.canvas.removeEventListener("contextmenu",this._doNothing);this.canvas.removeEventListener("drop",this._ondrop_callback);this.canvas.removeEventListener("dragenter",this._doReturnTrue);
this.canvas.removeEventListener("touchstart",this.touchHandler);this.canvas.removeEventListener("touchmove",this.touchHandler);this.canvas.removeEventListener("touchend",this.touchHandler);this.canvas.removeEventListener("touchcancel",this.touchHandler);this._ondrop_callback=this._key_callback=this._mousewheel_callback=this._mousedown_callback=null;this._events_binded=!1}else console.warn("LGraphCanvas: no events binded")};g.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()};g.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;this.canvas.webgl_enabled=!0};g.prototype.setDirty=function(a,b){a&&(this.dirty_canvas=!0);b&&(this.dirty_bgcanvas=!0)};
g.prototype.getCanvasWindow=function(){if(!this.canvas)return window;var a=this.canvas.ownerDocument;return a.defaultView||a.parentWindow};g.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))};g.prototype.stopRendering=function(){this.is_rendering=!1};g.prototype.processMouseDown=function(a){if(this.graph){this.adjustMouseEvent(a);
var b=this.getCanvasWindow();g.active_canvas=this;this.canvas.removeEventListener("mousemove",this._mousemove_callback);b.document.addEventListener("mousemove",this._mousemove_callback,!0);b.document.addEventListener("mouseup",this._mouseup_callback,!0);var e=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes,5),c=!1,f=300>k.getTime()-this.last_mouseclick;this.canvas_mouse[0]=a.canvasX;this.canvas_mouse[1]=a.canvasY;k.closeAllContextMenus(b);if(!this.onMouse||!0!=this.onMouse(a)){if(1==
a.which){a.ctrlKey&&(this.dragging_rectangle=new Float32Array(4),this.dragging_rectangle[0]=a.canvasX,this.dragging_rectangle[1]=a.canvasY,this.dragging_rectangle[2]=1,this.dragging_rectangle[3]=1,c=!0);var n=!1;if(e&&this.allow_interaction&&!c){this.live_mode||e.flags.pinned||this.bringToFront(e);if(!this.connecting_node&&!e.flags.collapsed&&!this.live_mode)if(!c&&!1!==e.flags.resizable&&r(a.canvasX,a.canvasY,e.pos[0]+e.size[0]-5,e.pos[1]+e.size[1]-5,10,10))this.resizing_node=e,this.canvas.style.cursor=
"se-resize",c=!0;else{if(e.outputs)for(var l=0,d=e.outputs.length;l<d;++l){var m=e.outputs[l],h=e.getConnectionPos(!1,l);if(r(a.canvasX,a.canvasY,h[0]-15,h[1]-10,30,20)){this.connecting_node=e;this.connecting_output=m;this.connecting_pos=e.getConnectionPos(!1,l);this.connecting_slot=l;a.shiftKey&&e.disconnectOutput(l);if(f){if(e.onOutputDblClick)e.onOutputDblClick(l,a)}else if(e.onOutputClick)e.onOutputClick(l,a);c=!0;break}}if(e.inputs)for(l=0,d=e.inputs.length;l<d;++l)if(m=e.inputs[l],h=e.getConnectionPos(!0,
l),r(a.canvasX,a.canvasY,h[0]-15,h[1]-10,30,20)){if(f){if(e.onInputDblClick)e.onInputDblClick(l,a)}else if(e.onInputClick)e.onInputClick(l,a);if(null!==m.link){c=this.graph.links[m.link];e.disconnectInput(l);if(this.allow_reconnect_links||a.shiftKey)this.connecting_node=this.graph._nodes_by_id[c.origin_id],this.connecting_slot=c.origin_slot,this.connecting_output=this.connecting_node.outputs[this.connecting_slot],this.connecting_pos=this.connecting_node.getConnectionPos(!1,this.connecting_slot);c=
this.dirty_bgcanvas=!0}}}!c&&r(a.canvasX,a.canvasY,e.pos[0],e.pos[1]-k.NODE_TITLE_HEIGHT,k.NODE_TITLE_HEIGHT,k.NODE_TITLE_HEIGHT)&&(e.collapse(),c=!0);if(!c){l=!1;if(d=this.processNodeWidgets(e,this.canvas_mouse,a))l=!0,this.node_widget=[e,d];if(f&&this.selected_nodes[e.id]){if(e.onDblClick)e.onDblClick(a,[a.canvasX-e.pos[0],a.canvasY-e.pos[1]],graphcanvas);this.processNodeDblClicked(e);l=!0}e.onMouseDown&&e.onMouseDown(a,[a.canvasX-e.pos[0],a.canvasY-e.pos[1]],this)?l=!0:this.live_mode&&(l=n=!0);
l||(this.allow_dragnodes&&(this.node_dragged=e),this.selected_nodes[e.id]||this.processNodeSelected(e,a));this.dirty_canvas=!0}}else this.selected_group=this.graph.getGroupOnPos(a.canvasX,a.canvasY),this.selected_group_resizing=!1,this.selected_group&&(a.ctrlKey&&(this.dragging_rectangle=null),10>q([a.canvasX,a.canvasY],[this.selected_group.pos[0]+this.selected_group.size[0],this.selected_group.pos[1]+this.selected_group.size[1]])*this.scale?this.selected_group_resizing=!0:this.selected_group.recomputeInsideNodes()),
f&&this.showSearchBox(a),n=!0;!c&&n&&this.allow_dragcanvas&&(this.dragging_canvas=!0)}else 2!=a.which&&3==a.which&&this.processContextMenu(e,a);this.last_mouse[0]=a.localX;this.last_mouse[1]=a.localY;this.last_mouseclick=k.getTime();this.last_mouse_dragging=!0;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}}};g.prototype.processMouseMove=function(a){this.autoresize&&this.resize();if(this.graph){g.active_canvas=this;this.adjustMouseEvent(a);var b=[a.localX,a.localY],e=[b[0]-this.last_mouse[0],b[1]-this.last_mouse[1]];this.last_mouse=b;this.canvas_mouse[0]=a.canvasX;this.canvas_mouse[1]=a.canvasY;a.dragging=this.last_mouse_dragging;this.node_widget&&(this.processNodeWidgets(this.node_widget[0],this.canvas_mouse,a,this.node_widget[1]),this.dirty_canvas=!0);if(this.dragging_rectangle)this.dragging_rectangle[2]=
a.canvasX-this.dragging_rectangle[0],this.dragging_rectangle[3]=a.canvasY-this.dragging_rectangle[1],this.dirty_canvas=!0;else if(this.selected_group)this.selected_group_resizing?this.selected_group.size=[a.canvasX-this.selected_group.pos[0],a.canvasY-this.selected_group.pos[1]]:(this.selected_group.move(e[0]/this.scale,e[1]/this.scale,a.ctrlKey),this.selected_group._nodes.length&&(this.dirty_canvas=!0)),this.dirty_bgcanvas=!0;else if(this.dragging_canvas)this.offset[0]+=e[0]/this.scale,this.offset[1]+=
e[1]/this.scale,this.dirty_bgcanvas=this.dirty_canvas=!0;else if(this.allow_interaction){this.connecting_node&&(this.dirty_canvas=!0);for(var c=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes),b=0,f=this.graph._nodes.length;b<f;++b)if(this.graph._nodes[b].mouseOver&&c!=this.graph._nodes[b]){this.graph._nodes[b].mouseOver=!1;if(this.node_over&&this.node_over.onMouseLeave)this.node_over.onMouseLeave(a);this.node_over=null;this.dirty_canvas=!0}if(c){if(!c.mouseOver&&(c.mouseOver=!0,this.node_over=
c,this.dirty_canvas=!0,c.onMouseEnter))c.onMouseEnter(a);if(c.onMouseMove)c.onMouseMove(a,[a.canvasX-c.pos[0],a.canvasY-c.pos[1]],this);if(this.connecting_node&&(f=this._highlight_input||[0,0],!this.isOverNodeBox(c,a.canvasX,a.canvasY))){var n=this.isOverNodeInput(c,a.canvasX,a.canvasY,f);-1!=n&&c.inputs[n]?k.isValidConnection(this.connecting_output.type,c.inputs[n].type)&&(this._highlight_input=f):this._highlight_input=null}this.canvas&&(r(a.canvasX,a.canvasY,c.pos[0]+c.size[0]-5,c.pos[1]+c.size[1]-
5,5,5)?this.canvas.style.cursor="se-resize":this.canvas.style.cursor="")}else this.canvas&&(this.canvas.style.cursor="");if(this.node_capturing_input&&this.node_capturing_input!=c&&this.node_capturing_input.onMouseMove)this.node_capturing_input.onMouseMove(a);if(this.node_dragged&&!this.live_mode){for(b in this.selected_nodes)c=this.selected_nodes[b],c.pos[0]+=e[0]/this.scale,c.pos[1]+=e[1]/this.scale;this.dirty_bgcanvas=this.dirty_canvas=!0}this.resizing_node&&!this.live_mode&&(this.resizing_node.size[0]=
a.canvasX-this.resizing_node.pos[0],this.resizing_node.size[1]=a.canvasY-this.resizing_node.pos[1],e=Math.max(this.resizing_node.inputs?this.resizing_node.inputs.length:0,this.resizing_node.outputs?this.resizing_node.outputs.length:0)*k.NODE_SLOT_HEIGHT+(this.resizing_node.widgets?this.resizing_node.widgets.length:0)*(k.NODE_WIDGET_HEIGHT+4)+4,this.resizing_node.size[1]<e&&(this.resizing_node.size[1]=e),this.resizing_node.size[0]<k.NODE_MIN_WIDTH&&(this.resizing_node.size[0]=k.NODE_MIN_WIDTH),this.canvas.style.cursor=
"se-resize",this.dirty_bgcanvas=this.dirty_canvas=!0)}a.preventDefault();return!1}};g.prototype.processMouseUp=function(a){if(this.graph){var b=this.getCanvasWindow().document;g.active_canvas=this;b.removeEventListener("mousemove",this._mousemove_callback,!0);this.canvas.addEventListener("mousemove",this._mousemove_callback,!0);b.removeEventListener("mouseup",this._mouseup_callback,!0);this.adjustMouseEvent(a);b=k.getTime();a.click_time=b-this.last_mouseclick;this.last_mouse_dragging=!1;if(1==a.which){this.node_widget=
null;if(this.selected_group){var b=this.selected_group.pos[0]-Math.round(this.selected_group.pos[0]),e=this.selected_group.pos[1]-Math.round(this.selected_group.pos[1]);this.selected_group.move(b,e,a.ctrlKey);this.selected_group.pos[0]=Math.round(this.selected_group.pos[0]);this.selected_group.pos[1]=Math.round(this.selected_group.pos[1]);this.selected_group._nodes.length&&(this.dirty_canvas=!0);this.selected_group=null}this.selected_group_resizing=!1;if(this.dragging_rectangle){if(this.graph){b=
this.graph._nodes;e=new Float32Array(4);this.deselectAllNodes();var c=Math.abs(this.dragging_rectangle[2]),f=Math.abs(this.dragging_rectangle[3]),n=0>this.dragging_rectangle[3]?this.dragging_rectangle[1]-f:this.dragging_rectangle[1];this.dragging_rectangle[0]=0>this.dragging_rectangle[2]?this.dragging_rectangle[0]-c:this.dragging_rectangle[0];this.dragging_rectangle[1]=n;this.dragging_rectangle[2]=c;this.dragging_rectangle[3]=f;f=[];for(n=0;n<b.length;++n)c=b[n],c.getBounding(e),s(this.dragging_rectangle,
e)&&f.push(c);f.length&&this.selectNodes(f)}this.dragging_rectangle=null}else if(this.connecting_node){this.dirty_bgcanvas=this.dirty_canvas=!0;if(c=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes))this.connecting_output.type==k.EVENT&&this.isOverNodeBox(c,a.canvasX,a.canvasY)?this.connecting_node.connect(this.connecting_slot,c,k.EVENT):(b=this.isOverNodeInput(c,a.canvasX,a.canvasY),-1!=b?this.connecting_node.connect(this.connecting_slot,c,b):(b=c.getInputInfo(0),this.connecting_output.type==
k.EVENT?this.connecting_node.connect(this.connecting_slot,c,k.EVENT):b&&!b.link&&k.isValidConnection(b.type&&this.connecting_output.type)&&this.connecting_node.connect(this.connecting_slot,c,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{c=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes);!c&&300>a.click_time&&this.deselectAllNodes();this.dirty_canvas=!0;this.dragging_canvas=!1;if(this.node_over&&this.node_over.onMouseUp)this.node_over.onMouseUp(a,[a.canvasX-this.node_over.pos[0],a.canvasY-this.node_over.pos[1]],this);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}};g.prototype.processMouseWheel=function(a){if(this.graph&&this.allow_dragcanvas){var b=null!=a.wheelDeltaY?a.wheelDeltaY:-60*a.detail;this.adjustMouseEvent(a);var e=this.scale;0<b?e*=1.1:0>b&&(e*=1/1.1);this.setZoom(e,[a.localX,
a.localY]);this.graph.change();a.preventDefault();return!1}};g.prototype.isOverNodeBox=function(a,b,e){var c=k.NODE_TITLE_HEIGHT;return r(b,e,a.pos[0]+2,a.pos[1]+2-c,c-4,c-4)?!0:!1};g.prototype.isOverNodeInput=function(a,b,e,c){if(a.inputs)for(var f=0,n=a.inputs.length;f<n;++f){var l=a.getConnectionPos(!0,f);if(r(b,e,l[0]-10,l[1]-5,20,10))return c&&(c[0]=l[0],c[1]=l[1]),f}return-1};g.prototype.processKey=function(a){if(this.graph){var b=!1;if("input"!=a.target.localName){if("keydown"==a.type){if(32==
a.keyCode&&(b=this.dragging_canvas=!0),65==a.keyCode&&a.ctrlKey&&(this.selectNodes(),b=!0),"KeyC"==a.code&&(a.metaKey||a.ctrlKey)&&!a.shiftKey&&this.selected_nodes&&(this.copyToClipboard(),b=!0),"KeyV"!=a.code||!a.metaKey&&!a.ctrlKey||a.shiftKey||this.pasteFromClipboard(),46!=a.keyCode&&8!=a.keyCode||"input"==a.target.localName||"textarea"==a.target.localName||(this.deleteSelectedNodes(),b=!0),this.selected_nodes)for(var e in this.selected_nodes)if(this.selected_nodes[e].onKeyDown)this.selected_nodes[e].onKeyDown(a)}else if("keyup"==
a.type&&(32==a.keyCode&&(this.dragging_canvas=!1),this.selected_nodes))for(e in this.selected_nodes)if(this.selected_nodes[e].onKeyUp)this.selected_nodes[e].onKeyUp(a);this.graph.change();if(b)return a.preventDefault(),!1}}};g.prototype.copyToClipboard=function(){var a={nodes:[],links:[]},b=0,e=[],c;for(c in this.selected_nodes){var f=this.selected_nodes[c];f._relative_id=b;e.push(f);b+=1}for(c=0;c<e.length;++c)if(f=e[c],a.nodes.push(f.clone().serialize()),f.inputs&&f.inputs.length)for(b=0;b<f.inputs.length;++b){var n=
f.inputs[b];if(n&&null!=n.link&&(n=this.graph.links[n.link])){var l=this.graph.getNodeById(n.origin_id);l&&this.selected_nodes[l.id]&&a.links.push([l._relative_id,b,f._relative_id,n.target_slot])}}localStorage.setItem("litegrapheditor_clipboard",JSON.stringify(a))};g.prototype.pasteFromClipboard=function(){var a=localStorage.getItem("litegrapheditor_clipboard");if(a){for(var a=JSON.parse(a),b=[],e=0;e<a.nodes.length;++e){var c=a.nodes[e],f=k.createNode(c.type);f&&(f.configure(c),f.pos[0]+=5,f.pos[1]+=
5,this.graph.add(f),b.push(f))}for(e=0;e<a.links.length;++e)c=a.links[e],b[c[0]].connect(c[1],b[c[2]],c[3]);this.selectNodes(b)}};g.prototype.processDrop=function(a){a.preventDefault();this.adjustMouseEvent(a);var b=[a.canvasX,a.canvasY],e=this.graph.getNodeOnPos(b[0],b[1]);if(e){if((e.onDropFile||e.onDropData)&&(b=a.dataTransfer.files)&&b.length)for(var c=0;c<b.length;c++){var f=a.dataTransfer.files[0],n=f.name;g.getFileExtension(n);if(e.onDropFile)e.onDropFile(f);if(e.onDropData){var l=new FileReader;
l.onload=function(a){e.onDropData(a.target.result,n,f)};var k=f.type.split("/")[0];"text"==k||""==k?l.readAsText(f):"image"==k?l.readAsDataURL(f):l.readAsArrayBuffer(f)}}return e.onDropItem&&e.onDropItem(event)?!0:this.onDropItem?this.onDropItem(event):!1}b=null;this.onDropItem&&(b=this.onDropItem(event));b||this.checkDropItem(a)};g.prototype.checkDropItem=function(a){if(a.dataTransfer.files.length){var b=a.dataTransfer.files[0],e=g.getFileExtension(b.name).toLowerCase();if(e=k.node_types_by_file_extension[e])if(e=
k.createNode(e.type),e.pos=[a.canvasX,a.canvasY],this.graph.add(e),e.onDropFile)e.onDropFile(b)}};g.prototype.processNodeDblClicked=function(a){if(this.onShowNodePanel)this.onShowNodePanel(a);if(this.onNodeDblClicked)this.onNodeDblClicked(a);this.setDirty(!0)};g.prototype.processNodeSelected=function(a,b){this.selectNode(a,b&&b.shiftKey);if(this.onNodeSelected)this.onNodeSelected(a)};g.prototype.processNodeDeselected=function(a){this.deselectNode(a);if(this.onNodeDeselected)this.onNodeDeselected(a)};
g.prototype.selectNode=function(a,b){null==a?this.deselectAllNodes():this.selectNodes([a],b)};g.prototype.selectNodes=function(a,b){b||this.deselectAllNodes();a=a||this.graph._nodes;for(var e=0;e<a.length;++e){var c=a[e];if(!c.selected){if(!c.selected&&c.onSelected)c.onSelected();c.selected=!0;this.selected_nodes[c.id]=c;if(c.inputs)for(var f=0;f<c.inputs.length;++f)this.highlighted_links[c.inputs[f].link]=!0;if(c.outputs)for(f=0;f<c.outputs.length;++f){var n=c.outputs[f];if(n.links)for(var l=0;l<
n.links.length;++l)this.highlighted_links[n.links[l]]=!0}}}this.setDirty(!0)};g.prototype.deselectNode=function(a){if(a.selected){if(a.onDeselected)a.onDeselected();a.selected=!1;if(a.inputs)for(var b=0;b<a.inputs.length;++b)delete this.highlighted_links[a.inputs[b].link];if(a.outputs)for(b=0;b<a.outputs.length;++b){var c=a.outputs[b];if(c.links)for(var g=0;g<c.links.length;++g)delete this.highlighted_links[c.links[g]]}}};g.prototype.deselectAllNodes=function(){if(this.graph){for(var a=this.graph._nodes,
b=0,c=a.length;b<c;++b){var g=a[b];if(g.selected){if(g.onDeselected)g.onDeselected();g.selected=!1}}this.selected_nodes={};this.highlighted_links={};this.setDirty(!0)}};g.prototype.deleteSelectedNodes=function(){for(var a in this.selected_nodes)this.graph.remove(this.selected_nodes[a]);this.selected_nodes={};this.highlighted_links={};this.setDirty(!0)};g.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)};g.prototype.adjustMouseEvent=function(a){if(this.canvas){var b=this.canvas.getBoundingClientRect();a.localX=a.pageX-b.left;a.localY=a.pageY-b.top}else a.localX=a.pageX,a.localY=a.pageY;a.deltaX=a.localX-this.last_mouse_position[0];a.deltaY=a.localY-this.last_mouse_position[1];this.last_mouse_position[0]=a.localX;this.last_mouse_position[1]=a.localY;a.canvasX=a.localX/this.scale-this.offset[0];a.canvasY=a.localY/this.scale-this.offset[1]};g.prototype.setZoom=
function(a,b){!b&&this.canvas&&(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 g=this.convertOffsetToCanvas(b),c=[g[0]-c[0],g[1]-c[1]];this.offset[0]+=c[0];this.offset[1]+=c[1];this.dirty_bgcanvas=this.dirty_canvas=!0};g.prototype.convertOffsetToCanvas=function(a,b){b=b||[];b[0]=a[0]/this.scale-this.offset[0];b[1]=a[1]/this.scale-this.offset[1];
return b};g.prototype.convertCanvasToOffset=function(a,b){b=b||[];b[0]=(a[0]+this.offset[0])*this.scale;b[1]=(a[1]+this.offset[1])*this.scale;return b};g.prototype.convertEventToCanvas=function(a){var b=this.canvas.getBoundingClientRect();return this.convertOffsetToCanvas([a.pageX-b.left,a.pageY-b.top])};g.prototype.bringToFront=function(a){var b=this.graph._nodes.indexOf(a);-1!=b&&(this.graph._nodes.splice(b,1),this.graph._nodes.push(a))};g.prototype.sendToBack=function(a){var b=this.graph._nodes.indexOf(a);
-1!=b&&(this.graph._nodes.splice(b,1),this.graph._nodes.unshift(a))};var m=new Float32Array(4);g.prototype.computeVisibleNodes=function(a,b){var c=b||[];c.length=0;a=a||this.graph._nodes;for(var g=0,f=a.length;g<f;++g){var n=a[g];(!this.live_mode||n.onDrawBackground||n.onDrawForeground)&&s(this.visible_area,n.getBounding(m))&&c.push(n)}return c};g.prototype.draw=function(a,b){if(this.canvas){var c=k.getTime();this.render_time=0.001*(c-this.last_draw_time);this.last_draw_time=c;if(this.graph){var g=
-this.offset[0],f=-this.offset[1],n=g+this.canvas.width/this.scale,l=f+this.canvas.height/this.scale;this.visible_area[0]=g;this.visible_area[1]=f;this.visible_area[2]=n-g;this.visible_area[3]=l-f}(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}};g.prototype.drawFrontCanvas=function(){this.dirty_canvas=
!1;this.ctx||(this.ctx=this.bgcanvas.getContext("2d"));var a=this.ctx;if(a){a.start2D&&a.start2D();var b=this.canvas;a.restore();a.setTransform(1,0,0,1,0,0);this.dirty_area&&(a.save(),a.beginPath(),a.rect(this.dirty_area[0],this.dirty_area[1],this.dirty_area[2],this.dirty_area[3]),a.clip());this.clear_background&&a.clearRect(0,0,b.width,b.height);this.bgcanvas==this.canvas?this.drawBackCanvas():a.drawImage(this.bgcanvas,0,0);if(this.onRender)this.onRender(b,a);this.show_info&&this.renderInfo(a);if(this.graph){a.save();
a.scale(this.scale,this.scale);a.translate(this.offset[0],this.offset[1]);for(var b=this.computeVisibleNodes(null,this.visible_nodes),c=0;c<b.length;++c){var g=b[c];a.save();a.translate(g.pos[0],g.pos[1]);this.drawNode(g,a);a.restore()}this.render_execution_order&&this.drawExecutionOrder(a);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 k.EVENT:b=k.EVENT_LINK_COLOR;
break;default:b=k.CONNECTING_LINK_COLOR}this.renderLink(a,this.connecting_pos,[this.canvas_mouse[0],this.canvas_mouse[1]],null,!1,null,b,this.connecting_output.dir||(this.connecting_node.flags.horizontal?k.DOWN:k.RIGHT),k.CENTER);a.beginPath();this.connecting_output.type===k.EVENT||this.connecting_output.shape===k.BOX_SHAPE?a.rect(this.connecting_pos[0]-6+0.5,this.connecting_pos[1]-5+0.5,14,10):a.arc(this.connecting_pos[0],this.connecting_pos[1],4,0,2*Math.PI);a.fill();a.fillStyle="#ffcc00";this._highlight_input&&
(a.beginPath(),a.arc(this._highlight_input[0],this._highlight_input[1],6,0,2*Math.PI),a.fill())}this.dragging_rectangle&&(a.strokeStyle="#FFF",a.strokeRect(this.dragging_rectangle[0],this.dragging_rectangle[1],this.dragging_rectangle[2],this.dragging_rectangle[3]));if(this.onDrawForeground)this.onDrawForeground(a,this.visible_rect);a.restore()}if(this.onDrawOverlay)this.onDrawOverlay(a);this.dirty_area&&a.restore();a.finish2D&&a.finish2D()}};g.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("N: "+this.graph._nodes.length+" ["+this.visible_nodes.length+"]",5,39),a.fillText("V: "+this.graph._version,5,52),a.fillText("FPS:"+this.fps.toFixed(2),5,65)):a.fillText("No graph selected",5,13);a.restore()};g.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);if(this._graph_stack&&this._graph_stack.length){b.save();var c=this.graph._subgraph_node;b.strokeStyle=c.bgcolor;b.lineWidth=10;b.strokeRect(1,1,a.width-2,a.height-2);b.lineWidth=1;b.font="40px Arial";b.textAlign="center";b.fillStyle=c.bgcolor;for(var g="",f=1;f<this._graph_stack.length;++f)g+=this._graph_stack[f]._subgraph_node.getTitle()+
" >> ";b.fillText(g+c.getTitle(),0.5*a.width,40);b.restore()}c=!1;this.onRenderBackground&&(c=this.onRenderBackground(a,b));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&&!c){b.globalAlpha=this.zoom_modify_alpha?(1-0.5/this.scale)*this.editor_alpha:this.editor_alpha;b.imageSmoothingEnabled=b.mozImageSmoothingEnabled=b.imageSmoothingEnabled=!1;if(!this._bg_img||this._bg_img.name!=
this.background_image){this._bg_img=new Image;this._bg_img.name=this.background_image;this._bg_img.src=this.background_image;var n=this;this._bg_img.onload=function(){n.draw(!0,!0)}}c=null;null==this._pattern&&0<this._bg_img.width?(c=b.createPattern(this._bg_img,"repeat"),this._pattern_img=this._bg_img,this._pattern=c):c=this._pattern;c&&(b.fillStyle=c,b.fillRect(this.visible_area[0],this.visible_area[1],this.visible_area[2],this.visible_area[3]),b.fillStyle="transparent");b.globalAlpha=1;b.imageSmoothingEnabled=
b.mozImageSmoothingEnabled=b.imageSmoothingEnabled=!0}this.graph._groups.length&&!this.live_mode&&this.drawGroups(a,b);if(this.onDrawBackground)this.onDrawBackground(b,this.visible_area);this.onBackgroundRender&&(console.error("WARNING! onBackgroundRender deprecated, now is named onDrawBackground "),this.onBackgroundRender=null);this.render_canvas_border&&(b.strokeStyle="#235",b.strokeRect(0,0,a.width,a.height));this.render_connections_shadows?(b.shadowColor="#000",b.shadowOffsetX=0,b.shadowOffsetY=
0,b.shadowBlur=6):b.shadowColor="rgba(0,0,0,0)";this.live_mode||this.drawConnections(b);b.shadowColor="rgba(0,0,0,0)";b.restore()}b.finish&&b.finish();this.dirty_bgcanvas=!1;this.dirty_canvas=!0};var c=new Float32Array(2);g.prototype.drawNode=function(a,b){this.current_node=a;var e=a.color||a.constructor.color||k.NODE_DEFAULT_COLOR,g=a.bgcolor||a.constructor.bgcolor||k.NODE_DEFAULT_BGCOLOR;if(this.live_mode){if(!a.flags.collapsed&&(b.shadowColor="transparent",a.onDrawForeground))a.onDrawForeground(b,
this,this.canvas)}else{var f=this.editor_alpha;b.globalAlpha=f;this.render_shadows?(b.shadowColor=k.DEFAULT_SHADOW_COLOR,b.shadowOffsetX=2*this.scale,b.shadowOffsetY=2*this.scale,b.shadowBlur=3*this.scale):b.shadowColor="transparent";if(!a.flags.collapsed||!a.onDrawCollaped||!0!=a.onDrawCollapsed(b,this)){var n=a._shape||k.BOX_SHAPE;c.set(a.size);if(a.flags.collapsed){b.font=this.inner_text_font;var l=a.getTitle?a.getTitle():a.title;a._collapsed_width=Math.min(a.size[0],b.measureText(l).width+40);
c[0]=a._collapsed_width;c[1]=0}a.flags.clip_area&&(b.save(),b.beginPath(),n==k.BOX_SHAPE?b.rect(0,0,c[0],c[1]):n==k.ROUND_SHAPE?b.roundRect(0,0,c[0],c[1],10):n==k.CIRCLE_SHAPE&&b.arc(0.5*c[0],0.5*c[1],0.5*c[0],0,2*Math.PI),b.clip());this.drawNodeShape(a,b,c,e,g,a.selected,a.mouseOver);b.shadowColor="transparent";b.textAlign=a.flags.horizontal?"center":"left";b.font=this.inner_text_font;e=0.6<this.scale;g=this.connecting_output;b.lineWidth=1;n=0;if(a.flags.collapsed){if(a.inputs)for(l=0;l<a.inputs.length;l++)if(d=
a.inputs[l],null!=d.link){b.fillStyle=d.color_on||this.default_connection_color.input_on;b.beginPath();d.type===k.EVENT||d.shape===k.BOX_SHAPE?b.rect(0.5,4-k.NODE_TITLE_HEIGHT+0.5,14,k.NODE_TITLE_HEIGHT-8):d.shape===k.ARROW_SHAPE?(b.moveTo(8,-0.5*k.NODE_TITLE_HEIGHT),b.lineTo(-4,-0.8*k.NODE_TITLE_HEIGHT),b.lineTo(-4,-0.2*k.NODE_TITLE_HEIGHT),b.closePath()):b.arc(0,-0.5*k.NODE_TITLE_HEIGHT,4,0,2*Math.PI);b.fill();break}if(a.outputs)for(l=0;l<a.outputs.length;l++)d=a.outputs[l],d.links&&d.links.length&&
(b.fillStyle=d.color_on||this.default_connection_color.output_on,b.strokeStyle="black",b.beginPath(),d.type===k.EVENT||d.shape===k.BOX_SHAPE?b.rect(a._collapsed_width-4+0.5,4-k.NODE_TITLE_HEIGHT+0.5,14,k.NODE_TITLE_HEIGHT-8):d.shape===k.ARROW_SHAPE?(b.moveTo(a._collapsed_width+6,-0.5*k.NODE_TITLE_HEIGHT),b.lineTo(a._collapsed_width-6,-0.8*k.NODE_TITLE_HEIGHT),b.lineTo(a._collapsed_width-6,-0.2*k.NODE_TITLE_HEIGHT),b.closePath()):b.arc(a._collapsed_width,-0.5*k.NODE_TITLE_HEIGHT,4,0,2*Math.PI),b.fill(),
b.stroke())}else{if(a.inputs)for(l=0;l<a.inputs.length;l++){var d=a.inputs[l];b.globalAlpha=f;this.connecting_node&&k.isValidConnection(d.type&&g.type)&&(b.globalAlpha=0.4*f);b.fillStyle=null!=d.link?d.color_on||this.default_connection_color.input_on:d.color_off||this.default_connection_color.input_off;var m=a.getConnectionPos(!0,l);m[0]-=a.pos[0];m[1]-=a.pos[1];n<m[1]+0.5*k.NODE_SLOT_HEIGHT&&(n=m[1]+0.5*k.NODE_SLOT_HEIGHT);b.beginPath();d.type===k.EVENT||d.shape===k.BOX_SHAPE?b.rect(m[0]-6+0.5,m[1]-
5+0.5,14,10):d.shape===k.ARROW_SHAPE?(b.moveTo(m[0]+8,m[1]+0.5),b.lineTo(m[0]-4,m[1]+6+0.5),b.lineTo(m[0]-4,m[1]-6+0.5),b.closePath()):b.arc(m[0],m[1],4,0,2*Math.PI);b.fill();if(e){var h=null!=d.label?d.label:d.name;h&&(b.fillStyle=k.NODE_TEXT_COLOR,a.flags.horizontal||d.dir==k.UP?b.fillText(h,m[0],m[1]-10):b.fillText(h,m[0]+10,m[1]+5))}}this.connecting_node&&(b.globalAlpha=0.4*f);b.textAlign=a.flags.horizontal?"center":"right";b.strokeStyle="black";if(a.outputs)for(l=0;l<a.outputs.length;l++)if(d=
a.outputs[l],m=a.getConnectionPos(!1,l),m[0]-=a.pos[0],m[1]-=a.pos[1],n<m[1]+0.5*k.NODE_SLOT_HEIGHT&&(n=m[1]+0.5*k.NODE_SLOT_HEIGHT),b.fillStyle=d.links&&d.links.length?d.color_on||this.default_connection_color.output_on:d.color_off||this.default_connection_color.output_off,b.beginPath(),d.type===k.EVENT||d.shape===k.BOX_SHAPE?b.rect(m[0]-6+0.5,m[1]-5+0.5,14,10):d.shape===k.ARROW_SHAPE?(b.moveTo(m[0]+8,m[1]+0.5),b.lineTo(m[0]-4,m[1]+6+0.5),b.lineTo(m[0]-4,m[1]-6+0.5),b.closePath()):b.arc(m[0],m[1],
4,0,2*Math.PI),b.fill(),b.stroke(),e&&(h=null!=d.label?d.label:d.name))b.fillStyle=k.NODE_TEXT_COLOR,a.flags.horizontal||d.dir==k.DOWN?b.fillText(h,m[0],m[1]-8):b.fillText(h,m[0]-10,m[1]+5);b.textAlign="left";b.globalAlpha=1;if(a.widgets){if(a.flags.horizontal||a.flags.widgets_up)n=2;this.drawNodeWidgets(a,n,b,this.node_widget&&this.node_widget[0]==a?this.node_widget[1]:null)}if(a.onDrawForeground)a.onDrawForeground(b,this,this.canvas)}a.flags.clip_area&&b.restore();b.globalAlpha=1}}};g.prototype.drawNodeShape=
function(a,b,c,d,f,n,l){b.strokeStyle=d;b.fillStyle=f;f=k.NODE_TITLE_HEIGHT;var m=a._shape||a.constructor.shape||k.BOX_SHAPE,h=a.constructor.title_mode,z=!0;h==k.TRANSPARENT_TITLE?z=!1:h==k.AUTOHIDE_TITLE&&l&&(z=!0);l=z?-f:0;var A=c[0]+1,p=z?c[1]+f:c[1];a.flags.collapsed||(b.beginPath(),m==k.BOX_SHAPE||0.5>this.scale?b.fillRect(0,l,A,p):m==k.ROUND_SHAPE||m==k.CARD_SHAPE?b.roundRect(0,l,A,p,this.round_radius,m==k.CARD_SHAPE?0:this.round_radius):m==k.CIRCLE_SHAPE&&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,this,this.canvas);if(z||h==k.TRANSPARENT_TITLE){if(h!=k.TRANSPARENT_TITLE){a.flags.collapsed&&(b.shadowColor=k.DEFAULT_SHADOW_COLOR);if(this.use_gradients){var q=g.gradients[d];q||(q=g.gradients[d]=b.createLinearGradient(0,0,400,0),q.addColorStop(0,
d),q.addColorStop(1,"#000"));b.fillStyle=q}else b.fillStyle=d;q=b.globalAlpha;b.beginPath();m==k.BOX_SHAPE||0.5>this.scale?b.rect(0,-f,c[0]+1,f):m!=k.ROUND_SHAPE&&m!=k.CARD_SHAPE||b.roundRect(0,-f,c[0]+1,f,this.round_radius,a.flags.collapsed?this.round_radius:0);b.fill();b.shadowColor="transparent"}m==k.ROUND_SHAPE||m==k.CIRCLE_SHAPE||m==k.CARD_SHAPE?(0.5<this.scale&&(b.fillStyle="black",b.beginPath(),b.arc(0.5*f,-0.5*f,0.5*(f-8),0,2*Math.PI),b.fill()),b.fillStyle=a.boxcolor||k.NODE_DEFAULT_BOXCOLOR,
b.beginPath(),b.arc(0.5*f,-0.5*f,0.4*(f-8),0,2*Math.PI),b.fill()):(0.5<this.scale&&(b.fillStyle="black",b.fillRect(4,-f+4,f-8,f-8)),b.fillStyle=a.boxcolor||k.NODE_DEFAULT_BOXCOLOR,b.fillRect(5,-f+5,f-10,f-10));b.globalAlpha=q;0.5<this.scale&&(b.font=this.title_text_font,q=a.getTitle())&&(b.fillStyle=n?"white":a.constructor.title_text_color||this.node_title_color,a.flags.collapsed?(b.textAlign="center",z=b.measureText(q),b.fillText(q,f+0.5*z.width,0.2*-f),b.textAlign="left"):(b.textAlign="left",b.fillText(q,
f,0.2*-f)));if(a.onDrawTitle)a.onDrawTitle(b)}n&&(h==k.TRANSPARENT_TITLE&&(l-=f,p+=f),b.lineWidth=1,b.globalAlpha=0.8,b.beginPath(),m==k.BOX_SHAPE?b.rect(-6,-6+l,12+A,12+p):m==k.ROUND_SHAPE||m==k.CARD_SHAPE&&a.flags.collapsed?b.roundRect(-6,-6+l,12+A,12+p,2*this.round_radius):m==k.CARD_SHAPE?b.roundRect(-6,-6+l,12+A,12+p,2*this.round_radius,2):m==k.CIRCLE_SHAPE&&b.arc(0.5*c[0],0.5*c[1],0.5*c[0]+6,0,2*Math.PI),b.strokeStyle="#FFF",b.stroke(),b.strokeStyle=d,b.globalAlpha=1)};g.prototype.drawConnections=
function(a){var b=k.getTime(),c=this.visible_area,c=new Float32Array([c[0]-20,c[1]-20,c[2]+40,c[3]+40]),g=new Float32Array(4);a.lineWidth=this.connections_width;a.fillStyle="#AAA";a.strokeStyle="#AAA";a.globalAlpha=this.editor_alpha;for(var f=this.graph._nodes,n=0,l=f.length;n<l;++n){var m=f[n];if(m.inputs&&m.inputs.length)for(var d=0;d<m.inputs.length;++d){var h=m.inputs[d];if(h&&null!=h.link&&(h=this.graph.links[h.link])){var p=this.graph.getNodeById(h.origin_id);if(null!=p){var q=h.origin_slot,
r=null,r=-1==q?[p.pos[0]+10,p.pos[1]+10]:p.getConnectionPos(!1,q),t=m.getConnectionPos(!0,d);g[0]=r[0];g[1]=r[1];g[2]=t[0]-r[0];g[3]=t[1]-r[1];0>g[2]&&(g[0]+=g[2],g[2]=Math.abs(g[2]));0>g[3]&&(g[1]+=g[3],g[3]=Math.abs(g[3]));if(s(g,c)){var v=p.outputs[q],q=m.inputs[d];if(v&&q&&(p=v.dir||(p.flags.horizontal?k.DOWN:k.RIGHT),q=q.dir||(m.flags.horizontal?k.UP:k.LEFT),this.renderLink(a,r,t,h,!1,0,null,p,q),h&&h._last_time&&1E3>b-h._last_time)){var v=2-0.002*(b-h._last_time),y=a.globalAlpha;a.globalAlpha=
y*v;this.renderLink(a,r,t,h,!0,v,"white",p,q);a.globalAlpha=y}}}}}}a.globalAlpha=1};g.prototype.renderLink=function(a,b,c,m,f,n,l,d,h){if(this.highquality_render){d=d||k.RIGHT;h=h||k.LEFT;var p=q(b,c);this.render_connections_border&&0.6<this.scale&&(a.lineWidth=this.connections_width+4);!l&&m&&(l=g.link_type_colors[m.type]);l||(l=this.default_link_color);null!=m&&this.highlighted_links[m.id]&&(l="#FFF");a.beginPath();if(this.render_curved_connections){a.moveTo(b[0],b[1]);var A=m=0,r=0,s=0;switch(d){case k.LEFT:m=
-0.25*p;break;case k.RIGHT:m=0.25*p;break;case k.UP:A=-0.25*p;break;case k.DOWN:A=0.25*p}switch(h){case k.LEFT:r=-0.25*p;break;case k.RIGHT:r=0.25*p;break;case k.UP:s=-0.25*p;break;case k.DOWN:s=0.25*p}a.bezierCurveTo(b[0]+m,b[1]+A,c[0]+r,c[1]+s,c[0],c[1])}else a.moveTo(b[0]+10,b[1]),a.lineTo(0.5*(b[0]+10+(c[0]-10)),b[1]),a.lineTo(0.5*(b[0]+10+(c[0]-10)),c[1]),a.lineTo(c[0]-10,c[1]);this.render_connections_border&&0.6<this.scale&&!f&&(a.strokeStyle="rgba(0,0,0,0.5)",a.stroke());a.lineWidth=this.connections_width;
a.fillStyle=a.strokeStyle=l;a.stroke();this.render_connection_arrows&&0.6<=this.scale&&this.render_connection_arrows&&0.6<this.scale&&(f=this.computeConnectionPoint(b,c,0.5,d,h),l=this.computeConnectionPoint(b,c,0.51,d,h),p=0,p=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(p),a.beginPath(),a.moveTo(-5,-5),a.lineTo(0,5),a.lineTo(5,-5),a.fill(),a.restore());if(n)for(n=0;5>n;++n)f=(0.001*k.getTime()+0.2*n)%1,f=this.computeConnectionPoint(b,
c,f,d,h),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()};g.prototype.computeConnectionPoint=function(a,b,c,g,f){g=g||k.RIGHT;f=f||k.LEFT;var n=q(a,b),l=[a[0],a[1]],m=[b[0],b[1]];switch(g){case k.LEFT:l[0]+=-0.25*n;break;case k.RIGHT:l[0]+=0.25*n;break;case k.UP:l[1]+=-0.25*n;break;case k.DOWN:l[1]+=0.25*n}switch(f){case k.LEFT:m[0]+=-0.25*n;break;case k.RIGHT:m[0]+=0.25*n;break;case k.UP:m[1]+=-0.25*n;break;case k.DOWN:m[1]+=
0.25*n}g=(1-c)*(1-c)*(1-c);f=3*(1-c)*(1-c)*c;n=3*(1-c)*c*c;c*=c*c;return[g*a[0]+f*l[0]+n*m[0]+c*b[0],g*a[1]+f*l[1]+n*m[1]+c*b[1]]};g.prototype.drawExecutionOrder=function(a){a.shadowColor="transparent";a.globalAlpha=0.25;a.textAlign="center";a.strokeStyle="white";a.globalAlpha=0.75;for(var b=this.visible_nodes,c=0;c<b.length;++c){var g=b[c];a.fillStyle="black";a.fillRect(g.pos[0]-k.NODE_TITLE_HEIGHT,g.pos[1]-k.NODE_TITLE_HEIGHT,k.NODE_TITLE_HEIGHT,k.NODE_TITLE_HEIGHT);0==g.order&&a.strokeRect(g.pos[0]-
k.NODE_TITLE_HEIGHT+0.5,g.pos[1]-k.NODE_TITLE_HEIGHT+0.5,k.NODE_TITLE_HEIGHT,k.NODE_TITLE_HEIGHT);a.fillStyle="#FFF";a.fillText(g.order,g.pos[0]+-0.5*k.NODE_TITLE_HEIGHT,g.pos[1]-6)}a.globalAlpha=1};g.prototype.drawNodeWidgets=function(a,b,c,g){if(!a.widgets||!a.widgets.length)return 0;var f=a.size[0];a=a.widgets;b+=2;var n=k.NODE_WIDGET_HEIGHT,l=0.5<this.scale;c.save();c.globalAlpha=this.editor_alpha;for(var m=0;m<a.length;++m){var d=a[m],h=b;d.y&&(h=d.y);d.last_y=h;c.strokeStyle="#AAA";c.fillStyle=
"#222";c.textAlign="left";switch(d.type){case "button":d.clicked&&(c.fillStyle="#AAA",d.clicked=!1,this.dirty_canvas=!0);c.fillRect(10,h,f-20,n);c.strokeRect(10,h,f-20,n);l&&(c.textAlign="center",c.fillStyle="#AAA",c.fillText(d.name,0.5*f,h+0.7*n));break;case "toggle":c.textAlign="left";c.strokeStyle="#AAA";c.fillStyle="#111";c.beginPath();c.roundRect(10,b,f-20,n,0.5*n);c.fill();c.stroke();c.fillStyle=d.value?"#89A":"#333";c.beginPath();c.arc(f-20,h+0.5*n,0.36*n,0,2*Math.PI);c.fill();l&&(c.fillStyle=
"#999",null!=d.name&&c.fillText(d.name,20,h+0.7*n),c.fillStyle=d.value?"#DDD":"#888",c.textAlign="right",c.fillText(d.value?d.options.on||"true":d.options.off||"false",f-30,h+0.7*n));break;case "slider":c.fillStyle="#111";c.fillRect(10,h,f-20,n);var p=(d.value-d.options.min)/(d.options.max-d.options.min);c.fillStyle=g==d?"#89A":"#678";c.fillRect(10,h,p*(f-20),n);c.strokeRect(10,h,f-20,n);l&&(c.textAlign="center",c.fillStyle="#DDD",c.fillText(d.name+" "+Number(d.value).toFixed(3),0.5*f,h+0.7*n));
break;case "number":case "combo":c.textAlign="left";c.strokeStyle="#AAA";c.fillStyle="#111";c.beginPath();c.roundRect(10,b,f-20,n,0.5*n);c.fill();c.stroke();l&&(c.fillStyle="#AAA",c.beginPath(),c.moveTo(26,b+5),c.lineTo(16,b+0.5*n),c.lineTo(26,b+n-5),c.moveTo(f-26,b+5),c.lineTo(f-16,b+0.5*n),c.lineTo(f-26,b+n-5),c.fill(),c.fillStyle="#999",c.fillText(d.name,30,h+0.7*n),c.fillStyle="#DDD",c.textAlign="right","number"==d.type?c.fillText(Number(d.value).toFixed(void 0!==d.options.precision?d.options.precision:
3),f-40,h+0.7*n):c.fillText(d.value,f-40,h+0.7*n));break;case "text":c.textAlign="left",c.strokeStyle="#AAA",c.fillStyle="#111",c.beginPath(),c.roundRect(10,b,f-20,n,0.5*n),c.fill(),c.stroke(),l&&(c.fillStyle="#999",null!=d.name&&c.fillText(d.name,20,h+0.7*n),c.fillStyle="#DDD",c.textAlign="right",c.fillText(d.value,f-20,h+0.7*n))}b+=n+4}c.restore()};g.prototype.processNodeWidgets=function(a,b,c,g){if(!a.widgets||!a.widgets.length)return null;for(var f=b[0]-a.pos[0],n=b[1]-a.pos[1],l=a.size[0],d=
this,m=this.getCanvasWindow(),h=0;h<a.widgets.length;++h){var p=a.widgets[h];if(p==g||6<f&&f<l-12&&n>p.last_y&&n<p.last_y+k.NODE_WIDGET_HEIGHT){switch(p.type){case "button":p.callback&&setTimeout(function(){p.callback(p,d,a,b)},20);this.dirty_canvas=p.clicked=!0;break;case "slider":c=Math.clamp((f-10)/(l-20),0,1);p.value=p.options.min+(p.options.max-p.options.min)*c;p.callback&&setTimeout(function(){p.callback(p.value,d,a,b)},20);this.dirty_canvas=!0;break;case "number":case "combo":if("mousemove"==
c.type&&"number"==p.type)p.value+=0.1*c.deltaX*(p.options.step||1),null!=p.options.min&&p.value<p.options.min&&(p.value=p.options.min),null!=p.options.max&&p.value>p.options.max&&(p.value=p.options.max);else if("mousedown"==c.type)if((g=p.options.values)&&g.constructor===Function&&(g=p.options.values(p,a)),f=40>f?-1:f>l-40?1:0,"number"==p.type)p.value+=0.1*f*(p.options.step||1),null!=p.options.min&&p.value<p.options.min&&(p.value=p.options.min),null!=p.options.max&&p.value>p.options.max&&(p.value=
p.options.max);else if(f)c=g.indexOf(p.value)+f,c>=g.length&&(c=0),0>c&&(c=g.length-1),p.value=g[c];else{new k.ContextMenu(g,{event:c,className:"dark",callback:q.bind(p)},m);var q=function(a,b,c){this.value=a;d.dirty_canvas=!0;return!1}}p.callback&&setTimeout(function(){this.callback(this.value,d,a,b)}.bind(p),20);this.dirty_canvas=!0;break;case "toggle":"mousedown"==c.type&&(p.value=!p.value,p.callback&&setTimeout(function(){p.callback(p.value,d,a,b)},20));break;case "text":"mousedown"==c.type&&
this.prompt("Value",p.value,function(b){this.value=b;p.callback&&p.callback(b,d,a)}.bind(p),c)}return p}}return null};g.prototype.drawGroups=function(a,b){if(this.graph){var c=this.graph._groups;b.save();b.globalAlpha=0.5*this.editor_alpha;for(var g=0;g<c.length;++g){var f=c[g];if(s(this.visible_area,f._bounding)){b.fillStyle=f.color||"#335";b.strokeStyle=f.color||"#335";var d=f._pos,l=f._size;b.globalAlpha=0.25*this.editor_alpha;b.beginPath();b.rect(d[0]+0.5,d[1]+0.5,l[0],l[1]);b.fill();b.globalAlpha=
this.editor_alpha;b.stroke();b.beginPath();b.moveTo(d[0]+l[0],d[1]+l[1]);b.lineTo(d[0]+l[0]-10,d[1]+l[1]);b.lineTo(d[0]+l[0],d[1]+l[1]-10);b.fill();l=f.font_size||k.DEFAULT_GROUP_FONT_SIZE;b.font=l+"px Arial";b.fillText(f.title,d[0]+4,d[1]+l)}}b.restore()}};g.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)};g.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 g=setInterval(function(){b.editor_alpha*=c;b.dirty_canvas=!0;b.dirty_bgcanvas=!0;1>c&&0.01>b.editor_alpha&&(clearInterval(g),1>c&&(b.live_mode=!0));1<c&&0.99<b.editor_alpha&&(clearInterval(g),b.editor_alpha=1)},1)}else this.live_mode=!this.live_mode,this.dirty_bgcanvas=this.dirty_canvas=!0};g.prototype.onNodeSelectionChange=
function(a){};g.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 g=this.getCanvasWindow(),f=g.document.createEvent("MouseEvent");f.initMouseEvent(c,!0,!0,g,1,b.screenX,b.screenY,b.clientX,b.clientY,!1,!1,!1,!1,0,null);b.target.dispatchEvent(f);a.preventDefault()};g.onGroupAdd=function(a,b,c){a=g.active_canvas;a.getCanvasWindow();b=new k.LGraphGroup;
b.pos=a.convertEventToCanvas(c);a.graph.add(b)};g.onMenuAdd=function(a,b,c,d){function f(a,b){var c=d.getFirstEvent(),e=k.createNode(a.value);e&&(e.pos=m.convertEventToCanvas(c),m.graph.add(e))}var m=g.active_canvas,l=m.getCanvasWindow();a=k.getNodeTypesCategories();b=[];for(var h in a)a[h]&&b.push({value:a[h],content:a[h],has_submenu:!0});var p=new k.ContextMenu(b,{event:c,callback:function(a,b,c){a=k.getNodeTypesInCategory(a.value,m.filter);b=[];for(var e in a)a[e].skip_list||b.push({content:a[e].title,
value:a[e].type});new k.ContextMenu(b,{event:c,callback:f,parentMenu:p},l);return!1},parentMenu:d},l);return!1};g.onMenuCollapseAll=function(){};g.onMenuNodeEdit=function(){};g.showMenuNodeOptionalInputs=function(a,b,c,d,f){function m(a,b,c){f&&(a.callback&&a.callback.call(l,f,a,b,c),a.value&&(f.addInput(a.value[0],a.value[1],a.value[2]),f.setDirtyCanvas(!0,!0)))}if(f){var l=this;a=g.active_canvas.getCanvasWindow();b=f.optional_inputs;f.onGetInputs&&(b=f.onGetInputs());var h=[];if(b)for(var p in b){var q=
b[p];if(q){var r=q[0];q[2]&&q[2].label&&(r=q[2].label);r={content:r,value:q};q[1]==k.ACTION&&(r.className="event");h.push(r)}else h.push(null)}this.onMenuNodeInputs&&(h=this.onMenuNodeInputs(h));if(h.length)return new k.ContextMenu(h,{event:c,callback:m,parentMenu:d,node:f},a),!1}};g.showMenuNodeOptionalOutputs=function(a,b,c,d,f){function m(a,b,c){if(f&&(a.callback&&a.callback.call(l,f,a,b,c),a.value))if(c=a.value[1],!c||c.constructor!==Object&&c.constructor!==Array)f.addOutput(a.value[0],a.value[1],
a.value[2]),f.setDirtyCanvas(!0,!0);else{a=[];for(var e in c)a.push({content:e,value:c[e]});new k.ContextMenu(a,{event:b,callback:m,parentMenu:d,node:f});return!1}}if(f){var l=this;a=g.active_canvas.getCanvasWindow();b=f.optional_outputs;f.onGetOutputs&&(b=f.onGetOutputs());var h=[];if(b)for(var p in b){var q=b[p];if(!q)h.push(null);else if(!f.flags||!f.flags.skip_repeated_outputs||-1==f.findOutputSlot(q[0])){var r=q[0];q[2]&&q[2].label&&(r=q[2].label);r={content:r,value:q};q[1]==k.EVENT&&(r.className=
"event");h.push(r)}}this.onMenuNodeOutputs&&(h=this.onMenuNodeOutputs(h));if(h.length)return new k.ContextMenu(h,{event:c,callback:m,parentMenu:d,node:f},a),!1}};g.onShowMenuNodeProperties=function(a,b,c,d,f){function m(a,b,c,e){f&&(b=this.getBoundingClientRect(),l.showEditPropertyValue(f,a.value,{position:[b.left,b.top]}))}if(f&&f.properties){var l=g.active_canvas;b=l.getCanvasWindow();var h=[],p;for(p in f.properties)a=void 0!==f.properties[p]?f.properties[p]:" ",a=g.decodeHTML(a),h.push({content:"<span class='property_name'>"+
p+"</span><span class='property_value'>"+a+"</span>",value:p});if(h.length)return new k.ContextMenu(h,{event:c,callback:m,parentMenu:d,allow_html:!0,node:f},b),!1}};g.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};g.onResizeNode=function(a,b,c,g,f){f&&(f.size=f.computeSize(),f.setDirtyCanvas(!0,!0))};g.onShowPropertyEditor=function(a,b,c,d,f){function m(){var b=h.value;"Number"==a.type?b=Number(b):"Boolean"==a.type&&(b=Boolean(b));f[l]=b;k.parentNode.removeChild(k);
f.setDirtyCanvas(!0,!0)}var l=a.property||"title";b=f[l];var k=document.createElement("div");k.className="graphdialog";k.innerHTML="<span class='name'></span><input autofocus type='text' class='value'/><button>OK</button>";k.querySelector(".name").innerText=l;var h=k.querySelector("input");h&&(h.value=b,h.addEventListener("blur",function(a){this.focus()}),h.addEventListener("keydown",function(a){13==a.keyCode&&(m(),a.preventDefault(),a.stopPropagation())}));b=g.active_canvas.canvas;c=b.getBoundingClientRect();
var p=d=-20;c&&(d-=c.left,p-=c.top);event?(k.style.left=event.pageX+d+"px",k.style.top=event.pageY+p+"px"):(k.style.left=0.5*b.width+d+"px",k.style.top=0.5*b.height+p+"px");k.querySelector("button").addEventListener("click",m);b.parentNode.appendChild(k)};g.prototype.prompt=function(a,b,c,d){var f=this;a=a||"";var m=document.createElement("div");m.className="graphdialog rounded";m.innerHTML="<span class='name'></span> <input autofocus type='text' class='value'/><button class='rounded'>OK</button>";
m.close=function(){f.prompt_box=null;m.parentNode.removeChild(m)};m.addEventListener("mouseleave",function(a){m.close()});f.prompt_box&&f.prompt_box.close();f.prompt_box=m;m.querySelector(".name").innerText=a;m.querySelector(".value").value=b;var l=m.querySelector("input");l.addEventListener("keydown",function(a){if(27==a.keyCode)m.close();else if(13==a.keyCode)c&&c(this.value),m.close();else return;a.preventDefault();a.stopPropagation()});m.querySelector("button").addEventListener("click",function(a){c&&
c(l.value);f.setDirty(!0);m.close()});a=g.active_canvas.canvas;b=a.getBoundingClientRect();var k=-20,h=-20;b&&(k-=b.left,h-=b.top);d?(m.style.left=d.pageX+k+"px",m.style.top=d.pageY+h+"px"):(m.style.left=0.5*a.width+k+"px",m.style.top=0.5*a.height+h+"px");a.parentNode.appendChild(m);setTimeout(function(){l.focus()},10);return m};g.search_limit=-1;g.prototype.showSearchBox=function(a){function b(b){if(b)if(f.onSearchBoxSelection)f.onSearchBoxSelection(b,a,s);else{var c=k.searchbox_extras[b];c&&(b=
c.type);if(b=k.createNode(b))b.pos=s.convertEventToCanvas(a),s.graph.add(b);if(c&&c.data){if(c.data.properties)for(var e in c.data.properties)b.addProperty(c.data.properties[e][0],c.data.properties[e][0]);if(c.data.inputs)for(e in b.inputs=[],c.data.inputs)b.addOutput(c.data.inputs[e][0],c.data.inputs[e][1]);if(c.data.outputs)for(e in b.outputs=[],c.data.outputs)b.addOutput(c.data.outputs[e][0],c.data.outputs[e][1]);c.data.title&&(b.title=c.data.title);c.data.json&&b.configure(c.data.json)}}m.close()}
function c(a){var b=q;q&&q.classList.remove("selected");q?(q=a?q.nextSibling:q.previousSibling)||(q=b):q=a?l.childNodes[0]:l.childNodes[l.childNodes.length];q&&(q.classList.add("selected"),q.scrollIntoView())}function d(){function a(c,e){var y=document.createElement("div");h||(h=c);y.innerText=c;y.dataset.type=escape(c);y.className="litegraph lite-search-item";e&&(y.className+=" "+e);y.addEventListener("click",function(a){b(unescape(this.dataset.type))});l.appendChild(y)}p=null;var c=r.value;h=null;
l.innerHTML="";if(c)if(f.onSearchBox){var e=f.onSearchBox(help,c,s);if(e)for(var y=0;y<e.length;++y)a(e[y])}else{e=0;c=c.toLowerCase();for(y in k.searchbox_extras){var m=k.searchbox_extras[y];if(-1!==m.desc.toLowerCase().indexOf(c)&&(a(m.desc,"searchbox_extra"),-1!==g.search_limit&&e++>g.search_limit))break}if(Array.prototype.filter)for(m=Object.keys(k.registered_node_types).filter(function(a){return-1!==a.toLowerCase().indexOf(c)}),y=0;y<m.length&&!(a(m[y]),-1!==g.search_limit&&e++>g.search_limit);y++);
else for(y in k.registered_node_types)if(-1!=y.indexOf(c)&&(a(y),-1!==g.search_limit&&e++>g.search_limit))break}}var f=this,m=document.createElement("div");m.className="litegraph litesearchbox graphdialog rounded";m.innerHTML="<span class='name'>Search</span> <input autofocus type='text' class='value rounded'/><div class='helper'></div>";m.close=function(){f.search_box=null;m.parentNode.removeChild(m)};m.addEventListener("mouseleave",function(a){m.close()});f.search_box&&f.search_box.close();f.search_box=
m;var l=m.querySelector(".helper"),h=null,p=null,q=null,r=m.querySelector("input");r&&(r.addEventListener("blur",function(a){this.focus()}),r.addEventListener("keydown",function(a){if(38==a.keyCode)c(!1);else if(40==a.keyCode)c(!0);else if(27==a.keyCode)m.close();else if(13==a.keyCode)q?b(q.innerHTML):h?b(h):m.close();else{p&&clearInterval(p);p=setTimeout(d,10);return}a.preventDefault();a.stopPropagation()}));var s=g.active_canvas,t=s.canvas,u=t.getBoundingClientRect(),v=-20,y=-20;u&&(v-=u.left,y-=
u.top);a?(m.style.left=a.pageX+v+"px",m.style.top=a.pageY+y+"px"):(m.style.left=0.5*t.width+v+"px",m.style.top=0.5*t.height+y+"px");t.parentNode.appendChild(m);r.focus();return m};g.prototype.showEditPropertyValue=function(a,b,c){function g(){f(q.value)}function f(c){"number"==typeof a.properties[b]&&(c=Number(c));"array"==m&&(c=c.split(",").map(Number));a.properties[b]=c;a._graph&&a._graph._version++;if(a.onPropertyChanged)a.onPropertyChanged(b,c);p.close();a.setDirtyCanvas(!0,!0)}if(a&&void 0!==
a.properties[b]){c=c||{};var m="string";null!==a.properties[b]&&(m=typeof a.properties[b]);"object"==m&&a.properties[b].length&&(m="array");var l=null;a.getPropertyInfo&&(l=a.getPropertyInfo(b));if(a.properties_info)for(var d=0;d<a.properties_info.length;++d)if(a.properties_info[d].name==b){l=a.properties_info[d];break}void 0!==l&&null!==l&&l.type&&(m=l.type);var k="";if("string"==m||"number"==m||"array"==m)k="<input autofocus type='text' class='value'/>";else if("enum"==m&&l.values){k="<select autofocus type='text' class='value'>";
for(d in l.values)var h=l.values.constructor===Array?l.values[d]:d,k=k+("<option value='"+h+"' "+(h==a.properties[b]?"selected":"")+">"+l.values[d]+"</option>");k+="</select>"}else if("boolean"==m)k="<input autofocus type='checkbox' class='value' "+(a.properties[b]?"checked":"")+"/>";else{console.warn("unknown type: "+m);return}var p=this.createDialog("<span class='name'>"+b+"</span>"+k+"<button>OK</button>",c);if("enum"==m&&l.values){var q=p.querySelector("select");q.addEventListener("change",function(a){f(a.target.value)})}else if("boolean"==
m)(q=p.querySelector("input"))&&q.addEventListener("click",function(a){f(!!q.checked)});else if(q=p.querySelector("input"))q.addEventListener("blur",function(a){this.focus()}),q.value=void 0!==a.properties[b]?a.properties[b]:"",q.addEventListener("keydown",function(a){13==a.keyCode&&(g(),a.preventDefault(),a.stopPropagation())});p.querySelector("button").addEventListener("click",g)}};g.prototype.createDialog=function(a,b){b=b||{};var c=document.createElement("div");c.className="graphdialog";c.innerHTML=
a;var g=this.canvas.getBoundingClientRect(),f=-20,m=-20;g&&(f-=g.left,m-=g.top);b.position?(f+=b.position[0],m+=b.position[1]):b.event?(f+=b.event.pageX,m+=b.event.pageY):(f+=0.5*this.canvas.width,m+=0.5*this.canvas.height);c.style.left=f+"px";c.style.top=m+"px";this.canvas.parentNode.appendChild(c);c.close=function(){this.parentNode&&this.parentNode.removeChild(this)};return c};g.onMenuNodeCollapse=function(a,b,c,m,f){f.collapse()};g.onMenuNodePin=function(a,b,c,m,f){f.pin()};g.onMenuNodeMode=function(a,
b,c,m,f){new k.ContextMenu(["Always","On Event","On Trigger","Never"],{event:c,callback:function(a){if(f)switch(a){case "On Event":f.mode=k.ON_EVENT;break;case "On Trigger":f.mode=k.ON_TRIGGER;break;case "Never":f.mode=k.NEVER;break;default:f.mode=k.ALWAYS}},parentMenu:m,node:f});return!1};g.onMenuNodeColors=function(a,b,c,m,f){if(!f)throw"no node for color";b=[];b.push({value:null,content:"<span style='display: block; padding-left: 4px;'>No color</span>"});for(var d in g.node_colors)a=g.node_colors[d],
a={value:d,content:"<span style='display: block; color: #999; padding-left: 4px; border-left: 8px solid "+a.color+"; background-color:"+a.bgcolor+"'>"+d+"</span>"},b.push(a);new k.ContextMenu(b,{event:c,callback:function(a){f&&((a=a.value?g.node_colors[a.value]:null)?f.constructor===k.LGraphGroup?f.color=a.groupcolor:(f.color=a.color,f.bgcolor=a.bgcolor):(delete f.color,delete f.bgcolor),f.setDirtyCanvas(!0,!0))},parentMenu:m,node:f});return!1};g.onMenuNodeShapes=function(a,b,c,m,f){if(!f)throw"no node passed";
new k.ContextMenu(k.VALID_SHAPES,{event:c,callback:function(a){f&&(f.shape=a,f.setDirtyCanvas(!0))},parentMenu:m,node:f});return!1};g.onMenuNodeRemove=function(a,b,c,m,f){if(!f)throw"no node passed";!1!==f.removable&&(f.graph.remove(f),f.setDirtyCanvas(!0,!0))};g.onMenuNodeClone=function(a,b,c,m,f){!1!=f.clonable&&(a=f.clone())&&(a.pos=[f.pos[0]+5,f.pos[1]+5],f.graph.add(a),f.setDirtyCanvas(!0,!0))};g.node_colors={red:{color:"#322",bgcolor:"#533",groupcolor:"#A88"},brown:{color:"#332922",bgcolor:"#593930",
groupcolor:"#b06634"},green:{color:"#232",bgcolor:"#353",groupcolor:"#8A8"},blue:{color:"#223",bgcolor:"#335",groupcolor:"#88A"},pale_blue:{color:"#2a363b",bgcolor:"#3f5159",groupcolor:"#3f789e"},cyan:{color:"#233",bgcolor:"#355",groupcolor:"#8AA"},purple:{color:"#323",bgcolor:"#535",groupcolor:"#a1309b"},yellow:{color:"#432",bgcolor:"#653",groupcolor:"#b58b2a"},black:{color:"#222",bgcolor:"#000",groupcolor:"#444"}};g.prototype.getCanvasMenuOptions=function(){var a=null;this.getMenuOptions?a=this.getMenuOptions():
(a=[{content:"Add Node",has_submenu:!0,callback:g.onMenuAdd},{content:"Add Group",callback:g.onGroupAdd}],this._graph_stack&&0<this._graph_stack.length&&a.push(null,{content:"Close subgraph",callback:this.closeSubgraph.bind(this)}));if(this.getExtraMenuOptions){var b=this.getExtraMenuOptions(this,a);b&&(a=a.concat(b))}return a};g.prototype.getNodeMenuOptions=function(a){var b=null,b=a.getMenuOptions?a.getMenuOptions(this):[{content:"Inputs",has_submenu:!0,disabled:!0,callback:g.showMenuNodeOptionalInputs},
{content:"Outputs",has_submenu:!0,disabled:!0,callback:g.showMenuNodeOptionalOutputs},null,{content:"Properties",has_submenu:!0,callback:g.onShowMenuNodeProperties},null,{content:"Title",callback:g.onShowPropertyEditor},{content:"Mode",has_submenu:!0,callback:g.onMenuNodeMode},{content:"Resize",callback:g.onResizeNode},{content:"Collapse",callback:g.onMenuNodeCollapse},{content:"Pin",callback:g.onMenuNodePin},{content:"Colors",has_submenu:!0,callback:g.onMenuNodeColors},{content:"Shapes",has_submenu:!0,
callback:g.onMenuNodeShapes},null];if(a.onGetInputs){var c=a.onGetInputs();c&&c.length&&(b[0].disabled=!1)}a.onGetOutputs&&(c=a.onGetOutputs())&&c.length&&(b[1].disabled=!1);a.getExtraMenuOptions&&(c=a.getExtraMenuOptions(this))&&(c.push(null),b=c.concat(b));!1!==a.clonable&&b.push({content:"Clone",callback:g.onMenuNodeClone});!1!==a.removable&&b.push(null,{content:"Remove",callback:g.onMenuNodeRemove});if(a.graph&&a.graph.onGetNodeMenuOptions)a.graph.onGetNodeMenuOptions(b,a);return b};g.prototype.getGroupMenuOptions=
function(a){return[{content:"Title",callback:g.onShowPropertyEditor},{content:"Color",has_submenu:!0,callback:g.onMenuNodeColors},{content:"Font size",property:"font_size",type:"Number",callback:g.onShowPropertyEditor},null,{content:"Remove",callback:g.onMenuNodeRemove}]};g.prototype.processContextMenu=function(a,b){var c=this,m=g.active_canvas.getCanvasWindow(),f=null,d={event:b,callback:function(b,f,m){if(b)if("Remove Slot"==b.content)b=b.slot,b.input?a.removeInput(b.slot):b.output&&a.removeOutput(b.slot);
else if("Disconnect Links"==b.content)b=b.slot,b.output?a.disconnectOutput(b.slot):b.input&&a.disconnectInput(b.slot);else if("Rename Slot"==b.content){b=b.slot;var l=b.input?a.getInputInfo(b.slot):a.getOutputInfo(b.slot),g=c.createDialog("<span class='name'>Name</span><input autofocus type='text'/><button>OK</button>",f),d=g.querySelector("input");d&&l&&(d.value=l.label);g.querySelector("button").addEventListener("click",function(a){d.value&&(l&&(l.label=d.value),c.setDirty(!0));g.close()})}},extra:a},
l=null;a&&(l=a.getSlotInPosition(b.canvasX,b.canvasY),g.active_node=a);l?(f=[],l&&l.output&&l.output.links&&l.output.links.length&&f.push({content:"Disconnect Links",slot:l}),f.push(l.locked?"Cannot remove":{content:"Remove Slot",slot:l}),f.push(l.nameLocked?"Cannot rename":{content:"Rename Slot",slot:l}),d.title=(l.input?l.input.type:l.output.type)||"*",l.input&&l.input.type==k.ACTION&&(d.title="Action"),l.output&&l.output.type==k.EVENT&&(d.title="Event")):a?f=this.getNodeMenuOptions(a):(f=this.getCanvasMenuOptions(),
(l=this.graph.getGroupOnPos(b.canvasX,b.canvasY))&&f.push(null,{content:"Edit Group",has_submenu:!0,submenu:{title:"Group",extra:l,options:this.getGroupMenuOptions(l)}}));f&&new k.ContextMenu(f,d,m)};this.CanvasRenderingContext2D&&(CanvasRenderingContext2D.prototype.roundRect=function(a,b,c,m,f,g){void 0===f&&(f=5);void 0===g&&(g=f);this.moveTo(a+f,b);this.lineTo(a+c-f,b);this.quadraticCurveTo(a+c,b,a+c,b+f);this.lineTo(a+c,b+m-g);this.quadraticCurveTo(a+c,b+m,a+c-g,b+m);this.lineTo(a+g,b+m);this.quadraticCurveTo(a,
b+m,a,b+m-g);this.lineTo(a,b+f);this.quadraticCurveTo(a,b,a+f,b)});k.compareObjects=function(a,b){for(var c in a)if(a[c]!=b[c])return!1;return!0};k.distance=q;k.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")+")"};k.isInsideRectangle=r;k.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)};k.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};k.overlapBounding=s;k.hex2num=function(a){"#"==a.charAt(0)&&(a=a.slice(1));a=a.toUpperCase();for(var b=Array(3),c=0,m,f,g=0;6>g;g+=2)m="0123456789ABCDEF".indexOf(a.charAt(g)),f="0123456789ABCDEF".indexOf(a.charAt(g+1)),b[c]=16*m+f,c++;return b};k.num2hex=function(a){for(var b="#",c,m,f=0;3>f;f++)c=a[f]/16,m=a[f]%16,b+="0123456789ABCDEF".charAt(c)+"0123456789ABCDEF".charAt(m);return b};t.prototype.addItem=function(a,b,c){function m(a){var b=
this.value;b&&b.has_submenu&&f.call(this,a)}function f(a){var b=this.value,f=!0;g.current_submenu&&g.current_submenu.close(a);if(c.callback){var m=c.callback.call(this,b,c,a,g,c.node);!0===m&&(f=!1)}if(b&&(b.callback&&!c.ignore_item_callbacks&&!0!==b.disabled&&(m=b.callback.call(this,b,c,a,g,c.extra),!0===m&&(f=!1)),b.submenu)){if(!b.submenu.options)throw"ContextMenu submenu needs options";new g.constructor(b.submenu.options,{callback:b.submenu.callback,event:a,parentMenu:g,ignore_item_callbacks:b.submenu.ignore_item_callbacks,
title:b.submenu.title,extra:b.submenu.extra,autoopen:c.autoopen});f=!1}f&&!g.lock&&g.close()}var g=this;c=c||{};var l=document.createElement("div");l.className="litemenu-entry submenu";var d=!1;if(null===b)l.classList.add("separator");else{l.innerHTML=b&&b.title?b.title:a;if(l.value=b)b.disabled&&(d=!0,l.classList.add("disabled")),(b.submenu||b.has_submenu)&&l.classList.add("has_submenu");"function"==typeof b?(l.dataset.value=a,l.onclick_callback=b):l.dataset.value=b;b.className&&(l.className+=" "+
b.className)}this.root.appendChild(l);d||l.addEventListener("click",f);c.autoopen&&l.addEventListener("mouseenter",m);return l};t.prototype.close=function(a,b){this.root.parentNode&&this.root.parentNode.removeChild(this.root);this.parentMenu&&!b&&(this.parentMenu.lock=!1,this.parentMenu.current_submenu=null,void 0===a?this.parentMenu.close():a&&!t.isCursorOverElement(a,this.parentMenu.root)&&t.trigger(this.parentMenu.root,"mouseleave",a));this.current_submenu&&this.current_submenu.close(a,!0)};t.trigger=
function(a,b,c,m){var f=document.createEvent("CustomEvent");f.initCustomEvent(b,!0,!0,c);f.srcElement=m;a.dispatchEvent?a.dispatchEvent(f):a.__events&&a.__events.dispatchEvent(f);return f};t.prototype.getTopMenu=function(){return this.options.parentMenu?this.options.parentMenu.getTopMenu():this};t.prototype.getFirstEvent=function(){return this.options.parentMenu?this.options.parentMenu.getFirstEvent():this.options.event};t.isCursorOverElement=function(a,b){var c=a.pageX,m=a.pageY,f=b.getBoundingClientRect();
return f?m>f.top&&m<f.top+f.height&&c>f.left&&c<f.left+f.width?!0:!1:!1};k.ContextMenu=t;k.closeAllContextMenus=function(a){a=a||window;a=a.document.querySelectorAll(".litecontextmenu");if(a.length){for(var b=[],c=0;c<a.length;c++)b.push(a[c]);for(c in b)b[c].close?b[c].close():b[c].parentNode&&b[c].parentNode.removeChild(b[c])}};k.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)))};k.getParameterNames=function(a){return(a+"").replace(/[/][/].*$/mg,"").replace(/\s+/g,"").replace(/[/][*][^/*]*[*][/]/g,"").split("){",1)[0].replace(/^[^(]*[(]/,"").replace(/=[^,]+/g,"").split(",").filter(Boolean)};Math.clamp=function(a,c,e){return c>a?c:e<a?e:a};"undefined"==
typeof window||window.requestAnimationFrame||(window.requestAnimationFrame=window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(a){window.setTimeout(a,1E3/60)})})(this);"undefined"!=typeof exports&&(exports.LiteGraph=this.LiteGraph);
a.constructor==Array?a[l]:l;null!=k&&k.constructor!==String&&(k=void 0===k.content?String(k):k.content);this.addItem(k,a[l],b);n++}f.addEventListener("mouseleave",function(a){c.lock||(f.closing_timer&&clearTimeout(f.closing_timer),f.closing_timer=setTimeout(c.close.bind(c),500))});f.addEventListener("mouseenter",function(a){f.closing_timer&&clearTimeout(f.closing_timer)});l=document;b.event&&(l=b.event.target.ownerDocument);l||(l=document);l.body.appendChild(f);n=b.left||0;l=b.top||0;if(b.event){n=
b.event.pageX-10;l=b.event.pageY-10;b.title&&(l-=20);b.parentMenu&&(n=b.parentMenu.root.getBoundingClientRect(),n=n.left+n.width);var k=document.body.getBoundingClientRect(),g=f.getBoundingClientRect();n>k.width-g.width-10&&(n=k.width-g.width-10);l>k.height-g.height-10&&(l=k.height-g.height-10)}f.style.left=n+"px";f.style.top=l+"px"}var k=u.LiteGraph={CANVAS_GRID_SIZE:10,NODE_TITLE_HEIGHT:20,NODE_SLOT_HEIGHT:15,NODE_WIDGET_HEIGHT:20,NODE_WIDTH:140,NODE_MIN_WIDTH:50,NODE_COLLAPSED_RADIUS:10,NODE_COLLAPSED_WIDTH:80,
NODE_TITLE_COLOR:"#999",NODE_TEXT_SIZE:14,NODE_TEXT_COLOR:"#AAA",NODE_SUBTEXT_SIZE:12,NODE_DEFAULT_COLOR:"#333",NODE_DEFAULT_BGCOLOR:"#444",NODE_DEFAULT_BOXCOLOR:"#666",NODE_DEFAULT_SHAPE:"box",DEFAULT_SHADOW_COLOR:"rgba(0,0,0,0.5)",DEFAULT_GROUP_FONT:24,LINK_COLOR:"#AAD",EVENT_LINK_COLOR:"#F85",CONNECTING_LINK_COLOR:"#AFA",MAX_NUMBER_OF_NODES:1E3,DEFAULT_POSITION:[100,100],VALID_SHAPES:["default","box","round","card"],BOX_SHAPE:1,ROUND_SHAPE:2,CIRCLE_SHAPE:3,CARD_SHAPE:4,ARROW_SHAPE:5,INPUT:1,OUTPUT:2,
EVENT:-1,ACTION:-1,ALWAYS:0,ON_EVENT:1,NEVER:2,ON_TRIGGER:3,UP:1,DOWN:2,LEFT:3,RIGHT:4,CENTER:5,NORMAL_TITLE:0,NO_TITLE:1,TRANSPARENT_TITLE:2,AUTOHIDE_TITLE:3,proxy:null,node_images_path:"",debug:!1,throw_errors:!0,allow_scripts:!1,registered_node_types:{},node_types_by_file_extension:{},Nodes:{},searchbox_extras:{},registerNodeType:function(a,b){if(!b.prototype)throw"Cannot register a simple object, it must be a class with a prototype";b.type=a;k.debug&&console.log("Node registered: "+a);a.split("/");
var e=b.name,c=a.lastIndexOf("/");b.category=a.substr(0,c);b.title||(b.title=e);if(b.prototype)for(var f in d.prototype)b.prototype[f]||(b.prototype[f]=d.prototype[f]);Object.defineProperty(b.prototype,"shape",{set:function(a){switch(a){case "default":delete this._shape;break;case "box":this._shape=k.BOX_SHAPE;break;case "round":this._shape=k.ROUND_SHAPE;break;case "circle":this._shape=k.CIRCLE_SHAPE;break;case "card":this._shape=k.CARD_SHAPE;break;default:this._shape=a}},get:function(a){return this._shape},
enumerable:!0});this.registered_node_types[a]=b;b.constructor.name&&(this.Nodes[e]=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},wrapFunctionAsNode:function(a,b,e,c){for(var f=Array(b.length),n="",l=k.getParameterNames(b),w=0;w<l.length;++w)n+="this.addInput('"+
l[w]+"',"+(e&&e[w]?"'"+e[w]+"'":"0")+");\n";e=Function(n+("this.addOutput('out',"+(c?"'"+c+"'":0)+");\n"));e.title=a.split("/").pop();e.desc="Generated from "+b.name;e.prototype.onExecute=function(){for(var a=0;a<f.length;++a)f[a]=this.getInputData(a);a=b.apply(this,f);this.setOutputData(0,a)};this.registerNodeType(a,e)},addNodeMethod:function(a,b){d.prototype[a]=b;for(var e in this.registered_node_types){var c=this.registered_node_types[e];c.prototype[a]&&(c.prototype["_"+a]=c.prototype[a]);c.prototype[a]=
b}},createNode:function(a,b,e){var c=this.registered_node_types[a];if(!c)return k.debug&&console.log('GraphNode type "'+a+'" not registered.'),null;b=b||c.title||a;c=new c(b);c.type=a;!c.title&&b&&(c.title=b);c.properties||(c.properties={});c.properties_info||(c.properties_info=[]);c.flags||(c.flags={});c.size||(c.size=c.computeSize());c.pos||(c.pos=k.DEFAULT_POSITION.concat());c.mode||(c.mode=k.ALWAYS);if(e)for(var f in e)c[f]=e[f];return c},getNodeType:function(a){return this.registered_node_types[a]},
getNodeTypesInCategory:function(a,b){var e=[],c;for(c in this.registered_node_types){var f=this.registered_node_types[c];b&&f.filter&&f.filter!=b||(""==a?null==f.category&&e.push(f):f.category==a&&e.push(f))}return e},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 e=[];for(b in a)e.push(b);return e},reloadNodes:function(a){var b=
document.getElementsByTagName("script"),e=[],c;for(c in b)e.push(b[c]);b=document.getElementsByTagName("head")[0];a=document.location.href+a;for(c in e){var f=e[c].src;if(f&&f.substr(0,a.length)==a)try{k.debug&&console.log("Reloading: "+f);var n=document.createElement("script");n.type="text/javascript";n.src=f;b.appendChild(n);b.removeChild(e[c])}catch(l){if(k.throw_errors)throw l;k.debug&&console.log("Error while reloading "+f)}}k.debug&&console.log("Nodes reloaded")},cloneObject:function(a,b){if(null==
a)return null;var e=JSON.parse(JSON.stringify(a));if(!b)return e;for(var c in e)b[c]=e[c];return b},isValidConnection:function(a,b){if(!a||!b||a==b||a==k.EVENT&&b==k.ACTION)return!0;a=String(a);b=String(b);a=a.toLowerCase();b=b.toLowerCase();if(-1==a.indexOf(",")&&-1==b.indexOf(","))return a==b;for(var e=a.split(","),c=b.split(","),f=0;f<e.length;++f)for(var n=0;n<c.length;++n)if(e[f]==c[n])return!0;return!1},registerSearchboxExtra:function(a,b,e){this.searchbox_extras[b]={type:a,desc:b,data:e}}};
k.getTime="undefined"!=typeof performance?performance.now.bind(performance):"undefined"!=typeof Date&&Date.now?Date.now.bind(Date):"undefined"!=typeof process?function(){var a=process.hrtime();return 0.001*a[0]+1E-6*a[1]}:function(){return(new Date).getTime()};u.LGraph=k.LGraph=h;h.supported_types=["number","string","boolean"];h.prototype.getSupportedTypes=function(){return this.supported_types||h.supported_types};h.STATUS_STOPPED=1;h.STATUS_RUNNING=2;h.prototype.clear=function(){this.stop();this.status=
h.STATUS_STOPPED;this.last_link_id=this.last_node_id=1;this._version=-1;if(this._nodes)for(var a=0;a<this._nodes.length;++a){var b=this._nodes[a];if(b.onRemoved)b.onRemoved()}this._nodes=[];this._nodes_by_id={};this._nodes_in_order=[];this._nodes_executable=null;this._groups=[];this.links={};this.iteration=0;this.config={};this.fixedtime=this.runningtime=this.globaltime=0;this.elapsed_time=this.fixedtime_lapse=0.01;this.starttime=this.last_update_time=0;this.catch_errors=!0;this.global_inputs={};
this.global_outputs={};this.change();this.sendActionToCanvas("clear")};h.prototype.attachCanvas=function(a){if(a.constructor!=g)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)};h.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))}};h.prototype.start=
function(a){if(this.status!=h.STATUS_RUNNING){this.status=h.STATUS_RUNNING;if(this.onPlayEvent)this.onPlayEvent();this.sendEventToAllNodes("onStart");this.last_update_time=this.starttime=k.getTime();a=a||0;var b=this;if(0==a&&"undefined"!=typeof window&&window.requestAnimationFrame){var e=function(){-1==b.execution_timer_id&&(window.requestAnimationFrame(e),b.runStep(1,!this.catch_errors))};this.execution_timer_id=-1;e()}else this.execution_timer_id=setInterval(function(){b.runStep(1,!this.catch_errors)},
a)}};h.prototype.stop=function(){if(this.status!=h.STATUS_STOPPED){this.status=h.STATUS_STOPPED;if(this.onStopEvent)this.onStopEvent();null!=this.execution_timer_id&&(-1!=this.execution_timer_id&&clearInterval(this.execution_timer_id),this.execution_timer_id=null);this.sendEventToAllNodes("onStop")}};h.prototype.runStep=function(a,b){a=a||1;var e=k.getTime();this.globaltime=0.001*(e-this.starttime);var c=this._nodes_executable?this._nodes_executable:this._nodes;if(c){if(b){for(var f=0;f<a;f++){for(var n=
0,l=c.length;n<l;++n){var w=c[n];if(w.mode==k.ALWAYS&&w.onExecute)w.onExecute()}this.fixedtime+=this.fixedtime_lapse;if(this.onExecuteStep)this.onExecuteStep()}if(this.onAfterExecute)this.onAfterExecute()}else try{for(f=0;f<a;f++){n=0;for(l=c.length;n<l;++n)if(w=c[n],w.mode==k.ALWAYS&&w.onExecute)w.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(k.throw_errors)throw g;k.debug&&console.log("Error during execution: "+g);this.stop()}c=k.getTime();e=c-e;0==e&&(e=1);this.execution_time=0.001*e;this.globaltime+=0.001*e;this.iteration+=1;this.elapsed_time=0.001*(c-this.last_update_time);this.last_update_time=c}};h.prototype.updateExecutionOrder=function(){this._nodes_in_order=this.computeExecutionOrder(!1);this._nodes_executable=[];for(var a=0;a<this._nodes_in_order.length;++a)this._nodes_in_order[a].onExecute&&this._nodes_executable.push(this._nodes_in_order[a])};
h.prototype.computeExecutionOrder=function(a,b){for(var e=[],c=[],f={},n={},l={},g=0,m=this._nodes.length;g<m;++g){var d=this._nodes[g];if(!a||d.onExecute){f[d.id]=d;var h=0;if(d.inputs)for(var p=0,q=d.inputs.length;p<q;p++)d.inputs[p]&&null!=d.inputs[p].link&&(h+=1);0==h?(c.push(d),b&&(d._level=1)):(b&&(d._level=0),l[d.id]=h)}}for(;0!=c.length;)if(d=c.shift(),e.push(d),delete f[d.id],d.outputs)for(g=0;g<d.outputs.length;g++)if(m=d.outputs[g],null!=m&&null!=m.links&&0!=m.links.length)for(p=0;p<m.links.length;p++)(h=
this.links[m.links[p]])&&!n[h.id]&&(q=this.getNodeById(h.target_id),null==q?n[h.id]=!0:(b&&(!q._level||q._level<=d._level)&&(q._level=d._level+1),n[h.id]=!0,l[q.id]-=1,0==l[q.id]&&c.push(q)));for(g in f)e.push(f[g]);e.length!=this._nodes.length&&k.debug&&console.warn("something went wrong, nodes missing");m=e.length;for(g=0;g<m;++g)e[g].order=g;e=e.sort(function(a,b){var e=a.constructor.priority||a.priority||0,c=b.constructor.priority||b.priority||0;return e==c?a.order-b.order:e-c});for(g=0;g<m;++g)e[g].order=
g;return e};h.prototype.getAncestors=function(a){for(var b=[],e=[a],c={};e.length;){var f=e.shift();if(f.inputs){c[f.id]||f==a||(c[f.id]=!0,b.push(f));for(var n=0;n<f.inputs.length;++n){var l=f.getInputNode(n);l&&-1==b.indexOf(l)&&e.push(l)}}}b.sort(function(a,b){return a.order-b.order});return b};h.prototype.arrange=function(a){a=a||40;for(var b=this.computeExecutionOrder(!1,!0),e=[],c=0;c<b.length;++c){var f=b[c],n=f._level||1;e[n]||(e[n]=[]);e[n].push(f)}b=a;for(c=0;c<e.length;++c)if(n=e[c]){for(var l=
100,k=a,g=0;g<n.length;++g)f=n[g],f.pos[0]=b,f.pos[1]=k,f.size[0]>l&&(l=f.size[0]),k+=f.size[1]+a;b+=l+a}this.setDirtyCanvas(!0,!0)};h.prototype.getTime=function(){return this.globaltime};h.prototype.getFixedTime=function(){return this.fixedtime};h.prototype.getElapsedTime=function(){return this.elapsed_time};h.prototype.sendEventToAllNodes=function(a,b,e){e=e||k.ALWAYS;var c=this._nodes_in_order?this._nodes_in_order:this._nodes;if(c)for(var f=0,n=c.length;f<n;++f){var l=c[f];if(l[a]&&l.mode==e)if(void 0===
b)l[a]();else if(b&&b.constructor===Array)l[a].apply(l,b);else l[a](b)}};h.prototype.sendActionToCanvas=function(a,b){if(this.list_of_graphcanvas)for(var e=0;e<this.list_of_graphcanvas.length;++e){var c=this.list_of_graphcanvas[e];c[a]&&c[a].apply(c,b)}};h.prototype.add=function(a,b){if(a)if(a.constructor===p)this._groups.push(a),this.setDirtyCanvas(!0),this.change(),a.graph=this,this._version++;else{-1!=a.id&&null!=this._nodes_by_id[a.id]&&(console.warn("LiteGraph: there is already a node with this ID, changing it"),
a.id=++this.last_node_id);if(this._nodes.length>=k.MAX_NUMBER_OF_NODES)throw"LiteGraph: max number of nodes in a graph reached";null==a.id||-1==a.id?a.id=++this.last_node_id:this.last_node_id<a.id&&(this.last_node_id=a.id);a.graph=this;this._version++;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}};h.prototype.remove=
function(a){if(a.constructor===k.LGraphGroup){var b=this._groups.indexOf(a);-1!=b&&this._groups.splice(b,1);a.graph=null;this._version++;this.setDirtyCanvas(!0,!0);this.change()}else if(null!=this._nodes_by_id[a.id]&&!a.ignore_remove){if(a.inputs)for(b=0;b<a.inputs.length;b++){var e=a.inputs[b];null!=e.link&&a.disconnectInput(b)}if(a.outputs)for(b=0;b<a.outputs.length;b++)e=a.outputs[b],null!=e.links&&e.links.length&&a.disconnectOutput(b);if(a.onRemoved)a.onRemoved();a.graph=null;this._version++;
if(this.list_of_graphcanvas)for(b=0;b<this.list_of_graphcanvas.length;++b)e=this.list_of_graphcanvas[b],e.selected_nodes[a.id]&&delete e.selected_nodes[a.id],e.node_dragged==a&&(e.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()}};h.prototype.getNodeById=function(a){return null==a?null:this._nodes_by_id[a]};h.prototype.findNodesByClass=
function(a){for(var b=[],e=0,c=this._nodes.length;e<c;++e)this._nodes[e].constructor===a&&b.push(this._nodes[e]);return b};h.prototype.findNodesByType=function(a){a=a.toLowerCase();for(var b=[],e=0,c=this._nodes.length;e<c;++e)this._nodes[e].type.toLowerCase()==a&&b.push(this._nodes[e]);return b};h.prototype.findNodesByTitle=function(a){for(var b=[],e=0,c=this._nodes.length;e<c;++e)this._nodes[e].title==a&&b.push(this._nodes[e]);return b};h.prototype.getNodeOnPos=function(a,b,e,c){e=e||this._nodes;
for(var f=e.length-1;0<=f;f--){var n=e[f];if(n.isPointInside(a,b,c))return n}return null};h.prototype.getGroupOnPos=function(a,b){for(var e=this._groups.length-1;0<=e;e--){var c=this._groups[e];if(c.isPointInside(a,b,2,!0))return c}return null};h.prototype.addGlobalInput=function(a,b,e){this.global_inputs[a]={name:a,type:b,value:e};this._version++;if(this.onGlobalInputAdded)this.onGlobalInputAdded(a,b);if(this.onGlobalsChange)this.onGlobalsChange()};h.prototype.setGlobalInputData=function(a,b){var e=
this.global_inputs[a];e&&(e.value=b)};h.prototype.setInputData=h.prototype.setGlobalInputData;h.prototype.getGlobalInputData=function(a){return(a=this.global_inputs[a])?a.value:null};h.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];this._version++;if(this.onGlobalInputRenamed)this.onGlobalInputRenamed(a,
b);if(this.onGlobalsChange)this.onGlobalsChange()}};h.prototype.changeGlobalInputType=function(a,b){if(!this.global_inputs[a])return!1;if(!this.global_inputs[a].type||this.global_inputs[a].type.toLowerCase()!=b.toLowerCase())if(this.global_inputs[a].type=b,this._version++,this.onGlobalInputTypeChanged)this.onGlobalInputTypeChanged(a,b)};h.prototype.removeGlobalInput=function(a){if(!this.global_inputs[a])return!1;delete this.global_inputs[a];this._version++;if(this.onGlobalInputRemoved)this.onGlobalInputRemoved(a);
if(this.onGlobalsChange)this.onGlobalsChange();return!0};h.prototype.addGlobalOutput=function(a,b,e){this.global_outputs[a]={name:a,type:b,value:e};this._version++;if(this.onGlobalOutputAdded)this.onGlobalOutputAdded(a,b);if(this.onGlobalsChange)this.onGlobalsChange()};h.prototype.setGlobalOutputData=function(a,b){var e=this.global_outputs[a];e&&(e.value=b)};h.prototype.getGlobalOutputData=function(a){return(a=this.global_outputs[a])?a.value:null};h.prototype.getOutputData=h.prototype.getGlobalOutputData;
h.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];this._version++;if(this.onGlobalOutputRenamed)this.onGlobalOutputRenamed(a,b);if(this.onGlobalsChange)this.onGlobalsChange()};h.prototype.changeGlobalOutputType=function(a,b){if(!this.global_outputs[a])return!1;if(!this.global_outputs[a].type||this.global_outputs[a].type.toLowerCase()!=
b.toLowerCase())if(this.global_outputs[a].type=b,this._version++,this.onGlobalOutputTypeChanged)this.onGlobalOutputTypeChanged(a,b)};h.prototype.removeGlobalOutput=function(a){if(!this.global_outputs[a])return!1;delete this.global_outputs[a];this._version++;if(this.onGlobalOutputRemoved)this.onGlobalOutputRemoved(a);if(this.onGlobalsChange)this.onGlobalsChange();return!0};h.prototype.triggerInput=function(a,b){for(var e=this.findNodesByTitle(a),c=0;c<e.length;++c)e[c].onTrigger(b)};h.prototype.setCallback=
function(a,b){for(var e=this.findNodesByTitle(a),c=0;c<e.length;++c)e[c].setTrigger(b)};h.prototype.connectionChange=function(a){this.updateExecutionOrder();if(this.onConnectionChange)this.onConnectionChange(a);this._version++;this.sendActionToCanvas("onConnectionChange")};h.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};h.prototype.change=function(){k.debug&&console.log("Graph changed");
this.sendActionToCanvas("setDirty",[!0,!0]);if(this.on_change)this.on_change(this)};h.prototype.setDirtyCanvas=function(a,b){this.sendActionToCanvas("setDirty",[a,b])};h.prototype.serialize=function(){for(var a=[],b=0,e=this._nodes.length;b<e;++b)a.push(this._nodes[b].serialize());e=[];for(b in this.links){var c=this.links[b];e.push([c.id,c.origin_id,c.origin_slot,c.target_id,c.target_slot,c.type])}c=[];for(b=0;b<this._groups.length;++b)c.push(this._groups[b].serialize());return{last_node_id:this.last_node_id,
last_link_id:this.last_link_id,nodes:a,links:e,groups:c,config:this.config}};h.prototype.configure=function(a,b){if(a){b||this.clear();var e=a.nodes;if(a.links&&a.links.constructor===Array){for(var c=[],f=0;f<a.links.length;++f){var n=a.links[f];c[n[0]]={id:n[0],origin_id:n[1],origin_slot:n[2],target_id:n[3],target_slot:n[4],type:n[5]}}a.links=c}for(f in a)this[f]=a[f];c=!1;this._nodes=[];if(e){f=0;for(n=e.length;f<n;++f){var l=e[f],g=k.createNode(l.type,l.title);g?(g.id=l.id,this.add(g,!0)):(k.debug&&
console.log("Node not found: "+l.type),c=!0)}f=0;for(n=e.length;f<n;++f)l=e[f],(g=this.getNodeById(l.id))&&g.configure(l)}this._groups.length=0;if(a.groups)for(f=0;f<a.groups.length;++f)e=new k.LGraphGroup,e.configure(a.groups[f]),this.add(e);this.updateExecutionOrder();this._version++;this.setDirtyCanvas(!0,!0);return c}};h.prototype.load=function(a){var b=this,e=new XMLHttpRequest;e.open("GET",a,!0);e.send(null);e.onload=function(a){200!==e.status?console.error("Error loading graph:",e.status,e.response):
(a=JSON.parse(e.response),b.configure(a))};e.onerror=function(a){console.error("Error loading graph:",a)}};h.prototype.onNodeTrace=function(a,b,e){};u.LGraphNode=k.LGraphNode=d;d.prototype._ctor=function(a){this.title=a||"Unnamed";this.size=[k.NODE_WIDTH,60];this.graph=null;this._pos=new Float32Array(10,10);Object.defineProperty(this,"pos",{set:function(a){!a||2>a.length||(this._pos[0]=a[0],this._pos[1]=a[1])},get:function(){return this._pos},enumerable:!0});this.id=-1;this.type=null;this.inputs=
[];this.outputs=[];this.connections=[];this.properties={};this.properties_info=[];this.flags={}};d.prototype.configure=function(a){this.graph&&this.graph._version++;for(var b in a)if("console"!=b)if("properties"==b)for(var e in a.properties){if(this.properties[e]=a.properties[e],this.onPropertyChanged)this.onPropertyChanged(e,a.properties[e])}else null!=a[b]&&("object"==typeof a[b]?this[b]&&this[b].configure?this[b].configure(a[b]):this[b]=k.cloneObject(a[b],this[b]):this[b]=a[b]);a.title||(this.title=
this.constructor.title);if(this.onConnectionsChange){if(this.inputs)for(var c=0;c<this.inputs.length;++c){e=this.inputs[c];var f=this.graph?this.graph.links[e.link]:null;this.onConnectionsChange(k.INPUT,c,!0,f,e)}if(this.outputs)for(c=0;c<this.outputs.length;++c)if(e=this.outputs[c],e.links)for(b=0;b<e.links.length;++b)f=this.graph?this.graph.links[e.links[b]]:null,this.onConnectionsChange(k.OUTPUT,c,!0,f,e)}for(c in this.inputs)e=this.inputs[c],e.link&&e.link.length&&(f=e.link,"object"==typeof f&&
(e.link=f[0],this.graph&&(this.graph.links[f[0]]={id:f[0],origin_id:f[1],origin_slot:f[2],target_id:f[3],target_slot:f[4]})));for(c in this.outputs)if(e=this.outputs[c],e.links&&0!=e.links.length)for(b in e.links)f=e.links[b],"object"==typeof f&&(e.links[b]=f[0]);if(this.onConfigure)this.onConfigure(a)};d.prototype.serialize=function(){var a={id:this.id,type:this.type,pos:this.pos,size:this.size,flags:k.cloneObject(this.flags),mode:this.mode};this.inputs&&(a.inputs=this.inputs);if(this.outputs){for(var b=
0;b<this.outputs.length;b++)delete this.outputs[b]._data;a.outputs=this.outputs}this.title&&this.title!=this.constructor.title&&(a.title=this.title);this.properties&&(a.properties=k.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);this.onSerialize&&this.onSerialize(a)&&console.warn("node onSerialize shouldnt return anything, data should be stored in the object pass in the first parameter");
return a};d.prototype.clone=function(){var a=k.createNode(this.type),b=k.cloneObject(this.serialize());if(b.inputs)for(var e=0;e<b.inputs.length;++e)b.inputs[e].link=null;if(b.outputs)for(e=0;e<b.outputs.length;++e)b.outputs[e].links&&(b.outputs[e].links.length=0);delete b.id;a.configure(b);return a};d.prototype.toString=function(){return JSON.stringify(this.serialize())};d.prototype.getTitle=function(){return this.title||this.constructor.title};d.prototype.setOutputData=function(a,b){if(this.outputs&&
!(-1==a||a>=this.outputs.length)){var e=this.outputs[a];if(e&&(e._data=b,this.outputs[a].links))for(e=0;e<this.outputs[a].links.length;e++)this.graph.links[this.outputs[a].links[e]].data=b}};d.prototype.getInputData=function(a,b){if(this.inputs&&!(a>=this.inputs.length||null==this.inputs[a].link)){var e=this.graph.links[this.inputs[a].link];if(!e)return null;if(!b)return e.data;var c=this.graph.getNodeById(e.origin_id);if(!c)return e.data;if(c.updateOutputData)c.updateOutputData(e.origin_slot);else if(c.onExecute)c.onExecute();
return e.data}};d.prototype.getInputDataByName=function(a,b){var e=this.findInputSlot(a);return-1==e?null:this.getInputData(e,b)};d.prototype.isInputConnected=function(a){return this.inputs?a<this.inputs.length&&null!=this.inputs[a].link:!1};d.prototype.getInputInfo=function(a){return this.inputs?a<this.inputs.length?this.inputs[a]:null:null};d.prototype.getInputNode=function(a){if(!this.inputs||a>=this.inputs.length)return null;a=this.inputs[a];return a&&null!==a.link?(a=this.graph.links[a.link])?
this.graph.getNodeById(a.origin_id):null:null};d.prototype.getInputOrProperty=function(a){if(!this.inputs||!this.inputs.length)return this.properties?this.properties[a]:null;for(var b=0,e=this.inputs.length;b<e;++b)if(a==this.inputs[b].name)return(a=this.graph.links[this.inputs[b].link])?a.data:null;return this.properties[a]};d.prototype.getOutputData=function(a){return!this.outputs||a>=this.outputs.length?null:this.outputs[a]._data};d.prototype.getOutputInfo=function(a){return this.outputs?a<this.outputs.length?
this.outputs[a]:null:null};d.prototype.isOutputConnected=function(a){return this.outputs?a<this.outputs.length&&this.outputs[a].links&&this.outputs[a].links.length:!1};d.prototype.isAnyOutputConnected=function(){if(!this.outputs)return!1;for(var a=0;a<this.outputs.length;++a)if(this.outputs[a].links&&this.outputs[a].links.length)return!0;return!1};d.prototype.getOutputNodes=function(a){if(!this.outputs||0==this.outputs.length||a>=this.outputs.length)return null;a=this.outputs[a];if(!a.links||0==a.links.length)return null;
for(var b=[],e=0;e<a.links.length;e++){var c=this.graph.links[a.links[e]];c&&(c=this.graph.getNodeById(c.target_id))&&b.push(c)}return b};d.prototype.trigger=function(a,b){if(this.outputs&&this.outputs.length){this.graph&&(this.graph._last_trigger_time=k.getTime());for(var e=0;e<this.outputs.length;++e){var c=this.outputs[e];!c||c.type!==k.EVENT||a&&c.name!=a||this.triggerSlot(e,b)}}};d.prototype.triggerSlot=function(a,b,e){if(this.outputs&&(a=this.outputs[a])&&(a=a.links)&&a.length){this.graph&&
(this.graph._last_trigger_time=k.getTime());for(var c=0;c<a.length;++c){var f=a[c];if(null==e||e==f){var n=this.graph.links[a[c]];if(n&&(n._last_time=k.getTime(),f=this.graph.getNodeById(n.target_id)))if(n=f.inputs[n.target_slot],f.onAction)f.onAction(n.name,b);else if(f.mode===k.ON_TRIGGER&&f.onExecute)f.onExecute(b)}}}};d.prototype.addProperty=function(a,b,e,c){e={name:a,type:e,default_value:b};if(c)for(var f in c)e[f]=c[f];this.properties_info||(this.properties_info=[]);this.properties_info.push(e);
this.properties||(this.properties={});this.properties[a]=b;return e};d.prototype.addOutput=function(a,b,e){a={name:a,type:b,links:null};if(e)for(var c in e)a[c]=e[c];this.outputs||(this.outputs=[]);this.outputs.push(a);if(this.onOutputAdded)this.onOutputAdded(a);this.size=this.computeSize();this.setDirtyCanvas(!0,!0);return a};d.prototype.addOutputs=function(a){for(var b=0;b<a.length;++b){var e=a[b],c={name:e[0],type:e[1],link:null};if(a[2])for(var f in e[2])c[f]=e[2][f];this.outputs||(this.outputs=
[]);this.outputs.push(c);if(this.onOutputAdded)this.onOutputAdded(c)}this.size=this.computeSize();this.setDirtyCanvas(!0,!0)};d.prototype.removeOutput=function(a){this.disconnectOutput(a);this.outputs.splice(a,1);for(var b=a;b<this.outputs.length;++b)if(this.outputs[b]&&this.outputs[b].links)for(var e=this.outputs[b].links,c=0;c<e.length;++c){var f=this.graph.links[e[c]];f&&(f.origin_slot-=1)}this.size=this.computeSize();if(this.onOutputRemoved)this.onOutputRemoved(a);this.setDirtyCanvas(!0,!0)};
d.prototype.addInput=function(a,b,e){a={name:a,type:b||0,link:null};if(e)for(var c in e)a[c]=e[c];this.inputs||(this.inputs=[]);this.inputs.push(a);this.size=this.computeSize();if(this.onInputAdded)this.onInputAdded(a);this.setDirtyCanvas(!0,!0);return a};d.prototype.addInputs=function(a){for(var b=0;b<a.length;++b){var e=a[b],c={name:e[0],type:e[1],link:null};if(a[2])for(var f in e[2])c[f]=e[2][f];this.inputs||(this.inputs=[]);this.inputs.push(c);if(this.onInputAdded)this.onInputAdded(c)}this.size=
this.computeSize();this.setDirtyCanvas(!0,!0)};d.prototype.removeInput=function(a){this.disconnectInput(a);this.inputs.splice(a,1);for(var b=a;b<this.inputs.length;++b)if(this.inputs[b]){var e=this.graph.links[this.inputs[b].link];e&&(e.target_slot-=1)}this.size=this.computeSize();if(this.onInputRemoved)this.onInputRemoved(a);this.setDirtyCanvas(!0,!0)};d.prototype.addConnection=function(a,b,e,c){a={name:a,type:b,pos:e,direction:c,links:null};this.connections.push(a);return a};d.prototype.computeSize=
function(a,b){function e(a){return a?n*a.length*0.6:0}var c=Math.max(this.inputs?this.inputs.length:1,this.outputs?this.outputs.length:1),f=b||new Float32Array([0,0]),c=Math.max(c,1),n=k.NODE_TEXT_SIZE;f[1]=(this.constructor.slot_start_y||0)+c*(n+1)+4;this.widgets&&this.widgets.length&&(f[1]+=this.widgets.length*(k.NODE_WIDGET_HEIGHT+4)+8);var c=e(this.title),l=0,g=0;if(this.inputs)for(var d=0,m=this.inputs.length;d<m;++d){var h=this.inputs[d],h=h.label||h.name||"",h=e(h);l<h&&(l=h)}if(this.outputs)for(d=
0,m=this.outputs.length;d<m;++d)h=this.outputs[d],h=h.label||h.name||"",h=e(h),g<h&&(g=h);f[0]=Math.max(l+g+10,c);f[0]=Math.max(f[0],k.NODE_WIDTH);this.widgets&&this.widgets.length&&(f[0]=Math.max(f[0],1.5*k.NODE_WIDTH));if(this.onResize)this.onResize(f);return f};d.prototype.addWidget=function(a,b,e,c,f){this.widgets||(this.widgets=[]);b={type:a.toLowerCase(),name:b,value:e,callback:c,options:f||{}};void 0!==b.options.y&&(b.y=b.options.y);c||console.warn("LiteGraph addWidget('button',...) without a callback");
if("combo"==a&&!b.options.values)throw"LiteGraph addWidget('combo',...) requires to pass values in options: { values:['red','blue'] }";this.widgets.push(b);return b};d.prototype.getBounding=function(a){a=a||new Float32Array(4);a[0]=this.pos[0]-4;a[1]=this.pos[1]-k.NODE_TITLE_HEIGHT;a[2]=this.size[0]+4;a[3]=this.size[1]+k.NODE_TITLE_HEIGHT;return a};d.prototype.isPointInside=function(a,b,e,c){e=e||0;var f=this.graph&&this.graph.isLive()?0:20;c&&(f=0);if(this.flags&&this.flags.collapsed){if(r(a,b,this.pos[0]-
e,this.pos[1]-k.NODE_TITLE_HEIGHT-e,(this._collapsed_width||k.NODE_COLLAPSED_WIDTH)+2*e,k.NODE_TITLE_HEIGHT+2*e))return!0}else if(this.pos[0]-4-e<a&&this.pos[0]+this.size[0]+4+e>a&&this.pos[1]-f-e<b&&this.pos[1]+this.size[1]+e>b)return!0;return!1};d.prototype.getSlotInPosition=function(a,b){if(this.inputs)for(var e=0,c=this.inputs.length;e<c;++e){var f=this.inputs[e],n=this.getConnectionPos(!0,e);if(r(a,b,n[0]-10,n[1]-5,20,10))return{input:f,slot:e,link_pos:n,locked:f.locked}}if(this.outputs)for(e=
0,c=this.outputs.length;e<c;++e)if(f=this.outputs[e],n=this.getConnectionPos(!1,e),r(a,b,n[0]-10,n[1]-5,20,10))return{output:f,slot:e,link_pos:n,locked:f.locked};return null};d.prototype.findInputSlot=function(a){if(!this.inputs)return-1;for(var b=0,e=this.inputs.length;b<e;++b)if(a==this.inputs[b].name)return b;return-1};d.prototype.findOutputSlot=function(a){if(!this.outputs)return-1;for(var b=0,e=this.outputs.length;b<e;++b)if(a==this.outputs[b].name)return b;return-1};d.prototype.connect=function(a,
b,e){e=e||0;if(!this.graph)return console.log("Connect: Error, node doesnt belong to any graph. Nodes must be added first to a graph before connecting them."),!1;if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return k.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.outputs||a>=this.outputs.length)return k.debug&&console.log("Connect: Error, slot number not found"),!1;b&&b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"target node is null";if(b==
this)return!1;if(e.constructor===String){if(e=b.findInputSlot(e),-1==e)return k.debug&&console.log("Connect: Error, no slot of name "+e),!1}else{if(e===k.EVENT)return!1;if(!b.inputs||e>=b.inputs.length)return k.debug&&console.log("Connect: Error, slot number not found"),!1}null!=b.inputs[e].link&&b.disconnectInput(e);var c=this.outputs[a];if(b.onConnectInput&&!1===b.onConnectInput(e,c.type,c))return!1;var f=b.inputs[e];if(k.isValidConnection(c.type,f.type)){var n={id:this.graph.last_link_id++,type:f.type,
origin_id:this.id,origin_slot:a,target_id:b.id,target_slot:e};this.graph.links[n.id]=n;null==c.links&&(c.links=[]);c.links.push(n.id);b.inputs[e].link=n.id;this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(k.OUTPUT,a,!0,n,c);if(b.onConnectionsChange)b.onConnectionsChange(k.INPUT,e,!0,n,f);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(k.INPUT,b,e,this,a),this.graph.onNodeConnectionChange(k.OUTPUT,this,a,b,e))}this.setDirtyCanvas(!1,
!0);this.graph.connectionChange(this);return!0};d.prototype.disconnectOutput=function(a,b){if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return k.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.outputs||a>=this.outputs.length)return k.debug&&console.log("Connect: Error, slot number not found"),!1;var e=this.outputs[a];if(!e||!e.links||0==e.links.length)return!1;if(b){b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"Target Node not found";for(var c=
0,f=e.links.length;c<f;c++){var n=e.links[c],l=this.graph.links[n];if(l.target_id==b.id){e.links.splice(c,1);var g=b.inputs[l.target_slot];g.link=null;delete this.graph.links[n];this.graph&&this.graph._version++;if(b.onConnectionsChange)b.onConnectionsChange(k.INPUT,l.target_slot,!1,l,g);if(this.onConnectionsChange)this.onConnectionsChange(k.OUTPUT,a,!1,l,e);if(this.graph&&this.graph.onNodeConnectionChange)this.graph.onNodeConnectionChange(k.OUTPUT,this,a);this.graph&&this.graph.onNodeConnectionChange&&
(this.graph.onNodeConnectionChange(k.OUTPUT,this,a),this.graph.onNodeConnectionChange(k.INPUT,b,l.target_slot));break}}}else{c=0;for(f=e.links.length;c<f;c++)if(n=e.links[c],l=this.graph.links[n]){b=this.graph.getNodeById(l.target_id);this.graph&&this.graph._version++;if(b){g=b.inputs[l.target_slot];g.link=null;if(b.onConnectionsChange)b.onConnectionsChange(k.INPUT,l.target_slot,!1,l,g);if(this.graph&&this.graph.onNodeConnectionChange)this.graph.onNodeConnectionChange(k.INPUT,b,l.target_slot)}delete this.graph.links[n];
if(this.onConnectionsChange)this.onConnectionsChange(k.OUTPUT,a,!1,l,e);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(k.OUTPUT,this,a),this.graph.onNodeConnectionChange(k.INPUT,b,l.target_slot))}e.links=null}this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this);return!0};d.prototype.disconnectInput=function(a){if(a.constructor===String){if(a=this.findInputSlot(a),-1==a)return k.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.inputs||
a>=this.inputs.length)return k.debug&&console.log("Connect: Error, slot number not found"),!1;var b=this.inputs[a];if(!b)return!1;var e=this.inputs[a].link;this.inputs[a].link=null;var c=this.graph.links[e];if(c){var f=this.graph.getNodeById(c.origin_id);if(!f)return!1;var n=f.outputs[c.origin_slot];if(!n||!n.links||0==n.links.length)return!1;for(var l=0,g=n.links.length;l<g;l++)if(n.links[l]==e){n.links.splice(l,1);break}delete this.graph.links[e];this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(k.INPUT,
a,!1,c,b);if(f.onConnectionsChange)f.onConnectionsChange(k.OUTPUT,l,!1,c,n);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(k.OUTPUT,f,l),this.graph.onNodeConnectionChange(k.INPUT,this,a))}this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this);return!0};d.prototype.getConnectionPos=function(a,b){return this.flags.collapsed?a?[this.pos[0],this.pos[1]-0.5*k.NODE_TITLE_HEIGHT]:[this.pos[0]+(this._collapsed_width||k.NODE_COLLAPSED_WIDTH),this.pos[1]-0.5*k.NODE_TITLE_HEIGHT]:
a&&-1==b?[this.pos[0]+10,this.pos[1]+10]:a&&this.inputs&&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&&this.outputs.length>b&&this.outputs[b].pos?[this.pos[0]+this.outputs[b].pos[0],this.pos[1]+this.outputs[b].pos[1]]:this.flags.horizontal?a?[this.pos[0]+this.size[0]/this.inputs.length*(b+0.5),this.pos[1]-k.NODE_TITLE_HEIGHT]:[this.pos[0]+this.size[0]/this.outputs.length*(b+0.5),this.pos[1]+this.size[1]]:a?[this.pos[0],
this.pos[1]+10+b*k.NODE_SLOT_HEIGHT+(this.constructor.slot_start_y||0)]:[this.pos[0]+this.size[0]+1,this.pos[1]+10+b*k.NODE_SLOT_HEIGHT+(this.constructor.slot_start_y||0)]};d.prototype.alignToGrid=function(){this.pos[0]=k.CANVAS_GRID_SIZE*Math.round(this.pos[0]/k.CANVAS_GRID_SIZE);this.pos[1]=k.CANVAS_GRID_SIZE*Math.round(this.pos[1]/k.CANVAS_GRID_SIZE)};d.prototype.trace=function(a){this.console||(this.console=[]);this.console.push(a);this.console.length>d.MAX_CONSOLE&&this.console.shift();this.graph.onNodeTrace(this,
a)};d.prototype.setDirtyCanvas=function(a,b){this.graph&&this.graph.sendActionToCanvas("setDirty",[a,b])};d.prototype.loadImage=function(a){var b=new Image;b.src=k.node_images_path+a;b.ready=!1;var e=this;b.onload=function(){this.ready=!0;e.setDirtyCanvas(!0)};return b};d.prototype.captureInput=function(a){if(this.graph&&this.graph.list_of_graphcanvas)for(var b=this.graph.list_of_graphcanvas,e=0;e<b.length;++e){var c=b[e];if(a||c.node_capturing_input==this)c.node_capturing_input=a?this:null}};d.prototype.collapse=
function(a){this.graph._version++;if(!1!==this.constructor.collapsable||a)this.flags.collapsed=this.flags.collapsed?!1:!0,this.setDirtyCanvas(!0,!0)};d.prototype.pin=function(a){this.graph._version++;this.flags.pinned=void 0===a?!this.flags.pinned:a};d.prototype.localToScreen=function(a,b,e){return[(a+this.pos[0])*e.scale+e.offset[0],(b+this.pos[1])*e.scale+e.offset[1]]};u.LGraphGroup=k.LGraphGroup=p;p.prototype._ctor=function(a){this.title=a||"Group";this.font_size=24;this.color=g.node_colors.pale_blue?
g.node_colors.pale_blue.groupcolor:"#AAA";this._bounding=new Float32Array([10,10,140,80]);this._pos=this._bounding.subarray(0,2);this._size=this._bounding.subarray(2,4);this._nodes=[];this.graph=null;Object.defineProperty(this,"pos",{set:function(a){!a||2>a.length||(this._pos[0]=a[0],this._pos[1]=a[1])},get:function(){return this._pos},enumerable:!0});Object.defineProperty(this,"size",{set:function(a){!a||2>a.length||(this._size[0]=Math.max(140,a[0]),this._size[1]=Math.max(80,a[1]))},get:function(){return this._size},
enumerable:!0})};p.prototype.configure=function(a){this.title=a.title;this._bounding.set(a.bounding);this.color=a.color;this.font=a.font};p.prototype.serialize=function(){var a=this._bounding;return{title:this.title,bounding:[Math.round(a[0]),Math.round(a[1]),Math.round(a[2]),Math.round(a[3])],color:this.color,font:this.font}};p.prototype.move=function(a,b,e){this._pos[0]+=a;this._pos[1]+=b;if(!e)for(e=0;e<this._nodes.length;++e){var c=this._nodes[e];c.pos[0]+=a;c.pos[1]+=b}};p.prototype.recomputeInsideNodes=
function(){this._nodes.length=0;for(var a=this.graph._nodes,b=new Float32Array(4),e=0;e<a.length;++e){var c=a[e];c.getBounding(b);s(this._bounding,b)&&this._nodes.push(c)}};p.prototype.isPointInside=d.prototype.isPointInside;p.prototype.setDirtyCanvas=d.prototype.setDirtyCanvas;u.LGraphCanvas=k.LGraphCanvas=g;g.link_type_colors={"-1":"#F85",number:"#AAA",node:"#DCA"};g.gradients={};g.prototype.clear=function(){this.fps=this.render_time=this.last_draw_time=this.frame=0;this.scale=1;this.offset=[0,
0];this.dragging_rectangle=null;this.selected_nodes={};this.selected_group=null;this.visible_nodes=[];this.connecting_node=this.node_capturing_input=this.node_over=this.node_dragged=null;this.highlighted_links={};this.dirty_bgcanvas=this.dirty_canvas=!0;this.node_widget=this.node_in_panel=this.dirty_area=null;this.last_mouse=[0,0];this.last_mouseclick=0;this.visible_area.set([0,0,0,0]);if(this.onClear)this.onClear()};g.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)))};g.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)};g.prototype.closeSubgraph=function(){if(this._graph_stack&&0!=this._graph_stack.length){var a=this._graph_stack.pop();this.selected_nodes={};this.highlighted_links=
{};a.attachCanvas(this);this.setDirty(!0,!0)}};g.prototype.setCanvas=function(a,b){if(a&&a.constructor===String&&(a=document.getElementById(a),!a))throw"Error creating LiteGraph canvas: Canvas not found";if(a!==this.canvas&&(!a&&this.canvas&&(b||this.unbindEvents()),this.canvas=a)){a.className+=" lgraphcanvas";a.data=this;this.bgcanvas=null;this.bgcanvas||(this.bgcanvas=document.createElement("canvas"),this.bgcanvas.width=this.canvas.width,this.bgcanvas.height=this.canvas.height);if(null==a.getContext){if("canvas"!=
a.localName)throw"Element supplied for LGraphCanvas must be a <canvas> element, you passed a "+a.localName;throw"This browser doesnt support Canvas";}null==(this.ctx=a.getContext("2d"))&&(a.webgl_enabled||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()}};g.prototype._doNothing=function(a){a.preventDefault();return!1};g.prototype._doReturnTrue=
function(a){a.preventDefault();return!0};g.prototype.bindEvents=function(){if(this._events_binded)console.warn("LGraphCanvas: events already binded");else{var a=this.canvas,b=this.getCanvasWindow().document;this._mousedown_callback=this.processMouseDown.bind(this);this._mousewheel_callback=this.processMouseWheel.bind(this);a.addEventListener("mousedown",this._mousedown_callback,!0);a.addEventListener("mousemove",this._mousemove_callback);a.addEventListener("mousewheel",this._mousewheel_callback,!1);
a.addEventListener("contextmenu",this._doNothing);a.addEventListener("DOMMouseScroll",this._mousewheel_callback,!1);a.addEventListener("touchstart",this.touchHandler,!0);a.addEventListener("touchmove",this.touchHandler,!0);a.addEventListener("touchend",this.touchHandler,!0);a.addEventListener("touchcancel",this.touchHandler,!0);this._key_callback=this.processKey.bind(this);a.addEventListener("keydown",this._key_callback,!0);b.addEventListener("keyup",this._key_callback,!0);this._ondrop_callback=this.processDrop.bind(this);
a.addEventListener("dragover",this._doNothing,!1);a.addEventListener("dragend",this._doNothing,!1);a.addEventListener("drop",this._ondrop_callback,!1);a.addEventListener("dragenter",this._doReturnTrue,!1);this._events_binded=!0}};g.prototype.unbindEvents=function(){if(this._events_binded){var a=this.getCanvasWindow().document;this.canvas.removeEventListener("mousedown",this._mousedown_callback);this.canvas.removeEventListener("mousewheel",this._mousewheel_callback);this.canvas.removeEventListener("DOMMouseScroll",
this._mousewheel_callback);this.canvas.removeEventListener("keydown",this._key_callback);a.removeEventListener("keyup",this._key_callback);this.canvas.removeEventListener("contextmenu",this._doNothing);this.canvas.removeEventListener("drop",this._ondrop_callback);this.canvas.removeEventListener("dragenter",this._doReturnTrue);this.canvas.removeEventListener("touchstart",this.touchHandler);this.canvas.removeEventListener("touchmove",this.touchHandler);this.canvas.removeEventListener("touchend",this.touchHandler);
this.canvas.removeEventListener("touchcancel",this.touchHandler);this._ondrop_callback=this._key_callback=this._mousewheel_callback=this._mousedown_callback=null;this._events_binded=!1}else console.warn("LGraphCanvas: no events binded")};g.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()};g.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;this.canvas.webgl_enabled=!0};g.prototype.setDirty=function(a,b){a&&(this.dirty_canvas=!0);b&&(this.dirty_bgcanvas=!0)};g.prototype.getCanvasWindow=function(){if(!this.canvas)return window;var a=this.canvas.ownerDocument;return a.defaultView||a.parentWindow};g.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))};g.prototype.stopRendering=function(){this.is_rendering=!1};g.prototype.processMouseDown=function(a){if(this.graph){this.adjustMouseEvent(a);var b=this.getCanvasWindow();g.active_canvas=this;this.canvas.removeEventListener("mousemove",this._mousemove_callback);b.document.addEventListener("mousemove",this._mousemove_callback,!0);b.document.addEventListener("mouseup",
this._mouseup_callback,!0);var e=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes,5),c=!1,f=300>k.getTime()-this.last_mouseclick;this.canvas_mouse[0]=a.canvasX;this.canvas_mouse[1]=a.canvasY;k.closeAllContextMenus(b);if(!this.onMouse||!0!=this.onMouse(a)){if(1==a.which){a.ctrlKey&&(this.dragging_rectangle=new Float32Array(4),this.dragging_rectangle[0]=a.canvasX,this.dragging_rectangle[1]=a.canvasY,this.dragging_rectangle[2]=1,this.dragging_rectangle[3]=1,c=!0);var n=!1;if(e&&this.allow_interaction&&
!c){this.live_mode||e.flags.pinned||this.bringToFront(e);if(!this.connecting_node&&!e.flags.collapsed&&!this.live_mode)if(!c&&!1!==e.flags.resizable&&r(a.canvasX,a.canvasY,e.pos[0]+e.size[0]-5,e.pos[1]+e.size[1]-5,10,10))this.resizing_node=e,this.canvas.style.cursor="se-resize",c=!0;else{if(e.outputs)for(var l=0,d=e.outputs.length;l<d;++l){var m=e.outputs[l],h=e.getConnectionPos(!1,l);if(r(a.canvasX,a.canvasY,h[0]-15,h[1]-10,30,20)){this.connecting_node=e;this.connecting_output=m;this.connecting_pos=
e.getConnectionPos(!1,l);this.connecting_slot=l;a.shiftKey&&e.disconnectOutput(l);if(f){if(e.onOutputDblClick)e.onOutputDblClick(l,a)}else if(e.onOutputClick)e.onOutputClick(l,a);c=!0;break}}if(e.inputs)for(l=0,d=e.inputs.length;l<d;++l)if(m=e.inputs[l],h=e.getConnectionPos(!0,l),r(a.canvasX,a.canvasY,h[0]-15,h[1]-10,30,20)){if(f){if(e.onInputDblClick)e.onInputDblClick(l,a)}else if(e.onInputClick)e.onInputClick(l,a);if(null!==m.link){c=this.graph.links[m.link];e.disconnectInput(l);if(this.allow_reconnect_links||
a.shiftKey)this.connecting_node=this.graph._nodes_by_id[c.origin_id],this.connecting_slot=c.origin_slot,this.connecting_output=this.connecting_node.outputs[this.connecting_slot],this.connecting_pos=this.connecting_node.getConnectionPos(!1,this.connecting_slot);c=this.dirty_bgcanvas=!0}}}!c&&r(a.canvasX,a.canvasY,e.pos[0],e.pos[1]-k.NODE_TITLE_HEIGHT,k.NODE_TITLE_HEIGHT,k.NODE_TITLE_HEIGHT)&&(e.collapse(),c=!0);if(!c){l=!1;if(d=this.processNodeWidgets(e,this.canvas_mouse,a))l=!0,this.node_widget=[e,
d];if(f&&this.selected_nodes[e.id]){if(e.onDblClick)e.onDblClick(a,[a.canvasX-e.pos[0],a.canvasY-e.pos[1]],graphcanvas);this.processNodeDblClicked(e);l=!0}e.onMouseDown&&e.onMouseDown(a,[a.canvasX-e.pos[0],a.canvasY-e.pos[1]],this)?l=!0:this.live_mode&&(l=n=!0);l||(this.allow_dragnodes&&(this.node_dragged=e),this.selected_nodes[e.id]||this.processNodeSelected(e,a));this.dirty_canvas=!0}}else this.selected_group=this.graph.getGroupOnPos(a.canvasX,a.canvasY),this.selected_group_resizing=!1,this.selected_group&&
(a.ctrlKey&&(this.dragging_rectangle=null),10>q([a.canvasX,a.canvasY],[this.selected_group.pos[0]+this.selected_group.size[0],this.selected_group.pos[1]+this.selected_group.size[1]])*this.scale?this.selected_group_resizing=!0:this.selected_group.recomputeInsideNodes()),f&&this.showSearchBox(a),n=!0;!c&&n&&this.allow_dragcanvas&&(this.dragging_canvas=!0)}else 2!=a.which&&3==a.which&&this.processContextMenu(e,a);this.last_mouse[0]=a.localX;this.last_mouse[1]=a.localY;this.last_mouseclick=k.getTime();
this.last_mouse_dragging=!0;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}}};g.prototype.processMouseMove=function(a){this.autoresize&&this.resize();if(this.graph){g.active_canvas=this;this.adjustMouseEvent(a);var b=[a.localX,a.localY],e=[b[0]-this.last_mouse[0],b[1]-this.last_mouse[1]];this.last_mouse=
b;this.canvas_mouse[0]=a.canvasX;this.canvas_mouse[1]=a.canvasY;a.dragging=this.last_mouse_dragging;this.node_widget&&(this.processNodeWidgets(this.node_widget[0],this.canvas_mouse,a,this.node_widget[1]),this.dirty_canvas=!0);if(this.dragging_rectangle)this.dragging_rectangle[2]=a.canvasX-this.dragging_rectangle[0],this.dragging_rectangle[3]=a.canvasY-this.dragging_rectangle[1],this.dirty_canvas=!0;else if(this.selected_group)this.selected_group_resizing?this.selected_group.size=[a.canvasX-this.selected_group.pos[0],
a.canvasY-this.selected_group.pos[1]]:(this.selected_group.move(e[0]/this.scale,e[1]/this.scale,a.ctrlKey),this.selected_group._nodes.length&&(this.dirty_canvas=!0)),this.dirty_bgcanvas=!0;else if(this.dragging_canvas)this.offset[0]+=e[0]/this.scale,this.offset[1]+=e[1]/this.scale,this.dirty_bgcanvas=this.dirty_canvas=!0;else if(this.allow_interaction){this.connecting_node&&(this.dirty_canvas=!0);for(var c=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes),b=0,f=this.graph._nodes.length;b<
f;++b)if(this.graph._nodes[b].mouseOver&&c!=this.graph._nodes[b]){this.graph._nodes[b].mouseOver=!1;if(this.node_over&&this.node_over.onMouseLeave)this.node_over.onMouseLeave(a);this.node_over=null;this.dirty_canvas=!0}if(c){if(!c.mouseOver&&(c.mouseOver=!0,this.node_over=c,this.dirty_canvas=!0,c.onMouseEnter))c.onMouseEnter(a);if(c.onMouseMove)c.onMouseMove(a,[a.canvasX-c.pos[0],a.canvasY-c.pos[1]],this);if(this.connecting_node&&(f=this._highlight_input||[0,0],!this.isOverNodeBox(c,a.canvasX,a.canvasY))){var n=
this.isOverNodeInput(c,a.canvasX,a.canvasY,f);-1!=n&&c.inputs[n]?k.isValidConnection(this.connecting_output.type,c.inputs[n].type)&&(this._highlight_input=f):this._highlight_input=null}this.canvas&&(r(a.canvasX,a.canvasY,c.pos[0]+c.size[0]-5,c.pos[1]+c.size[1]-5,5,5)?this.canvas.style.cursor="se-resize":this.canvas.style.cursor="")}else this.canvas&&(this.canvas.style.cursor="");if(this.node_capturing_input&&this.node_capturing_input!=c&&this.node_capturing_input.onMouseMove)this.node_capturing_input.onMouseMove(a);
if(this.node_dragged&&!this.live_mode){for(b in this.selected_nodes)c=this.selected_nodes[b],c.pos[0]+=e[0]/this.scale,c.pos[1]+=e[1]/this.scale;this.dirty_bgcanvas=this.dirty_canvas=!0}this.resizing_node&&!this.live_mode&&(this.resizing_node.size[0]=a.canvasX-this.resizing_node.pos[0],this.resizing_node.size[1]=a.canvasY-this.resizing_node.pos[1],e=Math.max(this.resizing_node.inputs?this.resizing_node.inputs.length:0,this.resizing_node.outputs?this.resizing_node.outputs.length:0)*k.NODE_SLOT_HEIGHT+
(this.resizing_node.widgets?this.resizing_node.widgets.length:0)*(k.NODE_WIDGET_HEIGHT+4)+4,this.resizing_node.size[1]<e&&(this.resizing_node.size[1]=e),this.resizing_node.size[0]<k.NODE_MIN_WIDTH&&(this.resizing_node.size[0]=k.NODE_MIN_WIDTH),this.canvas.style.cursor="se-resize",this.dirty_bgcanvas=this.dirty_canvas=!0)}a.preventDefault();return!1}};g.prototype.processMouseUp=function(a){if(this.graph){var b=this.getCanvasWindow().document;g.active_canvas=this;b.removeEventListener("mousemove",this._mousemove_callback,
!0);this.canvas.addEventListener("mousemove",this._mousemove_callback,!0);b.removeEventListener("mouseup",this._mouseup_callback,!0);this.adjustMouseEvent(a);b=k.getTime();a.click_time=b-this.last_mouseclick;this.last_mouse_dragging=!1;if(1==a.which){this.node_widget=null;if(this.selected_group){var b=this.selected_group.pos[0]-Math.round(this.selected_group.pos[0]),e=this.selected_group.pos[1]-Math.round(this.selected_group.pos[1]);this.selected_group.move(b,e,a.ctrlKey);this.selected_group.pos[0]=
Math.round(this.selected_group.pos[0]);this.selected_group.pos[1]=Math.round(this.selected_group.pos[1]);this.selected_group._nodes.length&&(this.dirty_canvas=!0);this.selected_group=null}this.selected_group_resizing=!1;if(this.dragging_rectangle){if(this.graph){b=this.graph._nodes;e=new Float32Array(4);this.deselectAllNodes();var c=Math.abs(this.dragging_rectangle[2]),f=Math.abs(this.dragging_rectangle[3]),n=0>this.dragging_rectangle[3]?this.dragging_rectangle[1]-f:this.dragging_rectangle[1];this.dragging_rectangle[0]=
0>this.dragging_rectangle[2]?this.dragging_rectangle[0]-c:this.dragging_rectangle[0];this.dragging_rectangle[1]=n;this.dragging_rectangle[2]=c;this.dragging_rectangle[3]=f;f=[];for(n=0;n<b.length;++n)c=b[n],c.getBounding(e),s(this.dragging_rectangle,e)&&f.push(c);f.length&&this.selectNodes(f)}this.dragging_rectangle=null}else if(this.connecting_node){this.dirty_bgcanvas=this.dirty_canvas=!0;if(c=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes))this.connecting_output.type==k.EVENT&&
this.isOverNodeBox(c,a.canvasX,a.canvasY)?this.connecting_node.connect(this.connecting_slot,c,k.EVENT):(b=this.isOverNodeInput(c,a.canvasX,a.canvasY),-1!=b?this.connecting_node.connect(this.connecting_slot,c,b):(b=c.getInputInfo(0),this.connecting_output.type==k.EVENT?this.connecting_node.connect(this.connecting_slot,c,k.EVENT):b&&!b.link&&k.isValidConnection(b.type&&this.connecting_output.type)&&this.connecting_node.connect(this.connecting_slot,c,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{c=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes);!c&&300>a.click_time&&this.deselectAllNodes();
this.dirty_canvas=!0;this.dragging_canvas=!1;if(this.node_over&&this.node_over.onMouseUp)this.node_over.onMouseUp(a,[a.canvasX-this.node_over.pos[0],a.canvasY-this.node_over.pos[1]],this);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}};g.prototype.processMouseWheel=function(a){if(this.graph&&this.allow_dragcanvas){var b=null!=a.wheelDeltaY?a.wheelDeltaY:-60*a.detail;this.adjustMouseEvent(a);var e=this.scale;0<b?e*=1.1:0>b&&(e*=1/1.1);this.setZoom(e,[a.localX,a.localY]);this.graph.change();a.preventDefault();return!1}};g.prototype.isOverNodeBox=function(a,b,e){var c=k.NODE_TITLE_HEIGHT;return r(b,e,a.pos[0]+2,a.pos[1]+2-c,c-4,c-4)?!0:!1};g.prototype.isOverNodeInput=
function(a,b,e,c){if(a.inputs)for(var f=0,n=a.inputs.length;f<n;++f){var l=a.getConnectionPos(!0,f);if(r(b,e,l[0]-10,l[1]-5,20,10))return c&&(c[0]=l[0],c[1]=l[1]),f}return-1};g.prototype.processKey=function(a){if(this.graph){var b=!1;if("input"!=a.target.localName){if("keydown"==a.type){if(32==a.keyCode&&(b=this.dragging_canvas=!0),65==a.keyCode&&a.ctrlKey&&(this.selectNodes(),b=!0),"KeyC"==a.code&&(a.metaKey||a.ctrlKey)&&!a.shiftKey&&this.selected_nodes&&(this.copyToClipboard(),b=!0),"KeyV"!=a.code||
!a.metaKey&&!a.ctrlKey||a.shiftKey||this.pasteFromClipboard(),46!=a.keyCode&&8!=a.keyCode||"input"==a.target.localName||"textarea"==a.target.localName||(this.deleteSelectedNodes(),b=!0),this.selected_nodes)for(var e in this.selected_nodes)if(this.selected_nodes[e].onKeyDown)this.selected_nodes[e].onKeyDown(a)}else if("keyup"==a.type&&(32==a.keyCode&&(this.dragging_canvas=!1),this.selected_nodes))for(e in this.selected_nodes)if(this.selected_nodes[e].onKeyUp)this.selected_nodes[e].onKeyUp(a);this.graph.change();
if(b)return a.preventDefault(),!1}}};g.prototype.copyToClipboard=function(){var a={nodes:[],links:[]},b=0,e=[],c;for(c in this.selected_nodes){var f=this.selected_nodes[c];f._relative_id=b;e.push(f);b+=1}for(c=0;c<e.length;++c)if(f=e[c],a.nodes.push(f.clone().serialize()),f.inputs&&f.inputs.length)for(b=0;b<f.inputs.length;++b){var n=f.inputs[b];if(n&&null!=n.link&&(n=this.graph.links[n.link])){var l=this.graph.getNodeById(n.origin_id);l&&this.selected_nodes[l.id]&&a.links.push([l._relative_id,b,
f._relative_id,n.target_slot])}}localStorage.setItem("litegrapheditor_clipboard",JSON.stringify(a))};g.prototype.pasteFromClipboard=function(){var a=localStorage.getItem("litegrapheditor_clipboard");if(a){for(var a=JSON.parse(a),b=[],e=0;e<a.nodes.length;++e){var c=a.nodes[e],f=k.createNode(c.type);f&&(f.configure(c),f.pos[0]+=5,f.pos[1]+=5,this.graph.add(f),b.push(f))}for(e=0;e<a.links.length;++e)c=a.links[e],b[c[0]].connect(c[1],b[c[2]],c[3]);this.selectNodes(b)}};g.prototype.processDrop=function(a){a.preventDefault();
this.adjustMouseEvent(a);var b=[a.canvasX,a.canvasY],e=this.graph.getNodeOnPos(b[0],b[1]);if(e){if((e.onDropFile||e.onDropData)&&(b=a.dataTransfer.files)&&b.length)for(var c=0;c<b.length;c++){var f=a.dataTransfer.files[0],n=f.name;g.getFileExtension(n);if(e.onDropFile)e.onDropFile(f);if(e.onDropData){var l=new FileReader;l.onload=function(a){e.onDropData(a.target.result,n,f)};var k=f.type.split("/")[0];"text"==k||""==k?l.readAsText(f):"image"==k?l.readAsDataURL(f):l.readAsArrayBuffer(f)}}return e.onDropItem&&
e.onDropItem(event)?!0:this.onDropItem?this.onDropItem(event):!1}b=null;this.onDropItem&&(b=this.onDropItem(event));b||this.checkDropItem(a)};g.prototype.checkDropItem=function(a){if(a.dataTransfer.files.length){var b=a.dataTransfer.files[0],e=g.getFileExtension(b.name).toLowerCase();if(e=k.node_types_by_file_extension[e])if(e=k.createNode(e.type),e.pos=[a.canvasX,a.canvasY],this.graph.add(e),e.onDropFile)e.onDropFile(b)}};g.prototype.processNodeDblClicked=function(a){if(this.onShowNodePanel)this.onShowNodePanel(a);
if(this.onNodeDblClicked)this.onNodeDblClicked(a);this.setDirty(!0)};g.prototype.processNodeSelected=function(a,b){this.selectNode(a,b&&b.shiftKey);if(this.onNodeSelected)this.onNodeSelected(a)};g.prototype.processNodeDeselected=function(a){this.deselectNode(a);if(this.onNodeDeselected)this.onNodeDeselected(a)};g.prototype.selectNode=function(a,b){null==a?this.deselectAllNodes():this.selectNodes([a],b)};g.prototype.selectNodes=function(a,b){b||this.deselectAllNodes();a=a||this.graph._nodes;for(var e=
0;e<a.length;++e){var c=a[e];if(!c.selected){if(!c.selected&&c.onSelected)c.onSelected();c.selected=!0;this.selected_nodes[c.id]=c;if(c.inputs)for(var f=0;f<c.inputs.length;++f)this.highlighted_links[c.inputs[f].link]=!0;if(c.outputs)for(f=0;f<c.outputs.length;++f){var n=c.outputs[f];if(n.links)for(var l=0;l<n.links.length;++l)this.highlighted_links[n.links[l]]=!0}}}this.setDirty(!0)};g.prototype.deselectNode=function(a){if(a.selected){if(a.onDeselected)a.onDeselected();a.selected=!1;if(a.inputs)for(var b=
0;b<a.inputs.length;++b)delete this.highlighted_links[a.inputs[b].link];if(a.outputs)for(b=0;b<a.outputs.length;++b){var c=a.outputs[b];if(c.links)for(var g=0;g<c.links.length;++g)delete this.highlighted_links[c.links[g]]}}};g.prototype.deselectAllNodes=function(){if(this.graph){for(var a=this.graph._nodes,b=0,c=a.length;b<c;++b){var g=a[b];if(g.selected){if(g.onDeselected)g.onDeselected();g.selected=!1}}this.selected_nodes={};this.highlighted_links={};this.setDirty(!0)}};g.prototype.deleteSelectedNodes=
function(){for(var a in this.selected_nodes)this.graph.remove(this.selected_nodes[a]);this.selected_nodes={};this.highlighted_links={};this.setDirty(!0)};g.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)};g.prototype.adjustMouseEvent=function(a){if(this.canvas){var b=this.canvas.getBoundingClientRect();a.localX=a.pageX-b.left;a.localY=a.pageY-b.top}else a.localX=
a.pageX,a.localY=a.pageY;a.deltaX=a.localX-this.last_mouse_position[0];a.deltaY=a.localY-this.last_mouse_position[1];this.last_mouse_position[0]=a.localX;this.last_mouse_position[1]=a.localY;a.canvasX=a.localX/this.scale-this.offset[0];a.canvasY=a.localY/this.scale-this.offset[1]};g.prototype.setZoom=function(a,b){!b&&this.canvas&&(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 g=this.convertOffsetToCanvas(b),c=[g[0]-c[0],g[1]-c[1]];this.offset[0]+=c[0];this.offset[1]+=c[1];this.dirty_bgcanvas=this.dirty_canvas=!0};g.prototype.convertOffsetToCanvas=function(a,b){b=b||[];b[0]=a[0]/this.scale-this.offset[0];b[1]=a[1]/this.scale-this.offset[1];return b};g.prototype.convertCanvasToOffset=function(a,b){b=b||[];b[0]=(a[0]+this.offset[0])*this.scale;b[1]=(a[1]+this.offset[1])*this.scale;return b};g.prototype.convertEventToCanvas=function(a){var b=
this.canvas.getBoundingClientRect();return this.convertOffsetToCanvas([a.pageX-b.left,a.pageY-b.top])};g.prototype.bringToFront=function(a){var b=this.graph._nodes.indexOf(a);-1!=b&&(this.graph._nodes.splice(b,1),this.graph._nodes.push(a))};g.prototype.sendToBack=function(a){var b=this.graph._nodes.indexOf(a);-1!=b&&(this.graph._nodes.splice(b,1),this.graph._nodes.unshift(a))};var m=new Float32Array(4);g.prototype.computeVisibleNodes=function(a,b){var c=b||[];c.length=0;a=a||this.graph._nodes;for(var g=
0,f=a.length;g<f;++g){var n=a[g];(!this.live_mode||n.onDrawBackground||n.onDrawForeground)&&s(this.visible_area,n.getBounding(m))&&c.push(n)}return c};g.prototype.draw=function(a,b){if(this.canvas){var c=k.getTime();this.render_time=0.001*(c-this.last_draw_time);this.last_draw_time=c;if(this.graph){var g=-this.offset[0],f=-this.offset[1],n=g+this.canvas.width/this.scale,l=f+this.canvas.height/this.scale;this.visible_area[0]=g;this.visible_area[1]=f;this.visible_area[2]=n-g;this.visible_area[3]=l-
f}(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}};g.prototype.drawFrontCanvas=function(){this.dirty_canvas=!1;this.ctx||(this.ctx=this.bgcanvas.getContext("2d"));var a=this.ctx;if(a){a.start2D&&a.start2D();var b=this.canvas;a.restore();a.setTransform(1,0,0,1,0,0);this.dirty_area&&
(a.save(),a.beginPath(),a.rect(this.dirty_area[0],this.dirty_area[1],this.dirty_area[2],this.dirty_area[3]),a.clip());this.clear_background&&a.clearRect(0,0,b.width,b.height);this.bgcanvas==this.canvas?this.drawBackCanvas():a.drawImage(this.bgcanvas,0,0);if(this.onRender)this.onRender(b,a);this.show_info&&this.renderInfo(a);if(this.graph){a.save();a.scale(this.scale,this.scale);a.translate(this.offset[0],this.offset[1]);for(var b=this.computeVisibleNodes(null,this.visible_nodes),c=0;c<b.length;++c){var g=
b[c];a.save();a.translate(g.pos[0],g.pos[1]);this.drawNode(g,a);a.restore()}this.render_execution_order&&this.drawExecutionOrder(a);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 k.EVENT:b=k.EVENT_LINK_COLOR;break;default:b=k.CONNECTING_LINK_COLOR}this.renderLink(a,this.connecting_pos,[this.canvas_mouse[0],this.canvas_mouse[1]],null,!1,null,b,this.connecting_output.dir||
(this.connecting_node.flags.horizontal?k.DOWN:k.RIGHT),k.CENTER);a.beginPath();this.connecting_output.type===k.EVENT||this.connecting_output.shape===k.BOX_SHAPE?a.rect(this.connecting_pos[0]-6+0.5,this.connecting_pos[1]-5+0.5,14,10):a.arc(this.connecting_pos[0],this.connecting_pos[1],4,0,2*Math.PI);a.fill();a.fillStyle="#ffcc00";this._highlight_input&&(a.beginPath(),a.arc(this._highlight_input[0],this._highlight_input[1],6,0,2*Math.PI),a.fill())}this.dragging_rectangle&&(a.strokeStyle="#FFF",a.strokeRect(this.dragging_rectangle[0],
this.dragging_rectangle[1],this.dragging_rectangle[2],this.dragging_rectangle[3]));if(this.onDrawForeground)this.onDrawForeground(a,this.visible_rect);a.restore()}if(this.onDrawOverlay)this.onDrawOverlay(a);this.dirty_area&&a.restore();a.finish2D&&a.finish2D()}};g.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("N: "+
this.graph._nodes.length+" ["+this.visible_nodes.length+"]",5,39),a.fillText("V: "+this.graph._version,5,52),a.fillText("FPS:"+this.fps.toFixed(2),5,65)):a.fillText("No graph selected",5,13);a.restore()};g.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);if(this._graph_stack&&this._graph_stack.length){b.save();var c=this.graph._subgraph_node;b.strokeStyle=c.bgcolor;b.lineWidth=10;b.strokeRect(1,1,a.width-2,a.height-2);b.lineWidth=1;b.font="40px Arial";b.textAlign="center";b.fillStyle=c.bgcolor;for(var g="",f=1;f<this._graph_stack.length;++f)g+=this._graph_stack[f]._subgraph_node.getTitle()+" >> ";b.fillText(g+c.getTitle(),0.5*a.width,40);b.restore()}c=!1;this.onRenderBackground&&(c=this.onRenderBackground(a,b));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&&!c){b.globalAlpha=this.zoom_modify_alpha?(1-0.5/this.scale)*this.editor_alpha:this.editor_alpha;b.imageSmoothingEnabled=b.mozImageSmoothingEnabled=b.imageSmoothingEnabled=!1;if(!this._bg_img||this._bg_img.name!=this.background_image){this._bg_img=new Image;this._bg_img.name=this.background_image;this._bg_img.src=this.background_image;var n=this;this._bg_img.onload=
function(){n.draw(!0,!0)}}c=null;null==this._pattern&&0<this._bg_img.width?(c=b.createPattern(this._bg_img,"repeat"),this._pattern_img=this._bg_img,this._pattern=c):c=this._pattern;c&&(b.fillStyle=c,b.fillRect(this.visible_area[0],this.visible_area[1],this.visible_area[2],this.visible_area[3]),b.fillStyle="transparent");b.globalAlpha=1;b.imageSmoothingEnabled=b.mozImageSmoothingEnabled=b.imageSmoothingEnabled=!0}this.graph._groups.length&&!this.live_mode&&this.drawGroups(a,b);if(this.onDrawBackground)this.onDrawBackground(b,
this.visible_area);this.onBackgroundRender&&(console.error("WARNING! onBackgroundRender deprecated, now is named onDrawBackground "),this.onBackgroundRender=null);this.render_canvas_border&&(b.strokeStyle="#235",b.strokeRect(0,0,a.width,a.height));this.render_connections_shadows?(b.shadowColor="#000",b.shadowOffsetX=0,b.shadowOffsetY=0,b.shadowBlur=6):b.shadowColor="rgba(0,0,0,0)";this.live_mode||this.drawConnections(b);b.shadowColor="rgba(0,0,0,0)";b.restore()}b.finish&&b.finish();this.dirty_bgcanvas=
!1;this.dirty_canvas=!0};var c=new Float32Array(2);g.prototype.drawNode=function(a,b){this.current_node=a;var e=a.color||a.constructor.color||k.NODE_DEFAULT_COLOR,g=a.bgcolor||a.constructor.bgcolor||k.NODE_DEFAULT_BGCOLOR;if(this.live_mode){if(!a.flags.collapsed&&(b.shadowColor="transparent",a.onDrawForeground))a.onDrawForeground(b,this,this.canvas)}else{var f=this.editor_alpha;b.globalAlpha=f;this.render_shadows?(b.shadowColor=k.DEFAULT_SHADOW_COLOR,b.shadowOffsetX=2*this.scale,b.shadowOffsetY=2*
this.scale,b.shadowBlur=3*this.scale):b.shadowColor="transparent";if(!a.flags.collapsed||!a.onDrawCollaped||!0!=a.onDrawCollapsed(b,this)){var n=a._shape||k.BOX_SHAPE;c.set(a.size);if(a.flags.collapsed){b.font=this.inner_text_font;var l=a.getTitle?a.getTitle():a.title;a._collapsed_width=Math.min(a.size[0],b.measureText(l).width+40);c[0]=a._collapsed_width;c[1]=0}a.flags.clip_area&&(b.save(),b.beginPath(),n==k.BOX_SHAPE?b.rect(0,0,c[0],c[1]):n==k.ROUND_SHAPE?b.roundRect(0,0,c[0],c[1],10):n==k.CIRCLE_SHAPE&&
b.arc(0.5*c[0],0.5*c[1],0.5*c[0],0,2*Math.PI),b.clip());this.drawNodeShape(a,b,c,e,g,a.selected,a.mouseOver);b.shadowColor="transparent";b.textAlign=a.flags.horizontal?"center":"left";b.font=this.inner_text_font;e=0.6<this.scale;g=this.connecting_output;b.lineWidth=1;n=0;if(a.flags.collapsed){if(a.inputs)for(l=0;l<a.inputs.length;l++)if(d=a.inputs[l],null!=d.link){b.fillStyle=d.color_on||this.default_connection_color.input_on;b.beginPath();d.type===k.EVENT||d.shape===k.BOX_SHAPE?b.rect(0.5,4-k.NODE_TITLE_HEIGHT+
0.5,14,k.NODE_TITLE_HEIGHT-8):d.shape===k.ARROW_SHAPE?(b.moveTo(8,-0.5*k.NODE_TITLE_HEIGHT),b.lineTo(-4,-0.8*k.NODE_TITLE_HEIGHT),b.lineTo(-4,-0.2*k.NODE_TITLE_HEIGHT),b.closePath()):b.arc(0,-0.5*k.NODE_TITLE_HEIGHT,4,0,2*Math.PI);b.fill();break}if(a.outputs)for(l=0;l<a.outputs.length;l++)d=a.outputs[l],d.links&&d.links.length&&(b.fillStyle=d.color_on||this.default_connection_color.output_on,b.strokeStyle="black",b.beginPath(),d.type===k.EVENT||d.shape===k.BOX_SHAPE?b.rect(a._collapsed_width-4+0.5,
4-k.NODE_TITLE_HEIGHT+0.5,14,k.NODE_TITLE_HEIGHT-8):d.shape===k.ARROW_SHAPE?(b.moveTo(a._collapsed_width+6,-0.5*k.NODE_TITLE_HEIGHT),b.lineTo(a._collapsed_width-6,-0.8*k.NODE_TITLE_HEIGHT),b.lineTo(a._collapsed_width-6,-0.2*k.NODE_TITLE_HEIGHT),b.closePath()):b.arc(a._collapsed_width,-0.5*k.NODE_TITLE_HEIGHT,4,0,2*Math.PI),b.fill(),b.stroke())}else{if(a.inputs)for(l=0;l<a.inputs.length;l++){var d=a.inputs[l];b.globalAlpha=f;this.connecting_node&&k.isValidConnection(d.type&&g.type)&&(b.globalAlpha=
0.4*f);b.fillStyle=null!=d.link?d.color_on||this.default_connection_color.input_on:d.color_off||this.default_connection_color.input_off;var m=a.getConnectionPos(!0,l);m[0]-=a.pos[0];m[1]-=a.pos[1];n<m[1]+0.5*k.NODE_SLOT_HEIGHT&&(n=m[1]+0.5*k.NODE_SLOT_HEIGHT);b.beginPath();d.type===k.EVENT||d.shape===k.BOX_SHAPE?b.rect(m[0]-6+0.5,m[1]-5+0.5,14,10):d.shape===k.ARROW_SHAPE?(b.moveTo(m[0]+8,m[1]+0.5),b.lineTo(m[0]-4,m[1]+6+0.5),b.lineTo(m[0]-4,m[1]-6+0.5),b.closePath()):b.arc(m[0],m[1],4,0,2*Math.PI);
b.fill();if(e){var h=null!=d.label?d.label:d.name;h&&(b.fillStyle=k.NODE_TEXT_COLOR,a.flags.horizontal||d.dir==k.UP?b.fillText(h,m[0],m[1]-10):b.fillText(h,m[0]+10,m[1]+5))}}this.connecting_node&&(b.globalAlpha=0.4*f);b.textAlign=a.flags.horizontal?"center":"right";b.strokeStyle="black";if(a.outputs)for(l=0;l<a.outputs.length;l++)if(d=a.outputs[l],m=a.getConnectionPos(!1,l),m[0]-=a.pos[0],m[1]-=a.pos[1],n<m[1]+0.5*k.NODE_SLOT_HEIGHT&&(n=m[1]+0.5*k.NODE_SLOT_HEIGHT),b.fillStyle=d.links&&d.links.length?
d.color_on||this.default_connection_color.output_on:d.color_off||this.default_connection_color.output_off,b.beginPath(),d.type===k.EVENT||d.shape===k.BOX_SHAPE?b.rect(m[0]-6+0.5,m[1]-5+0.5,14,10):d.shape===k.ARROW_SHAPE?(b.moveTo(m[0]+8,m[1]+0.5),b.lineTo(m[0]-4,m[1]+6+0.5),b.lineTo(m[0]-4,m[1]-6+0.5),b.closePath()):b.arc(m[0],m[1],4,0,2*Math.PI),b.fill(),b.stroke(),e&&(h=null!=d.label?d.label:d.name))b.fillStyle=k.NODE_TEXT_COLOR,a.flags.horizontal||d.dir==k.DOWN?b.fillText(h,m[0],m[1]-8):b.fillText(h,
m[0]-10,m[1]+5);b.textAlign="left";b.globalAlpha=1;if(a.widgets){if(a.flags.horizontal||a.flags.widgets_up)n=2;this.drawNodeWidgets(a,n,b,this.node_widget&&this.node_widget[0]==a?this.node_widget[1]:null)}if(a.onDrawForeground)a.onDrawForeground(b,this,this.canvas)}a.flags.clip_area&&b.restore();b.globalAlpha=1}}};g.prototype.drawNodeShape=function(a,b,c,d,f,n,l){b.strokeStyle=d;b.fillStyle=f;f=k.NODE_TITLE_HEIGHT;var m=a._shape||a.constructor.shape||k.BOX_SHAPE,h=a.constructor.title_mode,z=!0;h==
k.TRANSPARENT_TITLE?z=!1:h==k.AUTOHIDE_TITLE&&l&&(z=!0);l=z?-f:0;var A=c[0]+1,p=z?c[1]+f:c[1];a.flags.collapsed||(b.beginPath(),m==k.BOX_SHAPE||0.5>this.scale?b.fillRect(0,l,A,p):m==k.ROUND_SHAPE||m==k.CARD_SHAPE?b.roundRect(0,l,A,p,this.round_radius,m==k.CARD_SHAPE?0:this.round_radius):m==k.CIRCLE_SHAPE&&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,this,this.canvas);if(z||h==k.TRANSPARENT_TITLE){if(h!=k.TRANSPARENT_TITLE){a.flags.collapsed&&(b.shadowColor=k.DEFAULT_SHADOW_COLOR);if(this.use_gradients){var q=g.gradients[d];q||(q=g.gradients[d]=b.createLinearGradient(0,0,400,0),q.addColorStop(0,d),q.addColorStop(1,"#000"));b.fillStyle=q}else b.fillStyle=d;q=b.globalAlpha;b.beginPath();m==k.BOX_SHAPE||0.5>this.scale?b.rect(0,-f,c[0]+1,f):m!=k.ROUND_SHAPE&&
m!=k.CARD_SHAPE||b.roundRect(0,-f,c[0]+1,f,this.round_radius,a.flags.collapsed?this.round_radius:0);b.fill();b.shadowColor="transparent"}m==k.ROUND_SHAPE||m==k.CIRCLE_SHAPE||m==k.CARD_SHAPE?(0.5<this.scale&&(b.fillStyle="black",b.beginPath(),b.arc(0.5*f,-0.5*f,0.5*(f-8),0,2*Math.PI),b.fill()),b.fillStyle=a.boxcolor||k.NODE_DEFAULT_BOXCOLOR,b.beginPath(),b.arc(0.5*f,-0.5*f,0.4*(f-8),0,2*Math.PI),b.fill()):(0.5<this.scale&&(b.fillStyle="black",b.fillRect(4,-f+4,f-8,f-8)),b.fillStyle=a.boxcolor||k.NODE_DEFAULT_BOXCOLOR,
b.fillRect(5,-f+5,f-10,f-10));b.globalAlpha=q;0.5<this.scale&&(b.font=this.title_text_font,q=a.getTitle())&&(b.fillStyle=n?"white":a.constructor.title_text_color||this.node_title_color,a.flags.collapsed?(b.textAlign="center",z=b.measureText(q),b.fillText(q,f+0.5*z.width,0.2*-f),b.textAlign="left"):(b.textAlign="left",b.fillText(q,f,0.2*-f)));if(a.onDrawTitle)a.onDrawTitle(b)}n&&(h==k.TRANSPARENT_TITLE&&(l-=f,p+=f),b.lineWidth=1,b.globalAlpha=0.8,b.beginPath(),m==k.BOX_SHAPE?b.rect(-6,-6+l,12+A,12+
p):m==k.ROUND_SHAPE||m==k.CARD_SHAPE&&a.flags.collapsed?b.roundRect(-6,-6+l,12+A,12+p,2*this.round_radius):m==k.CARD_SHAPE?b.roundRect(-6,-6+l,12+A,12+p,2*this.round_radius,2):m==k.CIRCLE_SHAPE&&b.arc(0.5*c[0],0.5*c[1],0.5*c[0]+6,0,2*Math.PI),b.strokeStyle="#FFF",b.stroke(),b.strokeStyle=d,b.globalAlpha=1)};g.prototype.drawConnections=function(a){var b=k.getTime(),c=this.visible_area,c=new Float32Array([c[0]-20,c[1]-20,c[2]+40,c[3]+40]),g=new Float32Array(4);a.lineWidth=this.connections_width;a.fillStyle=
"#AAA";a.strokeStyle="#AAA";a.globalAlpha=this.editor_alpha;for(var f=this.graph._nodes,n=0,l=f.length;n<l;++n){var m=f[n];if(m.inputs&&m.inputs.length)for(var d=0;d<m.inputs.length;++d){var h=m.inputs[d];if(h&&null!=h.link&&(h=this.graph.links[h.link])){var p=this.graph.getNodeById(h.origin_id);if(null!=p){var q=h.origin_slot,r=null,r=-1==q?[p.pos[0]+10,p.pos[1]+10]:p.getConnectionPos(!1,q),t=m.getConnectionPos(!0,d);g[0]=r[0];g[1]=r[1];g[2]=t[0]-r[0];g[3]=t[1]-r[1];0>g[2]&&(g[0]+=g[2],g[2]=Math.abs(g[2]));
0>g[3]&&(g[1]+=g[3],g[3]=Math.abs(g[3]));if(s(g,c)){var v=p.outputs[q],q=m.inputs[d];if(v&&q&&(p=v.dir||(p.flags.horizontal?k.DOWN:k.RIGHT),q=q.dir||(m.flags.horizontal?k.UP:k.LEFT),this.renderLink(a,r,t,h,!1,0,null,p,q),h&&h._last_time&&1E3>b-h._last_time)){var v=2-0.002*(b-h._last_time),y=a.globalAlpha;a.globalAlpha=y*v;this.renderLink(a,r,t,h,!0,v,"white",p,q);a.globalAlpha=y}}}}}}a.globalAlpha=1};g.prototype.renderLink=function(a,b,c,m,f,n,l,d,h){if(this.highquality_render){d=d||k.RIGHT;h=h||
k.LEFT;var p=q(b,c);this.render_connections_border&&0.6<this.scale&&(a.lineWidth=this.connections_width+4);!l&&m&&(l=g.link_type_colors[m.type]);l||(l=this.default_link_color);null!=m&&this.highlighted_links[m.id]&&(l="#FFF");a.beginPath();if(this.render_curved_connections){a.moveTo(b[0],b[1]);var A=m=0,r=0,s=0;switch(d){case k.LEFT:m=-0.25*p;break;case k.RIGHT:m=0.25*p;break;case k.UP:A=-0.25*p;break;case k.DOWN:A=0.25*p}switch(h){case k.LEFT:r=-0.25*p;break;case k.RIGHT:r=0.25*p;break;case k.UP:s=
-0.25*p;break;case k.DOWN:s=0.25*p}a.bezierCurveTo(b[0]+m,b[1]+A,c[0]+r,c[1]+s,c[0],c[1])}else a.moveTo(b[0]+10,b[1]),a.lineTo(0.5*(b[0]+10+(c[0]-10)),b[1]),a.lineTo(0.5*(b[0]+10+(c[0]-10)),c[1]),a.lineTo(c[0]-10,c[1]);this.render_connections_border&&0.6<this.scale&&!f&&(a.strokeStyle="rgba(0,0,0,0.5)",a.stroke());a.lineWidth=this.connections_width;a.fillStyle=a.strokeStyle=l;a.stroke();this.render_connection_arrows&&0.6<=this.scale&&this.render_connection_arrows&&0.6<this.scale&&(f=this.computeConnectionPoint(b,
c,0.5,d,h),l=this.computeConnectionPoint(b,c,0.51,d,h),p=0,p=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(p),a.beginPath(),a.moveTo(-5,-5),a.lineTo(0,5),a.lineTo(5,-5),a.fill(),a.restore());if(n)for(n=0;5>n;++n)f=(0.001*k.getTime()+0.2*n)%1,f=this.computeConnectionPoint(b,c,f,d,h),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()};g.prototype.computeConnectionPoint=
function(a,b,c,g,f){g=g||k.RIGHT;f=f||k.LEFT;var n=q(a,b),l=[a[0],a[1]],m=[b[0],b[1]];switch(g){case k.LEFT:l[0]+=-0.25*n;break;case k.RIGHT:l[0]+=0.25*n;break;case k.UP:l[1]+=-0.25*n;break;case k.DOWN:l[1]+=0.25*n}switch(f){case k.LEFT:m[0]+=-0.25*n;break;case k.RIGHT:m[0]+=0.25*n;break;case k.UP:m[1]+=-0.25*n;break;case k.DOWN:m[1]+=0.25*n}g=(1-c)*(1-c)*(1-c);f=3*(1-c)*(1-c)*c;n=3*(1-c)*c*c;c*=c*c;return[g*a[0]+f*l[0]+n*m[0]+c*b[0],g*a[1]+f*l[1]+n*m[1]+c*b[1]]};g.prototype.drawExecutionOrder=function(a){a.shadowColor=
"transparent";a.globalAlpha=0.25;a.textAlign="center";a.strokeStyle="white";a.globalAlpha=0.75;for(var b=this.visible_nodes,c=0;c<b.length;++c){var g=b[c];a.fillStyle="black";a.fillRect(g.pos[0]-k.NODE_TITLE_HEIGHT,g.pos[1]-k.NODE_TITLE_HEIGHT,k.NODE_TITLE_HEIGHT,k.NODE_TITLE_HEIGHT);0==g.order&&a.strokeRect(g.pos[0]-k.NODE_TITLE_HEIGHT+0.5,g.pos[1]-k.NODE_TITLE_HEIGHT+0.5,k.NODE_TITLE_HEIGHT,k.NODE_TITLE_HEIGHT);a.fillStyle="#FFF";a.fillText(g.order,g.pos[0]+-0.5*k.NODE_TITLE_HEIGHT,g.pos[1]-6)}a.globalAlpha=
1};g.prototype.drawNodeWidgets=function(a,b,c,g){if(!a.widgets||!a.widgets.length)return 0;var f=a.size[0];a=a.widgets;b+=2;var n=k.NODE_WIDGET_HEIGHT,l=0.5<this.scale;c.save();c.globalAlpha=this.editor_alpha;for(var m=0;m<a.length;++m){var d=a[m],h=b;d.y&&(h=d.y);d.last_y=h;c.strokeStyle="#AAA";c.fillStyle="#222";c.textAlign="left";switch(d.type){case "button":d.clicked&&(c.fillStyle="#AAA",d.clicked=!1,this.dirty_canvas=!0);c.fillRect(10,h,f-20,n);c.strokeRect(10,h,f-20,n);l&&(c.textAlign="center",
c.fillStyle="#AAA",c.fillText(d.name,0.5*f,h+0.7*n));break;case "toggle":c.textAlign="left";c.strokeStyle="#AAA";c.fillStyle="#111";c.beginPath();c.roundRect(10,b,f-20,n,0.5*n);c.fill();c.stroke();c.fillStyle=d.value?"#89A":"#333";c.beginPath();c.arc(f-20,h+0.5*n,0.36*n,0,2*Math.PI);c.fill();l&&(c.fillStyle="#999",null!=d.name&&c.fillText(d.name,20,h+0.7*n),c.fillStyle=d.value?"#DDD":"#888",c.textAlign="right",c.fillText(d.value?d.options.on||"true":d.options.off||"false",f-30,h+0.7*n));break;case "slider":c.fillStyle=
"#111";c.fillRect(10,h,f-20,n);var p=(d.value-d.options.min)/(d.options.max-d.options.min);c.fillStyle=g==d?"#89A":"#678";c.fillRect(10,h,p*(f-20),n);c.strokeRect(10,h,f-20,n);l&&(c.textAlign="center",c.fillStyle="#DDD",c.fillText(d.name+" "+Number(d.value).toFixed(3),0.5*f,h+0.7*n));break;case "number":case "combo":c.textAlign="left";c.strokeStyle="#AAA";c.fillStyle="#111";c.beginPath();c.roundRect(10,b,f-20,n,0.5*n);c.fill();c.stroke();l&&(c.fillStyle="#AAA",c.beginPath(),c.moveTo(26,b+5),c.lineTo(16,
b+0.5*n),c.lineTo(26,b+n-5),c.moveTo(f-26,b+5),c.lineTo(f-16,b+0.5*n),c.lineTo(f-26,b+n-5),c.fill(),c.fillStyle="#999",c.fillText(d.name,30,h+0.7*n),c.fillStyle="#DDD",c.textAlign="right","number"==d.type?c.fillText(Number(d.value).toFixed(void 0!==d.options.precision?d.options.precision:3),f-40,h+0.7*n):c.fillText(d.value,f-40,h+0.7*n));break;case "text":c.textAlign="left",c.strokeStyle="#AAA",c.fillStyle="#111",c.beginPath(),c.roundRect(10,b,f-20,n,0.5*n),c.fill(),c.stroke(),l&&(c.fillStyle="#999",
null!=d.name&&c.fillText(d.name,20,h+0.7*n),c.fillStyle="#DDD",c.textAlign="right",c.fillText(d.value,f-20,h+0.7*n))}b+=n+4}c.restore()};g.prototype.processNodeWidgets=function(a,b,c,g){if(!a.widgets||!a.widgets.length)return null;for(var f=b[0]-a.pos[0],n=b[1]-a.pos[1],l=a.size[0],d=this,m=this.getCanvasWindow(),h=0;h<a.widgets.length;++h){var p=a.widgets[h];if(p==g||6<f&&f<l-12&&n>p.last_y&&n<p.last_y+k.NODE_WIDGET_HEIGHT){switch(p.type){case "button":p.callback&&setTimeout(function(){p.callback(p,
d,a,b)},20);this.dirty_canvas=p.clicked=!0;break;case "slider":c=Math.clamp((f-10)/(l-20),0,1);p.value=p.options.min+(p.options.max-p.options.min)*c;p.callback&&setTimeout(function(){p.callback(p.value,d,a,b)},20);this.dirty_canvas=!0;break;case "number":case "combo":if("mousemove"==c.type&&"number"==p.type)p.value+=0.1*c.deltaX*(p.options.step||1),null!=p.options.min&&p.value<p.options.min&&(p.value=p.options.min),null!=p.options.max&&p.value>p.options.max&&(p.value=p.options.max);else if("mousedown"==
c.type)if((g=p.options.values)&&g.constructor===Function&&(g=p.options.values(p,a)),f=40>f?-1:f>l-40?1:0,"number"==p.type)p.value+=0.1*f*(p.options.step||1),null!=p.options.min&&p.value<p.options.min&&(p.value=p.options.min),null!=p.options.max&&p.value>p.options.max&&(p.value=p.options.max);else if(f)c=g.indexOf(p.value)+f,c>=g.length&&(c=0),0>c&&(c=g.length-1),p.value=g[c];else{new k.ContextMenu(g,{event:c,className:"dark",callback:q.bind(p)},m);var q=function(a,b,c){this.value=a;d.dirty_canvas=
!0;return!1}}p.callback&&setTimeout(function(){this.callback(this.value,d,a,b)}.bind(p),20);this.dirty_canvas=!0;break;case "toggle":"mousedown"==c.type&&(p.value=!p.value,p.callback&&setTimeout(function(){p.callback(p.value,d,a,b)},20));break;case "text":"mousedown"==c.type&&this.prompt("Value",p.value,function(b){this.value=b;p.callback&&p.callback(b,d,a)}.bind(p),c)}return p}}return null};g.prototype.drawGroups=function(a,b){if(this.graph){var c=this.graph._groups;b.save();b.globalAlpha=0.5*this.editor_alpha;
for(var g=0;g<c.length;++g){var f=c[g];if(s(this.visible_area,f._bounding)){b.fillStyle=f.color||"#335";b.strokeStyle=f.color||"#335";var d=f._pos,l=f._size;b.globalAlpha=0.25*this.editor_alpha;b.beginPath();b.rect(d[0]+0.5,d[1]+0.5,l[0],l[1]);b.fill();b.globalAlpha=this.editor_alpha;b.stroke();b.beginPath();b.moveTo(d[0]+l[0],d[1]+l[1]);b.lineTo(d[0]+l[0]-10,d[1]+l[1]);b.lineTo(d[0]+l[0],d[1]+l[1]-10);b.fill();l=f.font_size||k.DEFAULT_GROUP_FONT_SIZE;b.font=l+"px Arial";b.fillText(f.title,d[0]+4,
d[1]+l)}}b.restore()}};g.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)};g.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 g=setInterval(function(){b.editor_alpha*=
c;b.dirty_canvas=!0;b.dirty_bgcanvas=!0;1>c&&0.01>b.editor_alpha&&(clearInterval(g),1>c&&(b.live_mode=!0));1<c&&0.99<b.editor_alpha&&(clearInterval(g),b.editor_alpha=1)},1)}else this.live_mode=!this.live_mode,this.dirty_bgcanvas=this.dirty_canvas=!0};g.prototype.onNodeSelectionChange=function(a){};g.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 g=
this.getCanvasWindow(),f=g.document.createEvent("MouseEvent");f.initMouseEvent(c,!0,!0,g,1,b.screenX,b.screenY,b.clientX,b.clientY,!1,!1,!1,!1,0,null);b.target.dispatchEvent(f);a.preventDefault()};g.onGroupAdd=function(a,b,c){a=g.active_canvas;a.getCanvasWindow();b=new k.LGraphGroup;b.pos=a.convertEventToCanvas(c);a.graph.add(b)};g.onMenuAdd=function(a,b,c,d){function f(a,b){var c=d.getFirstEvent(),e=k.createNode(a.value);e&&(e.pos=m.convertEventToCanvas(c),m.graph.add(e))}var m=g.active_canvas,l=
m.getCanvasWindow();a=k.getNodeTypesCategories();b=[];for(var h in a)a[h]&&b.push({value:a[h],content:a[h],has_submenu:!0});var p=new k.ContextMenu(b,{event:c,callback:function(a,b,c){a=k.getNodeTypesInCategory(a.value,m.filter);b=[];for(var e in a)a[e].skip_list||b.push({content:a[e].title,value:a[e].type});new k.ContextMenu(b,{event:c,callback:f,parentMenu:p},l);return!1},parentMenu:d},l);return!1};g.onMenuCollapseAll=function(){};g.onMenuNodeEdit=function(){};g.showMenuNodeOptionalInputs=function(a,
b,c,d,f){function m(a,b,c){f&&(a.callback&&a.callback.call(l,f,a,b,c),a.value&&(f.addInput(a.value[0],a.value[1],a.value[2]),f.setDirtyCanvas(!0,!0)))}if(f){var l=this;a=g.active_canvas.getCanvasWindow();b=f.optional_inputs;f.onGetInputs&&(b=f.onGetInputs());var h=[];if(b)for(var p in b){var q=b[p];if(q){var r=q[0];q[2]&&q[2].label&&(r=q[2].label);r={content:r,value:q};q[1]==k.ACTION&&(r.className="event");h.push(r)}else h.push(null)}this.onMenuNodeInputs&&(h=this.onMenuNodeInputs(h));if(h.length)return new k.ContextMenu(h,
{event:c,callback:m,parentMenu:d,node:f},a),!1}};g.showMenuNodeOptionalOutputs=function(a,b,c,d,f){function m(a,b,c){if(f&&(a.callback&&a.callback.call(l,f,a,b,c),a.value))if(c=a.value[1],!c||c.constructor!==Object&&c.constructor!==Array)f.addOutput(a.value[0],a.value[1],a.value[2]),f.setDirtyCanvas(!0,!0);else{a=[];for(var e in c)a.push({content:e,value:c[e]});new k.ContextMenu(a,{event:b,callback:m,parentMenu:d,node:f});return!1}}if(f){var l=this;a=g.active_canvas.getCanvasWindow();b=f.optional_outputs;
f.onGetOutputs&&(b=f.onGetOutputs());var h=[];if(b)for(var p in b){var q=b[p];if(!q)h.push(null);else if(!f.flags||!f.flags.skip_repeated_outputs||-1==f.findOutputSlot(q[0])){var r=q[0];q[2]&&q[2].label&&(r=q[2].label);r={content:r,value:q};q[1]==k.EVENT&&(r.className="event");h.push(r)}}this.onMenuNodeOutputs&&(h=this.onMenuNodeOutputs(h));if(h.length)return new k.ContextMenu(h,{event:c,callback:m,parentMenu:d,node:f},a),!1}};g.onShowMenuNodeProperties=function(a,b,c,d,f){function m(a,b,c,e){f&&
(b=this.getBoundingClientRect(),l.showEditPropertyValue(f,a.value,{position:[b.left,b.top]}))}if(f&&f.properties){var l=g.active_canvas;b=l.getCanvasWindow();var h=[],p;for(p in f.properties)a=void 0!==f.properties[p]?f.properties[p]:" ",a=g.decodeHTML(a),h.push({content:"<span class='property_name'>"+p+"</span><span class='property_value'>"+a+"</span>",value:p});if(h.length)return new k.ContextMenu(h,{event:c,callback:m,parentMenu:d,allow_html:!0,node:f},b),!1}};g.decodeHTML=function(a){var b=document.createElement("div");
b.innerText=a;return b.innerHTML};g.onResizeNode=function(a,b,c,g,f){f&&(f.size=f.computeSize(),f.setDirtyCanvas(!0,!0))};g.onShowPropertyEditor=function(a,b,c,d,f){function m(){var b=h.value;"Number"==a.type?b=Number(b):"Boolean"==a.type&&(b=Boolean(b));f[l]=b;k.parentNode.removeChild(k);f.setDirtyCanvas(!0,!0)}var l=a.property||"title";b=f[l];var k=document.createElement("div");k.className="graphdialog";k.innerHTML="<span class='name'></span><input autofocus type='text' class='value'/><button>OK</button>";
k.querySelector(".name").innerText=l;var h=k.querySelector("input");h&&(h.value=b,h.addEventListener("blur",function(a){this.focus()}),h.addEventListener("keydown",function(a){13==a.keyCode&&(m(),a.preventDefault(),a.stopPropagation())}));b=g.active_canvas.canvas;c=b.getBoundingClientRect();var p=d=-20;c&&(d-=c.left,p-=c.top);event?(k.style.left=event.pageX+d+"px",k.style.top=event.pageY+p+"px"):(k.style.left=0.5*b.width+d+"px",k.style.top=0.5*b.height+p+"px");k.querySelector("button").addEventListener("click",
m);b.parentNode.appendChild(k)};g.prototype.prompt=function(a,b,c,d){var f=this;a=a||"";var m=document.createElement("div");m.className="graphdialog rounded";m.innerHTML="<span class='name'></span> <input autofocus type='text' class='value'/><button class='rounded'>OK</button>";m.close=function(){f.prompt_box=null;m.parentNode.removeChild(m)};m.addEventListener("mouseleave",function(a){m.close()});f.prompt_box&&f.prompt_box.close();f.prompt_box=m;m.querySelector(".name").innerText=a;m.querySelector(".value").value=
b;var l=m.querySelector("input");l.addEventListener("keydown",function(a){if(27==a.keyCode)m.close();else if(13==a.keyCode)c&&c(this.value),m.close();else return;a.preventDefault();a.stopPropagation()});m.querySelector("button").addEventListener("click",function(a){c&&c(l.value);f.setDirty(!0);m.close()});a=g.active_canvas.canvas;b=a.getBoundingClientRect();var k=-20,h=-20;b&&(k-=b.left,h-=b.top);d?(m.style.left=d.pageX+k+"px",m.style.top=d.pageY+h+"px"):(m.style.left=0.5*a.width+k+"px",m.style.top=
0.5*a.height+h+"px");a.parentNode.appendChild(m);setTimeout(function(){l.focus()},10);return m};g.search_limit=-1;g.prototype.showSearchBox=function(a){function b(b){if(b)if(f.onSearchBoxSelection)f.onSearchBoxSelection(b,a,s);else{var c=k.searchbox_extras[b];c&&(b=c.type);if(b=k.createNode(b))b.pos=s.convertEventToCanvas(a),s.graph.add(b);if(c&&c.data){if(c.data.properties)for(var e in c.data.properties)b.addProperty(c.data.properties[e][0],c.data.properties[e][0]);if(c.data.inputs)for(e in b.inputs=
[],c.data.inputs)b.addOutput(c.data.inputs[e][0],c.data.inputs[e][1]);if(c.data.outputs)for(e in b.outputs=[],c.data.outputs)b.addOutput(c.data.outputs[e][0],c.data.outputs[e][1]);c.data.title&&(b.title=c.data.title);c.data.json&&b.configure(c.data.json)}}m.close()}function c(a){var b=q;q&&q.classList.remove("selected");q?(q=a?q.nextSibling:q.previousSibling)||(q=b):q=a?l.childNodes[0]:l.childNodes[l.childNodes.length];q&&(q.classList.add("selected"),q.scrollIntoView())}function d(){function a(c,
e){var y=document.createElement("div");h||(h=c);y.innerText=c;y.dataset.type=escape(c);y.className="litegraph lite-search-item";e&&(y.className+=" "+e);y.addEventListener("click",function(a){b(unescape(this.dataset.type))});l.appendChild(y)}p=null;var c=r.value;h=null;l.innerHTML="";if(c)if(f.onSearchBox){var e=f.onSearchBox(help,c,s);if(e)for(var y=0;y<e.length;++y)a(e[y])}else{e=0;c=c.toLowerCase();for(y in k.searchbox_extras){var m=k.searchbox_extras[y];if(-1!==m.desc.toLowerCase().indexOf(c)&&
(a(m.desc,"searchbox_extra"),-1!==g.search_limit&&e++>g.search_limit))break}if(Array.prototype.filter)for(m=Object.keys(k.registered_node_types).filter(function(a){return-1!==a.toLowerCase().indexOf(c)}),y=0;y<m.length&&!(a(m[y]),-1!==g.search_limit&&e++>g.search_limit);y++);else for(y in k.registered_node_types)if(-1!=y.indexOf(c)&&(a(y),-1!==g.search_limit&&e++>g.search_limit))break}}var f=this,m=document.createElement("div");m.className="litegraph litesearchbox graphdialog rounded";m.innerHTML=
"<span class='name'>Search</span> <input autofocus type='text' class='value rounded'/><div class='helper'></div>";m.close=function(){f.search_box=null;m.parentNode.removeChild(m)};m.addEventListener("mouseleave",function(a){m.close()});f.search_box&&f.search_box.close();f.search_box=m;var l=m.querySelector(".helper"),h=null,p=null,q=null,r=m.querySelector("input");r&&(r.addEventListener("blur",function(a){this.focus()}),r.addEventListener("keydown",function(a){if(38==a.keyCode)c(!1);else if(40==a.keyCode)c(!0);
else if(27==a.keyCode)m.close();else if(13==a.keyCode)q?b(q.innerHTML):h?b(h):m.close();else{p&&clearInterval(p);p=setTimeout(d,10);return}a.preventDefault();a.stopPropagation()}));var s=g.active_canvas,t=s.canvas,u=t.getBoundingClientRect(),v=-20,y=-20;u&&(v-=u.left,y-=u.top);a?(m.style.left=a.pageX+v+"px",m.style.top=a.pageY+y+"px"):(m.style.left=0.5*t.width+v+"px",m.style.top=0.5*t.height+y+"px");t.parentNode.appendChild(m);r.focus();return m};g.prototype.showEditPropertyValue=function(a,b,c){function g(){f(q.value)}
function f(c){"number"==typeof a.properties[b]&&(c=Number(c));"array"==m&&(c=c.split(",").map(Number));a.properties[b]=c;a._graph&&a._graph._version++;if(a.onPropertyChanged)a.onPropertyChanged(b,c);p.close();a.setDirtyCanvas(!0,!0)}if(a&&void 0!==a.properties[b]){c=c||{};var m="string";null!==a.properties[b]&&(m=typeof a.properties[b]);"object"==m&&a.properties[b].length&&(m="array");var l=null;a.getPropertyInfo&&(l=a.getPropertyInfo(b));if(a.properties_info)for(var d=0;d<a.properties_info.length;++d)if(a.properties_info[d].name==
b){l=a.properties_info[d];break}void 0!==l&&null!==l&&l.type&&(m=l.type);var k="";if("string"==m||"number"==m||"array"==m)k="<input autofocus type='text' class='value'/>";else if("enum"==m&&l.values){k="<select autofocus type='text' class='value'>";for(d in l.values)var h=l.values.constructor===Array?l.values[d]:d,k=k+("<option value='"+h+"' "+(h==a.properties[b]?"selected":"")+">"+l.values[d]+"</option>");k+="</select>"}else if("boolean"==m)k="<input autofocus type='checkbox' class='value' "+(a.properties[b]?
"checked":"")+"/>";else{console.warn("unknown type: "+m);return}var p=this.createDialog("<span class='name'>"+b+"</span>"+k+"<button>OK</button>",c);if("enum"==m&&l.values){var q=p.querySelector("select");q.addEventListener("change",function(a){f(a.target.value)})}else if("boolean"==m)(q=p.querySelector("input"))&&q.addEventListener("click",function(a){f(!!q.checked)});else if(q=p.querySelector("input"))q.addEventListener("blur",function(a){this.focus()}),q.value=void 0!==a.properties[b]?a.properties[b]:
"",q.addEventListener("keydown",function(a){13==a.keyCode&&(g(),a.preventDefault(),a.stopPropagation())});p.querySelector("button").addEventListener("click",g)}};g.prototype.createDialog=function(a,b){b=b||{};var c=document.createElement("div");c.className="graphdialog";c.innerHTML=a;var g=this.canvas.getBoundingClientRect(),f=-20,m=-20;g&&(f-=g.left,m-=g.top);b.position?(f+=b.position[0],m+=b.position[1]):b.event?(f+=b.event.pageX,m+=b.event.pageY):(f+=0.5*this.canvas.width,m+=0.5*this.canvas.height);
c.style.left=f+"px";c.style.top=m+"px";this.canvas.parentNode.appendChild(c);c.close=function(){this.parentNode&&this.parentNode.removeChild(this)};return c};g.onMenuNodeCollapse=function(a,b,c,m,f){f.collapse()};g.onMenuNodePin=function(a,b,c,m,f){f.pin()};g.onMenuNodeMode=function(a,b,c,m,f){new k.ContextMenu(["Always","On Event","On Trigger","Never"],{event:c,callback:function(a){if(f)switch(a){case "On Event":f.mode=k.ON_EVENT;break;case "On Trigger":f.mode=k.ON_TRIGGER;break;case "Never":f.mode=
k.NEVER;break;default:f.mode=k.ALWAYS}},parentMenu:m,node:f});return!1};g.onMenuNodeColors=function(a,b,c,m,f){if(!f)throw"no node for color";b=[];b.push({value:null,content:"<span style='display: block; padding-left: 4px;'>No color</span>"});for(var d in g.node_colors)a=g.node_colors[d],a={value:d,content:"<span style='display: block; color: #999; padding-left: 4px; border-left: 8px solid "+a.color+"; background-color:"+a.bgcolor+"'>"+d+"</span>"},b.push(a);new k.ContextMenu(b,{event:c,callback:function(a){f&&
((a=a.value?g.node_colors[a.value]:null)?f.constructor===k.LGraphGroup?f.color=a.groupcolor:(f.color=a.color,f.bgcolor=a.bgcolor):(delete f.color,delete f.bgcolor),f.setDirtyCanvas(!0,!0))},parentMenu:m,node:f});return!1};g.onMenuNodeShapes=function(a,b,c,m,f){if(!f)throw"no node passed";new k.ContextMenu(k.VALID_SHAPES,{event:c,callback:function(a){f&&(f.shape=a,f.setDirtyCanvas(!0))},parentMenu:m,node:f});return!1};g.onMenuNodeRemove=function(a,b,c,m,f){if(!f)throw"no node passed";!1!==f.removable&&
(f.graph.remove(f),f.setDirtyCanvas(!0,!0))};g.onMenuNodeClone=function(a,b,c,m,f){!1!=f.clonable&&(a=f.clone())&&(a.pos=[f.pos[0]+5,f.pos[1]+5],f.graph.add(a),f.setDirtyCanvas(!0,!0))};g.node_colors={red:{color:"#322",bgcolor:"#533",groupcolor:"#A88"},brown:{color:"#332922",bgcolor:"#593930",groupcolor:"#b06634"},green:{color:"#232",bgcolor:"#353",groupcolor:"#8A8"},blue:{color:"#223",bgcolor:"#335",groupcolor:"#88A"},pale_blue:{color:"#2a363b",bgcolor:"#3f5159",groupcolor:"#3f789e"},cyan:{color:"#233",
bgcolor:"#355",groupcolor:"#8AA"},purple:{color:"#323",bgcolor:"#535",groupcolor:"#a1309b"},yellow:{color:"#432",bgcolor:"#653",groupcolor:"#b58b2a"},black:{color:"#222",bgcolor:"#000",groupcolor:"#444"}};g.prototype.getCanvasMenuOptions=function(){var a=null;this.getMenuOptions?a=this.getMenuOptions():(a=[{content:"Add Node",has_submenu:!0,callback:g.onMenuAdd},{content:"Add Group",callback:g.onGroupAdd}],this._graph_stack&&0<this._graph_stack.length&&a.push(null,{content:"Close subgraph",callback:this.closeSubgraph.bind(this)}));
if(this.getExtraMenuOptions){var b=this.getExtraMenuOptions(this,a);b&&(a=a.concat(b))}return a};g.prototype.getNodeMenuOptions=function(a){var b=null,b=a.getMenuOptions?a.getMenuOptions(this):[{content:"Inputs",has_submenu:!0,disabled:!0,callback:g.showMenuNodeOptionalInputs},{content:"Outputs",has_submenu:!0,disabled:!0,callback:g.showMenuNodeOptionalOutputs},null,{content:"Properties",has_submenu:!0,callback:g.onShowMenuNodeProperties},null,{content:"Title",callback:g.onShowPropertyEditor},{content:"Mode",
has_submenu:!0,callback:g.onMenuNodeMode},{content:"Resize",callback:g.onResizeNode},{content:"Collapse",callback:g.onMenuNodeCollapse},{content:"Pin",callback:g.onMenuNodePin},{content:"Colors",has_submenu:!0,callback:g.onMenuNodeColors},{content:"Shapes",has_submenu:!0,callback:g.onMenuNodeShapes},null];if(a.onGetInputs){var c=a.onGetInputs();c&&c.length&&(b[0].disabled=!1)}a.onGetOutputs&&(c=a.onGetOutputs())&&c.length&&(b[1].disabled=!1);a.getExtraMenuOptions&&(c=a.getExtraMenuOptions(this))&&
(c.push(null),b=c.concat(b));!1!==a.clonable&&b.push({content:"Clone",callback:g.onMenuNodeClone});!1!==a.removable&&b.push(null,{content:"Remove",callback:g.onMenuNodeRemove});if(a.graph&&a.graph.onGetNodeMenuOptions)a.graph.onGetNodeMenuOptions(b,a);return b};g.prototype.getGroupMenuOptions=function(a){return[{content:"Title",callback:g.onShowPropertyEditor},{content:"Color",has_submenu:!0,callback:g.onMenuNodeColors},{content:"Font size",property:"font_size",type:"Number",callback:g.onShowPropertyEditor},
null,{content:"Remove",callback:g.onMenuNodeRemove}]};g.prototype.processContextMenu=function(a,b){var c=this,m=g.active_canvas.getCanvasWindow(),f=null,d={event:b,callback:function(b,f,m){if(b)if("Remove Slot"==b.content)b=b.slot,b.input?a.removeInput(b.slot):b.output&&a.removeOutput(b.slot);else if("Disconnect Links"==b.content)b=b.slot,b.output?a.disconnectOutput(b.slot):b.input&&a.disconnectInput(b.slot);else if("Rename Slot"==b.content){b=b.slot;var l=b.input?a.getInputInfo(b.slot):a.getOutputInfo(b.slot),
g=c.createDialog("<span class='name'>Name</span><input autofocus type='text'/><button>OK</button>",f),d=g.querySelector("input");d&&l&&(d.value=l.label);g.querySelector("button").addEventListener("click",function(a){d.value&&(l&&(l.label=d.value),c.setDirty(!0));g.close()})}},extra:a},l=null;a&&(l=a.getSlotInPosition(b.canvasX,b.canvasY),g.active_node=a);l?(f=[],l&&l.output&&l.output.links&&l.output.links.length&&f.push({content:"Disconnect Links",slot:l}),f.push(l.locked?"Cannot remove":{content:"Remove Slot",
slot:l}),f.push(l.nameLocked?"Cannot rename":{content:"Rename Slot",slot:l}),d.title=(l.input?l.input.type:l.output.type)||"*",l.input&&l.input.type==k.ACTION&&(d.title="Action"),l.output&&l.output.type==k.EVENT&&(d.title="Event")):a?f=this.getNodeMenuOptions(a):(f=this.getCanvasMenuOptions(),(l=this.graph.getGroupOnPos(b.canvasX,b.canvasY))&&f.push(null,{content:"Edit Group",has_submenu:!0,submenu:{title:"Group",extra:l,options:this.getGroupMenuOptions(l)}}));f&&new k.ContextMenu(f,d,m)};this.CanvasRenderingContext2D&&
(CanvasRenderingContext2D.prototype.roundRect=function(a,b,c,m,f,g){void 0===f&&(f=5);void 0===g&&(g=f);this.moveTo(a+f,b);this.lineTo(a+c-f,b);this.quadraticCurveTo(a+c,b,a+c,b+f);this.lineTo(a+c,b+m-g);this.quadraticCurveTo(a+c,b+m,a+c-g,b+m);this.lineTo(a+g,b+m);this.quadraticCurveTo(a,b+m,a,b+m-g);this.lineTo(a,b+f);this.quadraticCurveTo(a,b,a+f,b)});k.compareObjects=function(a,b){for(var c in a)if(a[c]!=b[c])return!1;return!0};k.distance=q;k.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")+")"};k.isInsideRectangle=r;k.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)};k.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};k.overlapBounding=s;k.hex2num=function(a){"#"==a.charAt(0)&&(a=a.slice(1));a=a.toUpperCase();for(var b=Array(3),c=0,m,f,g=0;6>g;g+=2)m="0123456789ABCDEF".indexOf(a.charAt(g)),
f="0123456789ABCDEF".indexOf(a.charAt(g+1)),b[c]=16*m+f,c++;return b};k.num2hex=function(a){for(var b="#",c,m,f=0;3>f;f++)c=a[f]/16,m=a[f]%16,b+="0123456789ABCDEF".charAt(c)+"0123456789ABCDEF".charAt(m);return b};t.prototype.addItem=function(a,b,c){function m(a){var b=this.value;b&&b.has_submenu&&f.call(this,a)}function f(a){var b=this.value,f=!0;g.current_submenu&&g.current_submenu.close(a);if(c.callback){var m=c.callback.call(this,b,c,a,g,c.node);!0===m&&(f=!1)}if(b&&(b.callback&&!c.ignore_item_callbacks&&
!0!==b.disabled&&(m=b.callback.call(this,b,c,a,g,c.extra),!0===m&&(f=!1)),b.submenu)){if(!b.submenu.options)throw"ContextMenu submenu needs options";new g.constructor(b.submenu.options,{callback:b.submenu.callback,event:a,parentMenu:g,ignore_item_callbacks:b.submenu.ignore_item_callbacks,title:b.submenu.title,extra:b.submenu.extra,autoopen:c.autoopen});f=!1}f&&!g.lock&&g.close()}var g=this;c=c||{};var l=document.createElement("div");l.className="litemenu-entry submenu";var d=!1;if(null===b)l.classList.add("separator");
else{l.innerHTML=b&&b.title?b.title:a;if(l.value=b)b.disabled&&(d=!0,l.classList.add("disabled")),(b.submenu||b.has_submenu)&&l.classList.add("has_submenu");"function"==typeof b?(l.dataset.value=a,l.onclick_callback=b):l.dataset.value=b;b.className&&(l.className+=" "+b.className)}this.root.appendChild(l);d||l.addEventListener("click",f);c.autoopen&&l.addEventListener("mouseenter",m);return l};t.prototype.close=function(a,b){this.root.parentNode&&this.root.parentNode.removeChild(this.root);this.parentMenu&&
!b&&(this.parentMenu.lock=!1,this.parentMenu.current_submenu=null,void 0===a?this.parentMenu.close():a&&!t.isCursorOverElement(a,this.parentMenu.root)&&t.trigger(this.parentMenu.root,"mouseleave",a));this.current_submenu&&this.current_submenu.close(a,!0)};t.trigger=function(a,b,c,m){var f=document.createEvent("CustomEvent");f.initCustomEvent(b,!0,!0,c);f.srcElement=m;a.dispatchEvent?a.dispatchEvent(f):a.__events&&a.__events.dispatchEvent(f);return f};t.prototype.getTopMenu=function(){return this.options.parentMenu?
this.options.parentMenu.getTopMenu():this};t.prototype.getFirstEvent=function(){return this.options.parentMenu?this.options.parentMenu.getFirstEvent():this.options.event};t.isCursorOverElement=function(a,b){var c=a.pageX,m=a.pageY,f=b.getBoundingClientRect();return f?m>f.top&&m<f.top+f.height&&c>f.left&&c<f.left+f.width?!0:!1:!1};k.ContextMenu=t;k.closeAllContextMenus=function(a){a=a||window;a=a.document.querySelectorAll(".litecontextmenu");if(a.length){for(var b=[],c=0;c<a.length;c++)b.push(a[c]);
for(c in b)b[c].close?b[c].close():b[c].parentNode&&b[c].parentNode.removeChild(b[c])}};k.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)))};k.getParameterNames=
function(a){return(a+"").replace(/[/][/].*$/mg,"").replace(/\s+/g,"").replace(/[/][*][^/*]*[*][/]/g,"").split("){",1)[0].replace(/^[^(]*[(]/,"").replace(/=[^,]+/g,"").split(",").filter(Boolean)};Math.clamp=function(a,c,e){return c>a?c:e<a?e:a};"undefined"==typeof window||window.requestAnimationFrame||(window.requestAnimationFrame=window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(a){window.setTimeout(a,1E3/60)})})(this);"undefined"!=typeof exports&&(exports.LiteGraph=this.LiteGraph);
(function(u){function h(){this.addOutput("in ms","number");this.addOutput("in sec","number")}function d(){this.size=[120,80];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.color="#335";this.bgcolor="#557"}function p(){var c="input_"+(1E3*Math.random()).toFixed();this.addOutput(c,null);this.properties={name:c,type:null};var a=this;Object.defineProperty(this.properties,"name",{get:function(){return c},set:function(b){if(""!=b){var e=a.getOutputInfo(0);e.name!=b&&(e.name=b,a.graph&&a.graph.renameGlobalInput(c,
b),c=b)}},enumerable:!0});Object.defineProperty(this.properties,"type",{get:function(){return a.outputs[0].type},set:function(b){a.outputs[0].type=b;a.graph&&a.graph.changeGlobalInputType(c,a.outputs[0].type)},enumerable:!0})}function g(){var c="output_"+(1E3*Math.random()).toFixed();this.addInput(c,null);this._value=null;this.properties={name:c,type:null};var a=this;Object.defineProperty(this.properties,"name",{get:function(){return c},set:function(b){if(""!=b){var e=a.getInputInfo(0);e.name!=b&&
@@ -281,18 +281,18 @@ v.registerNodeType("math/scale",c);a.title="Average";a.desc="Average Filter";a.p
this._values.length?this._values.set(c):this._values.set(c.subarray(0,this._values.length))};v.registerNodeType("math/average",a);b.title="TendTo";b.desc="moves the output value always closer to the input";b.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=0);var b=this.properties.factor;this._value=null==this._value?a:this._value*(1-b)+a*b;this.setOutputData(0,this._value)};v.registerNodeType("math/tendTo",b);e.values="+-*/%^".split("");e.title="Operation";e.desc="Easy math operators";
e["@OP"]={type:"enum",title:"operation",values:e.values};e.prototype.getTitle=function(){return"A "+this.properties.OP+" B"};e.prototype.setValue=function(a){"string"==typeof a&&(a=parseFloat(a));this.properties.value=a};e.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)};e.prototype.onDrawBackground=function(a){this.flags.collapsed||(a.font="40px Arial",a.fillStyle="#CCC",a.textAlign="center",a.fillText(this.properties.OP,0.5*this.size[0],0.35*this.size[1]+v.NODE_TITLE_HEIGHT),a.textAlign="left")};v.registerNodeType("math/operation",e);B.title="Compare";B.desc="compares between two values";B.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,e=this.outputs.length;c<e;++c){var d=this.outputs[c];if(d.links&&d.links.length){switch(d.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)}}};B.prototype.onGetOutputs=function(){return[["A==B",
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,e=this.outputs.length;c<e;++c){var f=this.outputs[c];if(f.links&&f.links.length){switch(f.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)}}};B.prototype.onGetOutputs=function(){return[["A==B",
"boolean"],["A!=B","boolean"],["A>B","boolean"],["A<B","boolean"],["A>=B","boolean"],["A<=B","boolean"]]};v.registerNodeType("math/compare",B);v.registerSearchboxExtra("math/compare","==",{outputs:[["A==B","boolean"]],title:"A==B"});v.registerSearchboxExtra("math/compare","!=",{outputs:[["A!=B","boolean"]],title:"A!=B"});v.registerSearchboxExtra("math/compare",">",{outputs:[["A>B","boolean"]],title:"A>B"});v.registerSearchboxExtra("math/compare","<",{outputs:[["A<B","boolean"]],title:"A<B"});v.registerSearchboxExtra("math/compare",
">=",{outputs:[["A>=B","boolean"]],title:"A>=B"});v.registerSearchboxExtra("math/compare","<=",{outputs:[["A<=B","boolean"]],title:"A<=B"});f.values="> < == != <= >=".split(" ");f["@OP"]={type:"enum",title:"operation",values:f.values};f.title="Condition";f.desc="evaluates condition between A and B";f.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)};v.registerNodeType("math/condition",f);n.title="Accumulate";n.desc="Increments a value every time";n.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)};
v.registerNodeType("math/accumulate",n);l.title="Trigonometry";l.desc="Sin Cos Tan";l.filter="shader";l.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 e=this.properties.offset,c=this.findInputSlot("offset");-1!=c&&(e=this.getInputData(c));for(var c=0,d=this.outputs.length;c<d;++c){switch(this.outputs[c].name){case "sin":value=Math.sin(a);break;case "cos":value=Math.cos(a);
v.registerNodeType("math/accumulate",n);l.title="Trigonometry";l.desc="Sin Cos Tan";l.filter="shader";l.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 e=this.properties.offset,c=this.findInputSlot("offset");-1!=c&&(e=this.getInputData(c));for(var c=0,f=this.outputs.length;c<f;++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+e)}};l.prototype.onGetInputs=function(){return[["v","number"],["amplitude","number"],["offset","number"]]};l.prototype.onGetOutputs=function(){return[["sin","number"],["cos","number"],["tan","number"],["asin","number"],["acos","number"],["atan","number"]]};v.registerNodeType("math/trigonometry",l);v.registerSearchboxExtra("math/trigonometry",
"SIN()",{outputs:[["sin","number"]],title:"SIN()"});v.registerSearchboxExtra("math/trigonometry","COS()",{outputs:[["cos","number"]],title:"COS()"});v.registerSearchboxExtra("math/trigonometry","TAN()",{outputs:[["tan","number"]],title:"TAN()"});w.title="Formula";w.desc="Compute formula";w.prototype.onExecute=function(){if(v.allow_scripts){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;this._func&&this._func_code==
this.properties.formula||(this._func=new Function("x","y","TIME","return "+this.properties.formula),this._func_code=this.properties.formula);a=this._func(a,b,this.graph.globaltime);this.setOutputData(0,a)}};w.prototype.getTitle=function(){return this._func_code||""};w.prototype.onDrawBackground=function(){var a=this.properties.formula;this.outputs&&this.outputs.length&&(this.outputs[0].label=a)};v.registerNodeType("math/formula",w);x.title="Vec2->XY";x.desc="vector 2 to components";x.prototype.onExecute=
function(){var a=this.getInputData(0);null!=a&&(this.setOutputData(0,a[0]),this.setOutputData(1,a[1]))};v.registerNodeType("math3d/vec2-to-xyz",x);z.title="XY->Vec2";z.desc="components to vector2";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._data;c[0]=a;c[1]=b;this.setOutputData(0,c)};v.registerNodeType("math3d/xy-to-vec2",z);A.title="Vec3->XYZ";A.desc="vector 3 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]))};v.registerNodeType("math3d/vec3-to-xyz",A);D.title="XYZ->Vec3";D.desc="components to vector3";D.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 e=this._data;e[0]=a;e[1]=b;e[2]=c;this.setOutputData(0,e)};v.registerNodeType("math3d/xyz-to-vec3",
D);C.title="Vec4->XYZW";C.desc="vector 4 to components";C.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]))};v.registerNodeType("math3d/vec4-to-xyzw",C);E.title="XYZW->Vec4";E.desc="components to vector4";E.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 e=this.getInputData(3);null==e&&(e=this.properties.w);var d=this._data;d[0]=a;d[1]=b;d[2]=c;d[3]=e;this.setOutputData(0,d)};v.registerNodeType("math3d/xyzw-to-vec4",E);u.glMatrix&&(u=function(){this.addOutput("quat","quat");this.properties={x:0,y:0,z:0,w:1};this._value=quat.create()},u.title="Quaternion",u.desc="quaternion",u.prototype.onExecute=function(){this._value[0]=this.properties.x;this._value[1]=this.properties.y;this._value[2]=this.properties.z;this._value[3]=
null==c&&(c=this.properties.z);var e=this.getInputData(3);null==e&&(e=this.properties.w);var f=this._data;f[0]=a;f[1]=b;f[2]=c;f[3]=e;this.setOutputData(0,f)};v.registerNodeType("math3d/xyzw-to-vec4",E);u.glMatrix&&(u=function(){this.addOutput("quat","quat");this.properties={x:0,y:0,z:0,w:1};this._value=quat.create()},u.title="Quaternion",u.desc="quaternion",u.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)},v.registerNodeType("math3d/quaternion",u),u=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()},u.title="Rotation",u.desc="quaternion rotation",u.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)},v.registerNodeType("math3d/rotation",u),u=function(){this.addInputs([["vec3","vec3"],["quat","quat"]]);this.addOutput("result","vec3");this.properties={vec:[0,0,1]}},u.title="Rot. Vec3",u.desc="rotate a point",u.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))},v.registerNodeType("math3d/rotate_vec3",
u),u=function(){this.addInputs([["A","quat"],["B","quat"]]);this.addOutput("A*B","quat");this._value=quat.create()},u.title="Mult. Quat",u.desc="rotate quaternion",u.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))}},v.registerNodeType("math3d/mult-quat",u),u=function(){this.addInputs([["A","quat"],["B","quat"],["factor","number"]]);this.addOutput("slerp","quat");this.addProperty("factor",

View File

@@ -7851,7 +7851,15 @@ function ContextMenu( values, options )
root.addEventListener("mouseleave", function(e) {
if(that.lock)
return;
that.close(e);
if(root.closing_timer)
clearTimeout( root.closing_timer );
root.closing_timer = setTimeout( that.close.bind(that), 500 );
//that.close(e);
});
root.addEventListener("mouseenter", function(e) {
if(root.closing_timer)
clearTimeout( root.closing_timer );
});
//insert before checking position
@@ -7947,6 +7955,7 @@ ContextMenu.prototype.addItem = function( name, value, options )
var value = this.value;
if(!value || !value.has_submenu)
return;
//if it is a submenu, autoopen like the item was clicked
inner_onclick.call(this,e);
}