From 29fc1a3929ce1fdef1fdecfdca3bb87c0a95ef89 Mon Sep 17 00:00:00 2001 From: tamat Date: Tue, 28 Feb 2023 14:05:51 +0100 Subject: [PATCH] fix in widget --- build/litegraph.core.js | 117 ++--- build/litegraph.core.min.js | 414 ++++++++--------- build/litegraph.js | 50 +- build/litegraph.min.js | 899 ++++++++++++++++++------------------ build/litegraph_mini.js | 50 +- build/litegraph_mini.min.js | 727 ++++++++++++++--------------- src/litegraph.js | 6 +- 7 files changed, 1172 insertions(+), 1091 deletions(-) diff --git a/build/litegraph.core.js b/build/litegraph.core.js index ef9929095..736c69984 100644 --- a/build/litegraph.core.js +++ b/build/litegraph.core.js @@ -89,6 +89,7 @@ NO_TITLE: 1, TRANSPARENT_TITLE: 2, AUTOHIDE_TITLE: 3, + VERTICAL_LAYOUT: "vertical", // arrange nodes vertically proxy: null, //used to redirect calls node_images_path: "", @@ -1260,7 +1261,7 @@ * Positions every node in a more readable manner * @method arrange */ - LGraph.prototype.arrange = function(margin) { + LGraph.prototype.arrange = function (margin, layout) { margin = margin || 100; var nodes = this.computeExecutionOrder(false, true); @@ -1285,12 +1286,14 @@ var y = margin + LiteGraph.NODE_TITLE_HEIGHT; for (var j = 0; j < column.length; ++j) { var node = column[j]; - node.pos[0] = x; - node.pos[1] = y; - if (node.size[0] > max_size) { - max_size = node.size[0]; + node.pos[0] = (layout == LiteGraph.VERTICAL_LAYOUT) ? y : x; + node.pos[1] = (layout == LiteGraph.VERTICAL_LAYOUT) ? x : y; + var max_size_index = (layout == LiteGraph.VERTICAL_LAYOUT) ? 1 : 0; + if (node.size[max_size_index] > max_size) { + max_size = node.size[max_size_index]; } - y += node.size[1] + margin + LiteGraph.NODE_TITLE_HEIGHT; + var node_size_index = (layout == LiteGraph.VERTICAL_LAYOUT) ? 0 : 1; + y += node.size[node_size_index] + margin + LiteGraph.NODE_TITLE_HEIGHT; } x += max_size + margin; } @@ -2468,43 +2471,34 @@ this.title = this.constructor.title; } - if (this.onConnectionsChange) { - if (this.inputs) { - for (var i = 0; i < this.inputs.length; ++i) { - var input = this.inputs[i]; - var link_info = this.graph - ? this.graph.links[input.link] - : null; - this.onConnectionsChange( - LiteGraph.INPUT, - i, - true, - link_info, - input - ); //link_info has been created now, so its updated - } - } + if (this.inputs) { + for (var i = 0; i < this.inputs.length; ++i) { + var input = this.inputs[i]; + var link_info = this.graph ? this.graph.links[input.link] : null; + if (this.onConnectionsChange) + this.onConnectionsChange( LiteGraph.INPUT, i, true, link_info, input ); //link_info has been created now, so its updated - if (this.outputs) { - for (var i = 0; i < this.outputs.length; ++i) { - var output = this.outputs[i]; - if (!output.links) { - continue; - } - for (var j = 0; j < output.links.length; ++j) { - var link_info = this.graph - ? this.graph.links[output.links[j]] - : null; - this.onConnectionsChange( - LiteGraph.OUTPUT, - i, - true, - link_info, - output - ); //link_info has been created now, so its updated - } - } - } + if( this.onInputAdded ) + this.onInputAdded(input); + + } + } + + if (this.outputs) { + for (var i = 0; i < this.outputs.length; ++i) { + var output = this.outputs[i]; + if (!output.links) { + continue; + } + for (var j = 0; j < output.links.length; ++j) { + var link_info = this.graph ? this.graph.links[output.links[j]] : null; + if (this.onConnectionsChange) + this.onConnectionsChange( LiteGraph.OUTPUT, i, true, link_info, output ); //link_info has been created now, so its updated + } + + if( this.onOutputAdded ) + this.onOutputAdded(output); + } } if( this.widgets ) @@ -3200,6 +3194,15 @@ return; } + if(slot == null) + { + console.error("slot must be a number"); + return; + } + + if(slot.constructor !== Number) + console.warn("slot must be a number, use node.trigger('name') if you want to use a string"); + var output = this.outputs[slot]; if (!output) { return; @@ -3346,26 +3349,26 @@ * @param {Object} extra_info this can be used to have special properties of an output (label, special color, position, etc) */ LGraphNode.prototype.addOutput = function(name, type, extra_info) { - var o = { name: name, type: type, links: null }; + var output = { name: name, type: type, links: null }; if (extra_info) { for (var i in extra_info) { - o[i] = extra_info[i]; + output[i] = extra_info[i]; } } if (!this.outputs) { this.outputs = []; } - this.outputs.push(o); + this.outputs.push(output); if (this.onOutputAdded) { - this.onOutputAdded(o); + this.onOutputAdded(output); } if (LiteGraph.auto_load_slot_types) LiteGraph.registerNodeAndSlotType(this,type,true); this.setSize( this.computeSize() ); this.setDirtyCanvas(true, true); - return o; + return output; }; /** @@ -3437,10 +3440,10 @@ */ LGraphNode.prototype.addInput = function(name, type, extra_info) { type = type || 0; - var o = { name: name, type: type, link: null }; + var input = { name: name, type: type, link: null }; if (extra_info) { for (var i in extra_info) { - o[i] = extra_info[i]; + input[i] = extra_info[i]; } } @@ -3448,17 +3451,17 @@ this.inputs = []; } - this.inputs.push(o); + this.inputs.push(input); this.setSize( this.computeSize() ); if (this.onInputAdded) { - this.onInputAdded(o); + this.onInputAdded(input); } LiteGraph.registerNodeAndSlotType(this,type); this.setDirtyCanvas(true, true); - return o; + return input; }; /** @@ -7489,8 +7492,8 @@ LGraphNode.prototype.executeAction = function(action) clientY_rel = e.clientY; } - e.deltaX = clientX_rel - this.last_mouse_position[0]; - e.deltaY = clientY_rel- this.last_mouse_position[1]; + // e.deltaX = clientX_rel - this.last_mouse_position[0]; + // e.deltaY = clientY_rel- this.last_mouse_position[1]; this.last_mouse_position[0] = clientX_rel; this.last_mouse_position[1] = clientY_rel; @@ -9927,7 +9930,8 @@ LGraphNode.prototype.executeAction = function(action) case "combo": var old_value = w.value; if (event.type == LiteGraph.pointerevents_method+"move" && w.type == "number") { - w.value += event.deltaX * 0.1 * (w.options.step || 1); + if(event.deltaX) + w.value += event.deltaX * 0.1 * (w.options.step || 1); if ( w.options.min != null && w.value < w.options.min ) { w.value = w.options.min; } @@ -11993,7 +11997,8 @@ LGraphNode.prototype.executeAction = function(action) if (root.onClose && typeof root.onClose == "function"){ root.onClose(); } - root.parentNode.removeChild(root); + if(root.parentNode) + root.parentNode.removeChild(root); /* XXX CHECK THIS */ if(this.parentNode){ this.parentNode.removeChild(this); diff --git a/build/litegraph.core.min.js b/build/litegraph.core.min.js index cd28aeab9..1df0d4e8e 100644 --- a/build/litegraph.core.min.js +++ b/build/litegraph.core.min.js @@ -1,15 +1,15 @@ -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(p,v,w){p!=Array.prototype&&p!=Object.prototype&&(p[v]=w.value)};$jscomp.getGlobal=function(p){return"undefined"!=typeof window&&window===p?p:"undefined"!=typeof global&&null!=global?global:p};$jscomp.global=$jscomp.getGlobal(this); -$jscomp.polyfill=function(p,v,w,l){if(v){w=$jscomp.global;p=p.split(".");for(l=0;lp&&(p=Math.max(0,w+p));if(null==l||l>w)l=w;l=Number(l);0>l&&(l=Math.max(0,w+l));for(p=Number(p||0);p=y}},"es6","es3"); -$jscomp.findInternal=function(p,v,w){p instanceof String&&(p=String(p));for(var l=p.length,z=0;zr&&(r=Math.max(0,w+r));if(null==l||l>w)l=w;l=Number(l);0>l&&(l=Math.max(0,w+l));for(r=Number(r||0);r=y}},"es6","es3"); +$jscomp.findInternal=function(r,v,w){r instanceof String&&(r=String(r));for(var l=r.length,z=0;z -h.width-k.width-10&&(e=h.width-k.width-10),h.height&&a>h.height-k.height-10&&(a=h.height-k.height-10));f.style.left=e+"px";f.style.top=a+"px";b.scale&&(f.style.transform="scale("+b.scale+")")}function E(a){this.points=a;this.nearest=this.selected=-1;this.size=null;this.must_update=!0;this.margin=5}var g=p.LiteGraph={VERSION:.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, +h.width-k.width-10&&(e=h.width-k.width-10),h.height&&a>h.height-k.height-10&&(a=h.height-k.height-10));f.style.left=e+"px";f.style.top=a+"px";b.scale&&(f.style.transform="scale("+b.scale+")")}function E(a){this.points=a;this.nearest=this.selected=-1;this.size=null;this.must_update=!0;this.margin=5}var g=r.LiteGraph={VERSION:.4,CANVAS_GRID_SIZE:10,NODE_TITLE_HEIGHT:30,NODE_TITLE_TEXT_Y:20,NODE_SLOT_HEIGHT:20,NODE_WIDGET_HEIGHT:20,NODE_WIDTH:140,NODE_MIN_WIDTH:50,NODE_COLLAPSED_RADIUS:10,NODE_COLLAPSED_WIDTH:80, NODE_TITLE_COLOR:"#999",NODE_SELECTED_TITLE_COLOR:"#FFF",NODE_TEXT_SIZE:14,NODE_TEXT_COLOR:"#AAA",NODE_SUBTEXT_SIZE:12,NODE_DEFAULT_COLOR:"#333",NODE_DEFAULT_BGCOLOR:"#353535",NODE_DEFAULT_BOXCOLOR:"#666",NODE_DEFAULT_SHAPE:"box",NODE_BOX_OUTLINE_COLOR:"#FFF",DEFAULT_SHADOW_COLOR:"rgba(0,0,0,0.5)",DEFAULT_GROUP_FONT:24,WIDGET_BGCOLOR:"#222",WIDGET_OUTLINE_COLOR:"#666",WIDGET_TEXT_COLOR:"#DDD",WIDGET_SECONDARY_TEXT_COLOR:"#999",LINK_COLOR:"#9A9",EVENT_LINK_COLOR:"#A86",CONNECTING_LINK_COLOR:"#AFA", MAX_NUMBER_OF_NODES:1E3,DEFAULT_POSITION:[100,100],VALID_SHAPES:["default","box","round","card"],BOX_SHAPE:1,ROUND_SHAPE:2,CIRCLE_SHAPE:3,CARD_SHAPE:4,ARROW_SHAPE:5,GRID_SHAPE:6,INPUT:1,OUTPUT:2,EVENT:-1,ACTION:-1,NODE_MODES:["Always","On Event","Never","On Trigger"],NODE_MODES_COLORS:["#666","#422","#333","#224","#626"],ALWAYS:0,ON_EVENT:1,NEVER:2,ON_TRIGGER:3,UP:1,DOWN:2,LEFT:3,RIGHT:4,CENTER:5,LINK_RENDER_MODES:["Straight","Linear","Spline"],STRAIGHT_LINK:0,LINEAR_LINK:1,SPLINE_LINK:2,NORMAL_TITLE:0, -NO_TITLE:1,TRANSPARENT_TITLE:2,AUTOHIDE_TITLE:3,proxy:null,node_images_path:"",debug:!1,catch_exceptions:!0,throw_errors:!0,allow_scripts:!1,registered_node_types:{},node_types_by_file_extension:{},Nodes:{},Globals:{},searchbox_extras:{},auto_sort_node_types:!1,node_box_coloured_when_on:!1,node_box_coloured_by_mode:!1,dialog_close_on_mouse_leave:!0,dialog_close_on_mouse_leave_delay:500,shift_click_do_break_link_from:!1,click_do_break_link_to:!1,search_hide_on_mouse_leave:!0,search_filter_enabled:!1, -search_show_all_on_open:!0,auto_load_slot_types:!1,registered_slot_in_types:{},registered_slot_out_types:{},slot_types_in:[],slot_types_out:[],slot_types_default_in:[],slot_types_default_out:[],alt_drag_do_clone_nodes:!1,do_add_triggers_slots:!1,allow_multi_output_for_events:!0,middle_click_slot_add_default_node:!1,release_link_on_empty_shows_menu:!1,pointerevents_method:"mouse",registerNodeType:function(a,b){if(!b.prototype)throw"Cannot register a simple object, it must be a class with a prototype"; +NO_TITLE:1,TRANSPARENT_TITLE:2,AUTOHIDE_TITLE:3,VERTICAL_LAYOUT:"vertical",proxy:null,node_images_path:"",debug:!1,catch_exceptions:!0,throw_errors:!0,allow_scripts:!1,registered_node_types:{},node_types_by_file_extension:{},Nodes:{},Globals:{},searchbox_extras:{},auto_sort_node_types:!1,node_box_coloured_when_on:!1,node_box_coloured_by_mode:!1,dialog_close_on_mouse_leave:!0,dialog_close_on_mouse_leave_delay:500,shift_click_do_break_link_from:!1,click_do_break_link_to:!1,search_hide_on_mouse_leave:!0, +search_filter_enabled:!1,search_show_all_on_open:!0,auto_load_slot_types:!1,registered_slot_in_types:{},registered_slot_out_types:{},slot_types_in:[],slot_types_out:[],slot_types_default_in:[],slot_types_default_out:[],alt_drag_do_clone_nodes:!1,do_add_triggers_slots:!1,allow_multi_output_for_events:!0,middle_click_slot_add_default_node:!1,release_link_on_empty_shows_menu:!1,pointerevents_method:"mouse",registerNodeType:function(a,b){if(!b.prototype)throw"Cannot register a simple object, it must be a class with a prototype"; b.type=a;g.debug&&console.log("Node registered: "+a);a.split("/");var c=b.name,d=a.lastIndexOf("/");b.category=a.substr(0,d);b.title||(b.title=c);if(b.prototype)for(var e in l.prototype)b.prototype[e]||(b.prototype[e]=l.prototype[e]);if(d=this.registered_node_types[a])console.log("replacing node type: "+a);else if(Object.hasOwnProperty(b.prototype,"shape")||Object.defineProperty(b.prototype,"shape",{set:function(a){switch(a){case "default":delete this._shape;break;case "box":this._shape=g.BOX_SHAPE; break;case "round":this._shape=g.ROUND_SHAPE;break;case "circle":this._shape=g.CIRCLE_SHAPE;break;case "card":this._shape=g.CARD_SHAPE;break;default:this._shape=a}},get:function(a){return this._shape},enumerable:!0,configurable:!0}),b.prototype.onPropertyChange&&console.warn("LiteGraph node class "+a+" has onPropertyChange method, it must be called onPropertyChanged with d at the end"),b.supported_extensions)for(e in b.supported_extensions){var f=b.supported_extensions[e];f&&f.constructor===String&& (this.node_types_by_file_extension[f.toLowerCase()]=b)}this.registered_node_types[a]=b;b.constructor.name&&(this.Nodes[c]=b);if(g.onNodeTypeRegistered)g.onNodeTypeRegistered(a,b);if(d&&g.onNodeTypeReplaced)g.onNodeTypeReplaced(a,b,d);b.prototype.onPropertyChange&&console.warn("LiteGraph node class "+a+" has onPropertyChange method, it must be called onPropertyChanged with d at the end");if(b.supported_extensions)for(e=0;eh&&(h=e.size[0]),k+=e.size[1]+a+g.NODE_TITLE_HEIGHT;b+=h+a}this.setDirtyCanvas(!0,!0)};v.prototype.getTime=function(){return this.globaltime};v.prototype.getFixedTime=function(){return this.fixedtime};v.prototype.getElapsedTime=function(){return this.elapsed_time}; -v.prototype.sendEventToAllNodes=function(a,b,c){c=c||g.ALWAYS;var d=this._nodes_in_order?this._nodes_in_order:this._nodes;if(d)for(var e=0,f=d.length;e=g.MAX_NUMBER_OF_NODES)throw"LiteGraph: max number of nodes in a graph reached";null==a.id||-1==a.id?a.id=++this.last_node_id:this.last_node_idk&&(k=f.size[t]);q+=f.size[b==g.VERTICAL_LAYOUT?0:1]+a+g.NODE_TITLE_HEIGHT}c+=k+a}this.setDirtyCanvas(!0,!0)};v.prototype.getTime=function(){return this.globaltime}; +v.prototype.getFixedTime=function(){return this.fixedtime};v.prototype.getElapsedTime=function(){return this.elapsed_time};v.prototype.sendEventToAllNodes=function(a,b,c){c=c||g.ALWAYS;var d=this._nodes_in_order?this._nodes_in_order:this._nodes;if(d)for(var e=0,f=d.length;e=g.MAX_NUMBER_OF_NODES)throw"LiteGraph: max number of nodes in a graph reached"; +null==a.id||-1==a.id?a.id=++this.last_node_id:this.last_node_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={}};l.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.onConnectionsChange){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}};l.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};l.prototype.getInputDataByName=function(a,b){a=this.findInputSlot(a);return-1==a?null:this.getInputData(a, -b)};l.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};l.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};l.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};l.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 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 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||!g.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 g.EVENT:g.allow_multi_output_for_events||(this.graph.beforeChange(),this.disconnectOutput(a,!1,{doProcessChange:!1}))}var f=new w(++this.graph.last_link_id,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(g.OUTPUT,a,!0,f,e);if(b.onConnectionsChange)b.onConnectionsChange(g.INPUT,c,!0,f,d);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};l.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 d=0,e=c.links.length;d=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 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 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&&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]-g.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)*g.NODE_SLOT_HEIGHT+(this.constructor.slot_start_y||0);return c};l.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)};l.prototype.trace=function(a){this.console||(this.console= -[]);this.console.push(a);this.console.length>l.MAX_CONSOLE&&this.console.shift();if(this.graph.onNodeTrace)this.graph.onNodeTrace(this,a)};l.prototype.setDirtyCanvas=function(a,b){this.graph&&this.graph.sendActionToCanvas("setDirty",[a,b])};l.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};l.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})};z.prototype.configure=function(a){this.title=a.title;this._bounding.set(a.bounding);this.color=a.color;this.font=a.font};z.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}};z.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)}};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};p.LGraphCanvas=g.LGraphCanvas=m;m.DEFAULT_BACKGROUND_IMAGE="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQBJREFUeNrs1rEKwjAUhlETUkj3vP9rdmr1Ysammk2w5wdxuLgcMHyptfawuZX4pJSWZTnfnu/lnIe/jNNxHHGNn//HNbbv+4dr6V+11uF527arU7+u63qfa/bnmh8sWLBgwYJlqRf8MEptXPBXJXa37BSl3ixYsGDBMliwFLyCV/DeLIMFCxYsWLBMwSt4Be/NggXLYMGCBUvBK3iNruC9WbBgwYJlsGApeAWv4L1ZBgsWLFiwYJmCV/AK3psFC5bBggULloJX8BpdwXuzYMGCBctgwVLwCl7Be7MMFixYsGDBsu8FH1FaSmExVfAxBa/gvVmwYMGCZbBg/W4vAQYA5tRF9QYlv/QAAAAASUVORK5CYII="; +r.LGraphNode=g.LGraphNode=l;l.prototype._ctor=function(a){this.title=a||"Unnamed";this.size=[g.NODE_WIDTH,60];this.graph=null;this._pos=new Float32Array(10,10);Object.defineProperty(this,"pos",{set:function(a){!a||2>a.length||(this._pos[0]=a[0],this._pos[1]=a[1])},get:function(){return this._pos},enumerable:!0});this.id=-1;this.type=null;this.inputs=[];this.outputs=[];this.connections=[];this.properties={};this.properties_info=[];this.flags={}};l.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}};l.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};l.prototype.getInputDataByName=function(a,b){a=this.findInputSlot(a);return-1==a?null:this.getInputData(a,b)};l.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};l.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};l.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};l.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 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 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||!g.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 g.EVENT:g.allow_multi_output_for_events||(this.graph.beforeChange(), +this.disconnectOutput(a,!1,{doProcessChange:!1}))}var f=new w(++this.graph.last_link_id,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(g.OUTPUT,a,!0,f,e);if(b.onConnectionsChange)b.onConnectionsChange(g.INPUT,c,!0,f,d);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};l.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 d=0,e=c.links.length;d=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 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 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&&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]-g.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)*g.NODE_SLOT_HEIGHT+(this.constructor.slot_start_y||0);return c};l.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)};l.prototype.trace=function(a){this.console||(this.console=[]);this.console.push(a);this.console.length>l.MAX_CONSOLE&&this.console.shift();if(this.graph.onNodeTrace)this.graph.onNodeTrace(this,a)};l.prototype.setDirtyCanvas=function(a,b){this.graph&&this.graph.sendActionToCanvas("setDirty",[a,b])};l.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};l.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})};z.prototype.configure=function(a){this.title=a.title;this._bounding.set(a.bounding);this.color=a.color;this.font=a.font};z.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}};z.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)}};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};r.LGraphCanvas=g.LGraphCanvas=m;m.DEFAULT_BACKGROUND_IMAGE="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQBJREFUeNrs1rEKwjAUhlETUkj3vP9rdmr1Ysammk2w5wdxuLgcMHyptfawuZX4pJSWZTnfnu/lnIe/jNNxHHGNn//HNbbv+4dr6V+11uF527arU7+u63qfa/bnmh8sWLBgwYJlqRf8MEptXPBXJXa37BSl3ixYsGDBMliwFLyCV/DeLIMFCxYsWLBMwSt4Be/NggXLYMGCBUvBK3iNruC9WbBgwYJlsGApeAWv4L1ZBgsWLFiwYJmCV/AK3psFC5bBggULloJX8BpdwXuzYMGCBctgwVLwCl7Be7MMFixYsGDBsu8FH1FaSmExVfAxBa/gvVmwYMGCZbBg/W4vAQYA5tRF9QYlv/QAAAAASUVORK5CYII="; m.link_type_colors={"-1":g.EVENT_LINK_COLOR,number:"#AAA",node:"#DCA"};m.gradients={};m.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()};m.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)))};m.prototype.getTopGraph=function(){return this._graph_stack.length?this._graph_stack[0]:this.graph};m.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)};m.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= @@ -142,13 +142,13 @@ m.getFileExtension=function(a){var b=a.indexOf("?");-1!=b&&(a=a.substr(0,b));b=a return a.defaultView||a.parentWindow};m.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))};m.prototype.stopRendering=function(){this.is_rendering=!1};m.prototype.blockClick=function(){this.block_click=!0;this.last_mouseclick=0};m.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();m.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&&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&&f&&this.allow_interaction&&!d&&!this.read_only&&!this.connecting_node&&!f.flags.collapsed&&!this.live_mode){e=d=h=!1;if(f.outputs)for(t=0,k=f.outputs.length;tf.size[0]-g.NODE_TITLE_HEIGHT&&0>k[1]&&(c=this,setTimeout(function(){c.openSubgraph(f.subgraph)},10)),this.live_mode&&(t=h=!0));t||(this.allow_dragnodes&&(this.graph.beforeChange(),this.node_dragged=f),this.selected_nodes[f.id]||this.processNodeSelected(f,a));this.dirty_canvas=!0}}else if(!d){if(!this.read_only)for(t=0;tk[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>H([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());h=!0}!d&&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(); @@ -183,122 +183,122 @@ if(b.inputs)for(var d=0;dc-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}};m.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);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=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;B.set(a.size);var k=a.horizontal;if(a.flags.collapsed){b.font=this.inner_text_font;var n=a.getTitle?a.getTitle():a.title;null!=n&&(a._collapsed_width=Math.min(a.size[0],b.measureText(n).width+2*g.NODE_TITLE_HEIGHT),B[0]=a._collapsed_width,B[1]=0)}a.clip_area&&(b.save(),b.beginPath(),h==g.BOX_SHAPE?b.rect(0,0,B[0],B[1]):h==g.ROUND_SHAPE? -b.roundRect(0,0,B[0],B[1],[10]):h==g.CIRCLE_SHAPE&&b.arc(.5*B[0],.5*B[1],.5*B[0],0,2*Math.PI),b.clip());a.has_errors&&(d="red");this.drawNodeShape(a,b,B,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 q=this.connecting_output;h=this.connecting_input;b.lineWidth=1;n=0;var t=new Float32Array(2);if(!a.flags.collapsed){if(a.inputs)for(c=0;cthis.ds.scale,n=a._shape||a.constructor.shape||g.ROUND_SHAPE,q=a.constructor.title_mode,t=!0;q==g.TRANSPARENT_TITLE||q==g.NO_TITLE?t=!1:q==g.AUTOHIDE_TITLE&&h&&(t=!0);x[0]=0;x[1]=t?-e:0;x[2]=c[0]+1;x[3]=t?c[1]+e:c[1];h=b.globalAlpha;b.beginPath();n==g.BOX_SHAPE||k?b.fillRect(x[0],x[1],x[2],x[3]):n==g.ROUND_SHAPE||n==g.CARD_SHAPE?b.roundRect(x[0],x[1],x[2],x[3],n==g.CARD_SHAPE?[this.round_radius,this.round_radius, -0,0]:[this.round_radius]):n==g.CIRCLE_SHAPE&&b.arc(.5*c[0],.5*c[1],.5*c[0],0,2*Math.PI);b.fill();!a.flags.collapsed&&t&&(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(t||q==g.TRANSPARENT_TITLE){if(a.onDrawTitleBar)a.onDrawTitleBar(b,e,c,this.ds.scale,d);else if(q!=g.TRANSPARENT_TITLE&&(a.constructor.title_color||this.render_title_colored)){t=a.constructor.title_color|| -d;a.flags.collapsed&&(b.shadowColor=g.DEFAULT_SHADOW_COLOR);if(this.use_gradients){var r=m.gradients[t];r||(r=m.gradients[t]=b.createLinearGradient(0,0,400,0),r.addColorStop(0,t),r.addColorStop(1,"#000"));b.fillStyle=r}else b.fillStyle=t;b.beginPath();n==g.BOX_SHAPE||k?b.rect(0,-e,c[0]+1,e):(n==g.ROUND_SHAPE||n==g.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"}t=!1;g.node_box_coloured_by_mode&& -g.NODE_MODES_COLORS[a.mode]&&(t=g.NODE_MODES_COLORS[a.mode]);g.node_box_coloured_when_on&&(t=a.action_triggered?"#FFF":a.execute_triggered?"#AAA":t);if(a.onDrawTitleBox)a.onDrawTitleBox(b,e,c,this.ds.scale);else n==g.ROUND_SHAPE||n==g.CIRCLE_SHAPE||n==g.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||t||g.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||t||g.NODE_DEFAULT_BOXCOLOR,b.fillRect(.5*(e-10),-.5*(e+10),10,10));b.globalAlpha=h;if(a.onDrawTitleText)a.onDrawTitleText(b,e,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),e,g.NODE_TITLE_TEXT_Y-e), -b.textAlign="left"):(b.textAlign="left",b.fillText(h,e,g.NODE_TITLE_TEXT_Y-e)));a.flags.collapsed||!a.subgraph||a.skip_subgraph_button||(h=g.NODE_TITLE_HEIGHT,t=a.size[0]-h,r=g.isInsideRectangle(this.graph_mouse[0]-a.pos[0],this.graph_mouse[1]-a.pos[1],t+2,-h+2,h-4,h-4),b.fillStyle=r?"#888":"#555",n==g.BOX_SHAPE||k?b.fillRect(t+2,-h+2,h-4,h-4):(b.beginPath(),b.roundRect(t+2,-h+2,h-4,h-4,[4]),b.fill()),b.fillStyle="#333",b.beginPath(),b.moveTo(t+.2*h,.6*-h),b.lineTo(t+.8*h,.6*-h),b.lineTo(t+.5*h,.3* --h),b.fill());if(a.onDrawTitle)a.onDrawTitle(b)}if(f){if(a.onBounding)a.onBounding(x);q==g.TRANSPARENT_TITLE&&(x[1]-=e,x[3]+=e);b.lineWidth=1;b.globalAlpha=.8;b.beginPath();n==g.BOX_SHAPE?b.rect(-6+x[0],-6+x[1],12+x[2],12+x[3]):n==g.ROUND_SHAPE||n==g.CARD_SHAPE&&a.flags.collapsed?b.roundRect(-6+x[0],-6+x[1],12+x[2],12+x[3],[2*this.round_radius]):n==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]):n==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=d;b.globalAlpha=1}0C[2]&&(C[0]+=C[2],C[2]=Math.abs(C[2]));0>C[3]&&(C[1]+=C[3],C[3]=Math.abs(C[3]));if(F(C, -G)){var m=n.outputs[q];q=f.inputs[h];if(m&&q&&(n=m.dir||(n.horizontal?g.DOWN:g.RIGHT),q=q.dir||(f.horizontal?g.UP:g.LEFT),this.renderLink(a,t,r,k,!1,0,null,n,q),k&&k._last_time&&1E3>b-k._last_time)){m=2-.002*(b-k._last_time);var l=a.globalAlpha;a.globalAlpha=l*m;this.renderLink(a,t,r,k,!0,m,"white",n,q);a.globalAlpha=l}}}}}}a.globalAlpha=1};m.prototype.renderLink=function(a,b,c,d,e,f,h,k,n,q){d&&this.visible_links.push(d);!h&&d&&(h=d.color||m.link_type_colors[d.type]);h||(h=this.default_link_color); -null!=d&&this.highlighted_links[d.id]&&(h="#FFF");k=k||g.RIGHT;n=n||g.LEFT;var t=H(b,c);this.render_connections_border&&.6b[1]?0:Math.PI,a.save(),a.translate(r[0],r[1]),a.rotate(t),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(q),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=h,r=0;5>r;++r)f=(.001*g.getTime()+.2*r)%1,e=this.computeConnectionPoint(b,c,f,k,n),a.beginPath(),a.arc(e[0],e[1],5,0,2*Math.PI),a.fill()};m.prototype.computeConnectionPoint=function(a,b,c,d,e){d=d||g.RIGHT;e=e||g.LEFT;var f=H(a,b),h=[a[0],a[1]],k=[b[0],b[1]];switch(d){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(e){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}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*h[0]+f*k[0]+c*b[0],d*a[1]+e*h[1]+f*k[1]+c*b[1]]};m.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;cf||f>l-12||hr.last_y+m||void 0===r.last_y)){d=r.value;switch(r.type){case "button":c.type===g.pointerevents_method+"down"&&(r.callback&&setTimeout(function(){r.callback(r,n,a,b,c)},20),this.dirty_canvas=r.clicked=!0);break;case "slider":q=Math.clamp((f-15)/(l-30),0,1);r.value=r.options.min+(r.options.max-r.options.min)*q;r.callback&& -setTimeout(function(){e(r,r.value)},20);this.dirty_canvas=!0;break;case "number":case "combo":d=r.value;if(c.type==g.pointerevents_method+"move"&&"number"==r.type)r.value+=.1*c.deltaX*(r.options.step||1),null!=r.options.min&&r.valuer.options.max&&(r.value=r.options.max);else if(c.type==g.pointerevents_method+"down"){var u=r.options.values;u&&u.constructor===Function&&(u=r.options.values(r,a));var p=null;"number"!=r.type&&(p=u.constructor=== -Array?u:Object.keys(u));f=40>f?-1:f>l-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)q=-1,this.last_mouseclick=0,q=u.constructor===Object?p.indexOf(String(r.value))+f:p.indexOf(r.value)+f,q>=p.length&&(q=p.length-1),0>q&&(q=0),r.value=u.constructor===Array?u[q]:q;else{var v=u!=p?Object.values(u):u;new g.ContextMenu(v,{scale:Math.max(1,this.ds.scale), -event:c,className:"dark",callback:function(a,b,c){u!=p&&(a=v.indexOf(a));this.value=a;e(this,a);n.dirty_canvas=!0;return!1}.bind(r)},q)}}else c.type==g.pointerevents_method+"up"&&"number"==r.type&&(f=40>f?-1:f>l-40?1:0,200>c.click_time&&0==f&&this.prompt("Value",r.value,function(a){this.value=Number(a);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==g.pointerevents_method+"down"&&(r.value=!r.value,setTimeout(function(){e(r, -r.value)},20));break;case "string":case "text":c.type==g.pointerevents_method+"down"&&this.prompt("Value",r.value,function(a){this.value=a;e(this,a)}.bind(r),c,r.options?r.options.multiline:!1);break;default:r.mouse&&(this.dirty_canvas=r.mouse(c,[f,h],a))}if(d!=r.value){if(a.onWidgetChanged)a.onWidgetChanged(r.name,r.value,d,r);a.graph._version++}return r}}}return null};m.prototype.drawGroups=function(a,b){if(this.graph){a=this.graph._groups;b.save();b.globalAlpha=.5*this.editor_alpha;for(var c=0;c< -a.length;++c){var d=a[c];if(F(this.visible_area,d._bounding)){b.fillStyle=d.color||"#335";b.strokeStyle=d.color||"#335";var e=d._pos,f=d._size;b.globalAlpha=.25*this.editor_alpha;b.beginPath();b.rect(e[0]+.5,e[1]+.5,f[0],f[1]);b.fill();b.globalAlpha=this.editor_alpha;b.stroke();b.beginPath();b.moveTo(e[0]+f[0],e[1]+f[1]);b.lineTo(e[0]+f[0]-10,e[1]+f[1]);b.lineTo(e[0]+f[0],e[1]+f[1]-10);b.fill();f=d.font_size||g.DEFAULT_GROUP_FONT_SIZE;b.font=f+"px Arial";b.textAlign="left";b.fillText(d.title,e[0]+ -4,e[1]+f)}}b.restore()}};m.prototype.adjustNodesSize=function(){for(var a=this.graph._nodes,b=0;bc&&.01>b.editor_alpha&&(clearInterval(d),1>c&&(b.live_mode=!0));1"+(n.label?n.label:k)+""+a+"",value:k})}if(h.length)return new g.ContextMenu(h,{event:c,callback:function(a, -b,c,d){e&&(b=this.getBoundingClientRect(),f.showEditPropertyValue(e,a.value,{position:[b.left,b.top]}))},parentMenu:d,allow_html:!0,node:e},b),!1}};m.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};m.onMenuResizeNode=function(a,b,c,d,e){if(e){a=function(a){a.size=a.computeSize();if(a.onResize)a.onResize(a.size)};b=m.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)}};m.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 h=!1;e&&e.outputs&&e.outputs[a.target_slot]&&(h=e.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,t){switch(b){case "Add Node":m.onMenuAdd(null,null,t,k,function(b){b.inputs&& -b.inputs.length&&b.outputs&&b.outputs.length&&d.connectByType(a.origin_slot,b,f)&&(b.connectByType(a.target_slot,e,h),b.pos[0]-=.5*b.size[0])});break;case "Delete":c.graph.removeLink(a.id)}}});return!1};m.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==g.EVENT?"_event_":e.type;if((e=b?g.slot_types_default_out:g.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=g.createNode(nodeNewType)){if(f){if(f.properties)for(var h in f.properties)e.addProperty(h, -f.properties[h]);if(f.inputs)for(h in e.inputs=[],f.inputs)e.addOutput(f.inputs[h][0],f.inputs[h][1]);if(f.outputs)for(h in e.outputs=[],f.outputs)e.addOutput(f.outputs[h][0],f.outputs[h][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};m.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 h=e.type==g.EVENT?"_event_":e.type,k=d?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 n in k[h])a.push(k[h][n]);else a.push(k[h]);var q=new g.ContextMenu(a,{event:b.e,title:(e&&""!=e.name?e.name+(h?" | ":""):"")+ -(e&&h?h:""),callback:function(a,g,k){switch(a){case "Add Node":m.onMenuAdd(null,null,k,q,function(a){d?b.nodeFrom.connectByType(f,a,h):b.nodeTo.connectByTypeOutput(f,a,h)});break;case "Search":d?c.showSearchBox(k,{node_from:b.nodeFrom,slot_from:e,type_filter_in:h}):c.showSearchBox(k,{node_to:b.nodeTo,slot_from:e,type_filter_out:h});break;default:c.createDefaultNodeForSlot(Object.assign(b,{position:[b.e.canvasX,b.e.canvasY],nodeType:a}))}}});return!1};m.onShowPropertyEditor=function(a,b,c,d,e){function f(){if(n){var b= -n.value;"Number"==a.type?b=Number(b):"Boolean"==a.type&&(b=!!b);e[h]=b;k.parentNode&&k.parentNode.removeChild(k);e.setDirtyCanvas(!0,!0)}}var h=a.property||"title";b=e[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 n=k.querySelector(".value");n&&(n.value=b,n.addEventListener("blur", -function(a){this.focus()}),n.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=m.active_canvas.canvas;c=b.getBoundingClientRect();var q=d=-20;c&&(d-=c.left,q-=c.top);event?(k.style.left=event.clientX+d+"px",k.style.top=event.clientY+q+"px"):(k.style.left=.5*b.width+d+"px",k.style.top=.5*b.height+q+"px");k.querySelector("button").addEventListener("click", -f);b.parentNode.appendChild(k);n&&n.focus();var t=null;k.addEventListener("mouseleave",function(a){g.dialog_close_on_mouse_leave&&!k.is_modified&&g.dialog_close_on_mouse_leave&&(t=setTimeout(k.close,g.dialog_close_on_mouse_leave_delay))});k.addEventListener("mouseenter",function(a){g.dialog_close_on_mouse_leave&&t&&clearTimeout(t)})};m.prototype.prompt=function(a,b,c,d,e){var f=this;a=a||"";var h=document.createElement("div");h.is_modified=!1;h.className="graphdialog rounded";h.innerHTML=e?" ": -" ";h.close=function(){f.prompt_box=null;h.parentNode&&h.parentNode.removeChild(h)};e=m.active_canvas.canvas;e.parentNode.appendChild(h);1c-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}};m.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);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=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;B.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),B[0]=a._collapsed_width,B[1]=0)}a.clip_area&&(b.save(),b.beginPath(),h==g.BOX_SHAPE?b.rect(0,0,B[0],B[1]):h==g.ROUND_SHAPE?b.roundRect(0,0,B[0],B[1],[10]):h==g.CIRCLE_SHAPE&&b.arc(.5*B[0],.5*B[1],.5*B[0],0,2*Math.PI),b.clip());a.has_errors&& +(d="red");this.drawNodeShape(a,b,B,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 p=this.connecting_output;h=this.connecting_input;b.lineWidth=1;q=0;var t=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,p=a.constructor.title_mode,t=!0;p==g.TRANSPARENT_TITLE||p==g.NO_TITLE?t=!1:p==g.AUTOHIDE_TITLE&&h&&(t=!0);x[0]=0;x[1]=t?-e:0;x[2]=c[0]+1;x[3]=t?c[1]+e: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&&t&&(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(t||p==g.TRANSPARENT_TITLE){if(a.onDrawTitleBar)a.onDrawTitleBar(b,e,c,this.ds.scale,d);else if(p!=g.TRANSPARENT_TITLE&&(a.constructor.title_color||this.render_title_colored)){t=a.constructor.title_color||d;a.flags.collapsed&&(b.shadowColor=g.DEFAULT_SHADOW_COLOR);if(this.use_gradients){var n=m.gradients[t];n||(n=m.gradients[t]= +b.createLinearGradient(0,0,400,0),n.addColorStop(0,t),n.addColorStop(1,"#000"));b.fillStyle=n}else b.fillStyle=t;b.beginPath();q==g.BOX_SHAPE||k?b.rect(0,-e,c[0]+1,e):(q==g.ROUND_SHAPE||q==g.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"}t=!1;g.node_box_coloured_by_mode&&g.NODE_MODES_COLORS[a.mode]&&(t=g.NODE_MODES_COLORS[a.mode]);g.node_box_coloured_when_on&&(t=a.action_triggered?"#FFF": +a.execute_triggered?"#AAA":t);if(a.onDrawTitleBox)a.onDrawTitleBox(b,e,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*e,-.5*e,6,0,2*Math.PI),b.fill()),b.fillStyle=a.boxcolor||t||g.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||t||g.NODE_DEFAULT_BOXCOLOR,b.fillRect(.5* +(e-10),-.5*(e+10),10,10));b.globalAlpha=h;if(a.onDrawTitleText)a.onDrawTitleText(b,e,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),e,g.NODE_TITLE_TEXT_Y-e),b.textAlign="left"):(b.textAlign="left",b.fillText(h,e,g.NODE_TITLE_TEXT_Y-e)));a.flags.collapsed||!a.subgraph||a.skip_subgraph_button|| +(h=g.NODE_TITLE_HEIGHT,t=a.size[0]-h,n=g.isInsideRectangle(this.graph_mouse[0]-a.pos[0],this.graph_mouse[1]-a.pos[1],t+2,-h+2,h-4,h-4),b.fillStyle=n?"#888":"#555",q==g.BOX_SHAPE||k?b.fillRect(t+2,-h+2,h-4,h-4):(b.beginPath(),b.roundRect(t+2,-h+2,h-4,h-4,[4]),b.fill()),b.fillStyle="#333",b.beginPath(),b.moveTo(t+.2*h,.6*-h),b.lineTo(t+.8*h,.6*-h),b.lineTo(t+.5*h,.3*-h),b.fill());if(a.onDrawTitle)a.onDrawTitle(b)}if(f){if(a.onBounding)a.onBounding(x);p==g.TRANSPARENT_TITLE&&(x[1]-=e,x[3]+=e);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=d;b.globalAlpha=1}0C[2]&&(C[0]+=C[2],C[2]=Math.abs(C[2]));0>C[3]&&(C[1]+=C[3],C[3]=Math.abs(C[3]));if(F(C,G)){var m=q.outputs[p];p=f.inputs[h];if(m&&p&&(q=m.dir||(q.horizontal?g.DOWN:g.RIGHT),p=p.dir||(f.horizontal?g.UP:g.LEFT),this.renderLink(a, +t,n,k,!1,0,null,q,p),k&&k._last_time&&1E3>b-k._last_time)){m=2-.002*(b-k._last_time);var l=a.globalAlpha;a.globalAlpha=l*m;this.renderLink(a,t,n,k,!0,m,"white",q,p);a.globalAlpha=l}}}}}}a.globalAlpha=1};m.prototype.renderLink=function(a,b,c,d,e,f,h,k,q,p){d&&this.visible_links.push(d);!h&&d&&(h=d.color||m.link_type_colors[d.type]);h||(h=this.default_link_color);null!=d&&this.highlighted_links[d.id]&&(h="#FFF");k=k||g.RIGHT;q=q||g.LEFT;var t=H(b,c);this.render_connections_border&&.6b[1]?0:Math.PI,a.save(),a.translate(n[0],n[1]),a.rotate(t),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(p),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=h,n=0;5>n;++n)f=(.001*g.getTime()+.2*n)%1,e=this.computeConnectionPoint(b,c,f,k,q),a.beginPath(),a.arc(e[0],e[1],5,0,2*Math.PI),a.fill()};m.prototype.computeConnectionPoint=function(a,b,c,d,e){d=d||g.RIGHT;e=e||g.LEFT;var f=H(a,b),h=[a[0],a[1]],k=[b[0],b[1]];switch(d){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(e){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}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*h[0]+f*k[0]+c*b[0],d*a[1]+e*h[1]+f*k[1]+c*b[1]]};m.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;cf||f>l-12||hn.last_y+m||void 0===n.last_y)){d=n.value;switch(n.type){case "button":c.type===g.pointerevents_method+"down"&&(n.callback&&setTimeout(function(){n.callback(n,q,a,b,c)},20),this.dirty_canvas=n.clicked=!0);break;case "slider":p=Math.clamp((f-15)/(l-30),0,1);n.value=n.options.min+(n.options.max-n.options.min)*p;n.callback&&setTimeout(function(){e(n,n.value)},20);this.dirty_canvas=!0;break;case "number":case "combo":d=n.value;if(c.type== +g.pointerevents_method+"move"&&"number"==n.type)c.deltaX&&(n.value+=.1*c.deltaX*(n.options.step||1)),null!=n.options.min&&n.valuen.options.max&&(n.value=n.options.max);else if(c.type==g.pointerevents_method+"down"){var u=n.options.values;u&&u.constructor===Function&&(u=n.options.values(n,a));var r=null;"number"!=n.type&&(r=u.constructor===Array?u:Object.keys(u));f=40>f?-1:f>l-40?1:0;if("number"==n.type)n.value+=.1*f*(n.options.step|| +1),null!=n.options.min&&n.valuen.options.max&&(n.value=n.options.max);else if(f)p=-1,this.last_mouseclick=0,p=u.constructor===Object?r.indexOf(String(n.value))+f:r.indexOf(n.value)+f,p>=r.length&&(p=r.length-1),0>p&&(p=0),n.value=u.constructor===Array?u[p]:p;else{var v=u!=r?Object.values(u):u;new g.ContextMenu(v,{scale:Math.max(1,this.ds.scale),event:c,className:"dark",callback:function(a,b,c){u!=r&&(a=v.indexOf(a));this.value=a; +e(this,a);q.dirty_canvas=!0;return!1}.bind(n)},p)}}else c.type==g.pointerevents_method+"up"&&"number"==n.type&&(f=40>f?-1:f>l-40?1:0,200>c.click_time&&0==f&&this.prompt("Value",n.value,function(a){this.value=Number(a);e(this,this.value)}.bind(n),c));d!=n.value&&setTimeout(function(){e(this,this.value)}.bind(n),20);this.dirty_canvas=!0;break;case "toggle":c.type==g.pointerevents_method+"down"&&(n.value=!n.value,setTimeout(function(){e(n,n.value)},20));break;case "string":case "text":c.type==g.pointerevents_method+ +"down"&&this.prompt("Value",n.value,function(a){this.value=a;e(this,a)}.bind(n),c,n.options?n.options.multiline:!1);break;default:n.mouse&&(this.dirty_canvas=n.mouse(c,[f,h],a))}if(d!=n.value){if(a.onWidgetChanged)a.onWidgetChanged(n.name,n.value,d,n);a.graph._version++}return n}}}return null};m.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));1"+(q.label?q.label:k)+""+a+"",value:k})}if(h.length)return new g.ContextMenu(h,{event:c,callback:function(a,b,c,d){e&&(b=this.getBoundingClientRect(),f.showEditPropertyValue(e,a.value,{position:[b.left,b.top]}))},parentMenu:d,allow_html:!0, +node:e},b),!1}};m.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};m.onMenuResizeNode=function(a,b,c,d,e){if(e){a=function(a){a.size=a.computeSize();if(a.onResize)a.onResize(a.size)};b=m.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)}};m.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 h=!1;e&&e.outputs&&e.outputs[a.target_slot]&&(h=e.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,t){switch(b){case "Add Node":m.onMenuAdd(null,null,t,k,function(b){b.inputs&&b.inputs.length&&b.outputs&&b.outputs.length&&d.connectByType(a.origin_slot,b,f)&&(b.connectByType(a.target_slot,e,h),b.pos[0]-= +.5*b.size[0])});break;case "Delete":c.graph.removeLink(a.id)}}});return!1};m.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==g.EVENT?"_event_":e.type;if((e=b?g.slot_types_default_out: +g.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=g.createNode(nodeNewType)){if(f){if(f.properties)for(var h in f.properties)e.addProperty(h,f.properties[h]);if(f.inputs)for(h in e.inputs= +[],f.inputs)e.addOutput(f.inputs[h][0],f.inputs[h][1]);if(f.outputs)for(h in e.outputs=[],f.outputs)e.addOutput(f.outputs[h][0],f.outputs[h][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}; +m.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 h=e.type==g.EVENT?"_event_":e.type,k=d?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 p=new g.ContextMenu(a,{event:b.e,title:(e&&""!=e.name?e.name+(h?" | ":""):"")+(e&&h?h:""),callback:function(a, +g,k){switch(a){case "Add Node":m.onMenuAdd(null,null,k,p,function(a){d?b.nodeFrom.connectByType(f,a,h):b.nodeTo.connectByTypeOutput(f,a,h)});break;case "Search":d?c.showSearchBox(k,{node_from:b.nodeFrom,slot_from:e,type_filter_in:h}):c.showSearchBox(k,{node_to:b.nodeTo,slot_from:e,type_filter_out:h});break;default:c.createDefaultNodeForSlot(Object.assign(b,{position:[b.e.canvasX,b.e.canvasY],nodeType:a}))}}});return!1};m.onShowPropertyEditor=function(a,b,c,d,e){function f(){if(q){var b=q.value;"Number"== +a.type?b=Number(b):"Boolean"==a.type&&(b=!!b);e[h]=b;k.parentNode&&k.parentNode.removeChild(k);e.setDirtyCanvas(!0,!0)}}var h=a.property||"title";b=e[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=m.active_canvas.canvas;c=b.getBoundingClientRect();var p=d=-20;c&&(d-=c.left,p-=c.top);event?(k.style.left=event.clientX+d+"px",k.style.top=event.clientY+p+"px"):(k.style.left=.5*b.width+d+"px",k.style.top=.5*b.height+p+"px");k.querySelector("button").addEventListener("click", +f);b.parentNode.appendChild(k);q&&q.focus();var t=null;k.addEventListener("mouseleave",function(a){g.dialog_close_on_mouse_leave&&!k.is_modified&&g.dialog_close_on_mouse_leave&&(t=setTimeout(k.close,g.dialog_close_on_mouse_leave_delay))});k.addEventListener("mouseenter",function(a){g.dialog_close_on_mouse_leave&&t&&clearTimeout(t)})};m.prototype.prompt=function(a,b,c,d,e){var f=this;a=a||"";var h=document.createElement("div");h.is_modified=!1;h.className="graphdialog rounded";h.innerHTML=e?" ": +" ";h.close=function(){f.prompt_box=null;h.parentNode&&h.parentNode.removeChild(h)};e=m.active_canvas.canvas;e.parentNode.appendChild(h);1m.search_limit))break}}t=null;if(Array.prototype.filter)t=Object.keys(g.registered_node_types).filter(e);else for(k in t=[],g.registered_node_types)e(k)&&t.push(k);for(k=0;km.search_limit);k++);if(b.show_general_after_typefiltered&&(l.value||r.value)){filtered_extra=[];for(k in g.registered_node_types)e(k,{inTypeOverride:l&&l.value?"*": -!1,outTypeOverride:r&&r.value?"*":!1})&&filtered_extra.push(k);for(k=0;km.search_limit);k++);}if((l.value||r.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;km.search_limit);k++);}}}def_options={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=Object.assign(def_options,b||{});var f=this,h=m.active_canvas,k=h.canvas,n=k.ownerDocument||document,q=document.createElement("div");q.className="litegraph litesearchbox graphdialog rounded";q.innerHTML="Search "; -b.do_type_filter&&(q.innerHTML+="",q.innerHTML+="");q.innerHTML+="
";n.fullscreenElement?n.fullscreenElement.appendChild(q):(n.body.appendChild(q),n.body.style.overflow="hidden");if(b.do_type_filter)var t=q.querySelector(".slot_in_type_filter"),r=q.querySelector(".slot_out_type_filter");q.close=function(){f.search_box=null;this.blur(); -k.focus();n.body.style.overflow="";setTimeout(function(){f.canvas.focus()},20);q.parentNode&&q.parentNode.removeChild(q)};1t.height-200&&(u.style.maxHeight=t.height-a.layerY-20+"px");z.focus();b.show_all_on_open&&e();return q};m.prototype.showEditPropertyValue=function(a,b,c){function d(){e(m.value)}function e(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(); -l.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 l=this.createDialog(""+(f.label?f.label:b)+""+g+"",c),m=!1;if("enum"!=h&&"combo"!=h||!f.values)if("boolean"==h||"toggle"==h)(m=l.querySelector("input"))&&m.addEventListener("click",function(a){l.modified();e(!!m.checked)});else{if(m=l.querySelector("input"))m.addEventListener("blur",function(a){this.focus()}), -q=void 0!==a.properties[b]?a.properties[b]:"","string"!==h&&(q=JSON.stringify(q)),m.value=q,m.addEventListener("keydown",function(a){if(27==a.keyCode)l.close();else if(13==a.keyCode)d();else if(13!=a.keyCode){l.modified();return}a.preventDefault();a.stopPropagation()})}else m=l.querySelector("select"),m.addEventListener("change",function(a){l.modified();e(a.target.value)});m&&m.focus();l.querySelector("button").addEventListener("click",d);return l}};m.prototype.createDialog=function(a,b){def_options= +function(a,c){c=c||{};c=Object.assign({skipFilter:!1,inTypeOverride:!1,outTypeOverride:!1},c);var e=g.registered_node_types[a];if(p&&e.filter!=p||(!b.show_all_if_empty||d)&&-1===a.toLowerCase().indexOf(d))return!1;if(b.do_type_filter&&!c.skipFilter){e=l.value;!1!==c.inTypeOverride&&(e=c.inTypeOverride);if(l&&e&&g.registered_slot_in_types[e]&&g.registered_slot_in_types[e].nodes&&(e=g.registered_slot_in_types[e].nodes.includes(a),!1===e))return!1;e=t.value;!1!==c.outTypeOverride&&(e=c.outTypeOverride); +if(t&&e&&g.registered_slot_out_types[e]&&g.registered_slot_out_types[e].nodes&&(e=g.registered_slot_out_types[e].nodes.includes(a),!1===e))return!1}return!0};var q=0;d=d.toLowerCase();var p=h.filter||h.graph.filter;if(b.do_type_filter&&f.search_box)var l=f.search_box.querySelector(".slot_in_type_filter"),t=f.search_box.querySelector(".slot_out_type_filter");else t=l=!1;for(k in g.searchbox_extras){var n=g.searchbox_extras[k];if(b.show_all_if_empty&&!d||-1!==n.desc.toLowerCase().indexOf(d)){var r= +g.registered_node_types[n.type];if((!r||r.filter==p)&&e(n.type)&&(a(n.desc,"searchbox_extra"),-1!==m.search_limit&&q++>m.search_limit))break}}n=null;if(Array.prototype.filter)n=Object.keys(g.registered_node_types).filter(e);else for(k in n=[],g.registered_node_types)e(k)&&n.push(k);for(k=0;km.search_limit);k++);if(b.show_general_after_typefiltered&&(l.value||t.value)){filtered_extra=[];for(k in g.registered_node_types)e(k,{inTypeOverride:l&&l.value?"*": +!1,outTypeOverride:t&&t.value?"*":!1})&&filtered_extra.push(k);for(k=0;km.search_limit);k++);}if((l.value||t.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;km.search_limit);k++);}}}def_options={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=Object.assign(def_options,b||{});var f=this,h=m.active_canvas,k=h.canvas,q=k.ownerDocument||document,p=document.createElement("div");p.className="litegraph litesearchbox graphdialog rounded";p.innerHTML="Search "; +b.do_type_filter&&(p.innerHTML+="",p.innerHTML+="");p.innerHTML+="
";q.fullscreenElement?q.fullscreenElement.appendChild(p):(q.body.appendChild(p),q.body.style.overflow="hidden");if(b.do_type_filter)var t=p.querySelector(".slot_in_type_filter"),n=p.querySelector(".slot_out_type_filter");p.close=function(){f.search_box=null;this.blur(); +k.focus();q.body.style.overflow="";setTimeout(function(){f.canvas.focus()},20);p.parentNode&&p.parentNode.removeChild(p)};1t.height-200&&(u.style.maxHeight=t.height-a.layerY-20+"px");z.focus();b.show_all_on_open&&e();return p};m.prototype.showEditPropertyValue=function(a,b,c){function d(){e(n.value)}function e(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(); +l.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 l=this.createDialog(""+(f.label?f.label:b)+""+g+"",c),n=!1;if("enum"!=h&&"combo"!=h||!f.values)if("boolean"==h||"toggle"==h)(n=l.querySelector("input"))&&n.addEventListener("click",function(a){l.modified();e(!!n.checked)});else{if(n=l.querySelector("input"))n.addEventListener("blur",function(a){this.focus()}), +p=void 0!==a.properties[b]?a.properties[b]:"","string"!==h&&(p=JSON.stringify(p)),n.value=p,n.addEventListener("keydown",function(a){if(27==a.keyCode)l.close();else if(13==a.keyCode)d();else if(13!=a.keyCode){l.modified();return}a.preventDefault();a.stopPropagation()})}else n=l.querySelector("select"),n.addEventListener("change",function(a){l.modified();e(a.target.value)});n&&n.focus();l.querySelector("button").addEventListener("click",d);return l}};m.prototype.createDialog=function(a,b){def_options= {checkForInput:!1,closeOnLeave:!0,closeOnLeave_checkModified:!0};b=Object.assign(def_options,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(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};m.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.removeChild(d);this.parentNode&&this.parentNode.removeChild(this)};d.toggleAltContent=function(a){if("undefined"!=typeof a){var b=a?"block":"none";a= -a?"none":"block"}else b="block"!=d.alt_content.style.display?"block":"none",a="block"!=d.alt_content.style.display?"none":"block";d.alt_content.style.display=b;d.content.style.display=a};d.toggleFooterVisibility=function(a){d.footer.style.display="undefined"!=typeof a?a?"block":"none":"block"!=d.footer.style.display?"block":"none"};d.clear=function(){this.content.innerHTML=""};d.addHTML=function(a,b,c){var e=document.createElement("div");b&&(e.className=b);e.innerHTML=a;c?d.footer.appendChild(e): -d.content.appendChild(e);return e};d.addButton=function(a,b,c){var e=document.createElement("button");e.innerText=a;e.options=c;e.classList.add("btn");e.addEventListener("click",b);d.footer.appendChild(e);return e};d.addSeparator=function(){var a=document.createElement("div");a.className="separator";d.content.appendChild(a)};d.addWidget=function(a,b,h,k,n){function e(a,b){k.callback&&k.callback(a,b,k);n&&n(a,b,k)}k=k||{};var f=String(h);a=a.toLowerCase();"number"==a&&(f=h.toFixed(3));var l=document.createElement("div"); -l.className="property";l.innerHTML="";l.querySelector(".property_name").innerText=k.label||b;var p=l.querySelector(".property_value");p.innerText=f;l.dataset.property=b;l.dataset.type=k.type||a;l.options=k;l.value=h;if("code"==a)l.addEventListener("click",function(a){d.inner_showCodePad(this.dataset.property)});else if("boolean"==a)l.classList.add("boolean"),h&&l.classList.add("bool-on"),l.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";e(a,this.value)});else if("string"==a||"number"==a)p.setAttribute("contenteditable",!0),p.addEventListener("keydown",function(b){"Enter"!=b.code||"string"==a&&b.shiftKey||(b.preventDefault(),this.blur())}),p.addEventListener("blur",function(){var a=this.innerText,b=this.parentNode.dataset.property;"number"==this.parentNode.dataset.type&&(a=Number(a)); -e(b,a)});else if("enum"==a||"combo"==a)f=m.getPropertyPrintableValue(h,k.values),p.innerText=f,p.addEventListener("click",function(a){var b=this.parentNode.dataset.property,d=this;new g.ContextMenu(k.values||[],{event:a,className:"dark",callback:function(a,c,f){d.innerText=a;e(b,a);return!1}},c)});d.content.appendChild(l);return l};if(d.onOpen&&"function"==typeof d.onOpen)d.onOpen();return d};m.getPropertyPrintableValue=function(a,b){if(!b||b.constructor===Array)return String(a);if(b.constructor=== +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(a){if("undefined"!=typeof a){var b=a?"block": +"none";a=a?"none":"block"}else b="block"!=d.alt_content.style.display?"block":"none",a="block"!=d.alt_content.style.display?"none":"block";d.alt_content.style.display=b;d.content.style.display=a};d.toggleFooterVisibility=function(a){d.footer.style.display="undefined"!=typeof a?a?"block":"none":"block"!=d.footer.style.display?"block":"none"};d.clear=function(){this.content.innerHTML=""};d.addHTML=function(a,b,c){var e=document.createElement("div");b&&(e.className=b);e.innerHTML=a;c?d.footer.appendChild(e): +d.content.appendChild(e);return e};d.addButton=function(a,b,c){var e=document.createElement("button");e.innerText=a;e.options=c;e.classList.add("btn");e.addEventListener("click",b);d.footer.appendChild(e);return e};d.addSeparator=function(){var a=document.createElement("div");a.className="separator";d.content.appendChild(a)};d.addWidget=function(a,b,h,k,q){function e(a,b){k.callback&&k.callback(a,b,k);q&&q(a,b,k)}k=k||{};var f=String(h);a=a.toLowerCase();"number"==a&&(f=h.toFixed(3));var l=document.createElement("div"); +l.className="property";l.innerHTML="";l.querySelector(".property_name").innerText=k.label||b;var r=l.querySelector(".property_value");r.innerText=f;l.dataset.property=b;l.dataset.type=k.type||a;l.options=k;l.value=h;if("code"==a)l.addEventListener("click",function(a){d.inner_showCodePad(this.dataset.property)});else if("boolean"==a)l.classList.add("boolean"),h&&l.classList.add("bool-on"),l.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";e(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)); +e(b,a)});else if("enum"==a||"combo"==a)f=m.getPropertyPrintableValue(h,k.values),r.innerText=f,r.addEventListener("click",function(a){var b=this.parentNode.dataset.property,d=this;new g.ContextMenu(k.values||[],{event:a,className:"dark",callback:function(a,c,f){d.innerText=a;e(b,a);return!1}},c)});d.content.appendChild(l);return l};if(d.onOpen&&"function"==typeof d.onOpen)d.onOpen();return d};m.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+")"}};m.prototype.closePanels=function(){var a=document.querySelector("#node-panel");a&&a.close();(a=document.querySelector("#option-panel"))&&a.close()};m.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 a=function(a,b,c){c&&c.key&&(a=c.key);c.values&&(b=Object.values(c.values).indexOf(b));e[a]=b},b=g.availableCanvasOptions;b.sort();for(pI in b){var c=b[pI];panel.addWidget("boolean",c,e[c],{key:c, on:"True",off:"False"},a)}panel.addWidget("combo","Render mode",g.LINK_RENDER_MODES[e.links_render_mode],{key:"links_render_mode",values:g.LINK_RENDER_MODES},a);panel.addSeparator();panel.footer.innerHTML=""})();e.canvas.parentNode.appendChild(panel)};m.prototype.showShowNodePanel=function(a){function b(){panel.content.innerHTML="";panel.addHTML(""+a.type+""+(a.constructor.desc||"")+"");panel.addHTML("

Properties

"); @@ -339,7 +339,7 @@ b.prototype.__lookupGetter__(c)):a.prototype[c]=b.prototype[c],b.prototype.__loo 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(a,b){return a[0]-b[0]}),this.selected=c.indexOf(b),this.must_update=!0);if(-1!=this.selected)return!0}};E.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:Math.clamp(e,0,1),b[1]=1-Math.clamp(f,0,1),c.sort(function(a,b){return a[0]-b[0]}),this.selected=c.indexOf(b),this.must_update=!0)}}}};E.prototype.onMouseUp=function(a,b){this.selected=-1;return!1};E.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,l=-1,m=0;mk||p>b||(l=m,k=p)}return l};g.CurveEditor=E;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){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,l=-1,m=0;mk||r>b||(l=m,k=r)}return l};g.CurveEditor=E;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,d){d=void 0===d?!1:d;if(a&&a.addEventListener&&b&&"function"===typeof c){var e=g.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)}}};g.pointerListenerRemove=function(a,b,c,d){d=void 0===d?!1:d;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,d);case "leave":case "cancel":case "gotpointercapture":case "lostpointercapture":if("pointer"==g.pointerevents_method)return a.removeEventListener(g.pointerevents_method+b,c,d);default:return a.removeEventListener(b,c,d)}};Math.clamp=function(a,b,c){return b>a?b:c max_size) { max_size = node.size[max_size_index]; } - node_size_index = (layout == LiteGraph.VERTICAL_LAYOUT) ? 0 : 1; + var node_size_index = (layout == LiteGraph.VERTICAL_LAYOUT) ? 0 : 1; y += node.size[node_size_index] + margin + LiteGraph.NODE_TITLE_HEIGHT; } x += max_size + margin; @@ -3194,6 +3194,15 @@ return; } + if(slot == null) + { + console.error("slot must be a number"); + return; + } + + if(slot.constructor !== Number) + console.warn("slot must be a number, use node.trigger('name') if you want to use a string"); + var output = this.outputs[slot]; if (!output) { return; @@ -7483,8 +7492,8 @@ LGraphNode.prototype.executeAction = function(action) clientY_rel = e.clientY; } - e.deltaX = clientX_rel - this.last_mouse_position[0]; - e.deltaY = clientY_rel- this.last_mouse_position[1]; + // e.deltaX = clientX_rel - this.last_mouse_position[0]; + // e.deltaY = clientY_rel- this.last_mouse_position[1]; this.last_mouse_position[0] = clientX_rel; this.last_mouse_position[1] = clientY_rel; @@ -9921,7 +9930,8 @@ LGraphNode.prototype.executeAction = function(action) case "combo": var old_value = w.value; if (event.type == LiteGraph.pointerevents_method+"move" && w.type == "number") { - w.value += event.deltaX * 0.1 * (w.options.step || 1); + if(event.deltaX) + w.value += event.deltaX * 0.1 * (w.options.step || 1); if ( w.options.min != null && w.value < w.options.min ) { w.value = w.options.min; } @@ -11987,7 +11997,8 @@ LGraphNode.prototype.executeAction = function(action) if (root.onClose && typeof root.onClose == "function"){ root.onClose(); } - root.parentNode.removeChild(root); + if(root.parentNode) + root.parentNode.removeChild(root); /* XXX CHECK THIS */ if(this.parentNode){ this.parentNode.removeChild(this); @@ -15606,7 +15617,7 @@ if (typeof exports != "undefined") { }; NodeScript.title = "Script"; - NodeScript.desc = "executes a code (max 100 characters)"; + NodeScript.desc = "executes a code (max 256 characters)"; NodeScript.widgets_info = { onExecute: { type: "code" } @@ -16208,7 +16219,32 @@ if (typeof exports != "undefined") { LiteGraph.registerNodeType("events/semaphore", SemaphoreEvent); + function OnceEvent() { + this.addInput("in", LiteGraph.ACTION ); + this.addInput("reset", LiteGraph.ACTION ); + this.addOutput("out", LiteGraph.EVENT ); + this._once = false; + this.properties = {}; + var that = this; + this.addWidget("button","reset","",function(){ + that._once = false; + }); + } + OnceEvent.title = "Once"; + OnceEvent.desc = "Only passes an event once, then gets locked"; + + OnceEvent.prototype.onAction = function(action, param) { + if( action == "in" && !this._once ) + { + this._once = true; + this.triggerSlot( 0, param ); + } + else if( action == "reset" ) + this._once = false; + }; + + LiteGraph.registerNodeType("events/once", OnceEvent); function DataStore() { this.addInput("data", 0); diff --git a/build/litegraph.min.js b/build/litegraph.min.js index 6c4553236..28710eefa 100644 --- a/build/litegraph.min.js +++ b/build/litegraph.min.js @@ -9,26 +9,26 @@ $jscomp.iteratorFromArray=function(B,c){$jscomp.initSymbolIterator();B instanceo $jscomp.polyfill("Array.prototype.fill",function(B){return B?B:function(c,l,r){var t=this.length||0;0>l&&(l=Math.max(0,t+l));if(null==r||r>t)r=t;r=Number(r);0>r&&(r=Math.max(0,t+r));for(l=Number(l||0);l=v}},"es6","es3"); $jscomp.findInternal=function(B,c,l){B instanceof String&&(B=String(B));for(var r=B.length,t=0;tc?-l:l}},"es6","es3"); -(function(B){function c(a){e.debug&&console.log("Graph created");this.list_of_graphcanvas=null;this.clear();a&&this.configure(a)}function l(a,b,d,g,f,e){this.id=a;this.type=b;this.origin_id=d;this.origin_slot=g;this.target_id=f;this.target_slot=e;this._data=null;this._pos=new Float32Array(2)}function r(a){this._ctor(a)}function t(a){this._ctor(a)}function v(a,b){this.offset=new Float32Array([0,0]);this.scale=1;this.max_scale=10;this.min_scale=.1;this.onredraw=null;this.enabled=!0;this.last_mouse= +(function(B){function c(a){e.debug&&console.log("Graph created");this.list_of_graphcanvas=null;this.clear();a&&this.configure(a)}function l(a,b,d,g,f,m){this.id=a;this.type=b;this.origin_id=d;this.origin_slot=g;this.target_id=f;this.target_slot=m;this._data=null;this._pos=new Float32Array(2)}function r(a){this._ctor(a)}function t(a){this._ctor(a)}function v(a,b){this.offset=new Float32Array([0,0]);this.scale=1;this.max_scale=10;this.min_scale=.1;this.onredraw=null;this.enabled=!0;this.last_mouse= [0,0];this.element=null;this.visible_area=new Float32Array(4);a&&(this.element=a,b||this.bindEvents(a))}function h(a,b,d){this.options=d=d||{};this.background_image=h.DEFAULT_BACKGROUND_IMAGE;a&&a.constructor===String&&(a=document.querySelector(a));this.ds=new v;this.zoom_modify_alpha=!0;this.title_text_font=""+e.NODE_TEXT_SIZE+"px Arial";this.inner_text_font="normal "+e.NODE_SUBTEXT_SIZE+"px Arial";this.node_title_color=e.NODE_TITLE_COLOR;this.default_link_color=e.LINK_COLOR;this.default_connection_color= {input_off:"#778",input_on:"#7F7",output_off:"#778",output_on:"#7F7"};this.default_connection_color_byType={};this.default_connection_color_byTypeOff={};this.highquality_render=!0;this.use_gradients=!1;this.editor_alpha=1;this.pause_rendering=!1;this.clear_background=!0;this.read_only=!1;this.render_only_selected=!0;this.live_mode=!1;this.allow_reconnect_links=this.allow_searchbox=this.allow_interaction=this.allow_dragnodes=this.allow_dragcanvas=this.show_info=!0;this.drag_mode=this.align_to_grid= !1;this.filter=this.dragging_rectangle=null;this.set_canvas_dirty_on_mouse_event=!0;this.always_render_background=!1;this.render_canvas_border=this.render_shadows=!0;this.render_connections_shadows=!1;this.render_connections_border=!0;this.render_connection_arrows=this.render_curved_connections=!1;this.render_collapsed_slots=!0;this.render_execution_order=!1;this.render_link_tooltip=this.render_title_colored=!0;this.links_render_mode=e.SPLINE_LINK;this.mouse=[0,0];this.canvas_mouse=this.graph_mouse= [0,0];this.onAfterChange=this.onBeforeChange=this.onConnectingChange=this.onSelectionChange=this.onNodeMoved=this.onDrawLinkTooltip=this.onDrawOverlay=this.onDrawForeground=this.onDrawBackground=this.onMouse=this.onSearchBoxSelection=this.onSearchBox=null;this.connections_width=3;this.round_radius=8;this.over_link_center=this.node_widget=this.current_node=null;this.last_mouse_position=[0,0];this.visible_area=this.ds.visible_area;this.visible_links=[];this.viewport=d.viewport||null;b&&b.attachCanvas(this); -this.setCanvas(a,d.skip_events);this.clear();d.skip_render||this.startRendering();this.autoresize=d.autoresize}function E(a,b){return Math.sqrt((b[0]-a[0])*(b[0]-a[0])+(b[1]-a[1])*(b[1]-a[1]))}function A(a,b,d,g,f,e){return da&&gb?!0:!1}function I(a,b){var d=a[0]+a[2],g=a[1]+a[3],f=b[1]+b[3];return a[0]>b[0]+b[2]||a[1]>f||da&&gb?!0:!1}function I(a,b){var d=a[0]+a[2],g=a[1]+a[3],f=b[1]+b[3];return a[0]>b[0]+b[2]||a[1]>f||d -u.width-c.width-10&&(f=u.width-c.width-10),u.height&&a>u.height-c.height-10&&(a=u.height-c.height-10));m.style.left=f+"px";m.style.top=a+"px";b.scale&&(m.style.transform="scale("+b.scale+")")}function F(a){this.points=a;this.nearest=this.selected=-1;this.size=null;this.must_update=!0;this.margin=5}var e=B.LiteGraph={VERSION:.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, +u.width-c.width-10&&(f=u.width-c.width-10),u.height&&a>u.height-c.height-10&&(a=u.height-c.height-10));m.style.left=f+"px";m.style.top=a+"px";b.scale&&(m.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}var e=B.LiteGraph={VERSION:.4,CANVAS_GRID_SIZE:10,NODE_TITLE_HEIGHT:30,NODE_TITLE_TEXT_Y:20,NODE_SLOT_HEIGHT:20,NODE_WIDGET_HEIGHT:20,NODE_WIDTH:140,NODE_MIN_WIDTH:50,NODE_COLLAPSED_RADIUS:10,NODE_COLLAPSED_WIDTH:80, NODE_TITLE_COLOR:"#999",NODE_SELECTED_TITLE_COLOR:"#FFF",NODE_TEXT_SIZE:14,NODE_TEXT_COLOR:"#AAA",NODE_SUBTEXT_SIZE:12,NODE_DEFAULT_COLOR:"#333",NODE_DEFAULT_BGCOLOR:"#353535",NODE_DEFAULT_BOXCOLOR:"#666",NODE_DEFAULT_SHAPE:"box",NODE_BOX_OUTLINE_COLOR:"#FFF",DEFAULT_SHADOW_COLOR:"rgba(0,0,0,0.5)",DEFAULT_GROUP_FONT:24,WIDGET_BGCOLOR:"#222",WIDGET_OUTLINE_COLOR:"#666",WIDGET_TEXT_COLOR:"#DDD",WIDGET_SECONDARY_TEXT_COLOR:"#999",LINK_COLOR:"#9A9",EVENT_LINK_COLOR:"#A86",CONNECTING_LINK_COLOR:"#AFA", MAX_NUMBER_OF_NODES:1E3,DEFAULT_POSITION:[100,100],VALID_SHAPES:["default","box","round","card"],BOX_SHAPE:1,ROUND_SHAPE:2,CIRCLE_SHAPE:3,CARD_SHAPE:4,ARROW_SHAPE:5,GRID_SHAPE:6,INPUT:1,OUTPUT:2,EVENT:-1,ACTION:-1,NODE_MODES:["Always","On Event","Never","On Trigger"],NODE_MODES_COLORS:["#666","#422","#333","#224","#626"],ALWAYS:0,ON_EVENT:1,NEVER:2,ON_TRIGGER:3,UP:1,DOWN:2,LEFT:3,RIGHT:4,CENTER:5,LINK_RENDER_MODES:["Straight","Linear","Spline"],STRAIGHT_LINK:0,LINEAR_LINK:1,SPLINE_LINK:2,NORMAL_TITLE:0, -NO_TITLE:1,TRANSPARENT_TITLE:2,AUTOHIDE_TITLE:3,proxy:null,node_images_path:"",debug:!1,catch_exceptions:!0,throw_errors:!0,allow_scripts:!1,registered_node_types:{},node_types_by_file_extension:{},Nodes:{},Globals:{},searchbox_extras:{},auto_sort_node_types:!1,node_box_coloured_when_on:!1,node_box_coloured_by_mode:!1,dialog_close_on_mouse_leave:!0,dialog_close_on_mouse_leave_delay:500,shift_click_do_break_link_from:!1,click_do_break_link_to:!1,search_hide_on_mouse_leave:!0,search_filter_enabled:!1, -search_show_all_on_open:!0,auto_load_slot_types:!1,registered_slot_in_types:{},registered_slot_out_types:{},slot_types_in:[],slot_types_out:[],slot_types_default_in:[],slot_types_default_out:[],alt_drag_do_clone_nodes:!1,do_add_triggers_slots:!1,allow_multi_output_for_events:!0,middle_click_slot_add_default_node:!1,release_link_on_empty_shows_menu:!1,pointerevents_method:"mouse",registerNodeType:function(a,b){if(!b.prototype)throw"Cannot register a simple object, it must be a class with a prototype"; +NO_TITLE:1,TRANSPARENT_TITLE:2,AUTOHIDE_TITLE:3,VERTICAL_LAYOUT:"vertical",proxy:null,node_images_path:"",debug:!1,catch_exceptions:!0,throw_errors:!0,allow_scripts:!1,registered_node_types:{},node_types_by_file_extension:{},Nodes:{},Globals:{},searchbox_extras:{},auto_sort_node_types:!1,node_box_coloured_when_on:!1,node_box_coloured_by_mode:!1,dialog_close_on_mouse_leave:!0,dialog_close_on_mouse_leave_delay:500,shift_click_do_break_link_from:!1,click_do_break_link_to:!1,search_hide_on_mouse_leave:!0, +search_filter_enabled:!1,search_show_all_on_open:!0,auto_load_slot_types:!1,registered_slot_in_types:{},registered_slot_out_types:{},slot_types_in:[],slot_types_out:[],slot_types_default_in:[],slot_types_default_out:[],alt_drag_do_clone_nodes:!1,do_add_triggers_slots:!1,allow_multi_output_for_events:!0,middle_click_slot_add_default_node:!1,release_link_on_empty_shows_menu:!1,pointerevents_method:"mouse",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,g=a.lastIndexOf("/");b.category=a.substr(0,g);b.title||(b.title=d);if(b.prototype)for(var f in r.prototype)b.prototype[f]||(b.prototype[f]=r.prototype[f]);if(g=this.registered_node_types[a])console.log("replacing node type: "+a);else if(Object.hasOwnProperty(b.prototype,"shape")||Object.defineProperty(b.prototype,"shape",{set:function(a){switch(a){case "default":delete this._shape;break;case "box":this._shape=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,configurable:!0}),b.prototype.onPropertyChange&&console.warn("LiteGraph node class "+a+" has onPropertyChange method, it must be called onPropertyChanged with d at the end"),b.supported_extensions)for(f in b.supported_extensions){var m=b.supported_extensions[f];m&&m.constructor===String&& (this.node_types_by_file_extension[m.toLowerCase()]=b)}this.registered_node_types[a]=b;b.constructor.name&&(this.Nodes[d]=b);if(e.onNodeTypeRegistered)e.onNodeTypeRegistered(a,b);if(g&&e.onNodeTypeReplaced)e.onNodeTypeReplaced(a,b,g);b.prototype.onPropertyChange&&console.warn("LiteGraph node class "+a+" has onPropertyChange method, it must be called onPropertyChanged with d at the end");if(b.supported_extensions)for(f=0;fu&&(u=f.size[0]),c+=f.size[1]+a+e.NODE_TITLE_HEIGHT;b+=u+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 g=this._nodes_in_order?this._nodes_in_order:this._nodes;if(g)for(var f=0,m=g.length;f=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_idc&&(c=m.size[A]);k+=m.size[b==e.VERTICAL_LAYOUT?0:1]+a+e.NODE_TITLE_HEIGHT}d+=c+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 g=this._nodes_in_order?this._nodes_in_order:this._nodes;if(g)for(var f=0,m=g.length;f=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={}};r.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)){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}};r.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};r.prototype.getInputDataByName=function(a,b){a=this.findInputSlot(a);return-1==a?null:this.getInputData(a, -b)};r.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};r.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};r.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]-f-db)return!0;return!1};r.prototype.getSlotInPosition= -function(a,b){var d=new Float32Array(2);if(this.inputs)for(var g=0,f=this.inputs.length;g=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)if(e.do_add_triggers_slots)b.changeMode(e.ON_TRIGGER),d=b.findInputSlot("onTrigger");else return null;else if(!b.inputs||d>=b.inputs.length)return e.debug&&console.log("Connect: Error, slot number not found"),null;var g=b.inputs[d],f=this.outputs[a];if(!this.outputs[a])return null;b.onBeforeConnectInput&&(d=b.onBeforeConnectInput(d));if(!1===d||null===d||!e.isValidConnection(f.type,g.type))return this.setDirtyCanvas(!1,!0),null;if(b.onConnectInput&&!1===b.onConnectInput(d,f.type,f,this,a)|| -this.onConnectOutput&&!1===this.onConnectOutput(a,g.type,g,b,d))return null;b.inputs[d]&&null!=b.inputs[d].link&&(this.graph.beforeChange(),b.disconnectInput(d,{doProcessChange:!1}));if(null!==f.links&&f.links.length)switch(f.type){case e.EVENT:e.allow_multi_output_for_events||(this.graph.beforeChange(),this.disconnectOutput(a,!1,{doProcessChange:!1}))}var m=new l(++this.graph.last_link_id,g.type||f.type,this.id,a,b.id,d);this.graph.links[m.id]=m;null==f.links&&(f.links=[]);f.links.push(m.id);b.inputs[d].link= -m.id;this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(e.OUTPUT,a,!0,m,f);if(b.onConnectionsChange)b.onConnectionsChange(e.INPUT,d,!0,m,g);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.afterChange();this.graph.connectionChange(this,m);return m};r.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 g=0,f=d.links.length;g=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;if(null!=d){this.inputs[a].link=null;var g=this.graph.links[d];if(g){var f=this.graph.getNodeById(g.origin_id);if(!f)return!1;var m=f.outputs[g.origin_slot];if(!m||!m.links||0==m.links.length)return!1;for(var u=0,c=m.links.length;ub&&this.inputs[b].pos)return d[0]=this.pos[0]+this.inputs[b].pos[0],d[1]=this.pos[1]+this.inputs[b].pos[1],d;if(!a&&g>b&&this.outputs[b].pos)return d[0]=this.pos[0]+this.outputs[b].pos[0],d[1]=this.pos[1]+this.outputs[b].pos[1], -d;if(this.horizontal)return d[0]=this.pos[0]+this.size[0]/g*(b+.5),d[1]=a?this.pos[1]-e.NODE_TITLE_HEIGHT:this.pos[1]+this.size[1],d;d[0]=a?this.pos[0]+f:this.pos[0]+this.size[0]+1-f;d[1]=this.pos[1]+(b+.7)*e.NODE_SLOT_HEIGHT+(this.constructor.slot_start_y||0);return d};r.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)};r.prototype.trace=function(a){this.console||(this.console= -[]);this.console.push(a);this.console.length>r.MAX_CONSOLE&&this.console.shift();if(this.graph.onNodeTrace)this.graph.onNodeTrace(this,a)};r.prototype.setDirtyCanvas=function(a,b){this.graph&&this.graph.sendActionToCanvas("setDirty",[a,b])};r.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};r.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})};t.prototype.configure=function(a){this.title=a.title;this._bounding.set(a.bounding);this.color=a.color;this.font=a.font};t.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}};t.prototype.move=function(a,b, -d){this._pos[0]+=a;this._pos[1]+=b;if(!d)for(d=0;d= -this.viewport[0]&&g=this.viewport[1]&&dthis.max_scale&&(a=this.max_scale);if(a!=this.scale&&this.element){var d=this.element.getBoundingClientRect();if(d&&(b=b||[.5*d.width,.5*d.height],d=this.convertCanvasToOffset(b),this.scale=a,.01>Math.abs(this.scale-1)&&(this.scale=1),a=this.convertCanvasToOffset(b),a=[a[0]-d[0],a[1]- -d[1]],this.offset[0]+=a[0],this.offset[1]+=a[1],this.onredraw))this.onredraw(this)}};v.prototype.changeDeltaScale=function(a,b){this.changeScale(this.scale*a,b)};v.prototype.reset=function(){this.scale=1;this.offset[0]=0;this.offset[1]=0};B.LGraphCanvas=e.LGraphCanvas=h;h.DEFAULT_BACKGROUND_IMAGE="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQBJREFUeNrs1rEKwjAUhlETUkj3vP9rdmr1Ysammk2w5wdxuLgcMHyptfawuZX4pJSWZTnfnu/lnIe/jNNxHHGNn//HNbbv+4dr6V+11uF527arU7+u63qfa/bnmh8sWLBgwYJlqRf8MEptXPBXJXa37BSl3ixYsGDBMliwFLyCV/DeLIMFCxYsWLBMwSt4Be/NggXLYMGCBUvBK3iNruC9WbBgwYJlsGApeAWv4L1ZBgsWLFiwYJmCV/AK3psFC5bBggULloJX8BpdwXuzYMGCBctgwVLwCl7Be7MMFixYsGDBsu8FH1FaSmExVfAxBa/gvVmwYMGCZbBg/W4vAQYA5tRF9QYlv/QAAAAASUVORK5CYII="; +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.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)){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}};r.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};r.prototype.getInputDataByName=function(a,b){a=this.findInputSlot(a);return-1==a?null:this.getInputData(a,b)};r.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};r.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};r.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]-f-db)return!0;return!1};r.prototype.getSlotInPosition=function(a,b){var d=new Float32Array(2);if(this.inputs)for(var g=0,f=this.inputs.length;g=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)if(e.do_add_triggers_slots)b.changeMode(e.ON_TRIGGER),d=b.findInputSlot("onTrigger");else return null;else if(!b.inputs||d>=b.inputs.length)return e.debug&&console.log("Connect: Error, slot number not found"),null;var g=b.inputs[d],f=this.outputs[a];if(!this.outputs[a])return null; +b.onBeforeConnectInput&&(d=b.onBeforeConnectInput(d));if(!1===d||null===d||!e.isValidConnection(f.type,g.type))return this.setDirtyCanvas(!1,!0),null;if(b.onConnectInput&&!1===b.onConnectInput(d,f.type,f,this,a)||this.onConnectOutput&&!1===this.onConnectOutput(a,g.type,g,b,d))return null;b.inputs[d]&&null!=b.inputs[d].link&&(this.graph.beforeChange(),b.disconnectInput(d,{doProcessChange:!1}));if(null!==f.links&&f.links.length)switch(f.type){case e.EVENT:e.allow_multi_output_for_events||(this.graph.beforeChange(), +this.disconnectOutput(a,!1,{doProcessChange:!1}))}var m=new l(++this.graph.last_link_id,g.type||f.type,this.id,a,b.id,d);this.graph.links[m.id]=m;null==f.links&&(f.links=[]);f.links.push(m.id);b.inputs[d].link=m.id;this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(e.OUTPUT,a,!0,m,f);if(b.onConnectionsChange)b.onConnectionsChange(e.INPUT,d,!0,m,g);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.afterChange();this.graph.connectionChange(this,m);return m};r.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 g=0,f=d.links.length;g=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;if(null!=d){this.inputs[a].link=null;var g=this.graph.links[d];if(g){var f=this.graph.getNodeById(g.origin_id);if(!f)return!1;var m=f.outputs[g.origin_slot];if(!m||!m.links||0==m.links.length)return!1;for(var u=0,c=m.links.length;ub&&this.inputs[b].pos)return d[0]=this.pos[0]+this.inputs[b].pos[0],d[1]=this.pos[1]+ +this.inputs[b].pos[1],d;if(!a&&g>b&&this.outputs[b].pos)return d[0]=this.pos[0]+this.outputs[b].pos[0],d[1]=this.pos[1]+this.outputs[b].pos[1],d;if(this.horizontal)return d[0]=this.pos[0]+this.size[0]/g*(b+.5),d[1]=a?this.pos[1]-e.NODE_TITLE_HEIGHT:this.pos[1]+this.size[1],d;d[0]=a?this.pos[0]+f:this.pos[0]+this.size[0]+1-f;d[1]=this.pos[1]+(b+.7)*e.NODE_SLOT_HEIGHT+(this.constructor.slot_start_y||0);return d};r.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)};r.prototype.trace=function(a){this.console||(this.console=[]);this.console.push(a);this.console.length>r.MAX_CONSOLE&&this.console.shift();if(this.graph.onNodeTrace)this.graph.onNodeTrace(this,a)};r.prototype.setDirtyCanvas=function(a,b){this.graph&&this.graph.sendActionToCanvas("setDirty",[a,b])};r.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};r.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})};t.prototype.configure=function(a){this.title=a.title;this._bounding.set(a.bounding);this.color=a.color;this.font=a.font};t.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}};t.prototype.move=function(a,b,d){this._pos[0]+=a;this._pos[1]+=b;if(!d)for(d=0;d=this.viewport[0]&&g=this.viewport[1]&&dthis.max_scale&&(a=this.max_scale);if(a!=this.scale&&this.element){var d=this.element.getBoundingClientRect();if(d&&(b= +b||[.5*d.width,.5*d.height],d=this.convertCanvasToOffset(b),this.scale=a,.01>Math.abs(this.scale-1)&&(this.scale=1),a=this.convertCanvasToOffset(b),a=[a[0]-d[0],a[1]-d[1]],this.offset[0]+=a[0],this.offset[1]+=a[1],this.onredraw))this.onredraw(this)}};v.prototype.changeDeltaScale=function(a,b){this.changeScale(this.scale*a,b)};v.prototype.reset=function(){this.scale=1;this.offset[0]=0;this.offset[1]=0};B.LGraphCanvas=e.LGraphCanvas=h;h.DEFAULT_BACKGROUND_IMAGE="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQBJREFUeNrs1rEKwjAUhlETUkj3vP9rdmr1Ysammk2w5wdxuLgcMHyptfawuZX4pJSWZTnfnu/lnIe/jNNxHHGNn//HNbbv+4dr6V+11uF527arU7+u63qfa/bnmh8sWLBgwYJlqRf8MEptXPBXJXa37BSl3ixYsGDBMliwFLyCV/DeLIMFCxYsWLBMwSt4Be/NggXLYMGCBUvBK3iNruC9WbBgwYJlsGApeAWv4L1ZBgsWLFiwYJmCV/AK3psFC5bBggULloJX8BpdwXuzYMGCBctgwVLwCl7Be7MMFixYsGDBsu8FH1FaSmExVfAxBa/gvVmwYMGCZbBg/W4vAQYA5tRF9QYlv/QAAAAASUVORK5CYII="; h.link_type_colors={"-1":e.EVENT_LINK_COLOR,number:"#AAA",node:"#DCA"};h.gradients={};h.prototype.clear=function(){this.fps=this.render_time=this.last_draw_time=this.frame=0;this.dragging_rectangle=null;this.selected_nodes={};this.selected_group=null;this.visible_nodes=[];this.connecting_node=this.node_capturing_input=this.node_over=this.node_dragged=null;this.highlighted_links={};this.dragging_canvas=!1;this.dirty_bgcanvas=this.dirty_canvas=!0;this.node_widget=this.node_in_panel=this.dirty_area= null;this.last_mouse=[0,0];this.last_mouseclick=0;this.pointer_is_double=this.pointer_is_down=!1;this.visible_area.set([0,0,0,0]);if(this.onClear)this.onClear()};h.prototype.setGraph=function(a,b){this.graph!=a&&(b||this.clear(),!a&&this.graph?this.graph.detachCanvas(this):(a.attachCanvas(this),this._graph_stack&&(this._graph_stack=null),this.setDirty(!0,!0)))};h.prototype.getTopGraph=function(){return this._graph_stack.length?this._graph_stack[0]:this.graph};h.prototype.openSubgraph=function(a){if(!a)throw"graph cannot be null"; if(this.graph==a)throw"graph cannot be the same";this.clear();this.graph&&(this._graph_stack||(this._graph_stack=[]),this._graph_stack.push(this.graph));a.attachCanvas(this);this.checkPanels();this.setDirty(!0,!0)};h.prototype.closeSubgraph=function(){if(this._graph_stack&&0!=this._graph_stack.length){var a=this.graph._subgraph_node,b=this._graph_stack.pop();this.selected_nodes={};this.highlighted_links={};b.attachCanvas(this);this.setDirty(!0,!0);a&&(this.centerOnNode(a),this.selectNodes([a]));this.ds.offset= @@ -142,22 +142,22 @@ h.getFileExtension=function(a){var b=a.indexOf("?");-1!=b&&(a=a.substr(0,b));b=a return a.defaultView||a.parentWindow};h.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))};h.prototype.stopRendering=function(){this.is_rendering=!1};h.prototype.blockClick=function(){this.block_click=!0;this.last_mouseclick=0};h.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();h.active_canvas=this;var d=this,g=a.clientX,f=a.clientY;this.ds.viewport=this.viewport;g=!this.viewport||this.viewport&&g>=this.viewport[0]&&g=this.viewport[1]&&ff-this.last_mouseclick&&u;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&&u?!0:!1;this.pointer_is_down=!0;this.canvas.focus();e.closeAllContextMenus(b);if(!this.onMouse|| -1!=this.onMouse(a)){if(1!=a.which||this.pointer_is_double)if(2==a.which){if(e.middle_click_slot_add_default_node&&m&&this.allow_interaction&&!g&&!this.read_only&&!this.connecting_node&&!m.flags.collapsed&&!this.live_mode){f=g=u=!1;if(m.outputs)for(C=0,c=m.outputs.length;Cm.size[0]-e.NODE_TITLE_HEIGHT&&0>c[1]&&(d=this,setTimeout(function(){d.openSubgraph(m.subgraph)},10)),this.live_mode&&(C=u=!0));C||(this.allow_dragnodes&&(this.graph.beforeChange(),this.node_dragged=m),this.selected_nodes[m.id]||this.processNodeSelected(m,a));this.dirty_canvas=!0}}else if(!g){if(!this.read_only)for(C=0;Cc[0]+4||a.canvasYc[1]+4)){this.showLinkMenu(u,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>E([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= +g=!0,A||(this.allow_dragnodes&&(this.graph.beforeChange(),this.node_dragged=m),this.selected_nodes[m.id]||this.processNodeSelected(m,a)));u=!1;if(m&&this.allow_interaction&&!g&&!this.read_only){this.live_mode||m.flags.pinned||this.bringToFront(m);if(!this.connecting_node&&!m.flags.collapsed&&!this.live_mode)if(!g&&!1!==m.resizable&&C(a.canvasX,a.canvasY,m.pos[0]+m.size[0]-5,m.pos[1]+m.size[1]-5,10,10))this.graph.beforeChange(),this.resizing_node=m,this.canvas.style.cursor="se-resize",g=!0;else{if(m.outputs){A= +0;for(var c=m.outputs.length;Am.size[0]-e.NODE_TITLE_HEIGHT&&0>c[1]&&(d=this,setTimeout(function(){d.openSubgraph(m.subgraph)},10)),this.live_mode&&(A=u=!0));A||(this.allow_dragnodes&&(this.graph.beforeChange(),this.node_dragged=m),this.selected_nodes[m.id]||this.processNodeSelected(m,a));this.dirty_canvas=!0}}else if(!g){if(!this.read_only)for(A=0;Ac[0]+4||a.canvasYc[1]+4)){this.showLinkMenu(u,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>F([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());f&&!this.read_only&&this.allow_searchbox&&(this.showSearchBox(a),a.preventDefault(),a.stopPropagation());u=!0}!g&&u&&this.allow_dragcanvas&&(this.dragging_canvas=!0)}this.last_mouse[0]=a.clientX;this.last_mouse[1]=a.clientY;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}}}};h.prototype.processMouseMove=function(a){this.autoresize&&this.resize();this.set_canvas_dirty_on_mouse_event&&(this.dirty_canvas=!0);if(this.graph){h.active_canvas=this;this.adjustMouseEvent(a);var b=[a.clientX,a.clientY];this.mouse[0]=b[0];this.mouse[1]=b[1];var d=[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);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);var g=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes);b=0;for(var f=this.graph._nodes.length;b< f;++b)if(this.graph._nodes[b].mouseOver&&g!=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(g){g.redraw_on_mouse&&(this.dirty_canvas=!0);if(!g.mouseOver&&(g.mouseOver=!0,this.node_over=g,this.dirty_canvas=!0,g.onMouseEnter))g.onMouseEnter(a);if(g.onMouseMove)g.onMouseMove(a,[a.canvasX-g.pos[0],a.canvasY-g.pos[1]],this);if(this.connecting_node)if(this.connecting_output){if(f= this._highlight_input||[0,0],!this.isOverNodeBox(g,a.canvasX,a.canvasY)){var m=this.isOverNodeInput(g,a.canvasX,a.canvasY,f);if(-1!=m&&g.inputs[m]){var u=g.inputs[m].type;e.isValidConnection(this.connecting_output.type,u)&&(this._highlight_input=f,this._highlight_input_slot=g.inputs[m])}else this._highlight_input_slot=this._highlight_input=null}}else this.connecting_input&&(f=this._highlight_output||[0,0],this.isOverNodeBox(g,a.canvasX,a.canvasY)||(m=this.isOverNodeOutput(g,a.canvasX,a.canvasY,f), --1!=m&&g.outputs[m]?(u=g.outputs[m].type,e.isValidConnection(this.connecting_input.type,u)&&(this._highlight_output=f)):this._highlight_output=null));this.canvas&&(A(a.canvasX,a.canvasY,g.pos[0]+g.size[0]-5,g.pos[1]+g.size[1]-5,5,5)?this.canvas.style.cursor="se-resize":this.canvas.style.cursor="crosshair")}else{f=null;for(b=0;bu[0]+4||a.canvasYu[1]+4)){f=m;break}f!=this.over_link_center&& +-1!=m&&g.outputs[m]?(u=g.outputs[m].type,e.isValidConnection(this.connecting_input.type,u)&&(this._highlight_output=f)):this._highlight_output=null));this.canvas&&(C(a.canvasX,a.canvasY,g.pos[0]+g.size[0]-5,g.pos[1]+g.size[1]-5,5,5)?this.canvas.style.cursor="se-resize":this.canvas.style.cursor="crosshair")}else{f=null;for(b=0;bu[0]+4||a.canvasYu[1]+4)){f=m;break}f!=this.over_link_center&& (this.over_link_center=f,this.dirty_canvas=!0);this.canvas&&(this.canvas.style.cursor="")}if(this.node_capturing_input&&this.node_capturing_input!=g&&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)g=this.selected_nodes[b],g.pos[0]+=d[0]/this.ds.scale,g.pos[1]+=d[1]/this.ds.scale;this.dirty_bgcanvas=this.dirty_canvas= !0}this.resizing_node&&!this.live_mode&&(d=[a.canvasX-this.resizing_node.pos[0],a.canvasY-this.resizing_node.pos[1]],b=this.resizing_node.computeSize(),d[0]=Math.max(b[0],d[0]),d[1]=Math.max(b[1],d[1]),this.resizing_node.setSize(d),this.canvas.style.cursor="se-resize",this.dirty_bgcanvas=this.dirty_canvas=!0)}a.preventDefault();return!1}};h.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 d= this.getCanvasWindow().document;h.active_canvas=this;this.options.skip_events||(e.pointerListenerRemove(d,"move",this._mousemove_callback,!0),e.pointerListenerAdd(this.canvas,"move",this._mousemove_callback,!0),e.pointerListenerRemove(d,"up",this._mouseup_callback,!0));this.adjustMouseEvent(a);d=e.getTime();a.click_time=d-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], @@ -166,11 +166,11 @@ a.canvasY,this.visible_nodes);if(this.dragging_rectangle){if(this.graph){d=this. [];for(m=0;ma.click_time&&A(a.canvasX,a.canvasY,g.pos[0],g.pos[1]-e.NODE_TITLE_HEIGHT,e.NODE_TITLE_HEIGHT,e.NODE_TITLE_HEIGHT)&&g.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.resizing_node=null;else if(this.node_dragged){(g=this.node_dragged)&&300>a.click_time&&C(a.canvasX,a.canvasY,g.pos[0],g.pos[1]-e.NODE_TITLE_HEIGHT,e.NODE_TITLE_HEIGHT,e.NODE_TITLE_HEIGHT)&&g.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{g=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes);!g&&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}};h.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=a.clientX,g=a.clientY;if(!this.viewport||this.viewport&& -d>=this.viewport[0]&&d=this.viewport[1]&&gb&&(d*=1/1.1),this.ds.changeScale(d,[a.clientX,a.clientY]),this.graph.change(),a.preventDefault(),!1}};h.prototype.isOverNodeBox=function(a,b,d){var g=e.NODE_TITLE_HEIGHT;return A(b,d,a.pos[0]+2,a.pos[1]+2-g,g-4,g-4)?!0:!1};h.prototype.isOverNodeInput=function(a,b,d,g){if(a.inputs)for(var f=0,e=a.inputs.length;f=this.viewport[0]&&d=this.viewport[1]&&gb&&(d*=1/1.1),this.ds.changeScale(d,[a.clientX,a.clientY]),this.graph.change(),a.preventDefault(),!1}};h.prototype.isOverNodeBox=function(a,b,d){var g=e.NODE_TITLE_HEIGHT;return C(b,d,a.pos[0]+2,a.pos[1]+2-g,g-4,g-4)?!0:!1};h.prototype.isOverNodeInput=function(a,b,d,g){if(a.inputs)for(var f=0,e=a.inputs.length;fd-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}};h.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 d=this.viewport||this.dirty_area;d&&(a.save(),a.beginPath(),a.rect(d[0],d[1],d[2],d[3]),a.clip());this.clear_background&&(d?a.clearRect(d[0],d[1],d[2],d[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,d?d[0]:0,d?d[1]:0);if(this.graph){a.save();this.ds.toCanvasContext(a);b=this.computeVisibleNodes(null, -this.visible_nodes);for(var g=0;g> ";b.fillText(g+d.getTitle(),.5*a.width,40);b.restore()}d=!1;this.onRenderBackground&&(d=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);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 m=this.editor_alpha;b.globalAlpha=m;this.render_shadows&&!f?(b.shadowColor=e.DEFAULT_SHADOW_COLOR,b.shadowOffsetX=2*this.ds.scale,b.shadowOffsetY= -2*this.ds.scale,b.shadowBlur=3*this.ds.scale):b.shadowColor="transparent";if(!a.flags.collapsed||!a.onDrawCollapsed||1!=a.onDrawCollapsed(b,this)){var c=a._shape||e.BOX_SHAPE;H.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*e.NODE_TITLE_HEIGHT),H[0]=a._collapsed_width,H[1]=0)}a.clip_area&&(b.save(),b.beginPath(),c==e.BOX_SHAPE?b.rect(0,0,H[0],H[1]):c==e.ROUND_SHAPE? -b.roundRect(0,0,H[0],H[1],[10]):c==e.CIRCLE_SHAPE&&b.arc(.5*H[0],.5*H[1],.5*H[0],0,2*Math.PI),b.clip());a.has_errors&&(g="red");this.drawNodeShape(a,b,H,d,g,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;g=!f;var x=this.connecting_output;c=this.connecting_input;b.lineWidth=1;q=0;var C=new Float32Array(2);if(!a.flags.collapsed){if(a.inputs)for(d=0;dthis.ds.scale,k=a._shape||a.constructor.shape||e.ROUND_SHAPE,x=a.constructor.title_mode,C=!0;x==e.TRANSPARENT_TITLE||x==e.NO_TITLE?C=!1:x==e.AUTOHIDE_TITLE&&c&&(C=!0);z[0]=0;z[1]=C?-f:0;z[2]=d[0]+1;z[3]=C?d[1]+f:d[1];c=b.globalAlpha;b.beginPath();k==e.BOX_SHAPE||u?b.fillRect(z[0],z[1],z[2],z[3]):k==e.ROUND_SHAPE||k==e.CARD_SHAPE?b.roundRect(z[0],z[1],z[2],z[3],k==e.CARD_SHAPE?[this.round_radius,this.round_radius, -0,0]:[this.round_radius]):k==e.CIRCLE_SHAPE&&b.arc(.5*d[0],.5*d[1],.5*d[0],0,2*Math.PI);b.fill();!a.flags.collapsed&&C&&(b.shadowColor="transparent",b.fillStyle="rgba(0,0,0,0.2)",b.fillRect(0,-1,z[2],2));b.shadowColor="transparent";if(a.onDrawBackground)a.onDrawBackground(b,this,this.canvas,this.graph_mouse);if(C||x==e.TRANSPARENT_TITLE){if(a.onDrawTitleBar)a.onDrawTitleBar(b,f,d,this.ds.scale,g);else if(x!=e.TRANSPARENT_TITLE&&(a.constructor.title_color||this.render_title_colored)){C=a.constructor.title_color|| -g;a.flags.collapsed&&(b.shadowColor=e.DEFAULT_SHADOW_COLOR);if(this.use_gradients){var w=h.gradients[C];w||(w=h.gradients[C]=b.createLinearGradient(0,0,400,0),w.addColorStop(0,C),w.addColorStop(1,"#000"));b.fillStyle=w}else b.fillStyle=C;b.beginPath();k==e.BOX_SHAPE||u?b.rect(0,-f,d[0]+1,f):(k==e.ROUND_SHAPE||k==e.CARD_SHAPE)&&b.roundRect(0,-f,d[0]+1,f,a.flags.collapsed?[this.round_radius]:[this.round_radius,this.round_radius,0,0]);b.fill();b.shadowColor="transparent"}C=!1;e.node_box_coloured_by_mode&& -e.NODE_MODES_COLORS[a.mode]&&(C=e.NODE_MODES_COLORS[a.mode]);e.node_box_coloured_when_on&&(C=a.action_triggered?"#FFF":a.execute_triggered?"#AAA":C);if(a.onDrawTitleBox)a.onDrawTitleBox(b,f,d,this.ds.scale);else k==e.ROUND_SHAPE||k==e.CIRCLE_SHAPE||k==e.CARD_SHAPE?(u&&(b.fillStyle="black",b.beginPath(),b.arc(.5*f,-.5*f,6,0,2*Math.PI),b.fill()),b.fillStyle=a.boxcolor||C||e.NODE_DEFAULT_BOXCOLOR,u?b.fillRect(.5*f-5,-.5*f-5,10,10):(b.beginPath(),b.arc(.5*f,-.5*f,5,0,2*Math.PI),b.fill())):(u&&(b.fillStyle= -"black",b.fillRect(.5*(f-10)-1,-.5*(f+10)-1,12,12)),b.fillStyle=a.boxcolor||C||e.NODE_DEFAULT_BOXCOLOR,b.fillRect(.5*(f-10),-.5*(f+10),10,10));b.globalAlpha=c;if(a.onDrawTitleText)a.onDrawTitleText(b,f,d,this.ds.scale,this.title_text_font,m);!u&&(b.font=this.title_text_font,c=String(a.getTitle()))&&(b.fillStyle=m?e.NODE_SELECTED_TITLE_COLOR:a.constructor.title_text_color||this.node_title_color,a.flags.collapsed?(b.textAlign="left",b.measureText(c),b.fillText(c.substr(0,20),f,e.NODE_TITLE_TEXT_Y-f), -b.textAlign="left"):(b.textAlign="left",b.fillText(c,f,e.NODE_TITLE_TEXT_Y-f)));a.flags.collapsed||!a.subgraph||a.skip_subgraph_button||(c=e.NODE_TITLE_HEIGHT,C=a.size[0]-c,w=e.isInsideRectangle(this.graph_mouse[0]-a.pos[0],this.graph_mouse[1]-a.pos[1],C+2,-c+2,c-4,c-4),b.fillStyle=w?"#888":"#555",k==e.BOX_SHAPE||u?b.fillRect(C+2,-c+2,c-4,c-4):(b.beginPath(),b.roundRect(C+2,-c+2,c-4,c-4,[4]),b.fill()),b.fillStyle="#333",b.beginPath(),b.moveTo(C+.2*c,.6*-c),b.lineTo(C+.8*c,.6*-c),b.lineTo(C+.5*c,.3* --c),b.fill());if(a.onDrawTitle)a.onDrawTitle(b)}if(m){if(a.onBounding)a.onBounding(z);x==e.TRANSPARENT_TITLE&&(z[1]-=f,z[3]+=f);b.lineWidth=1;b.globalAlpha=.8;b.beginPath();k==e.BOX_SHAPE?b.rect(-6+z[0],-6+z[1],12+z[2],12+z[3]):k==e.ROUND_SHAPE||k==e.CARD_SHAPE&&a.flags.collapsed?b.roundRect(-6+z[0],-6+z[1],12+z[2],12+z[3],[2*this.round_radius]):k==e.CARD_SHAPE?b.roundRect(-6+z[0],-6+z[1],12+z[2],12+z[3],[2*this.round_radius,2,2*this.round_radius,2]):k==e.CIRCLE_SHAPE&&b.arc(.5*d[0],.5*d[1],.5*d[0]+ -6,0,2*Math.PI);b.strokeStyle=e.NODE_BOX_OUTLINE_COLOR;b.stroke();b.strokeStyle=g;b.globalAlpha=1}0k[2]&&(k[0]+=k[2],k[2]=Math.abs(k[2]));0>k[3]&&(k[1]+=k[3],k[3]=Math.abs(k[3]));if(I(k, -M)){var L=D.outputs[x];x=m.inputs[c];if(L&&x&&(D=L.dir||(D.horizontal?e.DOWN:e.RIGHT),x=x.dir||(m.horizontal?e.UP:e.LEFT),this.renderLink(a,C,w,h,!1,0,null,D,x),h&&h._last_time&&1E3>b-h._last_time)){L=2-.002*(b-h._last_time);var G=a.globalAlpha;a.globalAlpha=G*L;this.renderLink(a,C,w,h,!0,L,"white",D,x);a.globalAlpha=G}}}}}}a.globalAlpha=1};h.prototype.renderLink=function(a,b,d,g,f,m,c,k,q,x){g&&this.visible_links.push(g);!c&&g&&(c=g.color||h.link_type_colors[g.type]);c||(c=this.default_link_color); -null!=g&&this.highlighted_links[g.id]&&(c="#FFF");k=k||e.RIGHT;q=q||e.LEFT;var u=E(b,d);this.render_connections_border&&.6b[1]?0:Math.PI,a.save(),a.translate(w[0],w[1]),a.rotate(u),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore(),a.save(),a.translate(g[0],g[1]), -a.rotate(x),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore()),a.beginPath(),a.arc(f[0],f[1],5,0,2*Math.PI),a.fill());if(m)for(a.fillStyle=c,w=0;5>w;++w)m=(.001*e.getTime()+.2*w)%1,f=this.computeConnectionPoint(b,d,m,k,q),a.beginPath(),a.arc(f[0],f[1],5,0,2*Math.PI),a.fill()};h.prototype.computeConnectionPoint=function(a,b,d,g,f){g=g||e.RIGHT;f=f||e.LEFT;var m=E(a,b),c=[a[0],a[1]],k=[b[0],b[1]];switch(g){case e.LEFT:c[0]+=-.25*m;break;case e.RIGHT:c[0]+=.25*m;break;case e.UP:c[1]+= --.25*m;break;case e.DOWN:c[1]+=.25*m}switch(f){case e.LEFT:k[0]+=-.25*m;break;case e.RIGHT:k[0]+=.25*m;break;case e.UP:k[1]+=-.25*m;break;case e.DOWN:k[1]+=.25*m}g=(1-d)*(1-d)*(1-d);f=3*(1-d)*(1-d)*d;m=3*(1-d)*d*d;d*=d*d;return[g*a[0]+f*c[0]+m*k[0]+d*b[0],g*a[1]+f*c[1]+m*k[1]+d*b[1]]};h.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,d=0;dc||c>G-12||kw.last_y+L||void 0===w.last_y)){g=w.value;switch(w.type){case "button":d.type===e.pointerevents_method+"down"&&(w.callback&&setTimeout(function(){w.callback(w,n,a,b,d)},20),this.dirty_canvas=w.clicked=!0);break;case "slider":x=Math.clamp((c-15)/(G-30),0,1);w.value=w.options.min+(w.options.max-w.options.min)*x;w.callback&& -setTimeout(function(){f(w,w.value)},20);this.dirty_canvas=!0;break;case "number":case "combo":g=w.value;if(d.type==e.pointerevents_method+"move"&&"number"==w.type)w.value+=.1*d.deltaX*(w.options.step||1),null!=w.options.min&&w.valuew.options.max&&(w.value=w.options.max);else if(d.type==e.pointerevents_method+"down"){var y=w.options.values;y&&y.constructor===Function&&(y=w.options.values(w,a));var D=null;"number"!=w.type&&(D=y.constructor=== -Array?y:Object.keys(y));c=40>c?-1:c>G-40?1:0;if("number"==w.type)w.value+=.1*c*(w.options.step||1),null!=w.options.min&&w.valuew.options.max&&(w.value=w.options.max);else if(c)x=-1,this.last_mouseclick=0,x=y.constructor===Object?D.indexOf(String(w.value))+c:D.indexOf(w.value)+c,x>=D.length&&(x=D.length-1),0>x&&(x=0),w.value=y.constructor===Array?y[x]:x;else{var h=y!=D?Object.values(y):y;new e.ContextMenu(h,{scale:Math.max(1,this.ds.scale), -event:d,className:"dark",callback:function(a,b,d){y!=D&&(a=h.indexOf(a));this.value=a;f(this,a);n.dirty_canvas=!0;return!1}.bind(w)},x)}}else d.type==e.pointerevents_method+"up"&&"number"==w.type&&(c=40>c?-1:c>G-40?1:0,200>d.click_time&&0==c&&this.prompt("Value",w.value,function(a){this.value=Number(a);f(this,this.value)}.bind(w),d));g!=w.value&&setTimeout(function(){f(this,this.value)}.bind(w),20);this.dirty_canvas=!0;break;case "toggle":d.type==e.pointerevents_method+"down"&&(w.value=!w.value,setTimeout(function(){f(w, -w.value)},20));break;case "string":case "text":d.type==e.pointerevents_method+"down"&&this.prompt("Value",w.value,function(a){this.value=a;f(this,a)}.bind(w),d,w.options?w.options.multiline:!1);break;default:w.mouse&&(this.dirty_canvas=w.mouse(d,[c,k],a))}if(g!=w.value){if(a.onWidgetChanged)a.onWidgetChanged(w.name,w.value,g,w);a.graph._version++}return w}}}return null};h.prototype.drawGroups=function(a,b){if(this.graph){a=this.graph._groups;b.save();b.globalAlpha=.5*this.editor_alpha;for(var d=0;d< -a.length;++d){var g=a[d];if(I(this.visible_area,g._bounding)){b.fillStyle=g.color||"#335";b.strokeStyle=g.color||"#335";var f=g._pos,c=g._size;b.globalAlpha=.25*this.editor_alpha;b.beginPath();b.rect(f[0]+.5,f[1]+.5,c[0],c[1]);b.fill();b.globalAlpha=this.editor_alpha;b.stroke();b.beginPath();b.moveTo(f[0]+c[0],f[1]+c[1]);b.lineTo(f[0]+c[0]-10,f[1]+c[1]);b.lineTo(f[0]+c[0],f[1]+c[1]-10);b.fill();c=g.font_size||e.DEFAULT_GROUP_FONT_SIZE;b.font=c+"px Arial";b.textAlign="left";b.fillText(g.title,f[0]+ -4,f[1]+c)}}b.restore()}};h.prototype.adjustNodesSize=function(){for(var a=this.graph._nodes,b=0;bd&&.01>b.editor_alpha&&(clearInterval(g),1>d&&(b.live_mode=!0));1"+(n.label?n.label:q)+""+a+"",value:q})}if(k.length)return new e.ContextMenu(k,{event:d,callback:function(a, -b,d,g){f&&(b=this.getBoundingClientRect(),c.showEditPropertyValue(f,a.value,{position:[b.left,b.top]}))},parentMenu:g,allow_html:!0,node:f},b),!1}};h.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};h.onMenuResizeNode=function(a,b,d,g,f){if(f){a=function(a){a.size=a.computeSize();if(a.onResize)a.onResize(a.size)};b=h.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)a(f);else for(var e in b.selected_nodes)a(b.selected_nodes[e]); -f.setDirtyCanvas(!0,!0)}};h.prototype.showLinkMenu=function(a,b){var d=this,g=d.graph.getNodeById(a.origin_id),f=d.graph.getNodeById(a.target_id),c=!1;g&&g.outputs&&g.outputs[a.origin_slot]&&(c=g.outputs[a.origin_slot].type);var k=!1;f&&f.outputs&&f.outputs[a.target_slot]&&(k=f.inputs[a.target_slot].type);var q=new e.ContextMenu(["Add Node",null,"Delete",null],{event:b,title:null!=a.data?a.data.constructor.name:null,callback:function(b,e,m){switch(b){case "Add Node":h.onMenuAdd(null,null,m,q,function(b){b.inputs&& -b.inputs.length&&b.outputs&&b.outputs.length&&g.connectByType(a.origin_slot,b,c)&&(b.connectByType(a.target_slot,f,k),b.pos[0]-=.5*b.size[0])});break;case "Delete":d.graph.removeLink(a.id)}}});return!1};h.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,d=!b&&a.nodeTo&&null!==a.slotTo;if(!b&&!d)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 g=b?a.nodeFrom:a.nodeTo,f=b?a.slotFrom:a.slotTo;switch(typeof f){case "string":d=b?g.findOutputSlot(f,!1):g.findInputSlot(f,!1);f=b?g.outputs[f]:g.inputs[f];break;case "object":d=b?g.findOutputSlot(f.name):g.findInputSlot(f.name);break;case "number":d=f;f=b?g.outputs[f]:g.inputs[f];break;default:return console.warn("Cant get slot information "+f),!1}!1!==f&&!1!== -d||console.warn("createDefaultNodeForSlot bad slotX "+f+" "+d);g=f.type==e.EVENT?"_event_":f.type;if((f=b?e.slot_types_default_out:e.slot_types_default_in)&&f[g]){nodeNewType=!1;if("object"==typeof f[g]||"array"==typeof f[g])for(var c in f[g]){if(a.nodeType==f[g][c]||"AUTO"==a.nodeType){nodeNewType=f[g][c];break}}else if(a.nodeType==f[g]||"AUTO"==a.nodeType)nodeNewType=f[g];if(nodeNewType){c=!1;"object"==typeof nodeNewType&&nodeNewType.node&&(c=nodeNewType,nodeNewType=nodeNewType.node);if(f=e.createNode(nodeNewType)){if(c){if(c.properties)for(var k in c.properties)f.addProperty(k, -c.properties[k]);if(c.inputs)for(k in f.inputs=[],c.inputs)f.addOutput(c.inputs[k][0],c.inputs[k][1]);if(c.outputs)for(k in f.outputs=[],c.outputs)f.addOutput(c.outputs[k][0],c.outputs[k][1]);c.title&&(f.title=c.title);c.json&&f.configure(c.json)}this.graph.add(f);f.pos=[a.position[0]+a.posAdd[0]+(a.posSizeFix[0]?a.posSizeFix[0]*f.size[0]:0),a.position[1]+a.posAdd[1]+(a.posSizeFix[1]?a.posSizeFix[1]*f.size[1]:0)];b?a.nodeFrom.connectByType(d,f,g):a.nodeTo.connectByTypeOutput(d,f,g);return!0}console.log("failed creating "+ -nodeNewType)}}return!1};h.prototype.showConnectionMenu=function(a){a=a||{};var b=Object.assign({nodeFrom:null,slotFrom:null,nodeTo:null,slotTo:null,e:null},a),d=this,g=b.nodeFrom&&b.slotFrom;a=!g&&b.nodeTo&&b.slotTo;if(!g&&!a)return console.warn("No data passed to showConnectionMenu"),!1;a=g?b.nodeFrom:b.nodeTo;var f=g?b.slotFrom:b.slotTo,c=!1;switch(typeof f){case "string":c=g?a.findOutputSlot(f,!1):a.findInputSlot(f,!1);f=g?a.outputs[f]:a.inputs[f];break;case "object":c=g?a.findOutputSlot(f.name): -a.findInputSlot(f.name);break;case "number":c=f;f=g?a.outputs[f]:a.inputs[f];break;default:return console.warn("Cant get slot information "+f),!1}a=["Add Node",null];d.allow_searchbox&&(a.push("Search"),a.push(null));var k=f.type==e.EVENT?"_event_":f.type,q=g?e.slot_types_default_out:e.slot_types_default_in;if(q&&q[k])if("object"==typeof q[k]||"array"==typeof q[k])for(var n in q[k])a.push(q[k][n]);else a.push(q[k]);var x=new e.ContextMenu(a,{event:b.e,title:(f&&""!=f.name?f.name+(k?" | ":""):"")+ -(f&&k?k:""),callback:function(a,e,m){switch(a){case "Add Node":h.onMenuAdd(null,null,m,x,function(a){g?b.nodeFrom.connectByType(c,a,k):b.nodeTo.connectByTypeOutput(c,a,k)});break;case "Search":g?d.showSearchBox(m,{node_from:b.nodeFrom,slot_from:f,type_filter_in:k}):d.showSearchBox(m,{node_to:b.nodeTo,slot_from:f,type_filter_out:k});break;default:d.createDefaultNodeForSlot(Object.assign(b,{position:[b.e.canvasX,b.e.canvasY],nodeType:a}))}}});return!1};h.onShowPropertyEditor=function(a,b,d,g,f){function c(){if(n){var b= -n.value;"Number"==a.type?b=Number(b):"Boolean"==a.type&&(b=!!b);f[k]=b;q.parentNode&&q.parentNode.removeChild(q);f.setDirtyCanvas(!0,!0)}}var k=a.property||"title";b=f[k];var q=document.createElement("div");q.is_modified=!1;q.className="graphdialog";q.innerHTML="";q.close=function(){q.parentNode&&q.parentNode.removeChild(q)};q.querySelector(".name").innerText=k;var n=q.querySelector(".value");n&&(n.value=b,n.addEventListener("blur", -function(a){this.focus()}),n.addEventListener("keydown",function(a){q.is_modified=!0;if(27==a.keyCode)q.close();else if(13==a.keyCode)c();else if(13!=a.keyCode&&"textarea"!=a.target.localName)return;a.preventDefault();a.stopPropagation()}));b=h.active_canvas.canvas;d=b.getBoundingClientRect();var x=g=-20;d&&(g-=d.left,x-=d.top);event?(q.style.left=event.clientX+g+"px",q.style.top=event.clientY+x+"px"):(q.style.left=.5*b.width+g+"px",q.style.top=.5*b.height+x+"px");q.querySelector("button").addEventListener("click", -c);b.parentNode.appendChild(q);n&&n.focus();var C=null;q.addEventListener("mouseleave",function(a){e.dialog_close_on_mouse_leave&&!q.is_modified&&e.dialog_close_on_mouse_leave&&(C=setTimeout(q.close,e.dialog_close_on_mouse_leave_delay))});q.addEventListener("mouseenter",function(a){e.dialog_close_on_mouse_leave&&C&&clearTimeout(C)})};h.prototype.prompt=function(a,b,d,g,f){var c=this;a=a||"";var k=document.createElement("div");k.is_modified=!1;k.className="graphdialog rounded";k.innerHTML=f?" ": -" ";k.close=function(){c.prompt_box=null;k.parentNode&&k.parentNode.removeChild(k)};f=h.active_canvas.canvas;f.parentNode.appendChild(k);1d-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}};h.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 d=this.viewport||this.dirty_area;d&&(a.save(),a.beginPath(),a.rect(d[0],d[1],d[2],d[3]),a.clip());this.clear_background&&(d?a.clearRect(d[0],d[1],d[2],d[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,d?d[0]:0,d?d[1]:0);if(this.graph){a.save();this.ds.toCanvasContext(a);b=this.computeVisibleNodes(null,this.visible_nodes);for(var g=0;g> ";b.fillText(g+d.getTitle(),.5*a.width,40);b.restore()}d=!1;this.onRenderBackground&&(d=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);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 m=this.editor_alpha;b.globalAlpha=m;this.render_shadows&&!f?(b.shadowColor=e.DEFAULT_SHADOW_COLOR,b.shadowOffsetX=2*this.ds.scale,b.shadowOffsetY=2*this.ds.scale,b.shadowBlur=3*this.ds.scale):b.shadowColor="transparent";if(!a.flags.collapsed||!a.onDrawCollapsed|| +1!=a.onDrawCollapsed(b,this)){var c=a._shape||e.BOX_SHAPE;E.set(a.size);var k=a.horizontal;if(a.flags.collapsed){b.font=this.inner_text_font;var n=a.getTitle?a.getTitle():a.title;null!=n&&(a._collapsed_width=Math.min(a.size[0],b.measureText(n).width+2*e.NODE_TITLE_HEIGHT),E[0]=a._collapsed_width,E[1]=0)}a.clip_area&&(b.save(),b.beginPath(),c==e.BOX_SHAPE?b.rect(0,0,E[0],E[1]):c==e.ROUND_SHAPE?b.roundRect(0,0,E[0],E[1],[10]):c==e.CIRCLE_SHAPE&&b.arc(.5*E[0],.5*E[1],.5*E[0],0,2*Math.PI),b.clip());a.has_errors&& +(g="red");this.drawNodeShape(a,b,E,d,g,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;g=!f;var x=this.connecting_output;c=this.connecting_input;b.lineWidth=1;n=0;var A=new Float32Array(2);if(!a.flags.collapsed){if(a.inputs)for(d=0;dthis.ds.scale,k=a._shape||a.constructor.shape|| +e.ROUND_SHAPE,x=a.constructor.title_mode,A=!0;x==e.TRANSPARENT_TITLE||x==e.NO_TITLE?A=!1:x==e.AUTOHIDE_TITLE&&c&&(A=!0);z[0]=0;z[1]=A?-f:0;z[2]=d[0]+1;z[3]=A?d[1]+f:d[1];c=b.globalAlpha;b.beginPath();k==e.BOX_SHAPE||u?b.fillRect(z[0],z[1],z[2],z[3]):k==e.ROUND_SHAPE||k==e.CARD_SHAPE?b.roundRect(z[0],z[1],z[2],z[3],k==e.CARD_SHAPE?[this.round_radius,this.round_radius,0,0]:[this.round_radius]):k==e.CIRCLE_SHAPE&&b.arc(.5*d[0],.5*d[1],.5*d[0],0,2*Math.PI);b.fill();!a.flags.collapsed&&A&&(b.shadowColor= +"transparent",b.fillStyle="rgba(0,0,0,0.2)",b.fillRect(0,-1,z[2],2));b.shadowColor="transparent";if(a.onDrawBackground)a.onDrawBackground(b,this,this.canvas,this.graph_mouse);if(A||x==e.TRANSPARENT_TITLE){if(a.onDrawTitleBar)a.onDrawTitleBar(b,f,d,this.ds.scale,g);else if(x!=e.TRANSPARENT_TITLE&&(a.constructor.title_color||this.render_title_colored)){A=a.constructor.title_color||g;a.flags.collapsed&&(b.shadowColor=e.DEFAULT_SHADOW_COLOR);if(this.use_gradients){var w=h.gradients[A];w||(w=h.gradients[A]= +b.createLinearGradient(0,0,400,0),w.addColorStop(0,A),w.addColorStop(1,"#000"));b.fillStyle=w}else b.fillStyle=A;b.beginPath();k==e.BOX_SHAPE||u?b.rect(0,-f,d[0]+1,f):(k==e.ROUND_SHAPE||k==e.CARD_SHAPE)&&b.roundRect(0,-f,d[0]+1,f,a.flags.collapsed?[this.round_radius]:[this.round_radius,this.round_radius,0,0]);b.fill();b.shadowColor="transparent"}A=!1;e.node_box_coloured_by_mode&&e.NODE_MODES_COLORS[a.mode]&&(A=e.NODE_MODES_COLORS[a.mode]);e.node_box_coloured_when_on&&(A=a.action_triggered?"#FFF": +a.execute_triggered?"#AAA":A);if(a.onDrawTitleBox)a.onDrawTitleBox(b,f,d,this.ds.scale);else k==e.ROUND_SHAPE||k==e.CIRCLE_SHAPE||k==e.CARD_SHAPE?(u&&(b.fillStyle="black",b.beginPath(),b.arc(.5*f,-.5*f,6,0,2*Math.PI),b.fill()),b.fillStyle=a.boxcolor||A||e.NODE_DEFAULT_BOXCOLOR,u?b.fillRect(.5*f-5,-.5*f-5,10,10):(b.beginPath(),b.arc(.5*f,-.5*f,5,0,2*Math.PI),b.fill())):(u&&(b.fillStyle="black",b.fillRect(.5*(f-10)-1,-.5*(f+10)-1,12,12)),b.fillStyle=a.boxcolor||A||e.NODE_DEFAULT_BOXCOLOR,b.fillRect(.5* +(f-10),-.5*(f+10),10,10));b.globalAlpha=c;if(a.onDrawTitleText)a.onDrawTitleText(b,f,d,this.ds.scale,this.title_text_font,m);!u&&(b.font=this.title_text_font,c=String(a.getTitle()))&&(b.fillStyle=m?e.NODE_SELECTED_TITLE_COLOR:a.constructor.title_text_color||this.node_title_color,a.flags.collapsed?(b.textAlign="left",b.measureText(c),b.fillText(c.substr(0,20),f,e.NODE_TITLE_TEXT_Y-f),b.textAlign="left"):(b.textAlign="left",b.fillText(c,f,e.NODE_TITLE_TEXT_Y-f)));a.flags.collapsed||!a.subgraph||a.skip_subgraph_button|| +(c=e.NODE_TITLE_HEIGHT,A=a.size[0]-c,w=e.isInsideRectangle(this.graph_mouse[0]-a.pos[0],this.graph_mouse[1]-a.pos[1],A+2,-c+2,c-4,c-4),b.fillStyle=w?"#888":"#555",k==e.BOX_SHAPE||u?b.fillRect(A+2,-c+2,c-4,c-4):(b.beginPath(),b.roundRect(A+2,-c+2,c-4,c-4,[4]),b.fill()),b.fillStyle="#333",b.beginPath(),b.moveTo(A+.2*c,.6*-c),b.lineTo(A+.8*c,.6*-c),b.lineTo(A+.5*c,.3*-c),b.fill());if(a.onDrawTitle)a.onDrawTitle(b)}if(m){if(a.onBounding)a.onBounding(z);x==e.TRANSPARENT_TITLE&&(z[1]-=f,z[3]+=f);b.lineWidth= +1;b.globalAlpha=.8;b.beginPath();k==e.BOX_SHAPE?b.rect(-6+z[0],-6+z[1],12+z[2],12+z[3]):k==e.ROUND_SHAPE||k==e.CARD_SHAPE&&a.flags.collapsed?b.roundRect(-6+z[0],-6+z[1],12+z[2],12+z[3],[2*this.round_radius]):k==e.CARD_SHAPE?b.roundRect(-6+z[0],-6+z[1],12+z[2],12+z[3],[2*this.round_radius,2,2*this.round_radius,2]):k==e.CIRCLE_SHAPE&&b.arc(.5*d[0],.5*d[1],.5*d[0]+6,0,2*Math.PI);b.strokeStyle=e.NODE_BOX_OUTLINE_COLOR;b.stroke();b.strokeStyle=g;b.globalAlpha=1}0k[2]&&(k[0]+=k[2],k[2]=Math.abs(k[2]));0>k[3]&&(k[1]+=k[3],k[3]=Math.abs(k[3]));if(I(k,M)){var L=D.outputs[x];x=m.inputs[c];if(L&&x&&(D=L.dir||(D.horizontal?e.DOWN:e.RIGHT),x=x.dir||(m.horizontal?e.UP:e.LEFT),this.renderLink(a, +A,w,h,!1,0,null,D,x),h&&h._last_time&&1E3>b-h._last_time)){L=2-.002*(b-h._last_time);var H=a.globalAlpha;a.globalAlpha=H*L;this.renderLink(a,A,w,h,!0,L,"white",D,x);a.globalAlpha=H}}}}}}a.globalAlpha=1};h.prototype.renderLink=function(a,b,d,g,f,m,c,k,n,x){g&&this.visible_links.push(g);!c&&g&&(c=g.color||h.link_type_colors[g.type]);c||(c=this.default_link_color);null!=g&&this.highlighted_links[g.id]&&(c="#FFF");k=k||e.RIGHT;n=n||e.LEFT;var u=F(b,d);this.render_connections_border&&.6b[1]?0:Math.PI,a.save(),a.translate(w[0],w[1]),a.rotate(u),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore(),a.save(),a.translate(g[0],g[1]),a.rotate(x),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore()),a.beginPath(),a.arc(f[0],f[1], +5,0,2*Math.PI),a.fill());if(m)for(a.fillStyle=c,w=0;5>w;++w)m=(.001*e.getTime()+.2*w)%1,f=this.computeConnectionPoint(b,d,m,k,n),a.beginPath(),a.arc(f[0],f[1],5,0,2*Math.PI),a.fill()};h.prototype.computeConnectionPoint=function(a,b,d,g,f){g=g||e.RIGHT;f=f||e.LEFT;var m=F(a,b),c=[a[0],a[1]],k=[b[0],b[1]];switch(g){case e.LEFT:c[0]+=-.25*m;break;case e.RIGHT:c[0]+=.25*m;break;case e.UP:c[1]+=-.25*m;break;case e.DOWN:c[1]+=.25*m}switch(f){case e.LEFT:k[0]+=-.25*m;break;case e.RIGHT:k[0]+=.25*m;break; +case e.UP:k[1]+=-.25*m;break;case e.DOWN:k[1]+=.25*m}g=(1-d)*(1-d)*(1-d);f=3*(1-d)*(1-d)*d;m=3*(1-d)*d*d;d*=d*d;return[g*a[0]+f*c[0]+m*k[0]+d*b[0],g*a[1]+f*c[1]+m*k[1]+d*b[1]]};h.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,d=0;dc||c>H-12||kw.last_y+L||void 0===w.last_y)){g=w.value;switch(w.type){case "button":d.type===e.pointerevents_method+"down"&&(w.callback&&setTimeout(function(){w.callback(w,n,a,b,d)},20),this.dirty_canvas=w.clicked=!0);break;case "slider":x=Math.clamp((c-15)/(H-30),0,1);w.value=w.options.min+(w.options.max-w.options.min)*x;w.callback&&setTimeout(function(){f(w,w.value)},20);this.dirty_canvas=!0;break;case "number":case "combo":g=w.value;if(d.type== +e.pointerevents_method+"move"&&"number"==w.type)d.deltaX&&(w.value+=.1*d.deltaX*(w.options.step||1)),null!=w.options.min&&w.valuew.options.max&&(w.value=w.options.max);else if(d.type==e.pointerevents_method+"down"){var y=w.options.values;y&&y.constructor===Function&&(y=w.options.values(w,a));var h=null;"number"!=w.type&&(h=y.constructor===Array?y:Object.keys(y));c=40>c?-1:c>H-40?1:0;if("number"==w.type)w.value+=.1*c*(w.options.step|| +1),null!=w.options.min&&w.valuew.options.max&&(w.value=w.options.max);else if(c)x=-1,this.last_mouseclick=0,x=y.constructor===Object?h.indexOf(String(w.value))+c:h.indexOf(w.value)+c,x>=h.length&&(x=h.length-1),0>x&&(x=0),w.value=y.constructor===Array?y[x]:x;else{var D=y!=h?Object.values(y):y;new e.ContextMenu(D,{scale:Math.max(1,this.ds.scale),event:d,className:"dark",callback:function(a,b,d){y!=h&&(a=D.indexOf(a));this.value=a; +f(this,a);n.dirty_canvas=!0;return!1}.bind(w)},x)}}else d.type==e.pointerevents_method+"up"&&"number"==w.type&&(c=40>c?-1:c>H-40?1:0,200>d.click_time&&0==c&&this.prompt("Value",w.value,function(a){this.value=Number(a);f(this,this.value)}.bind(w),d));g!=w.value&&setTimeout(function(){f(this,this.value)}.bind(w),20);this.dirty_canvas=!0;break;case "toggle":d.type==e.pointerevents_method+"down"&&(w.value=!w.value,setTimeout(function(){f(w,w.value)},20));break;case "string":case "text":d.type==e.pointerevents_method+ +"down"&&this.prompt("Value",w.value,function(a){this.value=a;f(this,a)}.bind(w),d,w.options?w.options.multiline:!1);break;default:w.mouse&&(this.dirty_canvas=w.mouse(d,[c,k],a))}if(g!=w.value){if(a.onWidgetChanged)a.onWidgetChanged(w.name,w.value,g,w);a.graph._version++}return w}}}return null};h.prototype.drawGroups=function(a,b){if(this.graph){a=this.graph._groups;b.save();b.globalAlpha=.5*this.editor_alpha;for(var d=0;dd&&.01>b.editor_alpha&&(clearInterval(g),1>d&&(b.live_mode=!0));1"+(q.label?q.label:n)+""+a+"",value:n})}if(k.length)return new e.ContextMenu(k,{event:d,callback:function(a,b,d,g){f&&(b=this.getBoundingClientRect(),c.showEditPropertyValue(f,a.value,{position:[b.left,b.top]}))},parentMenu:g,allow_html:!0, +node:f},b),!1}};h.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};h.onMenuResizeNode=function(a,b,d,g,f){if(f){a=function(a){a.size=a.computeSize();if(a.onResize)a.onResize(a.size)};b=h.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)a(f);else for(var e in b.selected_nodes)a(b.selected_nodes[e]);f.setDirtyCanvas(!0,!0)}};h.prototype.showLinkMenu=function(a,b){var d=this,g=d.graph.getNodeById(a.origin_id),f=d.graph.getNodeById(a.target_id), +c=!1;g&&g.outputs&&g.outputs[a.origin_slot]&&(c=g.outputs[a.origin_slot].type);var k=!1;f&&f.outputs&&f.outputs[a.target_slot]&&(k=f.inputs[a.target_slot].type);var n=new e.ContextMenu(["Add Node",null,"Delete",null],{event:b,title:null!=a.data?a.data.constructor.name:null,callback:function(b,e,m){switch(b){case "Add Node":h.onMenuAdd(null,null,m,n,function(b){b.inputs&&b.inputs.length&&b.outputs&&b.outputs.length&&g.connectByType(a.origin_slot,b,c)&&(b.connectByType(a.target_slot,f,k),b.pos[0]-= +.5*b.size[0])});break;case "Delete":d.graph.removeLink(a.id)}}});return!1};h.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,d=!b&&a.nodeTo&&null!==a.slotTo;if(!b&&!d)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 g=b?a.nodeFrom:a.nodeTo,f=b?a.slotFrom:a.slotTo;switch(typeof f){case "string":d=b?g.findOutputSlot(f,!1):g.findInputSlot(f,!1);f=b?g.outputs[f]:g.inputs[f];break;case "object":d=b?g.findOutputSlot(f.name):g.findInputSlot(f.name);break;case "number":d=f;f=b?g.outputs[f]:g.inputs[f];break;default:return console.warn("Cant get slot information "+f),!1}!1!==f&&!1!==d||console.warn("createDefaultNodeForSlot bad slotX "+f+" "+d);g=f.type==e.EVENT?"_event_":f.type;if((f=b?e.slot_types_default_out: +e.slot_types_default_in)&&f[g]){nodeNewType=!1;if("object"==typeof f[g]||"array"==typeof f[g])for(var c in f[g]){if(a.nodeType==f[g][c]||"AUTO"==a.nodeType){nodeNewType=f[g][c];break}}else if(a.nodeType==f[g]||"AUTO"==a.nodeType)nodeNewType=f[g];if(nodeNewType){c=!1;"object"==typeof nodeNewType&&nodeNewType.node&&(c=nodeNewType,nodeNewType=nodeNewType.node);if(f=e.createNode(nodeNewType)){if(c){if(c.properties)for(var k in c.properties)f.addProperty(k,c.properties[k]);if(c.inputs)for(k in f.inputs= +[],c.inputs)f.addOutput(c.inputs[k][0],c.inputs[k][1]);if(c.outputs)for(k in f.outputs=[],c.outputs)f.addOutput(c.outputs[k][0],c.outputs[k][1]);c.title&&(f.title=c.title);c.json&&f.configure(c.json)}this.graph.add(f);f.pos=[a.position[0]+a.posAdd[0]+(a.posSizeFix[0]?a.posSizeFix[0]*f.size[0]:0),a.position[1]+a.posAdd[1]+(a.posSizeFix[1]?a.posSizeFix[1]*f.size[1]:0)];b?a.nodeFrom.connectByType(d,f,g):a.nodeTo.connectByTypeOutput(d,f,g);return!0}console.log("failed creating "+nodeNewType)}}return!1}; +h.prototype.showConnectionMenu=function(a){a=a||{};var b=Object.assign({nodeFrom:null,slotFrom:null,nodeTo:null,slotTo:null,e:null},a),d=this,g=b.nodeFrom&&b.slotFrom;a=!g&&b.nodeTo&&b.slotTo;if(!g&&!a)return console.warn("No data passed to showConnectionMenu"),!1;a=g?b.nodeFrom:b.nodeTo;var f=g?b.slotFrom:b.slotTo,c=!1;switch(typeof f){case "string":c=g?a.findOutputSlot(f,!1):a.findInputSlot(f,!1);f=g?a.outputs[f]:a.inputs[f];break;case "object":c=g?a.findOutputSlot(f.name):a.findInputSlot(f.name); +break;case "number":c=f;f=g?a.outputs[f]:a.inputs[f];break;default:return console.warn("Cant get slot information "+f),!1}a=["Add Node",null];d.allow_searchbox&&(a.push("Search"),a.push(null));var k=f.type==e.EVENT?"_event_":f.type,n=g?e.slot_types_default_out:e.slot_types_default_in;if(n&&n[k])if("object"==typeof n[k]||"array"==typeof n[k])for(var q in n[k])a.push(n[k][q]);else a.push(n[k]);var x=new e.ContextMenu(a,{event:b.e,title:(f&&""!=f.name?f.name+(k?" | ":""):"")+(f&&k?k:""),callback:function(a, +e,m){switch(a){case "Add Node":h.onMenuAdd(null,null,m,x,function(a){g?b.nodeFrom.connectByType(c,a,k):b.nodeTo.connectByTypeOutput(c,a,k)});break;case "Search":g?d.showSearchBox(m,{node_from:b.nodeFrom,slot_from:f,type_filter_in:k}):d.showSearchBox(m,{node_to:b.nodeTo,slot_from:f,type_filter_out:k});break;default:d.createDefaultNodeForSlot(Object.assign(b,{position:[b.e.canvasX,b.e.canvasY],nodeType:a}))}}});return!1};h.onShowPropertyEditor=function(a,b,d,g,f){function c(){if(q){var b=q.value;"Number"== +a.type?b=Number(b):"Boolean"==a.type&&(b=!!b);f[k]=b;n.parentNode&&n.parentNode.removeChild(n);f.setDirtyCanvas(!0,!0)}}var k=a.property||"title";b=f[k];var n=document.createElement("div");n.is_modified=!1;n.className="graphdialog";n.innerHTML="";n.close=function(){n.parentNode&&n.parentNode.removeChild(n)};n.querySelector(".name").innerText=k;var q=n.querySelector(".value");q&&(q.value=b,q.addEventListener("blur", +function(a){this.focus()}),q.addEventListener("keydown",function(a){n.is_modified=!0;if(27==a.keyCode)n.close();else if(13==a.keyCode)c();else if(13!=a.keyCode&&"textarea"!=a.target.localName)return;a.preventDefault();a.stopPropagation()}));b=h.active_canvas.canvas;d=b.getBoundingClientRect();var x=g=-20;d&&(g-=d.left,x-=d.top);event?(n.style.left=event.clientX+g+"px",n.style.top=event.clientY+x+"px"):(n.style.left=.5*b.width+g+"px",n.style.top=.5*b.height+x+"px");n.querySelector("button").addEventListener("click", +c);b.parentNode.appendChild(n);q&&q.focus();var A=null;n.addEventListener("mouseleave",function(a){e.dialog_close_on_mouse_leave&&!n.is_modified&&e.dialog_close_on_mouse_leave&&(A=setTimeout(n.close,e.dialog_close_on_mouse_leave_delay))});n.addEventListener("mouseenter",function(a){e.dialog_close_on_mouse_leave&&A&&clearTimeout(A)})};h.prototype.prompt=function(a,b,d,g,f){var c=this;a=a||"";var k=document.createElement("div");k.is_modified=!1;k.className="graphdialog rounded";k.innerHTML=f?" ": +" ";k.close=function(){c.prompt_box=null;k.parentNode&&k.parentNode.removeChild(k)};f=h.active_canvas.canvas;f.parentNode.appendChild(k);1h.search_limit))break}}u=null;if(Array.prototype.filter)u=Object.keys(e.registered_node_types).filter(g);else for(m in u=[],e.registered_node_types)g(m)&&u.push(m);for(m=0;mh.search_limit);m++);if(b.show_general_after_typefiltered&&(G.value||n.value)){filtered_extra=[];for(m in e.registered_node_types)g(m,{inTypeOverride:G&&G.value?"*": -!1,outTypeOverride:n&&n.value?"*":!1})&&filtered_extra.push(m);for(m=0;mh.search_limit);m++);}if((G.value||n.value)&&0==y.childNodes.length&&b.show_general_if_none_on_typefilter){filtered_extra=[];for(m in e.registered_node_types)g(m,{skipFilter:!0})&&filtered_extra.push(m);for(m=0;mh.search_limit);m++);}}}def_options={slot_from:null, -node_from:null,node_to:null,do_type_filter:e.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:e.search_hide_on_mouse_leave,show_all_if_empty:!0,show_all_on_open:e.search_show_all_on_open};b=Object.assign(def_options,b||{});var c=this,k=h.active_canvas,q=k.canvas,n=q.ownerDocument||document,x=document.createElement("div");x.className="litegraph litesearchbox graphdialog rounded";x.innerHTML="Search "; -b.do_type_filter&&(x.innerHTML+="",x.innerHTML+="");x.innerHTML+="
";n.fullscreenElement?n.fullscreenElement.appendChild(x):(n.body.appendChild(x),n.body.style.overflow="hidden");if(b.do_type_filter)var C=x.querySelector(".slot_in_type_filter"),D=x.querySelector(".slot_out_type_filter");x.close=function(){c.search_box=null;this.blur(); -q.focus();n.body.style.overflow="";setTimeout(function(){c.canvas.focus()},20);x.parentNode&&x.parentNode.removeChild(x)};1C.height-200&&(y.style.maxHeight=C.height-a.layerY-20+"px");H.focus();b.show_all_on_open&&f();return x};h.prototype.showEditPropertyValue=function(a,b,d){function g(){f(D.value)}function f(f){e&&e.values&&e.values.constructor===Object&&void 0!=e.values[f]&&(f=e.values[f]);"number"==typeof a.properties[b]&&(f=Number(f));if("array"==c||"object"==c)f=JSON.parse(f);a.properties[b]=f;a.graph&&a.graph._version++;if(a.onPropertyChanged)a.onPropertyChanged(b,f);if(d.onclose)d.onclose(); -n.close();a.setDirtyCanvas(!0,!0)}if(a&&void 0!==a.properties[b]){d=d||{};var e=a.getPropertyInfo(b),c=e.type,k="";if("string"==c||"number"==c||"array"==c||"object"==c)k="";else if("enum"!=c&&"combo"!=c||!e.values)if("boolean"==c||"toggle"==c)k="";else{console.warn("unknown type: "+c);return}else{k=""}var n=this.createDialog(""+(e.label?e.label:b)+""+k+"",d),D=!1;if("enum"!=c&&"combo"!=c||!e.values)if("boolean"==c||"toggle"==c)(D=n.querySelector("input"))&&D.addEventListener("click",function(a){n.modified();f(!!D.checked)});else{if(D=n.querySelector("input"))D.addEventListener("blur",function(a){this.focus()}), -x=void 0!==a.properties[b]?a.properties[b]:"","string"!==c&&(x=JSON.stringify(x)),D.value=x,D.addEventListener("keydown",function(a){if(27==a.keyCode)n.close();else if(13==a.keyCode)g();else if(13!=a.keyCode){n.modified();return}a.preventDefault();a.stopPropagation()})}else D=n.querySelector("select"),D.addEventListener("change",function(a){n.modified();f(a.target.value)});D&&D.focus();n.querySelector("button").addEventListener("click",g);return n}};h.prototype.createDialog=function(a,b){def_options= +b.node_to.findInputSlot(b.slot_from);break;case "object":f=b.slot_from.name?b.node_to.findInputSlot(b.slot_from.name):-1;-1==f&&"undefined"!==typeof b.slot_from.slot_index&&(f=b.slot_from.slot_index);break;case "number":f=b.slot_from;break;default:f=0}!1!==f&&-1h.search_limit))break}}u=null;if(Array.prototype.filter)u=Object.keys(e.registered_node_types).filter(g);else for(m in u=[],e.registered_node_types)g(m)&&u.push(m);for(m=0;mh.search_limit);m++);if(b.show_general_after_typefiltered&&(q.value||H.value)){filtered_extra=[];for(m in e.registered_node_types)g(m,{inTypeOverride:q&&q.value?"*": +!1,outTypeOverride:H&&H.value?"*":!1})&&filtered_extra.push(m);for(m=0;mh.search_limit);m++);}if((q.value||H.value)&&0==y.childNodes.length&&b.show_general_if_none_on_typefilter){filtered_extra=[];for(m in e.registered_node_types)g(m,{skipFilter:!0})&&filtered_extra.push(m);for(m=0;mh.search_limit);m++);}}}def_options={slot_from:null, +node_from:null,node_to:null,do_type_filter:e.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:e.search_hide_on_mouse_leave,show_all_if_empty:!0,show_all_on_open:e.search_show_all_on_open};b=Object.assign(def_options,b||{});var c=this,k=h.active_canvas,n=k.canvas,q=n.ownerDocument||document,x=document.createElement("div");x.className="litegraph litesearchbox graphdialog rounded";x.innerHTML="Search "; +b.do_type_filter&&(x.innerHTML+="",x.innerHTML+="");x.innerHTML+="
";q.fullscreenElement?q.fullscreenElement.appendChild(x):(q.body.appendChild(x),q.body.style.overflow="hidden");if(b.do_type_filter)var A=x.querySelector(".slot_in_type_filter"),w=x.querySelector(".slot_out_type_filter");x.close=function(){c.search_box=null;this.blur(); +n.focus();q.body.style.overflow="";setTimeout(function(){c.canvas.focus()},20);x.parentNode&&x.parentNode.removeChild(x)};1A.height-200&&(y.style.maxHeight=A.height-a.layerY-20+"px");r.focus();b.show_all_on_open&&f();return x};h.prototype.showEditPropertyValue=function(a,b,d){function g(){f(h.value)}function f(f){c&&c.values&&c.values.constructor===Object&&void 0!=c.values[f]&&(f=c.values[f]);"number"==typeof a.properties[b]&&(f=Number(f));if("array"==e||"object"==e)f=JSON.parse(f);a.properties[b]=f;a.graph&&a.graph._version++;if(a.onPropertyChanged)a.onPropertyChanged(b,f);if(d.onclose)d.onclose(); +q.close();a.setDirtyCanvas(!0,!0)}if(a&&void 0!==a.properties[b]){d=d||{};var c=a.getPropertyInfo(b),e=c.type,k="";if("string"==e||"number"==e||"array"==e||"object"==e)k="";else if("enum"!=e&&"combo"!=e||!c.values)if("boolean"==e||"toggle"==e)k="";else{console.warn("unknown type: "+e);return}else{k=""}var q=this.createDialog(""+(c.label?c.label:b)+""+k+"",d),h=!1;if("enum"!=e&&"combo"!=e||!c.values)if("boolean"==e||"toggle"==e)(h=q.querySelector("input"))&&h.addEventListener("click",function(a){q.modified();f(!!h.checked)});else{if(h=q.querySelector("input"))h.addEventListener("blur",function(a){this.focus()}), +x=void 0!==a.properties[b]?a.properties[b]:"","string"!==e&&(x=JSON.stringify(x)),h.value=x,h.addEventListener("keydown",function(a){if(27==a.keyCode)q.close();else if(13==a.keyCode)g();else if(13!=a.keyCode){q.modified();return}a.preventDefault();a.stopPropagation()})}else h=q.querySelector("select"),h.addEventListener("change",function(a){q.modified();f(a.target.value)});h&&h.focus();q.querySelector("button").addEventListener("click",g);return q}};h.prototype.createDialog=function(a,b){def_options= {checkForInput:!1,closeOnLeave:!0,closeOnLeave_checkModified:!0};b=Object.assign(def_options,b||{});var d=document.createElement("div");d.className="graphdialog";d.innerHTML=a;d.is_modified=!1;a=this.canvas.getBoundingClientRect();var g=-20,f=-20;a&&(g-=a.left,f-=a.top);b.position?(g+=b.position[0],f+=b.position[1]):b.event?(g+=b.event.clientX,f+=b.event.clientY):(g+=.5*this.canvas.width,f+=.5*this.canvas.height);d.style.left=g+"px";d.style.top=f+"px";this.canvas.parentNode.appendChild(d);b.checkForInput&& (a=[],(a=d.querySelectorAll("input"))&&a.forEach(function(a){a.addEventListener("keydown",function(a){d.modified();if(27==a.keyCode)d.close();else if(13!=a.keyCode)return;a.preventDefault();a.stopPropagation()});a.focus()}));d.modified=function(){d.is_modified=!0};d.close=function(){d.parentNode&&d.parentNode.removeChild(d)};var c=null,k=!1;d.addEventListener("mouseleave",function(a){k||(b.closeOnLeave||e.dialog_close_on_mouse_leave)&&!d.is_modified&&e.dialog_close_on_mouse_leave&&(c=setTimeout(d.close, e.dialog_close_on_mouse_leave_delay))});d.addEventListener("mouseenter",function(a){(b.closeOnLeave||e.dialog_close_on_mouse_leave)&&c&&clearTimeout(c)});(a=d.querySelectorAll("select"))&&a.forEach(function(a){a.addEventListener("click",function(a){k++});a.addEventListener("blur",function(a){k=0});a.addEventListener("change",function(a){k=-1})});return d};h.prototype.createPanel=function(a,b){b=b||{};var d=b.window||window,g=document.createElement("div");g.className="litegraph dialog";g.innerHTML= "
";g.header=g.querySelector(".dialog-header");b.width&&(g.style.width=b.width+(b.width.constructor===Number?"px":""));b.height&&(g.style.height=b.height+(b.height.constructor===Number?"px":""));b.closable&&(b=document.createElement("span"),b.innerHTML="✕",b.classList.add("close"),b.addEventListener("click", -function(){g.close()}),g.header.appendChild(b));g.title_element=g.querySelector(".dialog-title");g.title_element.innerText=a;g.content=g.querySelector(".dialog-content");g.alt_content=g.querySelector(".dialog-alt-content");g.footer=g.querySelector(".dialog-footer");g.close=function(){if(g.onClose&&"function"==typeof g.onClose)g.onClose();g.parentNode.removeChild(g);this.parentNode&&this.parentNode.removeChild(this)};g.toggleAltContent=function(a){if("undefined"!=typeof a){var b=a?"block":"none";a= -a?"none":"block"}else b="block"!=g.alt_content.style.display?"block":"none",a="block"!=g.alt_content.style.display?"none":"block";g.alt_content.style.display=b;g.content.style.display=a};g.toggleFooterVisibility=function(a){g.footer.style.display="undefined"!=typeof a?a?"block":"none":"block"!=g.footer.style.display?"block":"none"};g.clear=function(){this.content.innerHTML=""};g.addHTML=function(a,b,d){var f=document.createElement("div");b&&(f.className=b);f.innerHTML=a;d?g.footer.appendChild(f): -g.content.appendChild(f);return f};g.addButton=function(a,b,d){var f=document.createElement("button");f.innerText=a;f.options=d;f.classList.add("btn");f.addEventListener("click",b);g.footer.appendChild(f);return f};g.addSeparator=function(){var a=document.createElement("div");a.className="separator";g.content.appendChild(a)};g.addWidget=function(a,b,c,k,q){function f(a,b){k.callback&&k.callback(a,b,k);q&&q(a,b,k)}k=k||{};var m=String(c);a=a.toLowerCase();"number"==a&&(m=c.toFixed(3));var n=document.createElement("div"); -n.className="property";n.innerHTML="";n.querySelector(".property_name").innerText=k.label||b;var u=n.querySelector(".property_value");u.innerText=m;n.dataset.property=b;n.dataset.type=k.type||a;n.options=k;n.value=c;if("code"==a)n.addEventListener("click",function(a){g.inner_showCodePad(this.dataset.property)});else if("boolean"==a)n.classList.add("boolean"),c&&n.classList.add("bool-on"),n.addEventListener("click",function(){var a= +function(){g.close()}),g.header.appendChild(b));g.title_element=g.querySelector(".dialog-title");g.title_element.innerText=a;g.content=g.querySelector(".dialog-content");g.alt_content=g.querySelector(".dialog-alt-content");g.footer=g.querySelector(".dialog-footer");g.close=function(){if(g.onClose&&"function"==typeof g.onClose)g.onClose();g.parentNode&&g.parentNode.removeChild(g);this.parentNode&&this.parentNode.removeChild(this)};g.toggleAltContent=function(a){if("undefined"!=typeof a){var b=a?"block": +"none";a=a?"none":"block"}else b="block"!=g.alt_content.style.display?"block":"none",a="block"!=g.alt_content.style.display?"none":"block";g.alt_content.style.display=b;g.content.style.display=a};g.toggleFooterVisibility=function(a){g.footer.style.display="undefined"!=typeof a?a?"block":"none":"block"!=g.footer.style.display?"block":"none"};g.clear=function(){this.content.innerHTML=""};g.addHTML=function(a,b,d){var f=document.createElement("div");b&&(f.className=b);f.innerHTML=a;d?g.footer.appendChild(f): +g.content.appendChild(f);return f};g.addButton=function(a,b,d){var f=document.createElement("button");f.innerText=a;f.options=d;f.classList.add("btn");f.addEventListener("click",b);g.footer.appendChild(f);return f};g.addSeparator=function(){var a=document.createElement("div");a.className="separator";g.content.appendChild(a)};g.addWidget=function(a,b,c,k,n){function f(a,b){k.callback&&k.callback(a,b,k);n&&n(a,b,k)}k=k||{};var m=String(c);a=a.toLowerCase();"number"==a&&(m=c.toFixed(3));var q=document.createElement("div"); +q.className="property";q.innerHTML="";q.querySelector(".property_name").innerText=k.label||b;var u=q.querySelector(".property_value");u.innerText=m;q.dataset.property=b;q.dataset.type=k.type||a;q.options=k;q.value=c;if("code"==a)q.addEventListener("click",function(a){g.inner_showCodePad(this.dataset.property)});else if("boolean"==a)q.classList.add("boolean"),c&&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";f(a,this.value)});else if("string"==a||"number"==a)u.setAttribute("contenteditable",!0),u.addEventListener("keydown",function(b){"Enter"!=b.code||"string"==a&&b.shiftKey||(b.preventDefault(),this.blur())}),u.addEventListener("blur",function(){var a=this.innerText,b=this.parentNode.dataset.property;"number"==this.parentNode.dataset.type&&(a=Number(a)); -f(b,a)});else if("enum"==a||"combo"==a)m=h.getPropertyPrintableValue(c,k.values),u.innerText=m,u.addEventListener("click",function(a){var b=this.parentNode.dataset.property,g=this;new e.ContextMenu(k.values||[],{event:a,className:"dark",callback:function(a,d,e){g.innerText=a;f(b,a);return!1}},d)});g.content.appendChild(n);return n};if(g.onOpen&&"function"==typeof g.onOpen)g.onOpen();return g};h.getPropertyPrintableValue=function(a,b){if(!b||b.constructor===Array)return String(a);if(b.constructor=== +f(b,a)});else if("enum"==a||"combo"==a)m=h.getPropertyPrintableValue(c,k.values),u.innerText=m,u.addEventListener("click",function(a){var b=this.parentNode.dataset.property,g=this;new e.ContextMenu(k.values||[],{event:a,className:"dark",callback:function(a,d,c){g.innerText=a;f(b,a);return!1}},d)});g.content.appendChild(q);return q};if(g.onOpen&&"function"==typeof g.onOpen)g.onOpen();return g};h.getPropertyPrintableValue=function(a,b){if(!b||b.constructor===Array)return String(a);if(b.constructor=== Object){var d="",g;for(g in b)if(b[g]==a){d=g;break}return String(a)+" ("+d+")"}};h.prototype.closePanels=function(){var a=document.querySelector("#node-panel");a&&a.close();(a=document.querySelector("#option-panel"))&&a.close()};h.prototype.showShowGraphOptionsPanel=function(a,b,d,g){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 f=b.event.target.lgraphcanvas}else f=this;f.closePanels(); a=f.getCanvasWindow();panel=f.createPanel("Options",{closable:!0,window:a,onOpen:function(){f.OPTIONPANEL_IS_OPEN=!0},onClose:function(){f.OPTIONPANEL_IS_OPEN=!1;f.options_panel=null}});f.options_panel=panel;panel.id="option-panel";panel.classList.add("settings");(function(){panel.content.innerHTML="";var a=function(a,b,d){d&&d.key&&(a=d.key);d.values&&(b=Object.values(d.values).indexOf(b));f[a]=b},b=e.availableCanvasOptions;b.sort();for(pI in b){var d=b[pI];panel.addWidget("boolean",d,f[d],{key:d, on:"True",off:"False"},a)}panel.addWidget("combo","Render mode",e.LINK_RENDER_MODES[f.links_render_mode],{key:"links_render_mode",values:e.LINK_RENDER_MODES},a);panel.addSeparator();panel.footer.innerHTML=""})();f.canvas.parentNode.appendChild(panel)};h.prototype.showShowNodePanel=function(a){function b(){panel.content.innerHTML="";panel.addHTML(""+a.type+""+(a.constructor.desc||"")+"");panel.addHTML("

Properties

"); @@ -306,55 +306,55 @@ var b=function(b,d){g.graph.beforeChange(a);switch(b){case "Title":a.title=d;bre e.NODE_MODES[a.mode],{values:e.NODE_MODES},b);var d="";void 0!==a.color&&(d=Object.keys(h.node_colors).filter(function(b){return h.node_colors[b].color==a.color}));panel.addWidget("combo","Color",d,{values:Object.keys(h.node_colors)},b);for(var c in a.properties){d=a.properties[c];var k=a.getPropertyInfo(c);a.onAddPropertyToPanel&&a.onAddPropertyToPanel(c,panel)||panel.addWidget(k.widget||k.type,c,d,k,b)}panel.addSeparator();if(a.onShowCustomPanelInfo)a.onShowCustomPanelInfo(panel);panel.footer.innerHTML= "";panel.addButton("Delete",function(){a.block_delete||(a.graph.remove(a),panel.close())}).classList.add("delete")}this.SELECTED_NODE=a;this.closePanels();var d=this.getCanvasWindow(),g=this;panel=this.createPanel(a.title||"",{closable:!0,window:d,onOpen:function(){g.NODEPANEL_IS_OPEN=!0},onClose:function(){g.NODEPANEL_IS_OPEN=!1;g.node_panel=null}});g.node_panel=panel;panel.id="node-panel";panel.node=a;panel.classList.add("settings");panel.inner_showCodePad=function(d){panel.classList.remove("settings"); panel.classList.add("centered");panel.alt_content.innerHTML="";var f=panel.alt_content.querySelector("textarea"),g=function(){panel.toggleAltContent(!1);panel.toggleFooterVisibility(!0);f.parentNode.removeChild(f);panel.classList.add("settings");panel.classList.remove("centered");b()};f.value=a.properties[d];f.addEventListener("keydown",function(b){"Enter"==b.code&&b.ctrlKey&&(a.setProperty(d,f.value),g())});panel.toggleAltContent(!0);panel.toggleFooterVisibility(!1); -f.style.height="calc(100% - 40px)";var e=panel.addButton("Assign",function(){a.setProperty(d,f.value);g()});panel.alt_content.appendChild(e);e=panel.addButton("Close",g);e.style.float="right";panel.alt_content.appendChild(e)};b();this.canvas.parentNode.appendChild(panel)};h.prototype.showSubgraphPropertiesDialog=function(a){function b(){g.clear();if(a.inputs)for(var d=0;d", -"subgraph_property");c.dataset.name=e.name;c.dataset.slot=d;c.querySelector(".name").innerText=e.name;c.querySelector(".type").innerText=e.type;c.querySelector("button").addEventListener("click",function(d){a.removeInput(Number(this.parentNode.dataset.slot));b()})}}}console.log("showing subgraph properties dialog");var d=this.canvas.parentNode.querySelector(".subgraph_dialog");d&&d.close();var g=this.createPanel("Subgraph Inputs",{closable:!0,width:500});g.node=a;g.classList.add("subgraph_dialog"); +f.style.height="calc(100% - 40px)";var c=panel.addButton("Assign",function(){a.setProperty(d,f.value);g()});panel.alt_content.appendChild(c);c=panel.addButton("Close",g);c.style.float="right";panel.alt_content.appendChild(c)};b();this.canvas.parentNode.appendChild(panel)};h.prototype.showSubgraphPropertiesDialog=function(a){function b(){g.clear();if(a.inputs)for(var d=0;d", +"subgraph_property");e.dataset.name=c.name;e.dataset.slot=d;e.querySelector(".name").innerText=c.name;e.querySelector(".type").innerText=c.type;e.querySelector("button").addEventListener("click",function(d){a.removeInput(Number(this.parentNode.dataset.slot));b()})}}}console.log("showing subgraph properties dialog");var d=this.canvas.parentNode.querySelector(".subgraph_dialog");d&&d.close();var g=this.createPanel("Subgraph Inputs",{closable:!0,width:500});g.node=a;g.classList.add("subgraph_dialog"); g.addHTML(" + NameType","subgraph_property extra",!0).querySelector("button").addEventListener("click",function(d){d=this.parentNode;var f=d.querySelector(".name").value,g=d.querySelector(".type").value;f&&-1==a.findInputSlot(f)&&(a.addInput(f,g),d.querySelector(".name").value="",d.querySelector(".type").value="",b())});b();this.canvas.parentNode.appendChild(g);return g};h.prototype.showSubgraphPropertiesDialogRight= -function(a){function b(){f.clear();if(a.outputs)for(var d=0;d","subgraph_property");e.dataset.name=g.name;e.dataset.slot=d;e.querySelector(".name").innerText=g.name;e.querySelector(".type").innerText=g.type;e.querySelector("button").addEventListener("click",function(d){a.removeOutput(Number(this.parentNode.dataset.slot)); +function(a){function b(){f.clear();if(a.outputs)for(var d=0;d","subgraph_property");c.dataset.name=g.name;c.dataset.slot=d;c.querySelector(".name").innerText=g.name;c.querySelector(".type").innerText=g.type;c.querySelector("button").addEventListener("click",function(d){a.removeOutput(Number(this.parentNode.dataset.slot)); b()})}}}function d(){var d=this.parentNode,f=d.querySelector(".name").value,g=d.querySelector(".type").value;f&&-1==a.findOutputSlot(f)&&(a.addOutput(f,g),d.querySelector(".name").value="",d.querySelector(".type").value="",b())}var g=this.canvas.parentNode.querySelector(".subgraph_dialog");g&&g.close();var f=this.createPanel("Subgraph Outputs",{closable:!0,width:500});f.node=a;f.classList.add("subgraph_dialog");g=f.addHTML(" + NameType", "subgraph_property extra",!0);g.querySelector(".name").addEventListener("keydown",function(a){13==a.keyCode&&d.apply(this)});g.querySelector("button").addEventListener("click",function(a){d.apply(this)});b();this.canvas.parentNode.appendChild(f);return f};h.prototype.checkPanels=function(){if(this.canvas)for(var a=this.canvas.parentNode.querySelectorAll(".litegraph.dialog"),b=0;b=Object.keys(a.selected_nodes).length)f.collapse();else for(var e in a.selected_nodes)a.selected_nodes[e].collapse();f.graph.afterChange()};h.onMenuNodePin=function(a,b,d,g,f){f.pin()};h.onMenuNodeMode=function(a,b,d,g,f){new e.ContextMenu(e.NODE_MODES,{event:d,callback:function(a){if(f){var b=Object.values(e.NODE_MODES).indexOf(a),d=function(d){0<=b&&e.NODE_MODES[b]?d.changeMode(b):(console.warn("unexpected mode: "+a),d.changeMode(e.ALWAYS))}, +g,f){f.graph.beforeChange();a=h.active_canvas;if(!a.selected_nodes||1>=Object.keys(a.selected_nodes).length)f.collapse();else for(var c in a.selected_nodes)a.selected_nodes[c].collapse();f.graph.afterChange()};h.onMenuNodePin=function(a,b,d,g,f){f.pin()};h.onMenuNodeMode=function(a,b,d,g,f){new e.ContextMenu(e.NODE_MODES,{event:d,callback:function(a){if(f){var b=Object.values(e.NODE_MODES).indexOf(a),d=function(d){0<=b&&e.NODE_MODES[b]?d.changeMode(b):(console.warn("unexpected mode: "+a),d.changeMode(e.ALWAYS))}, g=h.active_canvas;if(!g.selected_nodes||1>=Object.keys(g.selected_nodes).length)d(f);else for(var c in g.selected_nodes)d(g.selected_nodes[c])}},parentMenu:g,node:f});return!1};h.onMenuNodeColors=function(a,b,d,g,f){if(!f)throw"no node for color";b=[];b.push({value:null,content:"No color"});for(var c in h.node_colors)a=h.node_colors[c],a={value:c,content:""+c+""},b.push(a);new e.ContextMenu(b,{event:d,callback:function(a){if(f){var b=a.value?h.node_colors[a.value]:null;a=function(a){b?a.constructor===e.LGraphGroup?a.color=b.groupcolor:(a.color=b.color,a.bgcolor=b.bgcolor):(delete a.color,delete a.bgcolor)};var d=h.active_canvas;if(!d.selected_nodes||1>=Object.keys(d.selected_nodes).length)a(f);else for(var g in d.selected_nodes)a(d.selected_nodes[g]);f.setDirtyCanvas(!0,!0)}},parentMenu:g,node:f});return!1}; h.onMenuNodeShapes=function(a,b,d,g,f){if(!f)throw"no node passed";new e.ContextMenu(e.VALID_SHAPES,{event:d,callback:function(a){if(f){f.graph.beforeChange();var b=h.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)f.shape=a;else for(var d in b.selected_nodes)b.selected_nodes[d].shape=a;f.graph.afterChange();f.setDirtyCanvas(!0)}},parentMenu:g,node:f});return!1};h.onMenuNodeRemove=function(a,b,d,g,f){if(!f)throw"no node passed";a=f.graph;a.beforeChange();b=h.active_canvas; -if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)!1!==f.removable&&a.remove(f);else for(var e in b.selected_nodes)d=b.selected_nodes[e],!1!==d.removable&&a.remove(d);a.afterChange();f.setDirtyCanvas(!0,!0)};h.onMenuNodeToSubgraph=function(a,b,d,g,f){a=f.graph;if(b=h.active_canvas)d=Object.values(b.selected_nodes||{}),d.length||(d=[f]),g=e.createNode("graph/subgraph"),g.pos=f.pos.concat(),a.add(g),g.buildFromNodes(d),b.deselectAllNodes(),f.setDirtyCanvas(!0,!0)};h.onMenuNodeClone=function(a, -b,d,g,f){f.graph.beforeChange();var e={};a=function(a){if(0!=a.clonable){var b=a.clone();b&&(b.pos=[a.pos[0]+5,a.pos[1]+5],a.graph.add(b),e[b.id]=b)}};b=h.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)a(f);else for(var c in b.selected_nodes)a(b.selected_nodes[c]);Object.keys(e).length&&b.selectNodes(e);f.graph.afterChange();f.setDirtyCanvas(!0,!0)};h.node_colors={red:{color:"#322",bgcolor:"#533",groupcolor:"#A88"},brown:{color:"#332922",bgcolor:"#593930",groupcolor:"#b06634"}, +if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)!1!==f.removable&&a.remove(f);else for(var c in b.selected_nodes)d=b.selected_nodes[c],!1!==d.removable&&a.remove(d);a.afterChange();f.setDirtyCanvas(!0,!0)};h.onMenuNodeToSubgraph=function(a,b,d,g,f){a=f.graph;if(b=h.active_canvas)d=Object.values(b.selected_nodes||{}),d.length||(d=[f]),g=e.createNode("graph/subgraph"),g.pos=f.pos.concat(),a.add(g),g.buildFromNodes(d),b.deselectAllNodes(),f.setDirtyCanvas(!0,!0)};h.onMenuNodeClone=function(a, +b,d,g,f){f.graph.beforeChange();var c={};a=function(a){if(0!=a.clonable){var b=a.clone();b&&(b.pos=[a.pos[0]+5,a.pos[1]+5],a.graph.add(b),c[b.id]=b)}};b=h.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)a(f);else for(var e in b.selected_nodes)a(b.selected_nodes[e]);Object.keys(c).length&&b.selectNodes(c);f.graph.afterChange();f.setDirtyCanvas(!0,!0)};h.node_colors={red:{color:"#322",bgcolor:"#533",groupcolor:"#A88"},brown:{color:"#332922",bgcolor:"#593930",groupcolor:"#b06634"}, green:{color:"#232",bgcolor:"#353",groupcolor:"#8A8"},blue:{color:"#223",bgcolor:"#335",groupcolor:"#88A"},pale_blue:{color:"#2a363b",bgcolor:"#3f5159",groupcolor:"#3f789e"},cyan:{color:"#233",bgcolor:"#355",groupcolor:"#8AA"},purple:{color:"#323",bgcolor:"#535",groupcolor:"#a1309b"},yellow:{color:"#432",bgcolor:"#653",groupcolor:"#b58b2a"},black:{color:"#222",bgcolor:"#000",groupcolor:"#444"}};h.prototype.getCanvasMenuOptions=function(){if(this.getMenuOptions)var a=this.getMenuOptions();else a=[{content:"Add Node", has_submenu:!0,callback:h.onMenuAdd},{content:"Add Group",callback:h.onGroupAdd}],this._graph_stack&&0Name",f),k=c.querySelector("input");k&&e&&(k.value=e.label|| -"");var m=function(){a.graph.beforeChange();k.value&&(e&&(e.label=k.value),d.setDirty(!0));c.close();a.graph.afterChange()};c.querySelector("button").addEventListener("click",m);k.addEventListener("keydown",function(a){c.is_modified=!0;if(27==a.keyCode)c.close();else if(13==a.keyCode)m();else if(13!=a.keyCode&&"textarea"!=a.target.localName)return;a.preventDefault();a.stopPropagation()});k.focus()}},extra:a};a&&(c.title=a.type);var k=null;a&&(k=a.getSlotInPosition(b.canvasX,b.canvasY),h.active_node= +b.input?a.removeInput(b.slot):b.output&&a.removeOutput(b.slot),a.graph.afterChange();else if("Disconnect Links"==b.content)b=b.slot,a.graph.beforeChange(),b.output?a.disconnectOutput(b.slot):b.input&&a.disconnectInput(b.slot),a.graph.afterChange();else if("Rename Slot"==b.content){b=b.slot;var c=b.input?a.getInputInfo(b.slot):a.getOutputInfo(b.slot),e=d.createDialog("Name",f),k=e.querySelector("input");k&&c&&(k.value=c.label|| +"");var m=function(){a.graph.beforeChange();k.value&&(c&&(c.label=k.value),d.setDirty(!0));e.close();a.graph.afterChange()};e.querySelector("button").addEventListener("click",m);k.addEventListener("keydown",function(a){e.is_modified=!0;if(27==a.keyCode)e.close();else if(13==a.keyCode)m();else if(13!=a.keyCode&&"textarea"!=a.target.localName)return;a.preventDefault();a.stopPropagation()});k.focus()}},extra:a};a&&(c.title=a.type);var k=null;a&&(k=a.getSlotInPosition(b.canvasX,b.canvasY),h.active_node= a);k?(f=[],a.getSlotMenuOptions?f=a.getSlotMenuOptions(k):(k&&k.output&&k.output.links&&k.output.links.length&&f.push({content:"Disconnect Links",slot:k}),b=k.input||k.output,b.removable&&f.push(b.locked?"Cannot remove":{content:"Remove Slot",slot:k}),b.nameLocked||f.push({content:"Rename Slot",slot:k})),c.title=(k.input?k.input.type:k.output.type)||"*",k.input&&k.input.type==e.ACTION&&(c.title="Action"),k.output&&k.output.type==e.EVENT&&(c.title="Event")):a?f=this.getNodeMenuOptions(a):(f=this.getCanvasMenuOptions(), -(k=this.graph.getGroupOnPos(b.canvasX,b.canvasY))&&f.push(null,{content:"Edit Group",has_submenu:!0,submenu:{title:"Group",extra:k,options:this.getGroupMenuOptions(k)}}));f&&new e.ContextMenu(f,c,g)};"undefined"!=typeof window&&window.CanvasRenderingContext2D&&!window.CanvasRenderingContext2D.prototype.roundRect&&(window.CanvasRenderingContext2D.prototype.roundRect=function(a,b,d,g,f,e){var c,k;if(0===f)this.rect(a,b,d,g);else{void 0===e&&(e=f);if(null!=f&&f.constructor===Array)if(1==f.length)var m= -c=k=e=f[0];else if(2==f.length)m=e=f[0],c=k=f[1];else if(4==f.length)m=f[0],c=f[1],k=f[2],e=f[3];else return;else m=f||0,c=f||0,k=e||0,e=e||0;this.moveTo(a+m,b);this.lineTo(a+d-c,b);this.quadraticCurveTo(a+d,b,a+d,b+c);this.lineTo(a+d,b+g-e);this.quadraticCurveTo(a+d,b+g,a+d-e,b+g);this.lineTo(a+e,b+g);this.quadraticCurveTo(a,b+g,a,b+g-k);this.lineTo(a,b+k);this.quadraticCurveTo(a,b,a+m,b)}});e.compareObjects=function(a,b){for(var d in a)if(a[d]!=b[d])return!1;return!0};e.distance=E;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=A;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=I;e.hex2num=function(a){"#"==a.charAt(0)&&(a=a.slice(1));a=a.toUpperCase();for(var b=Array(3), -d=0,g,f,e=0;6>e;e+=2)g="0123456789ABCDEF".indexOf(a.charAt(e)),f="0123456789ABCDEF".indexOf(a.charAt(e+1)),b[d]=16*g+f,d++;return b};e.num2hex=function(a){for(var b="#",d,g,f=0;3>f;f++)d=a[f]/16,g=a[f]%16,b+="0123456789ABCDEF".charAt(d)+"0123456789ABCDEF".charAt(g);return b};J.prototype.addItem=function(a,b,d){function g(a){var b=this.value;b&&b.has_submenu&&f.call(this,a)}function f(a){var b=this.value,f=!0;c.current_submenu&&c.current_submenu.close(a);if(d.callback){var g=d.callback.call(this,b, +(k=this.graph.getGroupOnPos(b.canvasX,b.canvasY))&&f.push(null,{content:"Edit Group",has_submenu:!0,submenu:{title:"Group",extra:k,options:this.getGroupMenuOptions(k)}}));f&&new e.ContextMenu(f,c,g)};"undefined"!=typeof window&&window.CanvasRenderingContext2D&&!window.CanvasRenderingContext2D.prototype.roundRect&&(window.CanvasRenderingContext2D.prototype.roundRect=function(a,b,d,g,f,c){var e,k;if(0===f)this.rect(a,b,d,g);else{void 0===c&&(c=f);if(null!=f&&f.constructor===Array)if(1==f.length)var m= +e=k=c=f[0];else if(2==f.length)m=c=f[0],e=k=f[1];else if(4==f.length)m=f[0],e=f[1],k=f[2],c=f[3];else return;else m=f||0,e=f||0,k=c||0,c=c||0;this.moveTo(a+m,b);this.lineTo(a+d-e,b);this.quadraticCurveTo(a+d,b,a+d,b+e);this.lineTo(a+d,b+g-c);this.quadraticCurveTo(a+d,b+g,a+d-c,b+g);this.lineTo(a+c,b+g);this.quadraticCurveTo(a,b+g,a,b+g-k);this.lineTo(a,b+k);this.quadraticCurveTo(a,b,a+m,b)}});e.compareObjects=function(a,b){for(var d in a)if(a[d]!=b[d])return!1;return!0};e.distance=F;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=C;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=I;e.hex2num=function(a){"#"==a.charAt(0)&&(a=a.slice(1));a=a.toUpperCase();for(var b=Array(3), +d=0,g,f,c=0;6>c;c+=2)g="0123456789ABCDEF".indexOf(a.charAt(c)),f="0123456789ABCDEF".indexOf(a.charAt(c+1)),b[d]=16*g+f,d++;return b};e.num2hex=function(a){for(var b="#",d,g,f=0;3>f;f++)d=a[f]/16,g=a[f]%16,b+="0123456789ABCDEF".charAt(d)+"0123456789ABCDEF".charAt(g);return b};J.prototype.addItem=function(a,b,d){function g(a){var b=this.value;b&&b.has_submenu&&f.call(this,a)}function f(a){var b=this.value,f=!0;c.current_submenu&&c.current_submenu.close(a);if(d.callback){var g=d.callback.call(this,b, d,a,c,d.node);!0===g&&(f=!1)}if(b&&(b.callback&&!d.ignore_item_callbacks&&!0!==b.disabled&&(g=b.callback.call(this,b,d,a,c,d.extra),!0===g&&(f=!1)),b.submenu)){if(!b.submenu.options)throw"ContextMenu submenu needs options";new c.constructor(b.submenu.options,{callback:b.submenu.callback,event:a,parentMenu:c,ignore_item_callbacks:b.submenu.ignore_item_callbacks,title:b.submenu.title,extra:b.submenu.extra,autoopen:d.autoopen});f=!1}f&&!c.lock&&c.close()}var c=this;d=d||{};var k=document.createElement("div"); -k.className="litemenu-entry submenu";var q=!1;if(null===b)k.classList.add("separator");else{k.innerHTML=b&&b.title?b.title:a;if(k.value=b)b.disabled&&(q=!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);q||k.addEventListener("click",f);d.autoopen&&e.pointerListenerAdd(k,"enter",g);return k};J.prototype.close=function(a, +k.className="litemenu-entry submenu";var n=!1;if(null===b)k.classList.add("separator");else{k.innerHTML=b&&b.title?b.title:a;if(k.value=b)b.disabled&&(n=!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);n||k.addEventListener("click",f);d.autoopen&&e.pointerListenerAdd(k,"enter",g);return k};J.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&&!J.isCursorOverElement(a,this.parentMenu.root)&&J.trigger(this.parentMenu.root,e.pointerevents_method+"leave",a));this.current_submenu&&this.current_submenu.close(a,!0);this.root.closing_timer&&clearTimeout(this.root.closing_timer)};J.trigger=function(a,b,d,g){var f=document.createEvent("CustomEvent");f.initCustomEvent(b, !0,!0,d);f.srcElement=g;a.dispatchEvent?a.dispatchEvent(f):a.__events&&a.__events.dispatchEvent(f);return f};J.prototype.getTopMenu=function(){return this.options.parentMenu?this.options.parentMenu.getTopMenu():this};J.prototype.getFirstEvent=function(){return this.options.parentMenu?this.options.parentMenu.getFirstEvent():this.options.event};J.isCursorOverElement=function(a,b){var d=a.clientX;a=a.clientY;return(b=b.getBoundingClientRect())?a>b.top&&ab.left&&dMath.abs(b))return g[1];a=(a-g[0])/b;return g[1]*(1-a)+f[1]*a}}return 0}};F.prototype.draw=function(a,b,d,g,f,e){if(d=this.points){this.size=b;var c=b[0]-2*this.margin;b=b[1]-2*this.margin;f=f||"#666";a.save();a.translate(this.margin, -this.margin);g&&(a.fillStyle="#111",a.fillRect(0,0,c,b),a.fillStyle="#222",a.fillRect(.5*c,0,1,b),a.strokeStyle="#333",a.strokeRect(0,0,c,b));a.strokeStyle=f;e&&(a.globalAlpha=.5);a.beginPath();for(g=0;ga[1])){var g=this.size[0]-2*this.margin,f=this.size[1]-2*this.margin,e=a[0]-this.margin;a=a[1]-this.margin;this.selected=this.getCloserPoint([e,a],30/b.ds.scale);-1==this.selected&&(b=[e/g,1-a/f],d.push(b),d.sort(function(a,b){return a[0]-b[0]}),this.selected=d.indexOf(b),this.must_update=!0);if(-1!=this.selected)return!0}};F.prototype.onMouseMove=function(a,b){var d=this.points;if(d){var g=this.selected;if(!(0>g)){var f=(a[0]-this.margin)/(this.size[0]-2*this.margin),e=(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=d[g]){var c=0==g||g==d.length-1;!c&&(-10>a[0]||a[0]>this.size[0]+10||-10>a[1]||a[1]>this.size[1]+10)?(d.splice(g,1),this.selected=-1):(b[0]=c?0==g?0:1:Math.clamp(f,0,1),b[1]=1-Math.clamp(e,0,1),d.sort(function(a,b){return a[0]-b[0]}),this.selected=d.indexOf(b),this.must_update=!0)}}}};F.prototype.onMouseUp=function(a,b){this.selected=-1;return!1};F.prototype.getCloserPoint= -function(a,b){var d=this.points;if(!d)return-1;b=b||30;for(var g=this.size[0]-2*this.margin,f=this.size[1]-2*this.margin,e=d.length,c=[0,0],k=1E6,q=-1,x=0;xk||n>b||(q=x,k=n)}return q};e.CurveEditor=F;e.getParameterNames=function(a){return(a+"").replace(/[/][/].*$/gm,"").replace(/\s+/g,"").replace(/[/][*][^/*]*[*][/]/g,"").split("){",1)[0].replace(/^[^(]*[(]/,"").replace(/=[^,]+/g,"").split(",").filter(Boolean)};e.pointerListenerAdd= +b.prototype.__lookupGetter__(d)):a.prototype[d]=b.prototype[d],b.prototype.__lookupSetter__(d)&&a.prototype.__defineSetter__(d,b.prototype.__lookupSetter__(d)))};G.sampleCurve=function(a,b){if(b){for(var d=0;dMath.abs(b))return g[1];a=(a-g[0])/b;return g[1]*(1-a)+f[1]*a}}return 0}};G.prototype.draw=function(a,b,d,g,f,c){if(d=this.points){this.size=b;var e=b[0]-2*this.margin;b=b[1]-2*this.margin;f=f||"#666";a.save();a.translate(this.margin, +this.margin);g&&(a.fillStyle="#111",a.fillRect(0,0,e,b),a.fillStyle="#222",a.fillRect(.5*e,0,1,b),a.strokeStyle="#333",a.strokeRect(0,0,e,b));a.strokeStyle=f;c&&(a.globalAlpha=.5);a.beginPath();for(g=0;ga[1])){var g=this.size[0]-2*this.margin,f=this.size[1]-2*this.margin,c=a[0]-this.margin;a=a[1]-this.margin;this.selected=this.getCloserPoint([c,a],30/b.ds.scale);-1==this.selected&&(b=[c/g,1-a/f],d.push(b),d.sort(function(a,b){return a[0]-b[0]}),this.selected=d.indexOf(b),this.must_update=!0);if(-1!=this.selected)return!0}};G.prototype.onMouseMove=function(a,b){var d=this.points;if(d){var g=this.selected;if(!(0>g)){var f=(a[0]-this.margin)/(this.size[0]-2*this.margin),c=(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=d[g]){var e=0==g||g==d.length-1;!e&&(-10>a[0]||a[0]>this.size[0]+10||-10>a[1]||a[1]>this.size[1]+10)?(d.splice(g,1),this.selected=-1):(b[0]=e?0==g?0:1:Math.clamp(f,0,1),b[1]=1-Math.clamp(c,0,1),d.sort(function(a,b){return a[0]-b[0]}),this.selected=d.indexOf(b),this.must_update=!0)}}}};G.prototype.onMouseUp=function(a,b){this.selected=-1;return!1};G.prototype.getCloserPoint= +function(a,b){var d=this.points;if(!d)return-1;b=b||30;for(var g=this.size[0]-2*this.margin,f=this.size[1]-2*this.margin,c=d.length,e=[0,0],k=1E6,n=-1,x=0;xk||q>b||(n=x,k=q)}return n};e.CurveEditor=G;e.getParameterNames=function(a){return(a+"").replace(/[/][/].*$/gm,"").replace(/\s+/g,"").replace(/[/][*][^/*]*[*][/]/g,"").split("){",1)[0].replace(/^[^(]*[(]/,"").replace(/=[^,]+/g,"").split(",").filter(Boolean)};e.pointerListenerAdd= function(a,b,d,g){g=void 0===g?!1:g;if(a&&a.addEventListener&&b&&"function"===typeof d){var f=e.pointerevents_method;if("pointer"==f&&!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":f="touch";b="start";break;case "move":f="touch";break;case "up":f="touch";b="end";break;case "cancel":f="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(f+b,d,g);case "leave":case "cancel":case "gotpointercapture":case "lostpointercapture":if("mouse"!=f)return a.addEventListener(f+b,d,g);default:return a.addEventListener(b,d,g)}}};e.pointerListenerRemove=function(a,b,d,g){g=void 0===g?!1:g;if(a&&a.removeEventListener&&b&&"function"===typeof d)switch(b){case "down":case "up":case "move":case "over":case "out":case "enter":"pointer"!= e.pointerevents_method&&"mouse"!=e.pointerevents_method||a.removeEventListener(e.pointerevents_method+b,d,g);case "leave":case "cancel":case "gotpointercapture":case "lostpointercapture":if("pointer"==e.pointerevents_method)return a.removeEventListener(e.pointerevents_method+b,d,g);default:return a.removeEventListener(b,d,g)}};Math.clamp=function(a,b,d){return b>a?b:d=c?this.trigger(null,e,h):this._pending.push([c,e])};A.prototype.onExecute=function(c,e){c=1E3*this.graph.elapsed_time;this.isInputConnected(1)&&(this.properties.time_in_ms=this.getInputData(1));for(var h=0;h=c?this.trigger(null,e,h):this._pending.push([c,e])};C.prototype.onExecute= +function(c,e){c=1E3*this.graph.elapsed_time;this.isInputConnected(1)&&(this.properties.time_in_ms=this.getInputData(1));for(var h=0;hh[1]))return this.old_y=c.canvasY,this.captureInput(!0),this.mouse_captured=!0};r.prototype.onMouseMove=function(c){if(this.mouse_captured){var e=this.old_y-c.canvasY;c.shiftKey&&(e*=10);if(c.metaKey||c.altKey)e*=.1;this.old_y=c.canvasY;c=this._remainder+e/r.pixels_threshold;this._remainder=c%1;c=Math.clamp(this.properties.value+ -(c|0)*this.properties.step,this.properties.min,this.properties.max);this.properties.value=c;this.graph._version++;this.setDirtyCanvas(!0)}};r.prototype.onMouseUp=function(c,h){200>c.click_time&&(this.properties.value=Math.clamp(this.properties.value+(h[1]>.5*this.size[1]?-1:1)*this.properties.step,this.properties.min,this.properties.max),this.graph._version++,this.setDirtyCanvas(!0));this.mouse_captured&&(this.mouse_captured=!1,this.captureInput(!1))};F.registerNodeType("widget/number",r);t.title= -"Combo";t.desc="Widget to select from a list";t.prototype.onExecute=function(){this.setOutputData(0,this.properties.value)};t.prototype.onPropertyChanged=function(c,h){"values"==c?(this._values=h.split(";"),this.widget.options.values=this._values):"value"==c&&(this.widget.value=h)};F.registerNodeType("widget/combo",t);v.title="Knob";v.desc="Circular controller";v.size=[80,100];v.prototype.onDrawForeground=function(c){if(!this.flags.collapsed){-1==this.value&&(this.value=(this.properties.value-this.properties.min)/ +(c|0)*this.properties.step,this.properties.min,this.properties.max);this.properties.value=c;this.graph._version++;this.setDirtyCanvas(!0)}};r.prototype.onMouseUp=function(c,h){200>c.click_time&&(this.properties.value=Math.clamp(this.properties.value+(h[1]>.5*this.size[1]?-1:1)*this.properties.step,this.properties.min,this.properties.max),this.graph._version++,this.setDirtyCanvas(!0));this.mouse_captured&&(this.mouse_captured=!1,this.captureInput(!1))};G.registerNodeType("widget/number",r);t.title= +"Combo";t.desc="Widget to select from a list";t.prototype.onExecute=function(){this.setOutputData(0,this.properties.value)};t.prototype.onPropertyChanged=function(c,h){"values"==c?(this._values=h.split(";"),this.widget.options.values=this._values):"value"==c&&(this.widget.value=h)};G.registerNodeType("widget/combo",t);v.title="Knob";v.desc="Circular controller";v.size=[80,100];v.prototype.onDrawForeground=function(c){if(!this.flags.collapsed){-1==this.value&&(this.value=(this.properties.value-this.properties.min)/ (this.properties.max-this.properties.min));var e=.5*this.size[0],h=.5*this.size[1],l=.5*Math.min(this.size[0],this.size[1])-5;c.globalAlpha=1;c.save();c.translate(e,h);c.rotate(.75*Math.PI);c.fillStyle="rgba(0,0,0,0.5)";c.beginPath();c.moveTo(0,0);c.arc(0,0,l,0,1.5*Math.PI);c.fill();c.strokeStyle="black";c.fillStyle=this.properties.color;c.lineWidth=2;c.beginPath();c.moveTo(0,0);c.arc(0,0,l-4,0,1.5*Math.PI*Math.max(.01,this.value));c.closePath();c.fill();c.lineWidth=1;c.globalAlpha=1;c.restore(); c.fillStyle="black";c.beginPath();c.arc(e,h,.75*l,0,2*Math.PI,!0);c.fill();c.fillStyle=this.mouseOver?"white":this.properties.color;c.beginPath();var r=this.value*Math.PI*1.5+.75*Math.PI;c.arc(e+Math.cos(r)*l*.65,h+Math.sin(r)*l*.65,.05*l,0,2*Math.PI,!0);c.fill();c.fillStyle=this.mouseOver?"white":"#AAA";c.font=Math.floor(.5*l)+"px Arial";c.textAlign="center";c.fillText(this.properties.value.toFixed(this.properties.precision),e,h+.15*l)}};v.prototype.onExecute=function(){this.setOutputData(0,this.properties.value); -this.boxcolor=F.colorToString([this.value,this.value,this.value])};v.prototype.onMouseDown=function(c){this.center=[.5*this.size[0],.5*this.size[1]+20];this.radius=.5*this.size[0];if(20>c.canvasY-this.pos[1]||F.distance([c.canvasX,c.canvasY],[this.pos[0]+this.center[0],this.pos[1]+this.center[1]])>this.radius)return!1;this.oldmouse=[c.canvasX-this.pos[0],c.canvasY-this.pos[1]];this.captureInput(!0);return!0};v.prototype.onMouseMove=function(c){if(this.oldmouse){c=[c.canvasX-this.pos[0],c.canvasY- -this.pos[1]];var e=this.value;e-=.01*(c[1]-this.oldmouse[1]);1e&&(e=0);this.value=e;this.properties.value=this.properties.min+(this.properties.max-this.properties.min)*this.value;this.oldmouse=c;this.setDirtyCanvas(!0)}};v.prototype.onMouseUp=function(c){this.oldmouse&&(this.oldmouse=null,this.captureInput(!1))};v.prototype.onPropertyChanged=function(c,h){if("min"==c||"max"==c||"value"==c)return this.properties[c]=parseFloat(h),!0};F.registerNodeType("widget/knob",v);h.title="Inner Slider"; -h.prototype.onPropertyChanged=function(c,h){"value"==c&&(this.slider.value=h)};h.prototype.onExecute=function(){this.setOutputData(0,this.properties.value)};F.registerNodeType("widget/internal_slider",h);E.title="H.Slider";E.desc="Linear slider controller";E.prototype.onDrawForeground=function(c){-1==this.value&&(this.value=(this.properties.value-this.properties.min)/(this.properties.max-this.properties.min));c.globalAlpha=1;c.lineWidth=1;c.fillStyle="#000";c.fillRect(2,2,this.size[0]-4,this.size[1]- -4);c.fillStyle=this.properties.color;c.beginPath();c.rect(4,4,(this.size[0]-8)*this.value,this.size[1]-8);c.fill()};E.prototype.onExecute=function(){this.properties.value=this.properties.min+(this.properties.max-this.properties.min)*this.value;this.setOutputData(0,this.properties.value);this.boxcolor=F.colorToString([this.value,this.value,this.value])};E.prototype.onMouseDown=function(c){if(0>c.canvasY-this.pos[1])return!1;this.oldmouse=[c.canvasX-this.pos[0],c.canvasY-this.pos[1]];this.captureInput(!0); -return!0};E.prototype.onMouseMove=function(c){if(this.oldmouse){c=[c.canvasX-this.pos[0],c.canvasY-this.pos[1]];var e=this.value;e+=(c[0]-this.oldmouse[0])/this.size[0];1e&&(e=0);this.value=e;this.oldmouse=c;this.setDirtyCanvas(!0)}};E.prototype.onMouseUp=function(c){this.oldmouse=null;this.captureInput(!1)};E.prototype.onMouseLeave=function(c){};F.registerNodeType("widget/hslider",E);A.title="Progress";A.desc="Shows data in linear progress";A.prototype.onExecute=function(){var c=this.getInputData(0); -void 0!=c&&(this.properties.value=c)};A.prototype.onDrawForeground=function(c){c.lineWidth=1;c.fillStyle=this.properties.color;var e=(this.properties.value-this.properties.min)/(this.properties.max-this.properties.min);e=Math.min(1,e);e=Math.max(0,e);c.fillRect(2,2,(this.size[0]-4)*e,this.size[1]-4)};F.registerNodeType("widget/progress",A);I.title="Text";I.desc="Shows the input value";I.widgets=[{name:"resize",text:"Resize box",type:"button"},{name:"led_text",text:"LED",type:"minibutton"},{name:"normal_text", +this.boxcolor=G.colorToString([this.value,this.value,this.value])};v.prototype.onMouseDown=function(c){this.center=[.5*this.size[0],.5*this.size[1]+20];this.radius=.5*this.size[0];if(20>c.canvasY-this.pos[1]||G.distance([c.canvasX,c.canvasY],[this.pos[0]+this.center[0],this.pos[1]+this.center[1]])>this.radius)return!1;this.oldmouse=[c.canvasX-this.pos[0],c.canvasY-this.pos[1]];this.captureInput(!0);return!0};v.prototype.onMouseMove=function(c){if(this.oldmouse){c=[c.canvasX-this.pos[0],c.canvasY- +this.pos[1]];var e=this.value;e-=.01*(c[1]-this.oldmouse[1]);1e&&(e=0);this.value=e;this.properties.value=this.properties.min+(this.properties.max-this.properties.min)*this.value;this.oldmouse=c;this.setDirtyCanvas(!0)}};v.prototype.onMouseUp=function(c){this.oldmouse&&(this.oldmouse=null,this.captureInput(!1))};v.prototype.onPropertyChanged=function(c,h){if("min"==c||"max"==c||"value"==c)return this.properties[c]=parseFloat(h),!0};G.registerNodeType("widget/knob",v);h.title="Inner Slider"; +h.prototype.onPropertyChanged=function(c,h){"value"==c&&(this.slider.value=h)};h.prototype.onExecute=function(){this.setOutputData(0,this.properties.value)};G.registerNodeType("widget/internal_slider",h);F.title="H.Slider";F.desc="Linear slider controller";F.prototype.onDrawForeground=function(c){-1==this.value&&(this.value=(this.properties.value-this.properties.min)/(this.properties.max-this.properties.min));c.globalAlpha=1;c.lineWidth=1;c.fillStyle="#000";c.fillRect(2,2,this.size[0]-4,this.size[1]- +4);c.fillStyle=this.properties.color;c.beginPath();c.rect(4,4,(this.size[0]-8)*this.value,this.size[1]-8);c.fill()};F.prototype.onExecute=function(){this.properties.value=this.properties.min+(this.properties.max-this.properties.min)*this.value;this.setOutputData(0,this.properties.value);this.boxcolor=G.colorToString([this.value,this.value,this.value])};F.prototype.onMouseDown=function(c){if(0>c.canvasY-this.pos[1])return!1;this.oldmouse=[c.canvasX-this.pos[0],c.canvasY-this.pos[1]];this.captureInput(!0); +return!0};F.prototype.onMouseMove=function(c){if(this.oldmouse){c=[c.canvasX-this.pos[0],c.canvasY-this.pos[1]];var e=this.value;e+=(c[0]-this.oldmouse[0])/this.size[0];1e&&(e=0);this.value=e;this.oldmouse=c;this.setDirtyCanvas(!0)}};F.prototype.onMouseUp=function(c){this.oldmouse=null;this.captureInput(!1)};F.prototype.onMouseLeave=function(c){};G.registerNodeType("widget/hslider",F);C.title="Progress";C.desc="Shows data in linear progress";C.prototype.onExecute=function(){var c=this.getInputData(0); +void 0!=c&&(this.properties.value=c)};C.prototype.onDrawForeground=function(c){c.lineWidth=1;c.fillStyle=this.properties.color;var e=(this.properties.value-this.properties.min)/(this.properties.max-this.properties.min);e=Math.min(1,e);e=Math.max(0,e);c.fillRect(2,2,(this.size[0]-4)*e,this.size[1]-4)};G.registerNodeType("widget/progress",C);I.title="Text";I.desc="Shows the input value";I.widgets=[{name:"resize",text:"Resize box",type:"button"},{name:"led_text",text:"LED",type:"minibutton"},{name:"normal_text", text:"Normal",type:"minibutton"}];I.prototype.onDrawForeground=function(c){c.fillStyle=this.properties.color;var e=this.properties.value;this.properties.glowSize?(c.shadowColor=this.properties.color,c.shadowOffsetX=0,c.shadowOffsetY=0,c.shadowBlur=this.properties.glowSize):c.shadowColor="transparent";var h=this.properties.fontsize;c.textAlign=this.properties.align;c.font=h.toString()+"px "+this.properties.font;this.str="number"==typeof e?e.toFixed(this.properties.decimals):e;if("string"==typeof this.str){e= this.str.replace(/[\r\n]/g,"\\n").split("\\n");for(var l=0;lt?l.xbox.axes.lx:0,this._left_axis[1]=Math.abs(l.xbox.axes.ly)>t?l.xbox.axes.ly:0,this._right_axis[0]=Math.abs(l.xbox.axes.rx)>t?l.xbox.axes.rx:0,this._right_axis[1]=Math.abs(l.xbox.axes.ry)>t?l.xbox.axes.ry:0,this._triggers[0]=Math.abs(l.xbox.axes.ltrigger)>t?l.xbox.axes.ltrigger: 0,this._triggers[1]=Math.abs(l.xbox.axes.rtrigger)>t?l.xbox.axes.rtrigger:0);if(this.outputs)for(t=0;t","enum",{values:a.values});this.addWidget("combo", "Cond.",this.properties.OP,{property:"OP",values:a.values});this.size=[80,60]}function b(){this.addInput("in",0);this.addInput("cond","boolean");this.addOutput("true",0);this.addOutput("false",0);this.size=[80,60]}function d(){this.addInput("inc","number");this.addOutput("total","number");this.addProperty("increment",1);this.addProperty("value",0)}function g(){this.addInput("v","number");this.addOutput("sin","number");this.addProperty("amplitude",1);this.addProperty("offset",0);this.bgImageUrl="nodes/imgs/icon-sin.png"} function f(){this.addInput("x","number");this.addInput("y","number");this.addOutput("","number");this.properties={x:1,y:1,formula:"x+y"};this.code_widget=this.addWidget("text","F(x,y)",this.properties.formula,function(a,b,d){d.properties.formula=a});this.addWidget("toggle","allow",w.allow_scripts,function(a){w.allow_scripts=a});this._func=null}function m(){this.addInput("vec2","vec2");this.addOutput("x","number");this.addOutput("y","number")}function u(){this.addInputs([["x","number"],["y","number"]]); this.addOutput("vec2","vec2");this.properties={x:0,y:0};this._data=new Float32Array(2)}function O(){this.addInput("vec3","vec3");this.addOutput("x","number");this.addOutput("y","number");this.addOutput("z","number")}function K(){this.addInputs([["x","number"],["y","number"],["z","number"]]);this.addOutput("vec3","vec3");this.properties={x:0,y:0,z:0};this._data=new Float32Array(3)}function x(){this.addInput("vec4","vec4");this.addOutput("x","number");this.addOutput("y","number");this.addOutput("z", -"number");this.addOutput("w","number")}function C(){this.addInputs([["x","number"],["y","number"],["z","number"],["w","number"]]);this.addOutput("vec4","vec4");this.properties={x:0,y:0,z:0,w:0};this._data=new Float32Array(4)}var w=B.LiteGraph;c.title="Converter";c.desc="type A to type B";c.prototype.onExecute=function(){var a=this.getInputData(0);if(null!=a&&this.outputs)for(var b=0;ba&&(a+=1024);var c=Math.floor(a);a-=c;d=h.data[c];c=h.data[1023==c?0:c+1];b&&(a=a*a*a*(a*(6*a-15)+10));return d*(1-a)+c*a};h.prototype.onExecute=function(){var a= -this.getInputData(0)||0,b=this.properties.octaves||1,d=0,c=1;a+=this.properties.seed||0;for(var f=this.properties.speed||1,g=0,e=0;ec);++e);a=this.properties.min;this._last_v=d/g*(this.properties.max-a)+a;this.setOutputData(0,this._last_v)};h.prototype.onDrawBackground=function(a){this.outputs[0].label=(this._last_v||0).toFixed(3)};w.registerNodeType("math/noise",h);E.title="Spikes";E.desc="spike every random time"; -E.prototype.onExecute=function(){var a=this.graph.elapsed_time;this._remaining_time-=a;this._blink_time-=a;a=0;0this._remaining_time?(this._remaining_time=Math.random()*(this.properties.max_time-this.properties.min_time)+this.properties.min_time,this._blink_time=this.properties.duration,this.boxcolor="#FFF"):this.boxcolor="#000";this.setOutputData(0,a)};w.registerNodeType("math/spikes",E);A.title="Clamp";A.desc= -"Clamp number between min and max";A.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&(a=Math.max(this.properties.min,a),a=Math.min(this.properties.max,a),this.setOutputData(0,a))};A.prototype.getCode=function(a){a="";this.isInputConnected(0)&&(a+="clamp({{0}},"+this.properties.min+","+this.properties.max+")");return a};w.registerNodeType("math/clamp",A);I.title="Lerp";I.desc="Linear Interpolation";I.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=0);var b= -this.getInputData(1);null==b&&(b=0);var d=this.properties.f,c=this.getInputData(2);void 0!==c&&(d=c);this.setOutputData(0,a*(1-d)+b*d)};I.prototype.onGetInputs=function(){return[["f","number"]]};w.registerNodeType("math/lerp",I);J.title="Abs";J.desc="Absolute";J.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,Math.abs(a))};w.registerNodeType("math/abs",J);F.title="Floor";F.desc="Floor number to remove fractional part";F.prototype.onExecute=function(){var a= -this.getInputData(0);null!=a&&this.setOutputData(0,Math.floor(a))};w.registerNodeType("math/floor",F);e.title="Frac";e.desc="Returns fractional part";e.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,a%1)};w.registerNodeType("math/frac",e);D.title="Smoothstep";D.desc="Smoothstep";D.prototype.onExecute=function(){var a=this.getInputData(0);if(void 0!==a){var b=this.properties.A;a=Math.clamp((a-b)/(this.properties.B-b),0,1);this.setOutputData(0,a*a*(3-2*a))}}; -w.registerNodeType("math/smoothstep",D);H.title="Scale";H.desc="v * factor";H.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,a*this.properties.factor)};w.registerNodeType("math/scale",H);z.title="Gate";z.desc="if v is true, then outputs A, otherwise B";z.prototype.onExecute=function(){var a=this.getInputData(0);this.setOutputData(0,this.getInputData(a?1:2))};w.registerNodeType("math/gate",z);M.title="Average";M.desc="Average Filter";M.prototype.onExecute=function(){var a= +this.getInputData(0)||0,b=this.properties.octaves||1,d=0,c=1;a+=this.properties.seed||0;for(var f=this.properties.speed||1,g=0,e=0;ec);++e);a=this.properties.min;this._last_v=d/g*(this.properties.max-a)+a;this.setOutputData(0,this._last_v)};h.prototype.onDrawBackground=function(a){this.outputs[0].label=(this._last_v||0).toFixed(3)};w.registerNodeType("math/noise",h);F.title="Spikes";F.desc="spike every random time"; +F.prototype.onExecute=function(){var a=this.graph.elapsed_time;this._remaining_time-=a;this._blink_time-=a;a=0;0this._remaining_time?(this._remaining_time=Math.random()*(this.properties.max_time-this.properties.min_time)+this.properties.min_time,this._blink_time=this.properties.duration,this.boxcolor="#FFF"):this.boxcolor="#000";this.setOutputData(0,a)};w.registerNodeType("math/spikes",F);C.title="Clamp";C.desc= +"Clamp number between min and max";C.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&(a=Math.max(this.properties.min,a),a=Math.min(this.properties.max,a),this.setOutputData(0,a))};C.prototype.getCode=function(a){a="";this.isInputConnected(0)&&(a+="clamp({{0}},"+this.properties.min+","+this.properties.max+")");return a};w.registerNodeType("math/clamp",C);I.title="Lerp";I.desc="Linear Interpolation";I.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=0);var b= +this.getInputData(1);null==b&&(b=0);var d=this.properties.f,c=this.getInputData(2);void 0!==c&&(d=c);this.setOutputData(0,a*(1-d)+b*d)};I.prototype.onGetInputs=function(){return[["f","number"]]};w.registerNodeType("math/lerp",I);J.title="Abs";J.desc="Absolute";J.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,Math.abs(a))};w.registerNodeType("math/abs",J);G.title="Floor";G.desc="Floor number to remove fractional part";G.prototype.onExecute=function(){var a= +this.getInputData(0);null!=a&&this.setOutputData(0,Math.floor(a))};w.registerNodeType("math/floor",G);e.title="Frac";e.desc="Returns fractional part";e.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,a%1)};w.registerNodeType("math/frac",e);D.title="Smoothstep";D.desc="Smoothstep";D.prototype.onExecute=function(){var a=this.getInputData(0);if(void 0!==a){var b=this.properties.A;a=Math.clamp((a-b)/(this.properties.B-b),0,1);this.setOutputData(0,a*a*(3-2*a))}}; +w.registerNodeType("math/smoothstep",D);E.title="Scale";E.desc="v * factor";E.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,a*this.properties.factor)};w.registerNodeType("math/scale",E);z.title="Gate";z.desc="if v is true, then outputs A, otherwise B";z.prototype.onExecute=function(){var a=this.getInputData(0);this.setOutputData(0,this.getInputData(a?1:2))};w.registerNodeType("math/gate",z);M.title="Average";M.desc="Average Filter";M.prototype.onExecute=function(){var a= this.getInputData(0);null==a&&(a=0);var b=this._values.length;this._values[this._current%b]=a;this._current+=1;this._current>b&&(this._current=0);for(var d=a=0;db&&(b=1);this.properties.samples=Math.round(b);a=this._values;this._values=new Float32Array(this.properties.samples);a.length<=this._values.length?this._values.set(a):this._values.set(a.subarray(0,this._values.length))};w.registerNodeType("math/average", M);k.title="TendTo";k.desc="moves the output value always closer to the input";k.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=0);var b=this.properties.factor;this._value=null==this._value?a:this._value*(1-b)+a*b;this.setOutputData(0,this._value)};w.registerNodeType("math/tendTo",k);n.values="+ - * / % ^ max min".split(" ");n.title="Operation";n.desc="Easy math operators";n["@OP"]={type:"enum",title:"operation",values:n.values};n.size=[100,60];n.prototype.getTitle=function(){return"max"== this.properties.OP||"min"==this.properties.OP?this.properties.OP+"(A,B)":"A "+this.properties.OP+" B"};n.prototype.setValue=function(a){"string"==typeof a&&(a=parseFloat(a));this.properties.value=a};n.prototype.onPropertyChanged=function(a,b){if("OP"==a)switch(this.properties.OP){case "+":this._func=function(a,b){return a+b};break;case "-":this._func=function(a,b){return a-b};break;case "x":case "X":case "*":this._func=function(a,b){return a*b};break;case "/":this._func=function(a,b){return a/b}; @@ -481,41 +482,41 @@ f.size=[160,100];M.prototype.onPropertyChanged=function(a,b){"formula"==a&&(this this.boxcolor=null}catch(P){this.boxcolor="red"}this.setOutputData(0,d)}};f.prototype.getTitle=function(){return this._func_code||"Formula"};f.prototype.onDrawBackground=function(){var a=this.properties.formula;this.outputs&&this.outputs.length&&(this.outputs[0].label=a)};w.registerNodeType("math/formula",f);m.title="Vec2->XY";m.desc="vector 2 to components";m.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&(this.setOutputData(0,a[0]),this.setOutputData(1,a[1]))};w.registerNodeType("math3d/vec2-to-xy", m);u.title="XY->Vec2";u.desc="components to vector2";u.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=this.properties.x);var b=this.getInputData(1);null==b&&(b=this.properties.y);var d=this._data;d[0]=a;d[1]=b;this.setOutputData(0,d)};w.registerNodeType("math3d/xy-to-vec2",u);O.title="Vec3->XYZ";O.desc="vector 3 to components";O.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&(this.setOutputData(0,a[0]),this.setOutputData(1,a[1]),this.setOutputData(2,a[2]))}; w.registerNodeType("math3d/vec3-to-xyz",O);K.title="XYZ->Vec3";K.desc="components to vector3";K.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=this.properties.x);var b=this.getInputData(1);null==b&&(b=this.properties.y);var d=this.getInputData(2);null==d&&(d=this.properties.z);var c=this._data;c[0]=a;c[1]=b;c[2]=d;this.setOutputData(0,c)};w.registerNodeType("math3d/xyz-to-vec3",K);x.title="Vec4->XYZW";x.desc="vector 4 to components";x.prototype.onExecute=function(){var a=this.getInputData(0); -null!=a&&(this.setOutputData(0,a[0]),this.setOutputData(1,a[1]),this.setOutputData(2,a[2]),this.setOutputData(3,a[3]))};w.registerNodeType("math3d/vec4-to-xyzw",x);C.title="XYZW->Vec4";C.desc="components to vector4";C.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=this.properties.x);var b=this.getInputData(1);null==b&&(b=this.properties.y);var d=this.getInputData(2);null==d&&(d=this.properties.z);var c=this.getInputData(3);null==c&&(c=this.properties.w);var f=this._data;f[0]= -a;f[1]=b;f[2]=d;f[3]=c;this.setOutputData(0,f)};w.registerNodeType("math3d/xyzw-to-vec4",C)})(this); +null!=a&&(this.setOutputData(0,a[0]),this.setOutputData(1,a[1]),this.setOutputData(2,a[2]),this.setOutputData(3,a[3]))};w.registerNodeType("math3d/vec4-to-xyzw",x);A.title="XYZW->Vec4";A.desc="components to vector4";A.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=this.properties.x);var b=this.getInputData(1);null==b&&(b=this.properties.y);var d=this.getInputData(2);null==d&&(d=this.properties.z);var c=this.getInputData(3);null==c&&(c=this.properties.w);var f=this._data;f[0]= +a;f[1]=b;f[2]=d;f[3]=c;this.setOutputData(0,f)};w.registerNodeType("math3d/xyzw-to-vec4",A)})(this); (function(B){function c(){this.addInput("T","vec3");this.addInput("R","vec3");this.addInput("S","vec3");this.addOutput("mat4","mat4");this.properties={T:[0,0,0],R:[0,0,0],S:[1,1,1],R_in_degrees:!0};this._result=mat4.create();this._must_update=!0}function l(){this.addInput("A","number,vec3");this.addInput("B","number,vec3");this.addOutput("=","number,vec3");this.addProperty("OP","+","enum",{values:l.values});this._result=vec3.create()}function r(){this.addInput("in","vec3");this.addInput("f","number"); -this.addOutput("out","vec3");this.properties={f:1};this._data=new Float32Array(3)}function t(){this.addInput("in","vec3");this.addOutput("out","number")}function v(){this.addInput("in","vec3");this.addOutput("out","vec3");this._data=new Float32Array(3)}function h(){this.addInput("A","vec3");this.addInput("B","vec3");this.addInput("f","vec3");this.addOutput("out","vec3");this.properties={f:.5};this._data=new Float32Array(3)}function E(){this.addInput("A","vec3");this.addInput("B","vec3");this.addOutput("out", -"number")}var A=B.LiteGraph;c.title="mat4";c.temp_quat=new Float32Array([0,0,0,1]);c.temp_mat4=new Float32Array(16);c.temp_vec3=new Float32Array(3);c.prototype.onPropertyChanged=function(c,e){this._must_update=!0};c.prototype.onExecute=function(){var e=this._result,k=c.temp_quat,n=c.temp_mat4,q=c.temp_vec3,a=this.getInputData(0),b=this.getInputData(1),d=this.getInputData(2);if(this._must_update||a||b||d)a=a||this.properties.T,b=b||this.properties.R,d=d||this.properties.S,mat4.identity(e),mat4.translate(e, -e,a),this.properties.R_in_degrees?(q.set(b),vec3.scale(q,q,DEG2RAD),quat.fromEuler(k,q)):quat.fromEuler(k,b),mat4.fromQuat(n,k),mat4.multiply(e,e,n),mat4.scale(e,e,d);this.setOutputData(0,e)};A.registerNodeType("math3d/mat4",c);l.values="+ - * / % ^ max min dot cross".split(" ");A.registerSearchboxExtra("math3d/operation","CROSS()",{properties:{OP:"cross"},title:"CROSS()"});A.registerSearchboxExtra("math3d/operation","DOT()",{properties:{OP:"dot"},title:"DOT()"});l.title="Operation";l.desc="Easy math 3D operators"; +this.addOutput("out","vec3");this.properties={f:1};this._data=new Float32Array(3)}function t(){this.addInput("in","vec3");this.addOutput("out","number")}function v(){this.addInput("in","vec3");this.addOutput("out","vec3");this._data=new Float32Array(3)}function h(){this.addInput("A","vec3");this.addInput("B","vec3");this.addInput("f","vec3");this.addOutput("out","vec3");this.properties={f:.5};this._data=new Float32Array(3)}function F(){this.addInput("A","vec3");this.addInput("B","vec3");this.addOutput("out", +"number")}var C=B.LiteGraph;c.title="mat4";c.temp_quat=new Float32Array([0,0,0,1]);c.temp_mat4=new Float32Array(16);c.temp_vec3=new Float32Array(3);c.prototype.onPropertyChanged=function(c,e){this._must_update=!0};c.prototype.onExecute=function(){var e=this._result,k=c.temp_quat,n=c.temp_mat4,q=c.temp_vec3,a=this.getInputData(0),b=this.getInputData(1),d=this.getInputData(2);if(this._must_update||a||b||d)a=a||this.properties.T,b=b||this.properties.R,d=d||this.properties.S,mat4.identity(e),mat4.translate(e, +e,a),this.properties.R_in_degrees?(q.set(b),vec3.scale(q,q,DEG2RAD),quat.fromEuler(k,q)):quat.fromEuler(k,b),mat4.fromQuat(n,k),mat4.multiply(e,e,n),mat4.scale(e,e,d);this.setOutputData(0,e)};C.registerNodeType("math3d/mat4",c);l.values="+ - * / % ^ max min dot cross".split(" ");C.registerSearchboxExtra("math3d/operation","CROSS()",{properties:{OP:"cross"},title:"CROSS()"});C.registerSearchboxExtra("math3d/operation","DOT()",{properties:{OP:"dot"},title:"DOT()"});l.title="Operation";l.desc="Easy math 3D operators"; l["@OP"]={type:"enum",title:"operation",values:l.values};l.size=[100,60];l.prototype.getTitle=function(){return"max"==this.properties.OP||"min"==this.properties.OP?this.properties.OP+"(A,B)":"A "+this.properties.OP+" B"};l.prototype.onExecute=function(){var c=this.getInputData(0),e=this.getInputData(1);if(null!=c&&null!=e){c.constructor===Number&&(c=[c,c,c]);e.constructor===Number&&(e=[e,e,e]);var n=this._result;switch(this.properties.OP){case "+":n=vec3.add(n,c,e);break;case "-":n=vec3.sub(n,c,e); break;case "x":case "X":case "*":n=vec3.mul(n,c,e);break;case "/":n=vec3.div(n,c,e);break;case "%":n[0]=c[0]%e[0];n[1]=c[1]%e[1];n[2]=c[2]%e[2];break;case "^":n[0]=Math.pow(c[0],e[0]);n[1]=Math.pow(c[1],e[1]);n[2]=Math.pow(c[2],e[2]);break;case "max":n[0]=Math.max(c[0],e[0]);n[1]=Math.max(c[1],e[1]);n[2]=Math.max(c[2],e[2]);break;case "min":n[0]=Math.min(c[0],e[0]),n[1]=Math.min(c[1],e[1]),n[2]=Math.min(c[2],e[2]);case "dot":n=vec3.dot(c,e);break;case "cross":vec3.cross(n,c,e);break;default:console.warn("Unknown operation: "+ -this.properties.OP)}this.setOutputData(0,n)}};l.prototype.onDrawBackground=function(c){this.flags.collapsed||(c.font="40px Arial",c.fillStyle="#666",c.textAlign="center",c.fillText(this.properties.OP,.5*this.size[0],.5*(this.size[1]+A.NODE_TITLE_HEIGHT)),c.textAlign="left")};A.registerNodeType("math3d/operation",l);r.title="vec3_scale";r.desc="scales the components of a vec3";r.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var e=this.getInputData(1);null==e&&(e=this.properties.f); -var n=this._data;n[0]=c[0]*e;n[1]=c[1]*e;n[2]=c[2]*e;this.setOutputData(0,n)}};A.registerNodeType("math3d/vec3-scale",r);t.title="vec3_length";t.desc="returns the module of a vector";t.prototype.onExecute=function(){var c=this.getInputData(0);null!=c&&this.setOutputData(0,Math.sqrt(c[0]*c[0]+c[1]*c[1]+c[2]*c[2]))};A.registerNodeType("math3d/vec3-length",t);v.title="vec3_normalize";v.desc="returns the vector normalized";v.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var e= -Math.sqrt(c[0]*c[0]+c[1]*c[1]+c[2]*c[2]),n=this._data;n[0]=c[0]/e;n[1]=c[1]/e;n[2]=c[2]/e;this.setOutputData(0,n)}};A.registerNodeType("math3d/vec3-normalize",v);h.title="vec3_lerp";h.desc="returns the interpolated vector";h.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var e=this.getInputData(1);if(null!=e){var n=this.getInputOrProperty("f"),q=this._data;q[0]=c[0]*(1-n)+e[0]*n;q[1]=c[1]*(1-n)+e[1]*n;q[2]=c[2]*(1-n)+e[2]*n;this.setOutputData(0,q)}}};A.registerNodeType("math3d/vec3-lerp", -h);E.title="vec3_dot";E.desc="returns the dot product";E.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var e=this.getInputData(1);null!=e&&this.setOutputData(0,c[0]*e[0]+c[1]*e[1]+c[2]*e[2])}};A.registerNodeType("math3d/vec3-dot",E);if(B.glMatrix){B=function(){this.addInput("vec3","vec3");this.addOutput("remap","vec3");this.addOutput("clamped","vec3");this.properties={clamp:!0,range_min:[-1,-1,0],range_max:[1,1,0],target_min:[-1,-1,0],target_max:[1,1,0]};this._value=vec3.create(); -this._clamped=vec3.create()};var I=function(){this.addInputs([["A","quat"],["B","quat"],["factor","number"]]);this.addOutput("slerp","quat");this.addProperty("factor",.5);this._value=quat.create()},J=function(){this.addInputs([["A","quat"],["B","quat"]]);this.addOutput("A*B","quat");this._value=quat.create()},F=function(){this.addInputs([["vec3","vec3"],["quat","quat"]]);this.addOutput("result","vec3");this.properties={vec:[0,0,1]}},e=function(){this.addInput(["quat","quat"]);this.addOutput("euler", -"vec3");this._value=vec3.create()},D=function(){this.addInput("euler","vec3");this.addOutput("quat","quat");this.properties={euler:[0,0,0],use_yaw_pitch_roll:!1};this._degs=vec3.create();this._value=quat.create()},H=function(){this.addInputs([["degrees","number"],["axis","vec3"]]);this.addOutput("quat","quat");this.properties={angle:90,axis:vec3.fromValues(0,1,0)};this._value=quat.create()},z=function(){this.addOutput("quat","quat");this.properties={x:0,y:0,z:0,w:1,normalize:!1};this._value=quat.create()}; -z.title="Quaternion";z.desc="quaternion";z.prototype.onExecute=function(){this._value[0]=this.getInputOrProperty("x");this._value[1]=this.getInputOrProperty("y");this._value[2]=this.getInputOrProperty("z");this._value[3]=this.getInputOrProperty("w");this.properties.normalize&&quat.normalize(this._value,this._value);this.setOutputData(0,this._value)};z.prototype.onGetInputs=function(){return[["x","number"],["y","number"],["z","number"],["w","number"]]};A.registerNodeType("math3d/quaternion",z);H.title= -"Rotation";H.desc="quaternion rotation";H.prototype.onExecute=function(){var c=this.getInputData(0);null==c&&(c=this.properties.angle);var e=this.getInputData(1);null==e&&(e=this.properties.axis);c=quat.setAxisAngle(this._value,e,.0174532925*c);this.setOutputData(0,c)};A.registerNodeType("math3d/rotation",H);D.title="Euler->Quat";D.desc="Converts euler angles (in degrees) to quaternion";D.prototype.onExecute=function(){var c=this.getInputData(0);null==c&&(c=this.properties.euler);vec3.scale(this._degs, -c,DEG2RAD);this.properties.use_yaw_pitch_roll&&(this._degs=[this._degs[2],this._degs[0],this._degs[1]]);c=quat.fromEuler(this._value,this._degs);this.setOutputData(0,c)};A.registerNodeType("math3d/euler_to_quat",D);e.title="Euler->Quat";e.desc="Converts rotX,rotY,rotZ in degrees to quat";e.prototype.onExecute=function(){var c=this.getInputData(0);c&&(quat.toEuler(this._value,c),vec3.scale(this._value,this._value,DEG2RAD),this.setOutputData(0,this._value))};A.registerNodeType("math3d/quat_to_euler", -e);F.title="Rot. Vec3";F.desc="rotate a point";F.prototype.onExecute=function(){var c=this.getInputData(0);null==c&&(c=this.properties.vec);var e=this.getInputData(1);null==e?this.setOutputData(c):this.setOutputData(0,vec3.transformQuat(vec3.create(),c,e))};A.registerNodeType("math3d/rotate_vec3",F);J.title="Mult. Quat";J.desc="rotate quaternion";J.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var e=this.getInputData(1);null!=e&&(c=quat.multiply(this._value,c,e),this.setOutputData(0, -c))}};A.registerNodeType("math3d/mult-quat",J);I.title="Quat Slerp";I.desc="quaternion spherical interpolation";I.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var e=this.getInputData(1);if(null!=e){var n=this.properties.factor;null!=this.getInputData(2)&&(n=this.getInputData(2));c=quat.slerp(this._value,c,e,n);this.setOutputData(0,c)}}};A.registerNodeType("math3d/quat-slerp",I);B.title="Remap Range";B.desc="remap a 3D range";B.prototype.onExecute=function(){var c=this.getInputData(0); -c&&this._value.set(c);c=this.properties.range_min;for(var e=this.properties.range_max,n=this.properties.target_min,q=this.properties.target_max,a=0;3>a;++a){var b=e[a]-c[a];this._clamped[a]=Math.clamp(this._value[a],c[a],e[a]);0==b?this._value[a]=.5*(n[a]+q[a]):(b=(this._value[a]-c[a])/b,this.properties.clamp&&(b=Math.clamp(b,0,1)),this._value[a]=n[a]+b*(q[a]-n[a]))}this.setOutputData(0,this._value);this.setOutputData(1,this._clamped)};A.registerNodeType("math3d/remap_range",B)}else A.debug&&console.warn("No glmatrix found, some Math3D nodes may not work")})(this); +this.properties.OP)}this.setOutputData(0,n)}};l.prototype.onDrawBackground=function(c){this.flags.collapsed||(c.font="40px Arial",c.fillStyle="#666",c.textAlign="center",c.fillText(this.properties.OP,.5*this.size[0],.5*(this.size[1]+C.NODE_TITLE_HEIGHT)),c.textAlign="left")};C.registerNodeType("math3d/operation",l);r.title="vec3_scale";r.desc="scales the components of a vec3";r.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var e=this.getInputData(1);null==e&&(e=this.properties.f); +var n=this._data;n[0]=c[0]*e;n[1]=c[1]*e;n[2]=c[2]*e;this.setOutputData(0,n)}};C.registerNodeType("math3d/vec3-scale",r);t.title="vec3_length";t.desc="returns the module of a vector";t.prototype.onExecute=function(){var c=this.getInputData(0);null!=c&&this.setOutputData(0,Math.sqrt(c[0]*c[0]+c[1]*c[1]+c[2]*c[2]))};C.registerNodeType("math3d/vec3-length",t);v.title="vec3_normalize";v.desc="returns the vector normalized";v.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var e= +Math.sqrt(c[0]*c[0]+c[1]*c[1]+c[2]*c[2]),n=this._data;n[0]=c[0]/e;n[1]=c[1]/e;n[2]=c[2]/e;this.setOutputData(0,n)}};C.registerNodeType("math3d/vec3-normalize",v);h.title="vec3_lerp";h.desc="returns the interpolated vector";h.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var e=this.getInputData(1);if(null!=e){var n=this.getInputOrProperty("f"),q=this._data;q[0]=c[0]*(1-n)+e[0]*n;q[1]=c[1]*(1-n)+e[1]*n;q[2]=c[2]*(1-n)+e[2]*n;this.setOutputData(0,q)}}};C.registerNodeType("math3d/vec3-lerp", +h);F.title="vec3_dot";F.desc="returns the dot product";F.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var e=this.getInputData(1);null!=e&&this.setOutputData(0,c[0]*e[0]+c[1]*e[1]+c[2]*e[2])}};C.registerNodeType("math3d/vec3-dot",F);if(B.glMatrix){B=function(){this.addInput("vec3","vec3");this.addOutput("remap","vec3");this.addOutput("clamped","vec3");this.properties={clamp:!0,range_min:[-1,-1,0],range_max:[1,1,0],target_min:[-1,-1,0],target_max:[1,1,0]};this._value=vec3.create(); +this._clamped=vec3.create()};var I=function(){this.addInputs([["A","quat"],["B","quat"],["factor","number"]]);this.addOutput("slerp","quat");this.addProperty("factor",.5);this._value=quat.create()},J=function(){this.addInputs([["A","quat"],["B","quat"]]);this.addOutput("A*B","quat");this._value=quat.create()},G=function(){this.addInputs([["vec3","vec3"],["quat","quat"]]);this.addOutput("result","vec3");this.properties={vec:[0,0,1]}},e=function(){this.addInput(["quat","quat"]);this.addOutput("euler", +"vec3");this._value=vec3.create()},D=function(){this.addInput("euler","vec3");this.addOutput("quat","quat");this.properties={euler:[0,0,0],use_yaw_pitch_roll:!1};this._degs=vec3.create();this._value=quat.create()},E=function(){this.addInputs([["degrees","number"],["axis","vec3"]]);this.addOutput("quat","quat");this.properties={angle:90,axis:vec3.fromValues(0,1,0)};this._value=quat.create()},z=function(){this.addOutput("quat","quat");this.properties={x:0,y:0,z:0,w:1,normalize:!1};this._value=quat.create()}; +z.title="Quaternion";z.desc="quaternion";z.prototype.onExecute=function(){this._value[0]=this.getInputOrProperty("x");this._value[1]=this.getInputOrProperty("y");this._value[2]=this.getInputOrProperty("z");this._value[3]=this.getInputOrProperty("w");this.properties.normalize&&quat.normalize(this._value,this._value);this.setOutputData(0,this._value)};z.prototype.onGetInputs=function(){return[["x","number"],["y","number"],["z","number"],["w","number"]]};C.registerNodeType("math3d/quaternion",z);E.title= +"Rotation";E.desc="quaternion rotation";E.prototype.onExecute=function(){var c=this.getInputData(0);null==c&&(c=this.properties.angle);var e=this.getInputData(1);null==e&&(e=this.properties.axis);c=quat.setAxisAngle(this._value,e,.0174532925*c);this.setOutputData(0,c)};C.registerNodeType("math3d/rotation",E);D.title="Euler->Quat";D.desc="Converts euler angles (in degrees) to quaternion";D.prototype.onExecute=function(){var c=this.getInputData(0);null==c&&(c=this.properties.euler);vec3.scale(this._degs, +c,DEG2RAD);this.properties.use_yaw_pitch_roll&&(this._degs=[this._degs[2],this._degs[0],this._degs[1]]);c=quat.fromEuler(this._value,this._degs);this.setOutputData(0,c)};C.registerNodeType("math3d/euler_to_quat",D);e.title="Euler->Quat";e.desc="Converts rotX,rotY,rotZ in degrees to quat";e.prototype.onExecute=function(){var c=this.getInputData(0);c&&(quat.toEuler(this._value,c),vec3.scale(this._value,this._value,DEG2RAD),this.setOutputData(0,this._value))};C.registerNodeType("math3d/quat_to_euler", +e);G.title="Rot. Vec3";G.desc="rotate a point";G.prototype.onExecute=function(){var c=this.getInputData(0);null==c&&(c=this.properties.vec);var e=this.getInputData(1);null==e?this.setOutputData(c):this.setOutputData(0,vec3.transformQuat(vec3.create(),c,e))};C.registerNodeType("math3d/rotate_vec3",G);J.title="Mult. Quat";J.desc="rotate quaternion";J.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var e=this.getInputData(1);null!=e&&(c=quat.multiply(this._value,c,e),this.setOutputData(0, +c))}};C.registerNodeType("math3d/mult-quat",J);I.title="Quat Slerp";I.desc="quaternion spherical interpolation";I.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var e=this.getInputData(1);if(null!=e){var n=this.properties.factor;null!=this.getInputData(2)&&(n=this.getInputData(2));c=quat.slerp(this._value,c,e,n);this.setOutputData(0,c)}}};C.registerNodeType("math3d/quat-slerp",I);B.title="Remap Range";B.desc="remap a 3D range";B.prototype.onExecute=function(){var c=this.getInputData(0); +c&&this._value.set(c);c=this.properties.range_min;for(var e=this.properties.range_max,n=this.properties.target_min,q=this.properties.target_max,a=0;3>a;++a){var b=e[a]-c[a];this._clamped[a]=Math.clamp(this._value[a],c[a],e[a]);0==b?this._value[a]=.5*(n[a]+q[a]):(b=(this._value[a]-c[a])/b,this.properties.clamp&&(b=Math.clamp(b,0,1)),this._value[a]=n[a]+b*(q[a]-n[a]))}this.setOutputData(0,this._value);this.setOutputData(1,this._clamped)};C.registerNodeType("math3d/remap_range",B)}else C.debug&&console.warn("No glmatrix found, some Math3D nodes may not work")})(this); (function(B){function c(){this.addInput("","string");this.addOutput("table","table");this.addOutput("rows","number");this.addProperty("value","");this.addProperty("separator",",");this._table=null}B=B.LiteGraph;B.wrapFunctionAsNode("string/toString",function(c){if(c&&c.constructor===Object)try{return JSON.stringify(c)}catch(r){}return String(c)},[""],"string");B.wrapFunctionAsNode("string/compare",function(c,r){return c==r},["string","string"],"boolean");B.wrapFunctionAsNode("string/concatenate", function(c,r){return void 0===c?r:void 0===r?c:c+r},["string","string"],"string");B.wrapFunctionAsNode("string/contains",function(c,r){return void 0===c||void 0===r?!1:-1!=c.indexOf(r)},["string","string"],"boolean");B.wrapFunctionAsNode("string/toUpperCase",function(c){return null!=c&&c.constructor===String?c.toUpperCase():c},["string"],"string");B.wrapFunctionAsNode("string/split",function(c,r){null==r&&(r=this.properties.separator);if(null==c)return[];if(c.constructor===String)return c.split(r|| " ");if(c.constructor===Array){for(var l=[],v=0;ve;++e){var h=this.getInputData(e);if(null!=h){var l=this.values[e];l.push(h);l.length>c[0]&&l.shift()}}}};c.prototype.onDrawBackground=function(e){if(!this.flags.collapsed){var h= +function G(){this.addOutput("Webcam","image");this.properties={filterFacingMode:!1,facingMode:"user"};this.boxcolor="black";this.frame=0}var e=B.LiteGraph;c.title="Plot";c.desc="Plots data over time";c.colors=["#FFF","#F99","#9F9","#99F"];c.prototype.onExecute=function(c){if(!this.flags.collapsed){c=this.size;for(var e=0;4>e;++e){var h=this.getInputData(e);if(null!=h){var l=this.values[e];l.push(h);l.length>c[0]&&l.shift()}}}};c.prototype.onDrawBackground=function(e){if(!this.flags.collapsed){var h= this.size,l=.5*h[1]/this.properties.scale,t=c.colors,k=.5*h[1];e.fillStyle="#000";e.fillRect(0,0,h[0],h[1]);e.strokeStyle="#555";e.beginPath();e.moveTo(0,k);e.lineTo(h[0],k);e.stroke();if(this.inputs)for(var n=0;4>n;++n){var q=this.values[n];if(this.inputs[n]&&this.inputs[n].link){e.strokeStyle=t[n];e.beginPath();var a=q[0]*l*-1+k;e.moveTo(0,Math.clamp(a,0,h[1]));for(var b=1;b=c&&(this._video.currentTime=c*this._video.duration,this._video.pause()); this._video.dirty=!0;this.setOutputData(0,this._video);this.setOutputData(1,this._video.currentTime);this.setOutputData(2,this._video.duration);this.setDirtyCanvas(!0)}};J.prototype.onStart=function(){this.play()};J.prototype.onStop=function(){this.stop()};J.prototype.loadVideo=function(c){this._video_url=c;var h=c.substr(0,10).indexOf(":"),l="";-1!=h&&(l=c.substr(0,h));h="";l&&(h=c.substr(0,c.indexOf("/",l.length+3)),h=h.substr(l.length+3));this.properties.use_proxy&&l&&e.proxy&&h!=location.host&& (c=e.proxy+c.substr(c.indexOf(":")+3));this._video=document.createElement("video");this._video.src=c;this._video.type="type=video/mp4";this._video.muted=!0;this._video.autoplay=!0;var t=this;this._video.addEventListener("loadedmetadata",function(c){console.log("Duration: "+this.duration+" seconds");console.log("Size: "+this.videoWidth+","+this.videoHeight);t.setDirtyCanvas(!0);this.width=this.videoWidth;this.height=this.videoHeight});this._video.addEventListener("progress",function(c){console.log("video loading...")}); this._video.addEventListener("error",function(c){console.error("Error loading video: "+this.src);if(this.error)switch(this.error.code){case this.error.MEDIA_ERR_ABORTED:console.error("You stopped the video.");break;case this.error.MEDIA_ERR_NETWORK:console.error("Network error - please try again later.");break;case this.error.MEDIA_ERR_DECODE:console.error("Video is broken..");break;case this.error.MEDIA_ERR_SRC_NOT_SUPPORTED:console.error("Sorry, your browser can't play this video.")}});this._video.addEventListener("ended", function(c){console.log("Video Ended.");this.play()})};J.prototype.onPropertyChanged=function(c,e){this.properties[c]=e;"url"==c&&""!=e&&this.loadVideo(e);return!0};J.prototype.play=function(){this._video&&this._video.videoWidth&&this._video.play()};J.prototype.playPause=function(){this._video&&(this._video.paused?this.play():this.pause())};J.prototype.stop=function(){this._video&&(this._video.pause(),this._video.currentTime=0)};J.prototype.pause=function(){this._video&&(console.log("Video paused"), -this._video.pause())};J.prototype.onWidget=function(c,e){};e.registerNodeType("graphics/video",J);F.title="Webcam";F.desc="Webcam image";F.is_webcam_open=!1;F.prototype.openStream=function(){if(navigator.mediaDevices.getUserMedia){this._waiting_confirmation=!0;navigator.mediaDevices.getUserMedia({audio:!1,video:this.properties.filterFacingMode?{facingMode:this.properties.facingMode}:!0}).then(this.streamReady.bind(this)).catch(function(e){console.log("Webcam rejected",e);c._webcam_stream=!1;F.is_webcam_open= -!1;c.boxcolor="red";c.trigger("stream_error")});var c=this}else console.log("getUserMedia() is not supported in your browser, use chrome and enable WebRTC from about://flags")};F.prototype.closeStream=function(){if(this._webcam_stream){var c=this._webcam_stream.getTracks();if(c.length)for(var e=0;e=this.size[1]||!this.properties.show||!this._video||(c.save(),c.drawImage(this._video,0,0,this.size[0],this.size[1]),c.restore())};F.prototype.onGetOutputs=function(){return[["width","number"],["height","number"],["stream_ready",e.EVENT],["stream_closed",e.EVENT],["stream_error",e.EVENT]]};e.registerNodeType("graphics/webcam",F)})(this); +this._video.pause())};J.prototype.onWidget=function(c,e){};e.registerNodeType("graphics/video",J);G.title="Webcam";G.desc="Webcam image";G.is_webcam_open=!1;G.prototype.openStream=function(){if(navigator.mediaDevices.getUserMedia){this._waiting_confirmation=!0;navigator.mediaDevices.getUserMedia({audio:!1,video:this.properties.filterFacingMode?{facingMode:this.properties.facingMode}:!0}).then(this.streamReady.bind(this)).catch(function(e){console.log("Webcam rejected",e);c._webcam_stream=!1;G.is_webcam_open= +!1;c.boxcolor="red";c.trigger("stream_error")});var c=this}else console.log("getUserMedia() is not supported in your browser, use chrome and enable WebRTC from about://flags")};G.prototype.closeStream=function(){if(this._webcam_stream){var c=this._webcam_stream.getTracks();if(c.length)for(var e=0;e=this.size[1]||!this.properties.show||!this._video||(c.save(),c.drawImage(this._video,0,0,this.size[0],this.size[1]),c.restore())};G.prototype.onGetOutputs=function(){return[["width","number"],["height","number"],["stream_ready",e.EVENT],["stream_closed",e.EVENT],["stream_error",e.EVENT]]};e.registerNodeType("graphics/webcam",G)})(this); (function(B){function c(){this.addOutput("tex","Texture");this.addOutput("name","string");this.properties={name:"",filter:!0};this.size=[c.image_preview_size,c.image_preview_size]}function l(){this.addInput("Texture","Texture");this.properties={flipY:!1};this.size=[c.image_preview_size,c.image_preview_size]}function r(){this.addInput("Texture","Texture");this.addOutput("tex","Texture");this.addOutput("name","string");this.properties={name:"",generate_mipmaps:!1}}function t(){this.addInput("Texture", "Texture");this.addInput("TextureB","Texture");this.addInput("value","number");this.addOutput("Texture","Texture");this.help="

pixelcode must be vec3, uvcode must be vec2, is optional

\t\t

uv: tex. coords

color: texture colorB: textureB

time: scene time value: input value

For multiline you must type: result = ...

";this.properties={value:1,pixelcode:"color + colorB * value",uvcode:"",precision:c.DEFAULT}; this.has_error=!1}function v(){this.addOutput("out","Texture");this.properties={code:"",u_value:1,u_color:[1,1,1,1],width:512,height:512,precision:c.DEFAULT};this.properties.code=v.pixel_shader;this._uniforms={u_value:1,u_color:vec4.create(),in_texture:0,texSize:vec4.create(),time:0}}function h(){this.addInput("in","Texture");this.addInput("scale","vec2");this.addInput("offset","vec2");this.addOutput("out","Texture");this.properties={offset:vec2.fromValues(0,0),scale:vec2.fromValues(1,1),precision:c.DEFAULT}} -function E(){this.addInput("in","Texture");this.addInput("warp","Texture");this.addInput("factor","number");this.addOutput("out","Texture");this.properties={factor:.01,scale:[1,1],offset:[0,0],precision:c.DEFAULT};this._uniforms={u_texture:0,u_textureB:1,u_factor:1,u_scale:vec2.create(),u_offset:vec2.create()}}function A(){this.addInput("Texture","Texture");this.properties={additive:!1,antialiasing:!1,filter:!0,disable_alpha:!1,gamma:1,viewport:[0,0,1,1]};this.size[0]=130}function I(){this.addInput("Texture", -"Texture");this.addOutput("","Texture");this.properties={size:0,generate_mipmaps:!1,precision:c.DEFAULT}}function J(){this.addInput("Texture","Texture");this.addOutput("","Texture");this.properties={iterations:1,generate_mipmaps:!1,precision:c.DEFAULT}}function F(){this.addInput("Texture","Texture");this.addOutput("","Texture");this.properties={size:[512,512],generate_mipmaps:!1,precision:c.DEFAULT}}function e(){this.addInput("Texture","Texture");this.addOutput("tex","Texture");this.addOutput("avg", -"vec4");this.addOutput("lum","number");this.properties={use_previous_frame:!0,high_quality:!1};this._uniforms={u_texture:0,u_mipmap_offset:0};this._luminance=new Float32Array(4)}function D(){this.addInput("in","Texture");this.addInput("factor","Number");this.addOutput("out","Texture");this.properties={factor:.5};this._uniforms={u_texture:0,u_textureB:1,u_factor:this.properties.factor}}function H(){this.addInput("in","Texture");this.addOutput("avg","Texture");this.addOutput("array","Texture");this.properties= +function F(){this.addInput("in","Texture");this.addInput("warp","Texture");this.addInput("factor","number");this.addOutput("out","Texture");this.properties={factor:.01,scale:[1,1],offset:[0,0],precision:c.DEFAULT};this._uniforms={u_texture:0,u_textureB:1,u_factor:1,u_scale:vec2.create(),u_offset:vec2.create()}}function C(){this.addInput("Texture","Texture");this.properties={additive:!1,antialiasing:!1,filter:!0,disable_alpha:!1,gamma:1,viewport:[0,0,1,1]};this.size[0]=130}function I(){this.addInput("Texture", +"Texture");this.addOutput("","Texture");this.properties={size:0,generate_mipmaps:!1,precision:c.DEFAULT}}function J(){this.addInput("Texture","Texture");this.addOutput("","Texture");this.properties={iterations:1,generate_mipmaps:!1,precision:c.DEFAULT}}function G(){this.addInput("Texture","Texture");this.addOutput("","Texture");this.properties={size:[512,512],generate_mipmaps:!1,precision:c.DEFAULT}}function e(){this.addInput("Texture","Texture");this.addOutput("tex","Texture");this.addOutput("avg", +"vec4");this.addOutput("lum","number");this.properties={use_previous_frame:!0,high_quality:!1};this._uniforms={u_texture:0,u_mipmap_offset:0};this._luminance=new Float32Array(4)}function D(){this.addInput("in","Texture");this.addInput("factor","Number");this.addOutput("out","Texture");this.properties={factor:.5};this._uniforms={u_texture:0,u_textureB:1,u_factor:this.properties.factor}}function E(){this.addInput("in","Texture");this.addOutput("avg","Texture");this.addOutput("array","Texture");this.properties= {samples:64,frames_interval:1};this._uniforms={u_texture:0,u_textureB:1,u_samples:this.properties.samples,u_isamples:1/this.properties.samples};this.frame=0}function z(){this.addInput("Image","image");this.addOutput("","Texture");this.properties={}}function M(){this.addInput("Texture","Texture");this.addInput("LUT","Texture");this.addInput("Intensity","number");this.addOutput("","Texture");this.properties={enabled:!0,intensity:1,precision:c.DEFAULT,texture:null};M._shader||(M._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER, M.pixel_shader))}function k(){this.addInput("Texture","Texture");this.addInput("Atlas","Texture");this.addOutput("","Texture");this.properties={enabled:!0,num_row_symbols:4,symbol_size:16,brightness:1,colorize:!1,filter:!1,invert:!1,precision:c.DEFAULT,generate_mipmaps:!1,texture:null};k._shader||(k._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,k.pixel_shader));this._uniforms={u_texture:0,u_textureB:1,u_row_simbols:4,u_simbol_size:16,u_res:vec2.create()}}function n(){this.addInput("Texture","Texture"); this.addOutput("R","Texture");this.addOutput("G","Texture");this.addOutput("B","Texture");this.addOutput("A","Texture");n._shader||(n._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,n.pixel_shader))}function q(){this.addInput("R","Texture");this.addInput("G","Texture");this.addInput("B","Texture");this.addInput("A","Texture");this.addOutput("Texture","Texture");this.properties={precision:c.DEFAULT,R:1,G:1,B:1,A:1};this._color=vec4.create();this._uniforms={u_textureR:0,u_textureG:1,u_textureB:2, @@ -552,8 +553,8 @@ u_textureA:3,u_color:this._color}}function a(){this.addOutput("Texture","Texture "Texture");this.addInput("B","Texture");this.addInput("Mixer","Texture");this.addOutput("Texture","Texture");this.properties={factor:.5,size_from_biggest:!0,invert:!1,precision:c.DEFAULT};this._uniforms={u_textureA:0,u_textureB:1,u_textureMix:2,u_mix:vec4.create()}}function g(){this.addInput("Tex.","Texture");this.addOutput("Edges","Texture");this.properties={invert:!0,threshold:!1,factor:1,precision:c.DEFAULT};g._shader||(g._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,g.pixel_shader))}function f(){this.addInput("Texture", "Texture");this.addInput("Distance","number");this.addInput("Range","number");this.addOutput("Texture","Texture");this.properties={distance:100,range:50,only_depth:!1,high_precision:!1};this._uniforms={u_texture:0,u_distance:100,u_range:50,u_camera_planes:null}}function m(){this.addInput("Texture","Texture");this.addOutput("Texture","Texture");this.properties={precision:c.DEFAULT,invert:!1};this._uniforms={u_texture:0,u_camera_planes:null,u_ires:vec2.create()}}function u(){this.addInput("Texture", "Texture");this.addInput("Iterations","number");this.addInput("Intensity","number");this.addOutput("Blurred","Texture");this.properties={intensity:1,iterations:1,preserve_aspect:!1,scale:[1,1],precision:c.DEFAULT}}function O(){this.intensity=.5;this.persistence=.6;this.iterations=8;this.threshold=.8;this.scale=1;this.dirt_texture=null;this.dirt_factor=.5;this._textures=[];this._uniforms={u_intensity:1,u_texture:0,u_glow_texture:1,u_threshold:0,u_texel_size:vec2.create()}}function K(){this.addInput("in", -"Texture");this.addInput("dirt","Texture");this.addOutput("out","Texture");this.addOutput("glow","Texture");this.properties={enabled:!0,intensity:1,persistence:.99,iterations:16,threshold:0,scale:1,dirt_factor:.5,precision:c.DEFAULT};this.fx=new O}function x(){this.addInput("Texture","Texture");this.addOutput("Filtered","Texture");this.properties={intensity:1,radius:5}}function C(){this.addInput("Texture","Texture");this.addOutput("Filtered","Texture");this.properties={sigma:1.4,k:1.6,p:21.7,epsilon:79, -phi:.017}}function w(){this.addOutput("Webcam","Texture");this.properties={texture_name:"",facingMode:"user"};this.boxcolor="black";this.version=0}function L(){this.addInput("in","Texture");this.addInput("f","number");this.addOutput("out","Texture");this.properties={enabled:!0,factor:1,precision:c.LOW};this._uniforms={u_texture:0,u_factor:1}}function G(){this.addInput("in","");this.properties={precision:c.LOW,width:0,height:0,channels:1};this.addOutput("out","Texture")}function y(){this.addInput("in", +"Texture");this.addInput("dirt","Texture");this.addOutput("out","Texture");this.addOutput("glow","Texture");this.properties={enabled:!0,intensity:1,persistence:.99,iterations:16,threshold:0,scale:1,dirt_factor:.5,precision:c.DEFAULT};this.fx=new O}function x(){this.addInput("Texture","Texture");this.addOutput("Filtered","Texture");this.properties={intensity:1,radius:5}}function A(){this.addInput("Texture","Texture");this.addOutput("Filtered","Texture");this.properties={sigma:1.4,k:1.6,p:21.7,epsilon:79, +phi:.017}}function w(){this.addOutput("Webcam","Texture");this.properties={texture_name:"",facingMode:"user"};this.boxcolor="black";this.version=0}function L(){this.addInput("in","Texture");this.addInput("f","number");this.addOutput("out","Texture");this.properties={enabled:!0,factor:1,precision:c.LOW};this._uniforms={u_texture:0,u_factor:1}}function H(){this.addInput("in","");this.properties={precision:c.LOW,width:0,height:0,channels:1};this.addOutput("out","Texture")}function y(){this.addInput("in", "Texture");this.addOutput("out","Texture");this.properties={precision:c.LOW,split_channels:!1};this._values=new Uint8Array(1024);this._values.fill(255);this._curve_texture=null;this._uniforms={u_texture:0,u_curve:1,u_range:1};this._must_update=!0;this._points={RGB:[[0,0],[1,1]],R:[[0,0],[1,1]],G:[[0,0],[1,1]],B:[[0,0],[1,1]]};this.curve_editor=null;this.addWidget("toggle","Split Channels",!1,"split_channels");this.addWidget("combo","Channel","RGB",{values:["RGB","R","G","B"]});this.curve_offset=68; this.size=[240,160]}function P(){this.addInput("in","Texture");this.addInput("exp","number");this.addOutput("out","Texture");this.properties={exposition:1,precision:c.LOW};this._uniforms={u_texture:0,u_exposition:1}}function Q(){this.addInput("in","Texture");this.addInput("avg","number,Texture");this.addOutput("out","Texture");this.properties={enabled:!0,scale:1,gamma:1,average_lum:1,lum_white:1,precision:c.LOW};this._uniforms={u_texture:0,u_lumwhite2:1,u_igamma:1,u_scale:1,u_average_lum:1}}function S(){this.addOutput("out", "Texture");this.properties={width:512,height:512,seed:0,persistence:.1,octaves:8,scale:1,offset:[0,0],amplitude:1,precision:c.DEFAULT};this._key=0;this._texture=null;this._uniforms={u_persistence:.1,u_seed:0,u_offset:vec2.create(),u_scale:1,u_viewport:vec2.create()}}function R(){this.addInput("v");this.addOutput("out","Texture");this.properties={code:R.default_code,width:512,height:512,clear:!0,precision:c.DEFAULT,use_html_canvas:!1};this._temp_texture=this._func=null;this.compileCode()}function T(){this.addInput("in", @@ -571,8 +572,8 @@ a.save(),this.properties.flipY&&(a.translate(0,this.size[1]),a.scale(1,-1)),a.dr a.unbind(0)),this.properties.name&&(c.storeTexture?c.storeTexture(this.properties.name,a):c.getTexturesContainer()[this.properties.name]=a),this._texture=a,this.setOutputData(0,a),this.setOutputData(1,this.properties.name))},N.registerNodeType("texture/save",r),t.widgets_info={uvcode:{widget:"code"},pixelcode:{widget:"code"},precision:{widget:"combo",values:c.MODE_VALUES}},t.title="Operation",t.desc="Texture shader operation",t.presets={},t.prototype.getExtraMenuOptions=function(a){var b=this;return[{content:b.properties.show? "Hide Texture":"Show Texture",callback:function(){b.properties.show=!b.properties.show}}]},t.prototype.onPropertyChanged=function(){this.has_error=!1},t.prototype.onDrawBackground=function(a){this.flags.collapsed||20>=this.size[1]||!this.properties.show||!this._tex||this._tex.gl!=a||(a.save(),a.drawImage(this._tex,0,0,this.size[0],this.size[1]),a.restore())},t.prototype.onExecute=function(){var a=this.getInputData(0);if(this.isOutputConnected(0))if(this.properties.precision===c.PASS_THROUGH)this.setOutputData(0, a);else{var b=this.getInputData(1);if(this.properties.uvcode||this.properties.pixelcode){var d=512,f=512;a?(d=a.width,f=a.height):b&&(d=b.width,f=b.height);b||(b=GL.Texture.getWhiteTexture());var g=c.getTextureType(this.properties.precision,a);this._tex=a||this._tex?c.getTargetTexture(a||this._tex,this._tex,this.properties.precision):new GL.Texture(d,f,{type:g,format:gl.RGBA,filter:gl.LINEAR});g="";this.properties.uvcode&&(g="uv = "+this.properties.uvcode,-1!=this.properties.uvcode.indexOf(";")&& -(g=this.properties.uvcode));var e="";this.properties.pixelcode&&(e="result = "+this.properties.pixelcode,-1!=this.properties.pixelcode.indexOf(";")&&(e=this.properties.pixelcode));var k=this._shader;if(!(this.has_error||k&&this._shader_code==g+"|"+e)){var m=c.replaceCode(t.pixel_shader,{UV_CODE:g,PIXEL_CODE:e});try{k=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,m),this.boxcolor="#00FF00"}catch(X){GL.Shader.dumpErrorToConsole(X,Shader.SCREEN_VERTEX_SHADER,m);this.boxcolor="#FF0000";this.has_error=!0; -return}this._shader=k;this._shader_code=g+"|"+e}if(this._shader){var h=this.getInputData(2);null!=h?this.properties.value=h:h=parseFloat(this.properties.value);var q=this.graph.getTime();this._tex.drawTo(function(){gl.disable(gl.DEPTH_TEST);gl.disable(gl.CULL_FACE);gl.disable(gl.BLEND);a&&a.bind(0);b&&b.bind(1);var c=Mesh.getScreenQuad();k.uniforms({u_texture:0,u_textureB:1,value:h,texSize:[d,f,1/d,1/f],time:q}).draw(c)});this.setOutputData(0,this._tex)}}}},t.pixel_shader="precision highp float;\n\t\t\n\t\tuniform sampler2D u_texture;\n\t\tuniform sampler2D u_textureB;\n\t\tvarying vec2 v_coord;\n\t\tuniform vec4 texSize;\n\t\tuniform float time;\n\t\tuniform float value;\n\t\t\n\t\tvoid main() {\n\t\t\tvec2 uv = v_coord;\n\t\t\t{{UV_CODE}};\n\t\t\tvec4 color4 = texture2D(u_texture, uv);\n\t\t\tvec3 color = color4.rgb;\n\t\t\tvec4 color4B = texture2D(u_textureB, uv);\n\t\t\tvec3 colorB = color4B.rgb;\n\t\t\tvec3 result = color;\n\t\t\tfloat alpha = 1.0;\n\t\t\t{{PIXEL_CODE}};\n\t\t\tgl_FragColor = vec4(result, alpha);\n\t\t}\n\t\t", +(g=this.properties.uvcode));var e="";this.properties.pixelcode&&(e="result = "+this.properties.pixelcode,-1!=this.properties.pixelcode.indexOf(";")&&(e=this.properties.pixelcode));var k=this._shader;if(!(this.has_error||k&&this._shader_code==g+"|"+e)){var h=c.replaceCode(t.pixel_shader,{UV_CODE:g,PIXEL_CODE:e});try{k=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,h),this.boxcolor="#00FF00"}catch(X){GL.Shader.dumpErrorToConsole(X,Shader.SCREEN_VERTEX_SHADER,h);this.boxcolor="#FF0000";this.has_error=!0; +return}this._shader=k;this._shader_code=g+"|"+e}if(this._shader){var m=this.getInputData(2);null!=m?this.properties.value=m:m=parseFloat(this.properties.value);var n=this.graph.getTime();this._tex.drawTo(function(){gl.disable(gl.DEPTH_TEST);gl.disable(gl.CULL_FACE);gl.disable(gl.BLEND);a&&a.bind(0);b&&b.bind(1);var c=Mesh.getScreenQuad();k.uniforms({u_texture:0,u_textureB:1,value:m,texSize:[d,f,1/d,1/f],time:n}).draw(c)});this.setOutputData(0,this._tex)}}}},t.pixel_shader="precision highp float;\n\t\t\n\t\tuniform sampler2D u_texture;\n\t\tuniform sampler2D u_textureB;\n\t\tvarying vec2 v_coord;\n\t\tuniform vec4 texSize;\n\t\tuniform float time;\n\t\tuniform float value;\n\t\t\n\t\tvoid main() {\n\t\t\tvec2 uv = v_coord;\n\t\t\t{{UV_CODE}};\n\t\t\tvec4 color4 = texture2D(u_texture, uv);\n\t\t\tvec3 color = color4.rgb;\n\t\t\tvec4 color4B = texture2D(u_textureB, uv);\n\t\t\tvec3 colorB = color4B.rgb;\n\t\t\tvec3 result = color;\n\t\t\tfloat alpha = 1.0;\n\t\t\t{{PIXEL_CODE}};\n\t\t\tgl_FragColor = vec4(result, alpha);\n\t\t}\n\t\t", t.registerPreset=function(a,b){t.presets[a]=b},t.registerPreset("",""),t.registerPreset("bypass","color"),t.registerPreset("add","color + colorB * value"),t.registerPreset("substract","(color - colorB) * value"),t.registerPreset("mate","mix( color, colorB, color4B.a * value)"),t.registerPreset("invert","vec3(1.0) - color"),t.registerPreset("multiply","color * colorB * value"),t.registerPreset("divide","(color / colorB) / value"),t.registerPreset("difference","abs(color - colorB) * value"),t.registerPreset("max", "max(color, colorB) * value"),t.registerPreset("min","min(color, colorB) * value"),t.registerPreset("displace","texture2D(u_texture, uv + (colorB.xy - vec2(0.5)) * value).xyz"),t.registerPreset("grayscale","vec3(color.x + color.y + color.z) * value / 3.0"),t.registerPreset("saturation","mix( vec3(color.x + color.y + color.z) / 3.0, color, value )"),t.registerPreset("normalmap","\n\t\tfloat z0 = texture2D(u_texture, uv + vec2(-texSize.z, -texSize.w) ).x;\n\t\tfloat z1 = texture2D(u_texture, uv + vec2(0.0, -texSize.w) ).x;\n\t\tfloat z2 = texture2D(u_texture, uv + vec2(texSize.z, -texSize.w) ).x;\n\t\tfloat z3 = texture2D(u_texture, uv + vec2(-texSize.z, 0.0) ).x;\n\t\tfloat z4 = color.x;\n\t\tfloat z5 = texture2D(u_texture, uv + vec2(texSize.z, 0.0) ).x;\n\t\tfloat z6 = texture2D(u_texture, uv + vec2(-texSize.z, texSize.w) ).x;\n\t\tfloat z7 = texture2D(u_texture, uv + vec2(0.0, texSize.w) ).x;\n\t\tfloat z8 = texture2D(u_texture, uv + vec2(texSize.z, texSize.w) ).x;\n\t\tvec3 normal = vec3( z2 + 2.0*z4 + z7 - z0 - 2.0*z3 - z5, z5 + 2.0*z6 + z7 -z0 - 2.0*z1 - z2, 1.0 );\n\t\tnormal.xy *= value;\n\t\tresult.xyz = normalize(normal) * 0.5 + vec3(0.5);\n\t"), t.registerPreset("threshold","vec3(color.x > colorB.x * value ? 1.0 : 0.0,color.y > colorB.y * value ? 1.0 : 0.0,color.z > colorB.z * value ? 1.0 : 0.0)"),t.prototype.onInspect=function(a){var b=this;a.addCombo("Presets","",{values:Object.keys(t.presets),callback:function(d){var c=t.presets[d];c&&(b.setProperty("pixelcode",c),b.title=d,a.refresh())}})},N.registerNodeType("texture/operation",t),v.title="Shader",v.desc="Texture shader",v.widgets_info={code:{type:"code",lang:"glsl"},precision:{widget:"combo", @@ -583,31 +584,31 @@ k.u_value=this.properties.u_value;k.u_color.set(this.properties.u_color);this._t N.registerNodeType("texture/shader",v),h.widgets_info={precision:{widget:"combo",values:c.MODE_VALUES}},h.title="Scale/Offset",h.desc="Applies an scaling and offseting",h.prototype.onExecute=function(){var a=this.getInputData(0);if(this.isOutputConnected(0)&&a)if(this.properties.precision===c.PASS_THROUGH)this.setOutputData(0,a);else{var b=a.width,d=a.height,f=this.precision===c.LOW?gl.UNSIGNED_BYTE:gl.HIGH_PRECISION_FORMAT;this.precision===c.DEFAULT&&(f=a.type);this._tex&&this._tex.width==b&&this._tex.height== d&&this._tex.type==f||(this._tex=new GL.Texture(b,d,{type:f,format:gl.RGBA,filter:gl.LINEAR}));var g=this._shader;g||(g=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,h.pixel_shader));var e=this.getInputData(1);e?(this.properties.scale[0]=e[0],this.properties.scale[1]=e[1]):e=this.properties.scale;var k=this.getInputData(2);k?(this.properties.offset[0]=k[0],this.properties.offset[1]=k[1]):k=this.properties.offset;this._tex.drawTo(function(){gl.disable(gl.DEPTH_TEST);gl.disable(gl.CULL_FACE);gl.disable(gl.BLEND); a.bind(0);var b=Mesh.getScreenQuad();g.uniforms({u_texture:0,u_scale:e,u_offset:k}).draw(b)});this.setOutputData(0,this._tex)}},h.pixel_shader="precision highp float;\n\t\t\n\t\tuniform sampler2D u_texture;\n\t\tuniform sampler2D u_textureB;\n\t\tvarying vec2 v_coord;\n\t\tuniform vec2 u_scale;\n\t\tuniform vec2 u_offset;\n\t\t\n\t\tvoid main() {\n\t\t\tvec2 uv = v_coord;\n\t\t\tuv = uv / u_scale - u_offset;\n\t\t\tgl_FragColor = texture2D(u_texture, uv);\n\t\t}\n\t\t",N.registerNodeType("texture/scaleOffset", -h),E.widgets_info={precision:{widget:"combo",values:c.MODE_VALUES}},E.title="Warp",E.desc="Texture warp operation",E.prototype.onExecute=function(){var a=this.getInputData(0);if(this.isOutputConnected(0))if(this.properties.precision===c.PASS_THROUGH)this.setOutputData(0,a);else{var b=this.getInputData(1),d=512,f=512;a?(d=a.width,f=a.height):b&&(d=b.width,f=b.height);this._tex=a||this._tex?c.getTargetTexture(a||this._tex,this._tex,this.properties.precision):new GL.Texture(d,f,{type:this.precision=== -c.LOW?gl.UNSIGNED_BYTE:gl.HIGH_PRECISION_FORMAT,format:gl.RGBA,filter:gl.LINEAR});var g=this._shader;g||(g=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,E.pixel_shader));d=this.getInputData(2);null!=d?this.properties.factor=d:d=parseFloat(this.properties.factor);var e=this._uniforms;e.u_factor=d;e.u_scale.set(this.properties.scale);e.u_offset.set(this.properties.offset);this._tex.drawTo(function(){gl.disable(gl.DEPTH_TEST);gl.disable(gl.CULL_FACE);gl.disable(gl.BLEND);a&&a.bind(0);b&&b.bind(1);var d= -Mesh.getScreenQuad();g.uniforms(e).draw(d)});this.setOutputData(0,this._tex)}},E.pixel_shader="precision highp float;\n\t\t\n\t\tuniform sampler2D u_texture;\n\t\tuniform sampler2D u_textureB;\n\t\tvarying vec2 v_coord;\n\t\tuniform float u_factor;\n\t\tuniform vec2 u_scale;\n\t\tuniform vec2 u_offset;\n\t\t\n\t\tvoid main() {\n\t\t\tvec2 uv = v_coord;\n\t\t\tuv += ( texture2D(u_textureB, uv).rg - vec2(0.5)) * u_factor * u_scale + u_offset;\n\t\t\tgl_FragColor = texture2D(u_texture, uv);\n\t\t}\n\t\t", -N.registerNodeType("texture/warp",E),A.title="to Viewport",A.desc="Texture to viewport",A._prev_viewport=new Float32Array(4),A.prototype.onDrawBackground=function(a){if(!(this.flags.collapsed||40>=this.size[1])){var b=this.getInputData(0);b&&a.drawImage(a==gl?b:gl.canvas,10,30,this.size[0]-20,this.size[1]-40)}},A.prototype.onExecute=function(){var a=this.getInputData(0);if(a){this.properties.disable_alpha?gl.disable(gl.BLEND):(gl.enable(gl.BLEND),this.properties.additive?gl.blendFunc(gl.SRC_ALPHA, -gl.ONE):gl.blendFunc(gl.SRC_ALPHA,gl.ONE_MINUS_SRC_ALPHA));gl.disable(gl.DEPTH_TEST);var b=this.properties.gamma||1;this.isInputConnected(1)&&(b=this.getInputData(1));a.setParameter(gl.TEXTURE_MAG_FILTER,this.properties.filter?gl.LINEAR:gl.NEAREST);var d=A._prev_viewport;d.set(gl.viewport_data);var c=this.properties.viewport;gl.viewport(d[0]+d[2]*c[0],d[1]+d[3]*c[1],d[2]*c[2],d[3]*c[3]);gl.getViewport();this.properties.antialiasing?(A._shader||(A._shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER, -A.aa_pixel_shader)),c=Mesh.getScreenQuad(),a.bind(0),A._shader.uniforms({u_texture:0,uViewportSize:[a.width,a.height],u_igamma:1/b,inverseVP:[1/a.width,1/a.height]}).draw(c)):1!=b?(A._gamma_shader||(A._gamma_shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,A.gamma_pixel_shader)),a.toViewport(A._gamma_shader,{u_texture:0,u_igamma:1/b})):a.toViewport();gl.viewport(d[0],d[1],d[2],d[3])}},A.prototype.onGetInputs=function(){return[["gamma","number"]]},A.aa_pixel_shader="precision highp float;\n\t\tprecision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuniform sampler2D u_texture;\n\t\tuniform vec2 uViewportSize;\n\t\tuniform vec2 inverseVP;\n\t\tuniform float u_igamma;\n\t\t#define FXAA_REDUCE_MIN (1.0/ 128.0)\n\t\t#define FXAA_REDUCE_MUL (1.0 / 8.0)\n\t\t#define FXAA_SPAN_MAX 8.0\n\t\t\n\t\t/* from mitsuhiko/webgl-meincraft based on the code on geeks3d.com */\n\t\tvec4 applyFXAA(sampler2D tex, vec2 fragCoord)\n\t\t{\n\t\t\tvec4 color = vec4(0.0);\n\t\t\t/*vec2 inverseVP = vec2(1.0 / uViewportSize.x, 1.0 / uViewportSize.y);*/\n\t\t\tvec3 rgbNW = texture2D(tex, (fragCoord + vec2(-1.0, -1.0)) * inverseVP).xyz;\n\t\t\tvec3 rgbNE = texture2D(tex, (fragCoord + vec2(1.0, -1.0)) * inverseVP).xyz;\n\t\t\tvec3 rgbSW = texture2D(tex, (fragCoord + vec2(-1.0, 1.0)) * inverseVP).xyz;\n\t\t\tvec3 rgbSE = texture2D(tex, (fragCoord + vec2(1.0, 1.0)) * inverseVP).xyz;\n\t\t\tvec3 rgbM = texture2D(tex, fragCoord * inverseVP).xyz;\n\t\t\tvec3 luma = vec3(0.299, 0.587, 0.114);\n\t\t\tfloat lumaNW = dot(rgbNW, luma);\n\t\t\tfloat lumaNE = dot(rgbNE, luma);\n\t\t\tfloat lumaSW = dot(rgbSW, luma);\n\t\t\tfloat lumaSE = dot(rgbSE, luma);\n\t\t\tfloat lumaM = dot(rgbM, luma);\n\t\t\tfloat lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));\n\t\t\tfloat lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));\n\t\t\t\n\t\t\tvec2 dir;\n\t\t\tdir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));\n\t\t\tdir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));\n\t\t\t\n\t\t\tfloat dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * FXAA_REDUCE_MUL), FXAA_REDUCE_MIN);\n\t\t\t\n\t\t\tfloat rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce);\n\t\t\tdir = min(vec2(FXAA_SPAN_MAX, FXAA_SPAN_MAX), max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX), dir * rcpDirMin)) * inverseVP;\n\t\t\t\n\t\t\tvec3 rgbA = 0.5 * (texture2D(tex, fragCoord * inverseVP + dir * (1.0 / 3.0 - 0.5)).xyz + \n\t\t\t\ttexture2D(tex, fragCoord * inverseVP + dir * (2.0 / 3.0 - 0.5)).xyz);\n\t\t\tvec3 rgbB = rgbA * 0.5 + 0.25 * (texture2D(tex, fragCoord * inverseVP + dir * -0.5).xyz + \n\t\t\t\ttexture2D(tex, fragCoord * inverseVP + dir * 0.5).xyz);\n\t\t\t\n\t\t\t//return vec4(rgbA,1.0);\n\t\t\tfloat lumaB = dot(rgbB, luma);\n\t\t\tif ((lumaB < lumaMin) || (lumaB > lumaMax))\n\t\t\t\tcolor = vec4(rgbA, 1.0);\n\t\t\telse\n\t\t\t\tcolor = vec4(rgbB, 1.0);\n\t\t\tif(u_igamma != 1.0)\n\t\t\t\tcolor.xyz = pow( color.xyz, vec3(u_igamma) );\n\t\t\treturn color;\n\t\t}\n\t\t\n\t\tvoid main() {\n\t\t gl_FragColor = applyFXAA( u_texture, v_coord * uViewportSize) ;\n\t\t}\n\t\t", -A.gamma_pixel_shader="precision highp float;\n\t\tprecision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuniform sampler2D u_texture;\n\t\tuniform float u_igamma;\n\t\tvoid main() {\n\t\t\tvec4 color = texture2D( u_texture, v_coord);\n\t\t\tcolor.xyz = pow(color.xyz, vec3(u_igamma) );\n\t\t gl_FragColor = color;\n\t\t}\n\t\t",N.registerNodeType("texture/toviewport",A),I.title="Copy",I.desc="Copy Texture",I.widgets_info={size:{widget:"combo",values:[0,32,64,128,256,512,1024,2048]},precision:{widget:"combo", +h),F.widgets_info={precision:{widget:"combo",values:c.MODE_VALUES}},F.title="Warp",F.desc="Texture warp operation",F.prototype.onExecute=function(){var a=this.getInputData(0);if(this.isOutputConnected(0))if(this.properties.precision===c.PASS_THROUGH)this.setOutputData(0,a);else{var b=this.getInputData(1),d=512,f=512;a?(d=a.width,f=a.height):b&&(d=b.width,f=b.height);this._tex=a||this._tex?c.getTargetTexture(a||this._tex,this._tex,this.properties.precision):new GL.Texture(d,f,{type:this.precision=== +c.LOW?gl.UNSIGNED_BYTE:gl.HIGH_PRECISION_FORMAT,format:gl.RGBA,filter:gl.LINEAR});var g=this._shader;g||(g=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,F.pixel_shader));d=this.getInputData(2);null!=d?this.properties.factor=d:d=parseFloat(this.properties.factor);var e=this._uniforms;e.u_factor=d;e.u_scale.set(this.properties.scale);e.u_offset.set(this.properties.offset);this._tex.drawTo(function(){gl.disable(gl.DEPTH_TEST);gl.disable(gl.CULL_FACE);gl.disable(gl.BLEND);a&&a.bind(0);b&&b.bind(1);var d= +Mesh.getScreenQuad();g.uniforms(e).draw(d)});this.setOutputData(0,this._tex)}},F.pixel_shader="precision highp float;\n\t\t\n\t\tuniform sampler2D u_texture;\n\t\tuniform sampler2D u_textureB;\n\t\tvarying vec2 v_coord;\n\t\tuniform float u_factor;\n\t\tuniform vec2 u_scale;\n\t\tuniform vec2 u_offset;\n\t\t\n\t\tvoid main() {\n\t\t\tvec2 uv = v_coord;\n\t\t\tuv += ( texture2D(u_textureB, uv).rg - vec2(0.5)) * u_factor * u_scale + u_offset;\n\t\t\tgl_FragColor = texture2D(u_texture, uv);\n\t\t}\n\t\t", +N.registerNodeType("texture/warp",F),C.title="to Viewport",C.desc="Texture to viewport",C._prev_viewport=new Float32Array(4),C.prototype.onDrawBackground=function(a){if(!(this.flags.collapsed||40>=this.size[1])){var b=this.getInputData(0);b&&a.drawImage(a==gl?b:gl.canvas,10,30,this.size[0]-20,this.size[1]-40)}},C.prototype.onExecute=function(){var a=this.getInputData(0);if(a){this.properties.disable_alpha?gl.disable(gl.BLEND):(gl.enable(gl.BLEND),this.properties.additive?gl.blendFunc(gl.SRC_ALPHA, +gl.ONE):gl.blendFunc(gl.SRC_ALPHA,gl.ONE_MINUS_SRC_ALPHA));gl.disable(gl.DEPTH_TEST);var b=this.properties.gamma||1;this.isInputConnected(1)&&(b=this.getInputData(1));a.setParameter(gl.TEXTURE_MAG_FILTER,this.properties.filter?gl.LINEAR:gl.NEAREST);var d=C._prev_viewport;d.set(gl.viewport_data);var c=this.properties.viewport;gl.viewport(d[0]+d[2]*c[0],d[1]+d[3]*c[1],d[2]*c[2],d[3]*c[3]);gl.getViewport();this.properties.antialiasing?(C._shader||(C._shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER, +C.aa_pixel_shader)),c=Mesh.getScreenQuad(),a.bind(0),C._shader.uniforms({u_texture:0,uViewportSize:[a.width,a.height],u_igamma:1/b,inverseVP:[1/a.width,1/a.height]}).draw(c)):1!=b?(C._gamma_shader||(C._gamma_shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,C.gamma_pixel_shader)),a.toViewport(C._gamma_shader,{u_texture:0,u_igamma:1/b})):a.toViewport();gl.viewport(d[0],d[1],d[2],d[3])}},C.prototype.onGetInputs=function(){return[["gamma","number"]]},C.aa_pixel_shader="precision highp float;\n\t\tprecision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuniform sampler2D u_texture;\n\t\tuniform vec2 uViewportSize;\n\t\tuniform vec2 inverseVP;\n\t\tuniform float u_igamma;\n\t\t#define FXAA_REDUCE_MIN (1.0/ 128.0)\n\t\t#define FXAA_REDUCE_MUL (1.0 / 8.0)\n\t\t#define FXAA_SPAN_MAX 8.0\n\t\t\n\t\t/* from mitsuhiko/webgl-meincraft based on the code on geeks3d.com */\n\t\tvec4 applyFXAA(sampler2D tex, vec2 fragCoord)\n\t\t{\n\t\t\tvec4 color = vec4(0.0);\n\t\t\t/*vec2 inverseVP = vec2(1.0 / uViewportSize.x, 1.0 / uViewportSize.y);*/\n\t\t\tvec3 rgbNW = texture2D(tex, (fragCoord + vec2(-1.0, -1.0)) * inverseVP).xyz;\n\t\t\tvec3 rgbNE = texture2D(tex, (fragCoord + vec2(1.0, -1.0)) * inverseVP).xyz;\n\t\t\tvec3 rgbSW = texture2D(tex, (fragCoord + vec2(-1.0, 1.0)) * inverseVP).xyz;\n\t\t\tvec3 rgbSE = texture2D(tex, (fragCoord + vec2(1.0, 1.0)) * inverseVP).xyz;\n\t\t\tvec3 rgbM = texture2D(tex, fragCoord * inverseVP).xyz;\n\t\t\tvec3 luma = vec3(0.299, 0.587, 0.114);\n\t\t\tfloat lumaNW = dot(rgbNW, luma);\n\t\t\tfloat lumaNE = dot(rgbNE, luma);\n\t\t\tfloat lumaSW = dot(rgbSW, luma);\n\t\t\tfloat lumaSE = dot(rgbSE, luma);\n\t\t\tfloat lumaM = dot(rgbM, luma);\n\t\t\tfloat lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));\n\t\t\tfloat lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));\n\t\t\t\n\t\t\tvec2 dir;\n\t\t\tdir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));\n\t\t\tdir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));\n\t\t\t\n\t\t\tfloat dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * FXAA_REDUCE_MUL), FXAA_REDUCE_MIN);\n\t\t\t\n\t\t\tfloat rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce);\n\t\t\tdir = min(vec2(FXAA_SPAN_MAX, FXAA_SPAN_MAX), max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX), dir * rcpDirMin)) * inverseVP;\n\t\t\t\n\t\t\tvec3 rgbA = 0.5 * (texture2D(tex, fragCoord * inverseVP + dir * (1.0 / 3.0 - 0.5)).xyz + \n\t\t\t\ttexture2D(tex, fragCoord * inverseVP + dir * (2.0 / 3.0 - 0.5)).xyz);\n\t\t\tvec3 rgbB = rgbA * 0.5 + 0.25 * (texture2D(tex, fragCoord * inverseVP + dir * -0.5).xyz + \n\t\t\t\ttexture2D(tex, fragCoord * inverseVP + dir * 0.5).xyz);\n\t\t\t\n\t\t\t//return vec4(rgbA,1.0);\n\t\t\tfloat lumaB = dot(rgbB, luma);\n\t\t\tif ((lumaB < lumaMin) || (lumaB > lumaMax))\n\t\t\t\tcolor = vec4(rgbA, 1.0);\n\t\t\telse\n\t\t\t\tcolor = vec4(rgbB, 1.0);\n\t\t\tif(u_igamma != 1.0)\n\t\t\t\tcolor.xyz = pow( color.xyz, vec3(u_igamma) );\n\t\t\treturn color;\n\t\t}\n\t\t\n\t\tvoid main() {\n\t\t gl_FragColor = applyFXAA( u_texture, v_coord * uViewportSize) ;\n\t\t}\n\t\t", +C.gamma_pixel_shader="precision highp float;\n\t\tprecision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuniform sampler2D u_texture;\n\t\tuniform float u_igamma;\n\t\tvoid main() {\n\t\t\tvec4 color = texture2D( u_texture, v_coord);\n\t\t\tcolor.xyz = pow(color.xyz, vec3(u_igamma) );\n\t\t gl_FragColor = color;\n\t\t}\n\t\t",N.registerNodeType("texture/toviewport",C),I.title="Copy",I.desc="Copy Texture",I.widgets_info={size:{widget:"combo",values:[0,32,64,128,256,512,1024,2048]},precision:{widget:"combo", values:c.MODE_VALUES}},I.prototype.onExecute=function(){var a=this.getInputData(0);if((a||this._temp_texture)&&this.isOutputConnected(0)){if(a){var b=a.width,d=a.height;0!=this.properties.size&&(d=b=this.properties.size);var f=this._temp_texture,g=a.type;this.properties.precision===c.LOW?g=gl.UNSIGNED_BYTE:this.properties.precision===c.HIGH&&(g=gl.HIGH_PRECISION_FORMAT);f&&f.width==b&&f.height==d&&f.type==g||(f=gl.LINEAR,this.properties.generate_mipmaps&&isPowerOfTwo(b)&&isPowerOfTwo(d)&&(f=gl.LINEAR_MIPMAP_LINEAR), this._temp_texture=new GL.Texture(b,d,{type:g,format:gl.RGBA,minFilter:f,magFilter:gl.LINEAR}));a.copyTo(this._temp_texture);this.properties.generate_mipmaps&&(this._temp_texture.bind(0),gl.generateMipmap(this._temp_texture.texture_type),this._temp_texture.unbind(0))}this.setOutputData(0,this._temp_texture)}},N.registerNodeType("texture/copy",I),J.title="Downsample",J.desc="Downsample Texture",J.widgets_info={iterations:{type:"number",step:1,precision:0,min:0},precision:{widget:"combo",values:c.MODE_VALUES}}, -J.prototype.onExecute=function(){var a=this.getInputData(0);if((a||this._temp_texture)&&this.isOutputConnected(0)&&a&&a.texture_type===GL.TEXTURE_2D)if(1>this.properties.iterations)this.setOutputData(0,a);else{var b=J._shader;b||(J._shader=b=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,J.pixel_shader));var d=a.width|0,f=a.height|0,g=a.type;this.properties.precision===c.LOW?g=gl.UNSIGNED_BYTE:this.properties.precision===c.HIGH&&(g=gl.HIGH_PRECISION_FORMAT);var e=this.properties.iterations||1,k=a,m= -[];g={type:g,format:a.format};var h=vec2.create(),q={u_offset:h};this._texture&&GL.Texture.releaseTemporary(this._texture);for(var n=0;n>1||0;f=f>>1||0;a=GL.Texture.getTemporary(d,f,g);m.push(a);k.setParameter(GL.TEXTURE_MAG_FILTER,GL.NEAREST);k.copyTo(a,b,q);if(1==d&&1==f)break;k=a}this._texture=m.pop();for(n=0;nthis.properties.iterations)this.setOutputData(0,a);else{var b=J._shader;b||(J._shader=b=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,J.pixel_shader));var d=a.width|0,f=a.height|0,g=a.type;this.properties.precision===c.LOW?g=gl.UNSIGNED_BYTE:this.properties.precision===c.HIGH&&(g=gl.HIGH_PRECISION_FORMAT);var e=this.properties.iterations||1,k=a,h= +[];g={type:g,format:a.format};var m=vec2.create(),n={u_offset:m};this._texture&&GL.Texture.releaseTemporary(this._texture);for(var q=0;q>1||0;f=f>>1||0;a=GL.Texture.getTemporary(d,f,g);h.push(a);k.setParameter(GL.TEXTURE_MAG_FILTER,GL.NEAREST);k.copyTo(a,b,n);if(1==d&&1==f)break;k=a}this._texture=h.pop();for(q=0;qc;c++)this.isOutputConnected(c)?(this._channels[c]&&this._channels[c].width==a.width&&this._channels[c].height==a.height&&this._channels[c].type==a.type&&this._channels[c].format==b||(this._channels[c]=new GL.Texture(a.width,a.height,{type:a.type,format:b,filter:gl.LINEAR})), d++):this._channels[c]=null;if(d){gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var f=Mesh.getScreenQuad(),g=n._shader,e=[[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]];for(c=0;4>c;c++)this._channels[c]&&(this._channels[c].drawTo(function(){a.bind(0);g.uniforms({u_texture:0,u_mask:e[c]}).draw(f)}),this.setOutputData(c,this._channels[c]))}}},n.pixel_shader="precision highp float;\n\t\tprecision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuniform sampler2D u_texture;\n\t\tuniform vec4 u_mask;\n\t\t\n\t\tvoid main() {\n\t\t gl_FragColor = vec4( vec3( length( texture2D(u_texture, v_coord) * u_mask )), 1.0 );\n\t\t}\n\t\t", N.registerNodeType("texture/textureChannels",n),q.title="Channels to Texture",q.desc="Split texture channels",q.widgets_info={precision:{widget:"combo",values:c.MODE_VALUES}},q.prototype.onExecute=function(){var a=c.getWhiteTexture(),b=this.getInputData(0)||a,d=this.getInputData(1)||a,f=this.getInputData(2)||a,g=this.getInputData(3)||a;gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var e=Mesh.getScreenQuad();q._shader||(q._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,q.pixel_shader));var k=q._shader; -a=Math.max(b.width,d.width,f.width,g.width);var m=Math.max(b.height,d.height,f.height,g.height),h=this.properties.precision==c.HIGH?c.HIGH_PRECISION_FORMAT:gl.UNSIGNED_BYTE;this._texture&&this._texture.width==a&&this._texture.height==m&&this._texture.type==h||(this._texture=new GL.Texture(a,m,{type:h,format:gl.RGBA,filter:gl.LINEAR}));a=this._color;a[0]=this.properties.R;a[1]=this.properties.G;a[2]=this.properties.B;a[3]=this.properties.A;var n=this._uniforms;this._texture.drawTo(function(){b.bind(0); +a=Math.max(b.width,d.width,f.width,g.width);var h=Math.max(b.height,d.height,f.height,g.height),m=this.properties.precision==c.HIGH?c.HIGH_PRECISION_FORMAT:gl.UNSIGNED_BYTE;this._texture&&this._texture.width==a&&this._texture.height==h&&this._texture.type==m||(this._texture=new GL.Texture(a,h,{type:m,format:gl.RGBA,filter:gl.LINEAR}));a=this._color;a[0]=this.properties.R;a[1]=this.properties.G;a[2]=this.properties.B;a[3]=this.properties.A;var n=this._uniforms;this._texture.drawTo(function(){b.bind(0); d.bind(1);f.bind(2);g.bind(3);k.uniforms(n).draw(e)});this.setOutputData(0,this._texture)},q.pixel_shader="precision highp float;\n\t\tprecision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuniform sampler2D u_textureR;\n\t\tuniform sampler2D u_textureG;\n\t\tuniform sampler2D u_textureB;\n\t\tuniform sampler2D u_textureA;\n\t\tuniform vec4 u_color;\n\t\t\n\t\tvoid main() {\n\t\t gl_FragColor = u_color * vec4( \t\t\t\t\ttexture2D(u_textureR, v_coord).r,\t\t\t\t\ttexture2D(u_textureG, v_coord).r,\t\t\t\t\ttexture2D(u_textureB, v_coord).r,\t\t\t\t\ttexture2D(u_textureA, v_coord).r);\n\t\t}\n\t\t", N.registerNodeType("texture/channelsTexture",q),a.title="Color",a.desc="Generates a 1x1 texture with a constant color",a.widgets_info={precision:{widget:"combo",values:c.MODE_VALUES}},a.prototype.onDrawBackground=function(a){var b=this.properties.color;a.fillStyle="rgb("+Math.floor(255*Math.clamp(b[0],0,1))+","+Math.floor(255*Math.clamp(b[1],0,1))+","+Math.floor(255*Math.clamp(b[2],0,1))+")";this.flags.collapsed?this.boxcolor=a.fillStyle:a.fillRect(0,0,this.size[0],this.size[1])},a.prototype.onExecute= function(){var a=this.properties.precision==c.HIGH?c.HIGH_PRECISION_FORMAT:gl.UNSIGNED_BYTE;this._tex&&this._tex.type==a||(this._tex=new GL.Texture(1,1,{format:gl.RGBA,type:a,minFilter:gl.NEAREST}));a=this.properties.color;if(this.inputs)for(var b=0;ba.width?b: -a,this._tex,this.properties.precision);gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var e=Mesh.getScreenQuad(),k=null,m=this._uniforms;f?(k=d._shader_tex,k||(k=d._shader_tex=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,d.pixel_shader,{MIX_TEX:""}))):(k=d._shader_factor,k||(k=d._shader_factor=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,d.pixel_shader)),g=null==g?this.properties.factor:g,m.u_mix.set([g,g,g,g]));var h=this.properties.invert;this._tex.drawTo(function(){a.bind(h?1:0);b.bind(h?0:1);f&&f.bind(2); -k.uniforms(m).draw(e)});this.setOutputData(0,this._tex)}}},d.prototype.onGetInputs=function(){return[["factor","number"]]},d.pixel_shader="precision highp float;\n\t\tprecision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuniform sampler2D u_textureA;\n\t\tuniform sampler2D u_textureB;\n\t\t#ifdef MIX_TEX\n\t\t\tuniform sampler2D u_textureMix;\n\t\t#else\n\t\t\tuniform vec4 u_mix;\n\t\t#endif\n\t\t\n\t\tvoid main() {\n\t\t\t#ifdef MIX_TEX\n\t\t\t vec4 f = texture2D(u_textureMix, v_coord);\n\t\t\t#else\n\t\t\t vec4 f = u_mix;\n\t\t\t#endif\n\t\t gl_FragColor = mix( texture2D(u_textureA, v_coord), texture2D(u_textureB, v_coord), f );\n\t\t}\n\t\t", +a,this._tex,this.properties.precision);gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var e=Mesh.getScreenQuad(),k=null,h=this._uniforms;f?(k=d._shader_tex,k||(k=d._shader_tex=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,d.pixel_shader,{MIX_TEX:""}))):(k=d._shader_factor,k||(k=d._shader_factor=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,d.pixel_shader)),g=null==g?this.properties.factor:g,h.u_mix.set([g,g,g,g]));var m=this.properties.invert;this._tex.drawTo(function(){a.bind(m?1:0);b.bind(m?0:1);f&&f.bind(2); +k.uniforms(h).draw(e)});this.setOutputData(0,this._tex)}}},d.prototype.onGetInputs=function(){return[["factor","number"]]},d.pixel_shader="precision highp float;\n\t\tprecision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuniform sampler2D u_textureA;\n\t\tuniform sampler2D u_textureB;\n\t\t#ifdef MIX_TEX\n\t\t\tuniform sampler2D u_textureMix;\n\t\t#else\n\t\t\tuniform vec4 u_mix;\n\t\t#endif\n\t\t\n\t\tvoid main() {\n\t\t\t#ifdef MIX_TEX\n\t\t\t vec4 f = texture2D(u_textureMix, v_coord);\n\t\t\t#else\n\t\t\t vec4 f = u_mix;\n\t\t\t#endif\n\t\t gl_FragColor = mix( texture2D(u_textureA, v_coord), texture2D(u_textureB, v_coord), f );\n\t\t}\n\t\t", N.registerNodeType("texture/mix",d),g.title="Edges",g.desc="Detects edges",g.widgets_info={precision:{widget:"combo",values:c.MODE_VALUES}},g.prototype.onExecute=function(){if(this.isOutputConnected(0)){var a=this.getInputData(0);if(this.properties.precision===c.PASS_THROUGH)this.setOutputData(0,a);else if(a){this._tex=c.getTargetTexture(a,this._tex,this.properties.precision);gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var b=Mesh.getScreenQuad(),d=g._shader,f=this.properties.invert,e=this.properties.factor, k=this.properties.threshold?1:0;this._tex.drawTo(function(){a.bind(0);d.uniforms({u_texture:0,u_isize:[1/a.width,1/a.height],u_factor:e,u_threshold:k,u_invert:f?1:0}).draw(b)});this.setOutputData(0,this._tex)}}},g.pixel_shader="precision highp float;\n\t\tprecision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuniform sampler2D u_texture;\n\t\tuniform vec2 u_isize;\n\t\tuniform int u_invert;\n\t\tuniform float u_factor;\n\t\tuniform float u_threshold;\n\t\t\n\t\tvoid main() {\n\t\t\tvec4 center = texture2D(u_texture, v_coord);\n\t\t\tvec4 up = texture2D(u_texture, v_coord + u_isize * vec2(0.0,1.0) );\n\t\t\tvec4 down = texture2D(u_texture, v_coord + u_isize * vec2(0.0,-1.0) );\n\t\t\tvec4 left = texture2D(u_texture, v_coord + u_isize * vec2(1.0,0.0) );\n\t\t\tvec4 right = texture2D(u_texture, v_coord + u_isize * vec2(-1.0,0.0) );\n\t\t\tvec4 diff = abs(center - up) + abs(center - down) + abs(center - left) + abs(center - right);\n\t\t\tdiff *= u_factor;\n\t\t\tif(u_invert == 1)\n\t\t\t\tdiff.xyz = vec3(1.0) - diff.xyz;\n\t\t\tif( u_threshold == 0.0 )\n\t\t\t\tgl_FragColor = vec4( diff.xyz, center.a );\n\t\t\telse\n\t\t\t\tgl_FragColor = vec4( diff.x > 0.5 ? 1.0 : 0.0, diff.y > 0.5 ? 1.0 : 0.0, diff.z > 0.5 ? 1.0 : 0.0, center.a );\n\t\t}\n\t\t", N.registerNodeType("texture/edges",g),f.title="Depth Range",f.desc="Generates a texture with a depth range",f.prototype.onExecute=function(){if(this.isOutputConnected(0)){var a=this.getInputData(0);if(a){var b=gl.UNSIGNED_BYTE;this.properties.high_precision&&(b=gl.half_float_ext?gl.HALF_FLOAT_OES:gl.FLOAT);this._temp_texture&&this._temp_texture.type==b&&this._temp_texture.width==a.width&&this._temp_texture.height==a.height||(this._temp_texture=new GL.Texture(a.width,a.height,{type:b,format:gl.RGBA, @@ -638,10 +639,10 @@ this._temp_texture.height==a.height||(this._temp_texture=new GL.Texture(a.width, d.u_camera_planes=b;d.u_ires.set([0,0]);this._temp_texture.drawTo(function(){a.bind(0);g.uniforms(d).draw(f)});this._temp_texture.near_far_planes=b;this.setOutputData(0,this._temp_texture)}}},m.pixel_shader="precision highp float;\n\t\tprecision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuniform sampler2D u_texture;\n\t\tuniform vec2 u_camera_planes;\n\t\tuniform int u_invert;\n\t\tuniform vec2 u_ires;\n\t\t\n\t\tvoid main() {\n\t\t\tfloat zNear = u_camera_planes.x;\n\t\t\tfloat zFar = u_camera_planes.y;\n\t\t\tfloat depth = texture2D(u_texture, v_coord + u_ires*0.5).x * 2.0 - 1.0;\n\t\t\tfloat f = zNear * (depth + 1.0) / (zFar + zNear - depth * (zFar - zNear));\n\t\t\tif( u_invert == 1 )\n\t\t\t\tf = 1.0 - f;\n\t\t\tgl_FragColor = vec4(vec3(f),1.0);\n\t\t}\n\t\t", N.registerNodeType("texture/linear_depth",m),u.title="Blur",u.desc="Blur a texture",u.widgets_info={precision:{widget:"combo",values:c.MODE_VALUES}},u.max_iterations=20,u.prototype.onExecute=function(){var a=this.getInputData(0);if(a&&this.isOutputConnected(0)){var b=this._final_texture;b&&b.width==a.width&&b.height==a.height&&b.type==a.type||(b=this._final_texture=new GL.Texture(a.width,a.height,{type:a.type,format:gl.RGBA,filter:gl.LINEAR}));var d=this.properties.iterations;this.isInputConnected(1)&& (d=this.getInputData(1),this.properties.iterations=d);d=Math.min(Math.floor(d),u.max_iterations);if(0==d)this.setOutputData(0,a);else{var c=this.properties.intensity;this.isInputConnected(2)&&(c=this.getInputData(2),this.properties.intensity=c);var f=N.camera_aspect;f||void 0===window.gl||(f=gl.canvas.height/gl.canvas.width);f||(f=1);f=this.properties.preserve_aspect?f:1;var g=this.properties.scale||[1,1];a.applyBlur(f*g[0],g[1],c,b);for(a=1;a>=1;1<(g|0)&&(g>>=1);if(2>f)break;q=m[u]=GL.Texture.getTemporary(f,g,e);l[0]=1/n.width;l[1]=1/n.height;n.blit(q,h.uniforms(k));n=q}c&&(l[0]=1/n.width,l[1]=1/n.height,k.u_intensity=G,k.u_delta=1,n.blit(c,h.uniforms(k)));gl.enable(gl.BLEND);gl.blendFunc(gl.ONE,gl.ONE);k.u_intensity=this.persistence; -k.u_delta=.5;for(u-=2;0<=u;u--)q=m[u],m[u]=null,l[0]=1/n.width,l[1]=1/n.height,n.blit(q,h.uniforms(k)),GL.Texture.releaseTemporary(n),n=q;gl.disable(gl.BLEND);d&&n.blit(d);if(b){var t=this.dirt_texture,w=this.dirt_factor;k.u_intensity=G;h=t?O._dirt_final_shader:O._final_shader;h||(h=t?O._dirt_final_shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,O.final_pixel_shader,{USE_DIRT:""}):O._final_shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,O.final_pixel_shader));b.drawTo(function(){a.bind(0); -n.bind(1);t&&(h.setUniform("u_dirt_factor",w),h.setUniform("u_dirt_texture",t.bind(2)));h.toViewport(k)})}GL.Texture.releaseTemporary(n)},O.cut_pixel_shader="precision highp float;\n\tvarying vec2 v_coord;\n\tuniform sampler2D u_texture;\n\tuniform float u_threshold;\n\tvoid main() {\n\t\tgl_FragColor = max( texture2D( u_texture, v_coord ) - vec4( u_threshold ), vec4(0.0) );\n\t}",O.scale_pixel_shader="precision highp float;\n\tvarying vec2 v_coord;\n\tuniform sampler2D u_texture;\n\tuniform vec2 u_texel_size;\n\tuniform float u_delta;\n\tuniform float u_intensity;\n\t\n\tvec4 sampleBox(vec2 uv) {\n\t\tvec4 o = u_texel_size.xyxy * vec2(-u_delta, u_delta).xxyy;\n\t\tvec4 s = texture2D( u_texture, uv + o.xy ) + texture2D( u_texture, uv + o.zy) + texture2D( u_texture, uv + o.xw) + texture2D( u_texture, uv + o.zw);\n\t\treturn s * 0.25;\n\t}\n\tvoid main() {\n\t\tgl_FragColor = u_intensity * sampleBox( v_coord );\n\t}", +b)}}},N.registerNodeType("texture/blur",u),O.prototype.applyFX=function(a,b,d,c){var f=a.width,g=a.height,e={format:a.format,type:a.type,minFilter:GL.LINEAR,magFilter:GL.LINEAR,wrap:gl.CLAMP_TO_EDGE},k=this._uniforms,h=this._textures,m=O._cut_shader;m||(m=O._cut_shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,O.cut_pixel_shader));gl.disable(gl.DEPTH_TEST);gl.disable(gl.BLEND);k.u_threshold=this.threshold;var n=h[0]=GL.Texture.getTemporary(f,g,e);a.blit(n,m.uniforms(k));var q=n,y=this.iterations; +y=Math.clamp(y,1,16)|0;var l=k.u_texel_size,H=this.intensity;k.u_intensity=1;k.u_delta=this.scale;m=O._shader;m||(m=O._shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,O.scale_pixel_shader));for(var u=1;u>=1;1<(g|0)&&(g>>=1);if(2>f)break;n=h[u]=GL.Texture.getTemporary(f,g,e);l[0]=1/q.width;l[1]=1/q.height;q.blit(n,m.uniforms(k));q=n}c&&(l[0]=1/q.width,l[1]=1/q.height,k.u_intensity=H,k.u_delta=1,q.blit(c,m.uniforms(k)));gl.enable(gl.BLEND);gl.blendFunc(gl.ONE,gl.ONE);k.u_intensity=this.persistence; +k.u_delta=.5;for(u-=2;0<=u;u--)n=h[u],h[u]=null,l[0]=1/q.width,l[1]=1/q.height,q.blit(n,m.uniforms(k)),GL.Texture.releaseTemporary(q),q=n;gl.disable(gl.BLEND);d&&q.blit(d);if(b){var t=this.dirt_texture,w=this.dirt_factor;k.u_intensity=H;m=t?O._dirt_final_shader:O._final_shader;m||(m=t?O._dirt_final_shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,O.final_pixel_shader,{USE_DIRT:""}):O._final_shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,O.final_pixel_shader));b.drawTo(function(){a.bind(0); +q.bind(1);t&&(m.setUniform("u_dirt_factor",w),m.setUniform("u_dirt_texture",t.bind(2)));m.toViewport(k)})}GL.Texture.releaseTemporary(q)},O.cut_pixel_shader="precision highp float;\n\tvarying vec2 v_coord;\n\tuniform sampler2D u_texture;\n\tuniform float u_threshold;\n\tvoid main() {\n\t\tgl_FragColor = max( texture2D( u_texture, v_coord ) - vec4( u_threshold ), vec4(0.0) );\n\t}",O.scale_pixel_shader="precision highp float;\n\tvarying vec2 v_coord;\n\tuniform sampler2D u_texture;\n\tuniform vec2 u_texel_size;\n\tuniform float u_delta;\n\tuniform float u_intensity;\n\t\n\tvec4 sampleBox(vec2 uv) {\n\t\tvec4 o = u_texel_size.xyxy * vec2(-u_delta, u_delta).xxyy;\n\t\tvec4 s = texture2D( u_texture, uv + o.xy ) + texture2D( u_texture, uv + o.zy) + texture2D( u_texture, uv + o.xw) + texture2D( u_texture, uv + o.zw);\n\t\treturn s * 0.25;\n\t}\n\tvoid main() {\n\t\tgl_FragColor = u_intensity * sampleBox( v_coord );\n\t}", O.final_pixel_shader="precision highp float;\n\tvarying vec2 v_coord;\n\tuniform sampler2D u_texture;\n\tuniform sampler2D u_glow_texture;\n\t#ifdef USE_DIRT\n\t\tuniform sampler2D u_dirt_texture;\n\t#endif\n\tuniform vec2 u_texel_size;\n\tuniform float u_delta;\n\tuniform float u_intensity;\n\tuniform float u_dirt_factor;\n\t\n\tvec4 sampleBox(vec2 uv) {\n\t\tvec4 o = u_texel_size.xyxy * vec2(-u_delta, u_delta).xxyy;\n\t\tvec4 s = texture2D( u_glow_texture, uv + o.xy ) + texture2D( u_glow_texture, uv + o.zy) + texture2D( u_glow_texture, uv + o.xw) + texture2D( u_glow_texture, uv + o.zw);\n\t\treturn s * 0.25;\n\t}\n\tvoid main() {\n\t\tvec4 glow = sampleBox( v_coord );\n\t\t#ifdef USE_DIRT\n\t\t\tglow = mix( glow, glow * texture2D( u_dirt_texture, v_coord ), u_dirt_factor );\n\t\t#endif\n\t\tgl_FragColor = texture2D( u_texture, v_coord ) + u_intensity * glow;\n\t}", K.title="Glow",K.desc="Filters a texture giving it a glow effect",K.widgets_info={iterations:{type:"number",min:0,max:16,step:1,precision:0},threshold:{type:"number",min:0,max:10,step:.01,precision:2},precision:{widget:"combo",values:c.MODE_VALUES}},K.prototype.onGetInputs=function(){return[["enabled","boolean"],["threshold","number"],["intensity","number"],["persistence","number"],["iterations","number"],["dirt_factor","number"]]},K.prototype.onGetOutputs=function(){return[["average","Texture"]]}, K.prototype.onExecute=function(){var a=this.getInputData(0);if(a&&this.isAnyOutputConnected())if(this.properties.precision===c.PASS_THROUGH||!1===this.getInputOrProperty("enabled"))this.setOutputData(0,a);else{var b=this.fx;b.threshold=this.getInputOrProperty("threshold");b.iterations=this.getInputOrProperty("iterations");b.intensity=this.getInputOrProperty("intensity");b.persistence=this.getInputOrProperty("persistence");b.dirt_texture=this.getInputData(1);b.dirt_factor=this.getInputOrProperty("dirt_factor"); @@ -649,17 +650,17 @@ b.scale=this.properties.scale;var d=c.getTextureType(this.properties.precision,a var e=null;this.isOutputConnected(0)&&(e=this._final_texture,e&&e.width==a.width&&e.height==a.height&&e.type==d&&e.format==a.format||(e=this._final_texture=new GL.Texture(a.width,a.height,{type:d,format:a.format,filter:gl.LINEAR})));b.applyFX(a,e,g,f);this.isOutputConnected(0)&&this.setOutputData(0,e);this.isOutputConnected(1)&&this.setOutputData(1,f);this.isOutputConnected(2)&&this.setOutputData(2,g)}},N.registerNodeType("texture/glow",K),x.title="Kuwahara Filter",x.desc="Filters a texture giving an artistic oil canvas painting", x.max_radius=10,x._shaders=[],x.prototype.onExecute=function(){var a=this.getInputData(0);if(a&&this.isOutputConnected(0)){var b=this._temp_texture;b&&b.width==a.width&&b.height==a.height&&b.type==a.type||(this._temp_texture=new GL.Texture(a.width,a.height,{type:a.type,format:gl.RGBA,filter:gl.LINEAR}));b=this.properties.radius;b=Math.min(Math.floor(b),x.max_radius);if(0==b)this.setOutputData(0,a);else{var d=this.properties.intensity,c=N.camera_aspect;c||void 0===window.gl||(c=gl.canvas.height/gl.canvas.width); c||(c=1);c=this.properties.preserve_aspect?c:1;x._shaders[b]||(x._shaders[b]=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,x.pixel_shader,{RADIUS:b.toFixed(0)}));var f=x._shaders[b],g=GL.Mesh.getScreenQuad();a.bind(0);this._temp_texture.drawTo(function(){f.uniforms({u_texture:0,u_intensity:d,u_resolution:[a.width,a.height],u_iResolution:[1/a.width,1/a.height]}).draw(g)});this.setOutputData(0,this._temp_texture)}}},x.pixel_shader="\nprecision highp float;\nvarying vec2 v_coord;\nuniform sampler2D u_texture;\nuniform float u_intensity;\nuniform vec2 u_resolution;\nuniform vec2 u_iResolution;\n#ifndef RADIUS\n\t#define RADIUS 7\n#endif\nvoid main() {\n\n\tconst int radius = RADIUS;\n\tvec2 fragCoord = v_coord;\n\tvec2 src_size = u_iResolution;\n\tvec2 uv = v_coord;\n\tfloat n = float((radius + 1) * (radius + 1));\n\tint i;\n\tint j;\n\tvec3 m0 = vec3(0.0); vec3 m1 = vec3(0.0); vec3 m2 = vec3(0.0); vec3 m3 = vec3(0.0);\n\tvec3 s0 = vec3(0.0); vec3 s1 = vec3(0.0); vec3 s2 = vec3(0.0); vec3 s3 = vec3(0.0);\n\tvec3 c;\n\t\n\tfor (int j = -radius; j <= 0; ++j) {\n\t\tfor (int i = -radius; i <= 0; ++i) {\n\t\t\tc = texture2D(u_texture, uv + vec2(i,j) * src_size).rgb;\n\t\t\tm0 += c;\n\t\t\ts0 += c * c;\n\t\t}\n\t}\n\t\n\tfor (int j = -radius; j <= 0; ++j) {\n\t\tfor (int i = 0; i <= radius; ++i) {\n\t\t\tc = texture2D(u_texture, uv + vec2(i,j) * src_size).rgb;\n\t\t\tm1 += c;\n\t\t\ts1 += c * c;\n\t\t}\n\t}\n\t\n\tfor (int j = 0; j <= radius; ++j) {\n\t\tfor (int i = 0; i <= radius; ++i) {\n\t\t\tc = texture2D(u_texture, uv + vec2(i,j) * src_size).rgb;\n\t\t\tm2 += c;\n\t\t\ts2 += c * c;\n\t\t}\n\t}\n\t\n\tfor (int j = 0; j <= radius; ++j) {\n\t\tfor (int i = -radius; i <= 0; ++i) {\n\t\t\tc = texture2D(u_texture, uv + vec2(i,j) * src_size).rgb;\n\t\t\tm3 += c;\n\t\t\ts3 += c * c;\n\t\t}\n\t}\n\t\n\tfloat min_sigma2 = 1e+2;\n\tm0 /= n;\n\ts0 = abs(s0 / n - m0 * m0);\n\t\n\tfloat sigma2 = s0.r + s0.g + s0.b;\n\tif (sigma2 < min_sigma2) {\n\t\tmin_sigma2 = sigma2;\n\t\tgl_FragColor = vec4(m0, 1.0);\n\t}\n\t\n\tm1 /= n;\n\ts1 = abs(s1 / n - m1 * m1);\n\t\n\tsigma2 = s1.r + s1.g + s1.b;\n\tif (sigma2 < min_sigma2) {\n\t\tmin_sigma2 = sigma2;\n\t\tgl_FragColor = vec4(m1, 1.0);\n\t}\n\t\n\tm2 /= n;\n\ts2 = abs(s2 / n - m2 * m2);\n\t\n\tsigma2 = s2.r + s2.g + s2.b;\n\tif (sigma2 < min_sigma2) {\n\t\tmin_sigma2 = sigma2;\n\t\tgl_FragColor = vec4(m2, 1.0);\n\t}\n\t\n\tm3 /= n;\n\ts3 = abs(s3 / n - m3 * m3);\n\t\n\tsigma2 = s3.r + s3.g + s3.b;\n\tif (sigma2 < min_sigma2) {\n\t\tmin_sigma2 = sigma2;\n\t\tgl_FragColor = vec4(m3, 1.0);\n\t}\n}\n", -N.registerNodeType("texture/kuwahara",x),C.title="XDoG Filter",C.desc="Filters a texture giving an artistic ink style",C.max_radius=10,C._shaders=[],C.prototype.onExecute=function(){var a=this.getInputData(0);if(a&&this.isOutputConnected(0)){var b=this._temp_texture;b&&b.width==a.width&&b.height==a.height&&b.type==a.type||(this._temp_texture=new GL.Texture(a.width,a.height,{type:a.type,format:gl.RGBA,filter:gl.LINEAR}));C._xdog_shader||(C._xdog_shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,C.xdog_pixel_shader)); -var d=C._xdog_shader,c=GL.Mesh.getScreenQuad(),f=this.properties.sigma,g=this.properties.k,e=this.properties.p,k=this.properties.epsilon,m=this.properties.phi;a.bind(0);this._temp_texture.drawTo(function(){d.uniforms({src:0,sigma:f,k:g,p:e,epsilon:k,phi:m,cvsWidth:a.width,cvsHeight:a.height}).draw(c)});this.setOutputData(0,this._temp_texture)}},C.xdog_pixel_shader="\nprecision highp float;\nuniform sampler2D src;\n\nuniform float cvsHeight;\nuniform float cvsWidth;\n\nuniform float sigma;\nuniform float k;\nuniform float p;\nuniform float epsilon;\nuniform float phi;\nvarying vec2 v_coord;\n\nfloat cosh(float val)\n{\n\tfloat tmp = exp(val);\n\tfloat cosH = (tmp + 1.0 / tmp) / 2.0;\n\treturn cosH;\n}\n\nfloat tanh(float val)\n{\n\tfloat tmp = exp(val);\n\tfloat tanH = (tmp - 1.0 / tmp) / (tmp + 1.0 / tmp);\n\treturn tanH;\n}\n\nfloat sinh(float val)\n{\n\tfloat tmp = exp(val);\n\tfloat sinH = (tmp - 1.0 / tmp) / 2.0;\n\treturn sinH;\n}\n\nvoid main(void){\n\tvec3 destColor = vec3(0.0);\n\tfloat tFrag = 1.0 / cvsHeight;\n\tfloat sFrag = 1.0 / cvsWidth;\n\tvec2 Frag = vec2(sFrag,tFrag);\n\tvec2 uv = gl_FragCoord.st;\n\tfloat twoSigmaESquared = 2.0 * sigma * sigma;\n\tfloat twoSigmaRSquared = twoSigmaESquared * k * k;\n\tint halfWidth = int(ceil( 1.0 * sigma * k ));\n\n\tconst int MAX_NUM_ITERATION = 99999;\n\tvec2 sum = vec2(0.0);\n\tvec2 norm = vec2(0.0);\n\n\tfor(int cnt=0;cnt (2*halfWidth+1)*(2*halfWidth+1)){break;}\n\t\tint i = int(cnt / (2*halfWidth+1)) - halfWidth;\n\t\tint j = cnt - halfWidth - int(cnt / (2*halfWidth+1)) * (2*halfWidth+1);\n\n\t\tfloat d = length(vec2(i,j));\n\t\tvec2 kernel = vec2( exp( -d * d / twoSigmaESquared ), \n\t\t\t\t\t\t\texp( -d * d / twoSigmaRSquared ));\n\n\t\tvec2 L = texture2D(src, (uv + vec2(i,j)) * Frag).xx;\n\n\t\tnorm += kernel;\n\t\tsum += kernel * L;\n\t}\n\n\tsum /= norm;\n\n\tfloat H = 100.0 * ((1.0 + p) * sum.x - p * sum.y);\n\tfloat edge = ( H > epsilon )? 1.0 : 1.0 + tanh( phi * (H - epsilon));\n\tdestColor = vec3(edge);\n\tgl_FragColor = vec4(destColor, 1.0);\n}", -N.registerNodeType("texture/xDoG",C),w.title="Webcam",w.desc="Webcam texture",w.is_webcam_open=!1,w.prototype.openStream=function(){if(navigator.getUserMedia){this._waiting_confirmation=!0;navigator.mediaDevices.getUserMedia({audio:!1,video:{facingMode:this.properties.facingMode}}).then(this.streamReady.bind(this)).catch(function(b){w.is_webcam_open=!1;console.log("Webcam rejected",b);a._webcam_stream=!1;a.boxcolor="red";a.trigger("stream_error")});var a=this}},w.prototype.closeStream=function(){if(this._webcam_stream){var a= +N.registerNodeType("texture/kuwahara",x),A.title="XDoG Filter",A.desc="Filters a texture giving an artistic ink style",A.max_radius=10,A._shaders=[],A.prototype.onExecute=function(){var a=this.getInputData(0);if(a&&this.isOutputConnected(0)){var b=this._temp_texture;b&&b.width==a.width&&b.height==a.height&&b.type==a.type||(this._temp_texture=new GL.Texture(a.width,a.height,{type:a.type,format:gl.RGBA,filter:gl.LINEAR}));A._xdog_shader||(A._xdog_shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,A.xdog_pixel_shader)); +var d=A._xdog_shader,c=GL.Mesh.getScreenQuad(),f=this.properties.sigma,g=this.properties.k,e=this.properties.p,k=this.properties.epsilon,h=this.properties.phi;a.bind(0);this._temp_texture.drawTo(function(){d.uniforms({src:0,sigma:f,k:g,p:e,epsilon:k,phi:h,cvsWidth:a.width,cvsHeight:a.height}).draw(c)});this.setOutputData(0,this._temp_texture)}},A.xdog_pixel_shader="\nprecision highp float;\nuniform sampler2D src;\n\nuniform float cvsHeight;\nuniform float cvsWidth;\n\nuniform float sigma;\nuniform float k;\nuniform float p;\nuniform float epsilon;\nuniform float phi;\nvarying vec2 v_coord;\n\nfloat cosh(float val)\n{\n\tfloat tmp = exp(val);\n\tfloat cosH = (tmp + 1.0 / tmp) / 2.0;\n\treturn cosH;\n}\n\nfloat tanh(float val)\n{\n\tfloat tmp = exp(val);\n\tfloat tanH = (tmp - 1.0 / tmp) / (tmp + 1.0 / tmp);\n\treturn tanH;\n}\n\nfloat sinh(float val)\n{\n\tfloat tmp = exp(val);\n\tfloat sinH = (tmp - 1.0 / tmp) / 2.0;\n\treturn sinH;\n}\n\nvoid main(void){\n\tvec3 destColor = vec3(0.0);\n\tfloat tFrag = 1.0 / cvsHeight;\n\tfloat sFrag = 1.0 / cvsWidth;\n\tvec2 Frag = vec2(sFrag,tFrag);\n\tvec2 uv = gl_FragCoord.st;\n\tfloat twoSigmaESquared = 2.0 * sigma * sigma;\n\tfloat twoSigmaRSquared = twoSigmaESquared * k * k;\n\tint halfWidth = int(ceil( 1.0 * sigma * k ));\n\n\tconst int MAX_NUM_ITERATION = 99999;\n\tvec2 sum = vec2(0.0);\n\tvec2 norm = vec2(0.0);\n\n\tfor(int cnt=0;cnt (2*halfWidth+1)*(2*halfWidth+1)){break;}\n\t\tint i = int(cnt / (2*halfWidth+1)) - halfWidth;\n\t\tint j = cnt - halfWidth - int(cnt / (2*halfWidth+1)) * (2*halfWidth+1);\n\n\t\tfloat d = length(vec2(i,j));\n\t\tvec2 kernel = vec2( exp( -d * d / twoSigmaESquared ), \n\t\t\t\t\t\t\texp( -d * d / twoSigmaRSquared ));\n\n\t\tvec2 L = texture2D(src, (uv + vec2(i,j)) * Frag).xx;\n\n\t\tnorm += kernel;\n\t\tsum += kernel * L;\n\t}\n\n\tsum /= norm;\n\n\tfloat H = 100.0 * ((1.0 + p) * sum.x - p * sum.y);\n\tfloat edge = ( H > epsilon )? 1.0 : 1.0 + tanh( phi * (H - epsilon));\n\tdestColor = vec3(edge);\n\tgl_FragColor = vec4(destColor, 1.0);\n}", +N.registerNodeType("texture/xDoG",A),w.title="Webcam",w.desc="Webcam texture",w.is_webcam_open=!1,w.prototype.openStream=function(){if(navigator.getUserMedia){this._waiting_confirmation=!0;navigator.mediaDevices.getUserMedia({audio:!1,video:{facingMode:this.properties.facingMode}}).then(this.streamReady.bind(this)).catch(function(b){w.is_webcam_open=!1;console.log("Webcam rejected",b);a._webcam_stream=!1;a.boxcolor="red";a.trigger("stream_error")});var a=this}},w.prototype.closeStream=function(){if(this._webcam_stream){var a= this._webcam_stream.getTracks();if(a.length)for(var b=0;b=this.size[1]||!this._video||(a.save(),a.webgl?this._video_texture&&a.drawImage(this._video_texture,0,0,this.size[0],this.size[1]):a.drawImage(this._video, 0,0,this.size[0],this.size[1]),a.restore())},w.prototype.onExecute=function(){null!=this._webcam_stream||this._waiting_confirmation||this.openStream();if(this._video&&this._video.videoWidth){var a=this._video.videoWidth,b=this._video.videoHeight,d=this._video_texture;d&&d.width==a&&d.height==b||(this._video_texture=new GL.Texture(a,b,{format:gl.RGB,filter:gl.LINEAR}));this._video_texture.uploadImage(this._video);this._video_texture.version=++this.version;this.properties.texture_name&&(c.getTexturesContainer()[this.properties.texture_name]= this._video_texture);this.setOutputData(0,this._video_texture);for(a=1;aMath.abs(b))return c[1];a=(a-c[0])/b;return c[1]*(1-a)+f[1]*a}}return 0}},y.prototype.updateCurve=function(){for(var a=this._values,b=a.length/4,d=this.properties.split_channels,c=0;cd+f.NODE_TITLE_HEIGHT&&a.drawImage(b,10,g,this.size[0]-20,this.size[1]-d-f.NODE_TITLE_HEIGHT);var g=this.size[1]-f.NODE_TITLE_HEIGHT+.5;c=f.isInsideRectangle(c[0],c[1],this.pos[0],this.pos[1]+g,this.size[0],f.NODE_TITLE_HEIGHT);a.fillStyle=c?"#555":"#222";a.beginPath();this._shape==f.BOX_SHAPE?a.rect(0,g,this.size[0]+1,f.NODE_TITLE_HEIGHT):a.roundRect(0,g,this.size[0]+1,f.NODE_TITLE_HEIGHT,0,8);a.fill();a.textAlign="center";a.font="24px Arial";a.fillStyle= -c?"#DDD":"#999";a.fillText("+",.5*this.size[0],g+24)}};E.prototype.onMouseDown=function(a,b,d){b[1]>this.size[1]-f.NODE_TITLE_HEIGHT+.5&&d.showSubgraphPropertiesDialog(this)};E.prototype.onDrawSubgraphBackground=function(a){};E.prototype.getExtraMenuOptions=function(a){var b=this;return[{content:"Print Code",callback:function(){var a=b._context.computeShaderCode();console.log(a.vs_code,a.fs_code)}}]};f.registerNodeType("texture/shaderGraph",E);A.title="Uniform";A.desc="Input data for the shader"; -A.prototype.getTitle=function(){return this.properties.name&&this.flags.collapsed?this.properties.type+" "+this.properties.name:"Uniform"};A.prototype.onPropertyChanged=function(a,b){this.outputs[0].name=this.properties.type+" "+this.properties.name};A.prototype.onGetCode=function(a){if(this.shader_destination){var b=this.properties.type;if(!b){if(!a.onGetPropertyInfo)return;b=a.onGetPropertyInfo(this.property.name);if(!b)return;b=b.type}"number"==b?b="float":"texture"==b&&(b="sampler2D");-1!=m.GLSL_types.indexOf(b)&& -(a.addUniform("u_"+this.properties.name,b),this.setOutputData(0,b))}};A.prototype.getOutputVarName=function(a){return"u_"+this.properties.name};l("input/uniform",A);I.title="Attribute";I.desc="Input data from mesh attribute";I.prototype.getTitle=function(){return"att. "+this.properties.name};I.prototype.onGetCode=function(a){if(this.shader_destination){var b=this.properties.type;b&&-1!=m.GLSL_types.indexOf(b)&&("number"==b&&(b="float"),"coord"!=this.properties.name&&a.addCode("varying"," varying "+ +c?"#DDD":"#999";a.fillText("+",.5*this.size[0],g+24)}};F.prototype.onMouseDown=function(a,b,d){b[1]>this.size[1]-f.NODE_TITLE_HEIGHT+.5&&d.showSubgraphPropertiesDialog(this)};F.prototype.onDrawSubgraphBackground=function(a){};F.prototype.getExtraMenuOptions=function(a){var b=this;return[{content:"Print Code",callback:function(){var a=b._context.computeShaderCode();console.log(a.vs_code,a.fs_code)}}]};f.registerNodeType("texture/shaderGraph",F);C.title="Uniform";C.desc="Input data for the shader"; +C.prototype.getTitle=function(){return this.properties.name&&this.flags.collapsed?this.properties.type+" "+this.properties.name:"Uniform"};C.prototype.onPropertyChanged=function(a,b){this.outputs[0].name=this.properties.type+" "+this.properties.name};C.prototype.onGetCode=function(a){if(this.shader_destination){var b=this.properties.type;if(!b){if(!a.onGetPropertyInfo)return;b=a.onGetPropertyInfo(this.property.name);if(!b)return;b=b.type}"number"==b?b="float":"texture"==b&&(b="sampler2D");-1!=m.GLSL_types.indexOf(b)&& +(a.addUniform("u_"+this.properties.name,b),this.setOutputData(0,b))}};C.prototype.getOutputVarName=function(a){return"u_"+this.properties.name};l("input/uniform",C);I.title="Attribute";I.desc="Input data from mesh attribute";I.prototype.getTitle=function(){return"att. "+this.properties.name};I.prototype.onGetCode=function(a){if(this.shader_destination){var b=this.properties.type;b&&-1!=m.GLSL_types.indexOf(b)&&("number"==b&&(b="float"),"coord"!=this.properties.name&&a.addCode("varying"," varying "+ b+" v_"+this.properties.name+";"),this.setOutputData(0,b))}};I.prototype.getOutputVarName=function(a){return"v_"+this.properties.name};l("input/attribute",I);J.title="Sampler2D";J.desc="Reads a pixel from a texture";J.prototype.onGetCode=function(a){if(this.shader_destination){var b=t(this,0),d=r(this),c="vec4 "+d+" = vec4(0.0);\n";if(b){var f=t(this,1)||a.buffer_names.uvs;c+=d+" = texture2D("+b+","+f+");\n"}v(this,0)&&(c+="vec4 "+v(this,0)+" = "+d+";\n");v(this,1)&&(c+="vec3 "+v(this,1)+" = "+d+ -".xyz;\n");a.addCode("code",c,this.shader_destination);this.setOutputData(0,"vec4");this.setOutputData(1,"vec3")}};l("texture/sampler2D",J);F.title="const";F.prototype.getTitle=function(){return this.flags.collapsed?C(this.properties.value,this.properties.type,2):"Const"};F.prototype.onPropertyChanged=function(a,b){"type"==a&&(this.outputs[0].type!=b&&(this.disconnectOutput(0),this.outputs[0].type=b),this.widgets.length=1,this.updateWidgets());"value"==a&&(b.length?(this.widgets[1].value=b[1],2d;++d)b.push({name:t(this,d),type:this.getInputData(d)||"float"});var c=v(this,0);if(c){var f=b[0].type,g=this.properties.operation, e=[];for(d=0;2>d;++d){var k=b[d].name;null==k&&(k=null!=p.value?p.value:"(1.0)",b[d].type="float");b[d].type!=f&&("float"!=b[d].type||"*"!=g&&"/"!=g)&&(k=L(k,b[d].type,f));e.push(k)}a.addCode("code",f+" "+c+" = "+e[0]+g+e[1]+";",this.shader_destination);this.setOutputData(0,f)}}};l("math/operation",M);k.title="Func";k.prototype.onPropertyChanged=function(a,b){this.graph&&this.graph._version++;if("func"==a&&(a=K[b])){for(b=a.params.length;bd;++d)b.push({name:t(this,d),type:this.getInputData(d)||"float"});var c=v(this,0);if(c){var f=K[this.properties.func];if(f){var g=b[0].type,e=f.return_type;"T"==e&&(e=g);var k=[];for(d= -0;d=c;){e=.5*(k+c)|0;b=a[e];if(b==d)break;if(c==k-1)return c;ba&&(a=1);this.points&&this.points.length==3*a||(this.points=new Float32Array(3*a));this.properties.generate_normals?this.normals&&this.normals.length==this.points.length||(this.normals=new Float32Array(this.points.length)):this.normals=null;var d=this._last_radius||this.properties.radius,c=this.properties.mode,f=this.getInputData(0);this._old_obj_version=f?f._version:null;this.points=l.generatePoints(d,a,c,this.points,this.normals, -this.properties.regular,f);this.version++};l.generatePoints=function(a,d,c,f,e,k,h){var b=3*d;f&&f.length==b||(f=new Float32Array(b));var g=new Float32Array(3),n=new Float32Array([0,1,0]);if(k)if(c==l.RECTANGLE){b=Math.floor(Math.sqrt(d));for(d=0;dk||yh&&hq))break}this.geometry.indices=this.indices=new Uint32Array(n)}this.indices&&this.indices.length?(this.geometry.indices=this.indices,this.setOutputData(0,this.geometry)):this.setOutputData(0,null)}};z.registerNodeType("geometry/connectPoints",I);"undefined"!=typeof GL&&(J.title="to geometry",J.desc="converts a mesh to geometry",J.prototype.onExecute=function(){var a=this.getInputData(0);if(a){if(a!=this.last_mesh){this.last_mesh=a;for(i in a.vertexBuffers)this.geometry[i]= -a.vertexBuffers[i].data;a.indexBuffers.triangles&&(this.geometry.indices=a.indexBuffers.triangles.data);this.geometry._id=c();this.geometry._version=0}this.setOutputData(0,this.geometry);this.geometry&&this.setOutputData(1,this.geometry.vertices)}},z.registerNodeType("geometry/toGeometry",J),F.title="Geo to Mesh",F.prototype.updateMesh=function(a){this.mesh||(this.mesh=new GL.Mesh);for(var b in a)if("_"!=b[0]){var c=a[b],f=GL.Mesh.common_buffers[b];if(f||"indices"==b){f=f?f.spacing:3;var e=this.mesh.vertexBuffers[b]; +0;fe||yk&&kh))break}this.geometry.indices=this.indices=new Uint32Array(q)}this.indices&&this.indices.length?(this.geometry.indices=this.indices,this.setOutputData(0,this.geometry)):this.setOutputData(0,null)}};z.registerNodeType("geometry/connectPoints",I);"undefined"!=typeof GL&&(J.title="to geometry",J.desc="converts a mesh to geometry",J.prototype.onExecute=function(){var a=this.getInputData(0);if(a){if(a!=this.last_mesh){this.last_mesh=a;for(i in a.vertexBuffers)this.geometry[i]= +a.vertexBuffers[i].data;a.indexBuffers.triangles&&(this.geometry.indices=a.indexBuffers.triangles.data);this.geometry._id=c();this.geometry._version=0}this.setOutputData(0,this.geometry);this.geometry&&this.setOutputData(1,this.geometry.vertices)}},z.registerNodeType("geometry/toGeometry",J),G.title="Geo to Mesh",G.prototype.updateMesh=function(a){this.mesh||(this.mesh=new GL.Mesh);for(var b in a)if("_"!=b[0]){var c=a[b],f=GL.Mesh.common_buffers[b];if(f||"indices"==b){f=f?f.spacing:3;var e=this.mesh.vertexBuffers[b]; e&&e.data.length==c.length?(e.data.set(c),e.upload(GL.DYNAMIC_DRAW)):e=new GL.Buffer("indices"==b?GL.ELEMENT_ARRAY_BUFFER:GL.ARRAY_BUFFER,c,f,GL.DYNAMIC_DRAW);this.mesh.addBuffer(b,e)}}if(this.mesh.vertexBuffers.normals&&this.mesh.vertexBuffers.normals.data.length!=this.mesh.vertexBuffers.vertices.data.length){c=new Float32Array([0,1,0]);f=new Float32Array(this.mesh.vertexBuffers.vertices.data.length);for(b=0;b=c.NOTEON||k<=c.NOTEOFF)this.channel=e&15};Object.defineProperty(c.prototype,"velocity",{get:function(){return this.cmd==c.NOTEON?this.data[2]:-1},set:function(c){this.data[2]=c},enumerable:!0});c.notes="A A# B C C# D D# E F F# G G#".split(" ");c.note_to_index={A:0,"A#":1,B:2,C:3,"C#":4,D:5,"D#":6,E:7,F:8,"F#":9,G:10,"G#":11};Object.defineProperty(c.prototype,"note",{get:function(){return this.cmd!= c.NOTEON?-1:c.toNoteString(this.data[1],!0)},set:function(c){throw"notes cannot be assigned this way, must modify the data[1]";},enumerable:!0});Object.defineProperty(c.prototype,"octave",{get:function(){return this.cmd!=c.NOTEON?-1:Math.floor((this.data[1]-24)/12+1)},set:function(c){throw"octave cannot be assigned this way, must modify the data[1]";},enumerable:!0});c.prototype.getPitch=function(){return 440*Math.pow(2,(this.data[1]-69)/12)};c.computePitch=function(c){return 440*Math.pow(2,(c-69)/ 12)};c.prototype.getCC=function(){return this.data[1]};c.prototype.getCCValue=function(){return this.data[2]};c.prototype.getPitchBend=function(){return this.data[1]+(this.data[2]<<7)-8192};c.computePitchBend=function(c,e){return c+(e<<7)-8192};c.prototype.setCommandFromString=function(e){this.cmd=c.computeCommandFromString(e)};c.computeCommandFromString=function(e){if(!e)return 0;if(e&&e.constructor===Number)return e;e=e.toUpperCase();switch(e){case "NOTE ON":case "NOTEON":return c.NOTEON;case "NOTE OFF":case "NOTEOFF":return c.NOTEON; @@ -829,33 +830,33 @@ t.default_ports={0:"unknown"};t.prototype.getMIDIOutputs=function(){var c={};if( function(){return[["on_midi",z.EVENT]]};z.registerNodeType("midi/output",t);v.title="MIDI Show";v.desc="Shows MIDI in the graph";v.color="#243";v.prototype.getTitle=function(){return this.flags.collapsed?this._str:this.title};v.prototype.onAction=function(e,h){h&&(this._str=h.constructor===c?h.toString():"???")};v.prototype.onDrawForeground=function(c){this._str&&!this.flags.collapsed&&(c.font="30px Arial",c.fillText(this._str,10,.8*this.size[1]))};v.prototype.onGetInputs=function(){return[["in", z.ACTION]]};v.prototype.onGetOutputs=function(){return[["on_midi",z.EVENT]]};z.registerNodeType("midi/show",v);h.title="MIDI Filter";h.desc="Filters MIDI messages";h.color="#243";h["@cmd"]={type:"enum",title:"Command",values:c.commands_reversed};h.prototype.getTitle=function(){var e=-1==this.properties.cmd?"Nothing":c.commands_short[this.properties.cmd]||"Unknown";-1!=this.properties.min_value&&-1!=this.properties.max_value&&(e+=" "+(this.properties.min_value==this.properties.max_value?this.properties.max_value: this.properties.min_value+".."+this.properties.max_value));return"Filter: "+e};h.prototype.onPropertyChanged=function(e,h){"cmd"==e&&(e=Number(h),isNaN(e)&&(e=c.commands[h]||0),this.properties.cmd=e)};h.prototype.onAction=function(e,h){if(h&&h.constructor===c){if(this._learning)this._learning=!1,this.boxcolor="#AAA",this.properties.channel=h.channel,this.properties.cmd=h.cmd,this.properties.min_value=this.properties.max_value=h.data[1];else if(-1!=this.properties.channel&&h.channel!=this.properties.channel|| --1!=this.properties.cmd&&h.cmd!=this.properties.cmd||-1!=this.properties.min_value&&h.data[1]this.properties.max_value)return;this.trigger("on_midi",h)}};z.registerNodeType("midi/filter",h);E.title="MIDIEvent";E.desc="Create a MIDI Event";E.color="#243";E.prototype.onAction=function(e,h){"assign"==e?(this.properties.channel=h.channel,this.properties.cmd=h.cmd,this.properties.value1=h.data[1],this.properties.value2=h.data[2],h.cmd== -c.NOTEON?this.gate=!0:h.cmd==c.NOTEOFF&&(this.gate=!1)):(h=this.midi_event,h.channel=this.properties.channel,this.properties.cmd&&this.properties.cmd.constructor===String?h.setCommandFromString(this.properties.cmd):h.cmd=this.properties.cmd,h.data[0]=h.cmd|h.channel,h.data[1]=Number(this.properties.value1),h.data[2]=Number(this.properties.value2),this.trigger("on_midi",h))};E.prototype.onExecute=function(){var e=this.properties;if(this.inputs)for(var h=0;hthis.properties.max_value)return;this.trigger("on_midi",h)}};z.registerNodeType("midi/filter",h);F.title="MIDIEvent";F.desc="Create a MIDI Event";F.color="#243";F.prototype.onAction=function(e,h){"assign"==e?(this.properties.channel=h.channel,this.properties.cmd=h.cmd,this.properties.value1=h.data[1],this.properties.value2=h.data[2],h.cmd== +c.NOTEON?this.gate=!0:h.cmd==c.NOTEOFF&&(this.gate=!1)):(h=this.midi_event,h.channel=this.properties.channel,this.properties.cmd&&this.properties.cmd.constructor===String?h.setCommandFromString(this.properties.cmd):h.cmd=this.properties.cmd,h.data[0]=h.cmd|h.channel,h.data[1]=Number(this.properties.value1),h.data[2]=Number(this.properties.value2),this.trigger("on_midi",h))};F.prototype.onExecute=function(){var e=this.properties;if(this.inputs)for(var h=0;hc;++c)this.valid_notes[c]=-1!=this.notes_pitches.indexOf(c);for(c=0;12>c;++c)if(this.valid_notes[c])this.offset_notes[c]=0;else for(var e=1;12>e;++e){if(this.valid_notes[(c-e)%12]){this.offset_notes[c]=-e;break}if(this.valid_notes[(c+e)%12]){this.offset_notes[c]=e;break}}};F.prototype.onAction=function(e,h){h&&h.constructor===c&&(h.data[0]==c.NOTEON||h.data[0]==c.NOTEOFF?(this.midi_event=new c,this.midi_event.setup(h.data),this.midi_event.data[1]+=this.offset_notes[c.note_to_index[h.note]], -this.trigger("out",this.midi_event)):this.trigger("out",h))};F.prototype.onExecute=function(){var c=this.getInputData(1);null!=c&&c!=this._current_scale&&this.processScale(c)};z.registerNodeType("midi/quantize",F);e.title="MIDI fromFile";e.desc="Plays a MIDI file";e.color="#243";e.prototype.onAction=function(c){"play"==c?this.play():"pause"==c&&(this._playing=!this._playing)};e.prototype.onPropertyChanged=function(c,e){"url"==c&&this.loadMIDIFile(e)};e.prototype.onExecute=function(){if(this._midi&& +Math.round(this.midi_event.data[1]+this.properties.amount),this.trigger("out",this.midi_event)):this.trigger("out",h))};J.prototype.onExecute=function(){var c=this.getInputData(1);null!=c&&(this.properties.amount=c)};z.registerNodeType("midi/transpose",J);G.title="MIDI Quantize Pitch";G.desc="Transpose a MIDI note tp fit an scale";G.color="#243";G.prototype.onPropertyChanged=function(c,e){"scale"==c&&this.processScale(e)};G.prototype.processScale=function(c){this._current_scale=c;this.notes_pitches= +I.processScale(c);for(c=0;12>c;++c)this.valid_notes[c]=-1!=this.notes_pitches.indexOf(c);for(c=0;12>c;++c)if(this.valid_notes[c])this.offset_notes[c]=0;else for(var e=1;12>e;++e){if(this.valid_notes[(c-e)%12]){this.offset_notes[c]=-e;break}if(this.valid_notes[(c+e)%12]){this.offset_notes[c]=e;break}}};G.prototype.onAction=function(e,h){h&&h.constructor===c&&(h.data[0]==c.NOTEON||h.data[0]==c.NOTEOFF?(this.midi_event=new c,this.midi_event.setup(h.data),this.midi_event.data[1]+=this.offset_notes[c.note_to_index[h.note]], +this.trigger("out",this.midi_event)):this.trigger("out",h))};G.prototype.onExecute=function(){var c=this.getInputData(1);null!=c&&c!=this._current_scale&&this.processScale(c)};z.registerNodeType("midi/quantize",G);e.title="MIDI fromFile";e.desc="Plays a MIDI file";e.color="#243";e.prototype.onAction=function(c){"play"==c?this.play():"pause"==c&&(this._playing=!this._playing)};e.prototype.onPropertyChanged=function(c,e){"url"==c&&this.loadMIDIFile(e)};e.prototype.onExecute=function(){if(this._midi&& this._playing){this._current_time+=this.graph.elapsed_time;for(var e=100*this._current_time,h=0;hb;b++)for(var d=0;dg+f||c[1]>d))return b}}return-1};H.prototype.onAction=function(e,h){if("reset"==e)for(h=0;hh[1]))return e=this.getKeyIndex(h),this.keys[e]=!0,this._last_key=e,e=12*(this.properties.start_octave-1)+29+e,h=new c,h.setup([c.NOTEON,e,100]),this.trigger("note",h),!0};H.prototype.onMouseMove=function(e,h){if(!(0>h[1]||-1==this._last_key)){this.setDirtyCanvas(!0); -e=this.getKeyIndex(h);if(this._last_key==e)return!0;this.keys[this._last_key]=!1;h=12*(this.properties.start_octave-1)+29+this._last_key;var k=new c;k.setup([c.NOTEOFF,h,100]);this.trigger("note",k);this.keys[e]=!0;h=12*(this.properties.start_octave-1)+29+e;k=new c;k.setup([c.NOTEON,h,100]);this.trigger("note",k);this._last_key=e;return!0}};H.prototype.onMouseUp=function(e,h){if(!(0>h[1]))return e=this.getKeyIndex(h),this.keys[e]=!1,this._last_key=-1,e=12*(this.properties.start_octave-1)+29+e,h=new c, -h.setup([c.NOTEOFF,e,100]),this.trigger("note",h),!0};z.registerNodeType("midi/keys",H)})(this); +c){if(this.instrument&&h.data[0]==c.NOTEON){e=h.note;if(!e||"undefined"==e||e.constructor!==String)return;this.instrument.play(e,h.octave,this.properties.duration,this.properties.volume)}this.trigger("note",h)}};D.prototype.onExecute=function(){var c=this.getInputData(1);null!=c&&(this.properties.volume=c);c=this.getInputData(2);null!=c&&(this.properties.duration=c)};z.registerNodeType("midi/play",D);E.title="MIDI Keys";E.desc="Keyboard to play notes";E.color="#243";E.keys=[{x:0,w:1,h:1,t:0},{x:.75, +w:.5,h:.6,t:1},{x:1,w:1,h:1,t:0},{x:1.75,w:.5,h:.6,t:1},{x:2,w:1,h:1,t:0},{x:2.75,w:.5,h:.6,t:1},{x:3,w:1,h:1,t:0},{x:4,w:1,h:1,t:0},{x:4.75,w:.5,h:.6,t:1},{x:5,w:1,h:1,t:0},{x:5.75,w:.5,h:.6,t:1},{x:6,w:1,h:1,t:0}];E.prototype.onDrawForeground=function(c){if(!this.flags.collapsed){var e=12*this.properties.num_octaves;this.keys.length=e;var h=this.size[0]/(7*this.properties.num_octaves),a=this.size[1];c.globalAlpha=1;for(var b=0;2>b;b++)for(var d=0;dg+f||c[1]>d))return b}}return-1};E.prototype.onAction=function(e,h){if("reset"==e)for(h=0;hh[1]))return e=this.getKeyIndex(h),this.keys[e]=!0,this._last_key=e,e=12*(this.properties.start_octave-1)+29+e,h=new c,h.setup([c.NOTEON,e,100]),this.trigger("note",h),!0};E.prototype.onMouseMove=function(e,h){if(!(0>h[1]||-1==this._last_key)){this.setDirtyCanvas(!0); +e=this.getKeyIndex(h);if(this._last_key==e)return!0;this.keys[this._last_key]=!1;h=12*(this.properties.start_octave-1)+29+this._last_key;var k=new c;k.setup([c.NOTEOFF,h,100]);this.trigger("note",k);this.keys[e]=!0;h=12*(this.properties.start_octave-1)+29+e;k=new c;k.setup([c.NOTEON,h,100]);this.trigger("note",k);this._last_key=e;return!0}};E.prototype.onMouseUp=function(e,h){if(!(0>h[1]))return e=this.getKeyIndex(h),this.keys[e]=!1,this._last_key=-1,e=12*(this.properties.start_octave-1)+29+e,h=new c, +h.setup([c.NOTEOFF,e,100]),this.trigger("note",h),!0};z.registerNodeType("midi/keys",E)})(this); (function(B){function c(){this.properties={src:"",gain:.5,loop:!0,autoplay:!0,playbackRate:1};this._loading_audio=!1;this._audiobuffer=null;this._audionodes=[];this._last_sourcenode=null;this.addOutput("out","audio");this.addInput("gain","number");this.audionode=n.getAudioContext().createGain();this.audionode.graphnode=this;this.audionode.gain.value=this.properties.gain;this.properties.src&&this.loadSound(this.properties.src)}function l(){this.properties={gain:.5};this._audionodes=[];this._media_stream= null;this.addOutput("out","audio");this.addInput("gain","number");this.audionode=n.getAudioContext().createGain();this.audionode.graphnode=this;this.audionode.gain.value=this.properties.gain}function r(){this.properties={fftSize:2048,minDecibels:-100,maxDecibels:-10,smoothingTimeConstant:.5};this.audionode=n.getAudioContext().createAnalyser();this.audionode.graphnode=this;this.audionode.fftSize=this.properties.fftSize;this.audionode.minDecibels=this.properties.minDecibels;this.audionode.maxDecibels= this.properties.maxDecibels;this.audionode.smoothingTimeConstant=this.properties.smoothingTimeConstant;this.addInput("in","audio");this.addOutput("freqs","array");this.addOutput("samples","array");this._time_bin=this._freq_bin=null}function t(){this.properties={gain:1};this.audionode=n.getAudioContext().createGain();this.addInput("in","audio");this.addInput("gain","number");this.addOutput("out","audio")}function v(){this.properties={impulse_src:"",normalize:!0};this.audionode=n.getAudioContext().createConvolver(); -this.addInput("in","audio");this.addOutput("out","audio")}function h(){this.properties={threshold:-50,knee:40,ratio:12,reduction:-20,attack:0,release:.25};this.audionode=n.getAudioContext().createDynamicsCompressor();this.addInput("in","audio");this.addOutput("out","audio")}function E(){this.properties={};this.audionode=n.getAudioContext().createWaveShaper();this.addInput("in","audio");this.addInput("shape","waveshape");this.addOutput("out","audio")}function A(){this.properties={gain1:.5,gain2:.5}; +this.addInput("in","audio");this.addOutput("out","audio")}function h(){this.properties={threshold:-50,knee:40,ratio:12,reduction:-20,attack:0,release:.25};this.audionode=n.getAudioContext().createDynamicsCompressor();this.addInput("in","audio");this.addOutput("out","audio")}function F(){this.properties={};this.audionode=n.getAudioContext().createWaveShaper();this.addInput("in","audio");this.addInput("shape","waveshape");this.addOutput("out","audio")}function C(){this.properties={gain1:.5,gain2:.5}; this.audionode=n.getAudioContext().createGain();this.audionode1=n.getAudioContext().createGain();this.audionode1.gain.value=this.properties.gain1;this.audionode2=n.getAudioContext().createGain();this.audionode2.gain.value=this.properties.gain2;this.audionode1.connect(this.audionode);this.audionode2.connect(this.audionode);this.addInput("in1","audio");this.addInput("in1 gain","number");this.addInput("in2","audio");this.addInput("in2 gain","number");this.addOutput("out","audio")}function I(){this.properties= -{A:.1,D:.1,S:.1,R:.1};this.audionode=n.getAudioContext().createGain();this.audionode.gain.value=0;this.addInput("in","audio");this.addInput("gate","boolean");this.addOutput("out","audio");this.gate=!1}function J(){this.properties={delayTime:.5};this.audionode=n.getAudioContext().createDelay(10);this.audionode.delayTime.value=this.properties.delayTime;this.addInput("in","audio");this.addInput("time","number");this.addOutput("out","audio")}function F(){this.properties={frequency:350,detune:0,Q:1};this.addProperty("type", +{A:.1,D:.1,S:.1,R:.1};this.audionode=n.getAudioContext().createGain();this.audionode.gain.value=0;this.addInput("in","audio");this.addInput("gate","boolean");this.addOutput("out","audio");this.gate=!1}function J(){this.properties={delayTime:.5};this.audionode=n.getAudioContext().createDelay(10);this.audionode.delayTime.value=this.properties.delayTime;this.addInput("in","audio");this.addInput("time","number");this.addOutput("out","audio")}function G(){this.properties={frequency:350,detune:0,Q:1};this.addProperty("type", "lowpass","enum",{values:"lowpass highpass bandpass lowshelf highshelf peaking notch allpass".split(" ")});this.audionode=n.getAudioContext().createBiquadFilter();this.addInput("in","audio");this.addOutput("out","audio")}function e(){this.properties={frequency:440,detune:0,type:"sine"};this.addProperty("type","sine","enum",{values:["sine","square","sawtooth","triangle","custom"]});this.audionode=n.getAudioContext().createOscillator();this.addOutput("out","audio")}function D(){this.properties={continuous:!0, -mark:-1};this.addInput("data","array");this.addInput("mark","number");this.size=[300,200];this._last_buffer=null}function H(){this.properties={band:440,amplitude:1};this.addInput("freqs","array");this.addOutput("signal","number")}function z(){if(!z.default_code){var c=z.default_function.toString(),a=c.indexOf("{")+1,b=c.lastIndexOf("}");z.default_code=c.substr(a,b-a)}this.properties={code:z.default_code};c=n.getAudioContext();c.createScriptProcessor?this.audionode=c.createScriptProcessor(4096,1,1): +mark:-1};this.addInput("data","array");this.addInput("mark","number");this.size=[300,200];this._last_buffer=null}function E(){this.properties={band:440,amplitude:1};this.addInput("freqs","array");this.addOutput("signal","number")}function z(){if(!z.default_code){var c=z.default_function.toString(),a=c.indexOf("{")+1,b=c.lastIndexOf("}");z.default_code=c.substr(a,b-a)}this.properties={code:z.default_code};c=n.getAudioContext();c.createScriptProcessor?this.audionode=c.createScriptProcessor(4096,1,1): (console.warn("ScriptProcessorNode deprecated"),this.audionode=c.createGain());this.processCode();z._bypass_function||(z._bypass_function=this.audionode.onaudioprocess);this.addInput("in","audio");this.addOutput("out","audio")}function M(){this.audionode=n.getAudioContext().destination;this.addInput("in","audio")}var k=B.LiteGraph,n={};B.LGAudio=n;n.getAudioContext=function(){if(!this._audio_context){window.AudioContext=window.AudioContext||window.webkitAudioContext;if(!window.AudioContext)return console.error("AudioContext not supported by browser"), null;this._audio_context=new AudioContext;this._audio_context.onmessage=function(c){console.log("msg",c)};this._audio_context.onended=function(c){console.log("ended",c)};this._audio_context.oncomplete=function(c){console.log("complete",c)}}return this._audio_context};n.connect=function(c,a){try{c.connect(a)}catch(b){console.warn("LGraphAudio:",b)}};n.disconnect=function(c,a){try{c.disconnect(a)}catch(b){console.warn("LGraphAudio:",b)}};n.changeAllAudiosConnections=function(c,a){if(c.inputs)for(var b= 0;b=this.size[0]&&(e=this.size[0]-1),c.strokeStyle= -"red",c.beginPath(),c.moveTo(e,d),c.lineTo(e,0),c.stroke())}};D.title="Visualization";D.desc="Audio Visualization";k.registerNodeType("audio/visualization",D);H.prototype.onExecute=function(){if(this._freqs=this.getInputData(0)){var c=this.properties.band,a=this.getInputData(1);void 0!==a&&(c=a);a=n.getAudioContext().sampleRate/this._freqs.length;a=c/a*2;a>=this._freqs.length?a=this._freqs[this._freqs.length-1]:(c=a|0,a-=c,a=this._freqs[c]*(1-a)+this._freqs[c+1]*a);this.setOutputData(0,a/255*this.properties.amplitude)}}; -H.prototype.onGetInputs=function(){return[["band","number"]]};H.title="Signal";H.desc="extract the signal of some frequency";k.registerNodeType("audio/signal",H);z.prototype.onAdded=function(c){c.status==LGraph.STATUS_RUNNING&&(this.audionode.onaudioprocess=this._callback)};z["@code"]={widget:"code",type:"code"};z.prototype.onStart=function(){this.audionode.onaudioprocess=this._callback};z.prototype.onStop=function(){this.audionode.onaudioprocess=z._bypass_function};z.prototype.onPause=function(){this.audionode.onaudioprocess= +"red",c.beginPath(),c.moveTo(e,d),c.lineTo(e,0),c.stroke())}};D.title="Visualization";D.desc="Audio Visualization";k.registerNodeType("audio/visualization",D);E.prototype.onExecute=function(){if(this._freqs=this.getInputData(0)){var c=this.properties.band,a=this.getInputData(1);void 0!==a&&(c=a);a=n.getAudioContext().sampleRate/this._freqs.length;a=c/a*2;a>=this._freqs.length?a=this._freqs[this._freqs.length-1]:(c=a|0,a-=c,a=this._freqs[c]*(1-a)+this._freqs[c+1]*a);this.setOutputData(0,a/255*this.properties.amplitude)}}; +E.prototype.onGetInputs=function(){return[["band","number"]]};E.title="Signal";E.desc="extract the signal of some frequency";k.registerNodeType("audio/signal",E);z.prototype.onAdded=function(c){c.status==LGraph.STATUS_RUNNING&&(this.audionode.onaudioprocess=this._callback)};z["@code"]={widget:"code",type:"code"};z.prototype.onStart=function(){this.audionode.onaudioprocess=this._callback};z.prototype.onStop=function(){this.audionode.onaudioprocess=z._bypass_function};z.prototype.onPause=function(){this.audionode.onaudioprocess= z._bypass_function};z.prototype.onUnpause=function(){this.audionode.onaudioprocess=this._callback};z.prototype.onExecute=function(){};z.prototype.onRemoved=function(){this.audionode.onaudioprocess=z._bypass_function};z.prototype.processCode=function(){try{this._script=new (new Function("properties",this.properties.code))(this.properties),this._old_code=this.properties.code,this._callback=this._script.onaudioprocess}catch(q){console.error("Error in onaudioprocess code",q),this._callback=z._bypass_function, this.audionode.onaudioprocess=this._callback}};z.prototype.onPropertyChanged=function(c,a){"code"==c&&(this.properties.code=a,this.processCode(),this.graph&&this.graph.status==LGraph.STATUS_RUNNING&&(this.audionode.onaudioprocess=this._callback))};z.default_function=function(){this.onaudioprocess=function(c){var a=c.inputBuffer;c=c.outputBuffer;for(var b=0;b max_size) { max_size = node.size[max_size_index]; } - node_size_index = (layout == LiteGraph.VERTICAL_LAYOUT) ? 0 : 1; + var node_size_index = (layout == LiteGraph.VERTICAL_LAYOUT) ? 0 : 1; y += node.size[node_size_index] + margin + LiteGraph.NODE_TITLE_HEIGHT; } x += max_size + margin; @@ -3194,6 +3194,15 @@ return; } + if(slot == null) + { + console.error("slot must be a number"); + return; + } + + if(slot.constructor !== Number) + console.warn("slot must be a number, use node.trigger('name') if you want to use a string"); + var output = this.outputs[slot]; if (!output) { return; @@ -7483,8 +7492,8 @@ LGraphNode.prototype.executeAction = function(action) clientY_rel = e.clientY; } - e.deltaX = clientX_rel - this.last_mouse_position[0]; - e.deltaY = clientY_rel- this.last_mouse_position[1]; + // e.deltaX = clientX_rel - this.last_mouse_position[0]; + // e.deltaY = clientY_rel- this.last_mouse_position[1]; this.last_mouse_position[0] = clientX_rel; this.last_mouse_position[1] = clientY_rel; @@ -9921,7 +9930,8 @@ LGraphNode.prototype.executeAction = function(action) case "combo": var old_value = w.value; if (event.type == LiteGraph.pointerevents_method+"move" && w.type == "number") { - w.value += event.deltaX * 0.1 * (w.options.step || 1); + if(event.deltaX) + w.value += event.deltaX * 0.1 * (w.options.step || 1); if ( w.options.min != null && w.value < w.options.min ) { w.value = w.options.min; } @@ -11987,7 +11997,8 @@ LGraphNode.prototype.executeAction = function(action) if (root.onClose && typeof root.onClose == "function"){ root.onClose(); } - root.parentNode.removeChild(root); + if(root.parentNode) + root.parentNode.removeChild(root); /* XXX CHECK THIS */ if(this.parentNode){ this.parentNode.removeChild(this); @@ -15606,7 +15617,7 @@ if (typeof exports != "undefined") { }; NodeScript.title = "Script"; - NodeScript.desc = "executes a code (max 100 characters)"; + NodeScript.desc = "executes a code (max 256 characters)"; NodeScript.widgets_info = { onExecute: { type: "code" } @@ -16208,7 +16219,32 @@ if (typeof exports != "undefined") { LiteGraph.registerNodeType("events/semaphore", SemaphoreEvent); + function OnceEvent() { + this.addInput("in", LiteGraph.ACTION ); + this.addInput("reset", LiteGraph.ACTION ); + this.addOutput("out", LiteGraph.EVENT ); + this._once = false; + this.properties = {}; + var that = this; + this.addWidget("button","reset","",function(){ + that._once = false; + }); + } + OnceEvent.title = "Once"; + OnceEvent.desc = "Only passes an event once, then gets locked"; + + OnceEvent.prototype.onAction = function(action, param) { + if( action == "in" && !this._once ) + { + this._once = true; + this.triggerSlot( 0, param ); + } + else if( action == "reset" ) + this._once = false; + }; + + LiteGraph.registerNodeType("events/once", OnceEvent); function DataStore() { this.addInput("data", 0); diff --git a/build/litegraph_mini.min.js b/build/litegraph_mini.min.js index 567f3cd4b..446d5b0aa 100644 --- a/build/litegraph_mini.min.js +++ b/build/litegraph_mini.min.js @@ -2,61 +2,61 @@ var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.ASSUME_ES5=!1;$jscomp.ASSUME_NO $jscomp.polyfill=function(x,m,t,l){if(m){t=$jscomp.global;x=x.split(".");for(l=0;lt&&(t=Math.max(0,w+t));if(null==l||l>w)l=w;l=Number(l);0>l&&(l=Math.max(0,w+l));for(t=Number(t||0);t=z}},"es6","es3"); -$jscomp.findInternal=function(x,m,t){x instanceof String&&(x=String(x));for(var l=x.length,w=0;w=A}},"es6","es3"); +$jscomp.findInternal=function(x,m,t){x instanceof String&&(x=String(x));for(var l=x.length,w=0;wa&&db?!0:!1}function A(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||ca&&db?!0:!1}function B(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||c -k.width-n.width-10&&(e=k.width-n.width-10),k.height&&a>k.height-n.height-10&&(a=k.height-n.height-10));g.style.left=e+"px";g.style.top=a+"px";b.scale&&(g.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}var f=x.LiteGraph={VERSION:.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, +a.preventDefault(),!0},!0);b.scroll_speed||(b.scroll_speed=.1);g.addEventListener("wheel",c,!0);g.addEventListener("mousewheel",c,!0);this.root=g;b.title&&(e=document.createElement("div"),e.className="litemenu-title",e.innerHTML=b.title,g.appendChild(e));for(var h=e=0;h +h.width-n.width-10&&(e=h.width-n.width-10),h.height&&a>h.height-n.height-10&&(a=h.height-n.height-10));g.style.left=e+"px";g.style.top=a+"px";b.scale&&(g.style.transform="scale("+b.scale+")")}function I(a){this.points=a;this.nearest=this.selected=-1;this.size=null;this.must_update=!0;this.margin=5}var f=x.LiteGraph={VERSION:.4,CANVAS_GRID_SIZE:10,NODE_TITLE_HEIGHT:30,NODE_TITLE_TEXT_Y:20,NODE_SLOT_HEIGHT:20,NODE_WIDGET_HEIGHT:20,NODE_WIDTH:140,NODE_MIN_WIDTH:50,NODE_COLLAPSED_RADIUS:10,NODE_COLLAPSED_WIDTH:80, NODE_TITLE_COLOR:"#999",NODE_SELECTED_TITLE_COLOR:"#FFF",NODE_TEXT_SIZE:14,NODE_TEXT_COLOR:"#AAA",NODE_SUBTEXT_SIZE:12,NODE_DEFAULT_COLOR:"#333",NODE_DEFAULT_BGCOLOR:"#353535",NODE_DEFAULT_BOXCOLOR:"#666",NODE_DEFAULT_SHAPE:"box",NODE_BOX_OUTLINE_COLOR:"#FFF",DEFAULT_SHADOW_COLOR:"rgba(0,0,0,0.5)",DEFAULT_GROUP_FONT:24,WIDGET_BGCOLOR:"#222",WIDGET_OUTLINE_COLOR:"#666",WIDGET_TEXT_COLOR:"#DDD",WIDGET_SECONDARY_TEXT_COLOR:"#999",LINK_COLOR:"#9A9",EVENT_LINK_COLOR:"#A86",CONNECTING_LINK_COLOR:"#AFA", MAX_NUMBER_OF_NODES:1E3,DEFAULT_POSITION:[100,100],VALID_SHAPES:["default","box","round","card"],BOX_SHAPE:1,ROUND_SHAPE:2,CIRCLE_SHAPE:3,CARD_SHAPE:4,ARROW_SHAPE:5,GRID_SHAPE:6,INPUT:1,OUTPUT:2,EVENT:-1,ACTION:-1,NODE_MODES:["Always","On Event","Never","On Trigger"],NODE_MODES_COLORS:["#666","#422","#333","#224","#626"],ALWAYS:0,ON_EVENT:1,NEVER:2,ON_TRIGGER:3,UP:1,DOWN:2,LEFT:3,RIGHT:4,CENTER:5,LINK_RENDER_MODES:["Straight","Linear","Spline"],STRAIGHT_LINK:0,LINEAR_LINK:1,SPLINE_LINK:2,NORMAL_TITLE:0, -NO_TITLE:1,TRANSPARENT_TITLE:2,AUTOHIDE_TITLE:3,proxy:null,node_images_path:"",debug:!1,catch_exceptions:!0,throw_errors:!0,allow_scripts:!1,registered_node_types:{},node_types_by_file_extension:{},Nodes:{},Globals:{},searchbox_extras:{},auto_sort_node_types:!1,node_box_coloured_when_on:!1,node_box_coloured_by_mode:!1,dialog_close_on_mouse_leave:!0,dialog_close_on_mouse_leave_delay:500,shift_click_do_break_link_from:!1,click_do_break_link_to:!1,search_hide_on_mouse_leave:!0,search_filter_enabled:!1, -search_show_all_on_open:!0,auto_load_slot_types:!1,registered_slot_in_types:{},registered_slot_out_types:{},slot_types_in:[],slot_types_out:[],slot_types_default_in:[],slot_types_default_out:[],alt_drag_do_clone_nodes:!1,do_add_triggers_slots:!1,allow_multi_output_for_events:!0,middle_click_slot_add_default_node:!1,release_link_on_empty_shows_menu:!1,pointerevents_method:"mouse",registerNodeType:function(a,b){if(!b.prototype)throw"Cannot register a simple object, it must be a class with a prototype"; +NO_TITLE:1,TRANSPARENT_TITLE:2,AUTOHIDE_TITLE:3,VERTICAL_LAYOUT:"vertical",proxy:null,node_images_path:"",debug:!1,catch_exceptions:!0,throw_errors:!0,allow_scripts:!1,registered_node_types:{},node_types_by_file_extension:{},Nodes:{},Globals:{},searchbox_extras:{},auto_sort_node_types:!1,node_box_coloured_when_on:!1,node_box_coloured_by_mode:!1,dialog_close_on_mouse_leave:!0,dialog_close_on_mouse_leave_delay:500,shift_click_do_break_link_from:!1,click_do_break_link_to:!1,search_hide_on_mouse_leave:!0, +search_filter_enabled:!1,search_show_all_on_open:!0,auto_load_slot_types:!1,registered_slot_in_types:{},registered_slot_out_types:{},slot_types_in:[],slot_types_out:[],slot_types_default_in:[],slot_types_default_out:[],alt_drag_do_clone_nodes:!1,do_add_triggers_slots:!1,allow_multi_output_for_events:!0,middle_click_slot_add_default_node:!1,release_link_on_empty_shows_menu:!1,pointerevents_method:"mouse",registerNodeType:function(a,b){if(!b.prototype)throw"Cannot register a simple object, it must be a class with a prototype"; b.type=a;f.debug&&console.log("Node registered: "+a);a.split("/");var c=b.name,d=a.lastIndexOf("/");b.category=a.substr(0,d);b.title||(b.title=c);if(b.prototype)for(var e in l.prototype)b.prototype[e]||(b.prototype[e]=l.prototype[e]);if(d=this.registered_node_types[a])console.log("replacing node type: "+a);else if(Object.hasOwnProperty(b.prototype,"shape")||Object.defineProperty(b.prototype,"shape",{set:function(a){switch(a){case "default":delete this._shape;break;case "box":this._shape=f.BOX_SHAPE; break;case "round":this._shape=f.ROUND_SHAPE;break;case "circle":this._shape=f.CIRCLE_SHAPE;break;case "card":this._shape=f.CARD_SHAPE;break;default:this._shape=a}},get:function(a){return this._shape},enumerable:!0,configurable:!0}),b.prototype.onPropertyChange&&console.warn("LiteGraph node class "+a+" has onPropertyChange method, it must be called onPropertyChanged with d at the end"),b.supported_extensions)for(e in b.supported_extensions){var g=b.supported_extensions[e];g&&g.constructor===String&& (this.node_types_by_file_extension[g.toLowerCase()]=b)}this.registered_node_types[a]=b;b.constructor.name&&(this.Nodes[c]=b);if(f.onNodeTypeRegistered)f.onNodeTypeRegistered(a,b);if(d&&f.onNodeTypeReplaced)f.onNodeTypeReplaced(a,b,d);b.prototype.onPropertyChange&&console.warn("LiteGraph node class "+a+" has onPropertyChange method, it must be called onPropertyChanged with d at the end");if(b.supported_extensions)for(e=0;ek&&(k=e.size[0]),n+=e.size[1]+a+f.NODE_TITLE_HEIGHT;b+=k+a}this.setDirtyCanvas(!0,!0)};m.prototype.getTime=function(){return this.globaltime};m.prototype.getFixedTime=function(){return this.fixedtime};m.prototype.getElapsedTime=function(){return this.elapsed_time}; -m.prototype.sendEventToAllNodes=function(a,b,c){c=c||f.ALWAYS;var d=this._nodes_in_order?this._nodes_in_order:this._nodes;if(d)for(var e=0,g=d.length;e=f.MAX_NUMBER_OF_NODES)throw"LiteGraph: max number of nodes in a graph reached";null==a.id||-1==a.id?a.id=++this.last_node_id:this.last_node_idn&&(n=g.size[u]);p+=g.size[b==f.VERTICAL_LAYOUT?0:1]+a+f.NODE_TITLE_HEIGHT}c+=n+a}this.setDirtyCanvas(!0,!0)};m.prototype.getTime=function(){return this.globaltime}; +m.prototype.getFixedTime=function(){return this.fixedtime};m.prototype.getElapsedTime=function(){return this.elapsed_time};m.prototype.sendEventToAllNodes=function(a,b,c){c=c||f.ALWAYS;var d=this._nodes_in_order?this._nodes_in_order:this._nodes;if(d)for(var e=0,g=d.length;e=f.MAX_NUMBER_OF_NODES)throw"LiteGraph: max number of nodes in a graph reached"; +null==a.id||-1==a.id?a.id=++this.last_node_id:this.last_node_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={}};l.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]=f.cloneObject(a[b],this[b]):this[b]=a[b]);a.title||(this.title=this.constructor.title);if(this.onConnectionsChange){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}};l.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};l.prototype.getInputDataByName=function(a,b){a=this.findInputSlot(a);return-1==a?null:this.getInputData(a, -b)};l.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};l.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};l.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};l.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 f.debug&&console.log("Connect: Error, slot number not found"),null;b&&b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"target node is null";if(b==this)return null;if(c.constructor===String){if(c=b.findInputSlot(c),-1==c)return f.debug&&console.log("Connect: Error, no slot of name "+c),null}else if(c=== -f.EVENT)if(f.do_add_triggers_slots)b.changeMode(f.ON_TRIGGER),c=b.findInputSlot("onTrigger");else return null;else if(!b.inputs||c>=b.inputs.length)return f.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||!f.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 f.EVENT:f.allow_multi_output_for_events||(this.graph.beforeChange(),this.disconnectOutput(a,!1,{doProcessChange:!1}))}var g=new t(++this.graph.last_link_id,d.type||e.type,this.id,a,b.id,c);this.graph.links[g.id]=g;null==e.links&&(e.links=[]);e.links.push(g.id);b.inputs[c].link= -g.id;this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(f.OUTPUT,a,!0,g,e);if(b.onConnectionsChange)b.onConnectionsChange(f.INPUT,c,!0,g,d);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(f.INPUT,b,c,this,a),this.graph.onNodeConnectionChange(f.OUTPUT,this,a,b,c));this.setDirtyCanvas(!1,!0);this.graph.afterChange();this.graph.connectionChange(this,g);return g};l.prototype.disconnectOutput=function(a,b){if(a.constructor===String){if(a= -this.findOutputSlot(a),-1==a)return f.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.outputs||a>=this.outputs.length)return f.debug&&console.log("Connect: Error, slot number not found"),!1;var 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 f.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 g=e.outputs[d.origin_slot];if(!g||!g.links||0==g.links.length)return!1;for(var k=0,n=g.links.length;kb&&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]-f.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)*f.NODE_SLOT_HEIGHT+(this.constructor.slot_start_y||0);return c};l.prototype.alignToGrid=function(){this.pos[0]=f.CANVAS_GRID_SIZE*Math.round(this.pos[0]/f.CANVAS_GRID_SIZE);this.pos[1]=f.CANVAS_GRID_SIZE*Math.round(this.pos[1]/f.CANVAS_GRID_SIZE)};l.prototype.trace=function(a){this.console||(this.console= -[]);this.console.push(a);this.console.length>l.MAX_CONSOLE&&this.console.shift();if(this.graph.onNodeTrace)this.graph.onNodeTrace(this,a)};l.prototype.setDirtyCanvas=function(a,b){this.graph&&this.graph.sendActionToCanvas("setDirty",[a,b])};l.prototype.loadImage=function(a){var b=new Image;b.src=f.node_images_path+a;b.ready=!1;var c=this;b.onload=function(){this.ready=!0;c.setDirtyCanvas(!0)};return b};l.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})};w.prototype.configure=function(a){this.title=a.title;this._bounding.set(a.bounding);this.color=a.color;this.font=a.font};w.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}};w.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)}};z.prototype.changeDeltaScale=function(a,b){this.changeScale(this.scale*a,b)};z.prototype.reset=function(){this.scale=1;this.offset[0]=0;this.offset[1]=0};x.LGraphCanvas=f.LGraphCanvas=h;h.DEFAULT_BACKGROUND_IMAGE="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQBJREFUeNrs1rEKwjAUhlETUkj3vP9rdmr1Ysammk2w5wdxuLgcMHyptfawuZX4pJSWZTnfnu/lnIe/jNNxHHGNn//HNbbv+4dr6V+11uF527arU7+u63qfa/bnmh8sWLBgwYJlqRf8MEptXPBXJXa37BSl3ixYsGDBMliwFLyCV/DeLIMFCxYsWLBMwSt4Be/NggXLYMGCBUvBK3iNruC9WbBgwYJlsGApeAWv4L1ZBgsWLFiwYJmCV/AK3psFC5bBggULloJX8BpdwXuzYMGCBctgwVLwCl7Be7MMFixYsGDBsu8FH1FaSmExVfAxBa/gvVmwYMGCZbBg/W4vAQYA5tRF9QYlv/QAAAAASUVORK5CYII="; -h.link_type_colors={"-1":f.EVENT_LINK_COLOR,number:"#AAA",node:"#DCA"};h.gradients={};h.prototype.clear=function(){this.fps=this.render_time=this.last_draw_time=this.frame=0;this.dragging_rectangle=null;this.selected_nodes={};this.selected_group=null;this.visible_nodes=[];this.connecting_node=this.node_capturing_input=this.node_over=this.node_dragged=null;this.highlighted_links={};this.dragging_canvas=!1;this.dirty_bgcanvas=this.dirty_canvas=!0;this.node_widget=this.node_in_panel=this.dirty_area= -null;this.last_mouse=[0,0];this.last_mouseclick=0;this.pointer_is_double=this.pointer_is_down=!1;this.visible_area.set([0,0,0,0]);if(this.onClear)this.onClear()};h.prototype.setGraph=function(a,b){this.graph!=a&&(b||this.clear(),!a&&this.graph?this.graph.detachCanvas(this):(a.attachCanvas(this),this._graph_stack&&(this._graph_stack=null),this.setDirty(!0,!0)))};h.prototype.getTopGraph=function(){return this._graph_stack.length?this._graph_stack[0]:this.graph};h.prototype.openSubgraph=function(a){if(!a)throw"graph cannot be null"; -if(this.graph==a)throw"graph cannot be the same";this.clear();this.graph&&(this._graph_stack||(this._graph_stack=[]),this._graph_stack.push(this.graph));a.attachCanvas(this);this.checkPanels();this.setDirty(!0,!0)};h.prototype.closeSubgraph=function(){if(this._graph_stack&&0!=this._graph_stack.length){var a=this.graph._subgraph_node,b=this._graph_stack.pop();this.selected_nodes={};this.highlighted_links={};b.attachCanvas(this);this.setDirty(!0,!0);a&&(this.centerOnNode(a),this.selectNodes([a]));this.ds.offset= -[0,0];this.ds.scale=1}};h.prototype.getCurrentGraph=function(){return this.graph};h.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()}};h.prototype._doNothing=function(a){a.preventDefault();return!1};h.prototype._doReturnTrue=function(a){a.preventDefault(); -return!0};h.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);f.pointerListenerAdd(a,"down",this._mousedown_callback,!0);a.addEventListener("mousewheel",this._mousewheel_callback, +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]=f.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}};l.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};l.prototype.getInputDataByName=function(a,b){a=this.findInputSlot(a);return-1==a?null:this.getInputData(a,b)};l.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};l.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};l.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};l.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 f.debug&&console.log("Connect: Error, slot number not found"),null;b&&b.constructor=== +Number&&(b=this.graph.getNodeById(b));if(!b)throw"target node is null";if(b==this)return null;if(c.constructor===String){if(c=b.findInputSlot(c),-1==c)return f.debug&&console.log("Connect: Error, no slot of name "+c),null}else if(c===f.EVENT)if(f.do_add_triggers_slots)b.changeMode(f.ON_TRIGGER),c=b.findInputSlot("onTrigger");else return null;else if(!b.inputs||c>=b.inputs.length)return f.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||!f.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 f.EVENT:f.allow_multi_output_for_events||(this.graph.beforeChange(), +this.disconnectOutput(a,!1,{doProcessChange:!1}))}var g=new t(++this.graph.last_link_id,d.type||e.type,this.id,a,b.id,c);this.graph.links[g.id]=g;null==e.links&&(e.links=[]);e.links.push(g.id);b.inputs[c].link=g.id;this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(f.OUTPUT,a,!0,g,e);if(b.onConnectionsChange)b.onConnectionsChange(f.INPUT,c,!0,g,d);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(f.INPUT,b,c,this,a),this.graph.onNodeConnectionChange(f.OUTPUT, +this,a,b,c));this.setDirtyCanvas(!1,!0);this.graph.afterChange();this.graph.connectionChange(this,g);return g};l.prototype.disconnectOutput=function(a,b){if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return f.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.outputs||a>=this.outputs.length)return f.debug&&console.log("Connect: Error, slot number not found"),!1;var 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 f.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 g=e.outputs[d.origin_slot];if(!g||!g.links||0==g.links.length)return!1;for(var h=0,n=g.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&&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]-f.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)*f.NODE_SLOT_HEIGHT+(this.constructor.slot_start_y||0);return c};l.prototype.alignToGrid=function(){this.pos[0]=f.CANVAS_GRID_SIZE*Math.round(this.pos[0]/ +f.CANVAS_GRID_SIZE);this.pos[1]=f.CANVAS_GRID_SIZE*Math.round(this.pos[1]/f.CANVAS_GRID_SIZE)};l.prototype.trace=function(a){this.console||(this.console=[]);this.console.push(a);this.console.length>l.MAX_CONSOLE&&this.console.shift();if(this.graph.onNodeTrace)this.graph.onNodeTrace(this,a)};l.prototype.setDirtyCanvas=function(a,b){this.graph&&this.graph.sendActionToCanvas("setDirty",[a,b])};l.prototype.loadImage=function(a){var b=new Image;b.src=f.node_images_path+a;b.ready=!1;var c=this;b.onload= +function(){this.ready=!0;c.setDirtyCanvas(!0)};return b};l.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})};w.prototype.configure=function(a){this.title=a.title;this._bounding.set(a.bounding);this.color=a.color;this.font=a.font};w.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}};w.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)}};A.prototype.changeDeltaScale=function(a,b){this.changeScale(this.scale*a,b)};A.prototype.reset=function(){this.scale=1;this.offset[0]=0;this.offset[1]=0};x.LGraphCanvas=f.LGraphCanvas=k;k.DEFAULT_BACKGROUND_IMAGE="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQBJREFUeNrs1rEKwjAUhlETUkj3vP9rdmr1Ysammk2w5wdxuLgcMHyptfawuZX4pJSWZTnfnu/lnIe/jNNxHHGNn//HNbbv+4dr6V+11uF527arU7+u63qfa/bnmh8sWLBgwYJlqRf8MEptXPBXJXa37BSl3ixYsGDBMliwFLyCV/DeLIMFCxYsWLBMwSt4Be/NggXLYMGCBUvBK3iNruC9WbBgwYJlsGApeAWv4L1ZBgsWLFiwYJmCV/AK3psFC5bBggULloJX8BpdwXuzYMGCBctgwVLwCl7Be7MMFixYsGDBsu8FH1FaSmExVfAxBa/gvVmwYMGCZbBg/W4vAQYA5tRF9QYlv/QAAAAASUVORK5CYII="; +k.link_type_colors={"-1":f.EVENT_LINK_COLOR,number:"#AAA",node:"#DCA"};k.gradients={};k.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()};k.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)))};k.prototype.getTopGraph=function(){return this._graph_stack.length?this._graph_stack[0]:this.graph};k.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)};k.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}};k.prototype.getCurrentGraph=function(){return this.graph};k.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()}};k.prototype._doNothing=function(a){a.preventDefault();return!1};k.prototype._doReturnTrue=function(a){a.preventDefault(); +return!0};k.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);f.pointerListenerAdd(a,"down",this._mousedown_callback,!0);a.addEventListener("mousewheel",this._mousewheel_callback, !1);f.pointerListenerAdd(a,"up",this._mouseup_callback,!0);f.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}};h.prototype.unbindEvents=function(){if(this._events_binded){var a=this.getCanvasWindow().document;f.pointerListenerRemove(this.canvas,"move",this._mousedown_callback);f.pointerListenerRemove(this.canvas,"up",this._mousedown_callback);f.pointerListenerRemove(this.canvas,"down",this._mousedown_callback);this.canvas.removeEventListener("mousewheel",this._mousewheel_callback); +this._doNothing,!1);a.addEventListener("drop",this._ondrop_callback,!1);a.addEventListener("dragenter",this._doReturnTrue,!1);this._events_binded=!0}};k.prototype.unbindEvents=function(){if(this._events_binded){var a=this.getCanvasWindow().document;f.pointerListenerRemove(this.canvas,"move",this._mousedown_callback);f.pointerListenerRemove(this.canvas,"up",this._mousedown_callback);f.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")}; -h.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()};h.prototype.enableWebGL=function(){this.gl=this.ctx=enableWebGLCanvas(this.canvas);this.ctx.webgl=!0;this.bgcanvas=this.canvas;this.bgctx=this.gl;this.canvas.webgl_enabled=!0};h.prototype.setDirty=function(a,b){a&&(this.dirty_canvas=!0);b&&(this.dirty_bgcanvas=!0)};h.prototype.getCanvasWindow=function(){if(!this.canvas)return window;var a=this.canvas.ownerDocument; -return a.defaultView||a.parentWindow};h.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))};h.prototype.stopRendering=function(){this.is_rendering=!1};h.prototype.blockClick=function(){this.block_click=!0;this.last_mouseclick=0};h.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();h.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&&k;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&&k?!0:!1;this.pointer_is_down=!0;this.canvas.focus();f.closeAllContextMenus(b);if(!this.onMouse|| -1!=this.onMouse(a)){if(1!=a.which||this.pointer_is_double)if(2==a.which){if(f.middle_click_slot_add_default_node&&g&&this.allow_interaction&&!d&&!this.read_only&&!this.connecting_node&&!g.flags.collapsed&&!this.live_mode){e=d=k=!1;if(g.outputs)for(u=0,n=g.outputs.length;u=this.viewport[0]&&d=this.viewport[1]&&ee-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();f.closeAllContextMenus(b);if(!this.onMouse|| +1!=this.onMouse(a)){if(1!=a.which||this.pointer_is_double)if(2==a.which){if(f.middle_click_slot_add_default_node&&g&&this.allow_interaction&&!d&&!this.read_only&&!this.connecting_node&&!g.flags.collapsed&&!this.live_mode){e=d=h=!1;if(g.outputs)for(u=0,n=g.outputs.length;ug.size[0]-f.NODE_TITLE_HEIGHT&&0>n[1]&&(c=this,setTimeout(function(){c.openSubgraph(g.subgraph)},10)),this.live_mode&&(u=k=!0));u||(this.allow_dragnodes&&(this.graph.beforeChange(),this.node_dragged=g),this.selected_nodes[g.id]||this.processNodeSelected(g,a));this.dirty_canvas=!0}}else if(!d){if(!this.read_only)for(u=0;un[0]+4||a.canvasYn[1]+4)){this.showLinkMenu(k,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>D([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());k=!0}!d&&k&&this.allow_dragcanvas&&(this.dragging_canvas=!0)}this.last_mouse[0]=a.clientX;this.last_mouse[1]=a.clientY;this.last_mouseclick=f.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}}}};h.prototype.processMouseMove=function(a){this.autoresize&&this.resize();this.set_canvas_dirty_on_mouse_event&&(this.dirty_canvas=!0);if(this.graph){h.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(), +n,this);this.processNodeDblClicked(g);u=!0}g.onMouseDown&&g.onMouseDown(a,n,this)?u=!0:(g.subgraph&&!g.skip_subgraph_button&&!g.flags.collapsed&&n[0]>g.size[0]-f.NODE_TITLE_HEIGHT&&0>n[1]&&(c=this,setTimeout(function(){c.openSubgraph(g.subgraph)},10)),this.live_mode&&(u=h=!0));u||(this.allow_dragnodes&&(this.graph.beforeChange(),this.node_dragged=g),this.selected_nodes[g.id]||this.processNodeSelected(g,a));this.dirty_canvas=!0}}else if(!d){if(!this.read_only)for(u=0;un[0]+4||a.canvasYn[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>E([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());h=!0}!d&&h&&this.allow_dragcanvas&&(this.dragging_canvas=!0)}this.last_mouse[0]=a.clientX;this.last_mouse[1]=a.clientY;this.last_mouseclick=f.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}}}};k.prototype.processMouseMove=function(a){this.autoresize&&this.resize();this.set_canvas_dirty_on_mouse_event&&(this.dirty_canvas=!0);if(this.graph){k.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);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&&!this.read_only){this.connecting_node&&(this.dirty_canvas=!0);var d=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes);b=0;for(var e=this.graph._nodes.length;b< e;++b)if(this.graph._nodes[b].mouseOver&&d!=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(d){d.redraw_on_mouse&&(this.dirty_canvas=!0);if(!d.mouseOver&&(d.mouseOver=!0,this.node_over=d,this.dirty_canvas=!0,d.onMouseEnter))d.onMouseEnter(a);if(d.onMouseMove)d.onMouseMove(a,[a.canvasX-d.pos[0],a.canvasY-d.pos[1]],this);if(this.connecting_node)if(this.connecting_output){if(e= -this._highlight_input||[0,0],!this.isOverNodeBox(d,a.canvasX,a.canvasY)){var g=this.isOverNodeInput(d,a.canvasX,a.canvasY,e);if(-1!=g&&d.inputs[g]){var k=d.inputs[g].type;f.isValidConnection(this.connecting_output.type,k)&&(this._highlight_input=e,this._highlight_input_slot=d.inputs[g])}else this._highlight_input_slot=this._highlight_input=null}}else this.connecting_input&&(e=this._highlight_output||[0,0],this.isOverNodeBox(d,a.canvasX,a.canvasY)||(g=this.isOverNodeOutput(d,a.canvasX,a.canvasY,e), --1!=g&&d.outputs[g]?(k=d.outputs[g].type,f.isValidConnection(this.connecting_input.type,k)&&(this._highlight_output=e)):this._highlight_output=null));this.canvas&&(C(a.canvasX,a.canvasY,d.pos[0]+d.size[0]-5,d.pos[1]+d.size[1]-5,5,5)?this.canvas.style.cursor="se-resize":this.canvas.style.cursor="crosshair")}else{e=null;for(b=0;bk[0]+4||a.canvasYk[1]+4)){e=g;break}e!=this.over_link_center&& +this._highlight_input||[0,0],!this.isOverNodeBox(d,a.canvasX,a.canvasY)){var g=this.isOverNodeInput(d,a.canvasX,a.canvasY,e);if(-1!=g&&d.inputs[g]){var h=d.inputs[g].type;f.isValidConnection(this.connecting_output.type,h)&&(this._highlight_input=e,this._highlight_input_slot=d.inputs[g])}else this._highlight_input_slot=this._highlight_input=null}}else this.connecting_input&&(e=this._highlight_output||[0,0],this.isOverNodeBox(d,a.canvasX,a.canvasY)||(g=this.isOverNodeOutput(d,a.canvasX,a.canvasY,e), +-1!=g&&d.outputs[g]?(h=d.outputs[g].type,f.isValidConnection(this.connecting_input.type,h)&&(this._highlight_output=e)):this._highlight_output=null));this.canvas&&(D(a.canvasX,a.canvasY,d.pos[0]+d.size[0]-5,d.pos[1]+d.size[1]-5,5,5)?this.canvas.style.cursor="se-resize":this.canvas.style.cursor="crosshair")}else{e=null;for(b=0;bh[0]+4||a.canvasYh[1]+4)){e=g;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;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}};h.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;h.active_canvas=this;this.options.skip_events||(f.pointerListenerRemove(c,"move",this._mousemove_callback,!0),f.pointerListenerAdd(this.canvas,"move",this._mousemove_callback,!0),f.pointerListenerRemove(c,"up",this._mouseup_callback,!0));this.adjustMouseEvent(a);c=f.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], +!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}};k.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;k.active_canvas=this;this.options.skip_events||(f.pointerListenerRemove(c,"move",this._mousemove_callback,!0),f.pointerListenerAdd(this.canvas,"move",this._mousemove_callback,!0),f.pointerListenerRemove(c,"up",this._mouseup_callback,!0));this.adjustMouseEvent(a);c=f.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),g=Math.abs(this.dragging_rectangle[2]),k=Math.abs(this.dragging_rectangle[3]),n=0>this.dragging_rectangle[3]?this.dragging_rectangle[1]-k:this.dragging_rectangle[1];this.dragging_rectangle[0]=0>this.dragging_rectangle[2]?this.dragging_rectangle[0]-g:this.dragging_rectangle[0];this.dragging_rectangle[1]=n;this.dragging_rectangle[2]=g;this.dragging_rectangle[3]=k;if(!d||10this.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]-g:this.dragging_rectangle[0];this.dragging_rectangle[1]=n;this.dragging_rectangle[2]=g;this.dragging_rectangle[3]=h;if(!d||10a.click_time&&C(a.canvasX,a.canvasY,d.pos[0],d.pos[1]-f.NODE_TITLE_HEIGHT,f.NODE_TITLE_HEIGHT,f.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.resizing_node=null;else if(this.node_dragged){(d=this.node_dragged)&&300>a.click_time&&D(a.canvasX,a.canvasY,d.pos[0],d.pos[1]-f.NODE_TITLE_HEIGHT,f.NODE_TITLE_HEIGHT,f.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}};h.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}};h.prototype.isOverNodeBox=function(a,b,c){var d=f.NODE_TITLE_HEIGHT;return C(b,c,a.pos[0]+2,a.pos[1]+2-d,d-4,d-4)?!0:!1};h.prototype.isOverNodeInput=function(a,b,c,d){if(a.inputs)for(var e=0,g=a.inputs.length;e=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}};k.prototype.isOverNodeBox=function(a,b,c){var d=f.NODE_TITLE_HEIGHT;return D(b,c,a.pos[0]+2,a.pos[1]+2-d,d-4,d-4)?!0:!1};k.prototype.isOverNodeInput=function(a,b,c,d){if(a.inputs)for(var e=0,g=a.inputs.length;ea.nodes[d].pos[0]&&(b[0]=a.nodes[d].pos[0],c[0]=d),b[1]>a.nodes[d].pos[1]&&(b[1]=a.nodes[d].pos[1],c[1]=d)):(b=[a.nodes[d].pos[0],a.nodes[d].pos[1]],c=[d,d]);c=[];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}};h.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);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 g=this.editor_alpha;b.globalAlpha=g;this.render_shadows&&!e?(b.shadowColor=f.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 k=a._shape||f.BOX_SHAPE;I.set(a.size);var n=a.horizontal;if(a.flags.collapsed){b.font=this.inner_text_font;var p=a.getTitle?a.getTitle():a.title;null!=p&&(a._collapsed_width=Math.min(a.size[0],b.measureText(p).width+2*f.NODE_TITLE_HEIGHT),I[0]=a._collapsed_width,I[1]=0)}a.clip_area&&(b.save(),b.beginPath(),k==f.BOX_SHAPE?b.rect(0,0,I[0],I[1]):k==f.ROUND_SHAPE? -b.roundRect(0,0,I[0],I[1],[10]):k==f.CIRCLE_SHAPE&&b.arc(.5*I[0],.5*I[1],.5*I[0],0,2*Math.PI),b.clip());a.has_errors&&(d="red");this.drawNodeShape(a,b,I,c,d,a.is_selected,a.mouseOver);b.shadowColor="transparent";if(a.onDrawForeground)a.onDrawForeground(b,this,this.canvas);b.textAlign=n?"center":"left";b.font=this.inner_text_font;d=!e;var r=this.connecting_output;k=this.connecting_input;b.lineWidth=1;p=0;var u=new Float32Array(2);if(!a.flags.collapsed){if(a.inputs)for(c=0;cthis.ds.scale,p=a._shape||a.constructor.shape||f.ROUND_SHAPE,r=a.constructor.title_mode,u=!0;r==f.TRANSPARENT_TITLE||r==f.NO_TITLE?u=!1:r==f.AUTOHIDE_TITLE&&k&&(u=!0);B[0]=0;B[1]=u?-e:0;B[2]=c[0]+1;B[3]=u?c[1]+e:c[1];k=b.globalAlpha;b.beginPath();p==f.BOX_SHAPE||n?b.fillRect(B[0],B[1],B[2],B[3]):p==f.ROUND_SHAPE||p==f.CARD_SHAPE?b.roundRect(B[0],B[1],B[2],B[3],p==f.CARD_SHAPE?[this.round_radius,this.round_radius, -0,0]:[this.round_radius]):p==f.CIRCLE_SHAPE&&b.arc(.5*c[0],.5*c[1],.5*c[0],0,2*Math.PI);b.fill();!a.flags.collapsed&&u&&(b.shadowColor="transparent",b.fillStyle="rgba(0,0,0,0.2)",b.fillRect(0,-1,B[2],2));b.shadowColor="transparent";if(a.onDrawBackground)a.onDrawBackground(b,this,this.canvas,this.graph_mouse);if(u||r==f.TRANSPARENT_TITLE){if(a.onDrawTitleBar)a.onDrawTitleBar(b,e,c,this.ds.scale,d);else if(r!=f.TRANSPARENT_TITLE&&(a.constructor.title_color||this.render_title_colored)){u=a.constructor.title_color|| -d;a.flags.collapsed&&(b.shadowColor=f.DEFAULT_SHADOW_COLOR);if(this.use_gradients){var q=h.gradients[u];q||(q=h.gradients[u]=b.createLinearGradient(0,0,400,0),q.addColorStop(0,u),q.addColorStop(1,"#000"));b.fillStyle=q}else b.fillStyle=u;b.beginPath();p==f.BOX_SHAPE||n?b.rect(0,-e,c[0]+1,e):(p==f.ROUND_SHAPE||p==f.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"}u=!1;f.node_box_coloured_by_mode&& -f.NODE_MODES_COLORS[a.mode]&&(u=f.NODE_MODES_COLORS[a.mode]);f.node_box_coloured_when_on&&(u=a.action_triggered?"#FFF":a.execute_triggered?"#AAA":u);if(a.onDrawTitleBox)a.onDrawTitleBox(b,e,c,this.ds.scale);else p==f.ROUND_SHAPE||p==f.CIRCLE_SHAPE||p==f.CARD_SHAPE?(n&&(b.fillStyle="black",b.beginPath(),b.arc(.5*e,-.5*e,6,0,2*Math.PI),b.fill()),b.fillStyle=a.boxcolor||u||f.NODE_DEFAULT_BOXCOLOR,n?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())):(n&&(b.fillStyle= -"black",b.fillRect(.5*(e-10)-1,-.5*(e+10)-1,12,12)),b.fillStyle=a.boxcolor||u||f.NODE_DEFAULT_BOXCOLOR,b.fillRect(.5*(e-10),-.5*(e+10),10,10));b.globalAlpha=k;if(a.onDrawTitleText)a.onDrawTitleText(b,e,c,this.ds.scale,this.title_text_font,g);!n&&(b.font=this.title_text_font,k=String(a.getTitle()))&&(b.fillStyle=g?f.NODE_SELECTED_TITLE_COLOR:a.constructor.title_text_color||this.node_title_color,a.flags.collapsed?(b.textAlign="left",b.measureText(k),b.fillText(k.substr(0,20),e,f.NODE_TITLE_TEXT_Y-e), -b.textAlign="left"):(b.textAlign="left",b.fillText(k,e,f.NODE_TITLE_TEXT_Y-e)));a.flags.collapsed||!a.subgraph||a.skip_subgraph_button||(k=f.NODE_TITLE_HEIGHT,u=a.size[0]-k,q=f.isInsideRectangle(this.graph_mouse[0]-a.pos[0],this.graph_mouse[1]-a.pos[1],u+2,-k+2,k-4,k-4),b.fillStyle=q?"#888":"#555",p==f.BOX_SHAPE||n?b.fillRect(u+2,-k+2,k-4,k-4):(b.beginPath(),b.roundRect(u+2,-k+2,k-4,k-4,[4]),b.fill()),b.fillStyle="#333",b.beginPath(),b.moveTo(u+.2*k,.6*-k),b.lineTo(u+.8*k,.6*-k),b.lineTo(u+.5*k,.3* --k),b.fill());if(a.onDrawTitle)a.onDrawTitle(b)}if(g){if(a.onBounding)a.onBounding(B);r==f.TRANSPARENT_TITLE&&(B[1]-=e,B[3]+=e);b.lineWidth=1;b.globalAlpha=.8;b.beginPath();p==f.BOX_SHAPE?b.rect(-6+B[0],-6+B[1],12+B[2],12+B[3]):p==f.ROUND_SHAPE||p==f.CARD_SHAPE&&a.flags.collapsed?b.roundRect(-6+B[0],-6+B[1],12+B[2],12+B[3],[2*this.round_radius]):p==f.CARD_SHAPE?b.roundRect(-6+B[0],-6+B[1],12+B[2],12+B[3],[2*this.round_radius,2,2*this.round_radius,2]):p==f.CIRCLE_SHAPE&&b.arc(.5*c[0],.5*c[1],.5*c[0]+ -6,0,2*Math.PI);b.strokeStyle=f.NODE_BOX_OUTLINE_COLOR;b.stroke();b.strokeStyle=d;b.globalAlpha=1}0F[2]&&(F[0]+=F[2],F[2]=Math.abs(F[2]));0>F[3]&&(F[1]+=F[3],F[3]=Math.abs(F[3]));if(A(F, -K)){var y=p.outputs[r];r=g.inputs[k];if(y&&r&&(p=y.dir||(p.horizontal?f.DOWN:f.RIGHT),r=r.dir||(g.horizontal?f.UP:f.LEFT),this.renderLink(a,u,q,n,!1,0,null,p,r),n&&n._last_time&&1E3>b-n._last_time)){y=2-.002*(b-n._last_time);var h=a.globalAlpha;a.globalAlpha=h*y;this.renderLink(a,u,q,n,!0,y,"white",p,r);a.globalAlpha=h}}}}}}a.globalAlpha=1};h.prototype.renderLink=function(a,b,c,d,e,g,k,n,p,r){d&&this.visible_links.push(d);!k&&d&&(k=d.color||h.link_type_colors[d.type]);k||(k=this.default_link_color); -null!=d&&this.highlighted_links[d.id]&&(k="#FFF");n=n||f.RIGHT;p=p||f.LEFT;var u=D(b,c);this.render_connections_border&&.6b[1]?0:Math.PI,a.save(),a.translate(q[0],q[1]),a.rotate(u),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(r),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(g)for(a.fillStyle=k,q=0;5>q;++q)g=(.001*f.getTime()+.2*q)%1,e=this.computeConnectionPoint(b,c,g,n,p),a.beginPath(),a.arc(e[0],e[1],5,0,2*Math.PI),a.fill()};h.prototype.computeConnectionPoint=function(a,b,c,d,e){d=d||f.RIGHT;e=e||f.LEFT;var g=D(a,b),k=[a[0],a[1]],n=[b[0],b[1]];switch(d){case f.LEFT:k[0]+=-.25*g;break;case f.RIGHT:k[0]+=.25*g;break;case f.UP:k[1]+= --.25*g;break;case f.DOWN:k[1]+=.25*g}switch(e){case f.LEFT:n[0]+=-.25*g;break;case f.RIGHT:n[0]+=.25*g;break;case f.UP:n[1]+=-.25*g;break;case f.DOWN:n[1]+=.25*g}d=(1-c)*(1-c)*(1-c);e=3*(1-c)*(1-c)*c;g=3*(1-c)*c*c;c*=c*c;return[d*a[0]+e*k[0]+g*n[0]+c*b[0],d*a[1]+e*k[1]+g*n[1]+c*b[1]]};h.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;cg||g>l-12||kq.last_y+y||void 0===q.last_y)){d=q.value;switch(q.type){case "button":c.type===f.pointerevents_method+"down"&&(q.callback&&setTimeout(function(){q.callback(q,h,a,b,c)},20),this.dirty_canvas=q.clicked=!0);break;case "slider":r=Math.clamp((g-15)/(l-30),0,1);q.value=q.options.min+(q.options.max-q.options.min)*r;q.callback&& -setTimeout(function(){e(q,q.value)},20);this.dirty_canvas=!0;break;case "number":case "combo":d=q.value;if(c.type==f.pointerevents_method+"move"&&"number"==q.type)q.value+=.1*c.deltaX*(q.options.step||1),null!=q.options.min&&q.valueq.options.max&&(q.value=q.options.max);else if(c.type==f.pointerevents_method+"down"){var v=q.options.values;v&&v.constructor===Function&&(v=q.options.values(q,a));var m=null;"number"!=q.type&&(m=v.constructor=== -Array?v:Object.keys(v));g=40>g?-1:g>l-40?1:0;if("number"==q.type)q.value+=.1*g*(q.options.step||1),null!=q.options.min&&q.valueq.options.max&&(q.value=q.options.max);else if(g)r=-1,this.last_mouseclick=0,r=v.constructor===Object?m.indexOf(String(q.value))+g:m.indexOf(q.value)+g,r>=m.length&&(r=m.length-1),0>r&&(r=0),q.value=v.constructor===Array?v[r]:r;else{var w=v!=m?Object.values(v):v;new f.ContextMenu(w,{scale:Math.max(1,this.ds.scale), -event:c,className:"dark",callback:function(a,b,c){v!=m&&(a=w.indexOf(a));this.value=a;e(this,a);h.dirty_canvas=!0;return!1}.bind(q)},r)}}else c.type==f.pointerevents_method+"up"&&"number"==q.type&&(g=40>g?-1:g>l-40?1:0,200>c.click_time&&0==g&&this.prompt("Value",q.value,function(a){this.value=Number(a);e(this,this.value)}.bind(q),c));d!=q.value&&setTimeout(function(){e(this,this.value)}.bind(q),20);this.dirty_canvas=!0;break;case "toggle":c.type==f.pointerevents_method+"down"&&(q.value=!q.value,setTimeout(function(){e(q, -q.value)},20));break;case "string":case "text":c.type==f.pointerevents_method+"down"&&this.prompt("Value",q.value,function(a){this.value=a;e(this,a)}.bind(q),c,q.options?q.options.multiline:!1);break;default:q.mouse&&(this.dirty_canvas=q.mouse(c,[g,k],a))}if(d!=q.value){if(a.onWidgetChanged)a.onWidgetChanged(q.name,q.value,d,q);a.graph._version++}return q}}}return null};h.prototype.drawGroups=function(a,b){if(this.graph){a=this.graph._groups;b.save();b.globalAlpha=.5*this.editor_alpha;for(var c=0;c< -a.length;++c){var d=a[c];if(A(this.visible_area,d._bounding)){b.fillStyle=d.color||"#335";b.strokeStyle=d.color||"#335";var e=d._pos,g=d._size;b.globalAlpha=.25*this.editor_alpha;b.beginPath();b.rect(e[0]+.5,e[1]+.5,g[0],g[1]);b.fill();b.globalAlpha=this.editor_alpha;b.stroke();b.beginPath();b.moveTo(e[0]+g[0],e[1]+g[1]);b.lineTo(e[0]+g[0]-10,e[1]+g[1]);b.lineTo(e[0]+g[0],e[1]+g[1]-10);b.fill();g=d.font_size||f.DEFAULT_GROUP_FONT_SIZE;b.font=g+"px Arial";b.textAlign="left";b.fillText(d.title,e[0]+ -4,e[1]+g)}}b.restore()}};h.prototype.adjustNodesSize=function(){for(var a=this.graph._nodes,b=0;bc&&.01>b.editor_alpha&&(clearInterval(d),1>c&&(b.live_mode=!0));1"+(p.label?p.label:n)+""+a+"",value:n})}if(k.length)return new f.ContextMenu(k,{event:c,callback:function(a, -b,c,d){e&&(b=this.getBoundingClientRect(),g.showEditPropertyValue(e,a.value,{position:[b.left,b.top]}))},parentMenu:d,allow_html:!0,node:e},b),!1}};h.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};h.onMenuResizeNode=function(a,b,c,d,e){if(e){a=function(a){a.size=a.computeSize();if(a.onResize)a.onResize(a.size)};b=h.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]); -e.setDirtyCanvas(!0,!0)}};h.prototype.showLinkMenu=function(a,b){var c=this,d=c.graph.getNodeById(a.origin_id),e=c.graph.getNodeById(a.target_id),g=!1;d&&d.outputs&&d.outputs[a.origin_slot]&&(g=d.outputs[a.origin_slot].type);var k=!1;e&&e.outputs&&e.outputs[a.target_slot]&&(k=e.inputs[a.target_slot].type);var n=new f.ContextMenu(["Add Node",null,"Delete",null],{event:b,title:null!=a.data?a.data.constructor.name:null,callback:function(b,f,u){switch(b){case "Add Node":h.onMenuAdd(null,null,u,n,function(b){b.inputs&& -b.inputs.length&&b.outputs&&b.outputs.length&&d.connectByType(a.origin_slot,b,g)&&(b.connectByType(a.target_slot,e,k),b.pos[0]-=.5*b.size[0])});break;case "Delete":c.graph.removeLink(a.id)}}});return!1};h.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==f.EVENT?"_event_":e.type;if((e=b?f.slot_types_default_out:f.slot_types_default_in)&&e[d]){nodeNewType=!1;if("object"==typeof e[d]||"array"==typeof e[d])for(var g in e[d]){if(a.nodeType==e[d][g]||"AUTO"==a.nodeType){nodeNewType=e[d][g];break}}else if(a.nodeType==e[d]||"AUTO"==a.nodeType)nodeNewType=e[d];if(nodeNewType){g=!1;"object"==typeof nodeNewType&&nodeNewType.node&&(g=nodeNewType,nodeNewType=nodeNewType.node);if(e=f.createNode(nodeNewType)){if(g){if(g.properties)for(var k in g.properties)e.addProperty(k, -g.properties[k]);if(g.inputs)for(k in e.inputs=[],g.inputs)e.addOutput(g.inputs[k][0],g.inputs[k][1]);if(g.outputs)for(k in e.outputs=[],g.outputs)e.addOutput(g.outputs[k][0],g.outputs[k][1]);g.title&&(e.title=g.title);g.json&&e.configure(g.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};h.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,g=!1;switch(typeof e){case "string":g=d?a.findOutputSlot(e,!1):a.findInputSlot(e,!1);e=d?a.outputs[e]:a.inputs[e];break;case "object":g=d?a.findOutputSlot(e.name): -a.findInputSlot(e.name);break;case "number":g=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 k=e.type==f.EVENT?"_event_":e.type,n=d?f.slot_types_default_out:f.slot_types_default_in;if(n&&n[k])if("object"==typeof n[k]||"array"==typeof n[k])for(var p in n[k])a.push(n[k][p]);else a.push(n[k]);var r=new f.ContextMenu(a,{event:b.e,title:(e&&""!=e.name?e.name+(k?" | ":""):"")+ -(e&&k?k:""),callback:function(a,f,n){switch(a){case "Add Node":h.onMenuAdd(null,null,n,r,function(a){d?b.nodeFrom.connectByType(g,a,k):b.nodeTo.connectByTypeOutput(g,a,k)});break;case "Search":d?c.showSearchBox(n,{node_from:b.nodeFrom,slot_from:e,type_filter_in:k}):c.showSearchBox(n,{node_to:b.nodeTo,slot_from:e,type_filter_out:k});break;default:c.createDefaultNodeForSlot(Object.assign(b,{position:[b.e.canvasX,b.e.canvasY],nodeType:a}))}}});return!1};h.onShowPropertyEditor=function(a,b,c,d,e){function g(){if(p){var b= -p.value;"Number"==a.type?b=Number(b):"Boolean"==a.type&&(b=!!b);e[k]=b;n.parentNode&&n.parentNode.removeChild(n);e.setDirtyCanvas(!0,!0)}}var k=a.property||"title";b=e[k];var n=document.createElement("div");n.is_modified=!1;n.className="graphdialog";n.innerHTML="";n.close=function(){n.parentNode&&n.parentNode.removeChild(n)};n.querySelector(".name").innerText=k;var p=n.querySelector(".value");p&&(p.value=b,p.addEventListener("blur", -function(a){this.focus()}),p.addEventListener("keydown",function(a){n.is_modified=!0;if(27==a.keyCode)n.close();else if(13==a.keyCode)g();else if(13!=a.keyCode&&"textarea"!=a.target.localName)return;a.preventDefault();a.stopPropagation()}));b=h.active_canvas.canvas;c=b.getBoundingClientRect();var r=d=-20;c&&(d-=c.left,r-=c.top);event?(n.style.left=event.clientX+d+"px",n.style.top=event.clientY+r+"px"):(n.style.left=.5*b.width+d+"px",n.style.top=.5*b.height+r+"px");n.querySelector("button").addEventListener("click", -g);b.parentNode.appendChild(n);p&&p.focus();var u=null;n.addEventListener("mouseleave",function(a){f.dialog_close_on_mouse_leave&&!n.is_modified&&f.dialog_close_on_mouse_leave&&(u=setTimeout(n.close,f.dialog_close_on_mouse_leave_delay))});n.addEventListener("mouseenter",function(a){f.dialog_close_on_mouse_leave&&u&&clearTimeout(u)})};h.prototype.prompt=function(a,b,c,d,e){var g=this;a=a||"";var k=document.createElement("div");k.is_modified=!1;k.className="graphdialog rounded";k.innerHTML=e?" ": -" ";k.close=function(){g.prompt_box=null;k.parentNode&&k.parentNode.removeChild(k)};e=h.active_canvas.canvas;e.parentNode.appendChild(k);1=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}};k.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);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 g=this.editor_alpha;b.globalAlpha=g;this.render_shadows&&!e?(b.shadowColor=f.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||f.BOX_SHAPE;H.set(a.size);var n=a.horizontal;if(a.flags.collapsed){b.font=this.inner_text_font;var p=a.getTitle?a.getTitle():a.title;null!=p&&(a._collapsed_width=Math.min(a.size[0],b.measureText(p).width+2*f.NODE_TITLE_HEIGHT),H[0]=a._collapsed_width,H[1]=0)}a.clip_area&&(b.save(),b.beginPath(),h==f.BOX_SHAPE?b.rect(0,0,H[0],H[1]):h==f.ROUND_SHAPE?b.roundRect(0,0,H[0],H[1],[10]):h==f.CIRCLE_SHAPE&&b.arc(.5*H[0],.5*H[1],.5*H[0],0,2*Math.PI),b.clip());a.has_errors&& +(d="red");this.drawNodeShape(a,b,H,c,d,a.is_selected,a.mouseOver);b.shadowColor="transparent";if(a.onDrawForeground)a.onDrawForeground(b,this,this.canvas);b.textAlign=n?"center":"left";b.font=this.inner_text_font;d=!e;var r=this.connecting_output;h=this.connecting_input;b.lineWidth=1;p=0;var u=new Float32Array(2);if(!a.flags.collapsed){if(a.inputs)for(c=0;cthis.ds.scale,p=a._shape||a.constructor.shape|| +f.ROUND_SHAPE,r=a.constructor.title_mode,u=!0;r==f.TRANSPARENT_TITLE||r==f.NO_TITLE?u=!1:r==f.AUTOHIDE_TITLE&&h&&(u=!0);C[0]=0;C[1]=u?-e:0;C[2]=c[0]+1;C[3]=u?c[1]+e:c[1];h=b.globalAlpha;b.beginPath();p==f.BOX_SHAPE||n?b.fillRect(C[0],C[1],C[2],C[3]):p==f.ROUND_SHAPE||p==f.CARD_SHAPE?b.roundRect(C[0],C[1],C[2],C[3],p==f.CARD_SHAPE?[this.round_radius,this.round_radius,0,0]:[this.round_radius]):p==f.CIRCLE_SHAPE&&b.arc(.5*c[0],.5*c[1],.5*c[0],0,2*Math.PI);b.fill();!a.flags.collapsed&&u&&(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(u||r==f.TRANSPARENT_TITLE){if(a.onDrawTitleBar)a.onDrawTitleBar(b,e,c,this.ds.scale,d);else if(r!=f.TRANSPARENT_TITLE&&(a.constructor.title_color||this.render_title_colored)){u=a.constructor.title_color||d;a.flags.collapsed&&(b.shadowColor=f.DEFAULT_SHADOW_COLOR);if(this.use_gradients){var q=k.gradients[u];q||(q=k.gradients[u]= +b.createLinearGradient(0,0,400,0),q.addColorStop(0,u),q.addColorStop(1,"#000"));b.fillStyle=q}else b.fillStyle=u;b.beginPath();p==f.BOX_SHAPE||n?b.rect(0,-e,c[0]+1,e):(p==f.ROUND_SHAPE||p==f.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"}u=!1;f.node_box_coloured_by_mode&&f.NODE_MODES_COLORS[a.mode]&&(u=f.NODE_MODES_COLORS[a.mode]);f.node_box_coloured_when_on&&(u=a.action_triggered?"#FFF": +a.execute_triggered?"#AAA":u);if(a.onDrawTitleBox)a.onDrawTitleBox(b,e,c,this.ds.scale);else p==f.ROUND_SHAPE||p==f.CIRCLE_SHAPE||p==f.CARD_SHAPE?(n&&(b.fillStyle="black",b.beginPath(),b.arc(.5*e,-.5*e,6,0,2*Math.PI),b.fill()),b.fillStyle=a.boxcolor||u||f.NODE_DEFAULT_BOXCOLOR,n?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())):(n&&(b.fillStyle="black",b.fillRect(.5*(e-10)-1,-.5*(e+10)-1,12,12)),b.fillStyle=a.boxcolor||u||f.NODE_DEFAULT_BOXCOLOR,b.fillRect(.5* +(e-10),-.5*(e+10),10,10));b.globalAlpha=h;if(a.onDrawTitleText)a.onDrawTitleText(b,e,c,this.ds.scale,this.title_text_font,g);!n&&(b.font=this.title_text_font,h=String(a.getTitle()))&&(b.fillStyle=g?f.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),e,f.NODE_TITLE_TEXT_Y-e),b.textAlign="left"):(b.textAlign="left",b.fillText(h,e,f.NODE_TITLE_TEXT_Y-e)));a.flags.collapsed||!a.subgraph||a.skip_subgraph_button|| +(h=f.NODE_TITLE_HEIGHT,u=a.size[0]-h,q=f.isInsideRectangle(this.graph_mouse[0]-a.pos[0],this.graph_mouse[1]-a.pos[1],u+2,-h+2,h-4,h-4),b.fillStyle=q?"#888":"#555",p==f.BOX_SHAPE||n?b.fillRect(u+2,-h+2,h-4,h-4):(b.beginPath(),b.roundRect(u+2,-h+2,h-4,h-4,[4]),b.fill()),b.fillStyle="#333",b.beginPath(),b.moveTo(u+.2*h,.6*-h),b.lineTo(u+.8*h,.6*-h),b.lineTo(u+.5*h,.3*-h),b.fill());if(a.onDrawTitle)a.onDrawTitle(b)}if(g){if(a.onBounding)a.onBounding(C);r==f.TRANSPARENT_TITLE&&(C[1]-=e,C[3]+=e);b.lineWidth= +1;b.globalAlpha=.8;b.beginPath();p==f.BOX_SHAPE?b.rect(-6+C[0],-6+C[1],12+C[2],12+C[3]):p==f.ROUND_SHAPE||p==f.CARD_SHAPE&&a.flags.collapsed?b.roundRect(-6+C[0],-6+C[1],12+C[2],12+C[3],[2*this.round_radius]):p==f.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]):p==f.CIRCLE_SHAPE&&b.arc(.5*c[0],.5*c[1],.5*c[0]+6,0,2*Math.PI);b.strokeStyle=f.NODE_BOX_OUTLINE_COLOR;b.stroke();b.strokeStyle=d;b.globalAlpha=1}0G[2]&&(G[0]+=G[2],G[2]=Math.abs(G[2]));0>G[3]&&(G[1]+=G[3],G[3]=Math.abs(G[3]));if(B(G,L)){var y=p.outputs[r];r=g.inputs[h];if(y&&r&&(p=y.dir||(p.horizontal?f.DOWN:f.RIGHT),r=r.dir||(g.horizontal?f.UP:f.LEFT),this.renderLink(a, +u,q,n,!1,0,null,p,r),n&&n._last_time&&1E3>b-n._last_time)){y=2-.002*(b-n._last_time);var k=a.globalAlpha;a.globalAlpha=k*y;this.renderLink(a,u,q,n,!0,y,"white",p,r);a.globalAlpha=k}}}}}}a.globalAlpha=1};k.prototype.renderLink=function(a,b,c,d,e,g,h,n,p,r){d&&this.visible_links.push(d);!h&&d&&(h=d.color||k.link_type_colors[d.type]);h||(h=this.default_link_color);null!=d&&this.highlighted_links[d.id]&&(h="#FFF");n=n||f.RIGHT;p=p||f.LEFT;var u=E(b,c);this.render_connections_border&&.6b[1]?0:Math.PI,a.save(),a.translate(q[0],q[1]),a.rotate(u),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(r),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(g)for(a.fillStyle=h,q=0;5>q;++q)g=(.001*f.getTime()+.2*q)%1,e=this.computeConnectionPoint(b,c,g,n,p),a.beginPath(),a.arc(e[0],e[1],5,0,2*Math.PI),a.fill()};k.prototype.computeConnectionPoint=function(a,b,c,d,e){d=d||f.RIGHT;e=e||f.LEFT;var g=E(a,b),h=[a[0],a[1]],n=[b[0],b[1]];switch(d){case f.LEFT:h[0]+=-.25*g;break;case f.RIGHT:h[0]+=.25*g;break;case f.UP:h[1]+=-.25*g;break;case f.DOWN:h[1]+=.25*g}switch(e){case f.LEFT:n[0]+=-.25*g;break;case f.RIGHT:n[0]+=.25*g;break; +case f.UP:n[1]+=-.25*g;break;case f.DOWN:n[1]+=.25*g}d=(1-c)*(1-c)*(1-c);e=3*(1-c)*(1-c)*c;g=3*(1-c)*c*c;c*=c*c;return[d*a[0]+e*h[0]+g*n[0]+c*b[0],d*a[1]+e*h[1]+g*n[1]+c*b[1]]};k.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;cg||g>l-12||hq.last_y+y||void 0===q.last_y)){d=q.value;switch(q.type){case "button":c.type===f.pointerevents_method+"down"&&(q.callback&&setTimeout(function(){q.callback(q,k,a,b,c)},20),this.dirty_canvas=q.clicked=!0);break;case "slider":r=Math.clamp((g-15)/(l-30),0,1);q.value=q.options.min+(q.options.max-q.options.min)*r;q.callback&&setTimeout(function(){e(q,q.value)},20);this.dirty_canvas=!0;break;case "number":case "combo":d=q.value;if(c.type== +f.pointerevents_method+"move"&&"number"==q.type)c.deltaX&&(q.value+=.1*c.deltaX*(q.options.step||1)),null!=q.options.min&&q.valueq.options.max&&(q.value=q.options.max);else if(c.type==f.pointerevents_method+"down"){var v=q.options.values;v&&v.constructor===Function&&(v=q.options.values(q,a));var m=null;"number"!=q.type&&(m=v.constructor===Array?v:Object.keys(v));g=40>g?-1:g>l-40?1:0;if("number"==q.type)q.value+=.1*g*(q.options.step|| +1),null!=q.options.min&&q.valueq.options.max&&(q.value=q.options.max);else if(g)r=-1,this.last_mouseclick=0,r=v.constructor===Object?m.indexOf(String(q.value))+g:m.indexOf(q.value)+g,r>=m.length&&(r=m.length-1),0>r&&(r=0),q.value=v.constructor===Array?v[r]:r;else{var w=v!=m?Object.values(v):v;new f.ContextMenu(w,{scale:Math.max(1,this.ds.scale),event:c,className:"dark",callback:function(a,b,c){v!=m&&(a=w.indexOf(a));this.value=a; +e(this,a);k.dirty_canvas=!0;return!1}.bind(q)},r)}}else c.type==f.pointerevents_method+"up"&&"number"==q.type&&(g=40>g?-1:g>l-40?1:0,200>c.click_time&&0==g&&this.prompt("Value",q.value,function(a){this.value=Number(a);e(this,this.value)}.bind(q),c));d!=q.value&&setTimeout(function(){e(this,this.value)}.bind(q),20);this.dirty_canvas=!0;break;case "toggle":c.type==f.pointerevents_method+"down"&&(q.value=!q.value,setTimeout(function(){e(q,q.value)},20));break;case "string":case "text":c.type==f.pointerevents_method+ +"down"&&this.prompt("Value",q.value,function(a){this.value=a;e(this,a)}.bind(q),c,q.options?q.options.multiline:!1);break;default:q.mouse&&(this.dirty_canvas=q.mouse(c,[g,h],a))}if(d!=q.value){if(a.onWidgetChanged)a.onWidgetChanged(q.name,q.value,d,q);a.graph._version++}return q}}}return null};k.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));1"+(p.label?p.label:n)+""+a+"",value:n})}if(h.length)return new f.ContextMenu(h,{event:c,callback:function(a,b,c,d){e&&(b=this.getBoundingClientRect(),g.showEditPropertyValue(e,a.value,{position:[b.left,b.top]}))},parentMenu:d,allow_html:!0, +node:e},b),!1}};k.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};k.onMenuResizeNode=function(a,b,c,d,e){if(e){a=function(a){a.size=a.computeSize();if(a.onResize)a.onResize(a.size)};b=k.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]);e.setDirtyCanvas(!0,!0)}};k.prototype.showLinkMenu=function(a,b){var c=this,d=c.graph.getNodeById(a.origin_id),e=c.graph.getNodeById(a.target_id), +g=!1;d&&d.outputs&&d.outputs[a.origin_slot]&&(g=d.outputs[a.origin_slot].type);var h=!1;e&&e.outputs&&e.outputs[a.target_slot]&&(h=e.inputs[a.target_slot].type);var n=new f.ContextMenu(["Add Node",null,"Delete",null],{event:b,title:null!=a.data?a.data.constructor.name:null,callback:function(b,r,f){switch(b){case "Add Node":k.onMenuAdd(null,null,f,n,function(b){b.inputs&&b.inputs.length&&b.outputs&&b.outputs.length&&d.connectByType(a.origin_slot,b,g)&&(b.connectByType(a.target_slot,e,h),b.pos[0]-= +.5*b.size[0])});break;case "Delete":c.graph.removeLink(a.id)}}});return!1};k.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==f.EVENT?"_event_":e.type;if((e=b?f.slot_types_default_out: +f.slot_types_default_in)&&e[d]){nodeNewType=!1;if("object"==typeof e[d]||"array"==typeof e[d])for(var g in e[d]){if(a.nodeType==e[d][g]||"AUTO"==a.nodeType){nodeNewType=e[d][g];break}}else if(a.nodeType==e[d]||"AUTO"==a.nodeType)nodeNewType=e[d];if(nodeNewType){g=!1;"object"==typeof nodeNewType&&nodeNewType.node&&(g=nodeNewType,nodeNewType=nodeNewType.node);if(e=f.createNode(nodeNewType)){if(g){if(g.properties)for(var h in g.properties)e.addProperty(h,g.properties[h]);if(g.inputs)for(h in e.inputs= +[],g.inputs)e.addOutput(g.inputs[h][0],g.inputs[h][1]);if(g.outputs)for(h in e.outputs=[],g.outputs)e.addOutput(g.outputs[h][0],g.outputs[h][1]);g.title&&(e.title=g.title);g.json&&e.configure(g.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}; +k.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,g=!1;switch(typeof e){case "string":g=d?a.findOutputSlot(e,!1):a.findInputSlot(e,!1);e=d?a.outputs[e]:a.inputs[e];break;case "object":g=d?a.findOutputSlot(e.name):a.findInputSlot(e.name); +break;case "number":g=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 h=e.type==f.EVENT?"_event_":e.type,n=d?f.slot_types_default_out:f.slot_types_default_in;if(n&&n[h])if("object"==typeof n[h]||"array"==typeof n[h])for(var p in n[h])a.push(n[h][p]);else a.push(n[h]);var r=new f.ContextMenu(a,{event:b.e,title:(e&&""!=e.name?e.name+(h?" | ":""):"")+(e&&h?h:""),callback:function(a, +f,n){switch(a){case "Add Node":k.onMenuAdd(null,null,n,r,function(a){d?b.nodeFrom.connectByType(g,a,h):b.nodeTo.connectByTypeOutput(g,a,h)});break;case "Search":d?c.showSearchBox(n,{node_from:b.nodeFrom,slot_from:e,type_filter_in:h}):c.showSearchBox(n,{node_to:b.nodeTo,slot_from:e,type_filter_out:h});break;default:c.createDefaultNodeForSlot(Object.assign(b,{position:[b.e.canvasX,b.e.canvasY],nodeType:a}))}}});return!1};k.onShowPropertyEditor=function(a,b,c,d,e){function g(){if(p){var b=p.value;"Number"== +a.type?b=Number(b):"Boolean"==a.type&&(b=!!b);e[h]=b;n.parentNode&&n.parentNode.removeChild(n);e.setDirtyCanvas(!0,!0)}}var h=a.property||"title";b=e[h];var n=document.createElement("div");n.is_modified=!1;n.className="graphdialog";n.innerHTML="";n.close=function(){n.parentNode&&n.parentNode.removeChild(n)};n.querySelector(".name").innerText=h;var p=n.querySelector(".value");p&&(p.value=b,p.addEventListener("blur", +function(a){this.focus()}),p.addEventListener("keydown",function(a){n.is_modified=!0;if(27==a.keyCode)n.close();else if(13==a.keyCode)g();else if(13!=a.keyCode&&"textarea"!=a.target.localName)return;a.preventDefault();a.stopPropagation()}));b=k.active_canvas.canvas;c=b.getBoundingClientRect();var r=d=-20;c&&(d-=c.left,r-=c.top);event?(n.style.left=event.clientX+d+"px",n.style.top=event.clientY+r+"px"):(n.style.left=.5*b.width+d+"px",n.style.top=.5*b.height+r+"px");n.querySelector("button").addEventListener("click", +g);b.parentNode.appendChild(n);p&&p.focus();var u=null;n.addEventListener("mouseleave",function(a){f.dialog_close_on_mouse_leave&&!n.is_modified&&f.dialog_close_on_mouse_leave&&(u=setTimeout(n.close,f.dialog_close_on_mouse_leave_delay))});n.addEventListener("mouseenter",function(a){f.dialog_close_on_mouse_leave&&u&&clearTimeout(u)})};k.prototype.prompt=function(a,b,c,d,e){var g=this;a=a||"";var h=document.createElement("div");h.is_modified=!1;h.className="graphdialog rounded";h.innerHTML=e?" ": +" ";h.close=function(){g.prompt_box=null;h.parentNode&&h.parentNode.removeChild(h)};e=k.active_canvas.canvas;e.parentNode.appendChild(h);1h.search_limit))break}}p=null;if(Array.prototype.filter)p=Object.keys(f.registered_node_types).filter(e);else for(r in p=[],f.registered_node_types)e(r)&&p.push(r);for(r=0;rh.search_limit);r++);if(b.show_general_after_typefiltered&&(y.value||q.value)){filtered_extra=[];for(r in f.registered_node_types)e(r,{inTypeOverride:y&&y.value?"*": -!1,outTypeOverride:q&&q.value?"*":!1})&&filtered_extra.push(r);for(r=0;rh.search_limit);r++);}if((y.value||q.value)&&0==v.childNodes.length&&b.show_general_if_none_on_typefilter){filtered_extra=[];for(r in f.registered_node_types)e(r,{skipFilter:!0})&&filtered_extra.push(r);for(r=0;rh.search_limit);r++);}}}def_options={slot_from:null, -node_from:null,node_to:null,do_type_filter:f.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:f.search_hide_on_mouse_leave,show_all_if_empty:!0,show_all_on_open:f.search_show_all_on_open};b=Object.assign(def_options,b||{});var g=this,k=h.active_canvas,n=k.canvas,p=n.ownerDocument||document,r=document.createElement("div");r.className="litegraph litesearchbox graphdialog rounded";r.innerHTML="Search "; +if(q&&e&&f.registered_slot_out_types[e]&&f.registered_slot_out_types[e].nodes&&(e=f.registered_slot_out_types[e].nodes.includes(a),!1===e))return!1}return!0};var n=0;d=d.toLowerCase();var u=h.filter||h.graph.filter;if(b.do_type_filter&&g.search_box)var y=g.search_box.querySelector(".slot_in_type_filter"),q=g.search_box.querySelector(".slot_out_type_filter");else q=y=!1;for(r in f.searchbox_extras){var p=f.searchbox_extras[r];if(b.show_all_if_empty&&!d||-1!==p.desc.toLowerCase().indexOf(d)){var l= +f.registered_node_types[p.type];if((!l||l.filter==u)&&e(p.type)&&(a(p.desc,"searchbox_extra"),-1!==k.search_limit&&n++>k.search_limit))break}}p=null;if(Array.prototype.filter)p=Object.keys(f.registered_node_types).filter(e);else for(r in p=[],f.registered_node_types)e(r)&&p.push(r);for(r=0;rk.search_limit);r++);if(b.show_general_after_typefiltered&&(y.value||q.value)){filtered_extra=[];for(r in f.registered_node_types)e(r,{inTypeOverride:y&&y.value?"*": +!1,outTypeOverride:q&&q.value?"*":!1})&&filtered_extra.push(r);for(r=0;rk.search_limit);r++);}if((y.value||q.value)&&0==v.childNodes.length&&b.show_general_if_none_on_typefilter){filtered_extra=[];for(r in f.registered_node_types)e(r,{skipFilter:!0})&&filtered_extra.push(r);for(r=0;rk.search_limit);r++);}}}def_options={slot_from:null, +node_from:null,node_to:null,do_type_filter:f.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:f.search_hide_on_mouse_leave,show_all_if_empty:!0,show_all_on_open:f.search_show_all_on_open};b=Object.assign(def_options,b||{});var g=this,h=k.active_canvas,n=h.canvas,p=n.ownerDocument||document,r=document.createElement("div");r.className="litegraph litesearchbox graphdialog rounded";r.innerHTML="Search "; b.do_type_filter&&(r.innerHTML+="",r.innerHTML+="");r.innerHTML+="
";p.fullscreenElement?p.fullscreenElement.appendChild(r):(p.body.appendChild(r),p.body.style.overflow="hidden");if(b.do_type_filter)var u=r.querySelector(".slot_in_type_filter"),q=r.querySelector(".slot_out_type_filter");r.close=function(){g.search_box=null;this.blur(); n.focus();p.body.style.overflow="";setTimeout(function(){g.canvas.focus()},20);r.parentNode&&r.parentNode.removeChild(r)};1u.height-200&&(v.style.maxHeight=u.height-a.layerY-20+"px");z.focus();b.show_all_on_open&&e();return r};h.prototype.showEditPropertyValue=function(a,b,c){function d(){e(q.value)}function e(d){g&&g.values&&g.values.constructor===Object&&void 0!=g.values[d]&&(d=g.values[d]);"number"==typeof a.properties[b]&&(d=Number(d));if("array"==f||"object"==f)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(); -u.close();a.setDirtyCanvas(!0,!0)}if(a&&void 0!==a.properties[b]){c=c||{};var g=a.getPropertyInfo(b),f=g.type,n="";if("string"==f||"number"==f||"array"==f||"object"==f)n="";else if("enum"!=f&&"combo"!=f||!g.values)if("boolean"==f||"toggle"==f)n="";else{console.warn("unknown type: "+f);return}else{n=""}var u=this.createDialog(""+(g.label?g.label:b)+""+n+"",c),q=!1;if("enum"!=f&&"combo"!=f||!g.values)if("boolean"==f||"toggle"==f)(q=u.querySelector("input"))&&q.addEventListener("click",function(a){u.modified();e(!!q.checked)});else{if(q=u.querySelector("input"))q.addEventListener("blur",function(a){this.focus()}), -r=void 0!==a.properties[b]?a.properties[b]:"","string"!==f&&(r=JSON.stringify(r)),q.value=r,q.addEventListener("keydown",function(a){if(27==a.keyCode)u.close();else if(13==a.keyCode)d();else if(13!=a.keyCode){u.modified();return}a.preventDefault();a.stopPropagation()})}else q=u.querySelector("select"),q.addEventListener("change",function(a){u.modified();e(a.target.value)});q&&q.focus();u.querySelector("button").addEventListener("click",d);return u}};h.prototype.createDialog=function(a,b){def_options= +function(a){y=-1}),q.addEventListener("click",function(a){y++}),q.addEventListener("blur",function(a){y=0}),q.addEventListener("change",function(a){y=-1}))}g.search_box&&g.search_box.close();g.search_box=r;var v=r.querySelector(".helper"),m=null,w=null,t=null,A=r.querySelector("input");A&&(A.addEventListener("blur",function(a){this.focus()}),A.addEventListener("keydown",function(a){if(38==a.keyCode)d(!1);else if(40==a.keyCode)d(!0);else if(27==a.keyCode)r.close();else if(13==a.keyCode)t?c(t.innerHTML): +m?c(m):r.close();else{w&&clearInterval(w);w=setTimeout(e,250);return}a.preventDefault();a.stopPropagation();a.stopImmediatePropagation();return!0}));if(b.do_type_filter){if(u){var x=f.slot_types_in,H=x.length;if(b.type_filter_in==f.EVENT||b.type_filter_in==f.ACTION)b.type_filter_in="_event_";for(var B=0;Bu.height-200&&(v.style.maxHeight=u.height-a.layerY-20+"px");A.focus();b.show_all_on_open&&e();return r};k.prototype.showEditPropertyValue=function(a,b,c){function d(){e(q.value)}function e(d){g&&g.values&&g.values.constructor===Object&&void 0!=g.values[d]&&(d=g.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(); +u.close();a.setDirtyCanvas(!0,!0)}if(a&&void 0!==a.properties[b]){c=c||{};var g=a.getPropertyInfo(b),h=g.type,f="";if("string"==h||"number"==h||"array"==h||"object"==h)f="";else if("enum"!=h&&"combo"!=h||!g.values)if("boolean"==h||"toggle"==h)f="";else{console.warn("unknown type: "+h);return}else{f=""}var u=this.createDialog(""+(g.label?g.label:b)+""+f+"",c),q=!1;if("enum"!=h&&"combo"!=h||!g.values)if("boolean"==h||"toggle"==h)(q=u.querySelector("input"))&&q.addEventListener("click",function(a){u.modified();e(!!q.checked)});else{if(q=u.querySelector("input"))q.addEventListener("blur",function(a){this.focus()}), +r=void 0!==a.properties[b]?a.properties[b]:"","string"!==h&&(r=JSON.stringify(r)),q.value=r,q.addEventListener("keydown",function(a){if(27==a.keyCode)u.close();else if(13==a.keyCode)d();else if(13!=a.keyCode){u.modified();return}a.preventDefault();a.stopPropagation()})}else q=u.querySelector("select"),q.addEventListener("change",function(a){u.modified();e(a.target.value)});q&&q.focus();u.querySelector("button").addEventListener("click",d);return u}};k.prototype.createDialog=function(a,b){def_options= {checkForInput:!1,closeOnLeave:!0,closeOnLeave_checkModified:!0};b=Object.assign(def_options,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(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 g=null,k=!1;c.addEventListener("mouseleave",function(a){k||(b.closeOnLeave||f.dialog_close_on_mouse_leave)&&!c.is_modified&&f.dialog_close_on_mouse_leave&&(g=setTimeout(c.close, -f.dialog_close_on_mouse_leave_delay))});c.addEventListener("mouseenter",function(a){(b.closeOnLeave||f.dialog_close_on_mouse_leave)&&g&&clearTimeout(g)});(a=c.querySelectorAll("select"))&&a.forEach(function(a){a.addEventListener("click",function(a){k++});a.addEventListener("blur",function(a){k=0});a.addEventListener("change",function(a){k=-1})});return c};h.prototype.createPanel=function(a,b){b=b||{};var c=b.window||window,d=document.createElement("div");d.className="litegraph dialog";d.innerHTML= +(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 g=null,h=!1;c.addEventListener("mouseleave",function(a){h||(b.closeOnLeave||f.dialog_close_on_mouse_leave)&&!c.is_modified&&f.dialog_close_on_mouse_leave&&(g=setTimeout(c.close, +f.dialog_close_on_mouse_leave_delay))});c.addEventListener("mouseenter",function(a){(b.closeOnLeave||f.dialog_close_on_mouse_leave)&&g&&clearTimeout(g)});(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};k.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.removeChild(d);this.parentNode&&this.parentNode.removeChild(this)};d.toggleAltContent=function(a){if("undefined"!=typeof a){var b=a?"block":"none";a= -a?"none":"block"}else b="block"!=d.alt_content.style.display?"block":"none",a="block"!=d.alt_content.style.display?"none":"block";d.alt_content.style.display=b;d.content.style.display=a};d.toggleFooterVisibility=function(a){d.footer.style.display="undefined"!=typeof a?a?"block":"none":"block"!=d.footer.style.display?"block":"none"};d.clear=function(){this.content.innerHTML=""};d.addHTML=function(a,b,c){var e=document.createElement("div");b&&(e.className=b);e.innerHTML=a;c?d.footer.appendChild(e): -d.content.appendChild(e);return e};d.addButton=function(a,b,c){var e=document.createElement("button");e.innerText=a;e.options=c;e.classList.add("btn");e.addEventListener("click",b);d.footer.appendChild(e);return e};d.addSeparator=function(){var a=document.createElement("div");a.className="separator";d.content.appendChild(a)};d.addWidget=function(a,b,k,n,p){function e(a,b){n.callback&&n.callback(a,b,n);p&&p(a,b,n)}n=n||{};var g=String(k);a=a.toLowerCase();"number"==a&&(g=k.toFixed(3));var q=document.createElement("div"); -q.className="property";q.innerHTML="";q.querySelector(".property_name").innerText=n.label||b;var y=q.querySelector(".property_value");y.innerText=g;q.dataset.property=b;q.dataset.type=n.type||a;q.options=n;q.value=k;if("code"==a)q.addEventListener("click",function(a){d.inner_showCodePad(this.dataset.property)});else if("boolean"==a)q.classList.add("boolean"),k&&q.classList.add("bool-on"),q.addEventListener("click",function(){var a= +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(a){if("undefined"!=typeof a){var b=a?"block": +"none";a=a?"none":"block"}else b="block"!=d.alt_content.style.display?"block":"none",a="block"!=d.alt_content.style.display?"none":"block";d.alt_content.style.display=b;d.content.style.display=a};d.toggleFooterVisibility=function(a){d.footer.style.display="undefined"!=typeof a?a?"block":"none":"block"!=d.footer.style.display?"block":"none"};d.clear=function(){this.content.innerHTML=""};d.addHTML=function(a,b,c){var e=document.createElement("div");b&&(e.className=b);e.innerHTML=a;c?d.footer.appendChild(e): +d.content.appendChild(e);return e};d.addButton=function(a,b,c){var e=document.createElement("button");e.innerText=a;e.options=c;e.classList.add("btn");e.addEventListener("click",b);d.footer.appendChild(e);return e};d.addSeparator=function(){var a=document.createElement("div");a.className="separator";d.content.appendChild(a)};d.addWidget=function(a,b,h,n,p){function e(a,b){n.callback&&n.callback(a,b,n);p&&p(a,b,n)}n=n||{};var g=String(h);a=a.toLowerCase();"number"==a&&(g=h.toFixed(3));var q=document.createElement("div"); +q.className="property";q.innerHTML="";q.querySelector(".property_name").innerText=n.label||b;var y=q.querySelector(".property_value");y.innerText=g;q.dataset.property=b;q.dataset.type=n.type||a;q.options=n;q.value=h;if("code"==a)q.addEventListener("click",function(a){d.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";e(a,this.value)});else if("string"==a||"number"==a)y.setAttribute("contenteditable",!0),y.addEventListener("keydown",function(b){"Enter"!=b.code||"string"==a&&b.shiftKey||(b.preventDefault(),this.blur())}),y.addEventListener("blur",function(){var a=this.innerText,b=this.parentNode.dataset.property;"number"==this.parentNode.dataset.type&&(a=Number(a)); -e(b,a)});else if("enum"==a||"combo"==a)g=h.getPropertyPrintableValue(k,n.values),y.innerText=g,y.addEventListener("click",function(a){var b=this.parentNode.dataset.property,d=this;new f.ContextMenu(n.values||[],{event:a,className:"dark",callback:function(a,c,g){d.innerText=a;e(b,a);return!1}},c)});d.content.appendChild(q);return q};if(d.onOpen&&"function"==typeof d.onOpen)d.onOpen();return d};h.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+")"}};h.prototype.closePanels=function(){var a=document.querySelector("#node-panel");a&&a.close();(a=document.querySelector("#option-panel"))&&a.close()};h.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(); +e(b,a)});else if("enum"==a||"combo"==a)g=k.getPropertyPrintableValue(h,n.values),y.innerText=g,y.addEventListener("click",function(a){var b=this.parentNode.dataset.property,d=this;new f.ContextMenu(n.values||[],{event:a,className:"dark",callback:function(a,c,g){d.innerText=a;e(b,a);return!1}},c)});d.content.appendChild(q);return q};if(d.onOpen&&"function"==typeof d.onOpen)d.onOpen();return d};k.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+")"}};k.prototype.closePanels=function(){var a=document.querySelector("#node-panel");a&&a.close();(a=document.querySelector("#option-panel"))&&a.close()};k.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 a=function(a,b,c){c&&c.key&&(a=c.key);c.values&&(b=Object.values(c.values).indexOf(b));e[a]=b},b=f.availableCanvasOptions;b.sort();for(pI in b){var c=b[pI];panel.addWidget("boolean",c,e[c],{key:c, -on:"True",off:"False"},a)}panel.addWidget("combo","Render mode",f.LINK_RENDER_MODES[e.links_render_mode],{key:"links_render_mode",values:f.LINK_RENDER_MODES},a);panel.addSeparator();panel.footer.innerHTML=""})();e.canvas.parentNode.appendChild(panel)};h.prototype.showShowNodePanel=function(a){function b(){panel.content.innerHTML="";panel.addHTML(""+a.type+""+(a.constructor.desc||"")+"");panel.addHTML("

Properties

"); -var b=function(b,c){d.graph.beforeChange(a);switch(b){case "Title":a.title=c;break;case "Mode":b=Object.values(f.NODE_MODES).indexOf(c);0<=b&&f.NODE_MODES[b]?a.changeMode(b):console.warn("unexpected mode: "+c);break;case "Color":h.node_colors[c]?(a.color=h.node_colors[c].color,a.bgcolor=h.node_colors[c].bgcolor):console.warn("unexpected color: "+c);break;default:a.setProperty(b,c)}d.graph.afterChange();d.dirty_canvas=!0};panel.addWidget("string","Title",a.title,{},b);panel.addWidget("combo","Mode", -f.NODE_MODES[a.mode],{values:f.NODE_MODES},b);var c="";void 0!==a.color&&(c=Object.keys(h.node_colors).filter(function(b){return h.node_colors[b].color==a.color}));panel.addWidget("combo","Color",c,{values:Object.keys(h.node_colors)},b);for(var k in a.properties){c=a.properties[k];var n=a.getPropertyInfo(k);a.onAddPropertyToPanel&&a.onAddPropertyToPanel(k,panel)||panel.addWidget(n.widget||n.type,k,c,n,b)}panel.addSeparator();if(a.onShowCustomPanelInfo)a.onShowCustomPanelInfo(panel);panel.footer.innerHTML= +on:"True",off:"False"},a)}panel.addWidget("combo","Render mode",f.LINK_RENDER_MODES[e.links_render_mode],{key:"links_render_mode",values:f.LINK_RENDER_MODES},a);panel.addSeparator();panel.footer.innerHTML=""})();e.canvas.parentNode.appendChild(panel)};k.prototype.showShowNodePanel=function(a){function b(){panel.content.innerHTML="";panel.addHTML(""+a.type+""+(a.constructor.desc||"")+"");panel.addHTML("

Properties

"); +var b=function(b,c){d.graph.beforeChange(a);switch(b){case "Title":a.title=c;break;case "Mode":b=Object.values(f.NODE_MODES).indexOf(c);0<=b&&f.NODE_MODES[b]?a.changeMode(b):console.warn("unexpected mode: "+c);break;case "Color":k.node_colors[c]?(a.color=k.node_colors[c].color,a.bgcolor=k.node_colors[c].bgcolor):console.warn("unexpected color: "+c);break;default:a.setProperty(b,c)}d.graph.afterChange();d.dirty_canvas=!0};panel.addWidget("string","Title",a.title,{},b);panel.addWidget("combo","Mode", +f.NODE_MODES[a.mode],{values:f.NODE_MODES},b);var c="";void 0!==a.color&&(c=Object.keys(k.node_colors).filter(function(b){return k.node_colors[b].color==a.color}));panel.addWidget("combo","Color",c,{values:Object.keys(k.node_colors)},b);for(var h in a.properties){c=a.properties[h];var n=a.getPropertyInfo(h);a.onAddPropertyToPanel&&a.onAddPropertyToPanel(h,panel)||panel.addWidget(n.widget||n.type,h,c,n,b)}panel.addSeparator();if(a.onShowCustomPanelInfo)a.onShowCustomPanelInfo(panel);panel.footer.innerHTML= "";panel.addButton("Delete",function(){a.block_delete||(a.graph.remove(a),panel.close())}).classList.add("delete")}this.SELECTED_NODE=a;this.closePanels();var c=this.getCanvasWindow(),d=this;panel=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=panel;panel.id="node-panel";panel.node=a;panel.classList.add("settings");panel.inner_showCodePad=function(c){panel.classList.remove("settings"); panel.classList.add("centered");panel.alt_content.innerHTML="";var d=panel.alt_content.querySelector("textarea"),e=function(){panel.toggleAltContent(!1);panel.toggleFooterVisibility(!0);d.parentNode.removeChild(d);panel.classList.add("settings");panel.classList.remove("centered");b()};d.value=a.properties[c];d.addEventListener("keydown",function(b){"Enter"==b.code&&b.ctrlKey&&(a.setProperty(c,d.value),e())});panel.toggleAltContent(!0);panel.toggleFooterVisibility(!1); -d.style.height="calc(100% - 40px)";var f=panel.addButton("Assign",function(){a.setProperty(c,d.value);e()});panel.alt_content.appendChild(f);f=panel.addButton("Close",e);f.style.float="right";panel.alt_content.appendChild(f)};b();this.canvas.parentNode.appendChild(panel)};h.prototype.showSubgraphPropertiesDialog=function(a){function b(){d.clear();if(a.inputs)for(var c=0;c", +d.style.height="calc(100% - 40px)";var f=panel.addButton("Assign",function(){a.setProperty(c,d.value);e()});panel.alt_content.appendChild(f);f=panel.addButton("Close",e);f.style.float="right";panel.alt_content.appendChild(f)};b();this.canvas.parentNode.appendChild(panel)};k.prototype.showSubgraphPropertiesDialog=function(a){function b(){d.clear();if(a.inputs)for(var c=0;c", "subgraph_property");f.dataset.name=g.name;f.dataset.slot=c;f.querySelector(".name").innerText=g.name;f.querySelector(".type").innerText=g.type;f.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 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(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(d);return d};h.prototype.showSubgraphPropertiesDialogRight= +d.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(d);return d};k.prototype.showSubgraphPropertiesDialogRight= function(a){function b(){e.clear();if(a.outputs)for(var c=0;c","subgraph_property");f.dataset.name=d.name;f.dataset.slot=c;f.querySelector(".name").innerText=d.name;f.querySelector(".type").innerText=d.type;f.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 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(a){13==a.keyCode&&c.apply(this)});d.querySelector("button").addEventListener("click",function(a){c.apply(this)});b();this.canvas.parentNode.appendChild(e);return e};h.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()};h.onMenuNodePin=function(a,b,c,d,e){e.pin()};h.onMenuNodeMode=function(a,b,c,d,e){new f.ContextMenu(f.NODE_MODES,{event:c,callback:function(a){if(e){var b=Object.values(f.NODE_MODES).indexOf(a),c=function(c){0<=b&&f.NODE_MODES[b]?c.changeMode(b):(console.warn("unexpected mode: "+a),c.changeMode(f.ALWAYS))}, -d=h.active_canvas;if(!d.selected_nodes||1>=Object.keys(d.selected_nodes).length)c(e);else for(var g in d.selected_nodes)c(d.selected_nodes[g])}},parentMenu:d,node:e});return!1};h.onMenuNodeColors=function(a,b,c,d,e){if(!e)throw"no node for color";b=[];b.push({value:null,content:"No color"});for(var g in h.node_colors)a=h.node_colors[g],a={value:g,content:""+g+""},b.push(a);new f.ContextMenu(b,{event:c,callback:function(a){if(e){var b=a.value?h.node_colors[a.value]:null;a=function(a){b?a.constructor===f.LGraphGroup?a.color=b.groupcolor:(a.color=b.color,a.bgcolor=b.bgcolor):(delete a.color,delete a.bgcolor)};var c=h.active_canvas;if(!c.selected_nodes||1>=Object.keys(c.selected_nodes).length)a(e);else for(var d in c.selected_nodes)a(c.selected_nodes[d]);e.setDirtyCanvas(!0,!0)}},parentMenu:d,node:e});return!1}; -h.onMenuNodeShapes=function(a,b,c,d,e){if(!e)throw"no node passed";new f.ContextMenu(f.VALID_SHAPES,{event:c,callback:function(a){if(e){e.graph.beforeChange();var b=h.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)e.shape=a;else for(var c in b.selected_nodes)b.selected_nodes[c].shape=a;e.graph.afterChange();e.setDirtyCanvas(!0)}},parentMenu:d,node:e});return!1};h.onMenuNodeRemove=function(a,b,c,d,e){if(!e)throw"no node passed";a=e.graph;a.beforeChange();b=h.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)};h.onMenuNodeToSubgraph=function(a,b,c,d,e){a=e.graph;if(b=h.active_canvas)c=Object.values(b.selected_nodes||{}),c.length||(c=[e]),d=f.createNode("graph/subgraph"),d.pos=e.pos.concat(),a.add(d),d.buildFromNodes(c),b.deselectAllNodes(),e.setDirtyCanvas(!0,!0)};h.onMenuNodeClone=function(a, -b,c,d,e){e.graph.beforeChange();var f={};a=function(a){if(0!=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=h.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)a(e);else for(var k in b.selected_nodes)a(b.selected_nodes[k]);Object.keys(f).length&&b.selectNodes(f);e.graph.afterChange();e.setDirtyCanvas(!0,!0)};h.node_colors={red:{color:"#322",bgcolor:"#533",groupcolor:"#A88"},brown:{color:"#332922",bgcolor:"#593930",groupcolor:"#b06634"}, -green:{color:"#232",bgcolor:"#353",groupcolor:"#8A8"},blue:{color:"#223",bgcolor:"#335",groupcolor:"#88A"},pale_blue:{color:"#2a363b",bgcolor:"#3f5159",groupcolor:"#3f789e"},cyan:{color:"#233",bgcolor:"#355",groupcolor:"#8AA"},purple:{color:"#323",bgcolor:"#535",groupcolor:"#a1309b"},yellow:{color:"#432",bgcolor:"#653",groupcolor:"#b58b2a"},black:{color:"#222",bgcolor:"#000",groupcolor:"#444"}};h.prototype.getCanvasMenuOptions=function(){if(this.getMenuOptions)var a=this.getMenuOptions();else a=[{content:"Add Node", -has_submenu:!0,callback:h.onMenuAdd},{content:"Add Group",callback:h.onGroupAdd}],this._graph_stack&&0Name",d),r=g.querySelector("input");r&&f&&(r.value=f.label|| -"");var k=function(){a.graph.beforeChange();r.value&&(f&&(f.label=r.value),c.setDirty(!0));g.close();a.graph.afterChange()};g.querySelector("button").addEventListener("click",k);r.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()});r.focus()}},extra:a};a&&(g.title=a.type);var k=null;a&&(k=a.getSlotInPosition(b.canvasX,b.canvasY),h.active_node= -a);k?(e=[],a.getSlotMenuOptions?e=a.getSlotMenuOptions(k):(k&&k.output&&k.output.links&&k.output.links.length&&e.push({content:"Disconnect Links",slot:k}),b=k.input||k.output,b.removable&&e.push(b.locked?"Cannot remove":{content:"Remove Slot",slot:k}),b.nameLocked||e.push({content:"Rename Slot",slot:k})),g.title=(k.input?k.input.type:k.output.type)||"*",k.input&&k.input.type==f.ACTION&&(g.title="Action"),k.output&&k.output.type==f.EVENT&&(g.title="Event")):a?e=this.getNodeMenuOptions(a):(e=this.getCanvasMenuOptions(), -(k=this.graph.getGroupOnPos(b.canvasX,b.canvasY))&&e.push(null,{content:"Edit Group",has_submenu:!0,submenu:{title:"Group",extra:k,options:this.getGroupMenuOptions(k)}}));e&&new f.ContextMenu(e,g,d)};"undefined"!=typeof window&&window.CanvasRenderingContext2D&&!window.CanvasRenderingContext2D.prototype.roundRect&&(window.CanvasRenderingContext2D.prototype.roundRect=function(a,b,c,d,e,f){var g,h;if(0===e)this.rect(a,b,c,d);else{void 0===f&&(f=e);if(null!=e&&e.constructor===Array)if(1==e.length)var l= -g=h=f=e[0];else if(2==e.length)l=f=e[0],g=h=e[1];else if(4==e.length)l=e[0],g=e[1],h=e[2],f=e[3];else return;else l=e||0,g=e||0,h=f||0,f=f||0;this.moveTo(a+l,b);this.lineTo(a+c-g,b);this.quadraticCurveTo(a+c,b,a+c,b+g);this.lineTo(a+c,b+d-f);this.quadraticCurveTo(a+c,b+d,a+c-f,b+d);this.lineTo(a+f,b+d);this.quadraticCurveTo(a,b+d,a,b+d-h);this.lineTo(a,b+h);this.quadraticCurveTo(a,b,a+l,b)}});f.compareObjects=function(a,b){for(var c in a)if(a[c]!=b[c])return!1;return!0};f.distance=D;f.colorToString= -function(a){return"rgba("+Math.round(255*a[0]).toFixed()+","+Math.round(255*a[1]).toFixed()+","+Math.round(255*a[2]).toFixed()+","+(4==a.length?a[3].toFixed(2):"1.0")+")"};f.isInsideRectangle=C;f.growBounding=function(a,b,c){ba[2]&&(a[2]=b);ca[3]&&(a[3]=c)};f.isInsideBounding=function(a,b){return a[0]b[1][0]||a[1]>b[1][1]?!1:!0};f.overlapBounding=A;f.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};f.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};E.prototype.addItem=function(a,b,c){function d(a){var b=this.value;b&&b.has_submenu&&e.call(this,a)}function e(a){var b=this.value,d=!0;g.current_submenu&&g.current_submenu.close(a);if(c.callback){var e=c.callback.call(this,b, -c,a,g,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,g,c.extra),!0===e&&(d=!1)),b.submenu)){if(!b.submenu.options)throw"ContextMenu submenu needs options";new g.constructor(b.submenu.options,{callback:b.submenu.callback,event:a,parentMenu:g,ignore_item_callbacks:b.submenu.ignore_item_callbacks,title:b.submenu.title,extra:b.submenu.extra,autoopen:c.autoopen});d=!1}d&&!g.lock&&g.close()}var g=this;c=c||{};var k=document.createElement("div"); -k.className="litemenu-entry submenu";var h=!1;if(null===b)k.classList.add("separator");else{k.innerHTML=b&&b.title?b.title:a;if(k.value=b)b.disabled&&(h=!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);h||k.addEventListener("click",e);c.autoopen&&f.pointerListenerAdd(k,"enter",d);return k};E.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&&!E.isCursorOverElement(a,this.parentMenu.root)&&E.trigger(this.parentMenu.root,f.pointerevents_method+"leave",a));this.current_submenu&&this.current_submenu.close(a,!0);this.root.closing_timer&&clearTimeout(this.root.closing_timer)};E.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};E.prototype.getTopMenu=function(){return this.options.parentMenu?this.options.parentMenu.getTopMenu():this};E.prototype.getFirstEvent=function(){return this.options.parentMenu?this.options.parentMenu.getFirstEvent():this.options.event};E.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}};G.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(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 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 k=0==d||d==c.length-1;!k&&(-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]=k?0==d?0:1:Math.clamp(e,0,1),b[1]=1-Math.clamp(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 d=this.size[0]-2*this.margin,e=this.size[1]-2*this.margin,f=c.length,k=[0,0],h=1E6,l=-1,r=0;rh||u>b||(l=r,h=u)}return l};f.CurveEditor=G;f.getParameterNames=function(a){return(a+"").replace(/[/][/].*$/gm,"").replace(/\s+/g,"").replace(/[/][*][^/*]*[*][/]/g,"").split("){",1)[0].replace(/^[^(]*[(]/,"").replace(/=[^,]+/g,"").split(",").filter(Boolean)};f.pointerListenerAdd= +"subgraph_property extra",!0);d.querySelector(".name").addEventListener("keydown",function(a){13==a.keyCode&&c.apply(this)});d.querySelector("button").addEventListener("click",function(a){c.apply(this)});b();this.canvas.parentNode.appendChild(e);return e};k.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 g in a.selected_nodes)a.selected_nodes[g].collapse();e.graph.afterChange()};k.onMenuNodePin=function(a,b,c,d,e){e.pin()};k.onMenuNodeMode=function(a,b,c,d,e){new f.ContextMenu(f.NODE_MODES,{event:c,callback:function(a){if(e){var b=Object.values(f.NODE_MODES).indexOf(a),c=function(c){0<=b&&f.NODE_MODES[b]?c.changeMode(b):(console.warn("unexpected mode: "+a),c.changeMode(f.ALWAYS))}, +d=k.active_canvas;if(!d.selected_nodes||1>=Object.keys(d.selected_nodes).length)c(e);else for(var g in d.selected_nodes)c(d.selected_nodes[g])}},parentMenu:d,node:e});return!1};k.onMenuNodeColors=function(a,b,c,d,e){if(!e)throw"no node for color";b=[];b.push({value:null,content:"No color"});for(var g in k.node_colors)a=k.node_colors[g],a={value:g,content:""+g+""},b.push(a);new f.ContextMenu(b,{event:c,callback:function(a){if(e){var b=a.value?k.node_colors[a.value]:null;a=function(a){b?a.constructor===f.LGraphGroup?a.color=b.groupcolor:(a.color=b.color,a.bgcolor=b.bgcolor):(delete a.color,delete a.bgcolor)};var c=k.active_canvas;if(!c.selected_nodes||1>=Object.keys(c.selected_nodes).length)a(e);else for(var d in c.selected_nodes)a(c.selected_nodes[d]);e.setDirtyCanvas(!0,!0)}},parentMenu:d,node:e});return!1}; +k.onMenuNodeShapes=function(a,b,c,d,e){if(!e)throw"no node passed";new f.ContextMenu(f.VALID_SHAPES,{event:c,callback:function(a){if(e){e.graph.beforeChange();var b=k.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)e.shape=a;else for(var c in b.selected_nodes)b.selected_nodes[c].shape=a;e.graph.afterChange();e.setDirtyCanvas(!0)}},parentMenu:d,node:e});return!1};k.onMenuNodeRemove=function(a,b,c,d,e){if(!e)throw"no node passed";a=e.graph;a.beforeChange();b=k.active_canvas; +if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)!1!==e.removable&&a.remove(e);else for(var g in b.selected_nodes)c=b.selected_nodes[g],!1!==c.removable&&a.remove(c);a.afterChange();e.setDirtyCanvas(!0,!0)};k.onMenuNodeToSubgraph=function(a,b,c,d,e){a=e.graph;if(b=k.active_canvas)c=Object.values(b.selected_nodes||{}),c.length||(c=[e]),d=f.createNode("graph/subgraph"),d.pos=e.pos.concat(),a.add(d),d.buildFromNodes(c),b.deselectAllNodes(),e.setDirtyCanvas(!0,!0)};k.onMenuNodeClone=function(a, +b,c,d,e){e.graph.beforeChange();var g={};a=function(a){if(0!=a.clonable){var b=a.clone();b&&(b.pos=[a.pos[0]+5,a.pos[1]+5],a.graph.add(b),g[b.id]=b)}};b=k.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]);Object.keys(g).length&&b.selectNodes(g);e.graph.afterChange();e.setDirtyCanvas(!0,!0)};k.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"}};k.prototype.getCanvasMenuOptions=function(){if(this.getMenuOptions)var a=this.getMenuOptions();else a=[{content:"Add Node", +has_submenu:!0,callback:k.onMenuAdd},{content:"Add Group",callback:k.onGroupAdd}],this._graph_stack&&0Name",d),r=f.querySelector("input");r&&g&&(r.value=g.label|| +"");var h=function(){a.graph.beforeChange();r.value&&(g&&(g.label=r.value),c.setDirty(!0));f.close();a.graph.afterChange()};f.querySelector("button").addEventListener("click",h);r.addEventListener("keydown",function(a){f.is_modified=!0;if(27==a.keyCode)f.close();else if(13==a.keyCode)h();else if(13!=a.keyCode&&"textarea"!=a.target.localName)return;a.preventDefault();a.stopPropagation()});r.focus()}},extra:a};a&&(g.title=a.type);var h=null;a&&(h=a.getSlotInPosition(b.canvasX,b.canvasY),k.active_node= +a);h?(e=[],a.getSlotMenuOptions?e=a.getSlotMenuOptions(h):(h&&h.output&&h.output.links&&h.output.links.length&&e.push({content:"Disconnect Links",slot:h}),b=h.input||h.output,b.removable&&e.push(b.locked?"Cannot remove":{content:"Remove Slot",slot:h}),b.nameLocked||e.push({content:"Rename Slot",slot:h})),g.title=(h.input?h.input.type:h.output.type)||"*",h.input&&h.input.type==f.ACTION&&(g.title="Action"),h.output&&h.output.type==f.EVENT&&(g.title="Event")):a?e=this.getNodeMenuOptions(a):(e=this.getCanvasMenuOptions(), +(h=this.graph.getGroupOnPos(b.canvasX,b.canvasY))&&e.push(null,{content:"Edit Group",has_submenu:!0,submenu:{title:"Group",extra:h,options:this.getGroupMenuOptions(h)}}));e&&new f.ContextMenu(e,g,d)};"undefined"!=typeof window&&window.CanvasRenderingContext2D&&!window.CanvasRenderingContext2D.prototype.roundRect&&(window.CanvasRenderingContext2D.prototype.roundRect=function(a,b,c,d,e,g){var f,k;if(0===e)this.rect(a,b,c,d);else{void 0===g&&(g=e);if(null!=e&&e.constructor===Array)if(1==e.length)var l= +f=k=g=e[0];else if(2==e.length)l=g=e[0],f=k=e[1];else if(4==e.length)l=e[0],f=e[1],k=e[2],g=e[3];else return;else l=e||0,f=e||0,k=g||0,g=g||0;this.moveTo(a+l,b);this.lineTo(a+c-f,b);this.quadraticCurveTo(a+c,b,a+c,b+f);this.lineTo(a+c,b+d-g);this.quadraticCurveTo(a+c,b+d,a+c-g,b+d);this.lineTo(a+g,b+d);this.quadraticCurveTo(a,b+d,a,b+d-k);this.lineTo(a,b+k);this.quadraticCurveTo(a,b,a+l,b)}});f.compareObjects=function(a,b){for(var c in a)if(a[c]!=b[c])return!1;return!0};f.distance=E;f.colorToString= +function(a){return"rgba("+Math.round(255*a[0]).toFixed()+","+Math.round(255*a[1]).toFixed()+","+Math.round(255*a[2]).toFixed()+","+(4==a.length?a[3].toFixed(2):"1.0")+")"};f.isInsideRectangle=D;f.growBounding=function(a,b,c){ba[2]&&(a[2]=b);ca[3]&&(a[3]=c)};f.isInsideBounding=function(a,b){return a[0]b[1][0]||a[1]>b[1][1]?!1:!0};f.overlapBounding=B;f.hex2num=function(a){"#"==a.charAt(0)&&(a=a.slice(1));a=a.toUpperCase();for(var b=Array(3), +c=0,d,e,g=0;6>g;g+=2)d="0123456789ABCDEF".indexOf(a.charAt(g)),e="0123456789ABCDEF".indexOf(a.charAt(g+1)),b[c]=16*d+e,c++;return b};f.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};F.prototype.addItem=function(a,b,c){function d(a){var b=this.value;b&&b.has_submenu&&e.call(this,a)}function e(a){var b=this.value,d=!0;g.current_submenu&&g.current_submenu.close(a);if(c.callback){var e=c.callback.call(this,b, +c,a,g,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,g,c.extra),!0===e&&(d=!1)),b.submenu)){if(!b.submenu.options)throw"ContextMenu submenu needs options";new g.constructor(b.submenu.options,{callback:b.submenu.callback,event:a,parentMenu:g,ignore_item_callbacks:b.submenu.ignore_item_callbacks,title:b.submenu.title,extra:b.submenu.extra,autoopen:c.autoopen});d=!1}d&&!g.lock&&g.close()}var g=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",e);c.autoopen&&f.pointerListenerAdd(h,"enter",d);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,f.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,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};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 d[1];a=(a-d[0])/b;return d[1]*(1-a)+e[1]*a}}return 0}};I.prototype.draw=function(a,b,c,d,e,g){if(c=this.points){this.size=b;var f=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,f,b),a.fillStyle="#222",a.fillRect(.5*f,0,1,b),a.strokeStyle="#333",a.strokeRect(0,0,f,b));a.strokeStyle=e;g&&(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,g=a[0]-this.margin;a=a[1]-this.margin;this.selected=this.getCloserPoint([g,a],30/b.ds.scale);-1==this.selected&&(b=[g/d,1-a/e],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}};I.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),g=(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 f=0==d||d==c.length-1;!f&&(-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]=f?0==d?0:1:Math.clamp(e,0,1),b[1]=1-Math.clamp(g,0,1),c.sort(function(a,b){return a[0]-b[0]}),this.selected=c.indexOf(b),this.must_update=!0)}}}};I.prototype.onMouseUp=function(a,b){this.selected=-1;return!1};I.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,g=c.length,f=[0,0],k=1E6,l=-1,r=0;rk||u>b||(l=r,k=u)}return l};f.CurveEditor=I;f.getParameterNames=function(a){return(a+"").replace(/[/][/].*$/gm,"").replace(/\s+/g,"").replace(/[/][*][^/*]*[*][/]/g,"").split("){",1)[0].replace(/^[^(]*[(]/,"").replace(/=[^,]+/g,"").split(",").filter(Boolean)};f.pointerListenerAdd= function(a,b,c,d){d=void 0===d?!1:d;if(a&&a.addEventListener&&b&&"function"===typeof c){var e=f.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)}}};f.pointerListenerRemove=function(a,b,c,d){d=void 0===d?!1:d;if(a&&a.removeEventListener&&b&&"function"===typeof c)switch(b){case "down":case "up":case "move":case "over":case "out":case "enter":"pointer"!= f.pointerevents_method&&"mouse"!=f.pointerevents_method||a.removeEventListener(f.pointerevents_method+b,c,d);case "leave":case "cancel":case "gotpointercapture":case "lostpointercapture":if("pointer"==f.pointerevents_method)return a.removeEventListener(f.pointerevents_method+b,c,d);default:return a.removeEventListener(b,c,d)}};Math.clamp=function(a,b,c){return b>a?b:c=f?this.trigger(null,h,l):this._pending.push([f,h])};C.prototype.onExecute=function(f,h){f=1E3*this.graph.elapsed_time;this.isInputConnected(1)&&(this.properties.time_in_ms=this.getInputData(1));for(var l=0;l=f?this.trigger(null,k,l):this._pending.push([f,k])};D.prototype.onExecute= +function(f,k){f=1E3*this.graph.elapsed_time;this.isInputConnected(1)&&(this.properties.time_in_ms=this.getInputData(1));for(var l=0;lw?l.xbox.axes.lx:0,this._left_axis[1]=Math.abs(l.xbox.axes.ly)>w?l.xbox.axes.ly:0,this._right_axis[0]=Math.abs(l.xbox.axes.rx)>w?l.xbox.axes.rx:0,this._right_axis[1]=Math.abs(l.xbox.axes.ry)>w?l.xbox.axes.ry:0,this._triggers[0]=Math.abs(l.xbox.axes.ltrigger)>w?l.xbox.axes.ltrigger: -0,this._triggers[1]=Math.abs(l.xbox.axes.rtrigger)>w?l.xbox.axes.rtrigger:0);if(this.outputs)for(w=0;ww;w++)if(l[w]){l=l[w];w=this.xbox_mapping;w||(w=this.xbox_mapping={axes:[], +0,this._triggers[1]=Math.abs(l.xbox.axes.rtrigger)>w?l.xbox.axes.rtrigger:0);if(this.outputs)for(w=0;ww;w++)if(l[w]){l=l[w];w=this.xbox_mapping;w||(w=this.xbox_mapping={axes:[], buttons:{},hat:"",hatmap:m.CENTER});w.axes.lx=l.axes[0];w.axes.ly=l.axes[1];w.axes.rx=l.axes[2];w.axes.ry=l.axes[3];w.axes.ltrigger=l.buttons[6].value;w.axes.rtrigger=l.buttons[7].value;w.hat="";w.hatmap=m.CENTER;for(var t=0;tt)w.buttons[m.mapping_array[t]]=l.buttons[t].pressed,l.buttons[t].was_pressed&&this.trigger(m.mapping_array[t]+"_button_event");else switch(t){case 12:l.buttons[t].pressed&&(w.hat+="up",w.hatmap|=m.UP); break;case 13:l.buttons[t].pressed&&(w.hat+="down",w.hatmap|=m.DOWN);break;case 14:l.buttons[t].pressed&&(w.hat+="left",w.hatmap|=m.LEFT);break;case 15:l.buttons[t].pressed&&(w.hat+="right",w.hatmap|=m.RIGHT);break;case 16:w.buttons.home=l.buttons[t].pressed}l.xbox=w;return l}};m.prototype.onDrawBackground=function(l){if(!this.flags.collapsed){var m=this._left_axis,t=this._right_axis;l.strokeStyle="#88A";l.strokeRect(.5*(m[0]+1)*this.size[0]-4,.5*(m[1]+1)*this.size[1]-4,8,8);l.strokeStyle="#8A8"; l.strokeRect(.5*(t[0]+1)*this.size[0]-4,.5*(t[1]+1)*this.size[1]-4,8,8);m=this.size[1]/this._current_buttons.length;l.fillStyle="#AEB";for(t=0;t","enum",{values:a.values});this.addWidget("combo", +1);this.size=[120,50]}function A(){this.addOutput("value","number");this.addProperty("min",0);this.addProperty("max",1);this.size=[80,30]}function k(){this.addInput("in","number");this.addOutput("out","number");this.addProperty("min",0);this.addProperty("max",1);this.addProperty("smooth",!0);this.addProperty("seed",0);this.addProperty("octaves",1);this.addProperty("persistence",.8);this.addProperty("speed",1);this.size=[90,30]}function E(){this.addOutput("out","number");this.addProperty("min_time", +1);this.addProperty("max_time",2);this.addProperty("duration",.2);this.size=[90,30];this._blink_time=this._remaining_time=0}function D(){this.addInput("in","number");this.addOutput("out","number");this.size=[80,30];this.addProperty("min",0);this.addProperty("max",1)}function B(){this.properties={f:.5};this.addInput("A","number");this.addInput("B","number");this.addOutput("out","number")}function F(){this.addInput("in","number");this.addOutput("out","number");this.size=[80,30]}function I(){this.addInput("in", +"number");this.addOutput("out","number");this.size=[80,30]}function f(){this.addInput("in","number");this.addOutput("out","number");this.size=[80,30]}function z(){this.addInput("in","number");this.addOutput("out","number");this.size=[80,30];this.properties={A:0,B:1}}function H(){this.addInput("in","number",{label:""});this.addOutput("out","number",{label:""});this.size=[80,30];this.addProperty("factor",1)}function C(){this.addInput("v","boolean");this.addInput("A");this.addInput("B");this.addOutput("out")} +function L(){this.addInput("in","number");this.addOutput("out","number");this.size=[80,30];this.addProperty("samples",10);this._values=new Float32Array(10);this._current=0}function G(){this.addInput("in","number");this.addOutput("out","number");this.addProperty("factor",.1);this.size=[80,30];this._value=null}function K(){this.addInput("A","number,array,object");this.addInput("B","number");this.addOutput("=","number");this.addProperty("A",1);this.addProperty("B",1);this.addProperty("OP","+","enum", +{values:K.values});this._func=function(a,b){return a+b};this._result=[]}function J(){this.addInput("A","number");this.addInput("B","number");this.addOutput("A==B","boolean");this.addOutput("A!=B","boolean");this.addProperty("A",0);this.addProperty("B",0)}function a(){this.addInput("A","number");this.addInput("B","number");this.addOutput("true","boolean");this.addOutput("false","boolean");this.addProperty("A",1);this.addProperty("B",1);this.addProperty("OP",">","enum",{values:a.values});this.addWidget("combo", "Cond.",this.properties.OP,{property:"OP",values:a.values});this.size=[80,60]}function b(){this.addInput("in",0);this.addInput("cond","boolean");this.addOutput("true",0);this.addOutput("false",0);this.size=[80,60]}function c(){this.addInput("inc","number");this.addOutput("total","number");this.addProperty("increment",1);this.addProperty("value",0)}function d(){this.addInput("v","number");this.addOutput("sin","number");this.addProperty("amplitude",1);this.addProperty("offset",0);this.bgImageUrl="nodes/imgs/icon-sin.png"} -function e(){this.addInput("x","number");this.addInput("y","number");this.addOutput("","number");this.properties={x:1,y:1,formula:"x+y"};this.code_widget=this.addWidget("text","F(x,y)",this.properties.formula,function(a,b,c){c.properties.formula=a});this.addWidget("toggle","allow",q.allow_scripts,function(a){q.allow_scripts=a});this._func=null}function g(){this.addInput("vec2","vec2");this.addOutput("x","number");this.addOutput("y","number")}function k(){this.addInputs([["x","number"],["y","number"]]); +function e(){this.addInput("x","number");this.addInput("y","number");this.addOutput("","number");this.properties={x:1,y:1,formula:"x+y"};this.code_widget=this.addWidget("text","F(x,y)",this.properties.formula,function(a,b,c){c.properties.formula=a});this.addWidget("toggle","allow",q.allow_scripts,function(a){q.allow_scripts=a});this._func=null}function g(){this.addInput("vec2","vec2");this.addOutput("x","number");this.addOutput("y","number")}function h(){this.addInputs([["x","number"],["y","number"]]); this.addOutput("vec2","vec2");this.properties={x:0,y:0};this._data=new Float32Array(2)}function n(){this.addInput("vec3","vec3");this.addOutput("x","number");this.addOutput("y","number");this.addOutput("z","number")}function p(){this.addInputs([["x","number"],["y","number"],["z","number"]]);this.addOutput("vec3","vec3");this.properties={x:0,y:0,z:0};this._data=new Float32Array(3)}function r(){this.addInput("vec4","vec4");this.addOutput("x","number");this.addOutput("y","number");this.addOutput("z", "number");this.addOutput("w","number")}function u(){this.addInputs([["x","number"],["y","number"],["z","number"],["w","number"]]);this.addOutput("vec4","vec4");this.properties={x:0,y:0,z:0,w:0};this._data=new Float32Array(4)}var q=x.LiteGraph;m.title="Converter";m.desc="type A to type B";m.prototype.onExecute=function(){var a=this.getInputData(0);if(null!=a&&this.outputs)for(var b=0;ba&&(a+=1024);var d=Math.floor(a);a-=d;c=h.data[d];d=h.data[1023==d?0:d+1];b&&(a=a*a*a*(a*(6*a-15)+10));return c*(1-a)+d*a};h.prototype.onExecute=function(){var a= -this.getInputData(0)||0,b=this.properties.octaves||1,c=0,d=1;a+=this.properties.seed||0;for(var e=this.properties.speed||1,f=0,g=0;gd);++g);a=this.properties.min;this._last_v=c/f*(this.properties.max-a)+a;this.setOutputData(0,this._last_v)};h.prototype.onDrawBackground=function(a){this.outputs[0].label=(this._last_v||0).toFixed(3)};q.registerNodeType("math/noise",h);D.title="Spikes";D.desc="spike every random time"; -D.prototype.onExecute=function(){var a=this.graph.elapsed_time;this._remaining_time-=a;this._blink_time-=a;a=0;0this._remaining_time?(this._remaining_time=Math.random()*(this.properties.max_time-this.properties.min_time)+this.properties.min_time,this._blink_time=this.properties.duration,this.boxcolor="#FFF"):this.boxcolor="#000";this.setOutputData(0,a)};q.registerNodeType("math/spikes",D);C.title="Clamp";C.desc= -"Clamp number between min and max";C.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&(a=Math.max(this.properties.min,a),a=Math.min(this.properties.max,a),this.setOutputData(0,a))};C.prototype.getCode=function(a){a="";this.isInputConnected(0)&&(a+="clamp({{0}},"+this.properties.min+","+this.properties.max+")");return a};q.registerNodeType("math/clamp",C);A.title="Lerp";A.desc="Linear Interpolation";A.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=0);var b= -this.getInputData(1);null==b&&(b=0);var c=this.properties.f,d=this.getInputData(2);void 0!==d&&(c=d);this.setOutputData(0,a*(1-c)+b*c)};A.prototype.onGetInputs=function(){return[["f","number"]]};q.registerNodeType("math/lerp",A);E.title="Abs";E.desc="Absolute";E.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,Math.abs(a))};q.registerNodeType("math/abs",E);G.title="Floor";G.desc="Floor number to remove fractional part";G.prototype.onExecute=function(){var a= -this.getInputData(0);null!=a&&this.setOutputData(0,Math.floor(a))};q.registerNodeType("math/floor",G);f.title="Frac";f.desc="Returns fractional part";f.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,a%1)};q.registerNodeType("math/frac",f);L.title="Smoothstep";L.desc="Smoothstep";L.prototype.onExecute=function(){var a=this.getInputData(0);if(void 0!==a){var b=this.properties.A;a=Math.clamp((a-b)/(this.properties.B-b),0,1);this.setOutputData(0,a*a*(3-2*a))}}; -q.registerNodeType("math/smoothstep",L);I.title="Scale";I.desc="v * factor";I.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,a*this.properties.factor)};q.registerNodeType("math/scale",I);B.title="Gate";B.desc="if v is true, then outputs A, otherwise B";B.prototype.onExecute=function(){var a=this.getInputData(0);this.setOutputData(0,this.getInputData(a?1:2))};q.registerNodeType("math/gate",B);K.title="Average";K.desc="Average Filter";K.prototype.onExecute=function(){var a= -this.getInputData(0);null==a&&(a=0);var b=this._values.length;this._values[this._current%b]=a;this._current+=1;this._current>b&&(this._current=0);for(var c=a=0;cb&&(b=1);this.properties.samples=Math.round(b);a=this._values;this._values=new Float32Array(this.properties.samples);a.length<=this._values.length?this._values.set(a):this._values.set(a.subarray(0,this._values.length))};q.registerNodeType("math/average", -K);F.title="TendTo";F.desc="moves the output value always closer to the input";F.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=0);var b=this.properties.factor;this._value=null==this._value?a:this._value*(1-b)+a*b;this.setOutputData(0,this._value)};q.registerNodeType("math/tendTo",F);J.values="+ - * / % ^ max min".split(" ");J.title="Operation";J.desc="Easy math operators";J["@OP"]={type:"enum",title:"operation",values:J.values};J.size=[100,60];J.prototype.getTitle=function(){return"max"== -this.properties.OP||"min"==this.properties.OP?this.properties.OP+"(A,B)":"A "+this.properties.OP+" B"};J.prototype.setValue=function(a){"string"==typeof a&&(a=parseFloat(a));this.properties.value=a};J.prototype.onPropertyChanged=function(a,b){if("OP"==a)switch(this.properties.OP){case "+":this._func=function(a,b){return a+b};break;case "-":this._func=function(a,b){return a-b};break;case "x":case "X":case "*":this._func=function(a,b){return a*b};break;case "/":this._func=function(a,b){return a/b}; -break;case "%":this._func=function(a,b){return a%b};break;case "^":this._func=function(a,b){return Math.pow(a,b)};break;case "max":this._func=function(a,b){return Math.max(a,b)};break;case "min":this._func=function(a,b){return Math.min(a,b)};break;default:console.warn("Unknown operation: "+this.properties.OP),this._func=function(a){return a}}};J.prototype.onExecute=function(){var a=this.getInputData(0),b=this.getInputData(1);null!=a?a.constructor===Number&&(this.properties.A=a):a=this.properties.A; -null!=b?this.properties.B=b:b=this.properties.B;if(a.constructor===Number)var c=this._func(a,b);else if(a.constructor===Array){c=this._result;c.length=a.length;for(var d=0;dB":f=a>b;break;case "A=B":f=a>=b}this.setOutputData(c,f)}}};H.prototype.onGetOutputs=function(){return[["A==B","boolean"],["A!=B","boolean"],["A>B","boolean"],["A=B","boolean"],["A<=B","boolean"]]};q.registerNodeType("math/compare",H);q.registerSearchboxExtra("math/compare","==",{outputs:[["A==B","boolean"]],title:"A==B"}); +function(){return[["in_min","number"],["in_max","number"],["out_min","number"],["out_max","number"]]};q.registerNodeType("math/range",w);A.title="Rand";A.desc="Random number";A.prototype.onExecute=function(){if(this.inputs)for(var a=0;aa&&(a+=1024);var d=Math.floor(a);a-=d;c=k.data[d];d=k.data[1023==d?0:d+1];b&&(a=a*a*a*(a*(6*a-15)+10));return c*(1-a)+d*a};k.prototype.onExecute=function(){var a= +this.getInputData(0)||0,b=this.properties.octaves||1,c=0,d=1;a+=this.properties.seed||0;for(var e=this.properties.speed||1,f=0,g=0;gd);++g);a=this.properties.min;this._last_v=c/f*(this.properties.max-a)+a;this.setOutputData(0,this._last_v)};k.prototype.onDrawBackground=function(a){this.outputs[0].label=(this._last_v||0).toFixed(3)};q.registerNodeType("math/noise",k);E.title="Spikes";E.desc="spike every random time"; +E.prototype.onExecute=function(){var a=this.graph.elapsed_time;this._remaining_time-=a;this._blink_time-=a;a=0;0this._remaining_time?(this._remaining_time=Math.random()*(this.properties.max_time-this.properties.min_time)+this.properties.min_time,this._blink_time=this.properties.duration,this.boxcolor="#FFF"):this.boxcolor="#000";this.setOutputData(0,a)};q.registerNodeType("math/spikes",E);D.title="Clamp";D.desc= +"Clamp number between min and max";D.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&(a=Math.max(this.properties.min,a),a=Math.min(this.properties.max,a),this.setOutputData(0,a))};D.prototype.getCode=function(a){a="";this.isInputConnected(0)&&(a+="clamp({{0}},"+this.properties.min+","+this.properties.max+")");return a};q.registerNodeType("math/clamp",D);B.title="Lerp";B.desc="Linear Interpolation";B.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=0);var b= +this.getInputData(1);null==b&&(b=0);var c=this.properties.f,d=this.getInputData(2);void 0!==d&&(c=d);this.setOutputData(0,a*(1-c)+b*c)};B.prototype.onGetInputs=function(){return[["f","number"]]};q.registerNodeType("math/lerp",B);F.title="Abs";F.desc="Absolute";F.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,Math.abs(a))};q.registerNodeType("math/abs",F);I.title="Floor";I.desc="Floor number to remove fractional part";I.prototype.onExecute=function(){var a= +this.getInputData(0);null!=a&&this.setOutputData(0,Math.floor(a))};q.registerNodeType("math/floor",I);f.title="Frac";f.desc="Returns fractional part";f.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,a%1)};q.registerNodeType("math/frac",f);z.title="Smoothstep";z.desc="Smoothstep";z.prototype.onExecute=function(){var a=this.getInputData(0);if(void 0!==a){var b=this.properties.A;a=Math.clamp((a-b)/(this.properties.B-b),0,1);this.setOutputData(0,a*a*(3-2*a))}}; +q.registerNodeType("math/smoothstep",z);H.title="Scale";H.desc="v * factor";H.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,a*this.properties.factor)};q.registerNodeType("math/scale",H);C.title="Gate";C.desc="if v is true, then outputs A, otherwise B";C.prototype.onExecute=function(){var a=this.getInputData(0);this.setOutputData(0,this.getInputData(a?1:2))};q.registerNodeType("math/gate",C);L.title="Average";L.desc="Average Filter";L.prototype.onExecute=function(){var a= +this.getInputData(0);null==a&&(a=0);var b=this._values.length;this._values[this._current%b]=a;this._current+=1;this._current>b&&(this._current=0);for(var c=a=0;cb&&(b=1);this.properties.samples=Math.round(b);a=this._values;this._values=new Float32Array(this.properties.samples);a.length<=this._values.length?this._values.set(a):this._values.set(a.subarray(0,this._values.length))};q.registerNodeType("math/average", +L);G.title="TendTo";G.desc="moves the output value always closer to the input";G.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=0);var b=this.properties.factor;this._value=null==this._value?a:this._value*(1-b)+a*b;this.setOutputData(0,this._value)};q.registerNodeType("math/tendTo",G);K.values="+ - * / % ^ max min".split(" ");K.title="Operation";K.desc="Easy math operators";K["@OP"]={type:"enum",title:"operation",values:K.values};K.size=[100,60];K.prototype.getTitle=function(){return"max"== +this.properties.OP||"min"==this.properties.OP?this.properties.OP+"(A,B)":"A "+this.properties.OP+" B"};K.prototype.setValue=function(a){"string"==typeof a&&(a=parseFloat(a));this.properties.value=a};K.prototype.onPropertyChanged=function(a,b){if("OP"==a)switch(this.properties.OP){case "+":this._func=function(a,b){return a+b};break;case "-":this._func=function(a,b){return a-b};break;case "x":case "X":case "*":this._func=function(a,b){return a*b};break;case "/":this._func=function(a,b){return a/b}; +break;case "%":this._func=function(a,b){return a%b};break;case "^":this._func=function(a,b){return Math.pow(a,b)};break;case "max":this._func=function(a,b){return Math.max(a,b)};break;case "min":this._func=function(a,b){return Math.min(a,b)};break;default:console.warn("Unknown operation: "+this.properties.OP),this._func=function(a){return a}}};K.prototype.onExecute=function(){var a=this.getInputData(0),b=this.getInputData(1);null!=a?a.constructor===Number&&(this.properties.A=a):a=this.properties.A; +null!=b?this.properties.B=b:b=this.properties.B;if(a.constructor===Number)var c=this._func(a,b);else if(a.constructor===Array){c=this._result;c.length=a.length;for(var d=0;dB":f=a>b;break;case "A=B":f=a>=b}this.setOutputData(c,f)}}};J.prototype.onGetOutputs=function(){return[["A==B","boolean"],["A!=B","boolean"],["A>B","boolean"],["A=B","boolean"],["A<=B","boolean"]]};q.registerNodeType("math/compare",J);q.registerSearchboxExtra("math/compare","==",{outputs:[["A==B","boolean"]],title:"A==B"}); q.registerSearchboxExtra("math/compare","!=",{outputs:[["A!=B","boolean"]],title:"A!=B"});q.registerSearchboxExtra("math/compare",">",{outputs:[["A>B","boolean"]],title:"A>B"});q.registerSearchboxExtra("math/compare","<",{outputs:[["A=",{outputs:[["A>=B","boolean"]],title:"A>=B"});q.registerSearchboxExtra("math/compare","<=",{outputs:[["A<=B","boolean"]],title:"A<=B"});a.values="> < == != <= >= || &&".split(" ");a["@OP"]={type:"enum", title:"operation",values:a.values};a.title="Condition";a.desc="evaluates condition between A and B";a.prototype.getTitle=function(){return"A "+this.properties.OP+" B"};a.prototype.onExecute=function(){var a=this.getInputData(0);void 0===a?a=this.properties.A:this.properties.A=a;var b=this.getInputData(1);void 0===b?b=this.properties.B:this.properties.B=b;var c=!0;switch(this.properties.OP){case ">":c=a>b;break;case "<":c=a=":c=a>=b;break;case "||":c=a||b;break;case "&&":c=a&&b}this.setOutputData(0,c);this.setOutputData(1,!c)};q.registerNodeType("math/condition",a);b.title="Branch";b.desc="If condition is true, outputs IN in true, otherwise in false";b.prototype.onExecute=function(){var a=this.getInputData(0);this.getInputData(1)?(this.setOutputData(0,a),this.setOutputData(1,null)):(this.setOutputData(0,null),this.setOutputData(1,a))};q.registerNodeType("math/branch",b);c.title="Accumulate";c.desc="Increments a value every time"; c.prototype.onExecute=function(){null===this.properties.value&&(this.properties.value=0);var a=this.getInputData(0);this.properties.value=null!==a?this.properties.value+a:this.properties.value+this.properties.increment;this.setOutputData(0,this.properties.value)};q.registerNodeType("math/accumulate",c);d.title="Trigonometry";d.desc="Sin Cos Tan";d.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=0);var b=this.properties.amplitude,c=this.findInputSlot("amplitude");-1!=c&&(b=this.getInputData(c)); var d=this.properties.offset;c=this.findInputSlot("offset");-1!=c&&(d=this.getInputData(c));c=0;for(var e=this.outputs.length;cXY";g.desc="vector 2 to components";g.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&(this.setOutputData(0,a[0]),this.setOutputData(1,a[1]))};q.registerNodeType("math3d/vec2-to-xy", -g);k.title="XY->Vec2";k.desc="components to vector2";k.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=this.properties.x);var b=this.getInputData(1);null==b&&(b=this.properties.y);var c=this._data;c[0]=a;c[1]=b;this.setOutputData(0,c)};q.registerNodeType("math3d/xy-to-vec2",k);n.title="Vec3->XYZ";n.desc="vector 3 to components";n.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&(this.setOutputData(0,a[0]),this.setOutputData(1,a[1]),this.setOutputData(2,a[2]))}; +g);h.title="XY->Vec2";h.desc="components to vector2";h.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=this.properties.x);var b=this.getInputData(1);null==b&&(b=this.properties.y);var c=this._data;c[0]=a;c[1]=b;this.setOutputData(0,c)};q.registerNodeType("math3d/xy-to-vec2",h);n.title="Vec3->XYZ";n.desc="vector 3 to components";n.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&(this.setOutputData(0,a[0]),this.setOutputData(1,a[1]),this.setOutputData(2,a[2]))}; q.registerNodeType("math3d/vec3-to-xyz",n);p.title="XYZ->Vec3";p.desc="components to vector3";p.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=this.properties.x);var b=this.getInputData(1);null==b&&(b=this.properties.y);var c=this.getInputData(2);null==c&&(c=this.properties.z);var d=this._data;d[0]=a;d[1]=b;d[2]=c;this.setOutputData(0,d)};q.registerNodeType("math3d/xyz-to-vec3",p);r.title="Vec4->XYZW";r.desc="vector 4 to components";r.prototype.onExecute=function(){var a=this.getInputData(0); null!=a&&(this.setOutputData(0,a[0]),this.setOutputData(1,a[1]),this.setOutputData(2,a[2]),this.setOutputData(3,a[3]))};q.registerNodeType("math3d/vec4-to-xyzw",r);u.title="XYZW->Vec4";u.desc="components to vector4";u.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=this.properties.x);var b=this.getInputData(1);null==b&&(b=this.properties.y);var c=this.getInputData(2);null==c&&(c=this.properties.z);var d=this.getInputData(3);null==d&&(d=this.properties.w);var e=this._data;e[0]= a;e[1]=b;e[2]=c;e[3]=d;this.setOutputData(0,e)};q.registerNodeType("math3d/xyzw-to-vec4",u)})(this); @@ -463,20 +464,20 @@ function(m,l){return void 0===m?l:void 0===l?m:m+l},["string","string"],"string" " ");if(m.constructor===Array){for(var w=[],t=0;t