diff --git a/build/litegraph.js b/build/litegraph.js index 8675b93d1..052420893 100644 --- a/build/litegraph.js +++ b/build/litegraph.js @@ -10255,7 +10255,11 @@ LGraphNode.prototype.executeAction = function(action) if (!root_document) { root_document = document; } - root_document.body.appendChild(root); + + if( root_document.fullscreenElement ) + root_document.fullscreenElement.appendChild(root); + else + root_document.body.appendChild(root); //compute best position var left = options.left || 0; diff --git a/build/litegraph.min.js b/build/litegraph.min.js index 9c7bcd138..98c83fa6c 100755 --- a/build/litegraph.min.js +++ b/build/litegraph.min.js @@ -7,228 +7,228 @@ this.visible_links=[];b&&b.attachCanvas(this);this.setCanvas(a);this.clear();d.s "px";a.preventDefault();return!0}this.options=b=b||{};var x=this;b.parentMenu&&(b.parentMenu.constructor!==this.constructor?(console.error("parentMenu must be of class ContextMenu, ignoring it"),b.parentMenu=null):(this.parentMenu=b.parentMenu,this.parentMenu.lock=!0,this.parentMenu.current_submenu=this));b.event&&b.event.constructor!==MouseEvent&&b.event.constructor!==CustomEvent&&(console.error("Event passed to ContextMenu is not of type MouseEvent or CustomEvent. Ignoring it."),b.event=null);var e= document.createElement("div");e.className="litegraph litecontextmenu litemenubar-panel";b.className&&(e.className+=" "+b.className);e.style.minWidth=100;e.style.minHeight=100;e.style.pointerEvents="none";setTimeout(function(){e.style.pointerEvents="auto"},100);e.addEventListener("mouseup",function(a){a.preventDefault();return!0},!0);e.addEventListener("contextmenu",function(a){if(2!=a.button)return!1;a.preventDefault();return!1},!0);e.addEventListener("mousedown",function(a){if(2==a.button)return x.close(), a.preventDefault(),!0},!0);b.scroll_speed||(b.scroll_speed=0.1);e.addEventListener("wheel",d,!0);e.addEventListener("mousewheel",d,!0);this.root=e;if(b.title){var c=document.createElement("div");c.className="litemenu-title";c.innerHTML=b.title;e.appendChild(c)}var c=0,A;for(A in a){var h=a.constructor==Array?a[A]:A;null!=h&&h.constructor!==String&&(h=void 0===h.content?String(h):h.content);this.addItem(h,a[A],b);c++}e.addEventListener("mouseleave",function(a){x.lock||(e.closing_timer&&clearTimeout(e.closing_timer), -e.closing_timer=setTimeout(x.close.bind(x,a),500))});e.addEventListener("mouseenter",function(a){e.closing_timer&&clearTimeout(e.closing_timer)});A=document;b.event&&(A=b.event.target.ownerDocument);A||(A=document);A.body.appendChild(e);c=b.left||0;A=b.top||0;if(b.event){c=b.event.clientX-10;A=b.event.clientY-10;b.title&&(A-=20);b.parentMenu&&(c=b.parentMenu.root.getBoundingClientRect(),c=c.left+c.width);var h=document.body.getBoundingClientRect(),f=e.getBoundingClientRect();c>h.width-f.width-10&& -(c=h.width-f.width-10);A>h.height-f.height-10&&(A=h.height-f.height-10)}e.style.left=c+"px";e.style.top=A+"px";b.scale&&(e.style.transform="scale("+b.scale+")")}var e=v.LiteGraph={VERSION:0.4,CANVAS_GRID_SIZE:10,NODE_TITLE_HEIGHT:30,NODE_TITLE_TEXT_Y:20,NODE_SLOT_HEIGHT:20,NODE_WIDGET_HEIGHT:20,NODE_WIDTH:140,NODE_MIN_WIDTH:50,NODE_COLLAPSED_RADIUS:10,NODE_COLLAPSED_WIDTH:80,NODE_TITLE_COLOR:"#999",NODE_TEXT_SIZE:14,NODE_TEXT_COLOR:"#AAA",NODE_SUBTEXT_SIZE:12,NODE_DEFAULT_COLOR:"#333",NODE_DEFAULT_BGCOLOR:"#353535", -NODE_DEFAULT_BOXCOLOR:"#666",NODE_DEFAULT_SHAPE:"box",DEFAULT_SHADOW_COLOR:"rgba(0,0,0,0.5)",DEFAULT_GROUP_FONT:24,WIDGET_BGCOLOR:"#222",WIDGET_OUTLINE_COLOR:"#666",WIDGET_TEXT_COLOR:"#DDD",WIDGET_SECONDARY_TEXT_COLOR:"#999",LINK_COLOR:"#9A9",EVENT_LINK_COLOR:"#A86",CONNECTING_LINK_COLOR:"#AFA",MAX_NUMBER_OF_NODES:1E3,DEFAULT_POSITION:[100,100],VALID_SHAPES:["default","box","round","card"],BOX_SHAPE:1,ROUND_SHAPE:2,CIRCLE_SHAPE:3,CARD_SHAPE:4,ARROW_SHAPE:5,INPUT:1,OUTPUT:2,EVENT:-1,ACTION:-1,ALWAYS:0, -ON_EVENT:1,NEVER:2,ON_TRIGGER:3,UP:1,DOWN:2,LEFT:3,RIGHT:4,CENTER:5,STRAIGHT_LINK:0,LINEAR_LINK:1,SPLINE_LINK:2,NORMAL_TITLE:0,NO_TITLE:1,TRANSPARENT_TITLE:2,AUTOHIDE_TITLE:3,proxy:null,node_images_path:"",debug:!1,catch_exceptions:!0,throw_errors:!0,allow_scripts:!1,registered_node_types:{},node_types_by_file_extension:{},Nodes:{},searchbox_extras:{},registerNodeType:function(a,b){if(!b.prototype)throw"Cannot register a simple object, it must be a class with a prototype";b.type=a;e.debug&&console.log("Node registered: "+ -a);a.split("/");var d=b.name,x=a.lastIndexOf("/");b.category=a.substr(0,x);b.title||(b.title=d);if(b.prototype)for(var p in g.prototype)b.prototype[p]||(b.prototype[p]=g.prototype[p]);Object.hasOwnProperty(b.prototype,"shape")||Object.defineProperty(b.prototype,"shape",{set:function(a){switch(a){case "default":delete this._shape;break;case "box":this._shape=e.BOX_SHAPE;break;case "round":this._shape=e.ROUND_SHAPE;break;case "circle":this._shape=e.CIRCLE_SHAPE;break;case "card":this._shape=e.CARD_SHAPE; -break;default:this._shape=a}},get:function(a){return this._shape},enumerable:!0});(x=this.registered_node_types[a])&&console.log("replacing node type: "+a);this.registered_node_types[a]=b;b.constructor.name&&(this.Nodes[d]=b);if(e.onNodeTypeRegistered)e.onNodeTypeRegistered(a,b);if(x&&e.onNodeTypeReplaced)e.onNodeTypeReplaced(a,b,x);b.prototype.onPropertyChange&&console.warn("LiteGraph node class "+a+" has onPropertyChange method, it must be called onPropertyChanged with d at the end");if(b.supported_extensions)for(p in b.supported_extensions)this.node_types_by_file_extension[b.supported_extensions[p].toLowerCase()]= -b},wrapFunctionAsNode:function(a,b,d,x,p){for(var c=Array(b.length),A="",h=e.getParameterNames(b),f=0;fh&&(h=p.size[0]),f+=p.size[1]+a;b+=h+a}this.setDirtyCanvas(!0,!0)};c.prototype.getTime=function(){return this.globaltime};c.prototype.getFixedTime=function(){return this.fixedtime};c.prototype.getElapsedTime=function(){return this.elapsed_time}; -c.prototype.sendEventToAllNodes=function(a,b,d){d=d||e.ALWAYS;var x=this._nodes_in_order?this._nodes_in_order:this._nodes;if(x)for(var p=0,c=x.length;p=e.MAX_NUMBER_OF_NODES)throw"LiteGraph: max number of nodes in a graph reached";null==a.id||-1==a.id?a.id=++this.last_node_id:this.last_node_ida.length||(this._pos[0]= -a[0],this._pos[1]=a[1])},get:function(){return this._pos},enumerable:!0});this.id=-1;this.type=null;this.inputs=[];this.outputs=[];this.connections=[];this.properties={};this.properties_info=[];this.flags={}};g.prototype.configure=function(a){this.graph&&this.graph._version++;for(var b in a)if("properties"==b)for(var d in a.properties){if(this.properties[d]=a.properties[d],this.onPropertyChanged)this.onPropertyChanged(d,a.properties[d])}else null!=a[b]&&("object"==typeof a[b]?this[b]&&this[b].configure? -this[b].configure(a[b]):this[b]=e.cloneObject(a[b],this[b]):this[b]=a[b]);a.title||(this.title=this.constructor.title);if(this.onConnectionsChange){if(this.inputs)for(d=0;d=this.outputs.length)){var d=this.outputs[a];if(d&&(d._data=b,this.outputs[a].links))for(d=0;d=this.outputs.length)){var d=this.outputs[a];if(d&&(d.type=b,this.outputs[a].links))for(d=0;d=this.inputs.length||null==this.inputs[a].link)){var d=this.graph.links[this.inputs[a].link];if(!d)return null;if(!b)return d.data;var e=this.graph.getNodeById(d.origin_id);if(!e)return d.data; -if(e.updateOutputData)e.updateOutputData(d.origin_slot);else if(e.onExecute)e.onExecute();return d.data}};g.prototype.getInputDataType=function(a){if(!this.inputs||a>=this.inputs.length||null==this.inputs[a].link)return null;a=this.graph.links[this.inputs[a].link];if(!a)return null;var b=this.graph.getNodeById(a.origin_id);return b?(a=b.outputs[a.origin_slot])?a.type:null:a.type};g.prototype.getInputDataByName=function(a,b){var d=this.findInputSlot(a);return-1==d?null:this.getInputData(d,b)};g.prototype.isInputConnected= -function(a){return this.inputs?a=this.inputs.length)return null;a=this.inputs[a];return a&&null!==a.link?(a=this.graph.links[a.link])?this.graph.getNodeById(a.origin_id):null:null};g.prototype.getInputOrProperty=function(a){if(!this.inputs||!this.inputs.length)return this.properties?this.properties[a]: -null;for(var b=0,d=this.inputs.length;b=this.outputs.length?null:this.outputs[a]._data};g.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=[],d=0;da&&this.pos[1]-p-db)return!0;return!1};g.prototype.getSlotInPosition=function(a,b){var d=new Float32Array(2);if(this.inputs)for(var e=0,p=this.inputs.length;e=this.outputs.length)return e.debug&&console.log("Connect: Error, slot number not found"),null;b&&b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"target node is null";if(b==this)return null;if(d.constructor===String){if(d=b.findInputSlot(d),-1==d)return e.debug&&console.log("Connect: Error, no slot of name "+d),null}else{if(d=== -e.EVENT)return null;if(!b.inputs||d>=b.inputs.length)return e.debug&&console.log("Connect: Error, slot number not found"),null}null!=b.inputs[d].link&&b.disconnectInput(d);var c=this.outputs[a];if(b.onConnectInput&&!1===b.onConnectInput(d,c.type,c))return null;var p=b.inputs[d],h=null;if(e.isValidConnection(c.type,p.type)){h=new q(++this.graph.last_link_id,p.type,this.id,a,b.id,d);this.graph.links[h.id]=h;null==c.links&&(c.links=[]);c.links.push(h.id);b.inputs[d].link=h.id;this.graph&&this.graph._version++; -if(this.onConnectionsChange)this.onConnectionsChange(e.OUTPUT,a,!0,h,c);if(b.onConnectionsChange)b.onConnectionsChange(e.INPUT,d,!0,h,p);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(e.INPUT,b,d,this,a),this.graph.onNodeConnectionChange(e.OUTPUT,this,a,b,d))}this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this,h);return h};g.prototype.disconnectOutput=function(a,b){if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return e.debug&&console.log("Connect: Error, no slot of name "+ -a),!1}else if(!this.outputs||a>=this.outputs.length)return e.debug&&console.log("Connect: Error, slot number not found"),!1;var d=this.outputs[a];if(!d||!d.links||0==d.links.length)return!1;if(b){b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"Target Node not found";for(var c=0,p=d.links.length;c=this.inputs.length)return e.debug&&console.log("Connect: Error, slot number not found"),!1;var b=this.inputs[a];if(!b)return!1;var d=this.inputs[a].link;this.inputs[a].link=null;var c=this.graph.links[d];if(c){var p= -this.graph.getNodeById(c.origin_id);if(!p)return!1;var h=p.outputs[c.origin_slot];if(!h||!h.links||0==h.links.length)return!1;for(var f=0,k=h.links.length;fb&&this.inputs[b].pos)return d[0]=this.pos[0]+this.inputs[b].pos[0],d[1]=this.pos[1]+this.inputs[b].pos[1],d;if(!a&&c>b&&this.outputs[b].pos)return d[0]=this.pos[0]+this.outputs[b].pos[0],d[1]=this.pos[1]+this.outputs[b].pos[1],d;if(this.horizontal)return d[0]=this.pos[0]+this.size[0]/c*(b+0.5),d[1]=a?this.pos[1]-e.NODE_TITLE_HEIGHT: -this.pos[1]+this.size[1],d;d[0]=a?this.pos[0]+p:this.pos[0]+this.size[0]+1-p;d[1]=this.pos[1]+(b+0.7)*e.NODE_SLOT_HEIGHT+(this.constructor.slot_start_y||0);return d};g.prototype.alignToGrid=function(){this.pos[0]=e.CANVAS_GRID_SIZE*Math.round(this.pos[0]/e.CANVAS_GRID_SIZE);this.pos[1]=e.CANVAS_GRID_SIZE*Math.round(this.pos[1]/e.CANVAS_GRID_SIZE)};g.prototype.trace=function(a){this.console||(this.console=[]);this.console.push(a);this.console.length>g.MAX_CONSOLE&&this.console.shift();this.graph.onNodeTrace(this, -a)};g.prototype.setDirtyCanvas=function(a,b){this.graph&&this.graph.sendActionToCanvas("setDirty",[a,b])};g.prototype.loadImage=function(a){var b=new Image;b.src=e.node_images_path+a;b.ready=!1;var d=this;b.onload=function(){this.ready=!0;d.setDirtyCanvas(!0)};return b};g.prototype.captureInput=function(a){if(this.graph&&this.graph.list_of_graphcanvas)for(var b=this.graph.list_of_graphcanvas,d=0;da.length||(this._pos[0]=a[0],this._pos[1]=a[1])},get:function(){return this._pos},enumerable:!0});Object.defineProperty(this,"size",{set:function(a){!a||2>a.length||(this._size[0]=Math.max(140,a[0]),this._size[1]=Math.max(80,a[1]))},get:function(){return this._size}, -enumerable:!0})};l.prototype.configure=function(a){this.title=a.title;this._bounding.set(a.bounding);this.color=a.color;this.font=a.font};l.prototype.serialize=function(){var a=this._bounding;return{title:this.title,bounding:[Math.round(a[0]),Math.round(a[1]),Math.round(a[2]),Math.round(a[3])],color:this.color,font:this.font}};l.prototype.move=function(a,b,d){this._pos[0]+=a;this._pos[1]+=b;if(!d)for(d=0;dthis.max_scale&&(a=this.max_scale);if(a!=this.scale&&this.element){var d=this.element.getBoundingClientRect();if(d){b=b||[0.5*d.width,0.5*d.height];d=this.convertCanvasToOffset(b);this.scale=a;0.01>Math.abs(this.scale-1)&&(this.scale= -1);var e=this.convertCanvasToOffset(b),d=[e[0]-d[0],e[1]-d[1]];this.offset[0]+=d[0];this.offset[1]+=d[1];if(this.onredraw)this.onredraw(this)}}};r.prototype.changeDeltaScale=function(a,b){this.changeScale(this.scale*a,b)};r.prototype.reset=function(){this.scale=1;this.offset[0]=0;this.offset[1]=0};v.LGraphCanvas=e.LGraphCanvas=f;f.link_type_colors={"-1":e.EVENT_LINK_COLOR,number:"#AAA",node:"#DCA"};f.gradients={};f.prototype.clear=function(){this.fps=this.render_time=this.last_draw_time=this.frame= -0;this.dragging_rectangle=null;this.selected_nodes={};this.selected_group=null;this.visible_nodes=[];this.connecting_node=this.node_capturing_input=this.node_over=this.node_dragged=null;this.highlighted_links={};this.dirty_bgcanvas=this.dirty_canvas=!0;this.node_widget=this.node_in_panel=this.dirty_area=null;this.last_mouse=[0,0];this.last_mouseclick=0;this.visible_area.set([0,0,0,0]);if(this.onClear)this.onClear()};f.prototype.setGraph=function(a,b){this.graph!=a&&(b||this.clear(),!a&&this.graph? -this.graph.detachCanvas(this):(a.attachCanvas(this),this.setDirty(!0,!0)))};f.prototype.openSubgraph=function(a){if(!a)throw"graph cannot be null";if(this.graph==a)throw"graph cannot be the same";this.clear();this.graph&&(this._graph_stack||(this._graph_stack=[]),this._graph_stack.push(this.graph));a.attachCanvas(this);this.setDirty(!0,!0)};f.prototype.closeSubgraph=function(){if(this._graph_stack&&0!=this._graph_stack.length){var a=this.graph._subgraph_node,b=this._graph_stack.pop();this.selected_nodes= -{};this.highlighted_links={};b.attachCanvas(this);this.setDirty(!0,!0);a&&(this.centerOnNode(a),this.selectNodes([a]))}};f.prototype.getCurrentGraph=function(){return this.graph};f.prototype.setCanvas=function(a,b){if(a&&a.constructor===String&&(a=document.getElementById(a),!a))throw"Error creating LiteGraph canvas: Canvas not found";if(a!==this.canvas&&(!a&&this.canvas&&(b||this.unbindEvents()),this.canvas=a,this.ds.element=a)){a.className+=" lgraphcanvas";a.data=this;a.tabindex="1";this.bgcanvas= -null;this.bgcanvas||(this.bgcanvas=document.createElement("canvas"),this.bgcanvas.width=this.canvas.width,this.bgcanvas.height=this.canvas.height);if(null==a.getContext){if("canvas"!=a.localName)throw"Element supplied for LGraphCanvas must be a element, you passed a "+a.localName;throw"This browser doesn't support Canvas";}null==(this.ctx=a.getContext("2d"))&&(a.webgl_enabled||console.warn("This canvas seems to be WebGL, enabling WebGL renderer"),this.enableWebGL());this._mousemove_callback= -this.processMouseMove.bind(this);this._mouseup_callback=this.processMouseUp.bind(this);b||this.bindEvents()}};f.prototype._doNothing=function(a){a.preventDefault();return!1};f.prototype._doReturnTrue=function(a){a.preventDefault();return!0};f.prototype.bindEvents=function(){if(this._events_binded)console.warn("LGraphCanvas: events already binded");else{var a=this.canvas,b=this.getCanvasWindow().document;this._mousedown_callback=this.processMouseDown.bind(this);this._mousewheel_callback=this.processMouseWheel.bind(this); -a.addEventListener("mousedown",this._mousedown_callback,!0);a.addEventListener("mousemove",this._mousemove_callback);a.addEventListener("mousewheel",this._mousewheel_callback,!1);a.addEventListener("contextmenu",this._doNothing);a.addEventListener("DOMMouseScroll",this._mousewheel_callback,!1);a.addEventListener("touchstart",this.touchHandler,!0);a.addEventListener("touchmove",this.touchHandler,!0);a.addEventListener("touchend",this.touchHandler,!0);a.addEventListener("touchcancel",this.touchHandler, -!0);this._key_callback=this.processKey.bind(this);a.addEventListener("keydown",this._key_callback,!0);b.addEventListener("keyup",this._key_callback,!0);this._ondrop_callback=this.processDrop.bind(this);a.addEventListener("dragover",this._doNothing,!1);a.addEventListener("dragend",this._doNothing,!1);a.addEventListener("drop",this._ondrop_callback,!1);a.addEventListener("dragenter",this._doReturnTrue,!1);this._events_binded=!0}};f.prototype.unbindEvents=function(){if(this._events_binded){var a=this.getCanvasWindow().document; -this.canvas.removeEventListener("mousedown",this._mousedown_callback);this.canvas.removeEventListener("mousewheel",this._mousewheel_callback);this.canvas.removeEventListener("DOMMouseScroll",this._mousewheel_callback);this.canvas.removeEventListener("keydown",this._key_callback);a.removeEventListener("keyup",this._key_callback);this.canvas.removeEventListener("contextmenu",this._doNothing);this.canvas.removeEventListener("drop",this._ondrop_callback);this.canvas.removeEventListener("dragenter",this._doReturnTrue); -this.canvas.removeEventListener("touchstart",this.touchHandler);this.canvas.removeEventListener("touchmove",this.touchHandler);this.canvas.removeEventListener("touchend",this.touchHandler);this.canvas.removeEventListener("touchcancel",this.touchHandler);this._ondrop_callback=this._key_callback=this._mousewheel_callback=this._mousedown_callback=null;this._events_binded=!1}else console.warn("LGraphCanvas: no events binded")};f.getFileExtension=function(a){var b=a.indexOf("?");-1!=b&&(a=a.substr(0,b)); -b=a.lastIndexOf(".");return-1==b?"":a.substr(b+1).toLowerCase()};f.prototype.enableWebGL=function(){if(void 0===typeof GL)throw"litegl.js must be included to use a WebGL canvas";if(void 0===typeof enableWebGLCanvas)throw"webglCanvas.js must be included to use this feature";this.gl=this.ctx=enableWebGLCanvas(this.canvas);this.ctx.webgl=!0;this.bgcanvas=this.canvas;this.bgctx=this.gl;this.canvas.webgl_enabled=!0};f.prototype.setDirty=function(a,b){a&&(this.dirty_canvas=!0);b&&(this.dirty_bgcanvas=!0)}; -f.prototype.getCanvasWindow=function(){if(!this.canvas)return window;var a=this.canvas.ownerDocument;return a.defaultView||a.parentWindow};f.prototype.startRendering=function(){function a(){this.pause_rendering||this.draw();var b=this.getCanvasWindow();this.is_rendering&&b.requestAnimationFrame(a.bind(this))}this.is_rendering||(this.is_rendering=!0,a.call(this))};f.prototype.stopRendering=function(){this.is_rendering=!1};f.prototype.processMouseDown=function(a){if(this.graph){this.adjustMouseEvent(a); -var b=this.getCanvasWindow();f.active_canvas=this;this.canvas.removeEventListener("mousemove",this._mousemove_callback);b.document.addEventListener("mousemove",this._mousemove_callback,!0);b.document.addEventListener("mouseup",this._mouseup_callback,!0);var d=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes,5),c=!1,p=300>e.getTime()-this.last_mouseclick;this.canvas_mouse[0]=a.canvasX;this.canvas_mouse[1]=a.canvasY;this.canvas.focus();e.closeAllContextMenus(b);if(!this.onMouse||!0!=this.onMouse(a)){if(1== -a.which){a.ctrlKey&&(this.dragging_rectangle=new Float32Array(4),this.dragging_rectangle[0]=a.canvasX,this.dragging_rectangle[1]=a.canvasY,this.dragging_rectangle[2]=1,this.dragging_rectangle[3]=1,c=!0);var h=!1;if(d&&this.allow_interaction&&!c&&!this.read_only){this.live_mode||d.flags.pinned||this.bringToFront(d);if(!this.connecting_node&&!d.flags.collapsed&&!this.live_mode)if(!c&&!1!==d.resizable&&s(a.canvasX,a.canvasY,d.pos[0]+d.size[0]-5,d.pos[1]+d.size[1]-5,10,10))this.resizing_node=d,this.canvas.style.cursor= -"se-resize",c=!0;else{if(d.outputs)for(var k=0,n=d.outputs.length;kh[0]+4||a.canvasYh[1]+4)){this.showLinkMenu(d,a);break}this.selected_group=this.graph.getGroupOnPos(a.canvasX,a.canvasY);this.selected_group_resizing=!1;this.selected_group&&!this.read_only&&(a.ctrlKey&&(this.dragging_rectangle=null),10>y([a.canvasX,a.canvasY],[this.selected_group.pos[0]+this.selected_group.size[0],this.selected_group.pos[1]+this.selected_group.size[1]])*this.ds.scale? -this.selected_group_resizing=!0:this.selected_group.recomputeInsideNodes());p&&!this.read_only&&this.showSearchBox(a);h=!0}!c&&h&&this.allow_dragcanvas&&(this.dragging_canvas=!0)}else 2!=a.which&&3==a.which&&(this.read_only||this.processContextMenu(d,a));this.last_mouse[0]=a.localX;this.last_mouse[1]=a.localY;this.last_mouseclick=e.getTime();this.last_mouse_dragging=!0;this.graph.change();(!b.document.activeElement||"input"!=b.document.activeElement.nodeName.toLowerCase()&&"textarea"!=b.document.activeElement.nodeName.toLowerCase())&& -a.preventDefault();a.stopPropagation();if(this.onMouseDown)this.onMouseDown(a);return!1}}};f.prototype.processMouseMove=function(a){this.autoresize&&this.resize();if(this.graph){f.active_canvas=this;this.adjustMouseEvent(a);var b=[a.localX,a.localY],d=[b[0]-this.last_mouse[0],b[1]-this.last_mouse[1]];this.last_mouse=b;this.canvas_mouse[0]=a.canvasX;this.canvas_mouse[1]=a.canvasY;a.dragging=this.last_mouse_dragging;this.node_widget&&(this.processNodeWidgets(this.node_widget[0],this.canvas_mouse,a, -this.node_widget[1]),this.dirty_canvas=!0);if(this.dragging_rectangle)this.dragging_rectangle[2]=a.canvasX-this.dragging_rectangle[0],this.dragging_rectangle[3]=a.canvasY-this.dragging_rectangle[1],this.dirty_canvas=!0;else if(this.selected_group&&!this.read_only)this.selected_group_resizing?this.selected_group.size=[a.canvasX-this.selected_group.pos[0],a.canvasY-this.selected_group.pos[1]]:(this.selected_group.move(d[0]/this.ds.scale,d[1]/this.ds.scale,a.ctrlKey),this.selected_group._nodes.length&& -(this.dirty_canvas=!0)),this.dirty_bgcanvas=!0;else if(this.dragging_canvas)this.ds.offset[0]+=d[0]/this.ds.scale,this.ds.offset[1]+=d[1]/this.ds.scale,this.dirty_bgcanvas=this.dirty_canvas=!0;else if(this.allow_interaction&&!this.read_only){this.connecting_node&&(this.dirty_canvas=!0);for(var c=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes),b=0,p=this.graph._nodes.length;bk[0]+4||a.canvasYk[1]+4)){p=h;break}}p!=this.over_link_center&&(this.over_link_center=p,this.dirty_canvas=!0);this.canvas&&(this.canvas.style.cursor= -"")}if(this.node_capturing_input&&this.node_capturing_input!=c&&this.node_capturing_input.onMouseMove)this.node_capturing_input.onMouseMove(a);if(this.node_dragged&&!this.live_mode){for(b in this.selected_nodes)c=this.selected_nodes[b],c.pos[0]+=d[0]/this.ds.scale,c.pos[1]+=d[1]/this.ds.scale;this.dirty_bgcanvas=this.dirty_canvas=!0}this.resizing_node&&!this.live_mode&&(this.resizing_node.size[0]=a.canvasX-this.resizing_node.pos[0],this.resizing_node.size[1]=a.canvasY-this.resizing_node.pos[1],d= -Math.max(this.resizing_node.inputs?this.resizing_node.inputs.length:0,this.resizing_node.outputs?this.resizing_node.outputs.length:0)*e.NODE_SLOT_HEIGHT+(this.resizing_node.widgets?this.resizing_node.widgets.length:0)*(e.NODE_WIDGET_HEIGHT+4)+4,this.resizing_node.size[1]this.dragging_rectangle[3]?this.dragging_rectangle[1]-p:this.dragging_rectangle[1];this.dragging_rectangle[0]=0>this.dragging_rectangle[2]?this.dragging_rectangle[0]-c:this.dragging_rectangle[0];this.dragging_rectangle[1]=h;this.dragging_rectangle[2]=c;this.dragging_rectangle[3]=p;p=[];for(h=0;ha.click_time&&s(a.canvasX,a.canvasY,c.pos[0],c.pos[1]-e.NODE_TITLE_HEIGHT,e.NODE_TITLE_HEIGHT,e.NODE_TITLE_HEIGHT)&&c.collapse(); -this.dirty_bgcanvas=this.dirty_canvas=!0;this.node_dragged.pos[0]=Math.round(this.node_dragged.pos[0]);this.node_dragged.pos[1]=Math.round(this.node_dragged.pos[1]);this.graph.config.align_to_grid&&this.node_dragged.alignToGrid();if(this.onNodeMoved)this.onNodeMoved(this.node_dragged);this.node_dragged=null}else{c=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes);!c&&300>a.click_time&&this.deselectAllNodes();this.dirty_canvas=!0;this.dragging_canvas=!1;if(this.node_over&&this.node_over.onMouseUp)this.node_over.onMouseUp(a, -[a.canvasX-this.node_over.pos[0],a.canvasY-this.node_over.pos[1]],this);if(this.node_capturing_input&&this.node_capturing_input.onMouseUp)this.node_capturing_input.onMouseUp(a,[a.canvasX-this.node_capturing_input.pos[0],a.canvasY-this.node_capturing_input.pos[1]])}}else 2==a.which?(this.dirty_canvas=!0,this.dragging_canvas=!1):3==a.which&&(this.dirty_canvas=!0,this.dragging_canvas=!1);this.graph.change();a.stopPropagation();a.preventDefault();return!1}};f.prototype.processMouseWheel=function(a){if(this.graph&& -this.allow_dragcanvas){var b=null!=a.wheelDeltaY?a.wheelDeltaY:-60*a.detail;this.adjustMouseEvent(a);var d=this.ds.scale;0b&&(d*=1/1.1);this.ds.changeScale(d,[a.localX,a.localY]);this.graph.change();a.preventDefault();return!1}};f.prototype.isOverNodeBox=function(a,b,d){var c=e.NODE_TITLE_HEIGHT;return s(b,d,a.pos[0]+2,a.pos[1]+2-c,c-4,c-4)?!0:!1};f.prototype.isOverNodeInput=function(a,b,d,e){if(a.inputs)for(var c=0,h=a.inputs.length;cd-this.graph._last_trigger_time)&&this.drawBackCanvas();(this.dirty_canvas||a)&&this.drawFrontCanvas();this.fps=this.render_time?1/this.render_time:0;this.frame+=1}};f.prototype.drawFrontCanvas=function(){this.dirty_canvas=!1;this.ctx||(this.ctx=this.bgcanvas.getContext("2d"));var a=this.ctx; -if(a){a.start2D&&a.start2D();var b=this.canvas;a.restore();a.setTransform(1,0,0,1,0,0);this.dirty_area&&(a.save(),a.beginPath(),a.rect(this.dirty_area[0],this.dirty_area[1],this.dirty_area[2],this.dirty_area[3]),a.clip());this.clear_background&&a.clearRect(0,0,b.width,b.height);this.bgcanvas==this.canvas?this.drawBackCanvas():a.drawImage(this.bgcanvas,0,0);if(this.onRender)this.onRender(b,a);this.show_info&&this.renderInfo(a);if(this.graph){a.save();this.ds.toCanvasContext(a);for(var b=this.computeVisibleNodes(null, -this.visible_nodes),d=0;d> ";b.fillText(e+d.getTitle(),0.5*a.width,40);b.restore()}d=!1;this.onRenderBackground&&(d=this.onRenderBackground(a,b));b.restore();b.setTransform(1,0,0,1,0,0);this.visible_links.length=0;if(this.graph){b.save();this.ds.toCanvasContext(b);if(this.background_image&&0.5this.ds.scale,t=a._shape||a.constructor.shape||e.ROUND_SHAPE,l=a.constructor.title_mode,g=!0;l==e.TRANSPARENT_TITLE?g=!1:l==e.AUTOHIDE_TITLE&& -k&&(g=!0);n[0]=0;n[1]=g?-p:0;n[2]=d[0]+1;n[3]=g?d[1]+p:d[1];k=b.globalAlpha;b.beginPath();t==e.BOX_SHAPE||m?b.fillRect(n[0],n[1],n[2],n[3]):t==e.ROUND_SHAPE||t==e.CARD_SHAPE?b.roundRect(n[0],n[1],n[2],n[3],this.round_radius,t==e.CARD_SHAPE?0:this.round_radius):t==e.CIRCLE_SHAPE&&b.arc(0.5*d[0],0.5*d[1],0.5*d[0],0,2*Math.PI);b.fill();a.flags.collapsed||(b.shadowColor="transparent",b.fillStyle="rgba(0,0,0,0.2)",b.fillRect(0,-1,n[2],2));b.shadowColor="transparent";if(a.onDrawBackground)a.onDrawBackground(b, -this,this.canvas);if(g||l==e.TRANSPARENT_TITLE){if(a.onDrawTitleBar)a.onDrawTitleBar(b,p,d,this.ds.scale,c);else if(l!=e.TRANSPARENT_TITLE&&(a.constructor.title_color||this.render_title_colored)){g=a.constructor.title_color||c;a.flags.collapsed&&(b.shadowColor=e.DEFAULT_SHADOW_COLOR);if(this.use_gradients){var s=f.gradients[g];s||(s=f.gradients[g]=b.createLinearGradient(0,0,400,0),s.addColorStop(0,g),s.addColorStop(1,"#000"));b.fillStyle=s}else b.fillStyle=g;b.beginPath();t==e.BOX_SHAPE||m?b.rect(0, --p,d[0]+1,p):t!=e.ROUND_SHAPE&&t!=e.CARD_SHAPE||b.roundRect(0,-p,d[0]+1,p,this.round_radius,a.flags.collapsed?this.round_radius:0);b.fill();b.shadowColor="transparent"}if(a.onDrawTitleBox)a.onDrawTitleBox(b,p,d,this.ds.scale);else t==e.ROUND_SHAPE||t==e.CIRCLE_SHAPE||t==e.CARD_SHAPE?(m&&(b.fillStyle="black",b.beginPath(),b.arc(0.5*p,-0.5*p,6,0,2*Math.PI),b.fill()),b.fillStyle=a.boxcolor||e.NODE_DEFAULT_BOXCOLOR,b.beginPath(),b.arc(0.5*p,-0.5*p,5,0,2*Math.PI),b.fill()):(m&&(b.fillStyle="black",b.fillRect(0.5* -(p-10)-1,-0.5*(p+10)-1,12,12)),b.fillStyle=a.boxcolor||e.NODE_DEFAULT_BOXCOLOR,b.fillRect(0.5*(p-10),-0.5*(p+10),10,10));b.globalAlpha=k;if(a.onDrawTitleText)a.onDrawTitleText(b,p,d,this.ds.scale,this.title_text_font,h);!m&&(b.font=this.title_text_font,m=a.getTitle())&&(b.fillStyle=h?"white":a.constructor.title_text_color||this.node_title_color,a.flags.collapsed?(b.textAlign="center",k=b.measureText(m),b.fillText(m,p+0.5*k.width,e.NODE_TITLE_TEXT_Y-p),b.textAlign="left"):(b.textAlign="left",b.fillText(m, -p,e.NODE_TITLE_TEXT_Y-p)));if(a.onDrawTitle)a.onDrawTitle(b)}if(h){if(a.onBounding)a.onBounding(n);l==e.TRANSPARENT_TITLE&&(n[1]-=p,n[3]+=p);b.lineWidth=1;b.globalAlpha=0.8;b.beginPath();t==e.BOX_SHAPE?b.rect(-6+n[0],-6+n[1],12+n[2],12+n[3]):t==e.ROUND_SHAPE||t==e.CARD_SHAPE&&a.flags.collapsed?b.roundRect(-6+n[0],-6+n[1],12+n[2],12+n[3],2*this.round_radius):t==e.CARD_SHAPE?b.roundRect(-6+n[0],-6+n[1],12+n[2],12+n[3],2*this.round_radius,2):t==e.CIRCLE_SHAPE&&b.arc(0.5*d[0],0.5*d[1],0.5*d[0]+6,0,2* -Math.PI);b.strokeStyle="#FFF";b.stroke();b.strokeStyle=c;b.globalAlpha=1}};var D=new Float32Array(4),h=new Float32Array(4),t=new Float32Array(2),m=new Float32Array(2);f.prototype.drawConnections=function(a){var b=e.getTime(),d=this.visible_area;D[0]=d[0]-20;D[1]=d[1]-20;D[2]=d[2]+40;D[3]=d[3]+40;a.lineWidth=this.connections_width;a.fillStyle="#AAA";a.strokeStyle="#AAA";a.globalAlpha=this.editor_alpha;for(var d=this.graph._nodes,c=0,p=d.length;ch[2]&&(h[0]+=h[2],h[2]=Math.abs(h[2]));0>h[3]&&(h[1]+=h[3],h[3]=Math.abs(h[3]));if(u(h,D)){var B=l.outputs[g],g=k.inputs[f];if(B&&g&&(l=B.dir||(l.horizontal?e.DOWN:e.RIGHT),g=g.dir||(k.horizontal? -e.UP:e.LEFT),this.renderLink(a,s,w,n,!1,0,null,l,g),n&&n._last_time&&1E3>b-n._last_time)){var B=2-0.002*(b-n._last_time),J=a.globalAlpha;a.globalAlpha=J*B;this.renderLink(a,s,w,n,!0,B,"white",l,g);a.globalAlpha=J}}}}}}a.globalAlpha=1};f.prototype.renderLink=function(a,b,d,c,p,h,k,n,m,t){c&&this.visible_links.push(c);!k&&c&&(k=c.color||f.link_type_colors[c.type]);k||(k=this.default_link_color);null!=c&&this.highlighted_links[c.id]&&(k="#FFF");n=n||e.RIGHT;m=m||e.LEFT;var l=y(b,d);this.render_connections_border&& -0.6b[1]?0:Math.PI,a.save(),a.translate(g[0],g[1]),a.rotate(B),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore(),a.save(),a.translate(t[0],t[1]),a.rotate(s),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3), -a.fill(),a.restore()),a.beginPath(),a.arc(p[0],p[1],5,0,2*Math.PI),a.fill());if(h)for(a.fillStyle=k,g=0;5>g;++g)h=(0.001*e.getTime()+0.2*g)%1,p=this.computeConnectionPoint(b,d,h,n,m),a.beginPath(),a.arc(p[0],p[1],5,0,2*Math.PI),a.fill()};f.prototype.computeConnectionPoint=function(a,b,d,c,p){c=c||e.RIGHT;p=p||e.LEFT;var h=y(a,b),k=[a[0],a[1]],f=[b[0],b[1]];switch(c){case e.LEFT:k[0]+=-0.25*h;break;case e.RIGHT:k[0]+=0.25*h;break;case e.UP:k[1]+=-0.25*h;break;case e.DOWN:k[1]+=0.25*h}switch(p){case e.LEFT:f[0]+= --0.25*h;break;case e.RIGHT:f[0]+=0.25*h;break;case e.UP:f[1]+=-0.25*h;break;case e.DOWN:f[1]+=0.25*h}c=(1-d)*(1-d)*(1-d);p=3*(1-d)*(1-d)*d;h=3*(1-d)*d*d;d*=d*d;return[c*a[0]+p*k[0]+h*f[0]+d*b[0],c*a[1]+p*k[1]+h*f[1]+d*b[1]]};f.prototype.drawExecutionOrder=function(a){a.shadowColor="transparent";a.globalAlpha=0.25;a.textAlign="center";a.strokeStyle="white";a.globalAlpha=0.75;for(var b=this.visible_nodes,d=0;dg.last_y&&fg.options.max&&(g.value=g.options.max);else if("mousedown"==d.type)if((c=g.options.values)&&c.constructor===Function&&(c=g.options.values(g,a)),k=40>k?-1:k>n-40?1:0,"number"==g.type)g.value+=0.1*k*(g.options.step||1),null!=g.options.min&&g.valueg.options.max&&(g.value=g.options.max);else if(k)t=c.indexOf(g.value)+k,t>=c.length&&(t=0),0>t&&(t=c.length-1), -g.value=c[t];else{new e.ContextMenu(c,{scale:Math.max(1,this.ds.scale),event:d,className:"dark",callback:B.bind(g)},t);var B=function(a,b,d){this.value=a;h(this,a);m.dirty_canvas=!0;return!1}}setTimeout(function(){h(this,this.value)}.bind(g),20);this.dirty_canvas=!0;break;case "toggle":"mousedown"==d.type&&(g.value=!g.value,g.callback&&setTimeout(function(){h(g,g.value)},20));break;case "string":case "text":"mousedown"==d.type&&this.prompt("Value",g.value,function(a){this.value=a;h(this,a)}.bind(g), -d);break;default:g.mouse&&g.mouse(ctx,d,[k,f],a)}return g}}return null};f.prototype.drawGroups=function(a,b){if(this.graph){var d=this.graph._groups;b.save();b.globalAlpha=0.5*this.editor_alpha;for(var c=0;cd&&0.01>b.editor_alpha&&(clearInterval(e),1>d&&(b.live_mode=!0));1"+g+""+a+"",value:g});if(m.length)return new e.ContextMenu(m,{event:d,callback:k,parentMenu:c,allow_html:!0,node:h},b),!1}};f.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};f.onResizeNode=function(a,b,d,e,c){c&&(c.size=c.computeSize(),c.setDirtyCanvas(!0,!0))};f.prototype.showLinkMenu= -function(a,b){var d=this;console.log(a.data);new e.ContextMenu(["Delete"],{event:b,title:null!=a.data?a.data.constructor.name:null,callback:function(b){switch(b){case "Delete":d.graph.removeLink(a.id)}}});return!1};f.onShowPropertyEditor=function(a,b,d,e,c){function h(){var b=m.value;"Number"==a.type?b=Number(b):"Boolean"==a.type&&(b=Boolean(b));c[k]=b;n.parentNode&&n.parentNode.removeChild(n);c.setDirtyCanvas(!0,!0)}var k=a.property||"title";b=c[k];var n=document.createElement("div");n.className= -"graphdialog";n.innerHTML="";n.querySelector(".name").innerText=k;var m=n.querySelector("input");m&&(m.value=b,m.addEventListener("blur",function(a){this.focus()}),m.addEventListener("keydown",function(a){13==a.keyCode&&(h(),a.preventDefault(),a.stopPropagation())}));b=f.active_canvas.canvas;d=b.getBoundingClientRect();var g=e=-20;d&&(e-=d.left,g-=d.top);event?(n.style.left=event.clientX+e+"px",n.style.top=event.clientY+ -g+"px"):(n.style.left=0.5*b.width+e+"px",n.style.top=0.5*b.height+g+"px");n.querySelector("button").addEventListener("click",h);b.parentNode.appendChild(n)};f.prototype.prompt=function(a,b,d,e){var c=this;a=a||"";var h=!1,k=document.createElement("div");k.className="graphdialog rounded";k.innerHTML=" ";k.close=function(){c.prompt_box=null;k.parentNode&&k.parentNode.removeChild(k)};1f.search_limit))break}if(Array.prototype.filter)for(l=Object.keys(e.registered_node_types).filter(function(a){return-1!==a.toLowerCase().indexOf(d)}),n=0;nf.search_limit);n++);else for(n in e.registered_node_types)if(-1!= -n.indexOf(d)&&(a(n),-1!==f.search_limit&&k++>f.search_limit))break}}var h=this,k=document.createElement("div");k.className="litegraph litesearchbox graphdialog rounded";k.innerHTML="Search
";k.close=function(){h.search_box=null;document.body.focus();setTimeout(function(){h.canvas.focus()},20);k.parentNode&&k.parentNode.removeChild(k)};var n=null;1";else if("enum"==h&&k.values){n=""}else if("boolean"==h)n="";else{console.warn("unknown type: "+ -h);return}var g=this.createDialog(""+b+""+n+"",d);if("enum"==h&&k.values){var l=g.querySelector("select");l.addEventListener("change",function(a){c(a.target.value)})}else if("boolean"==h)(l=g.querySelector("input"))&&l.addEventListener("click",function(a){c(!!l.checked)});else if(l=g.querySelector("input"))l.addEventListener("blur",function(a){this.focus()}),m=void 0!==a.properties[b]?a.properties[b]:"",m=JSON.stringify(m),l.value=m,l.addEventListener("keydown", -function(a){13==a.keyCode&&(e(),a.preventDefault(),a.stopPropagation())});g.querySelector("button").addEventListener("click",e)}};f.prototype.createDialog=function(a,b){b=b||{};var d=document.createElement("div");d.className="graphdialog";d.innerHTML=a;var e=this.canvas.getBoundingClientRect(),c=-20,h=-20;e&&(c-=e.left,h-=e.top);b.position?(c+=b.position[0],h+=b.position[1]):b.event?(c+=b.event.clientX,h+=b.event.clientY):(c+=0.5*this.canvas.width,h+=0.5*this.canvas.height);d.style.left=c+"px";d.style.top= -h+"px";this.canvas.parentNode.appendChild(d);d.close=function(){this.parentNode&&this.parentNode.removeChild(this)};return d};f.onMenuNodeCollapse=function(a,b,d,e,c){c.collapse()};f.onMenuNodePin=function(a,b,d,e,c){c.pin()};f.onMenuNodeMode=function(a,b,d,c,h){new e.ContextMenu(["Always","On Event","On Trigger","Never"],{event:d,callback:function(a){if(h)switch(a){case "On Event":h.mode=e.ON_EVENT;break;case "On Trigger":h.mode=e.ON_TRIGGER;break;case "Never":h.mode=e.NEVER;break;default:h.mode= -e.ALWAYS}},parentMenu:c,node:h});return!1};f.onMenuNodeColors=function(a,b,d,c,h){if(!h)throw"no node for color";b=[];b.push({value:null,content:"No color"});for(var k in f.node_colors)a=f.node_colors[k],a={value:k,content:""+k+""},b.push(a);new e.ContextMenu(b,{event:d,callback:function(a){h&&((a=a.value?f.node_colors[a.value]: -null)?h.constructor===e.LGraphGroup?h.color=a.groupcolor:(h.color=a.color,h.bgcolor=a.bgcolor):(delete h.color,delete h.bgcolor),h.setDirtyCanvas(!0,!0))},parentMenu:c,node:h});return!1};f.onMenuNodeShapes=function(a,b,d,c,h){if(!h)throw"no node passed";new e.ContextMenu(e.VALID_SHAPES,{event:d,callback:function(a){h&&(h.shape=a,h.setDirtyCanvas(!0))},parentMenu:c,node:h});return!1};f.onMenuNodeRemove=function(a,b,d,c,e){if(!e)throw"no node passed";!1!==e.removable&&(e.graph.remove(e),e.setDirtyCanvas(!0, -!0))};f.onMenuNodeClone=function(a,b,d,e,c){!1!=c.clonable&&(a=c.clone())&&(a.pos=[c.pos[0]+5,c.pos[1]+5],c.graph.add(a),c.setDirtyCanvas(!0,!0))};f.node_colors={red:{color:"#322",bgcolor:"#533",groupcolor:"#A88"},brown:{color:"#332922",bgcolor:"#593930",groupcolor:"#b06634"},green:{color:"#232",bgcolor:"#353",groupcolor:"#8A8"},blue:{color:"#223",bgcolor:"#335",groupcolor:"#88A"},pale_blue:{color:"#2a363b",bgcolor:"#3f5159",groupcolor:"#3f789e"},cyan:{color:"#233",bgcolor:"#355",groupcolor:"#8AA"}, -purple:{color:"#323",bgcolor:"#535",groupcolor:"#a1309b"},yellow:{color:"#432",bgcolor:"#653",groupcolor:"#b58b2a"},black:{color:"#222",bgcolor:"#000",groupcolor:"#444"}};f.prototype.getCanvasMenuOptions=function(){var a=null;this.getMenuOptions?a=this.getMenuOptions():(a=[{content:"Add Node",has_submenu:!0,callback:f.onMenuAdd},{content:"Add Group",callback:f.onGroupAdd}],this._graph_stack&&0Name",c),f=k.querySelector("input");f&&h&&(f.value=h.label||"");k.querySelector("button").addEventListener("click",function(a){f.value&&(h&&(h.label=f.value),d.setDirty(!0));k.close()})}},extra:a};a&&(k.title=a.type);var n=null;a&&(n=a.getSlotInPosition(b.canvasX,b.canvasY),f.active_node=a);if(n){h=[];n&&n.output&&n.output.links&&n.output.links.length&&h.push({content:"Disconnect Links",slot:n});var m=n.input|| -n.output;h.push(m.locked?"Cannot remove":{content:"Remove Slot",slot:n});h.push(m.nameLocked?"Cannot rename":{content:"Rename Slot",slot:n});k.title=(n.input?n.input.type:n.output.type)||"*";n.input&&n.input.type==e.ACTION&&(k.title="Action");n.output&&n.output.type==e.EVENT&&(k.title="Event")}else a?h=this.getNodeMenuOptions(a):(h=this.getCanvasMenuOptions(),(n=this.graph.getGroupOnPos(b.canvasX,b.canvasY))&&h.push(null,{content:"Edit Group",has_submenu:!0,submenu:{title:"Group",extra:n,options:this.getGroupMenuOptions(n)}})); -h&&new e.ContextMenu(h,k,c)};this.CanvasRenderingContext2D&&(CanvasRenderingContext2D.prototype.roundRect=function(a,b,d,c,e,h){void 0===e&&(e=5);void 0===h&&(h=e);this.moveTo(a+e,b);this.lineTo(a+d-e,b);this.quadraticCurveTo(a+d,b,a+d,b+e);this.lineTo(a+d,b+c-h);this.quadraticCurveTo(a+d,b+c,a+d-h,b+c);this.lineTo(a+h,b+c);this.quadraticCurveTo(a,b+c,a,b+c-h);this.lineTo(a,b+e);this.quadraticCurveTo(a,b,a+e,b)});e.compareObjects=function(a,b){for(var d in a)if(a[d]!=b[d])return!1;return!0};e.distance= -y;e.colorToString=function(a){return"rgba("+Math.round(255*a[0]).toFixed()+","+Math.round(255*a[1]).toFixed()+","+Math.round(255*a[2]).toFixed()+","+(4==a.length?a[3].toFixed(2):"1.0")+")"};e.isInsideRectangle=s;e.growBounding=function(a,b,d){ba[2]&&(a[2]=b);da[3]&&(a[3]=d)};e.isInsideBounding=function(a,b){return a[0]b[1][0]||a[1]>b[1][1]?!1:!0};e.overlapBounding=u;e.hex2num=function(a){"#"==a.charAt(0)&&(a=a.slice(1));a=a.toUpperCase(); -for(var b=Array(3),d=0,c,e,h=0;6>h;h+=2)c="0123456789ABCDEF".indexOf(a.charAt(h)),e="0123456789ABCDEF".indexOf(a.charAt(h+1)),b[d]=16*c+e,d++;return b};e.num2hex=function(a){for(var b="#",d,c,e=0;3>e;e++)d=a[e]/16,c=a[e]%16,b+="0123456789ABCDEF".charAt(d)+"0123456789ABCDEF".charAt(c);return b};z.prototype.addItem=function(a,b,d){function c(a){var b=this.value;b&&b.has_submenu&&e.call(this,a)}function e(a){var b=this.value,c=!0;h.current_submenu&&h.current_submenu.close(a);if(d.callback){var k=d.callback.call(this, -b,d,a,h,d.node);!0===k&&(c=!1)}if(b&&(b.callback&&!d.ignore_item_callbacks&&!0!==b.disabled&&(k=b.callback.call(this,b,d,a,h,d.extra),!0===k&&(c=!1)),b.submenu)){if(!b.submenu.options)throw"ContextMenu submenu needs options";new h.constructor(b.submenu.options,{callback:b.submenu.callback,event:a,parentMenu:h,ignore_item_callbacks:b.submenu.ignore_item_callbacks,title:b.submenu.title,extra:b.submenu.extra,autoopen:d.autoopen});c=!1}c&&!h.lock&&h.close()}var h=this;d=d||{};var k=document.createElement("div"); -k.className="litemenu-entry submenu";var f=!1;if(null===b)k.classList.add("separator");else{k.innerHTML=b&&b.title?b.title:a;if(k.value=b)b.disabled&&(f=!0,k.classList.add("disabled")),(b.submenu||b.has_submenu)&&k.classList.add("has_submenu");"function"==typeof b?(k.dataset.value=a,k.onclick_callback=b):k.dataset.value=b;b.className&&(k.className+=" "+b.className)}this.root.appendChild(k);f||k.addEventListener("click",e);d.autoopen&&k.addEventListener("mouseenter",c);return k};z.prototype.close= -function(a,b){this.root.parentNode&&this.root.parentNode.removeChild(this.root);this.parentMenu&&!b&&(this.parentMenu.lock=!1,this.parentMenu.current_submenu=null,void 0===a?this.parentMenu.close():a&&!z.isCursorOverElement(a,this.parentMenu.root)&&z.trigger(this.parentMenu.root,"mouseleave",a));this.current_submenu&&this.current_submenu.close(a,!0);this.root.closing_timer&&clearTimeout(this.root.closing_timer)};z.trigger=function(a,b,d,c){var e=document.createEvent("CustomEvent");e.initCustomEvent(b, -!0,!0,d);e.srcElement=c;a.dispatchEvent?a.dispatchEvent(e):a.__events&&a.__events.dispatchEvent(e);return e};z.prototype.getTopMenu=function(){return this.options.parentMenu?this.options.parentMenu.getTopMenu():this};z.prototype.getFirstEvent=function(){return this.options.parentMenu?this.options.parentMenu.getFirstEvent():this.options.event};z.isCursorOverElement=function(a,b){var d=a.clientX,c=a.clientY,e=b.getBoundingClientRect();return e?c>e.top&&ce.left&&da?b:dh.width-f.width-10&&(c=h.width-f.width-10);A>h.height-f.height-10&&(A=h.height-f.height-10)}e.style.left=c+"px";e.style.top=A+"px";b.scale&&(e.style.transform="scale("+b.scale+")")}var e=v.LiteGraph={VERSION:0.4,CANVAS_GRID_SIZE:10,NODE_TITLE_HEIGHT:30,NODE_TITLE_TEXT_Y:20,NODE_SLOT_HEIGHT:20,NODE_WIDGET_HEIGHT:20,NODE_WIDTH:140,NODE_MIN_WIDTH:50,NODE_COLLAPSED_RADIUS:10,NODE_COLLAPSED_WIDTH:80,NODE_TITLE_COLOR:"#999",NODE_TEXT_SIZE:14,NODE_TEXT_COLOR:"#AAA",NODE_SUBTEXT_SIZE:12, +NODE_DEFAULT_COLOR:"#333",NODE_DEFAULT_BGCOLOR:"#353535",NODE_DEFAULT_BOXCOLOR:"#666",NODE_DEFAULT_SHAPE:"box",DEFAULT_SHADOW_COLOR:"rgba(0,0,0,0.5)",DEFAULT_GROUP_FONT:24,WIDGET_BGCOLOR:"#222",WIDGET_OUTLINE_COLOR:"#666",WIDGET_TEXT_COLOR:"#DDD",WIDGET_SECONDARY_TEXT_COLOR:"#999",LINK_COLOR:"#9A9",EVENT_LINK_COLOR:"#A86",CONNECTING_LINK_COLOR:"#AFA",MAX_NUMBER_OF_NODES:1E3,DEFAULT_POSITION:[100,100],VALID_SHAPES:["default","box","round","card"],BOX_SHAPE:1,ROUND_SHAPE:2,CIRCLE_SHAPE:3,CARD_SHAPE:4, +ARROW_SHAPE:5,INPUT:1,OUTPUT:2,EVENT:-1,ACTION:-1,ALWAYS:0,ON_EVENT:1,NEVER:2,ON_TRIGGER:3,UP:1,DOWN:2,LEFT:3,RIGHT:4,CENTER:5,STRAIGHT_LINK:0,LINEAR_LINK:1,SPLINE_LINK:2,NORMAL_TITLE:0,NO_TITLE:1,TRANSPARENT_TITLE:2,AUTOHIDE_TITLE:3,proxy:null,node_images_path:"",debug:!1,catch_exceptions:!0,throw_errors:!0,allow_scripts:!1,registered_node_types:{},node_types_by_file_extension:{},Nodes:{},searchbox_extras:{},registerNodeType:function(a,b){if(!b.prototype)throw"Cannot register a simple object, it must be a class with a prototype"; +b.type=a;e.debug&&console.log("Node registered: "+a);a.split("/");var d=b.name,x=a.lastIndexOf("/");b.category=a.substr(0,x);b.title||(b.title=d);if(b.prototype)for(var p in g.prototype)b.prototype[p]||(b.prototype[p]=g.prototype[p]);Object.hasOwnProperty(b.prototype,"shape")||Object.defineProperty(b.prototype,"shape",{set:function(a){switch(a){case "default":delete this._shape;break;case "box":this._shape=e.BOX_SHAPE;break;case "round":this._shape=e.ROUND_SHAPE;break;case "circle":this._shape=e.CIRCLE_SHAPE; +break;case "card":this._shape=e.CARD_SHAPE;break;default:this._shape=a}},get:function(a){return this._shape},enumerable:!0});(x=this.registered_node_types[a])&&console.log("replacing node type: "+a);this.registered_node_types[a]=b;b.constructor.name&&(this.Nodes[d]=b);if(e.onNodeTypeRegistered)e.onNodeTypeRegistered(a,b);if(x&&e.onNodeTypeReplaced)e.onNodeTypeReplaced(a,b,x);b.prototype.onPropertyChange&&console.warn("LiteGraph node class "+a+" has onPropertyChange method, it must be called onPropertyChanged with d at the end"); +if(b.supported_extensions)for(p in b.supported_extensions)this.node_types_by_file_extension[b.supported_extensions[p].toLowerCase()]=b},wrapFunctionAsNode:function(a,b,d,x,p){for(var c=Array(b.length),A="",h=e.getParameterNames(b),f=0;fh&&(h=p.size[0]),f+=p.size[1]+a;b+=h+a}this.setDirtyCanvas(!0,!0)};c.prototype.getTime=function(){return this.globaltime};c.prototype.getFixedTime= +function(){return this.fixedtime};c.prototype.getElapsedTime=function(){return this.elapsed_time};c.prototype.sendEventToAllNodes=function(a,b,d){d=d||e.ALWAYS;var x=this._nodes_in_order?this._nodes_in_order:this._nodes;if(x)for(var p=0,c=x.length;p=e.MAX_NUMBER_OF_NODES)throw"LiteGraph: max number of nodes in a graph reached"; +null==a.id||-1==a.id?a.id=++this.last_node_id:this.last_node_ida.length||(this._pos[0]=a[0],this._pos[1]=a[1])},get:function(){return this._pos},enumerable:!0});this.id=-1;this.type=null;this.inputs=[];this.outputs=[];this.connections=[];this.properties={};this.properties_info=[];this.flags={}};g.prototype.configure=function(a){this.graph&&this.graph._version++;for(var b in a)if("properties"==b)for(var d in a.properties){if(this.properties[d]=a.properties[d], +this.onPropertyChanged)this.onPropertyChanged(d,a.properties[d])}else null!=a[b]&&("object"==typeof a[b]?this[b]&&this[b].configure?this[b].configure(a[b]):this[b]=e.cloneObject(a[b],this[b]):this[b]=a[b]);a.title||(this.title=this.constructor.title);if(this.onConnectionsChange){if(this.inputs)for(d=0;d=this.outputs.length)){var d=this.outputs[a];if(d&&(d._data=b,this.outputs[a].links))for(d=0;d=this.outputs.length)){var d=this.outputs[a];if(d&&(d.type=b,this.outputs[a].links))for(d=0;d= +this.inputs.length||null==this.inputs[a].link)){var d=this.graph.links[this.inputs[a].link];if(!d)return null;if(!b)return d.data;var e=this.graph.getNodeById(d.origin_id);if(!e)return d.data;if(e.updateOutputData)e.updateOutputData(d.origin_slot);else if(e.onExecute)e.onExecute();return d.data}};g.prototype.getInputDataType=function(a){if(!this.inputs||a>=this.inputs.length||null==this.inputs[a].link)return null;a=this.graph.links[this.inputs[a].link];if(!a)return null;var b=this.graph.getNodeById(a.origin_id); +return b?(a=b.outputs[a.origin_slot])?a.type:null:a.type};g.prototype.getInputDataByName=function(a,b){var d=this.findInputSlot(a);return-1==d?null:this.getInputData(d,b)};g.prototype.isInputConnected=function(a){return this.inputs?a=this.inputs.length)return null;a=this.inputs[a];return a&& +null!==a.link?(a=this.graph.links[a.link])?this.graph.getNodeById(a.origin_id):null:null};g.prototype.getInputOrProperty=function(a){if(!this.inputs||!this.inputs.length)return this.properties?this.properties[a]:null;for(var b=0,d=this.inputs.length;b=this.outputs.length?null:this.outputs[a]._data};g.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=[],d=0;da&&this.pos[1]-p-db)return!0;return!1};g.prototype.getSlotInPosition=function(a,b){var d=new Float32Array(2);if(this.inputs)for(var e=0,p=this.inputs.length;e=this.outputs.length)return e.debug&&console.log("Connect: Error, slot number not found"),null;b&&b.constructor===Number&&(b=this.graph.getNodeById(b)); +if(!b)throw"target node is null";if(b==this)return null;if(d.constructor===String){if(d=b.findInputSlot(d),-1==d)return e.debug&&console.log("Connect: Error, no slot of name "+d),null}else{if(d===e.EVENT)return null;if(!b.inputs||d>=b.inputs.length)return e.debug&&console.log("Connect: Error, slot number not found"),null}null!=b.inputs[d].link&&b.disconnectInput(d);var c=this.outputs[a];if(b.onConnectInput&&!1===b.onConnectInput(d,c.type,c))return null;var p=b.inputs[d],h=null;if(e.isValidConnection(c.type, +p.type)){h=new q(++this.graph.last_link_id,p.type,this.id,a,b.id,d);this.graph.links[h.id]=h;null==c.links&&(c.links=[]);c.links.push(h.id);b.inputs[d].link=h.id;this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(e.OUTPUT,a,!0,h,c);if(b.onConnectionsChange)b.onConnectionsChange(e.INPUT,d,!0,h,p);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(e.INPUT,b,d,this,a),this.graph.onNodeConnectionChange(e.OUTPUT,this,a,b,d))}this.setDirtyCanvas(!1, +!0);this.graph.connectionChange(this,h);return h};g.prototype.disconnectOutput=function(a,b){if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return e.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.outputs||a>=this.outputs.length)return e.debug&&console.log("Connect: Error, slot number not found"),!1;var d=this.outputs[a];if(!d||!d.links||0==d.links.length)return!1;if(b){b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"Target Node not found"; +for(var c=0,p=d.links.length;c=this.inputs.length)return e.debug&&console.log("Connect: Error, slot number not found"),!1;var b=this.inputs[a];if(!b)return!1;var d=this.inputs[a].link;this.inputs[a].link=null;var c=this.graph.links[d];if(c){var p=this.graph.getNodeById(c.origin_id);if(!p)return!1;var h=p.outputs[c.origin_slot];if(!h||!h.links||0==h.links.length)return!1;for(var f=0,k=h.links.length;fb&&this.inputs[b].pos)return d[0]=this.pos[0]+this.inputs[b].pos[0],d[1]=this.pos[1]+this.inputs[b].pos[1],d;if(!a&&c>b&&this.outputs[b].pos)return d[0]=this.pos[0]+this.outputs[b].pos[0], +d[1]=this.pos[1]+this.outputs[b].pos[1],d;if(this.horizontal)return d[0]=this.pos[0]+this.size[0]/c*(b+0.5),d[1]=a?this.pos[1]-e.NODE_TITLE_HEIGHT:this.pos[1]+this.size[1],d;d[0]=a?this.pos[0]+p:this.pos[0]+this.size[0]+1-p;d[1]=this.pos[1]+(b+0.7)*e.NODE_SLOT_HEIGHT+(this.constructor.slot_start_y||0);return d};g.prototype.alignToGrid=function(){this.pos[0]=e.CANVAS_GRID_SIZE*Math.round(this.pos[0]/e.CANVAS_GRID_SIZE);this.pos[1]=e.CANVAS_GRID_SIZE*Math.round(this.pos[1]/e.CANVAS_GRID_SIZE)};g.prototype.trace= +function(a){this.console||(this.console=[]);this.console.push(a);this.console.length>g.MAX_CONSOLE&&this.console.shift();this.graph.onNodeTrace(this,a)};g.prototype.setDirtyCanvas=function(a,b){this.graph&&this.graph.sendActionToCanvas("setDirty",[a,b])};g.prototype.loadImage=function(a){var b=new Image;b.src=e.node_images_path+a;b.ready=!1;var d=this;b.onload=function(){this.ready=!0;d.setDirtyCanvas(!0)};return b};g.prototype.captureInput=function(a){if(this.graph&&this.graph.list_of_graphcanvas)for(var b= +this.graph.list_of_graphcanvas,d=0;da.length||(this._pos[0]=a[0],this._pos[1]=a[1])},get:function(){return this._pos},enumerable:!0}); +Object.defineProperty(this,"size",{set:function(a){!a||2>a.length||(this._size[0]=Math.max(140,a[0]),this._size[1]=Math.max(80,a[1]))},get:function(){return this._size},enumerable:!0})};l.prototype.configure=function(a){this.title=a.title;this._bounding.set(a.bounding);this.color=a.color;this.font=a.font};l.prototype.serialize=function(){var a=this._bounding;return{title:this.title,bounding:[Math.round(a[0]),Math.round(a[1]),Math.round(a[2]),Math.round(a[3])],color:this.color,font:this.font}};l.prototype.move= +function(a,b,d){this._pos[0]+=a;this._pos[1]+=b;if(!d)for(d=0;dthis.max_scale&&(a=this.max_scale);if(a!=this.scale&&this.element){var d=this.element.getBoundingClientRect(); +if(d){b=b||[0.5*d.width,0.5*d.height];d=this.convertCanvasToOffset(b);this.scale=a;0.01>Math.abs(this.scale-1)&&(this.scale=1);var e=this.convertCanvasToOffset(b),d=[e[0]-d[0],e[1]-d[1]];this.offset[0]+=d[0];this.offset[1]+=d[1];if(this.onredraw)this.onredraw(this)}}};r.prototype.changeDeltaScale=function(a,b){this.changeScale(this.scale*a,b)};r.prototype.reset=function(){this.scale=1;this.offset[0]=0;this.offset[1]=0};v.LGraphCanvas=e.LGraphCanvas=f;f.link_type_colors={"-1":e.EVENT_LINK_COLOR,number:"#AAA", +node:"#DCA"};f.gradients={};f.prototype.clear=function(){this.fps=this.render_time=this.last_draw_time=this.frame=0;this.dragging_rectangle=null;this.selected_nodes={};this.selected_group=null;this.visible_nodes=[];this.connecting_node=this.node_capturing_input=this.node_over=this.node_dragged=null;this.highlighted_links={};this.dirty_bgcanvas=this.dirty_canvas=!0;this.node_widget=this.node_in_panel=this.dirty_area=null;this.last_mouse=[0,0];this.last_mouseclick=0;this.visible_area.set([0,0,0,0]); +if(this.onClear)this.onClear()};f.prototype.setGraph=function(a,b){this.graph!=a&&(b||this.clear(),!a&&this.graph?this.graph.detachCanvas(this):(a.attachCanvas(this),this.setDirty(!0,!0)))};f.prototype.openSubgraph=function(a){if(!a)throw"graph cannot be null";if(this.graph==a)throw"graph cannot be the same";this.clear();this.graph&&(this._graph_stack||(this._graph_stack=[]),this._graph_stack.push(this.graph));a.attachCanvas(this);this.setDirty(!0,!0)};f.prototype.closeSubgraph=function(){if(this._graph_stack&& +0!=this._graph_stack.length){var a=this.graph._subgraph_node,b=this._graph_stack.pop();this.selected_nodes={};this.highlighted_links={};b.attachCanvas(this);this.setDirty(!0,!0);a&&(this.centerOnNode(a),this.selectNodes([a]))}};f.prototype.getCurrentGraph=function(){return this.graph};f.prototype.setCanvas=function(a,b){if(a&&a.constructor===String&&(a=document.getElementById(a),!a))throw"Error creating LiteGraph canvas: Canvas not found";if(a!==this.canvas&&(!a&&this.canvas&&(b||this.unbindEvents()), +this.canvas=a,this.ds.element=a)){a.className+=" lgraphcanvas";a.data=this;a.tabindex="1";this.bgcanvas=null;this.bgcanvas||(this.bgcanvas=document.createElement("canvas"),this.bgcanvas.width=this.canvas.width,this.bgcanvas.height=this.canvas.height);if(null==a.getContext){if("canvas"!=a.localName)throw"Element supplied for LGraphCanvas must be a element, you passed a "+a.localName;throw"This browser doesn't support Canvas";}null==(this.ctx=a.getContext("2d"))&&(a.webgl_enabled||console.warn("This canvas seems to be WebGL, enabling WebGL renderer"), +this.enableWebGL());this._mousemove_callback=this.processMouseMove.bind(this);this._mouseup_callback=this.processMouseUp.bind(this);b||this.bindEvents()}};f.prototype._doNothing=function(a){a.preventDefault();return!1};f.prototype._doReturnTrue=function(a){a.preventDefault();return!0};f.prototype.bindEvents=function(){if(this._events_binded)console.warn("LGraphCanvas: events already binded");else{var a=this.canvas,b=this.getCanvasWindow().document;this._mousedown_callback=this.processMouseDown.bind(this); +this._mousewheel_callback=this.processMouseWheel.bind(this);a.addEventListener("mousedown",this._mousedown_callback,!0);a.addEventListener("mousemove",this._mousemove_callback);a.addEventListener("mousewheel",this._mousewheel_callback,!1);a.addEventListener("contextmenu",this._doNothing);a.addEventListener("DOMMouseScroll",this._mousewheel_callback,!1);a.addEventListener("touchstart",this.touchHandler,!0);a.addEventListener("touchmove",this.touchHandler,!0);a.addEventListener("touchend",this.touchHandler, +!0);a.addEventListener("touchcancel",this.touchHandler,!0);this._key_callback=this.processKey.bind(this);a.addEventListener("keydown",this._key_callback,!0);b.addEventListener("keyup",this._key_callback,!0);this._ondrop_callback=this.processDrop.bind(this);a.addEventListener("dragover",this._doNothing,!1);a.addEventListener("dragend",this._doNothing,!1);a.addEventListener("drop",this._ondrop_callback,!1);a.addEventListener("dragenter",this._doReturnTrue,!1);this._events_binded=!0}};f.prototype.unbindEvents= +function(){if(this._events_binded){var a=this.getCanvasWindow().document;this.canvas.removeEventListener("mousedown",this._mousedown_callback);this.canvas.removeEventListener("mousewheel",this._mousewheel_callback);this.canvas.removeEventListener("DOMMouseScroll",this._mousewheel_callback);this.canvas.removeEventListener("keydown",this._key_callback);a.removeEventListener("keyup",this._key_callback);this.canvas.removeEventListener("contextmenu",this._doNothing);this.canvas.removeEventListener("drop", +this._ondrop_callback);this.canvas.removeEventListener("dragenter",this._doReturnTrue);this.canvas.removeEventListener("touchstart",this.touchHandler);this.canvas.removeEventListener("touchmove",this.touchHandler);this.canvas.removeEventListener("touchend",this.touchHandler);this.canvas.removeEventListener("touchcancel",this.touchHandler);this._ondrop_callback=this._key_callback=this._mousewheel_callback=this._mousedown_callback=null;this._events_binded=!1}else console.warn("LGraphCanvas: no events binded")}; +f.getFileExtension=function(a){var b=a.indexOf("?");-1!=b&&(a=a.substr(0,b));b=a.lastIndexOf(".");return-1==b?"":a.substr(b+1).toLowerCase()};f.prototype.enableWebGL=function(){if(void 0===typeof GL)throw"litegl.js must be included to use a WebGL canvas";if(void 0===typeof enableWebGLCanvas)throw"webglCanvas.js must be included to use this feature";this.gl=this.ctx=enableWebGLCanvas(this.canvas);this.ctx.webgl=!0;this.bgcanvas=this.canvas;this.bgctx=this.gl;this.canvas.webgl_enabled=!0};f.prototype.setDirty= +function(a,b){a&&(this.dirty_canvas=!0);b&&(this.dirty_bgcanvas=!0)};f.prototype.getCanvasWindow=function(){if(!this.canvas)return window;var a=this.canvas.ownerDocument;return a.defaultView||a.parentWindow};f.prototype.startRendering=function(){function a(){this.pause_rendering||this.draw();var b=this.getCanvasWindow();this.is_rendering&&b.requestAnimationFrame(a.bind(this))}this.is_rendering||(this.is_rendering=!0,a.call(this))};f.prototype.stopRendering=function(){this.is_rendering=!1};f.prototype.processMouseDown= +function(a){if(this.graph){this.adjustMouseEvent(a);var b=this.getCanvasWindow();f.active_canvas=this;this.canvas.removeEventListener("mousemove",this._mousemove_callback);b.document.addEventListener("mousemove",this._mousemove_callback,!0);b.document.addEventListener("mouseup",this._mouseup_callback,!0);var d=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes,5),c=!1,p=300>e.getTime()-this.last_mouseclick;this.canvas_mouse[0]=a.canvasX;this.canvas_mouse[1]=a.canvasY;this.canvas.focus(); +e.closeAllContextMenus(b);if(!this.onMouse||!0!=this.onMouse(a)){if(1==a.which){a.ctrlKey&&(this.dragging_rectangle=new Float32Array(4),this.dragging_rectangle[0]=a.canvasX,this.dragging_rectangle[1]=a.canvasY,this.dragging_rectangle[2]=1,this.dragging_rectangle[3]=1,c=!0);var h=!1;if(d&&this.allow_interaction&&!c&&!this.read_only){this.live_mode||d.flags.pinned||this.bringToFront(d);if(!this.connecting_node&&!d.flags.collapsed&&!this.live_mode)if(!c&&!1!==d.resizable&&s(a.canvasX,a.canvasY,d.pos[0]+ +d.size[0]-5,d.pos[1]+d.size[1]-5,10,10))this.resizing_node=d,this.canvas.style.cursor="se-resize",c=!0;else{if(d.outputs)for(var k=0,n=d.outputs.length;kh[0]+4||a.canvasYh[1]+4)){this.showLinkMenu(d,a);break}this.selected_group=this.graph.getGroupOnPos(a.canvasX,a.canvasY);this.selected_group_resizing=!1;this.selected_group&&!this.read_only&&(a.ctrlKey&&(this.dragging_rectangle=null),10>y([a.canvasX,a.canvasY],[this.selected_group.pos[0]+ +this.selected_group.size[0],this.selected_group.pos[1]+this.selected_group.size[1]])*this.ds.scale?this.selected_group_resizing=!0:this.selected_group.recomputeInsideNodes());p&&!this.read_only&&this.showSearchBox(a);h=!0}!c&&h&&this.allow_dragcanvas&&(this.dragging_canvas=!0)}else 2!=a.which&&3==a.which&&(this.read_only||this.processContextMenu(d,a));this.last_mouse[0]=a.localX;this.last_mouse[1]=a.localY;this.last_mouseclick=e.getTime();this.last_mouse_dragging=!0;this.graph.change();(!b.document.activeElement|| +"input"!=b.document.activeElement.nodeName.toLowerCase()&&"textarea"!=b.document.activeElement.nodeName.toLowerCase())&&a.preventDefault();a.stopPropagation();if(this.onMouseDown)this.onMouseDown(a);return!1}}};f.prototype.processMouseMove=function(a){this.autoresize&&this.resize();if(this.graph){f.active_canvas=this;this.adjustMouseEvent(a);var b=[a.localX,a.localY],d=[b[0]-this.last_mouse[0],b[1]-this.last_mouse[1]];this.last_mouse=b;this.canvas_mouse[0]=a.canvasX;this.canvas_mouse[1]=a.canvasY; +a.dragging=this.last_mouse_dragging;this.node_widget&&(this.processNodeWidgets(this.node_widget[0],this.canvas_mouse,a,this.node_widget[1]),this.dirty_canvas=!0);if(this.dragging_rectangle)this.dragging_rectangle[2]=a.canvasX-this.dragging_rectangle[0],this.dragging_rectangle[3]=a.canvasY-this.dragging_rectangle[1],this.dirty_canvas=!0;else if(this.selected_group&&!this.read_only)this.selected_group_resizing?this.selected_group.size=[a.canvasX-this.selected_group.pos[0],a.canvasY-this.selected_group.pos[1]]: +(this.selected_group.move(d[0]/this.ds.scale,d[1]/this.ds.scale,a.ctrlKey),this.selected_group._nodes.length&&(this.dirty_canvas=!0)),this.dirty_bgcanvas=!0;else if(this.dragging_canvas)this.ds.offset[0]+=d[0]/this.ds.scale,this.ds.offset[1]+=d[1]/this.ds.scale,this.dirty_bgcanvas=this.dirty_canvas=!0;else if(this.allow_interaction&&!this.read_only){this.connecting_node&&(this.dirty_canvas=!0);for(var c=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes),b=0,p=this.graph._nodes.length;b< +p;++b)if(this.graph._nodes[b].mouseOver&&c!=this.graph._nodes[b]){this.graph._nodes[b].mouseOver=!1;if(this.node_over&&this.node_over.onMouseLeave)this.node_over.onMouseLeave(a);this.node_over=null;this.dirty_canvas=!0}if(c){if(!c.mouseOver&&(c.mouseOver=!0,this.node_over=c,this.dirty_canvas=!0,c.onMouseEnter))c.onMouseEnter(a);if(c.onMouseMove)c.onMouseMove(a,[a.canvasX-c.pos[0],a.canvasY-c.pos[1]],this);if(this.connecting_node&&(p=this._highlight_input||[0,0],!this.isOverNodeBox(c,a.canvasX,a.canvasY))){var h= +this.isOverNodeInput(c,a.canvasX,a.canvasY,p);-1!=h&&c.inputs[h]?e.isValidConnection(this.connecting_output.type,c.inputs[h].type)&&(this._highlight_input=p):this._highlight_input=null}this.canvas&&(s(a.canvasX,a.canvasY,c.pos[0]+c.size[0]-5,c.pos[1]+c.size[1]-5,5,5)?this.canvas.style.cursor="se-resize":this.canvas.style.cursor="crosshair")}else{p=null;for(b=0;bk[0]+4||a.canvasY +k[1]+4)){p=h;break}}p!=this.over_link_center&&(this.over_link_center=p,this.dirty_canvas=!0);this.canvas&&(this.canvas.style.cursor="")}if(this.node_capturing_input&&this.node_capturing_input!=c&&this.node_capturing_input.onMouseMove)this.node_capturing_input.onMouseMove(a);if(this.node_dragged&&!this.live_mode){for(b in this.selected_nodes)c=this.selected_nodes[b],c.pos[0]+=d[0]/this.ds.scale,c.pos[1]+=d[1]/this.ds.scale;this.dirty_bgcanvas=this.dirty_canvas=!0}this.resizing_node&&!this.live_mode&& +(this.resizing_node.size[0]=a.canvasX-this.resizing_node.pos[0],this.resizing_node.size[1]=a.canvasY-this.resizing_node.pos[1],d=Math.max(this.resizing_node.inputs?this.resizing_node.inputs.length:0,this.resizing_node.outputs?this.resizing_node.outputs.length:0)*e.NODE_SLOT_HEIGHT+(this.resizing_node.widgets?this.resizing_node.widgets.length:0)*(e.NODE_WIDGET_HEIGHT+4)+4,this.resizing_node.size[1]this.dragging_rectangle[3]?this.dragging_rectangle[1]-p:this.dragging_rectangle[1];this.dragging_rectangle[0]=0>this.dragging_rectangle[2]?this.dragging_rectangle[0]-c:this.dragging_rectangle[0];this.dragging_rectangle[1]=h;this.dragging_rectangle[2]=c;this.dragging_rectangle[3]=p;p=[];for(h=0;ha.click_time&& +s(a.canvasX,a.canvasY,c.pos[0],c.pos[1]-e.NODE_TITLE_HEIGHT,e.NODE_TITLE_HEIGHT,e.NODE_TITLE_HEIGHT)&&c.collapse();this.dirty_bgcanvas=this.dirty_canvas=!0;this.node_dragged.pos[0]=Math.round(this.node_dragged.pos[0]);this.node_dragged.pos[1]=Math.round(this.node_dragged.pos[1]);this.graph.config.align_to_grid&&this.node_dragged.alignToGrid();if(this.onNodeMoved)this.onNodeMoved(this.node_dragged);this.node_dragged=null}else{c=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes);!c&&300> +a.click_time&&this.deselectAllNodes();this.dirty_canvas=!0;this.dragging_canvas=!1;if(this.node_over&&this.node_over.onMouseUp)this.node_over.onMouseUp(a,[a.canvasX-this.node_over.pos[0],a.canvasY-this.node_over.pos[1]],this);if(this.node_capturing_input&&this.node_capturing_input.onMouseUp)this.node_capturing_input.onMouseUp(a,[a.canvasX-this.node_capturing_input.pos[0],a.canvasY-this.node_capturing_input.pos[1]])}}else 2==a.which?(this.dirty_canvas=!0,this.dragging_canvas=!1):3==a.which&&(this.dirty_canvas= +!0,this.dragging_canvas=!1);this.graph.change();a.stopPropagation();a.preventDefault();return!1}};f.prototype.processMouseWheel=function(a){if(this.graph&&this.allow_dragcanvas){var b=null!=a.wheelDeltaY?a.wheelDeltaY:-60*a.detail;this.adjustMouseEvent(a);var d=this.ds.scale;0b&&(d*=1/1.1);this.ds.changeScale(d,[a.localX,a.localY]);this.graph.change();a.preventDefault();return!1}};f.prototype.isOverNodeBox=function(a,b,d){var c=e.NODE_TITLE_HEIGHT;return s(b,d,a.pos[0]+2,a.pos[1]+2-c, +c-4,c-4)?!0:!1};f.prototype.isOverNodeInput=function(a,b,d,e){if(a.inputs)for(var c=0,h=a.inputs.length;cd-this.graph._last_trigger_time)&&this.drawBackCanvas();(this.dirty_canvas||a)&&this.drawFrontCanvas();this.fps=this.render_time?1/this.render_time:0;this.frame+=1}};f.prototype.drawFrontCanvas=function(){this.dirty_canvas= +!1;this.ctx||(this.ctx=this.bgcanvas.getContext("2d"));var a=this.ctx;if(a){a.start2D&&a.start2D();var b=this.canvas;a.restore();a.setTransform(1,0,0,1,0,0);this.dirty_area&&(a.save(),a.beginPath(),a.rect(this.dirty_area[0],this.dirty_area[1],this.dirty_area[2],this.dirty_area[3]),a.clip());this.clear_background&&a.clearRect(0,0,b.width,b.height);this.bgcanvas==this.canvas?this.drawBackCanvas():a.drawImage(this.bgcanvas,0,0);if(this.onRender)this.onRender(b,a);this.show_info&&this.renderInfo(a);if(this.graph){a.save(); +this.ds.toCanvasContext(a);for(var b=this.computeVisibleNodes(null,this.visible_nodes),d=0;d> ";b.fillText(e+d.getTitle(),0.5*a.width,40);b.restore()}d=!1;this.onRenderBackground&&(d=this.onRenderBackground(a,b));b.restore();b.setTransform(1,0,0,1,0,0);this.visible_links.length=0;if(this.graph){b.save();this.ds.toCanvasContext(b);if(this.background_image&&0.5this.ds.scale,t=a._shape||a.constructor.shape||e.ROUND_SHAPE,l=a.constructor.title_mode, +g=!0;l==e.TRANSPARENT_TITLE?g=!1:l==e.AUTOHIDE_TITLE&&k&&(g=!0);n[0]=0;n[1]=g?-p:0;n[2]=d[0]+1;n[3]=g?d[1]+p:d[1];k=b.globalAlpha;b.beginPath();t==e.BOX_SHAPE||m?b.fillRect(n[0],n[1],n[2],n[3]):t==e.ROUND_SHAPE||t==e.CARD_SHAPE?b.roundRect(n[0],n[1],n[2],n[3],this.round_radius,t==e.CARD_SHAPE?0:this.round_radius):t==e.CIRCLE_SHAPE&&b.arc(0.5*d[0],0.5*d[1],0.5*d[0],0,2*Math.PI);b.fill();a.flags.collapsed||(b.shadowColor="transparent",b.fillStyle="rgba(0,0,0,0.2)",b.fillRect(0,-1,n[2],2));b.shadowColor= +"transparent";if(a.onDrawBackground)a.onDrawBackground(b,this,this.canvas);if(g||l==e.TRANSPARENT_TITLE){if(a.onDrawTitleBar)a.onDrawTitleBar(b,p,d,this.ds.scale,c);else if(l!=e.TRANSPARENT_TITLE&&(a.constructor.title_color||this.render_title_colored)){g=a.constructor.title_color||c;a.flags.collapsed&&(b.shadowColor=e.DEFAULT_SHADOW_COLOR);if(this.use_gradients){var s=f.gradients[g];s||(s=f.gradients[g]=b.createLinearGradient(0,0,400,0),s.addColorStop(0,g),s.addColorStop(1,"#000"));b.fillStyle=s}else b.fillStyle= +g;b.beginPath();t==e.BOX_SHAPE||m?b.rect(0,-p,d[0]+1,p):t!=e.ROUND_SHAPE&&t!=e.CARD_SHAPE||b.roundRect(0,-p,d[0]+1,p,this.round_radius,a.flags.collapsed?this.round_radius:0);b.fill();b.shadowColor="transparent"}if(a.onDrawTitleBox)a.onDrawTitleBox(b,p,d,this.ds.scale);else t==e.ROUND_SHAPE||t==e.CIRCLE_SHAPE||t==e.CARD_SHAPE?(m&&(b.fillStyle="black",b.beginPath(),b.arc(0.5*p,-0.5*p,6,0,2*Math.PI),b.fill()),b.fillStyle=a.boxcolor||e.NODE_DEFAULT_BOXCOLOR,b.beginPath(),b.arc(0.5*p,-0.5*p,5,0,2*Math.PI), +b.fill()):(m&&(b.fillStyle="black",b.fillRect(0.5*(p-10)-1,-0.5*(p+10)-1,12,12)),b.fillStyle=a.boxcolor||e.NODE_DEFAULT_BOXCOLOR,b.fillRect(0.5*(p-10),-0.5*(p+10),10,10));b.globalAlpha=k;if(a.onDrawTitleText)a.onDrawTitleText(b,p,d,this.ds.scale,this.title_text_font,h);!m&&(b.font=this.title_text_font,m=a.getTitle())&&(b.fillStyle=h?"white":a.constructor.title_text_color||this.node_title_color,a.flags.collapsed?(b.textAlign="center",k=b.measureText(m),b.fillText(m,p+0.5*k.width,e.NODE_TITLE_TEXT_Y- +p),b.textAlign="left"):(b.textAlign="left",b.fillText(m,p,e.NODE_TITLE_TEXT_Y-p)));if(a.onDrawTitle)a.onDrawTitle(b)}if(h){if(a.onBounding)a.onBounding(n);l==e.TRANSPARENT_TITLE&&(n[1]-=p,n[3]+=p);b.lineWidth=1;b.globalAlpha=0.8;b.beginPath();t==e.BOX_SHAPE?b.rect(-6+n[0],-6+n[1],12+n[2],12+n[3]):t==e.ROUND_SHAPE||t==e.CARD_SHAPE&&a.flags.collapsed?b.roundRect(-6+n[0],-6+n[1],12+n[2],12+n[3],2*this.round_radius):t==e.CARD_SHAPE?b.roundRect(-6+n[0],-6+n[1],12+n[2],12+n[3],2*this.round_radius,2):t== +e.CIRCLE_SHAPE&&b.arc(0.5*d[0],0.5*d[1],0.5*d[0]+6,0,2*Math.PI);b.strokeStyle="#FFF";b.stroke();b.strokeStyle=c;b.globalAlpha=1}};var D=new Float32Array(4),h=new Float32Array(4),t=new Float32Array(2),m=new Float32Array(2);f.prototype.drawConnections=function(a){var b=e.getTime(),d=this.visible_area;D[0]=d[0]-20;D[1]=d[1]-20;D[2]=d[2]+40;D[3]=d[3]+40;a.lineWidth=this.connections_width;a.fillStyle="#AAA";a.strokeStyle="#AAA";a.globalAlpha=this.editor_alpha;for(var d=this.graph._nodes,c=0,p=d.length;c< +p;++c){var k=d[c];if(k.inputs&&k.inputs.length)for(var f=0;fh[2]&&(h[0]+=h[2],h[2]=Math.abs(h[2]));0>h[3]&&(h[1]+=h[3],h[3]=Math.abs(h[3]));if(u(h,D)){var B=l.outputs[g],g=k.inputs[f];if(B&& +g&&(l=B.dir||(l.horizontal?e.DOWN:e.RIGHT),g=g.dir||(k.horizontal?e.UP:e.LEFT),this.renderLink(a,s,w,n,!1,0,null,l,g),n&&n._last_time&&1E3>b-n._last_time)){var B=2-0.002*(b-n._last_time),J=a.globalAlpha;a.globalAlpha=J*B;this.renderLink(a,s,w,n,!0,B,"white",l,g);a.globalAlpha=J}}}}}}a.globalAlpha=1};f.prototype.renderLink=function(a,b,d,c,p,h,k,n,m,t){c&&this.visible_links.push(c);!k&&c&&(k=c.color||f.link_type_colors[c.type]);k||(k=this.default_link_color);null!=c&&this.highlighted_links[c.id]&& +(k="#FFF");n=n||e.RIGHT;m=m||e.LEFT;var l=y(b,d);this.render_connections_border&&0.6b[1]?0:Math.PI,a.save(),a.translate(g[0],g[1]),a.rotate(B),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore(),a.save(),a.translate(t[0],t[1]),a.rotate(s), +a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore()),a.beginPath(),a.arc(p[0],p[1],5,0,2*Math.PI),a.fill());if(h)for(a.fillStyle=k,g=0;5>g;++g)h=(0.001*e.getTime()+0.2*g)%1,p=this.computeConnectionPoint(b,d,h,n,m),a.beginPath(),a.arc(p[0],p[1],5,0,2*Math.PI),a.fill()};f.prototype.computeConnectionPoint=function(a,b,d,c,p){c=c||e.RIGHT;p=p||e.LEFT;var h=y(a,b),k=[a[0],a[1]],f=[b[0],b[1]];switch(c){case e.LEFT:k[0]+=-0.25*h;break;case e.RIGHT:k[0]+=0.25*h;break;case e.UP:k[1]+= +-0.25*h;break;case e.DOWN:k[1]+=0.25*h}switch(p){case e.LEFT:f[0]+=-0.25*h;break;case e.RIGHT:f[0]+=0.25*h;break;case e.UP:f[1]+=-0.25*h;break;case e.DOWN:f[1]+=0.25*h}c=(1-d)*(1-d)*(1-d);p=3*(1-d)*(1-d)*d;h=3*(1-d)*d*d;d*=d*d;return[c*a[0]+p*k[0]+h*f[0]+d*b[0],c*a[1]+p*k[1]+h*f[1]+d*b[1]]};f.prototype.drawExecutionOrder=function(a){a.shadowColor="transparent";a.globalAlpha=0.25;a.textAlign="center";a.strokeStyle="white";a.globalAlpha=0.75;for(var b=this.visible_nodes,d=0;dg.last_y&&fg.options.max&&(g.value=g.options.max);else if("mousedown"==d.type)if((c=g.options.values)&&c.constructor===Function&&(c=g.options.values(g,a)),k=40>k?-1:k>n-40?1:0,"number"==g.type)g.value+=0.1*k*(g.options.step||1),null!=g.options.min&&g.valueg.options.max&&(g.value=g.options.max);else if(k)t= +c.indexOf(g.value)+k,t>=c.length&&(t=0),0>t&&(t=c.length-1),g.value=c[t];else{new e.ContextMenu(c,{scale:Math.max(1,this.ds.scale),event:d,className:"dark",callback:B.bind(g)},t);var B=function(a,b,d){this.value=a;h(this,a);m.dirty_canvas=!0;return!1}}setTimeout(function(){h(this,this.value)}.bind(g),20);this.dirty_canvas=!0;break;case "toggle":"mousedown"==d.type&&(g.value=!g.value,g.callback&&setTimeout(function(){h(g,g.value)},20));break;case "string":case "text":"mousedown"==d.type&&this.prompt("Value", +g.value,function(a){this.value=a;h(this,a)}.bind(g),d);break;default:g.mouse&&g.mouse(ctx,d,[k,f],a)}return g}}return null};f.prototype.drawGroups=function(a,b){if(this.graph){var d=this.graph._groups;b.save();b.globalAlpha=0.5*this.editor_alpha;for(var c=0;cd&&0.01>b.editor_alpha&&(clearInterval(e),1>d&&(b.live_mode=!0));1"+g+""+a+"",value:g});if(m.length)return new e.ContextMenu(m,{event:d,callback:k,parentMenu:c,allow_html:!0,node:h},b),!1}};f.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};f.onResizeNode=function(a, +b,d,e,c){c&&(c.size=c.computeSize(),c.setDirtyCanvas(!0,!0))};f.prototype.showLinkMenu=function(a,b){var d=this;console.log(a.data);new e.ContextMenu(["Delete"],{event:b,title:null!=a.data?a.data.constructor.name:null,callback:function(b){switch(b){case "Delete":d.graph.removeLink(a.id)}}});return!1};f.onShowPropertyEditor=function(a,b,d,e,c){function h(){var b=m.value;"Number"==a.type?b=Number(b):"Boolean"==a.type&&(b=Boolean(b));c[k]=b;n.parentNode&&n.parentNode.removeChild(n);c.setDirtyCanvas(!0, +!0)}var k=a.property||"title";b=c[k];var n=document.createElement("div");n.className="graphdialog";n.innerHTML="";n.querySelector(".name").innerText=k;var m=n.querySelector("input");m&&(m.value=b,m.addEventListener("blur",function(a){this.focus()}),m.addEventListener("keydown",function(a){13==a.keyCode&&(h(),a.preventDefault(),a.stopPropagation())}));b=f.active_canvas.canvas;d=b.getBoundingClientRect();var g= +e=-20;d&&(e-=d.left,g-=d.top);event?(n.style.left=event.clientX+e+"px",n.style.top=event.clientY+g+"px"):(n.style.left=0.5*b.width+e+"px",n.style.top=0.5*b.height+g+"px");n.querySelector("button").addEventListener("click",h);b.parentNode.appendChild(n)};f.prototype.prompt=function(a,b,d,e){var c=this;a=a||"";var h=!1,k=document.createElement("div");k.className="graphdialog rounded";k.innerHTML=" "; +k.close=function(){c.prompt_box=null;k.parentNode&&k.parentNode.removeChild(k)};1f.search_limit))break}if(Array.prototype.filter)for(l=Object.keys(e.registered_node_types).filter(function(a){return-1!==a.toLowerCase().indexOf(d)}),n=0;nf.search_limit);n++);else for(n in e.registered_node_types)if(-1!=n.indexOf(d)&&(a(n),-1!==f.search_limit&&k++>f.search_limit))break}}var h=this,k=document.createElement("div");k.className="litegraph litesearchbox graphdialog rounded";k.innerHTML="Search
";k.close=function(){h.search_box=null;document.body.focus();setTimeout(function(){h.canvas.focus()},20);k.parentNode&&k.parentNode.removeChild(k)}; +var n=null;1";else if("enum"==h&&k.values){n=""}else if("boolean"==h)n="";else{console.warn("unknown type: "+h);return}var g=this.createDialog(""+b+""+n+"",d);if("enum"==h&&k.values){var l=g.querySelector("select");l.addEventListener("change",function(a){c(a.target.value)})}else if("boolean"==h)(l=g.querySelector("input"))&&l.addEventListener("click",function(a){c(!!l.checked)});else if(l=g.querySelector("input"))l.addEventListener("blur",function(a){this.focus()}),m=void 0!==a.properties[b]? +a.properties[b]:"",m=JSON.stringify(m),l.value=m,l.addEventListener("keydown",function(a){13==a.keyCode&&(e(),a.preventDefault(),a.stopPropagation())});g.querySelector("button").addEventListener("click",e)}};f.prototype.createDialog=function(a,b){b=b||{};var d=document.createElement("div");d.className="graphdialog";d.innerHTML=a;var e=this.canvas.getBoundingClientRect(),c=-20,h=-20;e&&(c-=e.left,h-=e.top);b.position?(c+=b.position[0],h+=b.position[1]):b.event?(c+=b.event.clientX,h+=b.event.clientY): +(c+=0.5*this.canvas.width,h+=0.5*this.canvas.height);d.style.left=c+"px";d.style.top=h+"px";this.canvas.parentNode.appendChild(d);d.close=function(){this.parentNode&&this.parentNode.removeChild(this)};return d};f.onMenuNodeCollapse=function(a,b,d,e,c){c.collapse()};f.onMenuNodePin=function(a,b,d,e,c){c.pin()};f.onMenuNodeMode=function(a,b,d,c,h){new e.ContextMenu(["Always","On Event","On Trigger","Never"],{event:d,callback:function(a){if(h)switch(a){case "On Event":h.mode=e.ON_EVENT;break;case "On Trigger":h.mode= +e.ON_TRIGGER;break;case "Never":h.mode=e.NEVER;break;default:h.mode=e.ALWAYS}},parentMenu:c,node:h});return!1};f.onMenuNodeColors=function(a,b,d,c,h){if(!h)throw"no node for color";b=[];b.push({value:null,content:"No color"});for(var k in f.node_colors)a=f.node_colors[k],a={value:k,content:""+k+""},b.push(a); +new e.ContextMenu(b,{event:d,callback:function(a){h&&((a=a.value?f.node_colors[a.value]:null)?h.constructor===e.LGraphGroup?h.color=a.groupcolor:(h.color=a.color,h.bgcolor=a.bgcolor):(delete h.color,delete h.bgcolor),h.setDirtyCanvas(!0,!0))},parentMenu:c,node:h});return!1};f.onMenuNodeShapes=function(a,b,d,c,h){if(!h)throw"no node passed";new e.ContextMenu(e.VALID_SHAPES,{event:d,callback:function(a){h&&(h.shape=a,h.setDirtyCanvas(!0))},parentMenu:c,node:h});return!1};f.onMenuNodeRemove=function(a, +b,d,c,e){if(!e)throw"no node passed";!1!==e.removable&&(e.graph.remove(e),e.setDirtyCanvas(!0,!0))};f.onMenuNodeClone=function(a,b,d,e,c){!1!=c.clonable&&(a=c.clone())&&(a.pos=[c.pos[0]+5,c.pos[1]+5],c.graph.add(a),c.setDirtyCanvas(!0,!0))};f.node_colors={red:{color:"#322",bgcolor:"#533",groupcolor:"#A88"},brown:{color:"#332922",bgcolor:"#593930",groupcolor:"#b06634"},green:{color:"#232",bgcolor:"#353",groupcolor:"#8A8"},blue:{color:"#223",bgcolor:"#335",groupcolor:"#88A"},pale_blue:{color:"#2a363b", +bgcolor:"#3f5159",groupcolor:"#3f789e"},cyan:{color:"#233",bgcolor:"#355",groupcolor:"#8AA"},purple:{color:"#323",bgcolor:"#535",groupcolor:"#a1309b"},yellow:{color:"#432",bgcolor:"#653",groupcolor:"#b58b2a"},black:{color:"#222",bgcolor:"#000",groupcolor:"#444"}};f.prototype.getCanvasMenuOptions=function(){var a=null;this.getMenuOptions?a=this.getMenuOptions():(a=[{content:"Add Node",has_submenu:!0,callback:f.onMenuAdd},{content:"Add Group",callback:f.onGroupAdd}],this._graph_stack&&0Name",c),f=k.querySelector("input");f&&h&&(f.value=h.label||"");k.querySelector("button").addEventListener("click",function(a){f.value&&(h&&(h.label=f.value),d.setDirty(!0));k.close()})}},extra:a};a&&(k.title=a.type);var n=null;a&&(n=a.getSlotInPosition(b.canvasX,b.canvasY),f.active_node=a);if(n){h=[];n&&n.output&&n.output.links&& +n.output.links.length&&h.push({content:"Disconnect Links",slot:n});var m=n.input||n.output;h.push(m.locked?"Cannot remove":{content:"Remove Slot",slot:n});h.push(m.nameLocked?"Cannot rename":{content:"Rename Slot",slot:n});k.title=(n.input?n.input.type:n.output.type)||"*";n.input&&n.input.type==e.ACTION&&(k.title="Action");n.output&&n.output.type==e.EVENT&&(k.title="Event")}else a?h=this.getNodeMenuOptions(a):(h=this.getCanvasMenuOptions(),(n=this.graph.getGroupOnPos(b.canvasX,b.canvasY))&&h.push(null, +{content:"Edit Group",has_submenu:!0,submenu:{title:"Group",extra:n,options:this.getGroupMenuOptions(n)}}));h&&new e.ContextMenu(h,k,c)};this.CanvasRenderingContext2D&&(CanvasRenderingContext2D.prototype.roundRect=function(a,b,d,c,e,h){void 0===e&&(e=5);void 0===h&&(h=e);this.moveTo(a+e,b);this.lineTo(a+d-e,b);this.quadraticCurveTo(a+d,b,a+d,b+e);this.lineTo(a+d,b+c-h);this.quadraticCurveTo(a+d,b+c,a+d-h,b+c);this.lineTo(a+h,b+c);this.quadraticCurveTo(a,b+c,a,b+c-h);this.lineTo(a,b+e);this.quadraticCurveTo(a, +b,a+e,b)});e.compareObjects=function(a,b){for(var d in a)if(a[d]!=b[d])return!1;return!0};e.distance=y;e.colorToString=function(a){return"rgba("+Math.round(255*a[0]).toFixed()+","+Math.round(255*a[1]).toFixed()+","+Math.round(255*a[2]).toFixed()+","+(4==a.length?a[3].toFixed(2):"1.0")+")"};e.isInsideRectangle=s;e.growBounding=function(a,b,d){ba[2]&&(a[2]=b);da[3]&&(a[3]=d)};e.isInsideBounding=function(a,b){return a[0]b[1][0]||a[1]>b[1][1]? +!1:!0};e.overlapBounding=u;e.hex2num=function(a){"#"==a.charAt(0)&&(a=a.slice(1));a=a.toUpperCase();for(var b=Array(3),d=0,c,e,h=0;6>h;h+=2)c="0123456789ABCDEF".indexOf(a.charAt(h)),e="0123456789ABCDEF".indexOf(a.charAt(h+1)),b[d]=16*c+e,d++;return b};e.num2hex=function(a){for(var b="#",d,c,e=0;3>e;e++)d=a[e]/16,c=a[e]%16,b+="0123456789ABCDEF".charAt(d)+"0123456789ABCDEF".charAt(c);return b};z.prototype.addItem=function(a,b,d){function c(a){var b=this.value;b&&b.has_submenu&&e.call(this,a)}function e(a){var b= +this.value,c=!0;h.current_submenu&&h.current_submenu.close(a);if(d.callback){var k=d.callback.call(this,b,d,a,h,d.node);!0===k&&(c=!1)}if(b&&(b.callback&&!d.ignore_item_callbacks&&!0!==b.disabled&&(k=b.callback.call(this,b,d,a,h,d.extra),!0===k&&(c=!1)),b.submenu)){if(!b.submenu.options)throw"ContextMenu submenu needs options";new h.constructor(b.submenu.options,{callback:b.submenu.callback,event:a,parentMenu:h,ignore_item_callbacks:b.submenu.ignore_item_callbacks,title:b.submenu.title,extra:b.submenu.extra, +autoopen:d.autoopen});c=!1}c&&!h.lock&&h.close()}var h=this;d=d||{};var k=document.createElement("div");k.className="litemenu-entry submenu";var f=!1;if(null===b)k.classList.add("separator");else{k.innerHTML=b&&b.title?b.title:a;if(k.value=b)b.disabled&&(f=!0,k.classList.add("disabled")),(b.submenu||b.has_submenu)&&k.classList.add("has_submenu");"function"==typeof b?(k.dataset.value=a,k.onclick_callback=b):k.dataset.value=b;b.className&&(k.className+=" "+b.className)}this.root.appendChild(k);f||k.addEventListener("click", +e);d.autoopen&&k.addEventListener("mouseenter",c);return k};z.prototype.close=function(a,b){this.root.parentNode&&this.root.parentNode.removeChild(this.root);this.parentMenu&&!b&&(this.parentMenu.lock=!1,this.parentMenu.current_submenu=null,void 0===a?this.parentMenu.close():a&&!z.isCursorOverElement(a,this.parentMenu.root)&&z.trigger(this.parentMenu.root,"mouseleave",a));this.current_submenu&&this.current_submenu.close(a,!0);this.root.closing_timer&&clearTimeout(this.root.closing_timer)};z.trigger= +function(a,b,d,c){var e=document.createEvent("CustomEvent");e.initCustomEvent(b,!0,!0,d);e.srcElement=c;a.dispatchEvent?a.dispatchEvent(e):a.__events&&a.__events.dispatchEvent(e);return e};z.prototype.getTopMenu=function(){return this.options.parentMenu?this.options.parentMenu.getTopMenu():this};z.prototype.getFirstEvent=function(){return this.options.parentMenu?this.options.parentMenu.getFirstEvent():this.options.event};z.isCursorOverElement=function(a,b){var d=a.clientX,c=a.clientY,e=b.getBoundingClientRect(); +return e?c>e.top&&ce.left&&da?b:d