This commit is contained in:
tamat
2020-02-15 01:45:16 +01:00
parent 5cef341c29
commit b550042709
4 changed files with 36 additions and 36 deletions

View File

@@ -192,9 +192,9 @@
//used to know which nodes create when dragging files to the canvas
if (base_class.supported_extensions) {
for (var i in base_class.supported_extensions) {
this.node_types_by_file_extension[
base_class.supported_extensions[i].toLowerCase()
] = base_class;
var ext = base_class.supported_extensions[i];
if(ext && ext.constructor === String)
this.node_types_by_file_extension[ ext.toLowerCase() ] = base_class;
}
}
},

View File

@@ -13,35 +13,35 @@ NODE_COLLAPSED_WIDTH:80,NODE_TITLE_COLOR:"#999",NODE_TEXT_SIZE:14,NODE_TEXT_COLO
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:{},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;g.debug&&console.log("Node registered: "+a);a.split("/");var d=b.name,k=a.lastIndexOf("/");b.category=a.substr(0,k);b.title||(b.title=d);if(b.prototype)for(var f in n.prototype)b.prototype[f]||(b.prototype[f]=n.prototype[f]);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=g.BOX_SHAPE;break;case "round":this._shape=g.ROUND_SHAPE;break;case "circle":this._shape=g.CIRCLE_SHAPE;break;case "card":this._shape=g.CARD_SHAPE;break;default:this._shape=a}},get:function(a){return this._shape},enumerable:!0});(k=this.registered_node_types[a])&&console.log("replacing node type: "+a);this.registered_node_types[a]=b;b.constructor.name&&(this.Nodes[d]=b);if(g.onNodeTypeRegistered)g.onNodeTypeRegistered(a,b);if(k&&g.onNodeTypeReplaced)g.onNodeTypeReplaced(a,
b,k);b.prototype.onPropertyChange&&console.warn("LiteGraph node class "+a+" has onPropertyChange method, it must be called onPropertyChanged with d at the end");if(b.supported_extensions)for(f in b.supported_extensions)this.node_types_by_file_extension[b.supported_extensions[f].toLowerCase()]=b},wrapFunctionAsNode:function(a,b,d,k,f){for(var h=Array(b.length),w="",c=g.getParameterNames(b),e=0;e<c.length;++e)w+="this.addInput('"+c[e]+"',"+(d&&d[e]?"'"+d[e]+"'":"0")+");\n";w+="this.addOutput('out',"+
(k?"'"+k+"'":0)+");\n";f&&(w+="this.properties = "+JSON.stringify(f)+";\n");d=Function(w);d.title=a.split("/").pop();d.desc="Generated from "+b.name;d.prototype.onExecute=function(){for(var a=0;a<h.length;++a)h[a]=this.getInputData(a);a=b.apply(this,h);this.setOutputData(0,a)};this.registerNodeType(a,d)},addNodeMethod:function(a,b){n.prototype[a]=b;for(var d in this.registered_node_types){var k=this.registered_node_types[d];k.prototype[a]&&(k.prototype["_"+a]=k.prototype[a]);k.prototype[a]=b}},createNode:function(a,
b,d){var k=this.registered_node_types[a];if(!k)return g.debug&&console.log('GraphNode type "'+a+'" not registered.'),null;b=b||k.title||a;var f=null;if(g.catch_exceptions)try{f=new k(b)}catch(h){return console.error(h),null}else f=new k(b);f.type=a;!f.title&&b&&(f.title=b);f.properties||(f.properties={});f.properties_info||(f.properties_info=[]);f.flags||(f.flags={});f.size||(f.size=f.computeSize());f.pos||(f.pos=g.DEFAULT_POSITION.concat());f.mode||(f.mode=g.ALWAYS);if(d)for(var w in d)f[w]=d[w];
return f},getNodeType:function(a){return this.registered_node_types[a]},getNodeTypesInCategory:function(a,b){var d=[],k;for(k in this.registered_node_types){var f=this.registered_node_types[k];b&&f.filter&&f.filter!=b||(""==a?null==f.category&&d.push(f):f.category==a&&d.push(f))}return d},getNodeTypesCategories:function(a){var b={"":1},d;for(d in this.registered_node_types){var k=this.registered_node_types[d];!k.category||k.skip_list||a&&k.filter!=a||(b[k.category]=1)}a=[];for(d in b)a.push(d);return a},
reloadNodes:function(a){var b=document.getElementsByTagName("script"),d=[],k;for(k in b)d.push(b[k]);b=document.getElementsByTagName("head")[0];a=document.location.href+a;for(k in d){var f=d[k].src;if(f&&f.substr(0,a.length)==a)try{g.debug&&console.log("Reloading: "+f);var h=document.createElement("script");h.type="text/javascript";h.src=f;b.appendChild(h);b.removeChild(d[k])}catch(w){if(g.throw_errors)throw w;g.debug&&console.log("Error while reloading "+f)}}g.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 k in d)b[k]=d[k];return b},isValidConnection:function(a,b){if(!a||!b||a==b||a==g.EVENT&&b==g.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(","),k=b.split(","),f=0;f<d.length;++f)for(var h=0;h<k.length;++h)if(d[f]==k[h])return!0;return!1},registerSearchboxExtra:function(a,b,d){this.searchbox_extras[b.toLowerCase()]=
{type:a,desc:b,data:d}}};g.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()};y.LGraph=g.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.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!=e)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=g.getTime();a=a||0;var b=this;if(0==a&&"undefined"!=typeof window&&window.requestAnimationFrame){var d=function(){-1==b.execution_timer_id&&(window.requestAnimationFrame(d),b.runStep(1,!this.catch_errors))};this.execution_timer_id=-1;d()}else this.execution_timer_id=setInterval(function(){b.runStep(1,
!this.catch_errors)},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 k=g.getTime();this.globaltime=0.001*(k-this.starttime);var f=this._nodes_executable?this._nodes_executable:this._nodes;if(f){d=d||f.length;
if(b){for(var h=0;h<a;h++){for(var w=0;w<d;++w){var c=f[w];if(c.mode==g.ALWAYS&&c.onExecute)c.onExecute()}this.fixedtime+=this.fixedtime_lapse;if(this.onExecuteStep)this.onExecuteStep()}if(this.onAfterExecute)this.onAfterExecute()}else try{for(h=0;h<a;h++){for(w=0;w<d;++w)if(c=f[w],c.mode==g.ALWAYS&&c.onExecute)c.onExecute();this.fixedtime+=this.fixedtime_lapse;if(this.onExecuteStep)this.onExecuteStep()}if(this.onAfterExecute)this.onAfterExecute();this.errors_in_execution=!1}catch(e){this.errors_in_execution=
!0;if(g.throw_errors)throw e;g.debug&&console.log("Error during execution: "+e);this.stop()}a=g.getTime();k=a-k;0==k&&(k=1);this.execution_time=0.001*k;this.globaltime+=0.001*k;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=[],k=[],f={},h={},w={},c=0,e=this._nodes.length;c<e;++c){var r=this._nodes[c];if(!a||r.onExecute){f[r.id]=r;var s=0;if(r.inputs)for(var u=0,p=r.inputs.length;u<p;u++)r.inputs[u]&&null!=r.inputs[u].link&&(s+=1);0==s?(k.push(r),b&&(r._level=1)):(b&&(r._level=0),w[r.id]=s)}}for(;0!=k.length;)if(r=k.shift(),d.push(r),delete f[r.id],r.outputs)for(c=0;c<r.outputs.length;c++)if(e=r.outputs[c],null!=e&&null!=e.links&&0!=e.links.length)for(u=0;u<e.links.length;u++)(s=
this.links[e.links[u]])&&!h[s.id]&&(p=this.getNodeById(s.target_id),null==p?h[s.id]=!0:(b&&(!p._level||p._level<=r._level)&&(p._level=r._level+1),h[s.id]=!0,w[p.id]-=1,0==w[p.id]&&k.push(p)));for(c in f)d.push(f[c]);d.length!=this._nodes.length&&g.debug&&console.warn("something went wrong, nodes missing");e=d.length;for(c=0;c<e;++c)d[c].order=c;d=d.sort(function(a,b){var d=a.constructor.priority||a.priority||0,f=b.constructor.priority||b.priority||0;return d==f?a.order-b.order:d-f});for(c=0;c<e;++c)d[c].order=
c;return d};c.prototype.getAncestors=function(a){for(var b=[],d=[a],k={};d.length;){var f=d.shift();if(f.inputs){k[f.id]||f==a||(k[f.id]=!0,b.push(f));for(var g=0;g<f.inputs.length;++g){var w=f.getInputNode(g);w&&-1==b.indexOf(w)&&d.push(w)}}}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=[],k=0;k<b.length;++k){var f=b[k],h=f._level||1;d[h]||(d[h]=[]);d[h].push(f)}b=a;for(k=0;k<d.length;++k)if(h=d[k]){for(var w=
100,c=a+g.NODE_TITLE_HEIGHT,e=0;e<h.length;++e)f=h[e],f.pos[0]=b,f.pos[1]=c,f.size[0]>w&&(w=f.size[0]),c+=f.size[1]+a+g.NODE_TITLE_HEIGHT;b+=w+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||g.ALWAYS;var k=this._nodes_in_order?this._nodes_in_order:this._nodes;if(k)for(var f=0,h=k.length;f<
h;++f){var w=k[f];if(w.constructor===g.Subgraph&&"onExecute"!=a)w.mode==d&&w.sendEventToAllNodes(a,b,d);else if(w[a]&&w.mode==d)if(void 0===b)w[a]();else if(b&&b.constructor===Array)w[a].apply(w,b);else w[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 k=this.list_of_graphcanvas[d];k[a]&&k[a].apply(k,b)}};c.prototype.add=function(a,b){if(a)if(a.constructor===l)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>=g.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===g.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.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,k=this._nodes.length;d<k;++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,k=this._nodes.length;d<k;++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,k=this._nodes.length;d<k;++d)this._nodes[d].title==a&&b.push(this._nodes[d]);return b};c.prototype.getNodeOnPos=function(a,b,d,k){d=d||this._nodes;for(var f=d.length-1;0<=f;f--){var g=d[f];if(g.isPointInside(a,b,k))return g}return null};c.prototype.getGroupOnPos=function(a,b){for(var d=this._groups.length-1;0<=d;d--){var k=this._groups[d];
if(k.isPointInside(a,b,2,!0))return k}return null};c.prototype.checkNodeTypes=function(){for(var a=0;a<this._nodes.length;a++){var b=this._nodes[a];if(b.constructor!=g.registered_node_types[b.type]){console.log("node being replaced by newer version: "+b.type);var d=g.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(g.GraphInput,this._input_nodes);for(var d=0;d<this._input_nodes.length;++d){var k=this._input_nodes[d];if(k.properties.name==a){k.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.inputs[a]={name:a,type:b,value:d};this._version++;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);
b,k);b.prototype.onPropertyChange&&console.warn("LiteGraph node class "+a+" has onPropertyChange method, it must be called onPropertyChanged with d at the end");if(b.supported_extensions)for(f in b.supported_extensions)(d=b.supported_extensions[f])&&d.constructor===String&&(this.node_types_by_file_extension[d.toLowerCase()]=b)},wrapFunctionAsNode:function(a,b,d,k,f){for(var h=Array(b.length),w="",c=g.getParameterNames(b),e=0;e<c.length;++e)w+="this.addInput('"+c[e]+"',"+(d&&d[e]?"'"+d[e]+"'":"0")+
");\n";w+="this.addOutput('out',"+(k?"'"+k+"'":0)+");\n";f&&(w+="this.properties = "+JSON.stringify(f)+";\n");d=Function(w);d.title=a.split("/").pop();d.desc="Generated from "+b.name;d.prototype.onExecute=function(){for(var a=0;a<h.length;++a)h[a]=this.getInputData(a);a=b.apply(this,h);this.setOutputData(0,a)};this.registerNodeType(a,d)},addNodeMethod:function(a,b){n.prototype[a]=b;for(var d in this.registered_node_types){var k=this.registered_node_types[d];k.prototype[a]&&(k.prototype["_"+a]=k.prototype[a]);
k.prototype[a]=b}},createNode:function(a,b,d){var k=this.registered_node_types[a];if(!k)return g.debug&&console.log('GraphNode type "'+a+'" not registered.'),null;b=b||k.title||a;var f=null;if(g.catch_exceptions)try{f=new k(b)}catch(h){return console.error(h),null}else f=new k(b);f.type=a;!f.title&&b&&(f.title=b);f.properties||(f.properties={});f.properties_info||(f.properties_info=[]);f.flags||(f.flags={});f.size||(f.size=f.computeSize());f.pos||(f.pos=g.DEFAULT_POSITION.concat());f.mode||(f.mode=
g.ALWAYS);if(d)for(var w in d)f[w]=d[w];return f},getNodeType:function(a){return this.registered_node_types[a]},getNodeTypesInCategory:function(a,b){var d=[],k;for(k in this.registered_node_types){var f=this.registered_node_types[k];b&&f.filter&&f.filter!=b||(""==a?null==f.category&&d.push(f):f.category==a&&d.push(f))}return d},getNodeTypesCategories:function(a){var b={"":1},d;for(d in this.registered_node_types){var k=this.registered_node_types[d];!k.category||k.skip_list||a&&k.filter!=a||(b[k.category]=
1)}a=[];for(d in b)a.push(d);return a},reloadNodes:function(a){var b=document.getElementsByTagName("script"),d=[],k;for(k in b)d.push(b[k]);b=document.getElementsByTagName("head")[0];a=document.location.href+a;for(k in d){var f=d[k].src;if(f&&f.substr(0,a.length)==a)try{g.debug&&console.log("Reloading: "+f);var h=document.createElement("script");h.type="text/javascript";h.src=f;b.appendChild(h);b.removeChild(d[k])}catch(w){if(g.throw_errors)throw w;g.debug&&console.log("Error while reloading "+f)}}g.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 k in d)b[k]=d[k];return b},isValidConnection:function(a,b){if(!a||!b||a==b||a==g.EVENT&&b==g.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(","),k=b.split(","),f=0;f<d.length;++f)for(var h=0;h<k.length;++h)if(d[f]==k[h])return!0;return!1},registerSearchboxExtra:function(a,
b,d){this.searchbox_extras[b.toLowerCase()]={type:a,desc:b,data:d}}};g.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()};y.LGraph=g.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.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!=e)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=g.getTime();a=a||0;var b=this;if(0==a&&"undefined"!=typeof window&&window.requestAnimationFrame){var d=function(){-1==b.execution_timer_id&&(window.requestAnimationFrame(d),b.runStep(1,!this.catch_errors))};this.execution_timer_id=-1;d()}else this.execution_timer_id=
setInterval(function(){b.runStep(1,!this.catch_errors)},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 k=g.getTime();this.globaltime=0.001*(k-this.starttime);var f=this._nodes_executable?this._nodes_executable:
this._nodes;if(f){d=d||f.length;if(b){for(var h=0;h<a;h++){for(var w=0;w<d;++w){var c=f[w];if(c.mode==g.ALWAYS&&c.onExecute)c.onExecute()}this.fixedtime+=this.fixedtime_lapse;if(this.onExecuteStep)this.onExecuteStep()}if(this.onAfterExecute)this.onAfterExecute()}else try{for(h=0;h<a;h++){for(w=0;w<d;++w)if(c=f[w],c.mode==g.ALWAYS&&c.onExecute)c.onExecute();this.fixedtime+=this.fixedtime_lapse;if(this.onExecuteStep)this.onExecuteStep()}if(this.onAfterExecute)this.onAfterExecute();this.errors_in_execution=
!1}catch(e){this.errors_in_execution=!0;if(g.throw_errors)throw e;g.debug&&console.log("Error during execution: "+e);this.stop()}a=g.getTime();k=a-k;0==k&&(k=1);this.execution_time=0.001*k;this.globaltime+=0.001*k;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=[],k=[],f={},h={},w={},c=0,e=this._nodes.length;c<e;++c){var r=this._nodes[c];if(!a||r.onExecute){f[r.id]=r;var s=0;if(r.inputs)for(var u=0,p=r.inputs.length;u<p;u++)r.inputs[u]&&null!=r.inputs[u].link&&(s+=1);0==s?(k.push(r),b&&(r._level=1)):(b&&(r._level=0),w[r.id]=s)}}for(;0!=k.length;)if(r=k.shift(),d.push(r),delete f[r.id],r.outputs)for(c=0;c<r.outputs.length;c++)if(e=r.outputs[c],
null!=e&&null!=e.links&&0!=e.links.length)for(u=0;u<e.links.length;u++)(s=this.links[e.links[u]])&&!h[s.id]&&(p=this.getNodeById(s.target_id),null==p?h[s.id]=!0:(b&&(!p._level||p._level<=r._level)&&(p._level=r._level+1),h[s.id]=!0,w[p.id]-=1,0==w[p.id]&&k.push(p)));for(c in f)d.push(f[c]);d.length!=this._nodes.length&&g.debug&&console.warn("something went wrong, nodes missing");e=d.length;for(c=0;c<e;++c)d[c].order=c;d=d.sort(function(a,b){var d=a.constructor.priority||a.priority||0,f=b.constructor.priority||
b.priority||0;return d==f?a.order-b.order:d-f});for(c=0;c<e;++c)d[c].order=c;return d};c.prototype.getAncestors=function(a){for(var b=[],d=[a],k={};d.length;){var f=d.shift();if(f.inputs){k[f.id]||f==a||(k[f.id]=!0,b.push(f));for(var g=0;g<f.inputs.length;++g){var w=f.getInputNode(g);w&&-1==b.indexOf(w)&&d.push(w)}}}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=[],k=0;k<b.length;++k){var f=b[k],h=f._level||
1;d[h]||(d[h]=[]);d[h].push(f)}b=a;for(k=0;k<d.length;++k)if(h=d[k]){for(var w=100,c=a+g.NODE_TITLE_HEIGHT,e=0;e<h.length;++e)f=h[e],f.pos[0]=b,f.pos[1]=c,f.size[0]>w&&(w=f.size[0]),c+=f.size[1]+a+g.NODE_TITLE_HEIGHT;b+=w+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||g.ALWAYS;var k=this._nodes_in_order?
this._nodes_in_order:this._nodes;if(k)for(var f=0,h=k.length;f<h;++f){var w=k[f];if(w.constructor===g.Subgraph&&"onExecute"!=a)w.mode==d&&w.sendEventToAllNodes(a,b,d);else if(w[a]&&w.mode==d)if(void 0===b)w[a]();else if(b&&b.constructor===Array)w[a].apply(w,b);else w[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 k=this.list_of_graphcanvas[d];k[a]&&k[a].apply(k,b)}};c.prototype.add=function(a,b){if(a)if(a.constructor===
l)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>=g.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===g.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.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,k=this._nodes.length;d<k;++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,k=this._nodes.length;d<k;++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,k=this._nodes.length;d<k;++d)this._nodes[d].title==a&&b.push(this._nodes[d]);return b};c.prototype.getNodeOnPos=function(a,b,d,k){d=d||this._nodes;for(var f=d.length-1;0<=f;f--){var g=d[f];if(g.isPointInside(a,b,k))return g}return null};c.prototype.getGroupOnPos=function(a,b){for(var d=this._groups.length-
1;0<=d;d--){var k=this._groups[d];if(k.isPointInside(a,b,2,!0))return k}return null};c.prototype.checkNodeTypes=function(){for(var a=0;a<this._nodes.length;a++){var b=this._nodes[a];if(b.constructor!=g.registered_node_types[b.type]){console.log("node being replaced by newer version: "+b.type);var d=g.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(g.GraphInput,this._input_nodes);for(var d=0;d<this._input_nodes.length;++d){var k=this._input_nodes[d];if(k.properties.name==a){k.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.inputs[a]={name:a,type:b,value:d};this._version++;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),k=0;k<d.length;++k)d[k].onTrigger(b)};c.prototype.setCallback=function(a,b){for(var d=this.findNodesByTitle(a),k=0;k<d.length;++k)d[k].setTrigger(b)};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(){g.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 k=this.links[b];if(!k.serialize){console.warn("weird LLink bug, link info is not a LLink but a regular object");var f=new m;for(b in k)f[b]=k[b];k=this.links[b]=f}d.push(k.serialize())}k=[];for(b=0;b<this._groups.length;++b)k.push(this._groups[b].serialize());return{last_node_id:this.last_node_id,