mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-02 22:37:32 +00:00
fixed bug in context menu when fullscreen
This commit is contained in:
@@ -10255,7 +10255,11 @@ LGraphNode.prototype.executeAction = function(action)
|
||||
if (!root_document) {
|
||||
root_document = document;
|
||||
}
|
||||
root_document.body.appendChild(root);
|
||||
|
||||
if( root_document.fullscreenElement )
|
||||
root_document.fullscreenElement.appendChild(root);
|
||||
else
|
||||
root_document.body.appendChild(root);
|
||||
|
||||
//compute best position
|
||||
var left = options.left || 0;
|
||||
|
||||
444
build/litegraph.min.js
vendored
444
build/litegraph.min.js
vendored
@@ -7,228 +7,228 @@ this.visible_links=[];b&&b.attachCanvas(this);this.setCanvas(a);this.clear();d.s
|
||||
"px";a.preventDefault();return!0}this.options=b=b||{};var x=this;b.parentMenu&&(b.parentMenu.constructor!==this.constructor?(console.error("parentMenu must be of class ContextMenu, ignoring it"),b.parentMenu=null):(this.parentMenu=b.parentMenu,this.parentMenu.lock=!0,this.parentMenu.current_submenu=this));b.event&&b.event.constructor!==MouseEvent&&b.event.constructor!==CustomEvent&&(console.error("Event passed to ContextMenu is not of type MouseEvent or CustomEvent. Ignoring it."),b.event=null);var e=
|
||||
document.createElement("div");e.className="litegraph litecontextmenu litemenubar-panel";b.className&&(e.className+=" "+b.className);e.style.minWidth=100;e.style.minHeight=100;e.style.pointerEvents="none";setTimeout(function(){e.style.pointerEvents="auto"},100);e.addEventListener("mouseup",function(a){a.preventDefault();return!0},!0);e.addEventListener("contextmenu",function(a){if(2!=a.button)return!1;a.preventDefault();return!1},!0);e.addEventListener("mousedown",function(a){if(2==a.button)return x.close(),
|
||||
a.preventDefault(),!0},!0);b.scroll_speed||(b.scroll_speed=0.1);e.addEventListener("wheel",d,!0);e.addEventListener("mousewheel",d,!0);this.root=e;if(b.title){var c=document.createElement("div");c.className="litemenu-title";c.innerHTML=b.title;e.appendChild(c)}var c=0,A;for(A in a){var h=a.constructor==Array?a[A]:A;null!=h&&h.constructor!==String&&(h=void 0===h.content?String(h):h.content);this.addItem(h,a[A],b);c++}e.addEventListener("mouseleave",function(a){x.lock||(e.closing_timer&&clearTimeout(e.closing_timer),
|
||||
e.closing_timer=setTimeout(x.close.bind(x,a),500))});e.addEventListener("mouseenter",function(a){e.closing_timer&&clearTimeout(e.closing_timer)});A=document;b.event&&(A=b.event.target.ownerDocument);A||(A=document);A.body.appendChild(e);c=b.left||0;A=b.top||0;if(b.event){c=b.event.clientX-10;A=b.event.clientY-10;b.title&&(A-=20);b.parentMenu&&(c=b.parentMenu.root.getBoundingClientRect(),c=c.left+c.width);var h=document.body.getBoundingClientRect(),f=e.getBoundingClientRect();c>h.width-f.width-10&&
|
||||
(c=h.width-f.width-10);A>h.height-f.height-10&&(A=h.height-f.height-10)}e.style.left=c+"px";e.style.top=A+"px";b.scale&&(e.style.transform="scale("+b.scale+")")}var e=v.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:{},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;e.debug&&console.log("Node registered: "+
|
||||
a);a.split("/");var d=b.name,x=a.lastIndexOf("/");b.category=a.substr(0,x);b.title||(b.title=d);if(b.prototype)for(var p in g.prototype)b.prototype[p]||(b.prototype[p]=g.prototype[p]);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=e.BOX_SHAPE;break;case "round":this._shape=e.ROUND_SHAPE;break;case "circle":this._shape=e.CIRCLE_SHAPE;break;case "card":this._shape=e.CARD_SHAPE;
|
||||
break;default:this._shape=a}},get:function(a){return this._shape},enumerable:!0});(x=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(e.onNodeTypeRegistered)e.onNodeTypeRegistered(a,b);if(x&&e.onNodeTypeReplaced)e.onNodeTypeReplaced(a,b,x);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(p in b.supported_extensions)this.node_types_by_file_extension[b.supported_extensions[p].toLowerCase()]=
|
||||
b},wrapFunctionAsNode:function(a,b,d,x,p){for(var c=Array(b.length),A="",h=e.getParameterNames(b),f=0;f<h.length;++f)A+="this.addInput('"+h[f]+"',"+(d&&d[f]?"'"+d[f]+"'":"0")+");\n";A+="this.addOutput('out',"+(x?"'"+x+"'":0)+");\n";p&&(A+="this.properties = "+JSON.stringify(p)+";\n");d=Function(A);d.title=a.split("/").pop();d.desc="Generated from "+b.name;d.prototype.onExecute=function(){for(var a=0;a<c.length;++a)c[a]=this.getInputData(a);a=b.apply(this,c);this.setOutputData(0,a)};this.registerNodeType(a,
|
||||
d)},addNodeMethod:function(a,b){g.prototype[a]=b;for(var d in this.registered_node_types){var e=this.registered_node_types[d];e.prototype[a]&&(e.prototype["_"+a]=e.prototype[a]);e.prototype[a]=b}},createNode:function(a,b,d){var x=this.registered_node_types[a];if(!x)return e.debug&&console.log('GraphNode type "'+a+'" not registered.'),null;b=b||x.title||a;var p=null;if(e.catch_exceptions)try{p=new x(b)}catch(c){return console.error(c),null}else p=new x(b);p.type=a;!p.title&&b&&(p.title=b);p.properties||
|
||||
(p.properties={});p.properties_info||(p.properties_info=[]);p.flags||(p.flags={});p.size||(p.size=p.computeSize());p.pos||(p.pos=e.DEFAULT_POSITION.concat());p.mode||(p.mode=e.ALWAYS);if(d)for(var A in d)p[A]=d[A];return p},getNodeType:function(a){return this.registered_node_types[a]},getNodeTypesInCategory:function(a,b){var d=[],e;for(e in this.registered_node_types){var p=this.registered_node_types[e];b&&p.filter&&p.filter!=b||(""==a?null==p.category&&d.push(p):p.category==a&&d.push(p))}return d},
|
||||
getNodeTypesCategories:function(a){var b={"":1},d;for(d in this.registered_node_types){var e=this.registered_node_types[d];!e.category||e.skip_list||a&&e.filter!=a||(b[e.category]=1)}a=[];for(d in b)a.push(d);return a},reloadNodes:function(a){var b=document.getElementsByTagName("script"),d=[],x;for(x in b)d.push(b[x]);b=document.getElementsByTagName("head")[0];a=document.location.href+a;for(x in d){var p=d[x].src;if(p&&p.substr(0,a.length)==a)try{e.debug&&console.log("Reloading: "+p);var c=document.createElement("script");
|
||||
c.type="text/javascript";c.src=p;b.appendChild(c);b.removeChild(d[x])}catch(A){if(e.throw_errors)throw A;e.debug&&console.log("Error while reloading "+p)}}e.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 e in d)b[e]=d[e];return b},isValidConnection:function(a,b){if(!a||!b||a==b||a==e.EVENT&&b==e.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(","),x=b.split(","),p=0;p<d.length;++p)for(var c=0;c<x.length;++c)if(d[p]==x[c])return!0;return!1},registerSearchboxExtra:function(a,b,d){this.searchbox_extras[b.toLowerCase()]={type:a,desc:b,data:d}}};e.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()};v.LGraph=e.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!=f)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=e.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 x=e.getTime();this.globaltime=0.001*(x-this.starttime);var p=this._nodes_executable?this._nodes_executable:this._nodes;if(p){d=d||p.length;if(b){for(var c=0;c<a;c++){for(var A=0;A<d;++A){var h=p[A];if(h.mode==e.ALWAYS&&h.onExecute)h.onExecute()}this.fixedtime+=this.fixedtime_lapse;if(this.onExecuteStep)this.onExecuteStep()}if(this.onAfterExecute)this.onAfterExecute()}else try{for(c=0;c<a;c++){for(A=0;A<d;++A)if(h=p[A],h.mode==e.ALWAYS&&h.onExecute)h.onExecute();
|
||||
this.fixedtime+=this.fixedtime_lapse;if(this.onExecuteStep)this.onExecuteStep()}if(this.onAfterExecute)this.onAfterExecute();this.errors_in_execution=!1}catch(f){this.errors_in_execution=!0;if(e.throw_errors)throw f;e.debug&&console.log("Error during execution: "+f);this.stop()}a=e.getTime();x=a-x;0==x&&(x=1);this.execution_time=0.001*x;this.globaltime+=0.001*x;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=[],x=[],p={},c={},A={},h=0,f=this._nodes.length;h<f;++h){var k=this._nodes[h];if(!a||k.onExecute){p[k.id]=k;var n=0;if(k.inputs)for(var t=0,B=k.inputs.length;t<B;t++)k.inputs[t]&&null!=k.inputs[t].link&&(n+=1);0==n?(x.push(k),b&&(k._level=1)):(b&&(k._level=
|
||||
0),A[k.id]=n)}}for(;0!=x.length;)if(k=x.shift(),d.push(k),delete p[k.id],k.outputs)for(h=0;h<k.outputs.length;h++)if(f=k.outputs[h],null!=f&&null!=f.links&&0!=f.links.length)for(t=0;t<f.links.length;t++)(n=this.links[f.links[t]])&&!c[n.id]&&(B=this.getNodeById(n.target_id),null==B?c[n.id]=!0:(b&&(!B._level||B._level<=k._level)&&(B._level=k._level+1),c[n.id]=!0,A[B.id]-=1,0==A[B.id]&&x.push(B)));for(h in p)d.push(p[h]);d.length!=this._nodes.length&&e.debug&&console.warn("something went wrong, nodes missing");
|
||||
f=d.length;for(h=0;h<f;++h)d[h].order=h;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(h=0;h<f;++h)d[h].order=h;return d};c.prototype.getAncestors=function(a){for(var b=[],d=[a],e={};d.length;){var p=d.shift();if(p.inputs){e[p.id]||p==a||(e[p.id]=!0,b.push(p));for(var c=0;c<p.inputs.length;++c){var h=p.getInputNode(c);h&&-1==b.indexOf(h)&&d.push(h)}}}b.sort(function(a,b){return a.order-b.order});return b};
|
||||
c.prototype.arrange=function(a){a=a||40;for(var b=this.computeExecutionOrder(!1,!0),d=[],e=0;e<b.length;++e){var p=b[e],c=p._level||1;d[c]||(d[c]=[]);d[c].push(p)}b=a;for(e=0;e<d.length;++e)if(c=d[e]){for(var h=100,f=a,k=0;k<c.length;++k)p=c[k],p.pos[0]=b,p.pos[1]=f,p.size[0]>h&&(h=p.size[0]),f+=p.size[1]+a;b+=h+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||e.ALWAYS;var x=this._nodes_in_order?this._nodes_in_order:this._nodes;if(x)for(var p=0,c=x.length;p<c;++p){var h=x[p];if(h.constructor===e.Subgraph&&"onExecute"!=a)h.mode==d&&h.sendEventToAllNodes(a,b,d);else if(h[a]&&h.mode==d)if(void 0===b)h[a]();else if(b&&b.constructor===Array)h[a].apply(h,b);else h[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 e=this.list_of_graphcanvas[d];
|
||||
e[a]&&e[a].apply(e,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>=e.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===e.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,e=this._nodes.length;d<e;++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,e=this._nodes.length;d<e;++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,e=this._nodes.length;d<e;++d)this._nodes[d].title==a&&b.push(this._nodes[d]);return b};c.prototype.getNodeOnPos=function(a,b,d,e){d=d||this._nodes;for(var p=d.length-1;0<=p;p--){var c=d[p];if(c.isPointInside(a,
|
||||
b,e))return c}return null};c.prototype.getGroupOnPos=function(a,b){for(var d=this._groups.length-1;0<=d;d--){var e=this._groups[d];if(e.isPointInside(a,b,2,!0))return e}return null};c.prototype.checkNodeTypes=function(){for(var a=0;a<this._nodes.length;a++){var b=this._nodes[a];if(b.constructor!=e.registered_node_types[b.type]){console.log("node being replaced by newer version: "+b.type);var d=e.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(e.GraphInput,this._input_nodes);for(var d=0;d<this._input_nodes.length;++d){var x=this._input_nodes[d];if(x.properties.name==a){x.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),e=0;e<d.length;++e)d[e].onTrigger(b)};c.prototype.setCallback=function(a,b){for(var d=this.findNodesByTitle(a),e=0;e<d.length;++e)d[e].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(){e.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 x=this.links[b];if(!x.serialize){console.warn("weird LLink bug, link info is not a LLink but a regular object");var p=new q;for(b in x)p[b]=x[b];
|
||||
x=this.links[b]=p}d.push(x.serialize())}x=[];for(b=0;b<this._groups.length;++b)x.push(this._groups[b].serialize());return{last_node_id:this.last_node_id,last_link_id:this.last_link_id,nodes:a,links:d,groups:x,config:this.config,version:e.VERSION}};c.prototype.configure=function(a,b){if(a){b||this.clear();var d=a.nodes;if(a.links&&a.links.constructor===Array){for(var x=[],p=0;p<a.links.length;++p){var c=a.links[p],h=new q;h.configure(c);x[h.id]=h}a.links=x}for(p in a)this[p]=a[p];x=!1;this._nodes=
|
||||
[];if(d){p=0;for(c=d.length;p<c;++p){var h=d[p],f=e.createNode(h.type,h.title);f||(e.debug&&console.log("Node not found or has errors: "+h.type),f=new g,f.last_serialization=h,x=f.has_errors=!0);f.id=h.id;this.add(f,!0)}p=0;for(c=d.length;p<c;++p)h=d[p],(f=this.getNodeById(h.id))&&f.configure(h)}this._groups.length=0;if(a.groups)for(p=0;p<a.groups.length;++p)d=new e.LGraphGroup,d.configure(a.groups[p]),this.add(d);this.updateExecutionOrder();this._version++;this.setDirtyCanvas(!0,!0);return x}};c.prototype.load=
|
||||
function(a){var b=this,d=new XMLHttpRequest;d.open("GET",a,!0);d.send(null);d.onload=function(a){200!==d.status?console.error("Error loading graph:",d.status,d.response):(a=JSON.parse(d.response),b.configure(a))};d.onerror=function(a){console.error("Error loading graph:",a)}};c.prototype.onNodeTrace=function(a,b,d){};q.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)};q.prototype.serialize=function(){return[this.id,this.origin_id,this.origin_slot,this.target_id,this.target_slot,this.type]};e.LLink=q;v.LGraphNode=e.LGraphNode=g;g.prototype._ctor=function(a){this.title=a||"Unnamed";this.size=[e.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={}};g.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]=e.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 x=this.graph?this.graph.links[b.link]:null;this.onConnectionsChange(e.INPUT,d,!0,x,b)}if(this.outputs)for(d=0;d<this.outputs.length;++d){var p=this.outputs[d];if(p.links)for(b=0;b<p.links.length;++b)x=this.graph?this.graph.links[p.links[b]]:null,this.onConnectionsChange(e.OUTPUT,d,!0,
|
||||
x,p)}}if(a.widgets_values&&this.widgets)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)};g.prototype.serialize=function(){var a={id:this.id,type:this.type,pos:this.pos,size:this.size,flags:e.cloneObject(this.flags),order:this.order,mode:this.mode};if(this.constructor===g&&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=e.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].value;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};g.prototype.clone=function(){var a=e.createNode(this.type);if(!a)return null;var b=e.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};g.prototype.toString=function(){return JSON.stringify(this.serialize())};
|
||||
g.prototype.getTitle=function(){return this.title||this.constructor.title};g.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)}};g.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++)this.graph.links[this.outputs[a].links[d]].data=
|
||||
b}};g.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}};g.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 e=this.graph.getNodeById(d.origin_id);if(!e)return d.data;
|
||||
if(e.updateOutputData)e.updateOutputData(d.origin_slot);else if(e.onExecute)e.onExecute();return d.data}};g.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};g.prototype.getInputDataByName=function(a,b){var d=this.findInputSlot(a);return-1==d?null:this.getInputData(d,b)};g.prototype.isInputConnected=
|
||||
function(a){return this.inputs?a<this.inputs.length&&null!=this.inputs[a].link:!1};g.prototype.getInputInfo=function(a){return this.inputs?a<this.inputs.length?this.inputs[a]:null:null};g.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};g.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 e=this.inputs[b];if(a==e.name&&null!=e.link&&(e=this.graph.links[e.link]))return e.data}return this.properties[a]};g.prototype.getOutputData=function(a){return!this.outputs||a>=this.outputs.length?null:this.outputs[a]._data};g.prototype.getOutputInfo=function(a){return this.outputs?a<this.outputs.length?this.outputs[a]:null:null};g.prototype.isOutputConnected=function(a){return this.outputs?a<this.outputs.length&&this.outputs[a].links&&this.outputs[a].links.length:
|
||||
!1};g.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};g.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 e=this.graph.links[a.links[d]];e&&(e=this.graph.getNodeById(e.target_id))&&b.push(e)}return b};
|
||||
g.prototype.trigger=function(a,b){if(this.outputs&&this.outputs.length){this.graph&&(this.graph._last_trigger_time=e.getTime());for(var d=0;d<this.outputs.length;++d){var x=this.outputs[d];!x||x.type!==e.EVENT||a&&x.name!=a||this.triggerSlot(d,b)}}};g.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=e.getTime());for(var x=0;x<a.length;++x){var p=a[x];if(null==d||d==p){var c=this.graph.links[a[x]];if(c&&(c._last_time=
|
||||
e.getTime(),p=this.graph.getNodeById(c.target_id)))if(c=p.inputs[c.target_slot],p.onAction)p.onAction(c.name,b);else if(p.mode===e.ON_TRIGGER&&p.onExecute)p.onExecute(b)}}}};g.prototype.clearTriggeredSlot=function(a,b){if(this.outputs){var d=this.outputs[a];if(d&&(d=d.links)&&d.length)for(var e=0;e<d.length;++e){var p=d[e];if(null==b||b==p)if(p=this.graph.links[d[e]])p._last_time=0}}};g.prototype.addProperty=function(a,b,d,e){d={name:a,type:d,default_value:b};if(e)for(var p in e)d[p]=e[p];this.properties_info||
|
||||
(this.properties_info=[]);this.properties_info.push(d);this.properties||(this.properties={});this.properties[a]=b;return d};g.prototype.addOutput=function(a,b,d){a={name:a,type:b,links:null};if(d)for(var e in d)a[e]=d[e];this.outputs||(this.outputs=[]);this.outputs.push(a);if(this.onOutputAdded)this.onOutputAdded(a);this.size=this.computeSize();this.setDirtyCanvas(!0,!0);return a};g.prototype.addOutputs=function(a){for(var b=0;b<a.length;++b){var d=a[b],e={name:d[0],type:d[1],link:null};if(a[2])for(var p in d[2])e[p]=
|
||||
d[2][p];this.outputs||(this.outputs=[]);this.outputs.push(e);if(this.onOutputAdded)this.onOutputAdded(e)}this.size=this.computeSize();this.setDirtyCanvas(!0,!0)};g.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,e=0;e<d.length;++e){var p=this.graph.links[d[e]];p&&(p.origin_slot-=1)}this.size=this.computeSize();if(this.onOutputRemoved)this.onOutputRemoved(a);
|
||||
this.setDirtyCanvas(!0,!0)};g.prototype.addInput=function(a,b,d){a={name:a,type:b||0,link:null};if(d)for(var e in d)a[e]=d[e];this.inputs||(this.inputs=[]);this.inputs.push(a);this.size=this.computeSize();if(this.onInputAdded)this.onInputAdded(a);this.setDirtyCanvas(!0,!0);return a};g.prototype.addInputs=function(a){for(var b=0;b<a.length;++b){var d=a[b],e={name:d[0],type:d[1],link:null};if(a[2])for(var p in d[2])e[p]=d[2][p];this.inputs||(this.inputs=[]);this.inputs.push(e);if(this.onInputAdded)this.onInputAdded(e)}this.size=
|
||||
this.computeSize();this.setDirtyCanvas(!0,!0)};g.prototype.removeInput=function(a){this.disconnectInput(a);this.inputs.splice(a,1);for(var b=a;b<this.inputs.length;++b)if(this.inputs[b]){var d=this.graph.links[this.inputs[b].link];d&&(d.target_slot-=1)}this.size=this.computeSize();if(this.onInputRemoved)this.onInputRemoved(a);this.setDirtyCanvas(!0,!0)};g.prototype.addConnection=function(a,b,d,e){a={name:a,type:b,pos:d,direction:e,links:null};this.connections.push(a);return a};g.prototype.computeSize=
|
||||
function(a,b){function d(a){return a?h*a.length*0.6:0}if(this.constructor.size)return this.constructor.size.concat();var c=Math.max(this.inputs?this.inputs.length:1,this.outputs?this.outputs.length:1),p=b||new Float32Array([0,0]),c=Math.max(c,1),h=e.NODE_TEXT_SIZE;p[1]=(this.constructor.slot_start_y||0)+c*e.NODE_SLOT_HEIGHT;c=0;this.widgets&&this.widgets.length&&(c=this.widgets.length*(e.NODE_WIDGET_HEIGHT+4)+8);p[1]=this.widgets_up?Math.max(p[1],c):p[1]+c;var c=d(this.title),f=0,k=0;if(this.inputs)for(var n=
|
||||
0,t=this.inputs.length;n<t;++n){var m=this.inputs[n],m=m.label||m.name||"",m=d(m);f<m&&(f=m)}if(this.outputs)for(n=0,t=this.outputs.length;n<t;++n)m=this.outputs[n],m=m.label||m.name||"",m=d(m),k<m&&(k=m);p[0]=Math.max(f+k+10,c);p[0]=Math.max(p[0],e.NODE_WIDTH);this.widgets&&this.widgets.length&&(p[0]=Math.max(p[0],1.5*e.NODE_WIDTH));if(this.onResize)this.onResize(p);this.constructor.min_height&&p[1]<this.constructor.min_height&&(p[1]=this.constructor.min_height);p[1]+=6;return p};g.prototype.addWidget=
|
||||
function(a,b,d,e,p){this.widgets||(this.widgets=[]);b={type:a.toLowerCase(),name:b,value:d,callback:e,options:p||{}};void 0!==b.options.y&&(b.y=b.options.y);e||console.warn("LiteGraph addWidget(...) without a callback");if("combo"==a&&!b.options.values)throw"LiteGraph addWidget('combo',...) requires to pass values in options: { values:['red','blue'] }";this.widgets.push(b);this.size=this.computeSize();return b};g.prototype.addCustomWidget=function(a){this.widgets||(this.widgets=[]);this.widgets.push(a);
|
||||
return a};g.prototype.getBounding=function(a){a=a||new Float32Array(4);a[0]=this.pos[0]-4;a[1]=this.pos[1]-e.NODE_TITLE_HEIGHT;a[2]=this.size[0]+4;a[3]=this.size[1]+e.NODE_TITLE_HEIGHT;if(this.onBounding)this.onBounding(a);return a};g.prototype.isPointInside=function(a,b,d,c){d=d||0;var p=this.graph&&this.graph.isLive()?0:e.NODE_TITLE_HEIGHT;c&&(p=0);if(this.flags&&this.flags.collapsed){if(s(a,b,this.pos[0]-d,this.pos[1]-e.NODE_TITLE_HEIGHT-d,(this._collapsed_width||e.NODE_COLLAPSED_WIDTH)+2*d,e.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]-p-d<b&&this.pos[1]+this.size[1]+d>b)return!0;return!1};g.prototype.getSlotInPosition=function(a,b){var d=new Float32Array(2);if(this.inputs)for(var e=0,p=this.inputs.length;e<p;++e){var c=this.inputs[e];this.getConnectionPos(!0,e,d);if(s(a,b,d[0]-10,d[1]-5,20,10))return{input:c,slot:e,link_pos:d}}if(this.outputs)for(e=0,p=this.outputs.length;e<p;++e)if(c=this.outputs[e],this.getConnectionPos(!1,e,d),s(a,b,d[0]-10,
|
||||
d[1]-5,20,10))return{output:c,slot:e,link_pos:d};return null};g.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};g.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};g.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 e.debug&&console.log("Connect: Error, no slot of name "+a),null}else if(!this.outputs||a>=this.outputs.length)return e.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 e.debug&&console.log("Connect: Error, no slot of name "+d),null}else{if(d===
|
||||
e.EVENT)return null;if(!b.inputs||d>=b.inputs.length)return e.debug&&console.log("Connect: Error, slot number not found"),null}null!=b.inputs[d].link&&b.disconnectInput(d);var c=this.outputs[a];if(b.onConnectInput&&!1===b.onConnectInput(d,c.type,c))return null;var p=b.inputs[d],h=null;if(e.isValidConnection(c.type,p.type)){h=new q(++this.graph.last_link_id,p.type,this.id,a,b.id,d);this.graph.links[h.id]=h;null==c.links&&(c.links=[]);c.links.push(h.id);b.inputs[d].link=h.id;this.graph&&this.graph._version++;
|
||||
if(this.onConnectionsChange)this.onConnectionsChange(e.OUTPUT,a,!0,h,c);if(b.onConnectionsChange)b.onConnectionsChange(e.INPUT,d,!0,h,p);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(e.INPUT,b,d,this,a),this.graph.onNodeConnectionChange(e.OUTPUT,this,a,b,d))}this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this,h);return h};g.prototype.disconnectOutput=function(a,b){if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return e.debug&&console.log("Connect: Error, no slot of name "+
|
||||
a),!1}else if(!this.outputs||a>=this.outputs.length)return e.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 c=0,p=d.links.length;c<p;c++){var h=d.links[c],f=this.graph.links[h];if(f.target_id==b.id){d.links.splice(c,1);var k=b.inputs[f.target_slot];k.link=null;delete this.graph.links[h];this.graph&&this.graph._version++;
|
||||
if(b.onConnectionsChange)b.onConnectionsChange(e.INPUT,f.target_slot,!1,f,k);if(this.onConnectionsChange)this.onConnectionsChange(e.OUTPUT,a,!1,f,d);if(this.graph&&this.graph.onNodeConnectionChange)this.graph.onNodeConnectionChange(e.OUTPUT,this,a);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(e.OUTPUT,this,a),this.graph.onNodeConnectionChange(e.INPUT,b,f.target_slot));break}}}else{c=0;for(p=d.links.length;c<p;c++)if(h=d.links[c],f=this.graph.links[h]){b=this.graph.getNodeById(f.target_id);
|
||||
this.graph&&this.graph._version++;if(b){k=b.inputs[f.target_slot];k.link=null;if(b.onConnectionsChange)b.onConnectionsChange(e.INPUT,f.target_slot,!1,f,k);if(this.graph&&this.graph.onNodeConnectionChange)this.graph.onNodeConnectionChange(e.INPUT,b,f.target_slot)}delete this.graph.links[h];if(this.onConnectionsChange)this.onConnectionsChange(e.OUTPUT,a,!1,f,d);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(e.OUTPUT,this,a),this.graph.onNodeConnectionChange(e.INPUT,
|
||||
b,f.target_slot))}d.links=null}this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this);return!0};g.prototype.disconnectInput=function(a){if(a.constructor===String){if(a=this.findInputSlot(a),-1==a)return e.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.inputs||a>=this.inputs.length)return e.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;this.inputs[a].link=null;var c=this.graph.links[d];if(c){var p=
|
||||
this.graph.getNodeById(c.origin_id);if(!p)return!1;var h=p.outputs[c.origin_slot];if(!h||!h.links||0==h.links.length)return!1;for(var f=0,k=h.links.length;f<k;f++)if(h.links[f]==d){h.links.splice(f,1);break}delete this.graph.links[d];this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(e.INPUT,a,!1,c,b);if(p.onConnectionsChange)p.onConnectionsChange(e.OUTPUT,f,!1,c,h);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(e.OUTPUT,p,f),
|
||||
this.graph.onNodeConnectionChange(e.INPUT,this,a))}this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this);return!0};g.prototype.getConnectionPos=function(a,b,d){d=d||new Float32Array(2);var c=0;a&&this.inputs&&(c=this.inputs.length);!a&&this.outputs&&(c=this.outputs.length);var p=0.5*e.NODE_SLOT_HEIGHT;if(this.flags.collapsed)return b=this._collapsed_width||e.NODE_COLLAPSED_WIDTH,this.horizontal?(d[0]=this.pos[0]+0.5*b,d[1]=a?this.pos[1]-e.NODE_TITLE_HEIGHT:this.pos[1]):(d[0]=a?this.pos[0]:
|
||||
this.pos[0]+b,d[1]=this.pos[1]-0.5*e.NODE_TITLE_HEIGHT),d;if(a&&-1==b)return d[0]=this.pos[0]+0.5*e.NODE_TITLE_HEIGHT,d[1]=this.pos[1]+0.5*e.NODE_TITLE_HEIGHT,d;if(a&&c>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&&c>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]/c*(b+0.5),d[1]=a?this.pos[1]-e.NODE_TITLE_HEIGHT:
|
||||
this.pos[1]+this.size[1],d;d[0]=a?this.pos[0]+p:this.pos[0]+this.size[0]+1-p;d[1]=this.pos[1]+(b+0.7)*e.NODE_SLOT_HEIGHT+(this.constructor.slot_start_y||0);return d};g.prototype.alignToGrid=function(){this.pos[0]=e.CANVAS_GRID_SIZE*Math.round(this.pos[0]/e.CANVAS_GRID_SIZE);this.pos[1]=e.CANVAS_GRID_SIZE*Math.round(this.pos[1]/e.CANVAS_GRID_SIZE)};g.prototype.trace=function(a){this.console||(this.console=[]);this.console.push(a);this.console.length>g.MAX_CONSOLE&&this.console.shift();this.graph.onNodeTrace(this,
|
||||
a)};g.prototype.setDirtyCanvas=function(a,b){this.graph&&this.graph.sendActionToCanvas("setDirty",[a,b])};g.prototype.loadImage=function(a){var b=new Image;b.src=e.node_images_path+a;b.ready=!1;var d=this;b.onload=function(){this.ready=!0;d.setDirtyCanvas(!0)};return b};g.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 e=b[d];if(a||e.node_capturing_input==this)e.node_capturing_input=a?this:null}};g.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)};g.prototype.pin=function(a){this.graph._version++;this.flags.pinned=void 0===a?!this.flags.pinned:a};g.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]]};v.LGraphGroup=e.LGraphGroup=l;l.prototype._ctor=function(a){this.title=a||"Group";this.font_size=24;this.color=f.node_colors.pale_blue?
|
||||
f.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})};l.prototype.configure=function(a){this.title=a.title;this._bounding.set(a.bounding);this.color=a.color;this.font=a.font};l.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}};l.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 e=this._nodes[d];e.pos[0]+=a;e.pos[1]+=b}};l.prototype.recomputeInsideNodes=
|
||||
function(){this._nodes.length=0;for(var a=this.graph._nodes,b=new Float32Array(4),d=0;d<a.length;++d){var e=a[d];e.getBounding(b);u(this._bounding,b)&&this._nodes.push(e)}};l.prototype.isPointInside=g.prototype.isPointInside;l.prototype.setDirtyCanvas=g.prototype.setDirtyCanvas;e.DragAndScale=r;r.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)};r.prototype.computeVisibleArea=function(){if(this.element){var a=-this.offset[0],b=-this.offset[1],d=a+this.element.width/this.scale,e=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]=e-b}else this.visible_area[0]=this.visible_area[1]=this.visible_area[2]=this.visible_area[3]=
|
||||
0};r.prototype.onMouse=function(a){if(this.enabled){var b=this.element,d=b.getBoundingClientRect(),e=a.clientX-d.left,d=a.clientY-d.top;a.canvasx=e;a.canvasy=d;a.dragging=this.dragging;var c=!1;this.onmouse&&(c=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)c||
|
||||
(b=e-this.last_mouse[0],c=d-this.last_mouse[1],this.dragging&&this.mouseDrag(b,c));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]=e;this.last_mouse[1]=d;a.preventDefault();a.stopPropagation();return!1}};r.prototype.toCanvasContext=function(a){a.scale(this.scale,this.scale);a.translate(this.offset[0],this.offset[1])};r.prototype.convertOffsetToCanvas=function(a){return[(a[0]+this.offset[0])*this.scale,(a[1]+this.offset[1])*this.scale]};r.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};r.prototype.mouseDrag=function(a,b){this.offset[0]+=a/this.scale;this.offset[1]+=b/this.scale;if(this.onredraw)this.onredraw(this)};r.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 e=this.convertCanvasToOffset(b),d=[e[0]-d[0],e[1]-d[1]];this.offset[0]+=d[0];this.offset[1]+=d[1];if(this.onredraw)this.onredraw(this)}}};r.prototype.changeDeltaScale=function(a,b){this.changeScale(this.scale*a,b)};r.prototype.reset=function(){this.scale=1;this.offset[0]=0;this.offset[1]=0};v.LGraphCanvas=e.LGraphCanvas=f;f.link_type_colors={"-1":e.EVENT_LINK_COLOR,number:"#AAA",node:"#DCA"};f.gradients={};f.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.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()};f.prototype.setGraph=function(a,b){this.graph!=a&&(b||this.clear(),!a&&this.graph?
|
||||
this.graph.detachCanvas(this):(a.attachCanvas(this),this.setDirty(!0,!0)))};f.prototype.openSubgraph=function(a){if(!a)throw"graph cannot be null";if(this.graph==a)throw"graph cannot be the same";this.clear();this.graph&&(this._graph_stack||(this._graph_stack=[]),this._graph_stack.push(this.graph));a.attachCanvas(this);this.setDirty(!0,!0)};f.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]))}};f.prototype.getCurrentGraph=function(){return this.graph};f.prototype.setCanvas=function(a,b){if(a&&a.constructor===String&&(a=document.getElementById(a),!a))throw"Error creating LiteGraph canvas: Canvas not found";if(a!==this.canvas&&(!a&&this.canvas&&(b||this.unbindEvents()),this.canvas=a,this.ds.element=a)){a.className+=" lgraphcanvas";a.data=this;a.tabindex="1";this.bgcanvas=
|
||||
null;this.bgcanvas||(this.bgcanvas=document.createElement("canvas"),this.bgcanvas.width=this.canvas.width,this.bgcanvas.height=this.canvas.height);if(null==a.getContext){if("canvas"!=a.localName)throw"Element supplied for LGraphCanvas must be a <canvas> element, you passed a "+a.localName;throw"This browser doesn't support Canvas";}null==(this.ctx=a.getContext("2d"))&&(a.webgl_enabled||console.warn("This canvas seems to be WebGL, enabling WebGL renderer"),this.enableWebGL());this._mousemove_callback=
|
||||
this.processMouseMove.bind(this);this._mouseup_callback=this.processMouseUp.bind(this);b||this.bindEvents()}};f.prototype._doNothing=function(a){a.preventDefault();return!1};f.prototype._doReturnTrue=function(a){a.preventDefault();return!0};f.prototype.bindEvents=function(){if(this._events_binded)console.warn("LGraphCanvas: events already binded");else{var a=this.canvas,b=this.getCanvasWindow().document;this._mousedown_callback=this.processMouseDown.bind(this);this._mousewheel_callback=this.processMouseWheel.bind(this);
|
||||
a.addEventListener("mousedown",this._mousedown_callback,!0);a.addEventListener("mousemove",this._mousemove_callback);a.addEventListener("mousewheel",this._mousewheel_callback,!1);a.addEventListener("contextmenu",this._doNothing);a.addEventListener("DOMMouseScroll",this._mousewheel_callback,!1);a.addEventListener("touchstart",this.touchHandler,!0);a.addEventListener("touchmove",this.touchHandler,!0);a.addEventListener("touchend",this.touchHandler,!0);a.addEventListener("touchcancel",this.touchHandler,
|
||||
!0);this._key_callback=this.processKey.bind(this);a.addEventListener("keydown",this._key_callback,!0);b.addEventListener("keyup",this._key_callback,!0);this._ondrop_callback=this.processDrop.bind(this);a.addEventListener("dragover",this._doNothing,!1);a.addEventListener("dragend",this._doNothing,!1);a.addEventListener("drop",this._ondrop_callback,!1);a.addEventListener("dragenter",this._doReturnTrue,!1);this._events_binded=!0}};f.prototype.unbindEvents=function(){if(this._events_binded){var a=this.getCanvasWindow().document;
|
||||
this.canvas.removeEventListener("mousedown",this._mousedown_callback);this.canvas.removeEventListener("mousewheel",this._mousewheel_callback);this.canvas.removeEventListener("DOMMouseScroll",this._mousewheel_callback);this.canvas.removeEventListener("keydown",this._key_callback);a.removeEventListener("keyup",this._key_callback);this.canvas.removeEventListener("contextmenu",this._doNothing);this.canvas.removeEventListener("drop",this._ondrop_callback);this.canvas.removeEventListener("dragenter",this._doReturnTrue);
|
||||
this.canvas.removeEventListener("touchstart",this.touchHandler);this.canvas.removeEventListener("touchmove",this.touchHandler);this.canvas.removeEventListener("touchend",this.touchHandler);this.canvas.removeEventListener("touchcancel",this.touchHandler);this._ondrop_callback=this._key_callback=this._mousewheel_callback=this._mousedown_callback=null;this._events_binded=!1}else console.warn("LGraphCanvas: no events binded")};f.getFileExtension=function(a){var b=a.indexOf("?");-1!=b&&(a=a.substr(0,b));
|
||||
b=a.lastIndexOf(".");return-1==b?"":a.substr(b+1).toLowerCase()};f.prototype.enableWebGL=function(){if(void 0===typeof GL)throw"litegl.js must be included to use a WebGL canvas";if(void 0===typeof enableWebGLCanvas)throw"webglCanvas.js must be included to use this feature";this.gl=this.ctx=enableWebGLCanvas(this.canvas);this.ctx.webgl=!0;this.bgcanvas=this.canvas;this.bgctx=this.gl;this.canvas.webgl_enabled=!0};f.prototype.setDirty=function(a,b){a&&(this.dirty_canvas=!0);b&&(this.dirty_bgcanvas=!0)};
|
||||
f.prototype.getCanvasWindow=function(){if(!this.canvas)return window;var a=this.canvas.ownerDocument;return a.defaultView||a.parentWindow};f.prototype.startRendering=function(){function a(){this.pause_rendering||this.draw();var b=this.getCanvasWindow();this.is_rendering&&b.requestAnimationFrame(a.bind(this))}this.is_rendering||(this.is_rendering=!0,a.call(this))};f.prototype.stopRendering=function(){this.is_rendering=!1};f.prototype.processMouseDown=function(a){if(this.graph){this.adjustMouseEvent(a);
|
||||
var b=this.getCanvasWindow();f.active_canvas=this;this.canvas.removeEventListener("mousemove",this._mousemove_callback);b.document.addEventListener("mousemove",this._mousemove_callback,!0);b.document.addEventListener("mouseup",this._mouseup_callback,!0);var d=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes,5),c=!1,p=300>e.getTime()-this.last_mouseclick;this.canvas_mouse[0]=a.canvasX;this.canvas_mouse[1]=a.canvasY;this.canvas.focus();e.closeAllContextMenus(b);if(!this.onMouse||!0!=this.onMouse(a)){if(1==
|
||||
a.which){a.ctrlKey&&(this.dragging_rectangle=new Float32Array(4),this.dragging_rectangle[0]=a.canvasX,this.dragging_rectangle[1]=a.canvasY,this.dragging_rectangle[2]=1,this.dragging_rectangle[3]=1,c=!0);var h=!1;if(d&&this.allow_interaction&&!c&&!this.read_only){this.live_mode||d.flags.pinned||this.bringToFront(d);if(!this.connecting_node&&!d.flags.collapsed&&!this.live_mode)if(!c&&!1!==d.resizable&&s(a.canvasX,a.canvasY,d.pos[0]+d.size[0]-5,d.pos[1]+d.size[1]-5,10,10))this.resizing_node=d,this.canvas.style.cursor=
|
||||
"se-resize",c=!0;else{if(d.outputs)for(var k=0,n=d.outputs.length;k<n;++k){var t=d.outputs[k],m=d.getConnectionPos(!1,k);if(s(a.canvasX,a.canvasY,m[0]-15,m[1]-10,30,20)){this.connecting_node=d;this.connecting_output=t;this.connecting_pos=d.getConnectionPos(!1,k);this.connecting_slot=k;a.shiftKey&&d.disconnectOutput(k);if(p){if(d.onOutputDblClick)d.onOutputDblClick(k,a)}else if(d.onOutputClick)d.onOutputClick(k,a);c=!0;break}}if(d.inputs)for(k=0,n=d.inputs.length;k<n;++k)if(t=d.inputs[k],m=d.getConnectionPos(!0,
|
||||
k),s(a.canvasX,a.canvasY,m[0]-15,m[1]-10,30,20)){if(p){if(d.onInputDblClick)d.onInputDblClick(k,a)}else if(d.onInputClick)d.onInputClick(k,a);if(null!==t.link){c=this.graph.links[t.link];d.disconnectInput(k);if(this.allow_reconnect_links||a.shiftKey)this.connecting_node=this.graph._nodes_by_id[c.origin_id],this.connecting_slot=c.origin_slot,this.connecting_output=this.connecting_node.outputs[this.connecting_slot],this.connecting_pos=this.connecting_node.getConnectionPos(!1,this.connecting_slot);c=
|
||||
this.dirty_bgcanvas=!0}}}if(!c){k=!1;if(n=this.processNodeWidgets(d,this.canvas_mouse,a))k=!0,this.node_widget=[d,n];if(p&&this.selected_nodes[d.id]){if(d.onDblClick)d.onDblClick(a,[a.canvasX-d.pos[0],a.canvasY-d.pos[1]],this);this.processNodeDblClicked(d);k=!0}d.onMouseDown&&d.onMouseDown(a,[a.canvasX-d.pos[0],a.canvasY-d.pos[1]],this)?k=!0:this.live_mode&&(k=h=!0);k||(this.allow_dragnodes&&(this.node_dragged=d),this.selected_nodes[d.id]||this.processNodeSelected(d,a));this.dirty_canvas=!0}}else{if(!this.read_only)for(k=
|
||||
0;k<this.visible_links.length;++k)if(d=this.visible_links[k],(h=d._pos)&&!(a.canvasX<h[0]-4||a.canvasX>h[0]+4||a.canvasY<h[1]-4||a.canvasY>h[1]+4)){this.showLinkMenu(d,a);break}this.selected_group=this.graph.getGroupOnPos(a.canvasX,a.canvasY);this.selected_group_resizing=!1;this.selected_group&&!this.read_only&&(a.ctrlKey&&(this.dragging_rectangle=null),10>y([a.canvasX,a.canvasY],[this.selected_group.pos[0]+this.selected_group.size[0],this.selected_group.pos[1]+this.selected_group.size[1]])*this.ds.scale?
|
||||
this.selected_group_resizing=!0:this.selected_group.recomputeInsideNodes());p&&!this.read_only&&this.showSearchBox(a);h=!0}!c&&h&&this.allow_dragcanvas&&(this.dragging_canvas=!0)}else 2!=a.which&&3==a.which&&(this.read_only||this.processContextMenu(d,a));this.last_mouse[0]=a.localX;this.last_mouse[1]=a.localY;this.last_mouseclick=e.getTime();this.last_mouse_dragging=!0;this.graph.change();(!b.document.activeElement||"input"!=b.document.activeElement.nodeName.toLowerCase()&&"textarea"!=b.document.activeElement.nodeName.toLowerCase())&&
|
||||
a.preventDefault();a.stopPropagation();if(this.onMouseDown)this.onMouseDown(a);return!1}}};f.prototype.processMouseMove=function(a){this.autoresize&&this.resize();if(this.graph){f.active_canvas=this;this.adjustMouseEvent(a);var b=[a.localX,a.localY],d=[b[0]-this.last_mouse[0],b[1]-this.last_mouse[1]];this.last_mouse=b;this.canvas_mouse[0]=a.canvasX;this.canvas_mouse[1]=a.canvasY;a.dragging=this.last_mouse_dragging;this.node_widget&&(this.processNodeWidgets(this.node_widget[0],this.canvas_mouse,a,
|
||||
this.node_widget[1]),this.dirty_canvas=!0);if(this.dragging_rectangle)this.dragging_rectangle[2]=a.canvasX-this.dragging_rectangle[0],this.dragging_rectangle[3]=a.canvasY-this.dragging_rectangle[1],this.dirty_canvas=!0;else if(this.selected_group&&!this.read_only)this.selected_group_resizing?this.selected_group.size=[a.canvasX-this.selected_group.pos[0],a.canvasY-this.selected_group.pos[1]]:(this.selected_group.move(d[0]/this.ds.scale,d[1]/this.ds.scale,a.ctrlKey),this.selected_group._nodes.length&&
|
||||
(this.dirty_canvas=!0)),this.dirty_bgcanvas=!0;else if(this.dragging_canvas)this.ds.offset[0]+=d[0]/this.ds.scale,this.ds.offset[1]+=d[1]/this.ds.scale,this.dirty_bgcanvas=this.dirty_canvas=!0;else if(this.allow_interaction&&!this.read_only){this.connecting_node&&(this.dirty_canvas=!0);for(var c=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes),b=0,p=this.graph._nodes.length;b<p;++b)if(this.graph._nodes[b].mouseOver&&c!=this.graph._nodes[b]){this.graph._nodes[b].mouseOver=!1;if(this.node_over&&
|
||||
this.node_over.onMouseLeave)this.node_over.onMouseLeave(a);this.node_over=null;this.dirty_canvas=!0}if(c){if(!c.mouseOver&&(c.mouseOver=!0,this.node_over=c,this.dirty_canvas=!0,c.onMouseEnter))c.onMouseEnter(a);if(c.onMouseMove)c.onMouseMove(a,[a.canvasX-c.pos[0],a.canvasY-c.pos[1]],this);if(this.connecting_node&&(p=this._highlight_input||[0,0],!this.isOverNodeBox(c,a.canvasX,a.canvasY))){var h=this.isOverNodeInput(c,a.canvasX,a.canvasY,p);-1!=h&&c.inputs[h]?e.isValidConnection(this.connecting_output.type,
|
||||
c.inputs[h].type)&&(this._highlight_input=p):this._highlight_input=null}this.canvas&&(s(a.canvasX,a.canvasY,c.pos[0]+c.size[0]-5,c.pos[1]+c.size[1]-5,5,5)?this.canvas.style.cursor="se-resize":this.canvas.style.cursor="crosshair")}else{p=null;for(b=0;b<this.visible_links.length;++b){var h=this.visible_links[b],k=h._pos;if(k&&!(a.canvasX<k[0]-4||a.canvasX>k[0]+4||a.canvasY<k[1]-4||a.canvasY>k[1]+4)){p=h;break}}p!=this.over_link_center&&(this.over_link_center=p,this.dirty_canvas=!0);this.canvas&&(this.canvas.style.cursor=
|
||||
"")}if(this.node_capturing_input&&this.node_capturing_input!=c&&this.node_capturing_input.onMouseMove)this.node_capturing_input.onMouseMove(a);if(this.node_dragged&&!this.live_mode){for(b in this.selected_nodes)c=this.selected_nodes[b],c.pos[0]+=d[0]/this.ds.scale,c.pos[1]+=d[1]/this.ds.scale;this.dirty_bgcanvas=this.dirty_canvas=!0}this.resizing_node&&!this.live_mode&&(this.resizing_node.size[0]=a.canvasX-this.resizing_node.pos[0],this.resizing_node.size[1]=a.canvasY-this.resizing_node.pos[1],d=
|
||||
Math.max(this.resizing_node.inputs?this.resizing_node.inputs.length:0,this.resizing_node.outputs?this.resizing_node.outputs.length:0)*e.NODE_SLOT_HEIGHT+(this.resizing_node.widgets?this.resizing_node.widgets.length:0)*(e.NODE_WIDGET_HEIGHT+4)+4,this.resizing_node.size[1]<d&&(this.resizing_node.size[1]=d),this.resizing_node.size[0]<e.NODE_MIN_WIDTH&&(this.resizing_node.size[0]=e.NODE_MIN_WIDTH),this.canvas.style.cursor="se-resize",this.dirty_bgcanvas=this.dirty_canvas=!0)}a.preventDefault();return!1}};
|
||||
f.prototype.processMouseUp=function(a){if(this.graph){var b=this.getCanvasWindow().document;f.active_canvas=this;b.removeEventListener("mousemove",this._mousemove_callback,!0);this.canvas.addEventListener("mousemove",this._mousemove_callback,!0);b.removeEventListener("mouseup",this._mouseup_callback,!0);this.adjustMouseEvent(a);b=e.getTime();a.click_time=b-this.last_mouseclick;this.last_mouse_dragging=!1;if(1==a.which){this.node_widget=null;if(this.selected_group){var b=this.selected_group.pos[0]-
|
||||
Math.round(this.selected_group.pos[0]),d=this.selected_group.pos[1]-Math.round(this.selected_group.pos[1]);this.selected_group.move(b,d,a.ctrlKey);this.selected_group.pos[0]=Math.round(this.selected_group.pos[0]);this.selected_group.pos[1]=Math.round(this.selected_group.pos[1]);this.selected_group._nodes.length&&(this.dirty_canvas=!0);this.selected_group=null}this.selected_group_resizing=!1;if(this.dragging_rectangle){if(this.graph){b=this.graph._nodes;d=new Float32Array(4);this.deselectAllNodes();
|
||||
var c=Math.abs(this.dragging_rectangle[2]),p=Math.abs(this.dragging_rectangle[3]),h=0>this.dragging_rectangle[3]?this.dragging_rectangle[1]-p:this.dragging_rectangle[1];this.dragging_rectangle[0]=0>this.dragging_rectangle[2]?this.dragging_rectangle[0]-c:this.dragging_rectangle[0];this.dragging_rectangle[1]=h;this.dragging_rectangle[2]=c;this.dragging_rectangle[3]=p;p=[];for(h=0;h<b.length;++h)c=b[h],c.getBounding(d),u(this.dragging_rectangle,d)&&p.push(c);p.length&&this.selectNodes(p)}this.dragging_rectangle=
|
||||
null}else if(this.connecting_node){this.dirty_bgcanvas=this.dirty_canvas=!0;if(c=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes))this.connecting_output.type==e.EVENT&&this.isOverNodeBox(c,a.canvasX,a.canvasY)?this.connecting_node.connect(this.connecting_slot,c,e.EVENT):(b=this.isOverNodeInput(c,a.canvasX,a.canvasY),-1!=b?this.connecting_node.connect(this.connecting_slot,c,b):(b=c.getInputInfo(0),this.connecting_output.type==e.EVENT?this.connecting_node.connect(this.connecting_slot,
|
||||
c,e.EVENT):b&&!b.link&&e.isValidConnection(b.type&&this.connecting_output.type)&&this.connecting_node.connect(this.connecting_slot,c,0)));this.connecting_node=this.connecting_pos=this.connecting_output=null;this.connecting_slot=-1}else if(this.resizing_node)this.dirty_bgcanvas=this.dirty_canvas=!0,this.resizing_node=null;else if(this.node_dragged){(c=this.node_dragged)&&300>a.click_time&&s(a.canvasX,a.canvasY,c.pos[0],c.pos[1]-e.NODE_TITLE_HEIGHT,e.NODE_TITLE_HEIGHT,e.NODE_TITLE_HEIGHT)&&c.collapse();
|
||||
this.dirty_bgcanvas=this.dirty_canvas=!0;this.node_dragged.pos[0]=Math.round(this.node_dragged.pos[0]);this.node_dragged.pos[1]=Math.round(this.node_dragged.pos[1]);this.graph.config.align_to_grid&&this.node_dragged.alignToGrid();if(this.onNodeMoved)this.onNodeMoved(this.node_dragged);this.node_dragged=null}else{c=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes);!c&&300>a.click_time&&this.deselectAllNodes();this.dirty_canvas=!0;this.dragging_canvas=!1;if(this.node_over&&this.node_over.onMouseUp)this.node_over.onMouseUp(a,
|
||||
[a.canvasX-this.node_over.pos[0],a.canvasY-this.node_over.pos[1]],this);if(this.node_capturing_input&&this.node_capturing_input.onMouseUp)this.node_capturing_input.onMouseUp(a,[a.canvasX-this.node_capturing_input.pos[0],a.canvasY-this.node_capturing_input.pos[1]])}}else 2==a.which?(this.dirty_canvas=!0,this.dragging_canvas=!1):3==a.which&&(this.dirty_canvas=!0,this.dragging_canvas=!1);this.graph.change();a.stopPropagation();a.preventDefault();return!1}};f.prototype.processMouseWheel=function(a){if(this.graph&&
|
||||
this.allow_dragcanvas){var b=null!=a.wheelDeltaY?a.wheelDeltaY:-60*a.detail;this.adjustMouseEvent(a);var d=this.ds.scale;0<b?d*=1.1:0>b&&(d*=1/1.1);this.ds.changeScale(d,[a.localX,a.localY]);this.graph.change();a.preventDefault();return!1}};f.prototype.isOverNodeBox=function(a,b,d){var c=e.NODE_TITLE_HEIGHT;return s(b,d,a.pos[0]+2,a.pos[1]+2-c,c-4,c-4)?!0:!1};f.prototype.isOverNodeInput=function(a,b,d,e){if(a.inputs)for(var c=0,h=a.inputs.length;c<h;++c){var k=a.getConnectionPos(!0,c),f=!1;if(f=a.horizontal?
|
||||
s(b,d,k[0]-5,k[1]-10,10,20):s(b,d,k[0]-10,k[1]-5,40,10))return e&&(e[0]=k[0],e[1]=k[1]),c}return-1};f.prototype.processKey=function(a){if(this.graph){var b=!1;if("input"!=a.target.localName){if("keydown"==a.type){if(32==a.keyCode&&(b=this.dragging_canvas=!0),65==a.keyCode&&a.ctrlKey&&(this.selectNodes(),b=!0),"KeyC"==a.code&&(a.metaKey||a.ctrlKey)&&!a.shiftKey&&this.selected_nodes&&(this.copyToClipboard(),b=!0),"KeyV"!=a.code||!a.metaKey&&!a.ctrlKey||a.shiftKey||this.pasteFromClipboard(),46!=a.keyCode&&
|
||||
8!=a.keyCode||"input"==a.target.localName||"textarea"==a.target.localName||(this.deleteSelectedNodes(),b=!0),this.selected_nodes)for(var d in this.selected_nodes)if(this.selected_nodes[d].onKeyDown)this.selected_nodes[d].onKeyDown(a)}else if("keyup"==a.type&&(32==a.keyCode&&(this.dragging_canvas=!1),this.selected_nodes))for(d in this.selected_nodes)if(this.selected_nodes[d].onKeyUp)this.selected_nodes[d].onKeyUp(a);this.graph.change();if(b)return a.preventDefault(),a.stopImmediatePropagation(),!1}}};
|
||||
f.prototype.copyToClipboard=function(){var a={nodes:[],links:[]},b=0,d=[],e;for(e in this.selected_nodes){var c=this.selected_nodes[e];c._relative_id=b;d.push(c);b+=1}for(e=0;e<d.length;++e)if(c=d[e],a.nodes.push(c.clone().serialize()),c.inputs&&c.inputs.length)for(b=0;b<c.inputs.length;++b){var h=c.inputs[b];if(h&&null!=h.link&&(h=this.graph.links[h.link])){var k=this.graph.getNodeById(h.origin_id);k&&this.selected_nodes[k.id]&&a.links.push([k._relative_id,b,c._relative_id,h.target_slot])}}localStorage.setItem("litegrapheditor_clipboard",
|
||||
JSON.stringify(a))};f.prototype.pasteFromClipboard=function(){var a=localStorage.getItem("litegrapheditor_clipboard");if(a){for(var a=JSON.parse(a),b=[],d=0;d<a.nodes.length;++d){var c=a.nodes[d],p=e.createNode(c.type);p&&(p.configure(c),p.pos[0]+=5,p.pos[1]+=5,this.graph.add(p),b.push(p))}for(d=0;d<a.links.length;++d)c=a.links[d],b[c[0]].connect(c[1],b[c[2]],c[3]);this.selectNodes(b)}};f.prototype.processDrop=function(a){a.preventDefault();this.adjustMouseEvent(a);var b=[a.canvasX,a.canvasY],d=this.graph.getNodeOnPos(b[0],
|
||||
b[1]);if(d){if((d.onDropFile||d.onDropData)&&(b=a.dataTransfer.files)&&b.length)for(var e=0;e<b.length;e++){var c=a.dataTransfer.files[0],h=c.name;f.getFileExtension(h);if(d.onDropFile)d.onDropFile(c);if(d.onDropData){var k=new FileReader;k.onload=function(a){d.onDropData(a.target.result,h,c)};var n=c.type.split("/")[0];"text"==n||""==n?k.readAsText(c):"image"==n?k.readAsDataURL(c):k.readAsArrayBuffer(c)}}return d.onDropItem&&d.onDropItem(event)?!0:this.onDropItem?this.onDropItem(event):!1}b=null;
|
||||
this.onDropItem&&(b=this.onDropItem(event));b||this.checkDropItem(a)};f.prototype.checkDropItem=function(a){if(a.dataTransfer.files.length){var b=a.dataTransfer.files[0],d=f.getFileExtension(b.name).toLowerCase();if(d=e.node_types_by_file_extension[d])if(d=e.createNode(d.type),d.pos=[a.canvasX,a.canvasY],this.graph.add(d),d.onDropFile)d.onDropFile(b)}};f.prototype.processNodeDblClicked=function(a){if(this.onShowNodePanel)this.onShowNodePanel(a);if(this.onNodeDblClicked)this.onNodeDblClicked(a);this.setDirty(!0)};
|
||||
f.prototype.processNodeSelected=function(a,b){this.selectNode(a,b&&b.shiftKey);if(this.onNodeSelected)this.onNodeSelected(a)};f.prototype.processNodeDeselected=function(a){this.deselectNode(a);if(this.onNodeDeselected)this.onNodeDeselected(a)};f.prototype.selectNode=function(a,b){null==a?this.deselectAllNodes():this.selectNodes([a],b)};f.prototype.selectNodes=function(a,b){b||this.deselectAllNodes();a=a||this.graph._nodes;for(var d=0;d<a.length;++d){var e=a[d];if(!e.is_selected){if(!e.is_selected&&
|
||||
e.onSelected)e.onSelected();e.is_selected=!0;this.selected_nodes[e.id]=e;if(e.inputs)for(var c=0;c<e.inputs.length;++c)this.highlighted_links[e.inputs[c].link]=!0;if(e.outputs)for(c=0;c<e.outputs.length;++c){var h=e.outputs[c];if(h.links)for(var k=0;k<h.links.length;++k)this.highlighted_links[h.links[k]]=!0}}}if(this.onSelectionChange)this.onSelectionChange(this.selected_nodes);this.setDirty(!0)};f.prototype.deselectNode=function(a){if(a.is_selected){if(a.onDeselected)a.onDeselected();a.is_selected=
|
||||
!1;if(a.inputs)for(var b=0;b<a.inputs.length;++b)delete this.highlighted_links[a.inputs[b].link];if(a.outputs)for(b=0;b<a.outputs.length;++b){var d=a.outputs[b];if(d.links)for(var e=0;e<d.links.length;++e)delete this.highlighted_links[d.links[e]]}}};f.prototype.deselectAllNodes=function(){if(this.graph){for(var a=this.graph._nodes,b=0,d=a.length;b<d;++b){var e=a[b];if(e.is_selected){if(e.onDeselected)e.onDeselected();e.is_selected=!1}}this.selected_nodes={};this.current_node=null;this.highlighted_links=
|
||||
{};if(this.onSelectionChange)this.onSelectionChange(this.selected_nodes);this.setDirty(!0)}};f.prototype.deleteSelectedNodes=function(){for(var a in this.selected_nodes)this.graph.remove(this.selected_nodes[a]);this.selected_nodes={};this.current_node=null;this.highlighted_links={};this.setDirty(!0)};f.prototype.centerOnNode=function(a){this.ds.offset[0]=-a.pos[0]-0.5*a.size[0]+0.5*this.canvas.width/this.ds.scale;this.ds.offset[1]=-a.pos[1]-0.5*a.size[1]+0.5*this.canvas.height/this.ds.scale;this.setDirty(!0,
|
||||
!0)};f.prototype.adjustMouseEvent=function(a){if(this.canvas){var b=this.canvas.getBoundingClientRect();a.localX=a.clientX-b.left;a.localY=a.clientY-b.top}else a.localX=a.clientX,a.localY=a.clientY;a.deltaX=a.localX-this.last_mouse_position[0];a.deltaY=a.localY-this.last_mouse_position[1];this.last_mouse_position[0]=a.localX;this.last_mouse_position[1]=a.localY;a.canvasX=a.localX/this.ds.scale-this.ds.offset[0];a.canvasY=a.localY/this.ds.scale-this.ds.offset[1]};f.prototype.setZoom=function(a,b){this.ds.changeScale(a,
|
||||
b);this.dirty_bgcanvas=this.dirty_canvas=!0};f.prototype.convertOffsetToCanvas=function(a,b){return this.ds.convertOffsetToCanvas(a,b)};f.prototype.convertCanvasToOffset=function(a,b){return this.ds.convertCanvasToOffset(a,b)};f.prototype.convertEventToCanvasOffset=function(a){var b=this.canvas.getBoundingClientRect();return this.convertCanvasToOffset([a.clientX-b.left,a.clientY-b.top])};f.prototype.bringToFront=function(a){var b=this.graph._nodes.indexOf(a);-1!=b&&(this.graph._nodes.splice(b,1),
|
||||
this.graph._nodes.push(a))};f.prototype.sendToBack=function(a){var b=this.graph._nodes.indexOf(a);-1!=b&&(this.graph._nodes.splice(b,1),this.graph._nodes.unshift(a))};var w=new Float32Array(4);f.prototype.computeVisibleNodes=function(a,b){var d=b||[];d.length=0;a=a||this.graph._nodes;for(var e=0,c=a.length;e<c;++e){var h=a[e];(!this.live_mode||h.onDrawBackground||h.onDrawForeground)&&u(this.visible_area,h.getBounding(w))&&d.push(h)}return d};f.prototype.draw=function(a,b){if(this.canvas){var d=e.getTime();
|
||||
this.render_time=0.001*(d-this.last_draw_time);this.last_draw_time=d;this.graph&&this.ds.computeVisibleArea();(this.dirty_bgcanvas||b||this.always_render_background||this.graph&&this.graph._last_trigger_time&&1E3>d-this.graph._last_trigger_time)&&this.drawBackCanvas();(this.dirty_canvas||a)&&this.drawFrontCanvas();this.fps=this.render_time?1/this.render_time:0;this.frame+=1}};f.prototype.drawFrontCanvas=function(){this.dirty_canvas=!1;this.ctx||(this.ctx=this.bgcanvas.getContext("2d"));var a=this.ctx;
|
||||
if(a){a.start2D&&a.start2D();var b=this.canvas;a.restore();a.setTransform(1,0,0,1,0,0);this.dirty_area&&(a.save(),a.beginPath(),a.rect(this.dirty_area[0],this.dirty_area[1],this.dirty_area[2],this.dirty_area[3]),a.clip());this.clear_background&&a.clearRect(0,0,b.width,b.height);this.bgcanvas==this.canvas?this.drawBackCanvas():a.drawImage(this.bgcanvas,0,0);if(this.onRender)this.onRender(b,a);this.show_info&&this.renderInfo(a);if(this.graph){a.save();this.ds.toCanvasContext(a);for(var b=this.computeVisibleNodes(null,
|
||||
this.visible_nodes),d=0;d<b.length;++d){var c=b[d];a.save();a.translate(c.pos[0],c.pos[1]);this.drawNode(c,a);a.restore()}this.render_execution_order&&this.drawExecutionOrder(a);this.graph.config.links_ontop&&(this.live_mode||this.drawConnections(a));if(null!=this.connecting_pos){a.lineWidth=this.connections_width;b=null;switch(this.connecting_output.type){case e.EVENT:b=e.EVENT_LINK_COLOR;break;default:b=e.CONNECTING_LINK_COLOR}this.renderLink(a,this.connecting_pos,[this.canvas_mouse[0],this.canvas_mouse[1]],
|
||||
null,!1,null,b,this.connecting_output.dir||(this.connecting_node.horizontal?e.DOWN:e.RIGHT),e.CENTER);a.beginPath();this.connecting_output.type===e.EVENT||this.connecting_output.shape===e.BOX_SHAPE?a.rect(this.connecting_pos[0]-6+0.5,this.connecting_pos[1]-5+0.5,14,10):a.arc(this.connecting_pos[0],this.connecting_pos[1],4,0,2*Math.PI);a.fill();a.fillStyle="#ffcc00";this._highlight_input&&(a.beginPath(),a.arc(this._highlight_input[0],this._highlight_input[1],6,0,2*Math.PI),a.fill())}this.dragging_rectangle&&
|
||||
(a.strokeStyle="#FFF",a.strokeRect(this.dragging_rectangle[0],this.dragging_rectangle[1],this.dragging_rectangle[2],this.dragging_rectangle[3]));if(this.over_link_center&&this.render_link_tooltip)this.drawLinkTooltip(a,this.over_link_center);else if(this.onDrawLinkTooltip)this.onDrawLinkTooltip(a,null);if(this.onDrawForeground)this.onDrawForeground(a,this.visible_rect);a.restore()}if(this.onDrawOverlay)this.onDrawOverlay(a);this.dirty_area&&a.restore();a.finish2D&&a.finish2D()}};f.prototype.renderInfo=
|
||||
function(a,b,d){b=b||0;d=d||0;a.save();a.translate(b,d);a.font="10px Arial";a.fillStyle="#888";this.graph?(a.fillText("T: "+this.graph.globaltime.toFixed(2)+"s",5,13),a.fillText("I: "+this.graph.iteration,5,26),a.fillText("N: "+this.graph._nodes.length+" ["+this.visible_nodes.length+"]",5,39),a.fillText("V: "+this.graph._version,5,52),a.fillText("FPS:"+this.fps.toFixed(2),5,65)):a.fillText("No graph selected",5,13);a.restore()};f.prototype.drawBackCanvas=function(){var a=this.bgcanvas;if(a.width!=
|
||||
this.canvas.width||a.height!=this.canvas.height)a.width=this.canvas.width,a.height=this.canvas.height;this.bgctx||(this.bgctx=this.bgcanvas.getContext("2d"));var b=this.bgctx;b.start&&b.start();this.clear_background&&b.clearRect(0,0,a.width,a.height);if(this._graph_stack&&this._graph_stack.length){b.save();var d=this.graph._subgraph_node;b.strokeStyle=d.bgcolor;b.lineWidth=10;b.strokeRect(1,1,a.width-2,a.height-2);b.lineWidth=1;b.font="40px Arial";b.textAlign="center";b.fillStyle=d.bgcolor||"#AAA";
|
||||
for(var e="",c=1;c<this._graph_stack.length;++c)e+=this._graph_stack[c]._subgraph_node.getTitle()+" >> ";b.fillText(e+d.getTitle(),0.5*a.width,40);b.restore()}d=!1;this.onRenderBackground&&(d=this.onRenderBackground(a,b));b.restore();b.setTransform(1,0,0,1,0,0);this.visible_links.length=0;if(this.graph){b.save();this.ds.toCanvasContext(b);if(this.background_image&&0.5<this.ds.scale&&!d){b.globalAlpha=this.zoom_modify_alpha?(1-0.5/this.ds.scale)*this.editor_alpha:this.editor_alpha;b.imageSmoothingEnabled=
|
||||
b.mozImageSmoothingEnabled=b.imageSmoothingEnabled=!1;if(!this._bg_img||this._bg_img.name!=this.background_image){this._bg_img=new Image;this._bg_img.name=this.background_image;this._bg_img.src=this.background_image;var h=this;this._bg_img.onload=function(){h.draw(!0,!0)}}d=null;null==this._pattern&&0<this._bg_img.width?(d=b.createPattern(this._bg_img,"repeat"),this._pattern_img=this._bg_img,this._pattern=d):d=this._pattern;d&&(b.fillStyle=d,b.fillRect(this.visible_area[0],this.visible_area[1],this.visible_area[2],
|
||||
this.visible_area[3]),b.fillStyle="transparent");b.globalAlpha=1;b.imageSmoothingEnabled=b.mozImageSmoothingEnabled=b.imageSmoothingEnabled=!0}this.graph._groups.length&&!this.live_mode&&this.drawGroups(a,b);if(this.onDrawBackground)this.onDrawBackground(b,this.visible_area);this.onBackgroundRender&&(console.error("WARNING! onBackgroundRender deprecated, now is named onDrawBackground "),this.onBackgroundRender=null);this.render_canvas_border&&(b.strokeStyle="#235",b.strokeRect(0,0,a.width,a.height));
|
||||
this.render_connections_shadows?(b.shadowColor="#000",b.shadowOffsetX=0,b.shadowOffsetY=0,b.shadowBlur=6):b.shadowColor="rgba(0,0,0,0)";this.live_mode||this.drawConnections(b);b.shadowColor="rgba(0,0,0,0)";b.restore()}b.finish&&b.finish();this.dirty_bgcanvas=!1;this.dirty_canvas=!0};var k=new Float32Array(2);f.prototype.drawNode=function(a,b){this.current_node=a;var d=a.color||a.constructor.color||e.NODE_DEFAULT_COLOR,c=a.bgcolor||a.constructor.bgcolor||e.NODE_DEFAULT_BGCOLOR;if(this.live_mode){if(!a.flags.collapsed&&
|
||||
(b.shadowColor="transparent",a.onDrawForeground))a.onDrawForeground(b,this,this.canvas)}else{var p=this.editor_alpha;b.globalAlpha=p;this.render_shadows?(b.shadowColor=e.DEFAULT_SHADOW_COLOR,b.shadowOffsetX=2*this.ds.scale,b.shadowOffsetY=2*this.ds.scale,b.shadowBlur=3*this.ds.scale):b.shadowColor="transparent";if(!a.flags.collapsed||!a.onDrawCollapsed||!0!=a.onDrawCollapsed(b,this)){var h=a._shape||e.BOX_SHAPE;k.set(a.size);var f=a.horizontal;if(a.flags.collapsed){b.font=this.inner_text_font;var n=
|
||||
a.getTitle?a.getTitle():a.title;null!=n&&(a._collapsed_width=Math.min(a.size[0],b.measureText(n).width+2*e.NODE_TITLE_HEIGHT),k[0]=a._collapsed_width,k[1]=0)}a.clip_area&&(b.save(),b.beginPath(),h==e.BOX_SHAPE?b.rect(0,0,k[0],k[1]):h==e.ROUND_SHAPE?b.roundRect(0,0,k[0],k[1],10):h==e.CIRCLE_SHAPE&&b.arc(0.5*k[0],0.5*k[1],0.5*k[0],0,2*Math.PI),b.clip());a.has_errors&&(c="red");this.drawNodeShape(a,b,k,d,c,a.is_selected,a.mouseOver);b.shadowColor="transparent";if(a.onDrawForeground)a.onDrawForeground(b,
|
||||
this,this.canvas);b.textAlign=f?"center":"left";b.font=this.inner_text_font;c=0.6<this.ds.scale;h=this.connecting_output;b.lineWidth=1;var n=0,t=new Float32Array(2);if(!a.flags.collapsed){if(a.inputs)for(d=0;d<a.inputs.length;d++){var m=a.inputs[d];b.globalAlpha=p;this.connecting_node&&!e.isValidConnection(m.type,h.type)&&(b.globalAlpha=0.4*p);b.fillStyle=null!=m.link?m.color_on||this.default_connection_color.input_on:m.color_off||this.default_connection_color.input_off;var l=a.getConnectionPos(!0,
|
||||
d,t);l[0]-=a.pos[0];l[1]-=a.pos[1];n<l[1]+0.5*e.NODE_SLOT_HEIGHT&&(n=l[1]+0.5*e.NODE_SLOT_HEIGHT);b.beginPath();m.type===e.EVENT||m.shape===e.BOX_SHAPE?f?b.rect(l[0]-5+0.5,l[1]-8+0.5,10,14):b.rect(l[0]-6+0.5,l[1]-5+0.5,14,10):m.shape===e.ARROW_SHAPE?(b.moveTo(l[0]+8,l[1]+0.5),b.lineTo(l[0]-4,l[1]+6+0.5),b.lineTo(l[0]-4,l[1]-6+0.5),b.closePath()):b.arc(l[0],l[1],4,0,2*Math.PI);b.fill();if(c){var g=null!=m.label?m.label:m.name;g&&(b.fillStyle=e.NODE_TEXT_COLOR,f||m.dir==e.UP?b.fillText(g,l[0],l[1]-
|
||||
10):b.fillText(g,l[0]+10,l[1]+5))}}this.connecting_node&&(b.globalAlpha=0.4*p);b.textAlign=f?"center":"right";b.strokeStyle="black";if(a.outputs)for(d=0;d<a.outputs.length;d++)if(m=a.outputs[d],l=a.getConnectionPos(!1,d,t),l[0]-=a.pos[0],l[1]-=a.pos[1],n<l[1]+0.5*e.NODE_SLOT_HEIGHT&&(n=l[1]+0.5*e.NODE_SLOT_HEIGHT),b.fillStyle=m.links&&m.links.length?m.color_on||this.default_connection_color.output_on:m.color_off||this.default_connection_color.output_off,b.beginPath(),m.type===e.EVENT||m.shape===e.BOX_SHAPE?
|
||||
f?b.rect(l[0]-5+0.5,l[1]-8+0.5,10,14):b.rect(l[0]-6+0.5,l[1]-5+0.5,14,10):m.shape===e.ARROW_SHAPE?(b.moveTo(l[0]+8,l[1]+0.5),b.lineTo(l[0]-4,l[1]+6+0.5),b.lineTo(l[0]-4,l[1]-6+0.5),b.closePath()):b.arc(l[0],l[1],4,0,2*Math.PI),b.fill(),b.stroke(),c&&(g=null!=m.label?m.label:m.name))b.fillStyle=e.NODE_TEXT_COLOR,f||m.dir==e.DOWN?b.fillText(g,l[0],l[1]-8):b.fillText(g,l[0]-10,l[1]+5);b.textAlign="left";b.globalAlpha=1;if(a.widgets){if(f||a.widgets_up)n=2;this.drawNodeWidgets(a,n,b,this.node_widget&&
|
||||
this.node_widget[0]==a?this.node_widget[1]:null)}}else if(this.render_collapsed_slots){p=c=null;if(a.inputs)for(d=0;d<a.inputs.length;d++)if(m=a.inputs[d],null!=m.link){c=m;break}if(a.outputs)for(d=0;d<a.outputs.length;d++)m=a.outputs[d],m.links&&m.links.length&&(p=m);c&&(d=0,c=-0.5*e.NODE_TITLE_HEIGHT,f&&(d=0.5*a._collapsed_width,c=-e.NODE_TITLE_HEIGHT),b.fillStyle="#686",b.beginPath(),m.type===e.EVENT||m.shape===e.BOX_SHAPE?b.rect(d-7+0.5,c-4,14,8):m.shape===e.ARROW_SHAPE?(b.moveTo(d+8,c),b.lineTo(d+
|
||||
-4,c-4),b.lineTo(d+-4,c+4),b.closePath()):b.arc(d,c,4,0,2*Math.PI),b.fill());p&&(d=a._collapsed_width,c=-0.5*e.NODE_TITLE_HEIGHT,f&&(d=0.5*a._collapsed_width,c=0),b.fillStyle="#686",b.strokeStyle="black",b.beginPath(),m.type===e.EVENT||m.shape===e.BOX_SHAPE?b.rect(d-7+0.5,c-4,14,8):m.shape===e.ARROW_SHAPE?(b.moveTo(d+6,c),b.lineTo(d-6,c-4),b.lineTo(d-6,c+4),b.closePath()):b.arc(d,c,4,0,2*Math.PI),b.fill())}a.clip_area&&b.restore();b.globalAlpha=1}}};f.prototype.drawLinkTooltip=function(a,b){var d=
|
||||
b._pos;a.fillStyle="black";a.beginPath();a.arc(d[0],d[1],3,0,2*Math.PI);a.fill();if(null!=b.data&&(!this.onDrawLinkTooltip||!0!=this.onDrawLinkTooltip(a,b,this))){var e=b.data,c=null,c=e.constructor===Number?e.toFixed(2):e.constructor===String?'"'+e+'"':e.constructor===Boolean?String(e):e.toToolTip?e.toToolTip():"["+e.constructor.name+"]";null!=c&&(a.font="14px Courier New",e=a.measureText(c).width+20,a.shadowColor="black",a.shadowOffsetX=2,a.shadowOffsetY=2,a.shadowBlur=3,a.fillStyle="#454",a.beginPath(),
|
||||
a.roundRect(d[0]-0.5*e,d[1]-15-24,e,24,3,3),a.moveTo(d[0]-10,d[1]-15),a.lineTo(d[0]+10,d[1]-15),a.lineTo(d[0],d[1]-5),a.fill(),a.shadowColor="transparent",a.textAlign="center",a.fillStyle="#CEC",a.fillText(c,d[0],d[1]-15-24*0.3))}};var n=new Float32Array(4);f.prototype.drawNodeShape=function(a,b,d,c,p,h,k){b.strokeStyle=c;b.fillStyle=p;p=e.NODE_TITLE_HEIGHT;var m=0.5>this.ds.scale,t=a._shape||a.constructor.shape||e.ROUND_SHAPE,l=a.constructor.title_mode,g=!0;l==e.TRANSPARENT_TITLE?g=!1:l==e.AUTOHIDE_TITLE&&
|
||||
k&&(g=!0);n[0]=0;n[1]=g?-p:0;n[2]=d[0]+1;n[3]=g?d[1]+p:d[1];k=b.globalAlpha;b.beginPath();t==e.BOX_SHAPE||m?b.fillRect(n[0],n[1],n[2],n[3]):t==e.ROUND_SHAPE||t==e.CARD_SHAPE?b.roundRect(n[0],n[1],n[2],n[3],this.round_radius,t==e.CARD_SHAPE?0:this.round_radius):t==e.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,n[2],2));b.shadowColor="transparent";if(a.onDrawBackground)a.onDrawBackground(b,
|
||||
this,this.canvas);if(g||l==e.TRANSPARENT_TITLE){if(a.onDrawTitleBar)a.onDrawTitleBar(b,p,d,this.ds.scale,c);else if(l!=e.TRANSPARENT_TITLE&&(a.constructor.title_color||this.render_title_colored)){g=a.constructor.title_color||c;a.flags.collapsed&&(b.shadowColor=e.DEFAULT_SHADOW_COLOR);if(this.use_gradients){var s=f.gradients[g];s||(s=f.gradients[g]=b.createLinearGradient(0,0,400,0),s.addColorStop(0,g),s.addColorStop(1,"#000"));b.fillStyle=s}else b.fillStyle=g;b.beginPath();t==e.BOX_SHAPE||m?b.rect(0,
|
||||
-p,d[0]+1,p):t!=e.ROUND_SHAPE&&t!=e.CARD_SHAPE||b.roundRect(0,-p,d[0]+1,p,this.round_radius,a.flags.collapsed?this.round_radius:0);b.fill();b.shadowColor="transparent"}if(a.onDrawTitleBox)a.onDrawTitleBox(b,p,d,this.ds.scale);else t==e.ROUND_SHAPE||t==e.CIRCLE_SHAPE||t==e.CARD_SHAPE?(m&&(b.fillStyle="black",b.beginPath(),b.arc(0.5*p,-0.5*p,6,0,2*Math.PI),b.fill()),b.fillStyle=a.boxcolor||e.NODE_DEFAULT_BOXCOLOR,b.beginPath(),b.arc(0.5*p,-0.5*p,5,0,2*Math.PI),b.fill()):(m&&(b.fillStyle="black",b.fillRect(0.5*
|
||||
(p-10)-1,-0.5*(p+10)-1,12,12)),b.fillStyle=a.boxcolor||e.NODE_DEFAULT_BOXCOLOR,b.fillRect(0.5*(p-10),-0.5*(p+10),10,10));b.globalAlpha=k;if(a.onDrawTitleText)a.onDrawTitleText(b,p,d,this.ds.scale,this.title_text_font,h);!m&&(b.font=this.title_text_font,m=a.getTitle())&&(b.fillStyle=h?"white":a.constructor.title_text_color||this.node_title_color,a.flags.collapsed?(b.textAlign="center",k=b.measureText(m),b.fillText(m,p+0.5*k.width,e.NODE_TITLE_TEXT_Y-p),b.textAlign="left"):(b.textAlign="left",b.fillText(m,
|
||||
p,e.NODE_TITLE_TEXT_Y-p)));if(a.onDrawTitle)a.onDrawTitle(b)}if(h){if(a.onBounding)a.onBounding(n);l==e.TRANSPARENT_TITLE&&(n[1]-=p,n[3]+=p);b.lineWidth=1;b.globalAlpha=0.8;b.beginPath();t==e.BOX_SHAPE?b.rect(-6+n[0],-6+n[1],12+n[2],12+n[3]):t==e.ROUND_SHAPE||t==e.CARD_SHAPE&&a.flags.collapsed?b.roundRect(-6+n[0],-6+n[1],12+n[2],12+n[3],2*this.round_radius):t==e.CARD_SHAPE?b.roundRect(-6+n[0],-6+n[1],12+n[2],12+n[3],2*this.round_radius,2):t==e.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=c;b.globalAlpha=1}};var D=new Float32Array(4),h=new Float32Array(4),t=new Float32Array(2),m=new Float32Array(2);f.prototype.drawConnections=function(a){var b=e.getTime(),d=this.visible_area;D[0]=d[0]-20;D[1]=d[1]-20;D[2]=d[2]+40;D[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,c=0,p=d.length;c<p;++c){var k=d[c];if(k.inputs&&k.inputs.length)for(var f=
|
||||
0;f<k.inputs.length;++f){var n=k.inputs[f];if(n&&null!=n.link&&(n=this.graph.links[n.link])){var l=this.graph.getNodeById(n.origin_id);if(null!=l){var g=n.origin_slot,s=null,s=-1==g?[l.pos[0]+10,l.pos[1]+10]:l.getConnectionPos(!1,g,t),w=k.getConnectionPos(!0,f,m);h[0]=s[0];h[1]=s[1];h[2]=w[0]-s[0];h[3]=w[1]-s[1];0>h[2]&&(h[0]+=h[2],h[2]=Math.abs(h[2]));0>h[3]&&(h[1]+=h[3],h[3]=Math.abs(h[3]));if(u(h,D)){var B=l.outputs[g],g=k.inputs[f];if(B&&g&&(l=B.dir||(l.horizontal?e.DOWN:e.RIGHT),g=g.dir||(k.horizontal?
|
||||
e.UP:e.LEFT),this.renderLink(a,s,w,n,!1,0,null,l,g),n&&n._last_time&&1E3>b-n._last_time)){var B=2-0.002*(b-n._last_time),J=a.globalAlpha;a.globalAlpha=J*B;this.renderLink(a,s,w,n,!0,B,"white",l,g);a.globalAlpha=J}}}}}}a.globalAlpha=1};f.prototype.renderLink=function(a,b,d,c,p,h,k,n,m,t){c&&this.visible_links.push(c);!k&&c&&(k=c.color||f.link_type_colors[c.type]);k||(k=this.default_link_color);null!=c&&this.highlighted_links[c.id]&&(k="#FFF");n=n||e.RIGHT;m=m||e.LEFT;var l=y(b,d);this.render_connections_border&&
|
||||
0.6<this.ds.scale&&(a.lineWidth=this.connections_width+4);a.lineJoin="round";t=t||1;1<t&&(a.lineWidth=0.5);a.beginPath();for(var g=0;g<t;g+=1){var B=5*(g-0.5*(t-1));if(this.links_render_mode==e.SPLINE_LINK){a.moveTo(b[0],b[1]+B);var s=0,w=0,u=0,r=0;switch(n){case e.LEFT:s=-0.25*l;break;case e.RIGHT:s=0.25*l;break;case e.UP:w=-0.25*l;break;case e.DOWN:w=0.25*l}switch(m){case e.LEFT:u=-0.25*l;break;case e.RIGHT:u=0.25*l;break;case e.UP:r=-0.25*l;break;case e.DOWN:r=0.25*l}a.bezierCurveTo(b[0]+s,b[1]+
|
||||
w+B,d[0]+u,d[1]+r+B,d[0],d[1]+B)}else if(this.links_render_mode==e.LINEAR_LINK){a.moveTo(b[0],b[1]+B);r=u=w=s=0;switch(n){case e.LEFT:s=-1;break;case e.RIGHT:s=1;break;case e.UP:w=-1;break;case e.DOWN:w=1}switch(m){case e.LEFT:u=-1;break;case e.RIGHT:u=1;break;case e.UP:r=-1;break;case e.DOWN:r=1}a.lineTo(b[0]+15*s,b[1]+15*w+B);a.lineTo(d[0]+15*u,d[1]+15*r+B);a.lineTo(d[0],d[1]+B)}else if(this.links_render_mode==e.STRAIGHT_LINK)a.moveTo(b[0],b[1]),B=b[0],s=b[1],w=d[0],u=d[1],n==e.RIGHT?B+=10:s+=10,
|
||||
m==e.LEFT?w-=10:u-=10,a.lineTo(B,s),a.lineTo(0.5*(B+w),s),a.lineTo(0.5*(B+w),u),a.lineTo(w,u),a.lineTo(d[0],d[1]);else return}this.render_connections_border&&0.6<this.ds.scale&&!p&&(a.strokeStyle="rgba(0,0,0,0.5)",a.stroke());a.lineWidth=this.connections_width;a.fillStyle=a.strokeStyle=k;a.stroke();p=this.computeConnectionPoint(b,d,0.5,n,m);c&&c._pos&&(c._pos[0]=p[0],c._pos[1]=p[1]);0.6<=this.ds.scale&&this.highquality_render&&m!=e.CENTER&&(this.render_connection_arrows&&(g=this.computeConnectionPoint(b,
|
||||
d,0.25,n,m),c=this.computeConnectionPoint(b,d,0.26,n,m),t=this.computeConnectionPoint(b,d,0.75,n,m),l=this.computeConnectionPoint(b,d,0.76,n,m),s=B=0,this.render_curved_connections?(B=-Math.atan2(c[0]-g[0],c[1]-g[1]),s=-Math.atan2(l[0]-t[0],l[1]-t[1])):s=B=d[1]>b[1]?0:Math.PI,a.save(),a.translate(g[0],g[1]),a.rotate(B),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore(),a.save(),a.translate(t[0],t[1]),a.rotate(s),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),
|
||||
a.fill(),a.restore()),a.beginPath(),a.arc(p[0],p[1],5,0,2*Math.PI),a.fill());if(h)for(a.fillStyle=k,g=0;5>g;++g)h=(0.001*e.getTime()+0.2*g)%1,p=this.computeConnectionPoint(b,d,h,n,m),a.beginPath(),a.arc(p[0],p[1],5,0,2*Math.PI),a.fill()};f.prototype.computeConnectionPoint=function(a,b,d,c,p){c=c||e.RIGHT;p=p||e.LEFT;var h=y(a,b),k=[a[0],a[1]],f=[b[0],b[1]];switch(c){case e.LEFT:k[0]+=-0.25*h;break;case e.RIGHT:k[0]+=0.25*h;break;case e.UP:k[1]+=-0.25*h;break;case e.DOWN:k[1]+=0.25*h}switch(p){case e.LEFT:f[0]+=
|
||||
-0.25*h;break;case e.RIGHT:f[0]+=0.25*h;break;case e.UP:f[1]+=-0.25*h;break;case e.DOWN:f[1]+=0.25*h}c=(1-d)*(1-d)*(1-d);p=3*(1-d)*(1-d)*d;h=3*(1-d)*d*d;d*=d*d;return[c*a[0]+p*k[0]+h*f[0]+d*b[0],c*a[1]+p*k[1]+h*f[1]+d*b[1]]};f.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 c=b[d];a.fillStyle="black";a.fillRect(c.pos[0]-e.NODE_TITLE_HEIGHT,c.pos[1]-
|
||||
e.NODE_TITLE_HEIGHT,e.NODE_TITLE_HEIGHT,e.NODE_TITLE_HEIGHT);0==c.order&&a.strokeRect(c.pos[0]-e.NODE_TITLE_HEIGHT+0.5,c.pos[1]-e.NODE_TITLE_HEIGHT+0.5,e.NODE_TITLE_HEIGHT,e.NODE_TITLE_HEIGHT);a.fillStyle="#FFF";a.fillText(c.order,c.pos[0]+-0.5*e.NODE_TITLE_HEIGHT,c.pos[1]-6)}a.globalAlpha=1};f.prototype.drawNodeWidgets=function(a,b,d,c){if(!a.widgets||!a.widgets.length)return 0;var h=a.size[0],k=a.widgets;b+=2;var f=e.NODE_WIDGET_HEIGHT,n=0.5<this.ds.scale;d.save();d.globalAlpha=this.editor_alpha;
|
||||
for(var m=e.WIDGET_OUTLINE_COLOR,t=e.WIDGET_BGCOLOR,l=e.WIDGET_TEXT_COLOR,g=e.WIDGET_SECONDARY_TEXT_COLOR,B=0;B<k.length;++B){var s=k[B],w=b;s.y&&(w=s.y);s.last_y=w;d.strokeStyle=m;d.fillStyle="#222";d.textAlign="left";switch(s.type){case "button":s.clicked&&(d.fillStyle="#AAA",s.clicked=!1,this.dirty_canvas=!0);d.fillRect(15,w,h-30,f);d.strokeRect(15,w,h-30,f);n&&(d.textAlign="center",d.fillStyle=l,d.fillText(s.name,0.5*h,w+0.7*f));break;case "toggle":d.textAlign="left";d.strokeStyle=m;d.fillStyle=
|
||||
t;d.beginPath();d.roundRect(15,b,h-30,f,0.5*f);d.fill();d.stroke();d.fillStyle=s.value?"#89A":"#333";d.beginPath();d.arc(h-30,w+0.5*f,0.36*f,0,2*Math.PI);d.fill();n&&(d.fillStyle=g,null!=s.name&&d.fillText(s.name,30,w+0.7*f),d.fillStyle=s.value?l:g,d.textAlign="right",d.fillText(s.value?s.options.on||"true":s.options.off||"false",h-40,w+0.7*f));break;case "slider":d.fillStyle=t;d.fillRect(15,w,h-30,f);var u=s.options.max-s.options.min,r=(s.value-s.options.min)/u;d.fillStyle=c==s?"#89A":"#678";d.fillRect(15,
|
||||
w,r*(h-30),f);d.strokeRect(15,w,h-30,f);s.marker&&(u=(s.marker-s.options.min)/u,d.fillStyle="#AA9",d.fillRect(15+u*(h-30),w,2,f));n&&(d.textAlign="center",d.fillStyle=l,d.fillText(s.name+" "+Number(s.value).toFixed(3),0.5*h,w+0.7*f));break;case "number":case "combo":d.textAlign="left";d.strokeStyle=m;d.fillStyle=t;d.beginPath();d.roundRect(15,b,h-30,f,0.5*f);d.fill();d.stroke();n&&(d.fillStyle=l,d.beginPath(),d.moveTo(31,b+5),d.lineTo(21,b+0.5*f),d.lineTo(31,b+f-5),d.moveTo(h-15-16,b+5),d.lineTo(h-
|
||||
15-6,b+0.5*f),d.lineTo(h-15-16,b+f-5),d.fill(),d.fillStyle=g,d.fillText(s.name,35,w+0.7*f),d.fillStyle=l,d.textAlign="right","number"==s.type?d.fillText(Number(s.value).toFixed(void 0!==s.options.precision?s.options.precision:3),h-30-20,w+0.7*f):d.fillText(s.value,h-30-20,w+0.7*f));break;case "string":case "text":d.textAlign="left";d.strokeStyle=m;d.fillStyle=t;d.beginPath();d.roundRect(15,b,h-30,f,0.5*f);d.fill();d.stroke();n&&(d.fillStyle=g,null!=s.name&&d.fillText(s.name,30,w+0.7*f),d.fillStyle=
|
||||
l,d.textAlign="right",d.fillText(s.value,h-30,w+0.7*f));break;default:s.draw&&s.draw(d,a,s,w,f)}b+=f+4}d.restore()};f.prototype.processNodeWidgets=function(a,b,d,c){function h(e,c){e.value=c;e.property&&void 0!==a.properties[e.property]&&a.setProperty(e.property,c);e.callback&&e.callback(e.value,m,a,b,d)}if(!a.widgets||!a.widgets.length)return null;for(var k=b[0]-a.pos[0],f=b[1]-a.pos[1],n=a.size[0],m=this,t=this.getCanvasWindow(),l=0;l<a.widgets.length;++l){var g=a.widgets[l];if(g==c||6<k&&k<n-12&&
|
||||
f>g.last_y&&f<g.last_y+e.NODE_WIDGET_HEIGHT){switch(g.type){case "button":if("mousemove"===d.type)break;g.callback&&setTimeout(function(){g.callback(g,m,a,b)},20);this.dirty_canvas=g.clicked=!0;break;case "slider":t=Math.clamp((k-10)/(n-20),0,1);g.value=g.options.min+(g.options.max-g.options.min)*t;g.callback&&setTimeout(function(){h(g,g.value)},20);this.dirty_canvas=!0;break;case "number":case "combo":if("mousemove"==d.type&&"number"==g.type)g.value+=0.1*d.deltaX*(g.options.step||1),null!=g.options.min&&
|
||||
g.value<g.options.min&&(g.value=g.options.min),null!=g.options.max&&g.value>g.options.max&&(g.value=g.options.max);else if("mousedown"==d.type)if((c=g.options.values)&&c.constructor===Function&&(c=g.options.values(g,a)),k=40>k?-1:k>n-40?1:0,"number"==g.type)g.value+=0.1*k*(g.options.step||1),null!=g.options.min&&g.value<g.options.min&&(g.value=g.options.min),null!=g.options.max&&g.value>g.options.max&&(g.value=g.options.max);else if(k)t=c.indexOf(g.value)+k,t>=c.length&&(t=0),0>t&&(t=c.length-1),
|
||||
g.value=c[t];else{new e.ContextMenu(c,{scale:Math.max(1,this.ds.scale),event:d,className:"dark",callback:B.bind(g)},t);var B=function(a,b,d){this.value=a;h(this,a);m.dirty_canvas=!0;return!1}}setTimeout(function(){h(this,this.value)}.bind(g),20);this.dirty_canvas=!0;break;case "toggle":"mousedown"==d.type&&(g.value=!g.value,g.callback&&setTimeout(function(){h(g,g.value)},20));break;case "string":case "text":"mousedown"==d.type&&this.prompt("Value",g.value,function(a){this.value=a;h(this,a)}.bind(g),
|
||||
d);break;default:g.mouse&&g.mouse(ctx,d,[k,f],a)}return g}}return null};f.prototype.drawGroups=function(a,b){if(this.graph){var d=this.graph._groups;b.save();b.globalAlpha=0.5*this.editor_alpha;for(var c=0;c<d.length;++c){var h=d[c];if(u(this.visible_area,h._bounding)){b.fillStyle=h.color||"#335";b.strokeStyle=h.color||"#335";var k=h._pos,f=h._size;b.globalAlpha=0.25*this.editor_alpha;b.beginPath();b.rect(k[0]+0.5,k[1]+0.5,f[0],f[1]);b.fill();b.globalAlpha=this.editor_alpha;b.stroke();b.beginPath();
|
||||
b.moveTo(k[0]+f[0],k[1]+f[1]);b.lineTo(k[0]+f[0]-10,k[1]+f[1]);b.lineTo(k[0]+f[0],k[1]+f[1]-10);b.fill();f=h.font_size||e.DEFAULT_GROUP_FONT_SIZE;b.font=f+"px Arial";b.fillText(h.title,k[0]+4,k[1]+f)}}b.restore()}};f.prototype.adjustNodesSize=function(){for(var a=this.graph._nodes,b=0;b<a.length;++b)a[b].size=a[b].computeSize();this.setDirty(!0,!0)};f.prototype.resize=function(a,b){if(!a&&!b){var d=this.canvas.parentNode;a=d.offsetWidth;b=d.offsetHeight}if(this.canvas.width!=a||this.canvas.height!=
|
||||
b)this.canvas.width=a,this.canvas.height=b,this.bgcanvas.width=this.canvas.width,this.bgcanvas.height=this.canvas.height,this.setDirty(!0,!0)};f.prototype.switchLiveMode=function(a){if(a){var b=this,d=this.live_mode?1.1:0.9;this.live_mode&&(this.live_mode=!1,this.editor_alpha=0.1);var e=setInterval(function(){b.editor_alpha*=d;b.dirty_canvas=!0;b.dirty_bgcanvas=!0;1>d&&0.01>b.editor_alpha&&(clearInterval(e),1>d&&(b.live_mode=!0));1<d&&0.99<b.editor_alpha&&(clearInterval(e),b.editor_alpha=1)},1)}else this.live_mode=
|
||||
!this.live_mode,this.dirty_bgcanvas=this.dirty_canvas=!0};f.prototype.onNodeSelectionChange=function(a){};f.prototype.touchHandler=function(a){var b=a.changedTouches[0],d="";switch(a.type){case "touchstart":d="mousedown";break;case "touchmove":d="mousemove";break;case "touchend":d="mouseup";break;default:return}var e=this.getCanvasWindow(),c=e.document.createEvent("MouseEvent");c.initMouseEvent(d,!0,!0,e,1,b.screenX,b.screenY,b.clientX,b.clientY,!1,!1,!1,!1,0,null);b.target.dispatchEvent(c);a.preventDefault()};
|
||||
f.onGroupAdd=function(a,b,d){a=f.active_canvas;a.getCanvasWindow();b=new e.LGraphGroup;b.pos=a.convertEventToCanvasOffset(d);a.graph.add(b)};f.onMenuAdd=function(a,b,d,c){function h(a,b){var d=c.getFirstEvent(),f=e.createNode(a.value);f&&(f.pos=k.convertEventToCanvasOffset(d),k.graph.add(f))}var k=f.active_canvas,n=k.getCanvasWindow();a=e.getNodeTypesCategories(k.filter);b=[];for(var m in a)a[m]&&b.push({value:a[m],content:a[m],has_submenu:!0});var g=new e.ContextMenu(b,{event:d,callback:function(a,
|
||||
b,d){a=e.getNodeTypesInCategory(a.value,k.filter);b=[];for(var c in a)a[c].skip_list||b.push({content:a[c].title,value:a[c].type});new e.ContextMenu(b,{event:d,callback:h,parentMenu:g},n);return!1},parentMenu:c},n);return!1};f.onMenuCollapseAll=function(){};f.onMenuNodeEdit=function(){};f.showMenuNodeOptionalInputs=function(a,b,d,c,h){function k(a,b,d){h&&(a.callback&&a.callback.call(n,h,a,b,d),a.value&&(h.addInput(a.value[0],a.value[1],a.value[2]),h.setDirtyCanvas(!0,!0)))}if(h){var n=this;a=f.active_canvas.getCanvasWindow();
|
||||
b=h.optional_inputs;h.onGetInputs&&(b=h.onGetInputs());var m=[];if(b)for(var g in b){var t=b[g];if(t){var l=t[0];t[2]&&t[2].label&&(l=t[2].label);l={content:l,value:t};t[1]==e.ACTION&&(l.className="event");m.push(l)}else m.push(null)}this.onMenuNodeInputs&&(m=this.onMenuNodeInputs(m));if(m.length)return new e.ContextMenu(m,{event:d,callback:k,parentMenu:c,node:h},a),!1}};f.showMenuNodeOptionalOutputs=function(a,b,d,c,h){function k(a,b,d){if(h&&(a.callback&&a.callback.call(n,h,a,b,d),a.value))if(d=
|
||||
a.value[1],!d||d.constructor!==Object&&d.constructor!==Array)h.addOutput(a.value[0],a.value[1],a.value[2]),h.setDirtyCanvas(!0,!0);else{a=[];for(var f in d)a.push({content:f,value:d[f]});new e.ContextMenu(a,{event:b,callback:k,parentMenu:c,node:h});return!1}}if(h){var n=this;a=f.active_canvas.getCanvasWindow();b=h.optional_outputs;h.onGetOutputs&&(b=h.onGetOutputs());var m=[];if(b)for(var g in b){var t=b[g];if(!t)m.push(null);else if(!h.flags||!h.flags.skip_repeated_outputs||-1==h.findOutputSlot(t[0])){var l=
|
||||
t[0];t[2]&&t[2].label&&(l=t[2].label);l={content:l,value:t};t[1]==e.EVENT&&(l.className="event");m.push(l)}}this.onMenuNodeOutputs&&(m=this.onMenuNodeOutputs(m));if(m.length)return new e.ContextMenu(m,{event:d,callback:k,parentMenu:c,node:h},a),!1}};f.onShowMenuNodeProperties=function(a,b,d,c,h){function k(a,b,d,e){h&&(b=this.getBoundingClientRect(),n.showEditPropertyValue(h,a.value,{position:[b.left,b.top]}))}if(h&&h.properties){var n=f.active_canvas;b=n.getCanvasWindow();var m=[],g;for(g in h.properties)a=
|
||||
void 0!==h.properties[g]?h.properties[g]:" ","object"==typeof a&&(a=JSON.stringify(a)),a=f.decodeHTML(a),m.push({content:"<span class='property_name'>"+g+"</span><span class='property_value'>"+a+"</span>",value:g});if(m.length)return new e.ContextMenu(m,{event:d,callback:k,parentMenu:c,allow_html:!0,node:h},b),!1}};f.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};f.onResizeNode=function(a,b,d,e,c){c&&(c.size=c.computeSize(),c.setDirtyCanvas(!0,!0))};f.prototype.showLinkMenu=
|
||||
function(a,b){var d=this;console.log(a.data);new e.ContextMenu(["Delete"],{event:b,title:null!=a.data?a.data.constructor.name:null,callback:function(b){switch(b){case "Delete":d.graph.removeLink(a.id)}}});return!1};f.onShowPropertyEditor=function(a,b,d,e,c){function h(){var b=m.value;"Number"==a.type?b=Number(b):"Boolean"==a.type&&(b=Boolean(b));c[k]=b;n.parentNode&&n.parentNode.removeChild(n);c.setDirtyCanvas(!0,!0)}var k=a.property||"title";b=c[k];var n=document.createElement("div");n.className=
|
||||
"graphdialog";n.innerHTML="<span class='name'></span><input autofocus type='text' class='value'/><button>OK</button>";n.querySelector(".name").innerText=k;var m=n.querySelector("input");m&&(m.value=b,m.addEventListener("blur",function(a){this.focus()}),m.addEventListener("keydown",function(a){13==a.keyCode&&(h(),a.preventDefault(),a.stopPropagation())}));b=f.active_canvas.canvas;d=b.getBoundingClientRect();var g=e=-20;d&&(e-=d.left,g-=d.top);event?(n.style.left=event.clientX+e+"px",n.style.top=event.clientY+
|
||||
g+"px"):(n.style.left=0.5*b.width+e+"px",n.style.top=0.5*b.height+g+"px");n.querySelector("button").addEventListener("click",h);b.parentNode.appendChild(n)};f.prototype.prompt=function(a,b,d,e){var c=this;a=a||"";var h=!1,k=document.createElement("div");k.className="graphdialog rounded";k.innerHTML="<span class='name'></span> <input autofocus type='text' class='value'/><button class='rounded'>OK</button>";k.close=function(){c.prompt_box=null;k.parentNode&&k.parentNode.removeChild(k)};1<this.ds.scale&&
|
||||
(k.style.transform="scale("+this.ds.scale+")");k.addEventListener("mouseleave",function(a){h||k.close()});c.prompt_box&&c.prompt_box.close();c.prompt_box=k;k.querySelector(".name").innerText=a;k.querySelector(".value").value=b;var n=k.querySelector("input");n.addEventListener("keydown",function(a){h=!0;if(27==a.keyCode)k.close();else if(13==a.keyCode)d&&d(this.value),k.close();else return;a.preventDefault();a.stopPropagation()});k.querySelector("button").addEventListener("click",function(a){d&&d(n.value);
|
||||
c.setDirty(!0);k.close()});a=f.active_canvas.canvas;b=a.getBoundingClientRect();var m=-20,g=-20;b&&(m-=b.left,g-=b.top);e?(k.style.left=e.clientX+m+"px",k.style.top=e.clientY+g+"px"):(k.style.left=0.5*a.width+m+"px",k.style.top=0.5*a.height+g+"px");a.parentNode.appendChild(k);setTimeout(function(){n.focus()},10);return k};f.search_limit=-1;f.prototype.showSearchBox=function(a){function b(b){if(b)if(h.onSearchBoxSelection)h.onSearchBoxSelection(b,a,B);else{var d=e.searchbox_extras[b.toLowerCase()];
|
||||
d&&(b=d.type);if(b=e.createNode(b))b.pos=B.convertEventToCanvasOffset(a),B.graph.add(b);if(d&&d.data){if(d.data.properties)for(var c in d.data.properties)b.addProperty(c,d.data.properties[c]);if(d.data.inputs)for(c in b.inputs=[],d.data.inputs)b.addOutput(d.data.inputs[c][0],d.data.inputs[c][1]);if(d.data.outputs)for(c in b.outputs=[],d.data.outputs)b.addOutput(d.data.outputs[c][0],d.data.outputs[c][1]);d.data.title&&(b.title=d.data.title);d.data.json&&b.configure(d.data.json)}}k.close()}function d(a){var b=
|
||||
l;l&&l.classList.remove("selected");l?(l=a?l.nextSibling:l.previousSibling)||(l=b):l=a?m.childNodes[0]:m.childNodes[m.childNodes.length];l&&(l.classList.add("selected"),l.scrollIntoView())}function c(){function a(d,e){var c=document.createElement("div");g||(g=d);c.innerText=d;c.dataset.type=escape(d);c.className="litegraph lite-search-item";e&&(c.className+=" "+e);c.addEventListener("click",function(a){b(unescape(this.dataset.type))});m.appendChild(c)}t=null;var d=s.value;g=null;m.innerHTML="";if(d)if(h.onSearchBox){var k=
|
||||
h.onSearchBox(m,d,B);if(k)for(var n=0;n<k.length;++n)a(k[n])}else{k=0;d=d.toLowerCase();for(n in e.searchbox_extras){var l=e.searchbox_extras[n];if(-1!==l.desc.toLowerCase().indexOf(d)&&(a(l.desc,"searchbox_extra"),-1!==f.search_limit&&k++>f.search_limit))break}if(Array.prototype.filter)for(l=Object.keys(e.registered_node_types).filter(function(a){return-1!==a.toLowerCase().indexOf(d)}),n=0;n<l.length&&!(a(l[n]),-1!==f.search_limit&&k++>f.search_limit);n++);else for(n in e.registered_node_types)if(-1!=
|
||||
n.indexOf(d)&&(a(n),-1!==f.search_limit&&k++>f.search_limit))break}}var h=this,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(){h.search_box=null;document.body.focus();setTimeout(function(){h.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)});h.search_box&&h.search_box.close();h.search_box=k;var m=k.querySelector(".helper"),g=null,t=null,l=null,s=k.querySelector("input");s&&(s.addEventListener("blur",function(a){this.focus()}),s.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)l?
|
||||
b(l.innerHTML):g?b(g):k.close();else{t&&clearInterval(t);t=setTimeout(c,10);return}a.preventDefault();a.stopPropagation()}));var B=f.active_canvas,w=B.canvas,u=w.getBoundingClientRect(),r=-20,z=-20;u&&(r-=u.left,z-=u.top);a?(k.style.left=a.clientX+r+"px",k.style.top=a.clientY+z+"px"):(k.style.left=0.5*w.width+r+"px",k.style.top=0.5*w.height+z+"px");w.parentNode.appendChild(k);s.focus();return k};f.prototype.showEditPropertyValue=function(a,b,d){function e(){c(l.value)}function c(d){"number"==typeof a.properties[b]&&
|
||||
(d=Number(d));if("array"==h||"object"==h)d=JSON.parse(d);a.properties[b]=d;a._graph&&a._graph._version++;if(a.onPropertyChanged)a.onPropertyChanged(b,d);g.close();a.setDirtyCanvas(!0,!0)}if(a&&void 0!==a.properties[b]){d=d||{};var h="string";null!==a.properties[b]&&(h=typeof a.properties[b]);var k=null;a.getPropertyInfo&&(k=a.getPropertyInfo(b));if(a.properties_info)for(var f=0;f<a.properties_info.length;++f)if(a.properties_info[f].name==b){k=a.properties_info[f];break}void 0!==k&&null!==k&&k.type&&
|
||||
(h=k.type);var n="";if("string"==h||"number"==h||"array"==h||"object"==h)n="<input autofocus type='text' class='value'/>";else if("enum"==h&&k.values){n="<select autofocus type='text' class='value'>";for(f in k.values)var m=k.values.constructor===Array?k.values[f]:f,n=n+("<option value='"+m+"' "+(m==a.properties[b]?"selected":"")+">"+k.values[f]+"</option>");n+="</select>"}else if("boolean"==h)n="<input autofocus type='checkbox' class='value' "+(a.properties[b]?"checked":"")+"/>";else{console.warn("unknown type: "+
|
||||
h);return}var g=this.createDialog("<span class='name'>"+b+"</span>"+n+"<button>OK</button>",d);if("enum"==h&&k.values){var l=g.querySelector("select");l.addEventListener("change",function(a){c(a.target.value)})}else if("boolean"==h)(l=g.querySelector("input"))&&l.addEventListener("click",function(a){c(!!l.checked)});else if(l=g.querySelector("input"))l.addEventListener("blur",function(a){this.focus()}),m=void 0!==a.properties[b]?a.properties[b]:"",m=JSON.stringify(m),l.value=m,l.addEventListener("keydown",
|
||||
function(a){13==a.keyCode&&(e(),a.preventDefault(),a.stopPropagation())});g.querySelector("button").addEventListener("click",e)}};f.prototype.createDialog=function(a,b){b=b||{};var d=document.createElement("div");d.className="graphdialog";d.innerHTML=a;var e=this.canvas.getBoundingClientRect(),c=-20,h=-20;e&&(c-=e.left,h-=e.top);b.position?(c+=b.position[0],h+=b.position[1]):b.event?(c+=b.event.clientX,h+=b.event.clientY):(c+=0.5*this.canvas.width,h+=0.5*this.canvas.height);d.style.left=c+"px";d.style.top=
|
||||
h+"px";this.canvas.parentNode.appendChild(d);d.close=function(){this.parentNode&&this.parentNode.removeChild(this)};return d};f.onMenuNodeCollapse=function(a,b,d,e,c){c.collapse()};f.onMenuNodePin=function(a,b,d,e,c){c.pin()};f.onMenuNodeMode=function(a,b,d,c,h){new e.ContextMenu(["Always","On Event","On Trigger","Never"],{event:d,callback:function(a){if(h)switch(a){case "On Event":h.mode=e.ON_EVENT;break;case "On Trigger":h.mode=e.ON_TRIGGER;break;case "Never":h.mode=e.NEVER;break;default:h.mode=
|
||||
e.ALWAYS}},parentMenu:c,node:h});return!1};f.onMenuNodeColors=function(a,b,d,c,h){if(!h)throw"no node for color";b=[];b.push({value:null,content:"<span style='display: block; padding-left: 4px;'>No color</span>"});for(var k in f.node_colors)a=f.node_colors[k],a={value:k,content:"<span style='display: block; color: #999; padding-left: 4px; border-left: 8px solid "+a.color+"; background-color:"+a.bgcolor+"'>"+k+"</span>"},b.push(a);new e.ContextMenu(b,{event:d,callback:function(a){h&&((a=a.value?f.node_colors[a.value]:
|
||||
null)?h.constructor===e.LGraphGroup?h.color=a.groupcolor:(h.color=a.color,h.bgcolor=a.bgcolor):(delete h.color,delete h.bgcolor),h.setDirtyCanvas(!0,!0))},parentMenu:c,node:h});return!1};f.onMenuNodeShapes=function(a,b,d,c,h){if(!h)throw"no node passed";new e.ContextMenu(e.VALID_SHAPES,{event:d,callback:function(a){h&&(h.shape=a,h.setDirtyCanvas(!0))},parentMenu:c,node:h});return!1};f.onMenuNodeRemove=function(a,b,d,c,e){if(!e)throw"no node passed";!1!==e.removable&&(e.graph.remove(e),e.setDirtyCanvas(!0,
|
||||
!0))};f.onMenuNodeClone=function(a,b,d,e,c){!1!=c.clonable&&(a=c.clone())&&(a.pos=[c.pos[0]+5,c.pos[1]+5],c.graph.add(a),c.setDirtyCanvas(!0,!0))};f.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"}};f.prototype.getCanvasMenuOptions=function(){var a=null;this.getMenuOptions?a=this.getMenuOptions():(a=[{content:"Add Node",has_submenu:!0,callback:f.onMenuAdd},{content:"Add Group",callback:f.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};f.prototype.getNodeMenuOptions=function(a){var b=null,b=a.getMenuOptions?a.getMenuOptions(this):[{content:"Inputs",has_submenu:!0,disabled:!0,callback:f.showMenuNodeOptionalInputs},{content:"Outputs",has_submenu:!0,disabled:!0,callback:f.showMenuNodeOptionalOutputs},null,{content:"Properties",has_submenu:!0,callback:f.onShowMenuNodeProperties},null,{content:"Title",callback:f.onShowPropertyEditor},{content:"Mode",
|
||||
has_submenu:!0,callback:f.onMenuNodeMode},{content:"Resize",callback:f.onResizeNode},{content:"Collapse",callback:f.onMenuNodeCollapse},{content:"Pin",callback:f.onMenuNodePin},{content:"Colors",has_submenu:!0,callback:f.onMenuNodeColors},{content:"Shapes",has_submenu:!0,callback:f.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))&&
|
||||
(d.push(null),b=d.concat(b));!1!==a.clonable&&b.push({content:"Clone",callback:f.onMenuNodeClone});!1!==a.removable&&b.push(null,{content:"Remove",callback:f.onMenuNodeRemove});if(a.graph&&a.graph.onGetNodeMenuOptions)a.graph.onGetNodeMenuOptions(b,a);return b};f.prototype.getGroupMenuOptions=function(a){return[{content:"Title",callback:f.onShowPropertyEditor},{content:"Color",has_submenu:!0,callback:f.onMenuNodeColors},{content:"Font size",property:"font_size",type:"Number",callback:f.onShowPropertyEditor},
|
||||
null,{content:"Remove",callback:f.onMenuNodeRemove}]};f.prototype.processContextMenu=function(a,b){var d=this,c=f.active_canvas.getCanvasWindow(),h=null,k={event:b,callback:function(b,c,e){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 h=b.input?a.getInputInfo(b.slot):a.getOutputInfo(b.slot),
|
||||
k=d.createDialog("<span class='name'>Name</span><input autofocus type='text'/><button>OK</button>",c),f=k.querySelector("input");f&&h&&(f.value=h.label||"");k.querySelector("button").addEventListener("click",function(a){f.value&&(h&&(h.label=f.value),d.setDirty(!0));k.close()})}},extra:a};a&&(k.title=a.type);var n=null;a&&(n=a.getSlotInPosition(b.canvasX,b.canvasY),f.active_node=a);if(n){h=[];n&&n.output&&n.output.links&&n.output.links.length&&h.push({content:"Disconnect Links",slot:n});var m=n.input||
|
||||
n.output;h.push(m.locked?"Cannot remove":{content:"Remove Slot",slot:n});h.push(m.nameLocked?"Cannot rename":{content:"Rename Slot",slot:n});k.title=(n.input?n.input.type:n.output.type)||"*";n.input&&n.input.type==e.ACTION&&(k.title="Action");n.output&&n.output.type==e.EVENT&&(k.title="Event")}else a?h=this.getNodeMenuOptions(a):(h=this.getCanvasMenuOptions(),(n=this.graph.getGroupOnPos(b.canvasX,b.canvasY))&&h.push(null,{content:"Edit Group",has_submenu:!0,submenu:{title:"Group",extra:n,options:this.getGroupMenuOptions(n)}}));
|
||||
h&&new e.ContextMenu(h,k,c)};this.CanvasRenderingContext2D&&(CanvasRenderingContext2D.prototype.roundRect=function(a,b,d,c,e,h){void 0===e&&(e=5);void 0===h&&(h=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+c-h);this.quadraticCurveTo(a+d,b+c,a+d-h,b+c);this.lineTo(a+h,b+c);this.quadraticCurveTo(a,b+c,a,b+c-h);this.lineTo(a,b+e);this.quadraticCurveTo(a,b,a+e,b)});e.compareObjects=function(a,b){for(var d in a)if(a[d]!=b[d])return!1;return!0};e.distance=
|
||||
y;e.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")+")"};e.isInsideRectangle=s;e.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)};e.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};e.overlapBounding=u;e.hex2num=function(a){"#"==a.charAt(0)&&(a=a.slice(1));a=a.toUpperCase();
|
||||
for(var b=Array(3),d=0,c,e,h=0;6>h;h+=2)c="0123456789ABCDEF".indexOf(a.charAt(h)),e="0123456789ABCDEF".indexOf(a.charAt(h+1)),b[d]=16*c+e,d++;return b};e.num2hex=function(a){for(var b="#",d,c,e=0;3>e;e++)d=a[e]/16,c=a[e]%16,b+="0123456789ABCDEF".charAt(d)+"0123456789ABCDEF".charAt(c);return b};z.prototype.addItem=function(a,b,d){function c(a){var b=this.value;b&&b.has_submenu&&e.call(this,a)}function e(a){var b=this.value,c=!0;h.current_submenu&&h.current_submenu.close(a);if(d.callback){var k=d.callback.call(this,
|
||||
b,d,a,h,d.node);!0===k&&(c=!1)}if(b&&(b.callback&&!d.ignore_item_callbacks&&!0!==b.disabled&&(k=b.callback.call(this,b,d,a,h,d.extra),!0===k&&(c=!1)),b.submenu)){if(!b.submenu.options)throw"ContextMenu submenu needs options";new h.constructor(b.submenu.options,{callback:b.submenu.callback,event:a,parentMenu:h,ignore_item_callbacks:b.submenu.ignore_item_callbacks,title:b.submenu.title,extra:b.submenu.extra,autoopen:d.autoopen});c=!1}c&&!h.lock&&h.close()}var h=this;d=d||{};var k=document.createElement("div");
|
||||
k.className="litemenu-entry submenu";var f=!1;if(null===b)k.classList.add("separator");else{k.innerHTML=b&&b.title?b.title:a;if(k.value=b)b.disabled&&(f=!0,k.classList.add("disabled")),(b.submenu||b.has_submenu)&&k.classList.add("has_submenu");"function"==typeof b?(k.dataset.value=a,k.onclick_callback=b):k.dataset.value=b;b.className&&(k.className+=" "+b.className)}this.root.appendChild(k);f||k.addEventListener("click",e);d.autoopen&&k.addEventListener("mouseenter",c);return k};z.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&&!z.isCursorOverElement(a,this.parentMenu.root)&&z.trigger(this.parentMenu.root,"mouseleave",a));this.current_submenu&&this.current_submenu.close(a,!0);this.root.closing_timer&&clearTimeout(this.root.closing_timer)};z.trigger=function(a,b,d,c){var e=document.createEvent("CustomEvent");e.initCustomEvent(b,
|
||||
!0,!0,d);e.srcElement=c;a.dispatchEvent?a.dispatchEvent(e):a.__events&&a.__events.dispatchEvent(e);return e};z.prototype.getTopMenu=function(){return this.options.parentMenu?this.options.parentMenu.getTopMenu():this};z.prototype.getFirstEvent=function(){return this.options.parentMenu?this.options.parentMenu.getFirstEvent():this.options.event};z.isCursorOverElement=function(a,b){var d=a.clientX,c=a.clientY,e=b.getBoundingClientRect();return e?c>e.top&&c<e.top+e.height&&d>e.left&&d<e.left+e.width?!0:
|
||||
!1:!1};e.ContextMenu=z;e.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 in b)b[d].close?b[d].close():b[d].parentNode&&b[d].parentNode.removeChild(b[d])}};e.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)))};e.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);
|
||||
e.closing_timer=setTimeout(x.close.bind(x,a),500))});e.addEventListener("mouseenter",function(a){e.closing_timer&&clearTimeout(e.closing_timer)});A=document;b.event&&(A=b.event.target.ownerDocument);A||(A=document);A.fullscreenElement?A.fullscreenElement.appendChild(e):A.body.appendChild(e);c=b.left||0;A=b.top||0;if(b.event){c=b.event.clientX-10;A=b.event.clientY-10;b.title&&(A-=20);b.parentMenu&&(c=b.parentMenu.root.getBoundingClientRect(),c=c.left+c.width);var h=document.body.getBoundingClientRect(),
|
||||
f=e.getBoundingClientRect();c>h.width-f.width-10&&(c=h.width-f.width-10);A>h.height-f.height-10&&(A=h.height-f.height-10)}e.style.left=c+"px";e.style.top=A+"px";b.scale&&(e.style.transform="scale("+b.scale+")")}var e=v.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:{},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;e.debug&&console.log("Node registered: "+a);a.split("/");var d=b.name,x=a.lastIndexOf("/");b.category=a.substr(0,x);b.title||(b.title=d);if(b.prototype)for(var p in g.prototype)b.prototype[p]||(b.prototype[p]=g.prototype[p]);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=e.BOX_SHAPE;break;case "round":this._shape=e.ROUND_SHAPE;break;case "circle":this._shape=e.CIRCLE_SHAPE;
|
||||
break;case "card":this._shape=e.CARD_SHAPE;break;default:this._shape=a}},get:function(a){return this._shape},enumerable:!0});(x=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(e.onNodeTypeRegistered)e.onNodeTypeRegistered(a,b);if(x&&e.onNodeTypeReplaced)e.onNodeTypeReplaced(a,b,x);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(p in b.supported_extensions)this.node_types_by_file_extension[b.supported_extensions[p].toLowerCase()]=b},wrapFunctionAsNode:function(a,b,d,x,p){for(var c=Array(b.length),A="",h=e.getParameterNames(b),f=0;f<h.length;++f)A+="this.addInput('"+h[f]+"',"+(d&&d[f]?"'"+d[f]+"'":"0")+");\n";A+="this.addOutput('out',"+(x?"'"+x+"'":0)+");\n";p&&(A+="this.properties = "+JSON.stringify(p)+";\n");d=Function(A);d.title=a.split("/").pop();d.desc="Generated from "+b.name;d.prototype.onExecute=
|
||||
function(){for(var a=0;a<c.length;++a)c[a]=this.getInputData(a);a=b.apply(this,c);this.setOutputData(0,a)};this.registerNodeType(a,d)},addNodeMethod:function(a,b){g.prototype[a]=b;for(var d in this.registered_node_types){var e=this.registered_node_types[d];e.prototype[a]&&(e.prototype["_"+a]=e.prototype[a]);e.prototype[a]=b}},createNode:function(a,b,d){var x=this.registered_node_types[a];if(!x)return e.debug&&console.log('GraphNode type "'+a+'" not registered.'),null;b=b||x.title||a;var p=null;if(e.catch_exceptions)try{p=
|
||||
new x(b)}catch(c){return console.error(c),null}else p=new x(b);p.type=a;!p.title&&b&&(p.title=b);p.properties||(p.properties={});p.properties_info||(p.properties_info=[]);p.flags||(p.flags={});p.size||(p.size=p.computeSize());p.pos||(p.pos=e.DEFAULT_POSITION.concat());p.mode||(p.mode=e.ALWAYS);if(d)for(var A in d)p[A]=d[A];return p},getNodeType:function(a){return this.registered_node_types[a]},getNodeTypesInCategory:function(a,b){var d=[],e;for(e in this.registered_node_types){var p=this.registered_node_types[e];
|
||||
b&&p.filter&&p.filter!=b||(""==a?null==p.category&&d.push(p):p.category==a&&d.push(p))}return d},getNodeTypesCategories:function(a){var b={"":1},d;for(d in this.registered_node_types){var e=this.registered_node_types[d];!e.category||e.skip_list||a&&e.filter!=a||(b[e.category]=1)}a=[];for(d in b)a.push(d);return a},reloadNodes:function(a){var b=document.getElementsByTagName("script"),d=[],x;for(x in b)d.push(b[x]);b=document.getElementsByTagName("head")[0];a=document.location.href+a;for(x in d){var p=
|
||||
d[x].src;if(p&&p.substr(0,a.length)==a)try{e.debug&&console.log("Reloading: "+p);var c=document.createElement("script");c.type="text/javascript";c.src=p;b.appendChild(c);b.removeChild(d[x])}catch(A){if(e.throw_errors)throw A;e.debug&&console.log("Error while reloading "+p)}}e.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 e in d)b[e]=d[e];return b},isValidConnection:function(a,b){if(!a||!b||a==b||a==
|
||||
e.EVENT&&b==e.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(","),x=b.split(","),p=0;p<d.length;++p)for(var c=0;c<x.length;++c)if(d[p]==x[c])return!0;return!1},registerSearchboxExtra:function(a,b,d){this.searchbox_extras[b.toLowerCase()]={type:a,desc:b,data:d}}};e.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()};v.LGraph=e.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!=f)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=e.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 x=e.getTime();this.globaltime=0.001*(x-this.starttime);var p=this._nodes_executable?this._nodes_executable:this._nodes;if(p){d=d||p.length;if(b){for(var c=0;c<a;c++){for(var A=0;A<d;++A){var h=p[A];if(h.mode==e.ALWAYS&&h.onExecute)h.onExecute()}this.fixedtime+=this.fixedtime_lapse;if(this.onExecuteStep)this.onExecuteStep()}if(this.onAfterExecute)this.onAfterExecute()}else try{for(c=
|
||||
0;c<a;c++){for(A=0;A<d;++A)if(h=p[A],h.mode==e.ALWAYS&&h.onExecute)h.onExecute();this.fixedtime+=this.fixedtime_lapse;if(this.onExecuteStep)this.onExecuteStep()}if(this.onAfterExecute)this.onAfterExecute();this.errors_in_execution=!1}catch(f){this.errors_in_execution=!0;if(e.throw_errors)throw f;e.debug&&console.log("Error during execution: "+f);this.stop()}a=e.getTime();x=a-x;0==x&&(x=1);this.execution_time=0.001*x;this.globaltime+=0.001*x;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=[],x=[],p={},c={},A={},h=0,f=this._nodes.length;h<f;++h){var k=this._nodes[h];if(!a||k.onExecute){p[k.id]=k;var n=0;if(k.inputs)for(var t=0,B=k.inputs.length;t<
|
||||
B;t++)k.inputs[t]&&null!=k.inputs[t].link&&(n+=1);0==n?(x.push(k),b&&(k._level=1)):(b&&(k._level=0),A[k.id]=n)}}for(;0!=x.length;)if(k=x.shift(),d.push(k),delete p[k.id],k.outputs)for(h=0;h<k.outputs.length;h++)if(f=k.outputs[h],null!=f&&null!=f.links&&0!=f.links.length)for(t=0;t<f.links.length;t++)(n=this.links[f.links[t]])&&!c[n.id]&&(B=this.getNodeById(n.target_id),null==B?c[n.id]=!0:(b&&(!B._level||B._level<=k._level)&&(B._level=k._level+1),c[n.id]=!0,A[B.id]-=1,0==A[B.id]&&x.push(B)));for(h in p)d.push(p[h]);
|
||||
d.length!=this._nodes.length&&e.debug&&console.warn("something went wrong, nodes missing");f=d.length;for(h=0;h<f;++h)d[h].order=h;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(h=0;h<f;++h)d[h].order=h;return d};c.prototype.getAncestors=function(a){for(var b=[],d=[a],e={};d.length;){var p=d.shift();if(p.inputs){e[p.id]||p==a||(e[p.id]=!0,b.push(p));for(var c=0;c<p.inputs.length;++c){var h=p.getInputNode(c);
|
||||
h&&-1==b.indexOf(h)&&d.push(h)}}}b.sort(function(a,b){return a.order-b.order});return b};c.prototype.arrange=function(a){a=a||40;for(var b=this.computeExecutionOrder(!1,!0),d=[],e=0;e<b.length;++e){var p=b[e],c=p._level||1;d[c]||(d[c]=[]);d[c].push(p)}b=a;for(e=0;e<d.length;++e)if(c=d[e]){for(var h=100,f=a,k=0;k<c.length;++k)p=c[k],p.pos[0]=b,p.pos[1]=f,p.size[0]>h&&(h=p.size[0]),f+=p.size[1]+a;b+=h+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||e.ALWAYS;var x=this._nodes_in_order?this._nodes_in_order:this._nodes;if(x)for(var p=0,c=x.length;p<c;++p){var h=x[p];if(h.constructor===e.Subgraph&&"onExecute"!=a)h.mode==d&&h.sendEventToAllNodes(a,b,d);else if(h[a]&&h.mode==d)if(void 0===b)h[a]();else if(b&&b.constructor===Array)h[a].apply(h,b);else h[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 e=this.list_of_graphcanvas[d];e[a]&&e[a].apply(e,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>=e.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===e.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,e=this._nodes.length;d<e;++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,e=this._nodes.length;d<e;++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,e=this._nodes.length;d<e;++d)this._nodes[d].title==a&&b.push(this._nodes[d]);return b};c.prototype.getNodeOnPos=
|
||||
function(a,b,d,e){d=d||this._nodes;for(var p=d.length-1;0<=p;p--){var c=d[p];if(c.isPointInside(a,b,e))return c}return null};c.prototype.getGroupOnPos=function(a,b){for(var d=this._groups.length-1;0<=d;d--){var e=this._groups[d];if(e.isPointInside(a,b,2,!0))return e}return null};c.prototype.checkNodeTypes=function(){for(var a=0;a<this._nodes.length;a++){var b=this._nodes[a];if(b.constructor!=e.registered_node_types[b.type]){console.log("node being replaced by newer version: "+b.type);var d=e.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(e.GraphInput,this._input_nodes);for(var d=0;d<this._input_nodes.length;++d){var x=this._input_nodes[d];if(x.properties.name==a){x.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),e=0;e<d.length;++e)d[e].onTrigger(b)};c.prototype.setCallback=function(a,b){for(var d=this.findNodesByTitle(a),e=0;e<d.length;++e)d[e].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(){e.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 x=this.links[b];
|
||||
if(!x.serialize){console.warn("weird LLink bug, link info is not a LLink but a regular object");var p=new q;for(b in x)p[b]=x[b];x=this.links[b]=p}d.push(x.serialize())}x=[];for(b=0;b<this._groups.length;++b)x.push(this._groups[b].serialize());return{last_node_id:this.last_node_id,last_link_id:this.last_link_id,nodes:a,links:d,groups:x,config:this.config,version:e.VERSION}};c.prototype.configure=function(a,b){if(a){b||this.clear();var d=a.nodes;if(a.links&&a.links.constructor===Array){for(var x=[],
|
||||
p=0;p<a.links.length;++p){var c=a.links[p],h=new q;h.configure(c);x[h.id]=h}a.links=x}for(p in a)this[p]=a[p];x=!1;this._nodes=[];if(d){p=0;for(c=d.length;p<c;++p){var h=d[p],f=e.createNode(h.type,h.title);f||(e.debug&&console.log("Node not found or has errors: "+h.type),f=new g,f.last_serialization=h,x=f.has_errors=!0);f.id=h.id;this.add(f,!0)}p=0;for(c=d.length;p<c;++p)h=d[p],(f=this.getNodeById(h.id))&&f.configure(h)}this._groups.length=0;if(a.groups)for(p=0;p<a.groups.length;++p)d=new e.LGraphGroup,
|
||||
d.configure(a.groups[p]),this.add(d);this.updateExecutionOrder();this._version++;this.setDirtyCanvas(!0,!0);return x}};c.prototype.load=function(a){var b=this,d=new XMLHttpRequest;d.open("GET",a,!0);d.send(null);d.onload=function(a){200!==d.status?console.error("Error loading graph:",d.status,d.response):(a=JSON.parse(d.response),b.configure(a))};d.onerror=function(a){console.error("Error loading graph:",a)}};c.prototype.onNodeTrace=function(a,b,d){};q.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)};q.prototype.serialize=function(){return[this.id,this.origin_id,this.origin_slot,this.target_id,this.target_slot,this.type]};e.LLink=q;v.LGraphNode=e.LGraphNode=g;g.prototype._ctor=function(a){this.title=a||"Unnamed";this.size=[e.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={}};g.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]=e.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 x=this.graph?this.graph.links[b.link]:null;this.onConnectionsChange(e.INPUT,d,!0,x,b)}if(this.outputs)for(d=0;d<this.outputs.length;++d){var p=this.outputs[d];
|
||||
if(p.links)for(b=0;b<p.links.length;++b)x=this.graph?this.graph.links[p.links[b]]:null,this.onConnectionsChange(e.OUTPUT,d,!0,x,p)}}if(a.widgets_values&&this.widgets)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)};g.prototype.serialize=function(){var a={id:this.id,type:this.type,pos:this.pos,size:this.size,flags:e.cloneObject(this.flags),order:this.order,mode:this.mode};if(this.constructor===g&&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=e.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].value;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};g.prototype.clone=function(){var a=e.createNode(this.type);if(!a)return null;var b=e.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};g.prototype.toString=function(){return JSON.stringify(this.serialize())};g.prototype.getTitle=function(){return this.title||this.constructor.title};g.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)}};g.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++)this.graph.links[this.outputs[a].links[d]].data=b}};g.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}};g.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 e=this.graph.getNodeById(d.origin_id);if(!e)return d.data;if(e.updateOutputData)e.updateOutputData(d.origin_slot);else if(e.onExecute)e.onExecute();return d.data}};g.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};g.prototype.getInputDataByName=function(a,b){var d=this.findInputSlot(a);return-1==d?null:this.getInputData(d,b)};g.prototype.isInputConnected=function(a){return this.inputs?a<this.inputs.length&&null!=this.inputs[a].link:!1};g.prototype.getInputInfo=function(a){return this.inputs?a<this.inputs.length?this.inputs[a]:null:null};g.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};g.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 e=this.inputs[b];if(a==e.name&&null!=e.link&&(e=this.graph.links[e.link]))return e.data}return this.properties[a]};g.prototype.getOutputData=function(a){return!this.outputs||a>=this.outputs.length?null:this.outputs[a]._data};g.prototype.getOutputInfo=
|
||||
function(a){return this.outputs?a<this.outputs.length?this.outputs[a]:null:null};g.prototype.isOutputConnected=function(a){return this.outputs?a<this.outputs.length&&this.outputs[a].links&&this.outputs[a].links.length:!1};g.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};g.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 e=this.graph.links[a.links[d]];e&&(e=this.graph.getNodeById(e.target_id))&&b.push(e)}return b};g.prototype.trigger=function(a,b){if(this.outputs&&this.outputs.length){this.graph&&(this.graph._last_trigger_time=e.getTime());for(var d=0;d<this.outputs.length;++d){var x=this.outputs[d];!x||x.type!==e.EVENT||a&&x.name!=a||this.triggerSlot(d,b)}}};g.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=e.getTime());for(var x=0;x<a.length;++x){var p=a[x];if(null==d||d==p){var c=this.graph.links[a[x]];if(c&&(c._last_time=e.getTime(),p=this.graph.getNodeById(c.target_id)))if(c=p.inputs[c.target_slot],p.onAction)p.onAction(c.name,b);else if(p.mode===e.ON_TRIGGER&&p.onExecute)p.onExecute(b)}}}};g.prototype.clearTriggeredSlot=function(a,b){if(this.outputs){var d=this.outputs[a];if(d&&(d=d.links)&&d.length)for(var e=
|
||||
0;e<d.length;++e){var p=d[e];if(null==b||b==p)if(p=this.graph.links[d[e]])p._last_time=0}}};g.prototype.addProperty=function(a,b,d,e){d={name:a,type:d,default_value:b};if(e)for(var p in e)d[p]=e[p];this.properties_info||(this.properties_info=[]);this.properties_info.push(d);this.properties||(this.properties={});this.properties[a]=b;return d};g.prototype.addOutput=function(a,b,d){a={name:a,type:b,links:null};if(d)for(var e in d)a[e]=d[e];this.outputs||(this.outputs=[]);this.outputs.push(a);if(this.onOutputAdded)this.onOutputAdded(a);
|
||||
this.size=this.computeSize();this.setDirtyCanvas(!0,!0);return a};g.prototype.addOutputs=function(a){for(var b=0;b<a.length;++b){var d=a[b],e={name:d[0],type:d[1],link:null};if(a[2])for(var p in d[2])e[p]=d[2][p];this.outputs||(this.outputs=[]);this.outputs.push(e);if(this.onOutputAdded)this.onOutputAdded(e)}this.size=this.computeSize();this.setDirtyCanvas(!0,!0)};g.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,e=0;e<d.length;++e){var p=this.graph.links[d[e]];p&&(p.origin_slot-=1)}this.size=this.computeSize();if(this.onOutputRemoved)this.onOutputRemoved(a);this.setDirtyCanvas(!0,!0)};g.prototype.addInput=function(a,b,d){a={name:a,type:b||0,link:null};if(d)for(var e in d)a[e]=d[e];this.inputs||(this.inputs=[]);this.inputs.push(a);this.size=this.computeSize();if(this.onInputAdded)this.onInputAdded(a);this.setDirtyCanvas(!0,!0);return a};g.prototype.addInputs=
|
||||
function(a){for(var b=0;b<a.length;++b){var d=a[b],e={name:d[0],type:d[1],link:null};if(a[2])for(var p in d[2])e[p]=d[2][p];this.inputs||(this.inputs=[]);this.inputs.push(e);if(this.onInputAdded)this.onInputAdded(e)}this.size=this.computeSize();this.setDirtyCanvas(!0,!0)};g.prototype.removeInput=function(a){this.disconnectInput(a);this.inputs.splice(a,1);for(var b=a;b<this.inputs.length;++b)if(this.inputs[b]){var d=this.graph.links[this.inputs[b].link];d&&(d.target_slot-=1)}this.size=this.computeSize();
|
||||
if(this.onInputRemoved)this.onInputRemoved(a);this.setDirtyCanvas(!0,!0)};g.prototype.addConnection=function(a,b,d,e){a={name:a,type:b,pos:d,direction:e,links:null};this.connections.push(a);return a};g.prototype.computeSize=function(a,b){function d(a){return a?h*a.length*0.6:0}if(this.constructor.size)return this.constructor.size.concat();var c=Math.max(this.inputs?this.inputs.length:1,this.outputs?this.outputs.length:1),p=b||new Float32Array([0,0]),c=Math.max(c,1),h=e.NODE_TEXT_SIZE;p[1]=(this.constructor.slot_start_y||
|
||||
0)+c*e.NODE_SLOT_HEIGHT;c=0;this.widgets&&this.widgets.length&&(c=this.widgets.length*(e.NODE_WIDGET_HEIGHT+4)+8);p[1]=this.widgets_up?Math.max(p[1],c):p[1]+c;var c=d(this.title),f=0,k=0;if(this.inputs)for(var n=0,t=this.inputs.length;n<t;++n){var m=this.inputs[n],m=m.label||m.name||"",m=d(m);f<m&&(f=m)}if(this.outputs)for(n=0,t=this.outputs.length;n<t;++n)m=this.outputs[n],m=m.label||m.name||"",m=d(m),k<m&&(k=m);p[0]=Math.max(f+k+10,c);p[0]=Math.max(p[0],e.NODE_WIDTH);this.widgets&&this.widgets.length&&
|
||||
(p[0]=Math.max(p[0],1.5*e.NODE_WIDTH));if(this.onResize)this.onResize(p);this.constructor.min_height&&p[1]<this.constructor.min_height&&(p[1]=this.constructor.min_height);p[1]+=6;return p};g.prototype.addWidget=function(a,b,d,e,p){this.widgets||(this.widgets=[]);b={type:a.toLowerCase(),name:b,value:d,callback:e,options:p||{}};void 0!==b.options.y&&(b.y=b.options.y);e||console.warn("LiteGraph addWidget(...) without a callback");if("combo"==a&&!b.options.values)throw"LiteGraph addWidget('combo',...) requires to pass values in options: { values:['red','blue'] }";
|
||||
this.widgets.push(b);this.size=this.computeSize();return b};g.prototype.addCustomWidget=function(a){this.widgets||(this.widgets=[]);this.widgets.push(a);return a};g.prototype.getBounding=function(a){a=a||new Float32Array(4);a[0]=this.pos[0]-4;a[1]=this.pos[1]-e.NODE_TITLE_HEIGHT;a[2]=this.size[0]+4;a[3]=this.size[1]+e.NODE_TITLE_HEIGHT;if(this.onBounding)this.onBounding(a);return a};g.prototype.isPointInside=function(a,b,d,c){d=d||0;var p=this.graph&&this.graph.isLive()?0:e.NODE_TITLE_HEIGHT;c&&(p=
|
||||
0);if(this.flags&&this.flags.collapsed){if(s(a,b,this.pos[0]-d,this.pos[1]-e.NODE_TITLE_HEIGHT-d,(this._collapsed_width||e.NODE_COLLAPSED_WIDTH)+2*d,e.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]-p-d<b&&this.pos[1]+this.size[1]+d>b)return!0;return!1};g.prototype.getSlotInPosition=function(a,b){var d=new Float32Array(2);if(this.inputs)for(var e=0,p=this.inputs.length;e<p;++e){var c=this.inputs[e];this.getConnectionPos(!0,e,d);if(s(a,b,d[0]-
|
||||
10,d[1]-5,20,10))return{input:c,slot:e,link_pos:d}}if(this.outputs)for(e=0,p=this.outputs.length;e<p;++e)if(c=this.outputs[e],this.getConnectionPos(!1,e,d),s(a,b,d[0]-10,d[1]-5,20,10))return{output:c,slot:e,link_pos:d};return null};g.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};g.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};g.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 e.debug&&console.log("Connect: Error, no slot of name "+a),null}else if(!this.outputs||a>=this.outputs.length)return e.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 e.debug&&console.log("Connect: Error, no slot of name "+d),null}else{if(d===e.EVENT)return null;if(!b.inputs||d>=b.inputs.length)return e.debug&&console.log("Connect: Error, slot number not found"),null}null!=b.inputs[d].link&&b.disconnectInput(d);var c=this.outputs[a];if(b.onConnectInput&&!1===b.onConnectInput(d,c.type,c))return null;var p=b.inputs[d],h=null;if(e.isValidConnection(c.type,
|
||||
p.type)){h=new q(++this.graph.last_link_id,p.type,this.id,a,b.id,d);this.graph.links[h.id]=h;null==c.links&&(c.links=[]);c.links.push(h.id);b.inputs[d].link=h.id;this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(e.OUTPUT,a,!0,h,c);if(b.onConnectionsChange)b.onConnectionsChange(e.INPUT,d,!0,h,p);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(e.INPUT,b,d,this,a),this.graph.onNodeConnectionChange(e.OUTPUT,this,a,b,d))}this.setDirtyCanvas(!1,
|
||||
!0);this.graph.connectionChange(this,h);return h};g.prototype.disconnectOutput=function(a,b){if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return e.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.outputs||a>=this.outputs.length)return e.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 c=0,p=d.links.length;c<p;c++){var h=d.links[c],f=this.graph.links[h];if(f.target_id==b.id){d.links.splice(c,1);var k=b.inputs[f.target_slot];k.link=null;delete this.graph.links[h];this.graph&&this.graph._version++;if(b.onConnectionsChange)b.onConnectionsChange(e.INPUT,f.target_slot,!1,f,k);if(this.onConnectionsChange)this.onConnectionsChange(e.OUTPUT,a,!1,f,d);if(this.graph&&this.graph.onNodeConnectionChange)this.graph.onNodeConnectionChange(e.OUTPUT,this,a);this.graph&&this.graph.onNodeConnectionChange&&
|
||||
(this.graph.onNodeConnectionChange(e.OUTPUT,this,a),this.graph.onNodeConnectionChange(e.INPUT,b,f.target_slot));break}}}else{c=0;for(p=d.links.length;c<p;c++)if(h=d.links[c],f=this.graph.links[h]){b=this.graph.getNodeById(f.target_id);this.graph&&this.graph._version++;if(b){k=b.inputs[f.target_slot];k.link=null;if(b.onConnectionsChange)b.onConnectionsChange(e.INPUT,f.target_slot,!1,f,k);if(this.graph&&this.graph.onNodeConnectionChange)this.graph.onNodeConnectionChange(e.INPUT,b,f.target_slot)}delete this.graph.links[h];
|
||||
if(this.onConnectionsChange)this.onConnectionsChange(e.OUTPUT,a,!1,f,d);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(e.OUTPUT,this,a),this.graph.onNodeConnectionChange(e.INPUT,b,f.target_slot))}d.links=null}this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this);return!0};g.prototype.disconnectInput=function(a){if(a.constructor===String){if(a=this.findInputSlot(a),-1==a)return e.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.inputs||
|
||||
a>=this.inputs.length)return e.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;this.inputs[a].link=null;var c=this.graph.links[d];if(c){var p=this.graph.getNodeById(c.origin_id);if(!p)return!1;var h=p.outputs[c.origin_slot];if(!h||!h.links||0==h.links.length)return!1;for(var f=0,k=h.links.length;f<k;f++)if(h.links[f]==d){h.links.splice(f,1);break}delete this.graph.links[d];this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(e.INPUT,
|
||||
a,!1,c,b);if(p.onConnectionsChange)p.onConnectionsChange(e.OUTPUT,f,!1,c,h);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(e.OUTPUT,p,f),this.graph.onNodeConnectionChange(e.INPUT,this,a))}this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this);return!0};g.prototype.getConnectionPos=function(a,b,d){d=d||new Float32Array(2);var c=0;a&&this.inputs&&(c=this.inputs.length);!a&&this.outputs&&(c=this.outputs.length);var p=0.5*e.NODE_SLOT_HEIGHT;if(this.flags.collapsed)return b=
|
||||
this._collapsed_width||e.NODE_COLLAPSED_WIDTH,this.horizontal?(d[0]=this.pos[0]+0.5*b,d[1]=a?this.pos[1]-e.NODE_TITLE_HEIGHT:this.pos[1]):(d[0]=a?this.pos[0]:this.pos[0]+b,d[1]=this.pos[1]-0.5*e.NODE_TITLE_HEIGHT),d;if(a&&-1==b)return d[0]=this.pos[0]+0.5*e.NODE_TITLE_HEIGHT,d[1]=this.pos[1]+0.5*e.NODE_TITLE_HEIGHT,d;if(a&&c>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&&c>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]/c*(b+0.5),d[1]=a?this.pos[1]-e.NODE_TITLE_HEIGHT:this.pos[1]+this.size[1],d;d[0]=a?this.pos[0]+p:this.pos[0]+this.size[0]+1-p;d[1]=this.pos[1]+(b+0.7)*e.NODE_SLOT_HEIGHT+(this.constructor.slot_start_y||0);return d};g.prototype.alignToGrid=function(){this.pos[0]=e.CANVAS_GRID_SIZE*Math.round(this.pos[0]/e.CANVAS_GRID_SIZE);this.pos[1]=e.CANVAS_GRID_SIZE*Math.round(this.pos[1]/e.CANVAS_GRID_SIZE)};g.prototype.trace=
|
||||
function(a){this.console||(this.console=[]);this.console.push(a);this.console.length>g.MAX_CONSOLE&&this.console.shift();this.graph.onNodeTrace(this,a)};g.prototype.setDirtyCanvas=function(a,b){this.graph&&this.graph.sendActionToCanvas("setDirty",[a,b])};g.prototype.loadImage=function(a){var b=new Image;b.src=e.node_images_path+a;b.ready=!1;var d=this;b.onload=function(){this.ready=!0;d.setDirtyCanvas(!0)};return b};g.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 e=b[d];if(a||e.node_capturing_input==this)e.node_capturing_input=a?this:null}};g.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)};g.prototype.pin=function(a){this.graph._version++;this.flags.pinned=void 0===a?!this.flags.pinned:a};g.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]]};v.LGraphGroup=e.LGraphGroup=l;l.prototype._ctor=function(a){this.title=a||"Group";this.font_size=24;this.color=f.node_colors.pale_blue?f.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})};l.prototype.configure=function(a){this.title=a.title;this._bounding.set(a.bounding);this.color=a.color;this.font=a.font};l.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}};l.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 e=this._nodes[d];e.pos[0]+=a;e.pos[1]+=b}};l.prototype.recomputeInsideNodes=function(){this._nodes.length=0;for(var a=this.graph._nodes,b=new Float32Array(4),d=0;d<a.length;++d){var e=a[d];e.getBounding(b);u(this._bounding,b)&&this._nodes.push(e)}};l.prototype.isPointInside=g.prototype.isPointInside;l.prototype.setDirtyCanvas=g.prototype.setDirtyCanvas;e.DragAndScale=r;r.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)};r.prototype.computeVisibleArea=function(){if(this.element){var a=-this.offset[0],b=-this.offset[1],d=a+this.element.width/this.scale,e=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]=e-b}else this.visible_area[0]=this.visible_area[1]=this.visible_area[2]=this.visible_area[3]=0};r.prototype.onMouse=function(a){if(this.enabled){var b=this.element,d=b.getBoundingClientRect(),e=a.clientX-d.left,d=a.clientY-d.top;a.canvasx=e;a.canvasy=d;a.dragging=this.dragging;var c=!1;this.onmouse&&(c=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)c||(b=e-this.last_mouse[0],c=d-this.last_mouse[1],this.dragging&&this.mouseDrag(b,c));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]=e;this.last_mouse[1]=d;a.preventDefault();a.stopPropagation();return!1}};r.prototype.toCanvasContext=function(a){a.scale(this.scale,this.scale);a.translate(this.offset[0],this.offset[1])};r.prototype.convertOffsetToCanvas=function(a){return[(a[0]+
|
||||
this.offset[0])*this.scale,(a[1]+this.offset[1])*this.scale]};r.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};r.prototype.mouseDrag=function(a,b){this.offset[0]+=a/this.scale;this.offset[1]+=b/this.scale;if(this.onredraw)this.onredraw(this)};r.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 e=this.convertCanvasToOffset(b),d=[e[0]-d[0],e[1]-d[1]];this.offset[0]+=d[0];this.offset[1]+=d[1];if(this.onredraw)this.onredraw(this)}}};r.prototype.changeDeltaScale=function(a,b){this.changeScale(this.scale*a,b)};r.prototype.reset=function(){this.scale=1;this.offset[0]=0;this.offset[1]=0};v.LGraphCanvas=e.LGraphCanvas=f;f.link_type_colors={"-1":e.EVENT_LINK_COLOR,number:"#AAA",
|
||||
node:"#DCA"};f.gradients={};f.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.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()};f.prototype.setGraph=function(a,b){this.graph!=a&&(b||this.clear(),!a&&this.graph?this.graph.detachCanvas(this):(a.attachCanvas(this),this.setDirty(!0,!0)))};f.prototype.openSubgraph=function(a){if(!a)throw"graph cannot be null";if(this.graph==a)throw"graph cannot be the same";this.clear();this.graph&&(this._graph_stack||(this._graph_stack=[]),this._graph_stack.push(this.graph));a.attachCanvas(this);this.setDirty(!0,!0)};f.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]))}};f.prototype.getCurrentGraph=function(){return this.graph};f.prototype.setCanvas=function(a,b){if(a&&a.constructor===String&&(a=document.getElementById(a),!a))throw"Error creating LiteGraph canvas: Canvas not found";if(a!==this.canvas&&(!a&&this.canvas&&(b||this.unbindEvents()),
|
||||
this.canvas=a,this.ds.element=a)){a.className+=" lgraphcanvas";a.data=this;a.tabindex="1";this.bgcanvas=null;this.bgcanvas||(this.bgcanvas=document.createElement("canvas"),this.bgcanvas.width=this.canvas.width,this.bgcanvas.height=this.canvas.height);if(null==a.getContext){if("canvas"!=a.localName)throw"Element supplied for LGraphCanvas must be a <canvas> element, you passed a "+a.localName;throw"This browser doesn't support Canvas";}null==(this.ctx=a.getContext("2d"))&&(a.webgl_enabled||console.warn("This canvas seems to be WebGL, enabling WebGL renderer"),
|
||||
this.enableWebGL());this._mousemove_callback=this.processMouseMove.bind(this);this._mouseup_callback=this.processMouseUp.bind(this);b||this.bindEvents()}};f.prototype._doNothing=function(a){a.preventDefault();return!1};f.prototype._doReturnTrue=function(a){a.preventDefault();return!0};f.prototype.bindEvents=function(){if(this._events_binded)console.warn("LGraphCanvas: events already binded");else{var a=this.canvas,b=this.getCanvasWindow().document;this._mousedown_callback=this.processMouseDown.bind(this);
|
||||
this._mousewheel_callback=this.processMouseWheel.bind(this);a.addEventListener("mousedown",this._mousedown_callback,!0);a.addEventListener("mousemove",this._mousemove_callback);a.addEventListener("mousewheel",this._mousewheel_callback,!1);a.addEventListener("contextmenu",this._doNothing);a.addEventListener("DOMMouseScroll",this._mousewheel_callback,!1);a.addEventListener("touchstart",this.touchHandler,!0);a.addEventListener("touchmove",this.touchHandler,!0);a.addEventListener("touchend",this.touchHandler,
|
||||
!0);a.addEventListener("touchcancel",this.touchHandler,!0);this._key_callback=this.processKey.bind(this);a.addEventListener("keydown",this._key_callback,!0);b.addEventListener("keyup",this._key_callback,!0);this._ondrop_callback=this.processDrop.bind(this);a.addEventListener("dragover",this._doNothing,!1);a.addEventListener("dragend",this._doNothing,!1);a.addEventListener("drop",this._ondrop_callback,!1);a.addEventListener("dragenter",this._doReturnTrue,!1);this._events_binded=!0}};f.prototype.unbindEvents=
|
||||
function(){if(this._events_binded){var a=this.getCanvasWindow().document;this.canvas.removeEventListener("mousedown",this._mousedown_callback);this.canvas.removeEventListener("mousewheel",this._mousewheel_callback);this.canvas.removeEventListener("DOMMouseScroll",this._mousewheel_callback);this.canvas.removeEventListener("keydown",this._key_callback);a.removeEventListener("keyup",this._key_callback);this.canvas.removeEventListener("contextmenu",this._doNothing);this.canvas.removeEventListener("drop",
|
||||
this._ondrop_callback);this.canvas.removeEventListener("dragenter",this._doReturnTrue);this.canvas.removeEventListener("touchstart",this.touchHandler);this.canvas.removeEventListener("touchmove",this.touchHandler);this.canvas.removeEventListener("touchend",this.touchHandler);this.canvas.removeEventListener("touchcancel",this.touchHandler);this._ondrop_callback=this._key_callback=this._mousewheel_callback=this._mousedown_callback=null;this._events_binded=!1}else console.warn("LGraphCanvas: no events binded")};
|
||||
f.getFileExtension=function(a){var b=a.indexOf("?");-1!=b&&(a=a.substr(0,b));b=a.lastIndexOf(".");return-1==b?"":a.substr(b+1).toLowerCase()};f.prototype.enableWebGL=function(){if(void 0===typeof GL)throw"litegl.js must be included to use a WebGL canvas";if(void 0===typeof enableWebGLCanvas)throw"webglCanvas.js must be included to use this feature";this.gl=this.ctx=enableWebGLCanvas(this.canvas);this.ctx.webgl=!0;this.bgcanvas=this.canvas;this.bgctx=this.gl;this.canvas.webgl_enabled=!0};f.prototype.setDirty=
|
||||
function(a,b){a&&(this.dirty_canvas=!0);b&&(this.dirty_bgcanvas=!0)};f.prototype.getCanvasWindow=function(){if(!this.canvas)return window;var a=this.canvas.ownerDocument;return a.defaultView||a.parentWindow};f.prototype.startRendering=function(){function a(){this.pause_rendering||this.draw();var b=this.getCanvasWindow();this.is_rendering&&b.requestAnimationFrame(a.bind(this))}this.is_rendering||(this.is_rendering=!0,a.call(this))};f.prototype.stopRendering=function(){this.is_rendering=!1};f.prototype.processMouseDown=
|
||||
function(a){if(this.graph){this.adjustMouseEvent(a);var b=this.getCanvasWindow();f.active_canvas=this;this.canvas.removeEventListener("mousemove",this._mousemove_callback);b.document.addEventListener("mousemove",this._mousemove_callback,!0);b.document.addEventListener("mouseup",this._mouseup_callback,!0);var d=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes,5),c=!1,p=300>e.getTime()-this.last_mouseclick;this.canvas_mouse[0]=a.canvasX;this.canvas_mouse[1]=a.canvasY;this.canvas.focus();
|
||||
e.closeAllContextMenus(b);if(!this.onMouse||!0!=this.onMouse(a)){if(1==a.which){a.ctrlKey&&(this.dragging_rectangle=new Float32Array(4),this.dragging_rectangle[0]=a.canvasX,this.dragging_rectangle[1]=a.canvasY,this.dragging_rectangle[2]=1,this.dragging_rectangle[3]=1,c=!0);var h=!1;if(d&&this.allow_interaction&&!c&&!this.read_only){this.live_mode||d.flags.pinned||this.bringToFront(d);if(!this.connecting_node&&!d.flags.collapsed&&!this.live_mode)if(!c&&!1!==d.resizable&&s(a.canvasX,a.canvasY,d.pos[0]+
|
||||
d.size[0]-5,d.pos[1]+d.size[1]-5,10,10))this.resizing_node=d,this.canvas.style.cursor="se-resize",c=!0;else{if(d.outputs)for(var k=0,n=d.outputs.length;k<n;++k){var t=d.outputs[k],m=d.getConnectionPos(!1,k);if(s(a.canvasX,a.canvasY,m[0]-15,m[1]-10,30,20)){this.connecting_node=d;this.connecting_output=t;this.connecting_pos=d.getConnectionPos(!1,k);this.connecting_slot=k;a.shiftKey&&d.disconnectOutput(k);if(p){if(d.onOutputDblClick)d.onOutputDblClick(k,a)}else if(d.onOutputClick)d.onOutputClick(k,a);
|
||||
c=!0;break}}if(d.inputs)for(k=0,n=d.inputs.length;k<n;++k)if(t=d.inputs[k],m=d.getConnectionPos(!0,k),s(a.canvasX,a.canvasY,m[0]-15,m[1]-10,30,20)){if(p){if(d.onInputDblClick)d.onInputDblClick(k,a)}else if(d.onInputClick)d.onInputClick(k,a);if(null!==t.link){c=this.graph.links[t.link];d.disconnectInput(k);if(this.allow_reconnect_links||a.shiftKey)this.connecting_node=this.graph._nodes_by_id[c.origin_id],this.connecting_slot=c.origin_slot,this.connecting_output=this.connecting_node.outputs[this.connecting_slot],
|
||||
this.connecting_pos=this.connecting_node.getConnectionPos(!1,this.connecting_slot);c=this.dirty_bgcanvas=!0}}}if(!c){k=!1;if(n=this.processNodeWidgets(d,this.canvas_mouse,a))k=!0,this.node_widget=[d,n];if(p&&this.selected_nodes[d.id]){if(d.onDblClick)d.onDblClick(a,[a.canvasX-d.pos[0],a.canvasY-d.pos[1]],this);this.processNodeDblClicked(d);k=!0}d.onMouseDown&&d.onMouseDown(a,[a.canvasX-d.pos[0],a.canvasY-d.pos[1]],this)?k=!0:this.live_mode&&(k=h=!0);k||(this.allow_dragnodes&&(this.node_dragged=d),
|
||||
this.selected_nodes[d.id]||this.processNodeSelected(d,a));this.dirty_canvas=!0}}else{if(!this.read_only)for(k=0;k<this.visible_links.length;++k)if(d=this.visible_links[k],(h=d._pos)&&!(a.canvasX<h[0]-4||a.canvasX>h[0]+4||a.canvasY<h[1]-4||a.canvasY>h[1]+4)){this.showLinkMenu(d,a);break}this.selected_group=this.graph.getGroupOnPos(a.canvasX,a.canvasY);this.selected_group_resizing=!1;this.selected_group&&!this.read_only&&(a.ctrlKey&&(this.dragging_rectangle=null),10>y([a.canvasX,a.canvasY],[this.selected_group.pos[0]+
|
||||
this.selected_group.size[0],this.selected_group.pos[1]+this.selected_group.size[1]])*this.ds.scale?this.selected_group_resizing=!0:this.selected_group.recomputeInsideNodes());p&&!this.read_only&&this.showSearchBox(a);h=!0}!c&&h&&this.allow_dragcanvas&&(this.dragging_canvas=!0)}else 2!=a.which&&3==a.which&&(this.read_only||this.processContextMenu(d,a));this.last_mouse[0]=a.localX;this.last_mouse[1]=a.localY;this.last_mouseclick=e.getTime();this.last_mouse_dragging=!0;this.graph.change();(!b.document.activeElement||
|
||||
"input"!=b.document.activeElement.nodeName.toLowerCase()&&"textarea"!=b.document.activeElement.nodeName.toLowerCase())&&a.preventDefault();a.stopPropagation();if(this.onMouseDown)this.onMouseDown(a);return!1}}};f.prototype.processMouseMove=function(a){this.autoresize&&this.resize();if(this.graph){f.active_canvas=this;this.adjustMouseEvent(a);var b=[a.localX,a.localY],d=[b[0]-this.last_mouse[0],b[1]-this.last_mouse[1]];this.last_mouse=b;this.canvas_mouse[0]=a.canvasX;this.canvas_mouse[1]=a.canvasY;
|
||||
a.dragging=this.last_mouse_dragging;this.node_widget&&(this.processNodeWidgets(this.node_widget[0],this.canvas_mouse,a,this.node_widget[1]),this.dirty_canvas=!0);if(this.dragging_rectangle)this.dragging_rectangle[2]=a.canvasX-this.dragging_rectangle[0],this.dragging_rectangle[3]=a.canvasY-this.dragging_rectangle[1],this.dirty_canvas=!0;else if(this.selected_group&&!this.read_only)this.selected_group_resizing?this.selected_group.size=[a.canvasX-this.selected_group.pos[0],a.canvasY-this.selected_group.pos[1]]:
|
||||
(this.selected_group.move(d[0]/this.ds.scale,d[1]/this.ds.scale,a.ctrlKey),this.selected_group._nodes.length&&(this.dirty_canvas=!0)),this.dirty_bgcanvas=!0;else if(this.dragging_canvas)this.ds.offset[0]+=d[0]/this.ds.scale,this.ds.offset[1]+=d[1]/this.ds.scale,this.dirty_bgcanvas=this.dirty_canvas=!0;else if(this.allow_interaction&&!this.read_only){this.connecting_node&&(this.dirty_canvas=!0);for(var c=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes),b=0,p=this.graph._nodes.length;b<
|
||||
p;++b)if(this.graph._nodes[b].mouseOver&&c!=this.graph._nodes[b]){this.graph._nodes[b].mouseOver=!1;if(this.node_over&&this.node_over.onMouseLeave)this.node_over.onMouseLeave(a);this.node_over=null;this.dirty_canvas=!0}if(c){if(!c.mouseOver&&(c.mouseOver=!0,this.node_over=c,this.dirty_canvas=!0,c.onMouseEnter))c.onMouseEnter(a);if(c.onMouseMove)c.onMouseMove(a,[a.canvasX-c.pos[0],a.canvasY-c.pos[1]],this);if(this.connecting_node&&(p=this._highlight_input||[0,0],!this.isOverNodeBox(c,a.canvasX,a.canvasY))){var h=
|
||||
this.isOverNodeInput(c,a.canvasX,a.canvasY,p);-1!=h&&c.inputs[h]?e.isValidConnection(this.connecting_output.type,c.inputs[h].type)&&(this._highlight_input=p):this._highlight_input=null}this.canvas&&(s(a.canvasX,a.canvasY,c.pos[0]+c.size[0]-5,c.pos[1]+c.size[1]-5,5,5)?this.canvas.style.cursor="se-resize":this.canvas.style.cursor="crosshair")}else{p=null;for(b=0;b<this.visible_links.length;++b){var h=this.visible_links[b],k=h._pos;if(k&&!(a.canvasX<k[0]-4||a.canvasX>k[0]+4||a.canvasY<k[1]-4||a.canvasY>
|
||||
k[1]+4)){p=h;break}}p!=this.over_link_center&&(this.over_link_center=p,this.dirty_canvas=!0);this.canvas&&(this.canvas.style.cursor="")}if(this.node_capturing_input&&this.node_capturing_input!=c&&this.node_capturing_input.onMouseMove)this.node_capturing_input.onMouseMove(a);if(this.node_dragged&&!this.live_mode){for(b in this.selected_nodes)c=this.selected_nodes[b],c.pos[0]+=d[0]/this.ds.scale,c.pos[1]+=d[1]/this.ds.scale;this.dirty_bgcanvas=this.dirty_canvas=!0}this.resizing_node&&!this.live_mode&&
|
||||
(this.resizing_node.size[0]=a.canvasX-this.resizing_node.pos[0],this.resizing_node.size[1]=a.canvasY-this.resizing_node.pos[1],d=Math.max(this.resizing_node.inputs?this.resizing_node.inputs.length:0,this.resizing_node.outputs?this.resizing_node.outputs.length:0)*e.NODE_SLOT_HEIGHT+(this.resizing_node.widgets?this.resizing_node.widgets.length:0)*(e.NODE_WIDGET_HEIGHT+4)+4,this.resizing_node.size[1]<d&&(this.resizing_node.size[1]=d),this.resizing_node.size[0]<e.NODE_MIN_WIDTH&&(this.resizing_node.size[0]=
|
||||
e.NODE_MIN_WIDTH),this.canvas.style.cursor="se-resize",this.dirty_bgcanvas=this.dirty_canvas=!0)}a.preventDefault();return!1}};f.prototype.processMouseUp=function(a){if(this.graph){var b=this.getCanvasWindow().document;f.active_canvas=this;b.removeEventListener("mousemove",this._mousemove_callback,!0);this.canvas.addEventListener("mousemove",this._mousemove_callback,!0);b.removeEventListener("mouseup",this._mouseup_callback,!0);this.adjustMouseEvent(a);b=e.getTime();a.click_time=b-this.last_mouseclick;
|
||||
this.last_mouse_dragging=!1;if(1==a.which){this.node_widget=null;if(this.selected_group){var b=this.selected_group.pos[0]-Math.round(this.selected_group.pos[0]),d=this.selected_group.pos[1]-Math.round(this.selected_group.pos[1]);this.selected_group.move(b,d,a.ctrlKey);this.selected_group.pos[0]=Math.round(this.selected_group.pos[0]);this.selected_group.pos[1]=Math.round(this.selected_group.pos[1]);this.selected_group._nodes.length&&(this.dirty_canvas=!0);this.selected_group=null}this.selected_group_resizing=
|
||||
!1;if(this.dragging_rectangle){if(this.graph){b=this.graph._nodes;d=new Float32Array(4);this.deselectAllNodes();var c=Math.abs(this.dragging_rectangle[2]),p=Math.abs(this.dragging_rectangle[3]),h=0>this.dragging_rectangle[3]?this.dragging_rectangle[1]-p:this.dragging_rectangle[1];this.dragging_rectangle[0]=0>this.dragging_rectangle[2]?this.dragging_rectangle[0]-c:this.dragging_rectangle[0];this.dragging_rectangle[1]=h;this.dragging_rectangle[2]=c;this.dragging_rectangle[3]=p;p=[];for(h=0;h<b.length;++h)c=
|
||||
b[h],c.getBounding(d),u(this.dragging_rectangle,d)&&p.push(c);p.length&&this.selectNodes(p)}this.dragging_rectangle=null}else if(this.connecting_node){this.dirty_bgcanvas=this.dirty_canvas=!0;if(c=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes))this.connecting_output.type==e.EVENT&&this.isOverNodeBox(c,a.canvasX,a.canvasY)?this.connecting_node.connect(this.connecting_slot,c,e.EVENT):(b=this.isOverNodeInput(c,a.canvasX,a.canvasY),-1!=b?this.connecting_node.connect(this.connecting_slot,
|
||||
c,b):(b=c.getInputInfo(0),this.connecting_output.type==e.EVENT?this.connecting_node.connect(this.connecting_slot,c,e.EVENT):b&&!b.link&&e.isValidConnection(b.type&&this.connecting_output.type)&&this.connecting_node.connect(this.connecting_slot,c,0)));this.connecting_node=this.connecting_pos=this.connecting_output=null;this.connecting_slot=-1}else if(this.resizing_node)this.dirty_bgcanvas=this.dirty_canvas=!0,this.resizing_node=null;else if(this.node_dragged){(c=this.node_dragged)&&300>a.click_time&&
|
||||
s(a.canvasX,a.canvasY,c.pos[0],c.pos[1]-e.NODE_TITLE_HEIGHT,e.NODE_TITLE_HEIGHT,e.NODE_TITLE_HEIGHT)&&c.collapse();this.dirty_bgcanvas=this.dirty_canvas=!0;this.node_dragged.pos[0]=Math.round(this.node_dragged.pos[0]);this.node_dragged.pos[1]=Math.round(this.node_dragged.pos[1]);this.graph.config.align_to_grid&&this.node_dragged.alignToGrid();if(this.onNodeMoved)this.onNodeMoved(this.node_dragged);this.node_dragged=null}else{c=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes);!c&&300>
|
||||
a.click_time&&this.deselectAllNodes();this.dirty_canvas=!0;this.dragging_canvas=!1;if(this.node_over&&this.node_over.onMouseUp)this.node_over.onMouseUp(a,[a.canvasX-this.node_over.pos[0],a.canvasY-this.node_over.pos[1]],this);if(this.node_capturing_input&&this.node_capturing_input.onMouseUp)this.node_capturing_input.onMouseUp(a,[a.canvasX-this.node_capturing_input.pos[0],a.canvasY-this.node_capturing_input.pos[1]])}}else 2==a.which?(this.dirty_canvas=!0,this.dragging_canvas=!1):3==a.which&&(this.dirty_canvas=
|
||||
!0,this.dragging_canvas=!1);this.graph.change();a.stopPropagation();a.preventDefault();return!1}};f.prototype.processMouseWheel=function(a){if(this.graph&&this.allow_dragcanvas){var b=null!=a.wheelDeltaY?a.wheelDeltaY:-60*a.detail;this.adjustMouseEvent(a);var d=this.ds.scale;0<b?d*=1.1:0>b&&(d*=1/1.1);this.ds.changeScale(d,[a.localX,a.localY]);this.graph.change();a.preventDefault();return!1}};f.prototype.isOverNodeBox=function(a,b,d){var c=e.NODE_TITLE_HEIGHT;return s(b,d,a.pos[0]+2,a.pos[1]+2-c,
|
||||
c-4,c-4)?!0:!1};f.prototype.isOverNodeInput=function(a,b,d,e){if(a.inputs)for(var c=0,h=a.inputs.length;c<h;++c){var k=a.getConnectionPos(!0,c),f=!1;if(f=a.horizontal?s(b,d,k[0]-5,k[1]-10,10,20):s(b,d,k[0]-10,k[1]-5,40,10))return e&&(e[0]=k[0],e[1]=k[1]),c}return-1};f.prototype.processKey=function(a){if(this.graph){var b=!1;if("input"!=a.target.localName){if("keydown"==a.type){if(32==a.keyCode&&(b=this.dragging_canvas=!0),65==a.keyCode&&a.ctrlKey&&(this.selectNodes(),b=!0),"KeyC"==a.code&&(a.metaKey||
|
||||
a.ctrlKey)&&!a.shiftKey&&this.selected_nodes&&(this.copyToClipboard(),b=!0),"KeyV"!=a.code||!a.metaKey&&!a.ctrlKey||a.shiftKey||this.pasteFromClipboard(),46!=a.keyCode&&8!=a.keyCode||"input"==a.target.localName||"textarea"==a.target.localName||(this.deleteSelectedNodes(),b=!0),this.selected_nodes)for(var d in this.selected_nodes)if(this.selected_nodes[d].onKeyDown)this.selected_nodes[d].onKeyDown(a)}else if("keyup"==a.type&&(32==a.keyCode&&(this.dragging_canvas=!1),this.selected_nodes))for(d in this.selected_nodes)if(this.selected_nodes[d].onKeyUp)this.selected_nodes[d].onKeyUp(a);
|
||||
this.graph.change();if(b)return a.preventDefault(),a.stopImmediatePropagation(),!1}}};f.prototype.copyToClipboard=function(){var a={nodes:[],links:[]},b=0,d=[],e;for(e in this.selected_nodes){var c=this.selected_nodes[e];c._relative_id=b;d.push(c);b+=1}for(e=0;e<d.length;++e)if(c=d[e],a.nodes.push(c.clone().serialize()),c.inputs&&c.inputs.length)for(b=0;b<c.inputs.length;++b){var h=c.inputs[b];if(h&&null!=h.link&&(h=this.graph.links[h.link])){var k=this.graph.getNodeById(h.origin_id);k&&this.selected_nodes[k.id]&&
|
||||
a.links.push([k._relative_id,b,c._relative_id,h.target_slot])}}localStorage.setItem("litegrapheditor_clipboard",JSON.stringify(a))};f.prototype.pasteFromClipboard=function(){var a=localStorage.getItem("litegrapheditor_clipboard");if(a){for(var a=JSON.parse(a),b=[],d=0;d<a.nodes.length;++d){var c=a.nodes[d],p=e.createNode(c.type);p&&(p.configure(c),p.pos[0]+=5,p.pos[1]+=5,this.graph.add(p),b.push(p))}for(d=0;d<a.links.length;++d)c=a.links[d],b[c[0]].connect(c[1],b[c[2]],c[3]);this.selectNodes(b)}};
|
||||
f.prototype.processDrop=function(a){a.preventDefault();this.adjustMouseEvent(a);var b=[a.canvasX,a.canvasY],d=this.graph.getNodeOnPos(b[0],b[1]);if(d){if((d.onDropFile||d.onDropData)&&(b=a.dataTransfer.files)&&b.length)for(var e=0;e<b.length;e++){var c=a.dataTransfer.files[0],h=c.name;f.getFileExtension(h);if(d.onDropFile)d.onDropFile(c);if(d.onDropData){var k=new FileReader;k.onload=function(a){d.onDropData(a.target.result,h,c)};var n=c.type.split("/")[0];"text"==n||""==n?k.readAsText(c):"image"==
|
||||
n?k.readAsDataURL(c):k.readAsArrayBuffer(c)}}return d.onDropItem&&d.onDropItem(event)?!0:this.onDropItem?this.onDropItem(event):!1}b=null;this.onDropItem&&(b=this.onDropItem(event));b||this.checkDropItem(a)};f.prototype.checkDropItem=function(a){if(a.dataTransfer.files.length){var b=a.dataTransfer.files[0],d=f.getFileExtension(b.name).toLowerCase();if(d=e.node_types_by_file_extension[d])if(d=e.createNode(d.type),d.pos=[a.canvasX,a.canvasY],this.graph.add(d),d.onDropFile)d.onDropFile(b)}};f.prototype.processNodeDblClicked=
|
||||
function(a){if(this.onShowNodePanel)this.onShowNodePanel(a);if(this.onNodeDblClicked)this.onNodeDblClicked(a);this.setDirty(!0)};f.prototype.processNodeSelected=function(a,b){this.selectNode(a,b&&b.shiftKey);if(this.onNodeSelected)this.onNodeSelected(a)};f.prototype.processNodeDeselected=function(a){this.deselectNode(a);if(this.onNodeDeselected)this.onNodeDeselected(a)};f.prototype.selectNode=function(a,b){null==a?this.deselectAllNodes():this.selectNodes([a],b)};f.prototype.selectNodes=function(a,
|
||||
b){b||this.deselectAllNodes();a=a||this.graph._nodes;for(var d=0;d<a.length;++d){var e=a[d];if(!e.is_selected){if(!e.is_selected&&e.onSelected)e.onSelected();e.is_selected=!0;this.selected_nodes[e.id]=e;if(e.inputs)for(var c=0;c<e.inputs.length;++c)this.highlighted_links[e.inputs[c].link]=!0;if(e.outputs)for(c=0;c<e.outputs.length;++c){var h=e.outputs[c];if(h.links)for(var k=0;k<h.links.length;++k)this.highlighted_links[h.links[k]]=!0}}}if(this.onSelectionChange)this.onSelectionChange(this.selected_nodes);
|
||||
this.setDirty(!0)};f.prototype.deselectNode=function(a){if(a.is_selected){if(a.onDeselected)a.onDeselected();a.is_selected=!1;if(a.inputs)for(var b=0;b<a.inputs.length;++b)delete this.highlighted_links[a.inputs[b].link];if(a.outputs)for(b=0;b<a.outputs.length;++b){var d=a.outputs[b];if(d.links)for(var e=0;e<d.links.length;++e)delete this.highlighted_links[d.links[e]]}}};f.prototype.deselectAllNodes=function(){if(this.graph){for(var a=this.graph._nodes,b=0,d=a.length;b<d;++b){var e=a[b];if(e.is_selected){if(e.onDeselected)e.onDeselected();
|
||||
e.is_selected=!1}}this.selected_nodes={};this.current_node=null;this.highlighted_links={};if(this.onSelectionChange)this.onSelectionChange(this.selected_nodes);this.setDirty(!0)}};f.prototype.deleteSelectedNodes=function(){for(var a in this.selected_nodes)this.graph.remove(this.selected_nodes[a]);this.selected_nodes={};this.current_node=null;this.highlighted_links={};this.setDirty(!0)};f.prototype.centerOnNode=function(a){this.ds.offset[0]=-a.pos[0]-0.5*a.size[0]+0.5*this.canvas.width/this.ds.scale;
|
||||
this.ds.offset[1]=-a.pos[1]-0.5*a.size[1]+0.5*this.canvas.height/this.ds.scale;this.setDirty(!0,!0)};f.prototype.adjustMouseEvent=function(a){if(this.canvas){var b=this.canvas.getBoundingClientRect();a.localX=a.clientX-b.left;a.localY=a.clientY-b.top}else a.localX=a.clientX,a.localY=a.clientY;a.deltaX=a.localX-this.last_mouse_position[0];a.deltaY=a.localY-this.last_mouse_position[1];this.last_mouse_position[0]=a.localX;this.last_mouse_position[1]=a.localY;a.canvasX=a.localX/this.ds.scale-this.ds.offset[0];
|
||||
a.canvasY=a.localY/this.ds.scale-this.ds.offset[1]};f.prototype.setZoom=function(a,b){this.ds.changeScale(a,b);this.dirty_bgcanvas=this.dirty_canvas=!0};f.prototype.convertOffsetToCanvas=function(a,b){return this.ds.convertOffsetToCanvas(a,b)};f.prototype.convertCanvasToOffset=function(a,b){return this.ds.convertCanvasToOffset(a,b)};f.prototype.convertEventToCanvasOffset=function(a){var b=this.canvas.getBoundingClientRect();return this.convertCanvasToOffset([a.clientX-b.left,a.clientY-b.top])};f.prototype.bringToFront=
|
||||
function(a){var b=this.graph._nodes.indexOf(a);-1!=b&&(this.graph._nodes.splice(b,1),this.graph._nodes.push(a))};f.prototype.sendToBack=function(a){var b=this.graph._nodes.indexOf(a);-1!=b&&(this.graph._nodes.splice(b,1),this.graph._nodes.unshift(a))};var w=new Float32Array(4);f.prototype.computeVisibleNodes=function(a,b){var d=b||[];d.length=0;a=a||this.graph._nodes;for(var e=0,c=a.length;e<c;++e){var h=a[e];(!this.live_mode||h.onDrawBackground||h.onDrawForeground)&&u(this.visible_area,h.getBounding(w))&&
|
||||
d.push(h)}return d};f.prototype.draw=function(a,b){if(this.canvas){var d=e.getTime();this.render_time=0.001*(d-this.last_draw_time);this.last_draw_time=d;this.graph&&this.ds.computeVisibleArea();(this.dirty_bgcanvas||b||this.always_render_background||this.graph&&this.graph._last_trigger_time&&1E3>d-this.graph._last_trigger_time)&&this.drawBackCanvas();(this.dirty_canvas||a)&&this.drawFrontCanvas();this.fps=this.render_time?1/this.render_time:0;this.frame+=1}};f.prototype.drawFrontCanvas=function(){this.dirty_canvas=
|
||||
!1;this.ctx||(this.ctx=this.bgcanvas.getContext("2d"));var a=this.ctx;if(a){a.start2D&&a.start2D();var b=this.canvas;a.restore();a.setTransform(1,0,0,1,0,0);this.dirty_area&&(a.save(),a.beginPath(),a.rect(this.dirty_area[0],this.dirty_area[1],this.dirty_area[2],this.dirty_area[3]),a.clip());this.clear_background&&a.clearRect(0,0,b.width,b.height);this.bgcanvas==this.canvas?this.drawBackCanvas():a.drawImage(this.bgcanvas,0,0);if(this.onRender)this.onRender(b,a);this.show_info&&this.renderInfo(a);if(this.graph){a.save();
|
||||
this.ds.toCanvasContext(a);for(var b=this.computeVisibleNodes(null,this.visible_nodes),d=0;d<b.length;++d){var c=b[d];a.save();a.translate(c.pos[0],c.pos[1]);this.drawNode(c,a);a.restore()}this.render_execution_order&&this.drawExecutionOrder(a);this.graph.config.links_ontop&&(this.live_mode||this.drawConnections(a));if(null!=this.connecting_pos){a.lineWidth=this.connections_width;b=null;switch(this.connecting_output.type){case e.EVENT:b=e.EVENT_LINK_COLOR;break;default:b=e.CONNECTING_LINK_COLOR}this.renderLink(a,
|
||||
this.connecting_pos,[this.canvas_mouse[0],this.canvas_mouse[1]],null,!1,null,b,this.connecting_output.dir||(this.connecting_node.horizontal?e.DOWN:e.RIGHT),e.CENTER);a.beginPath();this.connecting_output.type===e.EVENT||this.connecting_output.shape===e.BOX_SHAPE?a.rect(this.connecting_pos[0]-6+0.5,this.connecting_pos[1]-5+0.5,14,10):a.arc(this.connecting_pos[0],this.connecting_pos[1],4,0,2*Math.PI);a.fill();a.fillStyle="#ffcc00";this._highlight_input&&(a.beginPath(),a.arc(this._highlight_input[0],
|
||||
this._highlight_input[1],6,0,2*Math.PI),a.fill())}this.dragging_rectangle&&(a.strokeStyle="#FFF",a.strokeRect(this.dragging_rectangle[0],this.dragging_rectangle[1],this.dragging_rectangle[2],this.dragging_rectangle[3]));if(this.over_link_center&&this.render_link_tooltip)this.drawLinkTooltip(a,this.over_link_center);else if(this.onDrawLinkTooltip)this.onDrawLinkTooltip(a,null);if(this.onDrawForeground)this.onDrawForeground(a,this.visible_rect);a.restore()}if(this.onDrawOverlay)this.onDrawOverlay(a);
|
||||
this.dirty_area&&a.restore();a.finish2D&&a.finish2D()}};f.prototype.renderInfo=function(a,b,d){b=b||0;d=d||0;a.save();a.translate(b,d);a.font="10px Arial";a.fillStyle="#888";this.graph?(a.fillText("T: "+this.graph.globaltime.toFixed(2)+"s",5,13),a.fillText("I: "+this.graph.iteration,5,26),a.fillText("N: "+this.graph._nodes.length+" ["+this.visible_nodes.length+"]",5,39),a.fillText("V: "+this.graph._version,5,52),a.fillText("FPS:"+this.fps.toFixed(2),5,65)):a.fillText("No graph selected",5,13);a.restore()};
|
||||
f.prototype.drawBackCanvas=function(){var a=this.bgcanvas;if(a.width!=this.canvas.width||a.height!=this.canvas.height)a.width=this.canvas.width,a.height=this.canvas.height;this.bgctx||(this.bgctx=this.bgcanvas.getContext("2d"));var b=this.bgctx;b.start&&b.start();this.clear_background&&b.clearRect(0,0,a.width,a.height);if(this._graph_stack&&this._graph_stack.length){b.save();var d=this.graph._subgraph_node;b.strokeStyle=d.bgcolor;b.lineWidth=10;b.strokeRect(1,1,a.width-2,a.height-2);b.lineWidth=1;
|
||||
b.font="40px Arial";b.textAlign="center";b.fillStyle=d.bgcolor||"#AAA";for(var e="",c=1;c<this._graph_stack.length;++c)e+=this._graph_stack[c]._subgraph_node.getTitle()+" >> ";b.fillText(e+d.getTitle(),0.5*a.width,40);b.restore()}d=!1;this.onRenderBackground&&(d=this.onRenderBackground(a,b));b.restore();b.setTransform(1,0,0,1,0,0);this.visible_links.length=0;if(this.graph){b.save();this.ds.toCanvasContext(b);if(this.background_image&&0.5<this.ds.scale&&!d){b.globalAlpha=this.zoom_modify_alpha?(1-
|
||||
0.5/this.ds.scale)*this.editor_alpha:this.editor_alpha;b.imageSmoothingEnabled=b.mozImageSmoothingEnabled=b.imageSmoothingEnabled=!1;if(!this._bg_img||this._bg_img.name!=this.background_image){this._bg_img=new Image;this._bg_img.name=this.background_image;this._bg_img.src=this.background_image;var h=this;this._bg_img.onload=function(){h.draw(!0,!0)}}d=null;null==this._pattern&&0<this._bg_img.width?(d=b.createPattern(this._bg_img,"repeat"),this._pattern_img=this._bg_img,this._pattern=d):d=this._pattern;
|
||||
d&&(b.fillStyle=d,b.fillRect(this.visible_area[0],this.visible_area[1],this.visible_area[2],this.visible_area[3]),b.fillStyle="transparent");b.globalAlpha=1;b.imageSmoothingEnabled=b.mozImageSmoothingEnabled=b.imageSmoothingEnabled=!0}this.graph._groups.length&&!this.live_mode&&this.drawGroups(a,b);if(this.onDrawBackground)this.onDrawBackground(b,this.visible_area);this.onBackgroundRender&&(console.error("WARNING! onBackgroundRender deprecated, now is named onDrawBackground "),this.onBackgroundRender=
|
||||
null);this.render_canvas_border&&(b.strokeStyle="#235",b.strokeRect(0,0,a.width,a.height));this.render_connections_shadows?(b.shadowColor="#000",b.shadowOffsetX=0,b.shadowOffsetY=0,b.shadowBlur=6):b.shadowColor="rgba(0,0,0,0)";this.live_mode||this.drawConnections(b);b.shadowColor="rgba(0,0,0,0)";b.restore()}b.finish&&b.finish();this.dirty_bgcanvas=!1;this.dirty_canvas=!0};var k=new Float32Array(2);f.prototype.drawNode=function(a,b){this.current_node=a;var d=a.color||a.constructor.color||e.NODE_DEFAULT_COLOR,
|
||||
c=a.bgcolor||a.constructor.bgcolor||e.NODE_DEFAULT_BGCOLOR;if(this.live_mode){if(!a.flags.collapsed&&(b.shadowColor="transparent",a.onDrawForeground))a.onDrawForeground(b,this,this.canvas)}else{var p=this.editor_alpha;b.globalAlpha=p;this.render_shadows?(b.shadowColor=e.DEFAULT_SHADOW_COLOR,b.shadowOffsetX=2*this.ds.scale,b.shadowOffsetY=2*this.ds.scale,b.shadowBlur=3*this.ds.scale):b.shadowColor="transparent";if(!a.flags.collapsed||!a.onDrawCollapsed||!0!=a.onDrawCollapsed(b,this)){var h=a._shape||
|
||||
e.BOX_SHAPE;k.set(a.size);var f=a.horizontal;if(a.flags.collapsed){b.font=this.inner_text_font;var n=a.getTitle?a.getTitle():a.title;null!=n&&(a._collapsed_width=Math.min(a.size[0],b.measureText(n).width+2*e.NODE_TITLE_HEIGHT),k[0]=a._collapsed_width,k[1]=0)}a.clip_area&&(b.save(),b.beginPath(),h==e.BOX_SHAPE?b.rect(0,0,k[0],k[1]):h==e.ROUND_SHAPE?b.roundRect(0,0,k[0],k[1],10):h==e.CIRCLE_SHAPE&&b.arc(0.5*k[0],0.5*k[1],0.5*k[0],0,2*Math.PI),b.clip());a.has_errors&&(c="red");this.drawNodeShape(a,b,
|
||||
k,d,c,a.is_selected,a.mouseOver);b.shadowColor="transparent";if(a.onDrawForeground)a.onDrawForeground(b,this,this.canvas);b.textAlign=f?"center":"left";b.font=this.inner_text_font;c=0.6<this.ds.scale;h=this.connecting_output;b.lineWidth=1;var n=0,t=new Float32Array(2);if(!a.flags.collapsed){if(a.inputs)for(d=0;d<a.inputs.length;d++){var m=a.inputs[d];b.globalAlpha=p;this.connecting_node&&!e.isValidConnection(m.type,h.type)&&(b.globalAlpha=0.4*p);b.fillStyle=null!=m.link?m.color_on||this.default_connection_color.input_on:
|
||||
m.color_off||this.default_connection_color.input_off;var l=a.getConnectionPos(!0,d,t);l[0]-=a.pos[0];l[1]-=a.pos[1];n<l[1]+0.5*e.NODE_SLOT_HEIGHT&&(n=l[1]+0.5*e.NODE_SLOT_HEIGHT);b.beginPath();m.type===e.EVENT||m.shape===e.BOX_SHAPE?f?b.rect(l[0]-5+0.5,l[1]-8+0.5,10,14):b.rect(l[0]-6+0.5,l[1]-5+0.5,14,10):m.shape===e.ARROW_SHAPE?(b.moveTo(l[0]+8,l[1]+0.5),b.lineTo(l[0]-4,l[1]+6+0.5),b.lineTo(l[0]-4,l[1]-6+0.5),b.closePath()):b.arc(l[0],l[1],4,0,2*Math.PI);b.fill();if(c){var g=null!=m.label?m.label:
|
||||
m.name;g&&(b.fillStyle=e.NODE_TEXT_COLOR,f||m.dir==e.UP?b.fillText(g,l[0],l[1]-10):b.fillText(g,l[0]+10,l[1]+5))}}this.connecting_node&&(b.globalAlpha=0.4*p);b.textAlign=f?"center":"right";b.strokeStyle="black";if(a.outputs)for(d=0;d<a.outputs.length;d++)if(m=a.outputs[d],l=a.getConnectionPos(!1,d,t),l[0]-=a.pos[0],l[1]-=a.pos[1],n<l[1]+0.5*e.NODE_SLOT_HEIGHT&&(n=l[1]+0.5*e.NODE_SLOT_HEIGHT),b.fillStyle=m.links&&m.links.length?m.color_on||this.default_connection_color.output_on:m.color_off||this.default_connection_color.output_off,
|
||||
b.beginPath(),m.type===e.EVENT||m.shape===e.BOX_SHAPE?f?b.rect(l[0]-5+0.5,l[1]-8+0.5,10,14):b.rect(l[0]-6+0.5,l[1]-5+0.5,14,10):m.shape===e.ARROW_SHAPE?(b.moveTo(l[0]+8,l[1]+0.5),b.lineTo(l[0]-4,l[1]+6+0.5),b.lineTo(l[0]-4,l[1]-6+0.5),b.closePath()):b.arc(l[0],l[1],4,0,2*Math.PI),b.fill(),b.stroke(),c&&(g=null!=m.label?m.label:m.name))b.fillStyle=e.NODE_TEXT_COLOR,f||m.dir==e.DOWN?b.fillText(g,l[0],l[1]-8):b.fillText(g,l[0]-10,l[1]+5);b.textAlign="left";b.globalAlpha=1;if(a.widgets){if(f||a.widgets_up)n=
|
||||
2;this.drawNodeWidgets(a,n,b,this.node_widget&&this.node_widget[0]==a?this.node_widget[1]:null)}}else if(this.render_collapsed_slots){p=c=null;if(a.inputs)for(d=0;d<a.inputs.length;d++)if(m=a.inputs[d],null!=m.link){c=m;break}if(a.outputs)for(d=0;d<a.outputs.length;d++)m=a.outputs[d],m.links&&m.links.length&&(p=m);c&&(d=0,c=-0.5*e.NODE_TITLE_HEIGHT,f&&(d=0.5*a._collapsed_width,c=-e.NODE_TITLE_HEIGHT),b.fillStyle="#686",b.beginPath(),m.type===e.EVENT||m.shape===e.BOX_SHAPE?b.rect(d-7+0.5,c-4,14,8):
|
||||
m.shape===e.ARROW_SHAPE?(b.moveTo(d+8,c),b.lineTo(d+-4,c-4),b.lineTo(d+-4,c+4),b.closePath()):b.arc(d,c,4,0,2*Math.PI),b.fill());p&&(d=a._collapsed_width,c=-0.5*e.NODE_TITLE_HEIGHT,f&&(d=0.5*a._collapsed_width,c=0),b.fillStyle="#686",b.strokeStyle="black",b.beginPath(),m.type===e.EVENT||m.shape===e.BOX_SHAPE?b.rect(d-7+0.5,c-4,14,8):m.shape===e.ARROW_SHAPE?(b.moveTo(d+6,c),b.lineTo(d-6,c-4),b.lineTo(d-6,c+4),b.closePath()):b.arc(d,c,4,0,2*Math.PI),b.fill())}a.clip_area&&b.restore();b.globalAlpha=
|
||||
1}}};f.prototype.drawLinkTooltip=function(a,b){var d=b._pos;a.fillStyle="black";a.beginPath();a.arc(d[0],d[1],3,0,2*Math.PI);a.fill();if(null!=b.data&&(!this.onDrawLinkTooltip||!0!=this.onDrawLinkTooltip(a,b,this))){var e=b.data,c=null,c=e.constructor===Number?e.toFixed(2):e.constructor===String?'"'+e+'"':e.constructor===Boolean?String(e):e.toToolTip?e.toToolTip():"["+e.constructor.name+"]";null!=c&&(a.font="14px Courier New",e=a.measureText(c).width+20,a.shadowColor="black",a.shadowOffsetX=2,a.shadowOffsetY=
|
||||
2,a.shadowBlur=3,a.fillStyle="#454",a.beginPath(),a.roundRect(d[0]-0.5*e,d[1]-15-24,e,24,3,3),a.moveTo(d[0]-10,d[1]-15),a.lineTo(d[0]+10,d[1]-15),a.lineTo(d[0],d[1]-5),a.fill(),a.shadowColor="transparent",a.textAlign="center",a.fillStyle="#CEC",a.fillText(c,d[0],d[1]-15-24*0.3))}};var n=new Float32Array(4);f.prototype.drawNodeShape=function(a,b,d,c,p,h,k){b.strokeStyle=c;b.fillStyle=p;p=e.NODE_TITLE_HEIGHT;var m=0.5>this.ds.scale,t=a._shape||a.constructor.shape||e.ROUND_SHAPE,l=a.constructor.title_mode,
|
||||
g=!0;l==e.TRANSPARENT_TITLE?g=!1:l==e.AUTOHIDE_TITLE&&k&&(g=!0);n[0]=0;n[1]=g?-p:0;n[2]=d[0]+1;n[3]=g?d[1]+p:d[1];k=b.globalAlpha;b.beginPath();t==e.BOX_SHAPE||m?b.fillRect(n[0],n[1],n[2],n[3]):t==e.ROUND_SHAPE||t==e.CARD_SHAPE?b.roundRect(n[0],n[1],n[2],n[3],this.round_radius,t==e.CARD_SHAPE?0:this.round_radius):t==e.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,n[2],2));b.shadowColor=
|
||||
"transparent";if(a.onDrawBackground)a.onDrawBackground(b,this,this.canvas);if(g||l==e.TRANSPARENT_TITLE){if(a.onDrawTitleBar)a.onDrawTitleBar(b,p,d,this.ds.scale,c);else if(l!=e.TRANSPARENT_TITLE&&(a.constructor.title_color||this.render_title_colored)){g=a.constructor.title_color||c;a.flags.collapsed&&(b.shadowColor=e.DEFAULT_SHADOW_COLOR);if(this.use_gradients){var s=f.gradients[g];s||(s=f.gradients[g]=b.createLinearGradient(0,0,400,0),s.addColorStop(0,g),s.addColorStop(1,"#000"));b.fillStyle=s}else b.fillStyle=
|
||||
g;b.beginPath();t==e.BOX_SHAPE||m?b.rect(0,-p,d[0]+1,p):t!=e.ROUND_SHAPE&&t!=e.CARD_SHAPE||b.roundRect(0,-p,d[0]+1,p,this.round_radius,a.flags.collapsed?this.round_radius:0);b.fill();b.shadowColor="transparent"}if(a.onDrawTitleBox)a.onDrawTitleBox(b,p,d,this.ds.scale);else t==e.ROUND_SHAPE||t==e.CIRCLE_SHAPE||t==e.CARD_SHAPE?(m&&(b.fillStyle="black",b.beginPath(),b.arc(0.5*p,-0.5*p,6,0,2*Math.PI),b.fill()),b.fillStyle=a.boxcolor||e.NODE_DEFAULT_BOXCOLOR,b.beginPath(),b.arc(0.5*p,-0.5*p,5,0,2*Math.PI),
|
||||
b.fill()):(m&&(b.fillStyle="black",b.fillRect(0.5*(p-10)-1,-0.5*(p+10)-1,12,12)),b.fillStyle=a.boxcolor||e.NODE_DEFAULT_BOXCOLOR,b.fillRect(0.5*(p-10),-0.5*(p+10),10,10));b.globalAlpha=k;if(a.onDrawTitleText)a.onDrawTitleText(b,p,d,this.ds.scale,this.title_text_font,h);!m&&(b.font=this.title_text_font,m=a.getTitle())&&(b.fillStyle=h?"white":a.constructor.title_text_color||this.node_title_color,a.flags.collapsed?(b.textAlign="center",k=b.measureText(m),b.fillText(m,p+0.5*k.width,e.NODE_TITLE_TEXT_Y-
|
||||
p),b.textAlign="left"):(b.textAlign="left",b.fillText(m,p,e.NODE_TITLE_TEXT_Y-p)));if(a.onDrawTitle)a.onDrawTitle(b)}if(h){if(a.onBounding)a.onBounding(n);l==e.TRANSPARENT_TITLE&&(n[1]-=p,n[3]+=p);b.lineWidth=1;b.globalAlpha=0.8;b.beginPath();t==e.BOX_SHAPE?b.rect(-6+n[0],-6+n[1],12+n[2],12+n[3]):t==e.ROUND_SHAPE||t==e.CARD_SHAPE&&a.flags.collapsed?b.roundRect(-6+n[0],-6+n[1],12+n[2],12+n[3],2*this.round_radius):t==e.CARD_SHAPE?b.roundRect(-6+n[0],-6+n[1],12+n[2],12+n[3],2*this.round_radius,2):t==
|
||||
e.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=c;b.globalAlpha=1}};var D=new Float32Array(4),h=new Float32Array(4),t=new Float32Array(2),m=new Float32Array(2);f.prototype.drawConnections=function(a){var b=e.getTime(),d=this.visible_area;D[0]=d[0]-20;D[1]=d[1]-20;D[2]=d[2]+40;D[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,c=0,p=d.length;c<
|
||||
p;++c){var k=d[c];if(k.inputs&&k.inputs.length)for(var f=0;f<k.inputs.length;++f){var n=k.inputs[f];if(n&&null!=n.link&&(n=this.graph.links[n.link])){var l=this.graph.getNodeById(n.origin_id);if(null!=l){var g=n.origin_slot,s=null,s=-1==g?[l.pos[0]+10,l.pos[1]+10]:l.getConnectionPos(!1,g,t),w=k.getConnectionPos(!0,f,m);h[0]=s[0];h[1]=s[1];h[2]=w[0]-s[0];h[3]=w[1]-s[1];0>h[2]&&(h[0]+=h[2],h[2]=Math.abs(h[2]));0>h[3]&&(h[1]+=h[3],h[3]=Math.abs(h[3]));if(u(h,D)){var B=l.outputs[g],g=k.inputs[f];if(B&&
|
||||
g&&(l=B.dir||(l.horizontal?e.DOWN:e.RIGHT),g=g.dir||(k.horizontal?e.UP:e.LEFT),this.renderLink(a,s,w,n,!1,0,null,l,g),n&&n._last_time&&1E3>b-n._last_time)){var B=2-0.002*(b-n._last_time),J=a.globalAlpha;a.globalAlpha=J*B;this.renderLink(a,s,w,n,!0,B,"white",l,g);a.globalAlpha=J}}}}}}a.globalAlpha=1};f.prototype.renderLink=function(a,b,d,c,p,h,k,n,m,t){c&&this.visible_links.push(c);!k&&c&&(k=c.color||f.link_type_colors[c.type]);k||(k=this.default_link_color);null!=c&&this.highlighted_links[c.id]&&
|
||||
(k="#FFF");n=n||e.RIGHT;m=m||e.LEFT;var l=y(b,d);this.render_connections_border&&0.6<this.ds.scale&&(a.lineWidth=this.connections_width+4);a.lineJoin="round";t=t||1;1<t&&(a.lineWidth=0.5);a.beginPath();for(var g=0;g<t;g+=1){var B=5*(g-0.5*(t-1));if(this.links_render_mode==e.SPLINE_LINK){a.moveTo(b[0],b[1]+B);var s=0,w=0,u=0,r=0;switch(n){case e.LEFT:s=-0.25*l;break;case e.RIGHT:s=0.25*l;break;case e.UP:w=-0.25*l;break;case e.DOWN:w=0.25*l}switch(m){case e.LEFT:u=-0.25*l;break;case e.RIGHT:u=0.25*
|
||||
l;break;case e.UP:r=-0.25*l;break;case e.DOWN:r=0.25*l}a.bezierCurveTo(b[0]+s,b[1]+w+B,d[0]+u,d[1]+r+B,d[0],d[1]+B)}else if(this.links_render_mode==e.LINEAR_LINK){a.moveTo(b[0],b[1]+B);r=u=w=s=0;switch(n){case e.LEFT:s=-1;break;case e.RIGHT:s=1;break;case e.UP:w=-1;break;case e.DOWN:w=1}switch(m){case e.LEFT:u=-1;break;case e.RIGHT:u=1;break;case e.UP:r=-1;break;case e.DOWN:r=1}a.lineTo(b[0]+15*s,b[1]+15*w+B);a.lineTo(d[0]+15*u,d[1]+15*r+B);a.lineTo(d[0],d[1]+B)}else if(this.links_render_mode==e.STRAIGHT_LINK)a.moveTo(b[0],
|
||||
b[1]),B=b[0],s=b[1],w=d[0],u=d[1],n==e.RIGHT?B+=10:s+=10,m==e.LEFT?w-=10:u-=10,a.lineTo(B,s),a.lineTo(0.5*(B+w),s),a.lineTo(0.5*(B+w),u),a.lineTo(w,u),a.lineTo(d[0],d[1]);else return}this.render_connections_border&&0.6<this.ds.scale&&!p&&(a.strokeStyle="rgba(0,0,0,0.5)",a.stroke());a.lineWidth=this.connections_width;a.fillStyle=a.strokeStyle=k;a.stroke();p=this.computeConnectionPoint(b,d,0.5,n,m);c&&c._pos&&(c._pos[0]=p[0],c._pos[1]=p[1]);0.6<=this.ds.scale&&this.highquality_render&&m!=e.CENTER&&
|
||||
(this.render_connection_arrows&&(g=this.computeConnectionPoint(b,d,0.25,n,m),c=this.computeConnectionPoint(b,d,0.26,n,m),t=this.computeConnectionPoint(b,d,0.75,n,m),l=this.computeConnectionPoint(b,d,0.76,n,m),s=B=0,this.render_curved_connections?(B=-Math.atan2(c[0]-g[0],c[1]-g[1]),s=-Math.atan2(l[0]-t[0],l[1]-t[1])):s=B=d[1]>b[1]?0:Math.PI,a.save(),a.translate(g[0],g[1]),a.rotate(B),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore(),a.save(),a.translate(t[0],t[1]),a.rotate(s),
|
||||
a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore()),a.beginPath(),a.arc(p[0],p[1],5,0,2*Math.PI),a.fill());if(h)for(a.fillStyle=k,g=0;5>g;++g)h=(0.001*e.getTime()+0.2*g)%1,p=this.computeConnectionPoint(b,d,h,n,m),a.beginPath(),a.arc(p[0],p[1],5,0,2*Math.PI),a.fill()};f.prototype.computeConnectionPoint=function(a,b,d,c,p){c=c||e.RIGHT;p=p||e.LEFT;var h=y(a,b),k=[a[0],a[1]],f=[b[0],b[1]];switch(c){case e.LEFT:k[0]+=-0.25*h;break;case e.RIGHT:k[0]+=0.25*h;break;case e.UP:k[1]+=
|
||||
-0.25*h;break;case e.DOWN:k[1]+=0.25*h}switch(p){case e.LEFT:f[0]+=-0.25*h;break;case e.RIGHT:f[0]+=0.25*h;break;case e.UP:f[1]+=-0.25*h;break;case e.DOWN:f[1]+=0.25*h}c=(1-d)*(1-d)*(1-d);p=3*(1-d)*(1-d)*d;h=3*(1-d)*d*d;d*=d*d;return[c*a[0]+p*k[0]+h*f[0]+d*b[0],c*a[1]+p*k[1]+h*f[1]+d*b[1]]};f.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 c=b[d];
|
||||
a.fillStyle="black";a.fillRect(c.pos[0]-e.NODE_TITLE_HEIGHT,c.pos[1]-e.NODE_TITLE_HEIGHT,e.NODE_TITLE_HEIGHT,e.NODE_TITLE_HEIGHT);0==c.order&&a.strokeRect(c.pos[0]-e.NODE_TITLE_HEIGHT+0.5,c.pos[1]-e.NODE_TITLE_HEIGHT+0.5,e.NODE_TITLE_HEIGHT,e.NODE_TITLE_HEIGHT);a.fillStyle="#FFF";a.fillText(c.order,c.pos[0]+-0.5*e.NODE_TITLE_HEIGHT,c.pos[1]-6)}a.globalAlpha=1};f.prototype.drawNodeWidgets=function(a,b,d,c){if(!a.widgets||!a.widgets.length)return 0;var h=a.size[0],k=a.widgets;b+=2;var f=e.NODE_WIDGET_HEIGHT,
|
||||
n=0.5<this.ds.scale;d.save();d.globalAlpha=this.editor_alpha;for(var m=e.WIDGET_OUTLINE_COLOR,t=e.WIDGET_BGCOLOR,l=e.WIDGET_TEXT_COLOR,g=e.WIDGET_SECONDARY_TEXT_COLOR,B=0;B<k.length;++B){var s=k[B],w=b;s.y&&(w=s.y);s.last_y=w;d.strokeStyle=m;d.fillStyle="#222";d.textAlign="left";switch(s.type){case "button":s.clicked&&(d.fillStyle="#AAA",s.clicked=!1,this.dirty_canvas=!0);d.fillRect(15,w,h-30,f);d.strokeRect(15,w,h-30,f);n&&(d.textAlign="center",d.fillStyle=l,d.fillText(s.name,0.5*h,w+0.7*f));break;
|
||||
case "toggle":d.textAlign="left";d.strokeStyle=m;d.fillStyle=t;d.beginPath();d.roundRect(15,b,h-30,f,0.5*f);d.fill();d.stroke();d.fillStyle=s.value?"#89A":"#333";d.beginPath();d.arc(h-30,w+0.5*f,0.36*f,0,2*Math.PI);d.fill();n&&(d.fillStyle=g,null!=s.name&&d.fillText(s.name,30,w+0.7*f),d.fillStyle=s.value?l:g,d.textAlign="right",d.fillText(s.value?s.options.on||"true":s.options.off||"false",h-40,w+0.7*f));break;case "slider":d.fillStyle=t;d.fillRect(15,w,h-30,f);var u=s.options.max-s.options.min,r=
|
||||
(s.value-s.options.min)/u;d.fillStyle=c==s?"#89A":"#678";d.fillRect(15,w,r*(h-30),f);d.strokeRect(15,w,h-30,f);s.marker&&(u=(s.marker-s.options.min)/u,d.fillStyle="#AA9",d.fillRect(15+u*(h-30),w,2,f));n&&(d.textAlign="center",d.fillStyle=l,d.fillText(s.name+" "+Number(s.value).toFixed(3),0.5*h,w+0.7*f));break;case "number":case "combo":d.textAlign="left";d.strokeStyle=m;d.fillStyle=t;d.beginPath();d.roundRect(15,b,h-30,f,0.5*f);d.fill();d.stroke();n&&(d.fillStyle=l,d.beginPath(),d.moveTo(31,b+5),
|
||||
d.lineTo(21,b+0.5*f),d.lineTo(31,b+f-5),d.moveTo(h-15-16,b+5),d.lineTo(h-15-6,b+0.5*f),d.lineTo(h-15-16,b+f-5),d.fill(),d.fillStyle=g,d.fillText(s.name,35,w+0.7*f),d.fillStyle=l,d.textAlign="right","number"==s.type?d.fillText(Number(s.value).toFixed(void 0!==s.options.precision?s.options.precision:3),h-30-20,w+0.7*f):d.fillText(s.value,h-30-20,w+0.7*f));break;case "string":case "text":d.textAlign="left";d.strokeStyle=m;d.fillStyle=t;d.beginPath();d.roundRect(15,b,h-30,f,0.5*f);d.fill();d.stroke();
|
||||
n&&(d.fillStyle=g,null!=s.name&&d.fillText(s.name,30,w+0.7*f),d.fillStyle=l,d.textAlign="right",d.fillText(s.value,h-30,w+0.7*f));break;default:s.draw&&s.draw(d,a,s,w,f)}b+=f+4}d.restore()};f.prototype.processNodeWidgets=function(a,b,d,c){function h(e,c){e.value=c;e.property&&void 0!==a.properties[e.property]&&a.setProperty(e.property,c);e.callback&&e.callback(e.value,m,a,b,d)}if(!a.widgets||!a.widgets.length)return null;for(var k=b[0]-a.pos[0],f=b[1]-a.pos[1],n=a.size[0],m=this,t=this.getCanvasWindow(),
|
||||
l=0;l<a.widgets.length;++l){var g=a.widgets[l];if(g==c||6<k&&k<n-12&&f>g.last_y&&f<g.last_y+e.NODE_WIDGET_HEIGHT){switch(g.type){case "button":if("mousemove"===d.type)break;g.callback&&setTimeout(function(){g.callback(g,m,a,b)},20);this.dirty_canvas=g.clicked=!0;break;case "slider":t=Math.clamp((k-10)/(n-20),0,1);g.value=g.options.min+(g.options.max-g.options.min)*t;g.callback&&setTimeout(function(){h(g,g.value)},20);this.dirty_canvas=!0;break;case "number":case "combo":if("mousemove"==d.type&&"number"==
|
||||
g.type)g.value+=0.1*d.deltaX*(g.options.step||1),null!=g.options.min&&g.value<g.options.min&&(g.value=g.options.min),null!=g.options.max&&g.value>g.options.max&&(g.value=g.options.max);else if("mousedown"==d.type)if((c=g.options.values)&&c.constructor===Function&&(c=g.options.values(g,a)),k=40>k?-1:k>n-40?1:0,"number"==g.type)g.value+=0.1*k*(g.options.step||1),null!=g.options.min&&g.value<g.options.min&&(g.value=g.options.min),null!=g.options.max&&g.value>g.options.max&&(g.value=g.options.max);else if(k)t=
|
||||
c.indexOf(g.value)+k,t>=c.length&&(t=0),0>t&&(t=c.length-1),g.value=c[t];else{new e.ContextMenu(c,{scale:Math.max(1,this.ds.scale),event:d,className:"dark",callback:B.bind(g)},t);var B=function(a,b,d){this.value=a;h(this,a);m.dirty_canvas=!0;return!1}}setTimeout(function(){h(this,this.value)}.bind(g),20);this.dirty_canvas=!0;break;case "toggle":"mousedown"==d.type&&(g.value=!g.value,g.callback&&setTimeout(function(){h(g,g.value)},20));break;case "string":case "text":"mousedown"==d.type&&this.prompt("Value",
|
||||
g.value,function(a){this.value=a;h(this,a)}.bind(g),d);break;default:g.mouse&&g.mouse(ctx,d,[k,f],a)}return g}}return null};f.prototype.drawGroups=function(a,b){if(this.graph){var d=this.graph._groups;b.save();b.globalAlpha=0.5*this.editor_alpha;for(var c=0;c<d.length;++c){var h=d[c];if(u(this.visible_area,h._bounding)){b.fillStyle=h.color||"#335";b.strokeStyle=h.color||"#335";var k=h._pos,f=h._size;b.globalAlpha=0.25*this.editor_alpha;b.beginPath();b.rect(k[0]+0.5,k[1]+0.5,f[0],f[1]);b.fill();b.globalAlpha=
|
||||
this.editor_alpha;b.stroke();b.beginPath();b.moveTo(k[0]+f[0],k[1]+f[1]);b.lineTo(k[0]+f[0]-10,k[1]+f[1]);b.lineTo(k[0]+f[0],k[1]+f[1]-10);b.fill();f=h.font_size||e.DEFAULT_GROUP_FONT_SIZE;b.font=f+"px Arial";b.fillText(h.title,k[0]+4,k[1]+f)}}b.restore()}};f.prototype.adjustNodesSize=function(){for(var a=this.graph._nodes,b=0;b<a.length;++b)a[b].size=a[b].computeSize();this.setDirty(!0,!0)};f.prototype.resize=function(a,b){if(!a&&!b){var d=this.canvas.parentNode;a=d.offsetWidth;b=d.offsetHeight}if(this.canvas.width!=
|
||||
a||this.canvas.height!=b)this.canvas.width=a,this.canvas.height=b,this.bgcanvas.width=this.canvas.width,this.bgcanvas.height=this.canvas.height,this.setDirty(!0,!0)};f.prototype.switchLiveMode=function(a){if(a){var b=this,d=this.live_mode?1.1:0.9;this.live_mode&&(this.live_mode=!1,this.editor_alpha=0.1);var e=setInterval(function(){b.editor_alpha*=d;b.dirty_canvas=!0;b.dirty_bgcanvas=!0;1>d&&0.01>b.editor_alpha&&(clearInterval(e),1>d&&(b.live_mode=!0));1<d&&0.99<b.editor_alpha&&(clearInterval(e),
|
||||
b.editor_alpha=1)},1)}else this.live_mode=!this.live_mode,this.dirty_bgcanvas=this.dirty_canvas=!0};f.prototype.onNodeSelectionChange=function(a){};f.prototype.touchHandler=function(a){var b=a.changedTouches[0],d="";switch(a.type){case "touchstart":d="mousedown";break;case "touchmove":d="mousemove";break;case "touchend":d="mouseup";break;default:return}var e=this.getCanvasWindow(),c=e.document.createEvent("MouseEvent");c.initMouseEvent(d,!0,!0,e,1,b.screenX,b.screenY,b.clientX,b.clientY,!1,!1,!1,
|
||||
!1,0,null);b.target.dispatchEvent(c);a.preventDefault()};f.onGroupAdd=function(a,b,d){a=f.active_canvas;a.getCanvasWindow();b=new e.LGraphGroup;b.pos=a.convertEventToCanvasOffset(d);a.graph.add(b)};f.onMenuAdd=function(a,b,d,c){function h(a,b){var d=c.getFirstEvent(),f=e.createNode(a.value);f&&(f.pos=k.convertEventToCanvasOffset(d),k.graph.add(f))}var k=f.active_canvas,n=k.getCanvasWindow();a=e.getNodeTypesCategories(k.filter);b=[];for(var m in a)a[m]&&b.push({value:a[m],content:a[m],has_submenu:!0});
|
||||
var g=new e.ContextMenu(b,{event:d,callback:function(a,b,d){a=e.getNodeTypesInCategory(a.value,k.filter);b=[];for(var c in a)a[c].skip_list||b.push({content:a[c].title,value:a[c].type});new e.ContextMenu(b,{event:d,callback:h,parentMenu:g},n);return!1},parentMenu:c},n);return!1};f.onMenuCollapseAll=function(){};f.onMenuNodeEdit=function(){};f.showMenuNodeOptionalInputs=function(a,b,d,c,h){function k(a,b,d){h&&(a.callback&&a.callback.call(n,h,a,b,d),a.value&&(h.addInput(a.value[0],a.value[1],a.value[2]),
|
||||
h.setDirtyCanvas(!0,!0)))}if(h){var n=this;a=f.active_canvas.getCanvasWindow();b=h.optional_inputs;h.onGetInputs&&(b=h.onGetInputs());var m=[];if(b)for(var g in b){var t=b[g];if(t){var l=t[0];t[2]&&t[2].label&&(l=t[2].label);l={content:l,value:t};t[1]==e.ACTION&&(l.className="event");m.push(l)}else m.push(null)}this.onMenuNodeInputs&&(m=this.onMenuNodeInputs(m));if(m.length)return new e.ContextMenu(m,{event:d,callback:k,parentMenu:c,node:h},a),!1}};f.showMenuNodeOptionalOutputs=function(a,b,d,c,h){function k(a,
|
||||
b,d){if(h&&(a.callback&&a.callback.call(n,h,a,b,d),a.value))if(d=a.value[1],!d||d.constructor!==Object&&d.constructor!==Array)h.addOutput(a.value[0],a.value[1],a.value[2]),h.setDirtyCanvas(!0,!0);else{a=[];for(var f in d)a.push({content:f,value:d[f]});new e.ContextMenu(a,{event:b,callback:k,parentMenu:c,node:h});return!1}}if(h){var n=this;a=f.active_canvas.getCanvasWindow();b=h.optional_outputs;h.onGetOutputs&&(b=h.onGetOutputs());var m=[];if(b)for(var g in b){var t=b[g];if(!t)m.push(null);else if(!h.flags||
|
||||
!h.flags.skip_repeated_outputs||-1==h.findOutputSlot(t[0])){var l=t[0];t[2]&&t[2].label&&(l=t[2].label);l={content:l,value:t};t[1]==e.EVENT&&(l.className="event");m.push(l)}}this.onMenuNodeOutputs&&(m=this.onMenuNodeOutputs(m));if(m.length)return new e.ContextMenu(m,{event:d,callback:k,parentMenu:c,node:h},a),!1}};f.onShowMenuNodeProperties=function(a,b,d,c,h){function k(a,b,d,e){h&&(b=this.getBoundingClientRect(),n.showEditPropertyValue(h,a.value,{position:[b.left,b.top]}))}if(h&&h.properties){var n=
|
||||
f.active_canvas;b=n.getCanvasWindow();var m=[],g;for(g in h.properties)a=void 0!==h.properties[g]?h.properties[g]:" ","object"==typeof a&&(a=JSON.stringify(a)),a=f.decodeHTML(a),m.push({content:"<span class='property_name'>"+g+"</span><span class='property_value'>"+a+"</span>",value:g});if(m.length)return new e.ContextMenu(m,{event:d,callback:k,parentMenu:c,allow_html:!0,node:h},b),!1}};f.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};f.onResizeNode=function(a,
|
||||
b,d,e,c){c&&(c.size=c.computeSize(),c.setDirtyCanvas(!0,!0))};f.prototype.showLinkMenu=function(a,b){var d=this;console.log(a.data);new e.ContextMenu(["Delete"],{event:b,title:null!=a.data?a.data.constructor.name:null,callback:function(b){switch(b){case "Delete":d.graph.removeLink(a.id)}}});return!1};f.onShowPropertyEditor=function(a,b,d,e,c){function h(){var b=m.value;"Number"==a.type?b=Number(b):"Boolean"==a.type&&(b=Boolean(b));c[k]=b;n.parentNode&&n.parentNode.removeChild(n);c.setDirtyCanvas(!0,
|
||||
!0)}var k=a.property||"title";b=c[k];var n=document.createElement("div");n.className="graphdialog";n.innerHTML="<span class='name'></span><input autofocus type='text' class='value'/><button>OK</button>";n.querySelector(".name").innerText=k;var m=n.querySelector("input");m&&(m.value=b,m.addEventListener("blur",function(a){this.focus()}),m.addEventListener("keydown",function(a){13==a.keyCode&&(h(),a.preventDefault(),a.stopPropagation())}));b=f.active_canvas.canvas;d=b.getBoundingClientRect();var g=
|
||||
e=-20;d&&(e-=d.left,g-=d.top);event?(n.style.left=event.clientX+e+"px",n.style.top=event.clientY+g+"px"):(n.style.left=0.5*b.width+e+"px",n.style.top=0.5*b.height+g+"px");n.querySelector("button").addEventListener("click",h);b.parentNode.appendChild(n)};f.prototype.prompt=function(a,b,d,e){var c=this;a=a||"";var h=!1,k=document.createElement("div");k.className="graphdialog rounded";k.innerHTML="<span class='name'></span> <input autofocus type='text' class='value'/><button class='rounded'>OK</button>";
|
||||
k.close=function(){c.prompt_box=null;k.parentNode&&k.parentNode.removeChild(k)};1<this.ds.scale&&(k.style.transform="scale("+this.ds.scale+")");k.addEventListener("mouseleave",function(a){h||k.close()});c.prompt_box&&c.prompt_box.close();c.prompt_box=k;k.querySelector(".name").innerText=a;k.querySelector(".value").value=b;var n=k.querySelector("input");n.addEventListener("keydown",function(a){h=!0;if(27==a.keyCode)k.close();else if(13==a.keyCode)d&&d(this.value),k.close();else return;a.preventDefault();
|
||||
a.stopPropagation()});k.querySelector("button").addEventListener("click",function(a){d&&d(n.value);c.setDirty(!0);k.close()});a=f.active_canvas.canvas;b=a.getBoundingClientRect();var m=-20,g=-20;b&&(m-=b.left,g-=b.top);e?(k.style.left=e.clientX+m+"px",k.style.top=e.clientY+g+"px"):(k.style.left=0.5*a.width+m+"px",k.style.top=0.5*a.height+g+"px");a.parentNode.appendChild(k);setTimeout(function(){n.focus()},10);return k};f.search_limit=-1;f.prototype.showSearchBox=function(a){function b(b){if(b)if(h.onSearchBoxSelection)h.onSearchBoxSelection(b,
|
||||
a,B);else{var d=e.searchbox_extras[b.toLowerCase()];d&&(b=d.type);if(b=e.createNode(b))b.pos=B.convertEventToCanvasOffset(a),B.graph.add(b);if(d&&d.data){if(d.data.properties)for(var c in d.data.properties)b.addProperty(c,d.data.properties[c]);if(d.data.inputs)for(c in b.inputs=[],d.data.inputs)b.addOutput(d.data.inputs[c][0],d.data.inputs[c][1]);if(d.data.outputs)for(c in b.outputs=[],d.data.outputs)b.addOutput(d.data.outputs[c][0],d.data.outputs[c][1]);d.data.title&&(b.title=d.data.title);d.data.json&&
|
||||
b.configure(d.data.json)}}k.close()}function d(a){var b=l;l&&l.classList.remove("selected");l?(l=a?l.nextSibling:l.previousSibling)||(l=b):l=a?m.childNodes[0]:m.childNodes[m.childNodes.length];l&&(l.classList.add("selected"),l.scrollIntoView())}function c(){function a(d,e){var c=document.createElement("div");g||(g=d);c.innerText=d;c.dataset.type=escape(d);c.className="litegraph lite-search-item";e&&(c.className+=" "+e);c.addEventListener("click",function(a){b(unescape(this.dataset.type))});m.appendChild(c)}
|
||||
t=null;var d=s.value;g=null;m.innerHTML="";if(d)if(h.onSearchBox){var k=h.onSearchBox(m,d,B);if(k)for(var n=0;n<k.length;++n)a(k[n])}else{k=0;d=d.toLowerCase();for(n in e.searchbox_extras){var l=e.searchbox_extras[n];if(-1!==l.desc.toLowerCase().indexOf(d)&&(a(l.desc,"searchbox_extra"),-1!==f.search_limit&&k++>f.search_limit))break}if(Array.prototype.filter)for(l=Object.keys(e.registered_node_types).filter(function(a){return-1!==a.toLowerCase().indexOf(d)}),n=0;n<l.length&&!(a(l[n]),-1!==f.search_limit&&
|
||||
k++>f.search_limit);n++);else for(n in e.registered_node_types)if(-1!=n.indexOf(d)&&(a(n),-1!==f.search_limit&&k++>f.search_limit))break}}var h=this,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(){h.search_box=null;document.body.focus();setTimeout(function(){h.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)});h.search_box&&h.search_box.close();h.search_box=k;var m=k.querySelector(".helper"),g=null,t=null,l=null,s=k.querySelector("input");s&&(s.addEventListener("blur",function(a){this.focus()}),s.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)l?b(l.innerHTML):g?b(g):k.close();else{t&&clearInterval(t);t=setTimeout(c,10);return}a.preventDefault();a.stopPropagation()}));var B=f.active_canvas,w=B.canvas,u=w.getBoundingClientRect(),r=-20,z=-20;u&&(r-=u.left,z-=u.top);a?(k.style.left=a.clientX+r+"px",k.style.top=a.clientY+z+"px"):(k.style.left=0.5*w.width+r+"px",k.style.top=0.5*w.height+z+"px");w.parentNode.appendChild(k);s.focus();return k};f.prototype.showEditPropertyValue=function(a,b,
|
||||
d){function e(){c(l.value)}function c(d){"number"==typeof a.properties[b]&&(d=Number(d));if("array"==h||"object"==h)d=JSON.parse(d);a.properties[b]=d;a._graph&&a._graph._version++;if(a.onPropertyChanged)a.onPropertyChanged(b,d);g.close();a.setDirtyCanvas(!0,!0)}if(a&&void 0!==a.properties[b]){d=d||{};var h="string";null!==a.properties[b]&&(h=typeof a.properties[b]);var k=null;a.getPropertyInfo&&(k=a.getPropertyInfo(b));if(a.properties_info)for(var f=0;f<a.properties_info.length;++f)if(a.properties_info[f].name==
|
||||
b){k=a.properties_info[f];break}void 0!==k&&null!==k&&k.type&&(h=k.type);var n="";if("string"==h||"number"==h||"array"==h||"object"==h)n="<input autofocus type='text' class='value'/>";else if("enum"==h&&k.values){n="<select autofocus type='text' class='value'>";for(f in k.values)var m=k.values.constructor===Array?k.values[f]:f,n=n+("<option value='"+m+"' "+(m==a.properties[b]?"selected":"")+">"+k.values[f]+"</option>");n+="</select>"}else if("boolean"==h)n="<input autofocus type='checkbox' class='value' "+
|
||||
(a.properties[b]?"checked":"")+"/>";else{console.warn("unknown type: "+h);return}var g=this.createDialog("<span class='name'>"+b+"</span>"+n+"<button>OK</button>",d);if("enum"==h&&k.values){var l=g.querySelector("select");l.addEventListener("change",function(a){c(a.target.value)})}else if("boolean"==h)(l=g.querySelector("input"))&&l.addEventListener("click",function(a){c(!!l.checked)});else if(l=g.querySelector("input"))l.addEventListener("blur",function(a){this.focus()}),m=void 0!==a.properties[b]?
|
||||
a.properties[b]:"",m=JSON.stringify(m),l.value=m,l.addEventListener("keydown",function(a){13==a.keyCode&&(e(),a.preventDefault(),a.stopPropagation())});g.querySelector("button").addEventListener("click",e)}};f.prototype.createDialog=function(a,b){b=b||{};var d=document.createElement("div");d.className="graphdialog";d.innerHTML=a;var e=this.canvas.getBoundingClientRect(),c=-20,h=-20;e&&(c-=e.left,h-=e.top);b.position?(c+=b.position[0],h+=b.position[1]):b.event?(c+=b.event.clientX,h+=b.event.clientY):
|
||||
(c+=0.5*this.canvas.width,h+=0.5*this.canvas.height);d.style.left=c+"px";d.style.top=h+"px";this.canvas.parentNode.appendChild(d);d.close=function(){this.parentNode&&this.parentNode.removeChild(this)};return d};f.onMenuNodeCollapse=function(a,b,d,e,c){c.collapse()};f.onMenuNodePin=function(a,b,d,e,c){c.pin()};f.onMenuNodeMode=function(a,b,d,c,h){new e.ContextMenu(["Always","On Event","On Trigger","Never"],{event:d,callback:function(a){if(h)switch(a){case "On Event":h.mode=e.ON_EVENT;break;case "On Trigger":h.mode=
|
||||
e.ON_TRIGGER;break;case "Never":h.mode=e.NEVER;break;default:h.mode=e.ALWAYS}},parentMenu:c,node:h});return!1};f.onMenuNodeColors=function(a,b,d,c,h){if(!h)throw"no node for color";b=[];b.push({value:null,content:"<span style='display: block; padding-left: 4px;'>No color</span>"});for(var k in f.node_colors)a=f.node_colors[k],a={value:k,content:"<span style='display: block; color: #999; padding-left: 4px; border-left: 8px solid "+a.color+"; background-color:"+a.bgcolor+"'>"+k+"</span>"},b.push(a);
|
||||
new e.ContextMenu(b,{event:d,callback:function(a){h&&((a=a.value?f.node_colors[a.value]:null)?h.constructor===e.LGraphGroup?h.color=a.groupcolor:(h.color=a.color,h.bgcolor=a.bgcolor):(delete h.color,delete h.bgcolor),h.setDirtyCanvas(!0,!0))},parentMenu:c,node:h});return!1};f.onMenuNodeShapes=function(a,b,d,c,h){if(!h)throw"no node passed";new e.ContextMenu(e.VALID_SHAPES,{event:d,callback:function(a){h&&(h.shape=a,h.setDirtyCanvas(!0))},parentMenu:c,node:h});return!1};f.onMenuNodeRemove=function(a,
|
||||
b,d,c,e){if(!e)throw"no node passed";!1!==e.removable&&(e.graph.remove(e),e.setDirtyCanvas(!0,!0))};f.onMenuNodeClone=function(a,b,d,e,c){!1!=c.clonable&&(a=c.clone())&&(a.pos=[c.pos[0]+5,c.pos[1]+5],c.graph.add(a),c.setDirtyCanvas(!0,!0))};f.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"}};f.prototype.getCanvasMenuOptions=function(){var a=null;this.getMenuOptions?a=this.getMenuOptions():(a=[{content:"Add Node",has_submenu:!0,callback:f.onMenuAdd},{content:"Add Group",callback:f.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};f.prototype.getNodeMenuOptions=function(a){var b=null,b=a.getMenuOptions?a.getMenuOptions(this):[{content:"Inputs",has_submenu:!0,disabled:!0,callback:f.showMenuNodeOptionalInputs},{content:"Outputs",has_submenu:!0,disabled:!0,callback:f.showMenuNodeOptionalOutputs},null,{content:"Properties",has_submenu:!0,callback:f.onShowMenuNodeProperties},
|
||||
null,{content:"Title",callback:f.onShowPropertyEditor},{content:"Mode",has_submenu:!0,callback:f.onMenuNodeMode},{content:"Resize",callback:f.onResizeNode},{content:"Collapse",callback:f.onMenuNodeCollapse},{content:"Pin",callback:f.onMenuNodePin},{content:"Colors",has_submenu:!0,callback:f.onMenuNodeColors},{content:"Shapes",has_submenu:!0,callback:f.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))&&(d.push(null),b=d.concat(b));!1!==a.clonable&&b.push({content:"Clone",callback:f.onMenuNodeClone});!1!==a.removable&&b.push(null,{content:"Remove",callback:f.onMenuNodeRemove});if(a.graph&&a.graph.onGetNodeMenuOptions)a.graph.onGetNodeMenuOptions(b,a);return b};f.prototype.getGroupMenuOptions=function(a){return[{content:"Title",callback:f.onShowPropertyEditor},{content:"Color",has_submenu:!0,callback:f.onMenuNodeColors},{content:"Font size",
|
||||
property:"font_size",type:"Number",callback:f.onShowPropertyEditor},null,{content:"Remove",callback:f.onMenuNodeRemove}]};f.prototype.processContextMenu=function(a,b){var d=this,c=f.active_canvas.getCanvasWindow(),h=null,k={event:b,callback:function(b,c,e){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 h=b.input?a.getInputInfo(b.slot):a.getOutputInfo(b.slot),k=d.createDialog("<span class='name'>Name</span><input autofocus type='text'/><button>OK</button>",c),f=k.querySelector("input");f&&h&&(f.value=h.label||"");k.querySelector("button").addEventListener("click",function(a){f.value&&(h&&(h.label=f.value),d.setDirty(!0));k.close()})}},extra:a};a&&(k.title=a.type);var n=null;a&&(n=a.getSlotInPosition(b.canvasX,b.canvasY),f.active_node=a);if(n){h=[];n&&n.output&&n.output.links&&
|
||||
n.output.links.length&&h.push({content:"Disconnect Links",slot:n});var m=n.input||n.output;h.push(m.locked?"Cannot remove":{content:"Remove Slot",slot:n});h.push(m.nameLocked?"Cannot rename":{content:"Rename Slot",slot:n});k.title=(n.input?n.input.type:n.output.type)||"*";n.input&&n.input.type==e.ACTION&&(k.title="Action");n.output&&n.output.type==e.EVENT&&(k.title="Event")}else a?h=this.getNodeMenuOptions(a):(h=this.getCanvasMenuOptions(),(n=this.graph.getGroupOnPos(b.canvasX,b.canvasY))&&h.push(null,
|
||||
{content:"Edit Group",has_submenu:!0,submenu:{title:"Group",extra:n,options:this.getGroupMenuOptions(n)}}));h&&new e.ContextMenu(h,k,c)};this.CanvasRenderingContext2D&&(CanvasRenderingContext2D.prototype.roundRect=function(a,b,d,c,e,h){void 0===e&&(e=5);void 0===h&&(h=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+c-h);this.quadraticCurveTo(a+d,b+c,a+d-h,b+c);this.lineTo(a+h,b+c);this.quadraticCurveTo(a,b+c,a,b+c-h);this.lineTo(a,b+e);this.quadraticCurveTo(a,
|
||||
b,a+e,b)});e.compareObjects=function(a,b){for(var d in a)if(a[d]!=b[d])return!1;return!0};e.distance=y;e.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")+")"};e.isInsideRectangle=s;e.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)};e.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};e.overlapBounding=u;e.hex2num=function(a){"#"==a.charAt(0)&&(a=a.slice(1));a=a.toUpperCase();for(var b=Array(3),d=0,c,e,h=0;6>h;h+=2)c="0123456789ABCDEF".indexOf(a.charAt(h)),e="0123456789ABCDEF".indexOf(a.charAt(h+1)),b[d]=16*c+e,d++;return b};e.num2hex=function(a){for(var b="#",d,c,e=0;3>e;e++)d=a[e]/16,c=a[e]%16,b+="0123456789ABCDEF".charAt(d)+"0123456789ABCDEF".charAt(c);return b};z.prototype.addItem=function(a,b,d){function c(a){var b=this.value;b&&b.has_submenu&&e.call(this,a)}function e(a){var b=
|
||||
this.value,c=!0;h.current_submenu&&h.current_submenu.close(a);if(d.callback){var k=d.callback.call(this,b,d,a,h,d.node);!0===k&&(c=!1)}if(b&&(b.callback&&!d.ignore_item_callbacks&&!0!==b.disabled&&(k=b.callback.call(this,b,d,a,h,d.extra),!0===k&&(c=!1)),b.submenu)){if(!b.submenu.options)throw"ContextMenu submenu needs options";new h.constructor(b.submenu.options,{callback:b.submenu.callback,event:a,parentMenu:h,ignore_item_callbacks:b.submenu.ignore_item_callbacks,title:b.submenu.title,extra:b.submenu.extra,
|
||||
autoopen:d.autoopen});c=!1}c&&!h.lock&&h.close()}var h=this;d=d||{};var k=document.createElement("div");k.className="litemenu-entry submenu";var f=!1;if(null===b)k.classList.add("separator");else{k.innerHTML=b&&b.title?b.title:a;if(k.value=b)b.disabled&&(f=!0,k.classList.add("disabled")),(b.submenu||b.has_submenu)&&k.classList.add("has_submenu");"function"==typeof b?(k.dataset.value=a,k.onclick_callback=b):k.dataset.value=b;b.className&&(k.className+=" "+b.className)}this.root.appendChild(k);f||k.addEventListener("click",
|
||||
e);d.autoopen&&k.addEventListener("mouseenter",c);return k};z.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&&!z.isCursorOverElement(a,this.parentMenu.root)&&z.trigger(this.parentMenu.root,"mouseleave",a));this.current_submenu&&this.current_submenu.close(a,!0);this.root.closing_timer&&clearTimeout(this.root.closing_timer)};z.trigger=
|
||||
function(a,b,d,c){var e=document.createEvent("CustomEvent");e.initCustomEvent(b,!0,!0,d);e.srcElement=c;a.dispatchEvent?a.dispatchEvent(e):a.__events&&a.__events.dispatchEvent(e);return e};z.prototype.getTopMenu=function(){return this.options.parentMenu?this.options.parentMenu.getTopMenu():this};z.prototype.getFirstEvent=function(){return this.options.parentMenu?this.options.parentMenu.getFirstEvent():this.options.event};z.isCursorOverElement=function(a,b){var d=a.clientX,c=a.clientY,e=b.getBoundingClientRect();
|
||||
return e?c>e.top&&c<e.top+e.height&&d>e.left&&d<e.left+e.width?!0:!1:!1};e.ContextMenu=z;e.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 in b)b[d].close?b[d].close():b[d].parentNode&&b[d].parentNode.removeChild(b[d])}};e.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)))};e.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(v){function c(){this.addOutput("in ms","number");this.addOutput("in sec","number")}function q(){this.size=[140,80];this.properties={enabled:!0};this.enabled=!0;this.subgraph=new 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 g(){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 l(){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){""!=
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
padding: 0;
|
||||
box-shadow: 0 0 10px black !important;
|
||||
background-color: #2e2e2e !important;
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
.litegraph.litecontextmenu.dark {
|
||||
|
||||
@@ -213,10 +213,6 @@ Editor.prototype.onFullscreenButton = function() {
|
||||
this.goFullscreen();
|
||||
};
|
||||
|
||||
Editor.prototype.onMaximizeButton = function() {
|
||||
this.maximize();
|
||||
};
|
||||
|
||||
Editor.prototype.addMiniWindow = function(w, h) {
|
||||
var miniwindow = document.createElement("div");
|
||||
miniwindow.className = "litegraph miniwindow";
|
||||
|
||||
@@ -10253,7 +10253,11 @@ LGraphNode.prototype.executeAction = function(action)
|
||||
if (!root_document) {
|
||||
root_document = document;
|
||||
}
|
||||
root_document.body.appendChild(root);
|
||||
|
||||
if( root_document.fullscreenElement )
|
||||
root_document.fullscreenElement.appendChild(root);
|
||||
else
|
||||
root_document.body.appendChild(root);
|
||||
|
||||
//compute best position
|
||||
var left = options.left || 0;
|
||||
|
||||
Reference in New Issue
Block a user