Files
ComfyUI_frontend/build/litegraph_mini.min.js
2023-10-05 10:54:37 +02:00

493 lines
243 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(x,n,t){x!=Array.prototype&&x!=Object.prototype&&(x[n]=t.value)};$jscomp.getGlobal=function(x){return"undefined"!=typeof window&&window===x?x:"undefined"!=typeof global&&null!=global?global:x};$jscomp.global=$jscomp.getGlobal(this);$jscomp.SYMBOL_PREFIX="jscomp_symbol_";
$jscomp.initSymbol=function(){$jscomp.initSymbol=function(){};$jscomp.global.Symbol||($jscomp.global.Symbol=$jscomp.Symbol)};$jscomp.Symbol=function(){var x=0;return function(n){return $jscomp.SYMBOL_PREFIX+(n||"")+x++}}();
$jscomp.initSymbolIterator=function(){$jscomp.initSymbol();var x=$jscomp.global.Symbol.iterator;x||(x=$jscomp.global.Symbol.iterator=$jscomp.global.Symbol("iterator"));"function"!=typeof Array.prototype[x]&&$jscomp.defineProperty(Array.prototype,x,{configurable:!0,writable:!0,value:function(){return $jscomp.arrayIterator(this)}});$jscomp.initSymbolIterator=function(){}};$jscomp.arrayIterator=function(x){var n=0;return $jscomp.iteratorPrototype(function(){return n<x.length?{done:!1,value:x[n++]}:{done:!0}})};
$jscomp.iteratorPrototype=function(x){$jscomp.initSymbolIterator();x={next:x};x[$jscomp.global.Symbol.iterator]=function(){return this};return x};$jscomp.makeIterator=function(x){$jscomp.initSymbolIterator();$jscomp.initSymbol();$jscomp.initSymbolIterator();var n=x[Symbol.iterator];return n?n.call(x):$jscomp.arrayIterator(x)};
$jscomp.polyfill=function(x,n,t,h){if(n){t=$jscomp.global;x=x.split(".");for(h=0;h<x.length-1;h++){var w=x[h];w in t||(t[w]={});t=t[w]}x=x[x.length-1];h=t[x];n=n(h);n!=h&&null!=n&&$jscomp.defineProperty(t,x,{configurable:!0,writable:!0,value:n})}};$jscomp.polyfill("Object.is",function(x){return x?x:function(n,t){return n===t?0!==n||1/n===1/t:n!==n&&t!==t}},"es6","es3");
$jscomp.polyfill("Array.prototype.includes",function(x){return x?x:function(n,t){var h=this;h instanceof String&&(h=String(h));var w=h.length;for(t=t||0;t<w;t++)if(h[t]==n||Object.is(h[t],n))return!0;return!1}},"es7","es3");
$jscomp.checkStringArgs=function(x,n,t){if(null==x)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 x+""};$jscomp.polyfill("String.prototype.includes",function(x){return x?x:function(n,t){return-1!==$jscomp.checkStringArgs(this,n,"includes").indexOf(n,t||0)}},"es6","es3");
$jscomp.owns=function(x,n){return Object.prototype.hasOwnProperty.call(x,n)};$jscomp.polyfill("Object.assign",function(x){return x?x:function(n,t){for(var h=1;h<arguments.length;h++){var w=arguments[h];if(w)for(var y in w)$jscomp.owns(w,y)&&(n[y]=w[y])}return n}},"es6","es3");
$jscomp.iteratorFromArray=function(x,n){$jscomp.initSymbolIterator();x instanceof String&&(x+="");var t=0,h={next:function(){if(t<x.length){var w=t++;return{value:n(w,x[w]),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.keys",function(x){return x?x:function(){return $jscomp.iteratorFromArray(this,function(n){return n})}},"es6","es3");
$jscomp.polyfill("Array.prototype.fill",function(x){return x?x:function(n,t,h){var w=this.length||0;0>t&&(t=Math.max(0,w+t));if(null==h||h>w)h=w;h=Number(h);0>h&&(h=Math.max(0,w+h));for(t=Number(t||0);t<h;t++)this[t]=n;return this}},"es6","es3");$jscomp.polyfill("Array.prototype.values",function(x){return x?x:function(){return $jscomp.iteratorFromArray(this,function(n,t){return t})}},"es8","es3");
$jscomp.polyfill("Object.values",function(x){return x?x:function(n){var t=[],h;for(h in n)$jscomp.owns(n,h)&&t.push(n[h]);return t}},"es8","es3");$jscomp.polyfill("Object.entries",function(x){return x?x:function(n){var t=[],h;for(h in n)$jscomp.owns(n,h)&&t.push([h,n[h]]);return t}},"es8","es3");
$jscomp.polyfill("String.prototype.startsWith",function(x){return x?x:function(n,t){var h=$jscomp.checkStringArgs(this,n,"startsWith");n+="";var w=h.length,y=n.length;t=Math.max(0,Math.min(t|0,h.length));for(var l=0;l<y&&t<w;)if(h[t++]!=n[l++])return!1;return l>=y}},"es6","es3");$jscomp.findInternal=function(x,n,t){x instanceof String&&(x=String(x));for(var h=x.length,w=0;w<h;w++){var y=x[w];if(n.call(t,y,w,x))return{i:w,v:y}}return{i:-1,v:void 0}};
$jscomp.polyfill("Array.prototype.findIndex",function(x){return x?x:function(n,t){return $jscomp.findInternal(this,n,t).i}},"es6","es3");
(function(x){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,e,d,g){this.id=a;this.type=b;this.origin_id=c;this.origin_slot=e;this.target_id=d;this.target_slot=g;this._data=null;this._pos=new Float32Array(2)}function h(a){this._ctor(a)}function w(a){this._ctor(a)}function y(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 l(a,b,c){this.options=c=c||{};this.background_image=l.DEFAULT_BACKGROUND_IMAGE;a&&a.constructor===String&&(a=document.querySelector(a));this.ds=new y;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.default_connection_color_byType={};this.default_connection_color_byTypeOff={};this.highquality_render=!0;this.use_gradients=!1;this.editor_alpha=1;this.pause_rendering=!1;this.clear_background=!0;this.clear_background_color="#222";this.read_only=!1;this.render_only_selected=!0;this.live_mode=!1;this.allow_interaction=this.allow_dragnodes=this.allow_dragcanvas=this.show_info=!0;this.multi_select=!1;this.allow_reconnect_links=
this.allow_searchbox=!0;this.drag_mode=this.align_to_grid=!1;this.filter=this.dragging_rectangle=null;this.set_canvas_dirty_on_mouse_event=!0;this.always_render_background=!1;this.render_canvas_border=this.render_shadows=!0;this.render_connections_shadows=!1;this.render_connections_border=!0;this.render_connection_arrows=this.render_curved_connections=!1;this.render_collapsed_slots=!0;this.render_execution_order=!1;this.render_link_tooltip=this.render_title_colored=!0;this.links_render_mode=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 E(a,b){return Math.sqrt((b[0]-a[0])*(b[0]-a[0])+(b[1]-a[1])*(b[1]-a[1]))}function B(a,b,c,e,d,g){return c<a&&c+d>a&&e<b&&e+g>b?!0:!1}function z(a,b){var c=a[0]+a[2],e=a[1]+a[3],d=b[1]+b[3];return a[0]>b[0]+b[2]||a[1]>d||c<b[0]||e<b[1]?!1:!0}function F(a,b){function c(a){var c=parseInt(g.style.top);g.style.top=(c+a.deltaY*
b.scroll_speed).toFixed()+"px";a.preventDefault();return!0}this.options=b=b||{};var e=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 d=null;b.event&&(d=b.event.constructor.name);"MouseEvent"!==d&&"CustomEvent"!==d&&"PointerEvent"!==d&&(console.error("Event passed to ContextMenu is not of type MouseEvent or CustomEvent. Ignoring it. ("+
d+")"),b.event=null);var g=document.createElement("div");g.className="litegraph litecontextmenu litemenubar-panel";b.className&&(g.className+=" "+b.className);g.style.minWidth=100;g.style.minHeight=100;g.style.pointerEvents="none";setTimeout(function(){g.style.pointerEvents="auto"},100);f.pointerListenerAdd(g,"up",function(a){a.preventDefault();return!0},!0);g.addEventListener("contextmenu",function(a){if(2!=a.button)return!1;a.preventDefault();return!1},!0);f.pointerListenerAdd(g,"down",function(a){if(2==
a.button)return e.close(),a.preventDefault(),!0},!0);b.scroll_speed||(b.scroll_speed=.1);g.addEventListener("wheel",c,!0);g.addEventListener("mousewheel",c,!0);this.root=g;b.title&&(d=document.createElement("div"),d.className="litemenu-title",d.innerHTML=b.title,g.appendChild(d));for(var k=d=0;k<a.length;k++){var m=a.constructor==Array?a[k]:k;null!=m&&m.constructor!==String&&(m=void 0===m.content?String(m):m.content);this.addItem(m,a[k],b);d++}f.pointerListenerAdd(g,"enter",function(a){g.closing_timer&&
clearTimeout(g.closing_timer)});a=document;b.event&&(a=b.event.target.ownerDocument);a||(a=document);a.fullscreenElement?a.fullscreenElement.appendChild(g):a.body.appendChild(g);d=b.left||0;a=b.top||0;b.event&&(d=b.event.clientX-10,a=b.event.clientY-10,b.title&&(a-=20),b.parentMenu&&(d=b.parentMenu.root.getBoundingClientRect(),d=d.left+d.width),k=document.body.getBoundingClientRect(),m=g.getBoundingClientRect(),0==k.height&&console.error("document.body height is 0. That is dangerous, set html,body { height: 100%; }"),
k.width&&d>k.width-m.width-10&&(d=k.width-m.width-10),k.height&&a>k.height-m.height-10&&(a=k.height-m.height-10));g.style.left=d+"px";g.style.top=a+"px";b.scale&&(g.style.transform="scale("+b.scale+")")}function G(a){this.points=a;this.nearest=this.selected=-1;this.size=null;this.must_update=!0;this.margin=5}function J(a,b,c){return b>a?b:c<a?c:a}var f=x.LiteGraph={VERSION:.4,CANVAS_GRID_SIZE:10,NODE_TITLE_HEIGHT:30,NODE_TITLE_TEXT_Y:20,NODE_SLOT_HEIGHT:20,NODE_WIDGET_HEIGHT:20,NODE_WIDTH:140,NODE_MIN_WIDTH:50,
NODE_COLLAPSED_RADIUS:10,NODE_COLLAPSED_WIDTH:80,NODE_TITLE_COLOR:"#999",NODE_SELECTED_TITLE_COLOR:"#FFF",NODE_TEXT_SIZE:14,NODE_TEXT_COLOR:"#AAA",NODE_SUBTEXT_SIZE:12,NODE_DEFAULT_COLOR:"#333",NODE_DEFAULT_BGCOLOR:"#353535",NODE_DEFAULT_BOXCOLOR:"#666",NODE_DEFAULT_SHAPE:"box",NODE_BOX_OUTLINE_COLOR:"#FFF",DEFAULT_SHADOW_COLOR:"rgba(0,0,0,0.5)",DEFAULT_GROUP_FONT:24,WIDGET_BGCOLOR:"#222",WIDGET_OUTLINE_COLOR:"#666",WIDGET_TEXT_COLOR:"#DDD",WIDGET_SECONDARY_TEXT_COLOR:"#999",LINK_COLOR:"#9A9",EVENT_LINK_COLOR:"#A86",
CONNECTING_LINK_COLOR:"#AFA",MAX_NUMBER_OF_NODES:1E3,DEFAULT_POSITION:[100,100],VALID_SHAPES:["default","box","round","card"],BOX_SHAPE:1,ROUND_SHAPE:2,CIRCLE_SHAPE:3,CARD_SHAPE:4,ARROW_SHAPE:5,GRID_SHAPE:6,INPUT:1,OUTPUT:2,EVENT:-1,ACTION:-1,NODE_MODES:["Always","On Event","Never","On Trigger"],NODE_MODES_COLORS:["#666","#422","#333","#224","#626"],ALWAYS:0,ON_EVENT:1,NEVER:2,ON_TRIGGER:3,UP:1,DOWN:2,LEFT:3,RIGHT:4,CENTER:5,LINK_RENDER_MODES:["Straight","Linear","Spline"],STRAIGHT_LINK:0,LINEAR_LINK:1,
SPLINE_LINK:2,NORMAL_TITLE:0,NO_TITLE:1,TRANSPARENT_TITLE:2,AUTOHIDE_TITLE:3,VERTICAL_LAYOUT:"vertical",proxy:null,node_images_path:"",debug:!1,catch_exceptions:!0,throw_errors:!0,allow_scripts:!1,registered_node_types:{},node_types_by_file_extension:{},Nodes:{},Globals:{},searchbox_extras:{},auto_sort_node_types:!1,node_box_coloured_when_on:!1,node_box_coloured_by_mode:!1,dialog_close_on_mouse_leave:!0,dialog_close_on_mouse_leave_delay:500,shift_click_do_break_link_from:!1,click_do_break_link_to:!1,
search_hide_on_mouse_leave:!0,search_filter_enabled:!1,search_show_all_on_open:!0,auto_load_slot_types:!1,registered_slot_in_types:{},registered_slot_out_types:{},slot_types_in:[],slot_types_out:[],slot_types_default_in:[],slot_types_default_out:[],alt_drag_do_clone_nodes:!1,do_add_triggers_slots:!1,allow_multi_output_for_events:!0,middle_click_slot_add_default_node:!1,release_link_on_empty_shows_menu:!1,pointerevents_method:"mouse",ctrl_shift_v_paste_connect_unselected_outputs:!1,use_uuids:!1,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);var c=b.name,e=a.lastIndexOf("/");b.category=a.substring(0,e);b.title||(b.title=c);for(var d in h.prototype)b.prototype[d]||(b.prototype[d]=h.prototype[d]);(e=this.registered_node_types[a])&&console.log("replacing node type: "+a);if(!Object.prototype.hasOwnProperty.call(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(){return this._shape},enumerable:!0,configurable:!0}),b.supported_extensions))for(var g in b.supported_extensions)(d=b.supported_extensions[g])&&d.constructor===String&&(this.node_types_by_file_extension[d.toLowerCase()]=b);this.registered_node_types[a]=b;b.constructor.name&&(this.Nodes[c]=
b);if(f.onNodeTypeRegistered)f.onNodeTypeRegistered(a,b);if(e&&f.onNodeTypeReplaced)f.onNodeTypeReplaced(a,b,e);b.prototype.onPropertyChange&&console.warn("LiteGraph node class "+a+" has onPropertyChange method, it must be called onPropertyChanged with d at the end");this.auto_load_slot_types&&new b(b.title||"tmpnode")},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]},registerNodeAndSlotType:function(a,b,c){c=c||!1;a=(a.constructor===String&&"anonymous"!==this.registered_node_types[a]?this.registered_node_types[a]:a).constructor.type;b="string"===typeof b?b.split(","):b==this.EVENT||b==this.ACTION?["_event_"]:["*"];for(var e=0;e<b.length;++e){var d=b[e];""===d&&(d="*");var g=c?"registered_slot_out_types":"registered_slot_in_types";void 0===this[g][d]&&(this[g][d]={nodes:[]});this[g][d].nodes.includes(a)||this[g][d].nodes.push(a);
c?this.slot_types_out.includes(d.toLowerCase())||(this.slot_types_out.push(d.toLowerCase()),this.slot_types_out.sort()):this.slot_types_in.includes(d.toLowerCase())||(this.slot_types_in.push(d.toLowerCase()),this.slot_types_in.sort())}},wrapFunctionAsNode:function(a,b,c,e,d){for(var g=Array(b.length),k="",m=f.getParameterNames(b),q=0;q<m.length;++q)k+="this.addInput('"+m[q]+"',"+(c&&c[q]?"'"+c[q]+"'":"0")+");\n";k+="this.addOutput('out',"+(e?"'"+e+"'":0)+");\n";d&&(k+="this.properties = "+JSON.stringify(d)+
";\n");c=Function(k);c.title=a.split("/").pop();c.desc="Generated from "+b.name;c.prototype.onExecute=function(){for(var a=0;a<g.length;++a)g[a]=this.getInputData(a);a=b.apply(this,g);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 e=this.registered_node_types[c];e.prototype[a]&&
(e.prototype["_"+a]=e.prototype[a]);e.prototype[a]=b}},createNode:function(a,b,c){var e=this.registered_node_types[a];if(!e)return f.debug&&console.log('GraphNode type "'+a+'" not registered.'),null;b=b||e.title||a;var d=null;if(f.catch_exceptions)try{d=new e(b)}catch(k){return console.error(k),null}else d=new e(b);d.type=a;!d.title&&b&&(d.title=b);d.properties||(d.properties={});d.properties_info||(d.properties_info=[]);d.flags||(d.flags={});d.size||(d.size=d.computeSize());d.pos||(d.pos=f.DEFAULT_POSITION.concat());
d.mode||(d.mode=f.ALWAYS);if(c)for(var g in c)d[g]=c[g];if(d.onNodeCreated)d.onNodeCreated();return d},getNodeType:function(a){return this.registered_node_types[a]},getNodeTypesInCategory:function(a,b){var c=[],e;for(e in this.registered_node_types){var d=this.registered_node_types[e];d.filter==b&&(""==a?null==d.category&&c.push(d):d.category==a&&c.push(d))}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 e=this.registered_node_types[c];e.category&&!e.skip_list&&e.filter==a&&(b[e.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=[],e=0;e<b.length;e++)c.push(b[e]);b=document.getElementsByTagName("head")[0];a=document.location.href+a;for(e=0;e<c.length;e++){var d=c[e].src;if(d&&d.substr(0,a.length)==a)try{f.debug&&console.log("Reloading: "+d);var g=
document.createElement("script");g.type="text/javascript";g.src=d;b.appendChild(g);b.removeChild(c[e])}catch(k){if(f.throw_errors)throw k;f.debug&&console.log("Error while reloading "+d)}}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},uuidv4:function(){return"10000000-1000-4000-8000-100000000000".replace(/[018]/g,function(a){return(a^16*Math.random()>>a/4).toString(16)})},isValidConnection:function(a,
b){if(""==a||"*"===a)a=0;if(""==b||"*"===b)b=0;if(!a||!b||a==b||a==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 e=0;e<b.length;++e)if(this.isValidConnection(a[c],b[e]))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,e){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);e&&e(b)});if(a.constructor===File||a.constructor===Blob){var d=new FileReader;d.onload=function(a){a=
a.target.result;"json"==b&&(a=JSON.parse(a));c&&c(a)};if("arraybuffer"==b)return d.readAsArrayBuffer(a);if("text"==b||"json"==b)return d.readAsText(a);if("blob"==b)return d.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()};x.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.nodes_executing=[];this.nodes_actioning=[];this.nodes_executedAction=[];this.inputs={};this.outputs={};this.change();this.sendActionToCanvas("clear")};n.prototype.attachCanvas=function(a){if(a.constructor!=l)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 e=f.getTime();this.globaltime=.001*(e-this.starttime);var d=this._nodes_executable?this._nodes_executable:this._nodes;if(d){c=c||d.length;if(b){for(var g=0;g<a;g++){for(var k=0;k<c;++k){var m=d[k];m.mode==
f.ALWAYS&&m.onExecute&&m.doExecute()}this.fixedtime+=this.fixedtime_lapse;if(this.onExecuteStep)this.onExecuteStep()}if(this.onAfterExecute)this.onAfterExecute()}else try{for(g=0;g<a;g++){for(k=0;k<c;++k)if(m=d[k],m.mode==f.ALWAYS&&m.onExecute)m.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();e=a-e;0==e&&(e=1);this.execution_time=.001*e;this.globaltime+=.001*e;this.iteration+=1;this.elapsed_time=.001*(a-this.last_update_time);this.last_update_time=a;this.nodes_executing=[];this.nodes_actioning=[];this.nodes_executedAction=[]}};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=[],e=[],d={},g={},k={},m=0,q=this._nodes.length;m<q;++m){var p=this._nodes[m];if(!a||p.onExecute){d[p.id]=p;var r=0;if(p.inputs)for(var u=0,l=p.inputs.length;u<l;u++)p.inputs[u]&&null!=p.inputs[u].link&&(r+=1);0==r?(e.push(p),b&&(p._level=1)):(b&&(p._level=0),k[p.id]=r)}}for(;0!=e.length;)if(p=e.shift(),c.push(p),delete d[p.id],p.outputs)for(m=0;m<p.outputs.length;m++)if(a=p.outputs[m],null!=a&&null!=a.links&&0!=a.links.length)for(u=0;u<a.links.length;u++)(q=
this.links[a.links[u]])&&!g[q.id]&&(r=this.getNodeById(q.target_id),null==r?g[q.id]=!0:(b&&(!r._level||r._level<=p._level)&&(r._level=p._level+1),g[q.id]=!0,--k[r.id],0==k[r.id]&&e.push(r)));for(m in d)c.push(d[m]);c.length!=this._nodes.length&&f.debug&&console.warn("something went wrong, nodes missing");q=c.length;for(m=0;m<q;++m)c[m].order=m;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(m=0;m<q;++m)c[m].order=
m;return c};n.prototype.getAncestors=function(a){for(var b=[],c=[a],e={};c.length;){var d=c.shift();if(d.inputs){e[d.id]||d==a||(e[d.id]=!0,b.push(d));for(var g=0;g<d.inputs.length;++g){var f=d.getInputNode(g);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,b){a=a||100;for(var c=this.computeExecutionOrder(!1,!0),e=[],d=0;d<c.length;++d){var g=c[d],k=g._level||1;e[k]||(e[k]=[]);e[k].push(g)}c=a;for(d=0;d<e.length;++d)if(g=e[d]){k=
100;for(var m=a+f.NODE_TITLE_HEIGHT,q=0;q<g.length;++q){var p=g[q];p.pos[0]=b==f.VERTICAL_LAYOUT?m:c;p.pos[1]=b==f.VERTICAL_LAYOUT?c:m;var r=b==f.VERTICAL_LAYOUT?1:0;p.size[r]>k&&(k=p.size[r]);m+=p.size[b==f.VERTICAL_LAYOUT?0:1]+a+f.NODE_TITLE_HEIGHT}c+=k+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 e=this._nodes_in_order?this._nodes_in_order:this._nodes;if(e)for(var d=0,g=e.length;d<g;++d){var k=e[d];if(k.constructor===f.Subgraph&&"onExecute"!=a)k.mode==c&&k.sendEventToAllNodes(a,b,c);else if(k[a]&&k.mode==c)if(void 0===b)k[a]();else if(b&&b.constructor===Array)k[a].apply(k,b);else k[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 e=this.list_of_graphcanvas[c];e[a]&&e[a].apply(e,b)}};
n.prototype.add=function(a,b){if(a)if(a.constructor===w)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=f.use_uuids?f.uuidv4():++this.last_node_id);if(this._nodes.length>=f.MAX_NUMBER_OF_NODES)throw"LiteGraph: max number of nodes in a graph reached";if(f.use_uuids){if(null==a.id||-1==a.id)a.id=f.uuidv4()}else 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,e=this._nodes.length;c<e;++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,e=this._nodes.length;c<e;++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,e=this._nodes.length;c<e;++c)this._nodes[c].title==a&&b.push(this._nodes[c]);
return b};n.prototype.getNodeOnPos=function(a,b,c,e){c=c||this._nodes;for(var d=c.length-1;0<=d;d--){var g=c[d];if(g.isPointInside(a,b,e))return g}return null};n.prototype.getGroupOnPos=function(a,b){for(var c=this._groups.length-1;0<=c;c--){var e=this._groups[c];if(e.isPointInside(a,b,2,!0))return e}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,c){this._input_nodes=this.findNodesByClass(f.GraphInput,this._input_nodes);for(var e=0;e<this._input_nodes.length;++e){var d=this._input_nodes[e];if(d.properties.name==a){d.actionDo(a,b,c);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 e=this.links[b];if(!e.serialize){console.warn("weird LLink bug, link info is not a LLink but a regular object");var d=new t;for(g in e)d[g]=e[g];e=this.links[b]=d}c.push(e.serialize())}var g=[];for(b=0;b<this._groups.length;++b)g.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:g,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=[],e=0;e<a.links.length;++e){var d=a.links[e];if(d){var g=new t;g.configure(d);c[g.id]=g}else console.warn("serialized graph link data contains errors, skipping.")}a.links=c}for(e in a)"nodes"!=e&&"groups"!=e&&(this[e]=a[e]);
c=!1;this._nodes=[];if(b){e=0;for(d=b.length;e<d;++e){g=b[e];var k=f.createNode(g.type,g.title);k||(f.debug&&console.log("Node not found or has errors: "+g.type),k=new h,k.last_serialization=g,c=k.has_errors=!0);k.id=g.id;this.add(k,!0)}e=0;for(d=b.length;e<d;++e)g=b[e],(k=this.getNodeById(g.id))&&k.configure(g)}this._groups.length=0;if(a.groups)for(e=0;e<a.groups.length;++e)b=new f.LGraphGroup,b.configure(a.groups[e]),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 e=new FileReader;e.addEventListener("load",function(a){a=JSON.parse(a.target.result);c.configure(a);b&&b()});e.readAsText(a)}else{var d=new XMLHttpRequest;d.open("GET",a,!0);d.send(null);d.onload=function(a){200!==d.status?console.error("Error loading graph:",d.status,d.response):(a=JSON.parse(d.response),c.configure(a),b&&b())};d.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;
x.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=f.use_uuids?f.uuidv4():-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.inputs)for(c=0;c<this.inputs.length;++c){b=this.inputs[c];var e=this.graph?this.graph.links[b.link]:null;if(this.onConnectionsChange)this.onConnectionsChange(f.INPUT,
c,!0,e,b);if(this.onInputAdded)this.onInputAdded(b)}if(this.outputs)for(c=0;c<this.outputs.length;++c){var d=this.outputs[c];if(d.links){for(b=0;b<d.links.length;++b)if(e=this.graph?this.graph.links[d.links[b]]:null,this.onConnectionsChange)this.onConnectionsChange(f.OUTPUT,c,!0,e,d);if(this.onOutputAdded)this.onOutputAdded(d)}}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;f.use_uuids&&(b.id=f.uuidv4());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 e=this.widgets[c];if(e&&e.options.property==a){e.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 e=this.graph.links[this.outputs[a].links[c]];e&&(e.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 e=this.inputs[b];if(a==e.name&&null!=e.link&&(e=this.graph.links[e.link]))return e.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 e=this.graph.links[a.links[c]];e&&(e=this.graph.getNodeById(e.target_id))&&b.push(e)}return b};h.prototype.addOnTriggerInput=function(){var a=this.findInputSlot("onTrigger");return-1==a?(this.addInput("onTrigger",f.EVENT,{optional:!0,nameLocked:!0}),this.findInputSlot("onTrigger")):
a};h.prototype.addOnExecutedOutput=function(){var a=this.findOutputSlot("onExecuted");return-1==a?(this.addOutput("onExecuted",f.ACTION,{optional:!0,nameLocked:!0}),this.findOutputSlot("onExecuted")):a};h.prototype.onAfterExecuteNode=function(a,b){var c=this.findOutputSlot("onExecuted");-1!=c&&this.triggerSlot(c,a,null,b)};h.prototype.changeMode=function(a){switch(a){case f.ON_EVENT:break;case f.ON_TRIGGER:this.addOnTriggerInput();this.addOnExecutedOutput();break;case f.NEVER:break;case f.ALWAYS:break;
case f.ON_REQUEST:break;default:return!1}this.mode=a;return!0};h.prototype.doExecute=function(a,b){b=b||{};this.onExecute&&(b.action_call||(b.action_call=this.id+"_exec_"+Math.floor(9999*Math.random())),this.graph.nodes_executing[this.id]=!0,this.onExecute(a,b),this.graph.nodes_executing[this.id]=!1,this.exec_version=this.graph.iteration,b&&b.action_call&&(this.action_call=b.action_call,this.graph.nodes_executedAction[this.id]=b.action_call));this.execute_triggered=2;if(this.onAfterExecuteNode)this.onAfterExecuteNode(a,
b)};h.prototype.actionDo=function(a,b,c){c=c||{};this.onAction&&(c.action_call||(c.action_call=this.id+"_"+(a?a:"action")+"_"+Math.floor(9999*Math.random())),this.graph.nodes_actioning[this.id]=a?a:"actioning",this.onAction(a,b,c),this.graph.nodes_actioning[this.id]=!1,c&&c.action_call&&(this.action_call=c.action_call,this.graph.nodes_executedAction[this.id]=c.action_call));this.action_triggered=2;if(this.onAfterExecuteNode)this.onAfterExecuteNode(b,c)};h.prototype.trigger=function(a,b,c){if(this.outputs&&
this.outputs.length){this.graph&&(this.graph._last_trigger_time=f.getTime());for(var e=0;e<this.outputs.length;++e){var d=this.outputs[e];!d||d.type!==f.EVENT||a&&d.name!=a||this.triggerSlot(e,b,null,c)}}};h.prototype.triggerSlot=function(a,b,c,e){e=e||{};if(this.outputs)if(null==a)console.error("slot must be a number");else if(a.constructor!==Number&&console.warn("slot must be a number, use node.trigger('name') if you want to use a string"),(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 g=a[d];if(null==c||c==g){var k=this.graph.links[a[d]];k&&(k._last_time=f.getTime(),g=this.graph.getNodeById(k.target_id))&&(g.mode===f.ON_TRIGGER?(e.action_call||(e.action_call=this.id+"_trigg_"+Math.floor(9999*Math.random())),g.onExecute&&g.doExecute(b,e)):g.onAction&&(e.action_call||(e.action_call=this.id+"_act_"+Math.floor(9999*Math.random())),k=g.inputs[k.target_slot],g.actionDo(k.name,b,e)))}}}};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 e=a[c];if(null==b||b==e)if(e=this.graph.links[a[c]])e._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,e){c={name:a,type:c,default_value:b};if(e)for(var d in e)c[d]=e[d];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 e in c)a[e]=c[e];this.outputs||(this.outputs=[]);this.outputs.push(a);if(this.onOutputAdded)this.onOutputAdded(a);f.auto_load_slot_types&&f.registerNodeAndSlotType(this,b,!0);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],e={name:c[0],type:c[1],link:null};if(a[2])for(var d in c[2])e[d]=c[2][d];this.outputs||(this.outputs=
[]);this.outputs.push(e);if(this.onOutputAdded)this.onOutputAdded(e);f.auto_load_slot_types&&f.registerNodeAndSlotType(this,c[1],!0)}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,e=0;e<c.length;++e){var d=this.graph.links[c[e]];d&&--d.origin_slot}this.setSize(this.computeSize());if(this.onOutputRemoved)this.onOutputRemoved(a);
this.setDirtyCanvas(!0,!0)};h.prototype.addInput=function(a,b,c){b=b||0;a={name:a,type:b,link:null};if(c)for(var e in c)a[e]=c[e];this.inputs||(this.inputs=[]);this.inputs.push(a);this.setSize(this.computeSize());if(this.onInputAdded)this.onInputAdded(a);f.registerNodeAndSlotType(this,b);this.setDirtyCanvas(!0,!0);return a};h.prototype.addInputs=function(a){for(var b=0;b<a.length;++b){var c=a[b],e={name:c[0],type:c[1],link:null};if(a[2])for(var d in c[2])e[d]=c[2][d];this.inputs||(this.inputs=[]);
this.inputs.push(e);if(this.onInputAdded)this.onInputAdded(e);f.registerNodeAndSlotType(this,c[1])}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 e=this.graph.links[this.inputs[c].link];e&&--e.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,e){a={name:a,type:b,pos:c,direction:e,links:null};this.connections.push(a);return a};h.prototype.computeSize=function(a){function b(a){return a?e*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 e=f.NODE_TEXT_SIZE,d=b(this.title),g=0,k=0;if(this.inputs)for(var m=0,q=this.inputs.length;m<q;++m){var p=this.inputs[m];p=p.label||
p.name||"";p=b(p);g<p&&(g=p)}if(this.outputs)for(m=0,q=this.outputs.length;m<q;++m)p=this.outputs[m],p=p.label||p.name||"",p=b(p),k<p&&(k=p);a[0]=Math.max(g+k+10,d);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){m=0;for(q=this.widgets.length;m<q;++m)c=this.widgets[m].computeSize?c+(this.widgets[m].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,e,d){this.widgets||(this.widgets=[]);!d&&e&&e.constructor===Object&&(d=e,e=null);d&&d.constructor===String&&(d={property:d});e&&e.constructor===String&&(d||(d={}),d.property=e,e=null);e&&e.constructor!==Function&&(console.warn("addWidget: callback must be a function"),
e=null);b={type:a.toLowerCase(),name:b,value:c,callback:e,options:d||{}};void 0!==b.options.y&&(b.y=b.options.y);e||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,e){c=c||0;var d=this.graph&&this.graph.isLive()?0:f.NODE_TITLE_HEIGHT;e&&(d=0);if(this.flags&&this.flags.collapsed){if(B(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]-d-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 e=0,d=this.inputs.length;e<d;++e){var g=this.inputs[e];this.getConnectionPos(!0,e,c);if(B(a,b,c[0]-10,c[1]-5,20,10))return{input:g,slot:e,link_pos:c}}if(this.outputs)for(e=0,d=this.outputs.length;e<
d;++e)if(g=this.outputs[e],this.getConnectionPos(!1,e,c),B(a,b,c[0]-10,c[1]-5,20,10))return{output:g,slot:e,link_pos:c};return null};h.prototype.findInputSlot=function(a,b){if(!this.inputs)return-1;for(var c=0,e=this.inputs.length;c<e;++c)if(a==this.inputs[c].name)return b?this.inputs[c]:c;return-1};h.prototype.findOutputSlot=function(a,b){b=b||!1;if(!this.outputs)return-1;for(var c=0,e=this.outputs.length;c<e;++c)if(a==this.outputs[c].name)return b?this.outputs[c]:c;return-1};h.prototype.findInputSlotFree=
function(a){a=a||{};a=Object.assign({returnObj:!1,typesNotAccepted:[]},a);if(!this.inputs)return-1;for(var b=0,c=this.inputs.length;b<c;++b)if(!(this.inputs[b].link&&null!=this.inputs[b].link||a.typesNotAccepted&&a.typesNotAccepted.includes&&a.typesNotAccepted.includes(this.inputs[b].type)))return a.returnObj?this.inputs[b]:b;return-1};h.prototype.findOutputSlotFree=function(a){a=a||{};a=Object.assign({returnObj:!1,typesNotAccepted:[]},a);if(!this.outputs)return-1;for(var b=0,c=this.outputs.length;b<
c;++b)if(!(this.outputs[b].links&&null!=this.outputs[b].links||a.typesNotAccepted&&a.typesNotAccepted.includes&&a.typesNotAccepted.includes(this.outputs[b].type)))return a.returnObj?this.outputs[b]:b;return-1};h.prototype.findInputSlotByType=function(a,b,c,e){return this.findSlotByType(!0,a,b,c,e)};h.prototype.findOutputSlotByType=function(a,b,c,e){return this.findSlotByType(!1,a,b,c,e)};h.prototype.findSlotByType=function(a,b,c,e,d){c=c||!1;e=e||!1;d=d||!1;a=a?this.inputs:this.outputs;if(!a)return-1;
if(""==b||"*"==b)b=0;for(var g=0,k=a.length;g<k;++g){var m=(b+"").toLowerCase().split(","),q="0"==a[g].type||"*"==a[g].type?"0":a[g].type;q=(q+"").toLowerCase().split(",");for(var p=0;p<m.length;p++)for(var r=0;r<q.length;r++)if("_event_"==m[p]&&(m[p]=f.EVENT),"_event_"==q[p]&&(q[p]=f.EVENT),"*"==m[p]&&(m[p]=0),"*"==q[p]&&(q[p]=0),!(m[p]!=q[r]||e&&a[g].links&&null!==a[g].links))return c?a[g]:g}if(e&&!d)for(g=0,k=a.length;g<k;++g)for(m=(b+"").toLowerCase().split(","),q="0"==a[g].type||"*"==a[g].type?
"0":a[g].type,q=(q+"").toLowerCase().split(","),p=0;p<m.length;p++)for(r=0;r<q.length;r++)if("*"==m[p]&&(m[p]=0),"*"==q[p]&&(q[p]=0),m[p]==q[r])return c?a[g]:g;return-1};h.prototype.connectByType=function(a,b,c,e){e=e||{};e=Object.assign({createEventInCase:!0,firstFreeIfOutputGeneralInCase:!0,generalTypeInCase:!0},e);b&&b.constructor===Number&&(b=this.graph.getNodeById(b));var d=b.findInputSlotByType(c,!1,!0);if(0<=d&&null!==d)return this.connect(a,b,d);if(e.createEventInCase&&c==f.EVENT)return this.connect(a,
b,-1);if(e.generalTypeInCase&&(d=b.findInputSlotByType(0,!1,!0,!0),0<=d)||e.firstFreeIfOutputGeneralInCase&&(0==c||"*"==c||""==c)&&(d=b.findInputSlotFree({typesNotAccepted:[f.EVENT]}),0<=d))return this.connect(a,b,d);console.debug("no way to connect type: ",c," to targetNODE ",b);return null};h.prototype.connectByTypeOutput=function(a,b,c,e){e=e||{};e=Object.assign({createEventInCase:!0,firstFreeIfInputGeneralInCase:!0,generalTypeInCase:!0},e);b&&b.constructor===Number&&(b=this.graph.getNodeById(b));
var d=b.findOutputSlotByType(c,!1,!0);if(0<=d&&null!==d||e.generalTypeInCase&&(d=b.findOutputSlotByType(0,!1,!0,!0),0<=d))return b.connect(d,this,a);if(e.createEventInCase&&c==f.EVENT&&f.do_add_triggers_slots)return d=b.addOnExecutedOutput(),b.connect(d,this,a);if(e.firstFreeIfInputGeneralInCase&&(0==c||"*"==c||""==c)&&(d=b.findOutputSlotFree({typesNotAccepted:[f.EVENT]}),0<=d))return b.connect(d,this,a);console.debug("no way to connect byOUT type: ",c," to sourceNODE ",b);return null};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)if(f.do_add_triggers_slots)b.changeMode(f.ON_TRIGGER),c=b.findInputSlot("onTrigger");else return null;else if(!b.inputs||c>=b.inputs.length)return f.debug&&console.log("Connect: Error, slot number not found"),null;var e=b.inputs[c],d=this.outputs[a];if(!this.outputs[a])return null;b.onBeforeConnectInput&&(c=b.onBeforeConnectInput(c));
if(!1===c||null===c||!f.isValidConnection(d.type,e.type))return this.setDirtyCanvas(!1,!0),null;if(b.onConnectInput&&!1===b.onConnectInput(c,d.type,d,this,a)||this.onConnectOutput&&!1===this.onConnectOutput(a,e.type,e,b,c))return null;b.inputs[c]&&null!=b.inputs[c].link&&(this.graph.beforeChange(),b.disconnectInput(c,{doProcessChange:!1}));if(null!==d.links&&d.links.length)switch(d.type){case f.EVENT:f.allow_multi_output_for_events||(this.graph.beforeChange(),this.disconnectOutput(a,!1,{doProcessChange:!1}))}var g=
f.use_uuids?f.uuidv4():++this.graph.last_link_id;g=new t(g,e.type||d.type,this.id,a,b.id,c);this.graph.links[g.id]=g;null==d.links&&(d.links=[]);d.links.push(g.id);b.inputs[c].link=g.id;this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(f.OUTPUT,a,!0,g,d);if(b.onConnectionsChange)b.onConnectionsChange(f.INPUT,c,!0,g,e);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(f.INPUT,b,c,this,a),this.graph.onNodeConnectionChange(f.OUTPUT,
this,a,b,c));this.setDirtyCanvas(!1,!0);this.graph.afterChange();this.graph.connectionChange(this,g);return g};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 e=0,d=c.links.length;e<d;e++){var g=c.links[e],k=this.graph.links[g];if(k.target_id==b.id){c.links.splice(e,1);var m=b.inputs[k.target_slot];m.link=null;delete this.graph.links[g];this.graph&&this.graph._version++;if(b.onConnectionsChange)b.onConnectionsChange(f.INPUT,k.target_slot,!1,k,m);if(this.onConnectionsChange)this.onConnectionsChange(f.OUTPUT,a,!1,k,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,k.target_slot));break}}}else{e=0;for(d=c.links.length;e<d;e++)if(g=c.links[e],k=this.graph.links[g]){b=this.graph.getNodeById(k.target_id);this.graph&&this.graph._version++;if(b){m=b.inputs[k.target_slot];m.link=null;if(b.onConnectionsChange)b.onConnectionsChange(f.INPUT,k.target_slot,!1,k,m);if(this.graph&&this.graph.onNodeConnectionChange)this.graph.onNodeConnectionChange(f.INPUT,
b,k.target_slot)}delete this.graph.links[g];if(this.onConnectionsChange)this.onConnectionsChange(f.OUTPUT,a,!1,k,c);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(f.OUTPUT,this,a),this.graph.onNodeConnectionChange(f.INPUT,b,k.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 e=this.graph.links[c];if(e){var d=this.graph.getNodeById(e.origin_id);if(!d)return!1;var g=d.outputs[e.origin_slot];if(!g||!g.links||0==g.links.length)return!1;for(var k=0,m=g.links.length;k<m;k++)if(g.links[k]==c){g.links.splice(k,1);break}delete this.graph.links[c];this.graph&&
this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(f.INPUT,a,!1,e,b);if(d.onConnectionsChange)d.onConnectionsChange(f.OUTPUT,k,!1,e,g);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(f.OUTPUT,d,k),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 e=0;a&&this.inputs&&(e=this.inputs.length);
!a&&this.outputs&&(e=this.outputs.length);var d=.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&&e>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&&e>b&&this.outputs[b].pos)return c[0]=this.pos[0]+this.outputs[b].pos[0],c[1]=this.pos[1]+this.outputs[b].pos[1],c;if(this.horizontal)return c[0]=this.pos[0]+this.size[0]/e*(b+.5),c[1]=a?this.pos[1]-f.NODE_TITLE_HEIGHT:this.pos[1]+this.size[1],c;c[0]=a?this.pos[0]+d:this.pos[0]+this.size[0]+1-d;c[1]=this.pos[1]+(b+.7)*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 e=b[c];if(a||e.node_capturing_input==this)e.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]]};x.LGraphGroup=f.LGraphGroup=w;w.prototype._ctor=function(a){this.title=a||"Group";this.font_size=24;this.color=l.node_colors.pale_blue?l.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})};w.prototype.configure=function(a){this.title=a.title;this._bounding.set(a.bounding);this.color=a.color;this.font_size=a.font_size};w.prototype.serialize=function(){var a=
this._bounding;return{title:this.title,bounding:[Math.round(a[0]),Math.round(a[1]),Math.round(a[2]),Math.round(a[3])],color:this.color,font_size:this.font_size}};w.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 e=this._nodes[c];e.pos[0]+=a;e.pos[1]+=b}};w.prototype.recomputeInsideNodes=function(){this._nodes.length=0;for(var a=this.graph._nodes,b=new Float32Array(4),c=0;c<a.length;++c){var e=a[c];e.getBounding(b);z(this._bounding,b)&&this._nodes.push(e)}};
w.prototype.isPointInside=h.prototype.isPointInside;w.prototype.setDirtyCanvas=h.prototype.setDirtyCanvas;f.DragAndScale=y;y.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)};y.prototype.computeVisibleArea=function(a){if(this.element){var b=this.element.width,c=this.element.height,e=-this.offset[0],d=-this.offset[1];a&&(e+=a[0]/this.scale,d+=a[1]/this.scale,b=a[2],c=a[3]);a=e+b/this.scale;c=d+c/this.scale;this.visible_area[0]=e;this.visible_area[1]=d;this.visible_area[2]=a-e;this.visible_area[3]=c-d}else this.visible_area[0]=this.visible_area[1]=this.visible_area[2]=this.visible_area[3]=0};y.prototype.onMouse=function(a){if(this.enabled){var b=
this.element,c=b.getBoundingClientRect(),e=a.clientX-c.left;c=a.clientY-c.top;a.canvasx=e;a.canvasy=c;a.dragging=this.dragging;var d=!this.viewport||this.viewport&&e>=this.viewport[0]&&e<this.viewport[0]+this.viewport[2]&&c>=this.viewport[1]&&c<this.viewport[1]+this.viewport[3],g=!1;this.onmouse&&(g=this.onmouse(a));a.type==f.pointerevents_method+"down"&&d?(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"?g||(b=e-this.last_mouse[0],g=c-this.last_mouse[1],this.dragging&&this.mouseDrag(b,g)):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)):!d||"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]=e;this.last_mouse[1]=c;if(d)return a.preventDefault(),a.stopPropagation(),!1}};y.prototype.toCanvasContext=function(a){a.scale(this.scale,this.scale);a.translate(this.offset[0],this.offset[1])};y.prototype.convertOffsetToCanvas=function(a){return[(a[0]+this.offset[0])*this.scale,
(a[1]+this.offset[1])*this.scale]};y.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};y.prototype.mouseDrag=function(a,b){this.offset[0]+=a/this.scale;this.offset[1]+=b/this.scale;if(this.onredraw)this.onredraw(this)};y.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)}};y.prototype.changeDeltaScale=function(a,b){this.changeScale(this.scale*a,b)};y.prototype.reset=function(){this.scale=1;this.offset[0]=0;this.offset[1]=0};x.LGraphCanvas=f.LGraphCanvas=l;l.DEFAULT_BACKGROUND_IMAGE="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQBJREFUeNrs1rEKwjAUhlETUkj3vP9rdmr1Ysammk2w5wdxuLgcMHyptfawuZX4pJSWZTnfnu/lnIe/jNNxHHGNn//HNbbv+4dr6V+11uF527arU7+u63qfa/bnmh8sWLBgwYJlqRf8MEptXPBXJXa37BSl3ixYsGDBMliwFLyCV/DeLIMFCxYsWLBMwSt4Be/NggXLYMGCBUvBK3iNruC9WbBgwYJlsGApeAWv4L1ZBgsWLFiwYJmCV/AK3psFC5bBggULloJX8BpdwXuzYMGCBctgwVLwCl7Be7MMFixYsGDBsu8FH1FaSmExVfAxBa/gvVmwYMGCZbBg/W4vAQYA5tRF9QYlv/QAAAAASUVORK5CYII=";
l.link_type_colors={"-1":f.EVENT_LINK_COLOR,number:"#AAA",node:"#DCA"};l.gradients={};l.prototype.clear=function(){this.fps=this.render_time=this.last_draw_time=this.frame=0;this.dragging_rectangle=null;this.selected_nodes={};this.selected_group=null;this.visible_nodes=[];this.connecting_node=this.node_capturing_input=this.node_over=this.node_dragged=null;this.highlighted_links={};this.dragging_canvas=!1;this.dirty_bgcanvas=this.dirty_canvas=!0;this.node_widget=this.node_in_panel=this.dirty_area=
null;this.last_mouse=[0,0];this.last_mouseclick=0;this.pointer_is_double=this.pointer_is_down=!1;this.visible_area.set([0,0,0,0]);if(this.onClear)this.onClear()};l.prototype.setGraph=function(a,b){this.graph!=a&&(b||this.clear(),!a&&this.graph?this.graph.detachCanvas(this):(a.attachCanvas(this),this._graph_stack&&(this._graph_stack=null),this.setDirty(!0,!0)))};l.prototype.getTopGraph=function(){return this._graph_stack.length?this._graph_stack[0]:this.graph};l.prototype.openSubgraph=function(a){if(!a)throw"graph cannot be null";
if(this.graph==a)throw"graph cannot be the same";this.clear();this.graph&&(this._graph_stack||(this._graph_stack=[]),this._graph_stack.push(this.graph));a.attachCanvas(this);this.checkPanels();this.setDirty(!0,!0)};l.prototype.closeSubgraph=function(){if(this._graph_stack&&0!=this._graph_stack.length){var a=this.graph._subgraph_node,b=this._graph_stack.pop();this.selected_nodes={};this.highlighted_links={};b.attachCanvas(this);this.setDirty(!0,!0);a&&(this.centerOnNode(a),this.selectNodes([a]));this.ds.offset=
[0,0];this.ds.scale=1}};l.prototype.getCurrentGraph=function(){return this.graph};l.prototype.setCanvas=function(a,b){if(a&&a.constructor===String&&(a=document.getElementById(a),!a))throw"Error creating LiteGraph canvas: Canvas not found";if(a!==this.canvas&&(!a&&this.canvas&&(b||this.unbindEvents()),this.canvas=a,this.ds.element=a)){a.className+=" lgraphcanvas";a.data=this;a.tabindex="1";this.bgcanvas=null;this.bgcanvas||(this.bgcanvas=document.createElement("canvas"),this.bgcanvas.width=this.canvas.width,
this.bgcanvas.height=this.canvas.height);if(null==a.getContext){if("canvas"!=a.localName)throw"Element supplied for LGraphCanvas must be a <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()}};l.prototype._doNothing=function(a){a.preventDefault();return!1};l.prototype._doReturnTrue=function(a){a.preventDefault();
return!0};l.prototype.bindEvents=function(){if(this._events_binded)console.warn("LGraphCanvas: events already binded");else{var a=this.canvas,b=this.getCanvasWindow().document;this._mousedown_callback=this.processMouseDown.bind(this);this._mousewheel_callback=this.processMouseWheel.bind(this);this._mousemove_callback=this.processMouseMove.bind(this);this._mouseup_callback=this.processMouseUp.bind(this);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}};l.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")};
l.getFileExtension=function(a){var b=a.indexOf("?");-1!=b&&(a=a.substr(0,b));b=a.lastIndexOf(".");return-1==b?"":a.substr(b+1).toLowerCase()};l.prototype.enableWebGL=function(){if("undefined"===typeof GL)throw"litegl.js must be included to use a WebGL canvas";if("undefined"===typeof enableWebGLCanvas)throw"webglCanvas.js must be included to use this feature";this.gl=this.ctx=enableWebGLCanvas(this.canvas);this.ctx.webgl=!0;this.bgcanvas=this.canvas;this.bgctx=this.gl;this.canvas.webgl_enabled=!0};
l.prototype.setDirty=function(a,b){a&&(this.dirty_canvas=!0);b&&(this.dirty_bgcanvas=!0)};l.prototype.getCanvasWindow=function(){if(!this.canvas)return window;var a=this.canvas.ownerDocument;return a.defaultView||a.parentWindow};l.prototype.startRendering=function(){function a(){this.pause_rendering||this.draw();var b=this.getCanvasWindow();this.is_rendering&&b.requestAnimationFrame(a.bind(this))}this.is_rendering||(this.is_rendering=!0,a.call(this))};l.prototype.stopRendering=function(){this.is_rendering=
!1};l.prototype.blockClick=function(){this.block_click=!0;this.last_mouseclick=0};l.prototype.processMouseDown=function(a){this.set_canvas_dirty_on_mouse_event&&(this.dirty_canvas=!0);if(this.graph){this.adjustMouseEvent(a);var b=this.getCanvasWindow();l.active_canvas=this;var c=this,e=a.clientX,d=a.clientY;this.ds.viewport=this.viewport;e=!this.viewport||this.viewport&&e>=this.viewport[0]&&e<this.viewport[0]+this.viewport[2]&&d>=this.viewport[1]&&d<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(e){var g=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes,5);e=!1;d=f.getTime();var k=void 0===a.isPrimary||!a.isPrimary;d=300>d-this.last_mouseclick&&k;this.mouse[0]=a.clientX;this.mouse[1]=a.clientY;this.graph_mouse[0]=a.canvasX;this.graph_mouse[1]=a.canvasY;this.last_click_position=
[this.mouse[0],this.mouse[1]];this.pointer_is_double=this.pointer_is_down&&k?!0:!1;this.pointer_is_down=!0;this.canvas.focus();f.closeAllContextMenus(b);if(!this.onMouse||1!=this.onMouse(a)){if(1!=a.which||this.pointer_is_double)if(2==a.which)if(f.middle_click_slot_add_default_node){if(g&&this.allow_interaction&&!e&&!this.read_only&&!this.connecting_node&&!g.flags.collapsed&&!this.live_mode){d=e=k=!1;if(g.outputs)for(r=0,m=g.outputs.length;r<m;++r)if(q=g.outputs[r],p=g.getConnectionPos(!1,r),B(a.canvasX,
a.canvasY,p[0]-15,p[1]-10,30,20)){k=q;e=r;d=!0;break}if(g.inputs)for(r=0,m=g.inputs.length;r<m;++r)if(q=g.inputs[r],p=g.getConnectionPos(!0,r),B(a.canvasX,a.canvasY,p[0]-15,p[1]-10,30,20)){k=q;e=r;d=!1;break}k&&!1!==e&&(r=.5-(e+1)/(d?g.outputs.length:g.inputs.length),k=g.getBounding(),this.createDefaultNodeForSlot({nodeFrom:d?g:null,slotFrom:d?e:null,nodeTo:d?null:g,slotTo:d?null:e,position:[d?k[0]+k[2]:k[0],a.canvasY-80],nodeType:"AUTO",posAdd:[d?30:-30,130*-r],posSizeFix:[d?0:-1,0]}))}}else!e&&
this.allow_dragcanvas&&(this.dragging_canvas=!0);else 3!=a.which&&!this.pointer_is_double||!this.allow_interaction||e||this.read_only||(g&&(Object.keys(this.selected_nodes).length&&(this.selected_nodes[g.id]||a.shiftKey||a.ctrlKey||a.metaKey)?this.selected_nodes[g.id]||this.selectNodes([g],!0):this.selectNodes([g])),this.processContextMenu(g,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);f.alt_drag_do_clone_nodes&&a.altKey&&g&&this.allow_interaction&&!e&&!this.read_only&&(cloned=g.clone())&&(cloned.pos[0]+=5,cloned.pos[1]+=5,this.graph.add(cloned,!1,{doCalcSize:!1}),g=cloned,e=!0,r||(this.allow_dragnodes&&(this.graph.beforeChange(),this.node_dragged=g),this.selected_nodes[g.id]||this.processNodeSelected(g,a)));k=!1;if(g&&(this.allow_interaction||g.flags.allow_interaction)&&!e&&!this.read_only){this.live_mode||g.flags.pinned||this.bringToFront(g);
if(this.allow_interaction&&!this.connecting_node&&!g.flags.collapsed&&!this.live_mode)if(!e&&!1!==g.resizable&&B(a.canvasX,a.canvasY,g.pos[0]+g.size[0]-5,g.pos[1]+g.size[1]-5,10,10))this.graph.beforeChange(),this.resizing_node=g,this.canvas.style.cursor="se-resize",e=!0;else{if(g.outputs){r=0;for(var m=g.outputs.length;r<m;++r){var q=g.outputs[r],p=g.getConnectionPos(!1,r);if(B(a.canvasX,a.canvasY,p[0]-15,p[1]-10,30,20)){this.connecting_node=g;this.connecting_output=q;this.connecting_output.slot_index=
r;this.connecting_pos=g.getConnectionPos(!1,r);this.connecting_slot=r;f.shift_click_do_break_link_from&&a.shiftKey&&g.disconnectOutput(r);if(d){if(g.onOutputDblClick)g.onOutputDblClick(r,a)}else if(g.onOutputClick)g.onOutputClick(r,a);e=!0;break}}}if(g.inputs)for(r=0,m=g.inputs.length;r<m;++r)if(q=g.inputs[r],p=g.getConnectionPos(!0,r),B(a.canvasX,a.canvasY,p[0]-15,p[1]-10,30,20)){if(d){if(g.onInputDblClick)g.onInputDblClick(r,a)}else if(g.onInputClick)g.onInputClick(r,a);null!==q.link&&(p=this.graph.links[q.link],
f.click_do_break_link_to&&(g.disconnectInput(r),e=this.dirty_bgcanvas=!0),this.allow_reconnect_links||a.shiftKey)&&(f.click_do_break_link_to||g.disconnectInput(r),this.connecting_node=this.graph._nodes_by_id[p.origin_id],this.connecting_slot=p.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);e||(this.connecting_node=g,this.connecting_input=q,this.connecting_input.slot_index=
r,this.connecting_pos=g.getConnectionPos(!0,r),this.connecting_slot=r,e=this.dirty_bgcanvas=!0)}}if(!e){var r=!1;m=[a.canvasX-g.pos[0],a.canvasY-g.pos[1]];if(p=this.processNodeWidgets(g,this.graph_mouse,a))r=!0,this.node_widget=[g,p];if(this.allow_interaction&&d&&this.selected_nodes[g.id]){if(g.onDblClick)g.onDblClick(a,m,this);this.processNodeDblClicked(g);r=!0}g.onMouseDown&&g.onMouseDown(a,m,this)?r=!0:(g.subgraph&&!g.skip_subgraph_button&&!g.flags.collapsed&&m[0]>g.size[0]-f.NODE_TITLE_HEIGHT&&
0>m[1]&&(c=this,setTimeout(function(){c.openSubgraph(g.subgraph)},10)),this.live_mode&&(r=k=!0));r?g.is_selected||this.processNodeSelected(g,a):(this.allow_dragnodes&&(this.graph.beforeChange(),this.node_dragged=g),this.processNodeSelected(g,a));this.dirty_canvas=!0}}else if(!e){if(!this.read_only)for(r=0;r<this.visible_links.length;++r)if(k=this.visible_links[r],m=k._pos,!(!m||a.canvasX<m[0]-4||a.canvasX>m[0]+4||a.canvasY<m[1]-4||a.canvasY>m[1]+4)){this.showLinkMenu(k,a);this.over_link_center=null;
break}this.selected_group=this.graph.getGroupOnPos(a.canvasX,a.canvasY);this.selected_group_resizing=!1;this.selected_group&&!this.read_only&&(a.ctrlKey&&(this.dragging_rectangle=null),10>E([a.canvasX,a.canvasY],[this.selected_group.pos[0]+this.selected_group.size[0],this.selected_group.pos[1]+this.selected_group.size[1]])*this.ds.scale?this.selected_group_resizing=!0:this.selected_group.recomputeInsideNodes());d&&!this.read_only&&this.allow_searchbox&&(this.showSearchBox(a),a.preventDefault(),a.stopPropagation());
k=!0}!e&&k&&this.allow_dragcanvas&&(this.dragging_canvas=!0)}this.last_mouse[0]=a.clientX;this.last_mouse[1]=a.clientY;this.last_mouseclick=f.getTime();this.last_mouse_dragging=!0;this.graph.change();(!b.document.activeElement||"input"!=b.document.activeElement.nodeName.toLowerCase()&&"textarea"!=b.document.activeElement.nodeName.toLowerCase())&&a.preventDefault();a.stopPropagation();if(this.onMouseDown)this.onMouseDown(a);return!1}}}};l.prototype.processMouseMove=function(a){this.autoresize&&this.resize();
this.set_canvas_dirty_on_mouse_event&&(this.dirty_canvas=!0);if(this.graph){l.active_canvas=this;this.adjustMouseEvent(a);var b=[a.clientX,a.clientY];this.mouse[0]=b[0];this.mouse[1]=b[1];var c=[b[0]-this.last_mouse[0],b[1]-this.last_mouse[1]];this.last_mouse=b;this.graph_mouse[0]=a.canvasX;this.graph_mouse[1]=a.canvasY;if(this.block_click)return a.preventDefault(),!1;a.dragging=this.last_mouse_dragging;this.node_widget&&(this.processNodeWidgets(this.node_widget[0],this.graph_mouse,a,this.node_widget[1]),
this.dirty_canvas=!0);var e=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes);if(this.dragging_rectangle)this.dragging_rectangle[2]=a.canvasX-this.dragging_rectangle[0],this.dragging_rectangle[3]=a.canvasY-this.dragging_rectangle[1],this.dirty_canvas=!0;else if(this.selected_group&&!this.read_only)this.selected_group_resizing?this.selected_group.size=[a.canvasX-this.selected_group.pos[0],a.canvasY-this.selected_group.pos[1]]:(this.selected_group.move(c[0]/this.ds.scale,c[1]/this.ds.scale,
a.ctrlKey),this.selected_group._nodes.length&&(this.dirty_canvas=!0)),this.dirty_bgcanvas=!0;else if(this.dragging_canvas)this.ds.offset[0]+=c[0]/this.ds.scale,this.ds.offset[1]+=c[1]/this.ds.scale,this.dirty_bgcanvas=this.dirty_canvas=!0;else if((this.allow_interaction||e&&e.flags.allow_interaction)&&!this.read_only){this.connecting_node&&(this.dirty_canvas=!0);b=0;for(var d=this.graph._nodes.length;b<d;++b)if(this.graph._nodes[b].mouseOver&&e!=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(e){e.redraw_on_mouse&&(this.dirty_canvas=!0);if(!e.mouseOver&&(e.mouseOver=!0,this.node_over=e,this.dirty_canvas=!0,e.onMouseEnter))e.onMouseEnter(a);if(e.onMouseMove)e.onMouseMove(a,[a.canvasX-e.pos[0],a.canvasY-e.pos[1]],this);if(this.connecting_node)if(this.connecting_output){if(d=this._highlight_input||[0,0],!this.isOverNodeBox(e,a.canvasX,a.canvasY)){var g=this.isOverNodeInput(e,
a.canvasX,a.canvasY,d);if(-1!=g&&e.inputs[g]){var k=e.inputs[g].type;f.isValidConnection(this.connecting_output.type,k)&&(this._highlight_input=d,this._highlight_input_slot=e.inputs[g])}else this._highlight_input_slot=this._highlight_input=null}}else this.connecting_input&&(d=this._highlight_output||[0,0],this.isOverNodeBox(e,a.canvasX,a.canvasY)||(g=this.isOverNodeOutput(e,a.canvasX,a.canvasY,d),-1!=g&&e.outputs[g]?(k=e.outputs[g].type,f.isValidConnection(this.connecting_input.type,k)&&(this._highlight_output=
d)):this._highlight_output=null));this.canvas&&(B(a.canvasX,a.canvasY,e.pos[0]+e.size[0]-5,e.pos[1]+e.size[1]-5,5,5)?this.canvas.style.cursor="se-resize":this.canvas.style.cursor="crosshair")}else{d=null;for(b=0;b<this.visible_links.length;++b)if(g=this.visible_links[b],k=g._pos,!(!k||a.canvasX<k[0]-4||a.canvasX>k[0]+4||a.canvasY<k[1]-4||a.canvasY>k[1]+4)){d=g;break}d!=this.over_link_center&&(this.over_link_center=d,this.dirty_canvas=!0);this.canvas&&(this.canvas.style.cursor="")}if(this.node_capturing_input&&
this.node_capturing_input!=e&&this.node_capturing_input.onMouseMove)this.node_capturing_input.onMouseMove(a,[a.canvasX-this.node_capturing_input.pos[0],a.canvasY-this.node_capturing_input.pos[1]],this);if(this.node_dragged&&!this.live_mode){for(b in this.selected_nodes)e=this.selected_nodes[b],e.pos[0]+=c[0]/this.ds.scale,e.pos[1]+=c[1]/this.ds.scale,e.is_selected||this.processNodeSelected(e,a);this.dirty_bgcanvas=this.dirty_canvas=!0}this.resizing_node&&!this.live_mode&&(c=[a.canvasX-this.resizing_node.pos[0],
a.canvasY-this.resizing_node.pos[1]],b=this.resizing_node.computeSize(),c[0]=Math.max(b[0],c[0]),c[1]=Math.max(b[1],c[1]),this.resizing_node.setSize(c),this.canvas.style.cursor="se-resize",this.dirty_bgcanvas=this.dirty_canvas=!0)}a.preventDefault();return!1}};l.prototype.processMouseUp=function(a){var b=void 0===a.isPrimary||a.isPrimary;if(!b)return!1;this.set_canvas_dirty_on_mouse_event&&(this.dirty_canvas=!0);if(this.graph){var c=this.getCanvasWindow().document;l.active_canvas=this;this.options.skip_events||
(f.pointerListenerRemove(c,"move",this._mousemove_callback,!0),f.pointerListenerAdd(this.canvas,"move",this._mousemove_callback,!0),f.pointerListenerRemove(c,"up",this._mouseup_callback,!0));this.adjustMouseEvent(a);c=f.getTime();a.click_time=c-this.last_mouseclick;this.last_mouse_dragging=!1;this.last_click_position=null;this.block_click&&(this.block_click=!1);if(1==a.which){this.node_widget&&this.processNodeWidgets(this.node_widget[0],this.graph_mouse,a);this.node_widget=null;this.selected_group&&
(this.selected_group.move(this.selected_group.pos[0]-Math.round(this.selected_group.pos[0]),this.selected_group.pos[1]-Math.round(this.selected_group.pos[1]),a.ctrlKey),this.selected_group.pos[0]=Math.round(this.selected_group.pos[0]),this.selected_group.pos[1]=Math.round(this.selected_group.pos[1]),this.selected_group._nodes.length&&(this.dirty_canvas=!0),this.selected_group=null);this.selected_group_resizing=!1;var e=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes);if(this.dragging_rectangle){if(this.graph){c=
this.graph._nodes;var d=new Float32Array(4),g=Math.abs(this.dragging_rectangle[2]),k=Math.abs(this.dragging_rectangle[3]),m=0>this.dragging_rectangle[3]?this.dragging_rectangle[1]-k:this.dragging_rectangle[1];this.dragging_rectangle[0]=0>this.dragging_rectangle[2]?this.dragging_rectangle[0]-g:this.dragging_rectangle[0];this.dragging_rectangle[1]=m;this.dragging_rectangle[2]=g;this.dragging_rectangle[3]=k;if(!e||10<g&&10<k){e=[];for(g=0;g<c.length;++g)k=c[g],k.getBounding(d),z(this.dragging_rectangle,
d)&&e.push(k);e.length&&this.selectNodes(e,a.shiftKey)}else this.selectNodes([e],a.shiftKey||a.ctrlKey)}this.dragging_rectangle=null}else if(this.connecting_node)this.dirty_bgcanvas=this.dirty_canvas=!0,c=(this.connecting_output||this.connecting_input).type,e?this.connecting_output?(d=this.isOverNodeInput(e,a.canvasX,a.canvasY),-1!=d?this.connecting_node.connect(this.connecting_slot,e,d):this.connecting_node.connectByType(this.connecting_slot,e,c)):this.connecting_input&&(d=this.isOverNodeOutput(e,
a.canvasX,a.canvasY),-1!=d?e.connect(d,this.connecting_node,this.connecting_slot):this.connecting_node.connectByTypeOutput(this.connecting_slot,e,c)):f.release_link_on_empty_shows_menu&&(a.shiftKey&&this.allow_searchbox?this.connecting_output?this.showSearchBox(a,{node_from:this.connecting_node,slot_from:this.connecting_output,type_filter_in:this.connecting_output.type}):this.connecting_input&&this.showSearchBox(a,{node_to:this.connecting_node,slot_from:this.connecting_input,type_filter_out:this.connecting_input.type}):
this.connecting_output?this.showConnectionMenu({nodeFrom:this.connecting_node,slotFrom:this.connecting_output,e:a}):this.connecting_input&&this.showConnectionMenu({nodeTo:this.connecting_node,slotTo:this.connecting_input,e:a})),this.connecting_node=this.connecting_pos=this.connecting_input=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){(e=
this.node_dragged)&&300>a.click_time&&B(a.canvasX,a.canvasY,e.pos[0],e.pos[1]-f.NODE_TITLE_HEIGHT,f.NODE_TITLE_HEIGHT,f.NODE_TITLE_HEIGHT)&&e.collapse();this.dirty_bgcanvas=this.dirty_canvas=!0;this.node_dragged.pos[0]=Math.round(this.node_dragged.pos[0]);this.node_dragged.pos[1]=Math.round(this.node_dragged.pos[1]);(this.graph.config.align_to_grid||this.align_to_grid)&&this.node_dragged.alignToGrid();if(this.onNodeMoved)this.onNodeMoved(this.node_dragged);this.graph.afterChange(this.node_dragged);
this.node_dragged=null}else{e=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes);!e&&300>a.click_time&&this.deselectAllNodes();this.dirty_canvas=!0;this.dragging_canvas=!1;if(this.node_over&&this.node_over.onMouseUp)this.node_over.onMouseUp(a,[a.canvasX-this.node_over.pos[0],a.canvasY-this.node_over.pos[1]],this);if(this.node_capturing_input&&this.node_capturing_input.onMouseUp)this.node_capturing_input.onMouseUp(a,[a.canvasX-this.node_capturing_input.pos[0],a.canvasY-this.node_capturing_input.pos[1]])}}else 2==
a.which?(this.dirty_canvas=!0,this.dragging_canvas=!1):3==a.which&&(this.dirty_canvas=!0,this.dragging_canvas=!1);b&&(this.pointer_is_double=this.pointer_is_down=!1);this.graph.change();a.stopPropagation();a.preventDefault();return!1}};l.prototype.processMouseWheel=function(a){if(this.graph&&this.allow_dragcanvas){var b=null!=a.wheelDeltaY?a.wheelDeltaY:-60*a.detail;this.adjustMouseEvent(a);var c=a.clientX,e=a.clientY;if(!this.viewport||this.viewport&&c>=this.viewport[0]&&c<this.viewport[0]+this.viewport[2]&&
e>=this.viewport[1]&&e<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}};l.prototype.isOverNodeBox=function(a,b,c){var e=f.NODE_TITLE_HEIGHT;return B(b,c,a.pos[0]+2,a.pos[1]+2-e,e-4,e-4)?!0:!1};l.prototype.isOverNodeInput=function(a,b,c,e){if(a.inputs)for(var d=0,g=a.inputs.length;d<g;++d){var f=a.getConnectionPos(!0,d);if(a.horizontal?B(b,c,f[0]-5,f[1]-10,10,20):B(b,c,f[0]-10,
f[1]-5,40,10))return e&&(e[0]=f[0],e[1]=f[1]),d}return-1};l.prototype.isOverNodeOutput=function(a,b,c,e){if(a.outputs)for(var d=0,g=a.outputs.length;d<g;++d){var f=a.getConnectionPos(!1,d);if(a.horizontal?B(b,c,f[0]-5,f[1]-10,10,20):B(b,c,f[0]-10,f[1]-5,40,10))return e&&(e[0]=f[0],e[1]=f[1]),d}return-1};l.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),27==a.keyCode&&(this.node_panel&&this.node_panel.close(),
this.options_panel&&this.options_panel.close(),b=!0),65==a.keyCode&&a.ctrlKey&&(this.selectNodes(),b=!0),67===a.keyCode&&(a.metaKey||a.ctrlKey)&&!a.shiftKey&&this.selected_nodes&&(this.copyToClipboard(),b=!0),86===a.keyCode&&(a.metaKey||a.ctrlKey)&&this.pasteFromClipboard(a.shiftKey),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}}};l.prototype.copyToClipboard=function(){var a={nodes:[],links:[]},b=0,c=[],e;for(e in this.selected_nodes){var d=this.selected_nodes[e];!1!==d.clonable&&(d._relative_id=b,c.push(d),b+=1)}for(e=0;e<c.length;++e)if(d=c[e],b=d.clone()){if(a.nodes.push(b.serialize()),
d.inputs&&d.inputs.length)for(b=0;b<d.inputs.length;++b){var g=d.inputs[b];if(g&&null!=g.link&&(g=this.graph.links[g.link])){var f=this.graph.getNodeById(g.origin_id);f&&a.links.push([f._relative_id,g.origin_slot,d._relative_id,g.target_slot,f.id])}}}else console.warn("node type not found: "+d.type);localStorage.setItem("litegrapheditor_clipboard",JSON.stringify(a))};l.prototype.pasteFromClipboard=function(a){a=void 0===a?!1:a;if(f.ctrl_shift_v_paste_connect_unselected_outputs||!a){var b=localStorage.getItem("litegrapheditor_clipboard");
if(b){this.graph.beforeChange();b=JSON.parse(b);for(var c=!1,e=!1,d=0;d<b.nodes.length;++d)c?(c[0]>b.nodes[d].pos[0]&&(c[0]=b.nodes[d].pos[0],e[0]=d),c[1]>b.nodes[d].pos[1]&&(c[1]=b.nodes[d].pos[1],e[1]=d)):(c=[b.nodes[d].pos[0],b.nodes[d].pos[1]],e=[d,d]);e=[];for(d=0;d<b.nodes.length;++d){var g=b.nodes[d],k=f.createNode(g.type);k&&(k.configure(g),k.pos[0]+=this.graph_mouse[0]-c[0],k.pos[1]+=this.graph_mouse[1]-c[1],this.graph.add(k,{doProcessChange:!1}),e.push(k))}for(d=0;d<b.links.length;++d){c=
b.links[d];g=c[0];if(null!=g)var m=e[g];else f.ctrl_shift_v_paste_connect_unselected_outputs&&a&&(g=c[4])&&(m=this.graph.getNodeById(g));g=e[c[2]];m&&g?m.connect(c[1],g,c[3]):console.warn("Warning, nodes missing on pasting")}this.selectNodes(e);this.graph.afterChange()}}};l.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 e=this.graph?this.graph.getNodeOnPos(b[0],b[1]):null;if(e){if((e.onDropFile||e.onDropData)&&(b=a.dataTransfer.files)&&b.length)for(c=0;c<b.length;c++){var d=a.dataTransfer.files[0],g=d.name;l.getFileExtension(g);if(e.onDropFile)e.onDropFile(d);if(e.onDropData){var f=new FileReader;f.onload=function(a){e.onDropData(a.target.result,g,d)};var m=d.type.split("/")[0];"text"==m||""==m?f.readAsText(d):"image"==m?f.readAsDataURL(d):f.readAsArrayBuffer(d)}}return e.onDropItem&&
e.onDropItem(event)?!0:this.onDropItem?this.onDropItem(event):!1}b=null;this.onDropItem&&(b=this.onDropItem(event));b||this.checkDropItem(a)}};l.prototype.checkDropItem=function(a){if(a.dataTransfer.files.length){var b=a.dataTransfer.files[0],c=l.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()}}};l.prototype.processNodeDblClicked=
function(a){if(this.onShowNodePanel)this.onShowNodePanel(a);else this.showShowNodePanel(a);if(this.onNodeDblClicked)this.onNodeDblClicked(a);this.setDirty(!0)};l.prototype.processNodeSelected=function(a,b){this.selectNode(a,b&&(b.shiftKey||b.ctrlKey||this.multi_select));if(this.onNodeSelected)this.onNodeSelected(a)};l.prototype.selectNode=function(a,b){null==a?this.deselectAllNodes():this.selectNodes([a],b)};l.prototype.selectNodes=function(a,b){b||this.deselectAllNodes();a=a||this.graph._nodes;"string"==
typeof a&&(a=[a]);for(var c in a)if(b=a[c],b.is_selected)this.deselectNode(b);else{if(!b.is_selected&&b.onSelected)b.onSelected();b.is_selected=!0;this.selected_nodes[b.id]=b;if(b.inputs)for(var e=0;e<b.inputs.length;++e)this.highlighted_links[b.inputs[e].link]=!0;if(b.outputs)for(e=0;e<b.outputs.length;++e){var d=b.outputs[e];if(d.links)for(var g=0;g<d.links.length;++g)this.highlighted_links[d.links[g]]=!0}}if(this.onSelectionChange)this.onSelectionChange(this.selected_nodes);this.setDirty(!0)};
l.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 e=0;e<c.links.length;++e)delete this.highlighted_links[c.links[e]]}}};l.prototype.deselectAllNodes=function(){if(this.graph){for(var a=this.graph._nodes,b=0,c=a.length;b<
c;++b){var e=a[b];if(e.is_selected){if(e.onDeselected)e.onDeselected();e.is_selected=!1;if(this.onNodeDeselected)this.onNodeDeselected(e)}}this.selected_nodes={};this.current_node=null;this.highlighted_links={};if(this.onSelectionChange)this.onSelectionChange(this.selected_nodes);this.setDirty(!0)}};l.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],e=b.graph.links[b.outputs[0].links[0]],d=b.getInputNode(0),g=b.getOutputNodes(0)[0];d&&g&&d.connect(c.origin_slot,g,e.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()};l.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)};l.prototype.adjustMouseEvent=function(a){if(this.canvas){var b=this.canvas.getBoundingClientRect();var c=a.clientX-b.left;b=a.clientY-b.top}else c=a.clientX,b=a.clientY;this.last_mouse_position[0]=c;this.last_mouse_position[1]=b;a.canvasX=c/this.ds.scale-this.ds.offset[0];a.canvasY=b/this.ds.scale-this.ds.offset[1]};
l.prototype.setZoom=function(a,b){this.ds.changeScale(a,b);this.dirty_bgcanvas=this.dirty_canvas=!0};l.prototype.convertOffsetToCanvas=function(a,b){return this.ds.convertOffsetToCanvas(a,b)};l.prototype.convertCanvasToOffset=function(a,b){return this.ds.convertCanvasToOffset(a,b)};l.prototype.convertEventToCanvasOffset=function(a){var b=this.canvas.getBoundingClientRect();return this.convertCanvasToOffset([a.clientX-b.left,a.clientY-b.top])};l.prototype.bringToFront=function(a){var b=this.graph._nodes.indexOf(a);
-1!=b&&(this.graph._nodes.splice(b,1),this.graph._nodes.push(a))};l.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);l.prototype.computeVisibleNodes=function(a,b){b=b||[];b.length=0;a=a||this.graph._nodes;for(var c=0,e=a.length;c<e;++c){var d=a[c];(!this.live_mode||d.onDrawBackground||d.onDrawForeground)&&z(this.visible_area,d.getBounding(L))&&b.push(d)}return b};l.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}};l.prototype.drawFrontCanvas=
function(){this.dirty_canvas=!1;this.ctx||(this.ctx=this.bgcanvas.getContext("2d"));var a=this.ctx;if(a){var b=this.canvas;a.start2D&&!this.viewport&&(a.start2D(),a.restore(),a.setTransform(1,0,0,1,0,0));var c=this.viewport||this.dirty_area;c&&(a.save(),a.beginPath(),a.rect(c[0],c[1],c[2],c[3]),a.clip());this.clear_background&&(c?a.clearRect(c[0],c[1],c[2],c[3]):a.clearRect(0,0,b.width,b.height));this.bgcanvas==this.canvas?this.drawBackCanvas():a.drawImage(this.bgcanvas,0,0);if(this.onRender)this.onRender(b,
a);this.show_info&&this.renderInfo(a,c?c[0]:0,c?c[1]:0);if(this.graph){a.save();this.ds.toCanvasContext(a);b=this.computeVisibleNodes(null,this.visible_nodes);for(var e=0;e<b.length;++e){var d=b[e];a.save();a.translate(d.pos[0],d.pos[1]);this.drawNode(d,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;d=this.connecting_output||this.connecting_input;
b=d.type;e=d.dir;null==e&&(e=this.connecting_output?this.connecting_node.horizontal?f.DOWN:f.RIGHT:this.connecting_node.horizontal?f.UP:f.LEFT);var g=d.shape;switch(b){case f.EVENT:d=f.EVENT_LINK_COLOR;break;default:d=f.CONNECTING_LINK_COLOR}this.renderLink(a,this.connecting_pos,[this.graph_mouse[0],this.graph_mouse[1]],null,!1,null,d,e,f.CENTER);a.beginPath();b===f.EVENT||g===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)):g===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";if(this._highlight_input){a.beginPath();var k=this._highlight_input_slot.shape;
k===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._highlight_output&&(a.beginPath(),k===f.ARROW_SHAPE?(a.moveTo(this._highlight_output[0]+8,this._highlight_output[1]+.5),a.lineTo(this._highlight_output[0]-4,this._highlight_output[1]+
6+.5),a.lineTo(this._highlight_output[0]-4,this._highlight_output[1]-6+.5),a.closePath()):a.arc(this._highlight_output[0],this._highlight_output[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()}};l.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")};l.prototype.drawSubgraphPanelLeft=function(a,b,c){var e=b.inputs?b.inputs.length:
0,d=Math.floor(1.6*f.NODE_SLOT_HEIGHT);c.fillStyle="#111";c.globalAlpha=.8;c.beginPath();c.roundRect(10,10,200,(e+1)*d+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{e=50;c.font="14px Arial";if(b.inputs)for(var g=0;g<b.inputs.length;++g){var k=b.inputs[g];if(!k.not_subgraph_input){if(this.drawButton(20,e+2,180,d-2)){var m=b.constructor.input_node_type||
"graph/input";this.graph.beforeChange();var q=f.createNode(m);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",k.name),q.setProperty("type",k.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:",m)}c.fillStyle="#9C9";c.beginPath();c.arc(184,e+.5*d,5,0,2*Math.PI);c.fill();c.fillStyle=
"#AAA";c.fillText(k.name,30,e+.75*d);c.fillStyle="#777";c.fillText(k.type,130,e+.75*d);e+=d}}this.drawButton(20,e+2,180,d-2,"+","#151515","#222")&&this.showSubgraphPropertiesDialog(b)}};l.prototype.drawSubgraphPanelRight=function(a,b,c){var e=b.outputs?b.outputs.length:0,d=this.bgcanvas.width,g=Math.floor(1.6*f.NODE_SLOT_HEIGHT);c.fillStyle="#111";c.globalAlpha=.8;c.beginPath();c.roundRect(d-200-10,10,200,(e+1)*g+50,[8]);c.fill();c.globalAlpha=1;c.fillStyle="#888";c.font="14px Arial";c.textAlign=
"left";e=c.measureText("Graph Outputs").width;c.fillText("Graph Outputs",d-e-20,34);if(this.drawButton(d-200,20,20,20,"X","#151515"))this.closeSubgraph();else{e=50;c.font="14px Arial";if(b.outputs)for(var k=0;k<b.outputs.length;++k){var m=b.outputs[k];if(!m.not_subgraph_input){if(this.drawButton(d-200,e+2,180,g-2)){var q=b.constructor.output_node_type||"graph/output";this.graph.beforeChange();var p=f.createNode(q);p?(a.add(p),this.block_click=!1,this.last_click_position=null,this.selectNodes([p]),
this.node_dragged=p,this.dragging_canvas=!1,p.setProperty("name",m.name),p.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:",q)}c.fillStyle="#9C9";c.beginPath();c.arc(d-200+16,e+.5*g,5,0,2*Math.PI);c.fill();c.fillStyle="#AAA";c.fillText(m.name,d-200+30,e+.75*g);c.fillStyle="#777";c.fillText(m.type,d-200+130,e+.75*g);e+=g}}this.drawButton(d-200,e+2,180,g-2,"+",
"#151515","#222")&&this.showSubgraphPropertiesDialogRight(b)}};l.prototype.drawButton=function(a,b,c,e,d,g,k,m){var q=this.ctx;g=g||f.NODE_DEFAULT_COLOR;k=k||"#555";m=m||f.NODE_TEXT_COLOR;var p=this.ds.convertOffsetToCanvas(this.graph_mouse),r=f.isInsideRectangle(p[0],p[1],a,b,c,e);if(p=this.last_click_position?[this.last_click_position[0],this.last_click_position[1]]:null){var u=this.canvas.getBoundingClientRect();p[0]-=u.left;p[1]-=u.top}p=p&&f.isInsideRectangle(p[0],p[1],a,b,c,e);q.fillStyle=r?
k:g;p&&(q.fillStyle="#AAA");q.beginPath();q.roundRect(a,b,c,e,[4]);q.fill();null!=d&&d.constructor==String&&(q.fillStyle=m,q.textAlign="center",q.font=(.65*e|0)+"px Arial",q.fillText(d,a+.5*c,b+.75*e),q.textAlign="left");a=p&&!this.block_click;p&&this.blockClick();return a};l.prototype.isAreaClicked=function(a,b,c,e,d){var g=this.mouse;f.isInsideRectangle(g[0],g[1],a,b,c,e);b=(a=(g=this.last_click_position)&&f.isInsideRectangle(g[0],g[1],a,b,c,e))&&!this.block_click;a&&d&&this.blockClick();return b};
l.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()};l.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 e="",d=1;d<this._graph_stack.length;++d)e+=this._graph_stack[d]._subgraph_node.getTitle()+" >> ";b.fillText(e+c.getTitle(),.5*a.width,40);b.restore()}c=!1;this.onRenderBackground&&(c=this.onRenderBackground(a,b));this.viewport||(b.restore(),b.setTransform(1,0,0,1,0,0));this.visible_links.length=0;if(this.graph){b.save();this.ds.toCanvasContext(b);1.5>this.ds.scale&&!c&&this.clear_background_color&&
(b.fillStyle=this.clear_background_color,b.fillRect(this.visible_area[0],this.visible_area[1],this.visible_area[2],this.visible_area[3]));if(this.background_image&&.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.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 g=this;
this._bg_img.onload=function(){g.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.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 D=new Float32Array(2);l.prototype.drawNode=function(a,b){this.current_node=a;var c=a.color||a.constructor.color||f.NODE_DEFAULT_COLOR,e=a.bgcolor||a.constructor.bgcolor||f.NODE_DEFAULT_BGCOLOR,d=.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 g=this.editor_alpha;b.globalAlpha=g;this.render_shadows&&!d?(b.shadowColor=f.DEFAULT_SHADOW_COLOR,b.shadowOffsetX=2*this.ds.scale,
b.shadowOffsetY=2*this.ds.scale,b.shadowBlur=3*this.ds.scale):b.shadowColor="transparent";if(!a.flags.collapsed||!a.onDrawCollapsed||1!=a.onDrawCollapsed(b,this)){var k=a._shape||f.BOX_SHAPE;D.set(a.size);var m=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),D[0]=a._collapsed_width,D[1]=0)}a.clip_area&&(b.save(),b.beginPath(),k==f.BOX_SHAPE?b.rect(0,0,
D[0],D[1]):k==f.ROUND_SHAPE?b.roundRect(0,0,D[0],D[1],[10]):k==f.CIRCLE_SHAPE&&b.arc(.5*D[0],.5*D[1],.5*D[0],0,2*Math.PI),b.clip());a.has_errors&&(e="red");this.drawNodeShape(a,b,D,c,e,a.is_selected,a.mouseOver);b.shadowColor="transparent";if(a.onDrawForeground)a.onDrawForeground(b,this,this.canvas);b.textAlign=m?"center":"left";b.font=this.inner_text_font;e=!d;var p=this.connecting_output;k=this.connecting_input;b.lineWidth=1;q=0;var r=new Float32Array(2);if(!a.flags.collapsed){if(a.inputs)for(c=
0;c<a.inputs.length;c++){var u=a.inputs[c],l=u.type,I=u.shape;b.globalAlpha=g;this.connecting_output&&!f.isValidConnection(u.type,p.type)&&(b.globalAlpha=.4*g);b.fillStyle=null!=u.link?u.color_on||this.default_connection_color_byType[l]||this.default_connection_color.input_on:u.color_off||this.default_connection_color_byTypeOff[l]||this.default_connection_color_byType[l]||this.default_connection_color.input_off;var v=a.getConnectionPos(!0,c,r);v[0]-=a.pos[0];v[1]-=a.pos[1];q<v[1]+.5*f.NODE_SLOT_HEIGHT&&
(q=v[1]+.5*f.NODE_SLOT_HEIGHT);b.beginPath();"array"==l&&(I=f.GRID_SHAPE);u.type===f.EVENT||u.shape===f.BOX_SHAPE?m?b.rect(v[0]-5+.5,v[1]-8+.5,10,14):b.rect(v[0]-6+.5,v[1]-5+.5,14,10):I===f.ARROW_SHAPE?(b.moveTo(v[0]+8,v[1]+.5),b.lineTo(v[0]-4,v[1]+6+.5),b.lineTo(v[0]-4,v[1]-6+.5),b.closePath()):I===f.GRID_SHAPE?(b.rect(v[0]-4,v[1]-4,2,2),b.rect(v[0]-1,v[1]-4,2,2),b.rect(v[0]+2,v[1]-4,2,2),b.rect(v[0]-4,v[1]-1,2,2),b.rect(v[0]-1,v[1]-1,2,2),b.rect(v[0]+2,v[1]-1,2,2),b.rect(v[0]-4,v[1]+2,2,2),b.rect(v[0]-
1,v[1]+2,2,2),b.rect(v[0]+2,v[1]+2,2,2)):d?b.rect(v[0]-4,v[1]-4,8,8):b.arc(v[0],v[1],4,0,2*Math.PI);b.fill();e&&(l=null!=u.label?u.label:u.name)&&(b.fillStyle=f.NODE_TEXT_COLOR,m||u.dir==f.UP?b.fillText(l,v[0],v[1]-10):b.fillText(l,v[0]+10,v[1]+5))}b.textAlign=m?"center":"right";b.strokeStyle="black";if(a.outputs)for(c=0;c<a.outputs.length;c++)if(u=a.outputs[c],l=u.type,I=u.shape,this.connecting_input&&!f.isValidConnection(l,k.type)&&(b.globalAlpha=.4*g),v=a.getConnectionPos(!1,c,r),v[0]-=a.pos[0],
v[1]-=a.pos[1],q<v[1]+.5*f.NODE_SLOT_HEIGHT&&(q=v[1]+.5*f.NODE_SLOT_HEIGHT),b.fillStyle=u.links&&u.links.length?u.color_on||this.default_connection_color_byType[l]||this.default_connection_color.output_on:u.color_off||this.default_connection_color_byTypeOff[l]||this.default_connection_color_byType[l]||this.default_connection_color.output_off,b.beginPath(),"array"==l&&(I=f.GRID_SHAPE),p=!0,l===f.EVENT||I===f.BOX_SHAPE?m?b.rect(v[0]-5+.5,v[1]-8+.5,10,14):b.rect(v[0]-6+.5,v[1]-5+.5,14,10):I===f.ARROW_SHAPE?
(b.moveTo(v[0]+8,v[1]+.5),b.lineTo(v[0]-4,v[1]+6+.5),b.lineTo(v[0]-4,v[1]-6+.5),b.closePath()):I===f.GRID_SHAPE?(b.rect(v[0]-4,v[1]-4,2,2),b.rect(v[0]-1,v[1]-4,2,2),b.rect(v[0]+2,v[1]-4,2,2),b.rect(v[0]-4,v[1]-1,2,2),b.rect(v[0]-1,v[1]-1,2,2),b.rect(v[0]+2,v[1]-1,2,2),b.rect(v[0]-4,v[1]+2,2,2),b.rect(v[0]-1,v[1]+2,2,2),b.rect(v[0]+2,v[1]+2,2,2),p=!1):d?b.rect(v[0]-4,v[1]-4,8,8):b.arc(v[0],v[1],4,0,2*Math.PI),b.fill(),!d&&p&&b.stroke(),e&&(l=null!=u.label?u.label:u.name))b.fillStyle=f.NODE_TEXT_COLOR,
m||u.dir==f.DOWN?b.fillText(l,v[0],v[1]-8):b.fillText(l,v[0]-10,v[1]+5);b.textAlign="left";b.globalAlpha=1;if(a.widgets){u=q;if(m||a.widgets_up)u=2;null!=a.widgets_start_y&&(u=a.widgets_start_y);this.drawNodeWidgets(a,u,b,this.node_widget&&this.node_widget[0]==a?this.node_widget[1]:null)}}else if(this.render_collapsed_slots){d=g=null;if(a.inputs)for(c=0;c<a.inputs.length;c++)if(u=a.inputs[c],null!=u.link){g=u;break}if(a.outputs)for(c=0;c<a.outputs.length;c++)u=a.outputs[c],u.links&&u.links.length&&
(d=u);g&&(g=0,c=-.5*f.NODE_TITLE_HEIGHT,m&&(g=.5*a._collapsed_width,c=-f.NODE_TITLE_HEIGHT),b.fillStyle="#686",b.beginPath(),u.type===f.EVENT||u.shape===f.BOX_SHAPE?b.rect(g-7+.5,c-4,14,8):u.shape===f.ARROW_SHAPE?(b.moveTo(g+8,c),b.lineTo(g+-4,c-4),b.lineTo(g+-4,c+4),b.closePath()):b.arc(g,c,4,0,2*Math.PI),b.fill());d&&(g=a._collapsed_width,c=-.5*f.NODE_TITLE_HEIGHT,m&&(g=.5*a._collapsed_width,c=0),b.fillStyle="#686",b.strokeStyle="black",b.beginPath(),u.type===f.EVENT||u.shape===f.BOX_SHAPE?b.rect(g-
7+.5,c-4,14,8):u.shape===f.ARROW_SHAPE?(b.moveTo(g+6,c),b.lineTo(g-6,c-4),b.lineTo(g-6,c+4),b.closePath()):b.arc(g,c,4,0,2*Math.PI),b.fill())}a.clip_area&&b.restore();b.globalAlpha=1}}};l.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 e=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*e,c[1]-15-24,e,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 A=new Float32Array(4);
l.prototype.drawNodeShape=function(a,b,c,e,d,g,k){b.strokeStyle=e;b.fillStyle=d;d=f.NODE_TITLE_HEIGHT;var m=.5>this.ds.scale,q=a._shape||a.constructor.shape||f.ROUND_SHAPE,p=a.constructor.title_mode,r=!0;p==f.TRANSPARENT_TITLE||p==f.NO_TITLE?r=!1:p==f.AUTOHIDE_TITLE&&k&&(r=!0);A[0]=0;A[1]=r?-d:0;A[2]=c[0]+1;A[3]=r?c[1]+d:c[1];k=b.globalAlpha;b.beginPath();q==f.BOX_SHAPE||m?b.fillRect(A[0],A[1],A[2],A[3]):q==f.ROUND_SHAPE||q==f.CARD_SHAPE?b.roundRect(A[0],A[1],A[2],A[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&&r&&(b.shadowColor="transparent",b.fillStyle="rgba(0,0,0,0.2)",b.fillRect(0,-1,A[2],2));b.shadowColor="transparent";if(a.onDrawBackground)a.onDrawBackground(b,this,this.canvas,this.graph_mouse);if(r||p==f.TRANSPARENT_TITLE){if(a.onDrawTitleBar)a.onDrawTitleBar(b,d,c,this.ds.scale,e);else if(p!=f.TRANSPARENT_TITLE&&(a.constructor.title_color||this.render_title_colored)){r=
a.constructor.title_color||e;a.flags.collapsed&&(b.shadowColor=f.DEFAULT_SHADOW_COLOR);if(this.use_gradients){var u=l.gradients[r];u||(u=l.gradients[r]=b.createLinearGradient(0,0,400,0),u.addColorStop(0,r),u.addColorStop(1,"#000"));b.fillStyle=u}else b.fillStyle=r;b.beginPath();q==f.BOX_SHAPE||m?b.rect(0,-d,c[0]+1,d):(q==f.ROUND_SHAPE||q==f.CARD_SHAPE)&&b.roundRect(0,-d,c[0]+1,d,a.flags.collapsed?[this.round_radius]:[this.round_radius,this.round_radius,0,0]);b.fill();b.shadowColor="transparent"}r=
!1;f.node_box_coloured_by_mode&&f.NODE_MODES_COLORS[a.mode]&&(r=f.NODE_MODES_COLORS[a.mode]);f.node_box_coloured_when_on&&(r=a.action_triggered?"#FFF":a.execute_triggered?"#AAA":r);if(a.onDrawTitleBox)a.onDrawTitleBox(b,d,c,this.ds.scale);else q==f.ROUND_SHAPE||q==f.CIRCLE_SHAPE||q==f.CARD_SHAPE?(m&&(b.fillStyle="black",b.beginPath(),b.arc(.5*d,-.5*d,6,0,2*Math.PI),b.fill()),b.fillStyle=a.boxcolor||r||f.NODE_DEFAULT_BOXCOLOR,m?b.fillRect(.5*d-5,-.5*d-5,10,10):(b.beginPath(),b.arc(.5*d,-.5*d,5,0,2*
Math.PI),b.fill())):(m&&(b.fillStyle="black",b.fillRect(.5*(d-10)-1,-.5*(d+10)-1,12,12)),b.fillStyle=a.boxcolor||r||f.NODE_DEFAULT_BOXCOLOR,b.fillRect(.5*(d-10),-.5*(d+10),10,10));b.globalAlpha=k;if(a.onDrawTitleText)a.onDrawTitleText(b,d,c,this.ds.scale,this.title_text_font,g);!m&&(b.font=this.title_text_font,k=String(a.getTitle()))&&(b.fillStyle=g?f.NODE_SELECTED_TITLE_COLOR:a.constructor.title_text_color||this.node_title_color,a.flags.collapsed?(b.textAlign="left",b.measureText(k),b.fillText(k.substr(0,
20),d,f.NODE_TITLE_TEXT_Y-d),b.textAlign="left"):(b.textAlign="left",b.fillText(k,d,f.NODE_TITLE_TEXT_Y-d)));a.flags.collapsed||!a.subgraph||a.skip_subgraph_button||(k=f.NODE_TITLE_HEIGHT,r=a.size[0]-k,u=f.isInsideRectangle(this.graph_mouse[0]-a.pos[0],this.graph_mouse[1]-a.pos[1],r+2,-k+2,k-4,k-4),b.fillStyle=u?"#888":"#555",q==f.BOX_SHAPE||m?b.fillRect(r+2,-k+2,k-4,k-4):(b.beginPath(),b.roundRect(r+2,-k+2,k-4,k-4,[4]),b.fill()),b.fillStyle="#333",b.beginPath(),b.moveTo(r+.2*k,.6*-k),b.lineTo(r+
.8*k,.6*-k),b.lineTo(r+.5*k,.3*-k),b.fill());if(a.onDrawTitle)a.onDrawTitle(b)}if(g){if(a.onBounding)a.onBounding(A);p==f.TRANSPARENT_TITLE&&(A[1]-=d,A[3]+=d);b.lineWidth=1;b.globalAlpha=.8;b.beginPath();q==f.BOX_SHAPE?b.rect(-6+A[0],-6+A[1],12+A[2],12+A[3]):q==f.ROUND_SHAPE||q==f.CARD_SHAPE&&a.flags.collapsed?b.roundRect(-6+A[0],-6+A[1],12+A[2],12+A[3],[2*this.round_radius]):q==f.CARD_SHAPE?b.roundRect(-6+A[0],-6+A[1],12+A[2],12+A[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=e;b.globalAlpha=1}0<a.execute_triggered&&a.execute_triggered--;0<a.action_triggered&&a.action_triggered--};var M=new Float32Array(4),C=new Float32Array(4),H=new Float32Array(2),N=new Float32Array(2);l.prototype.drawConnections=function(a){var b=f.getTime(),c=this.visible_area;M[0]=c[0]-20;M[1]=c[1]-20;M[2]=c[2]+40;M[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 e=0,d=c.length;e<d;++e){var g=c[e];if(g.inputs&&g.inputs.length)for(var k=0;k<g.inputs.length;++k){var m=g.inputs[k];if(m&&null!=m.link&&(m=this.graph.links[m.link])){var q=this.graph.getNodeById(m.origin_id);if(null!=q){var p=m.origin_slot;var r=-1==p?[q.pos[0]+10,q.pos[1]+10]:q.getConnectionPos(!1,p,H);var u=g.getConnectionPos(!0,k,N);C[0]=r[0];C[1]=r[1];C[2]=u[0]-r[0];C[3]=u[1]-r[1];0>C[2]&&(C[0]+=C[2],C[2]=Math.abs(C[2]));0>C[3]&&
(C[1]+=C[3],C[3]=Math.abs(C[3]));if(z(C,M)){var l=q.outputs[p];p=g.inputs[k];if(l&&p&&(q=l.dir||(q.horizontal?f.DOWN:f.RIGHT),p=p.dir||(g.horizontal?f.UP:f.LEFT),this.renderLink(a,r,u,m,!1,0,null,q,p),m&&m._last_time&&1E3>b-m._last_time)){l=2-.002*(b-m._last_time);var I=a.globalAlpha;a.globalAlpha=I*l;this.renderLink(a,r,u,m,!0,l,"white",q,p);a.globalAlpha=I}}}}}}a.globalAlpha=1};l.prototype.renderLink=function(a,b,c,e,d,g,k,m,q,p){e&&this.visible_links.push(e);!k&&e&&(k=e.color||l.link_type_colors[e.type]);
k||(k=this.default_link_color);null!=e&&this.highlighted_links[e.id]&&(k="#FFF");m=m||f.RIGHT;q=q||f.LEFT;var r=E(b,c);this.render_connections_border&&.6<this.ds.scale&&(a.lineWidth=this.connections_width+4);a.lineJoin="round";p=p||1;1<p&&(a.lineWidth=.5);a.beginPath();for(var u=0;u<p;u+=1){var K=5*(u-.5*(p-1));if(this.links_render_mode==f.SPLINE_LINK){a.moveTo(b[0],b[1]+K);var I=0,v=0,h=0,n=0;switch(m){case f.LEFT:I=-.25*r;break;case f.RIGHT:I=.25*r;break;case f.UP:v=-.25*r;break;case f.DOWN:v=.25*
r}switch(q){case f.LEFT:h=-.25*r;break;case f.RIGHT:h=.25*r;break;case f.UP:n=-.25*r;break;case f.DOWN:n=.25*r}a.bezierCurveTo(b[0]+I,b[1]+v+K,c[0]+h,c[1]+n+K,c[0],c[1]+K)}else if(this.links_render_mode==f.LINEAR_LINK){a.moveTo(b[0],b[1]+K);n=h=v=I=0;switch(m){case f.LEFT:I=-1;break;case f.RIGHT:I=1;break;case f.UP:v=-1;break;case f.DOWN:v=1}switch(q){case f.LEFT:h=-1;break;case f.RIGHT:h=1;break;case f.UP:n=-1;break;case f.DOWN:n=1}a.lineTo(b[0]+15*I,b[1]+15*v+K);a.lineTo(c[0]+15*h,c[1]+15*n+K);
a.lineTo(c[0],c[1]+K)}else if(this.links_render_mode==f.STRAIGHT_LINK)a.moveTo(b[0],b[1]),K=b[0],I=b[1],v=c[0],h=c[1],m==f.RIGHT?K+=10:I+=10,q==f.LEFT?v-=10:h-=10,a.lineTo(K,I),a.lineTo(.5*(K+v),I),a.lineTo(.5*(K+v),h),a.lineTo(v,h),a.lineTo(c[0],c[1]);else return}this.render_connections_border&&.6<this.ds.scale&&!d&&(a.strokeStyle="rgba(0,0,0,0.5)",a.stroke());a.lineWidth=this.connections_width;a.fillStyle=a.strokeStyle=k;a.stroke();d=this.computeConnectionPoint(b,c,.5,m,q);e&&e._pos&&(e._pos[0]=
d[0],e._pos[1]=d[1]);.6<=this.ds.scale&&this.highquality_render&&q!=f.CENTER&&(this.render_connection_arrows&&(u=this.computeConnectionPoint(b,c,.25,m,q),r=this.computeConnectionPoint(b,c,.26,m,q),e=this.computeConnectionPoint(b,c,.75,m,q),p=this.computeConnectionPoint(b,c,.76,m,q),this.render_curved_connections?(r=-Math.atan2(r[0]-u[0],r[1]-u[1]),p=-Math.atan2(p[0]-e[0],p[1]-e[1])):p=r=c[1]>b[1]?0:Math.PI,a.save(),a.translate(u[0],u[1]),a.rotate(r),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,
-3),a.fill(),a.restore(),a.save(),a.translate(e[0],e[1]),a.rotate(p),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore()),a.beginPath(),a.arc(d[0],d[1],5,0,2*Math.PI),a.fill());if(g)for(a.fillStyle=k,u=0;5>u;++u)g=(.001*f.getTime()+.2*u)%1,d=this.computeConnectionPoint(b,c,g,m,q),a.beginPath(),a.arc(d[0],d[1],5,0,2*Math.PI),a.fill()};l.prototype.computeConnectionPoint=function(a,b,c,e,d){e=e||f.RIGHT;d=d||f.LEFT;var g=E(a,b),k=[a[0],a[1]],m=[b[0],b[1]];switch(e){case f.LEFT:k[0]+=
-.25*g;break;case f.RIGHT:k[0]+=.25*g;break;case f.UP:k[1]+=-.25*g;break;case f.DOWN:k[1]+=.25*g}switch(d){case f.LEFT:m[0]+=-.25*g;break;case f.RIGHT:m[0]+=.25*g;break;case f.UP:m[1]+=-.25*g;break;case f.DOWN:m[1]+=.25*g}e=(1-c)*(1-c)*(1-c);d=3*(1-c)*(1-c)*c;g=3*(1-c)*c*c;c*=c*c;return[e*a[0]+d*k[0]+g*m[0]+c*b[0],e*a[1]+d*k[1]+g*m[1]+c*b[1]]};l.prototype.drawExecutionOrder=function(a){a.shadowColor="transparent";a.globalAlpha=.25;a.textAlign="center";a.strokeStyle="white";a.globalAlpha=.75;for(var b=
this.visible_nodes,c=0;c<b.length;++c){var e=b[c];a.fillStyle="black";a.fillRect(e.pos[0]-f.NODE_TITLE_HEIGHT,e.pos[1]-f.NODE_TITLE_HEIGHT,f.NODE_TITLE_HEIGHT,f.NODE_TITLE_HEIGHT);0==e.order&&a.strokeRect(e.pos[0]-f.NODE_TITLE_HEIGHT+.5,e.pos[1]-f.NODE_TITLE_HEIGHT+.5,f.NODE_TITLE_HEIGHT,f.NODE_TITLE_HEIGHT);a.fillStyle="#FFF";a.fillText(e.order,e.pos[0]+-.5*f.NODE_TITLE_HEIGHT,e.pos[1]-6)}a.globalAlpha=1};l.prototype.drawNodeWidgets=function(a,b,c,e){if(!a.widgets||!a.widgets.length)return 0;var d=
a.size[0],g=a.widgets;b+=2;var k=f.NODE_WIDGET_HEIGHT,m=.5<this.ds.scale;c.save();c.globalAlpha=this.editor_alpha;for(var q=f.WIDGET_OUTLINE_COLOR,p=f.WIDGET_BGCOLOR,r=f.WIDGET_TEXT_COLOR,u=f.WIDGET_SECONDARY_TEXT_COLOR,l=0;l<g.length;++l){var h=g[l],v=b;h.y&&(v=h.y);h.last_y=v;c.strokeStyle=q;c.fillStyle="#222";c.textAlign="left";h.disabled&&(c.globalAlpha*=.5);var n=h.width||d;switch(h.type){case "button":h.clicked&&(c.fillStyle="#AAA",h.clicked=!1,this.dirty_canvas=!0);c.fillRect(15,v,n-30,k);
m&&!h.disabled&&c.strokeRect(15,v,n-30,k);m&&(c.textAlign="center",c.fillStyle=r,c.fillText(h.label||h.name,.5*n,v+.7*k));break;case "toggle":c.textAlign="left";c.strokeStyle=q;c.fillStyle=p;c.beginPath();m?c.roundRect(15,v,n-30,k,[.5*k]):c.rect(15,v,n-30,k);c.fill();m&&!h.disabled&&c.stroke();c.fillStyle=h.value?"#89A":"#333";c.beginPath();c.arc(n-30,v+.5*k,.36*k,0,2*Math.PI);c.fill();if(m){c.fillStyle=u;var w=h.label||h.name;null!=w&&c.fillText(w,30,v+.7*k);c.fillStyle=h.value?r:u;c.textAlign="right";
c.fillText(h.value?h.options.on||"true":h.options.off||"false",n-40,v+.7*k)}break;case "slider":c.fillStyle=p;c.fillRect(15,v,n-30,k);w=h.options.max-h.options.min;var t=(h.value-h.options.min)/w;0>t&&(t=0);1<t&&(t=1);c.fillStyle=h.options.hasOwnProperty("slider_color")?h.options.slider_color:e==h?"#89A":"#678";c.fillRect(15,v,t*(n-30),k);m&&!h.disabled&&c.strokeRect(15,v,n-30,k);h.marker&&(w=(h.marker-h.options.min)/w,0>w&&(w=0),1<w&&(w=1),c.fillStyle=h.options.hasOwnProperty("marker_color")?h.options.marker_color:
"#AA9",c.fillRect(15+w*(n-30),v,2,k));m&&(c.textAlign="center",c.fillStyle=r,c.fillText(h.label||h.name+" "+Number(h.value).toFixed(null!=h.options.precision?h.options.precision:3),.5*n,v+.7*k));break;case "number":case "combo":c.textAlign="left";c.strokeStyle=q;c.fillStyle=p;c.beginPath();m?c.roundRect(15,v,n-30,k,[.5*k]):c.rect(15,v,n-30,k);c.fill();m&&(h.disabled||c.stroke(),c.fillStyle=r,h.disabled||(c.beginPath(),c.moveTo(31,v+5),c.lineTo(21,v+.5*k),c.lineTo(31,v+k-5),c.fill(),c.beginPath(),
c.moveTo(n-15-16,v+5),c.lineTo(n-15-6,v+.5*k),c.lineTo(n-15-16,v+k-5),c.fill()),c.fillStyle=u,c.fillText(h.label||h.name,35,v+.7*k),c.fillStyle=r,c.textAlign="right","number"==h.type?c.fillText(Number(h.value).toFixed(void 0!==h.options.precision?h.options.precision:3),n-30-20,v+.7*k):(w=h.value,h.options.values&&(t=h.options.values,t.constructor===Function&&(t=t()),t&&t.constructor!==Array&&(w=t[h.value])),c.fillText(w,n-30-20,v+.7*k)));break;case "string":case "text":c.textAlign="left";c.strokeStyle=
q;c.fillStyle=p;c.beginPath();m?c.roundRect(15,v,n-30,k,[.5*k]):c.rect(15,v,n-30,k);c.fill();m&&(h.disabled||c.stroke(),c.save(),c.beginPath(),c.rect(15,v,n-30,k),c.clip(),c.fillStyle=u,w=h.label||h.name,null!=w&&c.fillText(w,30,v+.7*k),c.fillStyle=r,c.textAlign="right",c.fillText(String(h.value).substr(0,30),n-30,v+.7*k),c.restore());break;default:h.draw&&h.draw(c,a,n,v,k)}b+=(h.computeSize?h.computeSize(n)[1]:k)+4;c.globalAlpha=this.editor_alpha}c.restore();c.textAlign="left"};l.prototype.processNodeWidgets=
function(a,b,c,e){function d(d,e){"number"==d.type&&(e=Number(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||!this.allow_interaction&&!a.flags.allow_interaction)return null;for(var g=b[0]-a.pos[0],k=b[1]-a.pos[1],m=a.size[0],q=this,p=this.getCanvasWindow(),r=0;r<a.widgets.length;++r){var u=a.widgets[r];if(u&&!u.disabled){var l=u.computeSize?u.computeSize(m)[1]:
f.NODE_WIDGET_HEIGHT,h=u.width||m;if(u==e||!(6>g||g>h-12||k<u.last_y||k>u.last_y+l||void 0===u.last_y)){e=u.value;switch(u.type){case "button":c.type===f.pointerevents_method+"down"&&(u.callback&&setTimeout(function(){u.callback(u,q,a,b,c)},20),this.dirty_canvas=u.clicked=!0);break;case "slider":e=u.value;p=J((g-15)/(h-30),0,1);if(u.options.read_only)break;u.value=u.options.min+(u.options.max-u.options.min)*p;e!=u.value&&setTimeout(function(){d(u,u.value)},20);this.dirty_canvas=!0;break;case "number":case "combo":e=
u.value;if(c.type==f.pointerevents_method+"move"&&"number"==u.type)c.deltaX&&(u.value+=.1*c.deltaX*(u.options.step||1)),null!=u.options.min&&u.value<u.options.min&&(u.value=u.options.min),null!=u.options.max&&u.value>u.options.max&&(u.value=u.options.max);else if(c.type==f.pointerevents_method+"down"){var v=u.options.values;v&&v.constructor===Function&&(v=u.options.values(u,a));var n=null;"number"!=u.type&&(n=v.constructor===Array?v:Object.keys(v));g=40>g?-1:g>h-40?1:0;if("number"==u.type)u.value+=
.1*g*(u.options.step||1),null!=u.options.min&&u.value<u.options.min&&(u.value=u.options.min),null!=u.options.max&&u.value>u.options.max&&(u.value=u.options.max);else if(g)p=-1,this.last_mouseclick=0,p=v.constructor===Object?n.indexOf(String(u.value))+g:n.indexOf(u.value)+g,p>=n.length&&(p=n.length-1),0>p&&(p=0),u.value=v.constructor===Array?v[p]:p;else{var w=v!=n?Object.values(v):v;new f.ContextMenu(w,{scale:Math.max(1,this.ds.scale),event:c,className:"dark",callback:function(a,b,c){v!=n&&(a=w.indexOf(a));
this.value=a;d(this,a);q.dirty_canvas=!0;return!1}.bind(u)},p)}}else c.type==f.pointerevents_method+"up"&&"number"==u.type&&(g=40>g?-1:g>h-40?1:0,200>c.click_time&&0==g&&this.prompt("Value",u.value,function(a){if(/^[0-9+\-*/()\s]+|\d+\.\d+$/.test(a))try{a=eval(a)}catch(O){}this.value=Number(a);d(this,this.value)}.bind(u),c));e!=u.value&&setTimeout(function(){d(this,this.value)}.bind(u),20);this.dirty_canvas=!0;break;case "toggle":c.type==f.pointerevents_method+"down"&&(u.value=!u.value,setTimeout(function(){d(u,
u.value)},20));break;case "string":case "text":c.type==f.pointerevents_method+"down"&&this.prompt("Value",u.value,function(a){d(this,a)}.bind(u),c,u.options?u.options.multiline:!1);break;default:u.mouse&&(this.dirty_canvas=u.mouse(c,[g,k],a))}if(e!=u.value){if(a.onWidgetChanged)a.onWidgetChanged(u.name,u.value,e,u);a.graph._version++}return u}}}return null};l.prototype.drawGroups=function(a,b){if(this.graph){a=this.graph._groups;b.save();b.globalAlpha=.5*this.editor_alpha;for(var c=0;c<a.length;++c){var e=
a[c];if(z(this.visible_area,e._bounding)){b.fillStyle=e.color||"#335";b.strokeStyle=e.color||"#335";var d=e._pos,g=e._size;b.globalAlpha=.25*this.editor_alpha;b.beginPath();b.rect(d[0]+.5,d[1]+.5,g[0],g[1]);b.fill();b.globalAlpha=this.editor_alpha;b.stroke();b.beginPath();b.moveTo(d[0]+g[0],d[1]+g[1]);b.lineTo(d[0]+g[0]-10,d[1]+g[1]);b.lineTo(d[0]+g[0],d[1]+g[1]-10);b.fill();g=e.font_size||f.DEFAULT_GROUP_FONT_SIZE;b.font=g+"px Arial";b.textAlign="left";b.fillText(e.title,d[0]+4,d[1]+g)}}b.restore()}};
l.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)};l.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)};l.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 e=setInterval(function(){b.editor_alpha*=c;b.dirty_canvas=!0;b.dirty_bgcanvas=!0;1>c&&.01>b.editor_alpha&&(clearInterval(e),1>c&&(b.live_mode=!0));1<c&&.99<b.editor_alpha&&(clearInterval(e),b.editor_alpha=1)},1)}else this.live_mode=!this.live_mode,this.dirty_bgcanvas=this.dirty_canvas=!0};l.prototype.onNodeSelectionChange=function(a){};l.onGroupAdd=function(a,b,c){a=l.active_canvas;a.getCanvasWindow();b=new f.LGraphGroup;b.pos=a.convertEventToCanvasOffset(c);
a.graph.add(b)};l.getBoundaryNodes=function(a){var b=null,c=null,e=null,d=null,g;for(g in a){var f=a[g],m=$jscomp.makeIterator(f.pos),q=m.next().value;m=m.next().value;var p=$jscomp.makeIterator(f.size),r=p.next().value;p=p.next().value;if(null===b||m<b.pos[1])b=f;if(null===c||q+r>c.pos[0]+c.size[0])c=f;if(null===e||m+p>e.pos[1]+e.size[1])e=f;if(null===d||q<d.pos[0])d=f}return{top:b,right:c,bottom:e,left:d}};l.prototype.boundaryNodesForSelection=function(){return l.getBoundaryNodes(Object.values(this.selected_nodes))};
l.alignNodes=function(a,b,c){if(a){var e=l.active_canvas;a=void 0===c?l.getBoundaryNodes(a):{top:c,right:c,bottom:c,left:c};c=$jscomp.makeIterator(Object.entries(e.selected_nodes));for(var d=c.next();!d.done;d=c.next())switch(d=$jscomp.makeIterator(d.value),d.next(),d=d.next().value,b){case "right":d.pos[0]=a.right.pos[0]+a.right.size[0]-d.size[0];break;case "left":d.pos[0]=a.left.pos[0];break;case "top":d.pos[1]=a.top.pos[1];break;case "bottom":d.pos[1]=a.bottom.pos[1]+a.bottom.size[1]-d.size[1]}e.dirty_canvas=
!0;e.dirty_bgcanvas=!0}};l.onNodeAlign=function(a,b,c,e,d){new f.ContextMenu(["Top","Bottom","Left","Right"],{event:c,callback:function(a){l.alignNodes(l.active_canvas.selected_nodes,a.toLowerCase(),d)},parentMenu:e})};l.onGroupAlign=function(a,b,c,e){new f.ContextMenu(["Top","Bottom","Left","Right"],{event:c,callback:function(a){l.alignNodes(l.active_canvas.selected_nodes,a.toLowerCase())},parentMenu:e})};l.onMenuAdd=function(a,b,c,e,d){function g(a,b){var e=[];f.getNodeTypesCategories(k.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===e.findIndex(function(a){return a.value===c})&&e.push({value:c,content:b,has_submenu:!0,callback:function(a,b,c,d){g(a.value,d)}})}});f.getNodeTypesInCategory(a.slice(0,-1),k.filter||q.filter).map(function(a){a.skip_list||e.push({value:a.type,content:a.title,has_submenu:!1,callback:function(a,b,c,e){b=
e.getFirstEvent();k.graph.beforeChange();if(a=f.createNode(a.value))a.pos=k.convertEventToCanvasOffset(b),k.graph.add(a);d&&d(a);k.graph.afterChange()}})});new f.ContextMenu(e,{event:c,parentMenu:b},m)}var k=l.active_canvas,m=k.getCanvasWindow(),q=k.graph;if(q)return g("",e),!1};l.onMenuCollapseAll=function(){};l.onMenuNodeEdit=function(){};l.showMenuNodeOptionalInputs=function(a,b,c,e,d){if(d){var g=this;a=l.active_canvas.getCanvasWindow();b=d.optional_inputs;d.onGetInputs&&(b=d.onGetInputs());var k=
[];if(b)for(var m=0;m<b.length;m++){var q=b[m];if(q){var p=q[0];q[2]||(q[2]={});q[2].label&&(p=q[2].label);q[2].removable=!0;p={content:p,value:q};q[1]==f.ACTION&&(p.className="event");k.push(p)}else k.push(null)}d.onMenuNodeInputs&&(b=d.onMenuNodeInputs(k))&&(k=b);if(k.length)return new f.ContextMenu(k,{event:c,callback:function(a,b,c){if(d&&(a.callback&&a.callback.call(g,d,a,b,c),a.value)){d.graph.beforeChange();d.addInput(a.value[0],a.value[1],a.value[2]);if(d.onNodeInputAdd)d.onNodeInputAdd(a.value);
d.setDirtyCanvas(!0,!0);d.graph.afterChange()}},parentMenu:e,node:d},a),!1;console.log("no input entries")}};l.showMenuNodeOptionalOutputs=function(a,b,c,e,d){function g(a,b,c){if(d&&(a.callback&&a.callback.call(k,d,a,b,c),a.value))if(c=a.value[1],!c||c.constructor!==Object&&c.constructor!==Array){d.graph.beforeChange();d.addOutput(a.value[0],a.value[1],a.value[2]);if(d.onNodeOutputAdd)d.onNodeOutputAdd(a.value);d.setDirtyCanvas(!0,!0);d.graph.afterChange()}else{a=[];for(var u in c)a.push({content:u,
value:c[u]});new f.ContextMenu(a,{event:b,callback:g,parentMenu:e,node:d});return!1}}if(d){var k=this;a=l.active_canvas.getCanvasWindow();b=d.optional_outputs;d.onGetOutputs&&(b=d.onGetOutputs());var m=[];if(b)for(var q=0;q<b.length;q++){var p=b[q];if(!p)m.push(null);else if(!d.flags||!d.flags.skip_repeated_outputs||-1==d.findOutputSlot(p[0])){var r=p[0];p[2]||(p[2]={});p[2].label&&(r=p[2].label);p[2].removable=!0;r={content:r,value:p};p[1]==f.EVENT&&(r.className="event");m.push(r)}}this.onMenuNodeOutputs&&
(m=this.onMenuNodeOutputs(m));f.do_add_triggers_slots&&-1==d.findOutputSlot("onExecuted")&&m.push({content:"On Executed",value:["onExecuted",f.EVENT,{nameLocked:!0}],className:"event"});d.onMenuNodeOutputs&&(b=d.onMenuNodeOutputs(m))&&(m=b);if(m.length)return new f.ContextMenu(m,{event:c,callback:g,parentMenu:e,node:d},a),!1}};l.onShowMenuNodeProperties=function(a,b,c,e,d){if(d&&d.properties){var g=l.active_canvas;b=g.getCanvasWindow();var k=[],m;for(m in d.properties){a=void 0!==d.properties[m]?
d.properties[m]:" ";"object"==typeof a&&(a=JSON.stringify(a));var q=d.getPropertyInfo(m);if("enum"==q.type||"combo"==q.type)a=l.getPropertyPrintableValue(a,q.values);a=l.decodeHTML(a);k.push({content:"<span class='property_name'>"+(q.label?q.label:m)+"</span><span class='property_value'>"+a+"</span>",value:m})}if(k.length)return new f.ContextMenu(k,{event:c,callback:function(a,b,c,e){d&&(b=this.getBoundingClientRect(),g.showEditPropertyValue(d,a.value,{position:[b.left,b.top]}))},parentMenu:e,allow_html:!0,
node:d},b),!1}};l.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};l.onMenuResizeNode=function(a,b,c,e,d){if(d){a=function(a){a.size=a.computeSize();if(a.onResize)a.onResize(a.size)};b=l.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)a(d);else for(var g in b.selected_nodes)a(b.selected_nodes[g]);d.setDirtyCanvas(!0,!0)}};l.prototype.showLinkMenu=function(a,b){var c=this,e=c.graph.getNodeById(a.origin_id),d=c.graph.getNodeById(a.target_id),
g=!1;e&&e.outputs&&e.outputs[a.origin_slot]&&(g=e.outputs[a.origin_slot].type);var k=!1;d&&d.outputs&&d.outputs[a.target_slot]&&(k=d.inputs[a.target_slot].type);var m=new f.ContextMenu(["Add Node",null,"Delete",null],{event:b,title:null!=a.data?a.data.constructor.name:null,callback:function(b,f,r){switch(b){case "Add Node":l.onMenuAdd(null,null,r,m,function(b){b.inputs&&b.inputs.length&&b.outputs&&b.outputs.length&&e.connectByType(a.origin_slot,b,g)&&(b.connectByType(a.target_slot,d,k),b.pos[0]-=
.5*b.size[0])});break;case "Delete":c.graph.removeLink(a.id)}}});return!1};l.prototype.createDefaultNodeForSlot=function(a){a=a||{};a=Object.assign({nodeFrom:null,slotFrom:null,nodeTo:null,slotTo:null,position:[],nodeType:null,posAdd:[0,0],posSizeFix:[0,0]},a);var b=a.nodeFrom&&null!==a.slotFrom,c=!b&&a.nodeTo&&null!==a.slotTo;if(!b&&!c)return console.warn("No data passed to createDefaultNodeForSlot "+a.nodeFrom+" "+a.slotFrom+" "+a.nodeTo+" "+a.slotTo),!1;if(!a.nodeType)return console.warn("No type to createDefaultNodeForSlot"),
!1;var e=b?a.nodeFrom:a.nodeTo,d=b?a.slotFrom:a.slotTo;switch(typeof d){case "string":c=b?e.findOutputSlot(d,!1):e.findInputSlot(d,!1);d=b?e.outputs[d]:e.inputs[d];break;case "object":c=b?e.findOutputSlot(d.name):e.findInputSlot(d.name);break;case "number":c=d;d=b?e.outputs[d]:e.inputs[d];break;default:return console.warn("Cant get slot information "+d),!1}!1!==d&&!1!==c||console.warn("createDefaultNodeForSlot bad slotX "+d+" "+c);e=d.type==f.EVENT?"_event_":d.type;if((d=b?f.slot_types_default_out:
f.slot_types_default_in)&&d[e]){nodeNewType=!1;if("object"==typeof d[e]||"array"==typeof d[e])for(var g in d[e]){if(a.nodeType==d[e][g]||"AUTO"==a.nodeType){nodeNewType=d[e][g];break}}else if(a.nodeType==d[e]||"AUTO"==a.nodeType)nodeNewType=d[e];if(nodeNewType){g=!1;"object"==typeof nodeNewType&&nodeNewType.node&&(g=nodeNewType,nodeNewType=nodeNewType.node);if(d=f.createNode(nodeNewType)){if(g){if(g.properties)for(var k in g.properties)d.addProperty(k,g.properties[k]);if(g.inputs)for(k in d.inputs=
[],g.inputs)d.addOutput(g.inputs[k][0],g.inputs[k][1]);if(g.outputs)for(k in d.outputs=[],g.outputs)d.addOutput(g.outputs[k][0],g.outputs[k][1]);g.title&&(d.title=g.title);g.json&&d.configure(g.json)}this.graph.add(d);d.pos=[a.position[0]+a.posAdd[0]+(a.posSizeFix[0]?a.posSizeFix[0]*d.size[0]:0),a.position[1]+a.posAdd[1]+(a.posSizeFix[1]?a.posSizeFix[1]*d.size[1]:0)];b?a.nodeFrom.connectByType(c,d,e):a.nodeTo.connectByTypeOutput(c,d,e);return!0}console.log("failed creating "+nodeNewType)}}return!1};
l.prototype.showConnectionMenu=function(a){a=a||{};var b=Object.assign({nodeFrom:null,slotFrom:null,nodeTo:null,slotTo:null,e:null},a),c=this,e=b.nodeFrom&&b.slotFrom;a=!e&&b.nodeTo&&b.slotTo;if(!e&&!a)return console.warn("No data passed to showConnectionMenu"),!1;a=e?b.nodeFrom:b.nodeTo;var d=e?b.slotFrom:b.slotTo,g=!1;switch(typeof d){case "string":g=e?a.findOutputSlot(d,!1):a.findInputSlot(d,!1);d=e?a.outputs[d]:a.inputs[d];break;case "object":g=e?a.findOutputSlot(d.name):a.findInputSlot(d.name);
break;case "number":g=d;d=e?a.outputs[d]:a.inputs[d];break;default:return console.warn("Cant get slot information "+d),!1}a=["Add Node",null];c.allow_searchbox&&(a.push("Search"),a.push(null));var k=d.type==f.EVENT?"_event_":d.type,m=e?f.slot_types_default_out:f.slot_types_default_in;if(m&&m[k])if("object"==typeof m[k]||"array"==typeof m[k])for(var q in m[k])a.push(m[k][q]);else a.push(m[k]);var p=new f.ContextMenu(a,{event:b.e,title:(d&&""!=d.name?d.name+(k?" | ":""):"")+(d&&k?k:""),callback:function(a,
f,q){switch(a){case "Add Node":l.onMenuAdd(null,null,q,p,function(a){e?b.nodeFrom.connectByType(g,a,k):b.nodeTo.connectByTypeOutput(g,a,k)});break;case "Search":e?c.showSearchBox(q,{node_from:b.nodeFrom,slot_from:d,type_filter_in:k}):c.showSearchBox(q,{node_to:b.nodeTo,slot_from:d,type_filter_out:k});break;default:c.createDefaultNodeForSlot(Object.assign(b,{position:[b.e.canvasX,b.e.canvasY],nodeType:a}))}}});return!1};l.onShowPropertyEditor=function(a,b,c,e,d){function g(){if(q){var b=q.value;"Number"==
a.type?b=Number(b):"Boolean"==a.type&&(b=!!b);d[k]=b;m.parentNode&&m.parentNode.removeChild(m);d.setDirtyCanvas(!0,!0)}}var k=a.property||"title";b=d[k];var m=document.createElement("div");m.is_modified=!1;m.className="graphdialog";m.innerHTML="<span class='name'></span><input autofocus type='text' class='value'/><button>OK</button>";m.close=function(){m.parentNode&&m.parentNode.removeChild(m)};m.querySelector(".name").innerText=k;var q=m.querySelector(".value");q&&(q.value=b,q.addEventListener("blur",
function(a){this.focus()}),q.addEventListener("keydown",function(a){m.is_modified=!0;if(27==a.keyCode)m.close();else if(13==a.keyCode)g();else if(13!=a.keyCode&&"textarea"!=a.target.localName)return;a.preventDefault();a.stopPropagation()}));b=l.active_canvas.canvas;c=b.getBoundingClientRect();var p=e=-20;c&&(e-=c.left,p-=c.top);event?(m.style.left=event.clientX+e+"px",m.style.top=event.clientY+p+"px"):(m.style.left=.5*b.width+e+"px",m.style.top=.5*b.height+p+"px");m.querySelector("button").addEventListener("click",
g);b.parentNode.appendChild(m);q&&q.focus();var r=null;m.addEventListener("mouseleave",function(a){f.dialog_close_on_mouse_leave&&!m.is_modified&&f.dialog_close_on_mouse_leave&&(r=setTimeout(m.close,f.dialog_close_on_mouse_leave_delay))});m.addEventListener("mouseenter",function(a){f.dialog_close_on_mouse_leave&&r&&clearTimeout(r)})};l.prototype.prompt=function(a,b,c,e,d){var g=this;a=a||"";var k=document.createElement("div");k.is_modified=!1;k.className="graphdialog rounded";k.innerHTML=d?"<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>";k.close=function(){g.prompt_box=null;k.parentNode&&k.parentNode.removeChild(k)};d=l.active_canvas.canvas;d.parentNode.appendChild(k);1<this.ds.scale&&(k.style.transform="scale("+this.ds.scale+")");var m=null,q=!1;f.pointerListenerAdd(k,"leave",function(a){q||f.dialog_close_on_mouse_leave&&!k.is_modified&&f.dialog_close_on_mouse_leave&&(m=setTimeout(k.close,f.dialog_close_on_mouse_leave_delay))});
f.pointerListenerAdd(k,"enter",function(a){f.dialog_close_on_mouse_leave&&m&&clearTimeout(m)});var p=k.querySelectorAll("select");p&&p.forEach(function(a){a.addEventListener("click",function(a){q++});a.addEventListener("blur",function(a){q=0});a.addEventListener("change",function(a){q=-1})});g.prompt_box&&g.prompt_box.close();g.prompt_box=k;k.querySelector(".name").innerText=a;var r=k.querySelector(".value");r.value=b;r.addEventListener("keydown",function(a){k.is_modified=!0;if(27==a.keyCode)k.close();
else if(13==a.keyCode&&"textarea"!=a.target.localName)c&&c(this.value),k.close();else return;a.preventDefault();a.stopPropagation()});k.querySelector("button").addEventListener("click",function(a){c&&c(r.value);g.setDirty(!0);k.close()});a=d.getBoundingClientRect();p=b=-20;a&&(b-=a.left,p-=a.top);e?(k.style.left=e.clientX+b+"px",k.style.top=e.clientY+p+"px"):(k.style.left=.5*d.width+b+"px",k.style.top=.5*d.height+p+"px");setTimeout(function(){r.focus()},10);return k};l.search_limit=-1;l.prototype.showSearchBox=
function(a,b){function c(c){if(c)if(g.onSearchBoxSelection)g.onSearchBoxSelection(c,a,k);else{var d=f.searchbox_extras[c.toLowerCase()];d&&(c=d.type);k.graph.beforeChange();if(c=f.createNode(c))c.pos=k.convertEventToCanvasOffset(a),k.graph.add(c,!1);if(d&&d.data){if(d.data.properties)for(var e in d.data.properties)c.addProperty(e,d.data.properties[e]);if(d.data.inputs)for(e in c.inputs=[],d.data.inputs)c.addOutput(d.data.inputs[e][0],d.data.inputs[e][1]);if(d.data.outputs)for(e in c.outputs=[],d.data.outputs)c.addOutput(d.data.outputs[e][0],
d.data.outputs[e][1]);d.data.title&&(c.title=d.data.title);d.data.json&&c.configure(d.data.json)}if(b.node_from){switch(typeof b.slot_from){case "string":d=b.node_from.findOutputSlot(b.slot_from);break;case "object":d=b.slot_from.name?b.node_from.findOutputSlot(b.slot_from.name):-1;-1==d&&"undefined"!==typeof b.slot_from.slot_index&&(d=b.slot_from.slot_index);break;case "number":d=b.slot_from;break;default:d=0}"undefined"!==typeof b.node_from.outputs[d]&&!1!==d&&-1<d&&b.node_from.connectByType(d,
c,b.node_from.outputs[d].type)}if(b.node_to){switch(typeof b.slot_from){case "string":d=b.node_to.findInputSlot(b.slot_from);break;case "object":d=b.slot_from.name?b.node_to.findInputSlot(b.slot_from.name):-1;-1==d&&"undefined"!==typeof b.slot_from.slot_index&&(d=b.slot_from.slot_index);break;case "number":d=b.slot_from;break;default:d=0}"undefined"!==typeof b.node_to.inputs[d]&&!1!==d&&-1<d&&b.node_to.connectByTypeOutput(d,c,b.node_to.inputs[d].type)}k.graph.afterChange()}p.close()}function e(a){var b=
y;y&&y.classList.remove("selected");y?(y=a?y.nextSibling:y.previousSibling)||(y=b):y=a?v.childNodes[0]:v.childNodes[v.childNodes.length];y&&(y.classList.add("selected"),y.scrollIntoView({block:"end",behavior:"smooth"}))}function d(){function a(a,b){var d=document.createElement("div");w||(w=a);d.innerText=a;d.dataset.type=escape(a);d.className="litegraph lite-search-item";b&&(d.className+=" "+b);d.addEventListener("click",function(a){c(unescape(this.dataset.type))});v.appendChild(d)}t=null;var d=x.value;
w=null;v.innerHTML="";if(d||b.show_all_if_empty)if(g.onSearchBox){var e=g.onSearchBox(v,d,k);if(e)for(var q=0;q<e.length;++q)a(e[q])}else{e=function(a,c){c=c||{};c=Object.assign({skipFilter:!1,inTypeOverride:!1,outTypeOverride:!1},c);var e=f.registered_node_types[a];if(m&&e.filter!=m||(!b.show_all_if_empty||d)&&-1===a.toLowerCase().indexOf(d))return!1;if(b.do_type_filter&&!c.skipFilter){e=p.value;!1!==c.inTypeOverride&&(e=c.inTypeOverride);if(p&&e&&f.registered_slot_in_types[e]&&f.registered_slot_in_types[e].nodes&&
(e=f.registered_slot_in_types[e].nodes.includes(a),!1===e))return!1;e=r.value;!1!==c.outTypeOverride&&(e=c.outTypeOverride);if(r&&e&&f.registered_slot_out_types[e]&&f.registered_slot_out_types[e].nodes&&(e=f.registered_slot_out_types[e].nodes.includes(a),!1===e))return!1}return!0};var u=0;d=d.toLowerCase();var m=k.filter||k.graph.filter;if(b.do_type_filter&&g.search_box)var p=g.search_box.querySelector(".slot_in_type_filter"),r=g.search_box.querySelector(".slot_out_type_filter");else r=p=!1;for(q in f.searchbox_extras){var h=
f.searchbox_extras[q];if(b.show_all_if_empty&&!d||-1!==h.desc.toLowerCase().indexOf(d)){var n=f.registered_node_types[h.type];if((!n||n.filter==m)&&e(h.type)&&(a(h.desc,"searchbox_extra"),-1!==l.search_limit&&u++>l.search_limit))break}}h=null;if(Array.prototype.filter)h=Object.keys(f.registered_node_types).filter(e);else for(q in h=[],f.registered_node_types)e(q)&&h.push(q);for(q=0;q<h.length&&!(a(h[q]),-1!==l.search_limit&&u++>l.search_limit);q++);if(b.show_general_after_typefiltered&&(p.value||
r.value)){filtered_extra=[];for(q in f.registered_node_types)e(q,{inTypeOverride:p&&p.value?"*":!1,outTypeOverride:r&&r.value?"*":!1})&&filtered_extra.push(q);for(q=0;q<filtered_extra.length&&!(a(filtered_extra[q],"generic_type"),-1!==l.search_limit&&u++>l.search_limit);q++);}if((p.value||r.value)&&0==v.childNodes.length&&b.show_general_if_none_on_typefilter){filtered_extra=[];for(q in f.registered_node_types)e(q,{skipFilter:!0})&&filtered_extra.push(q);for(q=0;q<filtered_extra.length&&!(a(filtered_extra[q],
"not_in_filter"),-1!==l.search_limit&&u++>l.search_limit);q++);}}}b=Object.assign({slot_from:null,node_from:null,node_to:null,do_type_filter:f.search_filter_enabled,type_filter_in:!1,type_filter_out:!1,show_general_if_none_on_typefilter:!0,show_general_after_typefiltered:!0,hide_on_mouse_leave:f.search_hide_on_mouse_leave,show_all_if_empty:!0,show_all_on_open:f.search_show_all_on_open},b||{});var g=this,k=l.active_canvas,m=k.canvas,q=m.ownerDocument||document,p=document.createElement("div");p.className=
"litegraph litesearchbox graphdialog rounded";p.innerHTML="<span class='name'>Search</span> <input autofocus type='text' class='value rounded'/>";b.do_type_filter&&(p.innerHTML+="<select class='slot_in_type_filter'><option value=''></option></select>",p.innerHTML+="<select class='slot_out_type_filter'><option value=''></option></select>");p.innerHTML+="<div class='helper'></div>";q.fullscreenElement?q.fullscreenElement.appendChild(p):(q.body.appendChild(p),q.body.style.overflow="hidden");if(b.do_type_filter)var r=
p.querySelector(".slot_in_type_filter"),u=p.querySelector(".slot_out_type_filter");p.close=function(){g.search_box=null;this.blur();m.focus();q.body.style.overflow="";setTimeout(function(){g.canvas.focus()},20);p.parentNode&&p.parentNode.removeChild(p)};1<this.ds.scale&&(p.style.transform="scale("+this.ds.scale+")");if(b.hide_on_mouse_leave){var h=!1,n=null;f.pointerListenerAdd(p,"enter",function(a){n&&(clearTimeout(n),n=null)});f.pointerListenerAdd(p,"leave",function(a){h||(n=setTimeout(function(){p.close()},
500))});b.do_type_filter&&(r.addEventListener("click",function(a){h++}),r.addEventListener("blur",function(a){h=0}),r.addEventListener("change",function(a){h=-1}),u.addEventListener("click",function(a){h++}),u.addEventListener("blur",function(a){h=0}),u.addEventListener("change",function(a){h=-1}))}g.search_box&&g.search_box.close();g.search_box=p;var v=p.querySelector(".helper"),w=null,t=null,y=null,x=p.querySelector("input");x&&(x.addEventListener("blur",function(a){this.focus()}),x.addEventListener("keydown",
function(a){if(38==a.keyCode)e(!1);else if(40==a.keyCode)e(!0);else if(27==a.keyCode)p.close();else if(13==a.keyCode)y?c(y.innerHTML):w?c(w):p.close();else{t&&clearInterval(t);t=setTimeout(d,250);return}a.preventDefault();a.stopPropagation();a.stopImmediatePropagation();return!0}));if(b.do_type_filter){if(r){var z=f.slot_types_in,L=z.length;if(b.type_filter_in==f.EVENT||b.type_filter_in==f.ACTION)b.type_filter_in="_event_";for(var A=0;A<L;A++){var D=document.createElement("option");D.value=z[A];D.innerHTML=
z[A];r.appendChild(D);!1!==b.type_filter_in&&(b.type_filter_in+"").toLowerCase()==(z[A]+"").toLowerCase()&&(D.selected=!0)}r.addEventListener("change",function(){d()})}if(u){z=f.slot_types_out;L=z.length;if(b.type_filter_out==f.EVENT||b.type_filter_out==f.ACTION)b.type_filter_out="_event_";for(A=0;A<L;A++)D=document.createElement("option"),D.value=z[A],D.innerHTML=z[A],u.appendChild(D),!1!==b.type_filter_out&&(b.type_filter_out+"").toLowerCase()==(z[A]+"").toLowerCase()&&(D.selected=!0);u.addEventListener("change",
function(){d()})}}r=m.getBoundingClientRect();u=(a?a.clientY:r.top+.5*r.height)-20;p.style.left=(a?a.clientX:r.left+.5*r.width)-80+"px";p.style.top=u+"px";a.layerY>r.height-200&&(v.style.maxHeight=r.height-a.layerY-20+"px");x.focus();b.show_all_on_open&&d();return p};l.prototype.showEditPropertyValue=function(a,b,c){function e(){d(u.value)}function d(d){g&&g.values&&g.values.constructor===Object&&void 0!=g.values[d]&&(d=g.values[d]);"number"==typeof a.properties[b]&&(d=Number(d));if("array"==f||"object"==
f)d=JSON.parse(d);a.properties[b]=d;a.graph&&a.graph._version++;if(a.onPropertyChanged)a.onPropertyChanged(b,d);if(c.onclose)c.onclose();r.close();a.setDirtyCanvas(!0,!0)}if(a&&void 0!==a.properties[b]){c=c||{};var g=a.getPropertyInfo(b),f=g.type,m="";if("string"==f||"number"==f||"array"==f||"object"==f)m="<input autofocus type='text' class='value'/>";else if("enum"!=f&&"combo"!=f||!g.values)if("boolean"==f||"toggle"==f)m="<input autofocus type='checkbox' class='value' "+(a.properties[b]?"checked":
"")+"/>";else{console.warn("unknown type: "+f);return}else{m="<select autofocus type='text' class='value'>";for(var q in g.values){var p=q;g.values.constructor===Array&&(p=g.values[q]);m+="<option value='"+p+"' "+(p==a.properties[b]?"selected":"")+">"+g.values[q]+"</option>"}m+="</select>"}var r=this.createDialog("<span class='name'>"+(g.label?g.label:b)+"</span>"+m+"<button>OK</button>",c),u=!1;if("enum"!=f&&"combo"!=f||!g.values)if("boolean"==f||"toggle"==f)(u=r.querySelector("input"))&&u.addEventListener("click",
function(a){r.modified();d(!!u.checked)});else{if(u=r.querySelector("input"))u.addEventListener("blur",function(a){this.focus()}),p=void 0!==a.properties[b]?a.properties[b]:"","string"!==f&&(p=JSON.stringify(p)),u.value=p,u.addEventListener("keydown",function(a){if(27==a.keyCode)r.close();else if(13==a.keyCode)e();else if(13!=a.keyCode){r.modified();return}a.preventDefault();a.stopPropagation()})}else u=r.querySelector("select"),u.addEventListener("change",function(a){r.modified();d(a.target.value)});
u&&u.focus();r.querySelector("button").addEventListener("click",e);return r}};l.prototype.createDialog=function(a,b){b=Object.assign({checkForInput:!1,closeOnLeave:!0,closeOnLeave_checkModified:!0},b||{});var c=document.createElement("div");c.className="graphdialog";c.innerHTML=a;c.is_modified=!1;a=this.canvas.getBoundingClientRect();var e=-20,d=-20;a&&(e-=a.left,d-=a.top);b.position?(e+=b.position[0],d+=b.position[1]):b.event?(e+=b.event.clientX,d+=b.event.clientY):(e+=.5*this.canvas.width,d+=.5*
this.canvas.height);c.style.left=e+"px";c.style.top=d+"px";this.canvas.parentNode.appendChild(c);b.checkForInput&&(a=[],(a=c.querySelectorAll("input"))&&a.forEach(function(a){a.addEventListener("keydown",function(a){c.modified();if(27==a.keyCode)c.close();else if(13!=a.keyCode)return;a.preventDefault();a.stopPropagation()});a.focus()}));c.modified=function(){c.is_modified=!0};c.close=function(){c.parentNode&&c.parentNode.removeChild(c)};var g=null,k=!1;c.addEventListener("mouseleave",function(a){k||
(b.closeOnLeave||f.dialog_close_on_mouse_leave)&&!c.is_modified&&f.dialog_close_on_mouse_leave&&(g=setTimeout(c.close,f.dialog_close_on_mouse_leave_delay))});c.addEventListener("mouseenter",function(a){(b.closeOnLeave||f.dialog_close_on_mouse_leave)&&g&&clearTimeout(g)});(a=c.querySelectorAll("select"))&&a.forEach(function(a){a.addEventListener("click",function(a){k++});a.addEventListener("blur",function(a){k=0});a.addEventListener("change",function(a){k=-1})});return c};l.prototype.createPanel=function(a,
b){b=b||{};var c=b.window||window,e=document.createElement("div");e.className="litegraph dialog";e.innerHTML="<div class='dialog-header'><span class='dialog-title'></span></div><div class='dialog-content'></div><div style='display:none;' class='dialog-alt-content'></div><div class='dialog-footer'></div>";e.header=e.querySelector(".dialog-header");b.width&&(e.style.width=b.width+(b.width.constructor===Number?"px":""));b.height&&(e.style.height=b.height+(b.height.constructor===Number?"px":""));b.closable&&
(b=document.createElement("span"),b.innerHTML="&#10005;",b.classList.add("close"),b.addEventListener("click",function(){e.close()}),e.header.appendChild(b));e.title_element=e.querySelector(".dialog-title");e.title_element.innerText=a;e.content=e.querySelector(".dialog-content");e.alt_content=e.querySelector(".dialog-alt-content");e.footer=e.querySelector(".dialog-footer");e.close=function(){if(e.onClose&&"function"==typeof e.onClose)e.onClose();e.parentNode&&e.parentNode.removeChild(e);this.parentNode&&
this.parentNode.removeChild(this)};e.toggleAltContent=function(a){if("undefined"!=typeof a){var b=a?"block":"none";a=a?"none":"block"}else b="block"!=e.alt_content.style.display?"block":"none",a="block"!=e.alt_content.style.display?"none":"block";e.alt_content.style.display=b;e.content.style.display=a};e.toggleFooterVisibility=function(a){e.footer.style.display="undefined"!=typeof a?a?"block":"none":"block"!=e.footer.style.display?"block":"none"};e.clear=function(){this.content.innerHTML=""};e.addHTML=
function(a,b,c){var d=document.createElement("div");b&&(d.className=b);d.innerHTML=a;c?e.footer.appendChild(d):e.content.appendChild(d);return d};e.addButton=function(a,b,c){var d=document.createElement("button");d.innerText=a;d.options=c;d.classList.add("btn");d.addEventListener("click",b);e.footer.appendChild(d);return d};e.addSeparator=function(){var a=document.createElement("div");a.className="separator";e.content.appendChild(a)};e.addWidget=function(a,b,k,m,q){function d(a,b){m.callback&&m.callback(a,
b,m);q&&q(a,b,m)}m=m||{};var g=String(k);a=a.toLowerCase();"number"==a&&(g=k.toFixed(3));var u=document.createElement("div");u.className="property";u.innerHTML="<span class='property_name'></span><span class='property_value'></span>";u.querySelector(".property_name").innerText=m.label||b;var h=u.querySelector(".property_value");h.innerText=g;u.dataset.property=b;u.dataset.type=m.type||a;u.options=m;u.value=k;if("code"==a)u.addEventListener("click",function(a){e.inner_showCodePad(this.dataset.property)});
else if("boolean"==a)u.classList.add("boolean"),k&&u.classList.add("bool-on"),u.addEventListener("click",function(){var a=this.dataset.property;this.value=!this.value;this.classList.toggle("bool-on");this.querySelector(".property_value").innerText=this.value?"true":"false";d(a,this.value)});else if("string"==a||"number"==a)h.setAttribute("contenteditable",!0),h.addEventListener("keydown",function(b){"Enter"!=b.code||"string"==a&&b.shiftKey||(b.preventDefault(),this.blur())}),h.addEventListener("blur",
function(){var a=this.innerText,b=this.parentNode.dataset.property;"number"==this.parentNode.dataset.type&&(a=Number(a));d(b,a)});else if("enum"==a||"combo"==a)g=l.getPropertyPrintableValue(k,m.values),h.innerText=g,h.addEventListener("click",function(a){var b=this.parentNode.dataset.property,e=this;new f.ContextMenu(m.values||[],{event:a,className:"dark",callback:function(a,c,f){e.innerText=a;d(b,a);return!1}},c)});e.content.appendChild(u);return u};if(e.onOpen&&"function"==typeof e.onOpen)e.onOpen();
return e};l.getPropertyPrintableValue=function(a,b){if(!b||b.constructor===Array)return String(a);if(b.constructor===Object){var c="",e;for(e in b)if(b[e]==a){c=e;break}return String(a)+" ("+c+")"}};l.prototype.closePanels=function(){var a=document.querySelector("#node-panel");a&&a.close();(a=document.querySelector("#option-panel"))&&a.close()};l.prototype.showShowGraphOptionsPanel=function(a,b,c,e){if(this.constructor&&"HTMLDivElement"==this.constructor.name){if(!(b&&b.event&&b.event.target&&b.event.target.lgraphcanvas)){console.warn("Canvas not found");
return}var d=b.event.target.lgraphcanvas}else d=this;d.closePanels();a=d.getCanvasWindow();panel=d.createPanel("Options",{closable:!0,window:a,onOpen:function(){d.OPTIONPANEL_IS_OPEN=!0},onClose:function(){d.OPTIONPANEL_IS_OPEN=!1;d.options_panel=null}});d.options_panel=panel;panel.id="option-panel";panel.classList.add("settings");(function(){panel.content.innerHTML="";var a=function(a,b,c){c&&c.key&&(a=c.key);c.values&&(b=Object.values(c.values).indexOf(b));d[a]=b},b=f.availableCanvasOptions;b.sort();
for(var c in b){var e=b[c];panel.addWidget("boolean",e,d[e],{key:e,on:"True",off:"False"},a)}panel.addWidget("combo","Render mode",f.LINK_RENDER_MODES[d.links_render_mode],{key:"links_render_mode",values:f.LINK_RENDER_MODES},a);panel.addSeparator();panel.footer.innerHTML=""})();d.canvas.parentNode.appendChild(panel)};l.prototype.showShowNodePanel=function(a){function b(){d.content.innerHTML="";d.addHTML("<span class='node_type'>"+a.type+"</span><span class='node_desc'>"+(a.constructor.desc||"")+"</span><span class='separator'></span>");
d.addHTML("<h3>Properties</h3>");var b=function(b,c){e.graph.beforeChange(a);switch(b){case "Title":a.title=c;break;case "Mode":b=Object.values(f.NODE_MODES).indexOf(c);0<=b&&f.NODE_MODES[b]?a.changeMode(b):console.warn("unexpected mode: "+c);break;case "Color":l.node_colors[c]?(a.color=l.node_colors[c].color,a.bgcolor=l.node_colors[c].bgcolor):console.warn("unexpected color: "+c);break;default:a.setProperty(b,c)}e.graph.afterChange();e.dirty_canvas=!0};d.addWidget("string","Title",a.title,{},b);
d.addWidget("combo","Mode",f.NODE_MODES[a.mode],{values:f.NODE_MODES},b);var c="";void 0!==a.color&&(c=Object.keys(l.node_colors).filter(function(b){return l.node_colors[b].color==a.color}));d.addWidget("combo","Color",c,{values:Object.keys(l.node_colors)},b);for(var m in a.properties){c=a.properties[m];var q=a.getPropertyInfo(m);a.onAddPropertyToPanel&&a.onAddPropertyToPanel(m,d)||d.addWidget(q.widget||q.type,m,c,q,b)}d.addSeparator();if(a.onShowCustomPanelInfo)a.onShowCustomPanelInfo(d);d.footer.innerHTML=
"";d.addButton("Delete",function(){a.block_delete||(a.graph.remove(a),d.close())}).classList.add("delete")}this.SELECTED_NODE=a;this.closePanels();var c=this.getCanvasWindow(),e=this,d=this.createPanel(a.title||"",{closable:!0,window:c,onOpen:function(){e.NODEPANEL_IS_OPEN=!0},onClose:function(){e.NODEPANEL_IS_OPEN=!1;e.node_panel=null}});e.node_panel=d;d.id="node-panel";d.node=a;d.classList.add("settings");d.inner_showCodePad=function(c){d.classList.remove("settings");d.classList.add("centered");
d.alt_content.innerHTML="<textarea class='code'></textarea>";var e=d.alt_content.querySelector("textarea"),f=function(){d.toggleAltContent(!1);d.toggleFooterVisibility(!0);e.parentNode.removeChild(e);d.classList.add("settings");d.classList.remove("centered");b()};e.value=a.properties[c];e.addEventListener("keydown",function(b){"Enter"==b.code&&b.ctrlKey&&(a.setProperty(c,e.value),f())});d.toggleAltContent(!0);d.toggleFooterVisibility(!1);e.style.height="calc(100% - 40px)";var g=d.addButton("Assign",
function(){a.setProperty(c,e.value);f()});d.alt_content.appendChild(g);g=d.addButton("Close",f);g.style.float="right";d.alt_content.appendChild(g)};b();this.canvas.parentNode.appendChild(d)};l.prototype.showSubgraphPropertiesDialog=function(a){function b(){e.clear();if(a.inputs)for(var c=0;c<a.inputs.length;++c){var f=a.inputs[c];if(!f.not_subgraph_input){var k=e.addHTML("<button>&#10005;</button> <span class='bullet_icon'></span><span class='name'></span><span class='type'></span>","subgraph_property");
k.dataset.name=f.name;k.dataset.slot=c;k.querySelector(".name").innerText=f.name;k.querySelector(".type").innerText=f.type;k.querySelector("button").addEventListener("click",function(c){a.removeInput(Number(this.parentNode.dataset.slot));b()})}}}console.log("showing subgraph properties dialog");var c=this.canvas.parentNode.querySelector(".subgraph_dialog");c&&c.close();var e=this.createPanel("Subgraph Inputs",{closable:!0,width:500});e.node=a;e.classList.add("subgraph_dialog");e.addHTML(" + <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(e);return e};l.prototype.showSubgraphPropertiesDialogRight=function(a){function b(){d.clear();if(a.outputs)for(var c=0;c<a.outputs.length;++c){var e=a.outputs[c];if(!e.not_subgraph_output){var f=
d.addHTML("<button>&#10005;</button> <span class='bullet_icon'></span><span class='name'></span><span class='type'></span>","subgraph_property");f.dataset.name=e.name;f.dataset.slot=c;f.querySelector(".name").innerText=e.name;f.querySelector(".type").innerText=e.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 e=this.canvas.parentNode.querySelector(".subgraph_dialog");e&&e.close();var d=this.createPanel("Subgraph Outputs",{closable:!0,width:500});d.node=a;d.classList.add("subgraph_dialog");e=d.addHTML(" + <span class='label'>Name</span><input class='name'/><span class='label'>Type</span><input class='type'></input><button>+</button>","subgraph_property extra",!0);e.querySelector(".name").addEventListener("keydown",
function(a){13==a.keyCode&&c.apply(this)});e.querySelector("button").addEventListener("click",function(a){c.apply(this)});b();this.canvas.parentNode.appendChild(d);return d};l.prototype.checkPanels=function(){if(this.canvas)for(var a=this.canvas.parentNode.querySelectorAll(".litegraph.dialog"),b=0;b<a.length;++b){var c=a[b];c.node&&(c.node.graph&&c.graph==this.graph||c.close())}};l.onMenuNodeCollapse=function(a,b,c,e,d){d.graph.beforeChange();a=l.active_canvas;if(!a.selected_nodes||1>=Object.keys(a.selected_nodes).length)d.collapse();
else for(var f in a.selected_nodes)a.selected_nodes[f].collapse();d.graph.afterChange()};l.onMenuNodePin=function(a,b,c,e,d){d.pin()};l.onMenuNodeMode=function(a,b,c,e,d){new f.ContextMenu(f.NODE_MODES,{event:c,callback:function(a){if(d){var b=Object.values(f.NODE_MODES).indexOf(a),c=function(c){0<=b&&f.NODE_MODES[b]?c.changeMode(b):(console.warn("unexpected mode: "+a),c.changeMode(f.ALWAYS))},e=l.active_canvas;if(!e.selected_nodes||1>=Object.keys(e.selected_nodes).length)c(d);else for(var g in e.selected_nodes)c(e.selected_nodes[g])}},
parentMenu:e,node:d});return!1};l.onMenuNodeColors=function(a,b,c,e,d){if(!d)throw"no node for color";b=[];b.push({value:null,content:"<span style='display: block; padding-left: 4px;'>No color</span>"});for(var g in l.node_colors)a=l.node_colors[g],a={value:g,content:"<span style='display: block; color: #999; padding-left: 4px; border-left: 8px solid "+a.color+"; background-color:"+a.bgcolor+"'>"+g+"</span>"},b.push(a);new f.ContextMenu(b,{event:c,callback:function(a){if(d){var b=a.value?l.node_colors[a.value]:
null;a=function(a){b?a.constructor===f.LGraphGroup?a.color=b.groupcolor:(a.color=b.color,a.bgcolor=b.bgcolor):(delete a.color,delete a.bgcolor)};var c=l.active_canvas;if(!c.selected_nodes||1>=Object.keys(c.selected_nodes).length)a(d);else for(var e in c.selected_nodes)a(c.selected_nodes[e]);d.setDirtyCanvas(!0,!0)}},parentMenu:e,node:d});return!1};l.onMenuNodeShapes=function(a,b,c,e,d){if(!d)throw"no node passed";new f.ContextMenu(f.VALID_SHAPES,{event:c,callback:function(a){if(d){d.graph.beforeChange();
var b=l.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)d.shape=a;else for(var c in b.selected_nodes)b.selected_nodes[c].shape=a;d.graph.afterChange();d.setDirtyCanvas(!0)}},parentMenu:e,node:d});return!1};l.onMenuNodeRemove=function(a,b,c,e,d){if(!d)throw"no node passed";a=d.graph;a.beforeChange();b=l.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)!1!==d.removable&&a.remove(d);else for(var f in b.selected_nodes)c=b.selected_nodes[f],!1!==c.removable&&
a.remove(c);a.afterChange();d.setDirtyCanvas(!0,!0)};l.onMenuNodeToSubgraph=function(a,b,c,e,d){a=d.graph;if(b=l.active_canvas)c=Object.values(b.selected_nodes||{}),c.length||(c=[d]),e=f.createNode("graph/subgraph"),e.pos=d.pos.concat(),a.add(e),e.buildFromNodes(c),b.deselectAllNodes(),d.setDirtyCanvas(!0,!0)};l.onMenuNodeClone=function(a,b,c,e,d){d.graph.beforeChange();var f={};a=function(a){if(!1!==a.clonable){var b=a.clone();b&&(b.pos=[a.pos[0]+5,a.pos[1]+5],a.graph.add(b),f[b.id]=b)}};b=l.active_canvas;
if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)a(d);else for(var k in b.selected_nodes)a(b.selected_nodes[k]);Object.keys(f).length&&b.selectNodes(f);d.graph.afterChange();d.setDirtyCanvas(!0,!0)};l.node_colors={red:{color:"#322",bgcolor:"#533",groupcolor:"#A88"},brown:{color:"#332922",bgcolor:"#593930",groupcolor:"#b06634"},green:{color:"#232",bgcolor:"#353",groupcolor:"#8A8"},blue:{color:"#223",bgcolor:"#335",groupcolor:"#88A"},pale_blue:{color:"#2a363b",bgcolor:"#3f5159",groupcolor:"#3f789e"},
cyan:{color:"#233",bgcolor:"#355",groupcolor:"#8AA"},purple:{color:"#323",bgcolor:"#535",groupcolor:"#a1309b"},yellow:{color:"#432",bgcolor:"#653",groupcolor:"#b58b2a"},black:{color:"#222",bgcolor:"#000",groupcolor:"#444"}};l.prototype.getCanvasMenuOptions=function(){if(this.getMenuOptions)var a=this.getMenuOptions();else a=[{content:"Add Node",has_submenu:!0,callback:l.onMenuAdd},{content:"Add Group",callback:l.onGroupAdd}],1<Object.keys(this.selected_nodes).length&&a.push({content:"Align",has_submenu:!0,
callback:l.onGroupAlign}),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};l.prototype.getNodeMenuOptions=function(a){if(a.getMenuOptions)var b=a.getMenuOptions(this);else b=[{content:"Inputs",has_submenu:!0,disabled:!0,callback:l.showMenuNodeOptionalInputs},{content:"Outputs",has_submenu:!0,disabled:!0,callback:l.showMenuNodeOptionalOutputs},
null,{content:"Properties",has_submenu:!0,callback:l.onShowMenuNodeProperties},null,{content:"Title",callback:l.onShowPropertyEditor},{content:"Mode",has_submenu:!0,callback:l.onMenuNodeMode}],!1!==a.resizable&&b.push({content:"Resize",callback:l.onMenuResizeNode}),b.push({content:"Collapse",callback:l.onMenuNodeCollapse},{content:"Pin",callback:l.onMenuNodePin},{content:"Colors",has_submenu:!0,callback:l.onMenuNodeColors},{content:"Shapes",has_submenu:!0,callback:l.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:l.onMenuNodeClone});1<Object.keys(this.selected_nodes).length&&b.push({content:"Align Selected To",has_submenu:!0,callback:l.onNodeAlign});b.push(null,{content:"Remove",disabled:!(!1!==a.removable&&!a.block_delete),callback:l.onMenuNodeRemove});if(a.graph&&
a.graph.onGetNodeMenuOptions)a.graph.onGetNodeMenuOptions(b,a);return b};l.prototype.getGroupMenuOptions=function(a){return[{content:"Title",callback:l.onShowPropertyEditor},{content:"Color",has_submenu:!0,callback:l.onMenuNodeColors},{content:"Font size",property:"font_size",type:"Number",callback:l.onShowPropertyEditor},null,{content:"Remove",callback:l.onMenuNodeRemove}]};l.prototype.processContextMenu=function(a,b){var c=this,e=l.active_canvas.getCanvasWindow(),d=null,g={event:b,callback:function(b,
d,e){if(b)if("Remove Slot"==b.content)b=b.slot,a.graph.beforeChange(),b.input?a.removeInput(b.slot):b.output&&a.removeOutput(b.slot),a.graph.afterChange();else if("Disconnect Links"==b.content)b=b.slot,a.graph.beforeChange(),b.output?a.disconnectOutput(b.slot):b.input&&a.disconnectInput(b.slot),a.graph.afterChange();else if("Rename Slot"==b.content){b=b.slot;var f=b.input?a.getInputInfo(b.slot):a.getOutputInfo(b.slot),g=c.createDialog("<span class='name'>Name</span><input autofocus type='text'/><button>OK</button>",
d),q=g.querySelector("input");q&&f&&(q.value=f.label||"");var p=function(){a.graph.beforeChange();q.value&&(f&&(f.label=q.value),c.setDirty(!0));g.close();a.graph.afterChange()};g.querySelector("button").addEventListener("click",p);q.addEventListener("keydown",function(a){g.is_modified=!0;if(27==a.keyCode)g.close();else if(13==a.keyCode)p();else if(13!=a.keyCode&&"textarea"!=a.target.localName)return;a.preventDefault();a.stopPropagation()});q.focus()}},extra:a};a&&(g.title=a.type);var k=null;a&&(k=
a.getSlotInPosition(b.canvasX,b.canvasY),l.active_node=a);k?(d=[],a.getSlotMenuOptions?d=a.getSlotMenuOptions(k):(k&&k.output&&k.output.links&&k.output.links.length&&d.push({content:"Disconnect Links",slot:k}),b=k.input||k.output,b.removable&&d.push(b.locked?"Cannot remove":{content:"Remove Slot",slot:k}),b.nameLocked||d.push({content:"Rename Slot",slot:k})),g.title=(k.input?k.input.type:k.output.type)||"*",k.input&&k.input.type==f.ACTION&&(g.title="Action"),k.output&&k.output.type==f.EVENT&&(g.title=
"Event")):a?d=this.getNodeMenuOptions(a):(d=this.getCanvasMenuOptions(),(k=this.graph.getGroupOnPos(b.canvasX,b.canvasY))&&d.push(null,{content:"Edit Group",has_submenu:!0,submenu:{title:"Group",extra:k,options:this.getGroupMenuOptions(k)}}));d&&new f.ContextMenu(d,g,e)};f.compareObjects=function(a,b){for(var c in a)if(a[c]!=b[c])return!1;return!0};f.distance=E;f.colorToString=function(a){return"rgba("+Math.round(255*a[0]).toFixed()+","+Math.round(255*a[1]).toFixed()+","+Math.round(255*a[2]).toFixed()+
","+(4==a.length?a[3].toFixed(2):"1.0")+")"};f.isInsideRectangle=B;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=z;f.hex2num=function(a){"#"==a.charAt(0)&&(a=a.slice(1));a=a.toUpperCase();for(var b=Array(3),c=0,e,d,f=0;6>f;f+=2)e="0123456789ABCDEF".indexOf(a.charAt(f)),d="0123456789ABCDEF".indexOf(a.charAt(f+1)),b[c]=16*e+d,c++;return b};
f.num2hex=function(a){for(var b="#",c,e,d=0;3>d;d++)c=a[d]/16,e=a[d]%16,b+="0123456789ABCDEF".charAt(c)+"0123456789ABCDEF".charAt(e);return b};F.prototype.addItem=function(a,b,c){function e(a){var b=this.value;b&&b.has_submenu&&d.call(this,a)}function d(a){var b=this.value,d=!0;g.current_submenu&&g.current_submenu.close(a);if(c.callback){var e=c.callback.call(this,b,c,a,g,c.node);!0===e&&(d=!1)}if(b&&(b.callback&&!c.ignore_item_callbacks&&!0!==b.disabled&&(e=b.callback.call(this,b,c,a,g,c.extra),
!0===e&&(d=!1)),b.submenu)){if(!b.submenu.options)throw"ContextMenu submenu needs options";new g.constructor(b.submenu.options,{callback:b.submenu.callback,event:a,parentMenu:g,ignore_item_callbacks:b.submenu.ignore_item_callbacks,title:b.submenu.title,extra:b.submenu.extra,autoopen:c.autoopen});d=!1}d&&!g.lock&&g.close()}var g=this;c=c||{};var k=document.createElement("div");k.className="litemenu-entry submenu";var m=!1;if(null===b)k.classList.add("separator");else{k.innerHTML=b&&b.title?b.title:
a;if(k.value=b)b.disabled&&(m=!0,k.classList.add("disabled")),(b.submenu||b.has_submenu)&&k.classList.add("has_submenu");"function"==typeof b?(k.dataset.value=a,k.onclick_callback=b):k.dataset.value=b;b.className&&(k.className+=" "+b.className)}this.root.appendChild(k);m||k.addEventListener("click",d);!m&&c.autoopen&&f.pointerListenerAdd(k,"enter",e);return k};F.prototype.close=function(a,b){this.root.parentNode&&this.root.parentNode.removeChild(this.root);this.parentMenu&&!b&&(this.parentMenu.lock=
!1,this.parentMenu.current_submenu=null,void 0===a?this.parentMenu.close():a&&!F.isCursorOverElement(a,this.parentMenu.root)&&F.trigger(this.parentMenu.root,f.pointerevents_method+"leave",a));this.current_submenu&&this.current_submenu.close(a,!0);this.root.closing_timer&&clearTimeout(this.root.closing_timer)};F.trigger=function(a,b,c,e){var d=document.createEvent("CustomEvent");d.initCustomEvent(b,!0,!0,c);d.srcElement=e;a.dispatchEvent?a.dispatchEvent(d):a.__events&&a.__events.dispatchEvent(d);return d};
F.prototype.getTopMenu=function(){return this.options.parentMenu?this.options.parentMenu.getTopMenu():this};F.prototype.getFirstEvent=function(){return this.options.parentMenu?this.options.parentMenu.getFirstEvent():this.options.event};F.isCursorOverElement=function(a,b){var c=a.clientX;a=a.clientY;return(b=b.getBoundingClientRect())?a>b.top&&a<b.top+b.height&&c>b.left&&c<b.left+b.width?!0:!1:!1};f.ContextMenu=F;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)))};G.sampleCurve=function(a,b){if(b){for(var c=0;c<b.length-1;++c){var e=b[c],d=b[c+1];if(!(d[0]<a)){b=d[0]-e[0];if(1E-5>Math.abs(b))return e[1];a=(a-e[0])/b;return e[1]*(1-a)+d[1]*a}}return 0}};G.prototype.draw=function(a,b,c,e,d,f){if(c=this.points){this.size=b;var g=b[0]-2*this.margin;b=b[1]-2*this.margin;d=d||"#666";a.save();a.translate(this.margin,this.margin);e&&(a.fillStyle="#111",a.fillRect(0,0,g,b),a.fillStyle="#222",a.fillRect(.5*g,0,1,b),a.strokeStyle="#333",
a.strokeRect(0,0,g,b));a.strokeStyle=d;f&&(a.globalAlpha=.5);a.beginPath();for(e=0;e<c.length;++e)d=c[e],a.lineTo(d[0]*g,(1-d[1])*b);a.stroke();a.globalAlpha=1;if(!f)for(e=0;e<c.length;++e)d=c[e],a.fillStyle=this.selected==e?"#FFF":this.nearest==e?"#DDD":"#AAA",a.beginPath(),a.arc(d[0]*g,(1-d[1])*b,2,0,2*Math.PI),a.fill();a.restore()}};G.prototype.onMouseDown=function(a,b){var c=this.points;if(c&&!(0>a[1])){var e=this.size[0]-2*this.margin,d=this.size[1]-2*this.margin,f=a[0]-this.margin;a=a[1]-this.margin;
this.selected=this.getCloserPoint([f,a],30/b.ds.scale);-1==this.selected&&(b=[f/e,1-a/d],c.push(b),c.sort(function(a,b){return a[0]-b[0]}),this.selected=c.indexOf(b),this.must_update=!0);if(-1!=this.selected)return!0}};G.prototype.onMouseMove=function(a,b){var c=this.points;if(c){var e=this.selected;if(!(0>e)){var d=(a[0]-this.margin)/(this.size[0]-2*this.margin),f=(a[1]-this.margin)/(this.size[1]-2*this.margin);this._nearest=this.getCloserPoint([a[0]-this.margin,a[1]-this.margin],30/b.ds.scale);
if(b=c[e]){var k=0==e||e==c.length-1;!k&&(-10>a[0]||a[0]>this.size[0]+10||-10>a[1]||a[1]>this.size[1]+10)?(c.splice(e,1),this.selected=-1):(b[0]=k?0==e?0:1:J(d,0,1),b[1]=1-J(f,0,1),c.sort(function(a,b){return a[0]-b[0]}),this.selected=c.indexOf(b),this.must_update=!0)}}}};G.prototype.onMouseUp=function(a,b){this.selected=-1;return!1};G.prototype.getCloserPoint=function(a,b){var c=this.points;if(!c)return-1;b=b||30;for(var e=this.size[0]-2*this.margin,d=this.size[1]-2*this.margin,f=c.length,k=[0,0],
m=1E6,q=-1,p=0;p<f;++p){var h=c[p];k[0]=h[0]*e;k[1]=(1-h[1])*d;h=vec2.distance(a,k);h>m||h>b||(q=p,m=h)}return q};f.CurveEditor=G;f.getParameterNames=function(a){return(a+"").replace(/[/][/].*$/gm,"").replace(/\s+/g,"").replace(/[/][*][^/*]*[*][/]/g,"").split("){",1)[0].replace(/^[^(]*[(]/,"").replace(/=[^,]+/g,"").split(",").filter(Boolean)};f.pointerListenerAdd=function(a,b,c,e){e=void 0===e?!1:e;if(a&&a.addEventListener&&b&&"function"===typeof c){var d=f.pointerevents_method;if("pointer"==d&&!window.PointerEvent)switch(console.warn("sMethod=='pointer' && !window.PointerEvent"),
console.log("Converting pointer["+b+"] : down move up cancel enter TO touchstart touchmove touchend, etc .."),b){case "down":d="touch";b="start";break;case "move":d="touch";break;case "up":d="touch";b="end";break;case "cancel":d="touch";break;case "enter":console.log("debug: Should I send a move event?");break;default:console.warn("PointerEvent not available in this browser ? The event "+b+" would not be called")}switch(b){case "down":case "up":case "move":case "over":case "out":case "enter":a.addEventListener(d+
b,c,e);case "leave":case "cancel":case "gotpointercapture":case "lostpointercapture":if("mouse"!=d)return a.addEventListener(d+b,c,e);default:return a.addEventListener(b,c,e)}}};f.pointerListenerRemove=function(a,b,c,e){e=void 0===e?!1:e;if(a&&a.removeEventListener&&b&&"function"===typeof c)switch(b){case "down":case "up":case "move":case "over":case "out":case "enter":"pointer"!=f.pointerevents_method&&"mouse"!=f.pointerevents_method||a.removeEventListener(f.pointerevents_method+b,c,e);case "leave":case "cancel":case "gotpointercapture":case "lostpointercapture":if("pointer"==
f.pointerevents_method)return a.removeEventListener(f.pointerevents_method+b,c,e);default:return a.removeEventListener(b,c,e)}};x.clamp=J;"undefined"==typeof window||window.requestAnimationFrame||(window.requestAnimationFrame=window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(a){window.setTimeout(a,1E3/60)})})(this);
"undefined"!=typeof exports&&(exports.LiteGraph=this.LiteGraph,exports.LGraph=this.LGraph,exports.LLink=this.LLink,exports.LGraphNode=this.LGraphNode,exports.LGraphGroup=this.LGraphGroup,exports.DragAndScale=this.DragAndScale,exports.LGraphCanvas=this.LGraphCanvas,exports.ContextMenu=this.ContextMenu);
(function(x){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 m.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 w(){this.addInput("","");this.name_in_graph="";this.properties={name:"",type:""};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 y(){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 l(){this.addOutput("bool","boolean");this.addProperty("value",!0);this.widget=this.addWidget("toggle","value",!0,"value");this.widgets_up=this.serialize_widgets=!0;this.size=[140,30]}function E(){this.addOutput("string","string");
this.addProperty("value","");this.widget=this.addWidget("text","value","","value");this.widgets_up=!0;this.size=[180,30]}function B(){this.addOutput("obj","object");this.size=[120,30];this._object={}}function z(){this.addInput("url","string");this.addOutput("file","string");this.addProperty("url","");this.addProperty("type","text");this.widget=this.addWidget("text","url","","url");this._data=null}function F(){this.addOutput("data","object");this.addProperty("value","");this.widget=this.addWidget("text",
"json","","value");this.widgets_up=!0;this.size=[140,30];this._value=null}function G(){this._value=[];this.addInput("json","");this.addOutput("arrayOut","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 J(){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",{precision:0,step:10,min:0})}function f(){this.addInput("array","array,table,string");this.addInput("index","number");this.addOutput("value","");this.addProperty("index",0)}function L(){this.addInput("table","table");this.addInput("row","number");this.addInput("col","number");this.addOutput("value","");this.addProperty("row",0);this.addProperty("column",0)}function D(){this.addInput("obj","object");this.addOutput("property",0);this.addProperty("value",0);this.widget=
this.addWidget("text","prop.","",this.setValue.bind(this));this.widgets_up=!0;this.size=[140,30];this._value=null}function A(){this.addInput("obj","");this.addOutput("keys","array");this.size=[140,30]}function M(){this.addInput("obj","");this.addInput("value","");this.addOutput("obj","");this.properties={property:""};this.name_widget=this.addWidget("text","prop.",this.properties.property,"property")}function C(){this.addInput("A","object");this.addInput("B","object");this.addOutput("out","object");
this._result={};var a=this;this.addWidget("button","clear","",function(){a._result={}});this.size=this.computeSize()}function H(){this.size=[60,30];this.addInput("in");this.addOutput("out");this.properties={varname:"myname",container:H.LITEGRAPH};this.value=null}function N(a){return a&&null!=a.length?Number(a.length):0}function N(a){return a&&null!=a.length?Number(a.length):0}function a(){this.size=[60,30];this.addInput("data",0);this.addInput("download",m.ACTION);this.properties={filename:"data.json"};
this.value=null;var a=this;this.addWidget("button","Download","",function(b){a.value&&a.downloadAsFile()})}function b(){this.size=[60,30];this.addInput("value",0,{label:""});this.value=0}function c(){this.addInput("in",0);this.addOutput("out",0);this.size=[40,30]}function e(){this.mode=m.ON_EVENT;this.size=[80,30];this.addProperty("msg","");this.addInput("log",m.EVENT);this.addInput("msg",0)}function d(){this.mode=m.ON_EVENT;this.addProperty("msg","");this.addInput("",m.EVENT);this.widget=this.addWidget("text",
"Text","","msg");this.widgets_up=!0;this.size=[200,30]}function g(){this.size=[60,30];this.addProperty("onExecute","return A;");this.addInput("A",0);this.addInput("B",0);this.addOutput("out",0);this._func=null;this.data={}}function k(){this.addInput("A",0);this.addInput("B",0);this.addOutput("true","boolean");this.addOutput("false","boolean");this.addProperty("A",1);this.addProperty("B",1);this.addProperty("OP","==","enum",{values:k.values});this.addWidget("combo","Op.",this.properties.OP,{property:"OP",
values:k.values});this.size=[80,60]}var m=x.LiteGraph;n.title="Time";n.desc="Time";n.prototype.onExecute=function(){this.setOutputData(0,1E3*this.graph.globaltime);this.setOutputData(1,this.graph.globaltime)};m.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]-m.NODE_TITLE_HEIGHT+.5,c=m.isInsideRectangle(d[0],d[1],this.pos[0],this.pos[1]+b,this.size[0],m.NODE_TITLE_HEIGHT),d=m.isInsideRectangle(d[0],d[1],this.pos[0],this.pos[1]+b,this.size[0]/2,m.NODE_TITLE_HEIGHT),a.fillStyle=c?"#555":"#222",a.beginPath(),this._shape==m.BOX_SHAPE?d?a.rect(0,b,this.size[0]/2+1,m.NODE_TITLE_HEIGHT):a.rect(this.size[0]/2,b,this.size[0]/2+1,m.NODE_TITLE_HEIGHT):d?a.roundRect(0,b,this.size[0]/
2+1,m.NODE_TITLE_HEIGHT,[0,0,8,8]):a.roundRect(this.size[0]/2,b,this.size[0]/2+1,m.NODE_TITLE_HEIGHT,[0,0,8,8]),c?a.fill():a.fillRect(0,b,this.size[0]+1,m.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]-m.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)*m.NODE_SLOT_HEIGHT+m.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.findOutputSlot(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=m.LGraphNode.prototype.serialize.call(this);a.subgraph=this.subgraph.serialize();return a};t.prototype.reassignSubgraphUUIDs=function(a){for(var b={},
c={},d=$jscomp.makeIterator(a.nodes),e=d.next();!e.done;e=d.next()){e=e.value;var f=e.id,g=m.uuidv4();e.id=g;if(b[f]||b[g])throw Error("New/old node UUID wasn't unique in changed map! "+f+" "+g);b[f]=g;b[g]=f}d=$jscomp.makeIterator(a.links);for(e=d.next();!e.done;e=d.next()){e=e.value;f=e[0];g=m.uuidv4();e[0]=g;if(c[f]||c[g])throw Error("New/old link UUID wasn't unique in changed map! "+f+" "+g);c[f]=g;c[g]=f;f=e[1];g=e[3];if(!b[f])throw Error("Old node UUID not found in mapping! "+f);e[1]=b[f];if(!b[g])throw Error("Old node UUID not found in mapping! "+
g);e[3]=b[g]}d=$jscomp.makeIterator(a.nodes);for(e=d.next();!e.done;e=d.next()){e=e.value;if(e.inputs)for(f=$jscomp.makeIterator(e.inputs),g=f.next();!g.done;g=f.next())g=g.value,g.link&&(g.link=c[g.link]);if(e.outputs)for(e=$jscomp.makeIterator(e.outputs),f=e.next();!f.done;f=e.next())f=f.value,f.links&&(f.links=f.links.map(function(a){return c[a]}))}a=$jscomp.makeIterator(a.nodes);for(e=a.next();!e.done;e=a.next())d=e.value,"graph/subgraph"===d.type&&(d=reassignGraphUUIDs(d.subgraph),b.assign(d.nodeIDs),
c.assign(d.linkIDs))};t.prototype.clone=function(){var a=m.createNode(this.type),b=this.serialize();if(m.use_uuids){var c=m.cloneObject(b.subgraph);this.reassignSubgraphUUIDs(c);b.subgraph=c}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 g=d.graph.links[f.link];g&&(b[g.origin_id]||
this.subgraph.addInput(f.name,g.type))}}if(d.outputs)for(e=0;e<d.outputs.length;++e)if((f=d.outputs[e])&&f.links&&f.links.length)for(var k=0;k<f.links.length&&(!(g=d.graph.links[f.links[k]])||b[g.target_id]);++k);}};m.Subgraph=t;m.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&&(m.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==m.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)};m.GraphInput=h;m.registerNodeType("graph/input",h);w.title="Output";w.desc="Output of the graph";w.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()};w.prototype.updateType=function(){var a=this.properties.type;this.type_widget&&(this.type_widget.value=a);if(this.inputs[0].type!=a){if("action"==a||"event"==a)a=m.EVENT;m.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)};w.prototype.onExecute=function(){this._value=
this.getInputData(0);this.graph.setOutputData(this.properties.name,this._value)};w.prototype.onAction=function(a,b){this.properties.type==m.ACTION&&this.graph.trigger(this.properties.name,b)};w.prototype.onRemoved=function(){this.name_in_graph&&this.graph.removeOutput(this.name_in_graph)};w.prototype.getTitle=function(){return this.flags.collapsed?this.properties.name:this.title};m.GraphOutput=w;m.registerNodeType("graph/output",w);y.title="Const Number";y.desc="Constant number";y.prototype.onExecute=
function(){this.setOutputData(0,parseFloat(this.properties.value))};y.prototype.getTitle=function(){return this.flags.collapsed?this.properties.value:this.title};y.prototype.setValue=function(a){this.setProperty("value",a)};y.prototype.onDrawBackground=function(a){this.outputs[0].label=this.properties.value.toFixed(3)};m.registerNodeType("basic/const",y);l.title="Const Boolean";l.desc="Constant boolean";l.prototype.getTitle=y.prototype.getTitle;l.prototype.onExecute=function(){this.setOutputData(0,
this.properties.value)};l.prototype.setValue=y.prototype.setValue;l.prototype.onGetInputs=function(){return[["toggle",m.ACTION]]};l.prototype.onAction=function(a){this.setValue(!this.properties.value)};m.registerNodeType("basic/boolean",l);E.title="Const String";E.desc="Constant string";E.prototype.getTitle=y.prototype.getTitle;E.prototype.onExecute=function(){this.setOutputData(0,this.properties.value)};E.prototype.setValue=y.prototype.setValue;E.prototype.onDropFile=function(a){var b=this,c=new FileReader;
c.onload=function(a){b.setProperty("value",a.target.result)};c.readAsText(a)};m.registerNodeType("basic/string",E);B.title="Const Object";B.desc="Constant Object";B.prototype.onExecute=function(){this.setOutputData(0,this._object)};m.registerNodeType("basic/object",B);z.title="Const File";z.desc="Fetches a file from an url";z["@type"]={type:"enum",values:["text","arraybuffer","blob","json"]};z.prototype.onPropertyChanged=function(a,b){"url"==a&&(null==b||""==b?this._data=null:this.fetchFile(b))};
z.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)};z.prototype.setValue=y.prototype.setValue;z.prototype.fetchFile=function(a){var b=this;a&&a.constructor===String?(this._url=a,this._type=this.properties.type,"http"==a.substr(0,4)&&m.proxy&&(a=m.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)};z.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)};m.registerNodeType("basic/file",z);F.title="Const Data";F.desc="Constant Data";F.prototype.onPropertyChanged=function(a,b){this.widget.value=b;if(null!=b&&""!=b)try{this._value=JSON.parse(b),this.boxcolor="#AEA"}catch(r){this.boxcolor="red"}};
F.prototype.onExecute=function(){this.setOutputData(0,this._value)};F.prototype.setValue=y.prototype.setValue;m.registerNodeType("basic/data",F);G.title="Const Array";G.desc="Constant Array";G.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(r){this.boxcolor="red"}};G.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)};G.prototype.setValue=y.prototype.setValue;m.registerNodeType("basic/array",G);J.title="Set Array";J.desc="Sets index of array";J.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))}};m.registerNodeType("basic/set_array",
J);f.title="Array[i]";f.desc="Returns an element from an array";f.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))])};m.registerNodeType("basic/array[]",f);L.title="Table[row][col]";L.desc="Returns an element from a table";L.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))};m.registerNodeType("basic/table[][]",L);D.title="Object property";D.desc="Outputs the property of an object";D.prototype.setValue=function(a){this.properties.value=a;this.widget.value=a};D.prototype.getTitle=function(){return this.flags.collapsed?"in."+this.properties.value:this.title};D.prototype.onPropertyChanged=function(a,b){this.widget.value=
b};D.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,a[this.properties.value])};m.registerNodeType("basic/object_property",D);A.title="Object keys";A.desc="Outputs an array with the keys of an object";A.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,Object.keys(a))};m.registerNodeType("basic/object_keys",A);M.title="Set Object";M.desc="Adds propertiesrty to object";M.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))}};m.registerNodeType("basic/set_object",M);C.title="Merge Objects";C.desc="Creates an object copying properties from others";C.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)};m.registerNodeType("basic/merge_objects",C);H.title="Variable";H.desc=
"store/read variable value";H.LITEGRAPH=0;H.GRAPH=1;H.GLOBALSCOPE=2;H["@container"]={type:"enum",values:{litegraph:H.LITEGRAPH,graph:H.GRAPH,global:H.GLOBALSCOPE}};H.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])};H.prototype.getContainer=function(){switch(this.properties.container){case H.GRAPH:return this.graph?
this.graph.vars:{};case H.GLOBALSCOPE:return x;default:return m.Globals}};H.prototype.getTitle=function(){return this.properties.varname};m.registerNodeType("basic/variable",H);m.wrapFunctionAsNode("basic/length",N,[""],"number");m.wrapFunctionAsNode("basic/not",function(a){return!a},[""],"boolean");a.title="Download";a.desc="Download some data";a.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)}};a.prototype.onAction=function(a,b){var c=this;setTimeout(function(){c.downloadAsFile()},100)};a.prototype.onExecute=function(){this.inputs[0]&&(this.value=this.getInputData(0))};a.prototype.getTitle=function(){return this.flags.collapsed?
this.properties.filename:this.title};m.registerNodeType("basic/download",a);b.title="Watch";b.desc="Show value of input";b.prototype.onExecute=function(){this.inputs[0]&&(this.value=this.getInputData(0))};b.prototype.getTitle=function(){return this.flags.collapsed?this.inputs[0].label:this.title};b.toString=function(a){if(null==a)return"null";if(a.constructor===Number)return a.toFixed(3);if(a.constructor===Array){for(var c="[",d=0;d<a.length;++d)c+=b.toString(a[d])+(d+1!=a.length?",":"");return c+
"]"}return String(a)};b.prototype.onDrawBackground=function(a){this.inputs[0].label=b.toString(this.value)};m.registerNodeType("basic/watch",b);c.title="Cast";c.desc="Allows to connect different types";c.prototype.onExecute=function(){this.setOutputData(0,this.getInputData(0))};m.registerNodeType("basic/cast",c);e.title="Console";e.desc="Show value inside the console";e.prototype.onAction=function(a,b){var c=this.getInputData(1);c||(c=this.properties.msg);c||(c="Event: "+b);"log"==a?console.log(c):
"warn"==a?console.warn(c):"error"==a&&console.error(c)};e.prototype.onExecute=function(){var a=this.getInputData(1);a||(a=this.properties.msg);null!=a&&"undefined"!=typeof a&&(this.properties.msg=a,console.log(a))};e.prototype.onGetInputs=function(){return[["log",m.ACTION],["warn",m.ACTION],["error",m.ACTION]]};m.registerNodeType("basic/console",e);d.title="Alert";d.desc="Show an alert window";d.color="#510";d.prototype.onConfigure=function(a){this.widget.value=a.properties.msg};d.prototype.onAction=
function(a,b){var c=this.properties.msg;setTimeout(function(){alert(c)},10)};m.registerNodeType("basic/alert",d);g.prototype.onConfigure=function(a){a.properties.onExecute&&m.allow_scripts?this.compileCode(a.properties.onExecute):console.warn("Script not compiled, LiteGraph.allow_scripts is false")};g.title="Script";g.desc="executes a code (max 256 characters)";g.widgets_info={onExecute:{type:"code"}};g.prototype.onPropertyChanged=function(a,b){"onExecute"==a&&m.allow_scripts?this.compileCode(b):
console.warn("Script not compiled, LiteGraph.allow_scripts is false")};g.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(K){console.error("Error parsing script"),console.error(K)}}};g.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(u){console.error("Error in script"),console.error(u)}};g.prototype.onGetOutputs=function(){return[["C",""]]};m.registerNodeType("basic/script",g);k.values=["==","!="];k["@OP"]={type:"enum",title:"operation",values:k.values};k.title="Compare *";k.desc="evaluates condition between A and B";k.prototype.getTitle=function(){return"*A "+this.properties.OP+
" *B"};k.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=!1;if(typeof a==typeof b)switch(this.properties.OP){case "==":case "!=":c=!0;switch(typeof a){case "object":var d=Object.getOwnPropertyNames(a),e=Object.getOwnPropertyNames(b);if(d.length!=e.length){c=!1;break}for(e=0;e<d.length;e++){var f=d[e];if(a[f]!==b[f]){c=!1;break}}break;default:c=a==b}"!="==
this.properties.OP&&(c=!c)}this.setOutputData(0,c);this.setOutputData(1,!c)};m.registerNodeType("basic/CompareValues",k)})(this);
(function(x){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 h=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(){h.addInput("",
f.ACTION);h.addOutput("",f.EVENT)});this.size=[90,70];this.flags={horizontal:!0,render_box:!1}}function w(){var h=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(){h.addOutput("",f.EVENT,{removable:!0})});this.size=[120,120];this.flags={render_box:!1}}
function y(){this.size=[60,30];this.addInput("event",f.ACTION);this.addOutput("event",f.EVENT);this.properties={equal_to:"",has_property:"",property_equal_to:""}}function l(){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 E(){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.addProperty("doCountExecution",!1,"boolean",{name:"Count Executions"});this.addWidget("toggle","Count Exec.",this.properties.doCountExecution,"doCountExecution");this.num=0}function B(){this.size=[60,30];this.addProperty("time_in_ms",1E3);this.addInput("event",f.ACTION);this.addOutput("on_time",f.EVENT);this._pending=[]}function z(){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 F(){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 h=this;this.addWidget("button","reset","",function(){h._ready=!1})}function G(){this.addInput("in",f.ACTION);this.addInput("reset",f.ACTION);this.addOutput("out",f.EVENT);this._once=!1;this.properties={};var h=this;this.addWidget("button","reset","",function(){h._once=!1})}function J(){this.addInput("data",
0);this.addInput("assign",f.ACTION);this.addOutput("data",0);this._last_value=null;this.properties={data:null,serialize:!0};var h=this;this.addWidget("button","store","",function(){h.properties.data=h._last_value})}var f=x.LiteGraph;n.title="Log Event";n.desc="Log event in console";n.prototype.onAction=function(f,h,l){console.log(f,h)};f.registerNodeType("events/log",n);t.title="TriggerEvent";t.desc="Triggers event if input evaluates to true";t.prototype.onExecute=function(f,h){var l=this.getInputData(0),
n=l!=this.prev;0===this.prev&&(n=!1);var w=n&&this.properties.only_on_change||!n&&!this.properties.only_on_change;l&&w&&this.triggerSlot(0,f,null,h);!l&&w&&this.triggerSlot(2,f,null,h);n&&this.triggerSlot(1,f,null,h);this.prev=l};f.registerNodeType("events/trigger",t);h.title="Sequence";h.desc="Triggers a sequence of events when an event arrives";h.prototype.getTitle=function(){return""};h.prototype.onAction=function(f,h,l){if(this.outputs){l=l||{};for(var n=0;n<this.outputs.length;++n)l.action_call=
l.action_call?l.action_call+"_seq_"+n:this.id+"_"+(f?f:"action")+"_seq_"+n+"_"+Math.floor(9999*Math.random()),this.triggerSlot(n,h,null,l)}};f.registerNodeType("events/sequence",h);w.title="Stepper";w.desc="Trigger events sequentially when an tick arrives";w.prototype.onDrawBackground=function(h){if(!this.flags.collapsed){var l=this.properties.index||0;h.fillStyle="#AFB";var n=this.size[0];l=(l+1)*f.NODE_SLOT_HEIGHT+4;h.beginPath();h.moveTo(n-30,l);h.lineTo(n-30,l+f.NODE_SLOT_HEIGHT);h.lineTo(n-15,
l+.5*f.NODE_SLOT_HEIGHT);h.fill()}};w.prototype.onExecute=function(){var f=this.getInputData(0);null!=f&&(f=Math.floor(f),f=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)};w.prototype.onAction=function(f,h){"reset"==f?this.properties.index=0:"step"==f&&(this.triggerSlot(this.properties.index+1,h),this.properties.index=(this.properties.index+1)%(this.outputs?this.outputs.length-1:
0))};f.registerNodeType("events/stepper",w);y.title="Filter Event";y.desc="Blocks events that do not match the filter";y.prototype.onAction=function(f,h,l){if(null!=h&&(!this.properties.equal_to||this.properties.equal_to==h)){if(this.properties.has_property&&(f=h[this.properties.has_property],null==f||this.properties.property_equal_to&&this.properties.property_equal_to!=f))return;this.triggerSlot(0,h,null,l)}};f.registerNodeType("events/filter",y);l.title="Branch";l.desc="If condition is true, outputs triggers true, otherwise false";
l.prototype.onExecute=function(){this._value=this.getInputData(1)};l.prototype.onAction=function(f,h,l){this._value=this.getInputData(1);this.triggerSlot(this._value?0:1,h,null,l)};f.registerNodeType("events/branch",l);E.title="Counter";E.desc="Counts events";E.prototype.getTitle=function(){return this.flags.collapsed?String(this.num):this.title};E.prototype.onAction=function(f,h,l){h=this.num;"inc"==f?this.num+=1:"dec"==f?--this.num:"reset"==f&&(this.num=0);this.num!=h&&this.trigger("change",this.num)};
E.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]))};E.prototype.onExecute=function(){this.properties.doCountExecution&&(this.num+=1);this.setOutputData(1,this.num)};f.registerNodeType("events/counter",E);B.title="Delay";B.desc="Delays one event";B.prototype.onAction=function(f,h,l){f=this.properties.time_in_ms;0>=f?this.trigger(null,h,l):this._pending.push([f,h])};B.prototype.onExecute=
function(f,h){f=1E3*this.graph.elapsed_time;this.isInputConnected(1)&&(this.properties.time_in_ms=this.getInputData(1));for(var l=0;l<this._pending.length;++l){var n=this._pending[l];n[0]-=f;0<n[0]||(this._pending.splice(l,1),--l,this.trigger(null,n[1],h))}};B.prototype.onGetInputs=function(){return[["event",f.ACTION],["time_in_ms","number"]]};f.registerNodeType("events/delay",B);z.title="Timer";z.desc="Sends an event every N milliseconds";z.prototype.onStart=function(){this.time=0};z.prototype.getTitle=
function(){return"Timer: "+this.last_interval.toString()+"ms"};z.on_color="#AAA";z.off_color="#222";z.prototype.onDrawBackground=function(){this.boxcolor=this.triggered?z.on_color:z.off_color;this.triggered=!1};z.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))};z.prototype.onGetInputs=function(){return[["interval","number"]]};z.prototype.onGetOutputs=function(){return[["tick","boolean"]]};f.registerNodeType("events/timer",z);F.title="Semaphore Event";F.desc="Until both events are not triggered, it doesnt continue.";F.prototype.onExecute=function(){this.setOutputData(1,this._ready);
this.boxcolor=this._ready?"#9F9":"#FA5"};F.prototype.onAction=function(f,h){"go"==f?this.triggerSlot(this._ready?0:1):"green"==f?this._ready=!0:"red"==f&&(this._ready=!1)};f.registerNodeType("events/semaphore",F);G.title="Once";G.desc="Only passes an event once, then gets locked";G.prototype.onAction=function(f,h){"in"!=f||this._once?"reset"==f&&(this._once=!1):(this._once=!0,this.triggerSlot(0,h))};f.registerNodeType("events/once",G);J.title="Data Store";J.desc="Stores data and only changes when event is received";
J.prototype.onExecute=function(){this._last_value=this.getInputData(0);this.setOutputData(0,this.properties.data)};J.prototype.onAction=function(f,h,l){this.properties.data=this._last_value};J.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",J)})(this);
(function(x){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=x.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(),w=this.properties.threshold||0;h&&(this._left_axis[0]=Math.abs(h.xbox.axes.lx)>w?h.xbox.axes.lx:0,this._left_axis[1]=Math.abs(h.xbox.axes.ly)>w?h.xbox.axes.ly:0,this._right_axis[0]=Math.abs(h.xbox.axes.rx)>w?h.xbox.axes.rx:0,this._right_axis[1]=Math.abs(h.xbox.axes.ry)>w?h.xbox.axes.ry:0,this._triggers[0]=Math.abs(h.xbox.axes.ltrigger)>w?h.xbox.axes.ltrigger:
0,this._triggers[1]=Math.abs(h.xbox.axes.rtrigger)>w?h.xbox.axes.rtrigger:0);if(this.outputs)for(w=0;w<this.outputs.length;w++){var t=this.outputs[w];if(t.links&&t.links.length){var l=null;if(h)switch(t.name){case "left_axis":l=this._left_axis;break;case "right_axis":l=this._right_axis;break;case "left_x_axis":l=this._left_axis[0];break;case "left_y_axis":l=this._left_axis[1];break;case "right_x_axis":l=this._right_axis[0];break;case "right_y_axis":l=this._right_axis[1];break;case "trigger_left":l=
this._triggers[0];break;case "trigger_right":l=this._triggers[1];break;case "a_button":l=h.xbox.buttons.a?1:0;break;case "b_button":l=h.xbox.buttons.b?1:0;break;case "x_button":l=h.xbox.buttons.x?1:0;break;case "y_button":l=h.xbox.buttons.y?1:0;break;case "lb_button":l=h.xbox.buttons.lb?1:0;break;case "rb_button":l=h.xbox.buttons.rb?1:0;break;case "ls_button":l=h.xbox.buttons.ls?1:0;break;case "rs_button":l=h.xbox.buttons.rs?1:0;break;case "hat_left":l=h.xbox.hatmap&n.LEFT;break;case "hat_right":l=
h.xbox.hatmap&n.RIGHT;break;case "hat_up":l=h.xbox.hatmap&n.UP;break;case "hat_down":l=h.xbox.hatmap&n.DOWN;break;case "hat":l=h.xbox.hatmap;break;case "start_button":l=h.xbox.buttons.start?1:0;break;case "back_button":l=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(w,n.buttons[t])}else switch(t.name){case "button_pressed":break;case "left_axis":case "right_axis":l=n.zero;break;
default:l=0}this.setOutputData(w,l)}}};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 w=this.properties.gamepad_index;4>w;w++)if(h[w]){h=h[w];w=this.xbox_mapping;w||(w=this.xbox_mapping={axes:[],
buttons:{},hat:"",hatmap:n.CENTER});w.axes.lx=h.axes[0];w.axes.ly=h.axes[1];w.axes.rx=h.axes[2];w.axes.ry=h.axes[3];w.axes.ltrigger=h.buttons[6].value;w.axes.rtrigger=h.buttons[7].value;w.hat="";w.hatmap=n.CENTER;for(var t=0;t<h.buttons.length;t++)if(this._current_buttons[t]=h.buttons[t].pressed,12>t)w.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&&(w.hat+="up",w.hatmap|=n.UP);
break;case 13:h.buttons[t].pressed&&(w.hat+="down",w.hatmap|=n.DOWN);break;case 14:h.buttons[t].pressed&&(w.hat+="left",w.hatmap|=n.LEFT);break;case 15:h.buttons[t].pressed&&(w.hat+="right",w.hatmap|=n.RIGHT);break;case 16:w.buttons.home=h.buttons[t].pressed}h.xbox=w;return h}};n.prototype.onDrawBackground=function(h){if(!this.flags.collapsed){var n=this._left_axis,t=this._right_axis;h.strokeStyle="#88A";h.strokeRect(.5*(n[0]+1)*this.size[0]-4,.5*(n[1]+1)*this.size[1]-4,8,8);h.strokeStyle="#8A8";
h.strokeRect(.5*(t[0]+1)*this.size[0]-4,.5*(t[1]+1)*this.size[1]-4,8,8);n=this.size[1]/this._current_buttons.length;h.fillStyle="#AEB";for(t=0;t<this._current_buttons.length;++t)this._current_buttons[t]&&h.fillRect(0,n*t,6,n)}};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(x){function n(){this.addInput("in",0);this.addOutput("out",0);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 w(){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 y(){this.addOutput("value","number");this.addProperty("min",0);this.addProperty("max",1);this.size=[80,30]}function l(){this.addInput("in","number");this.addOutput("out","number");this.addProperty("min",0);this.addProperty("max",1);this.addProperty("smooth",!0);this.addProperty("seed",0);this.addProperty("octaves",1);this.addProperty("persistence",.8);this.addProperty("speed",1);this.size=[90,30]}function E(){this.addOutput("out","number");this.addProperty("min_time",
1);this.addProperty("max_time",2);this.addProperty("duration",.2);this.size=[90,30];this._blink_time=this._remaining_time=0}function B(){this.addInput("in","number");this.addOutput("out","number");this.size=[80,30];this.addProperty("min",0);this.addProperty("max",1)}function z(){this.properties={f:.5};this.addInput("A","number");this.addInput("B","number");this.addOutput("out","number")}function F(){this.addInput("in","number");this.addOutput("out","number");this.size=[80,30]}function G(){this.addInput("in",
"number");this.addOutput("out","number");this.size=[80,30]}function J(){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];this.properties={A:0,B:1}}function L(){this.addInput("in","number",{label:""});this.addOutput("out","number",{label:""});this.size=[80,30];this.addProperty("factor",1)}function D(){this.addInput("v","boolean");this.addInput("A");this.addInput("B");this.addOutput("out")}
function A(){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 M(){this.addInput("in","number");this.addOutput("out","number");this.addProperty("factor",.1);this.size=[80,30];this._value=null}function C(){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:C.values});this._func=C.funcs[this.properties.OP];this._result=[]}function H(){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 N(){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:N.values});this.addWidget("combo",
"Cond.",this.properties.OP,{property:"OP",values:N.values});this.size=[80,60]}function a(){this.addInput("in",0);this.addInput("cond","boolean");this.addOutput("true",0);this.addOutput("false",0);this.size=[80,60]}function b(){this.addInput("inc","number");this.addOutput("total","number");this.addProperty("increment",1);this.addProperty("value",0)}function c(){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",r.allow_scripts,function(a){r.allow_scripts=a});this._func=null}function d(){this.addInput("vec2","vec2");this.addOutput("x","number");this.addOutput("y","number")}function g(){this.addInputs([["x","number"],["y","number"]]);
this.addOutput("vec2","vec2");this.properties={x:0,y:0};this._data=new Float32Array(2)}function k(){this.addInput("vec3","vec3");this.addOutput("x","number");this.addOutput("y","number");this.addOutput("z","number")}function m(){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 q(){this.addInput("vec4","vec4");this.addOutput("x","number");this.addOutput("y","number");this.addOutput("z",
"number");this.addOutput("w","number")}function p(){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 r=x.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"]]};r.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)};r.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))};r.registerNodeType("math/to_number",h);w.title="Range";w.desc="Convert a number from one range to another";w.prototype.getTitle=function(){return this.flags.collapsed?(this._last_v||0).toFixed(2):this.title};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)}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,clamp(this._last_v,b,d))};w.prototype.onDrawBackground=function(a){this.outputs[0].label=this._last_v?this._last_v.toFixed(3):"?"};w.prototype.onGetInputs=function(){return[["in_min",
"number"],["in_max","number"],["out_min","number"],["out_max","number"]]};r.registerNodeType("math/range",w);y.title="Rand";y.desc="Random number";y.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)};y.prototype.onDrawBackground=function(a){this.outputs[0].label=(this._last_v||
0).toFixed(3)};y.prototype.onGetInputs=function(){return[["min","number"],["max","number"]]};r.registerNodeType("math/rand",y);l.title="Noise";l.desc="Random number with temporal continuity";l.data=null;l.getValue=function(a,b){if(!l.data){l.data=new Float32Array(1024);for(var c=0;c<l.data.length;++c)l.data[c]=Math.random()}a%=1024;0>a&&(a+=1024);var d=Math.floor(a);a-=d;c=l.data[d];d=l.data[1023==d?0:d+1];b&&(a=a*a*a*(a*(6*a-15)+10));return c*(1-a)+d*a};l.prototype.onExecute=function(){var a=this.getInputData(0)||
0,b=this.properties.octaves||1,c=0,d=1;a+=this.properties.seed||0;for(var e=this.properties.speed||1,f=0,g=0;g<b&&!(c+=l.getValue(a*(1+g)*e,this.properties.smooth)*d,f+=d,d*=this.properties.persistence,.001>d);++g);a=this.properties.min;this._last_v=c/f*(this.properties.max-a)+a;this.setOutputData(0,this._last_v)};l.prototype.onDrawBackground=function(a){this.outputs[0].label=(this._last_v||0).toFixed(3)};r.registerNodeType("math/noise",l);E.title="Spikes";E.desc="spike every random time";E.prototype.onExecute=
function(){var a=this.graph.elapsed_time;this._remaining_time-=a;this._blink_time-=a;a=0;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)};r.registerNodeType("math/spikes",E);B.title="Clamp";B.desc="Clamp number between min and max";
B.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))};B.prototype.getCode=function(a){a="";this.isInputConnected(0)&&(a+="clamp({{0}},"+this.properties.min+","+this.properties.max+")");return a};r.registerNodeType("math/clamp",B);z.title="Lerp";z.desc="Linear Interpolation";z.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)};z.prototype.onGetInputs=function(){return[["f","number"]]};r.registerNodeType("math/lerp",z);F.title="Abs";F.desc="Absolute";F.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,Math.abs(a))};r.registerNodeType("math/abs",F);G.title="Floor";G.desc="Floor number to remove fractional part";G.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,
Math.floor(a))};r.registerNodeType("math/floor",G);J.title="Frac";J.desc="Returns fractional part";J.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,a%1)};r.registerNodeType("math/frac",J);f.title="Smoothstep";f.desc="Smoothstep";f.prototype.onExecute=function(){var a=this.getInputData(0);if(void 0!==a){var b=this.properties.A;a=clamp((a-b)/(this.properties.B-b),0,1);this.setOutputData(0,a*a*(3-2*a))}};r.registerNodeType("math/smoothstep",f);L.title="Scale";
L.desc="v * factor";L.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,a*this.properties.factor)};r.registerNodeType("math/scale",L);D.title="Gate";D.desc="if v is true, then outputs A, otherwise B";D.prototype.onExecute=function(){var a=this.getInputData(0);this.setOutputData(0,this.getInputData(a?1:2))};r.registerNodeType("math/gate",D);A.title="Average";A.desc="Average Filter";A.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)};A.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))};r.registerNodeType("math/average",A);M.title="TendTo";M.desc="moves the output value always closer to the input";
M.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)};r.registerNodeType("math/tendTo",M);C.values="+ - * / % ^ max min".split(" ");C.funcs={"+":function(a,b){return a+b},"-":function(a,b){return a-b},x:function(a,b){return a*b},X:function(a,b){return a*b},"*":function(a,b){return a*b},"/":function(a,b){return a/b},"%":function(a,b){return a%b},"^":function(a,
b){return Math.pow(a,b)},max:function(a,b){return Math.max(a,b)},min:function(a,b){return Math.min(a,b)}};C.title="Operation";C.desc="Easy math operators";C["@OP"]={type:"enum",title:"operation",values:C.values};C.size=[100,60];C.prototype.getTitle=function(){return"max"==this.properties.OP||"min"==this.properties.OP?this.properties.OP+"(A,B)":"A "+this.properties.OP+" B"};C.prototype.setValue=function(a){"string"==typeof a&&(a=parseFloat(a));this.properties.value=a};C.prototype.onPropertyChanged=
function(a,b){"OP"==a&&(this._func=C.funcs[this.properties.OP],this._func||(console.warn("Unknown operation: "+this.properties.OP),this._func=function(a){return a}))};C.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;var c=C.funcs[this.properties.OP];if(a.constructor===Number)var d=c(a,b);else if(a.constructor===Array){d=this._result;d.length=a.length;
for(var e=0;e<a.length;++e)d[e]=c(a[e],b)}else for(e in d={},a)d[e]=c(a[e],b);this.setOutputData(0,d)};C.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]+r.NODE_TITLE_HEIGHT)),a.textAlign="left")};r.registerNodeType("math/operation",C);r.registerSearchboxExtra("math/operation","MAX",{properties:{OP:"max"},title:"MAX()"});r.registerSearchboxExtra("math/operation",
"MIN",{properties:{OP:"min"},title:"MIN()"});H.title="Compare";H.desc="compares between two values";H.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)}}};H.prototype.onGetOutputs=function(){return[["A==B","boolean"],["A!=B","boolean"],["A>B","boolean"],["A<B","boolean"],["A>=B","boolean"],["A<=B","boolean"]]};r.registerNodeType("math/compare",H);r.registerSearchboxExtra("math/compare","==",{outputs:[["A==B","boolean"]],title:"A==B"});r.registerSearchboxExtra("math/compare","!=",{outputs:[["A!=B","boolean"]],title:"A!=B"});r.registerSearchboxExtra("math/compare",">",{outputs:[["A>B","boolean"]],
title:"A>B"});r.registerSearchboxExtra("math/compare","<",{outputs:[["A<B","boolean"]],title:"A<B"});r.registerSearchboxExtra("math/compare",">=",{outputs:[["A>=B","boolean"]],title:"A>=B"});r.registerSearchboxExtra("math/compare","<=",{outputs:[["A<=B","boolean"]],title:"A<=B"});N.values="> < == != <= >= || &&".split(" ");N["@OP"]={type:"enum",title:"operation",values:N.values};N.title="Condition";N.desc="evaluates condition between A and B";N.prototype.getTitle=function(){return"A "+this.properties.OP+
" B"};N.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)};r.registerNodeType("math/condition",N);a.title=
"Branch";a.desc="If condition is true, outputs IN in true, otherwise in false";a.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))};r.registerNodeType("math/branch",a);b.title="Accumulate";b.desc="Increments a value every time";b.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)};r.registerNodeType("math/accumulate",b);c.title="Trigonometry";c.desc="Sin Cos Tan";c.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)}};c.prototype.onGetInputs=function(){return[["v","number"],["amplitude","number"],["offset","number"]]};c.prototype.onGetOutputs=function(){return[["sin","number"],["cos","number"],["tan","number"],["asin","number"],["acos","number"],["atan","number"]]};
r.registerNodeType("math/trigonometry",c);r.registerSearchboxExtra("math/trigonometry","SIN()",{outputs:[["sin","number"]],title:"SIN()"});r.registerSearchboxExtra("math/trigonometry","COS()",{outputs:[["cos","number"]],title:"COS()"});r.registerSearchboxExtra("math/trigonometry","TAN()",{outputs:[["tan","number"]],title:"TAN()"});e.title="Formula";e.desc="Compute formula";e.size=[160,100];A.prototype.onPropertyChanged=function(a,b){"formula"==a&&(this.code_widget.value=b)};e.prototype.onExecute=
function(){if(r.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(v){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)};r.registerNodeType("math/formula",e);d.title="Vec2->XY";d.desc="vector 2 to components";d.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&(this.setOutputData(0,a[0]),this.setOutputData(1,a[1]))};r.registerNodeType("math3d/vec2-to-xy",d);g.title="XY->Vec2";g.desc="components to vector2";g.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)};r.registerNodeType("math3d/xy-to-vec2",g);k.title="Vec3->XYZ";k.desc="vector 3 to components";k.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]))};r.registerNodeType("math3d/vec3-to-xyz",k);m.title="XYZ->Vec3";m.desc="components to vector3";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.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)};r.registerNodeType("math3d/xyz-to-vec3",m);q.title="Vec4->XYZW";q.desc="vector 4 to components";q.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]))};r.registerNodeType("math3d/vec4-to-xyzw",q);p.title="XYZW->Vec4";p.desc="components to vector4";p.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=this.properties.x);var b=this.getInputData(1);null==b&&(b=this.properties.y);var c=this.getInputData(2);null==c&&(c=this.properties.z);var d=this.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)};r.registerNodeType("math3d/xyzw-to-vec4",p)})(this);
(function(x){function n(){this.addInput("","string");this.addOutput("table","table");this.addOutput("rows","number");this.addProperty("value","");this.addProperty("separator",",");this._table=null}x=x.LiteGraph;x.wrapFunctionAsNode("string/toString",function(n){if(n&&n.constructor===Object)try{return JSON.stringify(n)}catch(h){}return String(n)},[""],"string");x.wrapFunctionAsNode("string/compare",function(n,h){return n==h},["string","string"],"boolean");x.wrapFunctionAsNode("string/concatenate",
function(n,h){return void 0===n?h:void 0===h?n:n+h},["string","string"],"string");x.wrapFunctionAsNode("string/contains",function(n,h){return void 0===n||void 0===h?!1:-1!=n.indexOf(h)},["string","string"],"boolean");x.wrapFunctionAsNode("string/toUpperCase",function(n){return null!=n&&n.constructor===String?n.toUpperCase():n},["string"],"string");x.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 t=[],y=0;y<n.length;++y)"string"==typeof n[y]&&(t[y]=n[y].split(h||" "));return t}return null},["string,array","string"],"array",{separator:","});x.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(n){return n.trim().split(h)});this.setOutputData(0,this._table);this.setOutputData(1,this._table?this._table.length:0)}};x.registerNodeType("string/toTable",n)})(this);
(function(x){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(",")}function h(){this.properties={};this.addInput("a","boolean");this.addInput("b","boolean");this.addOutput("out","boolean")}function w(){this.properties=
{};this.addInput("a","boolean");this.addInput("b","boolean");this.addOutput("out","boolean")}function y(){this.properties={};this.addInput("in","boolean");this.addOutput("out","boolean")}function l(){this.properties={};this.addInput("a","boolean");this.addInput("b","boolean");this.addOutput("out","boolean")}function E(){this.properties={};this.addInput("onTrigger",B.ACTION);this.addInput("condition","boolean");this.addOutput("true",B.EVENT);this.addOutput("false",B.EVENT);this.mode=B.ON_TRIGGER}var B=
x.LiteGraph;n.title="Selector";n.desc="selects an output";n.prototype.onDrawBackground=function(h){if(!this.flags.collapsed){h.fillStyle="#AFB";var l=(this.selected+1)*B.NODE_SLOT_HEIGHT+6;h.beginPath();h.moveTo(50,l);h.lineTo(50,l+B.NODE_SLOT_HEIGHT);h.lineTo(34,l+.5*B.NODE_SLOT_HEIGHT);h.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]]};B.registerNodeType("logic/selector",n);t.title="Sequence";t.desc="select one element from a sequence from a string";t.prototype.onPropertyChanged=function(h,l){"sequence"==h&&(this.values=l.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])};B.registerNodeType("logic/sequence",t);h.title="AND";h.desc="Return true if all inputs are true";h.prototype.onExecute=function(){var h=!0,l;for(l in this.inputs)if(!this.getInputData(l)){h=!1;break}this.setOutputData(0,h)};h.prototype.onGetInputs=function(){return[["and","boolean"]]};B.registerNodeType("logic/AND",h);w.title="OR";w.desc="Return true if at least one input is true";w.prototype.onExecute=function(){var h=!1,l;for(l in this.inputs)if(this.getInputData(l)){h=
!0;break}this.setOutputData(0,h)};w.prototype.onGetInputs=function(){return[["or","boolean"]]};B.registerNodeType("logic/OR",w);y.title="NOT";y.desc="Return the logical negation";y.prototype.onExecute=function(){var h=!this.getInputData(0);this.setOutputData(0,h)};B.registerNodeType("logic/NOT",y);l.title="bool == bool";l.desc="Compare for logical equality";l.prototype.onExecute=function(){var h=null,l=!0,n;for(n in this.inputs)if(null===h)h=this.getInputData(n);else if(h!=this.getInputData(n)){l=
!1;break}this.setOutputData(0,l)};l.prototype.onGetInputs=function(){return[["bool","boolean"]]};B.registerNodeType("logic/CompareBool",l);E.title="Branch";E.desc="Branch execution on condition";E.prototype.onExecute=function(h,l){this.getInputData(1)?this.triggerSlot(0):this.triggerSlot(1)};B.registerNodeType("logic/IF",E)})(this);
(function(x){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=x.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,l=1;l<this.inputs.length;++l){var t=this.getInputData(l);if(null!=t){try{var x=JSON.stringify({type:0,room:h,channel:l,data:t})}catch(z){continue}n&&this._last_sent_data[l]==x||(this._last_sent_data[l]=x,this._ws.send(x))}}for(l=1;l<this.outputs.length;++l)this.setOutputData(l,
this._last_received_data[l]);"#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(l){n.boxcolor="#AFA";l=JSON.parse(l.data);if(!l.room||l.room==n.properties.room)if(1==l.type)if(l.data.object_class&&h[l.data.object_class]){var t=null;try{t=new h[l.data.object_class](l.data),n.triggerSlot(0,
t)}catch(B){}}else n.triggerSlot(0,l.data);else n._last_received_data[l.channel||0]=l.data};this._ws.onerror=function(h){console.log("couldnt connect to websocket");n.boxcolor="#E88"};this._ws.onclose=function(h){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 l=this.getInputData(n),t=this._last_sent_data[n];if(null!=l){if(h){var x=!0;if(l&&l.length&&t&&t.length==l.length&&l.constructor!==String)for(var z=0;z<l.length;++z){if(t[z]!=l[z]){x=!1;break}}else this._last_sent_data[n]!=
l&&(x=!1);if(x)continue}this._server.sendMessage({type:0,channel:n,data:l});if(l.length&&l.constructor!==String)if(this._last_sent_data[n])for(this._last_sent_data[n].length=l.length,z=0;z<l.length;++z)this._last_sent_data[n][z]=l[z];else this._last_sent_data[n]=l.constructor===Array?l.concat():new l.constructor(l);else this._last_sent_data[n]=l}}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(t,l){t=null;try{t=JSON.parse(l)}catch(E){return}if(1==t.type)if(t.data.object_class&&h[t.data.object_class]){l=null;try{l=new h[t.data.object_class](t.data),n.triggerSlot(0,l)}catch(E){return}}else n.triggerSlot(0,
t.data);else n._last_received_data[t.channel||0]=t.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(y){console.error("SillyServer error: "+y);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);