This commit is contained in:
tamat
2019-01-18 15:43:41 +01:00
3 changed files with 123 additions and 117 deletions

View File

@@ -2690,7 +2690,7 @@ LGraphNode.prototype.computeSize = function( minHeight, out )
* Allows to pass
*
* @method addWidget
* @return {Float32Array[4]} the total size
* @return {Object} the created widget
*/
LGraphNode.prototype.addWidget = function( type, name, value, callback, options )
{
@@ -4125,7 +4125,7 @@ LGraphCanvas.prototype.processMouseDown = function(e)
{
//double click node
if( node.onDblClick)
node.onDblClick(e,[e.canvasX - node.pos[0], e.canvasY - node.pos[1]],graphcanvas);
node.onDblClick(e,[e.canvasX - node.pos[0], e.canvasY - node.pos[1]], this);
this.processNodeDblClicked( node );
block_drag_node = true;
}
@@ -8062,11 +8062,14 @@ function ContextMenu( values, options )
function on_mouse_wheel(e)
{
var pos = parseInt( root.style.top );
root.style.top = (pos + e.deltaY * 0.1).toFixed() + "px";
root.style.top = (pos + e.deltaY * options.scroll_speed).toFixed() + "px";
e.preventDefault();
return true;
}
if(!options.scroll_speed)
options.scroll_speed = 0.1;
root.addEventListener("wheel", on_mouse_wheel, true);
root.addEventListener("mousewheel", on_mouse_wheel, true);

222
build/litegraph.min.js vendored
View File

@@ -2,117 +2,117 @@
a&&a.constructor===String&&(a=document.querySelector(a));this.max_zoom=10;this.min_zoom=0.1;this.zoom_modify_alpha=!0;this.title_text_font="bold "+k.NODE_TEXT_SIZE+"px Arial";this.inner_text_font="normal "+k.NODE_SUBTEXT_SIZE+"px Arial";this.node_title_color=k.NODE_TITLE_COLOR;this.default_link_color=k.LINK_COLOR;this.default_connection_color={input_off:"#AAB",input_on:"#7F7",output_off:"#AAB",output_on:"#7F7"};this.highquality_render=!0;this.use_gradients=!1;this.editor_alpha=1;this.pause_rendering=
!1;this.render_only_selected=this.clear_background=this.render_shadows=!0;this.live_mode=!1;this.allow_searchbox=this.allow_interaction=this.allow_dragnodes=this.allow_dragcanvas=this.show_info=!0;this.drag_mode=this.allow_reconnect_links=!1;this.filter=this.dragging_rectangle=null;this.always_render_background=!1;this.render_canvas_border=!0;this.render_connections_shadows=!1;this.render_connection_arrows=this.render_curved_connections=this.render_connections_border=!0;this.render_execution_order=
!1;this.canvas_mouse=[0,0];this.onDrawOverlay=this.onDrawForeground=this.onDrawBackground=this.onMouse=this.onSearchBoxSelection=this.onSearchBox=null;this.connections_width=3;this.round_radius=8;this.node_widget=this.current_node=null;this.last_mouse_position=[0,0];this.visible_area=new Float32Array(4);this.visible_links=[];b&&b.attachCanvas(this);this.setCanvas(a);this.clear();c.skip_render||this.startRendering();this.autoresize=c.autoresize}function t(a,b){return Math.sqrt((b[0]-a[0])*(b[0]-a[0])+
(b[1]-a[1])*(b[1]-a[1]))}function u(a,b,c,e,f,m){return c<a&&c+f>a&&e<b&&e+m>b?!0:!1}function y(a,b){var c=a[0]+a[2],e=a[1]+a[3],f=b[1]+b[3];return a[0]>b[0]+b[2]||a[1]>f||c<b[0]||e<b[1]?!1:!0}function v(a,b){function c(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 e=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 e.close(),a.preventDefault(),!0},!0);f.addEventListener("wheel",c,!0);f.addEventListener("mousewheel",c,!0);this.root=f;if(b.title){var m=document.createElement("div");m.className="litemenu-title";m.innerHTML=b.title;f.appendChild(m)}var m=0,n;for(n in a){var k=
a.constructor==Array?a[n]:n;null!=k&&k.constructor!==String&&(k=void 0===k.content?String(k):k.content);this.addItem(k,a[n],b);m++}f.addEventListener("mouseleave",function(a){e.lock||(f.closing_timer&&clearTimeout(f.closing_timer),f.closing_timer=setTimeout(e.close.bind(e,a),500))});f.addEventListener("mouseenter",function(a){f.closing_timer&&clearTimeout(f.closing_timer)});n=document;b.event&&(n=b.event.target.ownerDocument);n||(n=document);n.body.appendChild(f);m=b.left||0;n=b.top||0;if(b.event){m=
b.event.pageX-10;n=b.event.pageY-10;b.title&&(n-=20);b.parentMenu&&(m=b.parentMenu.root.getBoundingClientRect(),m=m.left+m.width);var k=document.body.getBoundingClientRect(),p=f.getBoundingClientRect();m>k.width-p.width-10&&(m=k.width-p.width-10);n>k.height-p.height-10&&(n=k.height-p.height-10)}f.style.left=m+"px";f.style.top=n+"px"}var k=w.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 c=b.name,e=a.lastIndexOf("/");b.category=a.substr(0,e);b.title||(b.title=c);if(b.prototype)for(var f in q.prototype)b.prototype[f]||(b.prototype[f]=q.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[c]=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,c,e){for(var f=Array(b.length),m="",n=k.getParameterNames(b),p=0;p<n.length;++p)m+="this.addInput('"+
n[p]+"',"+(c&&c[p]?"'"+c[p]+"'":"0")+");\n";c=Function(m+("this.addOutput('out',"+(e?"'"+e+"'":0)+");\n"));c.title=a.split("/").pop();c.desc="Generated from "+b.name;c.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,c)},addNodeMethod:function(a,b){q.prototype[a]=b;for(var c in this.registered_node_types){var e=this.registered_node_types[c];e.prototype[a]&&(e.prototype["_"+a]=e.prototype[a]);e.prototype[a]=
b}},createNode:function(a,b,c){var e=this.registered_node_types[a];if(!e)return k.debug&&console.log('GraphNode type "'+a+'" not registered.'),null;b=b||e.title||a;e=new e(b);e.type=a;!e.title&&b&&(e.title=b);e.properties||(e.properties={});e.properties_info||(e.properties_info=[]);e.flags||(e.flags={});e.size||(e.size=e.computeSize());e.pos||(e.pos=k.DEFAULT_POSITION.concat());e.mode||(e.mode=k.ALWAYS);if(c)for(var f in c)e[f]=c[f];return e},getNodeType:function(a){return this.registered_node_types[a]},
getNodeTypesInCategory:function(a,b){var c=[],e;for(e in this.registered_node_types){var f=this.registered_node_types[e];b&&f.filter&&f.filter!=b||(""==a?null==f.category&&c.push(f):f.category==a&&c.push(f))}return c},getNodeTypesCategories:function(){var a={"":1},b;for(b in this.registered_node_types)this.registered_node_types[b].category&&!this.registered_node_types[b].skip_list&&(a[this.registered_node_types[b].category]=1);var c=[];for(b in a)c.push(b);return c},reloadNodes:function(a){var b=
document.getElementsByTagName("script"),c=[],e;for(e in b)c.push(b[e]);b=document.getElementsByTagName("head")[0];a=document.location.href+a;for(e in c){var f=c[e].src;if(f&&f.substr(0,a.length)==a)try{k.debug&&console.log("Reloading: "+f);var m=document.createElement("script");m.type="text/javascript";m.src=f;b.appendChild(m);b.removeChild(c[e])}catch(n){if(k.throw_errors)throw n;k.debug&&console.log("Error while reloading "+f)}}k.debug&&console.log("Nodes reloaded")},cloneObject:function(a,b){if(null==
a)return null;var c=JSON.parse(JSON.stringify(a));if(!b)return c;for(var e in c)b[e]=c[e];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 c=a.split(","),e=b.split(","),f=0;f<c.length;++f)for(var m=0;m<e.length;++m)if(c[f]==e[m])return!0;return!1},registerSearchboxExtra:function(a,b,c){this.searchbox_extras[b]={type:a,desc:b,data:c}}};
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()};w.LGraph=k.LGraph=d;d.supported_types=["number","string","boolean"];d.prototype.getSupportedTypes=function(){return this.supported_types||d.supported_types};d.STATUS_STOPPED=1;d.STATUS_RUNNING=2;d.prototype.clear=function(){this.stop();this.status=
d.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")};d.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)};d.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))}};d.prototype.start=
function(a){if(this.status!=d.STATUS_RUNNING){this.status=d.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 c=function(){-1==b.execution_timer_id&&(window.requestAnimationFrame(c),b.runStep(1,!this.catch_errors))};this.execution_timer_id=-1;c()}else this.execution_timer_id=setInterval(function(){b.runStep(1,!this.catch_errors)},
a)}};d.prototype.stop=function(){if(this.status!=d.STATUS_STOPPED){this.status=d.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")}};d.prototype.runStep=function(a,b){a=a||1;var c=k.getTime();this.globaltime=0.001*(c-this.starttime);var e=this._nodes_executable?this._nodes_executable:this._nodes;if(e){if(b){for(var f=0;f<a;f++){for(var m=
0,n=e.length;m<n;++m){var p=e[m];if(p.mode==k.ALWAYS&&p.onExecute)p.onExecute()}this.fixedtime+=this.fixedtime_lapse;if(this.onExecuteStep)this.onExecuteStep()}if(this.onAfterExecute)this.onAfterExecute()}else try{for(f=0;f<a;f++){m=0;for(n=e.length;m<n;++m)if(p=e[m],p.mode==k.ALWAYS&&p.onExecute)p.onExecute();this.fixedtime+=this.fixedtime_lapse;if(this.onExecuteStep)this.onExecuteStep()}if(this.onAfterExecute)this.onAfterExecute();this.errors_in_execution=!1}catch(d){this.errors_in_execution=!0;
if(k.throw_errors)throw d;k.debug&&console.log("Error during execution: "+d);this.stop()}e=k.getTime();c=e-c;0==c&&(c=1);this.execution_time=0.001*c;this.globaltime+=0.001*c;this.iteration+=1;this.elapsed_time=0.001*(e-this.last_update_time);this.last_update_time=e}};d.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])};
d.prototype.computeExecutionOrder=function(a,b){for(var c=[],e=[],f={},m={},n={},p=0,d=this._nodes.length;p<d;++p){var g=this._nodes[p];if(!a||g.onExecute){f[g.id]=g;var h=0;if(g.inputs)for(var s=0,l=g.inputs.length;s<l;s++)g.inputs[s]&&null!=g.inputs[s].link&&(h+=1);0==h?(e.push(g),b&&(g._level=1)):(b&&(g._level=0),n[g.id]=h)}}for(;0!=e.length;)if(g=e.shift(),c.push(g),delete f[g.id],g.outputs)for(p=0;p<g.outputs.length;p++)if(d=g.outputs[p],null!=d&&null!=d.links&&0!=d.links.length)for(s=0;s<d.links.length;s++)(h=
this.links[d.links[s]])&&!m[h.id]&&(l=this.getNodeById(h.target_id),null==l?m[h.id]=!0:(b&&(!l._level||l._level<=g._level)&&(l._level=g._level+1),m[h.id]=!0,n[l.id]-=1,0==n[l.id]&&e.push(l)));for(p in f)c.push(f[p]);c.length!=this._nodes.length&&k.debug&&console.warn("something went wrong, nodes missing");d=c.length;for(p=0;p<d;++p)c[p].order=p;c=c.sort(function(a,b){var c=a.constructor.priority||a.priority||0,f=b.constructor.priority||b.priority||0;return c==f?a.order-b.order:c-f});for(p=0;p<d;++p)c[p].order=
p;return c};d.prototype.getAncestors=function(a){for(var b=[],c=[a],e={};c.length;){var f=c.shift();if(f.inputs){e[f.id]||f==a||(e[f.id]=!0,b.push(f));for(var m=0;m<f.inputs.length;++m){var n=f.getInputNode(m);n&&-1==b.indexOf(n)&&c.push(n)}}}b.sort(function(a,b){return a.order-b.order});return b};d.prototype.arrange=function(a){a=a||40;for(var b=this.computeExecutionOrder(!1,!0),c=[],e=0;e<b.length;++e){var f=b[e],m=f._level||1;c[m]||(c[m]=[]);c[m].push(f)}b=a;for(e=0;e<c.length;++e)if(m=c[e]){for(var n=
100,k=a,p=0;p<m.length;++p)f=m[p],f.pos[0]=b,f.pos[1]=k,f.size[0]>n&&(n=f.size[0]),k+=f.size[1]+a;b+=n+a}this.setDirtyCanvas(!0,!0)};d.prototype.getTime=function(){return this.globaltime};d.prototype.getFixedTime=function(){return this.fixedtime};d.prototype.getElapsedTime=function(){return this.elapsed_time};d.prototype.sendEventToAllNodes=function(a,b,c){c=c||k.ALWAYS;var e=this._nodes_in_order?this._nodes_in_order:this._nodes;if(e)for(var f=0,m=e.length;f<m;++f){var n=e[f];if(n[a]&&n.mode==c)if(void 0===
b)n[a]();else if(b&&b.constructor===Array)n[a].apply(n,b);else n[a](b)}};d.prototype.sendActionToCanvas=function(a,b){if(this.list_of_graphcanvas)for(var c=0;c<this.list_of_graphcanvas.length;++c){var e=this.list_of_graphcanvas[c];e[a]&&e[a].apply(e,b)}};d.prototype.add=function(a,b){if(a)if(a.constructor===r)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}};d.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 c=a.inputs[b];null!=c.link&&a.disconnectInput(b)}if(a.outputs)for(b=0;b<a.outputs.length;b++)c=a.outputs[b],null!=c.links&&c.links.length&&a.disconnectOutput(b);if(a.onRemoved)a.onRemoved();a.graph=null;this._version++;
if(this.list_of_graphcanvas)for(b=0;b<this.list_of_graphcanvas.length;++b)c=this.list_of_graphcanvas[b],c.selected_nodes[a.id]&&delete c.selected_nodes[a.id],c.node_dragged==a&&(c.node_dragged=null);b=this._nodes.indexOf(a);-1!=b&&this._nodes.splice(b,1);delete this._nodes_by_id[a.id];if(this.onNodeRemoved)this.onNodeRemoved(a);this.setDirtyCanvas(!0,!0);this.change();this.updateExecutionOrder()}};d.prototype.getNodeById=function(a){return null==a?null:this._nodes_by_id[a]};d.prototype.findNodesByClass=
function(a){for(var b=[],c=0,e=this._nodes.length;c<e;++c)this._nodes[c].constructor===a&&b.push(this._nodes[c]);return b};d.prototype.findNodesByType=function(a){a=a.toLowerCase();for(var b=[],c=0,e=this._nodes.length;c<e;++c)this._nodes[c].type.toLowerCase()==a&&b.push(this._nodes[c]);return b};d.prototype.findNodesByTitle=function(a){for(var b=[],c=0,e=this._nodes.length;c<e;++c)this._nodes[c].title==a&&b.push(this._nodes[c]);return b};d.prototype.getNodeOnPos=function(a,b,c,e){c=c||this._nodes;
for(var f=c.length-1;0<=f;f--){var m=c[f];if(m.isPointInside(a,b,e))return m}return null};d.prototype.getGroupOnPos=function(a,b){for(var c=this._groups.length-1;0<=c;c--){var e=this._groups[c];if(e.isPointInside(a,b,2,!0))return e}return null};d.prototype.addGlobalInput=function(a,b,c){this.global_inputs[a]={name:a,type:b,value:c};this._version++;if(this.onGlobalInputAdded)this.onGlobalInputAdded(a,b);if(this.onGlobalsChange)this.onGlobalsChange()};d.prototype.setGlobalInputData=function(a,b){var c=
this.global_inputs[a];c&&(c.value=b)};d.prototype.setInputData=d.prototype.setGlobalInputData;d.prototype.getGlobalInputData=function(a){return(a=this.global_inputs[a])?a.value:null};d.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()}};d.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)};d.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};d.prototype.addGlobalOutput=function(a,b,c){this.global_outputs[a]={name:a,type:b,value:c};this._version++;if(this.onGlobalOutputAdded)this.onGlobalOutputAdded(a,b);if(this.onGlobalsChange)this.onGlobalsChange()};d.prototype.setGlobalOutputData=function(a,b){var c=this.global_outputs[a];c&&(c.value=b)};d.prototype.getGlobalOutputData=function(a){return(a=this.global_outputs[a])?a.value:null};d.prototype.getOutputData=d.prototype.getGlobalOutputData;
d.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()};d.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)};d.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};d.prototype.triggerInput=function(a,b){for(var c=this.findNodesByTitle(a),e=0;e<c.length;++e)c[e].onTrigger(b)};d.prototype.setCallback=
function(a,b){for(var c=this.findNodesByTitle(a),e=0;e<c.length;++e)c[e].setTrigger(b)};d.prototype.connectionChange=function(a,b){this.updateExecutionOrder();if(this.onConnectionChange)this.onConnectionChange(a);this._version++;this.sendActionToCanvas("onConnectionChange")};d.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};d.prototype.clearTriggeredSlots=function(){for(var a in this.links){var b=
this.links[a];b&&b._last_time&&(b._last_time=0)}};d.prototype.change=function(){k.debug&&console.log("Graph changed");this.sendActionToCanvas("setDirty",[!0,!0]);if(this.on_change)this.on_change(this)};d.prototype.setDirtyCanvas=function(a,b){this.sendActionToCanvas("setDirty",[a,b])};d.prototype.serialize=function(){for(var a=[],b=0,c=this._nodes.length;b<c;++b)a.push(this._nodes[b].serialize());c=[];for(b in this.links){var e=this.links[b];c.push([e.id,e.origin_id,e.origin_slot,e.target_id,e.target_slot,
e.type])}e=[];for(b=0;b<this._groups.length;++b)e.push(this._groups[b].serialize());return{last_node_id:this.last_node_id,last_link_id:this.last_link_id,nodes:a,links:c,groups:e,config:this.config}};d.prototype.configure=function(a,b){if(a){b||this.clear();var c=a.nodes;if(a.links&&a.links.constructor===Array){for(var e=[],f=0;f<a.links.length;++f){var m=a.links[f],n=new l;n.configure(m);e[n.id]=n}a.links=e}for(f in a)this[f]=a[f];e=!1;this._nodes=[];if(c){f=0;for(m=c.length;f<m;++f){var n=c[f],p=
k.createNode(n.type,n.title);p?(p.id=n.id,this.add(p,!0)):(k.debug&&console.log("Node not found: "+n.type),e=!0)}f=0;for(m=c.length;f<m;++f)n=c[f],(p=this.getNodeById(n.id))&&p.configure(n)}this._groups.length=0;if(a.groups)for(f=0;f<a.groups.length;++f)c=new k.LGraphGroup,c.configure(a.groups[f]),this.add(c);this.updateExecutionOrder();this._version++;this.setDirtyCanvas(!0,!0);return e}};d.prototype.load=function(a){var b=this,c=new XMLHttpRequest;c.open("GET",a,!0);c.send(null);c.onload=function(a){200!==
c.status?console.error("Error loading graph:",c.status,c.response):(a=JSON.parse(c.response),b.configure(a))};c.onerror=function(a){console.error("Error loading graph:",a)}};d.prototype.onNodeTrace=function(a,b,c){};l.prototype.configure=function(a){a.constructor===Array?(this.id=a[0],this.origin_id=a[1],this.origin_slot=a[2],this.target_id=a[3],this.target_slot=a[4],this.type=a[5]):(this.id=a.id,this.type=a.type,this.origin_id=a.origin_id,this.origin_slot=a.origin_slot,this.target_id=a.target_id,
this.target_slot=a.target_slot)};l.prototype.serialize=function(){return[this.id,this.type,this.origin_id,this.origin_slot,this.target_id,this.target_slot]};k.LLink=l;w.LGraphNode=k.LGraphNode=q;q.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={}};q.prototype.configure=function(a){this.graph&&this.graph._version++;for(var b in a)if("console"!=b)if("properties"==b)for(var c in a.properties){if(this.properties[c]=a.properties[c],this.onPropertyChanged)this.onPropertyChanged(c,a.properties[c])}else null!=a[b]&&("object"==typeof a[b]?this[b]&&this[b].configure?this[b].configure(a[b]):this[b]=k.cloneObject(a[b],this[b]):this[b]=a[b]);
a.title||(this.title=this.constructor.title);if(this.onConnectionsChange){if(this.inputs)for(c=0;c<this.inputs.length;++c){b=this.inputs[c];var e=this.graph?this.graph.links[b.link]:null;this.onConnectionsChange(k.INPUT,c,!0,e,b)}if(this.outputs)for(c=0;c<this.outputs.length;++c){var f=this.outputs[c];if(f.links)for(b=0;b<f.links.length;++b)e=this.graph?this.graph.links[f.links[b]]:null,this.onConnectionsChange(k.OUTPUT,c,!0,e,f)}}if(this.onConfigure)this.onConfigure(a)};q.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};q.prototype.clone=function(){var a=k.createNode(this.type),b=k.cloneObject(this.serialize());if(b.inputs)for(var c=0;c<b.inputs.length;++c)b.inputs[c].link=null;if(b.outputs)for(c=0;c<b.outputs.length;++c)b.outputs[c].links&&(b.outputs[c].links.length=0);delete b.id;a.configure(b);
return a};q.prototype.toString=function(){return JSON.stringify(this.serialize())};q.prototype.getTitle=function(){return this.title||this.constructor.title};q.prototype.setOutputData=function(a,b){if(this.outputs&&!(-1==a||a>=this.outputs.length)){var c=this.outputs[a];if(c&&(c._data=b,this.outputs[a].links))for(c=0;c<this.outputs[a].links.length;c++)this.graph.links[this.outputs[a].links[c]].data=b}};q.prototype.getInputData=function(a,b){if(this.inputs&&!(a>=this.inputs.length||null==this.inputs[a].link)){var c=
this.graph.links[this.inputs[a].link];if(!c)return null;if(!b)return c.data;var e=this.graph.getNodeById(c.origin_id);if(!e)return c.data;if(e.updateOutputData)e.updateOutputData(c.origin_slot);else if(e.onExecute)e.onExecute();return c.data}};q.prototype.getInputDataByName=function(a,b){var c=this.findInputSlot(a);return-1==c?null:this.getInputData(c,b)};q.prototype.isInputConnected=function(a){return this.inputs?a<this.inputs.length&&null!=this.inputs[a].link:!1};q.prototype.getInputInfo=function(a){return this.inputs?
a<this.inputs.length?this.inputs[a]:null:null};q.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};q.prototype.getInputOrProperty=function(a){if(!this.inputs||!this.inputs.length)return this.properties?this.properties[a]:null;for(var b=0,c=this.inputs.length;b<c;++b){var e=this.inputs[b];if(a==e.name&&null!=e.link&&(e=this.graph.links[e.link]))return e.data}return this.properties[a]};
q.prototype.getOutputData=function(a){return!this.outputs||a>=this.outputs.length?null:this.outputs[a]._data};q.prototype.getOutputInfo=function(a){return this.outputs?a<this.outputs.length?this.outputs[a]:null:null};q.prototype.isOutputConnected=function(a){return this.outputs?a<this.outputs.length&&this.outputs[a].links&&this.outputs[a].links.length:!1};q.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};q.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=[],c=0;c<a.links.length;c++){var e=this.graph.links[a.links[c]];e&&(e=this.graph.getNodeById(e.target_id))&&b.push(e)}return b};q.prototype.trigger=function(a,b){if(this.outputs&&this.outputs.length){this.graph&&(this.graph._last_trigger_time=k.getTime());for(var c=0;c<this.outputs.length;++c){var e=this.outputs[c];
!e||e.type!==k.EVENT||a&&e.name!=a||this.triggerSlot(c,b)}}};q.prototype.triggerSlot=function(a,b,c){if(this.outputs&&(a=this.outputs[a])&&(a=a.links)&&a.length){this.graph&&(this.graph._last_trigger_time=k.getTime());for(var e=0;e<a.length;++e){var f=a[e];if(null==c||c==f){var m=this.graph.links[a[e]];if(m&&(m._last_time=k.getTime(),f=this.graph.getNodeById(m.target_id)))if(m=f.inputs[m.target_slot],f.onAction)f.onAction(m.name,b);else if(f.mode===k.ON_TRIGGER&&f.onExecute)f.onExecute(b)}}}};q.prototype.clearTriggeredSlot=
function(a,b){if(this.outputs){var c=this.outputs[a];if(c&&(c=c.links)&&c.length)for(var e=0;e<c.length;++e){var f=c[e];if(null==b||b==f)if(f=this.graph.links[c[e]])f._last_time=0}}};q.prototype.addProperty=function(a,b,c,e){c={name:a,type:c,default_value:b};if(e)for(var f in e)c[f]=e[f];this.properties_info||(this.properties_info=[]);this.properties_info.push(c);this.properties||(this.properties={});this.properties[a]=b;return c};q.prototype.addOutput=function(a,b,c){a={name:a,type:b,links:null};
if(c)for(var e in c)a[e]=c[e];this.outputs||(this.outputs=[]);this.outputs.push(a);if(this.onOutputAdded)this.onOutputAdded(a);this.size=this.computeSize();this.setDirtyCanvas(!0,!0);return a};q.prototype.addOutputs=function(a){for(var b=0;b<a.length;++b){var c=a[b],e={name:c[0],type:c[1],link:null};if(a[2])for(var f in c[2])e[f]=c[2][f];this.outputs||(this.outputs=[]);this.outputs.push(e);if(this.onOutputAdded)this.onOutputAdded(e)}this.size=this.computeSize();this.setDirtyCanvas(!0,!0)};q.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 c=this.outputs[b].links,e=0;e<c.length;++e){var f=this.graph.links[c[e]];f&&(f.origin_slot-=1)}this.size=this.computeSize();if(this.onOutputRemoved)this.onOutputRemoved(a);this.setDirtyCanvas(!0,!0)};q.prototype.addInput=function(a,b,c){a={name:a,type:b||0,link:null};if(c)for(var e in c)a[e]=c[e];this.inputs||(this.inputs=[]);this.inputs.push(a);this.size=
this.computeSize();if(this.onInputAdded)this.onInputAdded(a);this.setDirtyCanvas(!0,!0);return a};q.prototype.addInputs=function(a){for(var b=0;b<a.length;++b){var c=a[b],e={name:c[0],type:c[1],link:null};if(a[2])for(var f in c[2])e[f]=c[2][f];this.inputs||(this.inputs=[]);this.inputs.push(e);if(this.onInputAdded)this.onInputAdded(e)}this.size=this.computeSize();this.setDirtyCanvas(!0,!0)};q.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 c=
this.graph.links[this.inputs[b].link];c&&(c.target_slot-=1)}this.size=this.computeSize();if(this.onInputRemoved)this.onInputRemoved(a);this.setDirtyCanvas(!0,!0)};q.prototype.addConnection=function(a,b,c,e){a={name:a,type:b,pos:c,direction:e,links:null};this.connections.push(a);return a};q.prototype.computeSize=function(a,b){function c(a){return a?m*a.length*0.6:0}var e=Math.max(this.inputs?this.inputs.length:1,this.outputs?this.outputs.length:1),f=b||new Float32Array([0,0]),e=Math.max(e,1),m=k.NODE_TEXT_SIZE;
f[1]=(this.constructor.slot_start_y||0)+e*(m+1)+4;this.widgets&&this.widgets.length&&(f[1]+=this.widgets.length*(k.NODE_WIDGET_HEIGHT+4)+8);var e=c(this.title),n=0,p=0;if(this.inputs)for(var g=0,d=this.inputs.length;g<d;++g){var h=this.inputs[g],h=h.label||h.name||"",h=c(h);n<h&&(n=h)}if(this.outputs)for(g=0,d=this.outputs.length;g<d;++g)h=this.outputs[g],h=h.label||h.name||"",h=c(h),p<h&&(p=h);f[0]=Math.max(n+p+10,e);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};q.prototype.addWidget=function(a,b,c,e,f){this.widgets||(this.widgets=[]);b={type:a.toLowerCase(),name:b,value:c,callback:e,options:f||{}};void 0!==b.options.y&&(b.y=b.options.y);e||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};q.prototype.addCustomWidget=
function(a){this.widgets||(this.widgets=[]);this.widgets.push(a);return a};q.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;if(this.onBounding)this.onBounding(a);return a};q.prototype.isPointInside=function(a,b,c,e){c=c||0;var f=this.graph&&this.graph.isLive()?0:20;e&&(f=0);if(this.flags&&this.flags.collapsed){if(u(a,b,this.pos[0]-c,this.pos[1]-k.NODE_TITLE_HEIGHT-c,(this._collapsed_width||
k.NODE_COLLAPSED_WIDTH)+2*c,k.NODE_TITLE_HEIGHT+2*c))return!0}else if(this.pos[0]-4-c<a&&this.pos[0]+this.size[0]+4+c>a&&this.pos[1]-f-c<b&&this.pos[1]+this.size[1]+c>b)return!0;return!1};q.prototype.getSlotInPosition=function(a,b){var c=new Float32Array(2);if(this.inputs)for(var e=0,f=this.inputs.length;e<f;++e){var m=this.inputs[e];this.getConnectionPos(!0,e,c);if(u(a,b,c[0]-10,c[1]-5,20,10))return{input:m,slot:e,link_pos:c,locked:m.locked}}if(this.outputs)for(e=0,f=this.outputs.length;e<f;++e)if(m=
this.outputs[e],this.getConnectionPos(!1,e,c),u(a,b,c[0]-10,c[1]-5,20,10))return{output:m,slot:e,link_pos:c,locked:m.locked};return null};q.prototype.findInputSlot=function(a){if(!this.inputs)return-1;for(var b=0,c=this.inputs.length;b<c;++b)if(a==this.inputs[b].name)return b;return-1};q.prototype.findOutputSlot=function(a){if(!this.outputs)return-1;for(var b=0,c=this.outputs.length;b<c;++b)if(a==this.outputs[b].name)return b;return-1};q.prototype.connect=function(a,b,c){c=c||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."),
null;if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return k.debug&&console.log("Connect: Error, no slot of name "+a),null}else if(!this.outputs||a>=this.outputs.length)return k.debug&&console.log("Connect: Error, slot number not found"),null;b&&b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"target node is null";if(b==this)return null;if(c.constructor===String){if(c=b.findInputSlot(c),-1==c)return k.debug&&console.log("Connect: Error, no slot of name "+c),null}else{if(c===
k.EVENT)return null;if(!b.inputs||c>=b.inputs.length)return k.debug&&console.log("Connect: Error, slot number not found"),null}null!=b.inputs[c].link&&b.disconnectInput(c);var e=this.outputs[a];if(b.onConnectInput&&!1===b.onConnectInput(c,e.type,e))return null;var f=b.inputs[c],m=null;if(k.isValidConnection(e.type,f.type)){m=new l(this.graph.last_link_id++,f.type,this.id,a,b.id,c);this.graph.links[m.id]=m;null==e.links&&(e.links=[]);e.links.push(m.id);b.inputs[c].link=m.id;this.graph&&this.graph._version++;
if(this.onConnectionsChange)this.onConnectionsChange(k.OUTPUT,a,!0,m,e);if(b.onConnectionsChange)b.onConnectionsChange(k.INPUT,c,!0,m,f);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(k.INPUT,b,c,this,a),this.graph.onNodeConnectionChange(k.OUTPUT,this,a,b,c))}this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this,m);return m};q.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 c=this.outputs[a];if(!c||!c.links||0==c.links.length)return!1;if(b){b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"Target Node not found";for(var e=0,f=c.links.length;e<f;e++){var m=c.links[e],n=this.graph.links[m];if(n.target_id==b.id){c.links.splice(e,1);var p=b.inputs[n.target_slot];p.link=null;delete this.graph.links[m];this.graph&&this.graph._version++;
if(b.onConnectionsChange)b.onConnectionsChange(k.INPUT,n.target_slot,!1,n,p);if(this.onConnectionsChange)this.onConnectionsChange(k.OUTPUT,a,!1,n,c);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,n.target_slot));break}}}else{e=0;for(f=c.links.length;e<f;e++)if(m=c.links[e],n=this.graph.links[m]){b=this.graph.getNodeById(n.target_id);
this.graph&&this.graph._version++;if(b){p=b.inputs[n.target_slot];p.link=null;if(b.onConnectionsChange)b.onConnectionsChange(k.INPUT,n.target_slot,!1,n,p);if(this.graph&&this.graph.onNodeConnectionChange)this.graph.onNodeConnectionChange(k.INPUT,b,n.target_slot)}delete this.graph.links[m];if(this.onConnectionsChange)this.onConnectionsChange(k.OUTPUT,a,!1,n,c);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(k.OUTPUT,this,a),this.graph.onNodeConnectionChange(k.INPUT,
b,n.target_slot))}c.links=null}this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this);return!0};q.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 c=this.inputs[a].link;this.inputs[a].link=null;var e=this.graph.links[c];if(e){var f=
this.graph.getNodeById(e.origin_id);if(!f)return!1;var m=f.outputs[e.origin_slot];if(!m||!m.links||0==m.links.length)return!1;for(var n=0,p=m.links.length;n<p;n++)if(m.links[n]==c){m.links.splice(n,1);break}delete this.graph.links[c];this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(k.INPUT,a,!1,e,b);if(f.onConnectionsChange)f.onConnectionsChange(k.OUTPUT,n,!1,e,m);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(k.OUTPUT,f,n),
this.graph.onNodeConnectionChange(k.INPUT,this,a))}this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this);return!0};q.prototype.getConnectionPos=function(a,b,c){c=c||new Float32Array(2);var e=0;a&&this.inputs&&(e=this.inputs.length);!a&&this.outputs&&(e=this.outputs.length);if(this.flags.collapsed)return b=this._collapsed_width||k.NODE_COLLAPSED_WIDTH,this.flags.horizontal?(c[0]=this.pos[0]+0.5*b,c[1]=a?this.pos[1]-k.NODE_TITLE_HEIGHT:this.pos[1]):(c[0]=a?this.pos[0]:this.pos[0]+b,c[1]=this.pos[1]-
0.5*k.NODE_TITLE_HEIGHT),c;if(a&&-1==b)return c[0]=this.pos[0]+10,c[1]=this.pos[1]+10,c;if(a&&e>b&&this.inputs[b].pos)return c[0]=this.pos[0]+this.inputs[b].pos[0],c[1]=this.pos[1]+this.inputs[b].pos[1],c;if(!a&&e>b&&this.outputs[b].pos)return c[0]=this.pos[0]+this.outputs[b].pos[0],c[1]=this.pos[1]+this.outputs[b].pos[1],c;if(this.flags.horizontal)return c[0]=this.pos[0]+this.size[0]/e*(b+0.5),c[1]=a?this.pos[1]-k.NODE_TITLE_HEIGHT:this.pos[1]+this.size[1],c;c[0]=a?this.pos[0]:this.pos[0]+this.size[0]+
1;c[1]=this.pos[1]+10+b*k.NODE_SLOT_HEIGHT+(this.constructor.slot_start_y||0);return c};q.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)};q.prototype.trace=function(a){this.console||(this.console=[]);this.console.push(a);this.console.length>q.MAX_CONSOLE&&this.console.shift();this.graph.onNodeTrace(this,a)};q.prototype.setDirtyCanvas=function(a,b){this.graph&&this.graph.sendActionToCanvas("setDirty",
[a,b])};q.prototype.loadImage=function(a){var b=new Image;b.src=k.node_images_path+a;b.ready=!1;var c=this;b.onload=function(){this.ready=!0;c.setDirtyCanvas(!0)};return b};q.prototype.captureInput=function(a){if(this.graph&&this.graph.list_of_graphcanvas)for(var b=this.graph.list_of_graphcanvas,c=0;c<b.length;++c){var e=b[c];if(a||e.node_capturing_input==this)e.node_capturing_input=a?this:null}};q.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)};q.prototype.pin=function(a){this.graph._version++;this.flags.pinned=void 0===a?!this.flags.pinned:a};q.prototype.localToScreen=function(a,b,c){return[(a+this.pos[0])*c.scale+c.offset[0],(b+this.pos[1])*c.scale+c.offset[1]]};w.LGraphGroup=k.LGraphGroup=r;r.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})};r.prototype.configure=function(a){this.title=a.title;
this._bounding.set(a.bounding);this.color=a.color;this.font=a.font};r.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}};r.prototype.move=function(a,b,c){this._pos[0]+=a;this._pos[1]+=b;if(!c)for(c=0;c<this._nodes.length;++c){var e=this._nodes[c];e.pos[0]+=a;e.pos[1]+=b}};r.prototype.recomputeInsideNodes=function(){this._nodes.length=0;for(var a=this.graph._nodes,
b=new Float32Array(4),c=0;c<a.length;++c){var e=a[c];e.getBounding(b);y(this._bounding,b)&&this._nodes.push(e)}};r.prototype.isPointInside=q.prototype.isPointInside;r.prototype.setDirtyCanvas=q.prototype.setDirtyCanvas;w.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._subgraph_node,b=this._graph_stack.pop();this.selected_nodes={};this.highlighted_links={};b.attachCanvas(this);this.setDirty(!0,!0);
a&&(this.centerOnNode(a),this.selectNodes([a]))}};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;a.tabindex="1";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 c=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes,5),e=!1,f=300>k.getTime()-this.last_mouseclick;this.canvas_mouse[0]=a.canvasX;this.canvas_mouse[1]=a.canvasY;this.canvas.focus();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,e=!0);var m=
!1;if(c&&this.allow_interaction&&!e){this.live_mode||c.flags.pinned||this.bringToFront(c);if(!this.connecting_node&&!c.flags.collapsed&&!this.live_mode)if(!e&&!1!==c.resizable&&u(a.canvasX,a.canvasY,c.pos[0]+c.size[0]-5,c.pos[1]+c.size[1]-5,10,10))this.resizing_node=c,this.canvas.style.cursor="se-resize",e=!0;else{if(c.outputs)for(var n=0,p=c.outputs.length;n<p;++n){var h=c.outputs[n],d=c.getConnectionPos(!1,n);if(u(a.canvasX,a.canvasY,d[0]-15,d[1]-10,30,20)){this.connecting_node=c;this.connecting_output=
h;this.connecting_pos=c.getConnectionPos(!1,n);this.connecting_slot=n;a.shiftKey&&c.disconnectOutput(n);if(f){if(c.onOutputDblClick)c.onOutputDblClick(n,a)}else if(c.onOutputClick)c.onOutputClick(n,a);e=!0;break}}if(c.inputs)for(n=0,p=c.inputs.length;n<p;++n)if(h=c.inputs[n],d=c.getConnectionPos(!0,n),u(a.canvasX,a.canvasY,d[0]-15,d[1]-10,30,20)){if(f){if(c.onInputDblClick)c.onInputDblClick(n,a)}else if(c.onInputClick)c.onInputClick(n,a);if(null!==h.link){e=this.graph.links[h.link];c.disconnectInput(n);
if(this.allow_reconnect_links||a.shiftKey)this.connecting_node=this.graph._nodes_by_id[e.origin_id],this.connecting_slot=e.origin_slot,this.connecting_output=this.connecting_node.outputs[this.connecting_slot],this.connecting_pos=this.connecting_node.getConnectionPos(!1,this.connecting_slot);e=this.dirty_bgcanvas=!0}}}!e&&u(a.canvasX,a.canvasY,c.pos[0],c.pos[1]-k.NODE_TITLE_HEIGHT,k.NODE_TITLE_HEIGHT,k.NODE_TITLE_HEIGHT)&&(c.collapse(),e=!0);if(!e){n=!1;if(p=this.processNodeWidgets(c,this.canvas_mouse,
a))n=!0,this.node_widget=[c,p];if(f&&this.selected_nodes[c.id]){if(c.onDblClick)c.onDblClick(a,[a.canvasX-c.pos[0],a.canvasY-c.pos[1]],graphcanvas);this.processNodeDblClicked(c);n=!0}c.onMouseDown&&c.onMouseDown(a,[a.canvasX-c.pos[0],a.canvasY-c.pos[1]],this)?n=!0:this.live_mode&&(n=m=!0);n||(this.allow_dragnodes&&(this.node_dragged=c),this.selected_nodes[c.id]||this.processNodeSelected(c,a));this.dirty_canvas=!0}}else{for(n=0;n<this.visible_links.length;++n)if(c=this.visible_links[n],m=c._pos,!(a.canvasX<
m[0]-4||a.canvasX<m[0]+4||a.canvasY<m[1]-4||a.canvasY<m[1]-4)){console.log(c);break}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>t([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);m=!0}!e&&
m&&this.allow_dragcanvas&&(this.dragging_canvas=!0)}else 2!=a.which&&3==a.which&&this.processContextMenu(c,a);this.last_mouse[0]=a.localX;this.last_mouse[1]=a.localY;this.last_mouseclick=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],c=[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(c[0]/this.scale,c[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]+=c[0]/this.scale,this.offset[1]+=c[1]/this.scale,this.dirty_bgcanvas=
this.dirty_canvas=!0;else if(this.allow_interaction){this.connecting_node&&(this.dirty_canvas=!0);for(var e=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&&e!=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(e){if(!e.mouseOver&&(e.mouseOver=!0,this.node_over=e,this.dirty_canvas=!0,
e.onMouseEnter))e.onMouseEnter(a);if(e.onMouseMove)e.onMouseMove(a,[a.canvasX-e.pos[0],a.canvasY-e.pos[1]],this);if(this.connecting_node&&(f=this._highlight_input||[0,0],!this.isOverNodeBox(e,a.canvasX,a.canvasY))){var m=this.isOverNodeInput(e,a.canvasX,a.canvasY,f);-1!=m&&e.inputs[m]?k.isValidConnection(this.connecting_output.type,e.inputs[m].type)&&(this._highlight_input=f):this._highlight_input=null}this.canvas&&(u(a.canvasX,a.canvasY,e.pos[0]+e.size[0]-5,e.pos[1]+e.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!=e&&this.node_capturing_input.onMouseMove)this.node_capturing_input.onMouseMove(a);if(this.node_dragged&&!this.live_mode){for(b in this.selected_nodes)e=this.selected_nodes[b],e.pos[0]+=c[0]/this.scale,e.pos[1]+=c[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],c=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]<c&&(this.resizing_node.size[1]=c),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]),c=this.selected_group.pos[1]-Math.round(this.selected_group.pos[1]);this.selected_group.move(b,c,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;c=new Float32Array(4);
this.deselectAllNodes();var e=Math.abs(this.dragging_rectangle[2]),f=Math.abs(this.dragging_rectangle[3]),m=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]-e:this.dragging_rectangle[0];this.dragging_rectangle[1]=m;this.dragging_rectangle[2]=e;this.dragging_rectangle[3]=f;f=[];for(m=0;m<b.length;++m)e=b[m],e.getBounding(c),y(this.dragging_rectangle,c)&&f.push(e);f.length&&this.selectNodes(f)}this.dragging_rectangle=
null}else if(this.connecting_node){this.dirty_bgcanvas=this.dirty_canvas=!0;if(e=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes))this.connecting_output.type==k.EVENT&&this.isOverNodeBox(e,a.canvasX,a.canvasY)?this.connecting_node.connect(this.connecting_slot,e,k.EVENT):(b=this.isOverNodeInput(e,a.canvasX,a.canvasY),-1!=b?this.connecting_node.connect(this.connecting_slot,e,b):(b=e.getInputInfo(0),this.connecting_output.type==k.EVENT?this.connecting_node.connect(this.connecting_slot,
e,k.EVENT):b&&!b.link&&k.isValidConnection(b.type&&this.connecting_output.type)&&this.connecting_node.connect(this.connecting_slot,e,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{e=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes);!e&&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 c=this.scale;0<b?c*=1.1:0>b&&(c*=1/1.1);this.setZoom(c,[a.localX,a.localY]);
this.graph.change();a.preventDefault();return!1}};g.prototype.isOverNodeBox=function(a,b,c){var e=k.NODE_TITLE_HEIGHT;return u(b,c,a.pos[0]+2,a.pos[1]+2-e,e-4,e-4)?!0:!1};g.prototype.isOverNodeInput=function(a,b,c,e){if(a.inputs)for(var f=0,m=a.inputs.length;f<m;++f){var n=a.getConnectionPos(!0,f);if(u(b,c,n[0]-10,n[1]-5,20,10))return e&&(e[0]=n[0],e[1]=n[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 c in this.selected_nodes)if(this.selected_nodes[c].onKeyDown)this.selected_nodes[c].onKeyDown(a)}else if("keyup"==
(b[1]-a[1])*(b[1]-a[1]))}function u(a,b,c,e,f,m){return c<a&&c+f>a&&e<b&&e+m>b?!0:!1}function y(a,b){var c=a[0]+a[2],e=a[1]+a[3],f=b[1]+b[3];return a[0]>b[0]+b[2]||a[1]>f||c<b[0]||e<b[1]?!1:!0}function v(a,b){function c(a){var c=parseInt(f.style.top);f.style.top=(c+a.deltaY*b.scroll_speed).toFixed()+"px";a.preventDefault();return!0}this.options=b=b||{};var e=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 e.close(),a.preventDefault(),!0},!0);b.scroll_speed||(b.scroll_speed=0.1);f.addEventListener("wheel",c,!0);f.addEventListener("mousewheel",c,!0);this.root=f;if(b.title){var m=document.createElement("div");
m.className="litemenu-title";m.innerHTML=b.title;f.appendChild(m)}var m=0,n;for(n in a){var k=a.constructor==Array?a[n]:n;null!=k&&k.constructor!==String&&(k=void 0===k.content?String(k):k.content);this.addItem(k,a[n],b);m++}f.addEventListener("mouseleave",function(a){e.lock||(f.closing_timer&&clearTimeout(f.closing_timer),f.closing_timer=setTimeout(e.close.bind(e,a),500))});f.addEventListener("mouseenter",function(a){f.closing_timer&&clearTimeout(f.closing_timer)});n=document;b.event&&(n=b.event.target.ownerDocument);
n||(n=document);n.body.appendChild(f);m=b.left||0;n=b.top||0;if(b.event){m=b.event.pageX-10;n=b.event.pageY-10;b.title&&(n-=20);b.parentMenu&&(m=b.parentMenu.root.getBoundingClientRect(),m=m.left+m.width);var k=document.body.getBoundingClientRect(),p=f.getBoundingClientRect();m>k.width-p.width-10&&(m=k.width-p.width-10);n>k.height-p.height-10&&(n=k.height-p.height-10)}f.style.left=m+"px";f.style.top=n+"px"}var k=w.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 c=b.name,e=a.lastIndexOf("/");b.category=a.substr(0,e);b.title||(b.title=c);if(b.prototype)for(var f in q.prototype)b.prototype[f]||(b.prototype[f]=q.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[c]=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,c,e){for(var f=Array(b.length),
m="",n=k.getParameterNames(b),p=0;p<n.length;++p)m+="this.addInput('"+n[p]+"',"+(c&&c[p]?"'"+c[p]+"'":"0")+");\n";c=Function(m+("this.addOutput('out',"+(e?"'"+e+"'":0)+");\n"));c.title=a.split("/").pop();c.desc="Generated from "+b.name;c.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,c)},addNodeMethod:function(a,b){q.prototype[a]=b;for(var c in this.registered_node_types){var e=this.registered_node_types[c];
e.prototype[a]&&(e.prototype["_"+a]=e.prototype[a]);e.prototype[a]=b}},createNode:function(a,b,c){var e=this.registered_node_types[a];if(!e)return k.debug&&console.log('GraphNode type "'+a+'" not registered.'),null;b=b||e.title||a;e=new e(b);e.type=a;!e.title&&b&&(e.title=b);e.properties||(e.properties={});e.properties_info||(e.properties_info=[]);e.flags||(e.flags={});e.size||(e.size=e.computeSize());e.pos||(e.pos=k.DEFAULT_POSITION.concat());e.mode||(e.mode=k.ALWAYS);if(c)for(var f in c)e[f]=c[f];
return e},getNodeType:function(a){return this.registered_node_types[a]},getNodeTypesInCategory:function(a,b){var c=[],e;for(e in this.registered_node_types){var f=this.registered_node_types[e];b&&f.filter&&f.filter!=b||(""==a?null==f.category&&c.push(f):f.category==a&&c.push(f))}return c},getNodeTypesCategories:function(){var a={"":1},b;for(b in this.registered_node_types)this.registered_node_types[b].category&&!this.registered_node_types[b].skip_list&&(a[this.registered_node_types[b].category]=1);
var c=[];for(b in a)c.push(b);return c},reloadNodes:function(a){var b=document.getElementsByTagName("script"),c=[],e;for(e in b)c.push(b[e]);b=document.getElementsByTagName("head")[0];a=document.location.href+a;for(e in c){var f=c[e].src;if(f&&f.substr(0,a.length)==a)try{k.debug&&console.log("Reloading: "+f);var m=document.createElement("script");m.type="text/javascript";m.src=f;b.appendChild(m);b.removeChild(c[e])}catch(n){if(k.throw_errors)throw n;k.debug&&console.log("Error while reloading "+f)}}k.debug&&
console.log("Nodes reloaded")},cloneObject:function(a,b){if(null==a)return null;var c=JSON.parse(JSON.stringify(a));if(!b)return c;for(var e in c)b[e]=c[e];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 c=a.split(","),e=b.split(","),f=0;f<c.length;++f)for(var m=0;m<e.length;++m)if(c[f]==e[m])return!0;return!1},registerSearchboxExtra:function(a,
b,c){this.searchbox_extras[b]={type:a,desc:b,data:c}}};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()};w.LGraph=k.LGraph=d;d.supported_types=["number","string","boolean"];d.prototype.getSupportedTypes=function(){return this.supported_types||d.supported_types};d.STATUS_STOPPED=1;d.STATUS_RUNNING=
2;d.prototype.clear=function(){this.stop();this.status=d.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")};d.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)};d.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))}};d.prototype.start=function(a){if(this.status!=d.STATUS_RUNNING){this.status=d.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 c=function(){-1==b.execution_timer_id&&(window.requestAnimationFrame(c),b.runStep(1,!this.catch_errors))};this.execution_timer_id=-1;c()}else this.execution_timer_id=
setInterval(function(){b.runStep(1,!this.catch_errors)},a)}};d.prototype.stop=function(){if(this.status!=d.STATUS_STOPPED){this.status=d.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")}};d.prototype.runStep=function(a,b){a=a||1;var c=k.getTime();this.globaltime=0.001*(c-this.starttime);var e=this._nodes_executable?this._nodes_executable:
this._nodes;if(e){if(b){for(var f=0;f<a;f++){for(var m=0,n=e.length;m<n;++m){var p=e[m];if(p.mode==k.ALWAYS&&p.onExecute)p.onExecute()}this.fixedtime+=this.fixedtime_lapse;if(this.onExecuteStep)this.onExecuteStep()}if(this.onAfterExecute)this.onAfterExecute()}else try{for(f=0;f<a;f++){m=0;for(n=e.length;m<n;++m)if(p=e[m],p.mode==k.ALWAYS&&p.onExecute)p.onExecute();this.fixedtime+=this.fixedtime_lapse;if(this.onExecuteStep)this.onExecuteStep()}if(this.onAfterExecute)this.onAfterExecute();this.errors_in_execution=
!1}catch(d){this.errors_in_execution=!0;if(k.throw_errors)throw d;k.debug&&console.log("Error during execution: "+d);this.stop()}e=k.getTime();c=e-c;0==c&&(c=1);this.execution_time=0.001*c;this.globaltime+=0.001*c;this.iteration+=1;this.elapsed_time=0.001*(e-this.last_update_time);this.last_update_time=e}};d.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])};d.prototype.computeExecutionOrder=function(a,b){for(var c=[],e=[],f={},m={},n={},p=0,d=this._nodes.length;p<d;++p){var g=this._nodes[p];if(!a||g.onExecute){f[g.id]=g;var h=0;if(g.inputs)for(var s=0,l=g.inputs.length;s<l;s++)g.inputs[s]&&null!=g.inputs[s].link&&(h+=1);0==h?(e.push(g),b&&(g._level=1)):(b&&(g._level=0),n[g.id]=h)}}for(;0!=e.length;)if(g=e.shift(),c.push(g),delete f[g.id],g.outputs)for(p=0;p<g.outputs.length;p++)if(d=g.outputs[p],
null!=d&&null!=d.links&&0!=d.links.length)for(s=0;s<d.links.length;s++)(h=this.links[d.links[s]])&&!m[h.id]&&(l=this.getNodeById(h.target_id),null==l?m[h.id]=!0:(b&&(!l._level||l._level<=g._level)&&(l._level=g._level+1),m[h.id]=!0,n[l.id]-=1,0==n[l.id]&&e.push(l)));for(p in f)c.push(f[p]);c.length!=this._nodes.length&&k.debug&&console.warn("something went wrong, nodes missing");d=c.length;for(p=0;p<d;++p)c[p].order=p;c=c.sort(function(a,b){var c=a.constructor.priority||a.priority||0,f=b.constructor.priority||
b.priority||0;return c==f?a.order-b.order:c-f});for(p=0;p<d;++p)c[p].order=p;return c};d.prototype.getAncestors=function(a){for(var b=[],c=[a],e={};c.length;){var f=c.shift();if(f.inputs){e[f.id]||f==a||(e[f.id]=!0,b.push(f));for(var m=0;m<f.inputs.length;++m){var n=f.getInputNode(m);n&&-1==b.indexOf(n)&&c.push(n)}}}b.sort(function(a,b){return a.order-b.order});return b};d.prototype.arrange=function(a){a=a||40;for(var b=this.computeExecutionOrder(!1,!0),c=[],e=0;e<b.length;++e){var f=b[e],m=f._level||
1;c[m]||(c[m]=[]);c[m].push(f)}b=a;for(e=0;e<c.length;++e)if(m=c[e]){for(var n=100,k=a,p=0;p<m.length;++p)f=m[p],f.pos[0]=b,f.pos[1]=k,f.size[0]>n&&(n=f.size[0]),k+=f.size[1]+a;b+=n+a}this.setDirtyCanvas(!0,!0)};d.prototype.getTime=function(){return this.globaltime};d.prototype.getFixedTime=function(){return this.fixedtime};d.prototype.getElapsedTime=function(){return this.elapsed_time};d.prototype.sendEventToAllNodes=function(a,b,c){c=c||k.ALWAYS;var e=this._nodes_in_order?this._nodes_in_order:this._nodes;
if(e)for(var f=0,m=e.length;f<m;++f){var n=e[f];if(n[a]&&n.mode==c)if(void 0===b)n[a]();else if(b&&b.constructor===Array)n[a].apply(n,b);else n[a](b)}};d.prototype.sendActionToCanvas=function(a,b){if(this.list_of_graphcanvas)for(var c=0;c<this.list_of_graphcanvas.length;++c){var e=this.list_of_graphcanvas[c];e[a]&&e[a].apply(e,b)}};d.prototype.add=function(a,b){if(a)if(a.constructor===r)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}};d.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 c=a.inputs[b];null!=c.link&&a.disconnectInput(b)}if(a.outputs)for(b=0;b<a.outputs.length;b++)c=a.outputs[b],null!=c.links&&c.links.length&&a.disconnectOutput(b);
if(a.onRemoved)a.onRemoved();a.graph=null;this._version++;if(this.list_of_graphcanvas)for(b=0;b<this.list_of_graphcanvas.length;++b)c=this.list_of_graphcanvas[b],c.selected_nodes[a.id]&&delete c.selected_nodes[a.id],c.node_dragged==a&&(c.node_dragged=null);b=this._nodes.indexOf(a);-1!=b&&this._nodes.splice(b,1);delete this._nodes_by_id[a.id];if(this.onNodeRemoved)this.onNodeRemoved(a);this.setDirtyCanvas(!0,!0);this.change();this.updateExecutionOrder()}};d.prototype.getNodeById=function(a){return null==
a?null:this._nodes_by_id[a]};d.prototype.findNodesByClass=function(a){for(var b=[],c=0,e=this._nodes.length;c<e;++c)this._nodes[c].constructor===a&&b.push(this._nodes[c]);return b};d.prototype.findNodesByType=function(a){a=a.toLowerCase();for(var b=[],c=0,e=this._nodes.length;c<e;++c)this._nodes[c].type.toLowerCase()==a&&b.push(this._nodes[c]);return b};d.prototype.findNodesByTitle=function(a){for(var b=[],c=0,e=this._nodes.length;c<e;++c)this._nodes[c].title==a&&b.push(this._nodes[c]);return b};
d.prototype.getNodeOnPos=function(a,b,c,e){c=c||this._nodes;for(var f=c.length-1;0<=f;f--){var m=c[f];if(m.isPointInside(a,b,e))return m}return null};d.prototype.getGroupOnPos=function(a,b){for(var c=this._groups.length-1;0<=c;c--){var e=this._groups[c];if(e.isPointInside(a,b,2,!0))return e}return null};d.prototype.addGlobalInput=function(a,b,c){this.global_inputs[a]={name:a,type:b,value:c};this._version++;if(this.onGlobalInputAdded)this.onGlobalInputAdded(a,b);if(this.onGlobalsChange)this.onGlobalsChange()};
d.prototype.setGlobalInputData=function(a,b){var c=this.global_inputs[a];c&&(c.value=b)};d.prototype.setInputData=d.prototype.setGlobalInputData;d.prototype.getGlobalInputData=function(a){return(a=this.global_inputs[a])?a.value:null};d.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()}};d.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)};d.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};d.prototype.addGlobalOutput=function(a,b,c){this.global_outputs[a]={name:a,type:b,value:c};this._version++;if(this.onGlobalOutputAdded)this.onGlobalOutputAdded(a,b);if(this.onGlobalsChange)this.onGlobalsChange()};d.prototype.setGlobalOutputData=function(a,b){var c=this.global_outputs[a];c&&(c.value=b)};d.prototype.getGlobalOutputData=function(a){return(a=this.global_outputs[a])?
a.value:null};d.prototype.getOutputData=d.prototype.getGlobalOutputData;d.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()};d.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)};d.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};d.prototype.triggerInput=function(a,b){for(var c=this.findNodesByTitle(a),
e=0;e<c.length;++e)c[e].onTrigger(b)};d.prototype.setCallback=function(a,b){for(var c=this.findNodesByTitle(a),e=0;e<c.length;++e)c[e].setTrigger(b)};d.prototype.connectionChange=function(a,b){this.updateExecutionOrder();if(this.onConnectionChange)this.onConnectionChange(a);this._version++;this.sendActionToCanvas("onConnectionChange")};d.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};d.prototype.clearTriggeredSlots=function(){for(var a in this.links){var b=this.links[a];b&&b._last_time&&(b._last_time=0)}};d.prototype.change=function(){k.debug&&console.log("Graph changed");this.sendActionToCanvas("setDirty",[!0,!0]);if(this.on_change)this.on_change(this)};d.prototype.setDirtyCanvas=function(a,b){this.sendActionToCanvas("setDirty",[a,b])};d.prototype.serialize=function(){for(var a=[],b=0,c=this._nodes.length;b<c;++b)a.push(this._nodes[b].serialize());c=[];for(b in this.links){var e=
this.links[b];c.push([e.id,e.origin_id,e.origin_slot,e.target_id,e.target_slot,e.type])}e=[];for(b=0;b<this._groups.length;++b)e.push(this._groups[b].serialize());return{last_node_id:this.last_node_id,last_link_id:this.last_link_id,nodes:a,links:c,groups:e,config:this.config}};d.prototype.configure=function(a,b){if(a){b||this.clear();var c=a.nodes;if(a.links&&a.links.constructor===Array){for(var e=[],f=0;f<a.links.length;++f){var m=a.links[f],n=new l;n.configure(m);e[n.id]=n}a.links=e}for(f in a)this[f]=
a[f];e=!1;this._nodes=[];if(c){f=0;for(m=c.length;f<m;++f){var n=c[f],p=k.createNode(n.type,n.title);p?(p.id=n.id,this.add(p,!0)):(k.debug&&console.log("Node not found: "+n.type),e=!0)}f=0;for(m=c.length;f<m;++f)n=c[f],(p=this.getNodeById(n.id))&&p.configure(n)}this._groups.length=0;if(a.groups)for(f=0;f<a.groups.length;++f)c=new k.LGraphGroup,c.configure(a.groups[f]),this.add(c);this.updateExecutionOrder();this._version++;this.setDirtyCanvas(!0,!0);return e}};d.prototype.load=function(a){var b=this,
c=new XMLHttpRequest;c.open("GET",a,!0);c.send(null);c.onload=function(a){200!==c.status?console.error("Error loading graph:",c.status,c.response):(a=JSON.parse(c.response),b.configure(a))};c.onerror=function(a){console.error("Error loading graph:",a)}};d.prototype.onNodeTrace=function(a,b,c){};l.prototype.configure=function(a){a.constructor===Array?(this.id=a[0],this.origin_id=a[1],this.origin_slot=a[2],this.target_id=a[3],this.target_slot=a[4],this.type=a[5]):(this.id=a.id,this.type=a.type,this.origin_id=
a.origin_id,this.origin_slot=a.origin_slot,this.target_id=a.target_id,this.target_slot=a.target_slot)};l.prototype.serialize=function(){return[this.id,this.type,this.origin_id,this.origin_slot,this.target_id,this.target_slot]};k.LLink=l;w.LGraphNode=k.LGraphNode=q;q.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={}};q.prototype.configure=function(a){this.graph&&this.graph._version++;for(var b in a)if("console"!=b)if("properties"==b)for(var c in a.properties){if(this.properties[c]=a.properties[c],this.onPropertyChanged)this.onPropertyChanged(c,a.properties[c])}else null!=a[b]&&("object"==typeof a[b]?this[b]&&this[b].configure?this[b].configure(a[b]):
this[b]=k.cloneObject(a[b],this[b]):this[b]=a[b]);a.title||(this.title=this.constructor.title);if(this.onConnectionsChange){if(this.inputs)for(c=0;c<this.inputs.length;++c){b=this.inputs[c];var e=this.graph?this.graph.links[b.link]:null;this.onConnectionsChange(k.INPUT,c,!0,e,b)}if(this.outputs)for(c=0;c<this.outputs.length;++c){var f=this.outputs[c];if(f.links)for(b=0;b<f.links.length;++b)e=this.graph?this.graph.links[f.links[b]]:null,this.onConnectionsChange(k.OUTPUT,c,!0,e,f)}}if(this.onConfigure)this.onConfigure(a)};
q.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};q.prototype.clone=function(){var a=k.createNode(this.type),b=k.cloneObject(this.serialize());if(b.inputs)for(var c=0;c<b.inputs.length;++c)b.inputs[c].link=null;if(b.outputs)for(c=0;c<b.outputs.length;++c)b.outputs[c].links&&(b.outputs[c].links.length=
0);delete b.id;a.configure(b);return a};q.prototype.toString=function(){return JSON.stringify(this.serialize())};q.prototype.getTitle=function(){return this.title||this.constructor.title};q.prototype.setOutputData=function(a,b){if(this.outputs&&!(-1==a||a>=this.outputs.length)){var c=this.outputs[a];if(c&&(c._data=b,this.outputs[a].links))for(c=0;c<this.outputs[a].links.length;c++)this.graph.links[this.outputs[a].links[c]].data=b}};q.prototype.getInputData=function(a,b){if(this.inputs&&!(a>=this.inputs.length||
null==this.inputs[a].link)){var c=this.graph.links[this.inputs[a].link];if(!c)return null;if(!b)return c.data;var e=this.graph.getNodeById(c.origin_id);if(!e)return c.data;if(e.updateOutputData)e.updateOutputData(c.origin_slot);else if(e.onExecute)e.onExecute();return c.data}};q.prototype.getInputDataByName=function(a,b){var c=this.findInputSlot(a);return-1==c?null:this.getInputData(c,b)};q.prototype.isInputConnected=function(a){return this.inputs?a<this.inputs.length&&null!=this.inputs[a].link:!1};
q.prototype.getInputInfo=function(a){return this.inputs?a<this.inputs.length?this.inputs[a]:null:null};q.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};q.prototype.getInputOrProperty=function(a){if(!this.inputs||!this.inputs.length)return this.properties?this.properties[a]:null;for(var b=0,c=this.inputs.length;b<c;++b){var e=this.inputs[b];if(a==
e.name&&null!=e.link&&(e=this.graph.links[e.link]))return e.data}return this.properties[a]};q.prototype.getOutputData=function(a){return!this.outputs||a>=this.outputs.length?null:this.outputs[a]._data};q.prototype.getOutputInfo=function(a){return this.outputs?a<this.outputs.length?this.outputs[a]:null:null};q.prototype.isOutputConnected=function(a){return this.outputs?a<this.outputs.length&&this.outputs[a].links&&this.outputs[a].links.length:!1};q.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};q.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=[],c=0;c<a.links.length;c++){var e=this.graph.links[a.links[c]];e&&(e=this.graph.getNodeById(e.target_id))&&b.push(e)}return b};q.prototype.trigger=function(a,b){if(this.outputs&&this.outputs.length){this.graph&&
(this.graph._last_trigger_time=k.getTime());for(var c=0;c<this.outputs.length;++c){var e=this.outputs[c];!e||e.type!==k.EVENT||a&&e.name!=a||this.triggerSlot(c,b)}}};q.prototype.triggerSlot=function(a,b,c){if(this.outputs&&(a=this.outputs[a])&&(a=a.links)&&a.length){this.graph&&(this.graph._last_trigger_time=k.getTime());for(var e=0;e<a.length;++e){var f=a[e];if(null==c||c==f){var m=this.graph.links[a[e]];if(m&&(m._last_time=k.getTime(),f=this.graph.getNodeById(m.target_id)))if(m=f.inputs[m.target_slot],
f.onAction)f.onAction(m.name,b);else if(f.mode===k.ON_TRIGGER&&f.onExecute)f.onExecute(b)}}}};q.prototype.clearTriggeredSlot=function(a,b){if(this.outputs){var c=this.outputs[a];if(c&&(c=c.links)&&c.length)for(var e=0;e<c.length;++e){var f=c[e];if(null==b||b==f)if(f=this.graph.links[c[e]])f._last_time=0}}};q.prototype.addProperty=function(a,b,c,e){c={name:a,type:c,default_value:b};if(e)for(var f in e)c[f]=e[f];this.properties_info||(this.properties_info=[]);this.properties_info.push(c);this.properties||
(this.properties={});this.properties[a]=b;return c};q.prototype.addOutput=function(a,b,c){a={name:a,type:b,links:null};if(c)for(var e in c)a[e]=c[e];this.outputs||(this.outputs=[]);this.outputs.push(a);if(this.onOutputAdded)this.onOutputAdded(a);this.size=this.computeSize();this.setDirtyCanvas(!0,!0);return a};q.prototype.addOutputs=function(a){for(var b=0;b<a.length;++b){var c=a[b],e={name:c[0],type:c[1],link:null};if(a[2])for(var f in c[2])e[f]=c[2][f];this.outputs||(this.outputs=[]);this.outputs.push(e);
if(this.onOutputAdded)this.onOutputAdded(e)}this.size=this.computeSize();this.setDirtyCanvas(!0,!0)};q.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 c=this.outputs[b].links,e=0;e<c.length;++e){var f=this.graph.links[c[e]];f&&(f.origin_slot-=1)}this.size=this.computeSize();if(this.onOutputRemoved)this.onOutputRemoved(a);this.setDirtyCanvas(!0,!0)};q.prototype.addInput=function(a,
b,c){a={name:a,type:b||0,link:null};if(c)for(var e in c)a[e]=c[e];this.inputs||(this.inputs=[]);this.inputs.push(a);this.size=this.computeSize();if(this.onInputAdded)this.onInputAdded(a);this.setDirtyCanvas(!0,!0);return a};q.prototype.addInputs=function(a){for(var b=0;b<a.length;++b){var c=a[b],e={name:c[0],type:c[1],link:null};if(a[2])for(var f in c[2])e[f]=c[2][f];this.inputs||(this.inputs=[]);this.inputs.push(e);if(this.onInputAdded)this.onInputAdded(e)}this.size=this.computeSize();this.setDirtyCanvas(!0,
!0)};q.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 c=this.graph.links[this.inputs[b].link];c&&(c.target_slot-=1)}this.size=this.computeSize();if(this.onInputRemoved)this.onInputRemoved(a);this.setDirtyCanvas(!0,!0)};q.prototype.addConnection=function(a,b,c,e){a={name:a,type:b,pos:c,direction:e,links:null};this.connections.push(a);return a};q.prototype.computeSize=function(a,b){function c(a){return a?
m*a.length*0.6:0}var e=Math.max(this.inputs?this.inputs.length:1,this.outputs?this.outputs.length:1),f=b||new Float32Array([0,0]),e=Math.max(e,1),m=k.NODE_TEXT_SIZE;f[1]=(this.constructor.slot_start_y||0)+e*(m+1)+4;this.widgets&&this.widgets.length&&(f[1]+=this.widgets.length*(k.NODE_WIDGET_HEIGHT+4)+8);var e=c(this.title),n=0,p=0;if(this.inputs)for(var g=0,d=this.inputs.length;g<d;++g){var h=this.inputs[g],h=h.label||h.name||"",h=c(h);n<h&&(n=h)}if(this.outputs)for(g=0,d=this.outputs.length;g<d;++g)h=
this.outputs[g],h=h.label||h.name||"",h=c(h),p<h&&(p=h);f[0]=Math.max(n+p+10,e);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};q.prototype.addWidget=function(a,b,c,e,f){this.widgets||(this.widgets=[]);b={type:a.toLowerCase(),name:b,value:c,callback:e,options:f||{}};void 0!==b.options.y&&(b.y=b.options.y);e||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};q.prototype.addCustomWidget=function(a){this.widgets||(this.widgets=[]);this.widgets.push(a);return a};q.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;if(this.onBounding)this.onBounding(a);return a};q.prototype.isPointInside=function(a,b,c,e){c=c||0;var f=this.graph&&this.graph.isLive()?0:20;e&&(f=0);if(this.flags&&this.flags.collapsed){if(u(a,
b,this.pos[0]-c,this.pos[1]-k.NODE_TITLE_HEIGHT-c,(this._collapsed_width||k.NODE_COLLAPSED_WIDTH)+2*c,k.NODE_TITLE_HEIGHT+2*c))return!0}else if(this.pos[0]-4-c<a&&this.pos[0]+this.size[0]+4+c>a&&this.pos[1]-f-c<b&&this.pos[1]+this.size[1]+c>b)return!0;return!1};q.prototype.getSlotInPosition=function(a,b){var c=new Float32Array(2);if(this.inputs)for(var e=0,f=this.inputs.length;e<f;++e){var m=this.inputs[e];this.getConnectionPos(!0,e,c);if(u(a,b,c[0]-10,c[1]-5,20,10))return{input:m,slot:e,link_pos:c,
locked:m.locked}}if(this.outputs)for(e=0,f=this.outputs.length;e<f;++e)if(m=this.outputs[e],this.getConnectionPos(!1,e,c),u(a,b,c[0]-10,c[1]-5,20,10))return{output:m,slot:e,link_pos:c,locked:m.locked};return null};q.prototype.findInputSlot=function(a){if(!this.inputs)return-1;for(var b=0,c=this.inputs.length;b<c;++b)if(a==this.inputs[b].name)return b;return-1};q.prototype.findOutputSlot=function(a){if(!this.outputs)return-1;for(var b=0,c=this.outputs.length;b<c;++b)if(a==this.outputs[b].name)return b;
return-1};q.prototype.connect=function(a,b,c){c=c||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."),null;if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return k.debug&&console.log("Connect: Error, no slot of name "+a),null}else if(!this.outputs||a>=this.outputs.length)return k.debug&&console.log("Connect: Error, slot number not found"),null;b&&b.constructor===Number&&(b=this.graph.getNodeById(b));
if(!b)throw"target node is null";if(b==this)return null;if(c.constructor===String){if(c=b.findInputSlot(c),-1==c)return k.debug&&console.log("Connect: Error, no slot of name "+c),null}else{if(c===k.EVENT)return null;if(!b.inputs||c>=b.inputs.length)return k.debug&&console.log("Connect: Error, slot number not found"),null}null!=b.inputs[c].link&&b.disconnectInput(c);var e=this.outputs[a];if(b.onConnectInput&&!1===b.onConnectInput(c,e.type,e))return null;var f=b.inputs[c],m=null;if(k.isValidConnection(e.type,
f.type)){m=new l(this.graph.last_link_id++,f.type,this.id,a,b.id,c);this.graph.links[m.id]=m;null==e.links&&(e.links=[]);e.links.push(m.id);b.inputs[c].link=m.id;this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(k.OUTPUT,a,!0,m,e);if(b.onConnectionsChange)b.onConnectionsChange(k.INPUT,c,!0,m,f);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(k.INPUT,b,c,this,a),this.graph.onNodeConnectionChange(k.OUTPUT,this,a,b,c))}this.setDirtyCanvas(!1,
!0);this.graph.connectionChange(this,m);return m};q.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 c=this.outputs[a];if(!c||!c.links||0==c.links.length)return!1;if(b){b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"Target Node not found";
for(var e=0,f=c.links.length;e<f;e++){var m=c.links[e],n=this.graph.links[m];if(n.target_id==b.id){c.links.splice(e,1);var p=b.inputs[n.target_slot];p.link=null;delete this.graph.links[m];this.graph&&this.graph._version++;if(b.onConnectionsChange)b.onConnectionsChange(k.INPUT,n.target_slot,!1,n,p);if(this.onConnectionsChange)this.onConnectionsChange(k.OUTPUT,a,!1,n,c);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,n.target_slot));break}}}else{e=0;for(f=c.links.length;e<f;e++)if(m=c.links[e],n=this.graph.links[m]){b=this.graph.getNodeById(n.target_id);this.graph&&this.graph._version++;if(b){p=b.inputs[n.target_slot];p.link=null;if(b.onConnectionsChange)b.onConnectionsChange(k.INPUT,n.target_slot,!1,n,p);if(this.graph&&this.graph.onNodeConnectionChange)this.graph.onNodeConnectionChange(k.INPUT,b,n.target_slot)}delete this.graph.links[m];
if(this.onConnectionsChange)this.onConnectionsChange(k.OUTPUT,a,!1,n,c);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(k.OUTPUT,this,a),this.graph.onNodeConnectionChange(k.INPUT,b,n.target_slot))}c.links=null}this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this);return!0};q.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 c=this.inputs[a].link;this.inputs[a].link=null;var e=this.graph.links[c];if(e){var f=this.graph.getNodeById(e.origin_id);if(!f)return!1;var m=f.outputs[e.origin_slot];if(!m||!m.links||0==m.links.length)return!1;for(var n=0,p=m.links.length;n<p;n++)if(m.links[n]==c){m.links.splice(n,1);break}delete this.graph.links[c];this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(k.INPUT,
a,!1,e,b);if(f.onConnectionsChange)f.onConnectionsChange(k.OUTPUT,n,!1,e,m);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(k.OUTPUT,f,n),this.graph.onNodeConnectionChange(k.INPUT,this,a))}this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this);return!0};q.prototype.getConnectionPos=function(a,b,c){c=c||new Float32Array(2);var e=0;a&&this.inputs&&(e=this.inputs.length);!a&&this.outputs&&(e=this.outputs.length);if(this.flags.collapsed)return b=this._collapsed_width||
k.NODE_COLLAPSED_WIDTH,this.flags.horizontal?(c[0]=this.pos[0]+0.5*b,c[1]=a?this.pos[1]-k.NODE_TITLE_HEIGHT:this.pos[1]):(c[0]=a?this.pos[0]:this.pos[0]+b,c[1]=this.pos[1]-0.5*k.NODE_TITLE_HEIGHT),c;if(a&&-1==b)return c[0]=this.pos[0]+10,c[1]=this.pos[1]+10,c;if(a&&e>b&&this.inputs[b].pos)return c[0]=this.pos[0]+this.inputs[b].pos[0],c[1]=this.pos[1]+this.inputs[b].pos[1],c;if(!a&&e>b&&this.outputs[b].pos)return c[0]=this.pos[0]+this.outputs[b].pos[0],c[1]=this.pos[1]+this.outputs[b].pos[1],c;if(this.flags.horizontal)return c[0]=
this.pos[0]+this.size[0]/e*(b+0.5),c[1]=a?this.pos[1]-k.NODE_TITLE_HEIGHT:this.pos[1]+this.size[1],c;c[0]=a?this.pos[0]:this.pos[0]+this.size[0]+1;c[1]=this.pos[1]+10+b*k.NODE_SLOT_HEIGHT+(this.constructor.slot_start_y||0);return c};q.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)};q.prototype.trace=function(a){this.console||(this.console=[]);this.console.push(a);this.console.length>
q.MAX_CONSOLE&&this.console.shift();this.graph.onNodeTrace(this,a)};q.prototype.setDirtyCanvas=function(a,b){this.graph&&this.graph.sendActionToCanvas("setDirty",[a,b])};q.prototype.loadImage=function(a){var b=new Image;b.src=k.node_images_path+a;b.ready=!1;var c=this;b.onload=function(){this.ready=!0;c.setDirtyCanvas(!0)};return b};q.prototype.captureInput=function(a){if(this.graph&&this.graph.list_of_graphcanvas)for(var b=this.graph.list_of_graphcanvas,c=0;c<b.length;++c){var e=b[c];if(a||e.node_capturing_input==
this)e.node_capturing_input=a?this:null}};q.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)};q.prototype.pin=function(a){this.graph._version++;this.flags.pinned=void 0===a?!this.flags.pinned:a};q.prototype.localToScreen=function(a,b,c){return[(a+this.pos[0])*c.scale+c.offset[0],(b+this.pos[1])*c.scale+c.offset[1]]};w.LGraphGroup=k.LGraphGroup=r;r.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})};r.prototype.configure=function(a){this.title=a.title;this._bounding.set(a.bounding);this.color=a.color;this.font=a.font};r.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}};r.prototype.move=function(a,b,c){this._pos[0]+=a;this._pos[1]+=b;if(!c)for(c=0;c<this._nodes.length;++c){var e=
this._nodes[c];e.pos[0]+=a;e.pos[1]+=b}};r.prototype.recomputeInsideNodes=function(){this._nodes.length=0;for(var a=this.graph._nodes,b=new Float32Array(4),c=0;c<a.length;++c){var e=a[c];e.getBounding(b);y(this._bounding,b)&&this._nodes.push(e)}};r.prototype.isPointInside=q.prototype.isPointInside;r.prototype.setDirtyCanvas=q.prototype.setDirtyCanvas;w.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._subgraph_node,
b=this._graph_stack.pop();this.selected_nodes={};this.highlighted_links={};b.attachCanvas(this);this.setDirty(!0,!0);a&&(this.centerOnNode(a),this.selectNodes([a]))}};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;a.tabindex="1";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 c=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes,5),e=!1,f=300>k.getTime()-this.last_mouseclick;this.canvas_mouse[0]=a.canvasX;this.canvas_mouse[1]=a.canvasY;this.canvas.focus();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,e=!0);var m=!1;if(c&&this.allow_interaction&&!e){this.live_mode||c.flags.pinned||this.bringToFront(c);if(!this.connecting_node&&!c.flags.collapsed&&!this.live_mode)if(!e&&!1!==c.resizable&&u(a.canvasX,a.canvasY,c.pos[0]+c.size[0]-5,c.pos[1]+c.size[1]-5,10,10))this.resizing_node=c,this.canvas.style.cursor="se-resize",e=!0;else{if(c.outputs)for(var n=0,p=c.outputs.length;n<p;++n){var h=c.outputs[n],
d=c.getConnectionPos(!1,n);if(u(a.canvasX,a.canvasY,d[0]-15,d[1]-10,30,20)){this.connecting_node=c;this.connecting_output=h;this.connecting_pos=c.getConnectionPos(!1,n);this.connecting_slot=n;a.shiftKey&&c.disconnectOutput(n);if(f){if(c.onOutputDblClick)c.onOutputDblClick(n,a)}else if(c.onOutputClick)c.onOutputClick(n,a);e=!0;break}}if(c.inputs)for(n=0,p=c.inputs.length;n<p;++n)if(h=c.inputs[n],d=c.getConnectionPos(!0,n),u(a.canvasX,a.canvasY,d[0]-15,d[1]-10,30,20)){if(f){if(c.onInputDblClick)c.onInputDblClick(n,
a)}else if(c.onInputClick)c.onInputClick(n,a);if(null!==h.link){e=this.graph.links[h.link];c.disconnectInput(n);if(this.allow_reconnect_links||a.shiftKey)this.connecting_node=this.graph._nodes_by_id[e.origin_id],this.connecting_slot=e.origin_slot,this.connecting_output=this.connecting_node.outputs[this.connecting_slot],this.connecting_pos=this.connecting_node.getConnectionPos(!1,this.connecting_slot);e=this.dirty_bgcanvas=!0}}}!e&&u(a.canvasX,a.canvasY,c.pos[0],c.pos[1]-k.NODE_TITLE_HEIGHT,k.NODE_TITLE_HEIGHT,
k.NODE_TITLE_HEIGHT)&&(c.collapse(),e=!0);if(!e){n=!1;if(p=this.processNodeWidgets(c,this.canvas_mouse,a))n=!0,this.node_widget=[c,p];if(f&&this.selected_nodes[c.id]){if(c.onDblClick)c.onDblClick(a,[a.canvasX-c.pos[0],a.canvasY-c.pos[1]],this);this.processNodeDblClicked(c);n=!0}c.onMouseDown&&c.onMouseDown(a,[a.canvasX-c.pos[0],a.canvasY-c.pos[1]],this)?n=!0:this.live_mode&&(n=m=!0);n||(this.allow_dragnodes&&(this.node_dragged=c),this.selected_nodes[c.id]||this.processNodeSelected(c,a));this.dirty_canvas=
!0}}else{for(n=0;n<this.visible_links.length;++n)if(c=this.visible_links[n],m=c._pos,!(a.canvasX<m[0]-4||a.canvasX<m[0]+4||a.canvasY<m[1]-4||a.canvasY<m[1]-4)){console.log(c);break}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>t([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);m=!0}!e&&m&&this.allow_dragcanvas&&(this.dragging_canvas=!0)}else 2!=a.which&&3==a.which&&this.processContextMenu(c,a);this.last_mouse[0]=a.localX;this.last_mouse[1]=a.localY;this.last_mouseclick=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],c=[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(c[0]/this.scale,c[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]+=
c[0]/this.scale,this.offset[1]+=c[1]/this.scale,this.dirty_bgcanvas=this.dirty_canvas=!0;else if(this.allow_interaction){this.connecting_node&&(this.dirty_canvas=!0);for(var e=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&&e!=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(e){if(!e.mouseOver&&
(e.mouseOver=!0,this.node_over=e,this.dirty_canvas=!0,e.onMouseEnter))e.onMouseEnter(a);if(e.onMouseMove)e.onMouseMove(a,[a.canvasX-e.pos[0],a.canvasY-e.pos[1]],this);if(this.connecting_node&&(f=this._highlight_input||[0,0],!this.isOverNodeBox(e,a.canvasX,a.canvasY))){var m=this.isOverNodeInput(e,a.canvasX,a.canvasY,f);-1!=m&&e.inputs[m]?k.isValidConnection(this.connecting_output.type,e.inputs[m].type)&&(this._highlight_input=f):this._highlight_input=null}this.canvas&&(u(a.canvasX,a.canvasY,e.pos[0]+
e.size[0]-5,e.pos[1]+e.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!=e&&this.node_capturing_input.onMouseMove)this.node_capturing_input.onMouseMove(a);if(this.node_dragged&&!this.live_mode){for(b in this.selected_nodes)e=this.selected_nodes[b],e.pos[0]+=c[0]/this.scale,e.pos[1]+=c[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],c=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]<c&&(this.resizing_node.size[1]=c),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]),c=this.selected_group.pos[1]-Math.round(this.selected_group.pos[1]);this.selected_group.move(b,c,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;c=new Float32Array(4);this.deselectAllNodes();var e=Math.abs(this.dragging_rectangle[2]),f=Math.abs(this.dragging_rectangle[3]),m=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]-e:this.dragging_rectangle[0];this.dragging_rectangle[1]=m;this.dragging_rectangle[2]=e;this.dragging_rectangle[3]=f;f=[];for(m=0;m<b.length;++m)e=
b[m],e.getBounding(c),y(this.dragging_rectangle,c)&&f.push(e);f.length&&this.selectNodes(f)}this.dragging_rectangle=null}else if(this.connecting_node){this.dirty_bgcanvas=this.dirty_canvas=!0;if(e=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes))this.connecting_output.type==k.EVENT&&this.isOverNodeBox(e,a.canvasX,a.canvasY)?this.connecting_node.connect(this.connecting_slot,e,k.EVENT):(b=this.isOverNodeInput(e,a.canvasX,a.canvasY),-1!=b?this.connecting_node.connect(this.connecting_slot,
e,b):(b=e.getInputInfo(0),this.connecting_output.type==k.EVENT?this.connecting_node.connect(this.connecting_slot,e,k.EVENT):b&&!b.link&&k.isValidConnection(b.type&&this.connecting_output.type)&&this.connecting_node.connect(this.connecting_slot,e,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{e=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes);!e&&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 c=this.scale;0<b?c*=1.1:0>b&&(c*=1/1.1);this.setZoom(c,[a.localX,a.localY]);this.graph.change();a.preventDefault();return!1}};g.prototype.isOverNodeBox=function(a,b,c){var e=k.NODE_TITLE_HEIGHT;return u(b,c,a.pos[0]+2,a.pos[1]+2-e,e-4,e-4)?!0:!1};g.prototype.isOverNodeInput=function(a,b,c,e){if(a.inputs)for(var f=0,m=a.inputs.length;f<m;++f){var n=a.getConnectionPos(!0,f);if(u(b,c,n[0]-10,n[1]-5,20,10))return e&&(e[0]=n[0],e[1]=n[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 c in this.selected_nodes)if(this.selected_nodes[c].onKeyDown)this.selected_nodes[c].onKeyDown(a)}else if("keyup"==
a.type&&(32==a.keyCode&&(this.dragging_canvas=!1),this.selected_nodes))for(c in this.selected_nodes)if(this.selected_nodes[c].onKeyUp)this.selected_nodes[c].onKeyUp(a);this.graph.change();if(b)return a.preventDefault(),!1}}};g.prototype.copyToClipboard=function(){var a={nodes:[],links:[]},b=0,c=[],e;for(e in this.selected_nodes){var f=this.selected_nodes[e];f._relative_id=b;c.push(f);b+=1}for(e=0;e<c.length;++e)if(f=c[e],a.nodes.push(f.clone().serialize()),f.inputs&&f.inputs.length)for(b=0;b<f.inputs.length;++b){var m=
f.inputs[b];if(m&&null!=m.link&&(m=this.graph.links[m.link])){var n=this.graph.getNodeById(m.origin_id);n&&this.selected_nodes[n.id]&&a.links.push([n._relative_id,b,f._relative_id,m.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=[],c=0;c<a.nodes.length;++c){var e=a.nodes[c],f=k.createNode(e.type);f&&(f.configure(e),f.pos[0]+=5,f.pos[1]+=
5,this.graph.add(f),b.push(f))}for(c=0;c<a.links.length;++c)e=a.links[c],b[e[0]].connect(e[1],b[e[2]],e[3]);this.selectNodes(b)}};g.prototype.processDrop=function(a){a.preventDefault();this.adjustMouseEvent(a);var b=[a.canvasX,a.canvasY],c=this.graph.getNodeOnPos(b[0],b[1]);if(c){if((c.onDropFile||c.onDropData)&&(b=a.dataTransfer.files)&&b.length)for(var e=0;e<b.length;e++){var f=a.dataTransfer.files[0],m=f.name;g.getFileExtension(m);if(c.onDropFile)c.onDropFile(f);if(c.onDropData){var n=new FileReader;

View File

@@ -2688,7 +2688,7 @@ LGraphNode.prototype.computeSize = function( minHeight, out )
* Allows to pass
*
* @method addWidget
* @return {Float32Array[4]} the total size
* @return {Object} the created widget
*/
LGraphNode.prototype.addWidget = function( type, name, value, callback, options )
{
@@ -4123,7 +4123,7 @@ LGraphCanvas.prototype.processMouseDown = function(e)
{
//double click node
if( node.onDblClick)
node.onDblClick(e,[e.canvasX - node.pos[0], e.canvasY - node.pos[1]],graphcanvas);
node.onDblClick(e,[e.canvasX - node.pos[0], e.canvasY - node.pos[1]], this);
this.processNodeDblClicked( node );
block_drag_node = true;
}
@@ -8060,11 +8060,14 @@ function ContextMenu( values, options )
function on_mouse_wheel(e)
{
var pos = parseInt( root.style.top );
root.style.top = (pos + e.deltaY * 0.1).toFixed() + "px";
root.style.top = (pos + e.deltaY * options.scroll_speed).toFixed() + "px";
e.preventDefault();
return true;
}
if(!options.scroll_speed)
options.scroll_speed = 0.1;
root.addEventListener("wheel", on_mouse_wheel, true);
root.addEventListener("mousewheel", on_mouse_wheel, true);