Files
ComfyUI_frontend/build/litegraph_mini.min.js
2021-11-03 10:06:01 +01:00

420 lines
207 KiB
JavaScript

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(v,n,t){v!=Array.prototype&&v!=Object.prototype&&(v[n]=t.value)};$jscomp.getGlobal=function(v){return"undefined"!=typeof window&&window===v?v:"undefined"!=typeof global&&null!=global?global:v};$jscomp.global=$jscomp.getGlobal(this);
$jscomp.polyfill=function(v,n,t,h){if(n){t=$jscomp.global;v=v.split(".");for(h=0;h<v.length-1;h++){var r=v[h];r in t||(t[r]={});t=t[r]}v=v[v.length-1];h=t[v];n=n(h);n!=h&&null!=n&&$jscomp.defineProperty(t,v,{configurable:!0,writable:!0,value:n})}};$jscomp.polyfill("Array.prototype.fill",function(v){return v?v:function(n,t,h){var r=this.length||0;0>t&&(t=Math.max(0,r+t));if(null==h||h>r)h=r;h=Number(h);0>h&&(h=Math.max(0,r+h));for(t=Number(t||0);t<h;t++)this[t]=n;return this}},"es6","es3");
$jscomp.SYMBOL_PREFIX="jscomp_symbol_";$jscomp.initSymbol=function(){$jscomp.initSymbol=function(){};$jscomp.global.Symbol||($jscomp.global.Symbol=$jscomp.Symbol)};$jscomp.Symbol=function(){var v=0;return function(n){return $jscomp.SYMBOL_PREFIX+(n||"")+v++}}();
$jscomp.initSymbolIterator=function(){$jscomp.initSymbol();var v=$jscomp.global.Symbol.iterator;v||(v=$jscomp.global.Symbol.iterator=$jscomp.global.Symbol("iterator"));"function"!=typeof Array.prototype[v]&&$jscomp.defineProperty(Array.prototype,v,{configurable:!0,writable:!0,value:function(){return $jscomp.arrayIterator(this)}});$jscomp.initSymbolIterator=function(){}};$jscomp.arrayIterator=function(v){var n=0;return $jscomp.iteratorPrototype(function(){return n<v.length?{done:!1,value:v[n++]}:{done:!0}})};
$jscomp.iteratorPrototype=function(v){$jscomp.initSymbolIterator();v={next:v};v[$jscomp.global.Symbol.iterator]=function(){return this};return v};$jscomp.iteratorFromArray=function(v,n){$jscomp.initSymbolIterator();v instanceof String&&(v+="");var t=0,h={next:function(){if(t<v.length){var r=t++;return{value:n(r,v[r]),done:!1}}h.next=function(){return{done:!0,value:void 0}};return h.next()}};h[Symbol.iterator]=function(){return h};return h};
$jscomp.polyfill("Array.prototype.values",function(v){return v?v:function(){return $jscomp.iteratorFromArray(this,function(n,t){return t})}},"es8","es3");$jscomp.polyfill("Array.prototype.keys",function(v){return v?v:function(){return $jscomp.iteratorFromArray(this,function(n){return n})}},"es6","es3");$jscomp.owns=function(v,n){return Object.prototype.hasOwnProperty.call(v,n)};
$jscomp.polyfill("Object.values",function(v){return v?v:function(n){var t=[],h;for(h in n)$jscomp.owns(n,h)&&t.push(n[h]);return t}},"es8","es3");$jscomp.checkStringArgs=function(v,n,t){if(null==v)throw new TypeError("The 'this' value for String.prototype."+t+" must not be null or undefined");if(n instanceof RegExp)throw new TypeError("First argument to String.prototype."+t+" must not be a regular expression");return v+""};
$jscomp.polyfill("String.prototype.startsWith",function(v){return v?v:function(n,t){var h=$jscomp.checkStringArgs(this,n,"startsWith");n+="";var r=h.length,w=n.length;t=Math.max(0,Math.min(t|0,h.length));for(var g=0;g<w&&t<r;)if(h[t++]!=n[g++])return!1;return g>=w}},"es6","es3");$jscomp.findInternal=function(v,n,t){v instanceof String&&(v=String(v));for(var h=v.length,r=0;r<h;r++){var w=v[r];if(n.call(t,w,r,v))return{i:r,v:w}}return{i:-1,v:void 0}};
$jscomp.polyfill("Array.prototype.findIndex",function(v){return v?v:function(n,t){return $jscomp.findInternal(this,n,t).i}},"es6","es3");
(function(v){function n(a){f.debug&&console.log("Graph created");this.list_of_graphcanvas=null;this.clear();a&&this.configure(a)}function t(a,b,c,d,e,k){this.id=a;this.type=b;this.origin_id=c;this.origin_slot=d;this.target_id=e;this.target_slot=k;this._data=null;this._pos=new Float32Array(2)}function h(a){this._ctor(a)}function r(a){this._ctor(a)}function w(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 g(a,b,c){this.options=c=c||{};this.background_image=g.DEFAULT_BACKGROUND_IMAGE;a&&a.constructor===String&&(a=document.querySelector(a));this.ds=new w;this.zoom_modify_alpha=!0;this.title_text_font=""+f.NODE_TEXT_SIZE+"px Arial";this.inner_text_font="normal "+f.NODE_SUBTEXT_SIZE+"px Arial";this.node_title_color=f.NODE_TITLE_COLOR;this.default_link_color=f.LINK_COLOR;this.default_connection_color=
{input_off:"#778",input_on:"#7F7",output_off:"#778",output_on:"#7F7"};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_searchbox=this.allow_interaction=this.allow_dragnodes=this.allow_dragcanvas=this.show_info=!0;this.drag_mode=this.align_to_grid=this.allow_reconnect_links=!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=f.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=c.viewport||null;b&&b.attachCanvas(this);this.setCanvas(a,c.skip_events);this.clear();c.skip_render||this.startRendering();this.autoresize=
c.autoresize}function B(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,c,d,e,k){return c<a&&c+e>a&&d<b&&d+k>b?!0:!1}function y(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<b[0]||d<b[1]?!1:!0}function C(a,b){function c(a){var c=parseInt(k.style.top);k.style.top=(c+a.deltaY*b.scroll_speed).toFixed()+"px";a.preventDefault();return!0}this.options=b=b||{};var d=this;b.parentMenu&&(b.parentMenu.constructor!==this.constructor?(console.error("parentMenu must be of class ContextMenu, ignoring it"),
b.parentMenu=null):(this.parentMenu=b.parentMenu,this.parentMenu.lock=!0,this.parentMenu.current_submenu=this));var e=null;b.event&&(e=b.event.constructor.name);"MouseEvent"!==e&&"CustomEvent"!==e&&"PointerEvent"!==e&&(console.error("Event passed to ContextMenu is not of type MouseEvent or CustomEvent. Ignoring it. ("+e+")"),b.event=null);var k=document.createElement("div");k.className="litegraph litecontextmenu litemenubar-panel";b.className&&(k.className+=" "+b.className);k.style.minWidth=100;k.style.minHeight=
100;k.style.pointerEvents="none";setTimeout(function(){k.style.pointerEvents="auto"},100);f.pointerListenerAdd(k,"up",function(a){a.preventDefault();return!0},!0);k.addEventListener("contextmenu",function(a){if(2!=a.button)return!1;a.preventDefault();return!1},!0);f.pointerListenerAdd(k,"down",function(a){if(2==a.button)return d.close(),a.preventDefault(),!0},!0);b.scroll_speed||(b.scroll_speed=.1);k.addEventListener("wheel",c,!0);k.addEventListener("mousewheel",c,!0);this.root=k;b.title&&(e=document.createElement("div"),
e.className="litemenu-title",e.innerHTML=b.title,k.appendChild(e));for(var m=e=0;m<a.length;m++){var l=a.constructor==Array?a[m]:m;null!=l&&l.constructor!==String&&(l=void 0===l.content?String(l):l.content);this.addItem(l,a[m],b);e++}f.pointerListenerAdd(k,"enter",function(a){k.closing_timer&&clearTimeout(k.closing_timer)});a=document;b.event&&(a=b.event.target.ownerDocument);a||(a=document);a.fullscreenElement?a.fullscreenElement.appendChild(k):a.body.appendChild(k);e=b.left||0;a=b.top||0;b.event&&
(e=b.event.clientX-10,a=b.event.clientY-10,b.title&&(a-=20),b.parentMenu&&(e=b.parentMenu.root.getBoundingClientRect(),e=e.left+e.width),m=document.body.getBoundingClientRect(),l=k.getBoundingClientRect(),0==m.height&&console.error("document.body height is 0. That is dangerous, set html,body { height: 100%; }"),m.width&&e>m.width-l.width-10&&(e=m.width-l.width-10),m.height&&a>m.height-l.height-10&&(a=m.height-l.height-10));k.style.left=e+"px";k.style.top=a+"px";b.scale&&(k.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 f=v.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,INPUT:1,OUTPUT:2,
EVENT:-1,ACTION:-1,ALWAYS:0,ON_EVENT:1,NEVER:2,ON_TRIGGER:3,UP:1,DOWN:2,LEFT:3,RIGHT:4,CENTER:5,STRAIGHT_LINK:0,LINEAR_LINK:1,SPLINE_LINK:2,NORMAL_TITLE:0,NO_TITLE:1,TRANSPARENT_TITLE:2,AUTOHIDE_TITLE:3,proxy:null,node_images_path:"",debug:!1,catch_exceptions:!0,throw_errors:!0,allow_scripts:!1,registered_node_types:{},node_types_by_file_extension:{},Nodes:{},Globals:{},searchbox_extras:{},auto_sort_node_types:!1,pointerevents_method:"pointer",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 h.prototype)b.prototype[e]||(b.prototype[e]=h.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 k=b.supported_extensions[e];k&&k.constructor===String&&
(this.node_types_by_file_extension[k.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;e<b.supported_extensions.length;e++)(k=b.supported_extensions[e])&&k.constructor===
String&&(this.node_types_by_file_extension[k.toLowerCase()]=b)},unregisterNodeType:function(a){var b=a.constructor===String?this.registered_node_types[a]:a;if(!b)throw"node type not found: "+a;delete this.registered_node_types[b.type];b.constructor.name&&delete this.Nodes[b.constructor.name]},wrapFunctionAsNode:function(a,b,c,d,e){for(var k=Array(b.length),m="",l=f.getParameterNames(b),q=0;q<l.length;++q)m+="this.addInput('"+l[q]+"',"+(c&&c[q]?"'"+c[q]+"'":"0")+");\n";m+="this.addOutput('out',"+(d?
"'"+d+"'":0)+");\n";e&&(m+="this.properties = "+JSON.stringify(e)+";\n");c=Function(m);c.title=a.split("/").pop();c.desc="Generated from "+b.name;c.prototype.onExecute=function(){for(var a=0;a<k.length;++a)k[a]=this.getInputData(a);a=b.apply(this,k);this.setOutputData(0,a)};this.registerNodeType(a,c)},clearRegisteredTypes:function(){this.registered_node_types={};this.node_types_by_file_extension={};this.Nodes={};this.searchbox_extras={}},addNodeMethod:function(a,b){h.prototype[a]=b;for(var c in this.registered_node_types){var d=
this.registered_node_types[c];d.prototype[a]&&(d.prototype["_"+a]=d.prototype[a]);d.prototype[a]=b}},createNode:function(a,b,c){var d=this.registered_node_types[a];if(!d)return f.debug&&console.log('GraphNode type "'+a+'" not registered.'),null;b=b||d.title||a;var e=null;if(f.catch_exceptions)try{e=new d(b)}catch(m){return console.error(m),null}else e=new d(b);e.type=a;!e.title&&b&&(e.title=b);e.properties||(e.properties={});e.properties_info||(e.properties_info=[]);e.flags||(e.flags={});e.size||
(e.size=e.computeSize());e.pos||(e.pos=f.DEFAULT_POSITION.concat());e.mode||(e.mode=f.ALWAYS);if(c)for(var k in c)e[k]=c[k];return e},getNodeType:function(a){return this.registered_node_types[a]},getNodeTypesInCategory:function(a,b){var c=[],d;for(d in this.registered_node_types){var e=this.registered_node_types[d];e.filter==b&&(""==a?null==e.category&&c.push(e):e.category==a&&c.push(e))}this.auto_sort_node_types&&c.sort(function(a,b){return a.title.localeCompare(b.title)});return c},getNodeTypesCategories:function(a){var b=
{"":1},c;for(c in this.registered_node_types){var d=this.registered_node_types[c];d.category&&!d.skip_list&&d.filter==a&&(b[d.category]=1)}a=[];for(c in b)a.push(c);return this.auto_sort_node_types?a.sort():a},reloadNodes:function(a){for(var b=document.getElementsByTagName("script"),c=[],d=0;d<b.length;d++)c.push(b[d]);b=document.getElementsByTagName("head")[0];a=document.location.href+a;for(d=0;d<c.length;d++){var e=c[d].src;if(e&&e.substr(0,a.length)==a)try{f.debug&&console.log("Reloading: "+e);
var k=document.createElement("script");k.type="text/javascript";k.src=e;b.appendChild(k);b.removeChild(c[d])}catch(m){if(f.throw_errors)throw m;f.debug&&console.log("Error while reloading "+e)}}f.debug&&console.log("Nodes reloaded")},cloneObject:function(a,b){if(null==a)return null;a=JSON.parse(JSON.stringify(a));if(!b)return a;for(var c in a)b[c]=a[c];return b},isValidConnection:function(a,b){if(!a||!b||a==b||a==f.EVENT&&b==f.ACTION)return!0;a=String(a);b=String(b);a=a.toLowerCase();b=b.toLowerCase();
if(-1==a.indexOf(",")&&-1==b.indexOf(","))return a==b;a=a.split(",");b=b.split(",");for(var c=0;c<a.length;++c)for(var d=0;d<b.length;++d)if(a[c]==b[d])return!0;return!1},registerSearchboxExtra:function(a,b,c){this.searchbox_extras[b.toLowerCase()]={type:a,desc:b,data:c}},fetchFile:function(a,b,c,d){if(!a)return null;b=b||"text";if(a.constructor===String)return"http"==a.substr(0,4)&&f.proxy&&(a=f.proxy+a.substr(a.indexOf(":")+3)),fetch(a).then(function(a){if(!a.ok)throw Error("File not found");if("arraybuffer"==
b)return a.arrayBuffer();if("text"==b||"string"==b)return a.text();if("json"==b)return a.json();if("blob"==b)return a.blob()}).then(function(a){c&&c(a)}).catch(function(b){console.error("error fetching file:",a);d&&d(b)});if(a.constructor===File||a.constructor===Blob){var e=new FileReader;e.onload=function(a){a=a.target.result;"json"==b&&(a=JSON.parse(a));c&&c(a)};if("arraybuffer"==b)return e.readAsArrayBuffer(a);if("text"==b||"json"==b)return e.readAsText(a);if("blob"==b)return e.readAsBinaryString(a)}return null}};
f.getTime="undefined"!=typeof performance?performance.now.bind(performance):"undefined"!=typeof Date&&Date.now?Date.now.bind(Date):"undefined"!=typeof process?function(){var a=process.hrtime();return.001*a[0]+1E-6*a[1]}:function(){return(new Date).getTime()};v.LGraph=f.LGraph=n;n.supported_types=["number","string","boolean"];n.prototype.getSupportedTypes=function(){return this.supported_types||n.supported_types};n.STATUS_STOPPED=1;n.STATUS_RUNNING=2;n.prototype.clear=function(){this.stop();this.status=
n.STATUS_STOPPED;this.last_link_id=this.last_node_id=0;this._version=-1;if(this._nodes)for(var a=0;a<this._nodes.length;++a){var b=this._nodes[a];if(b.onRemoved)b.onRemoved()}this._nodes=[];this._nodes_by_id={};this._nodes_in_order=[];this._nodes_executable=null;this._groups=[];this.links={};this.iteration=0;this.config={};this.vars={};this.extra={};this.fixedtime=this.runningtime=this.globaltime=0;this.elapsed_time=this.fixedtime_lapse=.01;this.starttime=this.last_update_time=0;this.catch_errors=
!0;this.inputs={};this.outputs={};this.change();this.sendActionToCanvas("clear")};n.prototype.attachCanvas=function(a){if(a.constructor!=g)throw"attachCanvas expects a LGraphCanvas instance";a.graph&&a.graph!=this&&a.graph.detachCanvas(a);a.graph=this;this.list_of_graphcanvas||(this.list_of_graphcanvas=[]);this.list_of_graphcanvas.push(a)};n.prototype.detachCanvas=function(a){if(this.list_of_graphcanvas){var b=this.list_of_graphcanvas.indexOf(a);-1!=b&&(a.graph=null,this.list_of_graphcanvas.splice(b,
1))}};n.prototype.start=function(a){if(this.status!=n.STATUS_RUNNING){this.status=n.STATUS_RUNNING;if(this.onPlayEvent)this.onPlayEvent();this.sendEventToAllNodes("onStart");this.last_update_time=this.starttime=f.getTime();a=a||0;var b=this;if(0==a&&"undefined"!=typeof window&&window.requestAnimationFrame){var c=function(){if(-1==b.execution_timer_id){window.requestAnimationFrame(c);if(b.onBeforeStep)b.onBeforeStep();b.runStep(1,!b.catch_errors);if(b.onAfterStep)b.onAfterStep()}};this.execution_timer_id=
-1;c()}else this.execution_timer_id=setInterval(function(){if(b.onBeforeStep)b.onBeforeStep();b.runStep(1,!b.catch_errors);if(b.onAfterStep)b.onAfterStep()},a)}};n.prototype.stop=function(){if(this.status!=n.STATUS_STOPPED){this.status=n.STATUS_STOPPED;if(this.onStopEvent)this.onStopEvent();null!=this.execution_timer_id&&(-1!=this.execution_timer_id&&clearInterval(this.execution_timer_id),this.execution_timer_id=null);this.sendEventToAllNodes("onStop")}};n.prototype.runStep=function(a,b,c){a=a||1;
var d=f.getTime();this.globaltime=.001*(d-this.starttime);var e=this._nodes_executable?this._nodes_executable:this._nodes;if(e){c=c||e.length;if(b){for(var k=0;k<a;k++){for(var m=0;m<c;++m){var l=e[m];if(l.mode==f.ALWAYS&&l.onExecute)l.onExecute()}this.fixedtime+=this.fixedtime_lapse;if(this.onExecuteStep)this.onExecuteStep()}if(this.onAfterExecute)this.onAfterExecute()}else try{for(k=0;k<a;k++){for(m=0;m<c;++m)if(l=e[m],l.mode==f.ALWAYS&&l.onExecute)l.onExecute();this.fixedtime+=this.fixedtime_lapse;
if(this.onExecuteStep)this.onExecuteStep()}if(this.onAfterExecute)this.onAfterExecute();this.errors_in_execution=!1}catch(q){this.errors_in_execution=!0;if(f.throw_errors)throw q;f.debug&&console.log("Error during execution: "+q);this.stop()}a=f.getTime();d=a-d;0==d&&(d=1);this.execution_time=.001*d;this.globaltime+=.001*d;this.iteration+=1;this.elapsed_time=.001*(a-this.last_update_time);this.last_update_time=a}};n.prototype.updateExecutionOrder=function(){this._nodes_in_order=this.computeExecutionOrder(!1);
this._nodes_executable=[];for(var a=0;a<this._nodes_in_order.length;++a)this._nodes_in_order[a].onExecute&&this._nodes_executable.push(this._nodes_in_order[a])};n.prototype.computeExecutionOrder=function(a,b){for(var c=[],d=[],e={},k={},m={},l=0,q=this._nodes.length;l<q;++l){var u=this._nodes[l];if(!a||u.onExecute){e[u.id]=u;var g=0;if(u.inputs)for(var p=0,x=u.inputs.length;p<x;p++)u.inputs[p]&&null!=u.inputs[p].link&&(g+=1);0==g?(d.push(u),b&&(u._level=1)):(b&&(u._level=0),m[u.id]=g)}}for(;0!=d.length;)if(u=
d.shift(),c.push(u),delete e[u.id],u.outputs)for(l=0;l<u.outputs.length;l++)if(a=u.outputs[l],null!=a&&null!=a.links&&0!=a.links.length)for(p=0;p<a.links.length;p++)(q=this.links[a.links[p]])&&!k[q.id]&&(g=this.getNodeById(q.target_id),null==g?k[q.id]=!0:(b&&(!g._level||g._level<=u._level)&&(g._level=u._level+1),k[q.id]=!0,--m[g.id],0==m[g.id]&&d.push(g)));for(l in e)c.push(e[l]);c.length!=this._nodes.length&&f.debug&&console.warn("something went wrong, nodes missing");q=c.length;for(l=0;l<q;++l)c[l].order=
l;c=c.sort(function(a,b){var c=a.constructor.priority||a.priority||0,d=b.constructor.priority||b.priority||0;return c==d?a.order-b.order:c-d});for(l=0;l<q;++l)c[l].order=l;return c};n.prototype.getAncestors=function(a){for(var b=[],c=[a],d={};c.length;){var e=c.shift();if(e.inputs){d[e.id]||e==a||(d[e.id]=!0,b.push(e));for(var k=0;k<e.inputs.length;++k){var f=e.getInputNode(k);f&&-1==b.indexOf(f)&&c.push(f)}}}b.sort(function(a,b){return a.order-b.order});return b};n.prototype.arrange=function(a){a=
a||100;for(var b=this.computeExecutionOrder(!1,!0),c=[],d=0;d<b.length;++d){var e=b[d],k=e._level||1;c[k]||(c[k]=[]);c[k].push(e)}b=a;for(d=0;d<c.length;++d)if(k=c[d]){for(var m=100,l=a+f.NODE_TITLE_HEIGHT,q=0;q<k.length;++q)e=k[q],e.pos[0]=b,e.pos[1]=l,e.size[0]>m&&(m=e.size[0]),l+=e.size[1]+a+f.NODE_TITLE_HEIGHT;b+=m+a}this.setDirtyCanvas(!0,!0)};n.prototype.getTime=function(){return this.globaltime};n.prototype.getFixedTime=function(){return this.fixedtime};n.prototype.getElapsedTime=function(){return this.elapsed_time};
n.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,k=d.length;e<k;++e){var m=d[e];if(m.constructor===f.Subgraph&&"onExecute"!=a)m.mode==c&&m.sendEventToAllNodes(a,b,c);else if(m[a]&&m.mode==c)if(void 0===b)m[a]();else if(b&&b.constructor===Array)m[a].apply(m,b);else m[a](b)}};n.prototype.sendActionToCanvas=function(a,b){if(this.list_of_graphcanvas)for(var c=0;c<this.list_of_graphcanvas.length;++c){var d=this.list_of_graphcanvas[c];
d[a]&&d[a].apply(d,b)}};n.prototype.add=function(a,b){if(a)if(a.constructor===r)this._groups.push(a),this.setDirtyCanvas(!0),this.change(),a.graph=this,this._version++;else{-1!=a.id&&null!=this._nodes_by_id[a.id]&&(console.warn("LiteGraph: there is already a node with this ID, changing it"),a.id=++this.last_node_id);if(this._nodes.length>=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_id<a.id&&(this.last_node_id=
a.id);a.graph=this;this._version++;this._nodes.push(a);this._nodes_by_id[a.id]=a;if(a.onAdded)a.onAdded(this);this.config.align_to_grid&&a.alignToGrid();b||this.updateExecutionOrder();if(this.onNodeAdded)this.onNodeAdded(a);this.setDirtyCanvas(!0);this.change();return a}};n.prototype.remove=function(a){if(a.constructor===f.LGraphGroup){var b=this._groups.indexOf(a);-1!=b&&this._groups.splice(b,1);a.graph=null;this._version++;this.setDirtyCanvas(!0,!0);this.change()}else if(null!=this._nodes_by_id[a.id]&&
!a.ignore_remove){this.beforeChange();if(a.inputs)for(b=0;b<a.inputs.length;b++){var c=a.inputs[b];null!=c.link&&a.disconnectInput(b)}if(a.outputs)for(b=0;b<a.outputs.length;b++)c=a.outputs[b],null!=c.links&&c.links.length&&a.disconnectOutput(b);if(a.onRemoved)a.onRemoved();a.graph=null;this._version++;if(this.list_of_graphcanvas)for(b=0;b<this.list_of_graphcanvas.length;++b)c=this.list_of_graphcanvas[b],c.selected_nodes[a.id]&&delete c.selected_nodes[a.id],c.node_dragged==a&&(c.node_dragged=null);
b=this._nodes.indexOf(a);-1!=b&&this._nodes.splice(b,1);delete this._nodes_by_id[a.id];if(this.onNodeRemoved)this.onNodeRemoved(a);this.sendActionToCanvas("checkPanels");this.setDirtyCanvas(!0,!0);this.afterChange();this.change();this.updateExecutionOrder()}};n.prototype.getNodeById=function(a){return null==a?null:this._nodes_by_id[a]};n.prototype.findNodesByClass=function(a,b){b=b||[];for(var c=b.length=0,d=this._nodes.length;c<d;++c)this._nodes[c].constructor===a&&b.push(this._nodes[c]);return b};
n.prototype.findNodesByType=function(a,b){a=a.toLowerCase();b=b||[];for(var c=b.length=0,d=this._nodes.length;c<d;++c)this._nodes[c].type.toLowerCase()==a&&b.push(this._nodes[c]);return b};n.prototype.findNodeByTitle=function(a){for(var b=0,c=this._nodes.length;b<c;++b)if(this._nodes[b].title==a)return this._nodes[b];return null};n.prototype.findNodesByTitle=function(a){for(var b=[],c=0,d=this._nodes.length;c<d;++c)this._nodes[c].title==a&&b.push(this._nodes[c]);return b};n.prototype.getNodeOnPos=
function(a,b,c,d){c=c||this._nodes;for(var e=c.length-1;0<=e;e--){var k=c[e];if(k.isPointInside(a,b,d))return k}return null};n.prototype.getGroupOnPos=function(a,b){for(var c=this._groups.length-1;0<=c;c--){var d=this._groups[c];if(d.isPointInside(a,b,2,!0))return d}return null};n.prototype.checkNodeTypes=function(){for(var a=0;a<this._nodes.length;a++){var b=this._nodes[a];if(b.constructor!=f.registered_node_types[b.type]){console.log("node being replaced by newer version: "+b.type);var c=f.createNode(b.type);
this._nodes[a]=c;c.configure(b.serialize());c.graph=this;this._nodes_by_id[c.id]=c;b.inputs&&(c.inputs=b.inputs.concat());b.outputs&&(c.outputs=b.outputs.concat())}}this.updateExecutionOrder()};n.prototype.onAction=function(a,b){this._input_nodes=this.findNodesByClass(f.GraphInput,this._input_nodes);for(var c=0;c<this._input_nodes.length;++c){var d=this._input_nodes[c];if(d.properties.name==a){d.onAction(a,b);break}}};n.prototype.trigger=function(a,b){if(this.onTrigger)this.onTrigger(a,b)};n.prototype.addInput=
function(a,b,c){if(!this.inputs[a]){this.beforeChange();this.inputs[a]={name:a,type:b,value:c};this._version++;this.afterChange();if(this.onInputAdded)this.onInputAdded(a,b);if(this.onInputsOutputsChange)this.onInputsOutputsChange()}};n.prototype.setInputData=function(a,b){if(a=this.inputs[a])a.value=b};n.prototype.getInputData=function(a){return(a=this.inputs[a])?a.value:null};n.prototype.renameInput=function(a,b){if(b!=a){if(!this.inputs[a])return!1;if(this.inputs[b])return console.error("there is already one input with that name"),
!1;this.inputs[b]=this.inputs[a];delete this.inputs[a];this._version++;if(this.onInputRenamed)this.onInputRenamed(a,b);if(this.onInputsOutputsChange)this.onInputsOutputsChange()}};n.prototype.changeInputType=function(a,b){if(!this.inputs[a])return!1;if(!this.inputs[a].type||String(this.inputs[a].type).toLowerCase()!=String(b).toLowerCase())if(this.inputs[a].type=b,this._version++,this.onInputTypeChanged)this.onInputTypeChanged(a,b)};n.prototype.removeInput=function(a){if(!this.inputs[a])return!1;
delete this.inputs[a];this._version++;if(this.onInputRemoved)this.onInputRemoved(a);if(this.onInputsOutputsChange)this.onInputsOutputsChange();return!0};n.prototype.addOutput=function(a,b,c){this.outputs[a]={name:a,type:b,value:c};this._version++;if(this.onOutputAdded)this.onOutputAdded(a,b);if(this.onInputsOutputsChange)this.onInputsOutputsChange()};n.prototype.setOutputData=function(a,b){if(a=this.outputs[a])a.value=b};n.prototype.getOutputData=function(a){return(a=this.outputs[a])?a.value:null};
n.prototype.renameOutput=function(a,b){if(!this.outputs[a])return!1;if(this.outputs[b])return console.error("there is already one output with that name"),!1;this.outputs[b]=this.outputs[a];delete this.outputs[a];this._version++;if(this.onOutputRenamed)this.onOutputRenamed(a,b);if(this.onInputsOutputsChange)this.onInputsOutputsChange()};n.prototype.changeOutputType=function(a,b){if(!this.outputs[a])return!1;if(!this.outputs[a].type||String(this.outputs[a].type).toLowerCase()!=String(b).toLowerCase())if(this.outputs[a].type=
b,this._version++,this.onOutputTypeChanged)this.onOutputTypeChanged(a,b)};n.prototype.removeOutput=function(a){if(!this.outputs[a])return!1;delete this.outputs[a];this._version++;if(this.onOutputRemoved)this.onOutputRemoved(a);if(this.onInputsOutputsChange)this.onInputsOutputsChange();return!0};n.prototype.triggerInput=function(a,b){a=this.findNodesByTitle(a);for(var c=0;c<a.length;++c)a[c].onTrigger(b)};n.prototype.setCallback=function(a,b){a=this.findNodesByTitle(a);for(var c=0;c<a.length;++c)a[c].setTrigger(b)};
n.prototype.beforeChange=function(a){if(this.onBeforeChange)this.onBeforeChange(this,a);this.sendActionToCanvas("onBeforeChange",this)};n.prototype.afterChange=function(a){if(this.onAfterChange)this.onAfterChange(this,a);this.sendActionToCanvas("onAfterChange",this)};n.prototype.connectionChange=function(a,b){this.updateExecutionOrder();if(this.onConnectionChange)this.onConnectionChange(a);this._version++;this.sendActionToCanvas("onConnectionChange")};n.prototype.isLive=function(){if(!this.list_of_graphcanvas)return!1;
for(var a=0;a<this.list_of_graphcanvas.length;++a)if(this.list_of_graphcanvas[a].live_mode)return!0;return!1};n.prototype.clearTriggeredSlots=function(){for(var a in this.links){var b=this.links[a];b&&b._last_time&&(b._last_time=0)}};n.prototype.change=function(){f.debug&&console.log("Graph changed");this.sendActionToCanvas("setDirty",[!0,!0]);if(this.on_change)this.on_change(this)};n.prototype.setDirtyCanvas=function(a,b){this.sendActionToCanvas("setDirty",[a,b])};n.prototype.removeLink=function(a){if(a=
this.links[a]){var b=this.getNodeById(a.target_id);b&&b.disconnectInput(a.target_slot)}};n.prototype.serialize=function(){for(var a=[],b=0,c=this._nodes.length;b<c;++b)a.push(this._nodes[b].serialize());c=[];for(b in this.links){var d=this.links[b];if(!d.serialize){console.warn("weird LLink bug, link info is not a LLink but a regular object");var e=new t;for(k in d)e[k]=d[k];d=this.links[b]=e}c.push(d.serialize())}var k=[];for(b=0;b<this._groups.length;++b)k.push(this._groups[b].serialize());a={last_node_id:this.last_node_id,
last_link_id:this.last_link_id,nodes:a,links:c,groups:k,config:this.config,extra:this.extra,version:f.VERSION};if(this.onSerialize)this.onSerialize(a);return a};n.prototype.configure=function(a,b){if(a){b||this.clear();b=a.nodes;if(a.links&&a.links.constructor===Array){for(var c=[],d=0;d<a.links.length;++d){var e=a.links[d];if(e){var k=new t;k.configure(e);c[k.id]=k}else console.warn("serialized graph link data contains errors, skipping.")}a.links=c}for(d in a)"nodes"!=d&&"groups"!=d&&(this[d]=a[d]);
c=!1;this._nodes=[];if(b){d=0;for(e=b.length;d<e;++d){k=b[d];var m=f.createNode(k.type,k.title);m||(f.debug&&console.log("Node not found or has errors: "+k.type),m=new h,m.last_serialization=k,c=m.has_errors=!0);m.id=k.id;this.add(m,!0)}d=0;for(e=b.length;d<e;++d)k=b[d],(m=this.getNodeById(k.id))&&m.configure(k)}this._groups.length=0;if(a.groups)for(d=0;d<a.groups.length;++d)b=new f.LGraphGroup,b.configure(a.groups[d]),this.add(b);this.updateExecutionOrder();this.extra=a.extra||{};if(this.onConfigure)this.onConfigure(a);
this._version++;this.setDirtyCanvas(!0,!0);return c}};n.prototype.load=function(a,b){var c=this;if(a.constructor===File||a.constructor===Blob){var d=new FileReader;d.addEventListener("load",function(a){a=JSON.parse(a.target.result);c.configure(a);b&&b()});d.readAsText(a)}else{var e=new XMLHttpRequest;e.open("GET",a,!0);e.send(null);e.onload=function(a){200!==e.status?console.error("Error loading graph:",e.status,e.response):(a=JSON.parse(e.response),c.configure(a),b&&b())};e.onerror=function(a){console.error("Error loading graph:",
a)}}};n.prototype.onNodeTrace=function(a,b,c){};t.prototype.configure=function(a){a.constructor===Array?(this.id=a[0],this.origin_id=a[1],this.origin_slot=a[2],this.target_id=a[3],this.target_slot=a[4],this.type=a[5]):(this.id=a.id,this.type=a.type,this.origin_id=a.origin_id,this.origin_slot=a.origin_slot,this.target_id=a.target_id,this.target_slot=a.target_slot)};t.prototype.serialize=function(){return[this.id,this.origin_id,this.origin_slot,this.target_id,this.target_slot,this.type]};f.LLink=t;
v.LGraphNode=f.LGraphNode=h;h.prototype._ctor=function(a){this.title=a||"Unnamed";this.size=[f.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={}};h.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.inputs.length;++c){b=this.inputs[c];var d=this.graph?this.graph.links[b.link]:null;this.onConnectionsChange(f.INPUT,
c,!0,d,b)}if(this.outputs)for(c=0;c<this.outputs.length;++c){var e=this.outputs[c];if(e.links)for(b=0;b<e.links.length;++b)d=this.graph?this.graph.links[e.links[b]]:null,this.onConnectionsChange(f.OUTPUT,c,!0,d,e)}}if(this.widgets){for(c=0;c<this.widgets.length;++c)(b=this.widgets[c])&&b.options&&b.options.property&&this.properties[b.options.property]&&(b.value=JSON.parse(JSON.stringify(this.properties[b.options.property])));if(a.widgets_values)for(c=0;c<a.widgets_values.length;++c)this.widgets[c]&&
(this.widgets[c].value=a.widgets_values[c])}if(this.onConfigure)this.onConfigure(a)};h.prototype.serialize=function(){var a={id:this.id,type:this.type,pos:this.pos,size:this.size,flags:f.cloneObject(this.flags),order:this.order,mode:this.mode};if(this.constructor===h&&this.last_serialization)return this.last_serialization;this.inputs&&(a.inputs=this.inputs);if(this.outputs){for(var b=0;b<this.outputs.length;b++)delete this.outputs[b]._data;a.outputs=this.outputs}this.title&&this.title!=this.constructor.title&&
(a.title=this.title);this.properties&&(a.properties=f.cloneObject(this.properties));if(this.widgets&&this.serialize_widgets)for(a.widgets_values=[],b=0;b<this.widgets.length;++b)a.widgets_values[b]=this.widgets[b]?this.widgets[b].value:null;a.type||(a.type=this.constructor.type);this.color&&(a.color=this.color);this.bgcolor&&(a.bgcolor=this.bgcolor);this.boxcolor&&(a.boxcolor=this.boxcolor);this.shape&&(a.shape=this.shape);this.onSerialize&&this.onSerialize(a)&&console.warn("node onSerialize shouldnt return anything, data should be stored in the object pass in the first parameter");
return a};h.prototype.clone=function(){var a=f.createNode(this.type);if(!a)return null;var b=f.cloneObject(this.serialize());if(b.inputs)for(var c=0;c<b.inputs.length;++c)b.inputs[c].link=null;if(b.outputs)for(c=0;c<b.outputs.length;++c)b.outputs[c].links&&(b.outputs[c].links.length=0);delete b.id;a.configure(b);return a};h.prototype.toString=function(){return JSON.stringify(this.serialize())};h.prototype.getTitle=function(){return this.title||this.constructor.title};h.prototype.setProperty=function(a,
b){this.properties||(this.properties={});if(b!==this.properties[a]){var c=this.properties[a];this.properties[a]=b;this.onPropertyChanged&&!1===this.onPropertyChanged(a,b,c)&&(this.properties[a]=c);if(this.widgets)for(c=0;c<this.widgets.length;++c){var d=this.widgets[c];if(d&&d.options.property==a){d.value=b;break}}}};h.prototype.setOutputData=function(a,b){if(this.outputs&&!(-1==a||a>=this.outputs.length)){var c=this.outputs[a];if(c&&(c._data=b,this.outputs[a].links))for(c=0;c<this.outputs[a].links.length;c++){var d=
this.graph.links[this.outputs[a].links[c]];d&&(d.data=b)}}};h.prototype.setOutputDataType=function(a,b){if(this.outputs&&!(-1==a||a>=this.outputs.length)){var c=this.outputs[a];if(c&&(c.type=b,this.outputs[a].links))for(c=0;c<this.outputs[a].links.length;c++)this.graph.links[this.outputs[a].links[c]].type=b}};h.prototype.getInputData=function(a,b){if(this.inputs&&!(a>=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}};h.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};h.prototype.getInputDataByName=function(a,b){a=this.findInputSlot(a);return-1==a?null:this.getInputData(a,
b)};h.prototype.isInputConnected=function(a){return this.inputs?a<this.inputs.length&&null!=this.inputs[a].link:!1};h.prototype.getInputInfo=function(a){return this.inputs?a<this.inputs.length?this.inputs[a]:null:null};h.prototype.getInputLink=function(a){return this.inputs?a<this.inputs.length?this.graph.links[this.inputs[a].link]:null:null};h.prototype.getInputNode=function(a){if(!this.inputs||a>=this.inputs.length)return null;a=this.inputs[a];return a&&null!==a.link?(a=this.graph.links[a.link])?
this.graph.getNodeById(a.origin_id):null:null};h.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<c;++b){var d=this.inputs[b];if(a==d.name&&null!=d.link&&(d=this.graph.links[d.link]))return d.data}return this.properties[a]};h.prototype.getOutputData=function(a){return!this.outputs||a>=this.outputs.length?null:this.outputs[a]._data};h.prototype.getOutputInfo=function(a){return this.outputs?
a<this.outputs.length?this.outputs[a]:null:null};h.prototype.isOutputConnected=function(a){return this.outputs?a<this.outputs.length&&this.outputs[a].links&&this.outputs[a].links.length:!1};h.prototype.isAnyOutputConnected=function(){if(!this.outputs)return!1;for(var a=0;a<this.outputs.length;++a)if(this.outputs[a].links&&this.outputs[a].links.length)return!0;return!1};h.prototype.getOutputNodes=function(a){if(!this.outputs||0==this.outputs.length||a>=this.outputs.length)return null;a=this.outputs[a];
if(!a.links||0==a.links.length)return null;for(var b=[],c=0;c<a.links.length;c++){var d=this.graph.links[a.links[c]];d&&(d=this.graph.getNodeById(d.target_id))&&b.push(d)}return b};h.prototype.trigger=function(a,b){if(this.outputs&&this.outputs.length){this.graph&&(this.graph._last_trigger_time=f.getTime());for(var c=0;c<this.outputs.length;++c){var d=this.outputs[c];!d||d.type!==f.EVENT||a&&d.name!=a||this.triggerSlot(c,b)}}};h.prototype.triggerSlot=function(a,b,c){if(this.outputs&&(a=this.outputs[a])&&
(a=a.links)&&a.length){this.graph&&(this.graph._last_trigger_time=f.getTime());for(var d=0;d<a.length;++d){var e=a[d];if(null==c||c==e){var k=this.graph.links[a[d]];if(k&&(k._last_time=f.getTime(),e=this.graph.getNodeById(k.target_id)))if(k=e.inputs[k.target_slot],e.mode===f.ON_TRIGGER){if(e.onExecute)e.onExecute(b)}else if(e.onAction)e.onAction(k.name,b)}}}};h.prototype.clearTriggeredSlot=function(a,b){if(this.outputs&&(a=this.outputs[a])&&(a=a.links)&&a.length)for(var c=0;c<a.length;++c){var d=
a[c];if(null==b||b==d)if(d=this.graph.links[a[c]])d._last_time=0}};h.prototype.setSize=function(a){this.size=a;if(this.onResize)this.onResize(this.size)};h.prototype.addProperty=function(a,b,c,d){c={name:a,type:c,default_value:b};if(d)for(var e in d)c[e]=d[e];this.properties_info||(this.properties_info=[]);this.properties_info.push(c);this.properties||(this.properties={});this.properties[a]=b;return c};h.prototype.addOutput=function(a,b,c){a={name:a,type:b,links:null};if(c)for(var d in c)a[d]=c[d];
this.outputs||(this.outputs=[]);this.outputs.push(a);if(this.onOutputAdded)this.onOutputAdded(a);this.setSize(this.computeSize());this.setDirtyCanvas(!0,!0);return a};h.prototype.addOutputs=function(a){for(var b=0;b<a.length;++b){var c=a[b],d={name:c[0],type:c[1],link:null};if(a[2])for(var e in c[2])d[e]=c[2][e];this.outputs||(this.outputs=[]);this.outputs.push(d);if(this.onOutputAdded)this.onOutputAdded(d)}this.setSize(this.computeSize());this.setDirtyCanvas(!0,!0)};h.prototype.removeOutput=function(a){this.disconnectOutput(a);
this.outputs.splice(a,1);for(var b=a;b<this.outputs.length;++b)if(this.outputs[b]&&this.outputs[b].links)for(var c=this.outputs[b].links,d=0;d<c.length;++d){var e=this.graph.links[c[d]];e&&--e.origin_slot}this.setSize(this.computeSize());if(this.onOutputRemoved)this.onOutputRemoved(a);this.setDirtyCanvas(!0,!0)};h.prototype.addInput=function(a,b,c){a={name:a,type:b||0,link:null};if(c)for(var d in c)a[d]=c[d];this.inputs||(this.inputs=[]);this.inputs.push(a);this.setSize(this.computeSize());if(this.onInputAdded)this.onInputAdded(a);
this.setDirtyCanvas(!0,!0);return a};h.prototype.addInputs=function(a){for(var b=0;b<a.length;++b){var c=a[b],d={name:c[0],type:c[1],link:null};if(a[2])for(var e in c[2])d[e]=c[2][e];this.inputs||(this.inputs=[]);this.inputs.push(d);if(this.onInputAdded)this.onInputAdded(d)}this.setSize(this.computeSize());this.setDirtyCanvas(!0,!0)};h.prototype.removeInput=function(a){this.disconnectInput(a);for(var b=this.inputs.splice(a,1),c=a;c<this.inputs.length;++c)if(this.inputs[c]){var d=this.graph.links[this.inputs[c].link];
d&&--d.target_slot}this.setSize(this.computeSize());if(this.onInputRemoved)this.onInputRemoved(a,b[0]);this.setDirtyCanvas(!0,!0)};h.prototype.addConnection=function(a,b,c,d){a={name:a,type:b,pos:c,direction:d,links:null};this.connections.push(a);return a};h.prototype.computeSize=function(a){function b(a){return a?d*a.length*.6:0}if(this.constructor.size)return this.constructor.size.concat();var c=Math.max(this.inputs?this.inputs.length:1,this.outputs?this.outputs.length:1);a=a||new Float32Array([0,
0]);c=Math.max(c,1);var d=f.NODE_TEXT_SIZE,e=b(this.title),k=0,m=0;if(this.inputs)for(var l=0,q=this.inputs.length;l<q;++l){var u=this.inputs[l];u=u.label||u.name||"";u=b(u);k<u&&(k=u)}if(this.outputs)for(l=0,q=this.outputs.length;l<q;++l)u=this.outputs[l],u=u.label||u.name||"",u=b(u),m<u&&(m=u);a[0]=Math.max(k+m+10,e);a[0]=Math.max(a[0],f.NODE_WIDTH);this.widgets&&this.widgets.length&&(a[0]=Math.max(a[0],1.5*f.NODE_WIDTH));a[1]=(this.constructor.slot_start_y||0)+c*f.NODE_SLOT_HEIGHT;c=0;if(this.widgets&&
this.widgets.length){l=0;for(q=this.widgets.length;l<q;++l)c=this.widgets[l].computeSize?c+(this.widgets[l].computeSize(a[0])[1]+4):c+(f.NODE_WIDGET_HEIGHT+4);c+=8}a[1]=this.widgets_up?Math.max(a[1],c):null!=this.widgets_start_y?Math.max(a[1],c+this.widgets_start_y):a[1]+c;this.constructor.min_height&&a[1]<this.constructor.min_height&&(a[1]=this.constructor.min_height);a[1]+=6;return a};h.prototype.getPropertyInfo=function(a){var b=null;if(this.properties_info)for(var c=0;c<this.properties_info.length;++c)if(this.properties_info[c].name==
a){b=this.properties_info[c];break}this.constructor["@"+a]&&(b=this.constructor["@"+a]);this.constructor.widgets_info&&this.constructor.widgets_info[a]&&(b=this.constructor.widgets_info[a]);!b&&this.onGetPropertyInfo&&(b=this.onGetPropertyInfo(a));b||(b={});b.type||(b.type=typeof this.properties[a]);"combo"==b.widget&&(b.type="enum");return b};h.prototype.addWidget=function(a,b,c,d,e){this.widgets||(this.widgets=[]);!e&&d&&d.constructor===Object&&(e=d,d=null);e&&e.constructor===String&&(e={property:e});
d&&d.constructor===String&&(e||(e={}),e.property=d,d=null);d&&d.constructor!==Function&&(console.warn("addWidget: callback must be a function"),d=null);b={type:a.toLowerCase(),name:b,value:c,callback:d,options:e||{}};void 0!==b.options.y&&(b.y=b.options.y);d||b.options.callback||b.options.property||console.warn("LiteGraph addWidget(...) without a callback or property assigned");if("combo"==a&&!b.options.values)throw"LiteGraph addWidget('combo',...) requires to pass values in options: { values:['red','blue'] }";
this.widgets.push(b);this.setSize(this.computeSize());return b};h.prototype.addCustomWidget=function(a){this.widgets||(this.widgets=[]);this.widgets.push(a);return a};h.prototype.getBounding=function(a){a=a||new Float32Array(4);a[0]=this.pos[0]-4;a[1]=this.pos[1]-f.NODE_TITLE_HEIGHT;a[2]=this.size[0]+4;a[3]=this.flags.collapsed?f.NODE_TITLE_HEIGHT:this.size[1]+f.NODE_TITLE_HEIGHT;if(this.onBounding)this.onBounding(a);return a};h.prototype.isPointInside=function(a,b,c,d){c=c||0;var e=this.graph&&this.graph.isLive()?
0:f.NODE_TITLE_HEIGHT;d&&(e=0);if(this.flags&&this.flags.collapsed){if(A(a,b,this.pos[0]-c,this.pos[1]-f.NODE_TITLE_HEIGHT-c,(this._collapsed_width||f.NODE_COLLAPSED_WIDTH)+2*c,f.NODE_TITLE_HEIGHT+2*c))return!0}else if(this.pos[0]-4-c<a&&this.pos[0]+this.size[0]+4+c>a&&this.pos[1]-e-c<b&&this.pos[1]+this.size[1]+c>b)return!0;return!1};h.prototype.getSlotInPosition=function(a,b){var c=new Float32Array(2);if(this.inputs)for(var d=0,e=this.inputs.length;d<e;++d){var k=this.inputs[d];this.getConnectionPos(!0,
d,c);if(A(a,b,c[0]-10,c[1]-5,20,10))return{input:k,slot:d,link_pos:c}}if(this.outputs)for(d=0,e=this.outputs.length;d<e;++d)if(k=this.outputs[d],this.getConnectionPos(!1,d,c),A(a,b,c[0]-10,c[1]-5,20,10))return{output:k,slot:d,link_pos:c};return null};h.prototype.findInputSlot=function(a){if(!this.inputs)return-1;for(var b=0,c=this.inputs.length;b<c;++b)if(a==this.inputs[b].name)return b;return-1};h.prototype.findOutputSlot=function(a){if(!this.outputs)return-1;for(var b=0,c=this.outputs.length;b<
c;++b)if(a==this.outputs[b].name)return b;return-1};h.prototype.connect=function(a,b,c){c=c||0;if(!this.graph)return console.log("Connect: Error, node doesn't belong to any graph. Nodes must be added first to a graph before connecting them."),null;if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return f.debug&&console.log("Connect: Error, no slot of name "+a),null}else if(!this.outputs||a>=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)return null;if(!b.inputs||c>=b.inputs.length)return f.debug&&console.log("Connect: Error, slot number not found"),null}var d=!1;null!=b.inputs[c].link&&(this.graph.beforeChange(),b.disconnectInput(c),d=!0);var e=this.outputs[a];if(b.onConnectInput&&
!1===b.onConnectInput(c,e.type,e,this,a))return null;var k=b.inputs[c],m=null;if(!f.isValidConnection(e.type,k.type))return this.setDirtyCanvas(!1,!0),d&&this.graph.connectionChange(this,m),null;d||this.graph.beforeChange();m=new t(++this.graph.last_link_id,k.type,this.id,a,b.id,c);this.graph.links[m.id]=m;null==e.links&&(e.links=[]);e.links.push(m.id);b.inputs[c].link=m.id;this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(f.OUTPUT,a,!0,m,e);if(b.onConnectionsChange)b.onConnectionsChange(f.INPUT,
c,!0,m,k);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,m);return m};h.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<e;d++){var k=c.links[d],m=this.graph.links[k];if(m.target_id==b.id){c.links.splice(d,1);var l=b.inputs[m.target_slot];l.link=null;delete this.graph.links[k];this.graph&&this.graph._version++;if(b.onConnectionsChange)b.onConnectionsChange(f.INPUT,m.target_slot,
!1,m,l);if(this.onConnectionsChange)this.onConnectionsChange(f.OUTPUT,a,!1,m,c);if(this.graph&&this.graph.onNodeConnectionChange)this.graph.onNodeConnectionChange(f.OUTPUT,this,a);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(f.OUTPUT,this,a),this.graph.onNodeConnectionChange(f.INPUT,b,m.target_slot));break}}}else{d=0;for(e=c.links.length;d<e;d++)if(k=c.links[d],m=this.graph.links[k]){b=this.graph.getNodeById(m.target_id);this.graph&&this.graph._version++;if(b){l=
b.inputs[m.target_slot];l.link=null;if(b.onConnectionsChange)b.onConnectionsChange(f.INPUT,m.target_slot,!1,m,l);if(this.graph&&this.graph.onNodeConnectionChange)this.graph.onNodeConnectionChange(f.INPUT,b,m.target_slot)}delete this.graph.links[k];if(this.onConnectionsChange)this.onConnectionsChange(f.OUTPUT,a,!1,m,c);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(f.OUTPUT,this,a),this.graph.onNodeConnectionChange(f.INPUT,b,m.target_slot))}c.links=null}this.setDirtyCanvas(!1,
!0);this.graph.connectionChange(this);return!0};h.prototype.disconnectInput=function(a){if(a.constructor===String){if(a=this.findInputSlot(a),-1==a)return f.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.inputs||a>=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 k=e.outputs[d.origin_slot];if(!k||!k.links||0==k.links.length)return!1;for(var m=0,l=k.links.length;m<l;m++)if(k.links[m]==c){k.links.splice(m,1);break}delete this.graph.links[c];this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(f.INPUT,a,!1,d,b);if(e.onConnectionsChange)e.onConnectionsChange(f.OUTPUT,m,!1,d,k);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(f.OUTPUT,e,m),this.graph.onNodeConnectionChange(f.INPUT,
this,a))}}this.setDirtyCanvas(!1,!0);this.graph&&this.graph.connectionChange(this);return!0};h.prototype.getConnectionPos=function(a,b,c){c=c||new Float32Array(2);var d=0;a&&this.inputs&&(d=this.inputs.length);!a&&this.outputs&&(d=this.outputs.length);var e=.5*f.NODE_SLOT_HEIGHT;if(this.flags.collapsed)return b=this._collapsed_width||f.NODE_COLLAPSED_WIDTH,this.horizontal?(c[0]=this.pos[0]+.5*b,c[1]=a?this.pos[1]-f.NODE_TITLE_HEIGHT:this.pos[1]):(c[0]=a?this.pos[0]:this.pos[0]+b,c[1]=this.pos[1]-
.5*f.NODE_TITLE_HEIGHT),c;if(a&&-1==b)return c[0]=this.pos[0]+.5*f.NODE_TITLE_HEIGHT,c[1]=this.pos[1]+.5*f.NODE_TITLE_HEIGHT,c;if(a&&d>b&&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};h.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)};h.prototype.trace=function(a){this.console||(this.console=[]);this.console.push(a);this.console.length>h.MAX_CONSOLE&&this.console.shift();if(this.graph.onNodeTrace)this.graph.onNodeTrace(this,
a)};h.prototype.setDirtyCanvas=function(a,b){this.graph&&this.graph.sendActionToCanvas("setDirty",[a,b])};h.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};h.prototype.captureInput=function(a){if(this.graph&&this.graph.list_of_graphcanvas)for(var b=this.graph.list_of_graphcanvas,c=0;c<b.length;++c){var d=b[c];if(a||d.node_capturing_input==this)d.node_capturing_input=a?this:null}};h.prototype.collapse=
function(a){this.graph._version++;if(!1!==this.constructor.collapsable||a)this.flags.collapsed=this.flags.collapsed?!1:!0,this.setDirtyCanvas(!0,!0)};h.prototype.pin=function(a){this.graph._version++;this.flags.pinned=void 0===a?!this.flags.pinned:a};h.prototype.localToScreen=function(a,b,c){return[(a+this.pos[0])*c.scale+c.offset[0],(b+this.pos[1])*c.scale+c.offset[1]]};v.LGraphGroup=f.LGraphGroup=r;r.prototype._ctor=function(a){this.title=a||"Group";this.font_size=24;this.color=g.node_colors.pale_blue?
g.node_colors.pale_blue.groupcolor:"#AAA";this._bounding=new Float32Array([10,10,140,80]);this._pos=this._bounding.subarray(0,2);this._size=this._bounding.subarray(2,4);this._nodes=[];this.graph=null;Object.defineProperty(this,"pos",{set:function(a){!a||2>a.length||(this._pos[0]=a[0],this._pos[1]=a[1])},get:function(){return this._pos},enumerable:!0});Object.defineProperty(this,"size",{set:function(a){!a||2>a.length||(this._size[0]=Math.max(140,a[0]),this._size[1]=Math.max(80,a[1]))},get:function(){return this._size},
enumerable:!0})};r.prototype.configure=function(a){this.title=a.title;this._bounding.set(a.bounding);this.color=a.color;this.font=a.font};r.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}};r.prototype.move=function(a,b,c){this._pos[0]+=a;this._pos[1]+=b;if(!c)for(c=0;c<this._nodes.length;++c){var d=this._nodes[c];d.pos[0]+=a;d.pos[1]+=b}};r.prototype.recomputeInsideNodes=
function(){this._nodes.length=0;for(var a=this.graph._nodes,b=new Float32Array(4),c=0;c<a.length;++c){var d=a[c];d.getBounding(b);y(this._bounding,b)&&this._nodes.push(d)}};r.prototype.isPointInside=h.prototype.isPointInside;r.prototype.setDirtyCanvas=h.prototype.setDirtyCanvas;f.DragAndScale=w;w.prototype.bindEvents=function(a){this.last_mouse=new Float32Array(2);this._binded_mouse_callback=this.onMouse.bind(this);f.pointerListenerAdd(a,"down",this._binded_mouse_callback);f.pointerListenerAdd(a,
"move",this._binded_mouse_callback);f.pointerListenerAdd(a,"up",this._binded_mouse_callback);a.addEventListener("mousewheel",this._binded_mouse_callback,!1);a.addEventListener("wheel",this._binded_mouse_callback,!1)};w.prototype.computeVisibleArea=function(a){if(this.element){var b=this.element.width,c=this.element.height,d=-this.offset[0],e=-this.offset[1];a&&(d+=a[0]/this.scale,e+=a[1]/this.scale,b=a[2],c=a[3]);a=d+b/this.scale;c=e+c/this.scale;this.visible_area[0]=d;this.visible_area[1]=e;this.visible_area[2]=
a-d;this.visible_area[3]=c-e}else this.visible_area[0]=this.visible_area[1]=this.visible_area[2]=this.visible_area[3]=0};w.prototype.onMouse=function(a){if(this.enabled){var b=this.element,c=b.getBoundingClientRect(),d=a.clientX-c.left;c=a.clientY-c.top;a.canvasx=d;a.canvasy=c;a.dragging=this.dragging;var e=!this.viewport||this.viewport&&d>=this.viewport[0]&&d<this.viewport[0]+this.viewport[2]&&c>=this.viewport[1]&&c<this.viewport[1]+this.viewport[3],k=!1;this.onmouse&&(k=this.onmouse(a));a.type==
f.pointerevents_method+"down"&&e?(this.dragging=!0,f.pointerListenerRemove(b,"move",this._binded_mouse_callback),f.pointerListenerAdd(document,"move",this._binded_mouse_callback),f.pointerListenerAdd(document,"up",this._binded_mouse_callback)):a.type==f.pointerevents_method+"move"?k||(b=d-this.last_mouse[0],k=c-this.last_mouse[1],this.dragging&&this.mouseDrag(b,k)):a.type==f.pointerevents_method+"up"?(this.dragging=!1,f.pointerListenerRemove(document,"move",this._binded_mouse_callback),f.pointerListenerRemove(document,
"up",this._binded_mouse_callback),f.pointerListenerAdd(b,"move",this._binded_mouse_callback)):!e||"mousewheel"!=a.type&&"wheel"!=a.type&&"DOMMouseScroll"!=a.type||(a.eventType="mousewheel",a.wheel="wheel"==a.type?-a.deltaY:null!=a.wheelDeltaY?a.wheelDeltaY:-60*a.detail,a.delta=a.wheelDelta?a.wheelDelta/40:a.deltaY?-a.deltaY/3:0,this.changeDeltaScale(1+.05*a.delta));this.last_mouse[0]=d;this.last_mouse[1]=c;if(e)return a.preventDefault(),a.stopPropagation(),!1}};w.prototype.toCanvasContext=function(a){a.scale(this.scale,
this.scale);a.translate(this.offset[0],this.offset[1])};w.prototype.convertOffsetToCanvas=function(a){return[(a[0]+this.offset[0])*this.scale,(a[1]+this.offset[1])*this.scale]};w.prototype.convertCanvasToOffset=function(a,b){b=b||[0,0];b[0]=a[0]/this.scale-this.offset[0];b[1]=a[1]/this.scale-this.offset[1];return b};w.prototype.mouseDrag=function(a,b){this.offset[0]+=a/this.scale;this.offset[1]+=b/this.scale;if(this.onredraw)this.onredraw(this)};w.prototype.changeScale=function(a,b){a<this.min_scale?
a=this.min_scale:a>this.max_scale&&(a=this.max_scale);if(a!=this.scale&&this.element){var 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)}};w.prototype.changeDeltaScale=function(a,b){this.changeScale(this.scale*a,b)};w.prototype.reset=function(){this.scale=
1;this.offset[0]=0;this.offset[1]=0};v.LGraphCanvas=f.LGraphCanvas=g;g.DEFAULT_BACKGROUND_IMAGE="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQBJREFUeNrs1rEKwjAUhlETUkj3vP9rdmr1Ysammk2w5wdxuLgcMHyptfawuZX4pJSWZTnfnu/lnIe/jNNxHHGNn//HNbbv+4dr6V+11uF527arU7+u63qfa/bnmh8sWLBgwYJlqRf8MEptXPBXJXa37BSl3ixYsGDBMliwFLyCV/DeLIMFCxYsWLBMwSt4Be/NggXLYMGCBUvBK3iNruC9WbBgwYJlsGApeAWv4L1ZBgsWLFiwYJmCV/AK3psFC5bBggULloJX8BpdwXuzYMGCBctgwVLwCl7Be7MMFixYsGDBsu8FH1FaSmExVfAxBa/gvVmwYMGCZbBg/W4vAQYA5tRF9QYlv/QAAAAASUVORK5CYII=";
g.link_type_colors={"-1":f.EVENT_LINK_COLOR,number:"#AAA",node:"#DCA"};g.gradients={};g.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()};g.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)))};g.prototype.getTopGraph=function(){return this._graph_stack.length?this._graph_stack[0]:this.graph};g.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)};g.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}};g.prototype.getCurrentGraph=function(){return this.graph};g.prototype.setCanvas=function(a,b){if(a&&a.constructor===String&&(a=document.getElementById(a),!a))throw"Error creating LiteGraph canvas: Canvas not found";if(a!==this.canvas&&(!a&&this.canvas&&(b||this.unbindEvents()),this.canvas=a,this.ds.element=a)){a.className+=" lgraphcanvas";a.data=this;a.tabindex="1";this.bgcanvas=null;this.bgcanvas||(this.bgcanvas=document.createElement("canvas"),this.bgcanvas.width=this.canvas.width,
this.bgcanvas.height=this.canvas.height);if(null==a.getContext){if("canvas"!=a.localName)throw"Element supplied for LGraphCanvas must be a <canvas> element, you passed a "+a.localName;throw"This browser doesn't support Canvas";}null==(this.ctx=a.getContext("2d"))&&(a.webgl_enabled||console.warn("This canvas seems to be WebGL, enabling WebGL renderer"),this.enableWebGL());b||this.bindEvents()}};g.prototype._doNothing=function(a){a.preventDefault();return!1};g.prototype._doReturnTrue=function(a){a.preventDefault();
return!0};g.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}};g.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")};
g.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()};g.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};g.prototype.setDirty=function(a,b){a&&(this.dirty_canvas=!0);b&&(this.dirty_bgcanvas=!0)};g.prototype.getCanvasWindow=function(){if(!this.canvas)return window;var a=this.canvas.ownerDocument;
return a.defaultView||a.parentWindow};g.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))};g.prototype.stopRendering=function(){this.is_rendering=!1};g.prototype.blockClick=function(){this.block_click=!0;this.last_mouseclick=0};g.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();g.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[0]+this.viewport[2]&&e>=this.viewport[1]&&e<this.viewport[1]+this.viewport[3];this.options.skip_events||(f.pointerListenerRemove(this.canvas,"move",this._mousemove_callback),f.pointerListenerAdd(b.document,"move",this._mousemove_callback,!0),f.pointerListenerAdd(b.document,"up",
this._mouseup_callback,!0));if(d){var k=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes,5);e=!1;d=300>f.getTime()-this.last_mouseclick&&void 0!==a.isPrimary&&a.isPrimary;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&&void 0!==a.isPrimary&&!a.isPrimary?!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)2==a.which||3!=a.which&&!this.pointer_is_double||this.read_only||this.processContextMenu(k,a);else{a.ctrlKey&&(this.dragging_rectangle=new Float32Array(4),this.dragging_rectangle[0]=a.canvasX,this.dragging_rectangle[1]=a.canvasY,this.dragging_rectangle[2]=1,this.dragging_rectangle[3]=1,e=!0);var m=!1;if(k&&this.allow_interaction&&!e&&!this.read_only){this.live_mode||k.flags.pinned||this.bringToFront(k);if(!this.connecting_node&&
!k.flags.collapsed&&!this.live_mode)if(!e&&!1!==k.resizable&&A(a.canvasX,a.canvasY,k.pos[0]+k.size[0]-5,k.pos[1]+k.size[1]-5,10,10))this.graph.beforeChange(),this.resizing_node=k,this.canvas.style.cursor="se-resize",e=!0;else{if(k.outputs)for(var l=0,q=k.outputs.length;l<q;++l){var u=k.outputs[l],J=k.getConnectionPos(!1,l);if(A(a.canvasX,a.canvasY,J[0]-15,J[1]-10,30,20)){this.connecting_node=k;this.connecting_output=u;this.connecting_pos=k.getConnectionPos(!1,l);this.connecting_slot=l;a.shiftKey&&
k.disconnectOutput(l);if(d){if(k.onOutputDblClick)k.onOutputDblClick(l,a)}else if(k.onOutputClick)k.onOutputClick(l,a);e=!0;break}}if(k.inputs)for(l=0,q=k.inputs.length;l<q;++l)if(u=k.inputs[l],J=k.getConnectionPos(!0,l),A(a.canvasX,a.canvasY,J[0]-15,J[1]-10,30,20)){if(d){if(k.onInputDblClick)k.onInputDblClick(l,a)}else if(k.onInputClick)k.onInputClick(l,a);if(null!==u.link){e=this.graph.links[u.link];k.disconnectInput(l);if(this.allow_reconnect_links||a.shiftKey)this.connecting_node=this.graph._nodes_by_id[e.origin_id],
this.connecting_slot=e.origin_slot,this.connecting_output=this.connecting_node.outputs[this.connecting_slot],this.connecting_pos=this.connecting_node.getConnectionPos(!1,this.connecting_slot);e=this.dirty_bgcanvas=!0}}}if(!e){l=!1;q=[a.canvasX-k.pos[0],a.canvasY-k.pos[1]];if(J=this.processNodeWidgets(k,this.graph_mouse,a))l=!0,this.node_widget=[k,J];if(d&&this.selected_nodes[k.id]){if(k.onDblClick)k.onDblClick(a,q,this);this.processNodeDblClicked(k);l=!0}k.onMouseDown&&k.onMouseDown(a,q,this)?l=!0:
(k.subgraph&&!k.skip_subgraph_button&&!k.flags.collapsed&&q[0]>k.size[0]-f.NODE_TITLE_HEIGHT&&0>q[1]&&(c=this,setTimeout(function(){c.openSubgraph(k.subgraph)},10)),this.live_mode&&(l=m=!0));l||(this.allow_dragnodes&&(this.graph.beforeChange(),this.node_dragged=k),this.selected_nodes[k.id]||this.processNodeSelected(k,a));this.dirty_canvas=!0}}else{if(!this.read_only)for(l=0;l<this.visible_links.length;++l)if(m=this.visible_links[l],q=m._pos,!(!q||a.canvasX<q[0]-4||a.canvasX>q[0]+4||a.canvasY<q[1]-
4||a.canvasY>q[1]+4)){this.showLinkMenu(m,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>B([a.canvasX,a.canvasY],[this.selected_group.pos[0]+this.selected_group.size[0],this.selected_group.pos[1]+this.selected_group.size[1]])*this.ds.scale?this.selected_group_resizing=!0:this.selected_group.recomputeInsideNodes());d&&!this.read_only&&
this.allow_searchbox&&this.showSearchBox(a);m=!0}!e&&m&&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}}}};g.prototype.processMouseMove=
function(a){this.autoresize&&this.resize();this.set_canvas_dirty_on_mouse_event&&(this.dirty_canvas=!0);if(this.graph){g.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&&(e=this._highlight_input||[0,0],!this.isOverNodeBox(d,a.canvasX,a.canvasY))){var k=this.isOverNodeInput(d,a.canvasX,a.canvasY,e);-1!=k&&d.inputs[k]?
f.isValidConnection(this.connecting_output.type,d.inputs[k].type)&&(this._highlight_input=e,this._highlight_input_slot=d.inputs[k]):this._highlight_input_slot=this._highlight_input=null}this.canvas&&(A(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;b<this.visible_links.length;++b){k=this.visible_links[b];var m=k._pos;if(!(!m||a.canvasX<m[0]-4||a.canvasX>m[0]+4||a.canvasY<m[1]-4||a.canvasY>
m[1]+4)){e=k;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}};g.prototype.processMouseUp=function(a){if(void 0!==a.isPrimary&&!a.isPrimary)return!1;this.set_canvas_dirty_on_mouse_event&&
(this.dirty_canvas=!0);if(this.graph){var b=this.getCanvasWindow().document;g.active_canvas=this;this.options.skip_events||(f.pointerListenerRemove(b,"move",this._mousemove_callback,!0),f.pointerListenerAdd(this.canvas,"move",this._mousemove_callback,!0),f.pointerListenerRemove(b,"up",this._mouseup_callback,!0));this.adjustMouseEvent(a);b=f.getTime();a.click_time=b-this.last_mouseclick;this.last_mouse_dragging=!1;this.last_click_position=null;this.block_click&&(this.block_click=!1);if(1==a.which)if(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,this.dragging_rectangle){if(this.graph){b=this.graph._nodes;var c=new Float32Array(4);this.deselectAllNodes();var d=Math.abs(this.dragging_rectangle[2]),e=Math.abs(this.dragging_rectangle[3]),k=0>this.dragging_rectangle[3]?this.dragging_rectangle[1]-e:this.dragging_rectangle[1];this.dragging_rectangle[0]=0>this.dragging_rectangle[2]?this.dragging_rectangle[0]-d:this.dragging_rectangle[0];this.dragging_rectangle[1]=k;this.dragging_rectangle[2]=d;this.dragging_rectangle[3]=e;e=[];for(k=0;k<b.length;++k)d=
b[k],d.getBounding(c),y(this.dragging_rectangle,c)&&e.push(d);e.length&&this.selectNodes(e)}this.dragging_rectangle=null}else if(this.connecting_node){this.dirty_bgcanvas=this.dirty_canvas=!0;if(d=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes))this.connecting_output.type==f.EVENT&&this.isOverNodeBox(d,a.canvasX,a.canvasY)?this.connecting_node.connect(this.connecting_slot,d,f.EVENT):(b=this.isOverNodeInput(d,a.canvasX,a.canvasY),-1!=b?this.connecting_node.connect(this.connecting_slot,
d,b):(b=d.getInputInfo(0),this.connecting_output.type==f.EVENT?this.connecting_node.connect(this.connecting_slot,d,f.EVENT):b&&!b.link&&f.isValidConnection(b.type&&this.connecting_output.type)&&this.connecting_node.connect(this.connecting_slot,d,0)));this.connecting_node=this.connecting_pos=this.connecting_output=null;this.connecting_slot=-1}else if(this.resizing_node)this.dirty_bgcanvas=this.dirty_canvas=!0,this.graph.afterChange(this.resizing_node),this.resizing_node=null;else if(this.node_dragged){(d=
this.node_dragged)&&300>a.click_time&&A(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);void 0!==a.isPrimary&&a.isPrimary&&(this.pointer_is_double=this.pointer_is_down=!1);this.graph.change();a.stopPropagation();a.preventDefault();return!1}};g.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[0]+this.viewport[2]&&d>=this.viewport[1]&&d<this.viewport[1]+this.viewport[3])return c=this.ds.scale,0<b?c*=1.1:0>b&&(c*=1/1.1),this.ds.changeScale(c,[a.clientX,a.clientY]),this.graph.change(),a.preventDefault(),!1}};g.prototype.isOverNodeBox=function(a,b,c){var d=f.NODE_TITLE_HEIGHT;return A(b,c,a.pos[0]+2,a.pos[1]+2-d,d-4,d-4)?!0:!1};g.prototype.isOverNodeInput=function(a,b,c,d){if(a.inputs)for(var e=0,k=a.inputs.length;e<k;++e){var f=a.getConnectionPos(!0,e);if(a.horizontal?A(b,
c,f[0]-5,f[1]-10,10,20):A(b,c,f[0]-10,f[1]-5,40,10))return d&&(d[0]=f[0],d[1]=f[1]),e}return-1};g.prototype.processKey=function(a){if(this.graph){var b=!1;if("input"!=a.target.localName){if("keydown"==a.type){if(32==a.keyCode&&(b=this.dragging_canvas=!0),65==a.keyCode&&a.ctrlKey&&(this.selectNodes(),b=!0),"KeyC"==a.code&&(a.metaKey||a.ctrlKey)&&!a.shiftKey&&this.selected_nodes&&(this.copyToClipboard(),b=!0),"KeyV"!=a.code||!a.metaKey&&!a.ctrlKey||a.shiftKey||this.pasteFromClipboard(),46!=a.keyCode&&
8!=a.keyCode||"input"==a.target.localName||"textarea"==a.target.localName||(this.deleteSelectedNodes(),b=!0),this.selected_nodes)for(var c in this.selected_nodes)if(this.selected_nodes[c].onKeyDown)this.selected_nodes[c].onKeyDown(a)}else if("keyup"==a.type&&(32==a.keyCode&&(this.dragging_canvas=!1),this.selected_nodes))for(c in this.selected_nodes)if(this.selected_nodes[c].onKeyUp)this.selected_nodes[c].onKeyUp(a);this.graph.change();if(b)return a.preventDefault(),a.stopImmediatePropagation(),!1}}};
g.prototype.copyToClipboard=function(){var a={nodes:[],links:[]},b=0,c=[],d;for(d in this.selected_nodes){var e=this.selected_nodes[d];e._relative_id=b;c.push(e);b+=1}for(d=0;d<c.length;++d)if(e=c[d],b=e.clone()){if(a.nodes.push(b.serialize()),e.inputs&&e.inputs.length)for(b=0;b<e.inputs.length;++b){var k=e.inputs[b];if(k&&null!=k.link&&(k=this.graph.links[k.link])){var f=this.graph.getNodeById(k.origin_id);f&&this.selected_nodes[f.id]&&a.links.push([f._relative_id,k.origin_slot,e._relative_id,k.target_slot])}}}else console.warn("node type not found: "+
e.type);localStorage.setItem("litegrapheditor_clipboard",JSON.stringify(a))};g.prototype.pasteFromClipboard=function(){var a=localStorage.getItem("litegrapheditor_clipboard");if(a){this.graph.beforeChange();a=JSON.parse(a);for(var b=[],c=0;c<a.nodes.length;++c){var d=a.nodes[c],e=f.createNode(d.type);e&&(e.configure(d),e.pos[0]+=5,e.pos[1]+=5,this.graph.add(e),b.push(e))}for(c=0;c<a.links.length;++c){d=a.links[c];e=b[d[0]];var k=b[d[2]];e&&k?e.connect(d[1],k,d[3]):console.warn("Warning, nodes missing on pasting")}this.selectNodes(b);
this.graph.afterChange()}};g.prototype.processDrop=function(a){a.preventDefault();this.adjustMouseEvent(a);var b=a.clientX,c=a.clientY;if(!this.viewport||this.viewport&&b>=this.viewport[0]&&b<this.viewport[0]+this.viewport[2]&&c>=this.viewport[1]&&c<this.viewport[1]+this.viewport[3]){b=[a.canvasX,a.canvasY];var d=this.graph?this.graph.getNodeOnPos(b[0],b[1]):null;if(d){if((d.onDropFile||d.onDropData)&&(b=a.dataTransfer.files)&&b.length)for(c=0;c<b.length;c++){var e=a.dataTransfer.files[0],k=e.name;
g.getFileExtension(k);if(d.onDropFile)d.onDropFile(e);if(d.onDropData){var f=new FileReader;f.onload=function(a){d.onDropData(a.target.result,k,e)};var l=e.type.split("/")[0];"text"==l||""==l?f.readAsText(e):"image"==l?f.readAsDataURL(e):f.readAsArrayBuffer(e)}}return d.onDropItem&&d.onDropItem(event)?!0:this.onDropItem?this.onDropItem(event):!1}b=null;this.onDropItem&&(b=this.onDropItem(event));b||this.checkDropItem(a)}};g.prototype.checkDropItem=function(a){if(a.dataTransfer.files.length){var b=
a.dataTransfer.files[0],c=g.getFileExtension(b.name).toLowerCase();if(c=f.node_types_by_file_extension[c]){this.graph.beforeChange();c=f.createNode(c.type);c.pos=[a.canvasX,a.canvasY];this.graph.add(c);if(c.onDropFile)c.onDropFile(b);this.graph.afterChange()}}};g.prototype.processNodeDblClicked=function(a){if(this.onShowNodePanel)this.onShowNodePanel(a);else this.showShowNodePanel(a);if(this.onNodeDblClicked)this.onNodeDblClicked(a);this.setDirty(!0)};g.prototype.processNodeSelected=function(a,b){this.selectNode(a,
b&&b.shiftKey);if(this.onNodeSelected)this.onNodeSelected(a)};g.prototype.selectNode=function(a,b){null==a?this.deselectAllNodes():this.selectNodes([a],b)};g.prototype.selectNodes=function(a,b){b||this.deselectAllNodes();a=a||this.graph._nodes;for(b=0;b<a.length;++b){var c=a[b];if(!c.is_selected){if(!c.is_selected&&c.onSelected)c.onSelected();c.is_selected=!0;this.selected_nodes[c.id]=c;if(c.inputs)for(var d=0;d<c.inputs.length;++d)this.highlighted_links[c.inputs[d].link]=!0;if(c.outputs)for(d=0;d<
c.outputs.length;++d){var e=c.outputs[d];if(e.links)for(var f=0;f<e.links.length;++f)this.highlighted_links[e.links[f]]=!0}}}if(this.onSelectionChange)this.onSelectionChange(this.selected_nodes);this.setDirty(!0)};g.prototype.deselectNode=function(a){if(a.is_selected){if(a.onDeselected)a.onDeselected();a.is_selected=!1;if(this.onNodeDeselected)this.onNodeDeselected(a);if(a.inputs)for(var b=0;b<a.inputs.length;++b)delete this.highlighted_links[a.inputs[b].link];if(a.outputs)for(b=0;b<a.outputs.length;++b){var c=
a.outputs[b];if(c.links)for(var d=0;d<c.links.length;++d)delete this.highlighted_links[c.links[d]]}}};g.prototype.deselectAllNodes=function(){if(this.graph){for(var a=this.graph._nodes,b=0,c=a.length;b<c;++b){var d=a[b];if(d.is_selected){if(d.onDeselected)d.onDeselected();d.is_selected=!1;if(this.onNodeDeselected)this.onNodeDeselected(d)}}this.selected_nodes={};this.current_node=null;this.highlighted_links={};if(this.onSelectionChange)this.onSelectionChange(this.selected_nodes);this.setDirty(!0)}};
g.prototype.deleteSelectedNodes=function(){this.graph.beforeChange();for(var a in this.selected_nodes){var b=this.selected_nodes[a];if(!b.block_delete){if(b.inputs&&b.inputs.length&&b.outputs&&b.outputs.length&&f.isValidConnection(b.inputs[0].type,b.outputs[0].type)&&b.inputs[0].link&&b.outputs[0].links&&b.outputs[0].links.length){var c=b.graph.links[b.inputs[0].link],d=b.graph.links[b.outputs[0].links[0]],e=b.getInputNode(0),k=b.getOutputNodes(0)[0];e&&k&&e.connect(c.origin_slot,k,d.target_slot)}this.graph.remove(b);
if(this.onNodeDeselected)this.onNodeDeselected(b)}}this.selected_nodes={};this.current_node=null;this.highlighted_links={};this.setDirty(!0);this.graph.afterChange()};g.prototype.centerOnNode=function(a){this.ds.offset[0]=-a.pos[0]-.5*a.size[0]+.5*this.canvas.width/this.ds.scale;this.ds.offset[1]=-a.pos[1]-.5*a.size[1]+.5*this.canvas.height/this.ds.scale;this.setDirty(!0,!0)};g.prototype.adjustMouseEvent=function(a){if(this.canvas){var b=this.canvas.getBoundingClientRect();clientX_rel=a.clientX-b.left;
clientY_rel=a.clientY-b.top}else clientX_rel=a.clientX,clientY_rel=a.clientY;a.deltaX=clientX_rel-this.last_mouse_position[0];a.deltaY=clientY_rel-this.last_mouse_position[1];this.last_mouse_position[0]=clientX_rel;this.last_mouse_position[1]=clientY_rel;a.canvasX=clientX_rel/this.ds.scale-this.ds.offset[0];a.canvasY=clientY_rel/this.ds.scale-this.ds.offset[1]};g.prototype.setZoom=function(a,b){this.ds.changeScale(a,b);this.dirty_bgcanvas=this.dirty_canvas=!0};g.prototype.convertOffsetToCanvas=function(a,
b){return this.ds.convertOffsetToCanvas(a,b)};g.prototype.convertCanvasToOffset=function(a,b){return this.ds.convertCanvasToOffset(a,b)};g.prototype.convertEventToCanvasOffset=function(a){var b=this.canvas.getBoundingClientRect();return this.convertCanvasToOffset([a.clientX-b.left,a.clientY-b.top])};g.prototype.bringToFront=function(a){var b=this.graph._nodes.indexOf(a);-1!=b&&(this.graph._nodes.splice(b,1),this.graph._nodes.push(a))};g.prototype.sendToBack=function(a){var b=this.graph._nodes.indexOf(a);
-1!=b&&(this.graph._nodes.splice(b,1),this.graph._nodes.unshift(a))};var L=new Float32Array(4);g.prototype.computeVisibleNodes=function(a,b){b=b||[];b.length=0;a=a||this.graph._nodes;for(var c=0,d=a.length;c<d;++c){var e=a[c];(!this.live_mode||e.onDrawBackground||e.onDrawForeground)&&y(this.visible_area,e.getBounding(L))&&b.push(e)}return b};g.prototype.draw=function(a,b){if(this.canvas&&0!=this.canvas.width&&0!=this.canvas.height){var c=f.getTime();this.render_time=.001*(c-this.last_draw_time);this.last_draw_time=
c;this.graph&&this.ds.computeVisibleArea(this.viewport);(this.dirty_bgcanvas||b||this.always_render_background||this.graph&&this.graph._last_trigger_time&&1E3>c-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}};g.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.length;++d){var e=b[d];a.save();a.translate(e.pos[0],e.pos[1]);this.drawNode(e,a);a.restore()}this.render_execution_order&&this.drawExecutionOrder(a);this.graph.config.links_ontop&&(this.live_mode||this.drawConnections(a));if(null!=this.connecting_pos){a.lineWidth=this.connections_width;switch(this.connecting_output.type){case f.EVENT:b=f.EVENT_LINK_COLOR;break;default:b=f.CONNECTING_LINK_COLOR}this.renderLink(a,this.connecting_pos,[this.graph_mouse[0],this.graph_mouse[1]],
null,!1,null,b,this.connecting_output.dir||(this.connecting_node.horizontal?f.DOWN:f.RIGHT),f.CENTER);a.beginPath();this.connecting_output.type===f.EVENT||this.connecting_output.shape===f.BOX_SHAPE?(a.rect(this.connecting_pos[0]-6+.5,this.connecting_pos[1]-5+.5,14,10),a.fill(),a.beginPath(),a.rect(this.graph_mouse[0]-6+.5,this.graph_mouse[1]-5+.5,14,10)):this.connecting_output.shape===f.ARROW_SHAPE?(a.moveTo(this.connecting_pos[0]+8,this.connecting_pos[1]+.5),a.lineTo(this.connecting_pos[0]-4,this.connecting_pos[1]+
6+.5),a.lineTo(this.connecting_pos[0]-4,this.connecting_pos[1]-6+.5),a.closePath()):(a.arc(this.connecting_pos[0],this.connecting_pos[1],4,0,2*Math.PI),a.fill(),a.beginPath(),a.arc(this.graph_mouse[0],this.graph_mouse[1],4,0,2*Math.PI));a.fill();a.fillStyle="#ffcc00";this._highlight_input&&(a.beginPath(),this._highlight_input_slot.shape===f.ARROW_SHAPE?(a.moveTo(this._highlight_input[0]+8,this._highlight_input[1]+.5),a.lineTo(this._highlight_input[0]-4,this._highlight_input[1]+6+.5),a.lineTo(this._highlight_input[0]-
4,this._highlight_input[1]-6+.5),a.closePath()):a.arc(this._highlight_input[0],this._highlight_input[1],6,0,2*Math.PI),a.fill())}this.dragging_rectangle&&(a.strokeStyle="#FFF",a.strokeRect(this.dragging_rectangle[0],this.dragging_rectangle[1],this.dragging_rectangle[2],this.dragging_rectangle[3]));if(this.over_link_center&&this.render_link_tooltip)this.drawLinkTooltip(a,this.over_link_center);else if(this.onDrawLinkTooltip)this.onDrawLinkTooltip(a,null);if(this.onDrawForeground)this.onDrawForeground(a,
this.visible_rect);a.restore()}this._graph_stack&&this._graph_stack.length&&this.drawSubgraphPanel(a);if(this.onDrawOverlay)this.onDrawOverlay(a);c&&a.restore();a.finish2D&&a.finish2D()}};g.prototype.drawSubgraphPanel=function(a){var b=this.graph,c=b._subgraph_node;c?(this.drawSubgraphPanelLeft(b,c,a),this.drawSubgraphPanelRight(b,c,a)):console.warn("subgraph without subnode")};g.prototype.drawSubgraphPanelLeft=function(a,b,c){var d=b.inputs?b.inputs.length:0,e=Math.floor(1.6*f.NODE_SLOT_HEIGHT);
c.fillStyle="#111";c.globalAlpha=.8;c.beginPath();c.roundRect(10,10,200,(d+1)*e+50,[8]);c.fill();c.globalAlpha=1;c.fillStyle="#888";c.font="14px Arial";c.textAlign="left";c.fillText("Graph Inputs",20,34);if(this.drawButton(180,20,20,20,"X","#151515"))this.closeSubgraph();else{d=50;c.font="14px Arial";if(b.inputs)for(var k=0;k<b.inputs.length;++k){var m=b.inputs[k];if(!m.not_subgraph_input){if(this.drawButton(20,d+2,180,e-2)){var l=b.constructor.input_node_type||"graph/input";this.graph.beforeChange();
var q=f.createNode(l);q?(a.add(q),this.block_click=!1,this.last_click_position=null,this.selectNodes([q]),this.node_dragged=q,this.dragging_canvas=!1,q.setProperty("name",m.name),q.setProperty("type",m.type),this.node_dragged.pos[0]=this.graph_mouse[0]-5,this.node_dragged.pos[1]=this.graph_mouse[1]-5,this.graph.afterChange()):console.error("graph input node not found:",l)}c.fillStyle="#9C9";c.beginPath();c.arc(184,d+.5*e,5,0,2*Math.PI);c.fill();c.fillStyle="#AAA";c.fillText(m.name,30,d+.75*e);c.fillStyle=
"#777";c.fillText(m.type,130,d+.75*e);d+=e}}this.drawButton(20,d+2,180,e-2,"+","#151515","#222")&&this.showSubgraphPropertiesDialog(b)}};g.prototype.drawSubgraphPanelRight=function(a,b,c){var d=b.outputs?b.outputs.length:0,e=this.bgcanvas.width,k=Math.floor(1.6*f.NODE_SLOT_HEIGHT);c.fillStyle="#111";c.globalAlpha=.8;c.beginPath();c.roundRect(e-200-10,10,200,(d+1)*k+50,[8]);c.fill();c.globalAlpha=1;c.fillStyle="#888";c.font="14px Arial";c.textAlign="left";d=c.measureText("Graph Outputs").width;c.fillText("Graph Outputs",
e-d-20,34);if(this.drawButton(e-200,20,20,20,"X","#151515"))this.closeSubgraph();else{d=50;c.font="14px Arial";if(b.outputs)for(var m=0;m<b.outputs.length;++m){var l=b.outputs[m];if(!l.not_subgraph_input){if(this.drawButton(e-200,d+2,180,k-2)){var q=b.constructor.output_node_type||"graph/output";this.graph.beforeChange();var u=f.createNode(q);u?(a.add(u),this.block_click=!1,this.last_click_position=null,this.selectNodes([u]),this.node_dragged=u,this.dragging_canvas=!1,u.setProperty("name",l.name),
u.setProperty("type",l.type),this.node_dragged.pos[0]=this.graph_mouse[0]-5,this.node_dragged.pos[1]=this.graph_mouse[1]-5,this.graph.afterChange()):console.error("graph input node not found:",q)}c.fillStyle="#9C9";c.beginPath();c.arc(e-200+16,d+.5*k,5,0,2*Math.PI);c.fill();c.fillStyle="#AAA";c.fillText(l.name,e-200+30,d+.75*k);c.fillStyle="#777";c.fillText(l.type,e-200+130,d+.75*k);d+=k}}this.drawButton(e-200,d+2,180,k-2,"+","#151515","#222")&&this.showSubgraphPropertiesDialogRight(b)}};g.prototype.drawButton=
function(a,b,c,d,e,k,m,l){var q=this.ctx;k=k||f.NODE_DEFAULT_COLOR;m=m||"#555";l=l||f.NODE_TEXT_COLOR;var u=this.mouse,g=f.isInsideRectangle(u[0],u[1],a,b,c,d);u=(u=this.last_click_position)&&f.isInsideRectangle(u[0],u[1],a,b,c,d);q.fillStyle=g?m:k;u&&(q.fillStyle="#AAA");q.beginPath();q.roundRect(a,b,c,d,[4]);q.fill();null!=e&&e.constructor==String&&(q.fillStyle=l,q.textAlign="center",q.font=(.65*d|0)+"px Arial",q.fillText(e,a+.5*c,b+.75*d),q.textAlign="left");a=u&&!this.block_click;u&&this.blockClick();
return a};g.prototype.isAreaClicked=function(a,b,c,d,e){var k=this.mouse;f.isInsideRectangle(k[0],k[1],a,b,c,d);b=(a=(k=this.last_click_position)&&f.isInsideRectangle(k[0],k[1],a,b,c,d))&&!this.block_click;a&&e&&this.blockClick();return b};g.prototype.renderInfo=function(a,b,c){b=b||10;c=c||this.canvas.height-80;a.save();a.translate(b,c);a.font="10px Arial";a.fillStyle="#888";a.textAlign="left";this.graph?(a.fillText("T: "+this.graph.globaltime.toFixed(2)+"s",5,13),a.fillText("I: "+this.graph.iteration,
5,26),a.fillText("N: "+this.graph._nodes.length+" ["+this.visible_nodes.length+"]",5,39),a.fillText("V: "+this.graph._version,5,52),a.fillText("FPS:"+this.fps.toFixed(2),5,65)):a.fillText("No graph selected",5,13);a.restore()};g.prototype.drawBackCanvas=function(){var a=this.bgcanvas;if(a.width!=this.canvas.width||a.height!=this.canvas.height)a.width=this.canvas.width,a.height=this.canvas.height;this.bgctx||(this.bgctx=this.bgcanvas.getContext("2d"));var b=this.bgctx;b.start&&b.start();var c=this.viewport||
[0,0,b.canvas.width,b.canvas.height];this.clear_background&&b.clearRect(c[0],c[1],c[2],c[3]);if(this._graph_stack&&this._graph_stack.length){b.save();c=this.graph._subgraph_node;b.strokeStyle=c.bgcolor;b.lineWidth=10;b.strokeRect(1,1,a.width-2,a.height-2);b.lineWidth=1;b.font="40px Arial";b.textAlign="center";b.fillStyle=c.bgcolor||"#AAA";for(var d="",e=1;e<this._graph_stack.length;++e)d+=this._graph_stack[e]._subgraph_node.getTitle()+" >> ";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&&.5<this.ds.scale&&!c){b.globalAlpha=this.zoom_modify_alpha?(1-.5/this.ds.scale)*this.editor_alpha:this.editor_alpha;b.imageSmoothingEnabled=b.mozImageSmoothingEnabled=b.imageSmoothingEnabled=!1;if(!this._bg_img||this._bg_img.name!=this.background_image){this._bg_img=new Image;this._bg_img.name=
this.background_image;this._bg_img.src=this.background_image;var f=this;this._bg_img.onload=function(){f.draw(!0,!0)}}c=null;null==this._pattern&&0<this._bg_img.width?(c=b.createPattern(this._bg_img,"repeat"),this._pattern_img=this._bg_img,this._pattern=c):c=this._pattern;c&&(b.fillStyle=c,b.fillRect(this.visible_area[0],this.visible_area[1],this.visible_area[2],this.visible_area[3]),b.fillStyle="transparent");b.globalAlpha=1;b.imageSmoothingEnabled=b.mozImageSmoothingEnabled=b.imageSmoothingEnabled=
!0}this.graph._groups.length&&!this.live_mode&&this.drawGroups(a,b);if(this.onDrawBackground)this.onDrawBackground(b,this.visible_area);this.onBackgroundRender&&(console.error("WARNING! onBackgroundRender deprecated, now is named onDrawBackground "),this.onBackgroundRender=null);this.render_canvas_border&&(b.strokeStyle="#235",b.strokeRect(0,0,a.width,a.height));this.render_connections_shadows?(b.shadowColor="#000",b.shadowOffsetX=0,b.shadowOffsetY=0,b.shadowBlur=6):b.shadowColor="rgba(0,0,0,0)";
this.live_mode||this.drawConnections(b);b.shadowColor="rgba(0,0,0,0)";b.restore()}b.finish&&b.finish();this.dirty_bgcanvas=!1;this.dirty_canvas=!0};var G=new Float32Array(2);g.prototype.drawNode=function(a,b){this.current_node=a;var c=a.color||a.constructor.color||f.NODE_DEFAULT_COLOR,d=a.bgcolor||a.constructor.bgcolor||f.NODE_DEFAULT_BGCOLOR,e=.6>this.ds.scale;if(this.live_mode){if(!a.flags.collapsed&&(b.shadowColor="transparent",a.onDrawForeground))a.onDrawForeground(b,this,this.canvas)}else{var k=
this.editor_alpha;b.globalAlpha=k;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 m=a._shape||f.BOX_SHAPE;G.set(a.size);var l=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*f.NODE_TITLE_HEIGHT),G[0]=a._collapsed_width,G[1]=0)}a.clip_area&&(b.save(),b.beginPath(),m==f.BOX_SHAPE?b.rect(0,0,G[0],G[1]):m==f.ROUND_SHAPE?b.roundRect(0,0,G[0],G[1],[10]):m==f.CIRCLE_SHAPE&&b.arc(.5*G[0],.5*G[1],.5*G[0],0,2*Math.PI),b.clip());a.has_errors&&(d="red");this.drawNodeShape(a,b,G,c,d,a.is_selected,a.mouseOver);b.shadowColor="transparent";if(a.onDrawForeground)a.onDrawForeground(b,this,this.canvas);b.textAlign=l?"center":"left";b.font=this.inner_text_font;d=!e;m=this.connecting_output;
b.lineWidth=1;q=0;var u=new Float32Array(2);if(!a.flags.collapsed){if(a.inputs)for(c=0;c<a.inputs.length;c++){var g=a.inputs[c];b.globalAlpha=k;this.connecting_node&&!f.isValidConnection(g.type,m.type)&&(b.globalAlpha=.4*k);b.fillStyle=null!=g.link?g.color_on||this.default_connection_color.input_on:g.color_off||this.default_connection_color.input_off;var p=a.getConnectionPos(!0,c,u);p[0]-=a.pos[0];p[1]-=a.pos[1];q<p[1]+.5*f.NODE_SLOT_HEIGHT&&(q=p[1]+.5*f.NODE_SLOT_HEIGHT);b.beginPath();g.type===f.EVENT||
g.shape===f.BOX_SHAPE?l?b.rect(p[0]-5+.5,p[1]-8+.5,10,14):b.rect(p[0]-6+.5,p[1]-5+.5,14,10):g.shape===f.ARROW_SHAPE?(b.moveTo(p[0]+8,p[1]+.5),b.lineTo(p[0]-4,p[1]+6+.5),b.lineTo(p[0]-4,p[1]-6+.5),b.closePath()):e?b.rect(p[0]-4,p[1]-4,8,8):b.arc(p[0],p[1],4,0,2*Math.PI);b.fill();if(d){var x=null!=g.label?g.label:g.name;x&&(b.fillStyle=f.NODE_TEXT_COLOR,l||g.dir==f.UP?b.fillText(x,p[0],p[1]-10):b.fillText(x,p[0]+10,p[1]+5))}}this.connecting_node&&(b.globalAlpha=.4*k);b.textAlign=l?"center":"right";
b.strokeStyle="black";if(a.outputs)for(c=0;c<a.outputs.length;c++)if(g=a.outputs[c],p=a.getConnectionPos(!1,c,u),p[0]-=a.pos[0],p[1]-=a.pos[1],q<p[1]+.5*f.NODE_SLOT_HEIGHT&&(q=p[1]+.5*f.NODE_SLOT_HEIGHT),b.fillStyle=g.links&&g.links.length?g.color_on||this.default_connection_color.output_on:g.color_off||this.default_connection_color.output_off,b.beginPath(),g.type===f.EVENT||g.shape===f.BOX_SHAPE?l?b.rect(p[0]-5+.5,p[1]-8+.5,10,14):b.rect(p[0]-6+.5,p[1]-5+.5,14,10):g.shape===f.ARROW_SHAPE?(b.moveTo(p[0]+
8,p[1]+.5),b.lineTo(p[0]-4,p[1]+6+.5),b.lineTo(p[0]-4,p[1]-6+.5),b.closePath()):e?b.rect(p[0]-4,p[1]-4,8,8):b.arc(p[0],p[1],4,0,2*Math.PI),b.fill(),e||b.stroke(),d&&(x=null!=g.label?g.label:g.name))b.fillStyle=f.NODE_TEXT_COLOR,l||g.dir==f.DOWN?b.fillText(x,p[0],p[1]-8):b.fillText(x,p[0]-10,p[1]+5);b.textAlign="left";b.globalAlpha=1;if(a.widgets){g=q;if(l||a.widgets_up)g=2;null!=a.widgets_start_y&&(g=a.widgets_start_y);this.drawNodeWidgets(a,g,b,this.node_widget&&this.node_widget[0]==a?this.node_widget[1]:
null)}}else if(this.render_collapsed_slots){e=k=null;if(a.inputs)for(c=0;c<a.inputs.length;c++)if(g=a.inputs[c],null!=g.link){k=g;break}if(a.outputs)for(c=0;c<a.outputs.length;c++)g=a.outputs[c],g.links&&g.links.length&&(e=g);k&&(k=0,c=-.5*f.NODE_TITLE_HEIGHT,l&&(k=.5*a._collapsed_width,c=-f.NODE_TITLE_HEIGHT),b.fillStyle="#686",b.beginPath(),g.type===f.EVENT||g.shape===f.BOX_SHAPE?b.rect(k-7+.5,c-4,14,8):g.shape===f.ARROW_SHAPE?(b.moveTo(k+8,c),b.lineTo(k+-4,c-4),b.lineTo(k+-4,c+4),b.closePath()):
b.arc(k,c,4,0,2*Math.PI),b.fill());e&&(k=a._collapsed_width,c=-.5*f.NODE_TITLE_HEIGHT,l&&(k=.5*a._collapsed_width,c=0),b.fillStyle="#686",b.strokeStyle="black",b.beginPath(),g.type===f.EVENT||g.shape===f.BOX_SHAPE?b.rect(k-7+.5,c-4,14,8):g.shape===f.ARROW_SHAPE?(b.moveTo(k+6,c),b.lineTo(k-6,c-4),b.lineTo(k-6,c+4),b.closePath()):b.arc(k,c,4,0,2*Math.PI),b.fill())}a.clip_area&&b.restore();b.globalAlpha=1}}};g.prototype.drawLinkTooltip=function(a,b){var c=b._pos;a.fillStyle="black";a.beginPath();a.arc(c[0],
c[1],3,0,2*Math.PI);a.fill();if(null!=b.data&&(!this.onDrawLinkTooltip||1!=this.onDrawLinkTooltip(a,b,this))&&(b=b.data,b=b.constructor===Number?b.toFixed(2):b.constructor===String?'"'+b+'"':b.constructor===Boolean?String(b):b.toToolTip?b.toToolTip():"["+b.constructor.name+"]",null!=b)){b=b.substr(0,30);a.font="14px Courier New";var d=a.measureText(b).width+20;a.shadowColor="black";a.shadowOffsetX=2;a.shadowOffsetY=2;a.shadowBlur=3;a.fillStyle="#454";a.beginPath();a.roundRect(c[0]-.5*d,c[1]-15-24,
d,24,[3]);a.moveTo(c[0]-10,c[1]-15);a.lineTo(c[0]+10,c[1]-15);a.lineTo(c[0],c[1]-5);a.fill();a.shadowColor="transparent";a.textAlign="center";a.fillStyle="#CEC";a.fillText(b,c[0],c[1]-15-24*.3)}};var z=new Float32Array(4);g.prototype.drawNodeShape=function(a,b,c,d,e,k,m){b.strokeStyle=d;b.fillStyle=e;e=f.NODE_TITLE_HEIGHT;var l=.5>this.ds.scale,q=a._shape||a.constructor.shape||f.ROUND_SHAPE,u=a.constructor.title_mode,h=!0;u==f.TRANSPARENT_TITLE||u==f.NO_TITLE?h=!1:u==f.AUTOHIDE_TITLE&&m&&(h=!0);z[0]=
0;z[1]=h?-e:0;z[2]=c[0]+1;z[3]=h?c[1]+e:c[1];m=b.globalAlpha;b.beginPath();q==f.BOX_SHAPE||l?b.fillRect(z[0],z[1],z[2],z[3]):q==f.ROUND_SHAPE||q==f.CARD_SHAPE?b.roundRect(z[0],z[1],z[2],z[3],q==f.CARD_SHAPE?[this.round_radius,this.round_radius,0,0]:[this.round_radius]):q==f.CIRCLE_SHAPE&&b.arc(.5*c[0],.5*c[1],.5*c[0],0,2*Math.PI);b.fill();!a.flags.collapsed&&h&&(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(h||u==f.TRANSPARENT_TITLE){if(a.onDrawTitleBar)a.onDrawTitleBar(b,e,c,this.ds.scale,d);else if(u!=f.TRANSPARENT_TITLE&&(a.constructor.title_color||this.render_title_colored)){h=a.constructor.title_color||d;a.flags.collapsed&&(b.shadowColor=f.DEFAULT_SHADOW_COLOR);if(this.use_gradients){var p=g.gradients[h];p||(p=g.gradients[h]=b.createLinearGradient(0,0,400,0),p.addColorStop(0,h),p.addColorStop(1,"#000"));b.fillStyle=p}else b.fillStyle=h;b.beginPath();q==f.BOX_SHAPE||
l?b.rect(0,-e,c[0]+1,e):(q==f.ROUND_SHAPE||q==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"}if(a.onDrawTitleBox)a.onDrawTitleBox(b,e,c,this.ds.scale);else q==f.ROUND_SHAPE||q==f.CIRCLE_SHAPE||q==f.CARD_SHAPE?(l&&(b.fillStyle="black",b.beginPath(),b.arc(.5*e,-.5*e,6,0,2*Math.PI),b.fill()),b.fillStyle=a.boxcolor||f.NODE_DEFAULT_BOXCOLOR,l?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())):(l&&(b.fillStyle="black",b.fillRect(.5*(e-10)-1,-.5*(e+10)-1,12,12)),b.fillStyle=a.boxcolor||f.NODE_DEFAULT_BOXCOLOR,b.fillRect(.5*(e-10),-.5*(e+10),10,10));b.globalAlpha=m;if(a.onDrawTitleText)a.onDrawTitleText(b,e,c,this.ds.scale,this.title_text_font,k);!l&&(b.font=this.title_text_font,m=String(a.getTitle()))&&(b.fillStyle=k?f.NODE_SELECTED_TITLE_COLOR:a.constructor.title_text_color||this.node_title_color,a.flags.collapsed?(b.textAlign="left",b.measureText(m),b.fillText(m.substr(0,
20),e,f.NODE_TITLE_TEXT_Y-e),b.textAlign="left"):(b.textAlign="left",b.fillText(m,e,f.NODE_TITLE_TEXT_Y-e)));a.flags.collapsed||!a.subgraph||a.skip_subgraph_button||(m=f.NODE_TITLE_HEIGHT,h=a.size[0]-m,p=f.isInsideRectangle(this.graph_mouse[0]-a.pos[0],this.graph_mouse[1]-a.pos[1],h+2,-m+2,m-4,m-4),b.fillStyle=p?"#888":"#555",q==f.BOX_SHAPE||l?b.fillRect(h+2,-m+2,m-4,m-4):(b.beginPath(),b.roundRect(h+2,-m+2,m-4,m-4,[4]),b.fill()),b.fillStyle="#333",b.beginPath(),b.moveTo(h+.2*m,.6*-m),b.lineTo(h+
.8*m,.6*-m),b.lineTo(h+.5*m,.3*-m),b.fill());if(a.onDrawTitle)a.onDrawTitle(b)}if(k){if(a.onBounding)a.onBounding(z);u==f.TRANSPARENT_TITLE&&(z[1]-=e,z[3]+=e);b.lineWidth=1;b.globalAlpha=.8;b.beginPath();q==f.BOX_SHAPE?b.rect(-6+z[0],-6+z[1],12+z[2],12+z[3]):q==f.ROUND_SHAPE||q==f.CARD_SHAPE&&a.flags.collapsed?b.roundRect(-6+z[0],-6+z[1],12+z[2],12+z[3],[2*this.round_radius]):q==f.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]):q==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}};var I=new Float32Array(4),D=new Float32Array(4),H=new Float32Array(2),F=new Float32Array(2);g.prototype.drawConnections=function(a){var b=f.getTime(),c=this.visible_area;I[0]=c[0]-20;I[1]=c[1]-20;I[2]=c[2]+40;I[3]=c[3]+40;a.lineWidth=this.connections_width;a.fillStyle="#AAA";a.strokeStyle="#AAA";a.globalAlpha=this.editor_alpha;c=this.graph._nodes;for(var d=0,e=c.length;d<
e;++d){var k=c[d];if(k.inputs&&k.inputs.length)for(var m=0;m<k.inputs.length;++m){var l=k.inputs[m];if(l&&null!=l.link&&(l=this.graph.links[l.link])){var q=this.graph.getNodeById(l.origin_id);if(null!=q){var u=l.origin_slot;var g=-1==u?[q.pos[0]+10,q.pos[1]+10]:q.getConnectionPos(!1,u,H);var p=k.getConnectionPos(!0,m,F);D[0]=g[0];D[1]=g[1];D[2]=p[0]-g[0];D[3]=p[1]-g[1];0>D[2]&&(D[0]+=D[2],D[2]=Math.abs(D[2]));0>D[3]&&(D[1]+=D[3],D[3]=Math.abs(D[3]));if(y(D,I)){var x=q.outputs[u];u=k.inputs[m];if(x&&
u&&(q=x.dir||(q.horizontal?f.DOWN:f.RIGHT),u=u.dir||(k.horizontal?f.UP:f.LEFT),this.renderLink(a,g,p,l,!1,0,null,q,u),l&&l._last_time&&1E3>b-l._last_time)){x=2-.002*(b-l._last_time);var h=a.globalAlpha;a.globalAlpha=h*x;this.renderLink(a,g,p,l,!0,x,"white",q,u);a.globalAlpha=h}}}}}}a.globalAlpha=1};g.prototype.renderLink=function(a,b,c,d,e,k,m,l,q,u){d&&this.visible_links.push(d);!m&&d&&(m=d.color||g.link_type_colors[d.type]);m||(m=this.default_link_color);null!=d&&this.highlighted_links[d.id]&&(m=
"#FFF");l=l||f.RIGHT;q=q||f.LEFT;var h=B(b,c);this.render_connections_border&&.6<this.ds.scale&&(a.lineWidth=this.connections_width+4);a.lineJoin="round";u=u||1;1<u&&(a.lineWidth=.5);a.beginPath();for(var p=0;p<u;p+=1){var x=5*(p-.5*(u-1));if(this.links_render_mode==f.SPLINE_LINK){a.moveTo(b[0],b[1]+x);var K=0,r=0,n=0,t=0;switch(l){case f.LEFT:K=-.25*h;break;case f.RIGHT:K=.25*h;break;case f.UP:r=-.25*h;break;case f.DOWN:r=.25*h}switch(q){case f.LEFT:n=-.25*h;break;case f.RIGHT:n=.25*h;break;case f.UP:t=
-.25*h;break;case f.DOWN:t=.25*h}a.bezierCurveTo(b[0]+K,b[1]+r+x,c[0]+n,c[1]+t+x,c[0],c[1]+x)}else if(this.links_render_mode==f.LINEAR_LINK){a.moveTo(b[0],b[1]+x);t=n=r=K=0;switch(l){case f.LEFT:K=-1;break;case f.RIGHT:K=1;break;case f.UP:r=-1;break;case f.DOWN:r=1}switch(q){case f.LEFT:n=-1;break;case f.RIGHT:n=1;break;case f.UP:t=-1;break;case f.DOWN:t=1}a.lineTo(b[0]+15*K,b[1]+15*r+x);a.lineTo(c[0]+15*n,c[1]+15*t+x);a.lineTo(c[0],c[1]+x)}else if(this.links_render_mode==f.STRAIGHT_LINK)a.moveTo(b[0],
b[1]),x=b[0],K=b[1],r=c[0],n=c[1],l==f.RIGHT?x+=10:K+=10,q==f.LEFT?r-=10:n-=10,a.lineTo(x,K),a.lineTo(.5*(x+r),K),a.lineTo(.5*(x+r),n),a.lineTo(r,n),a.lineTo(c[0],c[1]);else return}this.render_connections_border&&.6<this.ds.scale&&!e&&(a.strokeStyle="rgba(0,0,0,0.5)",a.stroke());a.lineWidth=this.connections_width;a.fillStyle=a.strokeStyle=m;a.stroke();e=this.computeConnectionPoint(b,c,.5,l,q);d&&d._pos&&(d._pos[0]=e[0],d._pos[1]=e[1]);.6<=this.ds.scale&&this.highquality_render&&q!=f.CENTER&&(this.render_connection_arrows&&
(p=this.computeConnectionPoint(b,c,.25,l,q),h=this.computeConnectionPoint(b,c,.26,l,q),d=this.computeConnectionPoint(b,c,.75,l,q),u=this.computeConnectionPoint(b,c,.76,l,q),this.render_curved_connections?(h=-Math.atan2(h[0]-p[0],h[1]-p[1]),u=-Math.atan2(u[0]-d[0],u[1]-d[1])):u=h=c[1]>b[1]?0:Math.PI,a.save(),a.translate(p[0],p[1]),a.rotate(h),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(u),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(k)for(a.fillStyle=m,p=0;5>p;++p)k=(.001*f.getTime()+.2*p)%1,e=this.computeConnectionPoint(b,c,k,l,q),a.beginPath(),a.arc(e[0],e[1],5,0,2*Math.PI),a.fill()};g.prototype.computeConnectionPoint=function(a,b,c,d,e){d=d||f.RIGHT;e=e||f.LEFT;var k=B(a,b),m=[a[0],a[1]],l=[b[0],b[1]];switch(d){case f.LEFT:m[0]+=-.25*k;break;case f.RIGHT:m[0]+=.25*k;break;case f.UP:m[1]+=-.25*k;break;case f.DOWN:m[1]+=.25*k}switch(e){case f.LEFT:l[0]+=
-.25*k;break;case f.RIGHT:l[0]+=.25*k;break;case f.UP:l[1]+=-.25*k;break;case f.DOWN:l[1]+=.25*k}d=(1-c)*(1-c)*(1-c);e=3*(1-c)*(1-c)*c;k=3*(1-c)*c*c;c*=c*c;return[d*a[0]+e*m[0]+k*l[0]+c*b[0],d*a[1]+e*m[1]+k*l[1]+c*b[1]]};g.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;c<b.length;++c){var d=b[c];a.fillStyle="black";a.fillRect(d.pos[0]-f.NODE_TITLE_HEIGHT,d.pos[1]-f.NODE_TITLE_HEIGHT,
f.NODE_TITLE_HEIGHT,f.NODE_TITLE_HEIGHT);0==d.order&&a.strokeRect(d.pos[0]-f.NODE_TITLE_HEIGHT+.5,d.pos[1]-f.NODE_TITLE_HEIGHT+.5,f.NODE_TITLE_HEIGHT,f.NODE_TITLE_HEIGHT);a.fillStyle="#FFF";a.fillText(d.order,d.pos[0]+-.5*f.NODE_TITLE_HEIGHT,d.pos[1]-6)}a.globalAlpha=1};g.prototype.drawNodeWidgets=function(a,b,c,d){if(!a.widgets||!a.widgets.length)return 0;var e=a.size[0],k=a.widgets;b+=2;var m=f.NODE_WIDGET_HEIGHT,l=.5<this.ds.scale;c.save();c.globalAlpha=this.editor_alpha;for(var q=f.WIDGET_OUTLINE_COLOR,
u=f.WIDGET_BGCOLOR,g=f.WIDGET_TEXT_COLOR,p=f.WIDGET_SECONDARY_TEXT_COLOR,x=0;x<k.length;++x){var h=k[x],r=b;h.y&&(r=h.y);h.last_y=r;c.strokeStyle=q;c.fillStyle="#222";c.textAlign="left";h.disabled&&(c.globalAlpha*=.5);var n=h.width||e;switch(h.type){case "button":h.clicked&&(c.fillStyle="#AAA",h.clicked=!1,this.dirty_canvas=!0);c.fillRect(15,r,n-30,m);l&&!h.disabled&&c.strokeRect(15,r,n-30,m);l&&(c.textAlign="center",c.fillStyle=g,c.fillText(h.name,.5*n,r+.7*m));break;case "toggle":c.textAlign="left";
c.strokeStyle=q;c.fillStyle=u;c.beginPath();l?c.roundRect(15,b,n-30,m,[.5*m]):c.rect(15,b,n-30,m);c.fill();l&&!h.disabled&&c.stroke();c.fillStyle=h.value?"#89A":"#333";c.beginPath();c.arc(n-30,r+.5*m,.36*m,0,2*Math.PI);c.fill();l&&(c.fillStyle=p,null!=h.name&&c.fillText(h.name,30,r+.7*m),c.fillStyle=h.value?g:p,c.textAlign="right",c.fillText(h.value?h.options.on||"true":h.options.off||"false",n-40,r+.7*m));break;case "slider":c.fillStyle=u;c.fillRect(15,r,n-30,m);var t=h.options.max-h.options.min,
w=(h.value-h.options.min)/t;c.fillStyle=d==h?"#89A":"#678";c.fillRect(15,r,w*(n-30),m);l&&!h.disabled&&c.strokeRect(15,r,n-30,m);h.marker&&(t=(h.marker-h.options.min)/t,c.fillStyle="#AA9",c.fillRect(15+t*(n-30),r,2,m));l&&(c.textAlign="center",c.fillStyle=g,c.fillText(h.name+" "+Number(h.value).toFixed(3),.5*n,r+.7*m));break;case "number":case "combo":c.textAlign="left";c.strokeStyle=q;c.fillStyle=u;c.beginPath();l?c.roundRect(15,b,n-30,m,[.5*m]):c.rect(15,b,n-30,m);c.fill();l&&(h.disabled||c.stroke(),
c.fillStyle=g,h.disabled||(c.beginPath(),c.moveTo(31,b+5),c.lineTo(21,b+.5*m),c.lineTo(31,b+m-5),c.fill(),c.beginPath(),c.moveTo(n-15-16,b+5),c.lineTo(n-15-6,b+.5*m),c.lineTo(n-15-16,b+m-5),c.fill()),c.fillStyle=p,c.fillText(h.name,35,r+.7*m),c.fillStyle=g,c.textAlign="right","number"==h.type?c.fillText(Number(h.value).toFixed(void 0!==h.options.precision?h.options.precision:3),n-30-20,r+.7*m):(t=h.value,h.options.values&&(w=h.options.values,w.constructor===Function&&(w=w()),w&&w.constructor!==Array&&
(t=w[h.value])),c.fillText(t,n-30-20,r+.7*m)));break;case "string":case "text":c.textAlign="left";c.strokeStyle=q;c.fillStyle=u;c.beginPath();l?c.roundRect(15,b,n-30,m,[.5*m]):c.rect(15,b,n-30,m);c.fill();l&&(h.disabled||c.stroke(),c.save(),c.beginPath(),c.rect(15,b,n-30,m),c.clip(),c.fillStyle=p,null!=h.name&&c.fillText(h.name,30,r+.7*m),c.fillStyle=g,c.textAlign="right",c.fillText(String(h.value).substr(0,30),n-30,r+.7*m),c.restore());break;default:h.draw&&h.draw(c,a,n,r,m)}b+=(h.computeSize?h.computeSize(n)[1]:
m)+4;c.globalAlpha=this.editor_alpha}c.restore();c.textAlign="left"};g.prototype.processNodeWidgets=function(a,b,c,d){function e(d,e){d.value=e;d.options&&d.options.property&&void 0!==a.properties[d.options.property]&&a.setProperty(d.options.property,e);d.callback&&d.callback(d.value,q,a,b,c)}if(!a.widgets||!a.widgets.length)return null;for(var k=b[0]-a.pos[0],m=b[1]-a.pos[1],l=a.size[0],q=this,u=this.getCanvasWindow(),g=0;g<a.widgets.length;++g){var p=a.widgets[g];if(p&&!p.disabled){var x=p.computeSize?
p.computeSize(l)[1]:f.NODE_WIDGET_HEIGHT,h=p.width||l;if(p==d||!(6>k||k>h-12||m<p.last_y||m>p.last_y+x||void 0===p.last_y)){d=p.value;switch(p.type){case "button":c.type===f.pointerevents_method+"down"&&(p.callback&&setTimeout(function(){p.callback(p,q,a,b,c)},20),this.dirty_canvas=p.clicked=!0);break;case "slider":u=Math.clamp((k-15)/(h-30),0,1);p.value=p.options.min+(p.options.max-p.options.min)*u;p.callback&&setTimeout(function(){e(p,p.value)},20);this.dirty_canvas=!0;break;case "number":case "combo":d=
p.value;if(c.type==f.pointerevents_method+"move"&&"number"==p.type)p.value+=.1*c.deltaX*(p.options.step||1),null!=p.options.min&&p.value<p.options.min&&(p.value=p.options.min),null!=p.options.max&&p.value>p.options.max&&(p.value=p.options.max);else if(c.type==f.pointerevents_method+"down"){var r=p.options.values;r&&r.constructor===Function&&(r=p.options.values(p,a));var n=null;"number"!=p.type&&(n=r.constructor===Array?r:Object.keys(r));k=40>k?-1:k>h-40?1:0;if("number"==p.type)p.value+=.1*k*(p.options.step||
1),null!=p.options.min&&p.value<p.options.min&&(p.value=p.options.min),null!=p.options.max&&p.value>p.options.max&&(p.value=p.options.max);else if(k)u=-1,this.last_mouseclick=0,u=r.constructor===Object?n.indexOf(String(p.value))+k:n.indexOf(p.value)+k,u>=n.length&&(u=n.length-1),0>u&&(u=0),p.value=r.constructor===Array?r[u]:u;else{var t=r!=n?Object.values(r):r;new f.ContextMenu(t,{scale:Math.max(1,this.ds.scale),event:c,className:"dark",callback:function(a,b,c){r!=n&&(a=t.indexOf(a));this.value=a;
e(this,a);q.dirty_canvas=!0;return!1}.bind(p)},u)}}else c.type==f.pointerevents_method+"up"&&"number"==p.type&&(k=40>k?-1:k>h-40?1:0,200>c.click_time&&0==k&&this.prompt("Value",p.value,function(a){this.value=Number(a);e(this,this.value)}.bind(p),c));d!=p.value&&setTimeout(function(){e(this,this.value)}.bind(p),20);this.dirty_canvas=!0;break;case "toggle":c.type==f.pointerevents_method+"down"&&(p.value=!p.value,setTimeout(function(){e(p,p.value)},20));break;case "string":case "text":c.type==f.pointerevents_method+
"down"&&this.prompt("Value",p.value,function(a){this.value=a;e(this,a)}.bind(p),c,p.options?p.options.multiline:!1);break;default:p.mouse&&(this.dirty_canvas=p.mouse(c,[k,m],a))}if(d!=p.value){if(a.onWidgetChanged)a.onWidgetChanged(p.name,p.value,d,p);a.graph._version++}return p}}}return null};g.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(y(this.visible_area,d._bounding)){b.fillStyle=d.color||
"#335";b.strokeStyle=d.color||"#335";var e=d._pos,k=d._size;b.globalAlpha=.25*this.editor_alpha;b.beginPath();b.rect(e[0]+.5,e[1]+.5,k[0],k[1]);b.fill();b.globalAlpha=this.editor_alpha;b.stroke();b.beginPath();b.moveTo(e[0]+k[0],e[1]+k[1]);b.lineTo(e[0]+k[0]-10,e[1]+k[1]);b.lineTo(e[0]+k[0],e[1]+k[1]-10);b.fill();k=d.font_size||f.DEFAULT_GROUP_FONT_SIZE;b.font=k+"px Arial";b.textAlign="left";b.fillText(d.title,e[0]+4,e[1]+k)}}b.restore()}};g.prototype.adjustNodesSize=function(){for(var a=this.graph._nodes,
b=0;b<a.length;++b)a[b].size=a[b].computeSize();this.setDirty(!0,!0)};g.prototype.resize=function(a,b){a||b||(b=this.canvas.parentNode,a=b.offsetWidth,b=b.offsetHeight);if(this.canvas.width!=a||this.canvas.height!=b)this.canvas.width=a,this.canvas.height=b,this.bgcanvas.width=this.canvas.width,this.bgcanvas.height=this.canvas.height,this.setDirty(!0,!0)};g.prototype.switchLiveMode=function(a){if(a){var b=this,c=this.live_mode?1.1:.9;this.live_mode&&(this.live_mode=!1,this.editor_alpha=.1);var d=setInterval(function(){b.editor_alpha*=
c;b.dirty_canvas=!0;b.dirty_bgcanvas=!0;1>c&&.01>b.editor_alpha&&(clearInterval(d),1>c&&(b.live_mode=!0));1<c&&.99<b.editor_alpha&&(clearInterval(d),b.editor_alpha=1)},1)}else this.live_mode=!this.live_mode,this.dirty_bgcanvas=this.dirty_canvas=!0};g.prototype.onNodeSelectionChange=function(a){};g.onGroupAdd=function(a,b,c){a=g.active_canvas;a.getCanvasWindow();b=new f.LGraphGroup;b.pos=a.convertEventToCanvasOffset(c);a.graph.add(b)};g.onMenuAdd=function(a,b,c,d,e){function k(a,b){var d=[];f.getNodeTypesCategories(m.filter||
q.filter).filter(function(b){return b.startsWith(a)}).map(function(b){if(b){b=b.replace(new RegExp("^("+a+")"),"").split("/")[0];var c=""===a?b+"/":a+b+"/";-1!=b.indexOf("::")&&(b=b.split("::")[1]);-1===d.findIndex(function(a){return a.value===c})&&d.push({value:c,content:b,has_submenu:!0,callback:function(a,b,c,d){k(a.value,d)}})}});f.getNodeTypesInCategory(a.slice(0,-1),m.filter||q.filter).map(function(a){a.skip_list||d.push({value:a.type,content:a.title,has_submenu:!1,callback:function(a,b,c,d){b=
d.getFirstEvent();m.graph.beforeChange();if(a=f.createNode(a.value))a.pos=m.convertEventToCanvasOffset(b),m.graph.add(a);e&&e(a);m.graph.afterChange()}})});new f.ContextMenu(d,{event:c,parentMenu:b},l)}var m=g.active_canvas,l=m.getCanvasWindow(),q=m.graph;if(q)return k("",d),!1};g.onMenuCollapseAll=function(){};g.onMenuNodeEdit=function(){};g.showMenuNodeOptionalInputs=function(a,b,c,d,e){if(e){var k=this;a=g.active_canvas.getCanvasWindow();b=e.optional_inputs;e.onGetInputs&&(b=e.onGetInputs());var m=
[];if(b)for(var l=0;l<b.length;l++){var q=b[l];if(q){var u=q[0];q[2]||(q[2]={});q[2].label&&(u=q[2].label);q[2].removable=!0;u={content:u,value:q};q[1]==f.ACTION&&(u.className="event");m.push(u)}else m.push(null)}this.onMenuNodeInputs&&(m=this.onMenuNodeInputs(m));if(m.length)return new f.ContextMenu(m,{event:c,callback:function(a,b,c){e&&(a.callback&&a.callback.call(k,e,a,b,c),a.value&&(e.graph.beforeChange(),e.addInput(a.value[0],a.value[1],a.value[2]),e.setDirtyCanvas(!0,!0),e.graph.afterChange()))},
parentMenu:d,node:e},a),!1;console.log("no input entries")}};g.showMenuNodeOptionalOutputs=function(a,b,c,d,e){function k(a,b,c){if(e&&(a.callback&&a.callback.call(m,e,a,b,c),a.value))if(c=a.value[1],!c||c.constructor!==Object&&c.constructor!==Array)e.graph.beforeChange(),e.addOutput(a.value[0],a.value[1],a.value[2]),e.setDirtyCanvas(!0,!0),e.graph.afterChange();else{a=[];for(var q in c)a.push({content:q,value:c[q]});new f.ContextMenu(a,{event:b,callback:k,parentMenu:d,node:e});return!1}}if(e){var m=
this;a=g.active_canvas.getCanvasWindow();b=e.optional_outputs;e.onGetOutputs&&(b=e.onGetOutputs());var l=[];if(b)for(var q=0;q<b.length;q++){var u=b[q];if(!u)l.push(null);else if(!e.flags||!e.flags.skip_repeated_outputs||-1==e.findOutputSlot(u[0])){var h=u[0];u[2]||(u[2]={});u[2].label&&(h=u[2].label);u[2].removable=!0;h={content:h,value:u};u[1]==f.EVENT&&(h.className="event");l.push(h)}}this.onMenuNodeOutputs&&(l=this.onMenuNodeOutputs(l));if(l.length)return new f.ContextMenu(l,{event:c,callback:k,
parentMenu:d,node:e},a),!1}};g.onShowMenuNodeProperties=function(a,b,c,d,e){if(e&&e.properties){var k=g.active_canvas;b=k.getCanvasWindow();var m=[],l;for(l in e.properties){a=void 0!==e.properties[l]?e.properties[l]:" ";"object"==typeof a&&(a=JSON.stringify(a));var q=e.getPropertyInfo(l);if("enum"==q.type||"combo"==q.type)a=g.getPropertyPrintableValue(a,q.values);a=g.decodeHTML(a);m.push({content:"<span class='property_name'>"+(q.label?q.label:l)+"</span><span class='property_value'>"+a+"</span>",
value:l})}if(m.length)return new f.ContextMenu(m,{event:c,callback:function(a,b,c,d){e&&(b=this.getBoundingClientRect(),k.showEditPropertyValue(e,a.value,{position:[b.left,b.top]}))},parentMenu:d,allow_html:!0,node:e},b),!1}};g.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};g.onResizeNode=function(a,b,c,d,e){if(e){e.size=e.computeSize();if(e.onResize)e.onResize(e.size);e.setDirtyCanvas(!0,!0)}};g.prototype.showLinkMenu=function(a,b){var c=this;console.log(a);
var d=new f.ContextMenu(["Add Node",null,"Delete"],{event:b,title:null!=a.data?a.data.constructor.name:null,callback:function(b,f,m){switch(b){case "Add Node":g.onMenuAdd(null,null,m,d,function(b){console.log("node autoconnect");var d=c.graph.getNodeById(a.origin_id),e=c.graph.getNodeById(a.target_id);b.inputs&&b.inputs.length&&b.outputs&&b.outputs.length&&d.outputs[a.origin_slot].type==b.inputs[0].type&&b.outputs[0].type==e.inputs[0].type&&(d.connect(a.origin_slot,b,0),b.connect(0,e,a.target_slot),
b.pos[0]-=.5*b.size[0])});break;case "Delete":c.graph.removeLink(a.id)}}});return!1};g.onShowPropertyEditor=function(a,b,c,d,e){function f(){var b=q.value;"Number"==a.type?b=Number(b):"Boolean"==a.type&&(b=!!b);e[m]=b;l.parentNode&&l.parentNode.removeChild(l);e.setDirtyCanvas(!0,!0)}var m=a.property||"title";b=e[m];var l=document.createElement("div");l.className="graphdialog";l.innerHTML="<span class='name'></span><input autofocus type='text' class='value'/><button>OK</button>";l.querySelector(".name").innerText=
m;var q=l.querySelector(".value");q&&(q.value=b,q.addEventListener("blur",function(a){this.focus()}),q.addEventListener("keydown",function(a){if(13==a.keyCode||"textarea"==a.target.localName)f(),a.preventDefault(),a.stopPropagation()}));b=g.active_canvas.canvas;c=b.getBoundingClientRect();var u=d=-20;c&&(d-=c.left,u-=c.top);event?(l.style.left=event.clientX+d+"px",l.style.top=event.clientY+u+"px"):(l.style.left=.5*b.width+d+"px",l.style.top=.5*b.height+u+"px");l.querySelector("button").addEventListener("click",
f);b.parentNode.appendChild(l)};g.prototype.prompt=function(a,b,c,d,e){var k=this;a=a||"";var m=!1,l=document.createElement("div");l.className="graphdialog rounded";l.innerHTML=e?"<span class='name'></span> <textarea autofocus class='value'></textarea><button class='rounded'>OK</button>":"<span class='name'></span> <input autofocus type='text' class='value'/><button class='rounded'>OK</button>";l.close=function(){k.prompt_box=null;l.parentNode&&l.parentNode.removeChild(l)};1<this.ds.scale&&(l.style.transform=
"scale("+this.ds.scale+")");f.pointerListenerAdd(l,"leave",function(a){m||l.close()});k.prompt_box&&k.prompt_box.close();k.prompt_box=l;l.querySelector(".name").innerText=a;var q=l.querySelector(".value");q.value=b;q.addEventListener("keydown",function(a){m=!0;if(27==a.keyCode)l.close();else if(13==a.keyCode&&"textarea"!=a.target.localName)c&&c(this.value),l.close();else return;a.preventDefault();a.stopPropagation()});l.querySelector("button").addEventListener("click",function(a){c&&c(q.value);k.setDirty(!0);
l.close()});a=g.active_canvas.canvas;b=a.getBoundingClientRect();var u=e=-20;b&&(e-=b.left,u-=b.top);d?(l.style.left=d.clientX+e+"px",l.style.top=d.clientY+u+"px"):(l.style.left=.5*a.width+e+"px",l.style.top=.5*a.height+u+"px");a.parentNode.appendChild(l);setTimeout(function(){q.focus()},10);return l};g.search_limit=-1;g.prototype.showSearchBox=function(a){function b(b){if(b)if(e.onSearchBoxSelection)e.onSearchBoxSelection(b,a,k);else{var c=f.searchbox_extras[b.toLowerCase()];c&&(b=c.type);k.graph.beforeChange();
if(b=f.createNode(b))b.pos=k.convertEventToCanvasOffset(a),k.graph.add(b);if(c&&c.data){if(c.data.properties)for(var d in c.data.properties)b.addProperty(d,c.data.properties[d]);if(c.data.inputs)for(d in b.inputs=[],c.data.inputs)b.addOutput(c.data.inputs[d][0],c.data.inputs[d][1]);if(c.data.outputs)for(d in b.outputs=[],c.data.outputs)b.addOutput(c.data.outputs[d][0],c.data.outputs[d][1]);c.data.title&&(b.title=c.data.title);c.data.json&&b.configure(c.data.json);k.graph.afterChange()}}q.close()}
function c(a){var b=r;r&&r.classList.remove("selected");r?(r=a?r.nextSibling:r.previousSibling)||(r=b):r=a?h.childNodes[0]:h.childNodes[h.childNodes.length];r&&(r.classList.add("selected"),r.scrollIntoView({block:"end",behavior:"smooth"}))}function d(){function a(a,c){var d=document.createElement("div");p||(p=a);d.innerText=a;d.dataset.type=escape(a);d.className="litegraph lite-search-item";c&&(d.className+=" "+c);d.addEventListener("click",function(a){b(unescape(this.dataset.type))});h.appendChild(d)}
x=null;var c=n.value;p=null;h.innerHTML="";if(c)if(e.onSearchBox){var d=e.onSearchBox(h,c,k);if(d)for(var q=0;q<d.length;++q)a(d[q])}else{d=function(a){var b=f.registered_node_types[a];return m&&b.filter!=m?!1:-1!==a.toLowerCase().indexOf(c)};var l=0;c=c.toLowerCase();var m=k.filter||k.graph.filter;for(q in f.searchbox_extras){var u=f.searchbox_extras[q];if(-1!==u.desc.toLowerCase().indexOf(c)){var r=f.registered_node_types[u.type];if(!r||r.filter==m)if(a(u.desc,"searchbox_extra"),-1!==g.search_limit&&
l++>g.search_limit)break}}u=null;if(Array.prototype.filter)u=Object.keys(f.registered_node_types).filter(d);else for(q in u=[],f.registered_node_types)d(q)&&u.push(q);for(q=0;q<u.length&&!(a(u[q]),-1!==g.search_limit&&l++>g.search_limit);q++);}}var e=this,k=g.active_canvas,m=k.canvas,l=m.ownerDocument||document,q=document.createElement("div");q.className="litegraph litesearchbox graphdialog rounded";q.innerHTML="<span class='name'>Search</span> <input autofocus type='text' class='value rounded'/><div class='helper'></div>";
q.close=function(){e.search_box=null;l.body.focus();l.body.style.overflow="";setTimeout(function(){e.canvas.focus()},20);q.parentNode&&q.parentNode.removeChild(q)};var u=null;1<this.ds.scale&&(q.style.transform="scale("+this.ds.scale+")");f.pointerListenerAdd(q,"enter",function(a){u&&(clearTimeout(u),u=null)});f.pointerListenerAdd(q,"leave",function(a){u=setTimeout(function(){q.close()},500)});e.search_box&&e.search_box.close();e.search_box=q;var h=q.querySelector(".helper"),p=null,x=null,r=null,
n=q.querySelector("input");n&&(n.addEventListener("blur",function(a){this.focus()}),n.addEventListener("keydown",function(a){if(38==a.keyCode)c(!1);else if(40==a.keyCode)c(!0);else if(27==a.keyCode)q.close();else if(13==a.keyCode)r?b(r.innerHTML):p?b(p):q.close();else{x&&clearInterval(x);x=setTimeout(d,10);return}a.preventDefault();a.stopPropagation();a.stopImmediatePropagation();return!0}));l.fullscreenElement?l.fullscreenElement.appendChild(q):(l.body.appendChild(q),l.body.style.overflow="hidden");
m=m.getBoundingClientRect();var t=(a?a.clientY:m.top+.5*m.height)-20;q.style.left=(a?a.clientX:m.left+.5*m.width)-80+"px";q.style.top=t+"px";a.layerY>m.height-200&&(h.style.maxHeight=m.height-a.layerY-20+"px");n.focus();return q};g.prototype.showEditPropertyValue=function(a,b,c){function d(){e(p.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"==m||"object"==m)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();h.close();a.setDirtyCanvas(!0,!0)}if(a&&void 0!==a.properties[b]){c=c||{};var f=a.getPropertyInfo(b),m=f.type,l="";if("string"==m||"number"==m||"array"==m||"object"==m)l="<input autofocus type='text' class='value'/>";else if("enum"!=m&&"combo"!=m||!f.values)if("boolean"==m)l="<input autofocus type='checkbox' class='value' "+(a.properties[b]?"checked":"")+"/>";else{console.warn("unknown type: "+m);
return}else{l="<select autofocus type='text' class='value'>";for(var q in f.values){var g=q;f.values.constructor===Array&&(g=f.values[q]);l+="<option value='"+g+"' "+(g==a.properties[b]?"selected":"")+">"+f.values[q]+"</option>"}l+="</select>"}var h=this.createDialog("<span class='name'>"+(f.label?f.label:b)+"</span>"+l+"<button>OK</button>",c);if("enum"!=m&&"combo"!=m||!f.values)if("boolean"==m)(p=h.querySelector("input"))&&p.addEventListener("click",function(a){e(!!p.checked)});else{if(p=h.querySelector("input"))p.addEventListener("blur",
function(a){this.focus()}),g=void 0!==a.properties[b]?a.properties[b]:"","string"!==m&&(g=JSON.stringify(g)),p.value=g,p.addEventListener("keydown",function(a){13==a.keyCode&&(d(),a.preventDefault(),a.stopPropagation())})}else{var p=h.querySelector("select");p.addEventListener("change",function(a){e(a.target.value)})}h.querySelector("button").addEventListener("click",d);return h}};g.prototype.createDialog=function(a,b){b=b||{};var c=document.createElement("div");c.className="graphdialog";c.innerHTML=
a;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);c.close=function(){this.parentNode&&this.parentNode.removeChild(this)};return c};g.prototype.createPanel=function(a,b){b=b||{};var c=b.window||window,d=document.createElement("div");d.className="litegraph dialog";
d.innerHTML="<div class='dialog-header'><span class='dialog-title'></span></div><div class='dialog-content'></div><div class='dialog-footer'></div>";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="&#10005;",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.footer=d.querySelector(".dialog-footer");d.close=function(){this.parentNode&&this.parentNode.removeChild(this)};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,m,l,q){function e(a,b){console.log("change",a,b);l.callback&&l.callback(a,b);q&&q(a,b)}l=l||{};var k=String(m);a=a.toLowerCase();"number"==a&&(k=m.toFixed(3));var h=document.createElement("div");h.className="property";h.innerHTML="<span class='property_name'></span><span class='property_value'></span>";
h.querySelector(".property_name").innerText=l.label||b;var x=h.querySelector(".property_value");x.innerText=k;h.dataset.property=b;h.dataset.type=l.type||a;h.options=l;h.value=m;if("boolean"==a)h.classList.add("boolean"),m&&h.classList.add("bool-on"),h.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)x.setAttribute("contenteditable",
!0),x.addEventListener("keydown",function(a){"Enter"==a.code&&(a.preventDefault(),this.blur())}),x.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)k=g.getPropertyPrintableValue(m,l.values),x.innerText=k,x.addEventListener("click",function(a){var b=this.parentNode.dataset.property,d=this;new f.ContextMenu(l.values||[],{event:a,className:"dark",callback:function(a,
c,f){d.innerText=a;e(b,a);return!1}},c)});d.content.appendChild(h);return h};return d};g.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+")"}};g.prototype.showShowNodePanel=function(a){window.SELECTED_NODE=a;var b=document.querySelector("#node-panel");b&&b.close();var c=this.getCanvasWindow();b=this.createPanel(a.title||"",{closable:!0,window:c});b.id="node-panel";b.node=
a;b.classList.add("settings");var d=this;(function(){b.content.innerHTML="";b.addHTML("<span class='node_type'>"+a.type+"</span><span class='node_desc'>"+(a.constructor.desc||"")+"</span><span class='separator'></span>");b.addHTML("<h3>Properties</h3>");for(var c in a.properties){var f=a.properties[c],m=a.getPropertyInfo(c);a.onAddPropertyToPanel&&a.onAddPropertyToPanel(c,b)||b.addWidget(m.widget||m.type,c,f,m,function(b,c){d.graph.beforeChange(a);a.setProperty(b,c);d.graph.afterChange();d.dirty_canvas=
!0})}b.addSeparator();if(a.onShowCustomPanelInfo)a.onShowCustomPanelInfo(b);b.addButton("Delete",function(){a.block_delete||(a.graph.remove(a),b.close())}).classList.add("delete")})();this.canvas.parentNode.appendChild(b)};g.prototype.showSubgraphPropertiesDialog=function(a){function b(){d.clear();if(a.inputs)for(var c=0;c<a.inputs.length;++c){var f=a.inputs[c];if(!f.not_subgraph_input){var m=d.addHTML("<button>&#10005;</button> <span class='bullet_icon'></span><span class='name'></span><span class='type'></span>",
"subgraph_property");m.dataset.name=f.name;m.dataset.slot=c;m.querySelector(".name").innerText=f.name;m.querySelector(".type").innerText=f.type;m.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(" + <span class='label'>Name</span><input class='name'/><span class='label'>Type</span><input class='type'></input><button>+</button>","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};g.prototype.showSubgraphPropertiesDialogRight=
function(a){function b(){e.clear();if(a.outputs)for(var c=0;c<a.outputs.length;++c){var d=a.outputs[c];if(!d.not_subgraph_output){var f=e.addHTML("<button>&#10005;</button> <span class='bullet_icon'></span><span class='name'></span><span class='type'></span>","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(" + <span class='label'>Name</span><input class='name'/><span class='label'>Type</span><input class='type'></input><button>+</button>",
"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};g.prototype.checkPanels=function(){if(this.canvas)for(var a=this.canvas.parentNode.querySelectorAll(".litegraph.dialog"),b=0;b<a.length;++b){var c=a[b];c.node&&(c.node.graph&&c.graph==this.graph||c.close())}};g.onMenuNodeCollapse=function(a,b,c,
d,e){e.graph.beforeChange(e);e.collapse();e.graph.afterChange(e)};g.onMenuNodePin=function(a,b,c,d,e){e.pin()};g.onMenuNodeMode=function(a,b,c,d,e){new f.ContextMenu(["Always","On Event","On Trigger","Never"],{event:c,callback:function(a){if(e)switch(a){case "On Event":e.mode=f.ON_EVENT;break;case "On Trigger":e.mode=f.ON_TRIGGER;break;case "Never":e.mode=f.NEVER;break;default:e.mode=f.ALWAYS}},parentMenu:d,node:e});return!1};g.onMenuNodeColors=function(a,b,c,d,e){if(!e)throw"no node for color";b=
[];b.push({value:null,content:"<span style='display: block; padding-left: 4px;'>No color</span>"});for(var k in g.node_colors)a=g.node_colors[k],a={value:k,content:"<span style='display: block; color: #999; padding-left: 4px; border-left: 8px solid "+a.color+"; background-color:"+a.bgcolor+"'>"+k+"</span>"},b.push(a);new f.ContextMenu(b,{event:c,callback:function(a){e&&((a=a.value?g.node_colors[a.value]:null)?e.constructor===f.LGraphGroup?e.color=a.groupcolor:(e.color=a.color,e.bgcolor=a.bgcolor):
(delete e.color,delete e.bgcolor),e.setDirtyCanvas(!0,!0))},parentMenu:d,node:e});return!1};g.onMenuNodeShapes=function(a,b,c,d,e){if(!e)throw"no node passed";new f.ContextMenu(f.VALID_SHAPES,{event:c,callback:function(a){e&&(e.graph.beforeChange(e),e.shape=a,e.graph.afterChange(e),e.setDirtyCanvas(!0))},parentMenu:d,node:e});return!1};g.onMenuNodeRemove=function(a,b,c,d,e){if(!e)throw"no node passed";!1!==e.removable&&(a=e.graph,a.beforeChange(),a.remove(e),a.afterChange(),e.setDirtyCanvas(!0,!0))};
g.onMenuNodeToSubgraph=function(a,b,c,d,e){a=e.graph;if(b=g.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)};g.onMenuNodeClone=function(a,b,c,d,e){0!=e.clonable&&(a=e.clone())&&(a.pos=[e.pos[0]+5,e.pos[1]+5],e.graph.beforeChange(),e.graph.add(a),e.graph.afterChange(),e.setDirtyCanvas(!0,!0))};g.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"}};g.prototype.getCanvasMenuOptions=function(){if(this.getMenuOptions)var a=
this.getMenuOptions();else a=[{content:"Add Node",has_submenu:!0,callback:g.onMenuAdd},{content:"Add Group",callback:g.onGroupAdd}],this._graph_stack&&0<this._graph_stack.length&&a.push(null,{content:"Close subgraph",callback:this.closeSubgraph.bind(this)});if(this.getExtraMenuOptions){var b=this.getExtraMenuOptions(this,a);b&&(a=a.concat(b))}return a};g.prototype.getNodeMenuOptions=function(a){var b=null;b=a.getMenuOptions?a.getMenuOptions(this):[{content:"Inputs",has_submenu:!0,disabled:!0,callback:g.showMenuNodeOptionalInputs},
{content:"Outputs",has_submenu:!0,disabled:!0,callback:g.showMenuNodeOptionalOutputs},null,{content:"Properties",has_submenu:!0,callback:g.onShowMenuNodeProperties},null,{content:"Title",callback:g.onShowPropertyEditor},{content:"Mode",has_submenu:!0,callback:g.onMenuNodeMode},{content:"Resize",callback:function(){if(a.resizable)return g.onResizeNode}},{content:"Collapse",callback:g.onMenuNodeCollapse},{content:"Pin",callback:g.onMenuNodePin},{content:"Colors",has_submenu:!0,callback:g.onMenuNodeColors},
{content:"Shapes",has_submenu:!0,callback:g.onMenuNodeShapes},null];if(a.onGetInputs){var c=a.onGetInputs();c&&c.length&&(b[0].disabled=!1)}a.onGetOutputs&&(c=a.onGetOutputs())&&c.length&&(b[1].disabled=!1);a.getExtraMenuOptions&&(c=a.getExtraMenuOptions(this,b))&&(c.push(null),b=c.concat(b));!1!==a.clonable&&b.push({content:"Clone",callback:g.onMenuNodeClone});b.push(null,{content:"Remove",disabled:!(!1!==a.removable&&!a.block_delete),callback:g.onMenuNodeRemove});if(a.graph&&a.graph.onGetNodeMenuOptions)a.graph.onGetNodeMenuOptions(b,
a);return b};g.prototype.getGroupMenuOptions=function(a){return[{content:"Title",callback:g.onShowPropertyEditor},{content:"Color",has_submenu:!0,callback:g.onMenuNodeColors},{content:"Font size",property:"font_size",type:"Number",callback:g.onShowPropertyEditor},null,{content:"Remove",callback:g.onMenuNodeRemove}]};g.prototype.processContextMenu=function(a,b){var c=this,d=g.active_canvas.getCanvasWindow(),e=null,k={event:b,callback:function(b,d,e){if(b)if("Remove Slot"==b.content)b=b.slot,b.input?
a.removeInput(b.slot):b.output&&a.removeOutput(b.slot);else if("Disconnect Links"==b.content)b=b.slot,b.output?a.disconnectOutput(b.slot):b.input&&a.disconnectInput(b.slot);else if("Rename Slot"==b.content){b=b.slot;var f=b.input?a.getInputInfo(b.slot):a.getOutputInfo(b.slot),q=c.createDialog("<span class='name'>Name</span><input autofocus type='text'/><button>OK</button>",d),k=q.querySelector("input");k&&f&&(k.value=f.label||"");q.querySelector("button").addEventListener("click",function(a){k.value&&
(f&&(f.label=k.value),c.setDirty(!0));q.close()})}},extra:a};a&&(k.title=a.type);var m=null;a&&(m=a.getSlotInPosition(b.canvasX,b.canvasY),g.active_node=a);m?(e=[],a.getSlotMenuOptions?e=a.getSlotMenuOptions(m):(m&&m.output&&m.output.links&&m.output.links.length&&e.push({content:"Disconnect Links",slot:m}),b=m.input||m.output,e.push(b.locked||!b.removable?"Cannot remove":{content:"Remove Slot",slot:m}),e.push(b.nameLocked?"Cannot rename":{content:"Rename Slot",slot:m})),k.title=(m.input?m.input.type:
m.output.type)||"*",m.input&&m.input.type==f.ACTION&&(k.title="Action"),m.output&&m.output.type==f.EVENT&&(k.title="Event")):a?e=this.getNodeMenuOptions(a):(e=this.getCanvasMenuOptions(),(m=this.graph.getGroupOnPos(b.canvasX,b.canvasY))&&e.push(null,{content:"Edit Group",has_submenu:!0,submenu:{title:"Group",extra:m,options:this.getGroupMenuOptions(m)}}));e&&new f.ContextMenu(e,k,d)};"undefined"!=typeof window&&window.CanvasRenderingContext2D&&!window.CanvasRenderingContext2D.prototype.roundRect&&
(window.CanvasRenderingContext2D.prototype.roundRect=function(a,b,c,d,e,f){var k,g;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 q=k=g=f=e[0];else if(2==e.length)q=f=e[0],k=g=e[1];else if(4==e.length)q=e[0],k=e[1],g=e[2],f=e[3];else return;else q=e||0,k=e||0,g=f||0,f=f||0;this.moveTo(a+q,b);this.lineTo(a+c-k,b);this.quadraticCurveTo(a+c,b,a+c,b+k);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-g);this.lineTo(a,b+g);this.quadraticCurveTo(a,b,a+q,b)}});f.compareObjects=function(a,b){for(var c in a)if(a[c]!=b[c])return!1;return!0};f.distance=B;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=A;f.growBounding=function(a,b,c){b<a[0]?a[0]=b:b>a[2]&&(a[2]=b);c<a[1]?a[1]=c:c>a[3]&&(a[3]=c)};f.isInsideBounding=function(a,b){return a[0]<
b[0][0]||a[1]<b[0][1]||a[0]>b[1][0]||a[1]>b[1][1]?!1:!0};f.overlapBounding=y;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};C.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;k.current_submenu&&k.current_submenu.close(a);if(c.callback){var e=c.callback.call(this,b,c,a,k,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,k,c.extra),!0===e&&(d=!1)),b.submenu)){if(!b.submenu.options)throw"ContextMenu submenu needs options";new k.constructor(b.submenu.options,{callback:b.submenu.callback,event:a,parentMenu:k,ignore_item_callbacks:b.submenu.ignore_item_callbacks,
title:b.submenu.title,extra:b.submenu.extra,autoopen:c.autoopen});d=!1}d&&!k.lock&&k.close()}var k=this;c=c||{};var g=document.createElement("div");g.className="litemenu-entry submenu";var l=!1;if(null===b)g.classList.add("separator");else{g.innerHTML=b&&b.title?b.title:a;if(g.value=b)b.disabled&&(l=!0,g.classList.add("disabled")),(b.submenu||b.has_submenu)&&g.classList.add("has_submenu");"function"==typeof b?(g.dataset.value=a,g.onclick_callback=b):g.dataset.value=b;b.className&&(g.className+=" "+
b.className)}this.root.appendChild(g);l||g.addEventListener("click",e);c.autoopen&&f.pointerListenerAdd(g,"enter",d);return g};C.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&&!C.isCursorOverElement(a,this.parentMenu.root)&&C.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)};C.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};C.prototype.getTopMenu=function(){return this.options.parentMenu?this.options.parentMenu.getTopMenu():this};C.prototype.getFirstEvent=function(){return this.options.parentMenu?this.options.parentMenu.getFirstEvent():this.options.event};
C.isCursorOverElement=function(a,b){var c=a.clientX;a=a.clientY;return(b=b.getBoundingClientRect())?a>b.top&&a<b.top+b.height&&c>b.left&&c<b.left+b.width?!0:!1:!1};f.ContextMenu=C;f.closeAllContextMenus=function(a){a=a||window;a=a.document.querySelectorAll(".litecontextmenu");if(a.length){for(var b=[],c=0;c<a.length;c++)b.push(a[c]);for(c=0;c<b.length;c++)b[c].close?b[c].close():b[c].parentNode&&b[c].parentNode.removeChild(b[c])}};f.extendClass=function(a,b){for(var c in b)a.hasOwnProperty(c)||(a[c]=
b[c]);if(b.prototype)for(c in b.prototype)b.prototype.hasOwnProperty(c)&&!a.prototype.hasOwnProperty(c)&&(b.prototype.__lookupGetter__(c)?a.prototype.__defineGetter__(c,b.prototype.__lookupGetter__(c)):a.prototype[c]=b.prototype[c],b.prototype.__lookupSetter__(c)&&a.prototype.__defineSetter__(c,b.prototype.__lookupSetter__(c)))};E.sampleCurve=function(a,b){if(b){for(var c=0;c<b.length-1;++c){var d=b[c],e=b[c+1];if(!(e[0]<a)){b=e[0]-d[0];if(1E-5>Math.abs(b))return d[1];a=(a-d[0])/b;return d[1]*(1-
a)+e[1]*a}}return 0}};E.prototype.draw=function(a,b,c,d,e,f){if(c=this.points){this.size=b;var k=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,k,b),a.fillStyle="#222",a.fillRect(.5*k,0,1,b),a.strokeStyle="#333",a.strokeRect(0,0,k,b));a.strokeStyle=e;f&&(a.globalAlpha=.5);a.beginPath();for(d=0;d<c.length;++d)e=c[d],a.lineTo(e[0]*k,(1-e[1])*b);a.stroke();a.globalAlpha=1;if(!f)for(d=0;d<c.length;++d)e=c[d],a.fillStyle=
this.selected==d?"#FFF":this.nearest==d?"#DDD":"#AAA",a.beginPath(),a.arc(e[0]*k,(1-e[1])*b,2,0,2*Math.PI),a.fill();a.restore()}};E.prototype.onMouseDown=function(a,b){var c=this.points;if(c&&!(0>a[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],h=1E6,q=-1,u=0;u<f;++u){var r=c[u];g[0]=r[0]*d;g[1]=(1-r[1])*e;r=vec2.distance(a,g);r>h||r>b||(q=u,h=r)}return q};f.CurveEditor=E;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)switch(b){case "down":case "up":case "move":case "over":case "out":case "enter":a.addEventListener(f.pointerevents_method+b,c,d);case "leave":case "cancel":case "gotpointercapture":case "lostpointercapture":if("mouse"!=f.pointerevents_method)return a.addEventListener(f.pointerevents_method+
b,c,d);default:return a.addEventListener(b,c,d)}else console.log("cant pointerListenerAdd "+a+", "+b+", "+c)};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":a.removeEventListener(f.pointerevents_method+b,c,d);case "leave":case "cancel":case "gotpointercapture":case "lostpointercapture":if("mouse"!=f.pointerevents_method)return a.removeEventListener(f.pointerevents_method+
b,c,d);default:return a.removeEventListener(b,c,d)}else console.log("cant pointerListenerRemove "+a+", "+b+", "+c)};Math.clamp=function(a,b,c){return b>a?b:c<a?c:a};"undefined"==typeof window||window.requestAnimationFrame||(window.requestAnimationFrame=window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(a){window.setTimeout(a,1E3/60)})})(this);"undefined"!=typeof exports&&(exports.LiteGraph=this.LiteGraph);
(function(v){function n(){this.addOutput("in ms","number");this.addOutput("in sec","number")}function t(){this.size=[140,80];this.properties={enabled:!0};this.enabled=!0;this.subgraph=new l.LGraph;this.subgraph._subgraph_node=this;this.subgraph._is_subgraph=!0;this.subgraph.onTrigger=this.onSubgraphTrigger.bind(this);this.subgraph.onInputAdded=this.onSubgraphNewInput.bind(this);this.subgraph.onInputRenamed=this.onSubgraphRenamedInput.bind(this);this.subgraph.onInputTypeChanged=this.onSubgraphTypeChangeInput.bind(this);
this.subgraph.onInputRemoved=this.onSubgraphRemovedInput.bind(this);this.subgraph.onOutputAdded=this.onSubgraphNewOutput.bind(this);this.subgraph.onOutputRenamed=this.onSubgraphRenamedOutput.bind(this);this.subgraph.onOutputTypeChanged=this.onSubgraphTypeChangeOutput.bind(this);this.subgraph.onOutputRemoved=this.onSubgraphRemovedOutput.bind(this)}function h(){this.addOutput("","number");this.name_in_graph="";this.properties={name:"",type:"number",value:0};var a=this;this.name_widget=this.addWidget("text",
"Name",this.properties.name,function(b){b&&a.setProperty("name",b)});this.type_widget=this.addWidget("text","Type",this.properties.type,function(b){a.setProperty("type",b)});this.value_widget=this.addWidget("number","Value",this.properties.value,function(b){a.setProperty("value",b)});this.widgets_up=!0;this.size=[180,90]}function r(){this.addInput("","");this.name_in_graph="";this.properties={};this.name_widget=this.addWidget("text","Name",this.properties.name,"name");this.type_widget=this.addWidget("text",
"Type",this.properties.type,"type");this.widgets_up=!0;this.size=[180,60]}function w(){this.addOutput("value","number");this.addProperty("value",1);this.widget=this.addWidget("number","value",1,"value");this.widgets_up=!0;this.size=[180,30]}function g(){this.addOutput("","boolean");this.addProperty("value",!0);this.widget=this.addWidget("toggle","value",!0,"value");this.widgets_up=!0;this.size=[140,30]}function B(){this.addOutput("","string");this.addProperty("value","");this.widget=this.addWidget("text",
"value","","value");this.widgets_up=!0;this.size=[180,30]}function A(){this.addOutput("obj","object");this.size=[120,30];this._object={}}function y(){this.addInput("url","");this.addOutput("","");this.addProperty("url","");this.addProperty("type","text");this.widget=this.addWidget("text","url","","url");this._data=null}function C(){this.addOutput("","");this.addProperty("value","");this.widget=this.addWidget("text","json","","value");this.widgets_up=!0;this.size=[140,30];this._value=null}function E(){this._value=
[];this.addInput("","");this.addOutput("","array");this.addOutput("length","number");this.addProperty("value","[]");this.widget=this.addWidget("text","array",this.properties.value,"value");this.widgets_up=!0;this.size=[140,50]}function f(){this.addInput("arr","array");this.addInput("value","");this.addOutput("arr","array");this.properties={index:0};this.widget=this.addWidget("number","i",this.properties.index,"index")}function L(){this.addInput("array","array,table,string");this.addInput("index",
"number");this.addOutput("value","");this.addProperty("index",0)}function G(){this.addInput("table","table");this.addInput("row","number");this.addInput("col","number");this.addOutput("value","");this.addProperty("row",0);this.addProperty("column",0)}function z(){this.addInput("obj","");this.addOutput("","");this.addProperty("value","");this.widget=this.addWidget("text","prop.","",this.setValue.bind(this));this.widgets_up=!0;this.size=[140,30];this._value=null}function I(){this.addInput("obj","");
this.addOutput("keys","array");this.size=[140,30]}function D(){this.addInput("obj","");this.addInput("value","");this.addOutput("obj","");this.properties={property:""};this.name_widget=this.addWidget("text","prop.",this.properties.property,"property")}function H(){this.addInput("A","");this.addInput("B","");this.addOutput("","");this._result={};var a=this;this.addWidget("button","clear","",function(){a._result={}});this.size=this.computeSize()}function F(){this.size=[60,30];this.addInput("in");this.addOutput("out");
this.properties={varname:"myname",container:F.LITEGRAPH};this.value=null}function a(a){return a&&null!=a.length?Number(a.length):0}function a(a){return a&&null!=a.length?Number(a.length):0}function b(){this.size=[60,30];this.addInput("data",0);this.addInput("download",l.ACTION);this.properties={filename:"data.json"};this.value=null;var a=this;this.addWidget("button","Download","",function(b){a.value&&a.downloadAsFile()})}function c(){this.size=[60,30];this.addInput("value",0,{label:""});this.value=
0}function d(){this.addInput("in",0);this.addOutput("out",0);this.size=[40,30]}function e(){this.mode=l.ON_EVENT;this.size=[80,30];this.addProperty("msg","");this.addInput("log",l.EVENT);this.addInput("msg",0)}function k(){this.mode=l.ON_EVENT;this.addProperty("msg","");this.addInput("",l.EVENT);this.widget=this.addWidget("text","Text","","msg");this.widgets_up=!0;this.size=[200,30]}function m(){this.size=[60,30];this.addProperty("onExecute","return A;");this.addInput("A","");this.addInput("B","");
this.addOutput("out","");this._func=null;this.data={}}var l=v.LiteGraph;n.title="Time";n.desc="Time";n.prototype.onExecute=function(){this.setOutputData(0,1E3*this.graph.globaltime);this.setOutputData(1,this.graph.globaltime)};l.registerNodeType("basic/time",n);t.title="Subgraph";t.desc="Graph inside a node";t.title_color="#334";t.prototype.onGetInputs=function(){return[["enabled","boolean"]]};t.prototype.onDblClick=function(a,b,c){var d=this;setTimeout(function(){c.openSubgraph(d.subgraph)},10)};
t.prototype.onAction=function(a,b){this.subgraph.onAction(a,b)};t.prototype.onExecute=function(){if(this.enabled=this.getInputOrProperty("enabled")){if(this.inputs)for(var a=0;a<this.inputs.length;a++){var b=this.inputs[a],c=this.getInputData(a);this.subgraph.setInputData(b.name,c)}this.subgraph.runStep();if(this.outputs)for(a=0;a<this.outputs.length;a++)c=this.subgraph.getOutputData(this.outputs[a].name),this.setOutputData(a,c)}};t.prototype.sendEventToAllNodes=function(a,b,c){this.enabled&&this.subgraph.sendEventToAllNodes(a,
b,c)};t.prototype.onDrawBackground=function(a,b,c,d){this.flags.collapsed||(b=this.size[1]-l.NODE_TITLE_HEIGHT+.5,c=l.isInsideRectangle(d[0],d[1],this.pos[0],this.pos[1]+b,this.size[0],l.NODE_TITLE_HEIGHT),d=l.isInsideRectangle(d[0],d[1],this.pos[0],this.pos[1]+b,this.size[0]/2,l.NODE_TITLE_HEIGHT),a.fillStyle=c?"#555":"#222",a.beginPath(),this._shape==l.BOX_SHAPE?d?a.rect(0,b,this.size[0]/2+1,l.NODE_TITLE_HEIGHT):a.rect(this.size[0]/2,b,this.size[0]/2+1,l.NODE_TITLE_HEIGHT):d?a.roundRect(0,b,this.size[0]/
2+1,l.NODE_TITLE_HEIGHT,[0,0,8,8]):a.roundRect(this.size[0]/2,b,this.size[0]/2+1,l.NODE_TITLE_HEIGHT,[0,0,8,8]),c?a.fill():a.fillRect(0,b,this.size[0]+1,l.NODE_TITLE_HEIGHT),a.textAlign="center",a.font="24px Arial",a.fillStyle=c?"#DDD":"#999",a.fillText("+",.25*this.size[0],b+24),a.fillText("+",.75*this.size[0],b+24))};t.prototype.onMouseDown=function(a,b,c){a=this.size[1]-l.NODE_TITLE_HEIGHT+.5;console.log(0);b[1]>a&&(b[0]<this.size[0]/2?(console.log(1),c.showSubgraphPropertiesDialog(this)):(console.log(2),
c.showSubgraphPropertiesDialogRight(this)))};t.prototype.computeSize=function(){return[200,Math.max(this.inputs?this.inputs.length:0,this.outputs?this.outputs.length:0)*l.NODE_SLOT_HEIGHT+l.NODE_TITLE_HEIGHT]};t.prototype.onSubgraphTrigger=function(a,b){a=this.findOutputSlot(a);-1!=a&&this.triggerSlot(a)};t.prototype.onSubgraphNewInput=function(a,b){-1==this.findInputSlot(a)&&this.addInput(a,b)};t.prototype.onSubgraphRenamedInput=function(a,b){a=this.findInputSlot(a);-1!=a&&(this.getInputInfo(a).name=
b)};t.prototype.onSubgraphTypeChangeInput=function(a,b){a=this.findInputSlot(a);-1!=a&&(this.getInputInfo(a).type=b)};t.prototype.onSubgraphRemovedInput=function(a){a=this.findInputSlot(a);-1!=a&&this.removeInput(a)};t.prototype.onSubgraphNewOutput=function(a,b){-1==this.findOutputSlot(a)&&this.addOutput(a,b)};t.prototype.onSubgraphRenamedOutput=function(a,b){a=this.findOutputSlot(a);-1!=a&&(this.getOutputInfo(a).name=b)};t.prototype.onSubgraphTypeChangeOutput=function(a,b){a=this.findOutputSlot(a);
-1!=a&&(this.getOutputInfo(a).type=b)};t.prototype.onSubgraphRemovedOutput=function(a){a=this.findInputSlot(a);-1!=a&&this.removeOutput(a)};t.prototype.getExtraMenuOptions=function(a){var b=this;return[{content:"Open",callback:function(){a.openSubgraph(b.subgraph)}}]};t.prototype.onResize=function(a){a[1]+=20};t.prototype.serialize=function(){var a=l.LGraphNode.prototype.serialize.call(this);a.subgraph=this.subgraph.serialize();return a};t.prototype.clone=function(){var a=l.createNode(this.type),
b=this.serialize();delete b.id;delete b.inputs;delete b.outputs;a.configure(b);return a};t.prototype.buildFromNodes=function(a){for(var b={},c=0;c<a.length;++c){var d=a[c];b[d.id]=d}for(c=0;c<a.length;++c){d=a[c];if(d.inputs)for(var e=0;e<d.inputs.length;++e){var f=d.inputs[e];if(f&&f.link){var k=d.graph.links[f.link];k&&(b[k.origin_id]||this.subgraph.addInput(f.name,k.type))}}if(d.outputs)for(e=0;e<d.outputs.length;++e)if((f=d.outputs[e])&&f.links&&f.links.length)for(var g=0;g<f.links.length&&(!(k=
d.graph.links[f.links[g]])||b[k.target_id]);++g);}};l.Subgraph=t;l.registerNodeType("graph/subgraph",t);h.title="Input";h.desc="Input of the graph";h.prototype.onConfigure=function(){this.updateType()};h.prototype.updateType=function(){var a=this.properties.type;this.type_widget.value=a;this.outputs[0].type!=a&&(l.isValidConnection(this.outputs[0].type,a)||this.disconnectOutput(0),this.outputs[0].type=a);"number"==a?(this.value_widget.type="number",this.value_widget.value=0):"boolean"==a?(this.value_widget.type=
"toggle",this.value_widget.value=!0):"string"==a?(this.value_widget.type="text",this.value_widget.value=""):(this.value_widget.type=null,this.value_widget.value=null);this.properties.value=this.value_widget.value;this.graph&&this.name_in_graph&&this.graph.changeInputType(this.name_in_graph,a)};h.prototype.onPropertyChanged=function(a,b){if("name"==a){if(""==b||b==this.name_in_graph||"enabled"==b)return!1;this.graph&&(this.name_in_graph?this.graph.renameInput(this.name_in_graph,b):this.graph.addInput(b,
this.properties.type));this.name_in_graph=this.name_widget.value=b}else"type"==a&&this.updateType()};h.prototype.getTitle=function(){return this.flags.collapsed?this.properties.name:this.title};h.prototype.onAction=function(a,b){this.properties.type==l.EVENT&&this.triggerSlot(0,b)};h.prototype.onExecute=function(){var a=this.graph.inputs[this.properties.name];a?this.setOutputData(0,void 0!==a.value?a.value:this.properties.value):this.setOutputData(0,this.properties.value)};h.prototype.onRemoved=function(){this.name_in_graph&&
this.graph.removeInput(this.name_in_graph)};l.GraphInput=h;l.registerNodeType("graph/input",h);r.title="Output";r.desc="Output of the graph";r.prototype.onPropertyChanged=function(a,b){if("name"==a){if(""==b||b==this.name_in_graph||"enabled"==b)return!1;this.graph&&(this.name_in_graph?this.graph.renameOutput(this.name_in_graph,b):this.graph.addOutput(b,this.properties.type));this.name_in_graph=this.name_widget.value=b}else"type"==a&&this.updateType()};r.prototype.updateType=function(){var a=this.properties.type;
this.type_widget&&(this.type_widget.value=a);this.inputs[0].type!=a&&(l.isValidConnection(this.inputs[0].type,a)||this.disconnectInput(0),this.inputs[0].type=a);this.graph&&this.name_in_graph&&this.graph.changeOutputType(this.name_in_graph,a)};r.prototype.onExecute=function(){this._value=this.getInputData(0);this.graph.setOutputData(this.properties.name,this._value)};r.prototype.onAction=function(a,b){this.properties.type==l.ACTION&&this.graph.trigger(this.properties.name,b)};r.prototype.onRemoved=
function(){this.name_in_graph&&this.graph.removeOutput(this.name_in_graph)};r.prototype.getTitle=function(){return this.flags.collapsed?this.properties.name:this.title};l.GraphOutput=r;l.registerNodeType("graph/output",r);w.title="Const Number";w.desc="Constant number";w.prototype.onExecute=function(){this.setOutputData(0,parseFloat(this.properties.value))};w.prototype.getTitle=function(){return this.flags.collapsed?this.properties.value:this.title};w.prototype.setValue=function(a){this.setProperty("value",
a)};w.prototype.onDrawBackground=function(a){this.outputs[0].label=this.properties.value.toFixed(3)};l.registerNodeType("basic/const",w);g.title="Const Boolean";g.desc="Constant boolean";g.prototype.getTitle=w.prototype.getTitle;g.prototype.onExecute=function(){this.setOutputData(0,this.properties.value)};g.prototype.setValue=w.prototype.setValue;g.prototype.onGetInputs=function(){return[["toggle",l.ACTION]]};g.prototype.onAction=function(a){this.setValue(!this.properties.value)};l.registerNodeType("basic/boolean",
g);B.title="Const String";B.desc="Constant string";B.prototype.getTitle=w.prototype.getTitle;B.prototype.onExecute=function(){this.setOutputData(0,this.properties.value)};B.prototype.setValue=w.prototype.setValue;B.prototype.onDropFile=function(a){var b=this,c=new FileReader;c.onload=function(a){b.setProperty("value",a.target.result)};c.readAsText(a)};l.registerNodeType("basic/string",B);A.title="Const Object";A.desc="Constant Object";A.prototype.onExecute=function(){this.setOutputData(0,this._object)};
l.registerNodeType("basic/object",A);y.title="Const File";y.desc="Fetches a file from an url";y["@type"]={type:"enum",values:["text","arraybuffer","blob","json"]};y.prototype.onPropertyChanged=function(a,b){"url"==a&&(null==b||""==b?this._data=null:this.fetchFile(b))};y.prototype.onExecute=function(){var a=this.getInputData(0)||this.properties.url;!a||a==this._url&&this._type==this.properties.type||this.fetchFile(a);this.setOutputData(0,this._data)};y.prototype.setValue=w.prototype.setValue;y.prototype.fetchFile=
function(a){var b=this;a&&a.constructor===String?(this._url=a,this._type=this.properties.type,"http"==a.substr(0,4)&&l.proxy&&(a=l.proxy+a.substr(a.indexOf(":")+3)),fetch(a).then(function(a){if(!a.ok)throw Error("File not found");if("arraybuffer"==b.properties.type)return a.arrayBuffer();if("text"==b.properties.type)return a.text();if("json"==b.properties.type)return a.json();if("blob"==b.properties.type)return a.blob()}).then(function(a){b._data=a;b.boxcolor="#AEA"}).catch(function(c){b._data=null;
b.boxcolor="red";console.error("error fetching file:",a)})):(b._data=null,b.boxcolor=null)};y.prototype.onDropFile=function(a){var b=this;this._url=a.name;this._type=this.properties.type;this.properties.url=a.name;var c=new FileReader;c.onload=function(a){b.boxcolor="#AEA";a=a.target.result;"json"==b.properties.type&&(a=JSON.parse(a));b._data=a};if("arraybuffer"==b.properties.type)c.readAsArrayBuffer(a);else if("text"==b.properties.type||"json"==b.properties.type)c.readAsText(a);else if("blob"==b.properties.type)return c.readAsBinaryString(a)};
l.registerNodeType("basic/file",y);C.title="Const Data";C.desc="Constant Data";C.prototype.onPropertyChanged=function(a,b){this.widget.value=b;if(null!=b&&""!=b)try{this._value=JSON.parse(b),this.boxcolor="#AEA"}catch(J){this.boxcolor="red"}};C.prototype.onExecute=function(){this.setOutputData(0,this._value)};C.prototype.setValue=w.prototype.setValue;l.registerNodeType("basic/data",C);E.title="Const Array";E.desc="Constant Array";E.prototype.onPropertyChanged=function(a,b){this.widget.value=b;if(null!=
b&&""!=b)try{this._value="["!=b[0]?JSON.parse("["+b+"]"):JSON.parse(b),this.boxcolor="#AEA"}catch(J){this.boxcolor="red"}};E.prototype.onExecute=function(){var a=this.getInputData(0);if(a&&a.length){this._value||(this._value=[]);this._value.length=a.length;for(var b=0;b<a.length;++b)this._value[b]=a[b]}this.setOutputData(0,this._value);this.setOutputData(1,this._value?this._value.length||0:0)};E.prototype.setValue=w.prototype.setValue;l.registerNodeType("basic/array",E);f.title="Set Array";f.desc=
"Sets index of array";f.prototype.onExecute=function(){var a=this.getInputData(0);if(a){var b=this.getInputData(1);void 0!==b&&(this.properties.index&&(a[Math.floor(this.properties.index)]=b),this.setOutputData(0,a))}};l.registerNodeType("basic/set_array",f);L.title="Array[i]";L.desc="Returns an element from an array";L.prototype.onExecute=function(){var a=this.getInputData(0),b=this.getInputData(1);null==b&&(b=this.properties.index);null!=a&&null!=b&&this.setOutputData(0,a[Math.floor(Number(b))])};
l.registerNodeType("basic/array[]",L);G.title="Table[row][col]";G.desc="Returns an element from a table";G.prototype.onExecute=function(){var a=this.getInputData(0),b=this.getInputData(1),c=this.getInputData(2);null==b&&(b=this.properties.row);null==c&&(c=this.properties.column);null!=a&&null!=b&&null!=c&&((b=a[Math.floor(Number(b))])?this.setOutputData(0,b[Math.floor(Number(c))]):this.setOutputData(0,null))};l.registerNodeType("basic/table[][]",G);z.title="Object property";z.desc="Outputs the property of an object";
z.prototype.setValue=function(a){this.properties.value=a;this.widget.value=a};z.prototype.getTitle=function(){return this.flags.collapsed?"in."+this.properties.value:this.title};z.prototype.onPropertyChanged=function(a,b){this.widget.value=b};z.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,a[this.properties.value])};l.registerNodeType("basic/object_property",z);I.title="Object keys";I.desc="Outputs an array with the keys of an object";I.prototype.onExecute=
function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,Object.keys(a))};l.registerNodeType("basic/object_keys",I);D.title="Set Object";D.desc="Adds propertiesrty to object";D.prototype.onExecute=function(){var a=this.getInputData(0);if(a){var b=this.getInputData(1);void 0!==b&&(this.properties.property&&(a[this.properties.property]=b),this.setOutputData(0,a))}};l.registerNodeType("basic/set_object",D);H.title="Merge Objects";H.desc="Creates an object copying properties from others";H.prototype.onExecute=
function(){var a=this.getInputData(0),b=this.getInputData(1),c=this._result;if(a)for(var d in a)c[d]=a[d];if(b)for(d in b)c[d]=b[d];this.setOutputData(0,c)};l.registerNodeType("basic/merge_objects",H);F.title="Variable";F.desc="store/read variable value";F.LITEGRAPH=0;F.GRAPH=1;F.GLOBALSCOPE=2;F["@container"]={type:"enum",values:{litegraph:F.LITEGRAPH,graph:F.GRAPH,global:F.GLOBALSCOPE}};F.prototype.onExecute=function(){var a=this.getContainer();this.isInputConnected(0)?(this.value=this.getInputData(0),
a[this.properties.varname]=this.value,this.setOutputData(0,this.value)):this.setOutputData(0,a[this.properties.varname])};F.prototype.getContainer=function(){switch(this.properties.container){case F.GRAPH:return this.graph?this.graph.vars:{};case F.GLOBALSCOPE:return v;default:return l.Globals}};F.prototype.getTitle=function(){return this.properties.varname};l.registerNodeType("basic/variable",F);l.wrapFunctionAsNode("basic/length",a,[""],"number");l.wrapFunctionAsNode("basic/not",function(a){return!a},
[""],"boolean");b.title="Download";b.desc="Download some data";b.prototype.downloadAsFile=function(){if(null!=this.value){var a=null;a=this.value.constructor===String?this.value:JSON.stringify(this.value);a=new Blob([a]);var b=URL.createObjectURL(a);a=document.createElement("a");a.setAttribute("href",b);a.setAttribute("download",this.properties.filename);a.style.display="none";document.body.appendChild(a);a.click();document.body.removeChild(a);setTimeout(function(){URL.revokeObjectURL(b)},6E4)}};
b.prototype.onAction=function(a,b){var c=this;setTimeout(function(){c.downloadAsFile()},100)};b.prototype.onExecute=function(){this.inputs[0]&&(this.value=this.getInputData(0))};b.prototype.getTitle=function(){return this.flags.collapsed?this.properties.filename:this.title};l.registerNodeType("basic/download",b);c.title="Watch";c.desc="Show value of input";c.prototype.onExecute=function(){this.inputs[0]&&(this.value=this.getInputData(0))};c.prototype.getTitle=function(){return this.flags.collapsed?
this.inputs[0].label:this.title};c.toString=function(a){if(null==a)return"null";if(a.constructor===Number)return a.toFixed(3);if(a.constructor===Array){for(var b="[",d=0;d<a.length;++d)b+=c.toString(a[d])+(d+1!=a.length?",":"");return b+"]"}return String(a)};c.prototype.onDrawBackground=function(a){this.inputs[0].label=c.toString(this.value)};l.registerNodeType("basic/watch",c);d.title="Cast";d.desc="Allows to connect different types";d.prototype.onExecute=function(){this.setOutputData(0,this.getInputData(0))};
l.registerNodeType("basic/cast",d);e.title="Console";e.desc="Show value inside the console";e.prototype.onAction=function(a,b){"log"==a?console.log(b):"warn"==a?console.warn(b):"error"==a&&console.error(b)};e.prototype.onExecute=function(){var a=this.getInputData(1);null!==a&&(this.properties.msg=a);console.log(a)};e.prototype.onGetInputs=function(){return[["log",l.ACTION],["warn",l.ACTION],["error",l.ACTION]]};l.registerNodeType("basic/console",e);k.title="Alert";k.desc="Show an alert window";k.color=
"#510";k.prototype.onConfigure=function(a){this.widget.value=a.properties.msg};k.prototype.onAction=function(a,b){var c=this.properties.msg;setTimeout(function(){alert(c)},10)};l.registerNodeType("basic/alert",k);m.prototype.onConfigure=function(a){a.properties.onExecute&&l.allow_scripts?this.compileCode(a.properties.onExecute):console.warn("Script not compiled, LiteGraph.allow_scripts is false")};m.title="Script";m.desc="executes a code (max 100 characters)";m.widgets_info={onExecute:{type:"code"}};
m.prototype.onPropertyChanged=function(a,b){"onExecute"==a&&l.allow_scripts?this.compileCode(b):console.warn("Script not compiled, LiteGraph.allow_scripts is false")};m.prototype.compileCode=function(a){this._func=null;if(256<a.length)console.warn("Script too long, max 256 chars");else{for(var b=a.toLowerCase(),c="script body document eval nodescript function".split(" "),d=0;d<c.length;++d)if(-1!=b.indexOf(c[d])){console.warn("invalid script");return}try{this._func=new Function("A","B","C","DATA",
"node",a)}catch(x){console.error("Error parsing script"),console.error(x)}}};m.prototype.onExecute=function(){if(this._func)try{var a=this.getInputData(0),b=this.getInputData(1),c=this.getInputData(2);this.setOutputData(0,this._func(a,b,c,this.data,this))}catch(p){console.error("Error in script"),console.error(p)}};m.prototype.onGetOutputs=function(){return[["C",""]]};l.registerNodeType("basic/script",m)})(this);
(function(v){function n(){this.size=[60,30];this.addInput("event",f.ACTION)}function t(){this.size=[60,30];this.addInput("if","");this.addOutput("true",f.EVENT);this.addOutput("change",f.EVENT);this.addOutput("false",f.EVENT);this.properties={only_on_change:!0};this.prev=0}function h(){var g=this;this.addInput("",f.ACTION);this.addInput("",f.ACTION);this.addInput("",f.ACTION);this.addOutput("",f.EVENT);this.addOutput("",f.EVENT);this.addOutput("",f.EVENT);this.addWidget("button","+",null,function(){g.addInput("",
f.ACTION);g.addOutput("",f.EVENT)});this.size=[90,70];this.flags={horizontal:!0,render_box:!1}}function r(){var g=this;this.properties={index:0};this.addInput("index","number");this.addInput("step",f.ACTION);this.addInput("reset",f.ACTION);this.addOutput("index","number");this.addOutput("",f.EVENT);this.addOutput("",f.EVENT);this.addOutput("",f.EVENT,{removable:!0});this.addWidget("button","+",null,function(){g.addOutput("",f.EVENT,{removable:!0})});this.size=[120,120];this.flags={render_box:!1}}
function w(){this.size=[60,30];this.addInput("event",f.ACTION);this.addOutput("event",f.EVENT);this.properties={equal_to:"",has_property:"",property_equal_to:""}}function g(){this.addInput("in",f.ACTION);this.addInput("cond","boolean");this.addOutput("true",f.EVENT);this.addOutput("false",f.EVENT);this.size=[120,60];this._value=!1}function B(){this.addInput("inc",f.ACTION);this.addInput("dec",f.ACTION);this.addInput("reset",f.ACTION);this.addOutput("change",f.EVENT);this.addOutput("num","number");
this.num=0}function A(){this.size=[60,30];this.addProperty("time_in_ms",1E3);this.addInput("event",f.ACTION);this.addOutput("on_time",f.EVENT);this._pending=[]}function y(){this.addProperty("interval",1E3);this.addProperty("event","tick");this.addOutput("on_tick",f.EVENT);this.time=0;this.last_interval=1E3;this.triggered=!1}function C(){this.addInput("go",f.ACTION);this.addInput("green",f.ACTION);this.addInput("red",f.ACTION);this.addOutput("continue",f.EVENT);this.addOutput("blocked",f.EVENT);this.addOutput("is_green",
"boolean");this._ready=!1;this.properties={};var g=this;this.addWidget("button","reset","",function(){g._ready=!1})}function E(){this.addInput("data","");this.addInput("assign",f.ACTION);this.addOutput("data","");this._last_value=null;this.properties={data:null,serialize:!0};var g=this;this.addWidget("button","store","",function(){g.properties.data=g._last_value})}var f=v.LiteGraph;n.title="Log Event";n.desc="Log event in console";n.prototype.onAction=function(f,g){console.log(f,g)};f.registerNodeType("events/log",
n);t.title="TriggerEvent";t.desc="Triggers event if input evaluates to true";t.prototype.onExecute=function(f,g){f=this.getInputData(0);var h=f!=this.prev;0===this.prev&&(h=!1);var r=h&&this.properties.only_on_change||!h&&!this.properties.only_on_change;f&&r&&this.triggerSlot(0,g);!f&&r&&this.triggerSlot(2,g);h&&this.triggerSlot(1,g);this.prev=f};f.registerNodeType("events/trigger",t);h.title="Repeater";h.desc="Trigger events when an event arrives";h.prototype.getTitle=function(){return""};h.prototype.onAction=
function(f,g){if(this.outputs)for(f=0;f<this.outputs.length;++f)this.triggerSlot(f,g)};f.registerNodeType("events/repeater",h);r.title="Stepper";r.desc="Trigger events sequentially when an tick arrives";r.prototype.onDrawBackground=function(g){if(!this.flags.collapsed){var h=this.properties.index||0;g.fillStyle="#AFB";var r=this.size[0];h=(h+1)*f.NODE_SLOT_HEIGHT+4;g.beginPath();g.moveTo(r-30,h);g.lineTo(r-30,h+f.NODE_SLOT_HEIGHT);g.lineTo(r-15,h+.5*f.NODE_SLOT_HEIGHT);g.fill()}};r.prototype.onExecute=
function(){var f=this.getInputData(0);null!=f&&(f=Math.floor(f),f=Math.clamp(f,0,this.outputs?this.outputs.length-2:0),f!=this.properties.index&&(this.properties.index=f,this.triggerSlot(f+1)));this.setOutputData(0,this.properties.index)};r.prototype.onAction=function(f,g){"reset"==f?this.properties.index=0:"step"==f&&(this.triggerSlot(this.properties.index+1,g),this.properties.index=(this.properties.index+1)%(this.outputs?this.outputs.length-1:0))};f.registerNodeType("events/stepper",r);w.title=
"Filter Event";w.desc="Blocks events that do not match the filter";w.prototype.onAction=function(f,g){if(null!=g&&(!this.properties.equal_to||this.properties.equal_to==g)){if(this.properties.has_property&&(f=g[this.properties.has_property],null==f||this.properties.property_equal_to&&this.properties.property_equal_to!=f))return;this.triggerSlot(0,g)}};f.registerNodeType("events/filter",w);g.title="Branch";g.desc="If condition is true, outputs triggers true, otherwise false";g.prototype.onExecute=function(){this._value=
this.getInputData(1)};g.prototype.onAction=function(f,g){this.triggerSlot(this._value?0:1)};f.registerNodeType("events/branch",g);B.title="Counter";B.desc="Counts events";B.prototype.getTitle=function(){return this.flags.collapsed?String(this.num):this.title};B.prototype.onAction=function(f,g){g=this.num;"inc"==f?this.num+=1:"dec"==f?--this.num:"reset"==f&&(this.num=0);this.num!=g&&this.trigger("change",this.num)};B.prototype.onDrawBackground=function(f){this.flags.collapsed||(f.fillStyle="#AAA",
f.font="20px Arial",f.textAlign="center",f.fillText(this.num,.5*this.size[0],.5*this.size[1]))};B.prototype.onExecute=function(){this.setOutputData(1,this.num)};f.registerNodeType("events/counter",B);A.title="Delay";A.desc="Delays one event";A.prototype.onAction=function(f,g){f=this.properties.time_in_ms;0>=f?this.trigger(null,g):this._pending.push([f,g])};A.prototype.onExecute=function(){var f=1E3*this.graph.elapsed_time;this.isInputConnected(1)&&(this.properties.time_in_ms=this.getInputData(1));
for(var g=0;g<this._pending.length;++g){var h=this._pending[g];h[0]-=f;0<h[0]||(this._pending.splice(g,1),--g,this.trigger(null,h[1]))}};A.prototype.onGetInputs=function(){return[["event",f.ACTION],["time_in_ms","number"]]};f.registerNodeType("events/delay",A);y.title="Timer";y.desc="Sends an event every N milliseconds";y.prototype.onStart=function(){this.time=0};y.prototype.getTitle=function(){return"Timer: "+this.last_interval.toString()+"ms"};y.on_color="#AAA";y.off_color="#222";y.prototype.onDrawBackground=
function(){this.boxcolor=this.triggered?y.on_color:y.off_color;this.triggered=!1};y.prototype.onExecute=function(){var f=0==this.time;this.time+=1E3*this.graph.elapsed_time;this.last_interval=Math.max(1,this.getInputOrProperty("interval")|0);!f&&(this.time<this.last_interval||isNaN(this.last_interval))?this.inputs&&1<this.inputs.length&&this.inputs[1]&&this.setOutputData(1,!1):(this.triggered=!0,this.time%=this.last_interval,this.trigger("on_tick",this.properties.event),this.inputs&&1<this.inputs.length&&
this.inputs[1]&&this.setOutputData(1,!0))};y.prototype.onGetInputs=function(){return[["interval","number"]]};y.prototype.onGetOutputs=function(){return[["tick","boolean"]]};f.registerNodeType("events/timer",y);C.title="Semaphore Event";C.desc="Until both events are not triggered, it doesnt continue.";C.prototype.onExecute=function(){this.setOutputData(1,this._ready);this.boxcolor=this._ready?"#9F9":"#FA5"};C.prototype.onAction=function(f,g){"go"==f?this.triggerSlot(this._ready?0:1):"green"==f?this._ready=
!0:"red"==f&&(this._ready=!1)};f.registerNodeType("events/semaphore",C);E.title="Data Store";E.desc="Stores data and only changes when event is received";E.prototype.onExecute=function(){this._last_value=this.getInputData(0);this.setOutputData(0,this.properties.data)};E.prototype.onAction=function(f,g){this.properties.data=this._last_value};E.prototype.onSerialize=function(f){null!=f.data&&(0==this.properties.serialize||f.data.constructor!==String&&f.data.constructor!==Number&&f.data.constructor!==
Boolean&&f.data.constructor!==Array&&f.data.constructor!==Object)&&(f.data=null)};f.registerNodeType("basic/data_store",E)})(this);
(function(v){function n(){this.addOutput("left_x_axis","number");this.addOutput("left_y_axis","number");this.addOutput("button_pressed",t.EVENT);this.properties={gamepad_index:0,threshold:.1};this._left_axis=new Float32Array(2);this._right_axis=new Float32Array(2);this._triggers=new Float32Array(2);this._previous_buttons=new Uint8Array(17);this._current_buttons=new Uint8Array(17)}var t=v.LiteGraph;n.title="Gamepad";n.desc="gets the input of the gamepad";n.CENTER=0;n.LEFT=1;n.RIGHT=2;n.UP=4;n.DOWN=
8;n.zero=new Float32Array(2);n.buttons="a b x y lb rb lt rt back start ls rs home".split(" ");n.prototype.onExecute=function(){var h=this.getGamepad(),r=this.properties.threshold||0;h&&(this._left_axis[0]=Math.abs(h.xbox.axes.lx)>r?h.xbox.axes.lx:0,this._left_axis[1]=Math.abs(h.xbox.axes.ly)>r?h.xbox.axes.ly:0,this._right_axis[0]=Math.abs(h.xbox.axes.rx)>r?h.xbox.axes.rx:0,this._right_axis[1]=Math.abs(h.xbox.axes.ry)>r?h.xbox.axes.ry:0,this._triggers[0]=Math.abs(h.xbox.axes.ltrigger)>r?h.xbox.axes.ltrigger:
0,this._triggers[1]=Math.abs(h.xbox.axes.rtrigger)>r?h.xbox.axes.rtrigger:0);if(this.outputs)for(r=0;r<this.outputs.length;r++){var t=this.outputs[r];if(t.links&&t.links.length){var g=null;if(h)switch(t.name){case "left_axis":g=this._left_axis;break;case "right_axis":g=this._right_axis;break;case "left_x_axis":g=this._left_axis[0];break;case "left_y_axis":g=this._left_axis[1];break;case "right_x_axis":g=this._right_axis[0];break;case "right_y_axis":g=this._right_axis[1];break;case "trigger_left":g=
this._triggers[0];break;case "trigger_right":g=this._triggers[1];break;case "a_button":g=h.xbox.buttons.a?1:0;break;case "b_button":g=h.xbox.buttons.b?1:0;break;case "x_button":g=h.xbox.buttons.x?1:0;break;case "y_button":g=h.xbox.buttons.y?1:0;break;case "lb_button":g=h.xbox.buttons.lb?1:0;break;case "rb_button":g=h.xbox.buttons.rb?1:0;break;case "ls_button":g=h.xbox.buttons.ls?1:0;break;case "rs_button":g=h.xbox.buttons.rs?1:0;break;case "hat_left":g=h.xbox.hatmap&n.LEFT;break;case "hat_right":g=
h.xbox.hatmap&n.RIGHT;break;case "hat_up":g=h.xbox.hatmap&n.UP;break;case "hat_down":g=h.xbox.hatmap&n.DOWN;break;case "hat":g=h.xbox.hatmap;break;case "start_button":g=h.xbox.buttons.start?1:0;break;case "back_button":g=h.xbox.buttons.back?1:0;break;case "button_pressed":for(t=0;t<this._current_buttons.length;++t)this._current_buttons[t]&&!this._previous_buttons[t]&&this.triggerSlot(r,n.buttons[t])}else switch(t.name){case "button_pressed":break;case "left_axis":case "right_axis":g=n.zero;break;
default:g=0}this.setOutputData(r,g)}}};n.mapping={a:0,b:1,x:2,y:3,lb:4,rb:5,lt:6,rt:7,back:8,start:9,ls:10,rs:11};n.mapping_array="a b x y lb rb lt rt back start ls rs".split(" ");n.prototype.getGamepad=function(){var h=navigator.getGamepads||navigator.webkitGetGamepads||navigator.mozGetGamepads;if(!h)return null;h=h.call(navigator);this._previous_buttons.set(this._current_buttons);for(var r=this.properties.gamepad_index;4>r;r++)if(h[r]){h=h[r];r=this.xbox_mapping;r||(r=this.xbox_mapping={axes:[],
buttons:{},hat:"",hatmap:n.CENTER});r.axes.lx=h.axes[0];r.axes.ly=h.axes[1];r.axes.rx=h.axes[2];r.axes.ry=h.axes[3];r.axes.ltrigger=h.buttons[6].value;r.axes.rtrigger=h.buttons[7].value;r.hat="";r.hatmap=n.CENTER;for(var t=0;t<h.buttons.length;t++)if(this._current_buttons[t]=h.buttons[t].pressed,12>t)r.buttons[n.mapping_array[t]]=h.buttons[t].pressed,h.buttons[t].was_pressed&&this.trigger(n.mapping_array[t]+"_button_event");else switch(t){case 12:h.buttons[t].pressed&&(r.hat+="up",r.hatmap|=n.UP);
break;case 13:h.buttons[t].pressed&&(r.hat+="down",r.hatmap|=n.DOWN);break;case 14:h.buttons[t].pressed&&(r.hat+="left",r.hatmap|=n.LEFT);break;case 15:h.buttons[t].pressed&&(r.hat+="right",r.hatmap|=n.RIGHT);break;case 16:r.buttons.home=h.buttons[t].pressed}h.xbox=r;return h}};n.prototype.onDrawBackground=function(h){if(!this.flags.collapsed){var r=this._left_axis,n=this._right_axis;h.strokeStyle="#88A";h.strokeRect(.5*(r[0]+1)*this.size[0]-4,.5*(r[1]+1)*this.size[1]-4,8,8);h.strokeStyle="#8A8";
h.strokeRect(.5*(n[0]+1)*this.size[0]-4,.5*(n[1]+1)*this.size[1]-4,8,8);r=this.size[1]/this._current_buttons.length;h.fillStyle="#AEB";for(n=0;n<this._current_buttons.length;++n)this._current_buttons[n]&&h.fillRect(0,r*n,6,r)}};n.prototype.onGetOutputs=function(){return[["left_axis","vec2"],["right_axis","vec2"],["left_x_axis","number"],["left_y_axis","number"],["right_x_axis","number"],["right_y_axis","number"],["trigger_left","number"],["trigger_right","number"],["a_button","number"],["b_button",
"number"],["x_button","number"],["y_button","number"],["lb_button","number"],["rb_button","number"],["ls_button","number"],["rs_button","number"],["start_button","number"],["back_button","number"],["a_button_event",t.EVENT],["b_button_event",t.EVENT],["x_button_event",t.EVENT],["y_button_event",t.EVENT],["lb_button_event",t.EVENT],["rb_button_event",t.EVENT],["ls_button_event",t.EVENT],["rs_button_event",t.EVENT],["start_button_event",t.EVENT],["back_button_event",t.EVENT],["hat_left","number"],["hat_right",
"number"],["hat_up","number"],["hat_down","number"],["hat","number"],["button_pressed",t.EVENT]]};t.registerNodeType("input/gamepad",n)})(this);
(function(v){function n(){this.addInput("in","");this.addOutput("out");this.size=[80,30]}function t(){this.addInput("in");this.addOutput("out");this.size=[80,30]}function h(){this.addInput("in");this.addOutput("out")}function r(){this.addInput("in","number",{locked:!0});this.addOutput("out","number",{locked:!0});this.addOutput("clamped","number",{locked:!0});this.addProperty("in",0);this.addProperty("in_min",0);this.addProperty("in_max",1);this.addProperty("out_min",0);this.addProperty("out_max",
1);this.size=[120,50]}function w(){this.addOutput("value","number");this.addProperty("min",0);this.addProperty("max",1);this.size=[80,30]}function g(){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 B(){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 A(){this.addInput("in","number");this.addOutput("out","number");this.size=[80,30];this.addProperty("min",0);this.addProperty("max",1)}function y(){this.properties={f:.5};this.addInput("A","number");this.addInput("B","number");this.addOutput("out","number")}function C(){this.addInput("in","number");this.addOutput("out","number");this.size=[80,30]}function E(){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 L(){this.addInput("in","number");this.addOutput("out","number");this.size=[80,30];this.properties={A:0,B:1}}function G(){this.addInput("in","number",{label:""});this.addOutput("out","number",{label:""});this.size=[80,30];this.addProperty("factor",1)}function z(){this.addInput("v","boolean");this.addInput("A");this.addInput("B");this.addOutput("out")}
function I(){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 D(){this.addInput("in","number");this.addOutput("out","number");this.addProperty("factor",.1);this.size=[80,30];this._value=null}function H(){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:H.values});this._func=function(a,b){return a+b};this._result=[]}function F(){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","");this.addInput("cond","boolean");this.addOutput("true","");this.addOutput("false","");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",p.allow_scripts,function(a){p.allow_scripts=a});this._func=null}function k(){this.addInput("vec2","vec2");this.addOutput("x","number");this.addOutput("y","number")}function m(){this.addInputs([["x",
"number"],["y","number"]]);this.addOutput("vec2","vec2");this.properties={x:0,y:0};this._data=new Float32Array(2)}function l(){this.addInput("vec3","vec3");this.addOutput("x","number");this.addOutput("y","number");this.addOutput("z","number")}function q(){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 u(){this.addInput("vec4","vec4");this.addOutput("x","number");this.addOutput("y","number");
this.addOutput("z","number");this.addOutput("w","number")}function J(){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 p=v.LiteGraph;n.title="Converter";n.desc="type A to type B";n.prototype.onExecute=function(){var a=this.getInputData(0);if(null!=a&&this.outputs)for(var b=0;b<this.outputs.length;b++){var c=this.outputs[b];if(c.links&&c.links.length){var d=null;switch(c.name){case "number":d=
a.length?a[0]:parseFloat(a);break;case "vec2":case "vec3":case "vec4":d=1;switch(c.name){case "vec2":d=2;break;case "vec3":d=3;break;case "vec4":d=4}d=new Float32Array(d);if(a.length)for(c=0;c<a.length&&c<d.length;c++)d[c]=a[c];else d[0]=parseFloat(a)}this.setOutputData(b,d)}}};n.prototype.onGetOutputs=function(){return[["number","number"],["vec2","vec2"],["vec3","vec3"],["vec4","vec4"]]};p.registerNodeType("math/converter",n);t.title="Bypass";t.desc="removes the type";t.prototype.onExecute=function(){var a=
this.getInputData(0);this.setOutputData(0,a)};p.registerNodeType("math/bypass",t);h.title="to Number";h.desc="Cast to number";h.prototype.onExecute=function(){var a=this.getInputData(0);this.setOutputData(0,Number(a))};p.registerNodeType("math/to_number",h);r.title="Range";r.desc="Convert a number from one range to another";r.prototype.getTitle=function(){return this.flags.collapsed?(this._last_v||0).toFixed(2):this.title};r.prototype.onExecute=function(){if(this.inputs)for(var a=0;a<this.inputs.length;a++){var b=
this.inputs[a],c=this.getInputData(a);void 0!==c&&(this.properties[b.name]=c)}c=this.properties["in"];if(void 0===c||null===c||c.constructor!==Number)c=0;a=this.properties.in_min;b=this.properties.out_min;var d=this.properties.out_max;this._last_v=(c-a)/(this.properties.in_max-a)*(d-b)+b;this.setOutputData(0,this._last_v);this.setOutputData(1,Math.clamp(this._last_v,b,d))};r.prototype.onDrawBackground=function(a){this.outputs[0].label=this._last_v?this._last_v.toFixed(3):"?"};r.prototype.onGetInputs=
function(){return[["in_min","number"],["in_max","number"],["out_min","number"],["out_max","number"]]};p.registerNodeType("math/range",r);w.title="Rand";w.desc="Random number";w.prototype.onExecute=function(){if(this.inputs)for(var a=0;a<this.inputs.length;a++){var b=this.inputs[a],c=this.getInputData(a);void 0!==c&&(this.properties[b.name]=c)}a=this.properties.min;this._last_v=Math.random()*(this.properties.max-a)+a;this.setOutputData(0,this._last_v)};w.prototype.onDrawBackground=function(a){this.outputs[0].label=
(this._last_v||0).toFixed(3)};w.prototype.onGetInputs=function(){return[["min","number"],["max","number"]]};p.registerNodeType("math/rand",w);g.title="Noise";g.desc="Random number with temporal continuity";g.data=null;g.getValue=function(a,b){if(!g.data){g.data=new Float32Array(1024);for(var c=0;c<g.data.length;++c)g.data[c]=Math.random()}a%=1024;0>a&&(a+=1024);var d=Math.floor(a);a-=d;c=g.data[d];d=g.data[1023==d?0:d+1];b&&(a=a*a*a*(a*(6*a-15)+10));return c*(1-a)+d*a};g.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,k=0;k<b&&!(c+=g.getValue(a*(1+k)*e,this.properties.smooth)*d,f+=d,d*=this.properties.persistence,.001>d);++k);a=this.properties.min;this._last_v=c/f*(this.properties.max-a)+a;this.setOutputData(0,this._last_v)};g.prototype.onDrawBackground=function(a){this.outputs[0].label=(this._last_v||0).toFixed(3)};p.registerNodeType("math/noise",g);B.title="Spikes";B.desc="spike every random time";
B.prototype.onExecute=function(){var a=this.graph.elapsed_time;this._remaining_time-=a;this._blink_time-=a;a=0;0<this._blink_time&&(a=1/(Math.pow(this._blink_time/this.properties.duration*8-4,4)+1));0>this._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)};p.registerNodeType("math/spikes",B);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};p.registerNodeType("math/clamp",A);y.title="Lerp";y.desc="Linear Interpolation";y.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)};y.prototype.onGetInputs=function(){return[["f","number"]]};p.registerNodeType("math/lerp",y);C.title="Abs";C.desc="Absolute";C.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,Math.abs(a))};p.registerNodeType("math/abs",C);E.title="Floor";E.desc="Floor number to remove fractional part";E.prototype.onExecute=function(){var a=
this.getInputData(0);null!=a&&this.setOutputData(0,Math.floor(a))};p.registerNodeType("math/floor",E);f.title="Frac";f.desc="Returns fractional part";f.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,a%1)};p.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))}};
p.registerNodeType("math/smoothstep",L);G.title="Scale";G.desc="v * factor";G.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,a*this.properties.factor)};p.registerNodeType("math/scale",G);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))};p.registerNodeType("math/gate",z);I.title="Average";I.desc="Average Filter";I.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;c<b;++c)a+=this._values[c];this.setOutputData(0,a/b)};I.prototype.onPropertyChanged=function(a,b){1>b&&(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))};p.registerNodeType("math/average",
I);D.title="TendTo";D.desc="moves the output value always closer to the input";D.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)};p.registerNodeType("math/tendTo",D);H.values="+ - * / % ^ max min".split(" ");H.title="Operation";H.desc="Easy math operators";H["@OP"]={type:"enum",title:"operation",values:H.values};H.size=[100,60];H.prototype.getTitle=function(){return"max"==
this.properties.OP||"min"==this.properties.OP?this.properties.OP+"(A,B)":"A "+this.properties.OP+" B"};H.prototype.setValue=function(a){"string"==typeof a&&(a=parseFloat(a));this.properties.value=a};H.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}}};H.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;d<a.length;++d)c[d]=this._func(a[d],b)}else for(d in c={},a)c[d]=this._func(a[d],b);this.setOutputData(0,c)};H.prototype.onDrawBackground=function(a){this.flags.collapsed||(a.font="40px Arial",a.fillStyle="#666",a.textAlign="center",a.fillText(this.properties.OP,.5*this.size[0],.5*(this.size[1]+p.NODE_TITLE_HEIGHT)),a.textAlign=
"left")};p.registerNodeType("math/operation",H);p.registerSearchboxExtra("math/operation","MAX",{properties:{OP:"max"},title:"MAX()"});p.registerSearchboxExtra("math/operation","MIN",{properties:{OP:"min"},title:"MIN()"});F.title="Compare";F.desc="compares between two values";F.prototype.onExecute=function(){var a=this.getInputData(0),b=this.getInputData(1);void 0!==a?this.properties.A=a:a=this.properties.A;void 0!==b?this.properties.B=b:b=this.properties.B;for(var c=0,d=this.outputs.length;c<d;++c){var e=
this.outputs[c];if(e.links&&e.links.length){switch(e.name){case "A==B":var f=a==b;break;case "A!=B":f=a!=b;break;case "A>B":f=a>b;break;case "A<B":f=a<b;break;case "A<=B":f=a<=b;break;case "A>=B":f=a>=b}this.setOutputData(c,f)}}};F.prototype.onGetOutputs=function(){return[["A==B","boolean"],["A!=B","boolean"],["A>B","boolean"],["A<B","boolean"],["A>=B","boolean"],["A<=B","boolean"]]};p.registerNodeType("math/compare",F);p.registerSearchboxExtra("math/compare","==",{outputs:[["A==B","boolean"]],title:"A==B"});
p.registerSearchboxExtra("math/compare","!=",{outputs:[["A!=B","boolean"]],title:"A!=B"});p.registerSearchboxExtra("math/compare",">",{outputs:[["A>B","boolean"]],title:"A>B"});p.registerSearchboxExtra("math/compare","<",{outputs:[["A<B","boolean"]],title:"A<B"});p.registerSearchboxExtra("math/compare",">=",{outputs:[["A>=B","boolean"]],title:"A>=B"});p.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<b;break;case "==":c=a==b;break;case "!=":c=a!=b;break;case "<=":c=a<=b;break;
case ">=":c=a>=b;break;case "||":c=a||b;break;case "&&":c=a&&b}this.setOutputData(0,c);this.setOutputData(1,!c)};p.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))};p.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)};p.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;c<e;++c){switch(this.outputs[c].name){case "sin":var f=Math.sin(a);break;case "cos":f=Math.cos(a);break;case "tan":f=Math.tan(a);break;case "asin":f=Math.asin(a);break;case "acos":f=Math.acos(a);break;case "atan":f=Math.atan(a)}this.setOutputData(c,b*f+d)}};d.prototype.onGetInputs=function(){return[["v","number"],["amplitude","number"],["offset","number"]]};d.prototype.onGetOutputs=
function(){return[["sin","number"],["cos","number"],["tan","number"],["asin","number"],["acos","number"],["atan","number"]]};p.registerNodeType("math/trigonometry",d);p.registerSearchboxExtra("math/trigonometry","SIN()",{outputs:[["sin","number"]],title:"SIN()"});p.registerSearchboxExtra("math/trigonometry","COS()",{outputs:[["cos","number"]],title:"COS()"});p.registerSearchboxExtra("math/trigonometry","TAN()",{outputs:[["tan","number"]],title:"TAN()"});e.title="Formula";e.desc="Compute formula";
e.size=[160,100];I.prototype.onPropertyChanged=function(a,b){"formula"==a&&(this.code_widget.value=b)};e.prototype.onExecute=function(){if(p.allow_scripts){var a=this.getInputData(0),b=this.getInputData(1);null!=a?this.properties.x=a:a=this.properties.x;null!=b?this.properties.y=b:b=this.properties.y;try{this._func&&this._func_code==this.properties.formula||(this._func=new Function("x","y","TIME","return "+this.properties.formula),this._func_code=this.properties.formula);var c=this._func(a,b,this.graph.globaltime);
this.boxcolor=null}catch(M){this.boxcolor="red"}this.setOutputData(0,c)}};e.prototype.getTitle=function(){return this._func_code||"Formula"};e.prototype.onDrawBackground=function(){var a=this.properties.formula;this.outputs&&this.outputs.length&&(this.outputs[0].label=a)};p.registerNodeType("math/formula",e);k.title="Vec2->XY";k.desc="vector 2 to components";k.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&(this.setOutputData(0,a[0]),this.setOutputData(1,a[1]))};p.registerNodeType("math3d/vec2-to-xy",
k);m.title="XY->Vec2";m.desc="components to vector2";m.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)};p.registerNodeType("math3d/xy-to-vec2",m);l.title="Vec3->XYZ";l.desc="vector 3 to components";l.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]))};
p.registerNodeType("math3d/vec3-to-xyz",l);q.title="XYZ->Vec3";q.desc="components to vector3";q.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)};p.registerNodeType("math3d/xyz-to-vec3",q);u.title="Vec4->XYZW";u.desc="vector 4 to components";u.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]))};p.registerNodeType("math3d/vec4-to-xyzw",u);J.title="XYZW->Vec4";J.desc="components to vector4";J.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)};p.registerNodeType("math3d/xyzw-to-vec4",J)})(this);
(function(v){function n(){this.addInput("","string");this.addOutput("table","table");this.addOutput("rows","number");this.addProperty("value","");this.addProperty("separator",",");this._table=null}v=v.LiteGraph;v.wrapFunctionAsNode("string/toString",function(n){if(n&&n.constructor===Object)try{return JSON.stringify(n)}catch(h){}return String(n)},[""],"String");v.wrapFunctionAsNode("string/compare",function(n,h){return n==h},["string","string"],"boolean");v.wrapFunctionAsNode("string/concatenate",
function(n,h){return void 0===n?h:void 0===h?n:n+h},["string","string"],"string");v.wrapFunctionAsNode("string/contains",function(n,h){return void 0===n||void 0===h?!1:-1!=n.indexOf(h)},["string","string"],"boolean");v.wrapFunctionAsNode("string/toUpperCase",function(n){return null!=n&&n.constructor===String?n.toUpperCase():n},["string"],"string");v.wrapFunctionAsNode("string/split",function(n,h){null==h&&(h=this.properties.separator);if(null==n)return[];if(n.constructor===String)return n.split(h||
" ");if(n.constructor===Array){for(var r=[],t=0;t<n.length;++t)r[t]=n[t].split(h||" ");return r}return null},["string,array","string"],"array",{separator:","});v.wrapFunctionAsNode("string/toFixed",function(n){return null!=n&&n.constructor===Number?n.toFixed(this.properties.precision):n},["number"],"string",{precision:0});n.title="toTable";n.desc="Splits a string to table";n.prototype.onExecute=function(){var n=this.getInputData(0);if(n){var h=this.properties.separator||",";if(n!=this._str||h!=this._last_separator)this._last_separator=
h,this._str=n,this._table=n.split("\n").map(function(r){return r.trim().split(h)});this.setOutputData(0,this._table);this.setOutputData(1,this._table?this._table.length:0)}};v.registerNodeType("string/toTable",n)})(this);
(function(v){function n(){this.addInput("sel","number");this.addInput("A");this.addInput("B");this.addInput("C");this.addInput("D");this.addOutput("out");this.selected=0}function t(){this.properties={sequence:"A,B,C"};this.addInput("index","number");this.addInput("seq");this.addOutput("out");this.index=0;this.values=this.properties.sequence.split(",")}var h=v.LiteGraph;n.title="Selector";n.desc="selects an output";n.prototype.onDrawBackground=function(r){if(!this.flags.collapsed){r.fillStyle="#AFB";
var n=(this.selected+1)*h.NODE_SLOT_HEIGHT+6;r.beginPath();r.moveTo(50,n);r.lineTo(50,n+h.NODE_SLOT_HEIGHT);r.lineTo(34,n+.5*h.NODE_SLOT_HEIGHT);r.fill()}};n.prototype.onExecute=function(){var h=this.getInputData(0);if(null==h||h.constructor!==Number)h=0;this.selected=h=Math.round(h)%(this.inputs.length-1);h=this.getInputData(h+1);void 0!==h&&this.setOutputData(0,h)};n.prototype.onGetInputs=function(){return[["E",0],["F",0],["G",0],["H",0]]};h.registerNodeType("logic/selector",n);t.title="Sequence";
t.desc="select one element from a sequence from a string";t.prototype.onPropertyChanged=function(h,n){"sequence"==h&&(this.values=n.split(","))};t.prototype.onExecute=function(){var h=this.getInputData(1);h&&h!=this.current_sequence&&(this.values=h.split(","),this.current_sequence=h);h=this.getInputData(0);null==h&&(h=0);this.index=h=Math.round(h)%this.values.length;this.setOutputData(0,this.values[h])};h.registerNodeType("logic/sequence",t)})(this);
(function(v){function n(){this.size=[60,20];this.addInput("send",h.ACTION);this.addOutput("received",h.EVENT);this.addInput("in",0);this.addOutput("out",0);this.properties={url:"",room:"lgraph",only_send_changes:!0};this._ws=null;this._last_sent_data=[];this._last_received_data=[]}function t(){this.room_widget=this.addWidget("text","Room","lgraph",this.setRoom.bind(this));this.addWidget("button","Reconnect",null,this.connectSocket.bind(this));this.addInput("send",h.ACTION);this.addOutput("received",
h.EVENT);this.addInput("in",0);this.addOutput("out",0);this.properties={url:"tamats.com:55000",room:"lgraph",only_send_changes:!0};this._server=null;this.connectSocket();this._last_sent_data=[];this._last_received_data=[];"undefined"==typeof SillyClient&&console.warn("remember to add SillyClient.js to your project: https://tamats.com/projects/sillyserver/src/sillyclient.js")}var h=v.LiteGraph;n.title="WebSocket";n.desc="Send data through a websocket";n.prototype.onPropertyChanged=function(h,n){"url"==
h&&this.connectSocket()};n.prototype.onExecute=function(){!this._ws&&this.properties.url&&this.connectSocket();if(this._ws&&this._ws.readyState==WebSocket.OPEN){for(var h=this.properties.room,n=this.properties.only_send_changes,g=1;g<this.inputs.length;++g){var t=this.getInputData(g);if(null!=t){try{var v=JSON.stringify({type:0,room:h,channel:g,data:t})}catch(y){continue}n&&this._last_sent_data[g]==v||(this._last_sent_data[g]=v,this._ws.send(v))}}for(g=1;g<this.outputs.length;++g)this.setOutputData(g,
this._last_received_data[g]);"#AFA"==this.boxcolor&&(this.boxcolor="#6C6")}};n.prototype.connectSocket=function(){var n=this,t=this.properties.url;"ws"!=t.substr(0,2)&&(t="ws://"+t);this._ws=new WebSocket(t);this._ws.onopen=function(){console.log("ready");n.boxcolor="#6C6"};this._ws.onmessage=function(g){n.boxcolor="#AFA";g=JSON.parse(g.data);if(!g.room||g.room==n.properties.room)if(1==g.type)if(g.data.object_class&&h[g.data.object_class]){var r=null;try{r=new h[g.data.object_class](g.data),n.triggerSlot(0,
r)}catch(A){}}else n.triggerSlot(0,g.data);else n._last_received_data[g.channel||0]=g.data};this._ws.onerror=function(g){console.log("couldnt connect to websocket");n.boxcolor="#E88"};this._ws.onclose=function(g){console.log("connection closed");n.boxcolor="#000"}};n.prototype.send=function(h){this._ws&&this._ws.readyState==WebSocket.OPEN&&this._ws.send(JSON.stringify({type:1,msg:h}))};n.prototype.onAction=function(h,n){this._ws&&this._ws.readyState==WebSocket.OPEN&&this._ws.send({type:1,room:this.properties.room,
action:h,data:n})};n.prototype.onGetInputs=function(){return[["in",0]]};n.prototype.onGetOutputs=function(){return[["out",0]]};h.registerNodeType("network/websocket",n);t.title="SillyClient";t.desc="Connects to SillyServer to broadcast messages";t.prototype.onPropertyChanged=function(h,n){"room"==h&&(this.room_widget.value=n);this.connectSocket()};t.prototype.setRoom=function(h){this.properties.room=h;this.room_widget.value=h;this.connectSocket()};t.prototype.onDrawForeground=function(){for(var h=
1;h<this.inputs.length;++h){var n=this.inputs[h];n.label="in_"+h}for(h=1;h<this.outputs.length;++h)n=this.outputs[h],n.label="out_"+h};t.prototype.onExecute=function(){if(this._server&&this._server.is_connected){for(var h=this.properties.only_send_changes,n=1;n<this.inputs.length;++n){var g=this.getInputData(n),t=this._last_sent_data[n];if(null!=g){if(h){var v=!0;if(g&&g.length&&t&&t.length==g.length&&g.constructor!==String)for(var y=0;y<g.length;++y){if(t[y]!=g[y]){v=!1;break}}else this._last_sent_data[n]!=
g&&(v=!1);if(v)continue}this._server.sendMessage({type:0,channel:n,data:g});if(g.length&&g.constructor!==String)if(this._last_sent_data[n])for(this._last_sent_data[n].length=g.length,y=0;y<g.length;++y)this._last_sent_data[n][y]=g[y];else this._last_sent_data[n]=g.constructor===Array?g.concat():new g.constructor(g);else this._last_sent_data[n]=g}}for(n=1;n<this.outputs.length;++n)this.setOutputData(n,this._last_received_data[n]);"#AFA"==this.boxcolor&&(this.boxcolor="#6C6")}};t.prototype.connectSocket=
function(){var n=this;if("undefined"==typeof SillyClient)this._error||console.error("SillyClient node cannot be used, you must include SillyServer.js"),this._error=!0;else if(this._server=new SillyClient,this._server.on_ready=function(){console.log("ready");n.boxcolor="#6C6"},this._server.on_message=function(r,g){r=null;try{r=JSON.parse(g)}catch(B){return}if(1==r.type)if(r.data.object_class&&h[r.data.object_class]){g=null;try{g=new h[r.data.object_class](r.data),n.triggerSlot(0,g)}catch(B){return}}else n.triggerSlot(0,
r.data);else n._last_received_data[r.channel||0]=r.data;n.boxcolor="#AFA"},this._server.on_error=function(h){console.log("couldnt connect to websocket");n.boxcolor="#E88"},this._server.on_close=function(h){console.log("connection closed");n.boxcolor="#000"},this.properties.url&&this.properties.room){try{this._server.connect(this.properties.url,this.properties.room)}catch(w){console.error("SillyServer error: "+w);this._server=null;return}this._final_url=this.properties.url+"/"+this.properties.room}};
t.prototype.send=function(h){this._server&&this._server.is_connected&&this._server.sendMessage({type:1,data:h})};t.prototype.onAction=function(h,n){this._server&&this._server.is_connected&&this._server.sendMessage({type:1,action:h,data:n})};t.prototype.onGetInputs=function(){return[["in",0]]};t.prototype.onGetOutputs=function(){return[["out",0]]};h.registerNodeType("network/sillyclient",t)})(this);