This commit is contained in:
tamat
2020-12-28 10:36:06 +01:00
4 changed files with 215 additions and 184 deletions

View File

@@ -26,6 +26,7 @@
NODE_COLLAPSED_RADIUS: 10,
NODE_COLLAPSED_WIDTH: 80,
NODE_TITLE_COLOR: "#999",
NODE_SELECTED_TITLE_COLOR: "#FFF",
NODE_TEXT_SIZE: 14,
NODE_TEXT_COLOR: "#AAA",
NODE_SUBTEXT_SIZE: 12,
@@ -33,13 +34,14 @@
NODE_DEFAULT_BGCOLOR: "#353535",
NODE_DEFAULT_BOXCOLOR: "#666",
NODE_DEFAULT_SHAPE: "box",
NODE_BOX_OUTLINE_COLOR: "#FFF",
DEFAULT_SHADOW_COLOR: "rgba(0,0,0,0.5)",
DEFAULT_GROUP_FONT: 24,
WIDGET_BGCOLOR: "#222",
WIDGET_OUTLINE_COLOR: "#666",
WIDGET_TEXT_COLOR: "#DDD",
WIDGET_SECONDARY_TEXT_COLOR: "#999",
WIDGET_BGCOLOR: "#222",
WIDGET_OUTLINE_COLOR: "#666",
WIDGET_TEXT_COLOR: "#DDD",
WIDGET_SECONDARY_TEXT_COLOR: "#999",
LINK_COLOR: "#9A9",
EVENT_LINK_COLOR: "#A86",
@@ -96,6 +98,7 @@
Globals: {}, //used to store vars between graphs
searchbox_extras: {}, //used to add extra features to the search box
auto_sort_node_types: false, // If set to true, will automatically sort node types / categories in the context menus
/**
* Register a node class so it can be listed when the user wants to create a new one
@@ -416,7 +419,7 @@
}
}
return r;
return this.auto_sort_node_types ? r.sort() : r;
},
/**
@@ -440,7 +443,7 @@
for (var i in categories) {
result.push(i);
}
return result;
return this.auto_sort_node_types ? result.sort() : result;
},
//debug purposes: reloads all the js scripts that matches a wildcard
@@ -7966,7 +7969,7 @@ LGraphNode.prototype.executeAction = function(action)
var title = String(node.getTitle());
if (title) {
if (selected) {
ctx.fillStyle = "white";
ctx.fillStyle = LiteGraph.NODE_SELECTED_TITLE_COLOR;
} else {
ctx.fillStyle =
node.constructor.title_text_color ||
@@ -8069,7 +8072,7 @@ LGraphNode.prototype.executeAction = function(action)
Math.PI * 2
);
}
ctx.strokeStyle = "#FFF";
ctx.strokeStyle = LiteGraph.NODE_BOX_OUTLINE_COLOR;
ctx.stroke();
ctx.strokeStyle = fgcolor;
ctx.globalAlpha = 1;
@@ -9452,7 +9455,7 @@ LGraphNode.prototype.executeAction = function(action)
entries.push({
content:
"<span class='property_name'>" +
i +
(info.label ? info.label : i) +
"</span>" +
"<span class='property_value'>" +
value +
@@ -10050,7 +10053,7 @@ LGraphNode.prototype.executeAction = function(action)
var dialog = this.createDialog(
"<span class='name'>" +
property +
(info.label ? info.label : property) +
"</span>" +
input_html +
"<button>OK</button>",
@@ -10077,8 +10080,12 @@ LGraphNode.prototype.executeAction = function(action)
input.addEventListener("blur", function(e) {
this.focus();
});
var v = node.properties[property] !== undefined ? node.properties[property] : "";
v = JSON.stringify(v);
if (type !== 'string') {
v = JSON.stringify(v);
}
input.value = v;
input.addEventListener("keydown", function(e) {
if (e.keyCode != 13) {

324
build/litegraph.min.js vendored
View File

@@ -8,100 +8,100 @@ b.parentMenu,this.parentMenu.lock=!0,this.parentMenu.current_submenu=this));var
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 g.close(),a.preventDefault(),!0},!0);b.scroll_speed||(b.scroll_speed=0.1);f.addEventListener("wheel",d,!0);f.addEventListener("mousewheel",d,!0);this.root=f;b.title&&(e=document.createElement("div"),e.className=
"litemenu-title",e.innerHTML=b.title,f.appendChild(e));for(var m=e=0;m<a.length;m++){var s=a.constructor==Array?a[m]:m;null!=s&&s.constructor!==String&&(s=void 0===s.content?String(s):s.content);this.addItem(s,a[m],b);e++}f.addEventListener("mouseleave",function(a){g.lock||(f.closing_timer&&clearTimeout(f.closing_timer),f.closing_timer=setTimeout(g.close.bind(g,a),500))});f.addEventListener("mouseenter",function(a){f.closing_timer&&clearTimeout(f.closing_timer)});e=document;b.event&&(e=b.event.target.ownerDocument);
e||(e=document);e.fullscreenElement?e.fullscreenElement.appendChild(f):e.body.appendChild(f);m=b.left||0;e=b.top||0;if(b.event){m=b.event.clientX-10;e=b.event.clientY-10;b.title&&(e-=20);b.parentMenu&&(m=b.parentMenu.root.getBoundingClientRect(),m=m.left+m.width);var s=document.body.getBoundingClientRect(),y=f.getBoundingClientRect();0==s.height&&console.error("document.body height is 0. That is dangerous, set html,body { height: 100%; }");s.width&&m>s.width-y.width-10&&(m=s.width-y.width-10);s.height&&
e>s.height-y.height-10&&(e=s.height-y.height-10)}f.style.left=m+"px";f.style.top=e+"px";b.scale&&(f.style.transform="scale("+b.scale+")")}function D(a){this.points=a;this.nearest=this.selected=-1;this.size=null;this.must_update=!0;this.margin=5}var f=B.LiteGraph={VERSION:0.4,CANVAS_GRID_SIZE:10,NODE_TITLE_HEIGHT:30,NODE_TITLE_TEXT_Y:20,NODE_SLOT_HEIGHT:20,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:"#353535",NODE_DEFAULT_BOXCOLOR:"#666",NODE_DEFAULT_SHAPE:"box",DEFAULT_SHADOW_COLOR:"rgba(0,0,0,0.5)",DEFAULT_GROUP_FONT:24,WIDGET_BGCOLOR:"#222",WIDGET_OUTLINE_COLOR:"#666",WIDGET_TEXT_COLOR:"#DDD",WIDGET_SECONDARY_TEXT_COLOR:"#999",LINK_COLOR:"#9A9",EVENT_LINK_COLOR:"#A86",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,STRAIGHT_LINK:0,LINEAR_LINK:1,SPLINE_LINK:2,NORMAL_TITLE:0,NO_TITLE:1,TRANSPARENT_TITLE:2,AUTOHIDE_TITLE:3,proxy:null,node_images_path:"",debug:!1,catch_exceptions:!0,throw_errors:!0,allow_scripts:!1,registered_node_types:{},node_types_by_file_extension:{},Nodes:{},Globals:{},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;f.debug&&console.log("Node registered: "+a);a.split("/");var d=b.name,g=a.lastIndexOf("/");b.category=a.substr(0,g);b.title||(b.title=d);if(b.prototype)for(var e in u.prototype)b.prototype[e]||(b.prototype[e]=u.prototype[e]);if(g=this.registered_node_types[a])console.log("replacing node type: "+a);else if(Object.hasOwnProperty(b.prototype,"shape")||Object.defineProperty(b.prototype,"shape",{set:function(a){switch(a){case "default":delete this._shape;break;case "box":this._shape=f.BOX_SHAPE;
break;case "round":this._shape=f.ROUND_SHAPE;break;case "circle":this._shape=f.CIRCLE_SHAPE;break;case "card":this._shape=f.CARD_SHAPE;break;default:this._shape=a}},get:function(a){return this._shape},enumerable:!0,configurable:!0}),b.prototype.onPropertyChange&&console.warn("LiteGraph node class "+a+" has onPropertyChange method, it must be called onPropertyChanged with d at the end"),b.supported_extensions)for(e in b.supported_extensions){var E=b.supported_extensions[e];E&&E.constructor===String&&
(this.node_types_by_file_extension[E.toLowerCase()]=b)}this.registered_node_types[a]=b;b.constructor.name&&(this.Nodes[d]=b);if(f.onNodeTypeRegistered)f.onNodeTypeRegistered(a,b);if(g&&f.onNodeTypeReplaced)f.onNodeTypeReplaced(a,b,g);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(e=0;e<b.supported_extensions.length;e++)(E=b.supported_extensions[e])&&E.constructor===
String&&(this.node_types_by_file_extension[E.toLowerCase()]=b)},unregisterNodeType:function(a){var b=a.constructor===String?this.registered_node_types[a]:a;if(!b)throw"node type not found: "+a;delete this.registered_node_types[b.type];b.constructor.name&&delete this.Nodes[b.constructor.name]},wrapFunctionAsNode:function(a,b,d,g,e){for(var E=Array(b.length),m="",s=f.getParameterNames(b),y=0;y<s.length;++y)m+="this.addInput('"+s[y]+"',"+(d&&d[y]?"'"+d[y]+"'":"0")+");\n";m+="this.addOutput('out',"+(g?
"'"+g+"'":0)+");\n";e&&(m+="this.properties = "+JSON.stringify(e)+";\n");d=Function(m);d.title=a.split("/").pop();d.desc="Generated from "+b.name;d.prototype.onExecute=function(){for(var a=0;a<E.length;++a)E[a]=this.getInputData(a);a=b.apply(this,E);this.setOutputData(0,a)};this.registerNodeType(a,d)},clearRegisteredTypes:function(){this.registered_node_types={};this.node_types_by_file_extension={};this.Nodes={};this.searchbox_extras={}},addNodeMethod:function(a,b){u.prototype[a]=b;for(var d in this.registered_node_types){var g=
this.registered_node_types[d];g.prototype[a]&&(g.prototype["_"+a]=g.prototype[a]);g.prototype[a]=b}},createNode:function(a,b,d){var g=this.registered_node_types[a];if(!g)return f.debug&&console.log('GraphNode type "'+a+'" not registered.'),null;b=b||g.title||a;var e=null;if(f.catch_exceptions)try{e=new g(b)}catch(E){return console.error(E),null}else e=new g(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=f.DEFAULT_POSITION.concat());e.mode||(e.mode=f.ALWAYS);if(d)for(var m in d)e[m]=d[m];return e},getNodeType:function(a){return this.registered_node_types[a]},getNodeTypesInCategory:function(a,b){var d=[],g;for(g in this.registered_node_types){var e=this.registered_node_types[g];e.filter==b&&(""==a?null==e.category&&d.push(e):e.category==a&&d.push(e))}return d},getNodeTypesCategories:function(a){var b={"":1},d;for(d in this.registered_node_types){var g=this.registered_node_types[d];
g.category&&!g.skip_list&&g.filter==a&&(b[g.category]=1)}a=[];for(d in b)a.push(d);return a},reloadNodes:function(a){for(var b=document.getElementsByTagName("script"),d=[],g=0;g<b.length;g++)d.push(b[g]);b=document.getElementsByTagName("head")[0];a=document.location.href+a;for(g=0;g<d.length;g++){var e=d[g].src;if(e&&e.substr(0,a.length)==a)try{f.debug&&console.log("Reloading: "+e);var E=document.createElement("script");E.type="text/javascript";E.src=e;b.appendChild(E);b.removeChild(d[g])}catch(m){if(f.throw_errors)throw m;
f.debug&&console.log("Error while reloading "+e)}}f.debug&&console.log("Nodes reloaded")},cloneObject:function(a,b){if(null==a)return null;var d=JSON.parse(JSON.stringify(a));if(!b)return d;for(var g in d)b[g]=d[g];return b},isValidConnection:function(a,b){if(!a||!b||a==b||a==f.EVENT&&b==f.ACTION)return!0;a=String(a);b=String(b);a=a.toLowerCase();b=b.toLowerCase();if(-1==a.indexOf(",")&&-1==b.indexOf(","))return a==b;for(var d=a.split(","),g=b.split(","),e=0;e<d.length;++e)for(var E=0;E<g.length;++E)if(d[e]==
g[E])return!0;return!1},registerSearchboxExtra:function(a,b,d){this.searchbox_extras[b.toLowerCase()]={type:a,desc:b,data:d}},fetchFile:function(a,b,d,g){if(!a)return null;b=b||"text";if(a.constructor===String)return"http"==a.substr(0,4)&&f.proxy&&(a=f.proxy+a.substr(a.indexOf(":")+3)),fetch(a).then(function(a){if(!a.ok)throw Error("File not found");if("arraybuffer"==b)return a.arrayBuffer();if("text"==b||"string"==b)return a.text();if("json"==b)return a.json();if("blob"==b)return a.blob()}).then(function(a){d&&
d(a)})["catch"](function(b){console.error("error fetching file:",a);g&&g(b)});if(a.constructor===File||a.constructor===Blob){var e=new FileReader;e.onload=function(a){a=a.target.result;"json"==b&&(a=JSON.parse(a));d&&d(a)};if("arraybuffer"==b)return e.readAsArrayBuffer(a);if("text"==b||"json"==b)return e.readAsText(a);if("blob"==b)return e.readAsBinaryString(a)}return null}};f.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()};B.LGraph=f.LGraph=c;c.supported_types=["number","string","boolean"];c.prototype.getSupportedTypes=function(){return this.supported_types||c.supported_types};c.STATUS_STOPPED=1;c.STATUS_RUNNING=2;c.prototype.clear=function(){this.stop();this.status=c.STATUS_STOPPED;this.last_link_id=this.last_node_id=0;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.vars={};this.extra={};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.inputs={};this.outputs={};this.change();this.sendActionToCanvas("clear")};c.prototype.attachCanvas=function(a){if(a.constructor!=
h)throw"attachCanvas expects a LGraphCanvas instance";a.graph&&a.graph!=this&&a.graph.detachCanvas(a);a.graph=this;this.list_of_graphcanvas||(this.list_of_graphcanvas=[]);this.list_of_graphcanvas.push(a)};c.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))}};c.prototype.start=function(a){if(this.status!=c.STATUS_RUNNING){this.status=c.STATUS_RUNNING;if(this.onPlayEvent)this.onPlayEvent();
this.sendEventToAllNodes("onStart");this.last_update_time=this.starttime=f.getTime();a=a||0;var b=this;if(0==a&&"undefined"!=typeof window&&window.requestAnimationFrame){var d=function(){if(-1==b.execution_timer_id){window.requestAnimationFrame(d);if(b.onBeforeStep)b.onBeforeStep();b.runStep(1,!b.catch_errors);if(b.onAfterStep)b.onAfterStep()}};this.execution_timer_id=-1;d()}else this.execution_timer_id=setInterval(function(){if(b.onBeforeStep)b.onBeforeStep();b.runStep(1,!b.catch_errors);if(b.onAfterStep)b.onAfterStep()},
a)}};c.prototype.stop=function(){if(this.status!=c.STATUS_STOPPED){this.status=c.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")}};c.prototype.runStep=function(a,b,d){a=a||1;var g=f.getTime();this.globaltime=0.001*(g-this.starttime);var e=this._nodes_executable?this._nodes_executable:this._nodes;if(e){d=d||e.length;if(b){for(var E=
0;E<a;E++){for(var m=0;m<d;++m){var s=e[m];if(s.mode==f.ALWAYS&&s.onExecute)s.onExecute()}this.fixedtime+=this.fixedtime_lapse;if(this.onExecuteStep)this.onExecuteStep()}if(this.onAfterExecute)this.onAfterExecute()}else try{for(E=0;E<a;E++){for(m=0;m<d;++m)if(s=e[m],s.mode==f.ALWAYS&&s.onExecute)s.onExecute();this.fixedtime+=this.fixedtime_lapse;if(this.onExecuteStep)this.onExecuteStep()}if(this.onAfterExecute)this.onAfterExecute();this.errors_in_execution=!1}catch(y){this.errors_in_execution=!0;
if(f.throw_errors)throw y;f.debug&&console.log("Error during execution: "+y);this.stop()}a=f.getTime();g=a-g;0==g&&(g=1);this.execution_time=0.001*g;this.globaltime+=0.001*g;this.iteration+=1;this.elapsed_time=0.001*(a-this.last_update_time);this.last_update_time=a}};c.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])};
c.prototype.computeExecutionOrder=function(a,b){for(var d=[],g=[],e={},E={},m={},s=0,y=this._nodes.length;s<y;++s){var c=this._nodes[s];if(!a||c.onExecute){e[c.id]=c;var k=0;if(c.inputs)for(var z=0,F=c.inputs.length;z<F;z++)c.inputs[z]&&null!=c.inputs[z].link&&(k+=1);0==k?(g.push(c),b&&(c._level=1)):(b&&(c._level=0),m[c.id]=k)}}for(;0!=g.length;)if(c=g.shift(),d.push(c),delete e[c.id],c.outputs)for(s=0;s<c.outputs.length;s++)if(y=c.outputs[s],null!=y&&null!=y.links&&0!=y.links.length)for(z=0;z<y.links.length;z++)(k=
this.links[y.links[z]])&&!E[k.id]&&(F=this.getNodeById(k.target_id),null==F?E[k.id]=!0:(b&&(!F._level||F._level<=c._level)&&(F._level=c._level+1),E[k.id]=!0,m[F.id]-=1,0==m[F.id]&&g.push(F)));for(s in e)d.push(e[s]);d.length!=this._nodes.length&&f.debug&&console.warn("something went wrong, nodes missing");y=d.length;for(s=0;s<y;++s)d[s].order=s;d=d.sort(function(a,b){var d=a.constructor.priority||a.priority||0,e=b.constructor.priority||b.priority||0;return d==e?a.order-b.order:d-e});for(s=0;s<y;++s)d[s].order=
s;return d};c.prototype.getAncestors=function(a){for(var b=[],d=[a],g={};d.length;){var e=d.shift();if(e.inputs){g[e.id]||e==a||(g[e.id]=!0,b.push(e));for(var f=0;f<e.inputs.length;++f){var m=e.getInputNode(f);m&&-1==b.indexOf(m)&&d.push(m)}}}b.sort(function(a,b){return a.order-b.order});return b};c.prototype.arrange=function(a){a=a||100;for(var b=this.computeExecutionOrder(!1,!0),d=[],g=0;g<b.length;++g){var e=b[g],E=e._level||1;d[E]||(d[E]=[]);d[E].push(e)}b=a;for(g=0;g<d.length;++g)if(E=d[g]){for(var m=
100,s=a+f.NODE_TITLE_HEIGHT,y=0;y<E.length;++y)e=E[y],e.pos[0]=b,e.pos[1]=s,e.size[0]>m&&(m=e.size[0]),s+=e.size[1]+a+f.NODE_TITLE_HEIGHT;b+=m+a}this.setDirtyCanvas(!0,!0)};c.prototype.getTime=function(){return this.globaltime};c.prototype.getFixedTime=function(){return this.fixedtime};c.prototype.getElapsedTime=function(){return this.elapsed_time};c.prototype.sendEventToAllNodes=function(a,b,d){d=d||f.ALWAYS;var g=this._nodes_in_order?this._nodes_in_order:this._nodes;if(g)for(var e=0,E=g.length;e<
E;++e){var m=g[e];if(m.constructor===f.Subgraph&&"onExecute"!=a)m.mode==d&&m.sendEventToAllNodes(a,b,d);else if(m[a]&&m.mode==d)if(void 0===b)m[a]();else if(b&&b.constructor===Array)m[a].apply(m,b);else m[a](b)}};c.prototype.sendActionToCanvas=function(a,b){if(this.list_of_graphcanvas)for(var d=0;d<this.list_of_graphcanvas.length;++d){var g=this.list_of_graphcanvas[d];g[a]&&g[a].apply(g,b)}};c.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>=f.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}};c.prototype.remove=function(a){if(a.constructor===f.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 d=a.inputs[b];null!=d.link&&a.disconnectInput(b)}if(a.outputs)for(b=
0;b<a.outputs.length;b++)d=a.outputs[b],null!=d.links&&d.links.length&&a.disconnectOutput(b);if(a.onRemoved)a.onRemoved();a.graph=null;this._version++;if(this.list_of_graphcanvas)for(b=0;b<this.list_of_graphcanvas.length;++b)d=this.list_of_graphcanvas[b],d.selected_nodes[a.id]&&delete d.selected_nodes[a.id],d.node_dragged==a&&(d.node_dragged=null);b=this._nodes.indexOf(a);-1!=b&&this._nodes.splice(b,1);delete this._nodes_by_id[a.id];if(this.onNodeRemoved)this.onNodeRemoved(a);this.sendActionToCanvas("checkPanels");
this.setDirtyCanvas(!0,!0);this.change();this.updateExecutionOrder()}};c.prototype.getNodeById=function(a){return null==a?null:this._nodes_by_id[a]};c.prototype.findNodesByClass=function(a,b){b=b||[];for(var d=b.length=0,g=this._nodes.length;d<g;++d)this._nodes[d].constructor===a&&b.push(this._nodes[d]);return b};c.prototype.findNodesByType=function(a,b){a=a.toLowerCase();b=b||[];for(var d=b.length=0,g=this._nodes.length;d<g;++d)this._nodes[d].type.toLowerCase()==a&&b.push(this._nodes[d]);return b};
c.prototype.findNodeByTitle=function(a){for(var b=0,d=this._nodes.length;b<d;++b)if(this._nodes[b].title==a)return this._nodes[b];return null};c.prototype.findNodesByTitle=function(a){for(var b=[],d=0,g=this._nodes.length;d<g;++d)this._nodes[d].title==a&&b.push(this._nodes[d]);return b};c.prototype.getNodeOnPos=function(a,b,d,g){d=d||this._nodes;for(var e=d.length-1;0<=e;e--){var f=d[e];if(f.isPointInside(a,b,g))return f}return null};c.prototype.getGroupOnPos=function(a,b){for(var d=this._groups.length-
1;0<=d;d--){var g=this._groups[d];if(g.isPointInside(a,b,2,!0))return g}return null};c.prototype.checkNodeTypes=function(){for(var a=0;a<this._nodes.length;a++){var b=this._nodes[a];if(b.constructor!=f.registered_node_types[b.type]){console.log("node being replaced by newer version: "+b.type);var d=f.createNode(b.type);this._nodes[a]=d;d.configure(b.serialize());d.graph=this;this._nodes_by_id[d.id]=d;b.inputs&&(d.inputs=b.inputs.concat());b.outputs&&(d.outputs=b.outputs.concat())}}this.updateExecutionOrder()};
c.prototype.onAction=function(a,b){this._input_nodes=this.findNodesByClass(f.GraphInput,this._input_nodes);for(var d=0;d<this._input_nodes.length;++d){var g=this._input_nodes[d];if(g.properties.name==a){g.onAction(a,b);break}}};c.prototype.trigger=function(a,b){if(this.onTrigger)this.onTrigger(a,b)};c.prototype.addInput=function(a,b,d){if(!this.inputs[a]){this.beforeChange();this.inputs[a]={name:a,type:b,value:d};this._version++;this.afterChange();if(this.onInputAdded)this.onInputAdded(a,b);if(this.onInputsOutputsChange)this.onInputsOutputsChange()}};
c.prototype.setInputData=function(a,b){var d=this.inputs[a];d&&(d.value=b)};c.prototype.getInputData=function(a){return(a=this.inputs[a])?a.value:null};c.prototype.renameInput=function(a,b){if(b!=a){if(!this.inputs[a])return!1;if(this.inputs[b])return console.error("there is already one input with that name"),!1;this.inputs[b]=this.inputs[a];delete this.inputs[a];this._version++;if(this.onInputRenamed)this.onInputRenamed(a,b);if(this.onInputsOutputsChange)this.onInputsOutputsChange()}};c.prototype.changeInputType=
function(a,b){if(!this.inputs[a])return!1;if(!this.inputs[a].type||String(this.inputs[a].type).toLowerCase()!=String(b).toLowerCase())if(this.inputs[a].type=b,this._version++,this.onInputTypeChanged)this.onInputTypeChanged(a,b)};c.prototype.removeInput=function(a){if(!this.inputs[a])return!1;delete this.inputs[a];this._version++;if(this.onInputRemoved)this.onInputRemoved(a);if(this.onInputsOutputsChange)this.onInputsOutputsChange();return!0};c.prototype.addOutput=function(a,b,d){this.outputs[a]={name:a,
type:b,value:d};this._version++;if(this.onOutputAdded)this.onOutputAdded(a,b);if(this.onInputsOutputsChange)this.onInputsOutputsChange()};c.prototype.setOutputData=function(a,b){var d=this.outputs[a];d&&(d.value=b)};c.prototype.getOutputData=function(a){return(a=this.outputs[a])?a.value:null};c.prototype.renameOutput=function(a,b){if(!this.outputs[a])return!1;if(this.outputs[b])return console.error("there is already one output with that name"),!1;this.outputs[b]=this.outputs[a];delete this.outputs[a];
this._version++;if(this.onOutputRenamed)this.onOutputRenamed(a,b);if(this.onInputsOutputsChange)this.onInputsOutputsChange()};c.prototype.changeOutputType=function(a,b){if(!this.outputs[a])return!1;if(!this.outputs[a].type||String(this.outputs[a].type).toLowerCase()!=String(b).toLowerCase())if(this.outputs[a].type=b,this._version++,this.onOutputTypeChanged)this.onOutputTypeChanged(a,b)};c.prototype.removeOutput=function(a){if(!this.outputs[a])return!1;delete this.outputs[a];this._version++;if(this.onOutputRemoved)this.onOutputRemoved(a);
if(this.onInputsOutputsChange)this.onInputsOutputsChange();return!0};c.prototype.triggerInput=function(a,b){for(var d=this.findNodesByTitle(a),g=0;g<d.length;++g)d[g].onTrigger(b)};c.prototype.setCallback=function(a,b){for(var d=this.findNodesByTitle(a),g=0;g<d.length;++g)d[g].setTrigger(b)};c.prototype.beforeChange=function(a){if(this.onBeforeChange)this.onBeforeChange(this,a);this.sendActionToCanvas("onBeforeChange",this)};c.prototype.afterChange=function(a){if(this.onAfterChange)this.onAfterChange(this,
a);this.sendActionToCanvas("onAfterChange",this)};c.prototype.connectionChange=function(a,b){this.updateExecutionOrder();if(this.onConnectionChange)this.onConnectionChange(a);this._version++;this.sendActionToCanvas("onConnectionChange")};c.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};c.prototype.clearTriggeredSlots=function(){for(var a in this.links){var b=this.links[a];
b&&b._last_time&&(b._last_time=0)}};c.prototype.change=function(){f.debug&&console.log("Graph changed");this.sendActionToCanvas("setDirty",[!0,!0]);if(this.on_change)this.on_change(this)};c.prototype.setDirtyCanvas=function(a,b){this.sendActionToCanvas("setDirty",[a,b])};c.prototype.removeLink=function(a){if(a=this.links[a]){var b=this.getNodeById(a.target_id);b&&b.disconnectInput(a.target_slot)}};c.prototype.serialize=function(){for(var a=[],b=0,d=this._nodes.length;b<d;++b)a.push(this._nodes[b].serialize());
d=[];for(b in this.links){var g=this.links[b];if(!g.serialize){console.warn("weird LLink bug, link info is not a LLink but a regular object");var e=new l,E;for(E in g)e[E]=g[E];g=this.links[b]=e}d.push(g.serialize())}E=[];for(b=0;b<this._groups.length;++b)E.push(this._groups[b].serialize());a={last_node_id:this.last_node_id,last_link_id:this.last_link_id,nodes:a,links:d,groups:E,config:this.config,extra:this.extra,version:f.VERSION};if(this.onSerialize)this.onSerialize(a);return a};c.prototype.configure=
function(a,b){if(a){b||this.clear();var d=a.nodes;if(a.links&&a.links.constructor===Array){for(var g=[],e=0;e<a.links.length;++e){var E=a.links[e];if(E){var m=new l;m.configure(E);g[m.id]=m}else console.warn("serialized graph link data contains errors, skipping.")}a.links=g}for(e in a)"nodes"!=e&&"groups"!=e&&(this[e]=a[e]);g=!1;this._nodes=[];if(d){e=0;for(E=d.length;e<E;++e){var m=d[e],s=f.createNode(m.type,m.title);s||(f.debug&&console.log("Node not found or has errors: "+m.type),s=new u,s.last_serialization=
m,g=s.has_errors=!0);s.id=m.id;this.add(s,!0)}e=0;for(E=d.length;e<E;++e)m=d[e],(s=this.getNodeById(m.id))&&s.configure(m)}this._groups.length=0;if(a.groups)for(e=0;e<a.groups.length;++e)d=new f.LGraphGroup,d.configure(a.groups[e]),this.add(d);this.updateExecutionOrder();this.extra=a.extra||{};if(this.onConfigure)this.onConfigure(a);this._version++;this.setDirtyCanvas(!0,!0);return g}};c.prototype.load=function(a,b){var d=this;if(a.constructor===File||a.constructor===Blob){var g=new FileReader;g.addEventListener("load",
function(a){a=JSON.parse(a.target.result);d.configure(a);b&&b()});g.readAsText(a)}else{var e=new XMLHttpRequest;e.open("GET",a,!0);e.send(null);e.onload=function(a){200!==e.status?console.error("Error loading graph:",e.status,e.response):(a=JSON.parse(e.response),d.configure(a),b&&b())};e.onerror=function(a){console.error("Error loading graph:",a)}}};c.prototype.onNodeTrace=function(a,b,d){};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.origin_id,this.origin_slot,this.target_id,this.target_slot,this.type]};f.LLink=l;B.LGraphNode=f.LGraphNode=u;u.prototype._ctor=function(a){this.title=a||"Unnamed";this.size=[f.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={}};u.prototype.configure=function(a){this.graph&&this.graph._version++;for(var b in a)if("properties"==b)for(var d in a.properties){if(this.properties[d]=a.properties[d],this.onPropertyChanged)this.onPropertyChanged(d,
a.properties[d])}else null!=a[b]&&("object"==typeof a[b]?this[b]&&this[b].configure?this[b].configure(a[b]):this[b]=f.cloneObject(a[b],this[b]):this[b]=a[b]);a.title||(this.title=this.constructor.title);if(this.onConnectionsChange){if(this.inputs)for(d=0;d<this.inputs.length;++d){b=this.inputs[d];var g=this.graph?this.graph.links[b.link]:null;this.onConnectionsChange(f.INPUT,d,!0,g,b)}if(this.outputs)for(d=0;d<this.outputs.length;++d){var e=this.outputs[d];if(e.links)for(b=0;b<e.links.length;++b)g=
this.graph?this.graph.links[e.links[b]]:null,this.onConnectionsChange(f.OUTPUT,d,!0,g,e)}}if(this.widgets){for(d=0;d<this.widgets.length;++d)(b=this.widgets[d])&&b.options&&b.options.property&&this.properties[b.options.property]&&(b.value=JSON.parse(JSON.stringify(this.properties[b.options.property])));if(a.widgets_values)for(d=0;d<a.widgets_values.length;++d)this.widgets[d]&&(this.widgets[d].value=a.widgets_values[d])}if(this.onConfigure)this.onConfigure(a)};u.prototype.serialize=function(){var a=
{id:this.id,type:this.type,pos:this.pos,size:this.size,flags:f.cloneObject(this.flags),order:this.order,mode:this.mode};if(this.constructor===u&&this.last_serialization)return this.last_serialization;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=f.cloneObject(this.properties));if(this.widgets&&this.serialize_widgets)for(a.widgets_values=
[],b=0;b<this.widgets.length;++b)a.widgets_values[b]=this.widgets[b]?this.widgets[b].value:null;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};u.prototype.clone=function(){var a=f.createNode(this.type);
if(!a)return null;var b=f.cloneObject(this.serialize());if(b.inputs)for(var d=0;d<b.inputs.length;++d)b.inputs[d].link=null;if(b.outputs)for(d=0;d<b.outputs.length;++d)b.outputs[d].links&&(b.outputs[d].links.length=0);delete b.id;a.configure(b);return a};u.prototype.toString=function(){return JSON.stringify(this.serialize())};u.prototype.getTitle=function(){return this.title||this.constructor.title};u.prototype.setProperty=function(a,b){this.properties||(this.properties={});if(b!==this.properties[a]){var d=
this.properties[a];this.properties[a]=b;this.onPropertyChanged&&!1===this.onPropertyChanged(a,b,d)&&(this.properties[a]=d);if(this.widgets)for(d=0;d<this.widgets.length;++d){var g=this.widgets[d];if(g&&g.options.property==a){g.value=b;break}}}};u.prototype.setOutputData=function(a,b){if(this.outputs&&!(-1==a||a>=this.outputs.length)){var d=this.outputs[a];if(d&&(d._data=b,this.outputs[a].links))for(d=0;d<this.outputs[a].links.length;d++){var g=this.graph.links[this.outputs[a].links[d]];g&&(g.data=
b)}}};u.prototype.setOutputDataType=function(a,b){if(this.outputs&&!(-1==a||a>=this.outputs.length)){var d=this.outputs[a];if(d&&(d.type=b,this.outputs[a].links))for(d=0;d<this.outputs[a].links.length;d++)this.graph.links[this.outputs[a].links[d]].type=b}};u.prototype.getInputData=function(a,b){if(this.inputs&&!(a>=this.inputs.length||null==this.inputs[a].link)){var d=this.graph.links[this.inputs[a].link];if(!d)return null;if(!b)return d.data;var g=this.graph.getNodeById(d.origin_id);if(!g)return d.data;
if(g.updateOutputData)g.updateOutputData(d.origin_slot);else if(g.onExecute)g.onExecute();return d.data}};u.prototype.getInputDataType=function(a){if(!this.inputs||a>=this.inputs.length||null==this.inputs[a].link)return null;a=this.graph.links[this.inputs[a].link];if(!a)return null;var b=this.graph.getNodeById(a.origin_id);return b?(a=b.outputs[a.origin_slot])?a.type:null:a.type};u.prototype.getInputDataByName=function(a,b){var d=this.findInputSlot(a);return-1==d?null:this.getInputData(d,b)};u.prototype.isInputConnected=
function(a){return this.inputs?a<this.inputs.length&&null!=this.inputs[a].link:!1};u.prototype.getInputInfo=function(a){return this.inputs?a<this.inputs.length?this.inputs[a]:null:null};u.prototype.getInputLink=function(a){return this.inputs?a<this.inputs.length?this.graph.links[this.inputs[a].link]:null:null};u.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};u.prototype.getInputOrProperty=function(a){if(!this.inputs||!this.inputs.length)return this.properties?this.properties[a]:null;for(var b=0,d=this.inputs.length;b<d;++b){var g=this.inputs[b];if(a==g.name&&null!=g.link&&(g=this.graph.links[g.link]))return g.data}return this.properties[a]};u.prototype.getOutputData=function(a){return!this.outputs||a>=this.outputs.length?null:this.outputs[a]._data};u.prototype.getOutputInfo=function(a){return this.outputs?a<this.outputs.length?this.outputs[a]:
null:null};u.prototype.isOutputConnected=function(a){return this.outputs?a<this.outputs.length&&this.outputs[a].links&&this.outputs[a].links.length:!1};u.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};u.prototype.getOutputNodes=function(a){if(!this.outputs||0==this.outputs.length||a>=this.outputs.length)return null;a=this.outputs[a];if(!a.links||0==a.links.length)return null;
for(var b=[],d=0;d<a.links.length;d++){var g=this.graph.links[a.links[d]];g&&(g=this.graph.getNodeById(g.target_id))&&b.push(g)}return b};u.prototype.trigger=function(a,b){if(this.outputs&&this.outputs.length){this.graph&&(this.graph._last_trigger_time=f.getTime());for(var d=0;d<this.outputs.length;++d){var g=this.outputs[d];!g||g.type!==f.EVENT||a&&g.name!=a||this.triggerSlot(d,b)}}};u.prototype.triggerSlot=function(a,b,d){if(this.outputs&&(a=this.outputs[a])&&(a=a.links)&&a.length){this.graph&&
(this.graph._last_trigger_time=f.getTime());for(var g=0;g<a.length;++g){var e=a[g];if(null==d||d==e){var E=this.graph.links[a[g]];if(E&&(E._last_time=f.getTime(),e=this.graph.getNodeById(E.target_id)))if(E=e.inputs[E.target_slot],e.mode===f.ON_TRIGGER){if(e.onExecute)e.onExecute(b)}else if(e.onAction)e.onAction(E.name,b)}}}};u.prototype.clearTriggeredSlot=function(a,b){if(this.outputs){var d=this.outputs[a];if(d&&(d=d.links)&&d.length)for(var g=0;g<d.length;++g){var e=d[g];if(null==b||b==e)if(e=this.graph.links[d[g]])e._last_time=
0}}};u.prototype.setSize=function(a){this.size=a;if(this.onResize)this.onResize(this.size)};u.prototype.addProperty=function(a,b,d,g){d={name:a,type:d,default_value:b};if(g)for(var e in g)d[e]=g[e];this.properties_info||(this.properties_info=[]);this.properties_info.push(d);this.properties||(this.properties={});this.properties[a]=b;return d};u.prototype.addOutput=function(a,b,d){a={name:a,type:b,links:null};if(d)for(var g in d)a[g]=d[g];this.outputs||(this.outputs=[]);this.outputs.push(a);if(this.onOutputAdded)this.onOutputAdded(a);
this.setSize(this.computeSize());this.setDirtyCanvas(!0,!0);return a};u.prototype.addOutputs=function(a){for(var b=0;b<a.length;++b){var d=a[b],g={name:d[0],type:d[1],link:null};if(a[2])for(var e in d[2])g[e]=d[2][e];this.outputs||(this.outputs=[]);this.outputs.push(g);if(this.onOutputAdded)this.onOutputAdded(g)}this.setSize(this.computeSize());this.setDirtyCanvas(!0,!0)};u.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 d=this.outputs[b].links,g=0;g<d.length;++g){var e=this.graph.links[d[g]];e&&(e.origin_slot-=1)}this.setSize(this.computeSize());if(this.onOutputRemoved)this.onOutputRemoved(a);this.setDirtyCanvas(!0,!0)};u.prototype.addInput=function(a,b,d){a={name:a,type:b||0,link:null};if(d)for(var g in d)a[g]=d[g];this.inputs||(this.inputs=[]);this.inputs.push(a);this.setSize(this.computeSize());if(this.onInputAdded)this.onInputAdded(a);this.setDirtyCanvas(!0,!0);return a};u.prototype.addInputs=
function(a){for(var b=0;b<a.length;++b){var d=a[b],g={name:d[0],type:d[1],link:null};if(a[2])for(var e in d[2])g[e]=d[2][e];this.inputs||(this.inputs=[]);this.inputs.push(g);if(this.onInputAdded)this.onInputAdded(g)}this.setSize(this.computeSize());this.setDirtyCanvas(!0,!0)};u.prototype.removeInput=function(a){this.disconnectInput(a);for(var b=this.inputs.splice(a,1),d=a;d<this.inputs.length;++d)if(this.inputs[d]){var g=this.graph.links[this.inputs[d].link];g&&(g.target_slot-=1)}this.setSize(this.computeSize());
if(this.onInputRemoved)this.onInputRemoved(a,b[0]);this.setDirtyCanvas(!0,!0)};u.prototype.addConnection=function(a,b,d,g){a={name:a,type:b,pos:d,direction:g,links:null};this.connections.push(a);return a};u.prototype.computeSize=function(a){function b(a){return a?g*a.length*0.6:0}if(this.constructor.size)return this.constructor.size.concat();var d=Math.max(this.inputs?this.inputs.length:1,this.outputs?this.outputs.length:1);a=a||new Float32Array([0,0]);var d=Math.max(d,1),g=f.NODE_TEXT_SIZE,e=b(this.title),
E=0,m=0;if(this.inputs)for(var s=0,y=this.inputs.length;s<y;++s){var c=this.inputs[s],c=c.label||c.name||"",c=b(c);E<c&&(E=c)}if(this.outputs)for(s=0,y=this.outputs.length;s<y;++s)c=this.outputs[s],c=c.label||c.name||"",c=b(c),m<c&&(m=c);a[0]=Math.max(E+m+10,e);a[0]=Math.max(a[0],f.NODE_WIDTH);this.widgets&&this.widgets.length&&(a[0]=Math.max(a[0],1.5*f.NODE_WIDTH));a[1]=(this.constructor.slot_start_y||0)+d*f.NODE_SLOT_HEIGHT;d=0;if(this.widgets&&this.widgets.length){s=0;for(y=this.widgets.length;s<
y;++s)d=this.widgets[s].computeSize?d+(this.widgets[s].computeSize(a[0])[1]+4):d+(f.NODE_WIDGET_HEIGHT+4);d+=8}a[1]=this.widgets_up?Math.max(a[1],d):null!=this.widgets_start_y?Math.max(a[1],d+this.widgets_start_y):a[1]+d;this.constructor.min_height&&a[1]<this.constructor.min_height&&(a[1]=this.constructor.min_height);a[1]+=6;return a};u.prototype.getPropertyInfo=function(a){var b=null;if(this.properties_info)for(var d=0;d<this.properties_info.length;++d)if(this.properties_info[d].name==a){b=this.properties_info[d];
break}this.constructor["@"+a]&&(b=this.constructor["@"+a]);this.constructor.widgets_info&&this.constructor.widgets_info[a]&&(b=this.constructor.widgets_info[a]);!b&&this.onGetPropertyInfo&&(b=this.onGetPropertyInfo(a));b||(b={});b.type||(b.type=typeof this.properties[a]);"combo"==b.widget&&(b.type="enum");return b};u.prototype.addWidget=function(a,b,d,g,e){this.widgets||(this.widgets=[]);!e&&g&&g.constructor===Object&&(e=g,g=null);e&&e.constructor===String&&(e={property:e});g&&g.constructor===String&&
(e||(e={}),e.property=g,g=null);g&&g.constructor!==Function&&(console.warn("addWidget: callback must be a function"),g=null);b={type:a.toLowerCase(),name:b,value:d,callback:g,options:e||{}};void 0!==b.options.y&&(b.y=b.options.y);g||b.options.callback||b.options.property||console.warn("LiteGraph addWidget(...) without a callback or property assigned");if("combo"==a&&!b.options.values)throw"LiteGraph addWidget('combo',...) requires to pass values in options: { values:['red','blue'] }";this.widgets.push(b);
this.setSize(this.computeSize());return b};u.prototype.addCustomWidget=function(a){this.widgets||(this.widgets=[]);this.widgets.push(a);return a};u.prototype.getBounding=function(a){a=a||new Float32Array(4);a[0]=this.pos[0]-4;a[1]=this.pos[1]-f.NODE_TITLE_HEIGHT;a[2]=this.size[0]+4;a[3]=this.size[1]+f.NODE_TITLE_HEIGHT;if(this.onBounding)this.onBounding(a);return a};u.prototype.isPointInside=function(a,b,d,g){d=d||0;var e=this.graph&&this.graph.isLive()?0:f.NODE_TITLE_HEIGHT;g&&(e=0);if(this.flags&&
this.flags.collapsed){if(x(a,b,this.pos[0]-d,this.pos[1]-f.NODE_TITLE_HEIGHT-d,(this._collapsed_width||f.NODE_COLLAPSED_WIDTH)+2*d,f.NODE_TITLE_HEIGHT+2*d))return!0}else if(this.pos[0]-4-d<a&&this.pos[0]+this.size[0]+4+d>a&&this.pos[1]-e-d<b&&this.pos[1]+this.size[1]+d>b)return!0;return!1};u.prototype.getSlotInPosition=function(a,b){var d=new Float32Array(2);if(this.inputs)for(var g=0,e=this.inputs.length;g<e;++g){var f=this.inputs[g];this.getConnectionPos(!0,g,d);if(x(a,b,d[0]-10,d[1]-5,20,10))return{input:f,
slot:g,link_pos:d}}if(this.outputs)for(g=0,e=this.outputs.length;g<e;++g)if(f=this.outputs[g],this.getConnectionPos(!1,g,d),x(a,b,d[0]-10,d[1]-5,20,10))return{output:f,slot:g,link_pos:d};return null};u.prototype.findInputSlot=function(a){if(!this.inputs)return-1;for(var b=0,d=this.inputs.length;b<d;++b)if(a==this.inputs[b].name)return b;return-1};u.prototype.findOutputSlot=function(a){if(!this.outputs)return-1;for(var b=0,d=this.outputs.length;b<d;++b)if(a==this.outputs[b].name)return b;return-1};
u.prototype.connect=function(a,b,d){d=d||0;if(!this.graph)return console.log("Connect: Error, node doesn't 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 f.debug&&console.log("Connect: Error, no slot of name "+a),null}else if(!this.outputs||a>=this.outputs.length)return f.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(d.constructor===String){if(d=b.findInputSlot(d),-1==d)return f.debug&&console.log("Connect: Error, no slot of name "+d),null}else{if(d===f.EVENT)return null;if(!b.inputs||d>=b.inputs.length)return f.debug&&console.log("Connect: Error, slot number not found"),null}var g=!1;null!=b.inputs[d].link&&(this.graph.beforeChange(),b.disconnectInput(d),g=!0);var e=this.outputs[a];if(b.onConnectInput&&!1===b.onConnectInput(d,e.type,e,this,a))return null;
var c=b.inputs[d],m=null;if(!f.isValidConnection(e.type,c.type))return this.setDirtyCanvas(!1,!0),g&&this.graph.connectionChange(this,m),null;g||this.graph.beforeChange();m=new l(++this.graph.last_link_id,c.type,this.id,a,b.id,d);this.graph.links[m.id]=m;null==e.links&&(e.links=[]);e.links.push(m.id);b.inputs[d].link=m.id;this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(f.OUTPUT,a,!0,m,e);if(b.onConnectionsChange)b.onConnectionsChange(f.INPUT,d,!0,m,c);this.graph&&
this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(f.INPUT,b,d,this,a),this.graph.onNodeConnectionChange(f.OUTPUT,this,a,b,d));this.setDirtyCanvas(!1,!0);this.graph.afterChange();this.graph.connectionChange(this,m);return m};u.prototype.disconnectOutput=function(a,b){if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return f.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.outputs||a>=this.outputs.length)return f.debug&&console.log("Connect: Error, slot number not found"),
!1;var d=this.outputs[a];if(!d||!d.links||0==d.links.length)return!1;if(b){b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"Target Node not found";for(var g=0,e=d.links.length;g<e;g++){var c=d.links[g],m=this.graph.links[c];if(m.target_id==b.id){d.links.splice(g,1);var s=b.inputs[m.target_slot];s.link=null;delete this.graph.links[c];this.graph&&this.graph._version++;if(b.onConnectionsChange)b.onConnectionsChange(f.INPUT,m.target_slot,!1,m,s);if(this.onConnectionsChange)this.onConnectionsChange(f.OUTPUT,
a,!1,m,d);if(this.graph&&this.graph.onNodeConnectionChange)this.graph.onNodeConnectionChange(f.OUTPUT,this,a);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(f.OUTPUT,this,a),this.graph.onNodeConnectionChange(f.INPUT,b,m.target_slot));break}}}else{g=0;for(e=d.links.length;g<e;g++)if(c=d.links[g],m=this.graph.links[c]){b=this.graph.getNodeById(m.target_id);this.graph&&this.graph._version++;if(b){s=b.inputs[m.target_slot];s.link=null;if(b.onConnectionsChange)b.onConnectionsChange(f.INPUT,
m.target_slot,!1,m,s);if(this.graph&&this.graph.onNodeConnectionChange)this.graph.onNodeConnectionChange(f.INPUT,b,m.target_slot)}delete this.graph.links[c];if(this.onConnectionsChange)this.onConnectionsChange(f.OUTPUT,a,!1,m,d);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(f.OUTPUT,this,a),this.graph.onNodeConnectionChange(f.INPUT,b,m.target_slot))}d.links=null}this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this);return!0};u.prototype.disconnectInput=function(a){if(a.constructor===
String){if(a=this.findInputSlot(a),-1==a)return f.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.inputs||a>=this.inputs.length)return f.debug&&console.log("Connect: Error, slot number not found"),!1;var b=this.inputs[a];if(!b)return!1;var d=this.inputs[a].link;if(null!=d){this.inputs[a].link=null;var g=this.graph.links[d];if(g){var e=this.graph.getNodeById(g.origin_id);if(!e)return!1;var c=e.outputs[g.origin_slot];if(!c||!c.links||0==c.links.length)return!1;for(var m=0,
s=c.links.length;m<s;m++)if(c.links[m]==d){c.links.splice(m,1);break}delete this.graph.links[d];this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(f.INPUT,a,!1,g,b);if(e.onConnectionsChange)e.onConnectionsChange(f.OUTPUT,m,!1,g,c);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(f.OUTPUT,e,m),this.graph.onNodeConnectionChange(f.INPUT,this,a))}}this.setDirtyCanvas(!1,!0);this.graph&&this.graph.connectionChange(this);return!0};u.prototype.getConnectionPos=
function(a,b,d){d=d||new Float32Array(2);var g=0;a&&this.inputs&&(g=this.inputs.length);!a&&this.outputs&&(g=this.outputs.length);var e=0.5*f.NODE_SLOT_HEIGHT;if(this.flags.collapsed)return b=this._collapsed_width||f.NODE_COLLAPSED_WIDTH,this.horizontal?(d[0]=this.pos[0]+0.5*b,d[1]=a?this.pos[1]-f.NODE_TITLE_HEIGHT:this.pos[1]):(d[0]=a?this.pos[0]:this.pos[0]+b,d[1]=this.pos[1]-0.5*f.NODE_TITLE_HEIGHT),d;if(a&&-1==b)return d[0]=this.pos[0]+0.5*f.NODE_TITLE_HEIGHT,d[1]=this.pos[1]+0.5*f.NODE_TITLE_HEIGHT,
d;if(a&&g>b&&this.inputs[b].pos)return d[0]=this.pos[0]+this.inputs[b].pos[0],d[1]=this.pos[1]+this.inputs[b].pos[1],d;if(!a&&g>b&&this.outputs[b].pos)return d[0]=this.pos[0]+this.outputs[b].pos[0],d[1]=this.pos[1]+this.outputs[b].pos[1],d;if(this.horizontal)return d[0]=this.pos[0]+this.size[0]/g*(b+0.5),d[1]=a?this.pos[1]-f.NODE_TITLE_HEIGHT:this.pos[1]+this.size[1],d;d[0]=a?this.pos[0]+e:this.pos[0]+this.size[0]+1-e;d[1]=this.pos[1]+(b+0.7)*f.NODE_SLOT_HEIGHT+(this.constructor.slot_start_y||0);
return d};u.prototype.alignToGrid=function(){this.pos[0]=f.CANVAS_GRID_SIZE*Math.round(this.pos[0]/f.CANVAS_GRID_SIZE);this.pos[1]=f.CANVAS_GRID_SIZE*Math.round(this.pos[1]/f.CANVAS_GRID_SIZE)};u.prototype.trace=function(a){this.console||(this.console=[]);this.console.push(a);this.console.length>u.MAX_CONSOLE&&this.console.shift();if(this.graph.onNodeTrace)this.graph.onNodeTrace(this,a)};u.prototype.setDirtyCanvas=function(a,b){this.graph&&this.graph.sendActionToCanvas("setDirty",[a,b])};u.prototype.loadImage=
function(a){var b=new Image;b.src=f.node_images_path+a;b.ready=!1;var d=this;b.onload=function(){this.ready=!0;d.setDirtyCanvas(!0)};return b};u.prototype.captureInput=function(a){if(this.graph&&this.graph.list_of_graphcanvas)for(var b=this.graph.list_of_graphcanvas,d=0;d<b.length;++d){var g=b[d];if(a||g.node_capturing_input==this)g.node_capturing_input=a?this:null}};u.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)};u.prototype.pin=function(a){this.graph._version++;this.flags.pinned=void 0===a?!this.flags.pinned:a};u.prototype.localToScreen=function(a,b,d){return[(a+this.pos[0])*d.scale+d.offset[0],(b+this.pos[1])*d.scale+d.offset[1]]};B.LGraphGroup=f.LGraphGroup=r;r.prototype._ctor=function(a){this.title=a||"Group";this.font_size=24;this.color=h.node_colors.pale_blue?h.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,d){this._pos[0]+=a;this._pos[1]+=b;if(!d)for(d=0;d<this._nodes.length;++d){var g=this._nodes[d];g.pos[0]+=a;g.pos[1]+=b}};r.prototype.recomputeInsideNodes=function(){this._nodes.length=0;for(var a=this.graph._nodes,b=new Float32Array(4),d=0;d<a.length;++d){var g=
a[d];g.getBounding(b);G(this._bounding,b)&&this._nodes.push(g)}};r.prototype.isPointInside=u.prototype.isPointInside;r.prototype.setDirtyCanvas=u.prototype.setDirtyCanvas;f.DragAndScale=t;t.prototype.bindEvents=function(a){this.last_mouse=new Float32Array(2);this._binded_mouse_callback=this.onMouse.bind(this);a.addEventListener("mousedown",this._binded_mouse_callback);a.addEventListener("mousemove",this._binded_mouse_callback);a.addEventListener("mousewheel",this._binded_mouse_callback,!1);a.addEventListener("wheel",
this._binded_mouse_callback,!1)};t.prototype.computeVisibleArea=function(){if(this.element){var a=-this.offset[0],b=-this.offset[1],d=a+this.element.width/this.scale,g=b+this.element.height/this.scale;this.visible_area[0]=a;this.visible_area[1]=b;this.visible_area[2]=d-a;this.visible_area[3]=g-b}else this.visible_area[0]=this.visible_area[1]=this.visible_area[2]=this.visible_area[3]=0};t.prototype.onMouse=function(a){if(this.enabled){var b=this.element,d=b.getBoundingClientRect(),g=a.clientX-d.left,
d=a.clientY-d.top;a.canvasx=g;a.canvasy=d;a.dragging=this.dragging;var e=!1;this.onmouse&&(e=this.onmouse(a));if("mousedown"==a.type)this.dragging=!0,b.removeEventListener("mousemove",this._binded_mouse_callback),document.body.addEventListener("mousemove",this._binded_mouse_callback),document.body.addEventListener("mouseup",this._binded_mouse_callback);else if("mousemove"==a.type)e||(b=g-this.last_mouse[0],e=d-this.last_mouse[1],this.dragging&&this.mouseDrag(b,e));else if("mouseup"==a.type)this.dragging=
!1,document.body.removeEventListener("mousemove",this._binded_mouse_callback),document.body.removeEventListener("mouseup",this._binded_mouse_callback),b.addEventListener("mousemove",this._binded_mouse_callback);else if("mousewheel"==a.type||"wheel"==a.type||"DOMMouseScroll"==a.type)a.eventType="mousewheel",a.wheel="wheel"==a.type?-a.deltaY:null!=a.wheelDeltaY?a.wheelDeltaY:-60*a.detail,a.delta=a.wheelDelta?a.wheelDelta/40:a.deltaY?-a.deltaY/3:0,this.changeDeltaScale(1+0.05*a.delta);this.last_mouse[0]=
g;this.last_mouse[1]=d;a.preventDefault();a.stopPropagation();return!1}};t.prototype.toCanvasContext=function(a){a.scale(this.scale,this.scale);a.translate(this.offset[0],this.offset[1])};t.prototype.convertOffsetToCanvas=function(a){return[(a[0]+this.offset[0])*this.scale,(a[1]+this.offset[1])*this.scale]};t.prototype.convertCanvasToOffset=function(a,b){b=b||[0,0];b[0]=a[0]/this.scale-this.offset[0];b[1]=a[1]/this.scale-this.offset[1];return b};t.prototype.mouseDrag=function(a,b){this.offset[0]+=
a/this.scale;this.offset[1]+=b/this.scale;if(this.onredraw)this.onredraw(this)};t.prototype.changeScale=function(a,b){a<this.min_scale?a=this.min_scale:a>this.max_scale&&(a=this.max_scale);if(a!=this.scale&&this.element){var d=this.element.getBoundingClientRect();if(d){b=b||[0.5*d.width,0.5*d.height];d=this.convertCanvasToOffset(b);this.scale=a;0.01>Math.abs(this.scale-1)&&(this.scale=1);var g=this.convertCanvasToOffset(b),d=[g[0]-d[0],g[1]-d[1]];this.offset[0]+=d[0];this.offset[1]+=d[1];if(this.onredraw)this.onredraw(this)}}};
t.prototype.changeDeltaScale=function(a,b){this.changeScale(this.scale*a,b)};t.prototype.reset=function(){this.scale=1;this.offset[0]=0;this.offset[1]=0};B.LGraphCanvas=f.LGraphCanvas=h;h.DEFAULT_BACKGROUND_IMAGE="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQBJREFUeNrs1rEKwjAUhlETUkj3vP9rdmr1Ysammk2w5wdxuLgcMHyptfawuZX4pJSWZTnfnu/lnIe/jNNxHHGNn//HNbbv+4dr6V+11uF527arU7+u63qfa/bnmh8sWLBgwYJlqRf8MEptXPBXJXa37BSl3ixYsGDBMliwFLyCV/DeLIMFCxYsWLBMwSt4Be/NggXLYMGCBUvBK3iNruC9WbBgwYJlsGApeAWv4L1ZBgsWLFiwYJmCV/AK3psFC5bBggULloJX8BpdwXuzYMGCBctgwVLwCl7Be7MMFixYsGDBsu8FH1FaSmExVfAxBa/gvVmwYMGCZbBg/W4vAQYA5tRF9QYlv/QAAAAASUVORK5CYII=";
e>s.height-y.height-10&&(e=s.height-y.height-10)}f.style.left=m+"px";f.style.top=e+"px";b.scale&&(f.style.transform="scale("+b.scale+")")}function D(a){this.points=a;this.nearest=this.selected=-1;this.size=null;this.must_update=!0;this.margin=5}var f=B.LiteGraph={VERSION:0.4,CANVAS_GRID_SIZE:10,NODE_TITLE_HEIGHT:30,NODE_TITLE_TEXT_Y:20,NODE_SLOT_HEIGHT:20,NODE_WIDGET_HEIGHT:20,NODE_WIDTH:140,NODE_MIN_WIDTH:50,NODE_COLLAPSED_RADIUS:10,NODE_COLLAPSED_WIDTH:80,NODE_TITLE_COLOR:"#999",NODE_SELECTED_TITLE_COLOR:"#FFF",
NODE_TEXT_SIZE:14,NODE_TEXT_COLOR:"#AAA",NODE_SUBTEXT_SIZE:12,NODE_DEFAULT_COLOR:"#333",NODE_DEFAULT_BGCOLOR:"#353535",NODE_DEFAULT_BOXCOLOR:"#666",NODE_DEFAULT_SHAPE:"box",NODE_BOX_OUTLINE_COLOR:"#FFF",DEFAULT_SHADOW_COLOR:"rgba(0,0,0,0.5)",DEFAULT_GROUP_FONT:24,WIDGET_BGCOLOR:"#222",WIDGET_OUTLINE_COLOR:"#666",WIDGET_TEXT_COLOR:"#DDD",WIDGET_SECONDARY_TEXT_COLOR:"#999",LINK_COLOR:"#9A9",EVENT_LINK_COLOR:"#A86",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,STRAIGHT_LINK:0,LINEAR_LINK:1,SPLINE_LINK:2,NORMAL_TITLE:0,NO_TITLE:1,TRANSPARENT_TITLE:2,AUTOHIDE_TITLE:3,proxy:null,node_images_path:"",debug:!1,catch_exceptions:!0,throw_errors:!0,allow_scripts:!1,registered_node_types:{},node_types_by_file_extension:{},Nodes:{},Globals:{},searchbox_extras:{},auto_sort_node_types:!1,
registerNodeType:function(a,b){if(!b.prototype)throw"Cannot register a simple object, it must be a class with a prototype";b.type=a;f.debug&&console.log("Node registered: "+a);a.split("/");var d=b.name,g=a.lastIndexOf("/");b.category=a.substr(0,g);b.title||(b.title=d);if(b.prototype)for(var e in u.prototype)b.prototype[e]||(b.prototype[e]=u.prototype[e]);if(g=this.registered_node_types[a])console.log("replacing node type: "+a);else if(Object.hasOwnProperty(b.prototype,"shape")||Object.defineProperty(b.prototype,
"shape",{set:function(a){switch(a){case "default":delete this._shape;break;case "box":this._shape=f.BOX_SHAPE;break;case "round":this._shape=f.ROUND_SHAPE;break;case "circle":this._shape=f.CIRCLE_SHAPE;break;case "card":this._shape=f.CARD_SHAPE;break;default:this._shape=a}},get:function(a){return this._shape},enumerable:!0,configurable:!0}),b.prototype.onPropertyChange&&console.warn("LiteGraph node class "+a+" has onPropertyChange method, it must be called onPropertyChanged with d at the end"),b.supported_extensions)for(e in b.supported_extensions){var E=
b.supported_extensions[e];E&&E.constructor===String&&(this.node_types_by_file_extension[E.toLowerCase()]=b)}this.registered_node_types[a]=b;b.constructor.name&&(this.Nodes[d]=b);if(f.onNodeTypeRegistered)f.onNodeTypeRegistered(a,b);if(g&&f.onNodeTypeReplaced)f.onNodeTypeReplaced(a,b,g);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(e=0;e<b.supported_extensions.length;e++)(E=
b.supported_extensions[e])&&E.constructor===String&&(this.node_types_by_file_extension[E.toLowerCase()]=b)},unregisterNodeType:function(a){var b=a.constructor===String?this.registered_node_types[a]:a;if(!b)throw"node type not found: "+a;delete this.registered_node_types[b.type];b.constructor.name&&delete this.Nodes[b.constructor.name]},wrapFunctionAsNode:function(a,b,d,g,e){for(var E=Array(b.length),m="",s=f.getParameterNames(b),y=0;y<s.length;++y)m+="this.addInput('"+s[y]+"',"+(d&&d[y]?"'"+d[y]+
"'":"0")+");\n";m+="this.addOutput('out',"+(g?"'"+g+"'":0)+");\n";e&&(m+="this.properties = "+JSON.stringify(e)+";\n");d=Function(m);d.title=a.split("/").pop();d.desc="Generated from "+b.name;d.prototype.onExecute=function(){for(var a=0;a<E.length;++a)E[a]=this.getInputData(a);a=b.apply(this,E);this.setOutputData(0,a)};this.registerNodeType(a,d)},clearRegisteredTypes:function(){this.registered_node_types={};this.node_types_by_file_extension={};this.Nodes={};this.searchbox_extras={}},addNodeMethod:function(a,
b){u.prototype[a]=b;for(var d in this.registered_node_types){var g=this.registered_node_types[d];g.prototype[a]&&(g.prototype["_"+a]=g.prototype[a]);g.prototype[a]=b}},createNode:function(a,b,d){var g=this.registered_node_types[a];if(!g)return f.debug&&console.log('GraphNode type "'+a+'" not registered.'),null;b=b||g.title||a;var e=null;if(f.catch_exceptions)try{e=new g(b)}catch(E){return console.error(E),null}else e=new g(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=f.DEFAULT_POSITION.concat());e.mode||(e.mode=f.ALWAYS);if(d)for(var m in d)e[m]=d[m];return e},getNodeType:function(a){return this.registered_node_types[a]},getNodeTypesInCategory:function(a,b){var d=[],g;for(g in this.registered_node_types){var e=this.registered_node_types[g];e.filter==b&&(""==a?null==e.category&&d.push(e):e.category==a&&d.push(e))}return this.auto_sort_node_types?d.sort():d},getNodeTypesCategories:function(a){var b=
{"":1},d;for(d in this.registered_node_types){var g=this.registered_node_types[d];g.category&&!g.skip_list&&g.filter==a&&(b[g.category]=1)}a=[];for(d in b)a.push(d);return this.auto_sort_node_types?a.sort():a},reloadNodes:function(a){for(var b=document.getElementsByTagName("script"),d=[],g=0;g<b.length;g++)d.push(b[g]);b=document.getElementsByTagName("head")[0];a=document.location.href+a;for(g=0;g<d.length;g++){var e=d[g].src;if(e&&e.substr(0,a.length)==a)try{f.debug&&console.log("Reloading: "+e);
var E=document.createElement("script");E.type="text/javascript";E.src=e;b.appendChild(E);b.removeChild(d[g])}catch(m){if(f.throw_errors)throw m;f.debug&&console.log("Error while reloading "+e)}}f.debug&&console.log("Nodes reloaded")},cloneObject:function(a,b){if(null==a)return null;var d=JSON.parse(JSON.stringify(a));if(!b)return d;for(var g in d)b[g]=d[g];return b},isValidConnection:function(a,b){if(!a||!b||a==b||a==f.EVENT&&b==f.ACTION)return!0;a=String(a);b=String(b);a=a.toLowerCase();b=b.toLowerCase();
if(-1==a.indexOf(",")&&-1==b.indexOf(","))return a==b;for(var d=a.split(","),g=b.split(","),e=0;e<d.length;++e)for(var E=0;E<g.length;++E)if(d[e]==g[E])return!0;return!1},registerSearchboxExtra:function(a,b,d){this.searchbox_extras[b.toLowerCase()]={type:a,desc:b,data:d}},fetchFile:function(a,b,d,g){if(!a)return null;b=b||"text";if(a.constructor===String)return"http"==a.substr(0,4)&&f.proxy&&(a=f.proxy+a.substr(a.indexOf(":")+3)),fetch(a).then(function(a){if(!a.ok)throw Error("File not found");if("arraybuffer"==
b)return a.arrayBuffer();if("text"==b||"string"==b)return a.text();if("json"==b)return a.json();if("blob"==b)return a.blob()}).then(function(a){d&&d(a)})["catch"](function(b){console.error("error fetching file:",a);g&&g(b)});if(a.constructor===File||a.constructor===Blob){var e=new FileReader;e.onload=function(a){a=a.target.result;"json"==b&&(a=JSON.parse(a));d&&d(a)};if("arraybuffer"==b)return e.readAsArrayBuffer(a);if("text"==b||"json"==b)return e.readAsText(a);if("blob"==b)return e.readAsBinaryString(a)}return null}};
f.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()};B.LGraph=f.LGraph=c;c.supported_types=["number","string","boolean"];c.prototype.getSupportedTypes=function(){return this.supported_types||c.supported_types};c.STATUS_STOPPED=1;c.STATUS_RUNNING=2;c.prototype.clear=function(){this.stop();this.status=
c.STATUS_STOPPED;this.last_link_id=this.last_node_id=0;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.vars={};this.extra={};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.inputs={};this.outputs={};this.change();this.sendActionToCanvas("clear")};c.prototype.attachCanvas=function(a){if(a.constructor!=h)throw"attachCanvas expects a LGraphCanvas instance";a.graph&&a.graph!=this&&a.graph.detachCanvas(a);a.graph=this;this.list_of_graphcanvas||(this.list_of_graphcanvas=[]);this.list_of_graphcanvas.push(a)};c.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))}};c.prototype.start=function(a){if(this.status!=c.STATUS_RUNNING){this.status=c.STATUS_RUNNING;if(this.onPlayEvent)this.onPlayEvent();this.sendEventToAllNodes("onStart");this.last_update_time=this.starttime=f.getTime();a=a||0;var b=this;if(0==a&&"undefined"!=typeof window&&window.requestAnimationFrame){var d=function(){if(-1==b.execution_timer_id){window.requestAnimationFrame(d);if(b.onBeforeStep)b.onBeforeStep();b.runStep(1,!b.catch_errors);if(b.onAfterStep)b.onAfterStep()}};this.execution_timer_id=
-1;d()}else this.execution_timer_id=setInterval(function(){if(b.onBeforeStep)b.onBeforeStep();b.runStep(1,!b.catch_errors);if(b.onAfterStep)b.onAfterStep()},a)}};c.prototype.stop=function(){if(this.status!=c.STATUS_STOPPED){this.status=c.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")}};c.prototype.runStep=function(a,b,d){a=a||1;
var g=f.getTime();this.globaltime=0.001*(g-this.starttime);var e=this._nodes_executable?this._nodes_executable:this._nodes;if(e){d=d||e.length;if(b){for(var E=0;E<a;E++){for(var m=0;m<d;++m){var s=e[m];if(s.mode==f.ALWAYS&&s.onExecute)s.onExecute()}this.fixedtime+=this.fixedtime_lapse;if(this.onExecuteStep)this.onExecuteStep()}if(this.onAfterExecute)this.onAfterExecute()}else try{for(E=0;E<a;E++){for(m=0;m<d;++m)if(s=e[m],s.mode==f.ALWAYS&&s.onExecute)s.onExecute();this.fixedtime+=this.fixedtime_lapse;
if(this.onExecuteStep)this.onExecuteStep()}if(this.onAfterExecute)this.onAfterExecute();this.errors_in_execution=!1}catch(y){this.errors_in_execution=!0;if(f.throw_errors)throw y;f.debug&&console.log("Error during execution: "+y);this.stop()}a=f.getTime();g=a-g;0==g&&(g=1);this.execution_time=0.001*g;this.globaltime+=0.001*g;this.iteration+=1;this.elapsed_time=0.001*(a-this.last_update_time);this.last_update_time=a}};c.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])};c.prototype.computeExecutionOrder=function(a,b){for(var d=[],g=[],e={},E={},m={},s=0,y=this._nodes.length;s<y;++s){var c=this._nodes[s];if(!a||c.onExecute){e[c.id]=c;var k=0;if(c.inputs)for(var z=0,F=c.inputs.length;z<F;z++)c.inputs[z]&&null!=c.inputs[z].link&&(k+=1);0==k?(g.push(c),b&&(c._level=1)):(b&&(c._level=0),m[c.id]=k)}}for(;0!=g.length;)if(c=
g.shift(),d.push(c),delete e[c.id],c.outputs)for(s=0;s<c.outputs.length;s++)if(y=c.outputs[s],null!=y&&null!=y.links&&0!=y.links.length)for(z=0;z<y.links.length;z++)(k=this.links[y.links[z]])&&!E[k.id]&&(F=this.getNodeById(k.target_id),null==F?E[k.id]=!0:(b&&(!F._level||F._level<=c._level)&&(F._level=c._level+1),E[k.id]=!0,m[F.id]-=1,0==m[F.id]&&g.push(F)));for(s in e)d.push(e[s]);d.length!=this._nodes.length&&f.debug&&console.warn("something went wrong, nodes missing");y=d.length;for(s=0;s<y;++s)d[s].order=
s;d=d.sort(function(a,b){var d=a.constructor.priority||a.priority||0,e=b.constructor.priority||b.priority||0;return d==e?a.order-b.order:d-e});for(s=0;s<y;++s)d[s].order=s;return d};c.prototype.getAncestors=function(a){for(var b=[],d=[a],g={};d.length;){var e=d.shift();if(e.inputs){g[e.id]||e==a||(g[e.id]=!0,b.push(e));for(var f=0;f<e.inputs.length;++f){var m=e.getInputNode(f);m&&-1==b.indexOf(m)&&d.push(m)}}}b.sort(function(a,b){return a.order-b.order});return b};c.prototype.arrange=function(a){a=
a||100;for(var b=this.computeExecutionOrder(!1,!0),d=[],g=0;g<b.length;++g){var e=b[g],E=e._level||1;d[E]||(d[E]=[]);d[E].push(e)}b=a;for(g=0;g<d.length;++g)if(E=d[g]){for(var m=100,s=a+f.NODE_TITLE_HEIGHT,y=0;y<E.length;++y)e=E[y],e.pos[0]=b,e.pos[1]=s,e.size[0]>m&&(m=e.size[0]),s+=e.size[1]+a+f.NODE_TITLE_HEIGHT;b+=m+a}this.setDirtyCanvas(!0,!0)};c.prototype.getTime=function(){return this.globaltime};c.prototype.getFixedTime=function(){return this.fixedtime};c.prototype.getElapsedTime=function(){return this.elapsed_time};
c.prototype.sendEventToAllNodes=function(a,b,d){d=d||f.ALWAYS;var g=this._nodes_in_order?this._nodes_in_order:this._nodes;if(g)for(var e=0,E=g.length;e<E;++e){var m=g[e];if(m.constructor===f.Subgraph&&"onExecute"!=a)m.mode==d&&m.sendEventToAllNodes(a,b,d);else if(m[a]&&m.mode==d)if(void 0===b)m[a]();else if(b&&b.constructor===Array)m[a].apply(m,b);else m[a](b)}};c.prototype.sendActionToCanvas=function(a,b){if(this.list_of_graphcanvas)for(var d=0;d<this.list_of_graphcanvas.length;++d){var g=this.list_of_graphcanvas[d];
g[a]&&g[a].apply(g,b)}};c.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>=f.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}};c.prototype.remove=function(a){if(a.constructor===f.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 d=a.inputs[b];null!=d.link&&a.disconnectInput(b)}if(a.outputs)for(b=0;b<a.outputs.length;b++)d=a.outputs[b],null!=d.links&&d.links.length&&a.disconnectOutput(b);if(a.onRemoved)a.onRemoved();a.graph=null;this._version++;if(this.list_of_graphcanvas)for(b=0;b<this.list_of_graphcanvas.length;++b)d=this.list_of_graphcanvas[b],d.selected_nodes[a.id]&&delete d.selected_nodes[a.id],d.node_dragged==a&&(d.node_dragged=null);b=this._nodes.indexOf(a);
-1!=b&&this._nodes.splice(b,1);delete this._nodes_by_id[a.id];if(this.onNodeRemoved)this.onNodeRemoved(a);this.sendActionToCanvas("checkPanels");this.setDirtyCanvas(!0,!0);this.change();this.updateExecutionOrder()}};c.prototype.getNodeById=function(a){return null==a?null:this._nodes_by_id[a]};c.prototype.findNodesByClass=function(a,b){b=b||[];for(var d=b.length=0,g=this._nodes.length;d<g;++d)this._nodes[d].constructor===a&&b.push(this._nodes[d]);return b};c.prototype.findNodesByType=function(a,b){a=
a.toLowerCase();b=b||[];for(var d=b.length=0,g=this._nodes.length;d<g;++d)this._nodes[d].type.toLowerCase()==a&&b.push(this._nodes[d]);return b};c.prototype.findNodeByTitle=function(a){for(var b=0,d=this._nodes.length;b<d;++b)if(this._nodes[b].title==a)return this._nodes[b];return null};c.prototype.findNodesByTitle=function(a){for(var b=[],d=0,g=this._nodes.length;d<g;++d)this._nodes[d].title==a&&b.push(this._nodes[d]);return b};c.prototype.getNodeOnPos=function(a,b,d,g){d=d||this._nodes;for(var e=
d.length-1;0<=e;e--){var f=d[e];if(f.isPointInside(a,b,g))return f}return null};c.prototype.getGroupOnPos=function(a,b){for(var d=this._groups.length-1;0<=d;d--){var g=this._groups[d];if(g.isPointInside(a,b,2,!0))return g}return null};c.prototype.checkNodeTypes=function(){for(var a=0;a<this._nodes.length;a++){var b=this._nodes[a];if(b.constructor!=f.registered_node_types[b.type]){console.log("node being replaced by newer version: "+b.type);var d=f.createNode(b.type);this._nodes[a]=d;d.configure(b.serialize());
d.graph=this;this._nodes_by_id[d.id]=d;b.inputs&&(d.inputs=b.inputs.concat());b.outputs&&(d.outputs=b.outputs.concat())}}this.updateExecutionOrder()};c.prototype.onAction=function(a,b){this._input_nodes=this.findNodesByClass(f.GraphInput,this._input_nodes);for(var d=0;d<this._input_nodes.length;++d){var g=this._input_nodes[d];if(g.properties.name==a){g.onAction(a,b);break}}};c.prototype.trigger=function(a,b){if(this.onTrigger)this.onTrigger(a,b)};c.prototype.addInput=function(a,b,d){if(!this.inputs[a]){this.beforeChange();
this.inputs[a]={name:a,type:b,value:d};this._version++;this.afterChange();if(this.onInputAdded)this.onInputAdded(a,b);if(this.onInputsOutputsChange)this.onInputsOutputsChange()}};c.prototype.setInputData=function(a,b){var d=this.inputs[a];d&&(d.value=b)};c.prototype.getInputData=function(a){return(a=this.inputs[a])?a.value:null};c.prototype.renameInput=function(a,b){if(b!=a){if(!this.inputs[a])return!1;if(this.inputs[b])return console.error("there is already one input with that name"),!1;this.inputs[b]=
this.inputs[a];delete this.inputs[a];this._version++;if(this.onInputRenamed)this.onInputRenamed(a,b);if(this.onInputsOutputsChange)this.onInputsOutputsChange()}};c.prototype.changeInputType=function(a,b){if(!this.inputs[a])return!1;if(!this.inputs[a].type||String(this.inputs[a].type).toLowerCase()!=String(b).toLowerCase())if(this.inputs[a].type=b,this._version++,this.onInputTypeChanged)this.onInputTypeChanged(a,b)};c.prototype.removeInput=function(a){if(!this.inputs[a])return!1;delete this.inputs[a];
this._version++;if(this.onInputRemoved)this.onInputRemoved(a);if(this.onInputsOutputsChange)this.onInputsOutputsChange();return!0};c.prototype.addOutput=function(a,b,d){this.outputs[a]={name:a,type:b,value:d};this._version++;if(this.onOutputAdded)this.onOutputAdded(a,b);if(this.onInputsOutputsChange)this.onInputsOutputsChange()};c.prototype.setOutputData=function(a,b){var d=this.outputs[a];d&&(d.value=b)};c.prototype.getOutputData=function(a){return(a=this.outputs[a])?a.value:null};c.prototype.renameOutput=
function(a,b){if(!this.outputs[a])return!1;if(this.outputs[b])return console.error("there is already one output with that name"),!1;this.outputs[b]=this.outputs[a];delete this.outputs[a];this._version++;if(this.onOutputRenamed)this.onOutputRenamed(a,b);if(this.onInputsOutputsChange)this.onInputsOutputsChange()};c.prototype.changeOutputType=function(a,b){if(!this.outputs[a])return!1;if(!this.outputs[a].type||String(this.outputs[a].type).toLowerCase()!=String(b).toLowerCase())if(this.outputs[a].type=
b,this._version++,this.onOutputTypeChanged)this.onOutputTypeChanged(a,b)};c.prototype.removeOutput=function(a){if(!this.outputs[a])return!1;delete this.outputs[a];this._version++;if(this.onOutputRemoved)this.onOutputRemoved(a);if(this.onInputsOutputsChange)this.onInputsOutputsChange();return!0};c.prototype.triggerInput=function(a,b){for(var d=this.findNodesByTitle(a),g=0;g<d.length;++g)d[g].onTrigger(b)};c.prototype.setCallback=function(a,b){for(var d=this.findNodesByTitle(a),g=0;g<d.length;++g)d[g].setTrigger(b)};
c.prototype.beforeChange=function(a){if(this.onBeforeChange)this.onBeforeChange(this,a);this.sendActionToCanvas("onBeforeChange",this)};c.prototype.afterChange=function(a){if(this.onAfterChange)this.onAfterChange(this,a);this.sendActionToCanvas("onAfterChange",this)};c.prototype.connectionChange=function(a,b){this.updateExecutionOrder();if(this.onConnectionChange)this.onConnectionChange(a);this._version++;this.sendActionToCanvas("onConnectionChange")};c.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};c.prototype.clearTriggeredSlots=function(){for(var a in this.links){var b=this.links[a];b&&b._last_time&&(b._last_time=0)}};c.prototype.change=function(){f.debug&&console.log("Graph changed");this.sendActionToCanvas("setDirty",[!0,!0]);if(this.on_change)this.on_change(this)};c.prototype.setDirtyCanvas=function(a,b){this.sendActionToCanvas("setDirty",[a,b])};c.prototype.removeLink=function(a){if(a=
this.links[a]){var b=this.getNodeById(a.target_id);b&&b.disconnectInput(a.target_slot)}};c.prototype.serialize=function(){for(var a=[],b=0,d=this._nodes.length;b<d;++b)a.push(this._nodes[b].serialize());d=[];for(b in this.links){var g=this.links[b];if(!g.serialize){console.warn("weird LLink bug, link info is not a LLink but a regular object");var e=new l,E;for(E in g)e[E]=g[E];g=this.links[b]=e}d.push(g.serialize())}E=[];for(b=0;b<this._groups.length;++b)E.push(this._groups[b].serialize());a={last_node_id:this.last_node_id,
last_link_id:this.last_link_id,nodes:a,links:d,groups:E,config:this.config,extra:this.extra,version:f.VERSION};if(this.onSerialize)this.onSerialize(a);return a};c.prototype.configure=function(a,b){if(a){b||this.clear();var d=a.nodes;if(a.links&&a.links.constructor===Array){for(var g=[],e=0;e<a.links.length;++e){var E=a.links[e];if(E){var m=new l;m.configure(E);g[m.id]=m}else console.warn("serialized graph link data contains errors, skipping.")}a.links=g}for(e in a)"nodes"!=e&&"groups"!=e&&(this[e]=
a[e]);g=!1;this._nodes=[];if(d){e=0;for(E=d.length;e<E;++e){var m=d[e],s=f.createNode(m.type,m.title);s||(f.debug&&console.log("Node not found or has errors: "+m.type),s=new u,s.last_serialization=m,g=s.has_errors=!0);s.id=m.id;this.add(s,!0)}e=0;for(E=d.length;e<E;++e)m=d[e],(s=this.getNodeById(m.id))&&s.configure(m)}this._groups.length=0;if(a.groups)for(e=0;e<a.groups.length;++e)d=new f.LGraphGroup,d.configure(a.groups[e]),this.add(d);this.updateExecutionOrder();this.extra=a.extra||{};if(this.onConfigure)this.onConfigure(a);
this._version++;this.setDirtyCanvas(!0,!0);return g}};c.prototype.load=function(a,b){var d=this;if(a.constructor===File||a.constructor===Blob){var g=new FileReader;g.addEventListener("load",function(a){a=JSON.parse(a.target.result);d.configure(a);b&&b()});g.readAsText(a)}else{var e=new XMLHttpRequest;e.open("GET",a,!0);e.send(null);e.onload=function(a){200!==e.status?console.error("Error loading graph:",e.status,e.response):(a=JSON.parse(e.response),d.configure(a),b&&b())};e.onerror=function(a){console.error("Error loading graph:",
a)}}};c.prototype.onNodeTrace=function(a,b,d){};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.origin_id,this.origin_slot,this.target_id,this.target_slot,this.type]};f.LLink=l;
B.LGraphNode=f.LGraphNode=u;u.prototype._ctor=function(a){this.title=a||"Unnamed";this.size=[f.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={}};u.prototype.configure=function(a){this.graph&&this.graph._version++;
for(var b in a)if("properties"==b)for(var d in a.properties){if(this.properties[d]=a.properties[d],this.onPropertyChanged)this.onPropertyChanged(d,a.properties[d])}else null!=a[b]&&("object"==typeof a[b]?this[b]&&this[b].configure?this[b].configure(a[b]):this[b]=f.cloneObject(a[b],this[b]):this[b]=a[b]);a.title||(this.title=this.constructor.title);if(this.onConnectionsChange){if(this.inputs)for(d=0;d<this.inputs.length;++d){b=this.inputs[d];var g=this.graph?this.graph.links[b.link]:null;this.onConnectionsChange(f.INPUT,
d,!0,g,b)}if(this.outputs)for(d=0;d<this.outputs.length;++d){var e=this.outputs[d];if(e.links)for(b=0;b<e.links.length;++b)g=this.graph?this.graph.links[e.links[b]]:null,this.onConnectionsChange(f.OUTPUT,d,!0,g,e)}}if(this.widgets){for(d=0;d<this.widgets.length;++d)(b=this.widgets[d])&&b.options&&b.options.property&&this.properties[b.options.property]&&(b.value=JSON.parse(JSON.stringify(this.properties[b.options.property])));if(a.widgets_values)for(d=0;d<a.widgets_values.length;++d)this.widgets[d]&&
(this.widgets[d].value=a.widgets_values[d])}if(this.onConfigure)this.onConfigure(a)};u.prototype.serialize=function(){var a={id:this.id,type:this.type,pos:this.pos,size:this.size,flags:f.cloneObject(this.flags),order:this.order,mode:this.mode};if(this.constructor===u&&this.last_serialization)return this.last_serialization;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=f.cloneObject(this.properties));if(this.widgets&&this.serialize_widgets)for(a.widgets_values=[],b=0;b<this.widgets.length;++b)a.widgets_values[b]=this.widgets[b]?this.widgets[b].value:null;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};u.prototype.clone=function(){var a=f.createNode(this.type);if(!a)return null;var b=f.cloneObject(this.serialize());if(b.inputs)for(var d=0;d<b.inputs.length;++d)b.inputs[d].link=null;if(b.outputs)for(d=0;d<b.outputs.length;++d)b.outputs[d].links&&(b.outputs[d].links.length=0);delete b.id;a.configure(b);return a};u.prototype.toString=function(){return JSON.stringify(this.serialize())};u.prototype.getTitle=function(){return this.title||this.constructor.title};u.prototype.setProperty=function(a,
b){this.properties||(this.properties={});if(b!==this.properties[a]){var d=this.properties[a];this.properties[a]=b;this.onPropertyChanged&&!1===this.onPropertyChanged(a,b,d)&&(this.properties[a]=d);if(this.widgets)for(d=0;d<this.widgets.length;++d){var g=this.widgets[d];if(g&&g.options.property==a){g.value=b;break}}}};u.prototype.setOutputData=function(a,b){if(this.outputs&&!(-1==a||a>=this.outputs.length)){var d=this.outputs[a];if(d&&(d._data=b,this.outputs[a].links))for(d=0;d<this.outputs[a].links.length;d++){var g=
this.graph.links[this.outputs[a].links[d]];g&&(g.data=b)}}};u.prototype.setOutputDataType=function(a,b){if(this.outputs&&!(-1==a||a>=this.outputs.length)){var d=this.outputs[a];if(d&&(d.type=b,this.outputs[a].links))for(d=0;d<this.outputs[a].links.length;d++)this.graph.links[this.outputs[a].links[d]].type=b}};u.prototype.getInputData=function(a,b){if(this.inputs&&!(a>=this.inputs.length||null==this.inputs[a].link)){var d=this.graph.links[this.inputs[a].link];if(!d)return null;if(!b)return d.data;
var g=this.graph.getNodeById(d.origin_id);if(!g)return d.data;if(g.updateOutputData)g.updateOutputData(d.origin_slot);else if(g.onExecute)g.onExecute();return d.data}};u.prototype.getInputDataType=function(a){if(!this.inputs||a>=this.inputs.length||null==this.inputs[a].link)return null;a=this.graph.links[this.inputs[a].link];if(!a)return null;var b=this.graph.getNodeById(a.origin_id);return b?(a=b.outputs[a.origin_slot])?a.type:null:a.type};u.prototype.getInputDataByName=function(a,b){var d=this.findInputSlot(a);
return-1==d?null:this.getInputData(d,b)};u.prototype.isInputConnected=function(a){return this.inputs?a<this.inputs.length&&null!=this.inputs[a].link:!1};u.prototype.getInputInfo=function(a){return this.inputs?a<this.inputs.length?this.inputs[a]:null:null};u.prototype.getInputLink=function(a){return this.inputs?a<this.inputs.length?this.graph.links[this.inputs[a].link]:null:null};u.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};u.prototype.getInputOrProperty=function(a){if(!this.inputs||!this.inputs.length)return this.properties?this.properties[a]:null;for(var b=0,d=this.inputs.length;b<d;++b){var g=this.inputs[b];if(a==g.name&&null!=g.link&&(g=this.graph.links[g.link]))return g.data}return this.properties[a]};u.prototype.getOutputData=function(a){return!this.outputs||a>=this.outputs.length?null:this.outputs[a]._data};u.prototype.getOutputInfo=
function(a){return this.outputs?a<this.outputs.length?this.outputs[a]:null:null};u.prototype.isOutputConnected=function(a){return this.outputs?a<this.outputs.length&&this.outputs[a].links&&this.outputs[a].links.length:!1};u.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};u.prototype.getOutputNodes=function(a){if(!this.outputs||0==this.outputs.length||a>=this.outputs.length)return null;
a=this.outputs[a];if(!a.links||0==a.links.length)return null;for(var b=[],d=0;d<a.links.length;d++){var g=this.graph.links[a.links[d]];g&&(g=this.graph.getNodeById(g.target_id))&&b.push(g)}return b};u.prototype.trigger=function(a,b){if(this.outputs&&this.outputs.length){this.graph&&(this.graph._last_trigger_time=f.getTime());for(var d=0;d<this.outputs.length;++d){var g=this.outputs[d];!g||g.type!==f.EVENT||a&&g.name!=a||this.triggerSlot(d,b)}}};u.prototype.triggerSlot=function(a,b,d){if(this.outputs&&
(a=this.outputs[a])&&(a=a.links)&&a.length){this.graph&&(this.graph._last_trigger_time=f.getTime());for(var g=0;g<a.length;++g){var e=a[g];if(null==d||d==e){var E=this.graph.links[a[g]];if(E&&(E._last_time=f.getTime(),e=this.graph.getNodeById(E.target_id)))if(E=e.inputs[E.target_slot],e.mode===f.ON_TRIGGER){if(e.onExecute)e.onExecute(b)}else if(e.onAction)e.onAction(E.name,b)}}}};u.prototype.clearTriggeredSlot=function(a,b){if(this.outputs){var d=this.outputs[a];if(d&&(d=d.links)&&d.length)for(var g=
0;g<d.length;++g){var e=d[g];if(null==b||b==e)if(e=this.graph.links[d[g]])e._last_time=0}}};u.prototype.setSize=function(a){this.size=a;if(this.onResize)this.onResize(this.size)};u.prototype.addProperty=function(a,b,d,g){d={name:a,type:d,default_value:b};if(g)for(var e in g)d[e]=g[e];this.properties_info||(this.properties_info=[]);this.properties_info.push(d);this.properties||(this.properties={});this.properties[a]=b;return d};u.prototype.addOutput=function(a,b,d){a={name:a,type:b,links:null};if(d)for(var g in d)a[g]=
d[g];this.outputs||(this.outputs=[]);this.outputs.push(a);if(this.onOutputAdded)this.onOutputAdded(a);this.setSize(this.computeSize());this.setDirtyCanvas(!0,!0);return a};u.prototype.addOutputs=function(a){for(var b=0;b<a.length;++b){var d=a[b],g={name:d[0],type:d[1],link:null};if(a[2])for(var e in d[2])g[e]=d[2][e];this.outputs||(this.outputs=[]);this.outputs.push(g);if(this.onOutputAdded)this.onOutputAdded(g)}this.setSize(this.computeSize());this.setDirtyCanvas(!0,!0)};u.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 d=this.outputs[b].links,g=0;g<d.length;++g){var e=this.graph.links[d[g]];e&&(e.origin_slot-=1)}this.setSize(this.computeSize());if(this.onOutputRemoved)this.onOutputRemoved(a);this.setDirtyCanvas(!0,!0)};u.prototype.addInput=function(a,b,d){a={name:a,type:b||0,link:null};if(d)for(var g in d)a[g]=d[g];this.inputs||(this.inputs=[]);this.inputs.push(a);
this.setSize(this.computeSize());if(this.onInputAdded)this.onInputAdded(a);this.setDirtyCanvas(!0,!0);return a};u.prototype.addInputs=function(a){for(var b=0;b<a.length;++b){var d=a[b],g={name:d[0],type:d[1],link:null};if(a[2])for(var e in d[2])g[e]=d[2][e];this.inputs||(this.inputs=[]);this.inputs.push(g);if(this.onInputAdded)this.onInputAdded(g)}this.setSize(this.computeSize());this.setDirtyCanvas(!0,!0)};u.prototype.removeInput=function(a){this.disconnectInput(a);for(var b=this.inputs.splice(a,
1),d=a;d<this.inputs.length;++d)if(this.inputs[d]){var g=this.graph.links[this.inputs[d].link];g&&(g.target_slot-=1)}this.setSize(this.computeSize());if(this.onInputRemoved)this.onInputRemoved(a,b[0]);this.setDirtyCanvas(!0,!0)};u.prototype.addConnection=function(a,b,d,g){a={name:a,type:b,pos:d,direction:g,links:null};this.connections.push(a);return a};u.prototype.computeSize=function(a){function b(a){return a?g*a.length*0.6:0}if(this.constructor.size)return this.constructor.size.concat();var d=Math.max(this.inputs?
this.inputs.length:1,this.outputs?this.outputs.length:1);a=a||new Float32Array([0,0]);var d=Math.max(d,1),g=f.NODE_TEXT_SIZE,e=b(this.title),E=0,m=0;if(this.inputs)for(var s=0,y=this.inputs.length;s<y;++s){var c=this.inputs[s],c=c.label||c.name||"",c=b(c);E<c&&(E=c)}if(this.outputs)for(s=0,y=this.outputs.length;s<y;++s)c=this.outputs[s],c=c.label||c.name||"",c=b(c),m<c&&(m=c);a[0]=Math.max(E+m+10,e);a[0]=Math.max(a[0],f.NODE_WIDTH);this.widgets&&this.widgets.length&&(a[0]=Math.max(a[0],1.5*f.NODE_WIDTH));
a[1]=(this.constructor.slot_start_y||0)+d*f.NODE_SLOT_HEIGHT;d=0;if(this.widgets&&this.widgets.length){s=0;for(y=this.widgets.length;s<y;++s)d=this.widgets[s].computeSize?d+(this.widgets[s].computeSize(a[0])[1]+4):d+(f.NODE_WIDGET_HEIGHT+4);d+=8}a[1]=this.widgets_up?Math.max(a[1],d):null!=this.widgets_start_y?Math.max(a[1],d+this.widgets_start_y):a[1]+d;this.constructor.min_height&&a[1]<this.constructor.min_height&&(a[1]=this.constructor.min_height);a[1]+=6;return a};u.prototype.getPropertyInfo=function(a){var b=
null;if(this.properties_info)for(var d=0;d<this.properties_info.length;++d)if(this.properties_info[d].name==a){b=this.properties_info[d];break}this.constructor["@"+a]&&(b=this.constructor["@"+a]);this.constructor.widgets_info&&this.constructor.widgets_info[a]&&(b=this.constructor.widgets_info[a]);!b&&this.onGetPropertyInfo&&(b=this.onGetPropertyInfo(a));b||(b={});b.type||(b.type=typeof this.properties[a]);"combo"==b.widget&&(b.type="enum");return b};u.prototype.addWidget=function(a,b,d,g,e){this.widgets||
(this.widgets=[]);!e&&g&&g.constructor===Object&&(e=g,g=null);e&&e.constructor===String&&(e={property:e});g&&g.constructor===String&&(e||(e={}),e.property=g,g=null);g&&g.constructor!==Function&&(console.warn("addWidget: callback must be a function"),g=null);b={type:a.toLowerCase(),name:b,value:d,callback:g,options:e||{}};void 0!==b.options.y&&(b.y=b.options.y);g||b.options.callback||b.options.property||console.warn("LiteGraph addWidget(...) without a callback or property assigned");if("combo"==a&&
!b.options.values)throw"LiteGraph addWidget('combo',...) requires to pass values in options: { values:['red','blue'] }";this.widgets.push(b);this.setSize(this.computeSize());return b};u.prototype.addCustomWidget=function(a){this.widgets||(this.widgets=[]);this.widgets.push(a);return a};u.prototype.getBounding=function(a){a=a||new Float32Array(4);a[0]=this.pos[0]-4;a[1]=this.pos[1]-f.NODE_TITLE_HEIGHT;a[2]=this.size[0]+4;a[3]=this.size[1]+f.NODE_TITLE_HEIGHT;if(this.onBounding)this.onBounding(a);return a};
u.prototype.isPointInside=function(a,b,d,g){d=d||0;var e=this.graph&&this.graph.isLive()?0:f.NODE_TITLE_HEIGHT;g&&(e=0);if(this.flags&&this.flags.collapsed){if(x(a,b,this.pos[0]-d,this.pos[1]-f.NODE_TITLE_HEIGHT-d,(this._collapsed_width||f.NODE_COLLAPSED_WIDTH)+2*d,f.NODE_TITLE_HEIGHT+2*d))return!0}else if(this.pos[0]-4-d<a&&this.pos[0]+this.size[0]+4+d>a&&this.pos[1]-e-d<b&&this.pos[1]+this.size[1]+d>b)return!0;return!1};u.prototype.getSlotInPosition=function(a,b){var d=new Float32Array(2);if(this.inputs)for(var g=
0,e=this.inputs.length;g<e;++g){var f=this.inputs[g];this.getConnectionPos(!0,g,d);if(x(a,b,d[0]-10,d[1]-5,20,10))return{input:f,slot:g,link_pos:d}}if(this.outputs)for(g=0,e=this.outputs.length;g<e;++g)if(f=this.outputs[g],this.getConnectionPos(!1,g,d),x(a,b,d[0]-10,d[1]-5,20,10))return{output:f,slot:g,link_pos:d};return null};u.prototype.findInputSlot=function(a){if(!this.inputs)return-1;for(var b=0,d=this.inputs.length;b<d;++b)if(a==this.inputs[b].name)return b;return-1};u.prototype.findOutputSlot=
function(a){if(!this.outputs)return-1;for(var b=0,d=this.outputs.length;b<d;++b)if(a==this.outputs[b].name)return b;return-1};u.prototype.connect=function(a,b,d){d=d||0;if(!this.graph)return console.log("Connect: Error, node doesn't 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 f.debug&&console.log("Connect: Error, no slot of name "+a),null}else if(!this.outputs||a>=this.outputs.length)return f.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(d.constructor===String){if(d=b.findInputSlot(d),-1==d)return f.debug&&console.log("Connect: Error, no slot of name "+d),null}else{if(d===f.EVENT)return null;if(!b.inputs||d>=b.inputs.length)return f.debug&&console.log("Connect: Error, slot number not found"),null}var g=!1;null!=b.inputs[d].link&&(this.graph.beforeChange(),b.disconnectInput(d),
g=!0);var e=this.outputs[a];if(b.onConnectInput&&!1===b.onConnectInput(d,e.type,e,this,a))return null;var c=b.inputs[d],m=null;if(!f.isValidConnection(e.type,c.type))return this.setDirtyCanvas(!1,!0),g&&this.graph.connectionChange(this,m),null;g||this.graph.beforeChange();m=new l(++this.graph.last_link_id,c.type,this.id,a,b.id,d);this.graph.links[m.id]=m;null==e.links&&(e.links=[]);e.links.push(m.id);b.inputs[d].link=m.id;this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(f.OUTPUT,
a,!0,m,e);if(b.onConnectionsChange)b.onConnectionsChange(f.INPUT,d,!0,m,c);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(f.INPUT,b,d,this,a),this.graph.onNodeConnectionChange(f.OUTPUT,this,a,b,d));this.setDirtyCanvas(!1,!0);this.graph.afterChange();this.graph.connectionChange(this,m);return m};u.prototype.disconnectOutput=function(a,b){if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return f.debug&&console.log("Connect: Error, no slot of name "+a),
!1}else if(!this.outputs||a>=this.outputs.length)return f.debug&&console.log("Connect: Error, slot number not found"),!1;var d=this.outputs[a];if(!d||!d.links||0==d.links.length)return!1;if(b){b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"Target Node not found";for(var g=0,e=d.links.length;g<e;g++){var c=d.links[g],m=this.graph.links[c];if(m.target_id==b.id){d.links.splice(g,1);var s=b.inputs[m.target_slot];s.link=null;delete this.graph.links[c];this.graph&&this.graph._version++;
if(b.onConnectionsChange)b.onConnectionsChange(f.INPUT,m.target_slot,!1,m,s);if(this.onConnectionsChange)this.onConnectionsChange(f.OUTPUT,a,!1,m,d);if(this.graph&&this.graph.onNodeConnectionChange)this.graph.onNodeConnectionChange(f.OUTPUT,this,a);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(f.OUTPUT,this,a),this.graph.onNodeConnectionChange(f.INPUT,b,m.target_slot));break}}}else{g=0;for(e=d.links.length;g<e;g++)if(c=d.links[g],m=this.graph.links[c]){b=this.graph.getNodeById(m.target_id);
this.graph&&this.graph._version++;if(b){s=b.inputs[m.target_slot];s.link=null;if(b.onConnectionsChange)b.onConnectionsChange(f.INPUT,m.target_slot,!1,m,s);if(this.graph&&this.graph.onNodeConnectionChange)this.graph.onNodeConnectionChange(f.INPUT,b,m.target_slot)}delete this.graph.links[c];if(this.onConnectionsChange)this.onConnectionsChange(f.OUTPUT,a,!1,m,d);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(f.OUTPUT,this,a),this.graph.onNodeConnectionChange(f.INPUT,
b,m.target_slot))}d.links=null}this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this);return!0};u.prototype.disconnectInput=function(a){if(a.constructor===String){if(a=this.findInputSlot(a),-1==a)return f.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.inputs||a>=this.inputs.length)return f.debug&&console.log("Connect: Error, slot number not found"),!1;var b=this.inputs[a];if(!b)return!1;var d=this.inputs[a].link;if(null!=d){this.inputs[a].link=null;var g=this.graph.links[d];
if(g){var e=this.graph.getNodeById(g.origin_id);if(!e)return!1;var c=e.outputs[g.origin_slot];if(!c||!c.links||0==c.links.length)return!1;for(var m=0,s=c.links.length;m<s;m++)if(c.links[m]==d){c.links.splice(m,1);break}delete this.graph.links[d];this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(f.INPUT,a,!1,g,b);if(e.onConnectionsChange)e.onConnectionsChange(f.OUTPUT,m,!1,g,c);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(f.OUTPUT,
e,m),this.graph.onNodeConnectionChange(f.INPUT,this,a))}}this.setDirtyCanvas(!1,!0);this.graph&&this.graph.connectionChange(this);return!0};u.prototype.getConnectionPos=function(a,b,d){d=d||new Float32Array(2);var g=0;a&&this.inputs&&(g=this.inputs.length);!a&&this.outputs&&(g=this.outputs.length);var e=0.5*f.NODE_SLOT_HEIGHT;if(this.flags.collapsed)return b=this._collapsed_width||f.NODE_COLLAPSED_WIDTH,this.horizontal?(d[0]=this.pos[0]+0.5*b,d[1]=a?this.pos[1]-f.NODE_TITLE_HEIGHT:this.pos[1]):(d[0]=
a?this.pos[0]:this.pos[0]+b,d[1]=this.pos[1]-0.5*f.NODE_TITLE_HEIGHT),d;if(a&&-1==b)return d[0]=this.pos[0]+0.5*f.NODE_TITLE_HEIGHT,d[1]=this.pos[1]+0.5*f.NODE_TITLE_HEIGHT,d;if(a&&g>b&&this.inputs[b].pos)return d[0]=this.pos[0]+this.inputs[b].pos[0],d[1]=this.pos[1]+this.inputs[b].pos[1],d;if(!a&&g>b&&this.outputs[b].pos)return d[0]=this.pos[0]+this.outputs[b].pos[0],d[1]=this.pos[1]+this.outputs[b].pos[1],d;if(this.horizontal)return d[0]=this.pos[0]+this.size[0]/g*(b+0.5),d[1]=a?this.pos[1]-f.NODE_TITLE_HEIGHT:
this.pos[1]+this.size[1],d;d[0]=a?this.pos[0]+e:this.pos[0]+this.size[0]+1-e;d[1]=this.pos[1]+(b+0.7)*f.NODE_SLOT_HEIGHT+(this.constructor.slot_start_y||0);return d};u.prototype.alignToGrid=function(){this.pos[0]=f.CANVAS_GRID_SIZE*Math.round(this.pos[0]/f.CANVAS_GRID_SIZE);this.pos[1]=f.CANVAS_GRID_SIZE*Math.round(this.pos[1]/f.CANVAS_GRID_SIZE)};u.prototype.trace=function(a){this.console||(this.console=[]);this.console.push(a);this.console.length>u.MAX_CONSOLE&&this.console.shift();if(this.graph.onNodeTrace)this.graph.onNodeTrace(this,
a)};u.prototype.setDirtyCanvas=function(a,b){this.graph&&this.graph.sendActionToCanvas("setDirty",[a,b])};u.prototype.loadImage=function(a){var b=new Image;b.src=f.node_images_path+a;b.ready=!1;var d=this;b.onload=function(){this.ready=!0;d.setDirtyCanvas(!0)};return b};u.prototype.captureInput=function(a){if(this.graph&&this.graph.list_of_graphcanvas)for(var b=this.graph.list_of_graphcanvas,d=0;d<b.length;++d){var g=b[d];if(a||g.node_capturing_input==this)g.node_capturing_input=a?this:null}};u.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)};u.prototype.pin=function(a){this.graph._version++;this.flags.pinned=void 0===a?!this.flags.pinned:a};u.prototype.localToScreen=function(a,b,d){return[(a+this.pos[0])*d.scale+d.offset[0],(b+this.pos[1])*d.scale+d.offset[1]]};B.LGraphGroup=f.LGraphGroup=r;r.prototype._ctor=function(a){this.title=a||"Group";this.font_size=24;this.color=h.node_colors.pale_blue?
h.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,d){this._pos[0]+=a;this._pos[1]+=b;if(!d)for(d=0;d<this._nodes.length;++d){var g=this._nodes[d];g.pos[0]+=a;g.pos[1]+=b}};r.prototype.recomputeInsideNodes=
function(){this._nodes.length=0;for(var a=this.graph._nodes,b=new Float32Array(4),d=0;d<a.length;++d){var g=a[d];g.getBounding(b);G(this._bounding,b)&&this._nodes.push(g)}};r.prototype.isPointInside=u.prototype.isPointInside;r.prototype.setDirtyCanvas=u.prototype.setDirtyCanvas;f.DragAndScale=t;t.prototype.bindEvents=function(a){this.last_mouse=new Float32Array(2);this._binded_mouse_callback=this.onMouse.bind(this);a.addEventListener("mousedown",this._binded_mouse_callback);a.addEventListener("mousemove",
this._binded_mouse_callback);a.addEventListener("mousewheel",this._binded_mouse_callback,!1);a.addEventListener("wheel",this._binded_mouse_callback,!1)};t.prototype.computeVisibleArea=function(){if(this.element){var a=-this.offset[0],b=-this.offset[1],d=a+this.element.width/this.scale,g=b+this.element.height/this.scale;this.visible_area[0]=a;this.visible_area[1]=b;this.visible_area[2]=d-a;this.visible_area[3]=g-b}else this.visible_area[0]=this.visible_area[1]=this.visible_area[2]=this.visible_area[3]=
0};t.prototype.onMouse=function(a){if(this.enabled){var b=this.element,d=b.getBoundingClientRect(),g=a.clientX-d.left,d=a.clientY-d.top;a.canvasx=g;a.canvasy=d;a.dragging=this.dragging;var e=!1;this.onmouse&&(e=this.onmouse(a));if("mousedown"==a.type)this.dragging=!0,b.removeEventListener("mousemove",this._binded_mouse_callback),document.body.addEventListener("mousemove",this._binded_mouse_callback),document.body.addEventListener("mouseup",this._binded_mouse_callback);else if("mousemove"==a.type)e||
(b=g-this.last_mouse[0],e=d-this.last_mouse[1],this.dragging&&this.mouseDrag(b,e));else if("mouseup"==a.type)this.dragging=!1,document.body.removeEventListener("mousemove",this._binded_mouse_callback),document.body.removeEventListener("mouseup",this._binded_mouse_callback),b.addEventListener("mousemove",this._binded_mouse_callback);else if("mousewheel"==a.type||"wheel"==a.type||"DOMMouseScroll"==a.type)a.eventType="mousewheel",a.wheel="wheel"==a.type?-a.deltaY:null!=a.wheelDeltaY?a.wheelDeltaY:-60*
a.detail,a.delta=a.wheelDelta?a.wheelDelta/40:a.deltaY?-a.deltaY/3:0,this.changeDeltaScale(1+0.05*a.delta);this.last_mouse[0]=g;this.last_mouse[1]=d;a.preventDefault();a.stopPropagation();return!1}};t.prototype.toCanvasContext=function(a){a.scale(this.scale,this.scale);a.translate(this.offset[0],this.offset[1])};t.prototype.convertOffsetToCanvas=function(a){return[(a[0]+this.offset[0])*this.scale,(a[1]+this.offset[1])*this.scale]};t.prototype.convertCanvasToOffset=function(a,b){b=b||[0,0];b[0]=a[0]/
this.scale-this.offset[0];b[1]=a[1]/this.scale-this.offset[1];return b};t.prototype.mouseDrag=function(a,b){this.offset[0]+=a/this.scale;this.offset[1]+=b/this.scale;if(this.onredraw)this.onredraw(this)};t.prototype.changeScale=function(a,b){a<this.min_scale?a=this.min_scale:a>this.max_scale&&(a=this.max_scale);if(a!=this.scale&&this.element){var d=this.element.getBoundingClientRect();if(d){b=b||[0.5*d.width,0.5*d.height];d=this.convertCanvasToOffset(b);this.scale=a;0.01>Math.abs(this.scale-1)&&(this.scale=
1);var g=this.convertCanvasToOffset(b),d=[g[0]-d[0],g[1]-d[1]];this.offset[0]+=d[0];this.offset[1]+=d[1];if(this.onredraw)this.onredraw(this)}}};t.prototype.changeDeltaScale=function(a,b){this.changeScale(this.scale*a,b)};t.prototype.reset=function(){this.scale=1;this.offset[0]=0;this.offset[1]=0};B.LGraphCanvas=f.LGraphCanvas=h;h.DEFAULT_BACKGROUND_IMAGE="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQBJREFUeNrs1rEKwjAUhlETUkj3vP9rdmr1Ysammk2w5wdxuLgcMHyptfawuZX4pJSWZTnfnu/lnIe/jNNxHHGNn//HNbbv+4dr6V+11uF527arU7+u63qfa/bnmh8sWLBgwYJlqRf8MEptXPBXJXa37BSl3ixYsGDBMliwFLyCV/DeLIMFCxYsWLBMwSt4Be/NggXLYMGCBUvBK3iNruC9WbBgwYJlsGApeAWv4L1ZBgsWLFiwYJmCV/AK3psFC5bBggULloJX8BpdwXuzYMGCBctgwVLwCl7Be7MMFixYsGDBsu8FH1FaSmExVfAxBa/gvVmwYMGCZbBg/W4vAQYA5tRF9QYlv/QAAAAASUVORK5CYII=";
h.link_type_colors={"-1":f.EVENT_LINK_COLOR,number:"#AAA",node:"#DCA"};h.gradients={};h.prototype.clear=function(){this.fps=this.render_time=this.last_draw_time=this.frame=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.dragging_canvas=!1;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()};h.prototype.setGraph=function(a,b){this.graph!=a&&(b||this.clear(),!a&&this.graph?this.graph.detachCanvas(this):(a.attachCanvas(this),this._graph_stack&&(this._graph_stack=null),this.setDirty(!0,!0)))};h.prototype.getTopGraph=function(){return this._graph_stack.length?this._graph_stack[0]:this.graph};h.prototype.openSubgraph=function(a){if(!a)throw"graph cannot be null";if(this.graph==
a)throw"graph cannot be the same";this.clear();this.graph&&(this._graph_stack||(this._graph_stack=[]),this._graph_stack.push(this.graph));a.attachCanvas(this);this.checkPanels();this.setDirty(!0,!0)};h.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]))}};h.prototype.getCurrentGraph=
@@ -180,24 +180,24 @@ function(a,b){var d=b._pos;a.fillStyle="black";a.beginPath();a.arc(d[0],d[1],3,0
f.TRANSPARENT_TITLE?q=!1:k==f.AUTOHIDE_TITLE&&m&&(q=!0);w[0]=0;w[1]=q?-e:0;w[2]=d[0]+1;w[3]=q?d[1]+e:d[1];m=b.globalAlpha;b.beginPath();y==f.BOX_SHAPE||s?b.fillRect(w[0],w[1],w[2],w[3]):y==f.ROUND_SHAPE||y==f.CARD_SHAPE?b.roundRect(w[0],w[1],w[2],w[3],this.round_radius,y==f.CARD_SHAPE?0:this.round_radius):y==f.CIRCLE_SHAPE&&b.arc(0.5*d[0],0.5*d[1],0.5*d[0],0,2*Math.PI);b.fill();a.flags.collapsed||(b.shadowColor="transparent",b.fillStyle="rgba(0,0,0,0.2)",b.fillRect(0,-1,w[2],2));b.shadowColor="transparent";
if(a.onDrawBackground)a.onDrawBackground(b,this,this.canvas,this.graph_mouse);if(q||k==f.TRANSPARENT_TITLE){if(a.onDrawTitleBar)a.onDrawTitleBar(b,e,d,this.ds.scale,g);else if(k!=f.TRANSPARENT_TITLE&&(a.constructor.title_color||this.render_title_colored)){q=a.constructor.title_color||g;a.flags.collapsed&&(b.shadowColor=f.DEFAULT_SHADOW_COLOR);if(this.use_gradients){var z=h.gradients[q];z||(z=h.gradients[q]=b.createLinearGradient(0,0,400,0),z.addColorStop(0,q),z.addColorStop(1,"#000"));b.fillStyle=
z}else b.fillStyle=q;b.beginPath();y==f.BOX_SHAPE||s?b.rect(0,-e,d[0]+1,e):y!=f.ROUND_SHAPE&&y!=f.CARD_SHAPE||b.roundRect(0,-e,d[0]+1,e,this.round_radius,a.flags.collapsed?this.round_radius:0);b.fill();b.shadowColor="transparent"}if(a.onDrawTitleBox)a.onDrawTitleBox(b,e,d,this.ds.scale);else y==f.ROUND_SHAPE||y==f.CIRCLE_SHAPE||y==f.CARD_SHAPE?(s&&(b.fillStyle="black",b.beginPath(),b.arc(0.5*e,-0.5*e,6,0,2*Math.PI),b.fill()),b.fillStyle=a.boxcolor||f.NODE_DEFAULT_BOXCOLOR,s?b.fillRect(0.5*e-5,-0.5*
e-5,10,10):(b.beginPath(),b.arc(0.5*e,-0.5*e,5,0,2*Math.PI),b.fill())):(s&&(b.fillStyle="black",b.fillRect(0.5*(e-10)-1,-0.5*(e+10)-1,12,12)),b.fillStyle=a.boxcolor||f.NODE_DEFAULT_BOXCOLOR,b.fillRect(0.5*(e-10),-0.5*(e+10),10,10));b.globalAlpha=m;if(a.onDrawTitleText)a.onDrawTitleText(b,e,d,this.ds.scale,this.title_text_font,c);!s&&(b.font=this.title_text_font,m=String(a.getTitle()))&&(b.fillStyle=c?"white":a.constructor.title_text_color||this.node_title_color,a.flags.collapsed?(b.textAlign="left",
b.measureText(m),b.fillText(m.substr(0,20),e,f.NODE_TITLE_TEXT_Y-e),b.textAlign="left"):(b.textAlign="left",b.fillText(m,e,f.NODE_TITLE_TEXT_Y-e)));a.flags.collapsed||!a.subgraph||a.skip_subgraph_button||(m=f.NODE_TITLE_HEIGHT,q=a.size[0]-m,z=f.isInsideRectangle(this.graph_mouse[0]-a.pos[0],this.graph_mouse[1]-a.pos[1],q+2,-m+2,m-4,m-4),b.fillStyle=z?"#888":"#555",y==f.BOX_SHAPE||s?b.fillRect(q+2,-m+2,m-4,m-4):(b.beginPath(),b.roundRect(q+2,-m+2,m-4,m-4,4),b.fill()),b.fillStyle="#333",b.beginPath(),
b.moveTo(q+0.2*m,0.6*-m),b.lineTo(q+0.8*m,0.6*-m),b.lineTo(q+0.5*m,0.3*-m),b.fill());if(a.onDrawTitle)a.onDrawTitle(b)}if(c){if(a.onBounding)a.onBounding(w);k==f.TRANSPARENT_TITLE&&(w[1]-=e,w[3]+=e);b.lineWidth=1;b.globalAlpha=0.8;b.beginPath();y==f.BOX_SHAPE?b.rect(-6+w[0],-6+w[1],12+w[2],12+w[3]):y==f.ROUND_SHAPE||y==f.CARD_SHAPE&&a.flags.collapsed?b.roundRect(-6+w[0],-6+w[1],12+w[2],12+w[3],2*this.round_radius):y==f.CARD_SHAPE?b.roundRect(-6+w[0],-6+w[1],12+w[2],12+w[3],2*this.round_radius,2):
y==f.CIRCLE_SHAPE&&b.arc(0.5*d[0],0.5*d[1],0.5*d[0]+6,0,2*Math.PI);b.strokeStyle="#FFF";b.stroke();b.strokeStyle=g;b.globalAlpha=1}};var L=new Float32Array(4),n=new Float32Array(4),v=new Float32Array(2),k=new Float32Array(2);h.prototype.drawConnections=function(a){var b=f.getTime(),d=this.visible_area;L[0]=d[0]-20;L[1]=d[1]-20;L[2]=d[2]+40;L[3]=d[3]+40;a.lineWidth=this.connections_width;a.fillStyle="#AAA";a.strokeStyle="#AAA";a.globalAlpha=this.editor_alpha;for(var d=this.graph._nodes,g=0,e=d.length;g<
e;++g){var c=d[g];if(c.inputs&&c.inputs.length)for(var m=0;m<c.inputs.length;++m){var s=c.inputs[m];if(s&&null!=s.link&&(s=this.graph.links[s.link])){var y=this.graph.getNodeById(s.origin_id);if(null!=y){var q=s.origin_slot,h=null,h=-1==q?[y.pos[0]+10,y.pos[1]+10]:y.getConnectionPos(!1,q,v),z=c.getConnectionPos(!0,m,k);n[0]=h[0];n[1]=h[1];n[2]=z[0]-h[0];n[3]=z[1]-h[1];0>n[2]&&(n[0]+=n[2],n[2]=Math.abs(n[2]));0>n[3]&&(n[1]+=n[3],n[3]=Math.abs(n[3]));if(G(n,L)){var F=y.outputs[q],q=c.inputs[m];if(F&&
q&&(y=F.dir||(y.horizontal?f.DOWN:f.RIGHT),q=q.dir||(c.horizontal?f.UP:f.LEFT),this.renderLink(a,h,z,s,!1,0,null,y,q),s&&s._last_time&&1E3>b-s._last_time)){var F=2-0.002*(b-s._last_time),r=a.globalAlpha;a.globalAlpha=r*F;this.renderLink(a,h,z,s,!0,F,"white",y,q);a.globalAlpha=r}}}}}}a.globalAlpha=1};h.prototype.renderLink=function(a,b,d,g,e,c,m,s,y,k){g&&this.visible_links.push(g);!m&&g&&(m=g.color||h.link_type_colors[g.type]);m||(m=this.default_link_color);null!=g&&this.highlighted_links[g.id]&&
(m="#FFF");s=s||f.RIGHT;y=y||f.LEFT;var q=C(b,d);this.render_connections_border&&0.6<this.ds.scale&&(a.lineWidth=this.connections_width+4);a.lineJoin="round";k=k||1;1<k&&(a.lineWidth=0.5);a.beginPath();for(var z=0;z<k;z+=1){var F=5*(z-0.5*(k-1));if(this.links_render_mode==f.SPLINE_LINK){a.moveTo(b[0],b[1]+F);var n=0,J=0,I=0,v=0;switch(s){case f.LEFT:n=-0.25*q;break;case f.RIGHT:n=0.25*q;break;case f.UP:J=-0.25*q;break;case f.DOWN:J=0.25*q}switch(y){case f.LEFT:I=-0.25*q;break;case f.RIGHT:I=0.25*
q;break;case f.UP:v=-0.25*q;break;case f.DOWN:v=0.25*q}a.bezierCurveTo(b[0]+n,b[1]+J+F,d[0]+I,d[1]+v+F,d[0],d[1]+F)}else if(this.links_render_mode==f.LINEAR_LINK){a.moveTo(b[0],b[1]+F);v=I=J=n=0;switch(s){case f.LEFT:n=-1;break;case f.RIGHT:n=1;break;case f.UP:J=-1;break;case f.DOWN:J=1}switch(y){case f.LEFT:I=-1;break;case f.RIGHT:I=1;break;case f.UP:v=-1;break;case f.DOWN:v=1}a.lineTo(b[0]+15*n,b[1]+15*J+F);a.lineTo(d[0]+15*I,d[1]+15*v+F);a.lineTo(d[0],d[1]+F)}else if(this.links_render_mode==f.STRAIGHT_LINK)a.moveTo(b[0],
b[1]),F=b[0],n=b[1],J=d[0],I=d[1],s==f.RIGHT?F+=10:n+=10,y==f.LEFT?J-=10:I-=10,a.lineTo(F,n),a.lineTo(0.5*(F+J),n),a.lineTo(0.5*(F+J),I),a.lineTo(J,I),a.lineTo(d[0],d[1]);else return}this.render_connections_border&&0.6<this.ds.scale&&!e&&(a.strokeStyle="rgba(0,0,0,0.5)",a.stroke());a.lineWidth=this.connections_width;a.fillStyle=a.strokeStyle=m;a.stroke();e=this.computeConnectionPoint(b,d,0.5,s,y);g&&g._pos&&(g._pos[0]=e[0],g._pos[1]=e[1]);0.6<=this.ds.scale&&this.highquality_render&&y!=f.CENTER&&
(this.render_connection_arrows&&(z=this.computeConnectionPoint(b,d,0.25,s,y),g=this.computeConnectionPoint(b,d,0.26,s,y),k=this.computeConnectionPoint(b,d,0.75,s,y),q=this.computeConnectionPoint(b,d,0.76,s,y),n=F=0,this.render_curved_connections?(F=-Math.atan2(g[0]-z[0],g[1]-z[1]),n=-Math.atan2(q[0]-k[0],q[1]-k[1])):n=F=d[1]>b[1]?0:Math.PI,a.save(),a.translate(z[0],z[1]),a.rotate(F),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore(),a.save(),a.translate(k[0],k[1]),a.rotate(n),
a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore()),a.beginPath(),a.arc(e[0],e[1],5,0,2*Math.PI),a.fill());if(c)for(a.fillStyle=m,z=0;5>z;++z)c=(0.001*f.getTime()+0.2*z)%1,e=this.computeConnectionPoint(b,d,c,s,y),a.beginPath(),a.arc(e[0],e[1],5,0,2*Math.PI),a.fill()};h.prototype.computeConnectionPoint=function(a,b,d,g,e){g=g||f.RIGHT;e=e||f.LEFT;var c=C(a,b),m=[a[0],a[1]],s=[b[0],b[1]];switch(g){case f.LEFT:m[0]+=-0.25*c;break;case f.RIGHT:m[0]+=0.25*c;break;case f.UP:m[1]+=
-0.25*c;break;case f.DOWN:m[1]+=0.25*c}switch(e){case f.LEFT:s[0]+=-0.25*c;break;case f.RIGHT:s[0]+=0.25*c;break;case f.UP:s[1]+=-0.25*c;break;case f.DOWN:s[1]+=0.25*c}g=(1-d)*(1-d)*(1-d);e=3*(1-d)*(1-d)*d;c=3*(1-d)*d*d;d*=d*d;return[g*a[0]+e*m[0]+c*s[0]+d*b[0],g*a[1]+e*m[1]+c*s[1]+d*b[1]]};h.prototype.drawExecutionOrder=function(a){a.shadowColor="transparent";a.globalAlpha=0.25;a.textAlign="center";a.strokeStyle="white";a.globalAlpha=0.75;for(var b=this.visible_nodes,d=0;d<b.length;++d){var g=b[d];
a.fillStyle="black";a.fillRect(g.pos[0]-f.NODE_TITLE_HEIGHT,g.pos[1]-f.NODE_TITLE_HEIGHT,f.NODE_TITLE_HEIGHT,f.NODE_TITLE_HEIGHT);0==g.order&&a.strokeRect(g.pos[0]-f.NODE_TITLE_HEIGHT+0.5,g.pos[1]-f.NODE_TITLE_HEIGHT+0.5,f.NODE_TITLE_HEIGHT,f.NODE_TITLE_HEIGHT);a.fillStyle="#FFF";a.fillText(g.order,g.pos[0]+-0.5*f.NODE_TITLE_HEIGHT,g.pos[1]-6)}a.globalAlpha=1};h.prototype.drawNodeWidgets=function(a,b,d,g){if(!a.widgets||!a.widgets.length)return 0;var e=a.size[0],c=a.widgets;b+=2;var m=f.NODE_WIDGET_HEIGHT,
s=0.5<this.ds.scale;d.save();d.globalAlpha=this.editor_alpha;for(var y=f.WIDGET_OUTLINE_COLOR,k=f.WIDGET_BGCOLOR,q=f.WIDGET_TEXT_COLOR,z=f.WIDGET_SECONDARY_TEXT_COLOR,F=0;F<c.length;++F){var n=c[F],J=b;n.y&&(J=n.y);n.last_y=J;d.strokeStyle=y;d.fillStyle="#222";d.textAlign="left";n.disabled&&(d.globalAlpha*=0.5);var I=n.width||e;switch(n.type){case "button":n.clicked&&(d.fillStyle="#AAA",n.clicked=!1,this.dirty_canvas=!0);d.fillRect(15,J,I-30,m);s&&!n.disabled&&d.strokeRect(15,J,I-30,m);s&&(d.textAlign=
"center",d.fillStyle=q,d.fillText(n.name,0.5*I,J+0.7*m));break;case "toggle":d.textAlign="left";d.strokeStyle=y;d.fillStyle=k;d.beginPath();s?d.roundRect(15,b,I-30,m,0.5*m):d.rect(15,b,I-30,m);d.fill();s&&!n.disabled&&d.stroke();d.fillStyle=n.value?"#89A":"#333";d.beginPath();d.arc(I-30,J+0.5*m,0.36*m,0,2*Math.PI);d.fill();s&&(d.fillStyle=z,null!=n.name&&d.fillText(n.name,30,J+0.7*m),d.fillStyle=n.value?q:z,d.textAlign="right",d.fillText(n.value?n.options.on||"true":n.options.off||"false",I-40,J+
0.7*m));break;case "slider":d.fillStyle=k;d.fillRect(15,J,I-30,m);var h=n.options.max-n.options.min,v=(n.value-n.options.min)/h;d.fillStyle=g==n?"#89A":"#678";d.fillRect(15,J,v*(I-30),m);s&&!n.disabled&&d.strokeRect(15,J,I-30,m);n.marker&&(h=(n.marker-n.options.min)/h,d.fillStyle="#AA9",d.fillRect(15+h*(I-30),J,2,m));s&&(d.textAlign="center",d.fillStyle=q,d.fillText(n.name+" "+Number(n.value).toFixed(3),0.5*I,J+0.7*m));break;case "number":case "combo":d.textAlign="left";d.strokeStyle=y;d.fillStyle=
k;d.beginPath();s?d.roundRect(15,b,I-30,m,0.5*m):d.rect(15,b,I-30,m);d.fill();s&&(n.disabled||d.stroke(),d.fillStyle=q,n.disabled||(d.beginPath(),d.moveTo(31,b+5),d.lineTo(21,b+0.5*m),d.lineTo(31,b+m-5),d.fill(),d.beginPath(),d.moveTo(I-15-16,b+5),d.lineTo(I-15-6,b+0.5*m),d.lineTo(I-15-16,b+m-5),d.fill()),d.fillStyle=z,d.fillText(n.name,35,J+0.7*m),d.fillStyle=q,d.textAlign="right","number"==n.type?d.fillText(Number(n.value).toFixed(void 0!==n.options.precision?n.options.precision:3),I-30-20,J+0.7*
m):(h=n.value,n.options.values&&(v=n.options.values,v.constructor===Function&&(v=v()),v&&v.constructor!==Array&&(h=v[n.value])),d.fillText(h,I-30-20,J+0.7*m)));break;case "string":case "text":d.textAlign="left";d.strokeStyle=y;d.fillStyle=k;d.beginPath();s?d.roundRect(15,b,I-30,m,0.5*m):d.rect(15,b,I-30,m);d.fill();s&&(d.save(),d.beginPath(),d.rect(15,b,I-30,m),d.clip(),d.stroke(),d.fillStyle=z,null!=n.name&&d.fillText(n.name,30,J+0.7*m),d.fillStyle=q,d.textAlign="right",d.fillText(String(n.value).substr(0,
e-5,10,10):(b.beginPath(),b.arc(0.5*e,-0.5*e,5,0,2*Math.PI),b.fill())):(s&&(b.fillStyle="black",b.fillRect(0.5*(e-10)-1,-0.5*(e+10)-1,12,12)),b.fillStyle=a.boxcolor||f.NODE_DEFAULT_BOXCOLOR,b.fillRect(0.5*(e-10),-0.5*(e+10),10,10));b.globalAlpha=m;if(a.onDrawTitleText)a.onDrawTitleText(b,e,d,this.ds.scale,this.title_text_font,c);!s&&(b.font=this.title_text_font,m=String(a.getTitle()))&&(b.fillStyle=c?f.NODE_SELECTED_TITLE_COLOR:a.constructor.title_text_color||this.node_title_color,a.flags.collapsed?
(b.textAlign="left",b.measureText(m),b.fillText(m.substr(0,20),e,f.NODE_TITLE_TEXT_Y-e),b.textAlign="left"):(b.textAlign="left",b.fillText(m,e,f.NODE_TITLE_TEXT_Y-e)));a.flags.collapsed||!a.subgraph||a.skip_subgraph_button||(m=f.NODE_TITLE_HEIGHT,q=a.size[0]-m,z=f.isInsideRectangle(this.graph_mouse[0]-a.pos[0],this.graph_mouse[1]-a.pos[1],q+2,-m+2,m-4,m-4),b.fillStyle=z?"#888":"#555",y==f.BOX_SHAPE||s?b.fillRect(q+2,-m+2,m-4,m-4):(b.beginPath(),b.roundRect(q+2,-m+2,m-4,m-4,4),b.fill()),b.fillStyle=
"#333",b.beginPath(),b.moveTo(q+0.2*m,0.6*-m),b.lineTo(q+0.8*m,0.6*-m),b.lineTo(q+0.5*m,0.3*-m),b.fill());if(a.onDrawTitle)a.onDrawTitle(b)}if(c){if(a.onBounding)a.onBounding(w);k==f.TRANSPARENT_TITLE&&(w[1]-=e,w[3]+=e);b.lineWidth=1;b.globalAlpha=0.8;b.beginPath();y==f.BOX_SHAPE?b.rect(-6+w[0],-6+w[1],12+w[2],12+w[3]):y==f.ROUND_SHAPE||y==f.CARD_SHAPE&&a.flags.collapsed?b.roundRect(-6+w[0],-6+w[1],12+w[2],12+w[3],2*this.round_radius):y==f.CARD_SHAPE?b.roundRect(-6+w[0],-6+w[1],12+w[2],12+w[3],2*
this.round_radius,2):y==f.CIRCLE_SHAPE&&b.arc(0.5*d[0],0.5*d[1],0.5*d[0]+6,0,2*Math.PI);b.strokeStyle=f.NODE_BOX_OUTLINE_COLOR;b.stroke();b.strokeStyle=g;b.globalAlpha=1}};var L=new Float32Array(4),n=new Float32Array(4),v=new Float32Array(2),k=new Float32Array(2);h.prototype.drawConnections=function(a){var b=f.getTime(),d=this.visible_area;L[0]=d[0]-20;L[1]=d[1]-20;L[2]=d[2]+40;L[3]=d[3]+40;a.lineWidth=this.connections_width;a.fillStyle="#AAA";a.strokeStyle="#AAA";a.globalAlpha=this.editor_alpha;
for(var d=this.graph._nodes,g=0,e=d.length;g<e;++g){var c=d[g];if(c.inputs&&c.inputs.length)for(var m=0;m<c.inputs.length;++m){var s=c.inputs[m];if(s&&null!=s.link&&(s=this.graph.links[s.link])){var y=this.graph.getNodeById(s.origin_id);if(null!=y){var q=s.origin_slot,h=null,h=-1==q?[y.pos[0]+10,y.pos[1]+10]:y.getConnectionPos(!1,q,v),z=c.getConnectionPos(!0,m,k);n[0]=h[0];n[1]=h[1];n[2]=z[0]-h[0];n[3]=z[1]-h[1];0>n[2]&&(n[0]+=n[2],n[2]=Math.abs(n[2]));0>n[3]&&(n[1]+=n[3],n[3]=Math.abs(n[3]));if(G(n,
L)){var F=y.outputs[q],q=c.inputs[m];if(F&&q&&(y=F.dir||(y.horizontal?f.DOWN:f.RIGHT),q=q.dir||(c.horizontal?f.UP:f.LEFT),this.renderLink(a,h,z,s,!1,0,null,y,q),s&&s._last_time&&1E3>b-s._last_time)){var F=2-0.002*(b-s._last_time),r=a.globalAlpha;a.globalAlpha=r*F;this.renderLink(a,h,z,s,!0,F,"white",y,q);a.globalAlpha=r}}}}}}a.globalAlpha=1};h.prototype.renderLink=function(a,b,d,g,e,c,m,s,y,k){g&&this.visible_links.push(g);!m&&g&&(m=g.color||h.link_type_colors[g.type]);m||(m=this.default_link_color);
null!=g&&this.highlighted_links[g.id]&&(m="#FFF");s=s||f.RIGHT;y=y||f.LEFT;var q=C(b,d);this.render_connections_border&&0.6<this.ds.scale&&(a.lineWidth=this.connections_width+4);a.lineJoin="round";k=k||1;1<k&&(a.lineWidth=0.5);a.beginPath();for(var z=0;z<k;z+=1){var F=5*(z-0.5*(k-1));if(this.links_render_mode==f.SPLINE_LINK){a.moveTo(b[0],b[1]+F);var n=0,J=0,I=0,v=0;switch(s){case f.LEFT:n=-0.25*q;break;case f.RIGHT:n=0.25*q;break;case f.UP:J=-0.25*q;break;case f.DOWN:J=0.25*q}switch(y){case f.LEFT:I=
-0.25*q;break;case f.RIGHT:I=0.25*q;break;case f.UP:v=-0.25*q;break;case f.DOWN:v=0.25*q}a.bezierCurveTo(b[0]+n,b[1]+J+F,d[0]+I,d[1]+v+F,d[0],d[1]+F)}else if(this.links_render_mode==f.LINEAR_LINK){a.moveTo(b[0],b[1]+F);v=I=J=n=0;switch(s){case f.LEFT:n=-1;break;case f.RIGHT:n=1;break;case f.UP:J=-1;break;case f.DOWN:J=1}switch(y){case f.LEFT:I=-1;break;case f.RIGHT:I=1;break;case f.UP:v=-1;break;case f.DOWN:v=1}a.lineTo(b[0]+15*n,b[1]+15*J+F);a.lineTo(d[0]+15*I,d[1]+15*v+F);a.lineTo(d[0],d[1]+F)}else if(this.links_render_mode==
f.STRAIGHT_LINK)a.moveTo(b[0],b[1]),F=b[0],n=b[1],J=d[0],I=d[1],s==f.RIGHT?F+=10:n+=10,y==f.LEFT?J-=10:I-=10,a.lineTo(F,n),a.lineTo(0.5*(F+J),n),a.lineTo(0.5*(F+J),I),a.lineTo(J,I),a.lineTo(d[0],d[1]);else return}this.render_connections_border&&0.6<this.ds.scale&&!e&&(a.strokeStyle="rgba(0,0,0,0.5)",a.stroke());a.lineWidth=this.connections_width;a.fillStyle=a.strokeStyle=m;a.stroke();e=this.computeConnectionPoint(b,d,0.5,s,y);g&&g._pos&&(g._pos[0]=e[0],g._pos[1]=e[1]);0.6<=this.ds.scale&&this.highquality_render&&
y!=f.CENTER&&(this.render_connection_arrows&&(z=this.computeConnectionPoint(b,d,0.25,s,y),g=this.computeConnectionPoint(b,d,0.26,s,y),k=this.computeConnectionPoint(b,d,0.75,s,y),q=this.computeConnectionPoint(b,d,0.76,s,y),n=F=0,this.render_curved_connections?(F=-Math.atan2(g[0]-z[0],g[1]-z[1]),n=-Math.atan2(q[0]-k[0],q[1]-k[1])):n=F=d[1]>b[1]?0:Math.PI,a.save(),a.translate(z[0],z[1]),a.rotate(F),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore(),a.save(),a.translate(k[0],
k[1]),a.rotate(n),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore()),a.beginPath(),a.arc(e[0],e[1],5,0,2*Math.PI),a.fill());if(c)for(a.fillStyle=m,z=0;5>z;++z)c=(0.001*f.getTime()+0.2*z)%1,e=this.computeConnectionPoint(b,d,c,s,y),a.beginPath(),a.arc(e[0],e[1],5,0,2*Math.PI),a.fill()};h.prototype.computeConnectionPoint=function(a,b,d,g,e){g=g||f.RIGHT;e=e||f.LEFT;var c=C(a,b),m=[a[0],a[1]],s=[b[0],b[1]];switch(g){case f.LEFT:m[0]+=-0.25*c;break;case f.RIGHT:m[0]+=0.25*
c;break;case f.UP:m[1]+=-0.25*c;break;case f.DOWN:m[1]+=0.25*c}switch(e){case f.LEFT:s[0]+=-0.25*c;break;case f.RIGHT:s[0]+=0.25*c;break;case f.UP:s[1]+=-0.25*c;break;case f.DOWN:s[1]+=0.25*c}g=(1-d)*(1-d)*(1-d);e=3*(1-d)*(1-d)*d;c=3*(1-d)*d*d;d*=d*d;return[g*a[0]+e*m[0]+c*s[0]+d*b[0],g*a[1]+e*m[1]+c*s[1]+d*b[1]]};h.prototype.drawExecutionOrder=function(a){a.shadowColor="transparent";a.globalAlpha=0.25;a.textAlign="center";a.strokeStyle="white";a.globalAlpha=0.75;for(var b=this.visible_nodes,d=0;d<
b.length;++d){var g=b[d];a.fillStyle="black";a.fillRect(g.pos[0]-f.NODE_TITLE_HEIGHT,g.pos[1]-f.NODE_TITLE_HEIGHT,f.NODE_TITLE_HEIGHT,f.NODE_TITLE_HEIGHT);0==g.order&&a.strokeRect(g.pos[0]-f.NODE_TITLE_HEIGHT+0.5,g.pos[1]-f.NODE_TITLE_HEIGHT+0.5,f.NODE_TITLE_HEIGHT,f.NODE_TITLE_HEIGHT);a.fillStyle="#FFF";a.fillText(g.order,g.pos[0]+-0.5*f.NODE_TITLE_HEIGHT,g.pos[1]-6)}a.globalAlpha=1};h.prototype.drawNodeWidgets=function(a,b,d,g){if(!a.widgets||!a.widgets.length)return 0;var e=a.size[0],c=a.widgets;
b+=2;var m=f.NODE_WIDGET_HEIGHT,s=0.5<this.ds.scale;d.save();d.globalAlpha=this.editor_alpha;for(var y=f.WIDGET_OUTLINE_COLOR,k=f.WIDGET_BGCOLOR,q=f.WIDGET_TEXT_COLOR,z=f.WIDGET_SECONDARY_TEXT_COLOR,F=0;F<c.length;++F){var n=c[F],J=b;n.y&&(J=n.y);n.last_y=J;d.strokeStyle=y;d.fillStyle="#222";d.textAlign="left";n.disabled&&(d.globalAlpha*=0.5);var I=n.width||e;switch(n.type){case "button":n.clicked&&(d.fillStyle="#AAA",n.clicked=!1,this.dirty_canvas=!0);d.fillRect(15,J,I-30,m);s&&!n.disabled&&d.strokeRect(15,
J,I-30,m);s&&(d.textAlign="center",d.fillStyle=q,d.fillText(n.name,0.5*I,J+0.7*m));break;case "toggle":d.textAlign="left";d.strokeStyle=y;d.fillStyle=k;d.beginPath();s?d.roundRect(15,b,I-30,m,0.5*m):d.rect(15,b,I-30,m);d.fill();s&&!n.disabled&&d.stroke();d.fillStyle=n.value?"#89A":"#333";d.beginPath();d.arc(I-30,J+0.5*m,0.36*m,0,2*Math.PI);d.fill();s&&(d.fillStyle=z,null!=n.name&&d.fillText(n.name,30,J+0.7*m),d.fillStyle=n.value?q:z,d.textAlign="right",d.fillText(n.value?n.options.on||"true":n.options.off||
"false",I-40,J+0.7*m));break;case "slider":d.fillStyle=k;d.fillRect(15,J,I-30,m);var h=n.options.max-n.options.min,v=(n.value-n.options.min)/h;d.fillStyle=g==n?"#89A":"#678";d.fillRect(15,J,v*(I-30),m);s&&!n.disabled&&d.strokeRect(15,J,I-30,m);n.marker&&(h=(n.marker-n.options.min)/h,d.fillStyle="#AA9",d.fillRect(15+h*(I-30),J,2,m));s&&(d.textAlign="center",d.fillStyle=q,d.fillText(n.name+" "+Number(n.value).toFixed(3),0.5*I,J+0.7*m));break;case "number":case "combo":d.textAlign="left";d.strokeStyle=
y;d.fillStyle=k;d.beginPath();s?d.roundRect(15,b,I-30,m,0.5*m):d.rect(15,b,I-30,m);d.fill();s&&(n.disabled||d.stroke(),d.fillStyle=q,n.disabled||(d.beginPath(),d.moveTo(31,b+5),d.lineTo(21,b+0.5*m),d.lineTo(31,b+m-5),d.fill(),d.beginPath(),d.moveTo(I-15-16,b+5),d.lineTo(I-15-6,b+0.5*m),d.lineTo(I-15-16,b+m-5),d.fill()),d.fillStyle=z,d.fillText(n.name,35,J+0.7*m),d.fillStyle=q,d.textAlign="right","number"==n.type?d.fillText(Number(n.value).toFixed(void 0!==n.options.precision?n.options.precision:3),
I-30-20,J+0.7*m):(h=n.value,n.options.values&&(v=n.options.values,v.constructor===Function&&(v=v()),v&&v.constructor!==Array&&(h=v[n.value])),d.fillText(h,I-30-20,J+0.7*m)));break;case "string":case "text":d.textAlign="left";d.strokeStyle=y;d.fillStyle=k;d.beginPath();s?d.roundRect(15,b,I-30,m,0.5*m):d.rect(15,b,I-30,m);d.fill();s&&(d.save(),d.beginPath(),d.rect(15,b,I-30,m),d.clip(),d.stroke(),d.fillStyle=z,null!=n.name&&d.fillText(n.name,30,J+0.7*m),d.fillStyle=q,d.textAlign="right",d.fillText(String(n.value).substr(0,
30),I-30,J+0.7*m),d.restore());break;default:n.draw&&n.draw(d,a,I,J,m)}b+=(n.computeSize?n.computeSize(I)[1]:m)+4;d.globalAlpha=this.editor_alpha}d.restore();d.textAlign="left"};h.prototype.processNodeWidgets=function(a,b,d,g){function e(e,g){e.value=g;e.options&&e.options.property&&void 0!==a.properties[e.options.property]&&a.setProperty(e.options.property,g);e.callback&&e.callback(e.value,y,a,b,d)}if(!a.widgets||!a.widgets.length)return null;for(var c=b[0]-a.pos[0],m=b[1]-a.pos[1],s=a.size[0],y=
this,k=this.getCanvasWindow(),q=0;q<a.widgets.length;++q){var n=a.widgets[q];if(n&&!n.disabled){var F=n.computeSize?n.computeSize(s)[1]:f.NODE_WIDGET_HEIGHT,h=n.width||s;if(n==g||!(6>c||c>h-12||m<n.last_y||m>n.last_y+F)){g=n.value;switch(n.type){case "button":if("mousemove"===d.type)break;n.callback&&setTimeout(function(){n.callback(n,y,a,b,d)},20);this.dirty_canvas=n.clicked=!0;break;case "slider":k=Math.clamp((c-10)/(h-20),0,1);n.value=n.options.min+(n.options.max-n.options.min)*k;n.callback&&setTimeout(function(){e(n,
n.value)},20);this.dirty_canvas=!0;break;case "number":case "combo":g=n.value;if("mousemove"==d.type&&"number"==n.type)n.value+=0.1*d.deltaX*(n.options.step||1),null!=n.options.min&&n.value<n.options.min&&(n.value=n.options.min),null!=n.options.max&&n.value>n.options.max&&(n.value=n.options.max);else if("mousedown"==d.type){var J=n.options.values;J&&J.constructor===Function&&(J=n.options.values(n,a));var I=null;"number"!=n.type&&(I=J.constructor===Array?J:Object.keys(J));c=40>c?-1:c>h-40?1:0;if("number"==
@@ -213,60 +213,60 @@ new f.ContextMenu(b,{event:d,callback:c,parentMenu:g},y);return!1}};h.onMenuColl
b.length;y++){var k=b[y];if(k){var n=k[0];k[2]&&k[2].label&&(n=k[2].label);n={content:n,value:k};k[1]==f.ACTION&&(n.className="event");s.push(n)}else s.push(null)}this.onMenuNodeInputs&&(s=this.onMenuNodeInputs(s));if(s.length)return new f.ContextMenu(s,{event:d,callback:c,parentMenu:g,node:e},a),!1;console.log("no input entries")}};h.showMenuNodeOptionalOutputs=function(a,b,d,g,e){function c(a,b,d){if(e&&(a.callback&&a.callback.call(m,e,a,b,d),a.value))if(d=a.value[1],!d||d.constructor!==Object&&
d.constructor!==Array)e.graph.beforeChange(),e.addOutput(a.value[0],a.value[1],a.value[2]),e.setDirtyCanvas(!0,!0),e.graph.afterChange();else{a=[];for(var s in d)a.push({content:s,value:d[s]});new f.ContextMenu(a,{event:b,callback:c,parentMenu:g,node:e});return!1}}if(e){var m=this;a=h.active_canvas.getCanvasWindow();b=e.optional_outputs;e.onGetOutputs&&(b=e.onGetOutputs());var s=[];if(b)for(var y=0;y<b.length;y++){var k=b[y];if(!k)s.push(null);else if(!e.flags||!e.flags.skip_repeated_outputs||-1==
e.findOutputSlot(k[0])){var n=k[0];k[2]&&k[2].label&&(n=k[2].label);n={content:n,value:k};k[1]==f.EVENT&&(n.className="event");s.push(n)}}this.onMenuNodeOutputs&&(s=this.onMenuNodeOutputs(s));if(s.length)return new f.ContextMenu(s,{event:d,callback:c,parentMenu:g,node:e},a),!1}};h.onShowMenuNodeProperties=function(a,b,d,g,e){function c(a,b,d,g){e&&(b=this.getBoundingClientRect(),m.showEditPropertyValue(e,a.value,{position:[b.left,b.top]}))}if(e&&e.properties){var m=h.active_canvas;b=m.getCanvasWindow();
var s=[],k;for(k in e.properties){a=void 0!==e.properties[k]?e.properties[k]:" ";"object"==typeof a&&(a=JSON.stringify(a));var n=e.getPropertyInfo(k);if("enum"==n.type||"combo"==n.type)a=h.getPropertyPrintableValue(a,n.values);a=h.decodeHTML(a);s.push({content:"<span class='property_name'>"+k+"</span><span class='property_value'>"+a+"</span>",value:k})}if(s.length)return new f.ContextMenu(s,{event:d,callback:c,parentMenu:g,allow_html:!0,node:e},b),!1}};h.decodeHTML=function(a){var b=document.createElement("div");
b.innerText=a;return b.innerHTML};h.onResizeNode=function(a,b,d,g,e){if(e){e.size=e.computeSize();if(e.onResize)e.onResize(e.size);e.setDirtyCanvas(!0,!0)}};h.prototype.showLinkMenu=function(a,b){var d=this;console.log(a);var g=new f.ContextMenu(["Add Node",null,"Delete"],{event:b,title:null!=a.data?a.data.constructor.name:null,callback:function(b,f,c){switch(b){case "Add Node":h.onMenuAdd(null,null,c,g,function(b){console.log("node autoconnect");var e=d.graph.getNodeById(a.origin_id),g=d.graph.getNodeById(a.target_id);
b.inputs&&b.inputs.length&&b.outputs&&b.outputs.length&&e.outputs[a.origin_slot].type==b.inputs[0].type&&b.outputs[0].type==g.inputs[0].type&&(e.connect(a.origin_slot,b,0),b.connect(0,g,a.target_slot),b.pos[0]-=0.5*b.size[0])});break;case "Delete":d.graph.removeLink(a.id)}}});return!1};h.onShowPropertyEditor=function(a,b,d,g,e){function f(){var b=k.value;"Number"==a.type?b=Number(b):"Boolean"==a.type&&(b=Boolean(b));e[c]=b;s.parentNode&&s.parentNode.removeChild(s);e.setDirtyCanvas(!0,!0)}var c=a.property||
"title";b=e[c];var s=document.createElement("div");s.className="graphdialog";s.innerHTML="<span class='name'></span><input autofocus type='text' class='value'/><button>OK</button>";s.querySelector(".name").innerText=c;var k=s.querySelector("input");k&&(k.value=b,k.addEventListener("blur",function(a){this.focus()}),k.addEventListener("keydown",function(a){13==a.keyCode&&(f(),a.preventDefault(),a.stopPropagation())}));b=h.active_canvas.canvas;d=b.getBoundingClientRect();var n=g=-20;d&&(g-=d.left,n-=
d.top);event?(s.style.left=event.clientX+g+"px",s.style.top=event.clientY+n+"px"):(s.style.left=0.5*b.width+g+"px",s.style.top=0.5*b.height+n+"px");s.querySelector("button").addEventListener("click",f);b.parentNode.appendChild(s)};h.prototype.prompt=function(a,b,d,g){var e=this;a=a||"";var f=!1,c=document.createElement("div");c.className="graphdialog rounded";c.innerHTML="<span class='name'></span> <input autofocus type='text' class='value'/><button class='rounded'>OK</button>";c.close=function(){e.prompt_box=
null;c.parentNode&&c.parentNode.removeChild(c)};1<this.ds.scale&&(c.style.transform="scale("+this.ds.scale+")");c.addEventListener("mouseleave",function(a){f||c.close()});e.prompt_box&&e.prompt_box.close();e.prompt_box=c;c.querySelector(".name").innerText=a;c.querySelector(".value").value=b;var s=c.querySelector("input");s.addEventListener("keydown",function(a){f=!0;if(27==a.keyCode)c.close();else if(13==a.keyCode)d&&d(this.value),c.close();else return;a.preventDefault();a.stopPropagation()});c.querySelector("button").addEventListener("click",
function(a){d&&d(s.value);e.setDirty(!0);c.close()});a=h.active_canvas.canvas;b=a.getBoundingClientRect();var k=-20,n=-20;b&&(k-=b.left,n-=b.top);g?(c.style.left=g.clientX+k+"px",c.style.top=g.clientY+n+"px"):(c.style.left=0.5*a.width+k+"px",c.style.top=0.5*a.height+n+"px");a.parentNode.appendChild(c);setTimeout(function(){s.focus()},10);return c};h.search_limit=-1;h.prototype.showSearchBox=function(a){function b(b){if(b)if(e.onSearchBoxSelection)e.onSearchBoxSelection(b,a,c);else{var d=f.searchbox_extras[b.toLowerCase()];
d&&(b=d.type);c.graph.beforeChange();if(b=f.createNode(b))b.pos=c.convertEventToCanvasOffset(a),c.graph.add(b);if(d&&d.data){if(d.data.properties)for(var g in d.data.properties)b.addProperty(g,d.data.properties[g]);if(d.data.inputs)for(g in b.inputs=[],d.data.inputs)b.addOutput(d.data.inputs[g][0],d.data.inputs[g][1]);if(d.data.outputs)for(g in b.outputs=[],d.data.outputs)b.addOutput(d.data.outputs[g][0],d.data.outputs[g][1]);d.data.title&&(b.title=d.data.title);d.data.json&&b.configure(d.data.json);
c.graph.afterChange()}}k.close()}function d(a){var b=r;r&&r.classList.remove("selected");r?(r=a?r.nextSibling:r.previousSibling)||(r=b):r=a?q.childNodes[0]:q.childNodes[q.childNodes.length];r&&(r.classList.add("selected"),r.scrollIntoView({block:"end",behavior:"smooth"}))}function g(){function a(d,g){var e=document.createElement("div");v||(v=d);e.innerText=d;e.dataset.type=escape(d);e.className="litegraph lite-search-item";g&&(e.className+=" "+g);e.addEventListener("click",function(a){b(unescape(this.dataset.type))});
q.appendChild(e)}F=null;var d=J.value;v=null;q.innerHTML="";if(d)if(e.onSearchBox){var g=e.onSearchBox(q,d,c);if(g)for(var m=0;m<g.length;++m)a(g[m])}else{var g=0,d=d.toLowerCase(),s=c.filter||c.graph.filter;for(m in f.searchbox_extras){var k=f.searchbox_extras[m];if(-1!==k.desc.toLowerCase().indexOf(d)){var n=f.registered_node_types[k.type];if(!n||n.filter==s)if(a(k.desc,"searchbox_extra"),-1!==h.search_limit&&g++>h.search_limit)break}}k=null;if(Array.prototype.filter)k=Object.keys(f.registered_node_types).filter(y);
else for(m in k=[],f.registered_node_types)y(m)&&k.push(m);for(m=0;m<k.length&&!(a(k[m]),-1!==h.search_limit&&g++>h.search_limit);m++);var y=function(a){var b=f.registered_node_types[a];return s&&b.filter!=s?!1:-1!==a.toLowerCase().indexOf(d)}}}var e=this,c=h.active_canvas,m=c.canvas,s=m.ownerDocument||document,k=document.createElement("div");k.className="litegraph litesearchbox graphdialog rounded";k.innerHTML="<span class='name'>Search</span> <input autofocus type='text' class='value rounded'/><div class='helper'></div>";
var s=[],k;for(k in e.properties){a=void 0!==e.properties[k]?e.properties[k]:" ";"object"==typeof a&&(a=JSON.stringify(a));var n=e.getPropertyInfo(k);if("enum"==n.type||"combo"==n.type)a=h.getPropertyPrintableValue(a,n.values);a=h.decodeHTML(a);s.push({content:"<span class='property_name'>"+(n.label?n.label:k)+"</span><span class='property_value'>"+a+"</span>",value:k})}if(s.length)return new f.ContextMenu(s,{event:d,callback:c,parentMenu:g,allow_html:!0,node:e},b),!1}};h.decodeHTML=function(a){var b=
document.createElement("div");b.innerText=a;return b.innerHTML};h.onResizeNode=function(a,b,d,g,e){if(e){e.size=e.computeSize();if(e.onResize)e.onResize(e.size);e.setDirtyCanvas(!0,!0)}};h.prototype.showLinkMenu=function(a,b){var d=this;console.log(a);var g=new f.ContextMenu(["Add Node",null,"Delete"],{event:b,title:null!=a.data?a.data.constructor.name:null,callback:function(b,f,c){switch(b){case "Add Node":h.onMenuAdd(null,null,c,g,function(b){console.log("node autoconnect");var e=d.graph.getNodeById(a.origin_id),
g=d.graph.getNodeById(a.target_id);b.inputs&&b.inputs.length&&b.outputs&&b.outputs.length&&e.outputs[a.origin_slot].type==b.inputs[0].type&&b.outputs[0].type==g.inputs[0].type&&(e.connect(a.origin_slot,b,0),b.connect(0,g,a.target_slot),b.pos[0]-=0.5*b.size[0])});break;case "Delete":d.graph.removeLink(a.id)}}});return!1};h.onShowPropertyEditor=function(a,b,d,g,e){function f(){var b=k.value;"Number"==a.type?b=Number(b):"Boolean"==a.type&&(b=Boolean(b));e[c]=b;s.parentNode&&s.parentNode.removeChild(s);
e.setDirtyCanvas(!0,!0)}var c=a.property||"title";b=e[c];var s=document.createElement("div");s.className="graphdialog";s.innerHTML="<span class='name'></span><input autofocus type='text' class='value'/><button>OK</button>";s.querySelector(".name").innerText=c;var k=s.querySelector("input");k&&(k.value=b,k.addEventListener("blur",function(a){this.focus()}),k.addEventListener("keydown",function(a){13==a.keyCode&&(f(),a.preventDefault(),a.stopPropagation())}));b=h.active_canvas.canvas;d=b.getBoundingClientRect();
var n=g=-20;d&&(g-=d.left,n-=d.top);event?(s.style.left=event.clientX+g+"px",s.style.top=event.clientY+n+"px"):(s.style.left=0.5*b.width+g+"px",s.style.top=0.5*b.height+n+"px");s.querySelector("button").addEventListener("click",f);b.parentNode.appendChild(s)};h.prototype.prompt=function(a,b,d,g){var e=this;a=a||"";var f=!1,c=document.createElement("div");c.className="graphdialog rounded";c.innerHTML="<span class='name'></span> <input autofocus type='text' class='value'/><button class='rounded'>OK</button>";
c.close=function(){e.prompt_box=null;c.parentNode&&c.parentNode.removeChild(c)};1<this.ds.scale&&(c.style.transform="scale("+this.ds.scale+")");c.addEventListener("mouseleave",function(a){f||c.close()});e.prompt_box&&e.prompt_box.close();e.prompt_box=c;c.querySelector(".name").innerText=a;c.querySelector(".value").value=b;var s=c.querySelector("input");s.addEventListener("keydown",function(a){f=!0;if(27==a.keyCode)c.close();else if(13==a.keyCode)d&&d(this.value),c.close();else return;a.preventDefault();
a.stopPropagation()});c.querySelector("button").addEventListener("click",function(a){d&&d(s.value);e.setDirty(!0);c.close()});a=h.active_canvas.canvas;b=a.getBoundingClientRect();var k=-20,n=-20;b&&(k-=b.left,n-=b.top);g?(c.style.left=g.clientX+k+"px",c.style.top=g.clientY+n+"px"):(c.style.left=0.5*a.width+k+"px",c.style.top=0.5*a.height+n+"px");a.parentNode.appendChild(c);setTimeout(function(){s.focus()},10);return c};h.search_limit=-1;h.prototype.showSearchBox=function(a){function b(b){if(b)if(e.onSearchBoxSelection)e.onSearchBoxSelection(b,
a,c);else{var d=f.searchbox_extras[b.toLowerCase()];d&&(b=d.type);c.graph.beforeChange();if(b=f.createNode(b))b.pos=c.convertEventToCanvasOffset(a),c.graph.add(b);if(d&&d.data){if(d.data.properties)for(var g in d.data.properties)b.addProperty(g,d.data.properties[g]);if(d.data.inputs)for(g in b.inputs=[],d.data.inputs)b.addOutput(d.data.inputs[g][0],d.data.inputs[g][1]);if(d.data.outputs)for(g in b.outputs=[],d.data.outputs)b.addOutput(d.data.outputs[g][0],d.data.outputs[g][1]);d.data.title&&(b.title=
d.data.title);d.data.json&&b.configure(d.data.json);c.graph.afterChange()}}k.close()}function d(a){var b=r;r&&r.classList.remove("selected");r?(r=a?r.nextSibling:r.previousSibling)||(r=b):r=a?q.childNodes[0]:q.childNodes[q.childNodes.length];r&&(r.classList.add("selected"),r.scrollIntoView({block:"end",behavior:"smooth"}))}function g(){function a(d,g){var e=document.createElement("div");v||(v=d);e.innerText=d;e.dataset.type=escape(d);e.className="litegraph lite-search-item";g&&(e.className+=" "+g);
e.addEventListener("click",function(a){b(unescape(this.dataset.type))});q.appendChild(e)}F=null;var d=J.value;v=null;q.innerHTML="";if(d)if(e.onSearchBox){var g=e.onSearchBox(q,d,c);if(g)for(var m=0;m<g.length;++m)a(g[m])}else{var g=0,d=d.toLowerCase(),s=c.filter||c.graph.filter;for(m in f.searchbox_extras){var k=f.searchbox_extras[m];if(-1!==k.desc.toLowerCase().indexOf(d)){var n=f.registered_node_types[k.type];if(!n||n.filter==s)if(a(k.desc,"searchbox_extra"),-1!==h.search_limit&&g++>h.search_limit)break}}k=
null;if(Array.prototype.filter)k=Object.keys(f.registered_node_types).filter(y);else for(m in k=[],f.registered_node_types)y(m)&&k.push(m);for(m=0;m<k.length&&!(a(k[m]),-1!==h.search_limit&&g++>h.search_limit);m++);var y=function(a){var b=f.registered_node_types[a];return s&&b.filter!=s?!1:-1!==a.toLowerCase().indexOf(d)}}}var e=this,c=h.active_canvas,m=c.canvas,s=m.ownerDocument||document,k=document.createElement("div");k.className="litegraph litesearchbox graphdialog rounded";k.innerHTML="<span class='name'>Search</span> <input autofocus type='text' class='value rounded'/><div class='helper'></div>";
k.close=function(){e.search_box=null;s.body.focus();s.body.style.overflow="";setTimeout(function(){e.canvas.focus()},20);k.parentNode&&k.parentNode.removeChild(k)};var n=null;1<this.ds.scale&&(k.style.transform="scale("+this.ds.scale+")");k.addEventListener("mouseenter",function(a){n&&(clearTimeout(n),n=null)});k.addEventListener("mouseleave",function(a){n=setTimeout(function(){k.close()},500)});e.search_box&&e.search_box.close();e.search_box=k;var q=k.querySelector(".helper"),v=null,F=null,r=null,
J=k.querySelector("input");J&&(J.addEventListener("blur",function(a){this.focus()}),J.addEventListener("keydown",function(a){if(38==a.keyCode)d(!1);else if(40==a.keyCode)d(!0);else if(27==a.keyCode)k.close();else if(13==a.keyCode)r?b(r.innerHTML):v?b(v):k.close();else{F&&clearInterval(F);F=setTimeout(g,10);return}a.preventDefault();a.stopPropagation();a.stopImmediatePropagation();return!0}));s.fullscreenElement?s.fullscreenElement.appendChild(k):(s.body.appendChild(k),s.body.style.overflow="hidden");
var m=m.getBoundingClientRect(),I=(a?a.clientY:m.top+0.5*m.height)-20;k.style.left=(a?a.clientX:m.left+0.5*m.width)-80+"px";k.style.top=I+"px";a.layerY>m.height-200&&(q.style.maxHeight=m.height-a.layerY-20+"px");J.focus();return k};h.prototype.showEditPropertyValue=function(a,b,d){function g(){e(h.value)}function e(e){f&&f.values&&f.values.constructor===Object&&void 0!=f.values[e]&&(e=f.values[e]);"number"==typeof a.properties[b]&&(e=Number(e));if("array"==c||"object"==c)e=JSON.parse(e);a.properties[b]=
e;a.graph&&a.graph._version++;if(a.onPropertyChanged)a.onPropertyChanged(b,e);if(d.onclose)d.onclose();q.close();a.setDirtyCanvas(!0,!0)}if(a&&void 0!==a.properties[b]){d=d||{};var f=a.getPropertyInfo(b),c=f.type,s="";if("string"==c||"number"==c||"array"==c||"object"==c)s="<input autofocus type='text' class='value'/>";else if("enum"!=c&&"combo"!=c||!f.values)if("boolean"==c)s="<input autofocus type='checkbox' class='value' "+(a.properties[b]?"checked":"")+"/>";else{console.warn("unknown type: "+c);
return}else{var s="<select autofocus type='text' class='value'>",k;for(k in f.values){var n=k;f.values.constructor===Array&&(n=f.values[k]);s+="<option value='"+n+"' "+(n==a.properties[b]?"selected":"")+">"+f.values[k]+"</option>"}s+="</select>"}var q=this.createDialog("<span class='name'>"+b+"</span>"+s+"<button>OK</button>",d);if("enum"!=c&&"combo"!=c||!f.values)if("boolean"==c)(h=q.querySelector("input"))&&h.addEventListener("click",function(a){e(!!h.checked)});else{if(h=q.querySelector("input"))h.addEventListener("blur",
function(a){this.focus()}),n=void 0!==a.properties[b]?a.properties[b]:"",n=JSON.stringify(n),h.value=n,h.addEventListener("keydown",function(a){13==a.keyCode&&(g(),a.preventDefault(),a.stopPropagation())})}else{var h=q.querySelector("select");h.addEventListener("change",function(a){e(a.target.value)})}q.querySelector("button").addEventListener("click",g);return q}};h.prototype.createDialog=function(a,b){b=b||{};var d=document.createElement("div");d.className="graphdialog";d.innerHTML=a;var g=this.canvas.getBoundingClientRect(),
e=-20,f=-20;g&&(e-=g.left,f-=g.top);b.position?(e+=b.position[0],f+=b.position[1]):b.event?(e+=b.event.clientX,f+=b.event.clientY):(e+=0.5*this.canvas.width,f+=0.5*this.canvas.height);d.style.left=e+"px";d.style.top=f+"px";this.canvas.parentNode.appendChild(d);d.close=function(){this.parentNode&&this.parentNode.removeChild(this)};return d};h.prototype.createPanel=function(a,b){b=b||{};var d=b.window||window,g=document.createElement("div");g.className="litegraph dialog";g.innerHTML="<div class='dialog-header'><span class='dialog-title'></span></div><div class='dialog-content'></div><div class='dialog-footer'></div>";
g.header=g.querySelector(".dialog-header");b.width&&(g.style.width=b.width+(b.width.constructor===Number?"px":""));b.height&&(g.style.height=b.height+(b.height.constructor===Number?"px":""));if(b.closable){var e=document.createElement("span");e.innerHTML="&#10005;";e.classList.add("close");e.addEventListener("click",function(){g.close()});g.header.appendChild(e)}g.title_element=g.querySelector(".dialog-title");g.title_element.innerText=a;g.content=g.querySelector(".dialog-content");g.footer=g.querySelector(".dialog-footer");
g.close=function(){this.parentNode.removeChild(this)};g.clear=function(){this.content.innerHTML=""};g.addHTML=function(a,b,d){var e=document.createElement("div");b&&(e.className=b);e.innerHTML=a;d?g.footer.appendChild(e):g.content.appendChild(e);return e};g.addButton=function(a,b,d){var e=document.createElement("button");e.innerText=a;e.options=d;e.classList.add("btn");e.addEventListener("click",b);g.footer.appendChild(e);return e};g.addSeparator=function(){var a=document.createElement("div");a.className=
"separator";g.content.appendChild(a)};g.addWidget=function(a,b,e,c,k){function n(a,b){console.log("change",a,b);c.callback&&c.callback(a,b);k&&k(a,b)}c=c||{};var q=String(e);a=a.toLowerCase();"number"==a&&(q=e.toFixed(3));var F=document.createElement("div");F.className="property";F.innerHTML="<span class='property_name'></span><span class='property_value'></span>";F.querySelector(".property_name").innerText=b;var v=F.querySelector(".property_value");v.innerText=q;F.dataset.property=b;F.dataset.type=
c.type||a;F.options=c;F.value=e;if("boolean"==a)F.classList.add("boolean"),e&&F.classList.add("bool-on"),F.addEventListener("click",function(){var a=this.dataset.property;this.value=!this.value;this.classList.toggle("bool-on");this.querySelector(".property_value").innerText=this.value?"true":"false";n(a,this.value)});else if("string"==a||"number"==a)v.setAttribute("contenteditable",!0),v.addEventListener("keydown",function(a){"Enter"==a.code&&(a.preventDefault(),this.blur())}),v.addEventListener("blur",
function(){var a=this.innerText,b=this.parentNode.dataset.property;"number"==this.parentNode.dataset.type&&(a=Number(a));n(b,a)});else if("enum"==a||"combo"==a)q=h.getPropertyPrintableValue(e,c.values);v.innerText=q;v.addEventListener("click",function(a){var b=this.parentNode.dataset.property,e=this;new f.ContextMenu(c.values||[],{event:a,className:"dark",callback:function(a,d,g){e.innerText=a;n(b,a);return!1}},d)});g.content.appendChild(F);return F};return g};h.getPropertyPrintableValue=function(a,
b){if(!b||b.constructor===Array)return String(a);if(b.constructor===Object){var d="",g;for(g in b)if(b[g]==a){d=g;break}return String(a)+" ("+d+")"}};h.prototype.showShowNodePanel=function(a){window.SELECTED_NODE=a;var b=document.querySelector("#node-panel");b&&b.close();var d=this.getCanvasWindow(),b=this.createPanel(a.title||"",{closable:!0,window:d});b.id="node-panel";b.node=a;b.classList.add("settings");var g=this;(function(){b.content.innerHTML="";b.addHTML("<span class='node_type'>"+a.type+
"</span><span class='node_desc'>"+(a.constructor.desc||"")+"</span><span class='separator'></span>");b.addHTML("<h3>Properties</h3>");for(var d in a.properties){var f=a.properties[d],c=a.getPropertyInfo(d);a.onAddPropertyToPanel&&a.onAddPropertyToPanel(d,b)||b.addWidget(c.widget||c.type,d,f,c,function(b,d){g.graph.beforeChange(a);a.setProperty(b,d);g.graph.afterChange();g.dirty_canvas=!0})}b.addSeparator();if(a.onShowCustomPanelInfo)a.onShowCustomPanelInfo(b);b.addButton("Delete",function(){a.block_delete||
(a.graph.remove(a),b.close())}).classList.add("delete")})();this.canvas.parentNode.appendChild(b)};h.prototype.showSubgraphPropertiesDialog=function(a){function b(){g.clear();if(a.inputs)for(var d=0;d<a.inputs.length;++d){var f=a.inputs[d];if(!f.not_subgraph_input){var c=g.addHTML("<button>&#10005;</button> <span class='bullet_icon'></span><span class='name'></span><span class='type'></span>","subgraph_property");c.dataset.name=f.name;c.dataset.slot=d;c.querySelector(".name").innerText=f.name;c.querySelector(".type").innerText=
f.type;c.querySelector("button").addEventListener("click",function(d){a.removeInput(Number(this.parentNode.dataset.slot));b()})}}}console.log("showing subgraph properties dialog");var d=this.canvas.parentNode.querySelector(".subgraph_dialog");d&&d.close();var g=this.createPanel("Subgraph Inputs",{closable:!0,width:500});g.node=a;g.classList.add("subgraph_dialog");g.addHTML(" + <span class='label'>Name</span><input class='name'/><span class='label'>Type</span><input class='type'></input><button>+</button>",
"subgraph_property extra",!0).querySelector("button").addEventListener("click",function(d){d=this.parentNode;var g=d.querySelector(".name").value,f=d.querySelector(".type").value;g&&-1==a.findInputSlot(g)&&(a.addInput(g,f),d.querySelector(".name").value="",d.querySelector(".type").value="",b())});b();this.canvas.parentNode.appendChild(g);return g};h.prototype.checkPanels=function(){if(this.canvas)for(var a=this.canvas.parentNode.querySelectorAll(".litegraph.dialog"),b=0;b<a.length;++b){var d=a[b];
d.node&&(d.node.graph&&d.graph==this.graph||d.close())}};h.onMenuNodeCollapse=function(a,b,d,g,e){e.graph.beforeChange(e);e.collapse();e.graph.afterChange(e)};h.onMenuNodePin=function(a,b,d,g,e){e.pin()};h.onMenuNodeMode=function(a,b,d,g,e){new f.ContextMenu(["Always","On Event","On Trigger","Never"],{event:d,callback:function(a){if(e)switch(a){case "On Event":e.mode=f.ON_EVENT;break;case "On Trigger":e.mode=f.ON_TRIGGER;break;case "Never":e.mode=f.NEVER;break;default:e.mode=f.ALWAYS}},parentMenu:g,
node:e});return!1};h.onMenuNodeColors=function(a,b,d,g,e){if(!e)throw"no node for color";b=[];b.push({value:null,content:"<span style='display: block; padding-left: 4px;'>No color</span>"});for(var c in h.node_colors)a=h.node_colors[c],a={value:c,content:"<span style='display: block; color: #999; padding-left: 4px; border-left: 8px solid "+a.color+"; background-color:"+a.bgcolor+"'>"+c+"</span>"},b.push(a);new f.ContextMenu(b,{event:d,callback:function(a){e&&((a=a.value?h.node_colors[a.value]:null)?
e.constructor===f.LGraphGroup?e.color=a.groupcolor:(e.color=a.color,e.bgcolor=a.bgcolor):(delete e.color,delete e.bgcolor),e.setDirtyCanvas(!0,!0))},parentMenu:g,node:e});return!1};h.onMenuNodeShapes=function(a,b,d,g,e){if(!e)throw"no node passed";new f.ContextMenu(f.VALID_SHAPES,{event:d,callback:function(a){e&&(e.graph.beforeChange(e),e.shape=a,e.graph.afterChange(e),e.setDirtyCanvas(!0))},parentMenu:g,node:e});return!1};h.onMenuNodeRemove=function(a,b,d,g,e){if(!e)throw"no node passed";!1!==e.removable&&
(a=e.graph,a.beforeChange(),a.remove(e),a.afterChange(),e.setDirtyCanvas(!0,!0))};h.onMenuNodeToSubgraph=function(a,b,d,g,e){a=e.graph;if(b=h.active_canvas)d=Object.values(b.selected_nodes||{}),d.length||(d=[e]),g=f.createNode("graph/subgraph"),g.pos=e.pos.concat(),a.add(g),g.buildFromNodes(d),b.deselectAllNodes(),e.setDirtyCanvas(!0,!0)};h.onMenuNodeClone=function(a,b,d,g,e){!1!=e.clonable&&(a=e.clone())&&(a.pos=[e.pos[0]+5,e.pos[1]+5],e.graph.beforeChange(),e.graph.add(a),e.graph.afterChange(),
e.setDirtyCanvas(!0,!0))};h.node_colors={red:{color:"#322",bgcolor:"#533",groupcolor:"#A88"},brown:{color:"#332922",bgcolor:"#593930",groupcolor:"#b06634"},green:{color:"#232",bgcolor:"#353",groupcolor:"#8A8"},blue:{color:"#223",bgcolor:"#335",groupcolor:"#88A"},pale_blue:{color:"#2a363b",bgcolor:"#3f5159",groupcolor:"#3f789e"},cyan:{color:"#233",bgcolor:"#355",groupcolor:"#8AA"},purple:{color:"#323",bgcolor:"#535",groupcolor:"#a1309b"},yellow:{color:"#432",bgcolor:"#653",groupcolor:"#b58b2a"},black:{color:"#222",
bgcolor:"#000",groupcolor:"#444"}};h.prototype.getCanvasMenuOptions=function(){var a=null;this.getMenuOptions?a=this.getMenuOptions():(a=[{content:"Add Node",has_submenu:!0,callback:h.onMenuAdd},{content:"Add Group",callback:h.onGroupAdd}],this._graph_stack&&0<this._graph_stack.length&&a.push(null,{content:"Close subgraph",callback:this.closeSubgraph.bind(this)}));if(this.getExtraMenuOptions){var b=this.getExtraMenuOptions(this,a);b&&(a=a.concat(b))}return a};h.prototype.getNodeMenuOptions=function(a){var b=
null,b=a.getMenuOptions?a.getMenuOptions(this):[{content:"Inputs",has_submenu:!0,disabled:!0,callback:h.showMenuNodeOptionalInputs},{content:"Outputs",has_submenu:!0,disabled:!0,callback:h.showMenuNodeOptionalOutputs},null,{content:"Properties",has_submenu:!0,callback:h.onShowMenuNodeProperties},null,{content:"Title",callback:h.onShowPropertyEditor},{content:"Mode",has_submenu:!0,callback:h.onMenuNodeMode},{content:"Resize",callback:function(){if(a.resizable)return h.onResizeNode}},{content:"Collapse",
callback:h.onMenuNodeCollapse},{content:"Pin",callback:h.onMenuNodePin},{content:"Colors",has_submenu:!0,callback:h.onMenuNodeColors},{content:"Shapes",has_submenu:!0,callback:h.onMenuNodeShapes},null];if(a.onGetInputs){var d=a.onGetInputs();d&&d.length&&(b[0].disabled=!1)}a.onGetOutputs&&(d=a.onGetOutputs())&&d.length&&(b[1].disabled=!1);a.getExtraMenuOptions&&(d=a.getExtraMenuOptions(this,b))&&(d.push(null),b=d.concat(b));!1!==a.clonable&&b.push({content:"Clone",callback:h.onMenuNodeClone});b.push(null,
{content:"Remove",disabled:!(!1!==a.removable&&!a.block_delete),callback:h.onMenuNodeRemove});if(a.graph&&a.graph.onGetNodeMenuOptions)a.graph.onGetNodeMenuOptions(b,a);return b};h.prototype.getGroupMenuOptions=function(a){return[{content:"Title",callback:h.onShowPropertyEditor},{content:"Color",has_submenu:!0,callback:h.onMenuNodeColors},{content:"Font size",property:"font_size",type:"Number",callback:h.onShowPropertyEditor},null,{content:"Remove",callback:h.onMenuNodeRemove}]};h.prototype.processContextMenu=
function(a,b){var d=this,g=h.active_canvas.getCanvasWindow(),e=null,c={event:b,callback:function(b,e,g){if(b)if("Remove Slot"==b.content)b=b.slot,b.input?a.removeInput(b.slot):b.output&&a.removeOutput(b.slot);else if("Disconnect Links"==b.content)b=b.slot,b.output?a.disconnectOutput(b.slot):b.input&&a.disconnectInput(b.slot);else if("Rename Slot"==b.content){b=b.slot;var f=b.input?a.getInputInfo(b.slot):a.getOutputInfo(b.slot),c=d.createDialog("<span class='name'>Name</span><input autofocus type='text'/><button>OK</button>",
e),k=c.querySelector("input");k&&f&&(k.value=f.label||"");c.querySelector("button").addEventListener("click",function(a){k.value&&(f&&(f.label=k.value),d.setDirty(!0));c.close()})}},extra:a};a&&(c.title=a.type);var k=null;a&&(k=a.getSlotInPosition(b.canvasX,b.canvasY),h.active_node=a);if(k){e=[];if(a.getSlotMenuOptions)e=a.getSlotMenuOptions(k);else{k&&k.output&&k.output.links&&k.output.links.length&&e.push({content:"Disconnect Links",slot:k});var s=k.input||k.output;e.push(s.locked?"Cannot remove":
{content:"Remove Slot",slot:k});e.push(s.nameLocked?"Cannot rename":{content:"Rename Slot",slot:k})}c.title=(k.input?k.input.type:k.output.type)||"*";k.input&&k.input.type==f.ACTION&&(c.title="Action");k.output&&k.output.type==f.EVENT&&(c.title="Event")}else a?e=this.getNodeMenuOptions(a):(e=this.getCanvasMenuOptions(),(k=this.graph.getGroupOnPos(b.canvasX,b.canvasY))&&e.push(null,{content:"Edit Group",has_submenu:!0,submenu:{title:"Group",extra:k,options:this.getGroupMenuOptions(k)}}));e&&new f.ContextMenu(e,
c,g)};"undefined"!=typeof window&&window.CanvasRenderingContext2D&&(window.CanvasRenderingContext2D.prototype.roundRect=function(a,b,d,g,e,f){void 0===e&&(e=5);void 0===f&&(f=e);this.moveTo(a+e,b);this.lineTo(a+d-e,b);this.quadraticCurveTo(a+d,b,a+d,b+e);this.lineTo(a+d,b+g-f);this.quadraticCurveTo(a+d,b+g,a+d-f,b+g);this.lineTo(a+f,b+g);this.quadraticCurveTo(a,b+g,a,b+g-f);this.lineTo(a,b+e);this.quadraticCurveTo(a,b,a+e,b)});f.compareObjects=function(a,b){for(var d in a)if(a[d]!=b[d])return!1;return!0};
f.distance=C;f.colorToString=function(a){return"rgba("+Math.round(255*a[0]).toFixed()+","+Math.round(255*a[1]).toFixed()+","+Math.round(255*a[2]).toFixed()+","+(4==a.length?a[3].toFixed(2):"1.0")+")"};f.isInsideRectangle=x;f.growBounding=function(a,b,d){b<a[0]?a[0]=b:b>a[2]&&(a[2]=b);d<a[1]?a[1]=d:d>a[3]&&(a[3]=d)};f.isInsideBounding=function(a,b){return a[0]<b[0][0]||a[1]<b[0][1]||a[0]>b[1][0]||a[1]>b[1][1]?!1:!0};f.overlapBounding=G;f.hex2num=function(a){"#"==a.charAt(0)&&(a=a.slice(1));a=a.toUpperCase();
for(var b=Array(3),d=0,g,e,f=0;6>f;f+=2)g="0123456789ABCDEF".indexOf(a.charAt(f)),e="0123456789ABCDEF".indexOf(a.charAt(f+1)),b[d]=16*g+e,d++;return b};f.num2hex=function(a){for(var b="#",d,g,e=0;3>e;e++)d=a[e]/16,g=a[e]%16,b+="0123456789ABCDEF".charAt(d)+"0123456789ABCDEF".charAt(g);return b};A.prototype.addItem=function(a,b,d){function g(a){var b=this.value;b&&b.has_submenu&&e.call(this,a)}function e(a){var b=this.value,e=!0;f.current_submenu&&f.current_submenu.close(a);if(d.callback){var g=d.callback.call(this,
b,d,a,f,d.node);!0===g&&(e=!1)}if(b&&(b.callback&&!d.ignore_item_callbacks&&!0!==b.disabled&&(g=b.callback.call(this,b,d,a,f,d.extra),!0===g&&(e=!1)),b.submenu)){if(!b.submenu.options)throw"ContextMenu submenu needs options";new f.constructor(b.submenu.options,{callback:b.submenu.callback,event:a,parentMenu:f,ignore_item_callbacks:b.submenu.ignore_item_callbacks,title:b.submenu.title,extra:b.submenu.extra,autoopen:d.autoopen});e=!1}e&&!f.lock&&f.close()}var f=this;d=d||{};var c=document.createElement("div");
c.className="litemenu-entry submenu";var k=!1;if(null===b)c.classList.add("separator");else{c.innerHTML=b&&b.title?b.title:a;if(c.value=b)b.disabled&&(k=!0,c.classList.add("disabled")),(b.submenu||b.has_submenu)&&c.classList.add("has_submenu");"function"==typeof b?(c.dataset.value=a,c.onclick_callback=b):c.dataset.value=b;b.className&&(c.className+=" "+b.className)}this.root.appendChild(c);k||c.addEventListener("click",e);d.autoopen&&c.addEventListener("mouseenter",g);return c};A.prototype.close=
function(a,b){this.root.parentNode&&this.root.parentNode.removeChild(this.root);this.parentMenu&&!b&&(this.parentMenu.lock=!1,this.parentMenu.current_submenu=null,void 0===a?this.parentMenu.close():a&&!A.isCursorOverElement(a,this.parentMenu.root)&&A.trigger(this.parentMenu.root,"mouseleave",a));this.current_submenu&&this.current_submenu.close(a,!0);this.root.closing_timer&&clearTimeout(this.root.closing_timer)};A.trigger=function(a,b,d,g){var e=document.createEvent("CustomEvent");e.initCustomEvent(b,
!0,!0,d);e.srcElement=g;a.dispatchEvent?a.dispatchEvent(e):a.__events&&a.__events.dispatchEvent(e);return e};A.prototype.getTopMenu=function(){return this.options.parentMenu?this.options.parentMenu.getTopMenu():this};A.prototype.getFirstEvent=function(){return this.options.parentMenu?this.options.parentMenu.getFirstEvent():this.options.event};A.isCursorOverElement=function(a,b){var d=a.clientX,g=a.clientY,e=b.getBoundingClientRect();return e?g>e.top&&g<e.top+e.height&&d>e.left&&d<e.left+e.width?!0:
!1:!1};f.ContextMenu=A;f.closeAllContextMenus=function(a){a=a||window;a=a.document.querySelectorAll(".litecontextmenu");if(a.length){for(var b=[],d=0;d<a.length;d++)b.push(a[d]);for(d=0;d<b.length;d++)b[d].close?b[d].close():b[d].parentNode&&b[d].parentNode.removeChild(b[d])}};f.extendClass=function(a,b){for(var d in b)a.hasOwnProperty(d)||(a[d]=b[d]);if(b.prototype)for(d in b.prototype)b.prototype.hasOwnProperty(d)&&!a.prototype.hasOwnProperty(d)&&(b.prototype.__lookupGetter__(d)?a.prototype.__defineGetter__(d,
b.prototype.__lookupGetter__(d)):a.prototype[d]=b.prototype[d],b.prototype.__lookupSetter__(d)&&a.prototype.__defineSetter__(d,b.prototype.__lookupSetter__(d)))};D.sampleCurve=function(a,b){if(b){for(var d=0;d<b.length-1;++d){var g=b[d],e=b[d+1];if(!(e[0]<a)){d=e[0]-g[0];if(1E-5>Math.abs(d))return g[1];d=(a-g[0])/d;return g[1]*(1-d)+e[1]*d}}return 0}};D.prototype.draw=function(a,b,d,g,e,f){if(d=this.points){this.size=b;var c=b[0]-2*this.margin;b=b[1]-2*this.margin;e=e||"#666";a.save();a.translate(this.margin,
this.margin);g&&(a.fillStyle="#111",a.fillRect(0,0,c,b),a.fillStyle="#222",a.fillRect(0.5*c,0,1,b),a.strokeStyle="#333",a.strokeRect(0,0,c,b));a.strokeStyle=e;f&&(a.globalAlpha=0.5);a.beginPath();for(g=0;g<d.length;++g)e=d[g],a.lineTo(e[0]*c,(1-e[1])*b);a.stroke();a.globalAlpha=1;if(!f)for(g=0;g<d.length;++g)e=d[g],a.fillStyle=this.selected==g?"#FFF":this.nearest==g?"#DDD":"#AAA",a.beginPath(),a.arc(e[0]*c,(1-e[1])*b,2,0,2*Math.PI),a.fill();a.restore()}};D.prototype.onMouseDown=function(a,b){var d=
this.points;if(d&&!(0>a[1])){var g=this.size[0]-2*this.margin,e=this.size[1]-2*this.margin,f=a[0]-this.margin,c=a[1]-this.margin;this.selected=this.getCloserPoint([f,c],30/b.ds.scale);-1==this.selected&&(g=[f/g,1-c/e],d.push(g),d.sort(function(a,b){return a[0]-b[0]}),this.selected=d.indexOf(g),this.must_update=!0);if(-1!=this.selected)return!0}};D.prototype.onMouseMove=function(a,b){var d=this.points;if(d){var g=this.selected;if(!(0>g)){var e=(a[0]-this.margin)/(this.size[0]-2*this.margin),f=(a[1]-
this.margin)/(this.size[1]-2*this.margin);this._nearest=this.getCloserPoint([a[0]-this.margin,a[1]-this.margin],30/b.ds.scale);var c=d[g];if(c){var k=0==g||g==d.length-1;!k&&(-10>a[0]||a[0]>this.size[0]+10||-10>a[1]||a[1]>this.size[1]+10)?(d.splice(g,1),this.selected=-1):(c[0]=k?0==g?0:1:Math.clamp(e,0,1),c[1]=1-Math.clamp(f,0,1),d.sort(function(a,b){return a[0]-b[0]}),this.selected=d.indexOf(c),this.must_update=!0)}}}};D.prototype.onMouseUp=function(a,b){this.selected=-1;return!1};D.prototype.getCloserPoint=
function(a,b){var d=this.points;if(!d)return-1;b=b||30;for(var g=this.size[0]-2*this.margin,e=this.size[1]-2*this.margin,f=d.length,c=[0,0],k=1E6,n=-1,q=0;q<f;++q){var h=d[q];c[0]=h[0]*g;c[1]=(1-h[1])*e;h=vec2.distance(a,c);h>k||h>b||(n=q,k=h)}return n};f.CurveEditor=D;f.getParameterNames=function(a){return(a+"").replace(/[/][/].*$/gm,"").replace(/\s+/g,"").replace(/[/][*][^/*]*[*][/]/g,"").split("){",1)[0].replace(/^[^(]*[(]/,"").replace(/=[^,]+/g,"").split(",").filter(Boolean)};Math.clamp=function(a,
b,d){return b>a?b:d<a?d:a};"undefined"==typeof window||window.requestAnimationFrame||(window.requestAnimationFrame=window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(a){window.setTimeout(a,1E3/60)})})(this);"undefined"!=typeof exports&&(exports.LiteGraph=this.LiteGraph);
return}else{var s="<select autofocus type='text' class='value'>",k;for(k in f.values){var n=k;f.values.constructor===Array&&(n=f.values[k]);s+="<option value='"+n+"' "+(n==a.properties[b]?"selected":"")+">"+f.values[k]+"</option>"}s+="</select>"}var q=this.createDialog("<span class='name'>"+(f.label?f.label:b)+"</span>"+s+"<button>OK</button>",d);if("enum"!=c&&"combo"!=c||!f.values)if("boolean"==c)(h=q.querySelector("input"))&&h.addEventListener("click",function(a){e(!!h.checked)});else{if(h=q.querySelector("input"))h.addEventListener("blur",
function(a){this.focus()}),n=void 0!==a.properties[b]?a.properties[b]:"","string"!==c&&(n=JSON.stringify(n)),h.value=n,h.addEventListener("keydown",function(a){13==a.keyCode&&(g(),a.preventDefault(),a.stopPropagation())})}else{var h=q.querySelector("select");h.addEventListener("change",function(a){e(a.target.value)})}q.querySelector("button").addEventListener("click",g);return q}};h.prototype.createDialog=function(a,b){b=b||{};var d=document.createElement("div");d.className="graphdialog";d.innerHTML=
a;var g=this.canvas.getBoundingClientRect(),e=-20,f=-20;g&&(e-=g.left,f-=g.top);b.position?(e+=b.position[0],f+=b.position[1]):b.event?(e+=b.event.clientX,f+=b.event.clientY):(e+=0.5*this.canvas.width,f+=0.5*this.canvas.height);d.style.left=e+"px";d.style.top=f+"px";this.canvas.parentNode.appendChild(d);d.close=function(){this.parentNode&&this.parentNode.removeChild(this)};return d};h.prototype.createPanel=function(a,b){b=b||{};var d=b.window||window,g=document.createElement("div");g.className="litegraph dialog";
g.innerHTML="<div class='dialog-header'><span class='dialog-title'></span></div><div class='dialog-content'></div><div class='dialog-footer'></div>";g.header=g.querySelector(".dialog-header");b.width&&(g.style.width=b.width+(b.width.constructor===Number?"px":""));b.height&&(g.style.height=b.height+(b.height.constructor===Number?"px":""));if(b.closable){var e=document.createElement("span");e.innerHTML="&#10005;";e.classList.add("close");e.addEventListener("click",function(){g.close()});g.header.appendChild(e)}g.title_element=
g.querySelector(".dialog-title");g.title_element.innerText=a;g.content=g.querySelector(".dialog-content");g.footer=g.querySelector(".dialog-footer");g.close=function(){this.parentNode.removeChild(this)};g.clear=function(){this.content.innerHTML=""};g.addHTML=function(a,b,d){var e=document.createElement("div");b&&(e.className=b);e.innerHTML=a;d?g.footer.appendChild(e):g.content.appendChild(e);return e};g.addButton=function(a,b,d){var e=document.createElement("button");e.innerText=a;e.options=d;e.classList.add("btn");
e.addEventListener("click",b);g.footer.appendChild(e);return e};g.addSeparator=function(){var a=document.createElement("div");a.className="separator";g.content.appendChild(a)};g.addWidget=function(a,b,e,c,k){function n(a,b){console.log("change",a,b);c.callback&&c.callback(a,b);k&&k(a,b)}c=c||{};var q=String(e);a=a.toLowerCase();"number"==a&&(q=e.toFixed(3));var F=document.createElement("div");F.className="property";F.innerHTML="<span class='property_name'></span><span class='property_value'></span>";
F.querySelector(".property_name").innerText=b;var v=F.querySelector(".property_value");v.innerText=q;F.dataset.property=b;F.dataset.type=c.type||a;F.options=c;F.value=e;if("boolean"==a)F.classList.add("boolean"),e&&F.classList.add("bool-on"),F.addEventListener("click",function(){var a=this.dataset.property;this.value=!this.value;this.classList.toggle("bool-on");this.querySelector(".property_value").innerText=this.value?"true":"false";n(a,this.value)});else if("string"==a||"number"==a)v.setAttribute("contenteditable",
!0),v.addEventListener("keydown",function(a){"Enter"==a.code&&(a.preventDefault(),this.blur())}),v.addEventListener("blur",function(){var a=this.innerText,b=this.parentNode.dataset.property;"number"==this.parentNode.dataset.type&&(a=Number(a));n(b,a)});else if("enum"==a||"combo"==a)q=h.getPropertyPrintableValue(e,c.values);v.innerText=q;v.addEventListener("click",function(a){var b=this.parentNode.dataset.property,e=this;new f.ContextMenu(c.values||[],{event:a,className:"dark",callback:function(a,
d,g){e.innerText=a;n(b,a);return!1}},d)});g.content.appendChild(F);return F};return g};h.getPropertyPrintableValue=function(a,b){if(!b||b.constructor===Array)return String(a);if(b.constructor===Object){var d="",g;for(g in b)if(b[g]==a){d=g;break}return String(a)+" ("+d+")"}};h.prototype.showShowNodePanel=function(a){window.SELECTED_NODE=a;var b=document.querySelector("#node-panel");b&&b.close();var d=this.getCanvasWindow(),b=this.createPanel(a.title||"",{closable:!0,window:d});b.id="node-panel";b.node=
a;b.classList.add("settings");var g=this;(function(){b.content.innerHTML="";b.addHTML("<span class='node_type'>"+a.type+"</span><span class='node_desc'>"+(a.constructor.desc||"")+"</span><span class='separator'></span>");b.addHTML("<h3>Properties</h3>");for(var d in a.properties){var f=a.properties[d],c=a.getPropertyInfo(d);a.onAddPropertyToPanel&&a.onAddPropertyToPanel(d,b)||b.addWidget(c.widget||c.type,d,f,c,function(b,d){g.graph.beforeChange(a);a.setProperty(b,d);g.graph.afterChange();g.dirty_canvas=
!0})}b.addSeparator();if(a.onShowCustomPanelInfo)a.onShowCustomPanelInfo(b);b.addButton("Delete",function(){a.block_delete||(a.graph.remove(a),b.close())}).classList.add("delete")})();this.canvas.parentNode.appendChild(b)};h.prototype.showSubgraphPropertiesDialog=function(a){function b(){g.clear();if(a.inputs)for(var d=0;d<a.inputs.length;++d){var f=a.inputs[d];if(!f.not_subgraph_input){var c=g.addHTML("<button>&#10005;</button> <span class='bullet_icon'></span><span class='name'></span><span class='type'></span>",
"subgraph_property");c.dataset.name=f.name;c.dataset.slot=d;c.querySelector(".name").innerText=f.name;c.querySelector(".type").innerText=f.type;c.querySelector("button").addEventListener("click",function(d){a.removeInput(Number(this.parentNode.dataset.slot));b()})}}}console.log("showing subgraph properties dialog");var d=this.canvas.parentNode.querySelector(".subgraph_dialog");d&&d.close();var g=this.createPanel("Subgraph Inputs",{closable:!0,width:500});g.node=a;g.classList.add("subgraph_dialog");
g.addHTML(" + <span class='label'>Name</span><input class='name'/><span class='label'>Type</span><input class='type'></input><button>+</button>","subgraph_property extra",!0).querySelector("button").addEventListener("click",function(d){d=this.parentNode;var g=d.querySelector(".name").value,f=d.querySelector(".type").value;g&&-1==a.findInputSlot(g)&&(a.addInput(g,f),d.querySelector(".name").value="",d.querySelector(".type").value="",b())});b();this.canvas.parentNode.appendChild(g);return g};h.prototype.checkPanels=
function(){if(this.canvas)for(var a=this.canvas.parentNode.querySelectorAll(".litegraph.dialog"),b=0;b<a.length;++b){var d=a[b];d.node&&(d.node.graph&&d.graph==this.graph||d.close())}};h.onMenuNodeCollapse=function(a,b,d,g,e){e.graph.beforeChange(e);e.collapse();e.graph.afterChange(e)};h.onMenuNodePin=function(a,b,d,g,e){e.pin()};h.onMenuNodeMode=function(a,b,d,g,e){new f.ContextMenu(["Always","On Event","On Trigger","Never"],{event:d,callback:function(a){if(e)switch(a){case "On Event":e.mode=f.ON_EVENT;
break;case "On Trigger":e.mode=f.ON_TRIGGER;break;case "Never":e.mode=f.NEVER;break;default:e.mode=f.ALWAYS}},parentMenu:g,node:e});return!1};h.onMenuNodeColors=function(a,b,d,g,e){if(!e)throw"no node for color";b=[];b.push({value:null,content:"<span style='display: block; padding-left: 4px;'>No color</span>"});for(var c in h.node_colors)a=h.node_colors[c],a={value:c,content:"<span style='display: block; color: #999; padding-left: 4px; border-left: 8px solid "+a.color+"; background-color:"+a.bgcolor+
"'>"+c+"</span>"},b.push(a);new f.ContextMenu(b,{event:d,callback:function(a){e&&((a=a.value?h.node_colors[a.value]:null)?e.constructor===f.LGraphGroup?e.color=a.groupcolor:(e.color=a.color,e.bgcolor=a.bgcolor):(delete e.color,delete e.bgcolor),e.setDirtyCanvas(!0,!0))},parentMenu:g,node:e});return!1};h.onMenuNodeShapes=function(a,b,d,g,e){if(!e)throw"no node passed";new f.ContextMenu(f.VALID_SHAPES,{event:d,callback:function(a){e&&(e.graph.beforeChange(e),e.shape=a,e.graph.afterChange(e),e.setDirtyCanvas(!0))},
parentMenu:g,node:e});return!1};h.onMenuNodeRemove=function(a,b,d,g,e){if(!e)throw"no node passed";!1!==e.removable&&(a=e.graph,a.beforeChange(),a.remove(e),a.afterChange(),e.setDirtyCanvas(!0,!0))};h.onMenuNodeToSubgraph=function(a,b,d,g,e){a=e.graph;if(b=h.active_canvas)d=Object.values(b.selected_nodes||{}),d.length||(d=[e]),g=f.createNode("graph/subgraph"),g.pos=e.pos.concat(),a.add(g),g.buildFromNodes(d),b.deselectAllNodes(),e.setDirtyCanvas(!0,!0)};h.onMenuNodeClone=function(a,b,d,g,e){!1!=e.clonable&&
(a=e.clone())&&(a.pos=[e.pos[0]+5,e.pos[1]+5],e.graph.beforeChange(),e.graph.add(a),e.graph.afterChange(),e.setDirtyCanvas(!0,!0))};h.node_colors={red:{color:"#322",bgcolor:"#533",groupcolor:"#A88"},brown:{color:"#332922",bgcolor:"#593930",groupcolor:"#b06634"},green:{color:"#232",bgcolor:"#353",groupcolor:"#8A8"},blue:{color:"#223",bgcolor:"#335",groupcolor:"#88A"},pale_blue:{color:"#2a363b",bgcolor:"#3f5159",groupcolor:"#3f789e"},cyan:{color:"#233",bgcolor:"#355",groupcolor:"#8AA"},purple:{color:"#323",
bgcolor:"#535",groupcolor:"#a1309b"},yellow:{color:"#432",bgcolor:"#653",groupcolor:"#b58b2a"},black:{color:"#222",bgcolor:"#000",groupcolor:"#444"}};h.prototype.getCanvasMenuOptions=function(){var a=null;this.getMenuOptions?a=this.getMenuOptions():(a=[{content:"Add Node",has_submenu:!0,callback:h.onMenuAdd},{content:"Add Group",callback:h.onGroupAdd}],this._graph_stack&&0<this._graph_stack.length&&a.push(null,{content:"Close subgraph",callback:this.closeSubgraph.bind(this)}));if(this.getExtraMenuOptions){var b=
this.getExtraMenuOptions(this,a);b&&(a=a.concat(b))}return a};h.prototype.getNodeMenuOptions=function(a){var b=null,b=a.getMenuOptions?a.getMenuOptions(this):[{content:"Inputs",has_submenu:!0,disabled:!0,callback:h.showMenuNodeOptionalInputs},{content:"Outputs",has_submenu:!0,disabled:!0,callback:h.showMenuNodeOptionalOutputs},null,{content:"Properties",has_submenu:!0,callback:h.onShowMenuNodeProperties},null,{content:"Title",callback:h.onShowPropertyEditor},{content:"Mode",has_submenu:!0,callback:h.onMenuNodeMode},
{content:"Resize",callback:function(){if(a.resizable)return h.onResizeNode}},{content:"Collapse",callback:h.onMenuNodeCollapse},{content:"Pin",callback:h.onMenuNodePin},{content:"Colors",has_submenu:!0,callback:h.onMenuNodeColors},{content:"Shapes",has_submenu:!0,callback:h.onMenuNodeShapes},null];if(a.onGetInputs){var d=a.onGetInputs();d&&d.length&&(b[0].disabled=!1)}a.onGetOutputs&&(d=a.onGetOutputs())&&d.length&&(b[1].disabled=!1);a.getExtraMenuOptions&&(d=a.getExtraMenuOptions(this,b))&&(d.push(null),
b=d.concat(b));!1!==a.clonable&&b.push({content:"Clone",callback:h.onMenuNodeClone});b.push(null,{content:"Remove",disabled:!(!1!==a.removable&&!a.block_delete),callback:h.onMenuNodeRemove});if(a.graph&&a.graph.onGetNodeMenuOptions)a.graph.onGetNodeMenuOptions(b,a);return b};h.prototype.getGroupMenuOptions=function(a){return[{content:"Title",callback:h.onShowPropertyEditor},{content:"Color",has_submenu:!0,callback:h.onMenuNodeColors},{content:"Font size",property:"font_size",type:"Number",callback:h.onShowPropertyEditor},
null,{content:"Remove",callback:h.onMenuNodeRemove}]};h.prototype.processContextMenu=function(a,b){var d=this,g=h.active_canvas.getCanvasWindow(),e=null,c={event:b,callback:function(b,e,g){if(b)if("Remove Slot"==b.content)b=b.slot,b.input?a.removeInput(b.slot):b.output&&a.removeOutput(b.slot);else if("Disconnect Links"==b.content)b=b.slot,b.output?a.disconnectOutput(b.slot):b.input&&a.disconnectInput(b.slot);else if("Rename Slot"==b.content){b=b.slot;var f=b.input?a.getInputInfo(b.slot):a.getOutputInfo(b.slot),
c=d.createDialog("<span class='name'>Name</span><input autofocus type='text'/><button>OK</button>",e),k=c.querySelector("input");k&&f&&(k.value=f.label||"");c.querySelector("button").addEventListener("click",function(a){k.value&&(f&&(f.label=k.value),d.setDirty(!0));c.close()})}},extra:a};a&&(c.title=a.type);var k=null;a&&(k=a.getSlotInPosition(b.canvasX,b.canvasY),h.active_node=a);if(k){e=[];if(a.getSlotMenuOptions)e=a.getSlotMenuOptions(k);else{k&&k.output&&k.output.links&&k.output.links.length&&
e.push({content:"Disconnect Links",slot:k});var s=k.input||k.output;e.push(s.locked?"Cannot remove":{content:"Remove Slot",slot:k});e.push(s.nameLocked?"Cannot rename":{content:"Rename Slot",slot:k})}c.title=(k.input?k.input.type:k.output.type)||"*";k.input&&k.input.type==f.ACTION&&(c.title="Action");k.output&&k.output.type==f.EVENT&&(c.title="Event")}else a?e=this.getNodeMenuOptions(a):(e=this.getCanvasMenuOptions(),(k=this.graph.getGroupOnPos(b.canvasX,b.canvasY))&&e.push(null,{content:"Edit Group",
has_submenu:!0,submenu:{title:"Group",extra:k,options:this.getGroupMenuOptions(k)}}));e&&new f.ContextMenu(e,c,g)};"undefined"!=typeof window&&window.CanvasRenderingContext2D&&(window.CanvasRenderingContext2D.prototype.roundRect=function(a,b,d,g,e,f){void 0===e&&(e=5);void 0===f&&(f=e);this.moveTo(a+e,b);this.lineTo(a+d-e,b);this.quadraticCurveTo(a+d,b,a+d,b+e);this.lineTo(a+d,b+g-f);this.quadraticCurveTo(a+d,b+g,a+d-f,b+g);this.lineTo(a+f,b+g);this.quadraticCurveTo(a,b+g,a,b+g-f);this.lineTo(a,b+
e);this.quadraticCurveTo(a,b,a+e,b)});f.compareObjects=function(a,b){for(var d in a)if(a[d]!=b[d])return!1;return!0};f.distance=C;f.colorToString=function(a){return"rgba("+Math.round(255*a[0]).toFixed()+","+Math.round(255*a[1]).toFixed()+","+Math.round(255*a[2]).toFixed()+","+(4==a.length?a[3].toFixed(2):"1.0")+")"};f.isInsideRectangle=x;f.growBounding=function(a,b,d){b<a[0]?a[0]=b:b>a[2]&&(a[2]=b);d<a[1]?a[1]=d:d>a[3]&&(a[3]=d)};f.isInsideBounding=function(a,b){return a[0]<b[0][0]||a[1]<b[0][1]||
a[0]>b[1][0]||a[1]>b[1][1]?!1:!0};f.overlapBounding=G;f.hex2num=function(a){"#"==a.charAt(0)&&(a=a.slice(1));a=a.toUpperCase();for(var b=Array(3),d=0,g,e,f=0;6>f;f+=2)g="0123456789ABCDEF".indexOf(a.charAt(f)),e="0123456789ABCDEF".indexOf(a.charAt(f+1)),b[d]=16*g+e,d++;return b};f.num2hex=function(a){for(var b="#",d,g,e=0;3>e;e++)d=a[e]/16,g=a[e]%16,b+="0123456789ABCDEF".charAt(d)+"0123456789ABCDEF".charAt(g);return b};A.prototype.addItem=function(a,b,d){function g(a){var b=this.value;b&&b.has_submenu&&
e.call(this,a)}function e(a){var b=this.value,e=!0;f.current_submenu&&f.current_submenu.close(a);if(d.callback){var g=d.callback.call(this,b,d,a,f,d.node);!0===g&&(e=!1)}if(b&&(b.callback&&!d.ignore_item_callbacks&&!0!==b.disabled&&(g=b.callback.call(this,b,d,a,f,d.extra),!0===g&&(e=!1)),b.submenu)){if(!b.submenu.options)throw"ContextMenu submenu needs options";new f.constructor(b.submenu.options,{callback:b.submenu.callback,event:a,parentMenu:f,ignore_item_callbacks:b.submenu.ignore_item_callbacks,
title:b.submenu.title,extra:b.submenu.extra,autoopen:d.autoopen});e=!1}e&&!f.lock&&f.close()}var f=this;d=d||{};var c=document.createElement("div");c.className="litemenu-entry submenu";var k=!1;if(null===b)c.classList.add("separator");else{c.innerHTML=b&&b.title?b.title:a;if(c.value=b)b.disabled&&(k=!0,c.classList.add("disabled")),(b.submenu||b.has_submenu)&&c.classList.add("has_submenu");"function"==typeof b?(c.dataset.value=a,c.onclick_callback=b):c.dataset.value=b;b.className&&(c.className+=" "+
b.className)}this.root.appendChild(c);k||c.addEventListener("click",e);d.autoopen&&c.addEventListener("mouseenter",g);return c};A.prototype.close=function(a,b){this.root.parentNode&&this.root.parentNode.removeChild(this.root);this.parentMenu&&!b&&(this.parentMenu.lock=!1,this.parentMenu.current_submenu=null,void 0===a?this.parentMenu.close():a&&!A.isCursorOverElement(a,this.parentMenu.root)&&A.trigger(this.parentMenu.root,"mouseleave",a));this.current_submenu&&this.current_submenu.close(a,!0);this.root.closing_timer&&
clearTimeout(this.root.closing_timer)};A.trigger=function(a,b,d,g){var e=document.createEvent("CustomEvent");e.initCustomEvent(b,!0,!0,d);e.srcElement=g;a.dispatchEvent?a.dispatchEvent(e):a.__events&&a.__events.dispatchEvent(e);return e};A.prototype.getTopMenu=function(){return this.options.parentMenu?this.options.parentMenu.getTopMenu():this};A.prototype.getFirstEvent=function(){return this.options.parentMenu?this.options.parentMenu.getFirstEvent():this.options.event};A.isCursorOverElement=function(a,
b){var d=a.clientX,g=a.clientY,e=b.getBoundingClientRect();return e?g>e.top&&g<e.top+e.height&&d>e.left&&d<e.left+e.width?!0:!1:!1};f.ContextMenu=A;f.closeAllContextMenus=function(a){a=a||window;a=a.document.querySelectorAll(".litecontextmenu");if(a.length){for(var b=[],d=0;d<a.length;d++)b.push(a[d]);for(d=0;d<b.length;d++)b[d].close?b[d].close():b[d].parentNode&&b[d].parentNode.removeChild(b[d])}};f.extendClass=function(a,b){for(var d in b)a.hasOwnProperty(d)||(a[d]=b[d]);if(b.prototype)for(d in b.prototype)b.prototype.hasOwnProperty(d)&&
!a.prototype.hasOwnProperty(d)&&(b.prototype.__lookupGetter__(d)?a.prototype.__defineGetter__(d,b.prototype.__lookupGetter__(d)):a.prototype[d]=b.prototype[d],b.prototype.__lookupSetter__(d)&&a.prototype.__defineSetter__(d,b.prototype.__lookupSetter__(d)))};D.sampleCurve=function(a,b){if(b){for(var d=0;d<b.length-1;++d){var g=b[d],e=b[d+1];if(!(e[0]<a)){d=e[0]-g[0];if(1E-5>Math.abs(d))return g[1];d=(a-g[0])/d;return g[1]*(1-d)+e[1]*d}}return 0}};D.prototype.draw=function(a,b,d,g,e,f){if(d=this.points){this.size=
b;var c=b[0]-2*this.margin;b=b[1]-2*this.margin;e=e||"#666";a.save();a.translate(this.margin,this.margin);g&&(a.fillStyle="#111",a.fillRect(0,0,c,b),a.fillStyle="#222",a.fillRect(0.5*c,0,1,b),a.strokeStyle="#333",a.strokeRect(0,0,c,b));a.strokeStyle=e;f&&(a.globalAlpha=0.5);a.beginPath();for(g=0;g<d.length;++g)e=d[g],a.lineTo(e[0]*c,(1-e[1])*b);a.stroke();a.globalAlpha=1;if(!f)for(g=0;g<d.length;++g)e=d[g],a.fillStyle=this.selected==g?"#FFF":this.nearest==g?"#DDD":"#AAA",a.beginPath(),a.arc(e[0]*
c,(1-e[1])*b,2,0,2*Math.PI),a.fill();a.restore()}};D.prototype.onMouseDown=function(a,b){var d=this.points;if(d&&!(0>a[1])){var g=this.size[0]-2*this.margin,e=this.size[1]-2*this.margin,f=a[0]-this.margin,c=a[1]-this.margin;this.selected=this.getCloserPoint([f,c],30/b.ds.scale);-1==this.selected&&(g=[f/g,1-c/e],d.push(g),d.sort(function(a,b){return a[0]-b[0]}),this.selected=d.indexOf(g),this.must_update=!0);if(-1!=this.selected)return!0}};D.prototype.onMouseMove=function(a,b){var d=this.points;if(d){var g=
this.selected;if(!(0>g)){var e=(a[0]-this.margin)/(this.size[0]-2*this.margin),f=(a[1]-this.margin)/(this.size[1]-2*this.margin);this._nearest=this.getCloserPoint([a[0]-this.margin,a[1]-this.margin],30/b.ds.scale);var c=d[g];if(c){var k=0==g||g==d.length-1;!k&&(-10>a[0]||a[0]>this.size[0]+10||-10>a[1]||a[1]>this.size[1]+10)?(d.splice(g,1),this.selected=-1):(c[0]=k?0==g?0:1:Math.clamp(e,0,1),c[1]=1-Math.clamp(f,0,1),d.sort(function(a,b){return a[0]-b[0]}),this.selected=d.indexOf(c),this.must_update=
!0)}}}};D.prototype.onMouseUp=function(a,b){this.selected=-1;return!1};D.prototype.getCloserPoint=function(a,b){var d=this.points;if(!d)return-1;b=b||30;for(var g=this.size[0]-2*this.margin,e=this.size[1]-2*this.margin,f=d.length,c=[0,0],k=1E6,n=-1,q=0;q<f;++q){var h=d[q];c[0]=h[0]*g;c[1]=(1-h[1])*e;h=vec2.distance(a,c);h>k||h>b||(n=q,k=h)}return n};f.CurveEditor=D;f.getParameterNames=function(a){return(a+"").replace(/[/][/].*$/gm,"").replace(/\s+/g,"").replace(/[/][*][^/*]*[*][/]/g,"").split("){",
1)[0].replace(/^[^(]*[(]/,"").replace(/=[^,]+/g,"").split(",").filter(Boolean)};Math.clamp=function(a,b,d){return b>a?b:d<a?d:a};"undefined"==typeof window||window.requestAnimationFrame||(window.requestAnimationFrame=window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(a){window.setTimeout(a,1E3/60)})})(this);"undefined"!=typeof exports&&(exports.LiteGraph=this.LiteGraph);
(function(B){function c(){this.addOutput("in ms","number");this.addOutput("in sec","number")}function l(){this.size=[140,80];this.properties={enabled:!0};this.enabled=!0;this.subgraph=new m.LGraph;this.subgraph._subgraph_node=this;this.subgraph._is_subgraph=!0;this.subgraph.onTrigger=this.onSubgraphTrigger.bind(this);this.subgraph.onInputAdded=this.onSubgraphNewInput.bind(this);this.subgraph.onInputRenamed=this.onSubgraphRenamedInput.bind(this);this.subgraph.onInputTypeChanged=this.onSubgraphTypeChangeInput.bind(this);
this.subgraph.onInputRemoved=this.onSubgraphRemovedInput.bind(this);this.subgraph.onOutputAdded=this.onSubgraphNewOutput.bind(this);this.subgraph.onOutputRenamed=this.onSubgraphRenamedOutput.bind(this);this.subgraph.onOutputTypeChanged=this.onSubgraphTypeChangeOutput.bind(this);this.subgraph.onOutputRemoved=this.onSubgraphRemovedOutput.bind(this)}function u(){this.addOutput("","number");this.name_in_graph="";this.properties={name:"",type:"number",value:0};var a=this;this.name_widget=this.addWidget("text",
"Name",this.properties.name,function(b){b&&a.setProperty("name",b)});this.type_widget=this.addWidget("text","Type",this.properties.type,function(b){a.setProperty("type",b)});this.value_widget=this.addWidget("number","Value",this.properties.value,function(b){a.setProperty("value",b)});this.widgets_up=!0;this.size=[180,90]}function r(){this.addInput("","");this.name_in_graph="";this.properties={};var a=this;Object.defineProperty(this.properties,"name",{get:function(){return a.name_in_graph},set:function(b){""!=

View File

@@ -298,7 +298,24 @@ MyNode.prototype.onAction = function(action, data)
There are some nodes already available to handle events, like delaying, counting, etc.
### Customising Link Tooltips
When hovering over a link that connects two nodes together, a tooltip will be shown allowing the user to see the data that is being output from one node to the other.
Sometimes, you may have a node that outputs an object, rather than a primitive value that can be easily represented (like a string). In these instances, the tooltip will default to showing `[Object]`.
If you need a more descriptive tooltip, you can achieve this by adding a `toToolTip` function to your object which returns the text you wish to display in the tooltip.
For example, to ensure the link from output slot 0 shows `A useful description`, the output object would look like this:
```javascript
this.setOutputData(0, {
complexObject: {
yes: true,
},
toToolTip: () => 'A useful description',
});
```

View File

@@ -24,6 +24,7 @@
NODE_COLLAPSED_RADIUS: 10,
NODE_COLLAPSED_WIDTH: 80,
NODE_TITLE_COLOR: "#999",
NODE_SELECTED_TITLE_COLOR: "#FFF",
NODE_TEXT_SIZE: 14,
NODE_TEXT_COLOR: "#AAA",
NODE_SUBTEXT_SIZE: 12,
@@ -31,13 +32,14 @@
NODE_DEFAULT_BGCOLOR: "#353535",
NODE_DEFAULT_BOXCOLOR: "#666",
NODE_DEFAULT_SHAPE: "box",
NODE_BOX_OUTLINE_COLOR: "#FFF",
DEFAULT_SHADOW_COLOR: "rgba(0,0,0,0.5)",
DEFAULT_GROUP_FONT: 24,
WIDGET_BGCOLOR: "#222",
WIDGET_OUTLINE_COLOR: "#666",
WIDGET_TEXT_COLOR: "#DDD",
WIDGET_SECONDARY_TEXT_COLOR: "#999",
WIDGET_BGCOLOR: "#222",
WIDGET_OUTLINE_COLOR: "#666",
WIDGET_TEXT_COLOR: "#DDD",
WIDGET_SECONDARY_TEXT_COLOR: "#999",
LINK_COLOR: "#9A9",
EVENT_LINK_COLOR: "#A86",
@@ -94,6 +96,7 @@
Globals: {}, //used to store vars between graphs
searchbox_extras: {}, //used to add extra features to the search box
auto_sort_node_types: false, // If set to true, will automatically sort node types / categories in the context menus
/**
* Register a node class so it can be listed when the user wants to create a new one
@@ -414,7 +417,7 @@
}
}
return r;
return this.auto_sort_node_types ? r.sort() : r;
},
/**
@@ -438,7 +441,7 @@
for (var i in categories) {
result.push(i);
}
return result;
return this.auto_sort_node_types ? result.sort() : result;
},
//debug purposes: reloads all the js scripts that matches a wildcard
@@ -7964,7 +7967,7 @@ LGraphNode.prototype.executeAction = function(action)
var title = String(node.getTitle());
if (title) {
if (selected) {
ctx.fillStyle = "white";
ctx.fillStyle = LiteGraph.NODE_SELECTED_TITLE_COLOR;
} else {
ctx.fillStyle =
node.constructor.title_text_color ||
@@ -8067,7 +8070,7 @@ LGraphNode.prototype.executeAction = function(action)
Math.PI * 2
);
}
ctx.strokeStyle = "#FFF";
ctx.strokeStyle = LiteGraph.NODE_BOX_OUTLINE_COLOR;
ctx.stroke();
ctx.strokeStyle = fgcolor;
ctx.globalAlpha = 1;
@@ -9450,7 +9453,7 @@ LGraphNode.prototype.executeAction = function(action)
entries.push({
content:
"<span class='property_name'>" +
i +
(info.label ? info.label : i) +
"</span>" +
"<span class='property_value'>" +
value +
@@ -10048,7 +10051,7 @@ LGraphNode.prototype.executeAction = function(action)
var dialog = this.createDialog(
"<span class='name'>" +
property +
(info.label ? info.label : property) +
"</span>" +
input_html +
"<button>OK</button>",
@@ -10075,8 +10078,12 @@ LGraphNode.prototype.executeAction = function(action)
input.addEventListener("blur", function(e) {
this.focus();
});
var v = node.properties[property] !== undefined ? node.properties[property] : "";
v = JSON.stringify(v);
if (type !== 'string') {
v = JSON.stringify(v);
}
input.value = v;
input.addEventListener("keydown", function(e) {
if (e.keyCode != 13) {