diff --git a/build/litegraph.core.js b/build/litegraph.core.js index e322732f0..1aa50702b 100644 --- a/build/litegraph.core.js +++ b/build/litegraph.core.js @@ -98,6 +98,7 @@ catch_exceptions: true, throw_errors: true, allow_scripts: false, //if set to true some nodes like Formula would be allowed to evaluate code that comes from unsafe sources (like node configuration), which could lead to exploits + use_deferred_actions: true, //executes actions during the graph execution flow registered_node_types: {}, //nodetypes by string node_types_by_file_extension: {}, //used for dropping files in the canvas Nodes: {}, //node types by classname @@ -327,6 +328,55 @@ } }, + /** + * Create a new nodetype by passing an object with some properties + * like onCreate, inputs:Array, outputs:Array, properties, onExecute + * @method buildNodeClassFromObject + * @param {String} name node name with namespace (p.e.: 'math/sum') + * @param {Object} object methods expected onCreate, inputs, outputs, properties, onExecute + */ + buildNodeClassFromObject: function( + name, + object + ) { + var ctor_code = ""; + if(object.inputs) + for(var i=0; i < object.inputs.length; ++i) + { + var _name = object.inputs[i][0]; + var _type = object.inputs[i][1]; + if(_type && _type.constructor === String) + _type = '"'+_type+'"'; + ctor_code += "this.addInput('"+_name+"',"+_type+");\n"; + } + if(object.outputs) + for(var i=0; i < object.outputs.length; ++i) + { + var _name = object.outputs[i][0]; + var _type = object.outputs[i][1]; + if(_type && _type.constructor === String) + _type = '"'+_type+'"'; + ctor_code += "this.addOutput('"+_name+"',"+_type+");\n"; + } + if(object.properties) + for(var i in object.properties) + { + var prop = object.properties[i]; + if(prop && prop.constructor === String) + prop = '"'+prop+'"'; + ctor_code += "this.addProperty('"+i+"',"+prop+");\n"; + } + ctor_code += "if(this.onCreate)this.onCreate()"; + var classobj = Function(ctor_code); + for(var i in object) + if(i!="inputs" && i!="outputs" && i!="properties") + classobj.prototype[i] = object[i]; + classobj.title = object.title || name.split("/").pop(); + classobj.desc = object.desc || "Generated from object"; + this.registerNodeType(name, classobj); + return classobj; + }, + /** * Create a new nodetype by passing a function, it wraps it with a proper class and generates inputs according to the parameters of the function. * Useful to wrap simple methods that do not require properties, and that only process some input to generate an output. @@ -346,20 +396,31 @@ ) { var params = Array(func.length); var code = ""; - var names = LiteGraph.getParameterNames(func); - for (var i = 0; i < names.length; ++i) { - code += - "this.addInput('" + - names[i] + - "'," + - (param_types && param_types[i] - ? "'" + param_types[i] + "'" - : "0") + - ");\n"; + if(param_types !== null) //null means no inputs + { + var names = LiteGraph.getParameterNames(func); + for (var i = 0; i < names.length; ++i) { + var type = 0; + if(param_types) + { + //type = param_types[i] != null ? "'" + param_types[i] + "'" : "0"; + if( param_types[i] != null && param_types[i].constructor === String ) + type = "'" + param_types[i] + "'" ; + else if( param_types[i] != null ) + type = param_types[i]; + } + code += + "this.addInput('" + + names[i] + + "'," + + type + + ");\n"; + } } + if(return_type !== null) //null means no output code += "this.addOutput('out'," + - (return_type ? "'" + return_type + "'" : 0) + + (return_type != null ? (return_type.constructor === String ? "'" + return_type + "'" : return_type) : 0) + ");\n"; if (properties) { code += @@ -376,6 +437,7 @@ this.setOutputData(0, r); }; this.registerNodeType(name, classobj); + return classobj; }, /** @@ -3142,6 +3204,13 @@ // enable this to give the event an ID if (!options.action_call) options.action_call = this.id+"_exec_"+Math.floor(Math.random()*9999); + if(this._waiting_actions && this._waiting_actions.length) + for(var i = 0; i < this._waiting_actions.length;++i) + { + var p = this._waiting_actions[i]; + this.onAction(p[0],p[1],p[2],p[3],p[4]); + } + this.graph.nodes_executing[this.id] = true; //.push(this.id); this.onExecute(param, options); @@ -3155,6 +3224,14 @@ this.graph.nodes_executedAction[this.id] = options.action_call; } } + else { + if(this._waiting_actions && this._waiting_actions.length) + for(var i = 0; i < this._waiting_actions.length;++i) + { + var p = this._waiting_actions[i]; + this.onAction(p[0],p[1],p[2],p[3],p[4]); + } + } this.execute_triggered = 2; // the nFrames it will be used (-- each step), means "how old" is the event if(this.onAfterExecuteNode) this.onAfterExecuteNode(param, options); // callback }; @@ -3165,7 +3242,7 @@ * @param {String} action name * @param {*} param */ - LGraphNode.prototype.actionDo = function(action, param, options) { + LGraphNode.prototype.actionDo = function(action, param, options, action_slot ) { options = options || {}; if (this.onAction){ @@ -3174,7 +3251,7 @@ this.graph.nodes_actioning[this.id] = (action?action:"actioning"); //.push(this.id); - this.onAction(action, param, options); + this.onAction(action, param, options, action_slot); this.graph.nodes_actioning[this.id] = false; //.pop(); @@ -3282,8 +3359,19 @@ if (!options.action_call) options.action_call = this.id+"_act_"+Math.floor(Math.random()*9999); //pass the action name var target_connection = node.inputs[link_info.target_slot]; - // wrap node.onAction(target_connection.name, param); - node.actionDo(target_connection.name, param, options); + + //instead of executing them now, it will be executed in the next graph loop, to ensure data flow + if(LiteGraph.use_deferred_actions) + { + if(!node._waiting_actions) + node._waiting_actions = []; + node._waiting_actions.push([target_connection.name, param, options, link_info.target_slot]); + } + else + { + // wrap node.onAction(target_connection.name, param); + node.actionDo( target_connection.name, param, options, link_info.target_slot ); + } } } }; @@ -5646,7 +5734,7 @@ LGraphNode.prototype.executeAction = function(action) //Keyboard ****************** this._key_callback = this.processKey.bind(this); - + canvas.setAttribute("tabindex",1); //otherwise key events are ignored canvas.addEventListener("keydown", this._key_callback, true); document.addEventListener("keyup", this._key_callback, true); //in document, otherwise it doesn't fire keyup @@ -7150,6 +7238,8 @@ LGraphNode.prototype.executeAction = function(action) for (var i = 0; i < selected_nodes_array.length; ++i) { var node = selected_nodes_array[i]; + if(node.clonable === false) + continue; var cloned = node.clone(); if(!cloned) { @@ -11540,6 +11630,7 @@ LGraphNode.prototype.executeAction = function(action) //ESC dialog.close(); } else if (e.keyCode == 13) { + refreshHelper(); if (selected) { select(selected.innerHTML); } else if (first) { diff --git a/build/litegraph.core.min.js b/build/litegraph.core.min.js index 61708287d..85dd5b452 100644 --- a/build/litegraph.core.min.js +++ b/build/litegraph.core.min.js @@ -1,353 +1,342 @@ -var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.ASSUME_ES5=!1;$jscomp.ASSUME_NO_NATIVE_MAP=!1;$jscomp.ASSUME_NO_NATIVE_SET=!1;$jscomp.defineProperty=$jscomp.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(t,r,w){t!=Array.prototype&&t!=Object.prototype&&(t[r]=w.value)};$jscomp.getGlobal=function(t){return"undefined"!=typeof window&&window===t?t:"undefined"!=typeof global&&null!=global?global:t};$jscomp.global=$jscomp.getGlobal(this);$jscomp.SYMBOL_PREFIX="jscomp_symbol_"; -$jscomp.initSymbol=function(){$jscomp.initSymbol=function(){};$jscomp.global.Symbol||($jscomp.global.Symbol=$jscomp.Symbol)};$jscomp.Symbol=function(){var t=0;return function(r){return $jscomp.SYMBOL_PREFIX+(r||"")+t++}}(); -$jscomp.initSymbolIterator=function(){$jscomp.initSymbol();var t=$jscomp.global.Symbol.iterator;t||(t=$jscomp.global.Symbol.iterator=$jscomp.global.Symbol("iterator"));"function"!=typeof Array.prototype[t]&&$jscomp.defineProperty(Array.prototype,t,{configurable:!0,writable:!0,value:function(){return $jscomp.arrayIterator(this)}});$jscomp.initSymbolIterator=function(){}};$jscomp.arrayIterator=function(t){var r=0;return $jscomp.iteratorPrototype(function(){return rt&&(t=Math.max(0,w+t));if(null==m||m>w)m=w;m=Number(m);0>m&&(m=Math.max(0,w+m));for(t=Number(t||0);t=y}},"es6","es3");$jscomp.findInternal=function(t,r,w){t instanceof String&&(t=String(t));for(var m=t.length,B=0;Ba&&eb?!0:!1}function H(a,b){var c=a[0]+a[2],e=a[1]+a[3],d=b[1]+b[3];return a[0]>b[0]+b[2]||a[1]>d||ch.width-k.width-10&&(d=h.width-k.width-10),h.height&&a>h.height-k.height-10&&(a=h.height-k.height-10));f.style.left=d+"px";f.style.top=a+"px";b.scale&&(f.style.transform="scale("+b.scale+")")}function G(a){this.points=a;this.nearest=this.selected=-1;this.size=null;this.must_update=!0;this.margin=5}function K(a,b,c){return b>a?b:ca&&db?!0:!1}function Z(a,b){var c=a[0]+a[2],d=a[1]+a[3],e=b[1]+b[3];return a[0]>b[0]+b[2]||a[1]>e||cg.width-k.width-10&&(e=g.width-k.width-10),g.height&&a>g.height-k.height-10&&(a=g.height-k.height-10));f.style.left=e+"px";f.style.top=a+"px";b.scale&&(f.style.transform="scale("+b.scale+")")}function T(a){this.points=a;this.nearest=this.selected=-1;this.size=null;this.must_update=!0;this.margin=5}function ca(a,b,c){return b>a?b:c>a/4).toString(16)})},isValidConnection:function(a, -b){if(""==a||"*"===a)a=0;if(""==b||"*"===b)b=0;if(!a||!b||a==b||a==g.EVENT&&b==g.ACTION)return!0;a=String(a);b=String(b);a=a.toLowerCase();b=b.toLowerCase();if(-1==a.indexOf(",")&&-1==b.indexOf(","))return a==b;a=a.split(",");b=b.split(",");for(var c=0;ch&&(h=n.size[p]);k+=n.size[b==g.VERTICAL_LAYOUT?0:1]+a+g.NODE_TITLE_HEIGHT}c+=h+a}this.setDirtyCanvas(!0,!0)};r.prototype.getTime=function(){return this.globaltime};r.prototype.getFixedTime=function(){return this.fixedtime};r.prototype.getElapsedTime=function(){return this.elapsed_time};r.prototype.sendEventToAllNodes=function(a, -b,c){c=c||g.ALWAYS;var e=this._nodes_in_order?this._nodes_in_order:this._nodes;if(e)for(var d=0,f=e.length;d=g.MAX_NUMBER_OF_NODES)throw"LiteGraph: max number of nodes in a graph reached";if(g.use_uuids){if(null==a.id||-1==a.id)a.id=g.uuidv4()}else null==a.id||-1==a.id? -a.id=++this.last_node_id:this.last_node_ida.length||(this._pos[0]=a[0],this._pos[1]=a[1])},get:function(){return this._pos},enumerable:!0});this.id=g.use_uuids?g.uuidv4():-1;this.type=null;this.inputs=[];this.outputs=[];this.connections=[];this.properties={};this.properties_info=[];this.flags={}};m.prototype.configure=function(a){this.graph&& -this.graph._version++;for(var b in a)if("properties"==b)for(var c in a.properties){if(this.properties[c]=a.properties[c],this.onPropertyChanged)this.onPropertyChanged(c,a.properties[c])}else null!=a[b]&&("object"==typeof a[b]?this[b]&&this[b].configure?this[b].configure(a[b]):this[b]=g.cloneObject(a[b],this[b]):this[b]=a[b]);a.title||(this.title=this.constructor.title);if(this.inputs)for(c=0;c=this.outputs.length)){var c=this.outputs[a];if(c&&(c._data=b,this.outputs[a].links))for(c=0;c=this.outputs.length)){var c=this.outputs[a];if(c&&(c.type=b,this.outputs[a].links))for(c=0;c=this.inputs.length||null==this.inputs[a].link)){a=this.graph.links[this.inputs[a].link];if(!a)return null;if(!b)return a.data;b=this.graph.getNodeById(a.origin_id);if(!b)return a.data;if(b.updateOutputData)b.updateOutputData(a.origin_slot);else if(b.onExecute)b.onExecute();return a.data}};m.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};m.prototype.getInputDataByName=function(a,b){a=this.findInputSlot(a);return-1==a?null:this.getInputData(a,b)};m.prototype.isInputConnected=function(a){return 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};m.prototype.getInputOrProperty=function(a){if(!this.inputs||!this.inputs.length)return this.properties?this.properties[a]:null;for(var b=0,c=this.inputs.length;b=this.outputs.length?null:this.outputs[a]._data};m.prototype.getOutputInfo=function(a){return this.outputs?a=this.outputs.length)return null;a=this.outputs[a];if(!a.links||0==a.links.length)return null;for(var b=[],c=0;ca&&this.pos[1]-d-cb)return!0;return!1};m.prototype.getSlotInPosition=function(a,b){var c=new Float32Array(2);if(this.inputs)for(var e=0,d=this.inputs.length;e=this.outputs.length)return g.debug&&console.log("Connect: Error, slot number not found"),null;b&&b.constructor=== -Number&&(b=this.graph.getNodeById(b));if(!b)throw"target node is null";if(b==this)return null;if(c.constructor===String){if(c=b.findInputSlot(c),-1==c)return g.debug&&console.log("Connect: Error, no slot of name "+c),null}else if(c===g.EVENT)if(g.do_add_triggers_slots)b.changeMode(g.ON_TRIGGER),c=b.findInputSlot("onTrigger");else return null;else if(!b.inputs||c>=b.inputs.length)return g.debug&&console.log("Connect: Error, slot number not found"),null;var e=b.inputs[c],d=this.outputs[a];if(!this.outputs[a])return null; -b.onBeforeConnectInput&&(c=b.onBeforeConnectInput(c));if(!1===c||null===c||!g.isValidConnection(d.type,e.type))return this.setDirtyCanvas(!1,!0),null;if(b.onConnectInput&&!1===b.onConnectInput(c,d.type,d,this,a)||this.onConnectOutput&&!1===this.onConnectOutput(a,e.type,e,b,c))return null;b.inputs[c]&&null!=b.inputs[c].link&&(this.graph.beforeChange(),b.disconnectInput(c,{doProcessChange:!1}));if(null!==d.links&&d.links.length)switch(d.type){case g.EVENT:g.allow_multi_output_for_events||(this.graph.beforeChange(), -this.disconnectOutput(a,!1,{doProcessChange:!1}))}var f=g.use_uuids?g.uuidv4():++this.graph.last_link_id;f=new w(f,e.type||d.type,this.id,a,b.id,c);this.graph.links[f.id]=f;null==d.links&&(d.links=[]);d.links.push(f.id);b.inputs[c].link=f.id;this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(g.OUTPUT,a,!0,f,d);if(b.onConnectionsChange)b.onConnectionsChange(g.INPUT,c,!0,f,e);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(g.INPUT, -b,c,this,a),this.graph.onNodeConnectionChange(g.OUTPUT,this,a,b,c));this.setDirtyCanvas(!1,!0);this.graph.afterChange();this.graph.connectionChange(this,f);return f};m.prototype.disconnectOutput=function(a,b){if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return g.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.outputs||a>=this.outputs.length)return g.debug&&console.log("Connect: Error, slot number not found"),!1;var c=this.outputs[a];if(!c||!c.links||0==c.links.length)return!1; -if(b){b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"Target Node not found";for(var e=0,d=c.links.length;e=this.inputs.length)return g.debug&&console.log("Connect: Error, slot number not found"),!1;var b=this.inputs[a];if(!b)return!1;var c=this.inputs[a].link;if(null!=c){this.inputs[a].link=null;var e=this.graph.links[c];if(e){var d=this.graph.getNodeById(e.origin_id);if(!d)return!1;var f=d.outputs[e.origin_slot];if(!f||!f.links||0==f.links.length)return!1;for(var h=0,k=f.links.length;hb&&this.inputs[b].pos)return c[0]=this.pos[0]+this.inputs[b].pos[0],c[1]=this.pos[1]+ -this.inputs[b].pos[1],c;if(!a&&e>b&&this.outputs[b].pos)return c[0]=this.pos[0]+this.outputs[b].pos[0],c[1]=this.pos[1]+this.outputs[b].pos[1],c;if(this.horizontal)return c[0]=this.pos[0]+this.size[0]/e*(b+.5),c[1]=a?this.pos[1]-g.NODE_TITLE_HEIGHT:this.pos[1]+this.size[1],c;c[0]=a?this.pos[0]+d:this.pos[0]+this.size[0]+1-d;c[1]=this.pos[1]+(b+.7)*g.NODE_SLOT_HEIGHT+(this.constructor.slot_start_y||0);return c};m.prototype.alignToGrid=function(){this.pos[0]=g.CANVAS_GRID_SIZE*Math.round(this.pos[0]/ -g.CANVAS_GRID_SIZE);this.pos[1]=g.CANVAS_GRID_SIZE*Math.round(this.pos[1]/g.CANVAS_GRID_SIZE)};m.prototype.trace=function(a){this.console||(this.console=[]);this.console.push(a);this.console.length>m.MAX_CONSOLE&&this.console.shift();if(this.graph.onNodeTrace)this.graph.onNodeTrace(this,a)};m.prototype.setDirtyCanvas=function(a,b){this.graph&&this.graph.sendActionToCanvas("setDirty",[a,b])};m.prototype.loadImage=function(a){var b=new Image;b.src=g.node_images_path+a;b.ready=!1;var c=this;b.onload= -function(){this.ready=!0;c.setDirtyCanvas(!0)};return b};m.prototype.captureInput=function(a){if(this.graph&&this.graph.list_of_graphcanvas)for(var b=this.graph.list_of_graphcanvas,c=0;ca.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})};B.prototype.configure=function(a){this.title=a.title;this._bounding.set(a.bounding);this.color=a.color;this.font_size=a.font_size};B.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_size:this.font_size}};B.prototype.move=function(a,b,c){this._pos[0]+=a;this._pos[1]+=b;if(!c)for(c=0;c=this.viewport[0]&&e=this.viewport[1]&&cthis.max_scale&&(a=this.max_scale);if(a!=this.scale&&this.element){var c=this.element.getBoundingClientRect();if(c&&(b= -b||[.5*c.width,.5*c.height],c=this.convertCanvasToOffset(b),this.scale=a,.01>Math.abs(this.scale-1)&&(this.scale=1),a=this.convertCanvasToOffset(b),a=[a[0]-c[0],a[1]-c[1]],this.offset[0]+=a[0],this.offset[1]+=a[1],this.onredraw))this.onredraw(this)}};y.prototype.changeDeltaScale=function(a,b){this.changeScale(this.scale*a,b)};y.prototype.reset=function(){this.scale=1;this.offset[0]=0;this.offset[1]=0};t.LGraphCanvas=g.LGraphCanvas=l;l.DEFAULT_BACKGROUND_IMAGE="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQBJREFUeNrs1rEKwjAUhlETUkj3vP9rdmr1Ysammk2w5wdxuLgcMHyptfawuZX4pJSWZTnfnu/lnIe/jNNxHHGNn//HNbbv+4dr6V+11uF527arU7+u63qfa/bnmh8sWLBgwYJlqRf8MEptXPBXJXa37BSl3ixYsGDBMliwFLyCV/DeLIMFCxYsWLBMwSt4Be/NggXLYMGCBUvBK3iNruC9WbBgwYJlsGApeAWv4L1ZBgsWLFiwYJmCV/AK3psFC5bBggULloJX8BpdwXuzYMGCBctgwVLwCl7Be7MMFixYsGDBsu8FH1FaSmExVfAxBa/gvVmwYMGCZbBg/W4vAQYA5tRF9QYlv/QAAAAASUVORK5CYII="; -l.link_type_colors={"-1":g.EVENT_LINK_COLOR,number:"#AAA",node:"#DCA"};l.gradients={};l.prototype.clear=function(){this.fps=this.render_time=this.last_draw_time=this.frame=0;this.dragging_rectangle=null;this.selected_nodes={};this.selected_group=null;this.visible_nodes=[];this.connecting_node=this.node_capturing_input=this.node_over=this.node_dragged=null;this.highlighted_links={};this.dragging_canvas=!1;this.dirty_bgcanvas=this.dirty_canvas=!0;this.node_widget=this.node_in_panel=this.dirty_area= -null;this.last_mouse=[0,0];this.last_mouseclick=0;this.pointer_is_double=this.pointer_is_down=!1;this.visible_area.set([0,0,0,0]);if(this.onClear)this.onClear()};l.prototype.setGraph=function(a,b){this.graph!=a&&(b||this.clear(),!a&&this.graph?this.graph.detachCanvas(this):(a.attachCanvas(this),this._graph_stack&&(this._graph_stack=null),this.setDirty(!0,!0)))};l.prototype.getTopGraph=function(){return this._graph_stack.length?this._graph_stack[0]:this.graph};l.prototype.openSubgraph=function(a){if(!a)throw"graph cannot be null"; -if(this.graph==a)throw"graph cannot be the same";this.clear();this.graph&&(this._graph_stack||(this._graph_stack=[]),this._graph_stack.push(this.graph));a.attachCanvas(this);this.checkPanels();this.setDirty(!0,!0)};l.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]));this.ds.offset= -[0,0];this.ds.scale=1}};l.prototype.getCurrentGraph=function(){return this.graph};l.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 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());b||this.bindEvents()}};l.prototype._doNothing=function(a){a.preventDefault();return!1};l.prototype._doReturnTrue=function(a){a.preventDefault(); -return!0};l.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);this._mousemove_callback=this.processMouseMove.bind(this);this._mouseup_callback=this.processMouseUp.bind(this);g.pointerListenerAdd(a,"down",this._mousedown_callback,!0);a.addEventListener("mousewheel",this._mousewheel_callback, -!1);g.pointerListenerAdd(a,"up",this._mouseup_callback,!0);g.pointerListenerAdd(a,"move",this._mousemove_callback);a.addEventListener("contextmenu",this._doNothing);a.addEventListener("DOMMouseScroll",this._mousewheel_callback,!1);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}};l.prototype.unbindEvents=function(){if(this._events_binded){var a=this.getCanvasWindow().document;g.pointerListenerRemove(this.canvas,"move",this._mousedown_callback);g.pointerListenerRemove(this.canvas,"up",this._mousedown_callback);g.pointerListenerRemove(this.canvas,"down",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._ondrop_callback=this._key_callback=this._mousewheel_callback=this._mousedown_callback=null;this._events_binded=!1}else console.warn("LGraphCanvas: no events binded")}; -l.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()};l.prototype.enableWebGL=function(){if("undefined"===typeof GL)throw"litegl.js must be included to use a WebGL canvas";if("undefined"===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}; -l.prototype.setDirty=function(a,b){a&&(this.dirty_canvas=!0);b&&(this.dirty_bgcanvas=!0)};l.prototype.getCanvasWindow=function(){if(!this.canvas)return window;var a=this.canvas.ownerDocument;return a.defaultView||a.parentWindow};l.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))};l.prototype.stopRendering=function(){this.is_rendering= -!1};l.prototype.blockClick=function(){this.block_click=!0;this.last_mouseclick=0};l.prototype.processMouseDown=function(a){this.set_canvas_dirty_on_mouse_event&&(this.dirty_canvas=!0);if(this.graph){this.adjustMouseEvent(a);var b=this.getCanvasWindow();l.active_canvas=this;var c=this,e=a.clientX,d=a.clientY;this.ds.viewport=this.viewport;e=!this.viewport||this.viewport&&e>=this.viewport[0]&&e=this.viewport[1]&&dd-this.last_mouseclick&&h;this.mouse[0]=a.clientX;this.mouse[1]=a.clientY;this.graph_mouse[0]=a.canvasX;this.graph_mouse[1]=a.canvasY;this.last_click_position= -[this.mouse[0],this.mouse[1]];this.pointer_is_double=this.pointer_is_down&&h?!0:!1;this.pointer_is_down=!0;this.canvas.focus();g.closeAllContextMenus(b);if(!this.onMouse||1!=this.onMouse(a)){if(1!=a.which||this.pointer_is_double)if(2==a.which)if(g.middle_click_slot_add_default_node){if(f&&this.allow_interaction&&!e&&!this.read_only&&!this.connecting_node&&!f.flags.collapsed&&!this.live_mode){d=e=h=!1;if(f.outputs)for(p=0,k=f.outputs.length;pf.size[0]-g.NODE_TITLE_HEIGHT&& -0>k[1]&&(c=this,setTimeout(function(){c.openSubgraph(f.subgraph)},10)),this.live_mode&&(p=h=!0));p?f.is_selected||this.processNodeSelected(f,a):(this.allow_dragnodes&&(this.graph.beforeChange(),this.node_dragged=f),this.processNodeSelected(f,a));this.dirty_canvas=!0}}else if(!e){if(!this.read_only)for(p=0;pk[0]+4||a.canvasYk[1]+4)){this.showLinkMenu(h,a);this.over_link_center=null; -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>J([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());d&&!this.read_only&&this.allow_searchbox&&(this.showSearchBox(a),a.preventDefault(),a.stopPropagation()); -h=!0}!e&&h&&this.allow_dragcanvas&&(this.dragging_canvas=!0)}this.last_mouse[0]=a.clientX;this.last_mouse[1]=a.clientY;this.last_mouseclick=g.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}}}};l.prototype.processMouseMove=function(a){this.autoresize&&this.resize(); -this.set_canvas_dirty_on_mouse_event&&(this.dirty_canvas=!0);if(this.graph){l.active_canvas=this;this.adjustMouseEvent(a);var b=[a.clientX,a.clientY];this.mouse[0]=b[0];this.mouse[1]=b[1];var c=[b[0]-this.last_mouse[0],b[1]-this.last_mouse[1]];this.last_mouse=b;this.graph_mouse[0]=a.canvasX;this.graph_mouse[1]=a.canvasY;if(this.block_click)return a.preventDefault(),!1;a.dragging=this.last_mouse_dragging;this.node_widget&&(this.processNodeWidgets(this.node_widget[0],this.graph_mouse,a,this.node_widget[1]), -this.dirty_canvas=!0);var e=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes);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(c[0]/this.ds.scale,c[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]+=c[0]/this.ds.scale,this.ds.offset[1]+=c[1]/this.ds.scale,this.dirty_bgcanvas=this.dirty_canvas=!0;else if((this.allow_interaction||e&&e.flags.allow_interaction)&&!this.read_only){this.connecting_node&&(this.dirty_canvas=!0);b=0;for(var d=this.graph._nodes.length;bh[0]+4||a.canvasYh[1]+4)){d=f;break}d!=this.over_link_center&&(this.over_link_center=d,this.dirty_canvas=!0);this.canvas&&(this.canvas.style.cursor="")}if(this.node_capturing_input&& -this.node_capturing_input!=e&&this.node_capturing_input.onMouseMove)this.node_capturing_input.onMouseMove(a,[a.canvasX-this.node_capturing_input.pos[0],a.canvasY-this.node_capturing_input.pos[1]],this);if(this.node_dragged&&!this.live_mode){for(b in this.selected_nodes)e=this.selected_nodes[b],e.pos[0]+=c[0]/this.ds.scale,e.pos[1]+=c[1]/this.ds.scale,e.is_selected||this.processNodeSelected(e,a);this.dirty_bgcanvas=this.dirty_canvas=!0}this.resizing_node&&!this.live_mode&&(c=[a.canvasX-this.resizing_node.pos[0], -a.canvasY-this.resizing_node.pos[1]],b=this.resizing_node.computeSize(),c[0]=Math.max(b[0],c[0]),c[1]=Math.max(b[1],c[1]),this.resizing_node.setSize(c),this.canvas.style.cursor="se-resize",this.dirty_bgcanvas=this.dirty_canvas=!0)}a.preventDefault();return!1}};l.prototype.processMouseUp=function(a){var b=void 0===a.isPrimary||a.isPrimary;if(!b)return!1;this.set_canvas_dirty_on_mouse_event&&(this.dirty_canvas=!0);if(this.graph){var c=this.getCanvasWindow().document;l.active_canvas=this;this.options.skip_events|| -(g.pointerListenerRemove(c,"move",this._mousemove_callback,!0),g.pointerListenerAdd(this.canvas,"move",this._mousemove_callback,!0),g.pointerListenerRemove(c,"up",this._mouseup_callback,!0));this.adjustMouseEvent(a);c=g.getTime();a.click_time=c-this.last_mouseclick;this.last_mouse_dragging=!1;this.last_click_position=null;this.block_click&&(this.block_click=!1);if(1==a.which){this.node_widget&&this.processNodeWidgets(this.node_widget[0],this.graph_mouse,a);this.node_widget=null;this.selected_group&& -(this.selected_group.move(this.selected_group.pos[0]-Math.round(this.selected_group.pos[0]),this.selected_group.pos[1]-Math.round(this.selected_group.pos[1]),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;var e=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes);if(this.dragging_rectangle){if(this.graph){c= -this.graph._nodes;var d=new Float32Array(4),f=Math.abs(this.dragging_rectangle[2]),h=Math.abs(this.dragging_rectangle[3]),k=0>this.dragging_rectangle[3]?this.dragging_rectangle[1]-h:this.dragging_rectangle[1];this.dragging_rectangle[0]=0>this.dragging_rectangle[2]?this.dragging_rectangle[0]-f:this.dragging_rectangle[0];this.dragging_rectangle[1]=k;this.dragging_rectangle[2]=f;this.dragging_rectangle[3]=h;if(!e||10a.click_time&&C(a.canvasX,a.canvasY,e.pos[0],e.pos[1]-g.NODE_TITLE_HEIGHT,g.NODE_TITLE_HEIGHT,g.NODE_TITLE_HEIGHT)&&e.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.align_to_grid)&&this.node_dragged.alignToGrid();if(this.onNodeMoved)this.onNodeMoved(this.node_dragged);this.graph.afterChange(this.node_dragged); -this.node_dragged=null}else{e=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes);!e&&300>a.click_time&&this.deselectAllNodes();this.dirty_canvas=!0;this.dragging_canvas=!1;if(this.node_over&&this.node_over.onMouseUp)this.node_over.onMouseUp(a,[a.canvasX-this.node_over.pos[0],a.canvasY-this.node_over.pos[1]],this);if(this.node_capturing_input&&this.node_capturing_input.onMouseUp)this.node_capturing_input.onMouseUp(a,[a.canvasX-this.node_capturing_input.pos[0],a.canvasY-this.node_capturing_input.pos[1]])}}else 2== -a.which?(this.dirty_canvas=!0,this.dragging_canvas=!1):3==a.which&&(this.dirty_canvas=!0,this.dragging_canvas=!1);b&&(this.pointer_is_double=this.pointer_is_down=!1);this.graph.change();a.stopPropagation();a.preventDefault();return!1}};l.prototype.processMouseWheel=function(a){if(this.graph&&this.allow_dragcanvas){var b=null!=a.wheelDeltaY?a.wheelDeltaY:-60*a.detail;this.adjustMouseEvent(a);var c=a.clientX,e=a.clientY;if(!this.viewport||this.viewport&&c>=this.viewport[0]&&c=this.viewport[1]&&eb&&(c*=1/1.1),this.ds.changeScale(c,[a.clientX,a.clientY]),this.graph.change(),a.preventDefault(),!1}};l.prototype.isOverNodeBox=function(a,b,c){var e=g.NODE_TITLE_HEIGHT;return C(b,c,a.pos[0]+2,a.pos[1]+2-e,e-4,e-4)?!0:!1};l.prototype.isOverNodeInput=function(a,b,c,e){if(a.inputs)for(var d=0,f=a.inputs.length;d(a^16*Math.random()>>a/4).toString(16))},isValidConnection:function(a,b){if(""==a||"*"===a)a=0;if(""==b||"*"===b)b=0;if(!a||!b||a==b||a==h.EVENT&& +b==h.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;a=a.split(",");b=b.split(",");for(var c=0;cg&&(g=l.size[n]);k+=l.size[b==h.VERTICAL_LAYOUT?0:1]+a+h.NODE_TITLE_HEIGHT}c+=g+a}this.setDirtyCanvas(!0,!0)};w.prototype.getTime=function(){return this.globaltime};w.prototype.getFixedTime=function(){return this.fixedtime};w.prototype.getElapsedTime=function(){return this.elapsed_time};w.prototype.sendEventToAllNodes=function(a,b,c){c=c||h.ALWAYS;var d=this._nodes_in_order?this._nodes_in_order:this._nodes;if(d)for(var e=0,f=d.length;e< +f;++e){var g=d[e];if(g.constructor===h.Subgraph&&"onExecute"!=a)g.mode==c&&g.sendEventToAllNodes(a,b,c);else if(g[a]&&g.mode==c)if(void 0===b)g[a]();else if(b&&b.constructor===Array)g[a].apply(g,b);else g[a](b)}};w.prototype.sendActionToCanvas=function(a,b){if(this.list_of_graphcanvas)for(var c=0;c=h.MAX_NUMBER_OF_NODES)throw"LiteGraph: max number of nodes in a graph reached";if(h.use_uuids){if(null==a.id||-1==a.id)a.id=h.uuidv4()}else null==a.id||-1==a.id?a.id=++this.last_node_id:this.last_node_idb.length||(this._pos[0]=b[0],this._pos[1]=b[1])},get:function(){return this._pos},enumerable:!0});this.id=h.use_uuids?h.uuidv4():-1;this.type=null;this.inputs=[];this.outputs=[];this.connections=[];this.properties={};this.properties_info=[];this.flags={}};v.prototype.configure=function(a){this.graph&& +this.graph._version++;for(var b in a)if("properties"==b)for(var c in a.properties){if(this.properties[c]=a.properties[c],this.onPropertyChanged)this.onPropertyChanged(c,a.properties[c])}else null!=a[b]&&("object"==typeof a[b]?this[b]&&this[b].configure?this[b].configure(a[b]):this[b]=h.cloneObject(a[b],this[b]):this[b]=a[b]);a.title||(this.title=this.constructor.title);if(this.inputs)for(c=0;c=this.outputs.length)){var c=this.outputs[a];if(c&&(c._data=b,this.outputs[a].links))for(c=0;c=this.outputs.length)){var c=this.outputs[a];if(c&&(c.type=b,this.outputs[a].links))for(c=0;c=this.inputs.length||null==this.inputs[a].link)){a=this.graph.links[this.inputs[a].link];if(!a)return null;if(!b)return a.data;b=this.graph.getNodeById(a.origin_id);if(!b)return a.data;if(b.updateOutputData)b.updateOutputData(a.origin_slot);else if(b.onExecute)b.onExecute();return a.data}};v.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};v.prototype.getInputDataByName=function(a,b){a=this.findInputSlot(a);return-1==a?null:this.getInputData(a,b)};v.prototype.isInputConnected=function(a){return 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};v.prototype.getInputOrProperty=function(a){if(!this.inputs||!this.inputs.length)return this.properties?this.properties[a]:null;for(var b=0,c=this.inputs.length;b=this.outputs.length?null:this.outputs[a]._data};v.prototype.getOutputInfo=function(a){return this.outputs?a=this.outputs.length)return null;a=this.outputs[a];if(!a.links||0==a.links.length)return null;for(var b=[],c=0;ca&&this.pos[1]-e-cb)return!0;return!1};v.prototype.getSlotInPosition=function(a,b){var c=new Float32Array(2);if(this.inputs)for(var d=0,e=this.inputs.length;d=this.outputs.length)return h.debug&&console.log("Connect: Error, slot number not found"),null;b&&b.constructor=== +Number&&(b=this.graph.getNodeById(b));if(!b)throw"target node is null";if(b==this)return null;if(c.constructor===String){if(c=b.findInputSlot(c),-1==c)return h.debug&&console.log("Connect: Error, no slot of name "+c),null}else if(c===h.EVENT)if(h.do_add_triggers_slots)b.changeMode(h.ON_TRIGGER),c=b.findInputSlot("onTrigger");else return null;else if(!b.inputs||c>=b.inputs.length)return h.debug&&console.log("Connect: Error, slot number not found"),null;var d=b.inputs[c],e=this.outputs[a];if(!this.outputs[a])return null; +b.onBeforeConnectInput&&(c=b.onBeforeConnectInput(c));if(!1===c||null===c||!h.isValidConnection(e.type,d.type))return this.setDirtyCanvas(!1,!0),null;if(b.onConnectInput&&!1===b.onConnectInput(c,e.type,e,this,a)||this.onConnectOutput&&!1===this.onConnectOutput(a,d.type,d,b,c))return null;b.inputs[c]&&null!=b.inputs[c].link&&(this.graph.beforeChange(),b.disconnectInput(c,{doProcessChange:!1}));if(null!==e.links&&e.links.length)switch(e.type){case h.EVENT:h.allow_multi_output_for_events||(this.graph.beforeChange(), +this.disconnectOutput(a,!1,{doProcessChange:!1}))}var f=h.use_uuids?h.uuidv4():++this.graph.last_link_id;f=new Y(f,d.type||e.type,this.id,a,b.id,c);this.graph.links[f.id]=f;null==e.links&&(e.links=[]);e.links.push(f.id);b.inputs[c].link=f.id;this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(h.OUTPUT,a,!0,f,e);if(b.onConnectionsChange)b.onConnectionsChange(h.INPUT,c,!0,f,d);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(h.INPUT, +b,c,this,a),this.graph.onNodeConnectionChange(h.OUTPUT,this,a,b,c));this.setDirtyCanvas(!1,!0);this.graph.afterChange();this.graph.connectionChange(this,f);return f};v.prototype.disconnectOutput=function(a,b){if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return h.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.outputs||a>=this.outputs.length)return h.debug&&console.log("Connect: Error, slot number not found"),!1;var c=this.outputs[a];if(!c||!c.links||0==c.links.length)return!1; +if(b){b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"Target Node not found";for(var d=0,e=c.links.length;d=this.inputs.length)return h.debug&&console.log("Connect: Error, slot number not found"),!1;var b=this.inputs[a];if(!b)return!1;var c=this.inputs[a].link;if(null!=c){this.inputs[a].link=null;var d=this.graph.links[c];if(d){var e=this.graph.getNodeById(d.origin_id);if(!e)return!1;var f=e.outputs[d.origin_slot];if(!f||!f.links||0==f.links.length)return!1;for(var g=0,k=f.links.length;gb&&this.inputs[b].pos)return c[0]=this.pos[0]+this.inputs[b].pos[0],c[1]=this.pos[1]+ +this.inputs[b].pos[1],c;if(!a&&d>b&&this.outputs[b].pos)return c[0]=this.pos[0]+this.outputs[b].pos[0],c[1]=this.pos[1]+this.outputs[b].pos[1],c;if(this.horizontal)return c[0]=this.pos[0]+this.size[0]/d*(b+.5),c[1]=a?this.pos[1]-h.NODE_TITLE_HEIGHT:this.pos[1]+this.size[1],c;c[0]=a?this.pos[0]+e:this.pos[0]+this.size[0]+1-e;c[1]=this.pos[1]+(b+.7)*h.NODE_SLOT_HEIGHT+(this.constructor.slot_start_y||0);return c};v.prototype.alignToGrid=function(){this.pos[0]=h.CANVAS_GRID_SIZE*Math.round(this.pos[0]/ +h.CANVAS_GRID_SIZE);this.pos[1]=h.CANVAS_GRID_SIZE*Math.round(this.pos[1]/h.CANVAS_GRID_SIZE)};v.prototype.trace=function(a){this.console||(this.console=[]);this.console.push(a);this.console.length>v.MAX_CONSOLE&&this.console.shift();if(this.graph.onNodeTrace)this.graph.onNodeTrace(this,a)};v.prototype.setDirtyCanvas=function(a,b){this.graph&&this.graph.sendActionToCanvas("setDirty",[a,b])};v.prototype.loadImage=function(a){var b=new Image;b.src=h.node_images_path+a;b.ready=!1;var c=this;b.onload= +function(){this.ready=!0;c.setDirtyCanvas(!0)};return b};v.prototype.captureInput=function(a){if(this.graph&&this.graph.list_of_graphcanvas)for(var b=this.graph.list_of_graphcanvas,c=0;cb.length||(this._pos[0]=b[0],this._pos[1]=b[1])},get:function(){return this._pos},enumerable:!0});Object.defineProperty(this,"size",{set:function(b){!b||2>b.length||(this._size[0]=Math.max(140,b[0]),this._size[1]=Math.max(80,b[1]))},get:function(){return this._size},enumerable:!0})};P.prototype.configure=function(a){this.title=a.title;this._bounding.set(a.bounding);this.color=a.color;this.font_size=a.font_size};P.prototype.serialize=function(){var a= +this._bounding;return{title:this.title,bounding:[Math.round(a[0]),Math.round(a[1]),Math.round(a[2]),Math.round(a[3])],color:this.color,font_size:this.font_size}};P.prototype.move=function(a,b,c){this._pos[0]+=a;this._pos[1]+=b;if(!c)for(c=0;c=this.viewport[0]&&d=this.viewport[1]&&cthis.max_scale&&(a=this.max_scale);if(a!=this.scale&&this.element){var c=this.element.getBoundingClientRect();if(c&&(b= +b||[.5*c.width,.5*c.height],c=this.convertCanvasToOffset(b),this.scale=a,.01>Math.abs(this.scale-1)&&(this.scale=1),a=this.convertCanvasToOffset(b),a=[a[0]-c[0],a[1]-c[1]],this.offset[0]+=a[0],this.offset[1]+=a[1],this.onredraw))this.onredraw(this)}};L.prototype.changeDeltaScale=function(a,b){this.changeScale(this.scale*a,b)};L.prototype.reset=function(){this.scale=1;this.offset[0]=0;this.offset[1]=0};X.LGraphCanvas=h.LGraphCanvas=q;q.DEFAULT_BACKGROUND_IMAGE="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQBJREFUeNrs1rEKwjAUhlETUkj3vP9rdmr1Ysammk2w5wdxuLgcMHyptfawuZX4pJSWZTnfnu/lnIe/jNNxHHGNn//HNbbv+4dr6V+11uF527arU7+u63qfa/bnmh8sWLBgwYJlqRf8MEptXPBXJXa37BSl3ixYsGDBMliwFLyCV/DeLIMFCxYsWLBMwSt4Be/NggXLYMGCBUvBK3iNruC9WbBgwYJlsGApeAWv4L1ZBgsWLFiwYJmCV/AK3psFC5bBggULloJX8BpdwXuzYMGCBctgwVLwCl7Be7MMFixYsGDBsu8FH1FaSmExVfAxBa/gvVmwYMGCZbBg/W4vAQYA5tRF9QYlv/QAAAAASUVORK5CYII="; +q.link_type_colors={"-1":h.EVENT_LINK_COLOR,number:"#AAA",node:"#DCA"};q.gradients={};q.prototype.clear=function(){this.fps=this.render_time=this.last_draw_time=this.frame=0;this.dragging_rectangle=null;this.selected_nodes={};this.selected_group=null;this.visible_nodes=[];this.connecting_node=this.node_capturing_input=this.node_over=this.node_dragged=null;this.highlighted_links={};this.dragging_canvas=!1;this.dirty_bgcanvas=this.dirty_canvas=!0;this.node_widget=this.node_in_panel=this.dirty_area= +null;this.last_mouse=[0,0];this.last_mouseclick=0;this.pointer_is_double=this.pointer_is_down=!1;this.visible_area.set([0,0,0,0]);if(this.onClear)this.onClear()};q.prototype.setGraph=function(a,b){this.graph!=a&&(b||this.clear(),!a&&this.graph?this.graph.detachCanvas(this):(a.attachCanvas(this),this._graph_stack&&(this._graph_stack=null),this.setDirty(!0,!0)))};q.prototype.getTopGraph=function(){return this._graph_stack.length?this._graph_stack[0]:this.graph};q.prototype.openSubgraph=function(a){if(!a)throw"graph cannot be null"; +if(this.graph==a)throw"graph cannot be the same";this.clear();this.graph&&(this._graph_stack||(this._graph_stack=[]),this._graph_stack.push(this.graph));a.attachCanvas(this);this.checkPanels();this.setDirty(!0,!0)};q.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]));this.ds.offset= +[0,0];this.ds.scale=1}};q.prototype.getCurrentGraph=function(){return this.graph};q.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 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());b||this.bindEvents()}};q.prototype._doNothing=function(a){a.preventDefault();return!1};q.prototype._doReturnTrue=function(a){a.preventDefault(); +return!0};q.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);this._mousemove_callback=this.processMouseMove.bind(this);this._mouseup_callback=this.processMouseUp.bind(this);h.pointerListenerAdd(a,"down",this._mousedown_callback,!0);a.addEventListener("mousewheel",this._mousewheel_callback, +!1);h.pointerListenerAdd(a,"up",this._mouseup_callback,!0);h.pointerListenerAdd(a,"move",this._mousemove_callback);a.addEventListener("contextmenu",this._doNothing);a.addEventListener("DOMMouseScroll",this._mousewheel_callback,!1);this._key_callback=this.processKey.bind(this);a.setAttribute("tabindex",1);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}};q.prototype.unbindEvents=function(){if(this._events_binded){var a=this.getCanvasWindow().document;h.pointerListenerRemove(this.canvas,"move",this._mousedown_callback);h.pointerListenerRemove(this.canvas,"up",this._mousedown_callback);h.pointerListenerRemove(this.canvas,"down",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._ondrop_callback=this._key_callback=this._mousewheel_callback=this._mousedown_callback=null; +this._events_binded=!1}else console.warn("LGraphCanvas: no events binded")};q.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()};q.prototype.enableWebGL=function(){if("undefined"===typeof GL)throw"litegl.js must be included to use a WebGL canvas";if("undefined"===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};q.prototype.setDirty=function(a,b){a&&(this.dirty_canvas=!0);b&&(this.dirty_bgcanvas=!0)};q.prototype.getCanvasWindow=function(){if(!this.canvas)return window;var a=this.canvas.ownerDocument;return a.defaultView||a.parentWindow};q.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))};q.prototype.stopRendering=function(){this.is_rendering=!1};q.prototype.blockClick=function(){this.block_click=!0;this.last_mouseclick=0};q.prototype.processMouseDown=function(a){this.set_canvas_dirty_on_mouse_event&&(this.dirty_canvas=!0);if(this.graph){this.adjustMouseEvent(a);var b=this.getCanvasWindow();q.active_canvas=this;var c=this,d=a.clientX,e=a.clientY;this.ds.viewport=this.viewport;d=!this.viewport||this.viewport&&d>=this.viewport[0]&&d=this.viewport[1]&&ee-this.last_mouseclick&&g;this.mouse[0]=a.clientX;this.mouse[1]=a.clientY; +this.graph_mouse[0]=a.canvasX;this.graph_mouse[1]=a.canvasY;this.last_click_position=[this.mouse[0],this.mouse[1]];this.pointer_is_double=this.pointer_is_down&&g?!0:!1;this.pointer_is_down=!0;this.canvas.focus();h.closeAllContextMenus(b);if(!this.onMouse||1!=this.onMouse(a)){if(1!=a.which||this.pointer_is_double)if(2==a.which)if(h.middle_click_slot_add_default_node){if(f&&this.allow_interaction&&!d&&!this.read_only&&!this.connecting_node&&!f.flags.collapsed&&!this.live_mode){e=d=g=!1;if(f.outputs)for(n= +0,k=f.outputs.length;nf.size[0]-h.NODE_TITLE_HEIGHT&&0>k[1]&&(c=this,setTimeout(function(){c.openSubgraph(f.subgraph)},10)),this.live_mode&&(n=g=!0));n?f.is_selected||this.processNodeSelected(f,a):(this.allow_dragnodes&&(this.graph.beforeChange(),this.node_dragged=f),this.processNodeSelected(f,a));this.dirty_canvas=!0}}else if(!d){if(!this.read_only)for(n=0;nk[0]+4||a.canvasY +k[1]+4)){this.showLinkMenu(g,a);this.over_link_center=null;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>ba([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());e&&!this.read_only&&this.allow_searchbox&& +(this.showSearchBox(a),a.preventDefault(),a.stopPropagation());g=!0}!d&&g&&this.allow_dragcanvas&&(this.dragging_canvas=!0)}this.last_mouse[0]=a.clientX;this.last_mouse[1]=a.clientY;this.last_mouseclick=h.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}}}}; +q.prototype.processMouseMove=function(a){this.autoresize&&this.resize();this.set_canvas_dirty_on_mouse_event&&(this.dirty_canvas=!0);if(this.graph){q.active_canvas=this;this.adjustMouseEvent(a);var b=[a.clientX,a.clientY];this.mouse[0]=b[0];this.mouse[1]=b[1];var c=[b[0]-this.last_mouse[0],b[1]-this.last_mouse[1]];this.last_mouse=b;this.graph_mouse[0]=a.canvasX;this.graph_mouse[1]=a.canvasY;if(this.block_click)return a.preventDefault(),!1;a.dragging=this.last_mouse_dragging;this.node_widget&&(this.processNodeWidgets(this.node_widget[0], +this.graph_mouse,a,this.node_widget[1]),this.dirty_canvas=!0);var d=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes);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(c[0]/ +this.ds.scale,c[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]+=c[0]/this.ds.scale,this.ds.offset[1]+=c[1]/this.ds.scale,this.dirty_bgcanvas=this.dirty_canvas=!0;else if((this.allow_interaction||d&&d.flags.allow_interaction)&&!this.read_only){this.connecting_node&&(this.dirty_canvas=!0);b=0;for(var e=this.graph._nodes.length;bg[0]+4||a.canvasYg[1]+4)){e=f;break}e!=this.over_link_center&&(this.over_link_center=e,this.dirty_canvas=!0);this.canvas&&(this.canvas.style.cursor="")}if(this.node_capturing_input&& +this.node_capturing_input!=d&&this.node_capturing_input.onMouseMove)this.node_capturing_input.onMouseMove(a,[a.canvasX-this.node_capturing_input.pos[0],a.canvasY-this.node_capturing_input.pos[1]],this);if(this.node_dragged&&!this.live_mode){for(b in this.selected_nodes)d=this.selected_nodes[b],d.pos[0]+=c[0]/this.ds.scale,d.pos[1]+=c[1]/this.ds.scale,d.is_selected||this.processNodeSelected(d,a);this.dirty_bgcanvas=this.dirty_canvas=!0}this.resizing_node&&!this.live_mode&&(c=[a.canvasX-this.resizing_node.pos[0], +a.canvasY-this.resizing_node.pos[1]],b=this.resizing_node.computeSize(),c[0]=Math.max(b[0],c[0]),c[1]=Math.max(b[1],c[1]),this.resizing_node.setSize(c),this.canvas.style.cursor="se-resize",this.dirty_bgcanvas=this.dirty_canvas=!0)}a.preventDefault();return!1}};q.prototype.processMouseUp=function(a){var b=void 0===a.isPrimary||a.isPrimary;if(!b)return!1;this.set_canvas_dirty_on_mouse_event&&(this.dirty_canvas=!0);if(this.graph){var c=this.getCanvasWindow().document;q.active_canvas=this;this.options.skip_events|| +(h.pointerListenerRemove(c,"move",this._mousemove_callback,!0),h.pointerListenerAdd(this.canvas,"move",this._mousemove_callback,!0),h.pointerListenerRemove(c,"up",this._mouseup_callback,!0));this.adjustMouseEvent(a);c=h.getTime();a.click_time=c-this.last_mouseclick;this.last_mouse_dragging=!1;this.last_click_position=null;this.block_click&&(this.block_click=!1);if(1==a.which){this.node_widget&&this.processNodeWidgets(this.node_widget[0],this.graph_mouse,a);this.node_widget=null;this.selected_group&& +(this.selected_group.move(this.selected_group.pos[0]-Math.round(this.selected_group.pos[0]),this.selected_group.pos[1]-Math.round(this.selected_group.pos[1]),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;var d=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes);if(this.dragging_rectangle){if(this.graph){c= +this.graph._nodes;var e=new Float32Array(4),f=Math.abs(this.dragging_rectangle[2]),g=Math.abs(this.dragging_rectangle[3]),k=0>this.dragging_rectangle[3]?this.dragging_rectangle[1]-g:this.dragging_rectangle[1];this.dragging_rectangle[0]=0>this.dragging_rectangle[2]?this.dragging_rectangle[0]-f:this.dragging_rectangle[0];this.dragging_rectangle[1]=k;this.dragging_rectangle[2]=f;this.dragging_rectangle[3]=g;if(!d||10a.click_time&&K(a.canvasX,a.canvasY,d.pos[0],d.pos[1]-h.NODE_TITLE_HEIGHT,h.NODE_TITLE_HEIGHT,h.NODE_TITLE_HEIGHT)&&d.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.align_to_grid)&&this.node_dragged.alignToGrid();if(this.onNodeMoved)this.onNodeMoved(this.node_dragged);this.graph.afterChange(this.node_dragged); +this.node_dragged=null}else{d=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes);!d&&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);b&&(this.pointer_is_double=this.pointer_is_down=!1);this.graph.change();a.stopPropagation();a.preventDefault();return!1}};q.prototype.processMouseWheel=function(a){if(this.graph&&this.allow_dragcanvas){var b=null!=a.wheelDeltaY?a.wheelDeltaY:-60*a.detail;this.adjustMouseEvent(a);var c=a.clientX,d=a.clientY;if(!this.viewport||this.viewport&&c>=this.viewport[0]&&c=this.viewport[1]&&db&&(c*=1/1.1),this.ds.changeScale(c,[a.clientX,a.clientY]),this.graph.change(),a.preventDefault(),!1}};q.prototype.isOverNodeBox=function(a,b,c){var d=h.NODE_TITLE_HEIGHT;return K(b,c,a.pos[0]+2,a.pos[1]+2-d,d-4,d-4)?!0:!1};q.prototype.isOverNodeInput=function(a,b,c,d){if(a.inputs)for(var e=0,f=a.inputs.length;eb.nodes[d].pos[0]&&(c[0]=b.nodes[d].pos[0],e[0]=d),c[1]>b.nodes[d].pos[1]&&(c[1]=b.nodes[d].pos[1],e[1]=d)):(c=[b.nodes[d].pos[0],b.nodes[d].pos[1]],e=[d,d]);e=[];for(d=0;d=this.viewport[0]&&b=this.viewport[1]&&cc-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}};l.prototype.drawFrontCanvas= -function(){this.dirty_canvas=!1;this.ctx||(this.ctx=this.bgcanvas.getContext("2d"));var a=this.ctx;if(a){var b=this.canvas;a.start2D&&!this.viewport&&(a.start2D(),a.restore(),a.setTransform(1,0,0,1,0,0));var c=this.viewport||this.dirty_area;c&&(a.save(),a.beginPath(),a.rect(c[0],c[1],c[2],c[3]),a.clip());this.clear_background&&(c?a.clearRect(c[0],c[1],c[2],c[3]):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,c?c[0]:0,c?c[1]:0);if(this.graph){a.save();this.ds.toCanvasContext(a);b=this.computeVisibleNodes(null,this.visible_nodes);for(var e=0;e> ";b.fillText(e+c.getTitle(),.5*a.width,40);b.restore()}c=!1;this.onRenderBackground&&(c=this.onRenderBackground(a,b));this.viewport||(b.restore(),b.setTransform(1,0,0,1,0,0));this.visible_links.length=0;if(this.graph){b.save();this.ds.toCanvasContext(b);1.5>this.ds.scale&&!c&&this.clear_background_color&& -(b.fillStyle=this.clear_background_color,b.fillRect(this.visible_area[0],this.visible_area[1],this.visible_area[2],this.visible_area[3]));if(this.background_image&&.5this.ds.scale;if(this.live_mode){if(!a.flags.collapsed&&(b.shadowColor="transparent",a.onDrawForeground))a.onDrawForeground(b,this,this.canvas)}else{var f=this.editor_alpha;b.globalAlpha=f;this.render_shadows&&!d?(b.shadowColor=g.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||1!=a.onDrawCollapsed(b,this)){var h=a._shape||g.BOX_SHAPE;D.set(a.size);var k=a.horizontal;if(a.flags.collapsed){b.font=this.inner_text_font;var q=a.getTitle?a.getTitle():a.title;null!=q&&(a._collapsed_width=Math.min(a.size[0],b.measureText(q).width+2*g.NODE_TITLE_HEIGHT),D[0]=a._collapsed_width,D[1]=0)}a.clip_area&&(b.save(),b.beginPath(),h==g.BOX_SHAPE?b.rect(0,0, -D[0],D[1]):h==g.ROUND_SHAPE?b.roundRect(0,0,D[0],D[1],[10]):h==g.CIRCLE_SHAPE&&b.arc(.5*D[0],.5*D[1],.5*D[0],0,2*Math.PI),b.clip());a.has_errors&&(e="red");this.drawNodeShape(a,b,D,c,e,a.is_selected,a.mouseOver);b.shadowColor="transparent";if(a.onDrawForeground)a.onDrawForeground(b,this,this.canvas);b.textAlign=k?"center":"left";b.font=this.inner_text_font;e=!d;var n=this.connecting_output;h=this.connecting_input;b.lineWidth=1;q=0;var p=new Float32Array(2);if(!a.flags.collapsed){if(a.inputs)for(c= -0;cthis.ds.scale,q=a._shape||a.constructor.shape||g.ROUND_SHAPE,n=a.constructor.title_mode,p=!0;n==g.TRANSPARENT_TITLE||n==g.NO_TITLE?p=!1:n==g.AUTOHIDE_TITLE&&h&&(p=!0);x[0]=0;x[1]=p?-d:0;x[2]=c[0]+1;x[3]=p?c[1]+d:c[1];h=b.globalAlpha;b.beginPath();q==g.BOX_SHAPE||k?b.fillRect(x[0],x[1],x[2],x[3]):q==g.ROUND_SHAPE||q==g.CARD_SHAPE?b.roundRect(x[0],x[1],x[2],x[3],q==g.CARD_SHAPE?[this.round_radius, -this.round_radius,0,0]:[this.round_radius]):q==g.CIRCLE_SHAPE&&b.arc(.5*c[0],.5*c[1],.5*c[0],0,2*Math.PI);b.fill();!a.flags.collapsed&&p&&(b.shadowColor="transparent",b.fillStyle="rgba(0,0,0,0.2)",b.fillRect(0,-1,x[2],2));b.shadowColor="transparent";if(a.onDrawBackground)a.onDrawBackground(b,this,this.canvas,this.graph_mouse);if(p||n==g.TRANSPARENT_TITLE){if(a.onDrawTitleBar)a.onDrawTitleBar(b,d,c,this.ds.scale,e);else if(n!=g.TRANSPARENT_TITLE&&(a.constructor.title_color||this.render_title_colored)){p= -a.constructor.title_color||e;a.flags.collapsed&&(b.shadowColor=g.DEFAULT_SHADOW_COLOR);if(this.use_gradients){var A=l.gradients[p];A||(A=l.gradients[p]=b.createLinearGradient(0,0,400,0),A.addColorStop(0,p),A.addColorStop(1,"#000"));b.fillStyle=A}else b.fillStyle=p;b.beginPath();q==g.BOX_SHAPE||k?b.rect(0,-d,c[0]+1,d):(q==g.ROUND_SHAPE||q==g.CARD_SHAPE)&&b.roundRect(0,-d,c[0]+1,d,a.flags.collapsed?[this.round_radius]:[this.round_radius,this.round_radius,0,0]);b.fill();b.shadowColor="transparent"}p= -!1;g.node_box_coloured_by_mode&&g.NODE_MODES_COLORS[a.mode]&&(p=g.NODE_MODES_COLORS[a.mode]);g.node_box_coloured_when_on&&(p=a.action_triggered?"#FFF":a.execute_triggered?"#AAA":p);if(a.onDrawTitleBox)a.onDrawTitleBox(b,d,c,this.ds.scale);else q==g.ROUND_SHAPE||q==g.CIRCLE_SHAPE||q==g.CARD_SHAPE?(k&&(b.fillStyle="black",b.beginPath(),b.arc(.5*d,-.5*d,6,0,2*Math.PI),b.fill()),b.fillStyle=a.boxcolor||p||g.NODE_DEFAULT_BOXCOLOR,k?b.fillRect(.5*d-5,-.5*d-5,10,10):(b.beginPath(),b.arc(.5*d,-.5*d,5,0,2* -Math.PI),b.fill())):(k&&(b.fillStyle="black",b.fillRect(.5*(d-10)-1,-.5*(d+10)-1,12,12)),b.fillStyle=a.boxcolor||p||g.NODE_DEFAULT_BOXCOLOR,b.fillRect(.5*(d-10),-.5*(d+10),10,10));b.globalAlpha=h;if(a.onDrawTitleText)a.onDrawTitleText(b,d,c,this.ds.scale,this.title_text_font,f);!k&&(b.font=this.title_text_font,h=String(a.getTitle()))&&(b.fillStyle=f?g.NODE_SELECTED_TITLE_COLOR:a.constructor.title_text_color||this.node_title_color,a.flags.collapsed?(b.textAlign="left",b.measureText(h),b.fillText(h.substr(0, -20),d,g.NODE_TITLE_TEXT_Y-d),b.textAlign="left"):(b.textAlign="left",b.fillText(h,d,g.NODE_TITLE_TEXT_Y-d)));a.flags.collapsed||!a.subgraph||a.skip_subgraph_button||(h=g.NODE_TITLE_HEIGHT,p=a.size[0]-h,A=g.isInsideRectangle(this.graph_mouse[0]-a.pos[0],this.graph_mouse[1]-a.pos[1],p+2,-h+2,h-4,h-4),b.fillStyle=A?"#888":"#555",q==g.BOX_SHAPE||k?b.fillRect(p+2,-h+2,h-4,h-4):(b.beginPath(),b.roundRect(p+2,-h+2,h-4,h-4,[4]),b.fill()),b.fillStyle="#333",b.beginPath(),b.moveTo(p+.2*h,.6*-h),b.lineTo(p+ -.8*h,.6*-h),b.lineTo(p+.5*h,.3*-h),b.fill());if(a.onDrawTitle)a.onDrawTitle(b)}if(f){if(a.onBounding)a.onBounding(x);n==g.TRANSPARENT_TITLE&&(x[1]-=d,x[3]+=d);b.lineWidth=1;b.globalAlpha=.8;b.beginPath();q==g.BOX_SHAPE?b.rect(-6+x[0],-6+x[1],12+x[2],12+x[3]):q==g.ROUND_SHAPE||q==g.CARD_SHAPE&&a.flags.collapsed?b.roundRect(-6+x[0],-6+x[1],12+x[2],12+x[3],[2*this.round_radius]):q==g.CARD_SHAPE?b.roundRect(-6+x[0],-6+x[1],12+x[2],12+x[3],[2*this.round_radius,2,2*this.round_radius,2]):q==g.CIRCLE_SHAPE&& -b.arc(.5*c[0],.5*c[1],.5*c[0]+6,0,2*Math.PI);b.strokeStyle=g.NODE_BOX_OUTLINE_COLOR;b.stroke();b.strokeStyle=e;b.globalAlpha=1}0E[2]&&(E[0]+=E[2],E[2]=Math.abs(E[2]));0>E[3]&& -(E[1]+=E[3],E[3]=Math.abs(E[3]));if(H(E,I)){var v=q.outputs[n];n=f.inputs[h];if(v&&n&&(q=v.dir||(q.horizontal?g.DOWN:g.RIGHT),n=n.dir||(f.horizontal?g.UP:g.LEFT),this.renderLink(a,p,l,k,!1,0,null,q,n),k&&k._last_time&&1E3>b-k._last_time)){v=2-.002*(b-k._last_time);var t=a.globalAlpha;a.globalAlpha=t*v;this.renderLink(a,p,l,k,!0,v,"white",q,n);a.globalAlpha=t}}}}}}a.globalAlpha=1};l.prototype.renderLink=function(a,b,c,e,d,f,h,k,q,n){e&&this.visible_links.push(e);!h&&e&&(h=e.color||l.link_type_colors[e.type]); -h||(h=this.default_link_color);null!=e&&this.highlighted_links[e.id]&&(h="#FFF");k=k||g.RIGHT;q=q||g.LEFT;var p=J(b,c);this.render_connections_border&&.6b[1]?0:Math.PI,a.save(),a.translate(A[0],A[1]),a.rotate(p),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5, --3),a.fill(),a.restore(),a.save(),a.translate(e[0],e[1]),a.rotate(n),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore()),a.beginPath(),a.arc(d[0],d[1],5,0,2*Math.PI),a.fill());if(f)for(a.fillStyle=h,A=0;5>A;++A)f=(.001*g.getTime()+.2*A)%1,d=this.computeConnectionPoint(b,c,f,k,q),a.beginPath(),a.arc(d[0],d[1],5,0,2*Math.PI),a.fill()};l.prototype.computeConnectionPoint=function(a,b,c,e,d){e=e||g.RIGHT;d=d||g.LEFT;var f=J(a,b),h=[a[0],a[1]],k=[b[0],b[1]];switch(e){case g.LEFT:h[0]+= --.25*f;break;case g.RIGHT:h[0]+=.25*f;break;case g.UP:h[1]+=-.25*f;break;case g.DOWN:h[1]+=.25*f}switch(d){case g.LEFT:k[0]+=-.25*f;break;case g.RIGHT:k[0]+=.25*f;break;case g.UP:k[1]+=-.25*f;break;case g.DOWN:k[1]+=.25*f}e=(1-c)*(1-c)*(1-c);d=3*(1-c)*(1-c)*c;f=3*(1-c)*c*c;c*=c*c;return[e*a[0]+d*h[0]+f*k[0]+c*b[0],e*a[1]+d*h[1]+f*k[1]+c*b[1]]};l.prototype.drawExecutionOrder=function(a){a.shadowColor="transparent";a.globalAlpha=.25;a.textAlign="center";a.strokeStyle="white";a.globalAlpha=.75;for(var b= -this.visible_nodes,c=0;cz&&(z=0);1w&&(w=0),1f||f>u-12||hv.last_y+t||void 0===v.last_y)){e=v.value;switch(v.type){case "button":c.type===g.pointerevents_method+"down"&&(v.callback&&setTimeout(function(){v.callback(v,n,a,b,c)},20),this.dirty_canvas=v.clicked=!0);break;case "slider":e=v.value;p=K((f-15)/(u-30),0,1);if(v.options.read_only)break;v.value=v.options.min+(v.options.max-v.options.min)*p;e!=v.value&&setTimeout(function(){d(v,v.value)},20);this.dirty_canvas= -!0;break;case "number":case "combo":e=v.value;if(c.type==g.pointerevents_method+"move"&&"number"==v.type)l&&(v.value+=.1*l*(v.options.step||1)),null!=v.options.min&&v.valuev.options.max&&(v.value=v.options.max);else if(c.type==g.pointerevents_method+"down"){var r=v.options.values;r&&r.constructor===Function&&(r=v.options.values(v,a));var w=null;"number"!=v.type&&(w=r.constructor===Array?r:Object.keys(r));f=40>f?-1:f>u-40?1:0;if("number"== -v.type)v.value+=.1*f*(v.options.step||1),null!=v.options.min&&v.valuev.options.max&&(v.value=v.options.max);else if(f)p=-1,this.last_mouseclick=0,p=r.constructor===Object?w.indexOf(String(v.value))+f:w.indexOf(v.value)+f,p>=w.length&&(p=w.length-1),0>p&&(p=0),v.value=r.constructor===Array?r[p]:p;else{var z=r!=w?Object.values(r):r;new g.ContextMenu(z,{scale:Math.max(1,this.ds.scale),event:c,className:"dark",callback:function(a,b, -c){r!=w&&(a=z.indexOf(a));this.value=a;d(this,a);n.dirty_canvas=!0;return!1}.bind(v)},p)}}else c.type==g.pointerevents_method+"up"&&"number"==v.type&&(f=40>f?-1:f>u-40?1:0,200>c.click_time&&0==f&&this.prompt("Value",v.value,function(a){if(/^[0-9+\-*/()\s]+|\d+\.\d+$/.test(a))try{a=eval(a)}catch(O){}this.value=Number(a);d(this,this.value)}.bind(v),c));e!=v.value&&setTimeout(function(){d(this,this.value)}.bind(v),20);this.dirty_canvas=!0;break;case "toggle":c.type==g.pointerevents_method+"down"&&(v.value= -!v.value,setTimeout(function(){d(v,v.value)},20));break;case "string":case "text":c.type==g.pointerevents_method+"down"&&this.prompt("Value",v.value,function(a){d(this,a)}.bind(v),c,v.options?v.options.multiline:!1);break;default:v.mouse&&(this.dirty_canvas=v.mouse(c,[f,h],a))}if(e!=v.value){if(a.onWidgetChanged)a.onWidgetChanged(v.name,v.value,e,v);a.graph._version++}return v}}}return null};l.prototype.drawGroups=function(a,b){if(this.graph){a=this.graph._groups;b.save();b.globalAlpha=.5*this.editor_alpha; -for(var c=0;cc&&.01>b.editor_alpha&&(clearInterval(e),1>c&&(b.live_mode=!0));1c.pos[0]+c.size[0])c=h;if(null===e||g+n>e.pos[1]+e.size[1])e=h;if(null===d||l"+(q.label?q.label:k)+""+a+"",value:k})}if(h.length)return new g.ContextMenu(h,{event:c,callback:function(a,b,c,e){d&&(b=this.getBoundingClientRect(),f.showEditPropertyValue(d,a.value,{position:[b.left,b.top]}))},parentMenu:e,allow_html:!0, -node:d},b),!1}};l.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};l.onMenuResizeNode=function(a,b,c,e,d){if(d){a=function(a){a.size=a.computeSize();if(a.onResize)a.onResize(a.size)};b=l.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)a(d);else for(var f in b.selected_nodes)a(b.selected_nodes[f]);d.setDirtyCanvas(!0,!0)}};l.prototype.showLinkMenu=function(a,b){var c=this,e=c.graph.getNodeById(a.origin_id),d=c.graph.getNodeById(a.target_id), -f=!1;e&&e.outputs&&e.outputs[a.origin_slot]&&(f=e.outputs[a.origin_slot].type);var h=!1;d&&d.outputs&&d.outputs[a.target_slot]&&(h=d.inputs[a.target_slot].type);var k=new g.ContextMenu(["Add Node",null,"Delete",null],{event:b,title:null!=a.data?a.data.constructor.name:null,callback:function(b,g,p){switch(b){case "Add Node":l.onMenuAdd(null,null,p,k,function(b){b.inputs&&b.inputs.length&&b.outputs&&b.outputs.length&&e.connectByType(a.origin_slot,b,f)&&(b.connectByType(a.target_slot,d,h),b.pos[0]-= -.5*b.size[0])});break;case "Delete":c.graph.removeLink(a.id)}}});return!1};l.prototype.createDefaultNodeForSlot=function(a){a=a||{};a=Object.assign({nodeFrom:null,slotFrom:null,nodeTo:null,slotTo:null,position:[],nodeType:null,posAdd:[0,0],posSizeFix:[0,0]},a);var b=a.nodeFrom&&null!==a.slotFrom,c=!b&&a.nodeTo&&null!==a.slotTo;if(!b&&!c)return console.warn("No data passed to createDefaultNodeForSlot "+a.nodeFrom+" "+a.slotFrom+" "+a.nodeTo+" "+a.slotTo),!1;if(!a.nodeType)return console.warn("No type to createDefaultNodeForSlot"), -!1;var e=b?a.nodeFrom:a.nodeTo,d=b?a.slotFrom:a.slotTo;switch(typeof d){case "string":c=b?e.findOutputSlot(d,!1):e.findInputSlot(d,!1);d=b?e.outputs[d]:e.inputs[d];break;case "object":c=b?e.findOutputSlot(d.name):e.findInputSlot(d.name);break;case "number":c=d;d=b?e.outputs[d]:e.inputs[d];break;default:return console.warn("Cant get slot information "+d),!1}!1!==d&&!1!==c||console.warn("createDefaultNodeForSlot bad slotX "+d+" "+c);e=d.type==g.EVENT?"_event_":d.type;if((d=b?g.slot_types_default_out: -g.slot_types_default_in)&&d[e]){nodeNewType=!1;if("object"==typeof d[e]||"array"==typeof d[e])for(var f in d[e]){if(a.nodeType==d[e][f]||"AUTO"==a.nodeType){nodeNewType=d[e][f];break}}else if(a.nodeType==d[e]||"AUTO"==a.nodeType)nodeNewType=d[e];if(nodeNewType){f=!1;"object"==typeof nodeNewType&&nodeNewType.node&&(f=nodeNewType,nodeNewType=nodeNewType.node);if(d=g.createNode(nodeNewType)){if(f){if(f.properties)for(var h in f.properties)d.addProperty(h,f.properties[h]);if(f.inputs)for(h in d.inputs= -[],f.inputs)d.addOutput(f.inputs[h][0],f.inputs[h][1]);if(f.outputs)for(h in d.outputs=[],f.outputs)d.addOutput(f.outputs[h][0],f.outputs[h][1]);f.title&&(d.title=f.title);f.json&&d.configure(f.json)}this.graph.add(d);d.pos=[a.position[0]+a.posAdd[0]+(a.posSizeFix[0]?a.posSizeFix[0]*d.size[0]:0),a.position[1]+a.posAdd[1]+(a.posSizeFix[1]?a.posSizeFix[1]*d.size[1]:0)];b?a.nodeFrom.connectByType(c,d,e):a.nodeTo.connectByTypeOutput(c,d,e);return!0}console.log("failed creating "+nodeNewType)}}return!1}; -l.prototype.showConnectionMenu=function(a){a=a||{};var b=Object.assign({nodeFrom:null,slotFrom:null,nodeTo:null,slotTo:null,e:null},a),c=this,e=b.nodeFrom&&b.slotFrom;a=!e&&b.nodeTo&&b.slotTo;if(!e&&!a)return console.warn("No data passed to showConnectionMenu"),!1;a=e?b.nodeFrom:b.nodeTo;var d=e?b.slotFrom:b.slotTo,f=!1;switch(typeof d){case "string":f=e?a.findOutputSlot(d,!1):a.findInputSlot(d,!1);d=e?a.outputs[d]:a.inputs[d];break;case "object":f=e?a.findOutputSlot(d.name):a.findInputSlot(d.name); -break;case "number":f=d;d=e?a.outputs[d]:a.inputs[d];break;default:return console.warn("Cant get slot information "+d),!1}a=["Add Node",null];c.allow_searchbox&&(a.push("Search"),a.push(null));var h=d.type==g.EVENT?"_event_":d.type,k=e?g.slot_types_default_out:g.slot_types_default_in;if(k&&k[h])if("object"==typeof k[h]||"array"==typeof k[h])for(var q in k[h])a.push(k[h][q]);else a.push(k[h]);var n=new g.ContextMenu(a,{event:b.e,title:(d&&""!=d.name?d.name+(h?" | ":""):"")+(d&&h?h:""),callback:function(a, -g,k){switch(a){case "Add Node":l.onMenuAdd(null,null,k,n,function(a){e?b.nodeFrom.connectByType(f,a,h):b.nodeTo.connectByTypeOutput(f,a,h)});break;case "Search":e?c.showSearchBox(k,{node_from:b.nodeFrom,slot_from:d,type_filter_in:h}):c.showSearchBox(k,{node_to:b.nodeTo,slot_from:d,type_filter_out:h});break;default:c.createDefaultNodeForSlot(Object.assign(b,{position:[b.e.canvasX,b.e.canvasY],nodeType:a}))}}});return!1};l.onShowPropertyEditor=function(a,b,c,e,d){function f(){if(q){var b=q.value;"Number"== -a.type?b=Number(b):"Boolean"==a.type&&(b=!!b);d[h]=b;k.parentNode&&k.parentNode.removeChild(k);d.setDirtyCanvas(!0,!0)}}var h=a.property||"title";b=d[h];var k=document.createElement("div");k.is_modified=!1;k.className="graphdialog";k.innerHTML="";k.close=function(){k.parentNode&&k.parentNode.removeChild(k)};k.querySelector(".name").innerText=h;var q=k.querySelector(".value");q&&(q.value=b,q.addEventListener("blur", -function(a){this.focus()}),q.addEventListener("keydown",function(a){k.is_modified=!0;if(27==a.keyCode)k.close();else if(13==a.keyCode)f();else if(13!=a.keyCode&&"textarea"!=a.target.localName)return;a.preventDefault();a.stopPropagation()}));b=l.active_canvas.canvas;c=b.getBoundingClientRect();var n=e=-20;c&&(e-=c.left,n-=c.top);event?(k.style.left=event.clientX+e+"px",k.style.top=event.clientY+n+"px"):(k.style.left=.5*b.width+e+"px",k.style.top=.5*b.height+n+"px");k.querySelector("button").addEventListener("click", -f);b.parentNode.appendChild(k);q&&q.focus();var p=null;k.addEventListener("mouseleave",function(a){g.dialog_close_on_mouse_leave&&!k.is_modified&&g.dialog_close_on_mouse_leave&&(p=setTimeout(k.close,g.dialog_close_on_mouse_leave_delay))});k.addEventListener("mouseenter",function(a){g.dialog_close_on_mouse_leave&&p&&clearTimeout(p)})};l.prototype.prompt=function(a,b,c,e,d){var f=this;a=a||"";var h=document.createElement("div");h.is_modified=!1;h.className="graphdialog rounded";h.innerHTML=d?" ": -" ";h.close=function(){f.prompt_box=null;h.parentNode&&h.parentNode.removeChild(h)};d=l.active_canvas.canvas;d.parentNode.appendChild(h);1l.search_limit))break}}r=null;if(Array.prototype.filter)r=Object.keys(g.registered_node_types).filter(e);else for(k in r=[],g.registered_node_types)e(k)&&r.push(k);for(k=0;kl.search_limit);k++);if(b.show_general_after_typefiltered&&(p.value|| -m.value)){filtered_extra=[];for(k in g.registered_node_types)e(k,{inTypeOverride:p&&p.value?"*":!1,outTypeOverride:m&&m.value?"*":!1})&&filtered_extra.push(k);for(k=0;kl.search_limit);k++);}if((p.value||m.value)&&0==u.childNodes.length&&b.show_general_if_none_on_typefilter){filtered_extra=[];for(k in g.registered_node_types)e(k,{skipFilter:!0})&&filtered_extra.push(k);for(k=0;kl.search_limit);k++);}}}b=Object.assign({slot_from:null,node_from:null,node_to:null,do_type_filter:g.search_filter_enabled,type_filter_in:!1,type_filter_out:!1,show_general_if_none_on_typefilter:!0,show_general_after_typefiltered:!0,hide_on_mouse_leave:g.search_hide_on_mouse_leave,show_all_if_empty:!0,show_all_on_open:g.search_show_all_on_open},b||{});var f=this,h=l.active_canvas,k=h.canvas,q=k.ownerDocument||document,n=document.createElement("div");n.className= -"litegraph litesearchbox graphdialog rounded";n.innerHTML="Search ";b.do_type_filter&&(n.innerHTML+="",n.innerHTML+="");n.innerHTML+="
";q.fullscreenElement?q.fullscreenElement.appendChild(n):(q.body.appendChild(n),q.body.style.overflow="hidden");if(b.do_type_filter)var p= -n.querySelector(".slot_in_type_filter"),m=n.querySelector(".slot_out_type_filter");n.close=function(){f.search_box=null;this.blur();k.focus();q.body.style.overflow="";setTimeout(function(){f.canvas.focus()},20);n.parentNode&&n.parentNode.removeChild(n)};1p.height-200&&(u.style.maxHeight=p.height-a.layerY-20+"px");B.focus();b.show_all_on_open&&d();return n};l.prototype.showEditPropertyValue=function(a,b,c){function e(){d(m.value)}function d(d){f&&f.values&&f.values.constructor===Object&&void 0!=f.values[d]&&(d=f.values[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);if(c.onclose)c.onclose();p.close();a.setDirtyCanvas(!0,!0)}if(a&&void 0!==a.properties[b]){c=c||{};var f=a.getPropertyInfo(b),h=f.type,g="";if("string"==h||"number"==h||"array"==h||"object"==h)g="";else if("enum"!=h&&"combo"!=h||!f.values)if("boolean"==h||"toggle"==h)g="";else{console.warn("unknown type: "+h);return}else{g=""}var p=this.createDialog(""+(f.label?f.label:b)+""+g+"",c),m=!1;if("enum"!=h&&"combo"!=h||!f.values)if("boolean"==h||"toggle"==h)(m=p.querySelector("input"))&& -m.addEventListener("click",function(a){p.modified();d(!!m.checked)});else{if(m=p.querySelector("input"))m.addEventListener("blur",function(a){this.focus()}),n=void 0!==a.properties[b]?a.properties[b]:"","string"!==h&&(n=JSON.stringify(n)),m.value=n,m.addEventListener("keydown",function(a){if(27==a.keyCode)p.close();else if(13==a.keyCode)e();else if(13!=a.keyCode){p.modified();return}a.preventDefault();a.stopPropagation()})}else m=p.querySelector("select"),m.addEventListener("change",function(a){p.modified(); -d(a.target.value)});m&&m.focus();p.querySelector("button").addEventListener("click",e);return p}};l.prototype.createDialog=function(a,b){b=Object.assign({checkForInput:!1,closeOnLeave:!0,closeOnLeave_checkModified:!0},b||{});var c=document.createElement("div");c.className="graphdialog";c.innerHTML=a;c.is_modified=!1;a=this.canvas.getBoundingClientRect();var e=-20,d=-20;a&&(e-=a.left,d-=a.top);b.position?(e+=b.position[0],d+=b.position[1]):b.event?(e+=b.event.clientX,d+=b.event.clientY):(e+=.5*this.canvas.width, -d+=.5*this.canvas.height);c.style.left=e+"px";c.style.top=d+"px";this.canvas.parentNode.appendChild(c);b.checkForInput&&(a=[],(a=c.querySelectorAll("input"))&&a.forEach(function(a){a.addEventListener("keydown",function(a){c.modified();if(27==a.keyCode)c.close();else if(13!=a.keyCode)return;a.preventDefault();a.stopPropagation()});a.focus()}));c.modified=function(){c.is_modified=!0};c.close=function(){c.parentNode&&c.parentNode.removeChild(c)};var f=null,h=!1;c.addEventListener("mouseleave",function(a){h|| -(b.closeOnLeave||g.dialog_close_on_mouse_leave)&&!c.is_modified&&g.dialog_close_on_mouse_leave&&(f=setTimeout(c.close,g.dialog_close_on_mouse_leave_delay))});c.addEventListener("mouseenter",function(a){(b.closeOnLeave||g.dialog_close_on_mouse_leave)&&f&&clearTimeout(f)});(a=c.querySelectorAll("select"))&&a.forEach(function(a){a.addEventListener("click",function(a){h++});a.addEventListener("blur",function(a){h=0});a.addEventListener("change",function(a){h=-1})});return c};l.prototype.createPanel=function(a, -b){b=b||{};var c=b.window||window,e=document.createElement("div");e.className="litegraph dialog";e.innerHTML="
";e.header=e.querySelector(".dialog-header");b.width&&(e.style.width=b.width+(b.width.constructor===Number?"px":""));b.height&&(e.style.height=b.height+(b.height.constructor===Number?"px":""));b.closable&& -(b=document.createElement("span"),b.innerHTML="✕",b.classList.add("close"),b.addEventListener("click",function(){e.close()}),e.header.appendChild(b));e.title_element=e.querySelector(".dialog-title");e.title_element.innerText=a;e.content=e.querySelector(".dialog-content");e.alt_content=e.querySelector(".dialog-alt-content");e.footer=e.querySelector(".dialog-footer");e.close=function(){if(e.onClose&&"function"==typeof e.onClose)e.onClose();e.parentNode&&e.parentNode.removeChild(e);this.parentNode&& -this.parentNode.removeChild(this)};e.toggleAltContent=function(a){if("undefined"!=typeof a){var b=a?"block":"none";a=a?"none":"block"}else b="block"!=e.alt_content.style.display?"block":"none",a="block"!=e.alt_content.style.display?"none":"block";e.alt_content.style.display=b;e.content.style.display=a};e.toggleFooterVisibility=function(a){e.footer.style.display="undefined"!=typeof a?a?"block":"none":"block"!=e.footer.style.display?"block":"none"};e.clear=function(){this.content.innerHTML=""};e.addHTML= -function(a,b,c){var d=document.createElement("div");b&&(d.className=b);d.innerHTML=a;c?e.footer.appendChild(d):e.content.appendChild(d);return d};e.addButton=function(a,b,c){var d=document.createElement("button");d.innerText=a;d.options=c;d.classList.add("btn");d.addEventListener("click",b);e.footer.appendChild(d);return d};e.addSeparator=function(){var a=document.createElement("div");a.className="separator";e.content.appendChild(a)};e.addWidget=function(a,b,h,k,m){function d(a,b){k.callback&&k.callback(a, -b,k);m&&m(a,b,k)}k=k||{};var f=String(h);a=a.toLowerCase();"number"==a&&(f=h.toFixed(3));var q=document.createElement("div");q.className="property";q.innerHTML="";q.querySelector(".property_name").innerText=k.label||b;var r=q.querySelector(".property_value");r.innerText=f;q.dataset.property=b;q.dataset.type=k.type||a;q.options=k;q.value=h;if("code"==a)q.addEventListener("click",function(a){e.inner_showCodePad(this.dataset.property)}); -else if("boolean"==a)q.classList.add("boolean"),h&&q.classList.add("bool-on"),q.addEventListener("click",function(){var a=this.dataset.property;this.value=!this.value;this.classList.toggle("bool-on");this.querySelector(".property_value").innerText=this.value?"true":"false";d(a,this.value)});else if("string"==a||"number"==a)r.setAttribute("contenteditable",!0),r.addEventListener("keydown",function(b){"Enter"!=b.code||"string"==a&&b.shiftKey||(b.preventDefault(),this.blur())}),r.addEventListener("blur", -function(){var a=this.innerText,b=this.parentNode.dataset.property;"number"==this.parentNode.dataset.type&&(a=Number(a));d(b,a)});else if("enum"==a||"combo"==a)f=l.getPropertyPrintableValue(h,k.values),r.innerText=f,r.addEventListener("click",function(a){var b=this.parentNode.dataset.property,e=this;new g.ContextMenu(k.values||[],{event:a,className:"dark",callback:function(a,c,f){e.innerText=a;d(b,a);return!1}},c)});e.content.appendChild(q);return q};if(e.onOpen&&"function"==typeof e.onOpen)e.onOpen(); -return e};l.getPropertyPrintableValue=function(a,b){if(!b||b.constructor===Array)return String(a);if(b.constructor===Object){var c="",e;for(e in b)if(b[e]==a){c=e;break}return String(a)+" ("+c+")"}};l.prototype.closePanels=function(){var a=document.querySelector("#node-panel");a&&a.close();(a=document.querySelector("#option-panel"))&&a.close()};l.prototype.showShowGraphOptionsPanel=function(a,b,c,e){if(this.constructor&&"HTMLDivElement"==this.constructor.name){if(!(b&&b.event&&b.event.target&&b.event.target.lgraphcanvas)){console.warn("Canvas not found"); -return}var d=b.event.target.lgraphcanvas}else d=this;d.closePanels();a=d.getCanvasWindow();panel=d.createPanel("Options",{closable:!0,window:a,onOpen:function(){d.OPTIONPANEL_IS_OPEN=!0},onClose:function(){d.OPTIONPANEL_IS_OPEN=!1;d.options_panel=null}});d.options_panel=panel;panel.id="option-panel";panel.classList.add("settings");(function(){panel.content.innerHTML="";var a=function(a,b,c){c&&c.key&&(a=c.key);c.values&&(b=Object.values(c.values).indexOf(b));d[a]=b},b=g.availableCanvasOptions;b.sort(); -for(var c in b){var e=b[c];panel.addWidget("boolean",e,d[e],{key:e,on:"True",off:"False"},a)}panel.addWidget("combo","Render mode",g.LINK_RENDER_MODES[d.links_render_mode],{key:"links_render_mode",values:g.LINK_RENDER_MODES},a);panel.addSeparator();panel.footer.innerHTML=""})();d.canvas.parentNode.appendChild(panel)};l.prototype.showShowNodePanel=function(a){function b(){d.content.innerHTML="";d.addHTML(""+a.type+""+(a.constructor.desc||"")+""); -d.addHTML("

Properties

");var b=function(b,c){e.graph.beforeChange(a);switch(b){case "Title":a.title=c;break;case "Mode":b=Object.values(g.NODE_MODES).indexOf(c);0<=b&&g.NODE_MODES[b]?a.changeMode(b):console.warn("unexpected mode: "+c);break;case "Color":l.node_colors[c]?(a.color=l.node_colors[c].color,a.bgcolor=l.node_colors[c].bgcolor):console.warn("unexpected color: "+c);break;default:a.setProperty(b,c)}e.graph.afterChange();e.dirty_canvas=!0};d.addWidget("string","Title",a.title,{},b); -d.addWidget("combo","Mode",g.NODE_MODES[a.mode],{values:g.NODE_MODES},b);var c="";void 0!==a.color&&(c=Object.keys(l.node_colors).filter(function(b){return l.node_colors[b].color==a.color}));d.addWidget("combo","Color",c,{values:Object.keys(l.node_colors)},b);for(var k in a.properties){c=a.properties[k];var m=a.getPropertyInfo(k);a.onAddPropertyToPanel&&a.onAddPropertyToPanel(k,d)||d.addWidget(m.widget||m.type,k,c,m,b)}d.addSeparator();if(a.onShowCustomPanelInfo)a.onShowCustomPanelInfo(d);d.footer.innerHTML= -"";d.addButton("Delete",function(){a.block_delete||(a.graph.remove(a),d.close())}).classList.add("delete")}this.SELECTED_NODE=a;this.closePanels();var c=this.getCanvasWindow(),e=this,d=this.createPanel(a.title||"",{closable:!0,window:c,onOpen:function(){e.NODEPANEL_IS_OPEN=!0},onClose:function(){e.NODEPANEL_IS_OPEN=!1;e.node_panel=null}});e.node_panel=d;d.id="node-panel";d.node=a;d.classList.add("settings");d.inner_showCodePad=function(c){d.classList.remove("settings");d.classList.add("centered"); -d.alt_content.innerHTML="";var e=d.alt_content.querySelector("textarea"),f=function(){d.toggleAltContent(!1);d.toggleFooterVisibility(!0);e.parentNode.removeChild(e);d.classList.add("settings");d.classList.remove("centered");b()};e.value=a.properties[c];e.addEventListener("keydown",function(b){"Enter"==b.code&&b.ctrlKey&&(a.setProperty(c,e.value),f())});d.toggleAltContent(!0);d.toggleFooterVisibility(!1);e.style.height="calc(100% - 40px)";var g=d.addButton("Assign", -function(){a.setProperty(c,e.value);f()});d.alt_content.appendChild(g);g=d.addButton("Close",f);g.style.float="right";d.alt_content.appendChild(g)};b();this.canvas.parentNode.appendChild(d)};l.prototype.showSubgraphPropertiesDialog=function(a){function b(){e.clear();if(a.inputs)for(var c=0;c","subgraph_property"); -g.dataset.name=f.name;g.dataset.slot=c;g.querySelector(".name").innerText=f.name;g.querySelector(".type").innerText=f.type;g.querySelector("button").addEventListener("click",function(c){a.removeInput(Number(this.parentNode.dataset.slot));b()})}}}console.log("showing subgraph properties dialog");var c=this.canvas.parentNode.querySelector(".subgraph_dialog");c&&c.close();var e=this.createPanel("Subgraph Inputs",{closable:!0,width:500});e.node=a;e.classList.add("subgraph_dialog");e.addHTML(" + NameType", -"subgraph_property extra",!0).querySelector("button").addEventListener("click",function(c){c=this.parentNode;var d=c.querySelector(".name").value,e=c.querySelector(".type").value;d&&-1==a.findInputSlot(d)&&(a.addInput(d,e),c.querySelector(".name").value="",c.querySelector(".type").value="",b())});b();this.canvas.parentNode.appendChild(e);return e};l.prototype.showSubgraphPropertiesDialogRight=function(a){function b(){d.clear();if(a.outputs)for(var c=0;c","subgraph_property");g.dataset.name=e.name;g.dataset.slot=c;g.querySelector(".name").innerText=e.name;g.querySelector(".type").innerText=e.type;g.querySelector("button").addEventListener("click",function(c){a.removeOutput(Number(this.parentNode.dataset.slot));b()})}}}function c(){var c=this.parentNode,d=c.querySelector(".name").value,e=c.querySelector(".type").value;d&&-1==a.findOutputSlot(d)&& -(a.addOutput(d,e),c.querySelector(".name").value="",c.querySelector(".type").value="",b())}var e=this.canvas.parentNode.querySelector(".subgraph_dialog");e&&e.close();var d=this.createPanel("Subgraph Outputs",{closable:!0,width:500});d.node=a;d.classList.add("subgraph_dialog");e=d.addHTML(" + NameType","subgraph_property extra",!0);e.querySelector(".name").addEventListener("keydown", -function(a){13==a.keyCode&&c.apply(this)});e.querySelector("button").addEventListener("click",function(a){c.apply(this)});b();this.canvas.parentNode.appendChild(d);return d};l.prototype.checkPanels=function(){if(this.canvas)for(var a=this.canvas.parentNode.querySelectorAll(".litegraph.dialog"),b=0;b=Object.keys(a.selected_nodes).length)d.collapse(); -else for(var f in a.selected_nodes)a.selected_nodes[f].collapse();d.graph.afterChange()};l.onMenuNodePin=function(a,b,c,e,d){d.pin()};l.onMenuNodeMode=function(a,b,c,e,d){new g.ContextMenu(g.NODE_MODES,{event:c,callback:function(a){if(d){var b=Object.values(g.NODE_MODES).indexOf(a),c=function(c){0<=b&&g.NODE_MODES[b]?c.changeMode(b):(console.warn("unexpected mode: "+a),c.changeMode(g.ALWAYS))},e=l.active_canvas;if(!e.selected_nodes||1>=Object.keys(e.selected_nodes).length)c(d);else for(var f in e.selected_nodes)c(e.selected_nodes[f])}}, -parentMenu:e,node:d});return!1};l.onMenuNodeColors=function(a,b,c,e,d){if(!d)throw"no node for color";b=[];b.push({value:null,content:"No color"});for(var f in l.node_colors)a=l.node_colors[f],a={value:f,content:""+f+""},b.push(a);new g.ContextMenu(b,{event:c,callback:function(a){if(d){var b=a.value?l.node_colors[a.value]: -null;a=function(a){b?a.constructor===g.LGraphGroup?a.color=b.groupcolor:(a.color=b.color,a.bgcolor=b.bgcolor):(delete a.color,delete a.bgcolor)};var c=l.active_canvas;if(!c.selected_nodes||1>=Object.keys(c.selected_nodes).length)a(d);else for(var e in c.selected_nodes)a(c.selected_nodes[e]);d.setDirtyCanvas(!0,!0)}},parentMenu:e,node:d});return!1};l.onMenuNodeShapes=function(a,b,c,e,d){if(!d)throw"no node passed";new g.ContextMenu(g.VALID_SHAPES,{event:c,callback:function(a){if(d){d.graph.beforeChange(); -var b=l.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)d.shape=a;else for(var c in b.selected_nodes)b.selected_nodes[c].shape=a;d.graph.afterChange();d.setDirtyCanvas(!0)}},parentMenu:e,node:d});return!1};l.onMenuNodeRemove=function(a,b,c,e,d){if(!d)throw"no node passed";a=d.graph;a.beforeChange();b=l.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)!1!==d.removable&&a.remove(d);else for(var f in b.selected_nodes)c=b.selected_nodes[f],!1!==c.removable&& -a.remove(c);a.afterChange();d.setDirtyCanvas(!0,!0)};l.onMenuNodeToSubgraph=function(a,b,c,e,d){a=d.graph;if(b=l.active_canvas)c=Object.values(b.selected_nodes||{}),c.length||(c=[d]),e=g.createNode("graph/subgraph"),e.pos=d.pos.concat(),a.add(e),e.buildFromNodes(c),b.deselectAllNodes(),d.setDirtyCanvas(!0,!0)};l.onMenuNodeClone=function(a,b,c,e,d){d.graph.beforeChange();var f={};a=function(a){if(!1!==a.clonable){var b=a.clone();b&&(b.pos=[a.pos[0]+5,a.pos[1]+5],a.graph.add(b),f[b.id]=b)}};b=l.active_canvas; -if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)a(d);else for(var g in b.selected_nodes)a(b.selected_nodes[g]);Object.keys(f).length&&b.selectNodes(f);d.graph.afterChange();d.setDirtyCanvas(!0,!0)};l.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"}};l.prototype.getCanvasMenuOptions=function(){if(this.getMenuOptions)var a=this.getMenuOptions();else a=[{content:"Add Node",has_submenu:!0,callback:l.onMenuAdd},{content:"Add Group",callback:l.onGroupAdd}],1Name", -d),h=g.querySelector("input");h&&f&&(h.value=f.label||"");var k=function(){a.graph.beforeChange();h.value&&(f&&(f.label=h.value),c.setDirty(!0));g.close();a.graph.afterChange()};g.querySelector("button").addEventListener("click",k);h.addEventListener("keydown",function(a){g.is_modified=!0;if(27==a.keyCode)g.close();else if(13==a.keyCode)k();else if(13!=a.keyCode&&"textarea"!=a.target.localName)return;a.preventDefault();a.stopPropagation()});h.focus()}},extra:a};a&&(f.title=a.type);var h=null;a&&(h= -a.getSlotInPosition(b.canvasX,b.canvasY),l.active_node=a);h?(d=[],a.getSlotMenuOptions?d=a.getSlotMenuOptions(h):(h&&h.output&&h.output.links&&h.output.links.length&&d.push({content:"Disconnect Links",slot:h}),b=h.input||h.output,b.removable&&d.push(b.locked?"Cannot remove":{content:"Remove Slot",slot:h}),b.nameLocked||d.push({content:"Rename Slot",slot:h})),f.title=(h.input?h.input.type:h.output.type)||"*",h.input&&h.input.type==g.ACTION&&(f.title="Action"),h.output&&h.output.type==g.EVENT&&(f.title= -"Event")):a?d=this.getNodeMenuOptions(a):(d=this.getCanvasMenuOptions(),(h=this.graph.getGroupOnPos(b.canvasX,b.canvasY))&&d.push(null,{content:"Edit Group",has_submenu:!0,submenu:{title:"Group",extra:h,options:this.getGroupMenuOptions(h)}}));d&&new g.ContextMenu(d,f,e)};g.compareObjects=function(a,b){for(var c in a)if(a[c]!=b[c])return!1;return!0};g.distance=J;g.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")+")"};g.isInsideRectangle=C;g.growBounding=function(a,b,c){ba[2]&&(a[2]=b);ca[3]&&(a[3]=c)};g.isInsideBounding=function(a,b){return a[0]b[1][0]||a[1]>b[1][1]?!1:!0};g.overlapBounding=H;g.hex2num=function(a){"#"==a.charAt(0)&&(a=a.slice(1));a=a.toUpperCase();for(var b=Array(3),c=0,e,d,f=0;6>f;f+=2)e="0123456789ABCDEF".indexOf(a.charAt(f)),d="0123456789ABCDEF".indexOf(a.charAt(f+1)),b[c]=16*e+d,c++;return b}; -g.num2hex=function(a){for(var b="#",c,e,d=0;3>d;d++)c=a[d]/16,e=a[d]%16,b+="0123456789ABCDEF".charAt(c)+"0123456789ABCDEF".charAt(e);return b};F.prototype.addItem=function(a,b,c){function e(a){var b=this.value;b&&b.has_submenu&&d.call(this,a)}function d(a){var b=this.value,d=!0;f.current_submenu&&f.current_submenu.close(a);if(c.callback){var e=c.callback.call(this,b,c,a,f,c.node);!0===e&&(d=!1)}if(b&&(b.callback&&!c.ignore_item_callbacks&&!0!==b.disabled&&(e=b.callback.call(this,b,c,a,f,c.extra), -!0===e&&(d=!1)),b.submenu)){if(!b.submenu.options)throw"ContextMenu submenu needs options";new f.constructor(b.submenu.options,{callback:b.submenu.callback,event:a,parentMenu:f,ignore_item_callbacks:b.submenu.ignore_item_callbacks,title:b.submenu.title,extra:b.submenu.extra,autoopen:c.autoopen});d=!1}d&&!f.lock&&f.close()}var f=this;c=c||{};var h=document.createElement("div");h.className="litemenu-entry submenu";var k=!1;if(null===b)h.classList.add("separator");else{h.innerHTML=b&&b.title?b.title: -a;if(h.value=b)b.disabled&&(k=!0,h.classList.add("disabled")),(b.submenu||b.has_submenu)&&h.classList.add("has_submenu");"function"==typeof b?(h.dataset.value=a,h.onclick_callback=b):h.dataset.value=b;b.className&&(h.className+=" "+b.className)}this.root.appendChild(h);k||h.addEventListener("click",d);!k&&c.autoopen&&g.pointerListenerAdd(h,"enter",e);return h};F.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&&!F.isCursorOverElement(a,this.parentMenu.root)&&F.trigger(this.parentMenu.root,g.pointerevents_method+"leave",a));this.current_submenu&&this.current_submenu.close(a,!0);this.root.closing_timer&&clearTimeout(this.root.closing_timer)};F.trigger=function(a,b,c,e){var d=document.createEvent("CustomEvent");d.initCustomEvent(b,!0,!0,c);d.srcElement=e;a.dispatchEvent?a.dispatchEvent(d):a.__events&&a.__events.dispatchEvent(d);return d}; -F.prototype.getTopMenu=function(){return this.options.parentMenu?this.options.parentMenu.getTopMenu():this};F.prototype.getFirstEvent=function(){return this.options.parentMenu?this.options.parentMenu.getFirstEvent():this.options.event};F.isCursorOverElement=function(a,b){var c=a.clientX;a=a.clientY;return(b=b.getBoundingClientRect())?a>b.top&&ab.left&&cMath.abs(b))return e[1];a=(a-e[0])/b;return e[1]*(1-a)+d[1]*a}}return 0}};G.prototype.draw=function(a,b,c,e,d,f){if(c=this.points){this.size=b;var g=b[0]-2*this.margin;b=b[1]-2*this.margin;d=d||"#666";a.save();a.translate(this.margin,this.margin);e&&(a.fillStyle="#111",a.fillRect(0,0,g,b),a.fillStyle="#222",a.fillRect(.5*g,0,1,b),a.strokeStyle="#333", -a.strokeRect(0,0,g,b));a.strokeStyle=d;f&&(a.globalAlpha=.5);a.beginPath();for(e=0;ea[1])){var e=this.size[0]-2*this.margin,d=this.size[1]-2*this.margin,f=a[0]-this.margin;a=a[1]-this.margin; -this.selected=this.getCloserPoint([f,a],30/b.ds.scale);-1==this.selected&&(b=[f/e,1-a/d],c.push(b),c.sort(function(a,b){return a[0]-b[0]}),this.selected=c.indexOf(b),this.must_update=!0);if(-1!=this.selected)return!0}};G.prototype.onMouseMove=function(a,b){var c=this.points;if(c){var e=this.selected;if(!(0>e)){var d=(a[0]-this.margin)/(this.size[0]-2*this.margin),f=(a[1]-this.margin)/(this.size[1]-2*this.margin);this._nearest=this.getCloserPoint([a[0]-this.margin,a[1]-this.margin],30/b.ds.scale); -if(b=c[e]){var g=0==e||e==c.length-1;!g&&(-10>a[0]||a[0]>this.size[0]+10||-10>a[1]||a[1]>this.size[1]+10)?(c.splice(e,1),this.selected=-1):(b[0]=g?0==e?0:1:K(d,0,1),b[1]=1-K(f,0,1),c.sort(function(a,b){return a[0]-b[0]}),this.selected=c.indexOf(b),this.must_update=!0)}}}};G.prototype.onMouseUp=function(a,b){this.selected=-1;return!1};G.prototype.getCloserPoint=function(a,b){var c=this.points;if(!c)return-1;b=b||30;for(var e=this.size[0]-2*this.margin,d=this.size[1]-2*this.margin,f=c.length,g=[0,0], -k=1E6,l=-1,m=0;mk||p>b||(l=m,k=p)}return l};g.CurveEditor=G;g.getParameterNames=function(a){return(a+"").replace(/[/][/].*$/gm,"").replace(/\s+/g,"").replace(/[/][*][^/*]*[*][/]/g,"").split("){",1)[0].replace(/^[^(]*[(]/,"").replace(/=[^,]+/g,"").split(",").filter(Boolean)};g.pointerListenerAdd=function(a,b,c,e){e=void 0===e?!1:e;if(a&&a.addEventListener&&b&&"function"===typeof c){var d=g.pointerevents_method;if("pointer"==d&&!window.PointerEvent)switch(console.warn("sMethod=='pointer' && !window.PointerEvent"), -console.log("Converting pointer["+b+"] : down move up cancel enter TO touchstart touchmove touchend, etc .."),b){case "down":d="touch";b="start";break;case "move":d="touch";break;case "up":d="touch";b="end";break;case "cancel":d="touch";break;case "enter":console.log("debug: Should I send a move event?");break;default:console.warn("PointerEvent not available in this browser ? The event "+b+" would not be called")}switch(b){case "down":case "up":case "move":case "over":case "out":case "enter":a.addEventListener(d+ -b,c,e);case "leave":case "cancel":case "gotpointercapture":case "lostpointercapture":if("mouse"!=d)return a.addEventListener(d+b,c,e);default:return a.addEventListener(b,c,e)}}};g.pointerListenerRemove=function(a,b,c,e){e=void 0===e?!1:e;if(a&&a.removeEventListener&&b&&"function"===typeof c)switch(b){case "down":case "up":case "move":case "over":case "out":case "enter":"pointer"!=g.pointerevents_method&&"mouse"!=g.pointerevents_method||a.removeEventListener(g.pointerevents_method+b,c,e);case "leave":case "cancel":case "gotpointercapture":case "lostpointercapture":if("pointer"== -g.pointerevents_method)return a.removeEventListener(g.pointerevents_method+b,c,e);default:return a.removeEventListener(b,c,e)}};t.clamp=K;"undefined"==typeof window||window.requestAnimationFrame||(window.requestAnimationFrame=window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(a){window.setTimeout(a,1E3/60)})})(this); +a.type&&(32==a.keyCode&&(this.dragging_canvas=!1),this.selected_nodes))for(c in this.selected_nodes)if(this.selected_nodes[c].onKeyUp)this.selected_nodes[c].onKeyUp(a);this.graph.change();if(b)return a.preventDefault(),a.stopImmediatePropagation(),!1}}};q.prototype.copyToClipboard=function(){var a={nodes:[],links:[]},b=0,c=[],d;for(d in this.selected_nodes){var e=this.selected_nodes[d];!1!==e.clonable&&(e._relative_id=b,c.push(e),b+=1)}for(d=0;db.nodes[d].pos[0]&&(c[0]=b.nodes[d].pos[0]),c[1]>b.nodes[d].pos[1]&&(c[1]=b.nodes[d].pos[1])):c=[b.nodes[d].pos[0],b.nodes[d].pos[1]];var e=[];for(d=0;d=this.viewport[0]&&b=this.viewport[1]&&cc-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}};q.prototype.drawFrontCanvas=function(){this.dirty_canvas=!1;this.ctx||(this.ctx=this.bgcanvas.getContext("2d"));var a=this.ctx;if(a){var b=this.canvas;a.start2D&& +!this.viewport&&(a.start2D(),a.restore(),a.setTransform(1,0,0,1,0,0));var c=this.viewport||this.dirty_area;c&&(a.save(),a.beginPath(),a.rect(c[0],c[1],c[2],c[3]),a.clip());this.clear_background&&(c?a.clearRect(c[0],c[1],c[2],c[3]):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,c?c[0]:0,c?c[1]:0);if(this.graph){a.save();this.ds.toCanvasContext(a);b=this.computeVisibleNodes(null, +this.visible_nodes);for(var d=0;d> ";b.fillText(d+c.getTitle(),.5*a.width,40);b.restore()}c=!1;this.onRenderBackground&&(c=this.onRenderBackground(a,b));this.viewport||(b.restore(),b.setTransform(1,0,0,1,0,0));this.visible_links.length=0;if(this.graph){b.save();this.ds.toCanvasContext(b);1.5>this.ds.scale&&!c&&this.clear_background_color&&(b.fillStyle=this.clear_background_color,b.fillRect(this.visible_area[0],this.visible_area[1],this.visible_area[2],this.visible_area[3]));if(this.background_image&&.5this.ds.scale;if(this.live_mode){if(!a.flags.collapsed&&(b.shadowColor="transparent",a.onDrawForeground))a.onDrawForeground(b,this,this.canvas)}else{var f=this.editor_alpha;b.globalAlpha=f;this.render_shadows&&!e?(b.shadowColor=h.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||1!=a.onDrawCollapsed(b,this)){var g=a._shape||h.BOX_SHAPE; +N.set(a.size);var k=a.horizontal;if(a.flags.collapsed){b.font=this.inner_text_font;var m=a.getTitle?a.getTitle():a.title;null!=m&&(a._collapsed_width=Math.min(a.size[0],b.measureText(m).width+2*h.NODE_TITLE_HEIGHT),N[0]=a._collapsed_width,N[1]=0)}a.clip_area&&(b.save(),b.beginPath(),g==h.BOX_SHAPE?b.rect(0,0,N[0],N[1]):g==h.ROUND_SHAPE?b.roundRect(0,0,N[0],N[1],[10]):g==h.CIRCLE_SHAPE&&b.arc(.5*N[0],.5*N[1],.5*N[0],0,2*Math.PI),b.clip());a.has_errors&&(d="red");this.drawNodeShape(a,b,N,c,d,a.is_selected, +a.mouseOver);b.shadowColor="transparent";if(a.onDrawForeground)a.onDrawForeground(b,this,this.canvas);b.textAlign=k?"center":"left";b.font=this.inner_text_font;d=!e;var l=this.connecting_output;g=this.connecting_input;b.lineWidth=1;m=0;var n=new Float32Array(2);if(!a.flags.collapsed){if(a.inputs)for(c=0;cthis.ds.scale,m=a._shape||a.constructor.shape||h.ROUND_SHAPE,l=a.constructor.title_mode,n=!0;l==h.TRANSPARENT_TITLE||l==h.NO_TITLE?n=!1:l==h.AUTOHIDE_TITLE&& +g&&(n=!0);C[0]=0;C[1]=n?-e:0;C[2]=c[0]+1;C[3]=n?c[1]+e:c[1];g=b.globalAlpha;b.beginPath();m==h.BOX_SHAPE||k?b.fillRect(C[0],C[1],C[2],C[3]):m==h.ROUND_SHAPE||m==h.CARD_SHAPE?b.roundRect(C[0],C[1],C[2],C[3],m==h.CARD_SHAPE?[this.round_radius,this.round_radius,0,0]:[this.round_radius]):m==h.CIRCLE_SHAPE&&b.arc(.5*c[0],.5*c[1],.5*c[0],0,2*Math.PI);b.fill();!a.flags.collapsed&&n&&(b.shadowColor="transparent",b.fillStyle="rgba(0,0,0,0.2)",b.fillRect(0,-1,C[2],2));b.shadowColor="transparent";if(a.onDrawBackground)a.onDrawBackground(b, +this,this.canvas,this.graph_mouse);if(n||l==h.TRANSPARENT_TITLE){if(a.onDrawTitleBar)a.onDrawTitleBar(b,e,c,this.ds.scale,d);else if(l!=h.TRANSPARENT_TITLE&&(a.constructor.title_color||this.render_title_colored)){n=a.constructor.title_color||d;a.flags.collapsed&&(b.shadowColor=h.DEFAULT_SHADOW_COLOR);if(this.use_gradients){var p=q.gradients[n];p||(p=q.gradients[n]=b.createLinearGradient(0,0,400,0),p.addColorStop(0,n),p.addColorStop(1,"#000"));b.fillStyle=p}else b.fillStyle=n;b.beginPath();m==h.BOX_SHAPE|| +k?b.rect(0,-e,c[0]+1,e):(m==h.ROUND_SHAPE||m==h.CARD_SHAPE)&&b.roundRect(0,-e,c[0]+1,e,a.flags.collapsed?[this.round_radius]:[this.round_radius,this.round_radius,0,0]);b.fill();b.shadowColor="transparent"}n=!1;h.node_box_coloured_by_mode&&h.NODE_MODES_COLORS[a.mode]&&(n=h.NODE_MODES_COLORS[a.mode]);h.node_box_coloured_when_on&&(n=a.action_triggered?"#FFF":a.execute_triggered?"#AAA":n);if(a.onDrawTitleBox)a.onDrawTitleBox(b,e,c,this.ds.scale);else m==h.ROUND_SHAPE||m==h.CIRCLE_SHAPE||m==h.CARD_SHAPE? +(k&&(b.fillStyle="black",b.beginPath(),b.arc(.5*e,-.5*e,6,0,2*Math.PI),b.fill()),b.fillStyle=a.boxcolor||n||h.NODE_DEFAULT_BOXCOLOR,k?b.fillRect(.5*e-5,-.5*e-5,10,10):(b.beginPath(),b.arc(.5*e,-.5*e,5,0,2*Math.PI),b.fill())):(k&&(b.fillStyle="black",b.fillRect(.5*(e-10)-1,-.5*(e+10)-1,12,12)),b.fillStyle=a.boxcolor||n||h.NODE_DEFAULT_BOXCOLOR,b.fillRect(.5*(e-10),-.5*(e+10),10,10));b.globalAlpha=g;if(a.onDrawTitleText)a.onDrawTitleText(b,e,c,this.ds.scale,this.title_text_font,f);!k&&(b.font=this.title_text_font, +g=String(a.getTitle()))&&(b.fillStyle=f?h.NODE_SELECTED_TITLE_COLOR:a.constructor.title_text_color||this.node_title_color,a.flags.collapsed?(b.textAlign="left",b.measureText(g),b.fillText(g.substr(0,20),e,h.NODE_TITLE_TEXT_Y-e),b.textAlign="left"):(b.textAlign="left",b.fillText(g,e,h.NODE_TITLE_TEXT_Y-e)));a.flags.collapsed||!a.subgraph||a.skip_subgraph_button||(g=h.NODE_TITLE_HEIGHT,n=a.size[0]-g,p=h.isInsideRectangle(this.graph_mouse[0]-a.pos[0],this.graph_mouse[1]-a.pos[1],n+2,-g+2,g-4,g-4),b.fillStyle= +p?"#888":"#555",m==h.BOX_SHAPE||k?b.fillRect(n+2,-g+2,g-4,g-4):(b.beginPath(),b.roundRect(n+2,-g+2,g-4,g-4,[4]),b.fill()),b.fillStyle="#333",b.beginPath(),b.moveTo(n+.2*g,.6*-g),b.lineTo(n+.8*g,.6*-g),b.lineTo(n+.5*g,.3*-g),b.fill());if(a.onDrawTitle)a.onDrawTitle(b)}if(f){if(a.onBounding)a.onBounding(C);l==h.TRANSPARENT_TITLE&&(C[1]-=e,C[3]+=e);b.lineWidth=1;b.globalAlpha=.8;b.beginPath();m==h.BOX_SHAPE?b.rect(-6+C[0],-6+C[1],12+C[2],12+C[3]):m==h.ROUND_SHAPE||m==h.CARD_SHAPE&&a.flags.collapsed? +b.roundRect(-6+C[0],-6+C[1],12+C[2],12+C[3],[2*this.round_radius]):m==h.CARD_SHAPE?b.roundRect(-6+C[0],-6+C[1],12+C[2],12+C[3],[2*this.round_radius,2,2*this.round_radius,2]):m==h.CIRCLE_SHAPE&&b.arc(.5*c[0],.5*c[1],.5*c[0]+6,0,2*Math.PI);b.strokeStyle=h.NODE_BOX_OUTLINE_COLOR;b.stroke();b.strokeStyle=d;b.globalAlpha=1}0H[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(Z(H,aa)){var r=m.outputs[l];l=f.inputs[g];if(r&&l&&(m=r.dir||(m.horizontal?h.DOWN:h.RIGHT),l=l.dir||(f.horizontal?h.UP:h.LEFT),this.renderLink(a,n,p,k,!1,0,null,m,l),k&&k._last_time&&1E3>b-k._last_time)){r=2-.002*(b-k._last_time);var u=a.globalAlpha;a.globalAlpha=u* +r;this.renderLink(a,n,p,k,!0,r,"white",m,l);a.globalAlpha=u}}}}}}a.globalAlpha=1};q.prototype.renderLink=function(a,b,c,d,e,f,g,k,m,l){d&&this.visible_links.push(d);!g&&d&&(g=d.color||q.link_type_colors[d.type]);g||(g=this.default_link_color);null!=d&&this.highlighted_links[d.id]&&(g="#FFF");k=k||h.RIGHT;m=m||h.LEFT;var n=ba(b,c);this.render_connections_border&&.6b[1]?0:Math.PI,a.save(),a.translate(p[0],p[1]),a.rotate(n),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore(),a.save(),a.translate(d[0],d[1]),a.rotate(l),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore()),a.beginPath(),a.arc(e[0],e[1],5,0,2*Math.PI),a.fill());if(f)for(a.fillStyle=g,p=0;5>p;++p)f=(.001*h.getTime()+.2*p)%1,e=this.computeConnectionPoint(b,c,f,k, +m),a.beginPath(),a.arc(e[0],e[1],5,0,2*Math.PI),a.fill()};q.prototype.computeConnectionPoint=function(a,b,c,d,e){d=d||h.RIGHT;e=e||h.LEFT;var f=ba(a,b),g=[a[0],a[1]],k=[b[0],b[1]];switch(d){case h.LEFT:g[0]+=-.25*f;break;case h.RIGHT:g[0]+=.25*f;break;case h.UP:g[1]+=-.25*f;break;case h.DOWN:g[1]+=.25*f}switch(e){case h.LEFT:k[0]+=-.25*f;break;case h.RIGHT:k[0]+=.25*f;break;case h.UP:k[1]+=-.25*f;break;case h.DOWN:k[1]+=.25*f}d=(1-c)*(1-c)*(1-c);e=3*(1-c)*(1-c)*c;f=3*(1-c)*c*c;c*=c*c;return[d*a[0]+ +e*g[0]+f*k[0]+c*b[0],d*a[1]+e*g[1]+f*k[1]+c*b[1]]};q.prototype.drawExecutionOrder=function(a){a.shadowColor="transparent";a.globalAlpha=.25;a.textAlign="center";a.strokeStyle="white";a.globalAlpha=.75;for(var b=this.visible_nodes,c=0;cB&&(B=0);1z&&(z=0),1f||f>t-12||gr.last_y+u||void 0===r.last_y)){d=r.value;switch(r.type){case "button":c.type===h.pointerevents_method+"down"&&(r.callback&&setTimeout(function(){r.callback(r,l,a,b,c)},20),this.dirty_canvas=r.clicked=!0);break;case "slider":d= +r.value;n=ca((f-15)/(t-30),0,1);if(r.options.read_only)break;r.value=r.options.min+(r.options.max-r.options.min)*n;d!=r.value&&setTimeout(function(){e(r,r.value)},20);this.dirty_canvas=!0;break;case "number":case "combo":d=r.value;if(c.type==h.pointerevents_method+"move"&&"number"==r.type)m&&(r.value+=.1*m*(r.options.step||1)),null!=r.options.min&&r.valuer.options.max&&(r.value=r.options.max);else if(c.type==h.pointerevents_method+ +"down"){var x=r.options.values;x&&x.constructor===Function&&(x=r.options.values(r,a));var z=null;"number"!=r.type&&(z=x.constructor===Array?x:Object.keys(x));f=40>f?-1:f>t-40?1:0;if("number"==r.type)r.value+=.1*f*(r.options.step||1),null!=r.options.min&&r.valuer.options.max&&(r.value=r.options.max);else if(f)n=-1,this.last_mouseclick=0,n=x.constructor===Object?z.indexOf(String(r.value))+f:z.indexOf(r.value)+f,n>=z.length&&(n=z.length- +1),0>n&&(n=0),r.value=x.constructor===Array?x[n]:n;else{var B=x!=z?Object.values(x):x;new h.ContextMenu(B,{scale:Math.max(1,this.ds.scale),event:c,className:"dark",callback:E.bind(r)},n);function E(F,da,M){x!=z&&(F=B.indexOf(F));this.value=F;e(this,F);l.dirty_canvas=!0;return!1}}}else c.type==h.pointerevents_method+"up"&&"number"==r.type&&(f=40>f?-1:f>t-40?1:0,200>c.click_time&&0==f&&this.prompt("Value",r.value,function(E){if(/^[0-9+\-*/()\s]+|\d+\.\d+$/.test(E))try{E=eval(E)}catch(F){}this.value= +Number(E);e(this,this.value)}.bind(r),c));d!=r.value&&setTimeout(function(){e(this,this.value)}.bind(r),20);this.dirty_canvas=!0;break;case "toggle":c.type==h.pointerevents_method+"down"&&(r.value=!r.value,setTimeout(function(){e(r,r.value)},20));break;case "string":case "text":c.type==h.pointerevents_method+"down"&&this.prompt("Value",r.value,function(E){e(this,E)}.bind(r),c,r.options?r.options.multiline:!1);break;default:r.mouse&&(this.dirty_canvas=r.mouse(c,[f,g],a))}if(d!=r.value){if(a.onWidgetChanged)a.onWidgetChanged(r.name, +r.value,d,r);a.graph._version++}return r}}}return null};q.prototype.drawGroups=function(a,b){if(this.graph){a=this.graph._groups;b.save();b.globalAlpha=.5*this.editor_alpha;for(var c=0;cc&&.01>b.editor_alpha&&(clearInterval(d),1>c&&(b.live_mode=!0));1c.pos[0]+c.size[0])c=g;if(null===d||m+n>d.pos[1]+d.size[1])d=g;if(null===e||k"+(m.label?m.label:k)+""+a+"",value:k})}if(g.length)return new h.ContextMenu(g,{event:c,callback:function(l,n,p,r){e&&(n=this.getBoundingClientRect(),f.showEditPropertyValue(e,l.value,{position:[n.left,n.top]}))},parentMenu:d,allow_html:!0, +node:e},b),!1}};q.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};q.onMenuResizeNode=function(a,b,c,d,e){if(e){a=function(g){g.size=g.computeSize();if(g.onResize)g.onResize(g.size)};b=q.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)a(e);else for(var f in b.selected_nodes)a(b.selected_nodes[f]);e.setDirtyCanvas(!0,!0)}};q.prototype.showLinkMenu=function(a,b){var c=this,d=c.graph.getNodeById(a.origin_id),e=c.graph.getNodeById(a.target_id), +f=!1;d&&d.outputs&&d.outputs[a.origin_slot]&&(f=d.outputs[a.origin_slot].type);var g=!1;e&&e.outputs&&e.outputs[a.target_slot]&&(g=e.inputs[a.target_slot].type);var k=new h.ContextMenu(["Add Node",null,"Delete",null],{event:b,title:null!=a.data?a.data.constructor.name:null,callback:function(m,l,n){switch(m){case "Add Node":q.onMenuAdd(null,null,n,k,function(p){p.inputs&&p.inputs.length&&p.outputs&&p.outputs.length&&d.connectByType(a.origin_slot,p,f)&&(p.connectByType(a.target_slot,e,g),p.pos[0]-= +.5*p.size[0])});break;case "Delete":c.graph.removeLink(a.id)}}});return!1};q.prototype.createDefaultNodeForSlot=function(a){a=a||{};a=Object.assign({nodeFrom:null,slotFrom:null,nodeTo:null,slotTo:null,position:[],nodeType:null,posAdd:[0,0],posSizeFix:[0,0]},a);var b=a.nodeFrom&&null!==a.slotFrom,c=!b&&a.nodeTo&&null!==a.slotTo;if(!b&&!c)return console.warn("No data passed to createDefaultNodeForSlot "+a.nodeFrom+" "+a.slotFrom+" "+a.nodeTo+" "+a.slotTo),!1;if(!a.nodeType)return console.warn("No type to createDefaultNodeForSlot"), +!1;var d=b?a.nodeFrom:a.nodeTo,e=b?a.slotFrom:a.slotTo;switch(typeof e){case "string":c=b?d.findOutputSlot(e,!1):d.findInputSlot(e,!1);e=b?d.outputs[e]:d.inputs[e];break;case "object":c=b?d.findOutputSlot(e.name):d.findInputSlot(e.name);break;case "number":c=e;e=b?d.outputs[e]:d.inputs[e];break;default:return console.warn("Cant get slot information "+e),!1}!1!==e&&!1!==c||console.warn("createDefaultNodeForSlot bad slotX "+e+" "+c);d=e.type==h.EVENT?"_event_":e.type;if((e=b?h.slot_types_default_out: +h.slot_types_default_in)&&e[d]){nodeNewType=!1;if("object"==typeof e[d]||"array"==typeof e[d])for(var f in e[d]){if(a.nodeType==e[d][f]||"AUTO"==a.nodeType){nodeNewType=e[d][f];break}}else if(a.nodeType==e[d]||"AUTO"==a.nodeType)nodeNewType=e[d];if(nodeNewType){f=!1;"object"==typeof nodeNewType&&nodeNewType.node&&(f=nodeNewType,nodeNewType=nodeNewType.node);if(e=h.createNode(nodeNewType)){if(f){if(f.properties)for(var g in f.properties)e.addProperty(g,f.properties[g]);if(f.inputs)for(g in e.inputs= +[],f.inputs)e.addOutput(f.inputs[g][0],f.inputs[g][1]);if(f.outputs)for(g in e.outputs=[],f.outputs)e.addOutput(f.outputs[g][0],f.outputs[g][1]);f.title&&(e.title=f.title);f.json&&e.configure(f.json)}this.graph.add(e);e.pos=[a.position[0]+a.posAdd[0]+(a.posSizeFix[0]?a.posSizeFix[0]*e.size[0]:0),a.position[1]+a.posAdd[1]+(a.posSizeFix[1]?a.posSizeFix[1]*e.size[1]:0)];b?a.nodeFrom.connectByType(c,e,d):a.nodeTo.connectByTypeOutput(c,e,d);return!0}console.log("failed creating "+nodeNewType)}}return!1}; +q.prototype.showConnectionMenu=function(a){a=a||{};var b=Object.assign({nodeFrom:null,slotFrom:null,nodeTo:null,slotTo:null,e:null},a),c=this,d=b.nodeFrom&&b.slotFrom;a=!d&&b.nodeTo&&b.slotTo;if(!d&&!a)return console.warn("No data passed to showConnectionMenu"),!1;a=d?b.nodeFrom:b.nodeTo;var e=d?b.slotFrom:b.slotTo,f=!1;switch(typeof e){case "string":f=d?a.findOutputSlot(e,!1):a.findInputSlot(e,!1);e=d?a.outputs[e]:a.inputs[e];break;case "object":f=d?a.findOutputSlot(e.name):a.findInputSlot(e.name); +break;case "number":f=e;e=d?a.outputs[e]:a.inputs[e];break;default:return console.warn("Cant get slot information "+e),!1}a=["Add Node",null];c.allow_searchbox&&(a.push("Search"),a.push(null));var g=e.type==h.EVENT?"_event_":e.type,k=d?h.slot_types_default_out:h.slot_types_default_in;if(k&&k[g])if("object"==typeof k[g]||"array"==typeof k[g])for(var m in k[g])a.push(k[g][m]);else a.push(k[g]);var l=new h.ContextMenu(a,{event:b.e,title:(e&&""!=e.name?e.name+(g?" | ":""):"")+(e&&g?g:""),callback:function(n, +p,r){switch(n){case "Add Node":q.onMenuAdd(null,null,r,l,function(u){d?b.nodeFrom.connectByType(f,u,g):b.nodeTo.connectByTypeOutput(f,u,g)});break;case "Search":d?c.showSearchBox(r,{node_from:b.nodeFrom,slot_from:e,type_filter_in:g}):c.showSearchBox(r,{node_to:b.nodeTo,slot_from:e,type_filter_out:g});break;default:c.createDefaultNodeForSlot(Object.assign(b,{position:[b.e.canvasX,b.e.canvasY],nodeType:n}))}}});return!1};q.onShowPropertyEditor=function(a,b,c,d,e){function f(){if(m){var p=m.value;"Number"== +a.type?p=Number(p):"Boolean"==a.type&&(p=!!p);e[g]=p;k.parentNode&&k.parentNode.removeChild(k);e.setDirtyCanvas(!0,!0)}}var g=a.property||"title";b=e[g];var k=document.createElement("div");k.is_modified=!1;k.className="graphdialog";k.innerHTML="";k.close=function(){k.parentNode&&k.parentNode.removeChild(k)};k.querySelector(".name").innerText=g;var m=k.querySelector(".value");m&&(m.value=b,m.addEventListener("blur", +function(p){this.focus()}),m.addEventListener("keydown",function(p){k.is_modified=!0;if(27==p.keyCode)k.close();else if(13==p.keyCode)f();else if(13!=p.keyCode&&"textarea"!=p.target.localName)return;p.preventDefault();p.stopPropagation()}));b=q.active_canvas.canvas;c=b.getBoundingClientRect();var l=d=-20;c&&(d-=c.left,l-=c.top);event?(k.style.left=event.clientX+d+"px",k.style.top=event.clientY+l+"px"):(k.style.left=.5*b.width+d+"px",k.style.top=.5*b.height+l+"px");k.querySelector("button").addEventListener("click", +f);b.parentNode.appendChild(k);m&&m.focus();var n=null;k.addEventListener("mouseleave",function(p){h.dialog_close_on_mouse_leave&&!k.is_modified&&h.dialog_close_on_mouse_leave&&(n=setTimeout(k.close,h.dialog_close_on_mouse_leave_delay))});k.addEventListener("mouseenter",function(p){h.dialog_close_on_mouse_leave&&n&&clearTimeout(n)})};q.prototype.prompt=function(a,b,c,d,e){var f=this;a=a||"";var g=document.createElement("div");g.is_modified=!1;g.className="graphdialog rounded";g.innerHTML=e?" ": +" ";g.close=function(){f.prompt_box=null;g.parentNode&&g.parentNode.removeChild(g)};e=q.active_canvas.canvas;e.parentNode.appendChild(g);1q.search_limit))break}}O=null;if(Array.prototype.filter)O=Object.keys(h.registered_node_types).filter(R);else for(D in O=[],h.registered_node_types)R(D)&&O.push(D);for(D=0;Dq.search_limit);D++);if(b.show_general_after_typefiltered&&(V.value||W.value)){filtered_extra=[];for(D in h.registered_node_types)R(D,{inTypeOverride:V&&V.value?"*":!1,outTypeOverride:W&&W.value? +"*":!1})&&filtered_extra.push(D);for(D=0;Dq.search_limit);D++);}if((V.value||W.value)&&0==t.childNodes.length&&b.show_general_if_none_on_typefilter){filtered_extra=[];for(D in h.registered_node_types)R(D,{skipFilter:!0})&&filtered_extra.push(D);for(D=0;Dq.search_limit);D++);}function R(U,J){J=J||{};J=Object.assign({skipFilter:!1, +inTypeOverride:!1,outTypeOverride:!1},J);var G=h.registered_node_types[U];if(ea&&G.filter!=ea||(!b.show_all_if_empty||y)&&-1===U.toLowerCase().indexOf(y))return!1;if(b.do_type_filter&&!J.skipFilter){G=V.value;!1!==J.inTypeOverride&&(G=J.inTypeOverride);if(V&&G&&h.registered_slot_in_types[G]&&h.registered_slot_in_types[G].nodes&&(G=h.registered_slot_in_types[G].nodes.includes(U),!1===G))return!1;G=W.value;!1!==J.outTypeOverride&&(G=J.outTypeOverride);if(W&&G&&h.registered_slot_out_types[G]&&h.registered_slot_out_types[G].nodes&& +(G=h.registered_slot_out_types[G].nodes.includes(U),!1===G))return!1}return!0}}}b=Object.assign({slot_from:null,node_from:null,node_to:null,do_type_filter:h.search_filter_enabled,type_filter_in:!1,type_filter_out:!1,show_general_if_none_on_typefilter:!0,show_general_after_typefiltered:!0,hide_on_mouse_leave:h.search_hide_on_mouse_leave,show_all_if_empty:!0,show_all_on_open:h.search_show_all_on_open},b||{});var f=this,g=q.active_canvas,k=g.canvas,m=k.ownerDocument||document,l=document.createElement("div"); +l.className="litegraph litesearchbox graphdialog rounded";l.innerHTML="Search ";b.do_type_filter&&(l.innerHTML+="",l.innerHTML+="");l.innerHTML+="
";m.fullscreenElement?m.fullscreenElement.appendChild(l):(m.body.appendChild(l),m.body.style.overflow="hidden"); +if(b.do_type_filter)var n=l.querySelector(".slot_in_type_filter"),p=l.querySelector(".slot_out_type_filter");l.close=function(){f.search_box=null;this.blur();k.focus();m.body.style.overflow="";setTimeout(function(){f.canvas.focus()},20);l.parentNode&&l.parentNode.removeChild(l)};1n.height-200&&(t.style.maxHeight=n.height-a.layerY-20+"px");E.focus();b.show_all_on_open&&e();return l};q.prototype.showEditPropertyValue=function(a,b,c){function d(){e(p.value)}function e(r){f&&f.values&&f.values.constructor===Object&&void 0!=f.values[r]&&(r=f.values[r]); +"number"==typeof a.properties[b]&&(r=Number(r));if("array"==g||"object"==g)r=JSON.parse(r);a.properties[b]=r;a.graph&&a.graph._version++;if(a.onPropertyChanged)a.onPropertyChanged(b,r);if(c.onclose)c.onclose();n.close();a.setDirtyCanvas(!0,!0)}if(a&&void 0!==a.properties[b]){c=c||{};var f=a.getPropertyInfo(b),g=f.type,k="";if("string"==g||"number"==g||"array"==g||"object"==g)k="";else if("enum"!=g&&"combo"!=g||!f.values)if("boolean"==g||"toggle"==g)k="";else{console.warn("unknown type: "+g);return}else{k=""}var n=this.createDialog(""+(f.label?f.label:b)+""+k+"",c),p=!1;if("enum"!=g&&"combo"!=g||!f.values)if("boolean"==g||"toggle"==g)(p=n.querySelector("input"))&& +p.addEventListener("click",function(r){n.modified();e(!!p.checked)});else{if(p=n.querySelector("input"))p.addEventListener("blur",function(r){this.focus()}),l=void 0!==a.properties[b]?a.properties[b]:"","string"!==g&&(l=JSON.stringify(l)),p.value=l,p.addEventListener("keydown",function(r){if(27==r.keyCode)n.close();else if(13==r.keyCode)d();else if(13!=r.keyCode){n.modified();return}r.preventDefault();r.stopPropagation()})}else p=n.querySelector("select"),p.addEventListener("change",function(r){n.modified(); +e(r.target.value)});p&&p.focus();n.querySelector("button").addEventListener("click",d);return n}};q.prototype.createDialog=function(a,b){b=Object.assign({checkForInput:!1,closeOnLeave:!0,closeOnLeave_checkModified:!0},b||{});var c=document.createElement("div");c.className="graphdialog";c.innerHTML=a;c.is_modified=!1;a=this.canvas.getBoundingClientRect();var d=-20,e=-20;a&&(d-=a.left,e-=a.top);b.position?(d+=b.position[0],e+=b.position[1]):b.event?(d+=b.event.clientX,e+=b.event.clientY):(d+=.5*this.canvas.width, +e+=.5*this.canvas.height);c.style.left=d+"px";c.style.top=e+"px";this.canvas.parentNode.appendChild(c);b.checkForInput&&(a=[],(a=c.querySelectorAll("input"))&&a.forEach(function(k){k.addEventListener("keydown",function(m){c.modified();if(27==m.keyCode)c.close();else if(13!=m.keyCode)return;m.preventDefault();m.stopPropagation()});k.focus()}));c.modified=function(){c.is_modified=!0};c.close=function(){c.parentNode&&c.parentNode.removeChild(c)};var f=null,g=!1;c.addEventListener("mouseleave",function(k){g|| +(b.closeOnLeave||h.dialog_close_on_mouse_leave)&&!c.is_modified&&h.dialog_close_on_mouse_leave&&(f=setTimeout(c.close,h.dialog_close_on_mouse_leave_delay))});c.addEventListener("mouseenter",function(k){(b.closeOnLeave||h.dialog_close_on_mouse_leave)&&f&&clearTimeout(f)});(a=c.querySelectorAll("select"))&&a.forEach(function(k){k.addEventListener("click",function(m){g++});k.addEventListener("blur",function(m){g=0});k.addEventListener("change",function(m){g=-1})});return c};q.prototype.createPanel=function(a, +b){b=b||{};var c=b.window||window,d=document.createElement("div");d.className="litegraph dialog";d.innerHTML="
";d.header=d.querySelector(".dialog-header");b.width&&(d.style.width=b.width+(b.width.constructor===Number?"px":""));b.height&&(d.style.height=b.height+(b.height.constructor===Number?"px":""));b.closable&& +(b=document.createElement("span"),b.innerHTML="✕",b.classList.add("close"),b.addEventListener("click",function(){d.close()}),d.header.appendChild(b));d.title_element=d.querySelector(".dialog-title");d.title_element.innerText=a;d.content=d.querySelector(".dialog-content");d.alt_content=d.querySelector(".dialog-alt-content");d.footer=d.querySelector(".dialog-footer");d.close=function(){if(d.onClose&&"function"==typeof d.onClose)d.onClose();d.parentNode&&d.parentNode.removeChild(d);this.parentNode&& +this.parentNode.removeChild(this)};d.toggleAltContent=function(e){if("undefined"!=typeof e){var f=e?"block":"none";e=e?"none":"block"}else f="block"!=d.alt_content.style.display?"block":"none",e="block"!=d.alt_content.style.display?"none":"block";d.alt_content.style.display=f;d.content.style.display=e};d.toggleFooterVisibility=function(e){d.footer.style.display="undefined"!=typeof e?e?"block":"none":"block"!=d.footer.style.display?"block":"none"};d.clear=function(){this.content.innerHTML=""};d.addHTML= +function(e,f,g){var k=document.createElement("div");f&&(k.className=f);k.innerHTML=e;g?d.footer.appendChild(k):d.content.appendChild(k);return k};d.addButton=function(e,f,g){var k=document.createElement("button");k.innerText=e;k.options=g;k.classList.add("btn");k.addEventListener("click",f);d.footer.appendChild(k);return k};d.addSeparator=function(){var e=document.createElement("div");e.className="separator";d.content.appendChild(e)};d.addWidget=function(e,f,g,k,m){function l(u,t){k.callback&&k.callback(u, +t,k);m&&m(u,t,k)}k=k||{};var n=String(g);e=e.toLowerCase();"number"==e&&(n=g.toFixed(3));var p=document.createElement("div");p.className="property";p.innerHTML="";p.querySelector(".property_name").innerText=k.label||f;var r=p.querySelector(".property_value");r.innerText=n;p.dataset.property=f;p.dataset.type=k.type||e;p.options=k;p.value=g;if("code"==e)p.addEventListener("click",function(u){d.inner_showCodePad(this.dataset.property)}); +else if("boolean"==e)p.classList.add("boolean"),g&&p.classList.add("bool-on"),p.addEventListener("click",function(){var u=this.dataset.property;this.value=!this.value;this.classList.toggle("bool-on");this.querySelector(".property_value").innerText=this.value?"true":"false";l(u,this.value)});else if("string"==e||"number"==e)r.setAttribute("contenteditable",!0),r.addEventListener("keydown",function(u){"Enter"!=u.code||"string"==e&&u.shiftKey||(u.preventDefault(),this.blur())}),r.addEventListener("blur", +function(){var u=this.innerText,t=this.parentNode.dataset.property;"number"==this.parentNode.dataset.type&&(u=Number(u));l(t,u)});else if("enum"==e||"combo"==e)n=q.getPropertyPrintableValue(g,k.values),r.innerText=n,r.addEventListener("click",function(u){var t=this.parentNode.dataset.property,x=this;new h.ContextMenu(k.values||[],{event:u,className:"dark",callback:function(z,B,E){x.innerText=z;l(t,z);return!1}},c)});d.content.appendChild(p);return p};if(d.onOpen&&"function"==typeof d.onOpen)d.onOpen(); +return d};q.getPropertyPrintableValue=function(a,b){if(!b||b.constructor===Array)return String(a);if(b.constructor===Object){var c="",d;for(d in b)if(b[d]==a){c=d;break}return String(a)+" ("+c+")"}};q.prototype.closePanels=function(){var a=document.querySelector("#node-panel");a&&a.close();(a=document.querySelector("#option-panel"))&&a.close()};q.prototype.showShowGraphOptionsPanel=function(a,b,c,d){if(this.constructor&&"HTMLDivElement"==this.constructor.name){if(!(b&&b.event&&b.event.target&&b.event.target.lgraphcanvas)){console.warn("Canvas not found"); +return}var e=b.event.target.lgraphcanvas}else e=this;e.closePanels();a=e.getCanvasWindow();panel=e.createPanel("Options",{closable:!0,window:a,onOpen:function(){e.OPTIONPANEL_IS_OPEN=!0},onClose:function(){e.OPTIONPANEL_IS_OPEN=!1;e.options_panel=null}});e.options_panel=panel;panel.id="option-panel";panel.classList.add("settings");(function(){panel.content.innerHTML="";var f=function(l,n,p){p&&p.key&&(l=p.key);p.values&&(n=Object.values(p.values).indexOf(n));e[l]=n},g=h.availableCanvasOptions;g.sort(); +for(var k in g){var m=g[k];panel.addWidget("boolean",m,e[m],{key:m,on:"True",off:"False"},f)}panel.addWidget("combo","Render mode",h.LINK_RENDER_MODES[e.links_render_mode],{key:"links_render_mode",values:h.LINK_RENDER_MODES},f);panel.addSeparator();panel.footer.innerHTML=""})();e.canvas.parentNode.appendChild(panel)};q.prototype.showShowNodePanel=function(a){function b(){e.content.innerHTML="";e.addHTML(""+a.type+""+(a.constructor.desc||"")+""); +e.addHTML("

Properties

");var f=function(l,n){d.graph.beforeChange(a);switch(l){case "Title":a.title=n;break;case "Mode":l=Object.values(h.NODE_MODES).indexOf(n);0<=l&&h.NODE_MODES[l]?a.changeMode(l):console.warn("unexpected mode: "+n);break;case "Color":q.node_colors[n]?(a.color=q.node_colors[n].color,a.bgcolor=q.node_colors[n].bgcolor):console.warn("unexpected color: "+n);break;default:a.setProperty(l,n)}d.graph.afterChange();d.dirty_canvas=!0};e.addWidget("string","Title",a.title,{},f); +e.addWidget("combo","Mode",h.NODE_MODES[a.mode],{values:h.NODE_MODES},f);var g="";void 0!==a.color&&(g=Object.keys(q.node_colors).filter(function(l){return q.node_colors[l].color==a.color}));e.addWidget("combo","Color",g,{values:Object.keys(q.node_colors)},f);for(var k in a.properties){g=a.properties[k];var m=a.getPropertyInfo(k);a.onAddPropertyToPanel&&a.onAddPropertyToPanel(k,e)||e.addWidget(m.widget||m.type,k,g,m,f)}e.addSeparator();if(a.onShowCustomPanelInfo)a.onShowCustomPanelInfo(e);e.footer.innerHTML= +"";e.addButton("Delete",function(){a.block_delete||(a.graph.remove(a),e.close())}).classList.add("delete")}this.SELECTED_NODE=a;this.closePanels();var c=this.getCanvasWindow(),d=this,e=this.createPanel(a.title||"",{closable:!0,window:c,onOpen:function(){d.NODEPANEL_IS_OPEN=!0},onClose:function(){d.NODEPANEL_IS_OPEN=!1;d.node_panel=null}});d.node_panel=e;e.id="node-panel";e.node=a;e.classList.add("settings");e.inner_showCodePad=function(f){e.classList.remove("settings");e.classList.add("centered"); +e.alt_content.innerHTML="";var g=e.alt_content.querySelector("textarea"),k=function(){e.toggleAltContent(!1);e.toggleFooterVisibility(!0);g.parentNode.removeChild(g);e.classList.add("settings");e.classList.remove("centered");b()};g.value=a.properties[f];g.addEventListener("keydown",function(l){"Enter"==l.code&&l.ctrlKey&&(a.setProperty(f,g.value),k())});e.toggleAltContent(!0);e.toggleFooterVisibility(!1);g.style.height="calc(100% - 40px)";var m=e.addButton("Assign", +function(){a.setProperty(f,g.value);k()});e.alt_content.appendChild(m);m=e.addButton("Close",k);m.style.float="right";e.alt_content.appendChild(m)};b();this.canvas.parentNode.appendChild(e)};q.prototype.showSubgraphPropertiesDialog=function(a){function b(){d.clear();if(a.inputs)for(var e=0;e","subgraph_property"); +g.dataset.name=f.name;g.dataset.slot=e;g.querySelector(".name").innerText=f.name;g.querySelector(".type").innerText=f.type;g.querySelector("button").addEventListener("click",function(k){a.removeInput(Number(this.parentNode.dataset.slot));b()})}}}console.log("showing subgraph properties dialog");var c=this.canvas.parentNode.querySelector(".subgraph_dialog");c&&c.close();var d=this.createPanel("Subgraph Inputs",{closable:!0,width:500});d.node=a;d.classList.add("subgraph_dialog");d.addHTML(" + NameType", +"subgraph_property extra",!0).querySelector("button").addEventListener("click",function(e){e=this.parentNode;var f=e.querySelector(".name").value,g=e.querySelector(".type").value;f&&-1==a.findInputSlot(f)&&(a.addInput(f,g),e.querySelector(".name").value="",e.querySelector(".type").value="",b())});b();this.canvas.parentNode.appendChild(d);return d};q.prototype.showSubgraphPropertiesDialogRight=function(a){function b(){e.clear();if(a.outputs)for(var f=0;f","subgraph_property");k.dataset.name=g.name;k.dataset.slot=f;k.querySelector(".name").innerText=g.name;k.querySelector(".type").innerText=g.type;k.querySelector("button").addEventListener("click",function(m){a.removeOutput(Number(this.parentNode.dataset.slot));b()})}}}function c(){var f=this.parentNode,g=f.querySelector(".name").value,k=f.querySelector(".type").value;g&&-1==a.findOutputSlot(g)&& +(a.addOutput(g,k),f.querySelector(".name").value="",f.querySelector(".type").value="",b())}var d=this.canvas.parentNode.querySelector(".subgraph_dialog");d&&d.close();var e=this.createPanel("Subgraph Outputs",{closable:!0,width:500});e.node=a;e.classList.add("subgraph_dialog");d=e.addHTML(" + NameType","subgraph_property extra",!0);d.querySelector(".name").addEventListener("keydown", +function(f){13==f.keyCode&&c.apply(this)});d.querySelector("button").addEventListener("click",function(f){c.apply(this)});b();this.canvas.parentNode.appendChild(e);return e};q.prototype.checkPanels=function(){if(this.canvas)for(var a=this.canvas.parentNode.querySelectorAll(".litegraph.dialog"),b=0;b=Object.keys(a.selected_nodes).length)e.collapse(); +else for(var f in a.selected_nodes)a.selected_nodes[f].collapse();e.graph.afterChange()};q.onMenuNodePin=function(a,b,c,d,e){e.pin()};q.onMenuNodeMode=function(a,b,c,d,e){new h.ContextMenu(h.NODE_MODES,{event:c,callback:function(f){if(e){var g=Object.values(h.NODE_MODES).indexOf(f),k=function(n){0<=g&&h.NODE_MODES[g]?n.changeMode(g):(console.warn("unexpected mode: "+f),n.changeMode(h.ALWAYS))},m=q.active_canvas;if(!m.selected_nodes||1>=Object.keys(m.selected_nodes).length)k(e);else for(var l in m.selected_nodes)k(m.selected_nodes[l])}}, +parentMenu:d,node:e});return!1};q.onMenuNodeColors=function(a,b,c,d,e){if(!e)throw"no node for color";b=[];b.push({value:null,content:"No color"});for(var f in q.node_colors)a=q.node_colors[f],a={value:f,content:""+f+""},b.push(a);new h.ContextMenu(b,{event:c,callback:function(g){if(e){var k=g.value?q.node_colors[g.value]: +null;g=function(n){k?n.constructor===h.LGraphGroup?n.color=k.groupcolor:(n.color=k.color,n.bgcolor=k.bgcolor):(delete n.color,delete n.bgcolor)};var m=q.active_canvas;if(!m.selected_nodes||1>=Object.keys(m.selected_nodes).length)g(e);else for(var l in m.selected_nodes)g(m.selected_nodes[l]);e.setDirtyCanvas(!0,!0)}},parentMenu:d,node:e});return!1};q.onMenuNodeShapes=function(a,b,c,d,e){if(!e)throw"no node passed";new h.ContextMenu(h.VALID_SHAPES,{event:c,callback:function(f){if(e){e.graph.beforeChange(); +var g=q.active_canvas;if(!g.selected_nodes||1>=Object.keys(g.selected_nodes).length)e.shape=f;else for(var k in g.selected_nodes)g.selected_nodes[k].shape=f;e.graph.afterChange();e.setDirtyCanvas(!0)}},parentMenu:d,node:e});return!1};q.onMenuNodeRemove=function(a,b,c,d,e){if(!e)throw"no node passed";a=e.graph;a.beforeChange();b=q.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)!1!==e.removable&&a.remove(e);else for(var f in b.selected_nodes)c=b.selected_nodes[f],!1!==c.removable&& +a.remove(c);a.afterChange();e.setDirtyCanvas(!0,!0)};q.onMenuNodeToSubgraph=function(a,b,c,d,e){a=e.graph;if(b=q.active_canvas)c=Object.values(b.selected_nodes||{}),c.length||(c=[e]),d=h.createNode("graph/subgraph"),d.pos=e.pos.concat(),a.add(d),d.buildFromNodes(c),b.deselectAllNodes(),e.setDirtyCanvas(!0,!0)};q.onMenuNodeClone=function(a,b,c,d,e){e.graph.beforeChange();var f={};a=function(k){if(!1!==k.clonable){var m=k.clone();m&&(m.pos=[k.pos[0]+5,k.pos[1]+5],k.graph.add(m),f[m.id]=m)}};b=q.active_canvas; +if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)a(e);else for(var g in b.selected_nodes)a(b.selected_nodes[g]);Object.keys(f).length&&b.selectNodes(f);e.graph.afterChange();e.setDirtyCanvas(!0,!0)};q.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"}};q.prototype.getCanvasMenuOptions=function(){if(this.getMenuOptions)var a=this.getMenuOptions();else a=[{content:"Add Node",has_submenu:!0,callback:q.onMenuAdd},{content:"Add Group",callback:q.onGroupAdd}],1Name", +m),r=p.querySelector("input");r&&n&&(r.value=n.label||"");var u=function(){a.graph.beforeChange();r.value&&(n&&(n.label=r.value),c.setDirty(!0));p.close();a.graph.afterChange()};p.querySelector("button").addEventListener("click",u);r.addEventListener("keydown",function(t){p.is_modified=!0;if(27==t.keyCode)p.close();else if(13==t.keyCode)u();else if(13!=t.keyCode&&"textarea"!=t.target.localName)return;t.preventDefault();t.stopPropagation()});r.focus()}},extra:a};a&&(f.title=a.type);var g=null;a&&(g= +a.getSlotInPosition(b.canvasX,b.canvasY),q.active_node=a);g?(e=[],a.getSlotMenuOptions?e=a.getSlotMenuOptions(g):(g&&g.output&&g.output.links&&g.output.links.length&&e.push({content:"Disconnect Links",slot:g}),b=g.input||g.output,b.removable&&e.push(b.locked?"Cannot remove":{content:"Remove Slot",slot:g}),b.nameLocked||e.push({content:"Rename Slot",slot:g})),f.title=(g.input?g.input.type:g.output.type)||"*",g.input&&g.input.type==h.ACTION&&(f.title="Action"),g.output&&g.output.type==h.EVENT&&(f.title= +"Event")):a?e=this.getNodeMenuOptions(a):(e=this.getCanvasMenuOptions(),(g=this.graph.getGroupOnPos(b.canvasX,b.canvasY))&&e.push(null,{content:"Edit Group",has_submenu:!0,submenu:{title:"Group",extra:g,options:this.getGroupMenuOptions(g)}}));e&&new h.ContextMenu(e,f,d)};h.compareObjects=function(a,b){for(var c in a)if(a[c]!=b[c])return!1;return!0};h.distance=ba;h.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")+")"};h.isInsideRectangle=K;h.growBounding=function(a,b,c){ba[2]&&(a[2]=b);ca[3]&&(a[3]=c)};h.isInsideBounding=function(a,b){return a[0]b[1][0]||a[1]>b[1][1]?!1:!0};h.overlapBounding=Z;h.hex2num=function(a){"#"==a.charAt(0)&&(a=a.slice(1));a=a.toUpperCase();for(var b=Array(3),c=0,d,e,f=0;6>f;f+=2)d="0123456789ABCDEF".indexOf(a.charAt(f)),e="0123456789ABCDEF".indexOf(a.charAt(f+1)),b[c]=16*d+e,c++;return b}; +h.num2hex=function(a){for(var b="#",c,d,e=0;3>e;e++)c=a[e]/16,d=a[e]%16,b+="0123456789ABCDEF".charAt(c)+"0123456789ABCDEF".charAt(d);return b};Q.prototype.addItem=function(a,b,c){function d(m){var l=this.value;l&&l.has_submenu&&e.call(this,m)}function e(m){var l=this.value,n=!0;f.current_submenu&&f.current_submenu.close(m);if(c.callback){var p=c.callback.call(this,l,c,m,f,c.node);!0===p&&(n=!1)}if(l&&(l.callback&&!c.ignore_item_callbacks&&!0!==l.disabled&&(p=l.callback.call(this,l,c,m,f,c.extra), +!0===p&&(n=!1)),l.submenu)){if(!l.submenu.options)throw"ContextMenu submenu needs options";new f.constructor(l.submenu.options,{callback:l.submenu.callback,event:m,parentMenu:f,ignore_item_callbacks:l.submenu.ignore_item_callbacks,title:l.submenu.title,extra:l.submenu.extra,autoopen:c.autoopen});n=!1}n&&!f.lock&&f.close()}var f=this;c=c||{};var g=document.createElement("div");g.className="litemenu-entry submenu";var k=!1;if(null===b)g.classList.add("separator");else{g.innerHTML=b&&b.title?b.title: +a;if(g.value=b)b.disabled&&(k=!0,g.classList.add("disabled")),(b.submenu||b.has_submenu)&&g.classList.add("has_submenu");"function"==typeof b?(g.dataset.value=a,g.onclick_callback=b):g.dataset.value=b;b.className&&(g.className+=" "+b.className)}this.root.appendChild(g);k||g.addEventListener("click",e);!k&&c.autoopen&&h.pointerListenerAdd(g,"enter",d);return g};Q.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&&!Q.isCursorOverElement(a,this.parentMenu.root)&&Q.trigger(this.parentMenu.root,h.pointerevents_method+"leave",a));this.current_submenu&&this.current_submenu.close(a,!0);this.root.closing_timer&&clearTimeout(this.root.closing_timer)};Q.trigger=function(a,b,c,d){var e=document.createEvent("CustomEvent");e.initCustomEvent(b,!0,!0,c);e.srcElement=d;a.dispatchEvent?a.dispatchEvent(e):a.__events&&a.__events.dispatchEvent(e);return e}; +Q.prototype.getTopMenu=function(){return this.options.parentMenu?this.options.parentMenu.getTopMenu():this};Q.prototype.getFirstEvent=function(){return this.options.parentMenu?this.options.parentMenu.getFirstEvent():this.options.event};Q.isCursorOverElement=function(a,b){var c=a.clientX;a=a.clientY;return(b=b.getBoundingClientRect())?a>b.top&&ab.left&&cMath.abs(b))return d[1];a=(a-d[0])/b;return d[1]*(1-a)+e[1]*a}}return 0}};T.prototype.draw=function(a,b,c,d,e,f){if(c=this.points){this.size=b;var g=b[0]-2*this.margin;b=b[1]-2*this.margin;e=e||"#666";a.save();a.translate(this.margin,this.margin);d&&(a.fillStyle="#111",a.fillRect(0,0,g,b),a.fillStyle="#222",a.fillRect(.5*g,0,1,b),a.strokeStyle="#333", +a.strokeRect(0,0,g,b));a.strokeStyle=e;f&&(a.globalAlpha=.5);a.beginPath();for(d=0;da[1])){var d=this.size[0]-2*this.margin,e=this.size[1]-2*this.margin,f=a[0]-this.margin;a=a[1]-this.margin; +this.selected=this.getCloserPoint([f,a],30/b.ds.scale);-1==this.selected&&(b=[f/d,1-a/e],c.push(b),c.sort(function(g,k){return g[0]-k[0]}),this.selected=c.indexOf(b),this.must_update=!0);if(-1!=this.selected)return!0}};T.prototype.onMouseMove=function(a,b){var c=this.points;if(c){var d=this.selected;if(!(0>d)){var e=(a[0]-this.margin)/(this.size[0]-2*this.margin),f=(a[1]-this.margin)/(this.size[1]-2*this.margin);this._nearest=this.getCloserPoint([a[0]-this.margin,a[1]-this.margin],30/b.ds.scale); +if(b=c[d]){var g=0==d||d==c.length-1;!g&&(-10>a[0]||a[0]>this.size[0]+10||-10>a[1]||a[1]>this.size[1]+10)?(c.splice(d,1),this.selected=-1):(b[0]=g?0==d?0:1:ca(e,0,1),b[1]=1-ca(f,0,1),c.sort(function(k,m){return k[0]-m[0]}),this.selected=c.indexOf(b),this.must_update=!0)}}}};T.prototype.onMouseUp=function(a,b){this.selected=-1;return!1};T.prototype.getCloserPoint=function(a,b){var c=this.points;if(!c)return-1;b=b||30;for(var d=this.size[0]-2*this.margin,e=this.size[1]-2*this.margin,f=c.length,g=[0, +0],k=1E6,m=-1,l=0;lk||n>b||(m=l,k=n)}return m};h.CurveEditor=T;h.getParameterNames=function(a){return(a+"").replace(/[/][/].*$/gm,"").replace(/\s+/g,"").replace(/[/][*][^/*]*[*][/]/g,"").split("){",1)[0].replace(/^[^(]*[(]/,"").replace(/=[^,]+/g,"").split(",").filter(Boolean)};h.pointerListenerAdd=function(a,b,c,d=!1){if(a&&a.addEventListener&&b&&"function"===typeof c){var e=h.pointerevents_method;if("pointer"==e&&!window.PointerEvent)switch(console.warn("sMethod=='pointer' && !window.PointerEvent"), +console.log("Converting pointer["+b+"] : down move up cancel enter TO touchstart touchmove touchend, etc .."),b){case "down":e="touch";b="start";break;case "move":e="touch";break;case "up":e="touch";b="end";break;case "cancel":e="touch";break;case "enter":console.log("debug: Should I send a move event?");break;default:console.warn("PointerEvent not available in this browser ? The event "+b+" would not be called")}switch(b){case "down":case "up":case "move":case "over":case "out":case "enter":a.addEventListener(e+ +b,c,d);case "leave":case "cancel":case "gotpointercapture":case "lostpointercapture":if("mouse"!=e)return a.addEventListener(e+b,c,d);default:return a.addEventListener(b,c,d)}}};h.pointerListenerRemove=function(a,b,c,d=!1){if(a&&a.removeEventListener&&b&&"function"===typeof c)switch(b){case "down":case "up":case "move":case "over":case "out":case "enter":"pointer"!=h.pointerevents_method&&"mouse"!=h.pointerevents_method||a.removeEventListener(h.pointerevents_method+b,c,d);case "leave":case "cancel":case "gotpointercapture":case "lostpointercapture":if("pointer"== +h.pointerevents_method)return a.removeEventListener(h.pointerevents_method+b,c,d);default:return a.removeEventListener(b,c,d)}};X.clamp=ca;"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,exports.LGraph=this.LGraph,exports.LLink=this.LLink,exports.LGraphNode=this.LGraphNode,exports.LGraphGroup=this.LGraphGroup,exports.DragAndScale=this.DragAndScale,exports.LGraphCanvas=this.LGraphCanvas,exports.ContextMenu=this.ContextMenu); diff --git a/build/litegraph.js b/build/litegraph.js index e45fee519..8b6f45d54 100644 --- a/build/litegraph.js +++ b/build/litegraph.js @@ -98,6 +98,7 @@ catch_exceptions: true, throw_errors: true, allow_scripts: false, //if set to true some nodes like Formula would be allowed to evaluate code that comes from unsafe sources (like node configuration), which could lead to exploits + use_deferred_actions: true, //executes actions during the graph execution flow registered_node_types: {}, //nodetypes by string node_types_by_file_extension: {}, //used for dropping files in the canvas Nodes: {}, //node types by classname @@ -327,6 +328,55 @@ } }, + /** + * Create a new nodetype by passing an object with some properties + * like onCreate, inputs:Array, outputs:Array, properties, onExecute + * @method buildNodeClassFromObject + * @param {String} name node name with namespace (p.e.: 'math/sum') + * @param {Object} object methods expected onCreate, inputs, outputs, properties, onExecute + */ + buildNodeClassFromObject: function( + name, + object + ) { + var ctor_code = ""; + if(object.inputs) + for(var i=0; i < object.inputs.length; ++i) + { + var _name = object.inputs[i][0]; + var _type = object.inputs[i][1]; + if(_type && _type.constructor === String) + _type = '"'+_type+'"'; + ctor_code += "this.addInput('"+_name+"',"+_type+");\n"; + } + if(object.outputs) + for(var i=0; i < object.outputs.length; ++i) + { + var _name = object.outputs[i][0]; + var _type = object.outputs[i][1]; + if(_type && _type.constructor === String) + _type = '"'+_type+'"'; + ctor_code += "this.addOutput('"+_name+"',"+_type+");\n"; + } + if(object.properties) + for(var i in object.properties) + { + var prop = object.properties[i]; + if(prop && prop.constructor === String) + prop = '"'+prop+'"'; + ctor_code += "this.addProperty('"+i+"',"+prop+");\n"; + } + ctor_code += "if(this.onCreate)this.onCreate()"; + var classobj = Function(ctor_code); + for(var i in object) + if(i!="inputs" && i!="outputs" && i!="properties") + classobj.prototype[i] = object[i]; + classobj.title = object.title || name.split("/").pop(); + classobj.desc = object.desc || "Generated from object"; + this.registerNodeType(name, classobj); + return classobj; + }, + /** * Create a new nodetype by passing a function, it wraps it with a proper class and generates inputs according to the parameters of the function. * Useful to wrap simple methods that do not require properties, and that only process some input to generate an output. @@ -346,20 +396,31 @@ ) { var params = Array(func.length); var code = ""; - var names = LiteGraph.getParameterNames(func); - for (var i = 0; i < names.length; ++i) { - code += - "this.addInput('" + - names[i] + - "'," + - (param_types && param_types[i] - ? "'" + param_types[i] + "'" - : "0") + - ");\n"; + if(param_types !== null) //null means no inputs + { + var names = LiteGraph.getParameterNames(func); + for (var i = 0; i < names.length; ++i) { + var type = 0; + if(param_types) + { + //type = param_types[i] != null ? "'" + param_types[i] + "'" : "0"; + if( param_types[i] != null && param_types[i].constructor === String ) + type = "'" + param_types[i] + "'" ; + else if( param_types[i] != null ) + type = param_types[i]; + } + code += + "this.addInput('" + + names[i] + + "'," + + type + + ");\n"; + } } + if(return_type !== null) //null means no output code += "this.addOutput('out'," + - (return_type ? "'" + return_type + "'" : 0) + + (return_type != null ? (return_type.constructor === String ? "'" + return_type + "'" : return_type) : 0) + ");\n"; if (properties) { code += @@ -376,6 +437,7 @@ this.setOutputData(0, r); }; this.registerNodeType(name, classobj); + return classobj; }, /** @@ -3142,6 +3204,13 @@ // enable this to give the event an ID if (!options.action_call) options.action_call = this.id+"_exec_"+Math.floor(Math.random()*9999); + if(this._waiting_actions && this._waiting_actions.length) + for(var i = 0; i < this._waiting_actions.length;++i) + { + var p = this._waiting_actions[i]; + this.onAction(p[0],p[1],p[2],p[3],p[4]); + } + this.graph.nodes_executing[this.id] = true; //.push(this.id); this.onExecute(param, options); @@ -3155,6 +3224,14 @@ this.graph.nodes_executedAction[this.id] = options.action_call; } } + else { + if(this._waiting_actions && this._waiting_actions.length) + for(var i = 0; i < this._waiting_actions.length;++i) + { + var p = this._waiting_actions[i]; + this.onAction(p[0],p[1],p[2],p[3],p[4]); + } + } this.execute_triggered = 2; // the nFrames it will be used (-- each step), means "how old" is the event if(this.onAfterExecuteNode) this.onAfterExecuteNode(param, options); // callback }; @@ -3165,7 +3242,7 @@ * @param {String} action name * @param {*} param */ - LGraphNode.prototype.actionDo = function(action, param, options) { + LGraphNode.prototype.actionDo = function(action, param, options, action_slot ) { options = options || {}; if (this.onAction){ @@ -3174,7 +3251,7 @@ this.graph.nodes_actioning[this.id] = (action?action:"actioning"); //.push(this.id); - this.onAction(action, param, options); + this.onAction(action, param, options, action_slot); this.graph.nodes_actioning[this.id] = false; //.pop(); @@ -3282,8 +3359,19 @@ if (!options.action_call) options.action_call = this.id+"_act_"+Math.floor(Math.random()*9999); //pass the action name var target_connection = node.inputs[link_info.target_slot]; - // wrap node.onAction(target_connection.name, param); - node.actionDo(target_connection.name, param, options); + + //instead of executing them now, it will be executed in the next graph loop, to ensure data flow + if(LiteGraph.use_deferred_actions) + { + if(!node._waiting_actions) + node._waiting_actions = []; + node._waiting_actions.push([target_connection.name, param, options, link_info.target_slot]); + } + else + { + // wrap node.onAction(target_connection.name, param); + node.actionDo( target_connection.name, param, options, link_info.target_slot ); + } } } }; @@ -5646,7 +5734,7 @@ LGraphNode.prototype.executeAction = function(action) //Keyboard ****************** this._key_callback = this.processKey.bind(this); - + canvas.setAttribute("tabindex",1); //otherwise key events are ignored canvas.addEventListener("keydown", this._key_callback, true); document.addEventListener("keyup", this._key_callback, true); //in document, otherwise it doesn't fire keyup @@ -7150,6 +7238,8 @@ LGraphNode.prototype.executeAction = function(action) for (var i = 0; i < selected_nodes_array.length; ++i) { var node = selected_nodes_array[i]; + if(node.clonable === false) + continue; var cloned = node.clone(); if(!cloned) { @@ -11540,6 +11630,7 @@ LGraphNode.prototype.executeAction = function(action) //ESC dialog.close(); } else if (e.keyCode == 13) { + refreshHelper(); if (selected) { select(selected.innerHTML); } else if (first) { @@ -16186,6 +16277,63 @@ LiteGraph.registerNodeType("basic/jsonparse", JSONParse); LiteGraph.registerNodeType("events/sequence", Sequence); + //Sequence of events + function WaitAll() { + var that = this; + this.addInput("", LiteGraph.ACTION); + this.addInput("", LiteGraph.ACTION); + this.addOutput("", LiteGraph.EVENT); + this.addWidget("button","+",null,function(){ + that.addInput("", LiteGraph.ACTION); + that.size[0] = 90; + }); + this.size = [90, 70]; + this.ready = []; +} + +WaitAll.title = "WaitAll"; +WaitAll.desc = "Wait until all input events arrive then triggers output"; + +WaitAll.prototype.getTitle = function() { + return ""; +}; + +WaitAll.prototype.onDrawBackground = function(ctx) +{ + if (this.flags.collapsed) { + return; + } + for(var i = 0; i < this.inputs.length; ++i) + { + var y = i * LiteGraph.NODE_SLOT_HEIGHT + 10; + ctx.fillStyle = this.ready[i] ? "#AFB" : "#000"; + ctx.fillRect(20, y, 10, 10); + } +} + +WaitAll.prototype.onAction = function(action, param, options, slot_index) { + if(slot_index == null) + return; + + //check all + this.ready.length = this.outputs.length; + this.ready[slot_index] = true; + for(var i = 0; i < this.ready.length;++i) + if(!this.ready[i]) + return; + //pass + this.reset(); + this.triggerSlot(0); +}; + +WaitAll.prototype.reset = function() +{ + this.ready.length = 0; +} + +LiteGraph.registerNodeType("events/waitAll", WaitAll); + + //Sequencer for events function Stepper() { var that = this; diff --git a/build/litegraph_mini.js b/build/litegraph_mini.js index 911afcf79..b170ab57a 100644 --- a/build/litegraph_mini.js +++ b/build/litegraph_mini.js @@ -98,6 +98,7 @@ catch_exceptions: true, throw_errors: true, allow_scripts: false, //if set to true some nodes like Formula would be allowed to evaluate code that comes from unsafe sources (like node configuration), which could lead to exploits + use_deferred_actions: true, //executes actions during the graph execution flow registered_node_types: {}, //nodetypes by string node_types_by_file_extension: {}, //used for dropping files in the canvas Nodes: {}, //node types by classname @@ -327,6 +328,55 @@ } }, + /** + * Create a new nodetype by passing an object with some properties + * like onCreate, inputs:Array, outputs:Array, properties, onExecute + * @method buildNodeClassFromObject + * @param {String} name node name with namespace (p.e.: 'math/sum') + * @param {Object} object methods expected onCreate, inputs, outputs, properties, onExecute + */ + buildNodeClassFromObject: function( + name, + object + ) { + var ctor_code = ""; + if(object.inputs) + for(var i=0; i < object.inputs.length; ++i) + { + var _name = object.inputs[i][0]; + var _type = object.inputs[i][1]; + if(_type && _type.constructor === String) + _type = '"'+_type+'"'; + ctor_code += "this.addInput('"+_name+"',"+_type+");\n"; + } + if(object.outputs) + for(var i=0; i < object.outputs.length; ++i) + { + var _name = object.outputs[i][0]; + var _type = object.outputs[i][1]; + if(_type && _type.constructor === String) + _type = '"'+_type+'"'; + ctor_code += "this.addOutput('"+_name+"',"+_type+");\n"; + } + if(object.properties) + for(var i in object.properties) + { + var prop = object.properties[i]; + if(prop && prop.constructor === String) + prop = '"'+prop+'"'; + ctor_code += "this.addProperty('"+i+"',"+prop+");\n"; + } + ctor_code += "if(this.onCreate)this.onCreate()"; + var classobj = Function(ctor_code); + for(var i in object) + if(i!="inputs" && i!="outputs" && i!="properties") + classobj.prototype[i] = object[i]; + classobj.title = object.title || name.split("/").pop(); + classobj.desc = object.desc || "Generated from object"; + this.registerNodeType(name, classobj); + return classobj; + }, + /** * Create a new nodetype by passing a function, it wraps it with a proper class and generates inputs according to the parameters of the function. * Useful to wrap simple methods that do not require properties, and that only process some input to generate an output. @@ -346,20 +396,31 @@ ) { var params = Array(func.length); var code = ""; - var names = LiteGraph.getParameterNames(func); - for (var i = 0; i < names.length; ++i) { - code += - "this.addInput('" + - names[i] + - "'," + - (param_types && param_types[i] - ? "'" + param_types[i] + "'" - : "0") + - ");\n"; + if(param_types !== null) //null means no inputs + { + var names = LiteGraph.getParameterNames(func); + for (var i = 0; i < names.length; ++i) { + var type = 0; + if(param_types) + { + //type = param_types[i] != null ? "'" + param_types[i] + "'" : "0"; + if( param_types[i] != null && param_types[i].constructor === String ) + type = "'" + param_types[i] + "'" ; + else if( param_types[i] != null ) + type = param_types[i]; + } + code += + "this.addInput('" + + names[i] + + "'," + + type + + ");\n"; + } } + if(return_type !== null) //null means no output code += "this.addOutput('out'," + - (return_type ? "'" + return_type + "'" : 0) + + (return_type != null ? (return_type.constructor === String ? "'" + return_type + "'" : return_type) : 0) + ");\n"; if (properties) { code += @@ -376,6 +437,7 @@ this.setOutputData(0, r); }; this.registerNodeType(name, classobj); + return classobj; }, /** @@ -3142,6 +3204,13 @@ // enable this to give the event an ID if (!options.action_call) options.action_call = this.id+"_exec_"+Math.floor(Math.random()*9999); + if(this._waiting_actions && this._waiting_actions.length) + for(var i = 0; i < this._waiting_actions.length;++i) + { + var p = this._waiting_actions[i]; + this.onAction(p[0],p[1],p[2],p[3],p[4]); + } + this.graph.nodes_executing[this.id] = true; //.push(this.id); this.onExecute(param, options); @@ -3155,6 +3224,14 @@ this.graph.nodes_executedAction[this.id] = options.action_call; } } + else { + if(this._waiting_actions && this._waiting_actions.length) + for(var i = 0; i < this._waiting_actions.length;++i) + { + var p = this._waiting_actions[i]; + this.onAction(p[0],p[1],p[2],p[3],p[4]); + } + } this.execute_triggered = 2; // the nFrames it will be used (-- each step), means "how old" is the event if(this.onAfterExecuteNode) this.onAfterExecuteNode(param, options); // callback }; @@ -3165,7 +3242,7 @@ * @param {String} action name * @param {*} param */ - LGraphNode.prototype.actionDo = function(action, param, options) { + LGraphNode.prototype.actionDo = function(action, param, options, action_slot ) { options = options || {}; if (this.onAction){ @@ -3174,7 +3251,7 @@ this.graph.nodes_actioning[this.id] = (action?action:"actioning"); //.push(this.id); - this.onAction(action, param, options); + this.onAction(action, param, options, action_slot); this.graph.nodes_actioning[this.id] = false; //.pop(); @@ -3282,8 +3359,19 @@ if (!options.action_call) options.action_call = this.id+"_act_"+Math.floor(Math.random()*9999); //pass the action name var target_connection = node.inputs[link_info.target_slot]; - // wrap node.onAction(target_connection.name, param); - node.actionDo(target_connection.name, param, options); + + //instead of executing them now, it will be executed in the next graph loop, to ensure data flow + if(LiteGraph.use_deferred_actions) + { + if(!node._waiting_actions) + node._waiting_actions = []; + node._waiting_actions.push([target_connection.name, param, options, link_info.target_slot]); + } + else + { + // wrap node.onAction(target_connection.name, param); + node.actionDo( target_connection.name, param, options, link_info.target_slot ); + } } } }; @@ -5646,7 +5734,7 @@ LGraphNode.prototype.executeAction = function(action) //Keyboard ****************** this._key_callback = this.processKey.bind(this); - + canvas.setAttribute("tabindex",1); //otherwise key events are ignored canvas.addEventListener("keydown", this._key_callback, true); document.addEventListener("keyup", this._key_callback, true); //in document, otherwise it doesn't fire keyup @@ -7150,6 +7238,8 @@ LGraphNode.prototype.executeAction = function(action) for (var i = 0; i < selected_nodes_array.length; ++i) { var node = selected_nodes_array[i]; + if(node.clonable === false) + continue; var cloned = node.clone(); if(!cloned) { @@ -11540,6 +11630,7 @@ LGraphNode.prototype.executeAction = function(action) //ESC dialog.close(); } else if (e.keyCode == 13) { + refreshHelper(); if (selected) { select(selected.innerHTML); } else if (first) { @@ -16186,6 +16277,63 @@ LiteGraph.registerNodeType("basic/jsonparse", JSONParse); LiteGraph.registerNodeType("events/sequence", Sequence); + //Sequence of events + function WaitAll() { + var that = this; + this.addInput("", LiteGraph.ACTION); + this.addInput("", LiteGraph.ACTION); + this.addOutput("", LiteGraph.EVENT); + this.addWidget("button","+",null,function(){ + that.addInput("", LiteGraph.ACTION); + that.size[0] = 90; + }); + this.size = [90, 70]; + this.ready = []; +} + +WaitAll.title = "WaitAll"; +WaitAll.desc = "Wait until all input events arrive then triggers output"; + +WaitAll.prototype.getTitle = function() { + return ""; +}; + +WaitAll.prototype.onDrawBackground = function(ctx) +{ + if (this.flags.collapsed) { + return; + } + for(var i = 0; i < this.inputs.length; ++i) + { + var y = i * LiteGraph.NODE_SLOT_HEIGHT + 10; + ctx.fillStyle = this.ready[i] ? "#AFB" : "#000"; + ctx.fillRect(20, y, 10, 10); + } +} + +WaitAll.prototype.onAction = function(action, param, options, slot_index) { + if(slot_index == null) + return; + + //check all + this.ready.length = this.outputs.length; + this.ready[slot_index] = true; + for(var i = 0; i < this.ready.length;++i) + if(!this.ready[i]) + return; + //pass + this.reset(); + this.triggerSlot(0); +}; + +WaitAll.prototype.reset = function() +{ + this.ready.length = 0; +} + +LiteGraph.registerNodeType("events/waitAll", WaitAll); + + //Sequencer for events function Stepper() { var that = this; diff --git a/src/litegraph.d.ts b/src/litegraph.d.ts index 8dd8a51a1..92394a39a 100755 --- a/src/litegraph.d.ts +++ b/src/litegraph.d.ts @@ -249,6 +249,7 @@ export const LiteGraph: { * @param param_types an array containing the type of every parameter, otherwise parameters will accept any type * @param return_type string with the return type, otherwise it will be generic * @param properties properties to be configurable + * @return {LGraphNode} */ wrapFunctionAsNode( name: string, @@ -256,7 +257,7 @@ export const LiteGraph: { param_types?: string[], return_type?: string, properties?: object - ): void; + ): LGraphNode; /** * Adds this method to all node types, existing and to be created diff --git a/src/litegraph.js b/src/litegraph.js index 8947fbb5f..7e0a57193 100755 --- a/src/litegraph.js +++ b/src/litegraph.js @@ -96,6 +96,7 @@ catch_exceptions: true, throw_errors: true, allow_scripts: false, //if set to true some nodes like Formula would be allowed to evaluate code that comes from unsafe sources (like node configuration), which could lead to exploits + use_deferred_actions: true, //executes actions during the graph execution flow registered_node_types: {}, //nodetypes by string node_types_by_file_extension: {}, //used for dropping files in the canvas Nodes: {}, //node types by classname @@ -325,6 +326,55 @@ } }, + /** + * Create a new nodetype by passing an object with some properties + * like onCreate, inputs:Array, outputs:Array, properties, onExecute + * @method buildNodeClassFromObject + * @param {String} name node name with namespace (p.e.: 'math/sum') + * @param {Object} object methods expected onCreate, inputs, outputs, properties, onExecute + */ + buildNodeClassFromObject: function( + name, + object + ) { + var ctor_code = ""; + if(object.inputs) + for(var i=0; i < object.inputs.length; ++i) + { + var _name = object.inputs[i][0]; + var _type = object.inputs[i][1]; + if(_type && _type.constructor === String) + _type = '"'+_type+'"'; + ctor_code += "this.addInput('"+_name+"',"+_type+");\n"; + } + if(object.outputs) + for(var i=0; i < object.outputs.length; ++i) + { + var _name = object.outputs[i][0]; + var _type = object.outputs[i][1]; + if(_type && _type.constructor === String) + _type = '"'+_type+'"'; + ctor_code += "this.addOutput('"+_name+"',"+_type+");\n"; + } + if(object.properties) + for(var i in object.properties) + { + var prop = object.properties[i]; + if(prop && prop.constructor === String) + prop = '"'+prop+'"'; + ctor_code += "this.addProperty('"+i+"',"+prop+");\n"; + } + ctor_code += "if(this.onCreate)this.onCreate()"; + var classobj = Function(ctor_code); + for(var i in object) + if(i!="inputs" && i!="outputs" && i!="properties") + classobj.prototype[i] = object[i]; + classobj.title = object.title || name.split("/").pop(); + classobj.desc = object.desc || "Generated from object"; + this.registerNodeType(name, classobj); + return classobj; + }, + /** * Create a new nodetype by passing a function, it wraps it with a proper class and generates inputs according to the parameters of the function. * Useful to wrap simple methods that do not require properties, and that only process some input to generate an output. @@ -344,20 +394,31 @@ ) { var params = Array(func.length); var code = ""; - var names = LiteGraph.getParameterNames(func); - for (var i = 0; i < names.length; ++i) { - code += - "this.addInput('" + - names[i] + - "'," + - (param_types && param_types[i] - ? "'" + param_types[i] + "'" - : "0") + - ");\n"; + if(param_types !== null) //null means no inputs + { + var names = LiteGraph.getParameterNames(func); + for (var i = 0; i < names.length; ++i) { + var type = 0; + if(param_types) + { + //type = param_types[i] != null ? "'" + param_types[i] + "'" : "0"; + if( param_types[i] != null && param_types[i].constructor === String ) + type = "'" + param_types[i] + "'" ; + else if( param_types[i] != null ) + type = param_types[i]; + } + code += + "this.addInput('" + + names[i] + + "'," + + type + + ");\n"; + } } + if(return_type !== null) //null means no output code += "this.addOutput('out'," + - (return_type ? "'" + return_type + "'" : 0) + + (return_type != null ? (return_type.constructor === String ? "'" + return_type + "'" : return_type) : 0) + ");\n"; if (properties) { code += @@ -374,6 +435,7 @@ this.setOutputData(0, r); }; this.registerNodeType(name, classobj); + return classobj; }, /** @@ -3140,6 +3202,13 @@ // enable this to give the event an ID if (!options.action_call) options.action_call = this.id+"_exec_"+Math.floor(Math.random()*9999); + if(this._waiting_actions && this._waiting_actions.length) + for(var i = 0; i < this._waiting_actions.length;++i) + { + var p = this._waiting_actions[i]; + this.onAction(p[0],p[1],p[2],p[3],p[4]); + } + this.graph.nodes_executing[this.id] = true; //.push(this.id); this.onExecute(param, options); @@ -3153,6 +3222,14 @@ this.graph.nodes_executedAction[this.id] = options.action_call; } } + else { + if(this._waiting_actions && this._waiting_actions.length) + for(var i = 0; i < this._waiting_actions.length;++i) + { + var p = this._waiting_actions[i]; + this.onAction(p[0],p[1],p[2],p[3],p[4]); + } + } this.execute_triggered = 2; // the nFrames it will be used (-- each step), means "how old" is the event if(this.onAfterExecuteNode) this.onAfterExecuteNode(param, options); // callback }; @@ -3163,7 +3240,7 @@ * @param {String} action name * @param {*} param */ - LGraphNode.prototype.actionDo = function(action, param, options) { + LGraphNode.prototype.actionDo = function(action, param, options, action_slot ) { options = options || {}; if (this.onAction){ @@ -3172,7 +3249,7 @@ this.graph.nodes_actioning[this.id] = (action?action:"actioning"); //.push(this.id); - this.onAction(action, param, options); + this.onAction(action, param, options, action_slot); this.graph.nodes_actioning[this.id] = false; //.pop(); @@ -3280,8 +3357,19 @@ if (!options.action_call) options.action_call = this.id+"_act_"+Math.floor(Math.random()*9999); //pass the action name var target_connection = node.inputs[link_info.target_slot]; - // wrap node.onAction(target_connection.name, param); - node.actionDo(target_connection.name, param, options); + + //instead of executing them now, it will be executed in the next graph loop, to ensure data flow + if(LiteGraph.use_deferred_actions) + { + if(!node._waiting_actions) + node._waiting_actions = []; + node._waiting_actions.push([target_connection.name, param, options, link_info.target_slot]); + } + else + { + // wrap node.onAction(target_connection.name, param); + node.actionDo( target_connection.name, param, options, link_info.target_slot ); + } } } }; @@ -5644,7 +5732,7 @@ LGraphNode.prototype.executeAction = function(action) //Keyboard ****************** this._key_callback = this.processKey.bind(this); - + canvas.setAttribute("tabindex",1); //otherwise key events are ignored canvas.addEventListener("keydown", this._key_callback, true); document.addEventListener("keyup", this._key_callback, true); //in document, otherwise it doesn't fire keyup @@ -7148,6 +7236,8 @@ LGraphNode.prototype.executeAction = function(action) for (var i = 0; i < selected_nodes_array.length; ++i) { var node = selected_nodes_array[i]; + if(node.clonable === false) + continue; var cloned = node.clone(); if(!cloned) { @@ -11538,6 +11628,7 @@ LGraphNode.prototype.executeAction = function(action) //ESC dialog.close(); } else if (e.keyCode == 13) { + refreshHelper(); if (selected) { select(selected.innerHTML); } else if (first) { diff --git a/src/nodes/events.js b/src/nodes/events.js index 34d7351b6..ec458ef14 100755 --- a/src/nodes/events.js +++ b/src/nodes/events.js @@ -90,6 +90,63 @@ LiteGraph.registerNodeType("events/sequence", Sequence); + //Sequence of events + function WaitAll() { + var that = this; + this.addInput("", LiteGraph.ACTION); + this.addInput("", LiteGraph.ACTION); + this.addOutput("", LiteGraph.EVENT); + this.addWidget("button","+",null,function(){ + that.addInput("", LiteGraph.ACTION); + that.size[0] = 90; + }); + this.size = [90, 70]; + this.ready = []; +} + +WaitAll.title = "WaitAll"; +WaitAll.desc = "Wait until all input events arrive then triggers output"; + +WaitAll.prototype.getTitle = function() { + return ""; +}; + +WaitAll.prototype.onDrawBackground = function(ctx) +{ + if (this.flags.collapsed) { + return; + } + for(var i = 0; i < this.inputs.length; ++i) + { + var y = i * LiteGraph.NODE_SLOT_HEIGHT + 10; + ctx.fillStyle = this.ready[i] ? "#AFB" : "#000"; + ctx.fillRect(20, y, 10, 10); + } +} + +WaitAll.prototype.onAction = function(action, param, options, slot_index) { + if(slot_index == null) + return; + + //check all + this.ready.length = this.outputs.length; + this.ready[slot_index] = true; + for(var i = 0; i < this.ready.length;++i) + if(!this.ready[i]) + return; + //pass + this.reset(); + this.triggerSlot(0); +}; + +WaitAll.prototype.reset = function() +{ + this.ready.length = 0; +} + +LiteGraph.registerNodeType("events/waitAll", WaitAll); + + //Sequencer for events function Stepper() { var that = this; diff --git a/utils/builder.py b/utils/builder.py index af314bfc2..da0c4ad41 100755 --- a/utils/builder.py +++ b/utils/builder.py @@ -4,9 +4,15 @@ import argparse from datetime import date -compiler_path = "../node_modules/google-closure-compiler/compiler.jar" root_path = "./" +#compiler_path = "../node_modules/google-closure-compiler/cli.js" +#compiler_path = "../node_modules/google-closure-compiler-java/compiler.jar" +#compiler_path = "google-clouse-compiler" + +#compiler_path = "java -jar ../node_modules/google-closure-compiler-java/compiler.jar --js %s --js_output_file %s" +compiler_path = "../node_modules/google-closure-compiler/cli.js --js %s --js_output_file %s" + #arguments parser = argparse.ArgumentParser(description='Deploy a JS app creating a minifyed version checking for errors.') parser.add_argument('input_file', @@ -55,7 +61,8 @@ def packJSCode(files): continue data += open(src_file).read() + "\n" if check_files_individually: - os.system("java -jar %s --js %s --js_output_file %s" % (compiler_path, src_file, "temp.js") ) + os.system( compiler_path % ( src_file, "temp.js") ) + #os.system( "java -jar %s --js %s --js_output_file %s" % (compiler_path, src_file, "temp.js") ) sys.stderr.write('\033[92m' + "OK\n" + '\033[0m') os.write(f1,data) @@ -69,10 +76,10 @@ def packJSCode(files): def compileAndMinify(input_path, output_path): print " + Compiling and minifying..." if output_path != None: - os.system("java -jar %s --js %s --js_output_file %s" % (compiler_path, input_path, output_path) ) + os.system( compiler_path % ( input_path, output_path) ) sys.stderr.write(" * Stored in " + output_path + "\n"); else: - os.system("java -jar %s --js %s" % (compiler_path, input_path) ) + os.system( compiler_path % ( input_path ) ) #load project info if os.path.exists(args.input_file) == False: