Merge pull request #229 from RobTheFiveNine/bugfix/incorrect-property-editor-labels

Fix incorrect property editor labels + build improvements
This commit is contained in:
Javi Agenjo
2021-06-14 16:42:41 +02:00
committed by GitHub
10 changed files with 18796 additions and 11447 deletions

11909
build/litegraph.core.js Normal file

File diff suppressed because it is too large Load Diff

281
build/litegraph.core.min.js vendored Normal file
View File

@@ -0,0 +1,281 @@
var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.ASSUME_ES5=!1;$jscomp.ASSUME_NO_NATIVE_MAP=!1;$jscomp.ASSUME_NO_NATIVE_SET=!1;$jscomp.defineProperty=$jscomp.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(p,r,w){p!=Array.prototype&&p!=Object.prototype&&(p[r]=w.value)};$jscomp.getGlobal=function(p){return"undefined"!=typeof window&&window===p?p:"undefined"!=typeof global&&null!=global?global:p};$jscomp.global=$jscomp.getGlobal(this);
$jscomp.polyfill=function(p,r,w,q){if(r){w=$jscomp.global;p=p.split(".");for(q=0;q<p.length-1;q++){var y=p[q];y in w||(w[y]={});w=w[y]}p=p[p.length-1];q=w[p];r=r(q);r!=q&&null!=r&&$jscomp.defineProperty(w,p,{configurable:!0,writable:!0,value:r})}};$jscomp.polyfill("Array.prototype.fill",function(p){return p?p:function(r,p,q){var w=this.length||0;0>p&&(p=Math.max(0,w+p));if(null==q||q>w)q=w;q=Number(q);0>q&&(q=Math.max(0,w+q));for(p=Number(p||0);p<q;p++)this[p]=r;return this}},"es6","es3");
$jscomp.SYMBOL_PREFIX="jscomp_symbol_";$jscomp.initSymbol=function(){$jscomp.initSymbol=function(){};$jscomp.global.Symbol||($jscomp.global.Symbol=$jscomp.Symbol)};$jscomp.Symbol=function(){var p=0;return function(r){return $jscomp.SYMBOL_PREFIX+(r||"")+p++}}();
$jscomp.initSymbolIterator=function(){$jscomp.initSymbol();var p=$jscomp.global.Symbol.iterator;p||(p=$jscomp.global.Symbol.iterator=$jscomp.global.Symbol("iterator"));"function"!=typeof Array.prototype[p]&&$jscomp.defineProperty(Array.prototype,p,{configurable:!0,writable:!0,value:function(){return $jscomp.arrayIterator(this)}});$jscomp.initSymbolIterator=function(){}};$jscomp.arrayIterator=function(p){var r=0;return $jscomp.iteratorPrototype(function(){return r<p.length?{done:!1,value:p[r++]}:{done:!0}})};
$jscomp.iteratorPrototype=function(p){$jscomp.initSymbolIterator();p={next:p};p[$jscomp.global.Symbol.iterator]=function(){return this};return p};$jscomp.iteratorFromArray=function(p,r){$jscomp.initSymbolIterator();p instanceof String&&(p+="");var w=0,q={next:function(){if(w<p.length){var y=w++;return{value:r(y,p[y]),done:!1}}q.next=function(){return{done:!0,value:void 0}};return q.next()}};q[Symbol.iterator]=function(){return q};return q};
$jscomp.polyfill("Array.prototype.values",function(p){return p?p:function(){return $jscomp.iteratorFromArray(this,function(r,p){return p})}},"es8","es3");$jscomp.polyfill("Array.prototype.keys",function(p){return p?p:function(){return $jscomp.iteratorFromArray(this,function(r){return r})}},"es6","es3");$jscomp.owns=function(p,r){return Object.prototype.hasOwnProperty.call(p,r)};
$jscomp.polyfill("Object.values",function(p){return p?p:function(r){var p=[],q;for(q in r)$jscomp.owns(r,q)&&p.push(r[q]);return p}},"es8","es3");$jscomp.checkStringArgs=function(p,r,w){if(null==p)throw new TypeError("The 'this' value for String.prototype."+w+" must not be null or undefined");if(r instanceof RegExp)throw new TypeError("First argument to String.prototype."+w+" must not be a regular expression");return p+""};
$jscomp.polyfill("String.prototype.startsWith",function(p){return p?p:function(r,p){var q=$jscomp.checkStringArgs(this,r,"startsWith");r+="";var w=q.length,z=r.length;p=Math.max(0,Math.min(p|0,q.length));for(var l=0;l<z&&p<w;)if(q[p++]!=r[l++])return!1;return l>=z}},"es6","es3");$jscomp.findInternal=function(p,r,w){p instanceof String&&(p=String(p));for(var q=p.length,y=0;y<q;y++){var z=p[y];if(r.call(w,z,y,p))return{i:y,v:z}}return{i:-1,v:void 0}};
$jscomp.polyfill("Array.prototype.findIndex",function(p){return p?p:function(r,p){return $jscomp.findInternal(this,r,p).i}},"es6","es3");
(function(p){function r(a){f.debug&&console.log("Graph created");this.list_of_graphcanvas=null;this.clear();a&&this.configure(a)}function w(a,b,c,d,e,g){this.id=a;this.type=b;this.origin_id=c;this.origin_slot=d;this.target_id=e;this.target_slot=g;this._data=null;this._pos=new Float32Array(2)}function q(a){this._ctor(a)}function y(a){this._ctor(a)}function z(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 z;this.zoom_modify_alpha=!0;this.title_text_font=""+f.NODE_TEXT_SIZE+"px Arial";this.inner_text_font="normal "+f.NODE_SUBTEXT_SIZE+"px Arial";this.node_title_color=f.NODE_TITLE_COLOR;this.default_link_color=f.LINK_COLOR;this.default_connection_color=
{input_off:"#778",input_on:"#7F7",output_off:"#778",output_on:"#7F7"};this.highquality_render=!0;this.use_gradients=!1;this.editor_alpha=1;this.pause_rendering=!1;this.clear_background=!0;this.read_only=!1;this.render_only_selected=!0;this.live_mode=!1;this.allow_searchbox=this.allow_interaction=this.allow_dragnodes=this.allow_dragcanvas=this.show_info=!0;this.drag_mode=this.align_to_grid=this.allow_reconnect_links=!1;this.filter=this.dragging_rectangle=null;this.set_canvas_dirty_on_mouse_event=!0;
this.always_render_background=!1;this.render_canvas_border=this.render_shadows=!0;this.render_connections_shadows=!1;this.render_connections_border=!0;this.render_connection_arrows=this.render_curved_connections=!1;this.render_collapsed_slots=!0;this.render_execution_order=!1;this.render_link_tooltip=this.render_title_colored=!0;this.links_render_mode=f.SPLINE_LINK;this.mouse=[0,0];this.canvas_mouse=this.graph_mouse=[0,0];this.onAfterChange=this.onBeforeChange=this.onConnectingChange=this.onSelectionChange=
this.onNodeMoved=this.onDrawLinkTooltip=this.onDrawOverlay=this.onDrawForeground=this.onDrawBackground=this.onMouse=this.onSearchBoxSelection=this.onSearchBox=null;this.connections_width=3;this.round_radius=8;this.over_link_center=this.node_widget=this.current_node=null;this.last_mouse_position=[0,0];this.visible_area=this.ds.visible_area;this.visible_links=[];this.viewport=c.viewport||null;b&&b.attachCanvas(this);this.setCanvas(a,c.skip_events);this.clear();c.skip_render||this.startRendering();this.autoresize=
c.autoresize}function J(a,b){return Math.sqrt((b[0]-a[0])*(b[0]-a[0])+(b[1]-a[1])*(b[1]-a[1]))}function C(a,b,c,d,e,g){return c<a&&c+e>a&&d<b&&d+g>b?!0:!1}function H(a,b){var c=a[0]+a[2],d=a[1]+a[3],e=b[1]+b[3];return a[0]>b[0]+b[2]||a[1]>e||c<b[0]||d<b[1]?!1:!0}function E(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 d=this;b.parentMenu&&(b.parentMenu.constructor!==this.constructor?(console.error("parentMenu must be of class ContextMenu, ignoring it"),
b.parentMenu=null):(this.parentMenu=b.parentMenu,this.parentMenu.lock=!0,this.parentMenu.current_submenu=this));var e=null;b.event&&(e=b.event.constructor.name);"MouseEvent"!==e&&"CustomEvent"!==e&&"PointerEvent"!==e&&(console.error("Event passed to ContextMenu is not of type MouseEvent or CustomEvent. Ignoring it."),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);g.addEventListener("mouseup",function(a){a.preventDefault();return!0},!0);g.addEventListener("contextmenu",function(a){if(2!=a.button)return!1;a.preventDefault();return!1},!0);g.addEventListener("mousedown",function(a){if(2==a.button)return d.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&&(e=document.createElement("div"),
e.className="litemenu-title",e.innerHTML=b.title,g.appendChild(e));for(var h=e=0;h<a.length;h++){var f=a.constructor==Array?a[h]:h;null!=f&&f.constructor!==String&&(f=void 0===f.content?String(f):f.content);this.addItem(f,a[h],b);e++}g.addEventListener("mouseleave",function(a){d.lock||(g.closing_timer&&clearTimeout(g.closing_timer),g.closing_timer=setTimeout(d.close.bind(d,a),500))});g.addEventListener("mouseenter",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);e=b.left||0;a=b.top||0;b.event&&(e=b.event.clientX-10,a=b.event.clientY-10,b.title&&(a-=20),b.parentMenu&&(e=b.parentMenu.root.getBoundingClientRect(),e=e.left+e.width),h=document.body.getBoundingClientRect(),f=g.getBoundingClientRect(),0==h.height&&console.error("document.body height is 0. That is dangerous, set html,body { height: 100%; }"),h.width&&e>h.width-f.width-10&&(e=
h.width-f.width-10),h.height&&a>h.height-f.height-10&&(a=h.height-f.height-10));g.style.left=e+"px";g.style.top=a+"px";b.scale&&(g.style.transform="scale("+b.scale+")")}function G(a){this.points=a;this.nearest=this.selected=-1;this.size=null;this.must_update=!0;this.margin=5}var f=p.LiteGraph={VERSION:.4,CANVAS_GRID_SIZE:10,NODE_TITLE_HEIGHT:30,NODE_TITLE_TEXT_Y:20,NODE_SLOT_HEIGHT:20,NODE_WIDGET_HEIGHT:20,NODE_WIDTH:140,NODE_MIN_WIDTH:50,NODE_COLLAPSED_RADIUS:10,NODE_COLLAPSED_WIDTH:80,NODE_TITLE_COLOR:"#999",
NODE_SELECTED_TITLE_COLOR:"#FFF",NODE_TEXT_SIZE:14,NODE_TEXT_COLOR:"#AAA",NODE_SUBTEXT_SIZE:12,NODE_DEFAULT_COLOR:"#333",NODE_DEFAULT_BGCOLOR:"#353535",NODE_DEFAULT_BOXCOLOR:"#666",NODE_DEFAULT_SHAPE:"box",NODE_BOX_OUTLINE_COLOR:"#FFF",DEFAULT_SHADOW_COLOR:"rgba(0,0,0,0.5)",DEFAULT_GROUP_FONT:24,WIDGET_BGCOLOR:"#222",WIDGET_OUTLINE_COLOR:"#666",WIDGET_TEXT_COLOR:"#DDD",WIDGET_SECONDARY_TEXT_COLOR:"#999",LINK_COLOR:"#9A9",EVENT_LINK_COLOR:"#A86",CONNECTING_LINK_COLOR:"#AFA",MAX_NUMBER_OF_NODES:1E3,
DEFAULT_POSITION:[100,100],VALID_SHAPES:["default","box","round","card"],BOX_SHAPE:1,ROUND_SHAPE:2,CIRCLE_SHAPE:3,CARD_SHAPE:4,ARROW_SHAPE:5,INPUT:1,OUTPUT:2,EVENT:-1,ACTION:-1,ALWAYS:0,ON_EVENT:1,NEVER:2,ON_TRIGGER:3,UP:1,DOWN:2,LEFT:3,RIGHT:4,CENTER:5,STRAIGHT_LINK:0,LINEAR_LINK:1,SPLINE_LINK:2,NORMAL_TITLE:0,NO_TITLE:1,TRANSPARENT_TITLE:2,AUTOHIDE_TITLE:3,proxy:null,node_images_path:"",debug:!1,catch_exceptions:!0,throw_errors:!0,allow_scripts:!1,registered_node_types:{},node_types_by_file_extension:{},
Nodes:{},Globals:{},searchbox_extras:{},auto_sort_node_types:!1,registerNodeType:function(a,b){if(!b.prototype)throw"Cannot register a simple object, it must be a class with a prototype";b.type=a;f.debug&&console.log("Node registered: "+a);a.split("/");var c=b.name,d=a.lastIndexOf("/");b.category=a.substr(0,d);b.title||(b.title=c);if(b.prototype)for(var e in q.prototype)b.prototype[e]||(b.prototype[e]=q.prototype[e]);if(d=this.registered_node_types[a])console.log("replacing node type: "+a);else if(Object.hasOwnProperty(b.prototype,
"shape")||Object.defineProperty(b.prototype,"shape",{set:function(a){switch(a){case "default":delete this._shape;break;case "box":this._shape=f.BOX_SHAPE;break;case "round":this._shape=f.ROUND_SHAPE;break;case "circle":this._shape=f.CIRCLE_SHAPE;break;case "card":this._shape=f.CARD_SHAPE;break;default:this._shape=a}},get:function(a){return this._shape},enumerable:!0,configurable:!0}),b.prototype.onPropertyChange&&console.warn("LiteGraph node class "+a+" has onPropertyChange method, it must be called onPropertyChanged with d at the end"),
b.supported_extensions)for(e in b.supported_extensions){var g=b.supported_extensions[e];g&&g.constructor===String&&(this.node_types_by_file_extension[g.toLowerCase()]=b)}this.registered_node_types[a]=b;b.constructor.name&&(this.Nodes[c]=b);if(f.onNodeTypeRegistered)f.onNodeTypeRegistered(a,b);if(d&&f.onNodeTypeReplaced)f.onNodeTypeReplaced(a,b,d);b.prototype.onPropertyChange&&console.warn("LiteGraph node class "+a+" has onPropertyChange method, it must be called onPropertyChanged with d at the end");
if(b.supported_extensions)for(e=0;e<b.supported_extensions.length;e++)(g=b.supported_extensions[e])&&g.constructor===String&&(this.node_types_by_file_extension[g.toLowerCase()]=b)},unregisterNodeType:function(a){var b=a.constructor===String?this.registered_node_types[a]:a;if(!b)throw"node type not found: "+a;delete this.registered_node_types[b.type];b.constructor.name&&delete this.Nodes[b.constructor.name]},wrapFunctionAsNode:function(a,b,c,d,e){for(var g=Array(b.length),h="",k=f.getParameterNames(b),
n=0;n<k.length;++n)h+="this.addInput('"+k[n]+"',"+(c&&c[n]?"'"+c[n]+"'":"0")+");\n";h+="this.addOutput('out',"+(d?"'"+d+"'":0)+");\n";e&&(h+="this.properties = "+JSON.stringify(e)+";\n");c=Function(h);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){q.prototype[a]=b;for(var c in this.registered_node_types){var d=this.registered_node_types[c];d.prototype[a]&&(d.prototype["_"+a]=d.prototype[a]);d.prototype[a]=b}},createNode:function(a,b,c){var d=this.registered_node_types[a];if(!d)return f.debug&&console.log('GraphNode type "'+a+'" not registered.'),null;b=b||d.title||a;var e=null;if(f.catch_exceptions)try{e=new d(b)}catch(h){return console.error(h),null}else e=new d(b);e.type=
a;!e.title&&b&&(e.title=b);e.properties||(e.properties={});e.properties_info||(e.properties_info=[]);e.flags||(e.flags={});e.size||(e.size=e.computeSize());e.pos||(e.pos=f.DEFAULT_POSITION.concat());e.mode||(e.mode=f.ALWAYS);if(c)for(var g in c)e[g]=c[g];return e},getNodeType:function(a){return this.registered_node_types[a]},getNodeTypesInCategory:function(a,b){var c=[],d;for(d in this.registered_node_types){var e=this.registered_node_types[d];e.filter==b&&(""==a?null==e.category&&c.push(e):e.category==
a&&c.push(e))}this.auto_sort_node_types&&c.sort(function(a,b){return a.title.localeCompare(b.title)});return c},getNodeTypesCategories:function(a){var b={"":1},c;for(c in this.registered_node_types){var d=this.registered_node_types[c];d.category&&!d.skip_list&&d.filter==a&&(b[d.category]=1)}a=[];for(c in b)a.push(c);return this.auto_sort_node_types?a.sort():a},reloadNodes:function(a){for(var b=document.getElementsByTagName("script"),c=[],d=0;d<b.length;d++)c.push(b[d]);b=document.getElementsByTagName("head")[0];
a=document.location.href+a;for(d=0;d<c.length;d++){var e=c[d].src;if(e&&e.substr(0,a.length)==a)try{f.debug&&console.log("Reloading: "+e);var g=document.createElement("script");g.type="text/javascript";g.src=e;b.appendChild(g);b.removeChild(c[d])}catch(h){if(f.throw_errors)throw h;f.debug&&console.log("Error while reloading "+e)}}f.debug&&console.log("Nodes reloaded")},cloneObject:function(a,b){if(null==a)return null;a=JSON.parse(JSON.stringify(a));if(!b)return a;for(var c in a)b[c]=a[c];return b},
isValidConnection:function(a,b){if(!a||!b||a==b||a==f.EVENT&&b==f.ACTION)return!0;a=String(a);b=String(b);a=a.toLowerCase();b=b.toLowerCase();if(-1==a.indexOf(",")&&-1==b.indexOf(","))return a==b;a=a.split(",");b=b.split(",");for(var c=0;c<a.length;++c)for(var d=0;d<b.length;++d)if(a[c]==b[d])return!0;return!1},registerSearchboxExtra:function(a,b,c){this.searchbox_extras[b.toLowerCase()]={type:a,desc:b,data:c}},fetchFile:function(a,b,c,d){if(!a)return null;b=b||"text";if(a.constructor===String)return"http"==
a.substr(0,4)&&f.proxy&&(a=f.proxy+a.substr(a.indexOf(":")+3)),fetch(a).then(function(a){if(!a.ok)throw Error("File not found");if("arraybuffer"==b)return a.arrayBuffer();if("text"==b||"string"==b)return a.text();if("json"==b)return a.json();if("blob"==b)return a.blob()}).then(function(a){c&&c(a)}).catch(function(b){console.error("error fetching file:",a);d&&d(b)});if(a.constructor===File||a.constructor===Blob){var e=new FileReader;e.onload=function(a){a=a.target.result;"json"==b&&(a=JSON.parse(a));
c&&c(a)};if("arraybuffer"==b)return e.readAsArrayBuffer(a);if("text"==b||"json"==b)return e.readAsText(a);if("blob"==b)return e.readAsBinaryString(a)}return null}};f.getTime="undefined"!=typeof performance?performance.now.bind(performance):"undefined"!=typeof Date&&Date.now?Date.now.bind(Date):"undefined"!=typeof process?function(){var a=process.hrtime();return.001*a[0]+1E-6*a[1]}:function(){return(new Date).getTime()};p.LGraph=f.LGraph=r;r.supported_types=["number","string","boolean"];r.prototype.getSupportedTypes=
function(){return this.supported_types||r.supported_types};r.STATUS_STOPPED=1;r.STATUS_RUNNING=2;r.prototype.clear=function(){this.stop();this.status=r.STATUS_STOPPED;this.last_link_id=this.last_node_id=0;this._version=-1;if(this._nodes)for(var a=0;a<this._nodes.length;++a){var b=this._nodes[a];if(b.onRemoved)b.onRemoved()}this._nodes=[];this._nodes_by_id={};this._nodes_in_order=[];this._nodes_executable=null;this._groups=[];this.links={};this.iteration=0;this.config={};this.vars={};this.extra={};
this.fixedtime=this.runningtime=this.globaltime=0;this.elapsed_time=this.fixedtime_lapse=.01;this.starttime=this.last_update_time=0;this.catch_errors=!0;this.inputs={};this.outputs={};this.change();this.sendActionToCanvas("clear")};r.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)};r.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))}};r.prototype.start=function(a){if(this.status!=r.STATUS_RUNNING){this.status=r.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)}};r.prototype.stop=function(){if(this.status!=r.STATUS_STOPPED){this.status=r.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")}};r.prototype.runStep=function(a,b,c){a=a||1;var d=f.getTime();this.globaltime=.001*(d-this.starttime);var e=this._nodes_executable?this._nodes_executable:this._nodes;if(e){c=c||e.length;if(b){for(var g=0;g<a;g++){for(var h=0;h<c;++h){var k=e[h];if(k.mode==f.ALWAYS&&k.onExecute)k.onExecute()}this.fixedtime+=this.fixedtime_lapse;if(this.onExecuteStep)this.onExecuteStep()}if(this.onAfterExecute)this.onAfterExecute()}else try{for(g=0;g<
a;g++){for(h=0;h<c;++h)if(k=e[h],k.mode==f.ALWAYS&&k.onExecute)k.onExecute();this.fixedtime+=this.fixedtime_lapse;if(this.onExecuteStep)this.onExecuteStep()}if(this.onAfterExecute)this.onAfterExecute();this.errors_in_execution=!1}catch(n){this.errors_in_execution=!0;if(f.throw_errors)throw n;f.debug&&console.log("Error during execution: "+n);this.stop()}a=f.getTime();d=a-d;0==d&&(d=1);this.execution_time=.001*d;this.globaltime+=.001*d;this.iteration+=1;this.elapsed_time=.001*(a-this.last_update_time);
this.last_update_time=a}};r.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])};r.prototype.computeExecutionOrder=function(a,b){for(var c=[],d=[],e={},g={},h={},k=0,n=this._nodes.length;k<n;++k){var u=this._nodes[k];if(!a||u.onExecute){e[u.id]=u;var t=0;if(u.inputs)for(var m=0,l=u.inputs.length;m<
l;m++)u.inputs[m]&&null!=u.inputs[m].link&&(t+=1);0==t?(d.push(u),b&&(u._level=1)):(b&&(u._level=0),h[u.id]=t)}}for(;0!=d.length;)if(u=d.shift(),c.push(u),delete e[u.id],u.outputs)for(k=0;k<u.outputs.length;k++)if(a=u.outputs[k],null!=a&&null!=a.links&&0!=a.links.length)for(m=0;m<a.links.length;m++)(n=this.links[a.links[m]])&&!g[n.id]&&(t=this.getNodeById(n.target_id),null==t?g[n.id]=!0:(b&&(!t._level||t._level<=u._level)&&(t._level=u._level+1),g[n.id]=!0,--h[t.id],0==h[t.id]&&d.push(t)));for(k in e)c.push(e[k]);
c.length!=this._nodes.length&&f.debug&&console.warn("something went wrong, nodes missing");n=c.length;for(k=0;k<n;++k)c[k].order=k;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(k=0;k<n;++k)c[k].order=k;return c};r.prototype.getAncestors=function(a){for(var b=[],c=[a],d={};c.length;){var e=c.shift();if(e.inputs){d[e.id]||e==a||(d[e.id]=!0,b.push(e));for(var g=0;g<e.inputs.length;++g){var h=e.getInputNode(g);
h&&-1==b.indexOf(h)&&c.push(h)}}}b.sort(function(a,b){return a.order-b.order});return b};r.prototype.arrange=function(a){a=a||100;for(var b=this.computeExecutionOrder(!1,!0),c=[],d=0;d<b.length;++d){var e=b[d],g=e._level||1;c[g]||(c[g]=[]);c[g].push(e)}b=a;for(d=0;d<c.length;++d)if(g=c[d]){for(var h=100,k=a+f.NODE_TITLE_HEIGHT,n=0;n<g.length;++n)e=g[n],e.pos[0]=b,e.pos[1]=k,e.size[0]>h&&(h=e.size[0]),k+=e.size[1]+a+f.NODE_TITLE_HEIGHT;b+=h+a}this.setDirtyCanvas(!0,!0)};r.prototype.getTime=function(){return this.globaltime};
r.prototype.getFixedTime=function(){return this.fixedtime};r.prototype.getElapsedTime=function(){return this.elapsed_time};r.prototype.sendEventToAllNodes=function(a,b,c){c=c||f.ALWAYS;var d=this._nodes_in_order?this._nodes_in_order:this._nodes;if(d)for(var e=0,g=d.length;e<g;++e){var h=d[e];if(h.constructor===f.Subgraph&&"onExecute"!=a)h.mode==c&&h.sendEventToAllNodes(a,b,c);else if(h[a]&&h.mode==c)if(void 0===b)h[a]();else if(b&&b.constructor===Array)h[a].apply(h,b);else h[a](b)}};r.prototype.sendActionToCanvas=
function(a,b){if(this.list_of_graphcanvas)for(var c=0;c<this.list_of_graphcanvas.length;++c){var d=this.list_of_graphcanvas[c];d[a]&&d[a].apply(d,b)}};r.prototype.add=function(a,b){if(a)if(a.constructor===y)this._groups.push(a),this.setDirtyCanvas(!0),this.change(),a.graph=this,this._version++;else{-1!=a.id&&null!=this._nodes_by_id[a.id]&&(console.warn("LiteGraph: there is already a node with this ID, changing it"),a.id=++this.last_node_id);if(this._nodes.length>=f.MAX_NUMBER_OF_NODES)throw"LiteGraph: max number of nodes in a graph reached";
null==a.id||-1==a.id?a.id=++this.last_node_id:this.last_node_id<a.id&&(this.last_node_id=a.id);a.graph=this;this._version++;this._nodes.push(a);this._nodes_by_id[a.id]=a;if(a.onAdded)a.onAdded(this);this.config.align_to_grid&&a.alignToGrid();b||this.updateExecutionOrder();if(this.onNodeAdded)this.onNodeAdded(a);this.setDirtyCanvas(!0);this.change();return a}};r.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()}};r.prototype.getNodeById=function(a){return null==a?null:this._nodes_by_id[a]};r.prototype.findNodesByClass=function(a,b){b=b||[];for(var c=b.length=
0,d=this._nodes.length;c<d;++c)this._nodes[c].constructor===a&&b.push(this._nodes[c]);return b};r.prototype.findNodesByType=function(a,b){a=a.toLowerCase();b=b||[];for(var c=b.length=0,d=this._nodes.length;c<d;++c)this._nodes[c].type.toLowerCase()==a&&b.push(this._nodes[c]);return b};r.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};r.prototype.findNodesByTitle=function(a){for(var b=[],c=0,d=this._nodes.length;c<
d;++c)this._nodes[c].title==a&&b.push(this._nodes[c]);return b};r.prototype.getNodeOnPos=function(a,b,c,d){c=c||this._nodes;for(var e=c.length-1;0<=e;e--){var g=c[e];if(g.isPointInside(a,b,d))return g}return null};r.prototype.getGroupOnPos=function(a,b){for(var c=this._groups.length-1;0<=c;c--){var d=this._groups[c];if(d.isPointInside(a,b,2,!0))return d}return null};r.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()};r.prototype.onAction=function(a,b){this._input_nodes=this.findNodesByClass(f.GraphInput,this._input_nodes);for(var c=0;c<this._input_nodes.length;++c){var d=this._input_nodes[c];if(d.properties.name==a){d.onAction(a,b);break}}};r.prototype.trigger=function(a,b){if(this.onTrigger)this.onTrigger(a,
b)};r.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()}};r.prototype.setInputData=function(a,b){if(a=this.inputs[a])a.value=b};r.prototype.getInputData=function(a){return(a=this.inputs[a])?a.value:null};r.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()}};r.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)};r.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};r.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()};r.prototype.setOutputData=function(a,b){if(a=this.outputs[a])a.value=b};r.prototype.getOutputData=function(a){return(a=this.outputs[a])?a.value:null};
r.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()};r.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)};r.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};r.prototype.triggerInput=function(a,b){a=this.findNodesByTitle(a);for(var c=0;c<a.length;++c)a[c].onTrigger(b)};r.prototype.setCallback=function(a,b){a=this.findNodesByTitle(a);for(var c=0;c<a.length;++c)a[c].setTrigger(b)};
r.prototype.beforeChange=function(a){if(this.onBeforeChange)this.onBeforeChange(this,a);this.sendActionToCanvas("onBeforeChange",this)};r.prototype.afterChange=function(a){if(this.onAfterChange)this.onAfterChange(this,a);this.sendActionToCanvas("onAfterChange",this)};r.prototype.connectionChange=function(a,b){this.updateExecutionOrder();if(this.onConnectionChange)this.onConnectionChange(a);this._version++;this.sendActionToCanvas("onConnectionChange")};r.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};r.prototype.clearTriggeredSlots=function(){for(var a in this.links){var b=this.links[a];b&&b._last_time&&(b._last_time=0)}};r.prototype.change=function(){f.debug&&console.log("Graph changed");this.sendActionToCanvas("setDirty",[!0,!0]);if(this.on_change)this.on_change(this)};r.prototype.setDirtyCanvas=function(a,b){this.sendActionToCanvas("setDirty",[a,b])};r.prototype.removeLink=function(a){if(a=
this.links[a]){var b=this.getNodeById(a.target_id);b&&b.disconnectInput(a.target_slot)}};r.prototype.serialize=function(){for(var a=[],b=0,c=this._nodes.length;b<c;++b)a.push(this._nodes[b].serialize());c=[];for(b in this.links){var d=this.links[b];if(!d.serialize){console.warn("weird LLink bug, link info is not a LLink but a regular object");var e=new w;for(g in d)e[g]=d[g];d=this.links[b]=e}c.push(d.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};r.prototype.configure=function(a,b){if(a){b||this.clear();b=a.nodes;if(a.links&&a.links.constructor===Array){for(var c=[],d=0;d<a.links.length;++d){var e=a.links[d];if(e){var g=new w;g.configure(e);c[g.id]=g}else console.warn("serialized graph link data contains errors, skipping.")}a.links=c}for(d in a)"nodes"!=d&&"groups"!=d&&(this[d]=a[d]);
c=!1;this._nodes=[];if(b){d=0;for(e=b.length;d<e;++d){g=b[d];var h=f.createNode(g.type,g.title);h||(f.debug&&console.log("Node not found or has errors: "+g.type),h=new q,h.last_serialization=g,c=h.has_errors=!0);h.id=g.id;this.add(h,!0)}d=0;for(e=b.length;d<e;++d)g=b[d],(h=this.getNodeById(g.id))&&h.configure(g)}this._groups.length=0;if(a.groups)for(d=0;d<a.groups.length;++d)b=new f.LGraphGroup,b.configure(a.groups[d]),this.add(b);this.updateExecutionOrder();this.extra=a.extra||{};if(this.onConfigure)this.onConfigure(a);
this._version++;this.setDirtyCanvas(!0,!0);return c}};r.prototype.load=function(a,b){var c=this;if(a.constructor===File||a.constructor===Blob){var d=new FileReader;d.addEventListener("load",function(a){a=JSON.parse(a.target.result);c.configure(a);b&&b()});d.readAsText(a)}else{var e=new XMLHttpRequest;e.open("GET",a,!0);e.send(null);e.onload=function(a){200!==e.status?console.error("Error loading graph:",e.status,e.response):(a=JSON.parse(e.response),c.configure(a),b&&b())};e.onerror=function(a){console.error("Error loading graph:",
a)}}};r.prototype.onNodeTrace=function(a,b,c){};w.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)};w.prototype.serialize=function(){return[this.id,this.origin_id,this.origin_slot,this.target_id,this.target_slot,this.type]};f.LLink=w;
p.LGraphNode=f.LGraphNode=q;q.prototype._ctor=function(a){this.title=a||"Unnamed";this.size=[f.NODE_WIDTH,60];this.graph=null;this._pos=new Float32Array(10,10);Object.defineProperty(this,"pos",{set:function(a){!a||2>a.length||(this._pos[0]=a[0],this._pos[1]=a[1])},get:function(){return this._pos},enumerable:!0});this.id=-1;this.type=null;this.inputs=[];this.outputs=[];this.connections=[];this.properties={};this.properties_info=[];this.flags={}};q.prototype.configure=function(a){this.graph&&this.graph._version++;
for(var b in a)if("properties"==b)for(var c in a.properties){if(this.properties[c]=a.properties[c],this.onPropertyChanged)this.onPropertyChanged(c,a.properties[c])}else null!=a[b]&&("object"==typeof a[b]?this[b]&&this[b].configure?this[b].configure(a[b]):this[b]=f.cloneObject(a[b],this[b]):this[b]=a[b]);a.title||(this.title=this.constructor.title);if(this.onConnectionsChange){if(this.inputs)for(c=0;c<this.inputs.length;++c){b=this.inputs[c];var d=this.graph?this.graph.links[b.link]:null;this.onConnectionsChange(f.INPUT,
c,!0,d,b)}if(this.outputs)for(c=0;c<this.outputs.length;++c){var e=this.outputs[c];if(e.links)for(b=0;b<e.links.length;++b)d=this.graph?this.graph.links[e.links[b]]:null,this.onConnectionsChange(f.OUTPUT,c,!0,d,e)}}if(this.widgets){for(c=0;c<this.widgets.length;++c)(b=this.widgets[c])&&b.options&&b.options.property&&this.properties[b.options.property]&&(b.value=JSON.parse(JSON.stringify(this.properties[b.options.property])));if(a.widgets_values)for(c=0;c<a.widgets_values.length;++c)this.widgets[c]&&
(this.widgets[c].value=a.widgets_values[c])}if(this.onConfigure)this.onConfigure(a)};q.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===q&&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};q.prototype.clone=function(){var a=f.createNode(this.type);if(!a)return null;var b=f.cloneObject(this.serialize());if(b.inputs)for(var c=0;c<b.inputs.length;++c)b.inputs[c].link=null;if(b.outputs)for(c=0;c<b.outputs.length;++c)b.outputs[c].links&&(b.outputs[c].links.length=0);delete b.id;a.configure(b);return a};q.prototype.toString=function(){return JSON.stringify(this.serialize())};q.prototype.getTitle=function(){return this.title||this.constructor.title};q.prototype.setProperty=function(a,
b){this.properties||(this.properties={});if(b!==this.properties[a]){var c=this.properties[a];this.properties[a]=b;this.onPropertyChanged&&!1===this.onPropertyChanged(a,b,c)&&(this.properties[a]=c);if(this.widgets)for(c=0;c<this.widgets.length;++c){var d=this.widgets[c];if(d&&d.options.property==a){d.value=b;break}}}};q.prototype.setOutputData=function(a,b){if(this.outputs&&!(-1==a||a>=this.outputs.length)){var c=this.outputs[a];if(c&&(c._data=b,this.outputs[a].links))for(c=0;c<this.outputs[a].links.length;c++){var d=
this.graph.links[this.outputs[a].links[c]];d&&(d.data=b)}}};q.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}};q.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}};q.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};q.prototype.getInputDataByName=function(a,b){a=this.findInputSlot(a);return-1==a?null:this.getInputData(a,
b)};q.prototype.isInputConnected=function(a){return this.inputs?a<this.inputs.length&&null!=this.inputs[a].link:!1};q.prototype.getInputInfo=function(a){return this.inputs?a<this.inputs.length?this.inputs[a]:null:null};q.prototype.getInputLink=function(a){return this.inputs?a<this.inputs.length?this.graph.links[this.inputs[a].link]:null:null};q.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};q.prototype.getInputOrProperty=function(a){if(!this.inputs||!this.inputs.length)return this.properties?this.properties[a]:null;for(var b=0,c=this.inputs.length;b<c;++b){var d=this.inputs[b];if(a==d.name&&null!=d.link&&(d=this.graph.links[d.link]))return d.data}return this.properties[a]};q.prototype.getOutputData=function(a){return!this.outputs||a>=this.outputs.length?null:this.outputs[a]._data};q.prototype.getOutputInfo=function(a){return this.outputs?
a<this.outputs.length?this.outputs[a]:null:null};q.prototype.isOutputConnected=function(a){return this.outputs?a<this.outputs.length&&this.outputs[a].links&&this.outputs[a].links.length:!1};q.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};q.prototype.getOutputNodes=function(a){if(!this.outputs||0==this.outputs.length||a>=this.outputs.length)return null;a=this.outputs[a];
if(!a.links||0==a.links.length)return null;for(var b=[],c=0;c<a.links.length;c++){var d=this.graph.links[a.links[c]];d&&(d=this.graph.getNodeById(d.target_id))&&b.push(d)}return b};q.prototype.trigger=function(a,b){if(this.outputs&&this.outputs.length){this.graph&&(this.graph._last_trigger_time=f.getTime());for(var c=0;c<this.outputs.length;++c){var d=this.outputs[c];!d||d.type!==f.EVENT||a&&d.name!=a||this.triggerSlot(c,b)}}};q.prototype.triggerSlot=function(a,b,c){if(this.outputs&&(a=this.outputs[a])&&
(a=a.links)&&a.length){this.graph&&(this.graph._last_trigger_time=f.getTime());for(var d=0;d<a.length;++d){var e=a[d];if(null==c||c==e){var g=this.graph.links[a[d]];if(g&&(g._last_time=f.getTime(),e=this.graph.getNodeById(g.target_id)))if(g=e.inputs[g.target_slot],e.mode===f.ON_TRIGGER){if(e.onExecute)e.onExecute(b)}else if(e.onAction)e.onAction(g.name,b)}}}};q.prototype.clearTriggeredSlot=function(a,b){if(this.outputs&&(a=this.outputs[a])&&(a=a.links)&&a.length)for(var c=0;c<a.length;++c){var d=
a[c];if(null==b||b==d)if(d=this.graph.links[a[c]])d._last_time=0}};q.prototype.setSize=function(a){this.size=a;if(this.onResize)this.onResize(this.size)};q.prototype.addProperty=function(a,b,c,d){c={name:a,type:c,default_value:b};if(d)for(var e in d)c[e]=d[e];this.properties_info||(this.properties_info=[]);this.properties_info.push(c);this.properties||(this.properties={});this.properties[a]=b;return c};q.prototype.addOutput=function(a,b,c){a={name:a,type:b,links:null};if(c)for(var d in c)a[d]=c[d];
this.outputs||(this.outputs=[]);this.outputs.push(a);if(this.onOutputAdded)this.onOutputAdded(a);this.setSize(this.computeSize());this.setDirtyCanvas(!0,!0);return a};q.prototype.addOutputs=function(a){for(var b=0;b<a.length;++b){var c=a[b],d={name:c[0],type:c[1],link:null};if(a[2])for(var e in c[2])d[e]=c[2][e];this.outputs||(this.outputs=[]);this.outputs.push(d);if(this.onOutputAdded)this.onOutputAdded(d)}this.setSize(this.computeSize());this.setDirtyCanvas(!0,!0)};q.prototype.removeOutput=function(a){this.disconnectOutput(a);
this.outputs.splice(a,1);for(var b=a;b<this.outputs.length;++b)if(this.outputs[b]&&this.outputs[b].links)for(var c=this.outputs[b].links,d=0;d<c.length;++d){var e=this.graph.links[c[d]];e&&--e.origin_slot}this.setSize(this.computeSize());if(this.onOutputRemoved)this.onOutputRemoved(a);this.setDirtyCanvas(!0,!0)};q.prototype.addInput=function(a,b,c){a={name:a,type:b||0,link:null};if(c)for(var d in c)a[d]=c[d];this.inputs||(this.inputs=[]);this.inputs.push(a);this.setSize(this.computeSize());if(this.onInputAdded)this.onInputAdded(a);
this.setDirtyCanvas(!0,!0);return a};q.prototype.addInputs=function(a){for(var b=0;b<a.length;++b){var c=a[b],d={name:c[0],type:c[1],link:null};if(a[2])for(var e in c[2])d[e]=c[2][e];this.inputs||(this.inputs=[]);this.inputs.push(d);if(this.onInputAdded)this.onInputAdded(d)}this.setSize(this.computeSize());this.setDirtyCanvas(!0,!0)};q.prototype.removeInput=function(a){this.disconnectInput(a);for(var b=this.inputs.splice(a,1),c=a;c<this.inputs.length;++c)if(this.inputs[c]){var d=this.graph.links[this.inputs[c].link];
d&&--d.target_slot}this.setSize(this.computeSize());if(this.onInputRemoved)this.onInputRemoved(a,b[0]);this.setDirtyCanvas(!0,!0)};q.prototype.addConnection=function(a,b,c,d){a={name:a,type:b,pos:c,direction:d,links:null};this.connections.push(a);return a};q.prototype.computeSize=function(a){function b(a){return a?d*a.length*.6:0}if(this.constructor.size)return this.constructor.size.concat();var c=Math.max(this.inputs?this.inputs.length:1,this.outputs?this.outputs.length:1);a=a||new Float32Array([0,
0]);c=Math.max(c,1);var d=f.NODE_TEXT_SIZE,e=b(this.title),g=0,h=0;if(this.inputs)for(var k=0,n=this.inputs.length;k<n;++k){var u=this.inputs[k];u=u.label||u.name||"";u=b(u);g<u&&(g=u)}if(this.outputs)for(k=0,n=this.outputs.length;k<n;++k)u=this.outputs[k],u=u.label||u.name||"",u=b(u),h<u&&(h=u);a[0]=Math.max(g+h+10,e);a[0]=Math.max(a[0],f.NODE_WIDTH);this.widgets&&this.widgets.length&&(a[0]=Math.max(a[0],1.5*f.NODE_WIDTH));a[1]=(this.constructor.slot_start_y||0)+c*f.NODE_SLOT_HEIGHT;c=0;if(this.widgets&&
this.widgets.length){k=0;for(n=this.widgets.length;k<n;++k)c=this.widgets[k].computeSize?c+(this.widgets[k].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};q.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};q.prototype.addWidget=function(a,b,c,d,e){this.widgets||(this.widgets=[]);!e&&d&&d.constructor===Object&&(e=d,d=null);e&&e.constructor===String&&(e={property:e});
d&&d.constructor===String&&(e||(e={}),e.property=d,d=null);d&&d.constructor!==Function&&(console.warn("addWidget: callback must be a function"),d=null);b={type:a.toLowerCase(),name:b,value:c,callback:d,options:e||{}};void 0!==b.options.y&&(b.y=b.options.y);d||b.options.callback||b.options.property||console.warn("LiteGraph addWidget(...) without a callback or property assigned");if("combo"==a&&!b.options.values)throw"LiteGraph addWidget('combo',...) requires to pass values in options: { values:['red','blue'] }";
this.widgets.push(b);this.setSize(this.computeSize());return b};q.prototype.addCustomWidget=function(a){this.widgets||(this.widgets=[]);this.widgets.push(a);return a};q.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};q.prototype.isPointInside=function(a,b,c,d){c=c||0;var e=this.graph&&this.graph.isLive()?
0:f.NODE_TITLE_HEIGHT;d&&(e=0);if(this.flags&&this.flags.collapsed){if(C(a,b,this.pos[0]-c,this.pos[1]-f.NODE_TITLE_HEIGHT-c,(this._collapsed_width||f.NODE_COLLAPSED_WIDTH)+2*c,f.NODE_TITLE_HEIGHT+2*c))return!0}else if(this.pos[0]-4-c<a&&this.pos[0]+this.size[0]+4+c>a&&this.pos[1]-e-c<b&&this.pos[1]+this.size[1]+c>b)return!0;return!1};q.prototype.getSlotInPosition=function(a,b){var c=new Float32Array(2);if(this.inputs)for(var d=0,e=this.inputs.length;d<e;++d){var g=this.inputs[d];this.getConnectionPos(!0,
d,c);if(C(a,b,c[0]-10,c[1]-5,20,10))return{input:g,slot:d,link_pos:c}}if(this.outputs)for(d=0,e=this.outputs.length;d<e;++d)if(g=this.outputs[d],this.getConnectionPos(!1,d,c),C(a,b,c[0]-10,c[1]-5,20,10))return{output:g,slot:d,link_pos:c};return null};q.prototype.findInputSlot=function(a){if(!this.inputs)return-1;for(var b=0,c=this.inputs.length;b<c;++b)if(a==this.inputs[b].name)return b;return-1};q.prototype.findOutputSlot=function(a){if(!this.outputs)return-1;for(var b=0,c=this.outputs.length;b<
c;++b)if(a==this.outputs[b].name)return b;return-1};q.prototype.connect=function(a,b,c){c=c||0;if(!this.graph)return console.log("Connect: Error, node doesn't belong to any graph. Nodes must be added first to a graph before connecting them."),null;if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return f.debug&&console.log("Connect: Error, no slot of name "+a),null}else if(!this.outputs||a>=this.outputs.length)return f.debug&&console.log("Connect: Error, slot number not found"),null;b&&
b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"target node is null";if(b==this)return null;if(c.constructor===String){if(c=b.findInputSlot(c),-1==c)return f.debug&&console.log("Connect: Error, no slot of name "+c),null}else{if(c===f.EVENT)return null;if(!b.inputs||c>=b.inputs.length)return f.debug&&console.log("Connect: Error, slot number not found"),null}var d=!1;null!=b.inputs[c].link&&(this.graph.beforeChange(),b.disconnectInput(c),d=!0);var e=this.outputs[a];if(b.onConnectInput&&
!1===b.onConnectInput(c,e.type,e,this,a))return null;var g=b.inputs[c],h=null;if(!f.isValidConnection(e.type,g.type))return this.setDirtyCanvas(!1,!0),d&&this.graph.connectionChange(this,h),null;d||this.graph.beforeChange();h=new w(++this.graph.last_link_id,g.type,this.id,a,b.id,c);this.graph.links[h.id]=h;null==e.links&&(e.links=[]);e.links.push(h.id);b.inputs[c].link=h.id;this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(f.OUTPUT,a,!0,h,e);if(b.onConnectionsChange)b.onConnectionsChange(f.INPUT,
c,!0,h,g);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,h);return h};q.prototype.disconnectOutput=function(a,b){if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return f.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.outputs||a>=this.outputs.length)return f.debug&&
console.log("Connect: Error, slot number not found"),!1;var c=this.outputs[a];if(!c||!c.links||0==c.links.length)return!1;if(b){b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"Target Node not found";for(var d=0,e=c.links.length;d<e;d++){var g=c.links[d],h=this.graph.links[g];if(h.target_id==b.id){c.links.splice(d,1);var k=b.inputs[h.target_slot];k.link=null;delete this.graph.links[g];this.graph&&this.graph._version++;if(b.onConnectionsChange)b.onConnectionsChange(f.INPUT,h.target_slot,
!1,h,k);if(this.onConnectionsChange)this.onConnectionsChange(f.OUTPUT,a,!1,h,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,h.target_slot));break}}}else{d=0;for(e=c.links.length;d<e;d++)if(g=c.links[d],h=this.graph.links[g]){b=this.graph.getNodeById(h.target_id);this.graph&&this.graph._version++;if(b){k=
b.inputs[h.target_slot];k.link=null;if(b.onConnectionsChange)b.onConnectionsChange(f.INPUT,h.target_slot,!1,h,k);if(this.graph&&this.graph.onNodeConnectionChange)this.graph.onNodeConnectionChange(f.INPUT,b,h.target_slot)}delete this.graph.links[g];if(this.onConnectionsChange)this.onConnectionsChange(f.OUTPUT,a,!1,h,c);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(f.OUTPUT,this,a),this.graph.onNodeConnectionChange(f.INPUT,b,h.target_slot))}c.links=null}this.setDirtyCanvas(!1,
!0);this.graph.connectionChange(this);return!0};q.prototype.disconnectInput=function(a){if(a.constructor===String){if(a=this.findInputSlot(a),-1==a)return f.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.inputs||a>=this.inputs.length)return f.debug&&console.log("Connect: Error, slot number not found"),!1;var b=this.inputs[a];if(!b)return!1;var c=this.inputs[a].link;if(null!=c){this.inputs[a].link=null;var d=this.graph.links[c];if(d){var e=this.graph.getNodeById(d.origin_id);
if(!e)return!1;var g=e.outputs[d.origin_slot];if(!g||!g.links||0==g.links.length)return!1;for(var h=0,k=g.links.length;h<k;h++)if(g.links[h]==c){g.links.splice(h,1);break}delete this.graph.links[c];this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(f.INPUT,a,!1,d,b);if(e.onConnectionsChange)e.onConnectionsChange(f.OUTPUT,h,!1,d,g);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(f.OUTPUT,e,h),this.graph.onNodeConnectionChange(f.INPUT,
this,a))}}this.setDirtyCanvas(!1,!0);this.graph&&this.graph.connectionChange(this);return!0};q.prototype.getConnectionPos=function(a,b,c){c=c||new Float32Array(2);var d=0;a&&this.inputs&&(d=this.inputs.length);!a&&this.outputs&&(d=this.outputs.length);var e=.5*f.NODE_SLOT_HEIGHT;if(this.flags.collapsed)return b=this._collapsed_width||f.NODE_COLLAPSED_WIDTH,this.horizontal?(c[0]=this.pos[0]+.5*b,c[1]=a?this.pos[1]-f.NODE_TITLE_HEIGHT:this.pos[1]):(c[0]=a?this.pos[0]:this.pos[0]+b,c[1]=this.pos[1]-
.5*f.NODE_TITLE_HEIGHT),c;if(a&&-1==b)return c[0]=this.pos[0]+.5*f.NODE_TITLE_HEIGHT,c[1]=this.pos[1]+.5*f.NODE_TITLE_HEIGHT,c;if(a&&d>b&&this.inputs[b].pos)return c[0]=this.pos[0]+this.inputs[b].pos[0],c[1]=this.pos[1]+this.inputs[b].pos[1],c;if(!a&&d>b&&this.outputs[b].pos)return c[0]=this.pos[0]+this.outputs[b].pos[0],c[1]=this.pos[1]+this.outputs[b].pos[1],c;if(this.horizontal)return c[0]=this.pos[0]+this.size[0]/d*(b+.5),c[1]=a?this.pos[1]-f.NODE_TITLE_HEIGHT:this.pos[1]+this.size[1],c;c[0]=
a?this.pos[0]+e:this.pos[0]+this.size[0]+1-e;c[1]=this.pos[1]+(b+.7)*f.NODE_SLOT_HEIGHT+(this.constructor.slot_start_y||0);return c};q.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)};q.prototype.trace=function(a){this.console||(this.console=[]);this.console.push(a);this.console.length>q.MAX_CONSOLE&&this.console.shift();if(this.graph.onNodeTrace)this.graph.onNodeTrace(this,
a)};q.prototype.setDirtyCanvas=function(a,b){this.graph&&this.graph.sendActionToCanvas("setDirty",[a,b])};q.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};q.prototype.captureInput=function(a){if(this.graph&&this.graph.list_of_graphcanvas)for(var b=this.graph.list_of_graphcanvas,c=0;c<b.length;++c){var d=b[c];if(a||d.node_capturing_input==this)d.node_capturing_input=a?this:null}};q.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)};q.prototype.pin=function(a){this.graph._version++;this.flags.pinned=void 0===a?!this.flags.pinned:a};q.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]]};p.LGraphGroup=f.LGraphGroup=y;y.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})};y.prototype.configure=function(a){this.title=a.title;this._bounding.set(a.bounding);this.color=a.color;this.font=a.font};y.prototype.serialize=function(){var a=this._bounding;return{title:this.title,bounding:[Math.round(a[0]),Math.round(a[1]),Math.round(a[2]),Math.round(a[3])],color:this.color,font:this.font}};y.prototype.move=function(a,b,c){this._pos[0]+=a;this._pos[1]+=b;if(!c)for(c=0;c<this._nodes.length;++c){var d=this._nodes[c];d.pos[0]+=a;d.pos[1]+=b}};y.prototype.recomputeInsideNodes=
function(){this._nodes.length=0;for(var a=this.graph._nodes,b=new Float32Array(4),c=0;c<a.length;++c){var d=a[c];d.getBounding(b);H(this._bounding,b)&&this._nodes.push(d)}};y.prototype.isPointInside=q.prototype.isPointInside;y.prototype.setDirtyCanvas=q.prototype.setDirtyCanvas;f.DragAndScale=z;z.prototype.bindEvents=function(a){this.last_mouse=new Float32Array(2);this._binded_mouse_callback=this.onMouse.bind(this);a.addEventListener("mousedown",this._binded_mouse_callback);a.addEventListener("mousemove",
this._binded_mouse_callback);a.addEventListener("mousewheel",this._binded_mouse_callback,!1);a.addEventListener("wheel",this._binded_mouse_callback,!1)};z.prototype.computeVisibleArea=function(a){if(this.element){var b=this.element.width,c=this.element.height,d=-this.offset[0],e=-this.offset[1];a&&(d+=a[0]/this.scale,e+=a[1]/this.scale,b=a[2],c=a[3]);a=d+b/this.scale;c=e+c/this.scale;this.visible_area[0]=d;this.visible_area[1]=e;this.visible_area[2]=a-d;this.visible_area[3]=c-e}else this.visible_area[0]=
this.visible_area[1]=this.visible_area[2]=this.visible_area[3]=0};z.prototype.onMouse=function(a){if(this.enabled){var b=this.element,c=b.getBoundingClientRect(),d=a.clientX-c.left;c=a.clientY-c.top;a.canvasx=d;a.canvasy=c;a.dragging=this.dragging;var e=!this.viewport||this.viewport&&d>=this.viewport[0]&&d<this.viewport[0]+this.viewport[2]&&c>=this.viewport[1]&&c<this.viewport[1]+this.viewport[3],g=!1;this.onmouse&&(g=this.onmouse(a));"mousedown"==a.type&&e?(this.dragging=!0,b.removeEventListener("mousemove",
this._binded_mouse_callback),document.body.addEventListener("mousemove",this._binded_mouse_callback),document.body.addEventListener("mouseup",this._binded_mouse_callback)):"mousemove"==a.type?g||(b=d-this.last_mouse[0],g=c-this.last_mouse[1],this.dragging&&this.mouseDrag(b,g)):"mouseup"==a.type?(this.dragging=!1,document.body.removeEventListener("mousemove",this._binded_mouse_callback),document.body.removeEventListener("mouseup",this._binded_mouse_callback),b.addEventListener("mousemove",this._binded_mouse_callback)):
!e||"mousewheel"!=a.type&&"wheel"!=a.type&&"DOMMouseScroll"!=a.type||(a.eventType="mousewheel",a.wheel="wheel"==a.type?-a.deltaY:null!=a.wheelDeltaY?a.wheelDeltaY:-60*a.detail,a.delta=a.wheelDelta?a.wheelDelta/40:a.deltaY?-a.deltaY/3:0,this.changeDeltaScale(1+.05*a.delta));this.last_mouse[0]=d;this.last_mouse[1]=c;if(e)return a.preventDefault(),a.stopPropagation(),!1}};z.prototype.toCanvasContext=function(a){a.scale(this.scale,this.scale);a.translate(this.offset[0],this.offset[1])};z.prototype.convertOffsetToCanvas=
function(a){return[(a[0]+this.offset[0])*this.scale,(a[1]+this.offset[1])*this.scale]};z.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};z.prototype.mouseDrag=function(a,b){this.offset[0]+=a/this.scale;this.offset[1]+=b/this.scale;if(this.onredraw)this.onredraw(this)};z.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)}};z.prototype.changeDeltaScale=function(a,b){this.changeScale(this.scale*a,b)};z.prototype.reset=function(){this.scale=1;this.offset[0]=0;this.offset[1]=0};p.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.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]))}};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());this._mousemove_callback=this.processMouseMove.bind(this);this._mouseup_callback=this.processMouseUp.bind(this);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);a.addEventListener("mousedown",this._mousedown_callback,!0);a.addEventListener("mousemove",this._mousemove_callback);a.addEventListener("mousewheel",this._mousewheel_callback,!1);
a.addEventListener("contextmenu",this._doNothing);a.addEventListener("DOMMouseScroll",this._mousewheel_callback,!1);a.addEventListener("touchstart",this.touchHandler,!0);a.addEventListener("touchmove",this.touchHandler,!0);a.addEventListener("touchend",this.touchHandler,!0);a.addEventListener("touchcancel",this.touchHandler,!0);this._key_callback=this.processKey.bind(this);a.addEventListener("keydown",this._key_callback,!0);b.addEventListener("keyup",this._key_callback,!0);this._ondrop_callback=this.processDrop.bind(this);
a.addEventListener("dragover",this._doNothing,!1);a.addEventListener("dragend",this._doNothing,!1);a.addEventListener("drop",this._ondrop_callback,!1);a.addEventListener("dragenter",this._doReturnTrue,!1);this._events_binded=!0}};l.prototype.unbindEvents=function(){if(this._events_binded){var a=this.getCanvasWindow().document;this.canvas.removeEventListener("mousedown",this._mousedown_callback);this.canvas.removeEventListener("mousewheel",this._mousewheel_callback);this.canvas.removeEventListener("DOMMouseScroll",
this._mousewheel_callback);this.canvas.removeEventListener("keydown",this._key_callback);a.removeEventListener("keyup",this._key_callback);this.canvas.removeEventListener("contextmenu",this._doNothing);this.canvas.removeEventListener("drop",this._ondrop_callback);this.canvas.removeEventListener("dragenter",this._doReturnTrue);this.canvas.removeEventListener("touchstart",this.touchHandler);this.canvas.removeEventListener("touchmove",this.touchHandler);this.canvas.removeEventListener("touchend",this.touchHandler);
this.canvas.removeEventListener("touchcancel",this.touchHandler);this._ondrop_callback=this._key_callback=this._mousewheel_callback=this._mousedown_callback=null;this._events_binded=!1}else console.warn("LGraphCanvas: no events binded")};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(){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,d=a.localX,e=a.localY;this.ds.viewport=this.viewport;d=!this.viewport||this.viewport&&d>=this.viewport[0]&&d<this.viewport[0]+this.viewport[2]&&e>=this.viewport[1]&&
e<this.viewport[1]+this.viewport[3];this.options.skip_events||(this.canvas.removeEventListener("mousemove",this._mousemove_callback),b.document.addEventListener("mousemove",this._mousemove_callback,!0),b.document.addEventListener("mouseup",this._mouseup_callback,!0));if(d){var g=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes,5);e=!1;d=300>f.getTime()-this.last_mouseclick;this.mouse[0]=a.localX;this.mouse[1]=a.localY;this.graph_mouse[0]=a.canvasX;this.graph_mouse[1]=a.canvasY;this.last_click_position=
[this.mouse[0],this.mouse[1]];this.canvas.focus();f.closeAllContextMenus(b);if(!this.onMouse||1!=this.onMouse(a)){if(1==a.which){a.ctrlKey&&(this.dragging_rectangle=new Float32Array(4),this.dragging_rectangle[0]=a.canvasX,this.dragging_rectangle[1]=a.canvasY,this.dragging_rectangle[2]=1,this.dragging_rectangle[3]=1,e=!0);var h=!1;if(g&&this.allow_interaction&&!e&&!this.read_only){this.live_mode||g.flags.pinned||this.bringToFront(g);if(!this.connecting_node&&!g.flags.collapsed&&!this.live_mode)if(!e&&
!1!==g.resizable&&C(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)for(var k=0,n=g.outputs.length;k<n;++k){var u=g.outputs[k],t=g.getConnectionPos(!1,k);if(C(a.canvasX,a.canvasY,t[0]-15,t[1]-10,30,20)){this.connecting_node=g;this.connecting_output=u;this.connecting_pos=g.getConnectionPos(!1,k);this.connecting_slot=k;a.shiftKey&&g.disconnectOutput(k);if(d){if(g.onOutputDblClick)g.onOutputDblClick(k,
a)}else if(g.onOutputClick)g.onOutputClick(k,a);e=!0;break}}if(g.inputs)for(k=0,n=g.inputs.length;k<n;++k)if(u=g.inputs[k],t=g.getConnectionPos(!0,k),C(a.canvasX,a.canvasY,t[0]-15,t[1]-10,30,20)){if(d){if(g.onInputDblClick)g.onInputDblClick(k,a)}else if(g.onInputClick)g.onInputClick(k,a);if(null!==u.link){e=this.graph.links[u.link];g.disconnectInput(k);if(this.allow_reconnect_links||a.shiftKey)this.connecting_node=this.graph._nodes_by_id[e.origin_id],this.connecting_slot=e.origin_slot,this.connecting_output=
this.connecting_node.outputs[this.connecting_slot],this.connecting_pos=this.connecting_node.getConnectionPos(!1,this.connecting_slot);e=this.dirty_bgcanvas=!0}}}if(!e){k=!1;n=[a.canvasX-g.pos[0],a.canvasY-g.pos[1]];if(t=this.processNodeWidgets(g,this.graph_mouse,a))k=!0,this.node_widget=[g,t];if(d&&this.selected_nodes[g.id]){if(g.onDblClick)g.onDblClick(a,n,this);this.processNodeDblClicked(g);k=!0}g.onMouseDown&&g.onMouseDown(a,n,this)?k=!0:(g.subgraph&&!g.skip_subgraph_button&&!g.flags.collapsed&&
n[0]>g.size[0]-f.NODE_TITLE_HEIGHT&&0>n[1]&&(c=this,setTimeout(function(){c.openSubgraph(g.subgraph)},10)),this.live_mode&&(k=h=!0));k||(this.allow_dragnodes&&(this.graph.beforeChange(),this.node_dragged=g),this.selected_nodes[g.id]||this.processNodeSelected(g,a));this.dirty_canvas=!0}}else{if(!this.read_only)for(k=0;k<this.visible_links.length;++k)if(h=this.visible_links[k],n=h._pos,!(!n||a.canvasX<n[0]-4||a.canvasX>n[0]+4||a.canvasY<n[1]-4||a.canvasY>n[1]+4)){this.showLinkMenu(h,a);this.over_link_center=
null;break}this.selected_group=this.graph.getGroupOnPos(a.canvasX,a.canvasY);this.selected_group_resizing=!1;this.selected_group&&!this.read_only&&(a.ctrlKey&&(this.dragging_rectangle=null),10>J([a.canvasX,a.canvasY],[this.selected_group.pos[0]+this.selected_group.size[0],this.selected_group.pos[1]+this.selected_group.size[1]])*this.ds.scale?this.selected_group_resizing=!0:this.selected_group.recomputeInsideNodes());d&&!this.read_only&&this.allow_searchbox&&this.showSearchBox(a);h=!0}!e&&h&&this.allow_dragcanvas&&
(this.dragging_canvas=!0)}else 2!=a.which&&3==a.which&&(this.read_only||this.processContextMenu(g,a));this.last_mouse[0]=a.localX;this.last_mouse[1]=a.localY;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.localX,a.localY];this.mouse[0]=b[0];this.mouse[1]=b[1];var c=[b[0]-this.last_mouse[0],b[1]-this.last_mouse[1]];this.last_mouse=b;this.graph_mouse[0]=a.canvasX;this.graph_mouse[1]=a.canvasY;if(this.block_click)return a.preventDefault(),!1;a.dragging=this.last_mouse_dragging;this.node_widget&&(this.processNodeWidgets(this.node_widget[0],
this.graph_mouse,a,this.node_widget[1]),this.dirty_canvas=!0);if(this.dragging_rectangle)this.dragging_rectangle[2]=a.canvasX-this.dragging_rectangle[0],this.dragging_rectangle[3]=a.canvasY-this.dragging_rectangle[1],this.dirty_canvas=!0;else if(this.selected_group&&!this.read_only)this.selected_group_resizing?this.selected_group.size=[a.canvasX-this.selected_group.pos[0],a.canvasY-this.selected_group.pos[1]]:(this.selected_group.move(c[0]/this.ds.scale,c[1]/this.ds.scale,a.ctrlKey),this.selected_group._nodes.length&&
(this.dirty_canvas=!0)),this.dirty_bgcanvas=!0;else if(this.dragging_canvas)this.ds.offset[0]+=c[0]/this.ds.scale,this.ds.offset[1]+=c[1]/this.ds.scale,this.dirty_bgcanvas=this.dirty_canvas=!0;else if(this.allow_interaction&&!this.read_only){this.connecting_node&&(this.dirty_canvas=!0);var d=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes);b=0;for(var e=this.graph._nodes.length;b<e;++b)if(this.graph._nodes[b].mouseOver&&d!=this.graph._nodes[b]){this.graph._nodes[b].mouseOver=!1;if(this.node_over&&
this.node_over.onMouseLeave)this.node_over.onMouseLeave(a);this.node_over=null;this.dirty_canvas=!0}if(d){d.redraw_on_mouse&&(this.dirty_canvas=!0);if(!d.mouseOver&&(d.mouseOver=!0,this.node_over=d,this.dirty_canvas=!0,d.onMouseEnter))d.onMouseEnter(a);if(d.onMouseMove)d.onMouseMove(a,[a.canvasX-d.pos[0],a.canvasY-d.pos[1]],this);if(this.connecting_node&&(e=this._highlight_input||[0,0],!this.isOverNodeBox(d,a.canvasX,a.canvasY))){var g=this.isOverNodeInput(d,a.canvasX,a.canvasY,e);-1!=g&&d.inputs[g]?
f.isValidConnection(this.connecting_output.type,d.inputs[g].type)&&(this._highlight_input=e):this._highlight_input=null}this.canvas&&(C(a.canvasX,a.canvasY,d.pos[0]+d.size[0]-5,d.pos[1]+d.size[1]-5,5,5)?this.canvas.style.cursor="se-resize":this.canvas.style.cursor="crosshair")}else{e=null;for(b=0;b<this.visible_links.length;++b){g=this.visible_links[b];var h=g._pos;if(!(!h||a.canvasX<h[0]-4||a.canvasX>h[0]+4||a.canvasY<h[1]-4||a.canvasY>h[1]+4)){e=g;break}}e!=this.over_link_center&&(this.over_link_center=
e,this.dirty_canvas=!0);this.canvas&&(this.canvas.style.cursor="")}if(this.node_capturing_input&&this.node_capturing_input!=d&&this.node_capturing_input.onMouseMove)this.node_capturing_input.onMouseMove(a,[a.canvasX-this.node_capturing_input.pos[0],a.canvasY-this.node_capturing_input.pos[1]],this);if(this.node_dragged&&!this.live_mode){for(b in this.selected_nodes)d=this.selected_nodes[b],d.pos[0]+=c[0]/this.ds.scale,d.pos[1]+=c[1]/this.ds.scale;this.dirty_bgcanvas=this.dirty_canvas=!0}this.resizing_node&&
!this.live_mode&&(c=[a.canvasX-this.resizing_node.pos[0],a.canvasY-this.resizing_node.pos[1]],b=this.resizing_node.computeSize(),c[0]=Math.max(b[0],c[0]),c[1]=Math.max(b[1],c[1]),this.resizing_node.setSize(c),this.canvas.style.cursor="se-resize",this.dirty_bgcanvas=this.dirty_canvas=!0)}a.preventDefault();return!1}};l.prototype.processMouseUp=function(a){this.set_canvas_dirty_on_mouse_event&&(this.dirty_canvas=!0);if(this.graph){var b=this.getCanvasWindow().document;l.active_canvas=this;this.options.skip_events||
(b.removeEventListener("mousemove",this._mousemove_callback,!0),this.canvas.addEventListener("mousemove",this._mousemove_callback,!0),b.removeEventListener("mouseup",this._mouseup_callback,!0));this.adjustMouseEvent(a);b=f.getTime();a.click_time=b-this.last_mouseclick;this.last_mouse_dragging=!1;this.last_click_position=null;this.block_click&&(console.log("foo"),this.block_click=!1);if(1==a.which)if(this.node_widget&&this.processNodeWidgets(this.node_widget[0],this.graph_mouse,a),this.node_widget=
null,this.selected_group&&(this.selected_group.move(this.selected_group.pos[0]-Math.round(this.selected_group.pos[0]),this.selected_group.pos[1]-Math.round(this.selected_group.pos[1]),a.ctrlKey),this.selected_group.pos[0]=Math.round(this.selected_group.pos[0]),this.selected_group.pos[1]=Math.round(this.selected_group.pos[1]),this.selected_group._nodes.length&&(this.dirty_canvas=!0),this.selected_group=null),this.selected_group_resizing=!1,this.dragging_rectangle){if(this.graph){b=this.graph._nodes;
var c=new Float32Array(4);this.deselectAllNodes();var d=Math.abs(this.dragging_rectangle[2]),e=Math.abs(this.dragging_rectangle[3]),g=0>this.dragging_rectangle[3]?this.dragging_rectangle[1]-e:this.dragging_rectangle[1];this.dragging_rectangle[0]=0>this.dragging_rectangle[2]?this.dragging_rectangle[0]-d:this.dragging_rectangle[0];this.dragging_rectangle[1]=g;this.dragging_rectangle[2]=d;this.dragging_rectangle[3]=e;e=[];for(g=0;g<b.length;++g)d=b[g],d.getBounding(c),H(this.dragging_rectangle,c)&&e.push(d);
e.length&&this.selectNodes(e)}this.dragging_rectangle=null}else if(this.connecting_node){this.dirty_bgcanvas=this.dirty_canvas=!0;if(d=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes))this.connecting_output.type==f.EVENT&&this.isOverNodeBox(d,a.canvasX,a.canvasY)?this.connecting_node.connect(this.connecting_slot,d,f.EVENT):(b=this.isOverNodeInput(d,a.canvasX,a.canvasY),-1!=b?this.connecting_node.connect(this.connecting_slot,d,b):(b=d.getInputInfo(0),this.connecting_output.type==f.EVENT?
this.connecting_node.connect(this.connecting_slot,d,f.EVENT):b&&!b.link&&f.isValidConnection(b.type&&this.connecting_output.type)&&this.connecting_node.connect(this.connecting_slot,d,0)));this.connecting_node=this.connecting_pos=this.connecting_output=null;this.connecting_slot=-1}else if(this.resizing_node)this.dirty_bgcanvas=this.dirty_canvas=!0,this.graph.afterChange(this.resizing_node),this.resizing_node=null;else if(this.node_dragged){(d=this.node_dragged)&&300>a.click_time&&C(a.canvasX,a.canvasY,
d.pos[0],d.pos[1]-f.NODE_TITLE_HEIGHT,f.NODE_TITLE_HEIGHT,f.NODE_TITLE_HEIGHT)&&d.collapse();this.dirty_bgcanvas=this.dirty_canvas=!0;this.node_dragged.pos[0]=Math.round(this.node_dragged.pos[0]);this.node_dragged.pos[1]=Math.round(this.node_dragged.pos[1]);(this.graph.config.align_to_grid||this.align_to_grid)&&this.node_dragged.alignToGrid();if(this.onNodeMoved)this.onNodeMoved(this.node_dragged);this.graph.afterChange(this.node_dragged);this.node_dragged=null}else{d=this.graph.getNodeOnPos(a.canvasX,
a.canvasY,this.visible_nodes);!d&&300>a.click_time&&this.deselectAllNodes();this.dirty_canvas=!0;this.dragging_canvas=!1;if(this.node_over&&this.node_over.onMouseUp)this.node_over.onMouseUp(a,[a.canvasX-this.node_over.pos[0],a.canvasY-this.node_over.pos[1]],this);if(this.node_capturing_input&&this.node_capturing_input.onMouseUp)this.node_capturing_input.onMouseUp(a,[a.canvasX-this.node_capturing_input.pos[0],a.canvasY-this.node_capturing_input.pos[1]])}else 2==a.which?(this.dirty_canvas=!0,this.dragging_canvas=
!1):3==a.which&&(this.dirty_canvas=!0,this.dragging_canvas=!1);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.localX,d=a.localY;if(!this.viewport||this.viewport&&c>=this.viewport[0]&&c<this.viewport[0]+this.viewport[2]&&d>=this.viewport[1]&&d<this.viewport[1]+this.viewport[3])return c=this.ds.scale,0<b?c*=1.1:0>
b&&(c*=1/1.1),this.ds.changeScale(c,[a.localX,a.localY]),this.graph.change(),a.preventDefault(),!1}};l.prototype.isOverNodeBox=function(a,b,c){var d=f.NODE_TITLE_HEIGHT;return C(b,c,a.pos[0]+2,a.pos[1]+2-d,d-4,d-4)?!0:!1};l.prototype.isOverNodeInput=function(a,b,c,d){if(a.inputs)for(var e=0,g=a.inputs.length;e<g;++e){var h=a.getConnectionPos(!0,e);if(a.horizontal?C(b,c,h[0]-5,h[1]-10,10,20):C(b,c,h[0]-10,h[1]-5,40,10))return d&&(d[0]=h[0],d[1]=h[1]),e}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),65==a.keyCode&&a.ctrlKey&&(this.selectNodes(),b=!0),"KeyC"==a.code&&(a.metaKey||a.ctrlKey)&&!a.shiftKey&&this.selected_nodes&&(this.copyToClipboard(),b=!0),"KeyV"!=a.code||!a.metaKey&&!a.ctrlKey||a.shiftKey||this.pasteFromClipboard(),46!=a.keyCode&&8!=a.keyCode||"input"==a.target.localName||"textarea"==a.target.localName||(this.deleteSelectedNodes(),b=!0),this.selected_nodes)for(var c in this.selected_nodes)if(this.selected_nodes[c].onKeyDown)this.selected_nodes[c].onKeyDown(a)}else if("keyup"==
a.type&&(32==a.keyCode&&(this.dragging_canvas=!1),this.selected_nodes))for(c in this.selected_nodes)if(this.selected_nodes[c].onKeyUp)this.selected_nodes[c].onKeyUp(a);this.graph.change();if(b)return a.preventDefault(),a.stopImmediatePropagation(),!1}}};l.prototype.copyToClipboard=function(){var a={nodes:[],links:[]},b=0,c=[],d;for(d in this.selected_nodes){var e=this.selected_nodes[d];e._relative_id=b;c.push(e);b+=1}for(d=0;d<c.length;++d)if(e=c[d],b=e.clone()){if(a.nodes.push(b.serialize()),e.inputs&&
e.inputs.length)for(b=0;b<e.inputs.length;++b){var g=e.inputs[b];if(g&&null!=g.link&&(g=this.graph.links[g.link])){var h=this.graph.getNodeById(g.origin_id);h&&this.selected_nodes[h.id]&&a.links.push([h._relative_id,g.origin_slot,e._relative_id,g.target_slot])}}}else console.warn("node type not found: "+e.type);localStorage.setItem("litegrapheditor_clipboard",JSON.stringify(a))};l.prototype.pasteFromClipboard=function(){var a=localStorage.getItem("litegrapheditor_clipboard");if(a){this.graph.beforeChange();
a=JSON.parse(a);for(var b=[],c=0;c<a.nodes.length;++c){var d=a.nodes[c],e=f.createNode(d.type);e&&(e.configure(d),e.pos[0]+=5,e.pos[1]+=5,this.graph.add(e),b.push(e))}for(c=0;c<a.links.length;++c){d=a.links[c];e=b[d[0]];var g=b[d[2]];e&&g?e.connect(d[1],g,d[3]):console.warn("Warning, nodes missing on pasting")}this.selectNodes(b);this.graph.afterChange()}};l.prototype.processDrop=function(a){a.preventDefault();this.adjustMouseEvent(a);var b=a.localX,c=a.localY;if(!this.viewport||this.viewport&&b>=
this.viewport[0]&&b<this.viewport[0]+this.viewport[2]&&c>=this.viewport[1]&&c<this.viewport[1]+this.viewport[3]){b=[a.canvasX,a.canvasY];var d=this.graph?this.graph.getNodeOnPos(b[0],b[1]):null;if(d){if((d.onDropFile||d.onDropData)&&(b=a.dataTransfer.files)&&b.length)for(c=0;c<b.length;c++){var e=a.dataTransfer.files[0],g=e.name;l.getFileExtension(g);if(d.onDropFile)d.onDropFile(e);if(d.onDropData){var h=new FileReader;h.onload=function(a){d.onDropData(a.target.result,g,e)};var f=e.type.split("/")[0];
"text"==f||""==f?h.readAsText(e):"image"==f?h.readAsDataURL(e):h.readAsArrayBuffer(e)}}return d.onDropItem&&d.onDropItem(event)?!0:this.onDropItem?this.onDropItem(event):!1}b=null;this.onDropItem&&(b=this.onDropItem(event));b||this.checkDropItem(a)}};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);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;for(b=0;b<a.length;++b){var c=a[b];if(!c.is_selected){if(!c.is_selected&&c.onSelected)c.onSelected();c.is_selected=!0;this.selected_nodes[c.id]=c;if(c.inputs)for(var d=0;d<c.inputs.length;++d)this.highlighted_links[c.inputs[d].link]=!0;if(c.outputs)for(d=0;d<c.outputs.length;++d){var e=c.outputs[d];if(e.links)for(var g=0;g<e.links.length;++g)this.highlighted_links[e.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 d=0;d<c.links.length;++d)delete this.highlighted_links[c.links[d]]}}};l.prototype.deselectAllNodes=function(){if(this.graph){for(var a=this.graph._nodes,
b=0,c=a.length;b<c;++b){var d=a[b];if(d.is_selected){if(d.onDeselected)d.onDeselected();d.is_selected=!1;if(this.onNodeDeselected)this.onNodeDeselected(d)}}this.selected_nodes={};this.current_node=null;this.highlighted_links={};if(this.onSelectionChange)this.onSelectionChange(this.selected_nodes);this.setDirty(!0)}};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],d=b.graph.links[b.outputs[0].links[0]],e=b.getInputNode(0),g=b.getOutputNodes(0)[0];e&&g&&e.connect(c.origin_slot,g,d.target_slot)}this.graph.remove(b);if(this.onNodeDeselected)this.onNodeDeselected(b)}}this.selected_nodes={};this.current_node=null;this.highlighted_links={};this.setDirty(!0);this.graph.afterChange()};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();a.localX=a.clientX-b.left;a.localY=a.clientY-b.top}else a.localX=a.clientX,a.localY=a.clientY;a.deltaX=a.localX-this.last_mouse_position[0];a.deltaY=a.localY-this.last_mouse_position[1];this.last_mouse_position[0]=a.localX;
this.last_mouse_position[1]=a.localY;a.canvasX=a.localX/this.ds.scale-this.ds.offset[0];a.canvasY=a.localY/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 K=new Float32Array(4);l.prototype.computeVisibleNodes=function(a,b){b=b||[];b.length=0;a=a||this.graph._nodes;for(var c=0,d=a.length;c<d;++c){var e=a[c];
(!this.live_mode||e.onDrawBackground||e.onDrawForeground)&&H(this.visible_area,e.getBounding(K))&&b.push(e)}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 d=0;d<b.length;++d){var e=b[d];a.save();a.translate(e.pos[0],e.pos[1]);this.drawNode(e,a);a.restore()}this.render_execution_order&&this.drawExecutionOrder(a);this.graph.config.links_ontop&&
(this.live_mode||this.drawConnections(a));if(null!=this.connecting_pos){a.lineWidth=this.connections_width;switch(this.connecting_output.type){case f.EVENT:b=f.EVENT_LINK_COLOR;break;default:b=f.CONNECTING_LINK_COLOR}this.renderLink(a,this.connecting_pos,[this.graph_mouse[0],this.graph_mouse[1]],null,!1,null,b,this.connecting_output.dir||(this.connecting_node.horizontal?f.DOWN:f.RIGHT),f.CENTER);a.beginPath();this.connecting_output.type===f.EVENT||this.connecting_output.shape===f.BOX_SHAPE?a.rect(this.connecting_pos[0]-
6+.5,this.connecting_pos[1]-5+.5,14,10):a.arc(this.connecting_pos[0],this.connecting_pos[1],4,0,2*Math.PI);a.fill();a.fillStyle="#ffcc00";this._highlight_input&&(a.beginPath(),a.arc(this._highlight_input[0],this._highlight_input[1],6,0,2*Math.PI),a.fill())}this.dragging_rectangle&&(a.strokeStyle="#FFF",a.strokeRect(this.dragging_rectangle[0],this.dragging_rectangle[1],this.dragging_rectangle[2],this.dragging_rectangle[3]));if(this.over_link_center&&this.render_link_tooltip)this.drawLinkTooltip(a,
this.over_link_center);else if(this.onDrawLinkTooltip)this.onDrawLinkTooltip(a,null);if(this.onDrawForeground)this.onDrawForeground(a,this.visible_rect);a.restore()}this._graph_stack&&this._graph_stack.length&&this.drawSubgraphPanel(a);if(this.onDrawOverlay)this.onDrawOverlay(a);c&&a.restore();a.finish2D&&a.finish2D()}};l.prototype.drawSubgraphPanel=function(a){var b=this.graph,c=b._subgraph_node;if(c){var d=c.inputs?c.inputs.length:0,e=Math.floor(1.6*f.NODE_SLOT_HEIGHT);a.fillStyle="#111";a.globalAlpha=
.8;a.beginPath();a.roundRect(10,10,300,(d+1)*e+50,8);a.fill();a.globalAlpha=1;a.fillStyle="#888";a.font="14px Arial";a.textAlign="left";a.fillText("Graph Inputs",20,34);if(this.drawButton(280,20,20,20,"X","#151515"))this.closeSubgraph();else{d=50;a.font="20px Arial";if(c.inputs)for(var g=0;g<c.inputs.length;++g){var h=c.inputs[g];if(!h.not_subgraph_input){if(this.drawButton(20,d+2,280,e-2)){var k=c.constructor.input_node_type||"graph/input";this.graph.beforeChange();var n=f.createNode(k);n?(b.add(n),
this.block_click=!1,this.last_click_position=null,this.selectNodes([n]),this.node_dragged=n,this.dragging_canvas=!1,n.setProperty("name",h.name),n.setProperty("type",h.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:",k)}a.fillStyle="#9C9";a.beginPath();a.arc(284,d+.5*e,5,0,2*Math.PI);a.fill();a.fillStyle="#AAA";a.fillText(h.name,50,d+.75*e);k=a.measureText(h.name);a.fillStyle="#777";
a.fillText(h.type,50+k.width+10,d+.75*e);d+=e}}this.drawButton(20,d+2,280,e-2,"+","#151515","#222")&&this.showSubgraphPropertiesDialog(c)}}else console.warn("subgraph without subnode")};l.prototype.drawButton=function(a,b,c,d,e,g,h,k){var n=this.ctx;g=g||f.NODE_DEFAULT_COLOR;h=h||"#555";k=k||f.NODE_TEXT_COLOR;var u=this.mouse,t=f.isInsideRectangle(u[0],u[1],a,b,c,d);u=(u=this.last_click_position)&&f.isInsideRectangle(u[0],u[1],a,b,c,d);n.fillStyle=t?h:g;u&&(n.fillStyle="#AAA");n.beginPath();n.roundRect(a,
b,c,d,4);n.fill();null!=e&&e.constructor==String&&(n.fillStyle=k,n.textAlign="center",n.font=(.65*d|0)+"px Arial",n.fillText(e,a+.5*c,b+.75*d),n.textAlign="left");a=u&&!this.block_click;u&&this.blockClick();return a};l.prototype.isAreaClicked=function(a,b,c,d,e){var g=this.mouse;f.isInsideRectangle(g[0],g[1],a,b,c,d);b=(a=(g=this.last_click_position)&&f.isInsideRectangle(g[0],g[1],a,b,c,d))&&!this.block_click;a&&e&&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 d="",e=1;e<this._graph_stack.length;++e)d+=this._graph_stack[e]._subgraph_node.getTitle()+" >> ";b.fillText(d+c.getTitle(),.5*a.width,40);b.restore()}c=!1;this.onRenderBackground&&(c=this.onRenderBackground(a,b));this.viewport||(b.restore(),b.setTransform(1,0,0,1,0,0));this.visible_links.length=0;if(this.graph){b.save();this.ds.toCanvasContext(b);if(this.background_image&&.5<this.ds.scale&&!c){b.globalAlpha=this.zoom_modify_alpha?(1-.5/this.ds.scale)*this.editor_alpha:
this.editor_alpha;b.imageSmoothingEnabled=b.mozImageSmoothingEnabled=b.imageSmoothingEnabled=!1;if(!this._bg_img||this._bg_img.name!=this.background_image){this._bg_img=new Image;this._bg_img.name=this.background_image;this._bg_img.src=this.background_image;var 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.mozImageSmoothingEnabled=b.imageSmoothingEnabled=!0}this.graph._groups.length&&!this.live_mode&&this.drawGroups(a,b);if(this.onDrawBackground)this.onDrawBackground(b,this.visible_area);this.onBackgroundRender&&(console.error("WARNING! onBackgroundRender deprecated, now is named onDrawBackground "),this.onBackgroundRender=null);this.render_canvas_border&&(b.strokeStyle=
"#235",b.strokeRect(0,0,a.width,a.height));this.render_connections_shadows?(b.shadowColor="#000",b.shadowOffsetX=0,b.shadowOffsetY=0,b.shadowBlur=6):b.shadowColor="rgba(0,0,0,0)";this.live_mode||this.drawConnections(b);b.shadowColor="rgba(0,0,0,0)";b.restore()}b.finish&&b.finish();this.dirty_bgcanvas=!1;this.dirty_canvas=!0};var 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,d=a.bgcolor||a.constructor.bgcolor||
f.NODE_DEFAULT_BGCOLOR,e=.6>this.ds.scale;if(this.live_mode){if(!a.flags.collapsed&&(b.shadowColor="transparent",a.onDrawForeground))a.onDrawForeground(b,this,this.canvas)}else{var g=this.editor_alpha;b.globalAlpha=g;this.render_shadows&&!e?(b.shadowColor=f.DEFAULT_SHADOW_COLOR,b.shadowOffsetX=2*this.ds.scale,b.shadowOffsetY=2*this.ds.scale,b.shadowBlur=3*this.ds.scale):b.shadowColor="transparent";if(!a.flags.collapsed||!a.onDrawCollapsed||1!=a.onDrawCollapsed(b,this)){var h=a._shape||f.BOX_SHAPE;
D.set(a.size);var k=a.horizontal;if(a.flags.collapsed){b.font=this.inner_text_font;var n=a.getTitle?a.getTitle():a.title;null!=n&&(a._collapsed_width=Math.min(a.size[0],b.measureText(n).width+2*f.NODE_TITLE_HEIGHT),D[0]=a._collapsed_width,D[1]=0)}a.clip_area&&(b.save(),b.beginPath(),h==f.BOX_SHAPE?b.rect(0,0,D[0],D[1]):h==f.ROUND_SHAPE?b.roundRect(0,0,D[0],D[1],10):h==f.CIRCLE_SHAPE&&b.arc(.5*D[0],.5*D[1],.5*D[0],0,2*Math.PI),b.clip());a.has_errors&&(d="red");this.drawNodeShape(a,b,D,c,d,a.is_selected,
a.mouseOver);b.shadowColor="transparent";if(a.onDrawForeground)a.onDrawForeground(b,this,this.canvas);b.textAlign=k?"center":"left";b.font=this.inner_text_font;d=!e;h=this.connecting_output;b.lineWidth=1;n=0;var u=new Float32Array(2);if(!a.flags.collapsed){if(a.inputs)for(c=0;c<a.inputs.length;c++){var t=a.inputs[c];b.globalAlpha=g;this.connecting_node&&!f.isValidConnection(t.type,h.type)&&(b.globalAlpha=.4*g);b.fillStyle=null!=t.link?t.color_on||this.default_connection_color.input_on:t.color_off||
this.default_connection_color.input_off;var m=a.getConnectionPos(!0,c,u);m[0]-=a.pos[0];m[1]-=a.pos[1];n<m[1]+.5*f.NODE_SLOT_HEIGHT&&(n=m[1]+.5*f.NODE_SLOT_HEIGHT);b.beginPath();t.type===f.EVENT||t.shape===f.BOX_SHAPE?k?b.rect(m[0]-5+.5,m[1]-8+.5,10,14):b.rect(m[0]-6+.5,m[1]-5+.5,14,10):t.shape===f.ARROW_SHAPE?(b.moveTo(m[0]+8,m[1]+.5),b.lineTo(m[0]-4,m[1]+6+.5),b.lineTo(m[0]-4,m[1]-6+.5),b.closePath()):e?b.rect(m[0]-4,m[1]-4,8,8):b.arc(m[0],m[1],4,0,2*Math.PI);b.fill();if(d){var l=null!=t.label?
t.label:t.name;l&&(b.fillStyle=f.NODE_TEXT_COLOR,k||t.dir==f.UP?b.fillText(l,m[0],m[1]-10):b.fillText(l,m[0]+10,m[1]+5))}}this.connecting_node&&(b.globalAlpha=.4*g);b.textAlign=k?"center":"right";b.strokeStyle="black";if(a.outputs)for(c=0;c<a.outputs.length;c++)if(t=a.outputs[c],m=a.getConnectionPos(!1,c,u),m[0]-=a.pos[0],m[1]-=a.pos[1],n<m[1]+.5*f.NODE_SLOT_HEIGHT&&(n=m[1]+.5*f.NODE_SLOT_HEIGHT),b.fillStyle=t.links&&t.links.length?t.color_on||this.default_connection_color.output_on:t.color_off||
this.default_connection_color.output_off,b.beginPath(),t.type===f.EVENT||t.shape===f.BOX_SHAPE?k?b.rect(m[0]-5+.5,m[1]-8+.5,10,14):b.rect(m[0]-6+.5,m[1]-5+.5,14,10):t.shape===f.ARROW_SHAPE?(b.moveTo(m[0]+8,m[1]+.5),b.lineTo(m[0]-4,m[1]+6+.5),b.lineTo(m[0]-4,m[1]-6+.5),b.closePath()):e?b.rect(m[0]-4,m[1]-4,8,8):b.arc(m[0],m[1],4,0,2*Math.PI),b.fill(),e||b.stroke(),d&&(l=null!=t.label?t.label:t.name))b.fillStyle=f.NODE_TEXT_COLOR,k||t.dir==f.DOWN?b.fillText(l,m[0],m[1]-8):b.fillText(l,m[0]-10,m[1]+
5);b.textAlign="left";b.globalAlpha=1;if(a.widgets){t=n;if(k||a.widgets_up)t=2;null!=a.widgets_start_y&&(t=a.widgets_start_y);this.drawNodeWidgets(a,t,b,this.node_widget&&this.node_widget[0]==a?this.node_widget[1]:null)}}else if(this.render_collapsed_slots){e=g=null;if(a.inputs)for(c=0;c<a.inputs.length;c++)if(t=a.inputs[c],null!=t.link){g=t;break}if(a.outputs)for(c=0;c<a.outputs.length;c++)t=a.outputs[c],t.links&&t.links.length&&(e=t);g&&(g=0,c=-.5*f.NODE_TITLE_HEIGHT,k&&(g=.5*a._collapsed_width,
c=-f.NODE_TITLE_HEIGHT),b.fillStyle="#686",b.beginPath(),t.type===f.EVENT||t.shape===f.BOX_SHAPE?b.rect(g-7+.5,c-4,14,8):t.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());e&&(g=a._collapsed_width,c=-.5*f.NODE_TITLE_HEIGHT,k&&(g=.5*a._collapsed_width,c=0),b.fillStyle="#686",b.strokeStyle="black",b.beginPath(),t.type===f.EVENT||t.shape===f.BOX_SHAPE?b.rect(g-7+.5,c-4,14,8):t.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 d=a.measureText(b).width+20;a.shadowColor="black";a.shadowOffsetX=2;a.shadowOffsetY=2;a.shadowBlur=3;a.fillStyle="#454";a.beginPath();a.roundRect(c[0]-.5*d,c[1]-15-24,d,24,3,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 x=new Float32Array(4);l.prototype.drawNodeShape=function(a,b,c,d,e,g,h){b.strokeStyle=
d;b.fillStyle=e;e=f.NODE_TITLE_HEIGHT;var k=.5>this.ds.scale,n=a._shape||a.constructor.shape||f.ROUND_SHAPE,u=a.constructor.title_mode,t=!0;u==f.TRANSPARENT_TITLE?t=!1:u==f.AUTOHIDE_TITLE&&h&&(t=!0);x[0]=0;x[1]=t?-e:0;x[2]=c[0]+1;x[3]=t?c[1]+e:c[1];h=b.globalAlpha;b.beginPath();n==f.BOX_SHAPE||k?b.fillRect(x[0],x[1],x[2],x[3]):n==f.ROUND_SHAPE||n==f.CARD_SHAPE?b.roundRect(x[0],x[1],x[2],x[3],this.round_radius,n==f.CARD_SHAPE?0:this.round_radius):n==f.CIRCLE_SHAPE&&b.arc(.5*c[0],.5*c[1],.5*c[0],0,
2*Math.PI);b.fill();a.flags.collapsed||(b.shadowColor="transparent",b.fillStyle="rgba(0,0,0,0.2)",b.fillRect(0,-1,x[2],2));b.shadowColor="transparent";if(a.onDrawBackground)a.onDrawBackground(b,this,this.canvas,this.graph_mouse);if(t||u==f.TRANSPARENT_TITLE){if(a.onDrawTitleBar)a.onDrawTitleBar(b,e,c,this.ds.scale,d);else if(u!=f.TRANSPARENT_TITLE&&(a.constructor.title_color||this.render_title_colored)){t=a.constructor.title_color||d;a.flags.collapsed&&(b.shadowColor=f.DEFAULT_SHADOW_COLOR);if(this.use_gradients){var m=
l.gradients[t];m||(m=l.gradients[t]=b.createLinearGradient(0,0,400,0),m.addColorStop(0,t),m.addColorStop(1,"#000"));b.fillStyle=m}else b.fillStyle=t;b.beginPath();n==f.BOX_SHAPE||k?b.rect(0,-e,c[0]+1,e):(n==f.ROUND_SHAPE||n==f.CARD_SHAPE)&&b.roundRect(0,-e,c[0]+1,e,this.round_radius,a.flags.collapsed?this.round_radius:0);b.fill();b.shadowColor="transparent"}if(a.onDrawTitleBox)a.onDrawTitleBox(b,e,c,this.ds.scale);else n==f.ROUND_SHAPE||n==f.CIRCLE_SHAPE||n==f.CARD_SHAPE?(k&&(b.fillStyle="black",
b.beginPath(),b.arc(.5*e,-.5*e,6,0,2*Math.PI),b.fill()),b.fillStyle=a.boxcolor||f.NODE_DEFAULT_BOXCOLOR,k?b.fillRect(.5*e-5,-.5*e-5,10,10):(b.beginPath(),b.arc(.5*e,-.5*e,5,0,2*Math.PI),b.fill())):(k&&(b.fillStyle="black",b.fillRect(.5*(e-10)-1,-.5*(e+10)-1,12,12)),b.fillStyle=a.boxcolor||f.NODE_DEFAULT_BOXCOLOR,b.fillRect(.5*(e-10),-.5*(e+10),10,10));b.globalAlpha=h;if(a.onDrawTitleText)a.onDrawTitleText(b,e,c,this.ds.scale,this.title_text_font,g);!k&&(b.font=this.title_text_font,h=String(a.getTitle()))&&
(b.fillStyle=g?f.NODE_SELECTED_TITLE_COLOR:a.constructor.title_text_color||this.node_title_color,a.flags.collapsed?(b.textAlign="left",b.measureText(h),b.fillText(h.substr(0,20),e,f.NODE_TITLE_TEXT_Y-e),b.textAlign="left"):(b.textAlign="left",b.fillText(h,e,f.NODE_TITLE_TEXT_Y-e)));a.flags.collapsed||!a.subgraph||a.skip_subgraph_button||(h=f.NODE_TITLE_HEIGHT,t=a.size[0]-h,m=f.isInsideRectangle(this.graph_mouse[0]-a.pos[0],this.graph_mouse[1]-a.pos[1],t+2,-h+2,h-4,h-4),b.fillStyle=m?"#888":"#555",
n==f.BOX_SHAPE||k?b.fillRect(t+2,-h+2,h-4,h-4):(b.beginPath(),b.roundRect(t+2,-h+2,h-4,h-4,4),b.fill()),b.fillStyle="#333",b.beginPath(),b.moveTo(t+.2*h,.6*-h),b.lineTo(t+.8*h,.6*-h),b.lineTo(t+.5*h,.3*-h),b.fill());if(a.onDrawTitle)a.onDrawTitle(b)}if(g){if(a.onBounding)a.onBounding(x);u==f.TRANSPARENT_TITLE&&(x[1]-=e,x[3]+=e);b.lineWidth=1;b.globalAlpha=.8;b.beginPath();n==f.BOX_SHAPE?b.rect(-6+x[0],-6+x[1],12+x[2],12+x[3]):n==f.ROUND_SHAPE||n==f.CARD_SHAPE&&a.flags.collapsed?b.roundRect(-6+x[0],
-6+x[1],12+x[2],12+x[3],2*this.round_radius):n==f.CARD_SHAPE?b.roundRect(-6+x[0],-6+x[1],12+x[2],12+x[3],2*this.round_radius,2):n==f.CIRCLE_SHAPE&&b.arc(.5*c[0],.5*c[1],.5*c[0]+6,0,2*Math.PI);b.strokeStyle=f.NODE_BOX_OUTLINE_COLOR;b.stroke();b.strokeStyle=d;b.globalAlpha=1}};var I=new Float32Array(4),B=new Float32Array(4),L=new Float32Array(2),M=new Float32Array(2);l.prototype.drawConnections=function(a){var b=f.getTime(),c=this.visible_area;I[0]=c[0]-20;I[1]=c[1]-20;I[2]=c[2]+40;I[3]=c[3]+40;a.lineWidth=
this.connections_width;a.fillStyle="#AAA";a.strokeStyle="#AAA";a.globalAlpha=this.editor_alpha;c=this.graph._nodes;for(var d=0,e=c.length;d<e;++d){var g=c[d];if(g.inputs&&g.inputs.length)for(var h=0;h<g.inputs.length;++h){var k=g.inputs[h];if(k&&null!=k.link&&(k=this.graph.links[k.link])){var n=this.graph.getNodeById(k.origin_id);if(null!=n){var u=k.origin_slot;var t=-1==u?[n.pos[0]+10,n.pos[1]+10]:n.getConnectionPos(!1,u,L);var m=g.getConnectionPos(!0,h,M);B[0]=t[0];B[1]=t[1];B[2]=m[0]-t[0];B[3]=
m[1]-t[1];0>B[2]&&(B[0]+=B[2],B[2]=Math.abs(B[2]));0>B[3]&&(B[1]+=B[3],B[3]=Math.abs(B[3]));if(H(B,I)){var l=n.outputs[u];u=g.inputs[h];if(l&&u&&(n=l.dir||(n.horizontal?f.DOWN:f.RIGHT),u=u.dir||(g.horizontal?f.UP:f.LEFT),this.renderLink(a,t,m,k,!1,0,null,n,u),k&&k._last_time&&1E3>b-k._last_time)){l=2-.002*(b-k._last_time);var v=a.globalAlpha;a.globalAlpha=v*l;this.renderLink(a,t,m,k,!0,l,"white",n,u);a.globalAlpha=v}}}}}}a.globalAlpha=1};l.prototype.renderLink=function(a,b,c,d,e,g,h,k,n,u){d&&this.visible_links.push(d);
!h&&d&&(h=d.color||l.link_type_colors[d.type]);h||(h=this.default_link_color);null!=d&&this.highlighted_links[d.id]&&(h="#FFF");k=k||f.RIGHT;n=n||f.LEFT;var t=J(b,c);this.render_connections_border&&.6<this.ds.scale&&(a.lineWidth=this.connections_width+4);a.lineJoin="round";u=u||1;1<u&&(a.lineWidth=.5);a.beginPath();for(var m=0;m<u;m+=1){var r=5*(m-.5*(u-1));if(this.links_render_mode==f.SPLINE_LINK){a.moveTo(b[0],b[1]+r);var v=0,q=0,p=0,A=0;switch(k){case f.LEFT:v=-.25*t;break;case f.RIGHT:v=.25*t;
break;case f.UP:q=-.25*t;break;case f.DOWN:q=.25*t}switch(n){case f.LEFT:p=-.25*t;break;case f.RIGHT:p=.25*t;break;case f.UP:A=-.25*t;break;case f.DOWN:A=.25*t}a.bezierCurveTo(b[0]+v,b[1]+q+r,c[0]+p,c[1]+A+r,c[0],c[1]+r)}else if(this.links_render_mode==f.LINEAR_LINK){a.moveTo(b[0],b[1]+r);A=p=q=v=0;switch(k){case f.LEFT:v=-1;break;case f.RIGHT:v=1;break;case f.UP:q=-1;break;case f.DOWN:q=1}switch(n){case f.LEFT:p=-1;break;case f.RIGHT:p=1;break;case f.UP:A=-1;break;case f.DOWN:A=1}a.lineTo(b[0]+15*
v,b[1]+15*q+r);a.lineTo(c[0]+15*p,c[1]+15*A+r);a.lineTo(c[0],c[1]+r)}else if(this.links_render_mode==f.STRAIGHT_LINK)a.moveTo(b[0],b[1]),r=b[0],v=b[1],q=c[0],p=c[1],k==f.RIGHT?r+=10:v+=10,n==f.LEFT?q-=10:p-=10,a.lineTo(r,v),a.lineTo(.5*(r+q),v),a.lineTo(.5*(r+q),p),a.lineTo(q,p),a.lineTo(c[0],c[1]);else return}this.render_connections_border&&.6<this.ds.scale&&!e&&(a.strokeStyle="rgba(0,0,0,0.5)",a.stroke());a.lineWidth=this.connections_width;a.fillStyle=a.strokeStyle=h;a.stroke();e=this.computeConnectionPoint(b,
c,.5,k,n);d&&d._pos&&(d._pos[0]=e[0],d._pos[1]=e[1]);.6<=this.ds.scale&&this.highquality_render&&n!=f.CENTER&&(this.render_connection_arrows&&(m=this.computeConnectionPoint(b,c,.25,k,n),t=this.computeConnectionPoint(b,c,.26,k,n),d=this.computeConnectionPoint(b,c,.75,k,n),u=this.computeConnectionPoint(b,c,.76,k,n),this.render_curved_connections?(t=-Math.atan2(t[0]-m[0],t[1]-m[1]),u=-Math.atan2(u[0]-d[0],u[1]-d[1])):u=t=c[1]>b[1]?0:Math.PI,a.save(),a.translate(m[0],m[1]),a.rotate(t),a.beginPath(),a.moveTo(-5,
-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore(),a.save(),a.translate(d[0],d[1]),a.rotate(u),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore()),a.beginPath(),a.arc(e[0],e[1],5,0,2*Math.PI),a.fill());if(g)for(a.fillStyle=h,m=0;5>m;++m)g=(.001*f.getTime()+.2*m)%1,e=this.computeConnectionPoint(b,c,g,k,n),a.beginPath(),a.arc(e[0],e[1],5,0,2*Math.PI),a.fill()};l.prototype.computeConnectionPoint=function(a,b,c,d,e){d=d||f.RIGHT;e=e||f.LEFT;var g=J(a,b),h=[a[0],a[1]],k=
[b[0],b[1]];switch(d){case f.LEFT:h[0]+=-.25*g;break;case f.RIGHT:h[0]+=.25*g;break;case f.UP:h[1]+=-.25*g;break;case f.DOWN:h[1]+=.25*g}switch(e){case f.LEFT: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}d=(1-c)*(1-c)*(1-c);e=3*(1-c)*(1-c)*c;g=3*(1-c)*c*c;c*=c*c;return[d*a[0]+e*h[0]+g*k[0]+c*b[0],d*a[1]+e*h[1]+g*k[1]+c*b[1]]};l.prototype.drawExecutionOrder=function(a){a.shadowColor="transparent";a.globalAlpha=.25;a.textAlign="center";a.strokeStyle=
"white";a.globalAlpha=.75;for(var b=this.visible_nodes,c=0;c<b.length;++c){var d=b[c];a.fillStyle="black";a.fillRect(d.pos[0]-f.NODE_TITLE_HEIGHT,d.pos[1]-f.NODE_TITLE_HEIGHT,f.NODE_TITLE_HEIGHT,f.NODE_TITLE_HEIGHT);0==d.order&&a.strokeRect(d.pos[0]-f.NODE_TITLE_HEIGHT+.5,d.pos[1]-f.NODE_TITLE_HEIGHT+.5,f.NODE_TITLE_HEIGHT,f.NODE_TITLE_HEIGHT);a.fillStyle="#FFF";a.fillText(d.order,d.pos[0]+-.5*f.NODE_TITLE_HEIGHT,d.pos[1]-6)}a.globalAlpha=1};l.prototype.drawNodeWidgets=function(a,b,c,d){if(!a.widgets||
!a.widgets.length)return 0;var e=a.size[0],g=a.widgets;b+=2;var h=f.NODE_WIDGET_HEIGHT,k=.5<this.ds.scale;c.save();c.globalAlpha=this.editor_alpha;for(var n=f.WIDGET_OUTLINE_COLOR,l=f.WIDGET_BGCOLOR,t=f.WIDGET_TEXT_COLOR,m=f.WIDGET_SECONDARY_TEXT_COLOR,r=0;r<g.length;++r){var v=g[r],q=b;v.y&&(q=v.y);v.last_y=q;c.strokeStyle=n;c.fillStyle="#222";c.textAlign="left";v.disabled&&(c.globalAlpha*=.5);var p=v.width||e;switch(v.type){case "button":v.clicked&&(c.fillStyle="#AAA",v.clicked=!1,this.dirty_canvas=
!0);c.fillRect(15,q,p-30,h);k&&!v.disabled&&c.strokeRect(15,q,p-30,h);k&&(c.textAlign="center",c.fillStyle=t,c.fillText(v.name,.5*p,q+.7*h));break;case "toggle":c.textAlign="left";c.strokeStyle=n;c.fillStyle=l;c.beginPath();k?c.roundRect(15,b,p-30,h,.5*h):c.rect(15,b,p-30,h);c.fill();k&&!v.disabled&&c.stroke();c.fillStyle=v.value?"#89A":"#333";c.beginPath();c.arc(p-30,q+.5*h,.36*h,0,2*Math.PI);c.fill();k&&(c.fillStyle=m,null!=v.name&&c.fillText(v.name,30,q+.7*h),c.fillStyle=v.value?t:m,c.textAlign=
"right",c.fillText(v.value?v.options.on||"true":v.options.off||"false",p-40,q+.7*h));break;case "slider":c.fillStyle=l;c.fillRect(15,q,p-30,h);var A=v.options.max-v.options.min,F=(v.value-v.options.min)/A;c.fillStyle=d==v?"#89A":"#678";c.fillRect(15,q,F*(p-30),h);k&&!v.disabled&&c.strokeRect(15,q,p-30,h);v.marker&&(A=(v.marker-v.options.min)/A,c.fillStyle="#AA9",c.fillRect(15+A*(p-30),q,2,h));k&&(c.textAlign="center",c.fillStyle=t,c.fillText(v.name+" "+Number(v.value).toFixed(3),.5*p,q+.7*h));break;
case "number":case "combo":c.textAlign="left";c.strokeStyle=n;c.fillStyle=l;c.beginPath();k?c.roundRect(15,b,p-30,h,.5*h):c.rect(15,b,p-30,h);c.fill();k&&(v.disabled||c.stroke(),c.fillStyle=t,v.disabled||(c.beginPath(),c.moveTo(31,b+5),c.lineTo(21,b+.5*h),c.lineTo(31,b+h-5),c.fill(),c.beginPath(),c.moveTo(p-15-16,b+5),c.lineTo(p-15-6,b+.5*h),c.lineTo(p-15-16,b+h-5),c.fill()),c.fillStyle=m,c.fillText(v.name,35,q+.7*h),c.fillStyle=t,c.textAlign="right","number"==v.type?c.fillText(Number(v.value).toFixed(void 0!==
v.options.precision?v.options.precision:3),p-30-20,q+.7*h):(A=v.value,v.options.values&&(F=v.options.values,F.constructor===Function&&(F=F()),F&&F.constructor!==Array&&(A=F[v.value])),c.fillText(A,p-30-20,q+.7*h)));break;case "string":case "text":c.textAlign="left";c.strokeStyle=n;c.fillStyle=l;c.beginPath();k?c.roundRect(15,b,p-30,h,.5*h):c.rect(15,b,p-30,h);c.fill();k&&(v.disabled||c.stroke(),c.save(),c.beginPath(),c.rect(15,b,p-30,h),c.clip(),c.fillStyle=m,null!=v.name&&c.fillText(v.name,30,q+
.7*h),c.fillStyle=t,c.textAlign="right",c.fillText(String(v.value).substr(0,30),p-30,q+.7*h),c.restore());break;default:v.draw&&v.draw(c,a,p,q,h)}b+=(v.computeSize?v.computeSize(p)[1]:h)+4;c.globalAlpha=this.editor_alpha}c.restore();c.textAlign="left"};l.prototype.processNodeWidgets=function(a,b,c,d){function e(d,e){d.value=e;d.options&&d.options.property&&void 0!==a.properties[d.options.property]&&a.setProperty(d.options.property,e);d.callback&&d.callback(d.value,n,a,b,c)}if(!a.widgets||!a.widgets.length)return null;
for(var g=b[0]-a.pos[0],h=b[1]-a.pos[1],k=a.size[0],n=this,l=this.getCanvasWindow(),t=0;t<a.widgets.length;++t){var m=a.widgets[t];if(m&&!m.disabled){var p=m.computeSize?m.computeSize(k)[1]:f.NODE_WIDGET_HEIGHT,q=m.width||k;if(m==d||!(6>g||g>q-12||h<m.last_y||h>m.last_y+p||void 0===m.last_y)){d=m.value;switch(m.type){case "button":if("mousemove"===c.type)break;m.callback&&setTimeout(function(){m.callback(m,n,a,b,c)},20);this.dirty_canvas=m.clicked=!0;break;case "slider":l=Math.clamp((g-15)/(q-30),
0,1);m.value=m.options.min+(m.options.max-m.options.min)*l;m.callback&&setTimeout(function(){e(m,m.value)},20);this.dirty_canvas=!0;break;case "number":case "combo":d=m.value;if("mousemove"==c.type&&"number"==m.type)m.value+=.1*c.deltaX*(m.options.step||1),null!=m.options.min&&m.value<m.options.min&&(m.value=m.options.min),null!=m.options.max&&m.value>m.options.max&&(m.value=m.options.max);else if("mousedown"==c.type){var r=m.options.values;r&&r.constructor===Function&&(r=m.options.values(m,a));var w=
null;"number"!=m.type&&(w=r.constructor===Array?r:Object.keys(r));g=40>g?-1:g>q-40?1:0;if("number"==m.type)m.value+=.1*g*(m.options.step||1),null!=m.options.min&&m.value<m.options.min&&(m.value=m.options.min),null!=m.options.max&&m.value>m.options.max&&(m.value=m.options.max);else if(g)l=-1,this.last_mouseclick=0,l=r.constructor===Object?w.indexOf(String(m.value))+g:w.indexOf(m.value)+g,l>=w.length&&(l=w.length-1),0>l&&(l=0),m.value=r.constructor===Array?r[l]:l;else{var A=r!=w?Object.values(r):r;
new f.ContextMenu(A,{scale:Math.max(1,this.ds.scale),event:c,className:"dark",callback:function(a,b,c){r!=w&&(a=A.indexOf(a));this.value=a;e(this,a);n.dirty_canvas=!0;return!1}.bind(m)},l)}}else"mouseup"==c.type&&"number"==m.type&&(g=40>g?-1:g>q-40?1:0,200>c.click_time&&0==g&&this.prompt("Value",m.value,function(a){this.value=Number(a);e(this,this.value)}.bind(m),c));d!=m.value&&setTimeout(function(){e(this,this.value)}.bind(m),20);this.dirty_canvas=!0;break;case "toggle":"mousedown"==c.type&&(m.value=
!m.value,setTimeout(function(){e(m,m.value)},20));break;case "string":case "text":"mousedown"==c.type&&this.prompt("Value",m.value,function(a){this.value=a;e(this,a)}.bind(m),c,m.options?m.options.multiline:!1);break;default:m.mouse&&(this.dirty_canvas=m.mouse(c,[g,h],a))}if(d!=m.value){if(a.onWidgetChanged)a.onWidgetChanged(m.name,m.value,d,m);a.graph._version++}return m}}}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 d=a[c];if(H(this.visible_area,d._bounding)){b.fillStyle=d.color||"#335";b.strokeStyle=d.color||"#335";var e=d._pos,g=d._size;b.globalAlpha=.25*this.editor_alpha;b.beginPath();b.rect(e[0]+.5,e[1]+.5,g[0],g[1]);b.fill();b.globalAlpha=this.editor_alpha;b.stroke();b.beginPath();b.moveTo(e[0]+g[0],e[1]+g[1]);b.lineTo(e[0]+g[0]-10,e[1]+g[1]);b.lineTo(e[0]+g[0],e[1]+g[1]-10);b.fill();g=d.font_size||f.DEFAULT_GROUP_FONT_SIZE;b.font=g+"px Arial";b.fillText(d.title,e[0]+4,e[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 d=setInterval(function(){b.editor_alpha*=c;b.dirty_canvas=!0;b.dirty_bgcanvas=!0;1>c&&.01>b.editor_alpha&&(clearInterval(d),1>c&&(b.live_mode=!0));1<c&&.99<b.editor_alpha&&(clearInterval(d),b.editor_alpha=1)},1)}else this.live_mode=!this.live_mode,this.dirty_bgcanvas=this.dirty_canvas=!0};l.prototype.onNodeSelectionChange=function(a){};l.prototype.touchHandler=function(a){var b=a.changedTouches[0];switch(a.type){case "touchstart":var c=
"mousedown";break;case "touchmove":c="mousemove";break;case "touchend":c="mouseup";break;default:return}var d=this.getCanvasWindow(),e=d.document.createEvent("MouseEvent");e.initMouseEvent(c,!0,!0,d,1,b.screenX,b.screenY,b.clientX,b.clientY,!1,!1,!1,!1,0,null);b.target.dispatchEvent(e);a.preventDefault()};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.onMenuAdd=function(a,b,c,d,e){function g(a,b){var d=
[];f.getNodeTypesCategories(h.filter||n.filter).filter(function(b){return b.startsWith(a)}).map(function(b){if(b){b=b.replace(new RegExp("^("+a+")"),"").split("/")[0];var c=""===a?b+"/":a+b+"/";-1!=b.indexOf("::")&&(b=b.split("::")[1]);-1===d.findIndex(function(a){return a.value===c})&&d.push({value:c,content:b,has_submenu:!0,callback:function(a,b,c,d){g(a.value,d)}})}});f.getNodeTypesInCategory(a.slice(0,-1),h.filter||n.filter).map(function(a){a.skip_list||d.push({value:a.type,content:a.title,has_submenu:!1,
callback:function(a,b,c,d){b=d.getFirstEvent();h.graph.beforeChange();if(a=f.createNode(a.value))a.pos=h.convertEventToCanvasOffset(b),h.graph.add(a);e&&e(a);h.graph.afterChange()}})});new f.ContextMenu(d,{event:c,parentMenu:b},k)}var h=l.active_canvas,k=h.getCanvasWindow(),n=h.graph;if(n)return g("",d),!1};l.onMenuCollapseAll=function(){};l.onMenuNodeEdit=function(){};l.showMenuNodeOptionalInputs=function(a,b,c,d,e){if(e){var g=this;a=l.active_canvas.getCanvasWindow();b=e.optional_inputs;e.onGetInputs&&
(b=e.onGetInputs());var h=[];if(b)for(var k=0;k<b.length;k++){var n=b[k];if(n){var u=n[0];n[2]&&n[2].label&&(u=n[2].label);u={content:u,value:n};n[1]==f.ACTION&&(u.className="event");h.push(u)}else h.push(null)}this.onMenuNodeInputs&&(h=this.onMenuNodeInputs(h));if(h.length)return new f.ContextMenu(h,{event:c,callback:function(a,b,c){e&&(a.callback&&a.callback.call(g,e,a,b,c),a.value&&(e.graph.beforeChange(),e.addInput(a.value[0],a.value[1],a.value[2]),e.setDirtyCanvas(!0,!0),e.graph.afterChange()))},
parentMenu:d,node:e},a),!1;console.log("no input entries")}};l.showMenuNodeOptionalOutputs=function(a,b,c,d,e){function g(a,b,c){if(e&&(a.callback&&a.callback.call(h,e,a,b,c),a.value))if(c=a.value[1],!c||c.constructor!==Object&&c.constructor!==Array)e.graph.beforeChange(),e.addOutput(a.value[0],a.value[1],a.value[2]),e.setDirtyCanvas(!0,!0),e.graph.afterChange();else{a=[];for(var k in c)a.push({content:k,value:c[k]});new f.ContextMenu(a,{event:b,callback:g,parentMenu:d,node:e});return!1}}if(e){var h=
this;a=l.active_canvas.getCanvasWindow();b=e.optional_outputs;e.onGetOutputs&&(b=e.onGetOutputs());var k=[];if(b)for(var n=0;n<b.length;n++){var u=b[n];if(!u)k.push(null);else if(!e.flags||!e.flags.skip_repeated_outputs||-1==e.findOutputSlot(u[0])){var t=u[0];u[2]&&u[2].label&&(t=u[2].label);t={content:t,value:u};u[1]==f.EVENT&&(t.className="event");k.push(t)}}this.onMenuNodeOutputs&&(k=this.onMenuNodeOutputs(k));if(k.length)return new f.ContextMenu(k,{event:c,callback:g,parentMenu:d,node:e},a),!1}};
l.onShowMenuNodeProperties=function(a,b,c,d,e){if(e&&e.properties){var g=l.active_canvas;b=g.getCanvasWindow();var h=[],k;for(k in e.properties){a=void 0!==e.properties[k]?e.properties[k]:" ";"object"==typeof a&&(a=JSON.stringify(a));var n=e.getPropertyInfo(k);if("enum"==n.type||"combo"==n.type)a=l.getPropertyPrintableValue(a,n.values);a=l.decodeHTML(a);h.push({content:"<span class='property_name'>"+(n.label?n.label:k)+"</span><span class='property_value'>"+a+"</span>",value:k})}if(h.length)return new f.ContextMenu(h,
{event:c,callback:function(a,b,c,d){e&&(b=this.getBoundingClientRect(),g.showEditPropertyValue(e,a.value,{position:[b.left,b.top]}))},parentMenu:d,allow_html:!0,node:e},b),!1}};l.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};l.onResizeNode=function(a,b,c,d,e){if(e){e.size=e.computeSize();if(e.onResize)e.onResize(e.size);e.setDirtyCanvas(!0,!0)}};l.prototype.showLinkMenu=function(a,b){var c=this;console.log(a);var d=new f.ContextMenu(["Add Node",null,
"Delete"],{event:b,title:null!=a.data?a.data.constructor.name:null,callback:function(b,g,h){switch(b){case "Add Node":l.onMenuAdd(null,null,h,d,function(b){console.log("node autoconnect");var d=c.graph.getNodeById(a.origin_id),e=c.graph.getNodeById(a.target_id);b.inputs&&b.inputs.length&&b.outputs&&b.outputs.length&&d.outputs[a.origin_slot].type==b.inputs[0].type&&b.outputs[0].type==e.inputs[0].type&&(d.connect(a.origin_slot,b,0),b.connect(0,e,a.target_slot),b.pos[0]-=.5*b.size[0])});break;case "Delete":c.graph.removeLink(a.id)}}});
return!1};l.onShowPropertyEditor=function(a,b,c,d,e){function g(){var b=n.value;"Number"==a.type?b=Number(b):"Boolean"==a.type&&(b=!!b);e[h]=b;f.parentNode&&f.parentNode.removeChild(f);e.setDirtyCanvas(!0,!0)}var h=a.property||"title";b=e[h];var f=document.createElement("div");f.className="graphdialog";f.innerHTML="<span class='name'></span><input autofocus type='text' class='value'/><button>OK</button>";f.querySelector(".name").innerText=h;var n=f.querySelector(".value");n&&(n.value=b,n.addEventListener("blur",
function(a){this.focus()}),n.addEventListener("keydown",function(a){if(13==a.keyCode||"textarea"==a.target.localName)g(),a.preventDefault(),a.stopPropagation()}));b=l.active_canvas.canvas;c=b.getBoundingClientRect();var u=d=-20;c&&(d-=c.left,u-=c.top);event?(f.style.left=event.clientX+d+"px",f.style.top=event.clientY+u+"px"):(f.style.left=.5*b.width+d+"px",f.style.top=.5*b.height+u+"px");f.querySelector("button").addEventListener("click",g);b.parentNode.appendChild(f)};l.prototype.prompt=function(a,
b,c,d,e){var g=this;a=a||"";var h=!1,f=document.createElement("div");f.className="graphdialog rounded";f.innerHTML=e?"<span class='name'></span> <textarea autofocus class='value'></textarea><button class='rounded'>OK</button>":"<span class='name'></span> <input autofocus type='text' class='value'/><button class='rounded'>OK</button>";f.close=function(){g.prompt_box=null;f.parentNode&&f.parentNode.removeChild(f)};1<this.ds.scale&&(f.style.transform="scale("+this.ds.scale+")");f.addEventListener("mouseleave",
function(a){h||f.close()});g.prompt_box&&g.prompt_box.close();g.prompt_box=f;f.querySelector(".name").innerText=a;var n=f.querySelector(".value");n.value=b;n.addEventListener("keydown",function(a){h=!0;if(27==a.keyCode)f.close();else if(13==a.keyCode&&"textarea"!=a.target.localName)c&&c(this.value),f.close();else return;a.preventDefault();a.stopPropagation()});f.querySelector("button").addEventListener("click",function(a){c&&c(n.value);g.setDirty(!0);f.close()});a=l.active_canvas.canvas;b=a.getBoundingClientRect();
var u=e=-20;b&&(e-=b.left,u-=b.top);d?(f.style.left=d.clientX+e+"px",f.style.top=d.clientY+u+"px"):(f.style.left=.5*a.width+e+"px",f.style.top=.5*a.height+u+"px");a.parentNode.appendChild(f);setTimeout(function(){n.focus()},10);return f};l.search_limit=-1;l.prototype.showSearchBox=function(a){function b(b){if(b)if(e.onSearchBoxSelection)e.onSearchBoxSelection(b,a,g);else{var c=f.searchbox_extras[b.toLowerCase()];c&&(b=c.type);g.graph.beforeChange();if(b=f.createNode(b))b.pos=g.convertEventToCanvasOffset(a),
g.graph.add(b);if(c&&c.data){if(c.data.properties)for(var d in c.data.properties)b.addProperty(d,c.data.properties[d]);if(c.data.inputs)for(d in b.inputs=[],c.data.inputs)b.addOutput(c.data.inputs[d][0],c.data.inputs[d][1]);if(c.data.outputs)for(d in b.outputs=[],c.data.outputs)b.addOutput(c.data.outputs[d][0],c.data.outputs[d][1]);c.data.title&&(b.title=c.data.title);c.data.json&&b.configure(c.data.json);g.graph.afterChange()}}n.close()}function c(a){var b=p;p&&p.classList.remove("selected");p?(p=
a?p.nextSibling:p.previousSibling)||(p=b):p=a?t.childNodes[0]:t.childNodes[t.childNodes.length];p&&(p.classList.add("selected"),p.scrollIntoView({block:"end",behavior:"smooth"}))}function d(){function a(a,c){var d=document.createElement("div");m||(m=a);d.innerText=a;d.dataset.type=escape(a);d.className="litegraph lite-search-item";c&&(d.className+=" "+c);d.addEventListener("click",function(a){b(unescape(this.dataset.type))});t.appendChild(d)}q=null;var c=r.value;m=null;t.innerHTML="";if(c)if(e.onSearchBox){var d=
e.onSearchBox(t,c,g);if(d)for(var h=0;h<d.length;++h)a(d[h])}else{d=function(a){var b=f.registered_node_types[a];return n&&b.filter!=n?!1:-1!==a.toLowerCase().indexOf(c)};var k=0;c=c.toLowerCase();var n=g.filter||g.graph.filter;for(h in f.searchbox_extras){var p=f.searchbox_extras[h];if(-1!==p.desc.toLowerCase().indexOf(c)){var u=f.registered_node_types[p.type];if(!u||u.filter==n)if(a(p.desc,"searchbox_extra"),-1!==l.search_limit&&k++>l.search_limit)break}}p=null;if(Array.prototype.filter)p=Object.keys(f.registered_node_types).filter(d);
else for(h in p=[],f.registered_node_types)d(h)&&p.push(h);for(h=0;h<p.length&&!(a(p[h]),-1!==l.search_limit&&k++>l.search_limit);h++);}}var e=this,g=l.active_canvas,h=g.canvas,k=h.ownerDocument||document,n=document.createElement("div");n.className="litegraph litesearchbox graphdialog rounded";n.innerHTML="<span class='name'>Search</span> <input autofocus type='text' class='value rounded'/><div class='helper'></div>";n.close=function(){e.search_box=null;k.body.focus();k.body.style.overflow="";setTimeout(function(){e.canvas.focus()},
20);n.parentNode&&n.parentNode.removeChild(n)};var u=null;1<this.ds.scale&&(n.style.transform="scale("+this.ds.scale+")");n.addEventListener("mouseenter",function(a){u&&(clearTimeout(u),u=null)});n.addEventListener("mouseleave",function(a){u=setTimeout(function(){n.close()},500)});e.search_box&&e.search_box.close();e.search_box=n;var t=n.querySelector(".helper"),m=null,q=null,p=null,r=n.querySelector("input");r&&(r.addEventListener("blur",function(a){this.focus()}),r.addEventListener("keydown",function(a){if(38==
a.keyCode)c(!1);else if(40==a.keyCode)c(!0);else if(27==a.keyCode)n.close();else if(13==a.keyCode)p?b(p.innerHTML):m?b(m):n.close();else{q&&clearInterval(q);q=setTimeout(d,10);return}a.preventDefault();a.stopPropagation();a.stopImmediatePropagation();return!0}));k.fullscreenElement?k.fullscreenElement.appendChild(n):(k.body.appendChild(n),k.body.style.overflow="hidden");h=h.getBoundingClientRect();var w=(a?a.clientY:h.top+.5*h.height)-20;n.style.left=(a?a.clientX:h.left+.5*h.width)-80+"px";n.style.top=
w+"px";a.layerY>h.height-200&&(t.style.maxHeight=h.height-a.layerY-20+"px");r.focus();return n};l.prototype.showEditPropertyValue=function(a,b,c){function d(){e(m.value)}function e(d){g&&g.values&&g.values.constructor===Object&&void 0!=g.values[d]&&(d=g.values[d]);"number"==typeof a.properties[b]&&(d=Number(d));if("array"==f||"object"==f)d=JSON.parse(d);a.properties[b]=d;a.graph&&a.graph._version++;if(a.onPropertyChanged)a.onPropertyChanged(b,d);if(c.onclose)c.onclose();p.close();a.setDirtyCanvas(!0,
!0)}if(a&&void 0!==a.properties[b]){c=c||{};var g=a.getPropertyInfo(b),f=g.type,k="";if("string"==f||"number"==f||"array"==f||"object"==f)k="<input autofocus type='text' class='value'/>";else if("enum"!=f&&"combo"!=f||!g.values)if("boolean"==f)k="<input autofocus type='checkbox' class='value' "+(a.properties[b]?"checked":"")+"/>";else{console.warn("unknown type: "+f);return}else{k="<select autofocus type='text' class='value'>";for(var n in g.values){var l=n;g.values.constructor===Array&&(l=g.values[n]);
k+="<option value='"+l+"' "+(l==a.properties[b]?"selected":"")+">"+g.values[n]+"</option>"}k+="</select>"}var p=this.createDialog("<span class='name'>"+(g.label?g.label:b)+"</span>"+k+"<button>OK</button>",c);if("enum"!=f&&"combo"!=f||!g.values)if("boolean"==f)(m=p.querySelector("input"))&&m.addEventListener("click",function(a){e(!!m.checked)});else{if(m=p.querySelector("input"))m.addEventListener("blur",function(a){this.focus()}),l=void 0!==a.properties[b]?a.properties[b]:"","string"!==f&&(l=JSON.stringify(l)),
m.value=l,m.addEventListener("keydown",function(a){13==a.keyCode&&(d(),a.preventDefault(),a.stopPropagation())})}else{var m=p.querySelector("select");m.addEventListener("change",function(a){e(a.target.value)})}p.querySelector("button").addEventListener("click",d);return p}};l.prototype.createDialog=function(a,b){b=b||{};var c=document.createElement("div");c.className="graphdialog";c.innerHTML=a;a=this.canvas.getBoundingClientRect();var d=-20,e=-20;a&&(d-=a.left,e-=a.top);b.position?(d+=b.position[0],
e+=b.position[1]):b.event?(d+=b.event.clientX,e+=b.event.clientY):(d+=.5*this.canvas.width,e+=.5*this.canvas.height);c.style.left=d+"px";c.style.top=e+"px";this.canvas.parentNode.appendChild(c);c.close=function(){this.parentNode&&this.parentNode.removeChild(this)};return c};l.prototype.createPanel=function(a,b){b=b||{};var c=b.window||window,d=document.createElement("div");d.className="litegraph dialog";d.innerHTML="<div class='dialog-header'><span class='dialog-title'></span></div><div class='dialog-content'></div><div class='dialog-footer'></div>";
d.header=d.querySelector(".dialog-header");b.width&&(d.style.width=b.width+(b.width.constructor===Number?"px":""));b.height&&(d.style.height=b.height+(b.height.constructor===Number?"px":""));b.closable&&(b=document.createElement("span"),b.innerHTML="&#10005;",b.classList.add("close"),b.addEventListener("click",function(){d.close()}),d.header.appendChild(b));d.title_element=d.querySelector(".dialog-title");d.title_element.innerText=a;d.content=d.querySelector(".dialog-content");d.footer=d.querySelector(".dialog-footer");
d.close=function(){this.parentNode&&this.parentNode.removeChild(this)};d.clear=function(){this.content.innerHTML=""};d.addHTML=function(a,b,c){var e=document.createElement("div");b&&(e.className=b);e.innerHTML=a;c?d.footer.appendChild(e):d.content.appendChild(e);return e};d.addButton=function(a,b,c){var e=document.createElement("button");e.innerText=a;e.options=c;e.classList.add("btn");e.addEventListener("click",b);d.footer.appendChild(e);return e};d.addSeparator=function(){var a=document.createElement("div");
a.className="separator";d.content.appendChild(a)};d.addWidget=function(a,b,h,k,n){function e(a,b){console.log("change",a,b);k.callback&&k.callback(a,b);n&&n(a,b)}k=k||{};var g=String(h);a=a.toLowerCase();"number"==a&&(g=h.toFixed(3));var m=document.createElement("div");m.className="property";m.innerHTML="<span class='property_name'></span><span class='property_value'></span>";m.querySelector(".property_name").innerText=k.label||b;var p=m.querySelector(".property_value");p.innerText=g;m.dataset.property=
b;m.dataset.type=k.type||a;m.options=k;m.value=h;if("boolean"==a)m.classList.add("boolean"),h&&m.classList.add("bool-on"),m.addEventListener("click",function(){var a=this.dataset.property;this.value=!this.value;this.classList.toggle("bool-on");this.querySelector(".property_value").innerText=this.value?"true":"false";e(a,this.value)});else if("string"==a||"number"==a)p.setAttribute("contenteditable",!0),p.addEventListener("keydown",function(a){"Enter"==a.code&&(a.preventDefault(),this.blur())}),p.addEventListener("blur",
function(){var a=this.innerText,b=this.parentNode.dataset.property;"number"==this.parentNode.dataset.type&&(a=Number(a));e(b,a)});else if("enum"==a||"combo"==a)g=l.getPropertyPrintableValue(h,k.values),p.innerText=g,p.addEventListener("click",function(a){var b=this.parentNode.dataset.property,d=this;new f.ContextMenu(k.values||[],{event:a,className:"dark",callback:function(a,c,g){d.innerText=a;e(b,a);return!1}},c)});d.content.appendChild(m);return m};return d};l.getPropertyPrintableValue=function(a,
b){if(!b||b.constructor===Array)return String(a);if(b.constructor===Object){var c="",d;for(d in b)if(b[d]==a){c=d;break}return String(a)+" ("+c+")"}};l.prototype.showShowNodePanel=function(a){window.SELECTED_NODE=a;var b=document.querySelector("#node-panel");b&&b.close();var c=this.getCanvasWindow();b=this.createPanel(a.title||"",{closable:!0,window:c});b.id="node-panel";b.node=a;b.classList.add("settings");var d=this;(function(){b.content.innerHTML="";b.addHTML("<span class='node_type'>"+a.type+
"</span><span class='node_desc'>"+(a.constructor.desc||"")+"</span><span class='separator'></span>");b.addHTML("<h3>Properties</h3>");for(var c in a.properties){var g=a.properties[c],f=a.getPropertyInfo(c);a.onAddPropertyToPanel&&a.onAddPropertyToPanel(c,b)||b.addWidget(f.widget||f.type,c,g,f,function(b,c){d.graph.beforeChange(a);a.setProperty(b,c);d.graph.afterChange();d.dirty_canvas=!0})}b.addSeparator();if(a.onShowCustomPanelInfo)a.onShowCustomPanelInfo(b);b.addButton("Delete",function(){a.block_delete||
(a.graph.remove(a),b.close())}).classList.add("delete")})();this.canvas.parentNode.appendChild(b)};l.prototype.showSubgraphPropertiesDialog=function(a){function b(){d.clear();if(a.inputs)for(var c=0;c<a.inputs.length;++c){var g=a.inputs[c];if(!g.not_subgraph_input){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=g.name;f.dataset.slot=c;f.querySelector(".name").innerText=g.name;f.querySelector(".type").innerText=
g.type;f.querySelector("button").addEventListener("click",function(c){a.removeInput(Number(this.parentNode.dataset.slot));b()})}}}console.log("showing subgraph properties dialog");var c=this.canvas.parentNode.querySelector(".subgraph_dialog");c&&c.close();var d=this.createPanel("Subgraph Inputs",{closable:!0,width:500});d.node=a;d.classList.add("subgraph_dialog");d.addHTML(" + <span class='label'>Name</span><input class='name'/><span class='label'>Type</span><input class='type'></input><button>+</button>",
"subgraph_property extra",!0).querySelector("button").addEventListener("click",function(c){c=this.parentNode;var d=c.querySelector(".name").value,e=c.querySelector(".type").value;d&&-1==a.findInputSlot(d)&&(a.addInput(d,e),c.querySelector(".name").value="",c.querySelector(".type").value="",b())});b();this.canvas.parentNode.appendChild(d);return d};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,d,e){e.graph.beforeChange(e);e.collapse();e.graph.afterChange(e)};l.onMenuNodePin=function(a,b,c,d,e){e.pin()};l.onMenuNodeMode=function(a,b,c,d,e){new f.ContextMenu(["Always","On Event","On Trigger","Never"],{event:c,callback:function(a){if(e)switch(a){case "On Event":e.mode=f.ON_EVENT;break;case "On Trigger":e.mode=f.ON_TRIGGER;break;case "Never":e.mode=f.NEVER;break;default:e.mode=f.ALWAYS}},parentMenu:d,
node:e});return!1};l.onMenuNodeColors=function(a,b,c,d,e){if(!e)throw"no node for color";b=[];b.push({value:null,content:"<span style='display: block; padding-left: 4px;'>No color</span>"});for(var 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){e&&((a=a.value?l.node_colors[a.value]:null)?
e.constructor===f.LGraphGroup?e.color=a.groupcolor:(e.color=a.color,e.bgcolor=a.bgcolor):(delete e.color,delete e.bgcolor),e.setDirtyCanvas(!0,!0))},parentMenu:d,node:e});return!1};l.onMenuNodeShapes=function(a,b,c,d,e){if(!e)throw"no node passed";new f.ContextMenu(f.VALID_SHAPES,{event:c,callback:function(a){e&&(e.graph.beforeChange(e),e.shape=a,e.graph.afterChange(e),e.setDirtyCanvas(!0))},parentMenu:d,node:e});return!1};l.onMenuNodeRemove=function(a,b,c,d,e){if(!e)throw"no node passed";!1!==e.removable&&
(a=e.graph,a.beforeChange(),a.remove(e),a.afterChange(),e.setDirtyCanvas(!0,!0))};l.onMenuNodeToSubgraph=function(a,b,c,d,e){a=e.graph;if(b=l.active_canvas)c=Object.values(b.selected_nodes||{}),c.length||(c=[e]),d=f.createNode("graph/subgraph"),d.pos=e.pos.concat(),a.add(d),d.buildFromNodes(c),b.deselectAllNodes(),e.setDirtyCanvas(!0,!0)};l.onMenuNodeClone=function(a,b,c,d,e){0!=e.clonable&&(a=e.clone())&&(a.pos=[e.pos[0]+5,e.pos[1]+5],e.graph.beforeChange(),e.graph.add(a),e.graph.afterChange(),e.setDirtyCanvas(!0,
!0))};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}],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){var b=null;
b=a.getMenuOptions?a.getMenuOptions(this):[{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},{content:"Resize",callback:function(){if(a.resizable)return l.onResizeNode}},{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});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,d=l.active_canvas.getCanvasWindow(),e=null,g={event:b,callback:function(b,d,e){if(b)if("Remove Slot"==b.content)b=b.slot,b.input?a.removeInput(b.slot):b.output&&a.removeOutput(b.slot);else if("Disconnect Links"==b.content)b=b.slot,b.output?a.disconnectOutput(b.slot):b.input&&a.disconnectInput(b.slot);else if("Rename Slot"==b.content){b=b.slot;var g=b.input?a.getInputInfo(b.slot):a.getOutputInfo(b.slot),f=c.createDialog("<span class='name'>Name</span><input autofocus type='text'/><button>OK</button>",
d),h=f.querySelector("input");h&&g&&(h.value=g.label||"");f.querySelector("button").addEventListener("click",function(a){h.value&&(g&&(g.label=h.value),c.setDirty(!0));f.close()})}},extra:a};a&&(g.title=a.type);var h=null;a&&(h=a.getSlotInPosition(b.canvasX,b.canvasY),l.active_node=a);h?(e=[],a.getSlotMenuOptions?e=a.getSlotMenuOptions(h):(h&&h.output&&h.output.links&&h.output.links.length&&e.push({content:"Disconnect Links",slot:h}),b=h.input||h.output,e.push(b.locked?"Cannot remove":{content:"Remove Slot",
slot:h}),e.push(b.nameLocked?"Cannot rename":{content:"Rename Slot",slot:h})),g.title=(h.input?h.input.type:h.output.type)||"*",h.input&&h.input.type==f.ACTION&&(g.title="Action"),h.output&&h.output.type==f.EVENT&&(g.title="Event")):a?e=this.getNodeMenuOptions(a):(e=this.getCanvasMenuOptions(),(h=this.graph.getGroupOnPos(b.canvasX,b.canvasY))&&e.push(null,{content:"Edit Group",has_submenu:!0,submenu:{title:"Group",extra:h,options:this.getGroupMenuOptions(h)}}));e&&new f.ContextMenu(e,g,d)};"undefined"!=
typeof window&&window.CanvasRenderingContext2D&&(window.CanvasRenderingContext2D.prototype.roundRect=function(a,b,c,d,e,g){void 0===e&&(e=5);void 0===g&&(g=e);this.moveTo(a+e,b);this.lineTo(a+c-e,b);this.quadraticCurveTo(a+c,b,a+c,b+e);this.lineTo(a+c,b+d-g);this.quadraticCurveTo(a+c,b+d,a+c-g,b+d);this.lineTo(a+g,b+d);this.quadraticCurveTo(a,b+d,a,b+d-g);this.lineTo(a,b+e);this.quadraticCurveTo(a,b,a+e,b)});f.compareObjects=function(a,b){for(var c in a)if(a[c]!=b[c])return!1;return!0};f.distance=
J;f.colorToString=function(a){return"rgba("+Math.round(255*a[0]).toFixed()+","+Math.round(255*a[1]).toFixed()+","+Math.round(255*a[2]).toFixed()+","+(4==a.length?a[3].toFixed(2):"1.0")+")"};f.isInsideRectangle=C;f.growBounding=function(a,b,c){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=H;f.hex2num=function(a){"#"==a.charAt(0)&&(a=a.slice(1));a=a.toUpperCase();
for(var b=Array(3),c=0,d,e,g=0;6>g;g+=2)d="0123456789ABCDEF".indexOf(a.charAt(g)),e="0123456789ABCDEF".indexOf(a.charAt(g+1)),b[c]=16*d+e,c++;return b};f.num2hex=function(a){for(var b="#",c,d,e=0;3>e;e++)c=a[e]/16,d=a[e]%16,b+="0123456789ABCDEF".charAt(c)+"0123456789ABCDEF".charAt(d);return b};E.prototype.addItem=function(a,b,c){function d(a){var b=this.value;b&&b.has_submenu&&e.call(this,a)}function e(a){var b=this.value,d=!0;g.current_submenu&&g.current_submenu.close(a);if(c.callback){var e=c.callback.call(this,
b,c,a,g,c.node);!0===e&&(d=!1)}if(b&&(b.callback&&!c.ignore_item_callbacks&&!0!==b.disabled&&(e=b.callback.call(this,b,c,a,g,c.extra),!0===e&&(d=!1)),b.submenu)){if(!b.submenu.options)throw"ContextMenu submenu needs options";new g.constructor(b.submenu.options,{callback:b.submenu.callback,event:a,parentMenu:g,ignore_item_callbacks:b.submenu.ignore_item_callbacks,title:b.submenu.title,extra:b.submenu.extra,autoopen:c.autoopen});d=!1}d&&!g.lock&&g.close()}var g=this;c=c||{};var f=document.createElement("div");
f.className="litemenu-entry submenu";var k=!1;if(null===b)f.classList.add("separator");else{f.innerHTML=b&&b.title?b.title:a;if(f.value=b)b.disabled&&(k=!0,f.classList.add("disabled")),(b.submenu||b.has_submenu)&&f.classList.add("has_submenu");"function"==typeof b?(f.dataset.value=a,f.onclick_callback=b):f.dataset.value=b;b.className&&(f.className+=" "+b.className)}this.root.appendChild(f);k||f.addEventListener("click",e);c.autoopen&&f.addEventListener("mouseenter",d);return f};E.prototype.close=
function(a,b){this.root.parentNode&&this.root.parentNode.removeChild(this.root);this.parentMenu&&!b&&(this.parentMenu.lock=!1,this.parentMenu.current_submenu=null,void 0===a?this.parentMenu.close():a&&!E.isCursorOverElement(a,this.parentMenu.root)&&E.trigger(this.parentMenu.root,"mouseleave",a));this.current_submenu&&this.current_submenu.close(a,!0);this.root.closing_timer&&clearTimeout(this.root.closing_timer)};E.trigger=function(a,b,c,d){var e=document.createEvent("CustomEvent");e.initCustomEvent(b,
!0,!0,c);e.srcElement=d;a.dispatchEvent?a.dispatchEvent(e):a.__events&&a.__events.dispatchEvent(e);return e};E.prototype.getTopMenu=function(){return this.options.parentMenu?this.options.parentMenu.getTopMenu():this};E.prototype.getFirstEvent=function(){return this.options.parentMenu?this.options.parentMenu.getFirstEvent():this.options.event};E.isCursorOverElement=function(a,b){var c=a.clientX;a=a.clientY;return(b=b.getBoundingClientRect())?a>b.top&&a<b.top+b.height&&c>b.left&&c<b.left+b.width?!0:
!1:!1};f.ContextMenu=E;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 d=b[c],e=b[c+1];if(!(e[0]<a)){b=e[0]-d[0];if(1E-5>Math.abs(b))return d[1];a=(a-d[0])/b;return d[1]*(1-a)+e[1]*a}}return 0}};G.prototype.draw=function(a,b,c,d,e,f){if(c=this.points){this.size=b;var g=b[0]-2*this.margin;b=b[1]-2*this.margin;e=e||"#666";a.save();a.translate(this.margin,
this.margin);d&&(a.fillStyle="#111",a.fillRect(0,0,g,b),a.fillStyle="#222",a.fillRect(.5*g,0,1,b),a.strokeStyle="#333",a.strokeRect(0,0,g,b));a.strokeStyle=e;f&&(a.globalAlpha=.5);a.beginPath();for(d=0;d<c.length;++d)e=c[d],a.lineTo(e[0]*g,(1-e[1])*b);a.stroke();a.globalAlpha=1;if(!f)for(d=0;d<c.length;++d)e=c[d],a.fillStyle=this.selected==d?"#FFF":this.nearest==d?"#DDD":"#AAA",a.beginPath(),a.arc(e[0]*g,(1-e[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 d=this.size[0]-2*this.margin,e=this.size[1]-2*this.margin,f=a[0]-this.margin;a=a[1]-this.margin;this.selected=this.getCloserPoint([f,a],30/b.ds.scale);-1==this.selected&&(b=[f/d,1-a/e],c.push(b),c.sort(function(a,b){return a[0]-b[0]}),this.selected=c.indexOf(b),this.must_update=!0);if(-1!=this.selected)return!0}};G.prototype.onMouseMove=function(a,b){var c=this.points;if(c){var d=this.selected;if(!(0>d)){var e=(a[0]-this.margin)/(this.size[0]-2*this.margin),f=(a[1]-
this.margin)/(this.size[1]-2*this.margin);this._nearest=this.getCloserPoint([a[0]-this.margin,a[1]-this.margin],30/b.ds.scale);if(b=c[d]){var h=0==d||d==c.length-1;!h&&(-10>a[0]||a[0]>this.size[0]+10||-10>a[1]||a[1]>this.size[1]+10)?(c.splice(d,1),this.selected=-1):(b[0]=h?0==d?0:1:Math.clamp(e,0,1),b[1]=1-Math.clamp(f,0,1),c.sort(function(a,b){return a[0]-b[0]}),this.selected=c.indexOf(b),this.must_update=!0)}}}};G.prototype.onMouseUp=function(a,b){this.selected=-1;return!1};G.prototype.getCloserPoint=
function(a,b){var c=this.points;if(!c)return-1;b=b||30;for(var d=this.size[0]-2*this.margin,e=this.size[1]-2*this.margin,f=c.length,h=[0,0],k=1E6,l=-1,p=0;p<f;++p){var q=c[p];h[0]=q[0]*d;h[1]=(1-q[1])*e;q=vec2.distance(a,h);q>k||q>b||(l=p,k=q)}return l};f.CurveEditor=G;f.getParameterNames=function(a){return(a+"").replace(/[/][/].*$/gm,"").replace(/\s+/g,"").replace(/[/][*][^/*]*[*][/]/g,"").split("){",1)[0].replace(/^[^(]*[(]/,"").replace(/=[^,]+/g,"").split(",").filter(Boolean)};Math.clamp=function(a,
b,c){return b>a?b:c<a?c:a};"undefined"==typeof window||window.requestAnimationFrame||(window.requestAnimationFrame=window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(a){window.setTimeout(a,1E3/60)})})(this);"undefined"!=typeof exports&&(exports.LiteGraph=this.LiteGraph);

File diff suppressed because it is too large Load Diff

11880
build/litegraph.min.js vendored

File diff suppressed because it is too large Load Diff

View File

@@ -419,7 +419,11 @@
}
}
return this.auto_sort_node_types ? r.sort() : r;
if (this.auto_sort_node_types) {
r.sort((a, b) => a.title.localeCompare(b.title));
}
return r;
},
/**
@@ -10282,7 +10286,7 @@ LGraphNode.prototype.executeAction = function(action)
var elem = document.createElement("div");
elem.className = "property";
elem.innerHTML = "<span class='property_name'></span><span class='property_value'></span>";
elem.querySelector(".property_name").innerText = name;
elem.querySelector(".property_name").innerText = options.label || name;
var value_element = elem.querySelector(".property_value");
value_element.innerText = str_value;
elem.dataset["property"] = name;
@@ -10326,7 +10330,7 @@ LGraphNode.prototype.executeAction = function(action)
innerChange(propname, v);
});
}
else if (type == "enum" || type == "combo")
else if (type == "enum" || type == "combo") {
var str_value = LGraphCanvas.getPropertyPrintableValue( value, options.values );
value_element.innerText = str_value;
@@ -10348,6 +10352,7 @@ LGraphNode.prototype.executeAction = function(action)
return false;
}
});
}
root.content.appendChild(elem);

View File

@@ -1,396 +1,405 @@
(function(B){function n(a){h.debug&&console.log("Graph created");this.list_of_graphcanvas=null;this.clear();a&&this.configure(a)}function u(a,b,c,d,e,g){this.id=a;this.type=b;this.origin_id=c;this.origin_slot=d;this.target_id=e;this.target_slot=g;this._data=null;this._pos=new Float32Array(2)}function l(a){this._ctor(a)}function r(a){this._ctor(a)}function v(a,b){this.offset=new Float32Array([0,0]);this.scale=1;this.max_scale=10;this.min_scale=0.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 k(a,b,c){this.options=c=c||{};this.background_image=k.DEFAULT_BACKGROUND_IMAGE;a&&a.constructor===String&&(a=document.querySelector(a));this.ds=new v;this.zoom_modify_alpha=!0;this.title_text_font=""+h.NODE_TEXT_SIZE+"px Arial";this.inner_text_font="normal "+h.NODE_SUBTEXT_SIZE+"px Arial";this.node_title_color=h.NODE_TITLE_COLOR;this.default_link_color=h.LINK_COLOR;this.default_connection_color=
var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.ASSUME_ES5=!1;$jscomp.ASSUME_NO_NATIVE_MAP=!1;$jscomp.ASSUME_NO_NATIVE_SET=!1;$jscomp.defineProperty=$jscomp.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(v,m,q){v!=Array.prototype&&v!=Object.prototype&&(v[m]=q.value)};$jscomp.getGlobal=function(v){return"undefined"!=typeof window&&window===v?v:"undefined"!=typeof global&&null!=global?global:v};$jscomp.global=$jscomp.getGlobal(this);
$jscomp.polyfill=function(v,m,q,k){if(m){q=$jscomp.global;v=v.split(".");for(k=0;k<v.length-1;k++){var t=v[k];t in q||(q[t]={});q=q[t]}v=v[v.length-1];k=q[v];m=m(k);m!=k&&null!=m&&$jscomp.defineProperty(q,v,{configurable:!0,writable:!0,value:m})}};$jscomp.polyfill("Array.prototype.fill",function(v){return v?v:function(m,q,k){var t=this.length||0;0>q&&(q=Math.max(0,t+q));if(null==k||k>t)k=t;k=Number(k);0>k&&(k=Math.max(0,t+k));for(q=Number(q||0);q<k;q++)this[q]=m;return this}},"es6","es3");
$jscomp.SYMBOL_PREFIX="jscomp_symbol_";$jscomp.initSymbol=function(){$jscomp.initSymbol=function(){};$jscomp.global.Symbol||($jscomp.global.Symbol=$jscomp.Symbol)};$jscomp.Symbol=function(){var v=0;return function(m){return $jscomp.SYMBOL_PREFIX+(m||"")+v++}}();
$jscomp.initSymbolIterator=function(){$jscomp.initSymbol();var v=$jscomp.global.Symbol.iterator;v||(v=$jscomp.global.Symbol.iterator=$jscomp.global.Symbol("iterator"));"function"!=typeof Array.prototype[v]&&$jscomp.defineProperty(Array.prototype,v,{configurable:!0,writable:!0,value:function(){return $jscomp.arrayIterator(this)}});$jscomp.initSymbolIterator=function(){}};$jscomp.arrayIterator=function(v){var m=0;return $jscomp.iteratorPrototype(function(){return m<v.length?{done:!1,value:v[m++]}:{done:!0}})};
$jscomp.iteratorPrototype=function(v){$jscomp.initSymbolIterator();v={next:v};v[$jscomp.global.Symbol.iterator]=function(){return this};return v};$jscomp.iteratorFromArray=function(v,m){$jscomp.initSymbolIterator();v instanceof String&&(v+="");var q=0,k={next:function(){if(q<v.length){var t=q++;return{value:m(t,v[t]),done:!1}}k.next=function(){return{done:!0,value:void 0}};return k.next()}};k[Symbol.iterator]=function(){return k};return k};
$jscomp.polyfill("Array.prototype.values",function(v){return v?v:function(){return $jscomp.iteratorFromArray(this,function(m,q){return q})}},"es8","es3");$jscomp.polyfill("Array.prototype.keys",function(v){return v?v:function(){return $jscomp.iteratorFromArray(this,function(m){return m})}},"es6","es3");$jscomp.owns=function(v,m){return Object.prototype.hasOwnProperty.call(v,m)};
$jscomp.polyfill("Object.values",function(v){return v?v:function(m){var q=[],k;for(k in m)$jscomp.owns(m,k)&&q.push(m[k]);return q}},"es8","es3");$jscomp.checkStringArgs=function(v,m,q){if(null==v)throw new TypeError("The 'this' value for String.prototype."+q+" must not be null or undefined");if(m instanceof RegExp)throw new TypeError("First argument to String.prototype."+q+" must not be a regular expression");return v+""};
$jscomp.polyfill("String.prototype.startsWith",function(v){return v?v:function(m,q){var k=$jscomp.checkStringArgs(this,m,"startsWith");m+="";var t=k.length,w=m.length;q=Math.max(0,Math.min(q|0,k.length));for(var h=0;h<w&&q<t;)if(k[q++]!=m[h++])return!1;return h>=w}},"es6","es3");$jscomp.findInternal=function(v,m,q){v instanceof String&&(v=String(v));for(var k=v.length,t=0;t<k;t++){var w=v[t];if(m.call(q,w,t,v))return{i:t,v:w}}return{i:-1,v:void 0}};
$jscomp.polyfill("Array.prototype.findIndex",function(v){return v?v:function(m,q){return $jscomp.findInternal(this,m,q).i}},"es6","es3");
(function(v){function m(a){l.debug&&console.log("Graph created");this.list_of_graphcanvas=null;this.clear();a&&this.configure(a)}function q(a,b,c,d,e,f){this.id=a;this.type=b;this.origin_id=c;this.origin_slot=d;this.target_id=e;this.target_slot=f;this._data=null;this._pos=new Float32Array(2)}function k(a){this._ctor(a)}function t(a){this._ctor(a)}function w(a,b){this.offset=new Float32Array([0,0]);this.scale=1;this.max_scale=10;this.min_scale=.1;this.onredraw=null;this.enabled=!0;this.last_mouse=
[0,0];this.element=null;this.visible_area=new Float32Array(4);a&&(this.element=a,b||this.bindEvents(a))}function h(a,b,c){this.options=c=c||{};this.background_image=h.DEFAULT_BACKGROUND_IMAGE;a&&a.constructor===String&&(a=document.querySelector(a));this.ds=new w;this.zoom_modify_alpha=!0;this.title_text_font=""+l.NODE_TEXT_SIZE+"px Arial";this.inner_text_font="normal "+l.NODE_SUBTEXT_SIZE+"px Arial";this.node_title_color=l.NODE_TITLE_COLOR;this.default_link_color=l.LINK_COLOR;this.default_connection_color=
{input_off:"#778",input_on:"#7F7",output_off:"#778",output_on:"#7F7"};this.highquality_render=!0;this.use_gradients=!1;this.editor_alpha=1;this.pause_rendering=!1;this.clear_background=!0;this.read_only=!1;this.render_only_selected=!0;this.live_mode=!1;this.allow_searchbox=this.allow_interaction=this.allow_dragnodes=this.allow_dragcanvas=this.show_info=!0;this.drag_mode=this.align_to_grid=this.allow_reconnect_links=!1;this.filter=this.dragging_rectangle=null;this.set_canvas_dirty_on_mouse_event=!0;
this.always_render_background=!1;this.render_canvas_border=this.render_shadows=!0;this.render_connections_shadows=!1;this.render_connections_border=!0;this.render_connection_arrows=this.render_curved_connections=!1;this.render_collapsed_slots=!0;this.render_execution_order=!1;this.render_link_tooltip=this.render_title_colored=!0;this.links_render_mode=h.SPLINE_LINK;this.mouse=[0,0];this.canvas_mouse=this.graph_mouse=[0,0];this.onAfterChange=this.onBeforeChange=this.onConnectingChange=this.onSelectionChange=
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=l.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 y(a,b,c,d,e,g){return c<a&&c+e>a&&d<b&&d+g>b?!0:!1}function A(a,b){var c=a[0]+a[2],d=a[1]+a[3],e=b[1]+b[3];return a[0]>b[0]+b[2]||a[1]>e||c<b[0]||d<b[1]?!1:!0}function x(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 d=this;b.parentMenu&&(b.parentMenu.constructor!==this.constructor?(console.error("parentMenu must be of class ContextMenu, ignoring it"),
b.parentMenu=null):(this.parentMenu=b.parentMenu,this.parentMenu.lock=!0,this.parentMenu.current_submenu=this));var e=null;b.event&&(e=b.event.constructor.name);"MouseEvent"!==e&&"CustomEvent"!==e&&"PointerEvent"!==e&&(console.error("Event passed to ContextMenu is not of type MouseEvent or CustomEvent. Ignoring it."),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);g.addEventListener("mouseup",function(a){a.preventDefault();return!0},!0);g.addEventListener("contextmenu",function(a){if(2!=a.button)return!1;a.preventDefault();return!1},!0);g.addEventListener("mousedown",function(a){if(2==a.button)return d.close(),a.preventDefault(),!0},!0);b.scroll_speed||(b.scroll_speed=0.1);g.addEventListener("wheel",c,!0);g.addEventListener("mousewheel",c,!0);this.root=g;b.title&&(e=document.createElement("div"),
e.className="litemenu-title",e.innerHTML=b.title,g.appendChild(e));for(var f=e=0;f<a.length;f++){var m=a.constructor==Array?a[f]:f;null!=m&&m.constructor!==String&&(m=void 0===m.content?String(m):m.content);this.addItem(m,a[f],b);e++}g.addEventListener("mouseleave",function(a){d.lock||(g.closing_timer&&clearTimeout(g.closing_timer),g.closing_timer=setTimeout(d.close.bind(d,a),500))});g.addEventListener("mouseenter",function(a){g.closing_timer&&clearTimeout(g.closing_timer)});e=document;b.event&&(e=
b.event.target.ownerDocument);e||(e=document);e.fullscreenElement?e.fullscreenElement.appendChild(g):e.body.appendChild(g);f=b.left||0;e=b.top||0;if(b.event){f=b.event.clientX-10;e=b.event.clientY-10;b.title&&(e-=20);b.parentMenu&&(f=b.parentMenu.root.getBoundingClientRect(),f=f.left+f.width);var m=document.body.getBoundingClientRect(),q=g.getBoundingClientRect();0==m.height&&console.error("document.body height is 0. That is dangerous, set html,body { height: 100%; }");m.width&&f>m.width-q.width-
10&&(f=m.width-q.width-10);m.height&&e>m.height-q.height-10&&(e=m.height-q.height-10)}g.style.left=f+"px";g.style.top=e+"px";b.scale&&(g.style.transform="scale("+b.scale+")")}function I(a){this.points=a;this.nearest=this.selected=-1;this.size=null;this.must_update=!0;this.margin=5}var h=B.LiteGraph={VERSION:0.4,CANVAS_GRID_SIZE:10,NODE_TITLE_HEIGHT:30,NODE_TITLE_TEXT_Y:20,NODE_SLOT_HEIGHT:20,NODE_WIDGET_HEIGHT:20,NODE_WIDTH:140,NODE_MIN_WIDTH:50,NODE_COLLAPSED_RADIUS:10,NODE_COLLAPSED_WIDTH:80,NODE_TITLE_COLOR:"#999",
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 C(a,b,c,d,e,f){return c<a&&c+e>a&&d<b&&d+f>b?!0:!1}function B(a,b){var c=a[0]+a[2],d=a[1]+a[3],e=b[1]+b[3];return a[0]>b[0]+b[2]||a[1]>e||c<b[0]||d<b[1]?!1:!0}function x(a,b){function c(a){var c=parseInt(f.style.top);f.style.top=(c+a.deltaY*b.scroll_speed).toFixed()+"px";a.preventDefault();return!0}this.options=b=b||{};var d=this;b.parentMenu&&(b.parentMenu.constructor!==this.constructor?(console.error("parentMenu must be of class ContextMenu, ignoring it"),
b.parentMenu=null):(this.parentMenu=b.parentMenu,this.parentMenu.lock=!0,this.parentMenu.current_submenu=this));var e=null;b.event&&(e=b.event.constructor.name);"MouseEvent"!==e&&"CustomEvent"!==e&&"PointerEvent"!==e&&(console.error("Event passed to ContextMenu is not of type MouseEvent or CustomEvent. Ignoring it."),b.event=null);var f=document.createElement("div");f.className="litegraph litecontextmenu litemenubar-panel";b.className&&(f.className+=" "+b.className);f.style.minWidth=100;f.style.minHeight=
100;f.style.pointerEvents="none";setTimeout(function(){f.style.pointerEvents="auto"},100);f.addEventListener("mouseup",function(a){a.preventDefault();return!0},!0);f.addEventListener("contextmenu",function(a){if(2!=a.button)return!1;a.preventDefault();return!1},!0);f.addEventListener("mousedown",function(a){if(2==a.button)return d.close(),a.preventDefault(),!0},!0);b.scroll_speed||(b.scroll_speed=.1);f.addEventListener("wheel",c,!0);f.addEventListener("mousewheel",c,!0);this.root=f;b.title&&(e=document.createElement("div"),
e.className="litemenu-title",e.innerHTML=b.title,f.appendChild(e));for(var g=e=0;g<a.length;g++){var n=a.constructor==Array?a[g]:g;null!=n&&n.constructor!==String&&(n=void 0===n.content?String(n):n.content);this.addItem(n,a[g],b);e++}f.addEventListener("mouseleave",function(a){d.lock||(f.closing_timer&&clearTimeout(f.closing_timer),f.closing_timer=setTimeout(d.close.bind(d,a),500))});f.addEventListener("mouseenter",function(a){f.closing_timer&&clearTimeout(f.closing_timer)});a=document;b.event&&(a=
b.event.target.ownerDocument);a||(a=document);a.fullscreenElement?a.fullscreenElement.appendChild(f):a.body.appendChild(f);e=b.left||0;a=b.top||0;b.event&&(e=b.event.clientX-10,a=b.event.clientY-10,b.title&&(a-=20),b.parentMenu&&(e=b.parentMenu.root.getBoundingClientRect(),e=e.left+e.width),g=document.body.getBoundingClientRect(),n=f.getBoundingClientRect(),0==g.height&&console.error("document.body height is 0. That is dangerous, set html,body { height: 100%; }"),g.width&&e>g.width-n.width-10&&(e=
g.width-n.width-10),g.height&&a>g.height-n.height-10&&(a=g.height-n.height-10));f.style.left=e+"px";f.style.top=a+"px";b.scale&&(f.style.transform="scale("+b.scale+")")}function I(a){this.points=a;this.nearest=this.selected=-1;this.size=null;this.must_update=!0;this.margin=5}var l=v.LiteGraph={VERSION:.4,CANVAS_GRID_SIZE:10,NODE_TITLE_HEIGHT:30,NODE_TITLE_TEXT_Y:20,NODE_SLOT_HEIGHT:20,NODE_WIDGET_HEIGHT:20,NODE_WIDTH:140,NODE_MIN_WIDTH:50,NODE_COLLAPSED_RADIUS:10,NODE_COLLAPSED_WIDTH:80,NODE_TITLE_COLOR:"#999",
NODE_SELECTED_TITLE_COLOR:"#FFF",NODE_TEXT_SIZE:14,NODE_TEXT_COLOR:"#AAA",NODE_SUBTEXT_SIZE:12,NODE_DEFAULT_COLOR:"#333",NODE_DEFAULT_BGCOLOR:"#353535",NODE_DEFAULT_BOXCOLOR:"#666",NODE_DEFAULT_SHAPE:"box",NODE_BOX_OUTLINE_COLOR:"#FFF",DEFAULT_SHADOW_COLOR:"rgba(0,0,0,0.5)",DEFAULT_GROUP_FONT:24,WIDGET_BGCOLOR:"#222",WIDGET_OUTLINE_COLOR:"#666",WIDGET_TEXT_COLOR:"#DDD",WIDGET_SECONDARY_TEXT_COLOR:"#999",LINK_COLOR:"#9A9",EVENT_LINK_COLOR:"#A86",CONNECTING_LINK_COLOR:"#AFA",MAX_NUMBER_OF_NODES:1E3,
DEFAULT_POSITION:[100,100],VALID_SHAPES:["default","box","round","card"],BOX_SHAPE:1,ROUND_SHAPE:2,CIRCLE_SHAPE:3,CARD_SHAPE:4,ARROW_SHAPE:5,INPUT:1,OUTPUT:2,EVENT:-1,ACTION:-1,ALWAYS:0,ON_EVENT:1,NEVER:2,ON_TRIGGER:3,UP:1,DOWN:2,LEFT:3,RIGHT:4,CENTER:5,STRAIGHT_LINK:0,LINEAR_LINK:1,SPLINE_LINK:2,NORMAL_TITLE:0,NO_TITLE:1,TRANSPARENT_TITLE:2,AUTOHIDE_TITLE:3,proxy:null,node_images_path:"",debug:!1,catch_exceptions:!0,throw_errors:!0,allow_scripts:!1,registered_node_types:{},node_types_by_file_extension:{},
Nodes:{},Globals:{},searchbox_extras:{},auto_sort_node_types:!1,registerNodeType:function(a,b){if(!b.prototype)throw"Cannot register a simple object, it must be a class with a prototype";b.type=a;h.debug&&console.log("Node registered: "+a);a.split("/");var c=b.name,d=a.lastIndexOf("/");b.category=a.substr(0,d);b.title||(b.title=c);if(b.prototype)for(var e in l.prototype)b.prototype[e]||(b.prototype[e]=l.prototype[e]);if(d=this.registered_node_types[a])console.log("replacing node type: "+a);else if(Object.hasOwnProperty(b.prototype,
"shape")||Object.defineProperty(b.prototype,"shape",{set:function(a){switch(a){case "default":delete this._shape;break;case "box":this._shape=h.BOX_SHAPE;break;case "round":this._shape=h.ROUND_SHAPE;break;case "circle":this._shape=h.CIRCLE_SHAPE;break;case "card":this._shape=h.CARD_SHAPE;break;default:this._shape=a}},get:function(a){return this._shape},enumerable:!0,configurable:!0}),b.prototype.onPropertyChange&&console.warn("LiteGraph node class "+a+" has onPropertyChange method, it must be called onPropertyChanged with d at the end"),
b.supported_extensions)for(e in b.supported_extensions){var g=b.supported_extensions[e];g&&g.constructor===String&&(this.node_types_by_file_extension[g.toLowerCase()]=b)}this.registered_node_types[a]=b;b.constructor.name&&(this.Nodes[c]=b);if(h.onNodeTypeRegistered)h.onNodeTypeRegistered(a,b);if(d&&h.onNodeTypeReplaced)h.onNodeTypeReplaced(a,b,d);b.prototype.onPropertyChange&&console.warn("LiteGraph node class "+a+" has onPropertyChange method, it must be called onPropertyChanged with d at the end");
if(b.supported_extensions)for(e=0;e<b.supported_extensions.length;e++)(g=b.supported_extensions[e])&&g.constructor===String&&(this.node_types_by_file_extension[g.toLowerCase()]=b)},unregisterNodeType:function(a){var b=a.constructor===String?this.registered_node_types[a]:a;if(!b)throw"node type not found: "+a;delete this.registered_node_types[b.type];b.constructor.name&&delete this.Nodes[b.constructor.name]},wrapFunctionAsNode:function(a,b,c,d,e){for(var g=Array(b.length),f="",m=h.getParameterNames(b),
q=0;q<m.length;++q)f+="this.addInput('"+m[q]+"',"+(c&&c[q]?"'"+c[q]+"'":"0")+");\n";f+="this.addOutput('out',"+(d?"'"+d+"'":0)+");\n";e&&(f+="this.properties = "+JSON.stringify(e)+";\n");c=Function(f);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){l.prototype[a]=b;for(var c in this.registered_node_types){var d=this.registered_node_types[c];d.prototype[a]&&(d.prototype["_"+a]=d.prototype[a]);d.prototype[a]=b}},createNode:function(a,b,c){var d=this.registered_node_types[a];if(!d)return h.debug&&console.log('GraphNode type "'+a+'" not registered.'),null;b=b||d.title||a;var e=null;if(h.catch_exceptions)try{e=new d(b)}catch(g){return console.error(g),null}else e=new d(b);e.type=
a;!e.title&&b&&(e.title=b);e.properties||(e.properties={});e.properties_info||(e.properties_info=[]);e.flags||(e.flags={});e.size||(e.size=e.computeSize());e.pos||(e.pos=h.DEFAULT_POSITION.concat());e.mode||(e.mode=h.ALWAYS);if(c)for(var f in c)e[f]=c[f];return e},getNodeType:function(a){return this.registered_node_types[a]},getNodeTypesInCategory:function(a,b){var c=[],d;for(d in this.registered_node_types){var e=this.registered_node_types[d];e.filter==b&&(""==a?null==e.category&&c.push(e):e.category==
a&&c.push(e))}return this.auto_sort_node_types?c.sort():c},getNodeTypesCategories:function(a){var b={"":1},c;for(c in this.registered_node_types){var d=this.registered_node_types[c];d.category&&!d.skip_list&&d.filter==a&&(b[d.category]=1)}a=[];for(c in b)a.push(c);return this.auto_sort_node_types?a.sort():a},reloadNodes:function(a){for(var b=document.getElementsByTagName("script"),c=[],d=0;d<b.length;d++)c.push(b[d]);b=document.getElementsByTagName("head")[0];a=document.location.href+a;for(d=0;d<
c.length;d++){var e=c[d].src;if(e&&e.substr(0,a.length)==a)try{h.debug&&console.log("Reloading: "+e);var g=document.createElement("script");g.type="text/javascript";g.src=e;b.appendChild(g);b.removeChild(c[d])}catch(f){if(h.throw_errors)throw f;h.debug&&console.log("Error while reloading "+e)}}h.debug&&console.log("Nodes reloaded")},cloneObject:function(a,b){if(null==a)return null;var c=JSON.parse(JSON.stringify(a));if(!b)return c;for(var d in c)b[d]=c[d];return b},isValidConnection:function(a,b){if(!a||
!b||a==b||a==h.EVENT&&b==h.ACTION)return!0;a=String(a);b=String(b);a=a.toLowerCase();b=b.toLowerCase();if(-1==a.indexOf(",")&&-1==b.indexOf(","))return a==b;for(var c=a.split(","),d=b.split(","),e=0;e<c.length;++e)for(var g=0;g<d.length;++g)if(c[e]==d[g])return!0;return!1},registerSearchboxExtra:function(a,b,c){this.searchbox_extras[b.toLowerCase()]={type:a,desc:b,data:c}},fetchFile:function(a,b,c,d){if(!a)return null;b=b||"text";if(a.constructor===String)return"http"==a.substr(0,4)&&h.proxy&&(a=
h.proxy+a.substr(a.indexOf(":")+3)),fetch(a).then(function(a){if(!a.ok)throw Error("File not found");if("arraybuffer"==b)return a.arrayBuffer();if("text"==b||"string"==b)return a.text();if("json"==b)return a.json();if("blob"==b)return a.blob()}).then(function(a){c&&c(a)})["catch"](function(b){console.error("error fetching file:",a);d&&d(b)});if(a.constructor===File||a.constructor===Blob){var e=new FileReader;e.onload=function(a){a=a.target.result;"json"==b&&(a=JSON.parse(a));c&&c(a)};if("arraybuffer"==
b)return e.readAsArrayBuffer(a);if("text"==b||"json"==b)return e.readAsText(a);if("blob"==b)return e.readAsBinaryString(a)}return null}};h.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 0.001*a[0]+1E-6*a[1]}:function(){return(new Date).getTime()};B.LGraph=h.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=0.01;this.starttime=this.last_update_time=0;this.catch_errors=!0;this.inputs={};this.outputs={};this.change();this.sendActionToCanvas("clear")};n.prototype.attachCanvas=function(a){if(a.constructor!=k)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=h.getTime();a=a||0;var b=this;if(0==a&&"undefined"!=typeof window&&window.requestAnimationFrame){var c=function(){if(-1==b.execution_timer_id){window.requestAnimationFrame(c);if(b.onBeforeStep)b.onBeforeStep();
b.runStep(1,!b.catch_errors);if(b.onAfterStep)b.onAfterStep()}};this.execution_timer_id=-1;c()}else this.execution_timer_id=setInterval(function(){if(b.onBeforeStep)b.onBeforeStep();b.runStep(1,!b.catch_errors);if(b.onAfterStep)b.onAfterStep()},a)}};n.prototype.stop=function(){if(this.status!=n.STATUS_STOPPED){this.status=n.STATUS_STOPPED;if(this.onStopEvent)this.onStopEvent();null!=this.execution_timer_id&&(-1!=this.execution_timer_id&&clearInterval(this.execution_timer_id),this.execution_timer_id=
null);this.sendEventToAllNodes("onStop")}};n.prototype.runStep=function(a,b,c){a=a||1;var d=h.getTime();this.globaltime=0.001*(d-this.starttime);var e=this._nodes_executable?this._nodes_executable:this._nodes;if(e){c=c||e.length;if(b){for(var g=0;g<a;g++){for(var f=0;f<c;++f){var m=e[f];if(m.mode==h.ALWAYS&&m.onExecute)m.onExecute()}this.fixedtime+=this.fixedtime_lapse;if(this.onExecuteStep)this.onExecuteStep()}if(this.onAfterExecute)this.onAfterExecute()}else try{for(g=0;g<a;g++){for(f=0;f<c;++f)if(m=
e[f],m.mode==h.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(h.throw_errors)throw q;h.debug&&console.log("Error during execution: "+q);this.stop()}a=h.getTime();d=a-d;0==d&&(d=1);this.execution_time=0.001*d;this.globaltime+=0.001*d;this.iteration+=1;this.elapsed_time=0.001*(a-this.last_update_time);this.last_update_time=
a}};n.prototype.updateExecutionOrder=function(){this._nodes_in_order=this.computeExecutionOrder(!1);this._nodes_executable=[];for(var a=0;a<this._nodes_in_order.length;++a)this._nodes_in_order[a].onExecute&&this._nodes_executable.push(this._nodes_in_order[a])};n.prototype.computeExecutionOrder=function(a,b){for(var c=[],d=[],e={},g={},f={},m=0,q=this._nodes.length;m<q;++m){var k=this._nodes[m];if(!a||k.onExecute){e[k.id]=k;var s=0;if(k.inputs)for(var p=0,w=k.inputs.length;p<w;p++)k.inputs[p]&&null!=
k.inputs[p].link&&(s+=1);0==s?(d.push(k),b&&(k._level=1)):(b&&(k._level=0),f[k.id]=s)}}for(;0!=d.length;)if(k=d.shift(),c.push(k),delete e[k.id],k.outputs)for(m=0;m<k.outputs.length;m++)if(q=k.outputs[m],null!=q&&null!=q.links&&0!=q.links.length)for(p=0;p<q.links.length;p++)(s=this.links[q.links[p]])&&!g[s.id]&&(w=this.getNodeById(s.target_id),null==w?g[s.id]=!0:(b&&(!w._level||w._level<=k._level)&&(w._level=k._level+1),g[s.id]=!0,f[w.id]-=1,0==f[w.id]&&d.push(w)));for(m in e)c.push(e[m]);c.length!=
this._nodes.length&&h.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,e=b.constructor.priority||b.priority||0;return c==e?a.order-b.order:c-e});for(m=0;m<q;++m)c[m].order=m;return c};n.prototype.getAncestors=function(a){for(var b=[],c=[a],d={};c.length;){var e=c.shift();if(e.inputs){d[e.id]||e==a||(d[e.id]=!0,b.push(e));for(var g=0;g<e.inputs.length;++g){var f=e.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){a=a||100;for(var b=this.computeExecutionOrder(!1,!0),c=[],d=0;d<b.length;++d){var e=b[d],g=e._level||1;c[g]||(c[g]=[]);c[g].push(e)}b=a;for(d=0;d<c.length;++d)if(g=c[d]){for(var f=100,m=a+h.NODE_TITLE_HEIGHT,q=0;q<g.length;++q)e=g[q],e.pos[0]=b,e.pos[1]=m,e.size[0]>f&&(f=e.size[0]),m+=e.size[1]+a+h.NODE_TITLE_HEIGHT;b+=f+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||h.ALWAYS;var d=this._nodes_in_order?this._nodes_in_order:this._nodes;if(d)for(var e=0,g=d.length;e<g;++e){var f=d[e];if(f.constructor===h.Subgraph&&"onExecute"!=a)f.mode==c&&f.sendEventToAllNodes(a,b,c);else if(f[a]&&f.mode==c)if(void 0===b)f[a]();else if(b&&b.constructor===Array)f[a].apply(f,b);else f[a](b)}};n.prototype.sendActionToCanvas=
function(a,b){if(this.list_of_graphcanvas)for(var c=0;c<this.list_of_graphcanvas.length;++c){var d=this.list_of_graphcanvas[c];d[a]&&d[a].apply(d,b)}};n.prototype.add=function(a,b){if(a)if(a.constructor===r)this._groups.push(a),this.setDirtyCanvas(!0),this.change(),a.graph=this,this._version++;else{-1!=a.id&&null!=this._nodes_by_id[a.id]&&(console.warn("LiteGraph: there is already a node with this ID, changing it"),a.id=++this.last_node_id);if(this._nodes.length>=h.MAX_NUMBER_OF_NODES)throw"LiteGraph: max number of nodes in a graph reached";
null==a.id||-1==a.id?a.id=++this.last_node_id:this.last_node_id<a.id&&(this.last_node_id=a.id);a.graph=this;this._version++;this._nodes.push(a);this._nodes_by_id[a.id]=a;if(a.onAdded)a.onAdded(this);this.config.align_to_grid&&a.alignToGrid();b||this.updateExecutionOrder();if(this.onNodeAdded)this.onNodeAdded(a);this.setDirtyCanvas(!0);this.change();return a}};n.prototype.remove=function(a){if(a.constructor===h.LGraphGroup){var b=this._groups.indexOf(a);-1!=b&&this._groups.splice(b,1);a.graph=null;
Nodes:{},Globals:{},searchbox_extras:{},auto_sort_node_types:!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;l.debug&&console.log("Node registered: "+a);a.split("/");var c=b.name,d=a.lastIndexOf("/");b.category=a.substr(0,d);b.title||(b.title=c);if(b.prototype)for(var e in k.prototype)b.prototype[e]||(b.prototype[e]=k.prototype[e]);if(d=this.registered_node_types[a])console.log("replacing node type: "+a);else if(Object.hasOwnProperty(b.prototype,
"shape")||Object.defineProperty(b.prototype,"shape",{set:function(a){switch(a){case "default":delete this._shape;break;case "box":this._shape=l.BOX_SHAPE;break;case "round":this._shape=l.ROUND_SHAPE;break;case "circle":this._shape=l.CIRCLE_SHAPE;break;case "card":this._shape=l.CARD_SHAPE;break;default:this._shape=a}},get:function(a){return this._shape},enumerable:!0,configurable:!0}),b.prototype.onPropertyChange&&console.warn("LiteGraph node class "+a+" has onPropertyChange method, it must be called onPropertyChanged with d at the end"),
b.supported_extensions)for(e in b.supported_extensions){var f=b.supported_extensions[e];f&&f.constructor===String&&(this.node_types_by_file_extension[f.toLowerCase()]=b)}this.registered_node_types[a]=b;b.constructor.name&&(this.Nodes[c]=b);if(l.onNodeTypeRegistered)l.onNodeTypeRegistered(a,b);if(d&&l.onNodeTypeReplaced)l.onNodeTypeReplaced(a,b,d);b.prototype.onPropertyChange&&console.warn("LiteGraph node class "+a+" has onPropertyChange method, it must be called onPropertyChanged with d at the end");
if(b.supported_extensions)for(e=0;e<b.supported_extensions.length;e++)(f=b.supported_extensions[e])&&f.constructor===String&&(this.node_types_by_file_extension[f.toLowerCase()]=b)},unregisterNodeType:function(a){var b=a.constructor===String?this.registered_node_types[a]:a;if(!b)throw"node type not found: "+a;delete this.registered_node_types[b.type];b.constructor.name&&delete this.Nodes[b.constructor.name]},wrapFunctionAsNode:function(a,b,c,d,e){for(var f=Array(b.length),g="",n=l.getParameterNames(b),
r=0;r<n.length;++r)g+="this.addInput('"+n[r]+"',"+(c&&c[r]?"'"+c[r]+"'":"0")+");\n";g+="this.addOutput('out',"+(d?"'"+d+"'":0)+");\n";e&&(g+="this.properties = "+JSON.stringify(e)+";\n");c=Function(g);c.title=a.split("/").pop();c.desc="Generated from "+b.name;c.prototype.onExecute=function(){for(var a=0;a<f.length;++a)f[a]=this.getInputData(a);a=b.apply(this,f);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){k.prototype[a]=b;for(var c in this.registered_node_types){var d=this.registered_node_types[c];d.prototype[a]&&(d.prototype["_"+a]=d.prototype[a]);d.prototype[a]=b}},createNode:function(a,b,c){var d=this.registered_node_types[a];if(!d)return l.debug&&console.log('GraphNode type "'+a+'" not registered.'),null;b=b||d.title||a;var e=null;if(l.catch_exceptions)try{e=new d(b)}catch(g){return console.error(g),null}else e=new d(b);e.type=
a;!e.title&&b&&(e.title=b);e.properties||(e.properties={});e.properties_info||(e.properties_info=[]);e.flags||(e.flags={});e.size||(e.size=e.computeSize());e.pos||(e.pos=l.DEFAULT_POSITION.concat());e.mode||(e.mode=l.ALWAYS);if(c)for(var f in c)e[f]=c[f];return e},getNodeType:function(a){return this.registered_node_types[a]},getNodeTypesInCategory:function(a,b){var c=[],d;for(d in this.registered_node_types){var e=this.registered_node_types[d];e.filter==b&&(""==a?null==e.category&&c.push(e):e.category==
a&&c.push(e))}this.auto_sort_node_types&&c.sort(function(a,b){return a.title.localeCompare(b.title)});return c},getNodeTypesCategories:function(a){var b={"":1},c;for(c in this.registered_node_types){var d=this.registered_node_types[c];d.category&&!d.skip_list&&d.filter==a&&(b[d.category]=1)}a=[];for(c in b)a.push(c);return this.auto_sort_node_types?a.sort():a},reloadNodes:function(a){for(var b=document.getElementsByTagName("script"),c=[],d=0;d<b.length;d++)c.push(b[d]);b=document.getElementsByTagName("head")[0];
a=document.location.href+a;for(d=0;d<c.length;d++){var e=c[d].src;if(e&&e.substr(0,a.length)==a)try{l.debug&&console.log("Reloading: "+e);var f=document.createElement("script");f.type="text/javascript";f.src=e;b.appendChild(f);b.removeChild(c[d])}catch(g){if(l.throw_errors)throw g;l.debug&&console.log("Error while reloading "+e)}}l.debug&&console.log("Nodes reloaded")},cloneObject:function(a,b){if(null==a)return null;a=JSON.parse(JSON.stringify(a));if(!b)return a;for(var c in a)b[c]=a[c];return b},
isValidConnection:function(a,b){if(!a||!b||a==b||a==l.EVENT&&b==l.ACTION)return!0;a=String(a);b=String(b);a=a.toLowerCase();b=b.toLowerCase();if(-1==a.indexOf(",")&&-1==b.indexOf(","))return a==b;a=a.split(",");b=b.split(",");for(var c=0;c<a.length;++c)for(var d=0;d<b.length;++d)if(a[c]==b[d])return!0;return!1},registerSearchboxExtra:function(a,b,c){this.searchbox_extras[b.toLowerCase()]={type:a,desc:b,data:c}},fetchFile:function(a,b,c,d){if(!a)return null;b=b||"text";if(a.constructor===String)return"http"==
a.substr(0,4)&&l.proxy&&(a=l.proxy+a.substr(a.indexOf(":")+3)),fetch(a).then(function(a){if(!a.ok)throw Error("File not found");if("arraybuffer"==b)return a.arrayBuffer();if("text"==b||"string"==b)return a.text();if("json"==b)return a.json();if("blob"==b)return a.blob()}).then(function(a){c&&c(a)}).catch(function(b){console.error("error fetching file:",a);d&&d(b)});if(a.constructor===File||a.constructor===Blob){var e=new FileReader;e.onload=function(a){a=a.target.result;"json"==b&&(a=JSON.parse(a));
c&&c(a)};if("arraybuffer"==b)return e.readAsArrayBuffer(a);if("text"==b||"json"==b)return e.readAsText(a);if("blob"==b)return e.readAsBinaryString(a)}return null}};l.getTime="undefined"!=typeof performance?performance.now.bind(performance):"undefined"!=typeof Date&&Date.now?Date.now.bind(Date):"undefined"!=typeof process?function(){var a=process.hrtime();return.001*a[0]+1E-6*a[1]}:function(){return(new Date).getTime()};v.LGraph=l.LGraph=m;m.supported_types=["number","string","boolean"];m.prototype.getSupportedTypes=
function(){return this.supported_types||m.supported_types};m.STATUS_STOPPED=1;m.STATUS_RUNNING=2;m.prototype.clear=function(){this.stop();this.status=m.STATUS_STOPPED;this.last_link_id=this.last_node_id=0;this._version=-1;if(this._nodes)for(var a=0;a<this._nodes.length;++a){var b=this._nodes[a];if(b.onRemoved)b.onRemoved()}this._nodes=[];this._nodes_by_id={};this._nodes_in_order=[];this._nodes_executable=null;this._groups=[];this.links={};this.iteration=0;this.config={};this.vars={};this.extra={};
this.fixedtime=this.runningtime=this.globaltime=0;this.elapsed_time=this.fixedtime_lapse=.01;this.starttime=this.last_update_time=0;this.catch_errors=!0;this.inputs={};this.outputs={};this.change();this.sendActionToCanvas("clear")};m.prototype.attachCanvas=function(a){if(a.constructor!=h)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)};m.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))}};m.prototype.start=function(a){if(this.status!=m.STATUS_RUNNING){this.status=m.STATUS_RUNNING;if(this.onPlayEvent)this.onPlayEvent();this.sendEventToAllNodes("onStart");this.last_update_time=this.starttime=l.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)}};m.prototype.stop=function(){if(this.status!=m.STATUS_STOPPED){this.status=m.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")}};m.prototype.runStep=function(a,b,c){a=a||1;var d=l.getTime();this.globaltime=.001*(d-this.starttime);var e=this._nodes_executable?this._nodes_executable:this._nodes;if(e){c=c||e.length;if(b){for(var f=0;f<a;f++){for(var g=0;g<c;++g){var n=e[g];if(n.mode==l.ALWAYS&&n.onExecute)n.onExecute()}this.fixedtime+=this.fixedtime_lapse;if(this.onExecuteStep)this.onExecuteStep()}if(this.onAfterExecute)this.onAfterExecute()}else try{for(f=0;f<
a;f++){for(g=0;g<c;++g)if(n=e[g],n.mode==l.ALWAYS&&n.onExecute)n.onExecute();this.fixedtime+=this.fixedtime_lapse;if(this.onExecuteStep)this.onExecuteStep()}if(this.onAfterExecute)this.onAfterExecute();this.errors_in_execution=!1}catch(r){this.errors_in_execution=!0;if(l.throw_errors)throw r;l.debug&&console.log("Error during execution: "+r);this.stop()}a=l.getTime();d=a-d;0==d&&(d=1);this.execution_time=.001*d;this.globaltime+=.001*d;this.iteration+=1;this.elapsed_time=.001*(a-this.last_update_time);
this.last_update_time=a}};m.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])};m.prototype.computeExecutionOrder=function(a,b){for(var c=[],d=[],e={},f={},g={},n=0,r=this._nodes.length;n<r;++n){var h=this._nodes[n];if(!a||h.onExecute){e[h.id]=h;var u=0;if(h.inputs)for(var p=0,z=h.inputs.length;p<
z;p++)h.inputs[p]&&null!=h.inputs[p].link&&(u+=1);0==u?(d.push(h),b&&(h._level=1)):(b&&(h._level=0),g[h.id]=u)}}for(;0!=d.length;)if(h=d.shift(),c.push(h),delete e[h.id],h.outputs)for(n=0;n<h.outputs.length;n++)if(a=h.outputs[n],null!=a&&null!=a.links&&0!=a.links.length)for(p=0;p<a.links.length;p++)(r=this.links[a.links[p]])&&!f[r.id]&&(u=this.getNodeById(r.target_id),null==u?f[r.id]=!0:(b&&(!u._level||u._level<=h._level)&&(u._level=h._level+1),f[r.id]=!0,--g[u.id],0==g[u.id]&&d.push(u)));for(n in e)c.push(e[n]);
c.length!=this._nodes.length&&l.debug&&console.warn("something went wrong, nodes missing");r=c.length;for(n=0;n<r;++n)c[n].order=n;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(n=0;n<r;++n)c[n].order=n;return c};m.prototype.getAncestors=function(a){for(var b=[],c=[a],d={};c.length;){var e=c.shift();if(e.inputs){d[e.id]||e==a||(d[e.id]=!0,b.push(e));for(var f=0;f<e.inputs.length;++f){var g=e.getInputNode(f);
g&&-1==b.indexOf(g)&&c.push(g)}}}b.sort(function(a,b){return a.order-b.order});return b};m.prototype.arrange=function(a){a=a||100;for(var b=this.computeExecutionOrder(!1,!0),c=[],d=0;d<b.length;++d){var e=b[d],f=e._level||1;c[f]||(c[f]=[]);c[f].push(e)}b=a;for(d=0;d<c.length;++d)if(f=c[d]){for(var g=100,n=a+l.NODE_TITLE_HEIGHT,r=0;r<f.length;++r)e=f[r],e.pos[0]=b,e.pos[1]=n,e.size[0]>g&&(g=e.size[0]),n+=e.size[1]+a+l.NODE_TITLE_HEIGHT;b+=g+a}this.setDirtyCanvas(!0,!0)};m.prototype.getTime=function(){return this.globaltime};
m.prototype.getFixedTime=function(){return this.fixedtime};m.prototype.getElapsedTime=function(){return this.elapsed_time};m.prototype.sendEventToAllNodes=function(a,b,c){c=c||l.ALWAYS;var d=this._nodes_in_order?this._nodes_in_order:this._nodes;if(d)for(var e=0,f=d.length;e<f;++e){var g=d[e];if(g.constructor===l.Subgraph&&"onExecute"!=a)g.mode==c&&g.sendEventToAllNodes(a,b,c);else if(g[a]&&g.mode==c)if(void 0===b)g[a]();else if(b&&b.constructor===Array)g[a].apply(g,b);else g[a](b)}};m.prototype.sendActionToCanvas=
function(a,b){if(this.list_of_graphcanvas)for(var c=0;c<this.list_of_graphcanvas.length;++c){var d=this.list_of_graphcanvas[c];d[a]&&d[a].apply(d,b)}};m.prototype.add=function(a,b){if(a)if(a.constructor===t)this._groups.push(a),this.setDirtyCanvas(!0),this.change(),a.graph=this,this._version++;else{-1!=a.id&&null!=this._nodes_by_id[a.id]&&(console.warn("LiteGraph: there is already a node with this ID, changing it"),a.id=++this.last_node_id);if(this._nodes.length>=l.MAX_NUMBER_OF_NODES)throw"LiteGraph: max number of nodes in a graph reached";
null==a.id||-1==a.id?a.id=++this.last_node_id:this.last_node_id<a.id&&(this.last_node_id=a.id);a.graph=this;this._version++;this._nodes.push(a);this._nodes_by_id[a.id]=a;if(a.onAdded)a.onAdded(this);this.config.align_to_grid&&a.alignToGrid();b||this.updateExecutionOrder();if(this.onNodeAdded)this.onNodeAdded(a);this.setDirtyCanvas(!0);this.change();return a}};m.prototype.remove=function(a){if(a.constructor===l.LGraphGroup){var b=this._groups.indexOf(a);-1!=b&&this._groups.splice(b,1);a.graph=null;
this._version++;this.setDirtyCanvas(!0,!0);this.change()}else if(null!=this._nodes_by_id[a.id]&&!a.ignore_remove){this.beforeChange();if(a.inputs)for(b=0;b<a.inputs.length;b++){var c=a.inputs[b];null!=c.link&&a.disconnectInput(b)}if(a.outputs)for(b=0;b<a.outputs.length;b++)c=a.outputs[b],null!=c.links&&c.links.length&&a.disconnectOutput(b);if(a.onRemoved)a.onRemoved();a.graph=null;this._version++;if(this.list_of_graphcanvas)for(b=0;b<this.list_of_graphcanvas.length;++b)c=this.list_of_graphcanvas[b],
c.selected_nodes[a.id]&&delete c.selected_nodes[a.id],c.node_dragged==a&&(c.node_dragged=null);b=this._nodes.indexOf(a);-1!=b&&this._nodes.splice(b,1);delete this._nodes_by_id[a.id];if(this.onNodeRemoved)this.onNodeRemoved(a);this.sendActionToCanvas("checkPanels");this.setDirtyCanvas(!0,!0);this.afterChange();this.change();this.updateExecutionOrder()}};n.prototype.getNodeById=function(a){return null==a?null:this._nodes_by_id[a]};n.prototype.findNodesByClass=function(a,b){b=b||[];for(var c=b.length=
0,d=this._nodes.length;c<d;++c)this._nodes[c].constructor===a&&b.push(this._nodes[c]);return b};n.prototype.findNodesByType=function(a,b){a=a.toLowerCase();b=b||[];for(var c=b.length=0,d=this._nodes.length;c<d;++c)this._nodes[c].type.toLowerCase()==a&&b.push(this._nodes[c]);return b};n.prototype.findNodeByTitle=function(a){for(var b=0,c=this._nodes.length;b<c;++b)if(this._nodes[b].title==a)return this._nodes[b];return null};n.prototype.findNodesByTitle=function(a){for(var b=[],c=0,d=this._nodes.length;c<
d;++c)this._nodes[c].title==a&&b.push(this._nodes[c]);return b};n.prototype.getNodeOnPos=function(a,b,c,d){c=c||this._nodes;for(var e=c.length-1;0<=e;e--){var g=c[e];if(g.isPointInside(a,b,d))return g}return null};n.prototype.getGroupOnPos=function(a,b){for(var c=this._groups.length-1;0<=c;c--){var d=this._groups[c];if(d.isPointInside(a,b,2,!0))return d}return null};n.prototype.checkNodeTypes=function(){for(var a=0;a<this._nodes.length;a++){var b=this._nodes[a];if(b.constructor!=h.registered_node_types[b.type]){console.log("node being replaced by newer version: "+
b.type);var c=h.createNode(b.type);this._nodes[a]=c;c.configure(b.serialize());c.graph=this;this._nodes_by_id[c.id]=c;b.inputs&&(c.inputs=b.inputs.concat());b.outputs&&(c.outputs=b.outputs.concat())}}this.updateExecutionOrder()};n.prototype.onAction=function(a,b){this._input_nodes=this.findNodesByClass(h.GraphInput,this._input_nodes);for(var c=0;c<this._input_nodes.length;++c){var d=this._input_nodes[c];if(d.properties.name==a){d.onAction(a,b);break}}};n.prototype.trigger=function(a,b){if(this.onTrigger)this.onTrigger(a,
b)};n.prototype.addInput=function(a,b,c){if(!this.inputs[a]){this.beforeChange();this.inputs[a]={name:a,type:b,value:c};this._version++;this.afterChange();if(this.onInputAdded)this.onInputAdded(a,b);if(this.onInputsOutputsChange)this.onInputsOutputsChange()}};n.prototype.setInputData=function(a,b){var c=this.inputs[a];c&&(c.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){var c=this.outputs[a];c&&(c.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){for(var c=this.findNodesByTitle(a),d=0;d<c.length;++d)c[d].onTrigger(b)};n.prototype.setCallback=function(a,b){for(var c=this.findNodesByTitle(a),d=0;d<c.length;++d)c[d].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(){h.debug&&console.log("Graph changed");this.sendActionToCanvas("setDirty",[!0,!0]);if(this.on_change)this.on_change(this)};n.prototype.setDirtyCanvas=function(a,b){this.sendActionToCanvas("setDirty",[a,b])};n.prototype.removeLink=function(a){if(a=
this.links[a]){var b=this.getNodeById(a.target_id);b&&b.disconnectInput(a.target_slot)}};n.prototype.serialize=function(){for(var a=[],b=0,c=this._nodes.length;b<c;++b)a.push(this._nodes[b].serialize());c=[];for(b in this.links){var d=this.links[b];if(!d.serialize){console.warn("weird LLink bug, link info is not a LLink but a regular object");var e=new u,g;for(g in d)e[g]=d[g];d=this.links[b]=e}c.push(d.serialize())}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:h.VERSION};if(this.onSerialize)this.onSerialize(a);return a};n.prototype.configure=function(a,b){if(a){b||this.clear();var c=a.nodes;if(a.links&&a.links.constructor===Array){for(var d=[],e=0;e<a.links.length;++e){var g=a.links[e];if(g){var f=new u;f.configure(g);d[f.id]=f}else console.warn("serialized graph link data contains errors, skipping.")}a.links=d}for(e in a)"nodes"!=e&&"groups"!=e&&(this[e]=
a[e]);d=!1;this._nodes=[];if(c){e=0;for(g=c.length;e<g;++e){var f=c[e],m=h.createNode(f.type,f.title);m||(h.debug&&console.log("Node not found or has errors: "+f.type),m=new l,m.last_serialization=f,d=m.has_errors=!0);m.id=f.id;this.add(m,!0)}e=0;for(g=c.length;e<g;++e)f=c[e],(m=this.getNodeById(f.id))&&m.configure(f)}this._groups.length=0;if(a.groups)for(e=0;e<a.groups.length;++e)c=new h.LGraphGroup,c.configure(a.groups[e]),this.add(c);this.updateExecutionOrder();this.extra=a.extra||{};if(this.onConfigure)this.onConfigure(a);
this._version++;this.setDirtyCanvas(!0,!0);return d}};n.prototype.load=function(a,b){var c=this;if(a.constructor===File||a.constructor===Blob){var d=new FileReader;d.addEventListener("load",function(a){a=JSON.parse(a.target.result);c.configure(a);b&&b()});d.readAsText(a)}else{var e=new XMLHttpRequest;e.open("GET",a,!0);e.send(null);e.onload=function(a){200!==e.status?console.error("Error loading graph:",e.status,e.response):(a=JSON.parse(e.response),c.configure(a),b&&b())};e.onerror=function(a){console.error("Error loading graph:",
a)}}};n.prototype.onNodeTrace=function(a,b,c){};u.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)};u.prototype.serialize=function(){return[this.id,this.origin_id,this.origin_slot,this.target_id,this.target_slot,this.type]};h.LLink=u;
B.LGraphNode=h.LGraphNode=l;l.prototype._ctor=function(a){this.title=a||"Unnamed";this.size=[h.NODE_WIDTH,60];this.graph=null;this._pos=new Float32Array(10,10);Object.defineProperty(this,"pos",{set:function(a){!a||2>a.length||(this._pos[0]=a[0],this._pos[1]=a[1])},get:function(){return this._pos},enumerable:!0});this.id=-1;this.type=null;this.inputs=[];this.outputs=[];this.connections=[];this.properties={};this.properties_info=[];this.flags={}};l.prototype.configure=function(a){this.graph&&this.graph._version++;
for(var b in a)if("properties"==b)for(var c in a.properties){if(this.properties[c]=a.properties[c],this.onPropertyChanged)this.onPropertyChanged(c,a.properties[c])}else null!=a[b]&&("object"==typeof a[b]?this[b]&&this[b].configure?this[b].configure(a[b]):this[b]=h.cloneObject(a[b],this[b]):this[b]=a[b]);a.title||(this.title=this.constructor.title);if(this.onConnectionsChange){if(this.inputs)for(c=0;c<this.inputs.length;++c){b=this.inputs[c];var d=this.graph?this.graph.links[b.link]:null;this.onConnectionsChange(h.INPUT,
c,!0,d,b)}if(this.outputs)for(c=0;c<this.outputs.length;++c){var e=this.outputs[c];if(e.links)for(b=0;b<e.links.length;++b)d=this.graph?this.graph.links[e.links[b]]:null,this.onConnectionsChange(h.OUTPUT,c,!0,d,e)}}if(this.widgets){for(c=0;c<this.widgets.length;++c)(b=this.widgets[c])&&b.options&&b.options.property&&this.properties[b.options.property]&&(b.value=JSON.parse(JSON.stringify(this.properties[b.options.property])));if(a.widgets_values)for(c=0;c<a.widgets_values.length;++c)this.widgets[c]&&
(this.widgets[c].value=a.widgets_values[c])}if(this.onConfigure)this.onConfigure(a)};l.prototype.serialize=function(){var a={id:this.id,type:this.type,pos:this.pos,size:this.size,flags:h.cloneObject(this.flags),order:this.order,mode:this.mode};if(this.constructor===l&&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=h.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};l.prototype.clone=function(){var a=h.createNode(this.type);if(!a)return null;var b=h.cloneObject(this.serialize());if(b.inputs)for(var c=0;c<b.inputs.length;++c)b.inputs[c].link=null;if(b.outputs)for(c=0;c<b.outputs.length;++c)b.outputs[c].links&&(b.outputs[c].links.length=0);delete b.id;a.configure(b);return a};l.prototype.toString=function(){return JSON.stringify(this.serialize())};l.prototype.getTitle=function(){return this.title||this.constructor.title};l.prototype.setProperty=function(a,
b){this.properties||(this.properties={});if(b!==this.properties[a]){var c=this.properties[a];this.properties[a]=b;this.onPropertyChanged&&!1===this.onPropertyChanged(a,b,c)&&(this.properties[a]=c);if(this.widgets)for(c=0;c<this.widgets.length;++c){var d=this.widgets[c];if(d&&d.options.property==a){d.value=b;break}}}};l.prototype.setOutputData=function(a,b){if(this.outputs&&!(-1==a||a>=this.outputs.length)){var c=this.outputs[a];if(c&&(c._data=b,this.outputs[a].links))for(c=0;c<this.outputs[a].links.length;c++){var d=
this.graph.links[this.outputs[a].links[c]];d&&(d.data=b)}}};l.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}};l.prototype.getInputData=function(a,b){if(this.inputs&&!(a>=this.inputs.length||null==this.inputs[a].link)){var c=this.graph.links[this.inputs[a].link];if(!c)return null;if(!b)return c.data;
var d=this.graph.getNodeById(c.origin_id);if(!d)return c.data;if(d.updateOutputData)d.updateOutputData(c.origin_slot);else if(d.onExecute)d.onExecute();return c.data}};l.prototype.getInputDataType=function(a){if(!this.inputs||a>=this.inputs.length||null==this.inputs[a].link)return null;a=this.graph.links[this.inputs[a].link];if(!a)return null;var b=this.graph.getNodeById(a.origin_id);return b?(a=b.outputs[a.origin_slot])?a.type:null:a.type};l.prototype.getInputDataByName=function(a,b){var c=this.findInputSlot(a);
return-1==c?null:this.getInputData(c,b)};l.prototype.isInputConnected=function(a){return this.inputs?a<this.inputs.length&&null!=this.inputs[a].link:!1};l.prototype.getInputInfo=function(a){return this.inputs?a<this.inputs.length?this.inputs[a]:null:null};l.prototype.getInputLink=function(a){return this.inputs?a<this.inputs.length?this.graph.links[this.inputs[a].link]:null:null};l.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};l.prototype.getInputOrProperty=function(a){if(!this.inputs||!this.inputs.length)return this.properties?this.properties[a]:null;for(var b=0,c=this.inputs.length;b<c;++b){var d=this.inputs[b];if(a==d.name&&null!=d.link&&(d=this.graph.links[d.link]))return d.data}return this.properties[a]};l.prototype.getOutputData=function(a){return!this.outputs||a>=this.outputs.length?null:this.outputs[a]._data};l.prototype.getOutputInfo=
function(a){return this.outputs?a<this.outputs.length?this.outputs[a]:null:null};l.prototype.isOutputConnected=function(a){return this.outputs?a<this.outputs.length&&this.outputs[a].links&&this.outputs[a].links.length:!1};l.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};l.prototype.getOutputNodes=function(a){if(!this.outputs||0==this.outputs.length||a>=this.outputs.length)return null;
a=this.outputs[a];if(!a.links||0==a.links.length)return null;for(var b=[],c=0;c<a.links.length;c++){var d=this.graph.links[a.links[c]];d&&(d=this.graph.getNodeById(d.target_id))&&b.push(d)}return b};l.prototype.trigger=function(a,b){if(this.outputs&&this.outputs.length){this.graph&&(this.graph._last_trigger_time=h.getTime());for(var c=0;c<this.outputs.length;++c){var d=this.outputs[c];!d||d.type!==h.EVENT||a&&d.name!=a||this.triggerSlot(c,b)}}};l.prototype.triggerSlot=function(a,b,c){if(this.outputs&&
(a=this.outputs[a])&&(a=a.links)&&a.length){this.graph&&(this.graph._last_trigger_time=h.getTime());for(var d=0;d<a.length;++d){var e=a[d];if(null==c||c==e){var g=this.graph.links[a[d]];if(g&&(g._last_time=h.getTime(),e=this.graph.getNodeById(g.target_id)))if(g=e.inputs[g.target_slot],e.mode===h.ON_TRIGGER){if(e.onExecute)e.onExecute(b)}else if(e.onAction)e.onAction(g.name,b)}}}};l.prototype.clearTriggeredSlot=function(a,b){if(this.outputs){var c=this.outputs[a];if(c&&(c=c.links)&&c.length)for(var d=
0;d<c.length;++d){var e=c[d];if(null==b||b==e)if(e=this.graph.links[c[d]])e._last_time=0}}};l.prototype.setSize=function(a){this.size=a;if(this.onResize)this.onResize(this.size)};l.prototype.addProperty=function(a,b,c,d){c={name:a,type:c,default_value:b};if(d)for(var e in d)c[e]=d[e];this.properties_info||(this.properties_info=[]);this.properties_info.push(c);this.properties||(this.properties={});this.properties[a]=b;return c};l.prototype.addOutput=function(a,b,c){a={name:a,type:b,links:null};if(c)for(var d in c)a[d]=
c[d];this.outputs||(this.outputs=[]);this.outputs.push(a);if(this.onOutputAdded)this.onOutputAdded(a);this.setSize(this.computeSize());this.setDirtyCanvas(!0,!0);return a};l.prototype.addOutputs=function(a){for(var b=0;b<a.length;++b){var c=a[b],d={name:c[0],type:c[1],link:null};if(a[2])for(var e in c[2])d[e]=c[2][e];this.outputs||(this.outputs=[]);this.outputs.push(d);if(this.onOutputAdded)this.onOutputAdded(d)}this.setSize(this.computeSize());this.setDirtyCanvas(!0,!0)};l.prototype.removeOutput=
function(a){this.disconnectOutput(a);this.outputs.splice(a,1);for(var b=a;b<this.outputs.length;++b)if(this.outputs[b]&&this.outputs[b].links)for(var c=this.outputs[b].links,d=0;d<c.length;++d){var e=this.graph.links[c[d]];e&&(e.origin_slot-=1)}this.setSize(this.computeSize());if(this.onOutputRemoved)this.onOutputRemoved(a);this.setDirtyCanvas(!0,!0)};l.prototype.addInput=function(a,b,c){a={name:a,type:b||0,link:null};if(c)for(var d in c)a[d]=c[d];this.inputs||(this.inputs=[]);this.inputs.push(a);
this.setSize(this.computeSize());if(this.onInputAdded)this.onInputAdded(a);this.setDirtyCanvas(!0,!0);return a};l.prototype.addInputs=function(a){for(var b=0;b<a.length;++b){var c=a[b],d={name:c[0],type:c[1],link:null};if(a[2])for(var e in c[2])d[e]=c[2][e];this.inputs||(this.inputs=[]);this.inputs.push(d);if(this.onInputAdded)this.onInputAdded(d)}this.setSize(this.computeSize());this.setDirtyCanvas(!0,!0)};l.prototype.removeInput=function(a){this.disconnectInput(a);for(var b=this.inputs.splice(a,
1),c=a;c<this.inputs.length;++c)if(this.inputs[c]){var d=this.graph.links[this.inputs[c].link];d&&(d.target_slot-=1)}this.setSize(this.computeSize());if(this.onInputRemoved)this.onInputRemoved(a,b[0]);this.setDirtyCanvas(!0,!0)};l.prototype.addConnection=function(a,b,c,d){a={name:a,type:b,pos:c,direction:d,links:null};this.connections.push(a);return a};l.prototype.computeSize=function(a){function b(a){return a?d*a.length*0.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]);var c=Math.max(c,1),d=h.NODE_TEXT_SIZE,e=b(this.title),g=0,f=0;if(this.inputs)for(var m=0,q=this.inputs.length;m<q;++m){var k=this.inputs[m],k=k.label||k.name||"",k=b(k);g<k&&(g=k)}if(this.outputs)for(m=0,q=this.outputs.length;m<q;++m)k=this.outputs[m],k=k.label||k.name||"",k=b(k),f<k&&(f=k);a[0]=Math.max(g+f+10,e);a[0]=Math.max(a[0],h.NODE_WIDTH);this.widgets&&this.widgets.length&&(a[0]=Math.max(a[0],1.5*h.NODE_WIDTH));
a[1]=(this.constructor.slot_start_y||0)+c*h.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+(h.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};l.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};l.prototype.addWidget=function(a,b,c,d,e){this.widgets||
(this.widgets=[]);!e&&d&&d.constructor===Object&&(e=d,d=null);e&&e.constructor===String&&(e={property:e});d&&d.constructor===String&&(e||(e={}),e.property=d,d=null);d&&d.constructor!==Function&&(console.warn("addWidget: callback must be a function"),d=null);b={type:a.toLowerCase(),name:b,value:c,callback:d,options:e||{}};void 0!==b.options.y&&(b.y=b.options.y);d||b.options.callback||b.options.property||console.warn("LiteGraph addWidget(...) without a callback or property assigned");if("combo"==a&&
!b.options.values)throw"LiteGraph addWidget('combo',...) requires to pass values in options: { values:['red','blue'] }";this.widgets.push(b);this.setSize(this.computeSize());return b};l.prototype.addCustomWidget=function(a){this.widgets||(this.widgets=[]);this.widgets.push(a);return a};l.prototype.getBounding=function(a){a=a||new Float32Array(4);a[0]=this.pos[0]-4;a[1]=this.pos[1]-h.NODE_TITLE_HEIGHT;a[2]=this.size[0]+4;a[3]=this.flags.collapsed?h.NODE_TITLE_HEIGHT:this.size[1]+h.NODE_TITLE_HEIGHT;
if(this.onBounding)this.onBounding(a);return a};l.prototype.isPointInside=function(a,b,c,d){c=c||0;var e=this.graph&&this.graph.isLive()?0:h.NODE_TITLE_HEIGHT;d&&(e=0);if(this.flags&&this.flags.collapsed){if(y(a,b,this.pos[0]-c,this.pos[1]-h.NODE_TITLE_HEIGHT-c,(this._collapsed_width||h.NODE_COLLAPSED_WIDTH)+2*c,h.NODE_TITLE_HEIGHT+2*c))return!0}else if(this.pos[0]-4-c<a&&this.pos[0]+this.size[0]+4+c>a&&this.pos[1]-e-c<b&&this.pos[1]+this.size[1]+c>b)return!0;return!1};l.prototype.getSlotInPosition=
function(a,b){var c=new Float32Array(2);if(this.inputs)for(var d=0,e=this.inputs.length;d<e;++d){var g=this.inputs[d];this.getConnectionPos(!0,d,c);if(y(a,b,c[0]-10,c[1]-5,20,10))return{input:g,slot:d,link_pos:c}}if(this.outputs)for(d=0,e=this.outputs.length;d<e;++d)if(g=this.outputs[d],this.getConnectionPos(!1,d,c),y(a,b,c[0]-10,c[1]-5,20,10))return{output:g,slot:d,link_pos:c};return null};l.prototype.findInputSlot=function(a){if(!this.inputs)return-1;for(var b=0,c=this.inputs.length;b<c;++b)if(a==
this.inputs[b].name)return b;return-1};l.prototype.findOutputSlot=function(a){if(!this.outputs)return-1;for(var b=0,c=this.outputs.length;b<c;++b)if(a==this.outputs[b].name)return b;return-1};l.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 h.debug&&console.log("Connect: Error, no slot of name "+
a),null}else if(!this.outputs||a>=this.outputs.length)return h.debug&&console.log("Connect: Error, slot number not found"),null;b&&b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"target node is null";if(b==this)return null;if(c.constructor===String){if(c=b.findInputSlot(c),-1==c)return h.debug&&console.log("Connect: Error, no slot of name "+c),null}else{if(c===h.EVENT)return null;if(!b.inputs||c>=b.inputs.length)return h.debug&&console.log("Connect: Error, slot number not found"),
null}var d=!1;null!=b.inputs[c].link&&(this.graph.beforeChange(),b.disconnectInput(c),d=!0);var e=this.outputs[a];if(b.onConnectInput&&!1===b.onConnectInput(c,e.type,e,this,a))return null;var g=b.inputs[c],f=null;if(!h.isValidConnection(e.type,g.type))return this.setDirtyCanvas(!1,!0),d&&this.graph.connectionChange(this,f),null;d||this.graph.beforeChange();f=new u(++this.graph.last_link_id,g.type,this.id,a,b.id,c);this.graph.links[f.id]=f;null==e.links&&(e.links=[]);e.links.push(f.id);b.inputs[c].link=
f.id;this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(h.OUTPUT,a,!0,f,e);if(b.onConnectionsChange)b.onConnectionsChange(h.INPUT,c,!0,f,g);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(h.INPUT,b,c,this,a),this.graph.onNodeConnectionChange(h.OUTPUT,this,a,b,c));this.setDirtyCanvas(!1,!0);this.graph.afterChange();this.graph.connectionChange(this,f);return f};l.prototype.disconnectOutput=function(a,b){if(a.constructor===String){if(a=
this.findOutputSlot(a),-1==a)return h.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.outputs||a>=this.outputs.length)return h.debug&&console.log("Connect: Error, slot number not found"),!1;var c=this.outputs[a];if(!c||!c.links||0==c.links.length)return!1;if(b){b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"Target Node not found";for(var d=0,e=c.links.length;d<e;d++){var g=c.links[d],f=this.graph.links[g];if(f.target_id==b.id){c.links.splice(d,1);var m=
b.inputs[f.target_slot];m.link=null;delete this.graph.links[g];this.graph&&this.graph._version++;if(b.onConnectionsChange)b.onConnectionsChange(h.INPUT,f.target_slot,!1,f,m);if(this.onConnectionsChange)this.onConnectionsChange(h.OUTPUT,a,!1,f,c);if(this.graph&&this.graph.onNodeConnectionChange)this.graph.onNodeConnectionChange(h.OUTPUT,this,a);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(h.OUTPUT,this,a),this.graph.onNodeConnectionChange(h.INPUT,b,f.target_slot));
break}}}else{d=0;for(e=c.links.length;d<e;d++)if(g=c.links[d],f=this.graph.links[g]){b=this.graph.getNodeById(f.target_id);this.graph&&this.graph._version++;if(b){m=b.inputs[f.target_slot];m.link=null;if(b.onConnectionsChange)b.onConnectionsChange(h.INPUT,f.target_slot,!1,f,m);if(this.graph&&this.graph.onNodeConnectionChange)this.graph.onNodeConnectionChange(h.INPUT,b,f.target_slot)}delete this.graph.links[g];if(this.onConnectionsChange)this.onConnectionsChange(h.OUTPUT,a,!1,f,c);this.graph&&this.graph.onNodeConnectionChange&&
(this.graph.onNodeConnectionChange(h.OUTPUT,this,a),this.graph.onNodeConnectionChange(h.INPUT,b,f.target_slot))}c.links=null}this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this);return!0};l.prototype.disconnectInput=function(a){if(a.constructor===String){if(a=this.findInputSlot(a),-1==a)return h.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.inputs||a>=this.inputs.length)return h.debug&&console.log("Connect: Error, slot number not found"),!1;var b=this.inputs[a];
if(!b)return!1;var c=this.inputs[a].link;if(null!=c){this.inputs[a].link=null;var d=this.graph.links[c];if(d){var e=this.graph.getNodeById(d.origin_id);if(!e)return!1;var g=e.outputs[d.origin_slot];if(!g||!g.links||0==g.links.length)return!1;for(var f=0,m=g.links.length;f<m;f++)if(g.links[f]==c){g.links.splice(f,1);break}delete this.graph.links[c];this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(h.INPUT,a,!1,d,b);if(e.onConnectionsChange)e.onConnectionsChange(h.OUTPUT,
f,!1,d,g);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(h.OUTPUT,e,f),this.graph.onNodeConnectionChange(h.INPUT,this,a))}}this.setDirtyCanvas(!1,!0);this.graph&&this.graph.connectionChange(this);return!0};l.prototype.getConnectionPos=function(a,b,c){c=c||new Float32Array(2);var d=0;a&&this.inputs&&(d=this.inputs.length);!a&&this.outputs&&(d=this.outputs.length);var e=0.5*h.NODE_SLOT_HEIGHT;if(this.flags.collapsed)return b=this._collapsed_width||h.NODE_COLLAPSED_WIDTH,
this.horizontal?(c[0]=this.pos[0]+0.5*b,c[1]=a?this.pos[1]-h.NODE_TITLE_HEIGHT:this.pos[1]):(c[0]=a?this.pos[0]:this.pos[0]+b,c[1]=this.pos[1]-0.5*h.NODE_TITLE_HEIGHT),c;if(a&&-1==b)return c[0]=this.pos[0]+0.5*h.NODE_TITLE_HEIGHT,c[1]=this.pos[1]+0.5*h.NODE_TITLE_HEIGHT,c;if(a&&d>b&&this.inputs[b].pos)return c[0]=this.pos[0]+this.inputs[b].pos[0],c[1]=this.pos[1]+this.inputs[b].pos[1],c;if(!a&&d>b&&this.outputs[b].pos)return c[0]=this.pos[0]+this.outputs[b].pos[0],c[1]=this.pos[1]+this.outputs[b].pos[1],
c;if(this.horizontal)return c[0]=this.pos[0]+this.size[0]/d*(b+0.5),c[1]=a?this.pos[1]-h.NODE_TITLE_HEIGHT:this.pos[1]+this.size[1],c;c[0]=a?this.pos[0]+e:this.pos[0]+this.size[0]+1-e;c[1]=this.pos[1]+(b+0.7)*h.NODE_SLOT_HEIGHT+(this.constructor.slot_start_y||0);return c};l.prototype.alignToGrid=function(){this.pos[0]=h.CANVAS_GRID_SIZE*Math.round(this.pos[0]/h.CANVAS_GRID_SIZE);this.pos[1]=h.CANVAS_GRID_SIZE*Math.round(this.pos[1]/h.CANVAS_GRID_SIZE)};l.prototype.trace=function(a){this.console||
(this.console=[]);this.console.push(a);this.console.length>l.MAX_CONSOLE&&this.console.shift();if(this.graph.onNodeTrace)this.graph.onNodeTrace(this,a)};l.prototype.setDirtyCanvas=function(a,b){this.graph&&this.graph.sendActionToCanvas("setDirty",[a,b])};l.prototype.loadImage=function(a){var b=new Image;b.src=h.node_images_path+a;b.ready=!1;var c=this;b.onload=function(){this.ready=!0;c.setDirtyCanvas(!0)};return b};l.prototype.captureInput=function(a){if(this.graph&&this.graph.list_of_graphcanvas)for(var b=
this.graph.list_of_graphcanvas,c=0;c<b.length;++c){var d=b[c];if(a||d.node_capturing_input==this)d.node_capturing_input=a?this:null}};l.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)};l.prototype.pin=function(a){this.graph._version++;this.flags.pinned=void 0===a?!this.flags.pinned:a};l.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]]};B.LGraphGroup=h.LGraphGroup=r;r.prototype._ctor=function(a){this.title=a||"Group";this.font_size=24;this.color=k.node_colors.pale_blue?k.node_colors.pale_blue.groupcolor:"#AAA";this._bounding=new Float32Array([10,10,140,80]);this._pos=this._bounding.subarray(0,2);this._size=this._bounding.subarray(2,4);this._nodes=[];this.graph=null;Object.defineProperty(this,"pos",{set:function(a){!a||2>a.length||(this._pos[0]=a[0],this._pos[1]=a[1])},get:function(){return this._pos},enumerable:!0});
Object.defineProperty(this,"size",{set:function(a){!a||2>a.length||(this._size[0]=Math.max(140,a[0]),this._size[1]=Math.max(80,a[1]))},get:function(){return this._size},enumerable:!0})};r.prototype.configure=function(a){this.title=a.title;this._bounding.set(a.bounding);this.color=a.color;this.font=a.font};r.prototype.serialize=function(){var a=this._bounding;return{title:this.title,bounding:[Math.round(a[0]),Math.round(a[1]),Math.round(a[2]),Math.round(a[3])],color:this.color,font:this.font}};r.prototype.move=
function(a,b,c){this._pos[0]+=a;this._pos[1]+=b;if(!c)for(c=0;c<this._nodes.length;++c){var d=this._nodes[c];d.pos[0]+=a;d.pos[1]+=b}};r.prototype.recomputeInsideNodes=function(){this._nodes.length=0;for(var a=this.graph._nodes,b=new Float32Array(4),c=0;c<a.length;++c){var d=a[c];d.getBounding(b);A(this._bounding,b)&&this._nodes.push(d)}};r.prototype.isPointInside=l.prototype.isPointInside;r.prototype.setDirtyCanvas=l.prototype.setDirtyCanvas;h.DragAndScale=v;v.prototype.bindEvents=function(a){this.last_mouse=
new Float32Array(2);this._binded_mouse_callback=this.onMouse.bind(this);a.addEventListener("mousedown",this._binded_mouse_callback);a.addEventListener("mousemove",this._binded_mouse_callback);a.addEventListener("mousewheel",this._binded_mouse_callback,!1);a.addEventListener("wheel",this._binded_mouse_callback,!1)};v.prototype.computeVisibleArea=function(a){if(this.element){var b=this.element.width,c=this.element.height,d=-this.offset[0],e=-this.offset[1];a&&(d+=a[0]/this.scale,e+=a[1]/this.scale,
b=a[2],c=a[3]);a=d+b/this.scale;c=e+c/this.scale;this.visible_area[0]=d;this.visible_area[1]=e;this.visible_area[2]=a-d;this.visible_area[3]=c-e}else this.visible_area[0]=this.visible_area[1]=this.visible_area[2]=this.visible_area[3]=0};v.prototype.onMouse=function(a){if(this.enabled){var b=this.element,c=b.getBoundingClientRect(),d=a.clientX-c.left,c=a.clientY-c.top;a.canvasx=d;a.canvasy=c;a.dragging=this.dragging;var e=!this.viewport||this.viewport&&d>=this.viewport[0]&&d<this.viewport[0]+this.viewport[2]&&
c>=this.viewport[1]&&c<this.viewport[1]+this.viewport[3],g=!1;this.onmouse&&(g=this.onmouse(a));"mousedown"==a.type&&e?(this.dragging=!0,b.removeEventListener("mousemove",this._binded_mouse_callback),document.body.addEventListener("mousemove",this._binded_mouse_callback),document.body.addEventListener("mouseup",this._binded_mouse_callback)):"mousemove"==a.type?g||(b=d-this.last_mouse[0],g=c-this.last_mouse[1],this.dragging&&this.mouseDrag(b,g)):"mouseup"==a.type?(this.dragging=!1,document.body.removeEventListener("mousemove",
this._binded_mouse_callback),document.body.removeEventListener("mouseup",this._binded_mouse_callback),b.addEventListener("mousemove",this._binded_mouse_callback)):!e||"mousewheel"!=a.type&&"wheel"!=a.type&&"DOMMouseScroll"!=a.type||(a.eventType="mousewheel",a.wheel="wheel"==a.type?-a.deltaY:null!=a.wheelDeltaY?a.wheelDeltaY:-60*a.detail,a.delta=a.wheelDelta?a.wheelDelta/40:a.deltaY?-a.deltaY/3:0,this.changeDeltaScale(1+0.05*a.delta));this.last_mouse[0]=d;this.last_mouse[1]=c;if(e)return a.preventDefault(),
a.stopPropagation(),!1}};v.prototype.toCanvasContext=function(a){a.scale(this.scale,this.scale);a.translate(this.offset[0],this.offset[1])};v.prototype.convertOffsetToCanvas=function(a){return[(a[0]+this.offset[0])*this.scale,(a[1]+this.offset[1])*this.scale]};v.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};v.prototype.mouseDrag=function(a,b){this.offset[0]+=a/this.scale;this.offset[1]+=b/this.scale;if(this.onredraw)this.onredraw(this)};
v.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||[0.5*c.width,0.5*c.height];c=this.convertCanvasToOffset(b);this.scale=a;0.01>Math.abs(this.scale-1)&&(this.scale=1);var d=this.convertCanvasToOffset(b),c=[d[0]-c[0],d[1]-c[1]];this.offset[0]+=c[0];this.offset[1]+=c[1];if(this.onredraw)this.onredraw(this)}}};v.prototype.changeDeltaScale=function(a,b){this.changeScale(this.scale*
a,b)};v.prototype.reset=function(){this.scale=1;this.offset[0]=0;this.offset[1]=0};B.LGraphCanvas=h.LGraphCanvas=k;k.DEFAULT_BACKGROUND_IMAGE="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQBJREFUeNrs1rEKwjAUhlETUkj3vP9rdmr1Ysammk2w5wdxuLgcMHyptfawuZX4pJSWZTnfnu/lnIe/jNNxHHGNn//HNbbv+4dr6V+11uF527arU7+u63qfa/bnmh8sWLBgwYJlqRf8MEptXPBXJXa37BSl3ixYsGDBMliwFLyCV/DeLIMFCxYsWLBMwSt4Be/NggXLYMGCBUvBK3iNruC9WbBgwYJlsGApeAWv4L1ZBgsWLFiwYJmCV/AK3psFC5bBggULloJX8BpdwXuzYMGCBctgwVLwCl7Be7MMFixYsGDBsu8FH1FaSmExVfAxBa/gvVmwYMGCZbBg/W4vAQYA5tRF9QYlv/QAAAAASUVORK5CYII=";
k.link_type_colors={"-1":h.EVENT_LINK_COLOR,number:"#AAA",node:"#DCA"};k.gradients={};k.prototype.clear=function(){this.fps=this.render_time=this.last_draw_time=this.frame=0;this.dragging_rectangle=null;this.selected_nodes={};this.selected_group=null;this.visible_nodes=[];this.connecting_node=this.node_capturing_input=this.node_over=this.node_dragged=null;this.highlighted_links={};this.dragging_canvas=!1;this.dirty_bgcanvas=this.dirty_canvas=!0;this.node_widget=this.node_in_panel=this.dirty_area=
null;this.last_mouse=[0,0];this.last_mouseclick=0;this.visible_area.set([0,0,0,0]);if(this.onClear)this.onClear()};k.prototype.setGraph=function(a,b){this.graph!=a&&(b||this.clear(),!a&&this.graph?this.graph.detachCanvas(this):(a.attachCanvas(this),this._graph_stack&&(this._graph_stack=null),this.setDirty(!0,!0)))};k.prototype.getTopGraph=function(){return this._graph_stack.length?this._graph_stack[0]:this.graph};k.prototype.openSubgraph=function(a){if(!a)throw"graph cannot be null";if(this.graph==
a)throw"graph cannot be the same";this.clear();this.graph&&(this._graph_stack||(this._graph_stack=[]),this._graph_stack.push(this.graph));a.attachCanvas(this);this.checkPanels();this.setDirty(!0,!0)};k.prototype.closeSubgraph=function(){if(this._graph_stack&&0!=this._graph_stack.length){var a=this.graph._subgraph_node,b=this._graph_stack.pop();this.selected_nodes={};this.highlighted_links={};b.attachCanvas(this);this.setDirty(!0,!0);a&&(this.centerOnNode(a),this.selectNodes([a]))}};k.prototype.getCurrentGraph=
function(){return this.graph};k.prototype.setCanvas=function(a,b){if(a&&a.constructor===String&&(a=document.getElementById(a),!a))throw"Error creating LiteGraph canvas: Canvas not found";if(a!==this.canvas&&(!a&&this.canvas&&(b||this.unbindEvents()),this.canvas=a,this.ds.element=a)){a.className+=" lgraphcanvas";a.data=this;a.tabindex="1";this.bgcanvas=null;this.bgcanvas||(this.bgcanvas=document.createElement("canvas"),this.bgcanvas.width=this.canvas.width,this.bgcanvas.height=this.canvas.height);
if(null==a.getContext){if("canvas"!=a.localName)throw"Element supplied for LGraphCanvas must be a <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());this._mousemove_callback=this.processMouseMove.bind(this);this._mouseup_callback=this.processMouseUp.bind(this);b||this.bindEvents()}};k.prototype._doNothing=function(a){a.preventDefault();
return!1};k.prototype._doReturnTrue=function(a){a.preventDefault();return!0};k.prototype.bindEvents=function(){if(this._events_binded)console.warn("LGraphCanvas: events already binded");else{var a=this.canvas,b=this.getCanvasWindow().document;this._mousedown_callback=this.processMouseDown.bind(this);this._mousewheel_callback=this.processMouseWheel.bind(this);a.addEventListener("mousedown",this._mousedown_callback,!0);a.addEventListener("mousemove",this._mousemove_callback);a.addEventListener("mousewheel",
this._mousewheel_callback,!1);a.addEventListener("contextmenu",this._doNothing);a.addEventListener("DOMMouseScroll",this._mousewheel_callback,!1);a.addEventListener("touchstart",this.touchHandler,!0);a.addEventListener("touchmove",this.touchHandler,!0);a.addEventListener("touchend",this.touchHandler,!0);a.addEventListener("touchcancel",this.touchHandler,!0);this._key_callback=this.processKey.bind(this);a.addEventListener("keydown",this._key_callback,!0);b.addEventListener("keyup",this._key_callback,
!0);this._ondrop_callback=this.processDrop.bind(this);a.addEventListener("dragover",this._doNothing,!1);a.addEventListener("dragend",this._doNothing,!1);a.addEventListener("drop",this._ondrop_callback,!1);a.addEventListener("dragenter",this._doReturnTrue,!1);this._events_binded=!0}};k.prototype.unbindEvents=function(){if(this._events_binded){var a=this.getCanvasWindow().document;this.canvas.removeEventListener("mousedown",this._mousedown_callback);this.canvas.removeEventListener("mousewheel",this._mousewheel_callback);
this.canvas.removeEventListener("DOMMouseScroll",this._mousewheel_callback);this.canvas.removeEventListener("keydown",this._key_callback);a.removeEventListener("keyup",this._key_callback);this.canvas.removeEventListener("contextmenu",this._doNothing);this.canvas.removeEventListener("drop",this._ondrop_callback);this.canvas.removeEventListener("dragenter",this._doReturnTrue);this.canvas.removeEventListener("touchstart",this.touchHandler);this.canvas.removeEventListener("touchmove",this.touchHandler);
this.canvas.removeEventListener("touchend",this.touchHandler);this.canvas.removeEventListener("touchcancel",this.touchHandler);this._ondrop_callback=this._key_callback=this._mousewheel_callback=this._mousedown_callback=null;this._events_binded=!1}else console.warn("LGraphCanvas: no events binded")};k.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()};k.prototype.enableWebGL=function(){if(void 0===typeof GL)throw"litegl.js must be included to use a WebGL canvas";
if(void 0===typeof enableWebGLCanvas)throw"webglCanvas.js must be included to use this feature";this.gl=this.ctx=enableWebGLCanvas(this.canvas);this.ctx.webgl=!0;this.bgcanvas=this.canvas;this.bgctx=this.gl;this.canvas.webgl_enabled=!0};k.prototype.setDirty=function(a,b){a&&(this.dirty_canvas=!0);b&&(this.dirty_bgcanvas=!0)};k.prototype.getCanvasWindow=function(){if(!this.canvas)return window;var a=this.canvas.ownerDocument;return a.defaultView||a.parentWindow};k.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))};k.prototype.stopRendering=function(){this.is_rendering=!1};k.prototype.blockClick=function(){this.block_click=!0;this.last_mouseclick=0};k.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();k.active_canvas=this;var c=this,d=a.localX,
e=a.localY;this.ds.viewport=this.viewport;d=!this.viewport||this.viewport&&d>=this.viewport[0]&&d<this.viewport[0]+this.viewport[2]&&e>=this.viewport[1]&&e<this.viewport[1]+this.viewport[3];this.options.skip_events||(this.canvas.removeEventListener("mousemove",this._mousemove_callback),b.document.addEventListener("mousemove",this._mousemove_callback,!0),b.document.addEventListener("mouseup",this._mouseup_callback,!0));if(d){var g=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes,5),e=
!1,d=300>h.getTime()-this.last_mouseclick;this.mouse[0]=a.localX;this.mouse[1]=a.localY;this.graph_mouse[0]=a.canvasX;this.graph_mouse[1]=a.canvasY;this.last_click_position=[this.mouse[0],this.mouse[1]];this.canvas.focus();h.closeAllContextMenus(b);if(!this.onMouse||!0!=this.onMouse(a)){if(1==a.which){a.ctrlKey&&(this.dragging_rectangle=new Float32Array(4),this.dragging_rectangle[0]=a.canvasX,this.dragging_rectangle[1]=a.canvasY,this.dragging_rectangle[2]=1,this.dragging_rectangle[3]=1,e=!0);var f=
!1;if(g&&this.allow_interaction&&!e&&!this.read_only){this.live_mode||g.flags.pinned||this.bringToFront(g);if(!this.connecting_node&&!g.flags.collapsed&&!this.live_mode)if(!e&&!1!==g.resizable&&y(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)for(var m=0,q=g.outputs.length;m<q;++m){var D=g.outputs[m],s=g.getConnectionPos(!1,m);if(y(a.canvasX,a.canvasY,s[0]-15,s[1]-10,30,
20)){this.connecting_node=g;this.connecting_output=D;this.connecting_pos=g.getConnectionPos(!1,m);this.connecting_slot=m;a.shiftKey&&g.disconnectOutput(m);if(d){if(g.onOutputDblClick)g.onOutputDblClick(m,a)}else if(g.onOutputClick)g.onOutputClick(m,a);e=!0;break}}if(g.inputs)for(m=0,q=g.inputs.length;m<q;++m)if(D=g.inputs[m],s=g.getConnectionPos(!0,m),y(a.canvasX,a.canvasY,s[0]-15,s[1]-10,30,20)){if(d){if(g.onInputDblClick)g.onInputDblClick(m,a)}else if(g.onInputClick)g.onInputClick(m,a);if(null!==
D.link){e=this.graph.links[D.link];g.disconnectInput(m);if(this.allow_reconnect_links||a.shiftKey)this.connecting_node=this.graph._nodes_by_id[e.origin_id],this.connecting_slot=e.origin_slot,this.connecting_output=this.connecting_node.outputs[this.connecting_slot],this.connecting_pos=this.connecting_node.getConnectionPos(!1,this.connecting_slot);e=this.dirty_bgcanvas=!0}}}if(!e){m=!1;q=[a.canvasX-g.pos[0],a.canvasY-g.pos[1]];if(s=this.processNodeWidgets(g,this.graph_mouse,a))m=!0,this.node_widget=
[g,s];if(d&&this.selected_nodes[g.id]){if(g.onDblClick)g.onDblClick(a,q,this);this.processNodeDblClicked(g);m=!0}g.onMouseDown&&g.onMouseDown(a,q,this)?m=!0:(g.subgraph&&!g.skip_subgraph_button&&!g.flags.collapsed&&q[0]>g.size[0]-h.NODE_TITLE_HEIGHT&&0>q[1]&&(c=this,setTimeout(function(){c.openSubgraph(g.subgraph)},10)),this.live_mode&&(m=f=!0));m||(this.allow_dragnodes&&(this.graph.beforeChange(),this.node_dragged=g),this.selected_nodes[g.id]||this.processNodeSelected(g,a));this.dirty_canvas=!0}}else{if(!this.read_only)for(m=
0;m<this.visible_links.length;++m)if(f=this.visible_links[m],(q=f._pos)&&!(a.canvasX<q[0]-4||a.canvasX>q[0]+4||a.canvasY<q[1]-4||a.canvasY>q[1]+4)){this.showLinkMenu(f,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);f=!0}!e&&f&&this.allow_dragcanvas&&(this.dragging_canvas=!0)}else 2!=a.which&&3==a.which&&(this.read_only||this.processContextMenu(g,a));this.last_mouse[0]=a.localX;this.last_mouse[1]=a.localY;this.last_mouseclick=h.getTime();this.last_mouse_dragging=!0;this.graph.change();(!b.document.activeElement||"input"!=b.document.activeElement.nodeName.toLowerCase()&&
"textarea"!=b.document.activeElement.nodeName.toLowerCase())&&a.preventDefault();a.stopPropagation();if(this.onMouseDown)this.onMouseDown(a);return!1}}}};k.prototype.processMouseMove=function(a){this.autoresize&&this.resize();this.set_canvas_dirty_on_mouse_event&&(this.dirty_canvas=!0);if(this.graph){k.active_canvas=this;this.adjustMouseEvent(a);var b=[a.localX,a.localY];this.mouse[0]=b[0];this.mouse[1]=b[1];var c=[b[0]-this.last_mouse[0],b[1]-this.last_mouse[1]];this.last_mouse=b;this.graph_mouse[0]=
a.canvasX;this.graph_mouse[1]=a.canvasY;if(this.block_click)return a.preventDefault(),!1;a.dragging=this.last_mouse_dragging;this.node_widget&&(this.processNodeWidgets(this.node_widget[0],this.graph_mouse,a,this.node_widget[1]),this.dirty_canvas=!0);if(this.dragging_rectangle)this.dragging_rectangle[2]=a.canvasX-this.dragging_rectangle[0],this.dragging_rectangle[3]=a.canvasY-this.dragging_rectangle[1],this.dirty_canvas=!0;else if(this.selected_group&&!this.read_only)this.selected_group_resizing?this.selected_group.size=
[a.canvasX-this.selected_group.pos[0],a.canvasY-this.selected_group.pos[1]]:(this.selected_group.move(c[0]/this.ds.scale,c[1]/this.ds.scale,a.ctrlKey),this.selected_group._nodes.length&&(this.dirty_canvas=!0)),this.dirty_bgcanvas=!0;else if(this.dragging_canvas)this.ds.offset[0]+=c[0]/this.ds.scale,this.ds.offset[1]+=c[1]/this.ds.scale,this.dirty_bgcanvas=this.dirty_canvas=!0;else if(this.allow_interaction&&!this.read_only){this.connecting_node&&(this.dirty_canvas=!0);for(var d=this.graph.getNodeOnPos(a.canvasX,
a.canvasY,this.visible_nodes),b=0,e=this.graph._nodes.length;b<e;++b)if(this.graph._nodes[b].mouseOver&&d!=this.graph._nodes[b]){this.graph._nodes[b].mouseOver=!1;if(this.node_over&&this.node_over.onMouseLeave)this.node_over.onMouseLeave(a);this.node_over=null;this.dirty_canvas=!0}if(d){d.redraw_on_mouse&&(this.dirty_canvas=!0);if(!d.mouseOver&&(d.mouseOver=!0,this.node_over=d,this.dirty_canvas=!0,d.onMouseEnter))d.onMouseEnter(a);if(d.onMouseMove)d.onMouseMove(a,[a.canvasX-d.pos[0],a.canvasY-d.pos[1]],
this);if(this.connecting_node&&(e=this._highlight_input||[0,0],!this.isOverNodeBox(d,a.canvasX,a.canvasY))){var g=this.isOverNodeInput(d,a.canvasX,a.canvasY,e);-1!=g&&d.inputs[g]?h.isValidConnection(this.connecting_output.type,d.inputs[g].type)&&(this._highlight_input=e):this._highlight_input=null}this.canvas&&(y(a.canvasX,a.canvasY,d.pos[0]+d.size[0]-5,d.pos[1]+d.size[1]-5,5,5)?this.canvas.style.cursor="se-resize":this.canvas.style.cursor="crosshair")}else{e=null;for(b=0;b<this.visible_links.length;++b){var g=
this.visible_links[b],f=g._pos;if(f&&!(a.canvasX<f[0]-4||a.canvasX>f[0]+4||a.canvasY<f[1]-4||a.canvasY>f[1]+4)){e=g;break}}e!=this.over_link_center&&(this.over_link_center=e,this.dirty_canvas=!0);this.canvas&&(this.canvas.style.cursor="")}if(this.node_capturing_input&&this.node_capturing_input!=d&&this.node_capturing_input.onMouseMove)this.node_capturing_input.onMouseMove(a,[a.canvasX-this.node_capturing_input.pos[0],a.canvasY-this.node_capturing_input.pos[1]],this);if(this.node_dragged&&!this.live_mode){for(b in this.selected_nodes)d=
this.selected_nodes[b],d.pos[0]+=c[0]/this.ds.scale,d.pos[1]+=c[1]/this.ds.scale;this.dirty_bgcanvas=this.dirty_canvas=!0}this.resizing_node&&!this.live_mode&&(c=[a.canvasX-this.resizing_node.pos[0],a.canvasY-this.resizing_node.pos[1]],b=this.resizing_node.computeSize(),c[0]=Math.max(b[0],c[0]),c[1]=Math.max(b[1],c[1]),this.resizing_node.setSize(c),this.canvas.style.cursor="se-resize",this.dirty_bgcanvas=this.dirty_canvas=!0)}a.preventDefault();return!1}};k.prototype.processMouseUp=function(a){this.set_canvas_dirty_on_mouse_event&&
(this.dirty_canvas=!0);if(this.graph){var b=this.getCanvasWindow().document;k.active_canvas=this;this.options.skip_events||(b.removeEventListener("mousemove",this._mousemove_callback,!0),this.canvas.addEventListener("mousemove",this._mousemove_callback,!0),b.removeEventListener("mouseup",this._mouseup_callback,!0));this.adjustMouseEvent(a);b=h.getTime();a.click_time=b-this.last_mouseclick;this.last_mouse_dragging=!1;this.last_click_position=null;this.block_click&&(console.log("foo"),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;if(this.selected_group){var b=this.selected_group.pos[0]-Math.round(this.selected_group.pos[0]),c=this.selected_group.pos[1]-Math.round(this.selected_group.pos[1]);this.selected_group.move(b,c,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;if(this.dragging_rectangle){if(this.graph){b=this.graph._nodes;c=new Float32Array(4);this.deselectAllNodes();var d=Math.abs(this.dragging_rectangle[2]),e=Math.abs(this.dragging_rectangle[3]),g=0>this.dragging_rectangle[3]?this.dragging_rectangle[1]-e:this.dragging_rectangle[1];this.dragging_rectangle[0]=0>this.dragging_rectangle[2]?this.dragging_rectangle[0]-d:this.dragging_rectangle[0];this.dragging_rectangle[1]=g;this.dragging_rectangle[2]=
d;this.dragging_rectangle[3]=e;e=[];for(g=0;g<b.length;++g)d=b[g],d.getBounding(c),A(this.dragging_rectangle,c)&&e.push(d);e.length&&this.selectNodes(e)}this.dragging_rectangle=null}else if(this.connecting_node){this.dirty_bgcanvas=this.dirty_canvas=!0;if(d=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes))this.connecting_output.type==h.EVENT&&this.isOverNodeBox(d,a.canvasX,a.canvasY)?this.connecting_node.connect(this.connecting_slot,d,h.EVENT):(b=this.isOverNodeInput(d,a.canvasX,a.canvasY),
-1!=b?this.connecting_node.connect(this.connecting_slot,d,b):(b=d.getInputInfo(0),this.connecting_output.type==h.EVENT?this.connecting_node.connect(this.connecting_slot,d,h.EVENT):b&&!b.link&&h.isValidConnection(b.type&&this.connecting_output.type)&&this.connecting_node.connect(this.connecting_slot,d,0)));this.connecting_node=this.connecting_pos=this.connecting_output=null;this.connecting_slot=-1}else if(this.resizing_node)this.dirty_bgcanvas=this.dirty_canvas=!0,this.graph.afterChange(this.resizing_node),
this.resizing_node=null;else if(this.node_dragged){(d=this.node_dragged)&&300>a.click_time&&y(a.canvasX,a.canvasY,d.pos[0],d.pos[1]-h.NODE_TITLE_HEIGHT,h.NODE_TITLE_HEIGHT,h.NODE_TITLE_HEIGHT)&&d.collapse();this.dirty_bgcanvas=this.dirty_canvas=!0;this.node_dragged.pos[0]=Math.round(this.node_dragged.pos[0]);this.node_dragged.pos[1]=Math.round(this.node_dragged.pos[1]);(this.graph.config.align_to_grid||this.align_to_grid)&&this.node_dragged.alignToGrid();if(this.onNodeMoved)this.onNodeMoved(this.node_dragged);
this.graph.afterChange(this.node_dragged);this.node_dragged=null}else{d=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes);!d&&300>a.click_time&&this.deselectAllNodes();this.dirty_canvas=!0;this.dragging_canvas=!1;if(this.node_over&&this.node_over.onMouseUp)this.node_over.onMouseUp(a,[a.canvasX-this.node_over.pos[0],a.canvasY-this.node_over.pos[1]],this);if(this.node_capturing_input&&this.node_capturing_input.onMouseUp)this.node_capturing_input.onMouseUp(a,[a.canvasX-this.node_capturing_input.pos[0],
a.canvasY-this.node_capturing_input.pos[1]])}}else 2==a.which?(this.dirty_canvas=!0,this.dragging_canvas=!1):3==a.which&&(this.dirty_canvas=!0,this.dragging_canvas=!1);this.graph.change();a.stopPropagation();a.preventDefault();return!1}};k.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.localX,d=a.localY;if(!this.viewport||this.viewport&&c>=this.viewport[0]&&c<this.viewport[0]+this.viewport[2]&&
d>=this.viewport[1]&&d<this.viewport[1]+this.viewport[3])return c=this.ds.scale,0<b?c*=1.1:0>b&&(c*=1/1.1),this.ds.changeScale(c,[a.localX,a.localY]),this.graph.change(),a.preventDefault(),!1}};k.prototype.isOverNodeBox=function(a,b,c){var d=h.NODE_TITLE_HEIGHT;return y(b,c,a.pos[0]+2,a.pos[1]+2-d,d-4,d-4)?!0:!1};k.prototype.isOverNodeInput=function(a,b,c,d){if(a.inputs)for(var e=0,g=a.inputs.length;e<g;++e){var f=a.getConnectionPos(!0,e),m=!1;if(m=a.horizontal?y(b,c,f[0]-5,f[1]-10,10,20):y(b,c,f[0]-
10,f[1]-5,40,10))return d&&(d[0]=f[0],d[1]=f[1]),e}return-1};k.prototype.processKey=function(a){if(this.graph){var b=!1;if("input"!=a.target.localName){if("keydown"==a.type){if(32==a.keyCode&&(b=this.dragging_canvas=!0),65==a.keyCode&&a.ctrlKey&&(this.selectNodes(),b=!0),"KeyC"==a.code&&(a.metaKey||a.ctrlKey)&&!a.shiftKey&&this.selected_nodes&&(this.copyToClipboard(),b=!0),"KeyV"!=a.code||!a.metaKey&&!a.ctrlKey||a.shiftKey||this.pasteFromClipboard(),46!=a.keyCode&&8!=a.keyCode||"input"==a.target.localName||
"textarea"==a.target.localName||(this.deleteSelectedNodes(),b=!0),this.selected_nodes)for(var c in this.selected_nodes)if(this.selected_nodes[c].onKeyDown)this.selected_nodes[c].onKeyDown(a)}else if("keyup"==a.type&&(32==a.keyCode&&(this.dragging_canvas=!1),this.selected_nodes))for(c in this.selected_nodes)if(this.selected_nodes[c].onKeyUp)this.selected_nodes[c].onKeyUp(a);this.graph.change();if(b)return a.preventDefault(),a.stopImmediatePropagation(),!1}}};k.prototype.copyToClipboard=function(){var a=
{nodes:[],links:[]},b=0,c=[],d;for(d in this.selected_nodes){var e=this.selected_nodes[d];e._relative_id=b;c.push(e);b+=1}for(d=0;d<c.length;++d)if(e=c[d],b=e.clone()){if(a.nodes.push(b.serialize()),e.inputs&&e.inputs.length)for(b=0;b<e.inputs.length;++b){var g=e.inputs[b];if(g&&null!=g.link&&(g=this.graph.links[g.link])){var f=this.graph.getNodeById(g.origin_id);f&&this.selected_nodes[f.id]&&a.links.push([f._relative_id,g.origin_slot,e._relative_id,g.target_slot])}}}else console.warn("node type not found: "+
e.type);localStorage.setItem("litegrapheditor_clipboard",JSON.stringify(a))};k.prototype.pasteFromClipboard=function(){var a=localStorage.getItem("litegrapheditor_clipboard");if(a){this.graph.beforeChange();for(var a=JSON.parse(a),b=[],c=0;c<a.nodes.length;++c){var d=a.nodes[c],e=h.createNode(d.type);e&&(e.configure(d),e.pos[0]+=5,e.pos[1]+=5,this.graph.add(e),b.push(e))}for(c=0;c<a.links.length;++c){var d=a.links[c],e=b[d[0]],g=b[d[2]];e&&g?e.connect(d[1],g,d[3]):console.warn("Warning, nodes missing on pasting")}this.selectNodes(b);
this.graph.afterChange()}};k.prototype.processDrop=function(a){a.preventDefault();this.adjustMouseEvent(a);var b=a.localX,c=a.localY;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]){var b=[a.canvasX,a.canvasY],d=this.graph?this.graph.getNodeOnPos(b[0],b[1]):null;if(d){if((d.onDropFile||d.onDropData)&&(b=a.dataTransfer.files)&&b.length)for(c=0;c<b.length;c++){var e=a.dataTransfer.files[0],g=e.name;
k.getFileExtension(g);if(d.onDropFile)d.onDropFile(e);if(d.onDropData){var f=new FileReader;f.onload=function(a){d.onDropData(a.target.result,g,e)};var m=e.type.split("/")[0];"text"==m||""==m?f.readAsText(e):"image"==m?f.readAsDataURL(e):f.readAsArrayBuffer(e)}}return d.onDropItem&&d.onDropItem(event)?!0:this.onDropItem?this.onDropItem(event):!1}b=null;this.onDropItem&&(b=this.onDropItem(event));b||this.checkDropItem(a)}};k.prototype.checkDropItem=function(a){if(a.dataTransfer.files.length){var b=
a.dataTransfer.files[0],c=k.getFileExtension(b.name).toLowerCase();if(c=h.node_types_by_file_extension[c]){this.graph.beforeChange();c=h.createNode(c.type);c.pos=[a.canvasX,a.canvasY];this.graph.add(c);if(c.onDropFile)c.onDropFile(b);this.graph.afterChange()}}};k.prototype.processNodeDblClicked=function(a){if(this.onShowNodePanel)this.onShowNodePanel(a);else this.showShowNodePanel(a);if(this.onNodeDblClicked)this.onNodeDblClicked(a);this.setDirty(!0)};k.prototype.processNodeSelected=function(a,b){this.selectNode(a,
b&&b.shiftKey);if(this.onNodeSelected)this.onNodeSelected(a)};k.prototype.selectNode=function(a,b){null==a?this.deselectAllNodes():this.selectNodes([a],b)};k.prototype.selectNodes=function(a,b){b||this.deselectAllNodes();a=a||this.graph._nodes;for(var c=0;c<a.length;++c){var d=a[c];if(!d.is_selected){if(!d.is_selected&&d.onSelected)d.onSelected();d.is_selected=!0;this.selected_nodes[d.id]=d;if(d.inputs)for(var e=0;e<d.inputs.length;++e)this.highlighted_links[d.inputs[e].link]=!0;if(d.outputs)for(e=
0;e<d.outputs.length;++e){var g=d.outputs[e];if(g.links)for(var f=0;f<g.links.length;++f)this.highlighted_links[g.links[f]]=!0}}}if(this.onSelectionChange)this.onSelectionChange(this.selected_nodes);this.setDirty(!0)};k.prototype.deselectNode=function(a){if(a.is_selected){if(a.onDeselected)a.onDeselected();a.is_selected=!1;if(this.onNodeDeselected)this.onNodeDeselected(a);if(a.inputs)for(var b=0;b<a.inputs.length;++b)delete this.highlighted_links[a.inputs[b].link];if(a.outputs)for(b=0;b<a.outputs.length;++b){var c=
a.outputs[b];if(c.links)for(var d=0;d<c.links.length;++d)delete this.highlighted_links[c.links[d]]}}};k.prototype.deselectAllNodes=function(){if(this.graph){for(var a=this.graph._nodes,b=0,c=a.length;b<c;++b){var d=a[b];if(d.is_selected){if(d.onDeselected)d.onDeselected();d.is_selected=!1;if(this.onNodeDeselected)this.onNodeDeselected(d)}}this.selected_nodes={};this.current_node=null;this.highlighted_links={};if(this.onSelectionChange)this.onSelectionChange(this.selected_nodes);this.setDirty(!0)}};
k.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&&h.isValidConnection(b.inputs[0].type,b.outputs[0].type)&&b.inputs[0].link&&b.outputs[0].links&&b.outputs[0].links.length){var c=b.graph.links[b.inputs[0].link],d=b.graph.links[b.outputs[0].links[0]],e=b.getInputNode(0),g=b.getOutputNodes(0)[0];e&&g&&e.connect(c.origin_slot,g,d.target_slot)}this.graph.remove(b);
if(this.onNodeDeselected)this.onNodeDeselected(b)}}this.selected_nodes={};this.current_node=null;this.highlighted_links={};this.setDirty(!0);this.graph.afterChange()};k.prototype.centerOnNode=function(a){this.ds.offset[0]=-a.pos[0]-0.5*a.size[0]+0.5*this.canvas.width/this.ds.scale;this.ds.offset[1]=-a.pos[1]-0.5*a.size[1]+0.5*this.canvas.height/this.ds.scale;this.setDirty(!0,!0)};k.prototype.adjustMouseEvent=function(a){if(this.canvas){var b=this.canvas.getBoundingClientRect();a.localX=a.clientX-
b.left;a.localY=a.clientY-b.top}else a.localX=a.clientX,a.localY=a.clientY;a.deltaX=a.localX-this.last_mouse_position[0];a.deltaY=a.localY-this.last_mouse_position[1];this.last_mouse_position[0]=a.localX;this.last_mouse_position[1]=a.localY;a.canvasX=a.localX/this.ds.scale-this.ds.offset[0];a.canvasY=a.localY/this.ds.scale-this.ds.offset[1]};k.prototype.setZoom=function(a,b){this.ds.changeScale(a,b);this.dirty_bgcanvas=this.dirty_canvas=!0};k.prototype.convertOffsetToCanvas=function(a,b){return this.ds.convertOffsetToCanvas(a,
b)};k.prototype.convertCanvasToOffset=function(a,b){return this.ds.convertCanvasToOffset(a,b)};k.prototype.convertEventToCanvasOffset=function(a){var b=this.canvas.getBoundingClientRect();return this.convertCanvasToOffset([a.clientX-b.left,a.clientY-b.top])};k.prototype.bringToFront=function(a){var b=this.graph._nodes.indexOf(a);-1!=b&&(this.graph._nodes.splice(b,1),this.graph._nodes.push(a))};k.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);k.prototype.computeVisibleNodes=function(a,b){var c=b||[];c.length=0;a=a||this.graph._nodes;for(var d=0,e=a.length;d<e;++d){var g=a[d];(!this.live_mode||g.onDrawBackground||g.onDrawForeground)&&A(this.visible_area,g.getBounding(L))&&c.push(g)}return c};k.prototype.draw=function(a,b){if(this.canvas&&0!=this.canvas.width&&0!=this.canvas.height){var c=h.getTime();this.render_time=0.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}};k.prototype.drawFrontCanvas=function(){this.dirty_canvas=!1;this.ctx||(this.ctx=this.bgcanvas.getContext("2d"));var a=this.ctx;if(a){var b=this.canvas;a.start2D&&!this.viewport&&(a.start2D(),
a.restore(),a.setTransform(1,0,0,1,0,0));var c=this.viewport||this.dirty_area;c&&(a.save(),a.beginPath(),a.rect(c[0],c[1],c[2],c[3]),a.clip());this.clear_background&&(c?a.clearRect(c[0],c[1],c[2],c[3]):a.clearRect(0,0,b.width,b.height));this.bgcanvas==this.canvas?this.drawBackCanvas():a.drawImage(this.bgcanvas,0,0);if(this.onRender)this.onRender(b,a);this.show_info&&this.renderInfo(a,c?c[0]:0,c?c[1]:0);if(this.graph){a.save();this.ds.toCanvasContext(a);for(var b=this.computeVisibleNodes(null,this.visible_nodes),
d=0;d<b.length;++d){var e=b[d];a.save();a.translate(e.pos[0],e.pos[1]);this.drawNode(e,a);a.restore()}this.render_execution_order&&this.drawExecutionOrder(a);this.graph.config.links_ontop&&(this.live_mode||this.drawConnections(a));if(null!=this.connecting_pos){a.lineWidth=this.connections_width;b=null;switch(this.connecting_output.type){case h.EVENT:b=h.EVENT_LINK_COLOR;break;default:b=h.CONNECTING_LINK_COLOR}this.renderLink(a,this.connecting_pos,[this.graph_mouse[0],this.graph_mouse[1]],null,!1,
null,b,this.connecting_output.dir||(this.connecting_node.horizontal?h.DOWN:h.RIGHT),h.CENTER);a.beginPath();this.connecting_output.type===h.EVENT||this.connecting_output.shape===h.BOX_SHAPE?a.rect(this.connecting_pos[0]-6+0.5,this.connecting_pos[1]-5+0.5,14,10):a.arc(this.connecting_pos[0],this.connecting_pos[1],4,0,2*Math.PI);a.fill();a.fillStyle="#ffcc00";this._highlight_input&&(a.beginPath(),a.arc(this._highlight_input[0],this._highlight_input[1],6,0,2*Math.PI),a.fill())}this.dragging_rectangle&&
(a.strokeStyle="#FFF",a.strokeRect(this.dragging_rectangle[0],this.dragging_rectangle[1],this.dragging_rectangle[2],this.dragging_rectangle[3]));if(this.over_link_center&&this.render_link_tooltip)this.drawLinkTooltip(a,this.over_link_center);else if(this.onDrawLinkTooltip)this.onDrawLinkTooltip(a,null);if(this.onDrawForeground)this.onDrawForeground(a,this.visible_rect);a.restore()}this._graph_stack&&this._graph_stack.length&&this.drawSubgraphPanel(a);if(this.onDrawOverlay)this.onDrawOverlay(a);c&&
a.restore();a.finish2D&&a.finish2D()}};k.prototype.drawSubgraphPanel=function(a){var b=this.graph,c=b._subgraph_node;if(c){var d=c.inputs?c.inputs.length:0,e=Math.floor(1.6*h.NODE_SLOT_HEIGHT);a.fillStyle="#111";a.globalAlpha=0.8;a.beginPath();a.roundRect(10,10,300,(d+1)*e+50,8);a.fill();a.globalAlpha=1;a.fillStyle="#888";a.font="14px Arial";a.textAlign="left";a.fillText("Graph Inputs",20,34);if(this.drawButton(280,20,20,20,"X","#151515"))this.closeSubgraph();else{d=50;a.font="20px Arial";if(c.inputs)for(var g=
0;g<c.inputs.length;++g){var f=c.inputs[g];if(!f.not_subgraph_input){if(this.drawButton(20,d+2,280,e-2)){var m=c.constructor.input_node_type||"graph/input";this.graph.beforeChange();var q=h.createNode(m);q?(b.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",f.name),q.setProperty("type",f.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)}a.fillStyle="#9C9";a.beginPath();a.arc(284,d+0.5*e,5,0,2*Math.PI);a.fill();a.fillStyle="#AAA";a.fillText(f.name,50,d+0.75*e);m=a.measureText(f.name);a.fillStyle="#777";a.fillText(f.type,50+m.width+10,d+0.75*e);d+=e}}this.drawButton(20,d+2,280,e-2,"+","#151515","#222")&&this.showSubgraphPropertiesDialog(c)}}else console.warn("subgraph without subnode")};k.prototype.drawButton=function(a,b,c,d,e,g,f,m){var q=this.ctx;g=g||h.NODE_DEFAULT_COLOR;f=f||"#555";
m=m||h.NODE_TEXT_COLOR;var k=this.mouse,s=h.isInsideRectangle(k[0],k[1],a,b,c,d),k=(k=this.last_click_position)&&h.isInsideRectangle(k[0],k[1],a,b,c,d);q.fillStyle=s?f:g;k&&(q.fillStyle="#AAA");q.beginPath();q.roundRect(a,b,c,d,4);q.fill();null!=e&&e.constructor==String&&(q.fillStyle=m,q.textAlign="center",q.font=(0.65*d|0)+"px Arial",q.fillText(e,a+0.5*c,b+0.75*d),q.textAlign="left");a=k&&!this.block_click;k&&this.blockClick();return a};k.prototype.isAreaClicked=function(a,b,c,d,e){var g=this.mouse;
h.isInsideRectangle(g[0],g[1],a,b,c,d);b=(a=(g=this.last_click_position)&&h.isInsideRectangle(g[0],g[1],a,b,c,d))&&!this.block_click;a&&e&&this.blockClick();return b};k.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()};k.prototype.drawBackCanvas=function(){var a=this.bgcanvas;if(a.width!=this.canvas.width||a.height!=this.canvas.height)a.width=this.canvas.width,a.height=this.canvas.height;this.bgctx||(this.bgctx=this.bgcanvas.getContext("2d"));var b=this.bgctx;b.start&&b.start();var c=this.viewport||[0,0,b.canvas.width,b.canvas.height];this.clear_background&&b.clearRect(c[0],
c[1],c[2],c[3]);if(this._graph_stack&&this._graph_stack.length){b.save();c=this.graph._subgraph_node;b.strokeStyle=c.bgcolor;b.lineWidth=10;b.strokeRect(1,1,a.width-2,a.height-2);b.lineWidth=1;b.font="40px Arial";b.textAlign="center";b.fillStyle=c.bgcolor||"#AAA";for(var d="",e=1;e<this._graph_stack.length;++e)d+=this._graph_stack[e]._subgraph_node.getTitle()+" >> ";b.fillText(d+c.getTitle(),0.5*a.width,40);b.restore()}c=!1;this.onRenderBackground&&(c=this.onRenderBackground(a,b));this.viewport||
(b.restore(),b.setTransform(1,0,0,1,0,0));this.visible_links.length=0;if(this.graph){b.save();this.ds.toCanvasContext(b);if(this.background_image&&0.5<this.ds.scale&&!c){b.globalAlpha=this.zoom_modify_alpha?(1-0.5/this.ds.scale)*this.editor_alpha:this.editor_alpha;b.imageSmoothingEnabled=b.mozImageSmoothingEnabled=b.imageSmoothingEnabled=!1;if(!this._bg_img||this._bg_img.name!=this.background_image){this._bg_img=new Image;this._bg_img.name=this.background_image;this._bg_img.src=this.background_image;
var 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.mozImageSmoothingEnabled=b.imageSmoothingEnabled=!0}this.graph._groups.length&&!this.live_mode&&this.drawGroups(a,
b);if(this.onDrawBackground)this.onDrawBackground(b,this.visible_area);this.onBackgroundRender&&(console.error("WARNING! onBackgroundRender deprecated, now is named onDrawBackground "),this.onBackgroundRender=null);this.render_canvas_border&&(b.strokeStyle="#235",b.strokeRect(0,0,a.width,a.height));this.render_connections_shadows?(b.shadowColor="#000",b.shadowOffsetX=0,b.shadowOffsetY=0,b.shadowBlur=6):b.shadowColor="rgba(0,0,0,0)";this.live_mode||this.drawConnections(b);b.shadowColor="rgba(0,0,0,0)";
b.restore()}b.finish&&b.finish();this.dirty_bgcanvas=!1;this.dirty_canvas=!0};var G=new Float32Array(2);k.prototype.drawNode=function(a,b){this.current_node=a;var c=a.color||a.constructor.color||h.NODE_DEFAULT_COLOR,d=a.bgcolor||a.constructor.bgcolor||h.NODE_DEFAULT_BGCOLOR,e=0.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&&!e?(b.shadowColor=
h.DEFAULT_SHADOW_COLOR,b.shadowOffsetX=2*this.ds.scale,b.shadowOffsetY=2*this.ds.scale,b.shadowBlur=3*this.ds.scale):b.shadowColor="transparent";if(!a.flags.collapsed||!a.onDrawCollapsed||!0!=a.onDrawCollapsed(b,this)){var f=a._shape||h.BOX_SHAPE;G.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*h.NODE_TITLE_HEIGHT),G[0]=a._collapsed_width,G[1]=0)}a.clip_area&&
(b.save(),b.beginPath(),f==h.BOX_SHAPE?b.rect(0,0,G[0],G[1]):f==h.ROUND_SHAPE?b.roundRect(0,0,G[0],G[1],10):f==h.CIRCLE_SHAPE&&b.arc(0.5*G[0],0.5*G[1],0.5*G[0],0,2*Math.PI),b.clip());a.has_errors&&(d="red");this.drawNodeShape(a,b,G,c,d,a.is_selected,a.mouseOver);b.shadowColor="transparent";if(a.onDrawForeground)a.onDrawForeground(b,this,this.canvas);b.textAlign=m?"center":"left";b.font=this.inner_text_font;d=!e;f=this.connecting_output;b.lineWidth=1;var q=0,k=new Float32Array(2);if(!a.flags.collapsed){if(a.inputs)for(c=
0;c<a.inputs.length;c++){var s=a.inputs[c];b.globalAlpha=g;this.connecting_node&&!h.isValidConnection(s.type,f.type)&&(b.globalAlpha=0.4*g);b.fillStyle=null!=s.link?s.color_on||this.default_connection_color.input_on:s.color_off||this.default_connection_color.input_off;var p=a.getConnectionPos(!0,c,k);p[0]-=a.pos[0];p[1]-=a.pos[1];q<p[1]+0.5*h.NODE_SLOT_HEIGHT&&(q=p[1]+0.5*h.NODE_SLOT_HEIGHT);b.beginPath();s.type===h.EVENT||s.shape===h.BOX_SHAPE?m?b.rect(p[0]-5+0.5,p[1]-8+0.5,10,14):b.rect(p[0]-6+
0.5,p[1]-5+0.5,14,10):s.shape===h.ARROW_SHAPE?(b.moveTo(p[0]+8,p[1]+0.5),b.lineTo(p[0]-4,p[1]+6+0.5),b.lineTo(p[0]-4,p[1]-6+0.5),b.closePath()):e?b.rect(p[0]-4,p[1]-4,8,8):b.arc(p[0],p[1],4,0,2*Math.PI);b.fill();if(d){var w=null!=s.label?s.label:s.name;w&&(b.fillStyle=h.NODE_TEXT_COLOR,m||s.dir==h.UP?b.fillText(w,p[0],p[1]-10):b.fillText(w,p[0]+10,p[1]+5))}}this.connecting_node&&(b.globalAlpha=0.4*g);b.textAlign=m?"center":"right";b.strokeStyle="black";if(a.outputs)for(c=0;c<a.outputs.length;c++)if(s=
a.outputs[c],p=a.getConnectionPos(!1,c,k),p[0]-=a.pos[0],p[1]-=a.pos[1],q<p[1]+0.5*h.NODE_SLOT_HEIGHT&&(q=p[1]+0.5*h.NODE_SLOT_HEIGHT),b.fillStyle=s.links&&s.links.length?s.color_on||this.default_connection_color.output_on:s.color_off||this.default_connection_color.output_off,b.beginPath(),s.type===h.EVENT||s.shape===h.BOX_SHAPE?m?b.rect(p[0]-5+0.5,p[1]-8+0.5,10,14):b.rect(p[0]-6+0.5,p[1]-5+0.5,14,10):s.shape===h.ARROW_SHAPE?(b.moveTo(p[0]+8,p[1]+0.5),b.lineTo(p[0]-4,p[1]+6+0.5),b.lineTo(p[0]-4,p[1]-
6+0.5),b.closePath()):e?b.rect(p[0]-4,p[1]-4,8,8):b.arc(p[0],p[1],4,0,2*Math.PI),b.fill(),e||b.stroke(),d&&(w=null!=s.label?s.label:s.name))b.fillStyle=h.NODE_TEXT_COLOR,m||s.dir==h.DOWN?b.fillText(w,p[0],p[1]-8):b.fillText(w,p[0]-10,p[1]+5);b.textAlign="left";b.globalAlpha=1;if(a.widgets){s=q;if(m||a.widgets_up)s=2;null!=a.widgets_start_y&&(s=a.widgets_start_y);this.drawNodeWidgets(a,s,b,this.node_widget&&this.node_widget[0]==a?this.node_widget[1]:null)}}else if(this.render_collapsed_slots){e=g=
null;if(a.inputs)for(c=0;c<a.inputs.length;c++)if(s=a.inputs[c],null!=s.link){g=s;break}if(a.outputs)for(c=0;c<a.outputs.length;c++)s=a.outputs[c],s.links&&s.links.length&&(e=s);g&&(g=0,c=-0.5*h.NODE_TITLE_HEIGHT,m&&(g=0.5*a._collapsed_width,c=-h.NODE_TITLE_HEIGHT),b.fillStyle="#686",b.beginPath(),s.type===h.EVENT||s.shape===h.BOX_SHAPE?b.rect(g-7+0.5,c-4,14,8):s.shape===h.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());e&&(g=a._collapsed_width,
c=-0.5*h.NODE_TITLE_HEIGHT,m&&(g=0.5*a._collapsed_width,c=0),b.fillStyle="#686",b.strokeStyle="black",b.beginPath(),s.type===h.EVENT||s.shape===h.BOX_SHAPE?b.rect(g-7+0.5,c-4,14,8):s.shape===h.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}}};k.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||
!0!=this.onDrawLinkTooltip(a,b,this))){var d=b.data,e=null,e=d.constructor===Number?d.toFixed(2):d.constructor===String?'"'+d+'"':d.constructor===Boolean?String(d):d.toToolTip?d.toToolTip():"["+d.constructor.name+"]";null!=e&&(e=e.substr(0,30),a.font="14px Courier New",d=a.measureText(e).width+20,a.shadowColor="black",a.shadowOffsetX=2,a.shadowOffsetY=2,a.shadowBlur=3,a.fillStyle="#454",a.beginPath(),a.roundRect(c[0]-0.5*d,c[1]-15-24,d,24,3,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(e,c[0],c[1]-15-24*0.3))}};var z=new Float32Array(4);k.prototype.drawNodeShape=function(a,b,c,d,e,g,f){b.strokeStyle=d;b.fillStyle=e;e=h.NODE_TITLE_HEIGHT;var m=0.5>this.ds.scale,q=a._shape||a.constructor.shape||h.ROUND_SHAPE,D=a.constructor.title_mode,s=!0;D==h.TRANSPARENT_TITLE?s=!1:D==h.AUTOHIDE_TITLE&&f&&(s=!0);z[0]=0;z[1]=s?-e:0;z[2]=c[0]+1;z[3]=s?c[1]+e:c[1];f=b.globalAlpha;b.beginPath();q==h.BOX_SHAPE||
m?b.fillRect(z[0],z[1],z[2],z[3]):q==h.ROUND_SHAPE||q==h.CARD_SHAPE?b.roundRect(z[0],z[1],z[2],z[3],this.round_radius,q==h.CARD_SHAPE?0:this.round_radius):q==h.CIRCLE_SHAPE&&b.arc(0.5*c[0],0.5*c[1],0.5*c[0],0,2*Math.PI);b.fill();a.flags.collapsed||(b.shadowColor="transparent",b.fillStyle="rgba(0,0,0,0.2)",b.fillRect(0,-1,z[2],2));b.shadowColor="transparent";if(a.onDrawBackground)a.onDrawBackground(b,this,this.canvas,this.graph_mouse);if(s||D==h.TRANSPARENT_TITLE){if(a.onDrawTitleBar)a.onDrawTitleBar(b,
e,c,this.ds.scale,d);else if(D!=h.TRANSPARENT_TITLE&&(a.constructor.title_color||this.render_title_colored)){s=a.constructor.title_color||d;a.flags.collapsed&&(b.shadowColor=h.DEFAULT_SHADOW_COLOR);if(this.use_gradients){var p=k.gradients[s];p||(p=k.gradients[s]=b.createLinearGradient(0,0,400,0),p.addColorStop(0,s),p.addColorStop(1,"#000"));b.fillStyle=p}else b.fillStyle=s;b.beginPath();q==h.BOX_SHAPE||m?b.rect(0,-e,c[0]+1,e):q!=h.ROUND_SHAPE&&q!=h.CARD_SHAPE||b.roundRect(0,-e,c[0]+1,e,this.round_radius,
a.flags.collapsed?this.round_radius:0);b.fill();b.shadowColor="transparent"}if(a.onDrawTitleBox)a.onDrawTitleBox(b,e,c,this.ds.scale);else q==h.ROUND_SHAPE||q==h.CIRCLE_SHAPE||q==h.CARD_SHAPE?(m&&(b.fillStyle="black",b.beginPath(),b.arc(0.5*e,-0.5*e,6,0,2*Math.PI),b.fill()),b.fillStyle=a.boxcolor||h.NODE_DEFAULT_BOXCOLOR,m?b.fillRect(0.5*e-5,-0.5*e-5,10,10):(b.beginPath(),b.arc(0.5*e,-0.5*e,5,0,2*Math.PI),b.fill())):(m&&(b.fillStyle="black",b.fillRect(0.5*(e-10)-1,-0.5*(e+10)-1,12,12)),b.fillStyle=
a.boxcolor||h.NODE_DEFAULT_BOXCOLOR,b.fillRect(0.5*(e-10),-0.5*(e+10),10,10));b.globalAlpha=f;if(a.onDrawTitleText)a.onDrawTitleText(b,e,c,this.ds.scale,this.title_text_font,g);!m&&(b.font=this.title_text_font,f=String(a.getTitle()))&&(b.fillStyle=g?h.NODE_SELECTED_TITLE_COLOR:a.constructor.title_text_color||this.node_title_color,a.flags.collapsed?(b.textAlign="left",b.measureText(f),b.fillText(f.substr(0,20),e,h.NODE_TITLE_TEXT_Y-e),b.textAlign="left"):(b.textAlign="left",b.fillText(f,e,h.NODE_TITLE_TEXT_Y-
e)));a.flags.collapsed||!a.subgraph||a.skip_subgraph_button||(f=h.NODE_TITLE_HEIGHT,s=a.size[0]-f,p=h.isInsideRectangle(this.graph_mouse[0]-a.pos[0],this.graph_mouse[1]-a.pos[1],s+2,-f+2,f-4,f-4),b.fillStyle=p?"#888":"#555",q==h.BOX_SHAPE||m?b.fillRect(s+2,-f+2,f-4,f-4):(b.beginPath(),b.roundRect(s+2,-f+2,f-4,f-4,4),b.fill()),b.fillStyle="#333",b.beginPath(),b.moveTo(s+0.2*f,0.6*-f),b.lineTo(s+0.8*f,0.6*-f),b.lineTo(s+0.5*f,0.3*-f),b.fill());if(a.onDrawTitle)a.onDrawTitle(b)}if(g){if(a.onBounding)a.onBounding(z);
D==h.TRANSPARENT_TITLE&&(z[1]-=e,z[3]+=e);b.lineWidth=1;b.globalAlpha=0.8;b.beginPath();q==h.BOX_SHAPE?b.rect(-6+z[0],-6+z[1],12+z[2],12+z[3]):q==h.ROUND_SHAPE||q==h.CARD_SHAPE&&a.flags.collapsed?b.roundRect(-6+z[0],-6+z[1],12+z[2],12+z[3],2*this.round_radius):q==h.CARD_SHAPE?b.roundRect(-6+z[0],-6+z[1],12+z[2],12+z[3],2*this.round_radius,2):q==h.CIRCLE_SHAPE&&b.arc(0.5*c[0],0.5*c[1],0.5*c[0]+6,0,2*Math.PI);b.strokeStyle=h.NODE_BOX_OUTLINE_COLOR;b.stroke();b.strokeStyle=d;b.globalAlpha=1}};var K=
new Float32Array(4),C=new Float32Array(4),H=new Float32Array(2),F=new Float32Array(2);k.prototype.drawConnections=function(a){var b=h.getTime(),c=this.visible_area;K[0]=c[0]-20;K[1]=c[1]-20;K[2]=c[2]+40;K[3]=c[3]+40;a.lineWidth=this.connections_width;a.fillStyle="#AAA";a.strokeStyle="#AAA";a.globalAlpha=this.editor_alpha;for(var c=this.graph._nodes,d=0,e=c.length;d<e;++d){var g=c[d];if(g.inputs&&g.inputs.length)for(var f=0;f<g.inputs.length;++f){var m=g.inputs[f];if(m&&null!=m.link&&(m=this.graph.links[m.link])){var q=
this.graph.getNodeById(m.origin_id);if(null!=q){var k=m.origin_slot,s=null,s=-1==k?[q.pos[0]+10,q.pos[1]+10]:q.getConnectionPos(!1,k,H),p=g.getConnectionPos(!0,f,F);C[0]=s[0];C[1]=s[1];C[2]=p[0]-s[0];C[3]=p[1]-s[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(A(C,K)){var w=q.outputs[k],k=g.inputs[f];if(w&&k&&(q=w.dir||(q.horizontal?h.DOWN:h.RIGHT),k=k.dir||(g.horizontal?h.UP:h.LEFT),this.renderLink(a,s,p,m,!1,0,null,q,k),m&&m._last_time&&1E3>b-m._last_time)){var w=
2-0.002*(b-m._last_time),t=a.globalAlpha;a.globalAlpha=t*w;this.renderLink(a,s,p,m,!0,w,"white",q,k);a.globalAlpha=t}}}}}}a.globalAlpha=1};k.prototype.renderLink=function(a,b,c,d,e,g,f,m,q,D){d&&this.visible_links.push(d);!f&&d&&(f=d.color||k.link_type_colors[d.type]);f||(f=this.default_link_color);null!=d&&this.highlighted_links[d.id]&&(f="#FFF");m=m||h.RIGHT;q=q||h.LEFT;var s=E(b,c);this.render_connections_border&&0.6<this.ds.scale&&(a.lineWidth=this.connections_width+4);a.lineJoin="round";D=D||
1;1<D&&(a.lineWidth=0.5);a.beginPath();for(var p=0;p<D;p+=1){var w=5*(p-0.5*(D-1));if(this.links_render_mode==h.SPLINE_LINK){a.moveTo(b[0],b[1]+w);var t=0,J=0,l=0,r=0;switch(m){case h.LEFT:t=-0.25*s;break;case h.RIGHT:t=0.25*s;break;case h.UP:J=-0.25*s;break;case h.DOWN:J=0.25*s}switch(q){case h.LEFT:l=-0.25*s;break;case h.RIGHT:l=0.25*s;break;case h.UP:r=-0.25*s;break;case h.DOWN:r=0.25*s}a.bezierCurveTo(b[0]+t,b[1]+J+w,c[0]+l,c[1]+r+w,c[0],c[1]+w)}else if(this.links_render_mode==h.LINEAR_LINK){a.moveTo(b[0],
b[1]+w);r=l=J=t=0;switch(m){case h.LEFT:t=-1;break;case h.RIGHT:t=1;break;case h.UP:J=-1;break;case h.DOWN:J=1}switch(q){case h.LEFT:l=-1;break;case h.RIGHT:l=1;break;case h.UP:r=-1;break;case h.DOWN:r=1}a.lineTo(b[0]+15*t,b[1]+15*J+w);a.lineTo(c[0]+15*l,c[1]+15*r+w);a.lineTo(c[0],c[1]+w)}else if(this.links_render_mode==h.STRAIGHT_LINK)a.moveTo(b[0],b[1]),w=b[0],t=b[1],J=c[0],l=c[1],m==h.RIGHT?w+=10:t+=10,q==h.LEFT?J-=10:l-=10,a.lineTo(w,t),a.lineTo(0.5*(w+J),t),a.lineTo(0.5*(w+J),l),a.lineTo(J,l),
a.lineTo(c[0],c[1]);else return}this.render_connections_border&&0.6<this.ds.scale&&!e&&(a.strokeStyle="rgba(0,0,0,0.5)",a.stroke());a.lineWidth=this.connections_width;a.fillStyle=a.strokeStyle=f;a.stroke();e=this.computeConnectionPoint(b,c,0.5,m,q);d&&d._pos&&(d._pos[0]=e[0],d._pos[1]=e[1]);0.6<=this.ds.scale&&this.highquality_render&&q!=h.CENTER&&(this.render_connection_arrows&&(p=this.computeConnectionPoint(b,c,0.25,m,q),d=this.computeConnectionPoint(b,c,0.26,m,q),D=this.computeConnectionPoint(b,
c,0.75,m,q),s=this.computeConnectionPoint(b,c,0.76,m,q),t=w=0,this.render_curved_connections?(w=-Math.atan2(d[0]-p[0],d[1]-p[1]),t=-Math.atan2(s[0]-D[0],s[1]-D[1])):t=w=c[1]>b[1]?0:Math.PI,a.save(),a.translate(p[0],p[1]),a.rotate(w),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore(),a.save(),a.translate(D[0],D[1]),a.rotate(t),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore()),a.beginPath(),a.arc(e[0],e[1],5,0,2*Math.PI),a.fill());if(g)for(a.fillStyle=
f,p=0;5>p;++p)g=(0.001*h.getTime()+0.2*p)%1,e=this.computeConnectionPoint(b,c,g,m,q),a.beginPath(),a.arc(e[0],e[1],5,0,2*Math.PI),a.fill()};k.prototype.computeConnectionPoint=function(a,b,c,d,e){d=d||h.RIGHT;e=e||h.LEFT;var g=E(a,b),f=[a[0],a[1]],m=[b[0],b[1]];switch(d){case h.LEFT:f[0]+=-0.25*g;break;case h.RIGHT:f[0]+=0.25*g;break;case h.UP:f[1]+=-0.25*g;break;case h.DOWN:f[1]+=0.25*g}switch(e){case h.LEFT:m[0]+=-0.25*g;break;case h.RIGHT:m[0]+=0.25*g;break;case h.UP:m[1]+=-0.25*g;break;case h.DOWN:m[1]+=
0.25*g}d=(1-c)*(1-c)*(1-c);e=3*(1-c)*(1-c)*c;g=3*(1-c)*c*c;c*=c*c;return[d*a[0]+e*f[0]+g*m[0]+c*b[0],d*a[1]+e*f[1]+g*m[1]+c*b[1]]};k.prototype.drawExecutionOrder=function(a){a.shadowColor="transparent";a.globalAlpha=0.25;a.textAlign="center";a.strokeStyle="white";a.globalAlpha=0.75;for(var b=this.visible_nodes,c=0;c<b.length;++c){var d=b[c];a.fillStyle="black";a.fillRect(d.pos[0]-h.NODE_TITLE_HEIGHT,d.pos[1]-h.NODE_TITLE_HEIGHT,h.NODE_TITLE_HEIGHT,h.NODE_TITLE_HEIGHT);0==d.order&&a.strokeRect(d.pos[0]-
h.NODE_TITLE_HEIGHT+0.5,d.pos[1]-h.NODE_TITLE_HEIGHT+0.5,h.NODE_TITLE_HEIGHT,h.NODE_TITLE_HEIGHT);a.fillStyle="#FFF";a.fillText(d.order,d.pos[0]+-0.5*h.NODE_TITLE_HEIGHT,d.pos[1]-6)}a.globalAlpha=1};k.prototype.drawNodeWidgets=function(a,b,c,d){if(!a.widgets||!a.widgets.length)return 0;var e=a.size[0],g=a.widgets;b+=2;var f=h.NODE_WIDGET_HEIGHT,m=0.5<this.ds.scale;c.save();c.globalAlpha=this.editor_alpha;for(var q=h.WIDGET_OUTLINE_COLOR,k=h.WIDGET_BGCOLOR,s=h.WIDGET_TEXT_COLOR,p=h.WIDGET_SECONDARY_TEXT_COLOR,
w=0;w<g.length;++w){var t=g[w],l=b;t.y&&(l=t.y);t.last_y=l;c.strokeStyle=q;c.fillStyle="#222";c.textAlign="left";t.disabled&&(c.globalAlpha*=0.5);var r=t.width||e;switch(t.type){case "button":t.clicked&&(c.fillStyle="#AAA",t.clicked=!1,this.dirty_canvas=!0);c.fillRect(15,l,r-30,f);m&&!t.disabled&&c.strokeRect(15,l,r-30,f);m&&(c.textAlign="center",c.fillStyle=s,c.fillText(t.name,0.5*r,l+0.7*f));break;case "toggle":c.textAlign="left";c.strokeStyle=q;c.fillStyle=k;c.beginPath();m?c.roundRect(15,b,r-
30,f,0.5*f):c.rect(15,b,r-30,f);c.fill();m&&!t.disabled&&c.stroke();c.fillStyle=t.value?"#89A":"#333";c.beginPath();c.arc(r-30,l+0.5*f,0.36*f,0,2*Math.PI);c.fill();m&&(c.fillStyle=p,null!=t.name&&c.fillText(t.name,30,l+0.7*f),c.fillStyle=t.value?s:p,c.textAlign="right",c.fillText(t.value?t.options.on||"true":t.options.off||"false",r-40,l+0.7*f));break;case "slider":c.fillStyle=k;c.fillRect(15,l,r-30,f);var n=t.options.max-t.options.min,v=(t.value-t.options.min)/n;c.fillStyle=d==t?"#89A":"#678";c.fillRect(15,
l,v*(r-30),f);m&&!t.disabled&&c.strokeRect(15,l,r-30,f);t.marker&&(n=(t.marker-t.options.min)/n,c.fillStyle="#AA9",c.fillRect(15+n*(r-30),l,2,f));m&&(c.textAlign="center",c.fillStyle=s,c.fillText(t.name+" "+Number(t.value).toFixed(3),0.5*r,l+0.7*f));break;case "number":case "combo":c.textAlign="left";c.strokeStyle=q;c.fillStyle=k;c.beginPath();m?c.roundRect(15,b,r-30,f,0.5*f):c.rect(15,b,r-30,f);c.fill();m&&(t.disabled||c.stroke(),c.fillStyle=s,t.disabled||(c.beginPath(),c.moveTo(31,b+5),c.lineTo(21,
b+0.5*f),c.lineTo(31,b+f-5),c.fill(),c.beginPath(),c.moveTo(r-15-16,b+5),c.lineTo(r-15-6,b+0.5*f),c.lineTo(r-15-16,b+f-5),c.fill()),c.fillStyle=p,c.fillText(t.name,35,l+0.7*f),c.fillStyle=s,c.textAlign="right","number"==t.type?c.fillText(Number(t.value).toFixed(void 0!==t.options.precision?t.options.precision:3),r-30-20,l+0.7*f):(n=t.value,t.options.values&&(v=t.options.values,v.constructor===Function&&(v=v()),v&&v.constructor!==Array&&(n=v[t.value])),c.fillText(n,r-30-20,l+0.7*f)));break;case "string":case "text":c.textAlign=
"left";c.strokeStyle=q;c.fillStyle=k;c.beginPath();m?c.roundRect(15,b,r-30,f,0.5*f):c.rect(15,b,r-30,f);c.fill();m&&(t.disabled||c.stroke(),c.save(),c.beginPath(),c.rect(15,b,r-30,f),c.clip(),c.fillStyle=p,null!=t.name&&c.fillText(t.name,30,l+0.7*f),c.fillStyle=s,c.textAlign="right",c.fillText(String(t.value).substr(0,30),r-30,l+0.7*f),c.restore());break;default:t.draw&&t.draw(c,a,r,l,f)}b+=(t.computeSize?t.computeSize(r)[1]:f)+4;c.globalAlpha=this.editor_alpha}c.restore();c.textAlign="left"};k.prototype.processNodeWidgets=
function(a,b,c,d){function e(e,d){e.value=d;e.options&&e.options.property&&void 0!==a.properties[e.options.property]&&a.setProperty(e.options.property,d);e.callback&&e.callback(e.value,q,a,b,c)}if(!a.widgets||!a.widgets.length)return null;for(var g=b[0]-a.pos[0],f=b[1]-a.pos[1],m=a.size[0],q=this,k=this.getCanvasWindow(),l=0;l<a.widgets.length;++l){var p=a.widgets[l];if(p&&!p.disabled){var w=p.computeSize?p.computeSize(m)[1]:h.NODE_WIDGET_HEIGHT,t=p.width||m;if(p==d||!(6>g||g>t-12||f<p.last_y||f>
p.last_y+w||void 0===p.last_y)){d=p.value;switch(p.type){case "button":if("mousemove"===c.type)break;p.callback&&setTimeout(function(){p.callback(p,q,a,b,c)},20);this.dirty_canvas=p.clicked=!0;break;case "slider":k=Math.clamp((g-15)/(t-30),0,1);p.value=p.options.min+(p.options.max-p.options.min)*k;p.callback&&setTimeout(function(){e(p,p.value)},20);this.dirty_canvas=!0;break;case "number":case "combo":d=p.value;if("mousemove"==c.type&&"number"==p.type)p.value+=0.1*c.deltaX*(p.options.step||1),null!=
p.options.min&&p.value<p.options.min&&(p.value=p.options.min),null!=p.options.max&&p.value>p.options.max&&(p.value=p.options.max);else if("mousedown"==c.type){var r=p.options.values;r&&r.constructor===Function&&(r=p.options.values(p,a));var n=null;"number"!=p.type&&(n=r.constructor===Array?r:Object.keys(r));g=40>g?-1:g>t-40?1:0;if("number"==p.type)p.value+=0.1*g*(p.options.step||1),null!=p.options.min&&p.value<p.options.min&&(p.value=p.options.min),null!=p.options.max&&p.value>p.options.max&&(p.value=
p.options.max);else if(g)k=-1,this.last_mouseclick=0,k=r.constructor===Object?n.indexOf(String(p.value))+g:n.indexOf(p.value)+g,k>=n.length&&(k=n.length-1),0>k&&(k=0),p.value=r.constructor===Array?r[k]:k;else{var v=r!=n?Object.values(r):r;new h.ContextMenu(v,{scale:Math.max(1,this.ds.scale),event:c,className:"dark",callback:u.bind(p)},k);var u=function(a,b,c){r!=n&&(a=v.indexOf(a));this.value=a;e(this,a);q.dirty_canvas=!0;return!1}}}else"mouseup"==c.type&&"number"==p.type&&(g=40>g?-1:g>t-40?1:0,200>
c.click_time&&0==g&&this.prompt("Value",p.value,function(a){this.value=Number(a);e(this,this.value)}.bind(p),c));d!=p.value&&setTimeout(function(){e(this,this.value)}.bind(p),20);this.dirty_canvas=!0;break;case "toggle":"mousedown"==c.type&&(p.value=!p.value,setTimeout(function(){e(p,p.value)},20));break;case "string":case "text":"mousedown"==c.type&&this.prompt("Value",p.value,function(a){this.value=a;e(this,a)}.bind(p),c,p.options?p.options.multiline:!1);break;default:p.mouse&&(this.dirty_canvas=
p.mouse(c,[g,f],a))}if(d!=p.value){if(a.onWidgetChanged)a.onWidgetChanged(p.name,p.value,d,p);a.graph._version++}return p}}}return null};k.prototype.drawGroups=function(a,b){if(this.graph){var c=this.graph._groups;b.save();b.globalAlpha=0.5*this.editor_alpha;for(var d=0;d<c.length;++d){var e=c[d];if(A(this.visible_area,e._bounding)){b.fillStyle=e.color||"#335";b.strokeStyle=e.color||"#335";var g=e._pos,f=e._size;b.globalAlpha=0.25*this.editor_alpha;b.beginPath();b.rect(g[0]+0.5,g[1]+0.5,f[0],f[1]);
b.fill();b.globalAlpha=this.editor_alpha;b.stroke();b.beginPath();b.moveTo(g[0]+f[0],g[1]+f[1]);b.lineTo(g[0]+f[0]-10,g[1]+f[1]);b.lineTo(g[0]+f[0],g[1]+f[1]-10);b.fill();f=e.font_size||h.DEFAULT_GROUP_FONT_SIZE;b.font=f+"px Arial";b.fillText(e.title,g[0]+4,g[1]+f)}}b.restore()}};k.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)};k.prototype.resize=function(a,b){if(!a&&!b){var c=this.canvas.parentNode;a=c.offsetWidth;
b=c.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)};k.prototype.switchLiveMode=function(a){if(a){var b=this,c=this.live_mode?1.1:0.9;this.live_mode&&(this.live_mode=!1,this.editor_alpha=0.1);var d=setInterval(function(){b.editor_alpha*=c;b.dirty_canvas=!0;b.dirty_bgcanvas=!0;1>c&&0.01>b.editor_alpha&&(clearInterval(d),1>c&&(b.live_mode=!0));1<c&&
0.99<b.editor_alpha&&(clearInterval(d),b.editor_alpha=1)},1)}else this.live_mode=!this.live_mode,this.dirty_bgcanvas=this.dirty_canvas=!0};k.prototype.onNodeSelectionChange=function(a){};k.prototype.touchHandler=function(a){var b=a.changedTouches[0],c="";switch(a.type){case "touchstart":c="mousedown";break;case "touchmove":c="mousemove";break;case "touchend":c="mouseup";break;default:return}var d=this.getCanvasWindow(),e=d.document.createEvent("MouseEvent");e.initMouseEvent(c,!0,!0,d,1,b.screenX,
b.screenY,b.clientX,b.clientY,!1,!1,!1,!1,0,null);b.target.dispatchEvent(e);a.preventDefault()};k.onGroupAdd=function(a,b,c){a=k.active_canvas;a.getCanvasWindow();b=new h.LGraphGroup;b.pos=a.convertEventToCanvasOffset(c);a.graph.add(b)};k.onMenuAdd=function(a,b,c,d,e){function g(a,b){var d=[];h.getNodeTypesCategories(f.filter||q.filter).filter(function(b){return b.startsWith(a)}).map(function(b){if(b){b=b.replace(RegExp("^("+a+")"),"").split("/")[0];var c=""===a?b+"/":a+b+"/";-1!=b.indexOf("::")&&
(b=b.split("::")[1]);-1===d.findIndex(function(a){return a.value===c})&&d.push({value:c,content:b,has_submenu:!0,callback:function(a,b,c,e){g(a.value,e)}})}});h.getNodeTypesInCategory(a.slice(0,-1),f.filter||q.filter).map(function(a){a.skip_list||d.push({value:a.type,content:a.title,has_submenu:!1,callback:function(a,b,c,d){b=d.getFirstEvent();f.graph.beforeChange();if(a=h.createNode(a.value))a.pos=f.convertEventToCanvasOffset(b),f.graph.add(a);e&&e(a);f.graph.afterChange()}})});new h.ContextMenu(d,
{event:c,parentMenu:b},m)}var f=k.active_canvas,m=f.getCanvasWindow(),q=f.graph;if(q)return g("",d),!1};k.onMenuCollapseAll=function(){};k.onMenuNodeEdit=function(){};k.showMenuNodeOptionalInputs=function(a,b,c,d,e){function g(a,b,c){e&&(a.callback&&a.callback.call(f,e,a,b,c),a.value&&(e.graph.beforeChange(),e.addInput(a.value[0],a.value[1],a.value[2]),e.setDirtyCanvas(!0,!0),e.graph.afterChange()))}if(e){var f=this;a=k.active_canvas.getCanvasWindow();b=e.optional_inputs;e.onGetInputs&&(b=e.onGetInputs());
var m=[];if(b)for(var q=0;q<b.length;q++){var l=b[q];if(l){var r=l[0];l[2]&&l[2].label&&(r=l[2].label);r={content:r,value:l};l[1]==h.ACTION&&(r.className="event");m.push(r)}else m.push(null)}this.onMenuNodeInputs&&(m=this.onMenuNodeInputs(m));if(m.length)return new h.ContextMenu(m,{event:c,callback:g,parentMenu:d,node:e},a),!1;console.log("no input entries")}};k.showMenuNodeOptionalOutputs=function(a,b,c,d,e){function g(a,b,c){if(e&&(a.callback&&a.callback.call(f,e,a,b,c),a.value))if(c=a.value[1],
!c||c.constructor!==Object&&c.constructor!==Array)e.graph.beforeChange(),e.addOutput(a.value[0],a.value[1],a.value[2]),e.setDirtyCanvas(!0,!0),e.graph.afterChange();else{a=[];for(var m in c)a.push({content:m,value:c[m]});new h.ContextMenu(a,{event:b,callback:g,parentMenu:d,node:e});return!1}}if(e){var f=this;a=k.active_canvas.getCanvasWindow();b=e.optional_outputs;e.onGetOutputs&&(b=e.onGetOutputs());var m=[];if(b)for(var q=0;q<b.length;q++){var l=b[q];if(!l)m.push(null);else if(!e.flags||!e.flags.skip_repeated_outputs||
-1==e.findOutputSlot(l[0])){var r=l[0];l[2]&&l[2].label&&(r=l[2].label);r={content:r,value:l};l[1]==h.EVENT&&(r.className="event");m.push(r)}}this.onMenuNodeOutputs&&(m=this.onMenuNodeOutputs(m));if(m.length)return new h.ContextMenu(m,{event:c,callback:g,parentMenu:d,node:e},a),!1}};k.onShowMenuNodeProperties=function(a,b,c,d,e){function g(a,b,c,d){e&&(b=this.getBoundingClientRect(),f.showEditPropertyValue(e,a.value,{position:[b.left,b.top]}))}if(e&&e.properties){var f=k.active_canvas;b=f.getCanvasWindow();
var m=[],q;for(q in e.properties){a=void 0!==e.properties[q]?e.properties[q]:" ";"object"==typeof a&&(a=JSON.stringify(a));var l=e.getPropertyInfo(q);if("enum"==l.type||"combo"==l.type)a=k.getPropertyPrintableValue(a,l.values);a=k.decodeHTML(a);m.push({content:"<span class='property_name'>"+(l.label?l.label:q)+"</span><span class='property_value'>"+a+"</span>",value:q})}if(m.length)return new h.ContextMenu(m,{event:c,callback:g,parentMenu:d,allow_html:!0,node:e},b),!1}};k.decodeHTML=function(a){var b=
document.createElement("div");b.innerText=a;return b.innerHTML};k.onResizeNode=function(a,b,c,d,e){if(e){e.size=e.computeSize();if(e.onResize)e.onResize(e.size);e.setDirtyCanvas(!0,!0)}};k.prototype.showLinkMenu=function(a,b){var c=this;console.log(a);var d=new h.ContextMenu(["Add Node",null,"Delete"],{event:b,title:null!=a.data?a.data.constructor.name:null,callback:function(b,g,f){switch(b){case "Add Node":k.onMenuAdd(null,null,f,d,function(b){console.log("node autoconnect");var e=c.graph.getNodeById(a.origin_id),
d=c.graph.getNodeById(a.target_id);b.inputs&&b.inputs.length&&b.outputs&&b.outputs.length&&e.outputs[a.origin_slot].type==b.inputs[0].type&&b.outputs[0].type==d.inputs[0].type&&(e.connect(a.origin_slot,b,0),b.connect(0,d,a.target_slot),b.pos[0]-=0.5*b.size[0])});break;case "Delete":c.graph.removeLink(a.id)}}});return!1};k.onShowPropertyEditor=function(a,b,c,d,e){function g(){var b=q.value;"Number"==a.type?b=Number(b):"Boolean"==a.type&&(b=Boolean(b));e[f]=b;m.parentNode&&m.parentNode.removeChild(m);
e.setDirtyCanvas(!0,!0)}var f=a.property||"title";b=e[f];var m=document.createElement("div");m.className="graphdialog";m.innerHTML="<span class='name'></span><input autofocus type='text' class='value'/><button>OK</button>";m.querySelector(".name").innerText=f;var q=m.querySelector(".value");q&&(q.value=b,q.addEventListener("blur",function(a){this.focus()}),q.addEventListener("keydown",function(a){if(13==a.keyCode||"textarea"==a.target.localName)g(),a.preventDefault(),a.stopPropagation()}));b=k.active_canvas.canvas;
c=b.getBoundingClientRect();var h=d=-20;c&&(d-=c.left,h-=c.top);event?(m.style.left=event.clientX+d+"px",m.style.top=event.clientY+h+"px"):(m.style.left=0.5*b.width+d+"px",m.style.top=0.5*b.height+h+"px");m.querySelector("button").addEventListener("click",g);b.parentNode.appendChild(m)};k.prototype.prompt=function(a,b,c,d,e){var g=this;a=a||"";var f=!1,m=document.createElement("div");m.className="graphdialog rounded";m.innerHTML=e?"<span class='name'></span> <textarea autofocus class='value'></textarea><button class='rounded'>OK</button>":
"<span class='name'></span> <input autofocus type='text' class='value'/><button class='rounded'>OK</button>";m.close=function(){g.prompt_box=null;m.parentNode&&m.parentNode.removeChild(m)};1<this.ds.scale&&(m.style.transform="scale("+this.ds.scale+")");m.addEventListener("mouseleave",function(a){f||m.close()});g.prompt_box&&g.prompt_box.close();g.prompt_box=m;m.querySelector(".name").innerText=a;var q=m.querySelector(".value");q.value=b;q.addEventListener("keydown",function(a){f=!0;if(27==a.keyCode)m.close();
else if(13==a.keyCode&&"textarea"!=a.target.localName)c&&c(this.value),m.close();else return;a.preventDefault();a.stopPropagation()});m.querySelector("button").addEventListener("click",function(a){c&&c(q.value);g.setDirty(!0);m.close()});a=k.active_canvas.canvas;b=a.getBoundingClientRect();var h=e=-20;b&&(e-=b.left,h-=b.top);d?(m.style.left=d.clientX+e+"px",m.style.top=d.clientY+h+"px"):(m.style.left=0.5*a.width+e+"px",m.style.top=0.5*a.height+h+"px");a.parentNode.appendChild(m);setTimeout(function(){q.focus()},
10);return m};k.search_limit=-1;k.prototype.showSearchBox=function(a){function b(b){if(b)if(e.onSearchBoxSelection)e.onSearchBoxSelection(b,a,g);else{var c=h.searchbox_extras[b.toLowerCase()];c&&(b=c.type);g.graph.beforeChange();if(b=h.createNode(b))b.pos=g.convertEventToCanvasOffset(a),g.graph.add(b);if(c&&c.data){if(c.data.properties)for(var d in c.data.properties)b.addProperty(d,c.data.properties[d]);if(c.data.inputs)for(d in b.inputs=[],c.data.inputs)b.addOutput(c.data.inputs[d][0],c.data.inputs[d][1]);
if(c.data.outputs)for(d in b.outputs=[],c.data.outputs)b.addOutput(c.data.outputs[d][0],c.data.outputs[d][1]);c.data.title&&(b.title=c.data.title);c.data.json&&b.configure(c.data.json);g.graph.afterChange()}}q.close()}function c(a){var b=t;t&&t.classList.remove("selected");t?(t=a?t.nextSibling:t.previousSibling)||(t=b):t=a?r.childNodes[0]:r.childNodes[r.childNodes.length];t&&(t.classList.add("selected"),t.scrollIntoView({block:"end",behavior:"smooth"}))}function d(){function a(c,d){var e=document.createElement("div");
p||(p=c);e.innerText=c;e.dataset.type=escape(c);e.className="litegraph lite-search-item";d&&(e.className+=" "+d);e.addEventListener("click",function(a){b(unescape(this.dataset.type))});r.appendChild(e)}w=null;var c=J.value;p=null;r.innerHTML="";if(c)if(e.onSearchBox){var d=e.onSearchBox(r,c,g);if(d)for(var m=0;m<d.length;++m)a(d[m])}else{var d=0,c=c.toLowerCase(),f=g.filter||g.graph.filter;for(m in h.searchbox_extras){var q=h.searchbox_extras[m];if(-1!==q.desc.toLowerCase().indexOf(c)){var l=h.registered_node_types[q.type];
if(!l||l.filter==f)if(a(q.desc,"searchbox_extra"),-1!==k.search_limit&&d++>k.search_limit)break}}q=null;if(Array.prototype.filter)q=Object.keys(h.registered_node_types).filter(t);else for(m in q=[],h.registered_node_types)t(m)&&q.push(m);for(m=0;m<q.length&&!(a(q[m]),-1!==k.search_limit&&d++>k.search_limit);m++);var t=function(a){var b=h.registered_node_types[a];return f&&b.filter!=f?!1:-1!==a.toLowerCase().indexOf(c)}}}var e=this,g=k.active_canvas,f=g.canvas,m=f.ownerDocument||document,q=document.createElement("div");
q.className="litegraph litesearchbox graphdialog rounded";q.innerHTML="<span class='name'>Search</span> <input autofocus type='text' class='value rounded'/><div class='helper'></div>";q.close=function(){e.search_box=null;m.body.focus();m.body.style.overflow="";setTimeout(function(){e.canvas.focus()},20);q.parentNode&&q.parentNode.removeChild(q)};var l=null;1<this.ds.scale&&(q.style.transform="scale("+this.ds.scale+")");q.addEventListener("mouseenter",function(a){l&&(clearTimeout(l),l=null)});q.addEventListener("mouseleave",
function(a){l=setTimeout(function(){q.close()},500)});e.search_box&&e.search_box.close();e.search_box=q;var r=q.querySelector(".helper"),p=null,w=null,t=null,J=q.querySelector("input");J&&(J.addEventListener("blur",function(a){this.focus()}),J.addEventListener("keydown",function(a){if(38==a.keyCode)c(!1);else if(40==a.keyCode)c(!0);else if(27==a.keyCode)q.close();else if(13==a.keyCode)t?b(t.innerHTML):p?b(p):q.close();else{w&&clearInterval(w);w=setTimeout(d,10);return}a.preventDefault();a.stopPropagation();
a.stopImmediatePropagation();return!0}));m.fullscreenElement?m.fullscreenElement.appendChild(q):(m.body.appendChild(q),m.body.style.overflow="hidden");var f=f.getBoundingClientRect(),n=(a?a.clientY:f.top+0.5*f.height)-20;q.style.left=(a?a.clientX:f.left+0.5*f.width)-80+"px";q.style.top=n+"px";a.layerY>f.height-200&&(r.style.maxHeight=f.height-a.layerY-20+"px");J.focus();return q};k.prototype.showEditPropertyValue=function(a,b,c){function d(){e(p.value)}function e(d){g&&g.values&&g.values.constructor===
Object&&void 0!=g.values[d]&&(d=g.values[d]);"number"==typeof a.properties[b]&&(d=Number(d));if("array"==f||"object"==f)d=JSON.parse(d);a.properties[b]=d;a.graph&&a.graph._version++;if(a.onPropertyChanged)a.onPropertyChanged(b,d);if(c.onclose)c.onclose();k.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)m="<input autofocus type='checkbox' class='value' "+(a.properties[b]?"checked":"")+"/>";else{console.warn("unknown type: "+f);return}else{var m="<select autofocus type='text' class='value'>",q;for(q in g.values){var h=q;g.values.constructor===Array&&(h=g.values[q]);m+="<option value='"+h+"' "+(h==a.properties[b]?"selected":"")+">"+g.values[q]+"</option>"}m+="</select>"}var k=this.createDialog("<span class='name'>"+(g.label?g.label:b)+"</span>"+m+"<button>OK</button>",c);
if("enum"!=f&&"combo"!=f||!g.values)if("boolean"==f)(p=k.querySelector("input"))&&p.addEventListener("click",function(a){e(!!p.checked)});else{if(p=k.querySelector("input"))p.addEventListener("blur",function(a){this.focus()}),h=void 0!==a.properties[b]?a.properties[b]:"","string"!==f&&(h=JSON.stringify(h)),p.value=h,p.addEventListener("keydown",function(a){13==a.keyCode&&(d(),a.preventDefault(),a.stopPropagation())})}else{var p=k.querySelector("select");p.addEventListener("change",function(a){e(a.target.value)})}k.querySelector("button").addEventListener("click",
d);return k}};k.prototype.createDialog=function(a,b){b=b||{};var c=document.createElement("div");c.className="graphdialog";c.innerHTML=a;var d=this.canvas.getBoundingClientRect(),e=-20,g=-20;d&&(e-=d.left,g-=d.top);b.position?(e+=b.position[0],g+=b.position[1]):b.event?(e+=b.event.clientX,g+=b.event.clientY):(e+=0.5*this.canvas.width,g+=0.5*this.canvas.height);c.style.left=e+"px";c.style.top=g+"px";this.canvas.parentNode.appendChild(c);c.close=function(){this.parentNode&&this.parentNode.removeChild(this)};
return c};k.prototype.createPanel=function(a,b){b=b||{};var c=b.window||window,d=document.createElement("div");d.className="litegraph dialog";d.innerHTML="<div class='dialog-header'><span class='dialog-title'></span></div><div class='dialog-content'></div><div class='dialog-footer'></div>";d.header=d.querySelector(".dialog-header");b.width&&(d.style.width=b.width+(b.width.constructor===Number?"px":""));b.height&&(d.style.height=b.height+(b.height.constructor===Number?"px":""));if(b.closable){var e=
document.createElement("span");e.innerHTML="&#10005;";e.classList.add("close");e.addEventListener("click",function(){d.close()});d.header.appendChild(e)}d.title_element=d.querySelector(".dialog-title");d.title_element.innerText=a;d.content=d.querySelector(".dialog-content");d.footer=d.querySelector(".dialog-footer");d.close=function(){this.parentNode&&this.parentNode.removeChild(this)};d.clear=function(){this.content.innerHTML=""};d.addHTML=function(a,b,c){var e=document.createElement("div");b&&(e.className=
b);e.innerHTML=a;c?d.footer.appendChild(e):d.content.appendChild(e);return e};d.addButton=function(a,b,c){var e=document.createElement("button");e.innerText=a;e.options=c;e.classList.add("btn");e.addEventListener("click",b);d.footer.appendChild(e);return e};d.addSeparator=function(){var a=document.createElement("div");a.className="separator";d.content.appendChild(a)};d.addWidget=function(a,b,e,q,l){function r(a,b){console.log("change",a,b);q.callback&&q.callback(a,b);l&&l(a,b)}q=q||{};var p=String(e);
a=a.toLowerCase();"number"==a&&(p=e.toFixed(3));var w=document.createElement("div");w.className="property";w.innerHTML="<span class='property_name'></span><span class='property_value'></span>";w.querySelector(".property_name").innerText=b;var t=w.querySelector(".property_value");t.innerText=p;w.dataset.property=b;w.dataset.type=q.type||a;w.options=q;w.value=e;if("boolean"==a)w.classList.add("boolean"),e&&w.classList.add("bool-on"),w.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";r(a,this.value)});else if("string"==a||"number"==a)t.setAttribute("contenteditable",!0),t.addEventListener("keydown",function(a){"Enter"==a.code&&(a.preventDefault(),this.blur())}),t.addEventListener("blur",function(){var a=this.innerText,b=this.parentNode.dataset.property;"number"==this.parentNode.dataset.type&&(a=Number(a));r(b,a)});else if("enum"==a||"combo"==a)p=k.getPropertyPrintableValue(e,
q.values);t.innerText=p;t.addEventListener("click",function(a){var b=this.parentNode.dataset.property,e=this;new h.ContextMenu(q.values||[],{event:a,className:"dark",callback:function(a,c,d){e.innerText=a;r(b,a);return!1}},c)});d.content.appendChild(w);return w};return d};k.getPropertyPrintableValue=function(a,b){if(!b||b.constructor===Array)return String(a);if(b.constructor===Object){var c="",d;for(d in b)if(b[d]==a){c=d;break}return String(a)+" ("+c+")"}};k.prototype.showShowNodePanel=function(a){window.SELECTED_NODE=
a;var b=document.querySelector("#node-panel");b&&b.close();var c=this.getCanvasWindow(),b=this.createPanel(a.title||"",{closable:!0,window:c});b.id="node-panel";b.node=a;b.classList.add("settings");var d=this;(function(){b.content.innerHTML="";b.addHTML("<span class='node_type'>"+a.type+"</span><span class='node_desc'>"+(a.constructor.desc||"")+"</span><span class='separator'></span>");b.addHTML("<h3>Properties</h3>");for(var c in a.properties){var g=a.properties[c],f=a.getPropertyInfo(c);a.onAddPropertyToPanel&&
a.onAddPropertyToPanel(c,b)||b.addWidget(f.widget||f.type,c,g,f,function(b,c){d.graph.beforeChange(a);a.setProperty(b,c);d.graph.afterChange();d.dirty_canvas=!0})}b.addSeparator();if(a.onShowCustomPanelInfo)a.onShowCustomPanelInfo(b);b.addButton("Delete",function(){a.block_delete||(a.graph.remove(a),b.close())}).classList.add("delete")})();this.canvas.parentNode.appendChild(b)};k.prototype.showSubgraphPropertiesDialog=function(a){function b(){d.clear();if(a.inputs)for(var c=0;c<a.inputs.length;++c){var g=
a.inputs[c];if(!g.not_subgraph_input){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=g.name;f.dataset.slot=c;f.querySelector(".name").innerText=g.name;f.querySelector(".type").innerText=g.type;f.querySelector("button").addEventListener("click",function(c){a.removeInput(Number(this.parentNode.dataset.slot));b()})}}}console.log("showing subgraph properties dialog");var c=this.canvas.parentNode.querySelector(".subgraph_dialog");
c&&c.close();var d=this.createPanel("Subgraph Inputs",{closable:!0,width:500});d.node=a;d.classList.add("subgraph_dialog");d.addHTML(" + <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,f=c.querySelector(".type").value;d&&-1==a.findInputSlot(d)&&(a.addInput(d,f),c.querySelector(".name").value=
"",c.querySelector(".type").value="",b())});b();this.canvas.parentNode.appendChild(d);return d};k.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())}};k.onMenuNodeCollapse=function(a,b,c,d,e){e.graph.beforeChange(e);e.collapse();e.graph.afterChange(e)};k.onMenuNodePin=function(a,b,c,d,e){e.pin()};k.onMenuNodeMode=function(a,b,c,d,e){new h.ContextMenu(["Always",
"On Event","On Trigger","Never"],{event:c,callback:function(a){if(e)switch(a){case "On Event":e.mode=h.ON_EVENT;break;case "On Trigger":e.mode=h.ON_TRIGGER;break;case "Never":e.mode=h.NEVER;break;default:e.mode=h.ALWAYS}},parentMenu:d,node:e});return!1};k.onMenuNodeColors=function(a,b,c,d,e){if(!e)throw"no node for color";b=[];b.push({value:null,content:"<span style='display: block; padding-left: 4px;'>No color</span>"});for(var g in k.node_colors)a=k.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 h.ContextMenu(b,{event:c,callback:function(a){e&&((a=a.value?k.node_colors[a.value]:null)?e.constructor===h.LGraphGroup?e.color=a.groupcolor:(e.color=a.color,e.bgcolor=a.bgcolor):(delete e.color,delete e.bgcolor),e.setDirtyCanvas(!0,!0))},parentMenu:d,node:e});return!1};k.onMenuNodeShapes=function(a,b,c,d,e){if(!e)throw"no node passed";new h.ContextMenu(h.VALID_SHAPES,{event:c,callback:function(a){e&&(e.graph.beforeChange(e),
e.shape=a,e.graph.afterChange(e),e.setDirtyCanvas(!0))},parentMenu:d,node:e});return!1};k.onMenuNodeRemove=function(a,b,c,d,e){if(!e)throw"no node passed";!1!==e.removable&&(a=e.graph,a.beforeChange(),a.remove(e),a.afterChange(),e.setDirtyCanvas(!0,!0))};k.onMenuNodeToSubgraph=function(a,b,c,d,e){a=e.graph;if(b=k.active_canvas)c=Object.values(b.selected_nodes||{}),c.length||(c=[e]),d=h.createNode("graph/subgraph"),d.pos=e.pos.concat(),a.add(d),d.buildFromNodes(c),b.deselectAllNodes(),e.setDirtyCanvas(!0,
!0)};k.onMenuNodeClone=function(a,b,c,d,e){!1!=e.clonable&&(a=e.clone())&&(a.pos=[e.pos[0]+5,e.pos[1]+5],e.graph.beforeChange(),e.graph.add(a),e.graph.afterChange(),e.setDirtyCanvas(!0,!0))};k.node_colors={red:{color:"#322",bgcolor:"#533",groupcolor:"#A88"},brown:{color:"#332922",bgcolor:"#593930",groupcolor:"#b06634"},green:{color:"#232",bgcolor:"#353",groupcolor:"#8A8"},blue:{color:"#223",bgcolor:"#335",groupcolor:"#88A"},pale_blue:{color:"#2a363b",bgcolor:"#3f5159",groupcolor:"#3f789e"},cyan:{color:"#233",
bgcolor:"#355",groupcolor:"#8AA"},purple:{color:"#323",bgcolor:"#535",groupcolor:"#a1309b"},yellow:{color:"#432",bgcolor:"#653",groupcolor:"#b58b2a"},black:{color:"#222",bgcolor:"#000",groupcolor:"#444"}};k.prototype.getCanvasMenuOptions=function(){var a=null;this.getMenuOptions?a=this.getMenuOptions():(a=[{content:"Add Node",has_submenu:!0,callback:k.onMenuAdd},{content:"Add Group",callback:k.onGroupAdd}],this._graph_stack&&0<this._graph_stack.length&&a.push(null,{content:"Close subgraph",callback:this.closeSubgraph.bind(this)}));
if(this.getExtraMenuOptions){var b=this.getExtraMenuOptions(this,a);b&&(a=a.concat(b))}return a};k.prototype.getNodeMenuOptions=function(a){var b=null,b=a.getMenuOptions?a.getMenuOptions(this):[{content:"Inputs",has_submenu:!0,disabled:!0,callback:k.showMenuNodeOptionalInputs},{content:"Outputs",has_submenu:!0,disabled:!0,callback:k.showMenuNodeOptionalOutputs},null,{content:"Properties",has_submenu:!0,callback:k.onShowMenuNodeProperties},null,{content:"Title",callback:k.onShowPropertyEditor},{content:"Mode",
has_submenu:!0,callback:k.onMenuNodeMode},{content:"Resize",callback:function(){if(a.resizable)return k.onResizeNode}},{content:"Collapse",callback:k.onMenuNodeCollapse},{content:"Pin",callback:k.onMenuNodePin},{content:"Colors",has_submenu:!0,callback:k.onMenuNodeColors},{content:"Shapes",has_submenu:!0,callback:k.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:k.onMenuNodeClone});b.push(null,{content:"Remove",disabled:!(!1!==a.removable&&!a.block_delete),callback:k.onMenuNodeRemove});if(a.graph&&a.graph.onGetNodeMenuOptions)a.graph.onGetNodeMenuOptions(b,a);return b};k.prototype.getGroupMenuOptions=function(a){return[{content:"Title",callback:k.onShowPropertyEditor},{content:"Color",has_submenu:!0,callback:k.onMenuNodeColors},{content:"Font size",
property:"font_size",type:"Number",callback:k.onShowPropertyEditor},null,{content:"Remove",callback:k.onMenuNodeRemove}]};k.prototype.processContextMenu=function(a,b){var c=this,d=k.active_canvas.getCanvasWindow(),e=null,g={event:b,callback:function(b,d,e){if(b)if("Remove Slot"==b.content)b=b.slot,b.input?a.removeInput(b.slot):b.output&&a.removeOutput(b.slot);else if("Disconnect Links"==b.content)b=b.slot,b.output?a.disconnectOutput(b.slot):b.input&&a.disconnectInput(b.slot);else if("Rename Slot"==
b.content){b=b.slot;var m=b.input?a.getInputInfo(b.slot):a.getOutputInfo(b.slot),f=c.createDialog("<span class='name'>Name</span><input autofocus type='text'/><button>OK</button>",d),g=f.querySelector("input");g&&m&&(g.value=m.label||"");f.querySelector("button").addEventListener("click",function(a){g.value&&(m&&(m.label=g.value),c.setDirty(!0));f.close()})}},extra:a};a&&(g.title=a.type);var f=null;a&&(f=a.getSlotInPosition(b.canvasX,b.canvasY),k.active_node=a);if(f){e=[];if(a.getSlotMenuOptions)e=
a.getSlotMenuOptions(f);else{f&&f.output&&f.output.links&&f.output.links.length&&e.push({content:"Disconnect Links",slot:f});var m=f.input||f.output;e.push(m.locked?"Cannot remove":{content:"Remove Slot",slot:f});e.push(m.nameLocked?"Cannot rename":{content:"Rename Slot",slot:f})}g.title=(f.input?f.input.type:f.output.type)||"*";f.input&&f.input.type==h.ACTION&&(g.title="Action");f.output&&f.output.type==h.EVENT&&(g.title="Event")}else a?e=this.getNodeMenuOptions(a):(e=this.getCanvasMenuOptions(),
(f=this.graph.getGroupOnPos(b.canvasX,b.canvasY))&&e.push(null,{content:"Edit Group",has_submenu:!0,submenu:{title:"Group",extra:f,options:this.getGroupMenuOptions(f)}}));e&&new h.ContextMenu(e,g,d)};"undefined"!=typeof window&&window.CanvasRenderingContext2D&&(window.CanvasRenderingContext2D.prototype.roundRect=function(a,b,c,d,e,g){void 0===e&&(e=5);void 0===g&&(g=e);this.moveTo(a+e,b);this.lineTo(a+c-e,b);this.quadraticCurveTo(a+c,b,a+c,b+e);this.lineTo(a+c,b+d-g);this.quadraticCurveTo(a+c,b+d,
a+c-g,b+d);this.lineTo(a+g,b+d);this.quadraticCurveTo(a,b+d,a,b+d-g);this.lineTo(a,b+e);this.quadraticCurveTo(a,b,a+e,b)});h.compareObjects=function(a,b){for(var c in a)if(a[c]!=b[c])return!1;return!0};h.distance=E;h.colorToString=function(a){return"rgba("+Math.round(255*a[0]).toFixed()+","+Math.round(255*a[1]).toFixed()+","+Math.round(255*a[2]).toFixed()+","+(4==a.length?a[3].toFixed(2):"1.0")+")"};h.isInsideRectangle=y;h.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)};h.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};h.overlapBounding=A;h.hex2num=function(a){"#"==a.charAt(0)&&(a=a.slice(1));a=a.toUpperCase();for(var b=Array(3),c=0,d,e,g=0;6>g;g+=2)d="0123456789ABCDEF".indexOf(a.charAt(g)),e="0123456789ABCDEF".indexOf(a.charAt(g+1)),b[c]=16*d+e,c++;return b};h.num2hex=function(a){for(var b="#",c,d,e=0;3>e;e++)c=a[e]/16,d=a[e]%16,b+="0123456789ABCDEF".charAt(c)+"0123456789ABCDEF".charAt(d);return b};
x.prototype.addItem=function(a,b,c){function d(a){var b=this.value;b&&b.has_submenu&&e.call(this,a)}function e(a){var b=this.value,d=!0;g.current_submenu&&g.current_submenu.close(a);if(c.callback){var e=c.callback.call(this,b,c,a,g,c.node);!0===e&&(d=!1)}if(b&&(b.callback&&!c.ignore_item_callbacks&&!0!==b.disabled&&(e=b.callback.call(this,b,c,a,g,c.extra),!0===e&&(d=!1)),b.submenu)){if(!b.submenu.options)throw"ContextMenu submenu needs options";new g.constructor(b.submenu.options,{callback:b.submenu.callback,
event:a,parentMenu:g,ignore_item_callbacks:b.submenu.ignore_item_callbacks,title:b.submenu.title,extra:b.submenu.extra,autoopen:c.autoopen});d=!1}d&&!g.lock&&g.close()}var g=this;c=c||{};var f=document.createElement("div");f.className="litemenu-entry submenu";var m=!1;if(null===b)f.classList.add("separator");else{f.innerHTML=b&&b.title?b.title:a;if(f.value=b)b.disabled&&(m=!0,f.classList.add("disabled")),(b.submenu||b.has_submenu)&&f.classList.add("has_submenu");"function"==typeof b?(f.dataset.value=
a,f.onclick_callback=b):f.dataset.value=b;b.className&&(f.className+=" "+b.className)}this.root.appendChild(f);m||f.addEventListener("click",e);c.autoopen&&f.addEventListener("mouseenter",d);return f};x.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&&!x.isCursorOverElement(a,this.parentMenu.root)&&x.trigger(this.parentMenu.root,"mouseleave",
a));this.current_submenu&&this.current_submenu.close(a,!0);this.root.closing_timer&&clearTimeout(this.root.closing_timer)};x.trigger=function(a,b,c,d){var e=document.createEvent("CustomEvent");e.initCustomEvent(b,!0,!0,c);e.srcElement=d;a.dispatchEvent?a.dispatchEvent(e):a.__events&&a.__events.dispatchEvent(e);return e};x.prototype.getTopMenu=function(){return this.options.parentMenu?this.options.parentMenu.getTopMenu():this};x.prototype.getFirstEvent=function(){return this.options.parentMenu?this.options.parentMenu.getFirstEvent():
this.options.event};x.isCursorOverElement=function(a,b){var c=a.clientX,d=a.clientY,e=b.getBoundingClientRect();return e?d>e.top&&d<e.top+e.height&&c>e.left&&c<e.left+e.width?!0:!1:!1};h.ContextMenu=x;h.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])}};h.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)))};I.sampleCurve=function(a,b){if(b){for(var c=0;c<b.length-1;++c){var d=b[c],e=b[c+1];if(!(e[0]<a)){c=e[0]-d[0];if(1E-5>Math.abs(c))return d[1];c=(a-d[0])/c;return d[1]*
(1-c)+e[1]*c}}return 0}};I.prototype.draw=function(a,b,c,d,e,g){if(c=this.points){this.size=b;var f=b[0]-2*this.margin;b=b[1]-2*this.margin;e=e||"#666";a.save();a.translate(this.margin,this.margin);d&&(a.fillStyle="#111",a.fillRect(0,0,f,b),a.fillStyle="#222",a.fillRect(0.5*f,0,1,b),a.strokeStyle="#333",a.strokeRect(0,0,f,b));a.strokeStyle=e;g&&(a.globalAlpha=0.5);a.beginPath();for(d=0;d<c.length;++d)e=c[d],a.lineTo(e[0]*f,(1-e[1])*b);a.stroke();a.globalAlpha=1;if(!g)for(d=0;d<c.length;++d)e=c[d],
a.fillStyle=this.selected==d?"#FFF":this.nearest==d?"#DDD":"#AAA",a.beginPath(),a.arc(e[0]*f,(1-e[1])*b,2,0,2*Math.PI),a.fill();a.restore()}};I.prototype.onMouseDown=function(a,b){var c=this.points;if(c&&!(0>a[1])){var d=this.size[0]-2*this.margin,e=this.size[1]-2*this.margin,g=a[0]-this.margin,f=a[1]-this.margin;this.selected=this.getCloserPoint([g,f],30/b.ds.scale);-1==this.selected&&(d=[g/d,1-f/e],c.push(d),c.sort(function(a,b){return a[0]-b[0]}),this.selected=c.indexOf(d),this.must_update=!0);
if(-1!=this.selected)return!0}};I.prototype.onMouseMove=function(a,b){var c=this.points;if(c){var d=this.selected;if(!(0>d)){var e=(a[0]-this.margin)/(this.size[0]-2*this.margin),g=(a[1]-this.margin)/(this.size[1]-2*this.margin);this._nearest=this.getCloserPoint([a[0]-this.margin,a[1]-this.margin],30/b.ds.scale);var f=c[d];if(f){var m=0==d||d==c.length-1;!m&&(-10>a[0]||a[0]>this.size[0]+10||-10>a[1]||a[1]>this.size[1]+10)?(c.splice(d,1),this.selected=-1):(f[0]=m?0==d?0:1:Math.clamp(e,0,1),f[1]=1-
Math.clamp(g,0,1),c.sort(function(a,b){return a[0]-b[0]}),this.selected=c.indexOf(f),this.must_update=!0)}}}};I.prototype.onMouseUp=function(a,b){this.selected=-1;return!1};I.prototype.getCloserPoint=function(a,b){var c=this.points;if(!c)return-1;b=b||30;for(var d=this.size[0]-2*this.margin,e=this.size[1]-2*this.margin,g=c.length,f=[0,0],m=1E6,h=-1,k=0;k<g;++k){var l=c[k];f[0]=l[0]*d;f[1]=(1-l[1])*e;l=vec2.distance(a,f);l>m||l>b||(h=k,m=l)}return h};h.CurveEditor=I;h.getParameterNames=function(a){return(a+
"").replace(/[/][/].*$/gm,"").replace(/\s+/g,"").replace(/[/][*][^/*]*[*][/]/g,"").split("){",1)[0].replace(/^[^(]*[(]/,"").replace(/=[^,]+/g,"").split(",").filter(Boolean)};Math.clamp=function(a,b,c){return b>a?b:c<a?c:a};"undefined"==typeof window||window.requestAnimationFrame||(window.requestAnimationFrame=window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(a){window.setTimeout(a,1E3/60)})})(this);"undefined"!=typeof exports&&(exports.LiteGraph=this.LiteGraph);
(function(B){function n(){this.addOutput("in ms","number");this.addOutput("in sec","number")}function u(){this.size=[140,80];this.properties={enabled:!0};this.enabled=!0;this.subgraph=new f.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 l(){this.addOutput("","number");this.name_in_graph="";this.properties={name:"",type:"number",value:0};var a=this;this.name_widget=this.addWidget("text",
"Name",this.properties.name,function(b){b&&a.setProperty("name",b)});this.type_widget=this.addWidget("text","Type",this.properties.type,function(b){a.setProperty("type",b)});this.value_widget=this.addWidget("number","Value",this.properties.value,function(b){a.setProperty("value",b)});this.widgets_up=!0;this.size=[180,90]}function r(){this.addInput("","");this.name_in_graph="";this.properties={};var a=this;Object.defineProperty(this.properties,"name",{get:function(){return a.name_in_graph},set:function(b){""!=
b&&b!=a.name_in_graph&&(a.name_in_graph?a.graph.renameOutput(a.name_in_graph,b):a.graph.addOutput(b,a.properties.type),a.name_widget.value=b,a.name_in_graph=b)},enumerable:!0});Object.defineProperty(this.properties,"type",{get:function(){return a.inputs[0].type},set:function(b){if("action"==b||"event"==b)b=f.ACTION;f.isValidConnection(a.inputs[0].type,b)||a.disconnectInput(0);a.inputs[0].type=b;a.name_in_graph&&a.graph.changeOutputType(a.name_in_graph,a.inputs[0].type);a.type_widget.value=b||""},
enumerable:!0});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 v(){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 k(){this.addOutput("","boolean");this.addProperty("value",!0);this.widget=this.addWidget("toggle","value",!0,"value");this.widgets_up=
!0;this.size=[140,30]}function E(){this.addOutput("","string");this.addProperty("value","");this.widget=this.addWidget("text","value","","value");this.widgets_up=!0;this.size=[180,30]}function y(){this.addOutput("obj","object");this.size=[120,30];this._object={}}function A(){this.addInput("url","");this.addOutput("","");this.addProperty("url","");this.addProperty("type","text");this.widget=this.addWidget("text","url","","url");this._data=null}function x(){this.addOutput("","");this.addProperty("value",
"");this.widget=this.addWidget("text","json","","value");this.widgets_up=!0;this.size=[140,30];this._value=null}function I(){this._value=[];this.addInput("","");this.addOutput("","array");this.addOutput("length","number");this.addProperty("value","[]");this.widget=this.addWidget("text","array",this.properties.value,"value");this.widgets_up=!0;this.size=[140,50]}function h(){this.addInput("arr","array");this.addInput("value","");this.addOutput("arr","array");this.properties={index:0};this.widget=this.addWidget("number",
"i",this.properties.index,"index")}function L(){this.addInput("array","array,table,string");this.addInput("index","number");this.addOutput("value","");this.addProperty("index",0)}function G(){this.addInput("table","table");this.addInput("row","number");this.addInput("col","number");this.addOutput("value","");this.addProperty("row",0);this.addProperty("column",0)}function z(){this.addInput("obj","");this.addOutput("","");this.addProperty("value","");this.widget=this.addWidget("text","prop.","",this.setValue.bind(this));
this.widgets_up=!0;this.size=[140,30];this._value=null}function K(){this.addInput("obj","");this.addOutput("keys","array");this.size=[140,30]}function C(){this.addInput("obj","");this.addInput("value","");this.addOutput("obj","");this.properties={property:""};this.name_widget=this.addWidget("text","prop.",this.properties.property,"property")}function H(){this.addInput("A","");this.addInput("B","");this.addOutput("","");this._result={};var a=this;this.addWidget("button","clear","",function(){a._result=
{}});this.size=this.computeSize()}function F(){this.size=[60,30];this.addInput("in");this.addOutput("out");this.properties={varname:"myname",container:F.LITEGRAPH};this.value=null}function a(){this.size=[60,30];this.addInput("data",0);this.addInput("download",f.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 d(){this.mode=f.ON_EVENT;this.size=[80,30];this.addProperty("msg","");this.addInput("log",f.EVENT);this.addInput("msg",0)}function e(){this.mode=f.ON_EVENT;this.addProperty("msg","");this.addInput("",f.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","");this.addInput("B","");this.addOutput("out","");this._func=
null;this.data={}}var f=B.LiteGraph;n.title="Time";n.desc="Time";n.prototype.onExecute=function(){this.setOutputData(0,1E3*this.graph.globaltime);this.setOutputData(1,this.graph.globaltime)};f.registerNodeType("basic/time",n);u.title="Subgraph";u.desc="Graph inside a node";u.title_color="#334";u.prototype.onGetInputs=function(){return[["enabled","boolean"]]};u.prototype.onDblClick=function(a,b,c){var d=this;setTimeout(function(){c.openSubgraph(d.subgraph)},10)};u.prototype.onAction=function(a,b){this.subgraph.onAction(a,
b)};u.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)}};u.prototype.sendEventToAllNodes=function(a,b,c){this.enabled&&this.subgraph.sendEventToAllNodes(a,b,c)};u.prototype.onDrawBackground=
function(a,b,c,d){this.flags.collapsed||(b=this.size[1]-f.NODE_TITLE_HEIGHT+0.5,d=f.isInsideRectangle(d[0],d[1],this.pos[0],this.pos[1]+b,this.size[0],f.NODE_TITLE_HEIGHT),a.fillStyle=d?"#555":"#222",a.beginPath(),this._shape==f.BOX_SHAPE?a.rect(0,b,this.size[0]+1,f.NODE_TITLE_HEIGHT):a.roundRect(0,b,this.size[0]+1,f.NODE_TITLE_HEIGHT,0,8),a.fill(),a.textAlign="center",a.font="24px Arial",a.fillStyle=d?"#DDD":"#999",a.fillText("+",0.5*this.size[0],b+24))};u.prototype.onMouseDown=function(a,b,c){b[1]>
this.size[1]-f.NODE_TITLE_HEIGHT+0.5&&c.showSubgraphPropertiesDialog(this)};u.prototype.computeSize=function(){return[200,Math.max(this.inputs?this.inputs.length:0,this.outputs?this.outputs.length:0)*f.NODE_SLOT_HEIGHT+f.NODE_TITLE_HEIGHT]};u.prototype.onSubgraphTrigger=function(a,b){var c=this.findOutputSlot(a);-1!=c&&this.triggerSlot(c)};u.prototype.onSubgraphNewInput=function(a,b){-1==this.findInputSlot(a)&&this.addInput(a,b)};u.prototype.onSubgraphRenamedInput=function(a,b){var c=this.findInputSlot(a);
-1!=c&&(this.getInputInfo(c).name=b)};u.prototype.onSubgraphTypeChangeInput=function(a,b){var c=this.findInputSlot(a);-1!=c&&(this.getInputInfo(c).type=b)};u.prototype.onSubgraphRemovedInput=function(a){a=this.findInputSlot(a);-1!=a&&this.removeInput(a)};u.prototype.onSubgraphNewOutput=function(a,b){-1==this.findOutputSlot(a)&&this.addOutput(a,b)};u.prototype.onSubgraphRenamedOutput=function(a,b){var c=this.findOutputSlot(a);-1!=c&&(this.getOutputInfo(c).name=b)};u.prototype.onSubgraphTypeChangeOutput=
function(a,b){var c=this.findOutputSlot(a);-1!=c&&(this.getOutputInfo(c).type=b)};u.prototype.onSubgraphRemovedOutput=function(a){a=this.findInputSlot(a);-1!=a&&this.removeOutput(a)};u.prototype.getExtraMenuOptions=function(a){var b=this;return[{content:"Open",callback:function(){a.openSubgraph(b.subgraph)}}]};u.prototype.onResize=function(a){a[1]+=20};u.prototype.serialize=function(){var a=f.LGraphNode.prototype.serialize.call(this);a.subgraph=this.subgraph.serialize();return a};u.prototype.clone=
function(){var a=f.createNode(this.type),b=this.serialize();delete b.id;delete b.inputs;delete b.outputs;a.configure(b);return a};u.prototype.buildFromNodes=function(a){for(var b={},c=0,d=0;d<a.length;++d){var e=a[d];b[e.id]=e;c=Math.min(e.pos[0],c);Math.max(e.pos[0],c)}for(d=0;d<a.length;++d){e=a[d];if(e.inputs)for(c=0;c<e.inputs.length;++c){var f=e.inputs[c];if(f&&f.link){var g=e.graph.links[f.link];g&&(b[g.origin_id]||this.subgraph.addInput(f.name,g.type))}}if(e.outputs)for(c=0;c<e.outputs.length;++c)if((f=
e.outputs[c])&&f.links&&f.links.length)for(var h=0;h<f.links.length&&(!(g=e.graph.links[f.links[h]])||b[g.target_id]);++h);}};f.Subgraph=u;f.registerNodeType("graph/subgraph",u);l.title="Input";l.desc="Input of the graph";l.prototype.onConfigure=function(){this.updateType()};l.prototype.updateType=function(){var a=this.properties.type;this.type_widget.value=a;this.outputs[0].type!=a&&(f.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)};l.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()};l.prototype.getTitle=function(){return this.flags.collapsed?this.properties.name:this.title};l.prototype.onAction=function(a,b){this.properties.type==f.EVENT&&this.triggerSlot(0,b)};l.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)};l.prototype.onRemoved=function(){this.name_in_graph&&this.graph.removeInput(this.name_in_graph)};f.GraphInput=l;f.registerNodeType("graph/input",l);r.title="Output";r.desc="Output of the graph";r.prototype.onExecute=function(){this._value=this.getInputData(0);this.graph.setOutputData(this.properties.name,this._value)};r.prototype.onAction=function(a,b){this.properties.type==f.ACTION&&this.graph.trigger(this.properties.name,b)};r.prototype.onRemoved=function(){this.name_in_graph&&
this.graph.removeOutput(this.name_in_graph)};r.prototype.getTitle=function(){return this.flags.collapsed?this.properties.name:this.title};f.GraphOutput=r;f.registerNodeType("graph/output",r);v.title="Const Number";v.desc="Constant number";v.prototype.onExecute=function(){this.setOutputData(0,parseFloat(this.properties.value))};v.prototype.getTitle=function(){return this.flags.collapsed?this.properties.value:this.title};v.prototype.setValue=function(a){this.setProperty("value",a)};v.prototype.onDrawBackground=
function(a){this.outputs[0].label=this.properties.value.toFixed(3)};f.registerNodeType("basic/const",v);k.title="Const Boolean";k.desc="Constant boolean";k.prototype.getTitle=v.prototype.getTitle;k.prototype.onExecute=function(){this.setOutputData(0,this.properties.value)};k.prototype.setValue=v.prototype.setValue;k.prototype.onGetInputs=function(){return[["toggle",f.ACTION]]};k.prototype.onAction=function(a){this.setValue(!this.properties.value)};f.registerNodeType("basic/boolean",k);E.title="Const String";
E.desc="Constant string";E.prototype.getTitle=v.prototype.getTitle;E.prototype.onExecute=function(){this.setOutputData(0,this.properties.value)};E.prototype.setValue=v.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)};f.registerNodeType("basic/string",E);y.title="Const Object";y.desc="Constant Object";y.prototype.onExecute=function(){this.setOutputData(0,this._object)};f.registerNodeType("basic/object",
y);A.title="Const File";A.desc="Fetches a file from an url";A["@type"]={type:"enum",values:["text","arraybuffer","blob","json"]};A.prototype.onPropertyChanged=function(a,b){"url"==a&&(null==b||""==b?this._data=null:this.fetchFile(b))};A.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)};A.prototype.setValue=v.prototype.setValue;A.prototype.fetchFile=function(a){var b=
this;a&&a.constructor===String?(this._url=a,this._type=this.properties.type,"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.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)};A.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)};
f.registerNodeType("basic/file",A);x.title="Const Data";x.desc="Constant Data";x.prototype.onPropertyChanged=function(a,b){this.widget.value=b;if(null!=b&&""!=b)try{this._value=JSON.parse(b),this.boxcolor="#AEA"}catch(c){this.boxcolor="red"}};x.prototype.onExecute=function(){this.setOutputData(0,this._value)};x.prototype.setValue=v.prototype.setValue;f.registerNodeType("basic/data",x);I.title="Const Array";I.desc="Constant Array";I.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(c){this.boxcolor="red"}};I.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)};I.prototype.setValue=v.prototype.setValue;f.registerNodeType("basic/array",I);h.title="Set Array";h.desc=
"Sets index of array";h.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))}};f.registerNodeType("basic/set_array",h);L.title="Array[i]";L.desc="Returns an element from an array";L.prototype.onExecute=function(){var a=this.getInputData(0),b=this.getInputData(1);null==b&&(b=this.properties.index);null!=a&&null!=b&&this.setOutputData(0,a[Math.floor(Number(b))])};
f.registerNodeType("basic/array[]",L);G.title="Table[row][col]";G.desc="Returns an element from a table";G.prototype.onExecute=function(){var a=this.getInputData(0),b=this.getInputData(1),c=this.getInputData(2);null==b&&(b=this.properties.row);null==c&&(c=this.properties.column);null!=a&&null!=b&&null!=c&&((b=a[Math.floor(Number(b))])?this.setOutputData(0,b[Math.floor(Number(c))]):this.setOutputData(0,null))};f.registerNodeType("basic/table[][]",G);z.title="Object property";z.desc="Outputs the property of an object";
z.prototype.setValue=function(a){this.properties.value=a;this.widget.value=a};z.prototype.getTitle=function(){return this.flags.collapsed?"in."+this.properties.value:this.title};z.prototype.onPropertyChanged=function(a,b){this.widget.value=b};z.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,a[this.properties.value])};f.registerNodeType("basic/object_property",z);K.title="Object keys";K.desc="Outputs an array with the keys of an object";K.prototype.onExecute=
function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,Object.keys(a))};f.registerNodeType("basic/object_keys",K);C.title="Set Object";C.desc="Adds propertiesrty to object";C.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))}};f.registerNodeType("basic/set_object",C);H.title="Merge Objects";H.desc="Creates an object copying properties from others";H.prototype.onExecute=
function(){var a=this.getInputData(0),b=this.getInputData(1),c=this._result;if(a)for(var d in a)c[d]=a[d];if(b)for(d in b)c[d]=b[d];this.setOutputData(0,c)};f.registerNodeType("basic/merge_objects",H);F.title="Variable";F.desc="store/read variable value";F.LITEGRAPH=0;F.GRAPH=1;F.GLOBALSCOPE=2;F["@container"]={type:"enum",values:{litegraph:F.LITEGRAPH,graph:F.GRAPH,global:F.GLOBALSCOPE}};F.prototype.onExecute=function(){var a=this.getContainer();this.isInputConnected(0)?(this.value=this.getInputData(0),
a[this.properties.varname]=this.value,this.setOutputData(0,this.value)):this.setOutputData(0,a[this.properties.varname])};F.prototype.getContainer=function(){switch(this.properties.container){case F.GRAPH:return this.graph?this.graph.vars:{};case F.GLOBALSCOPE:return B;default:return f.Globals}};F.prototype.getTitle=function(){return this.properties.varname};f.registerNodeType("basic/variable",F);f.wrapFunctionAsNode("basic/length",function(a){return a&&null!=a.length?Number(a.length):0},[""],"number");
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]),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};f.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)};f.registerNodeType("basic/watch",b);c.title="Cast";c.desc="Allows to connect different types";c.prototype.onExecute=function(){this.setOutputData(0,this.getInputData(0))};f.registerNodeType("basic/cast",
c);d.title="Console";d.desc="Show value inside the console";d.prototype.onAction=function(a,b){"log"==a?console.log(b):"warn"==a?console.warn(b):"error"==a&&console.error(b)};d.prototype.onExecute=function(){var a=this.getInputData(1);null!==a&&(this.properties.msg=a);console.log(a)};d.prototype.onGetInputs=function(){return[["log",f.ACTION],["warn",f.ACTION],["error",f.ACTION]]};f.registerNodeType("basic/console",d);e.title="Alert";e.desc="Show an alert window";e.color="#510";e.prototype.onConfigure=
function(a){this.widget.value=a.properties.msg};e.prototype.onAction=function(a,b){var c=this.properties.msg;setTimeout(function(){alert(c)},10)};f.registerNodeType("basic/alert",e);g.prototype.onConfigure=function(a){a.properties.onExecute&&f.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 100 characters)";g.widgets_info={onExecute:{type:"code"}};g.prototype.onPropertyChanged=
function(a,b){"onExecute"==a&&f.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(e){console.error("Error parsing script"),
console.error(e)}}};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(d){console.error("Error in script"),console.error(d)}};g.prototype.onGetOutputs=function(){return[["C",""]]};f.registerNodeType("basic/script",g)})(this);
(function(B){function n(){this.size=[60,30];this.addInput("event",x.ACTION)}function u(){this.size=[60,30];this.addInput("if","");this.addOutput("true",x.EVENT);this.addOutput("change",x.EVENT);this.addOutput("false",x.EVENT);this.properties={only_on_change:!0};this.prev=0}function l(){this.addInput("",x.ACTION);this.addInput("",x.ACTION);this.addInput("",x.ACTION);this.addInput("",x.ACTION);this.addInput("",x.ACTION);this.addInput("",x.ACTION);this.addOutput("",x.EVENT);this.addOutput("",x.EVENT);
this.addOutput("",x.EVENT);this.addOutput("",x.EVENT);this.addOutput("",x.EVENT);this.addOutput("",x.EVENT);this.size=[120,30];this.flags={horizontal:!0,render_box:!1}}function r(){this.size=[60,30];this.addInput("event",x.ACTION);this.addOutput("event",x.EVENT);this.properties={equal_to:"",has_property:"",property_equal_to:""}}function v(){this.addInput("in",x.ACTION);this.addInput("cond","boolean");this.addOutput("true",x.EVENT);this.addOutput("false",x.EVENT);this.size=[120,60];this._value=!1}
function k(){this.addInput("inc",x.ACTION);this.addInput("dec",x.ACTION);this.addInput("reset",x.ACTION);this.addOutput("change",x.EVENT);this.addOutput("num","number");this.num=0}function E(){this.size=[60,30];this.addProperty("time_in_ms",1E3);this.addInput("event",x.ACTION);this.addOutput("on_time",x.EVENT);this._pending=[]}function y(){this.addProperty("interval",1E3);this.addProperty("event","tick");this.addOutput("on_tick",x.EVENT);this.time=0;this.last_interval=1E3;this.triggered=!1}function A(){this.addInput("data",
"");this.addInput("assign",x.ACTION);this.addOutput("data","");this._last_value=null;this.properties={data:null,serialize:!0};var k=this;this.addWidget("button","store","",function(){k.properties.data=k._last_value})}var x=B.LiteGraph;n.title="Log Event";n.desc="Log event in console";n.prototype.onAction=function(k,h){console.log(k,h)};x.registerNodeType("events/log",n);u.title="TriggerEvent";u.desc="Triggers event if input evaluates to true";u.prototype.onExecute=function(k,h){var l=this.getInputData(0),
r=l!=this.prev;0===this.prev&&(r=!1);var n=r&&this.properties.only_on_change||!r&&!this.properties.only_on_change;l&&n&&this.triggerSlot(0,h);!l&&n&&this.triggerSlot(2,h);r&&this.triggerSlot(1,h);this.prev=l};x.registerNodeType("events/trigger",u);l.title="Sequencer";l.desc="Trigger events when an event arrives";l.prototype.getTitle=function(){return""};l.prototype.onAction=function(k,h){if(this.outputs)for(var l=0;l<this.outputs.length;++l)this.triggerSlot(l,h)};x.registerNodeType("events/sequencer",
l);r.title="Filter Event";r.desc="Blocks events that do not match the filter";r.prototype.onAction=function(k,h){if(null!=h&&(!this.properties.equal_to||this.properties.equal_to==h)){if(this.properties.has_property){var l=h[this.properties.has_property];if(null==l||this.properties.property_equal_to&&this.properties.property_equal_to!=l)return}this.triggerSlot(0,h)}};x.registerNodeType("events/filter",r);v.title="Branch";v.desc="If condition is true, outputs triggers true, otherwise false";v.prototype.onExecute=
function(){this._value=this.getInputData(1)};v.prototype.onAction=function(k,h){this.triggerSlot(this._value?0:1)};x.registerNodeType("events/branch",v);k.title="Counter";k.desc="Counts events";k.prototype.getTitle=function(){return this.flags.collapsed?String(this.num):this.title};k.prototype.onAction=function(k,h){var l=this.num;"inc"==k?this.num+=1:"dec"==k?this.num-=1:"reset"==k&&(this.num=0);this.num!=l&&this.trigger("change",this.num)};k.prototype.onDrawBackground=function(k){this.flags.collapsed||
(k.fillStyle="#AAA",k.font="20px Arial",k.textAlign="center",k.fillText(this.num,0.5*this.size[0],0.5*this.size[1]))};k.prototype.onExecute=function(){this.setOutputData(1,this.num)};x.registerNodeType("events/counter",k);E.title="Delay";E.desc="Delays one event";E.prototype.onAction=function(k,h){var l=this.properties.time_in_ms;0>=l?this.trigger(null,h):this._pending.push([l,h])};E.prototype.onExecute=function(){var k=1E3*this.graph.elapsed_time;this.isInputConnected(1)&&(this.properties.time_in_ms=
this.getInputData(1));for(var h=0;h<this._pending.length;++h){var l=this._pending[h];l[0]-=k;0<l[0]||(this._pending.splice(h,1),--h,this.trigger(null,l[1]))}};E.prototype.onGetInputs=function(){return[["event",x.ACTION],["time_in_ms","number"]]};x.registerNodeType("events/delay",E);y.title="Timer";y.desc="Sends an event every N milliseconds";y.prototype.onStart=function(){this.time=0};y.prototype.getTitle=function(){return"Timer: "+this.last_interval.toString()+"ms"};y.on_color="#AAA";y.off_color=
"#222";y.prototype.onDrawBackground=function(){this.boxcolor=this.triggered?y.on_color:y.off_color;this.triggered=!1};y.prototype.onExecute=function(){var k=0==this.time;this.time+=1E3*this.graph.elapsed_time;this.last_interval=Math.max(1,this.getInputOrProperty("interval")|0);!k&&(this.time<this.last_interval||isNaN(this.last_interval))?this.inputs&&1<this.inputs.length&&this.inputs[1]&&this.setOutputData(1,!1):(this.triggered=!0,this.time%=this.last_interval,this.trigger("on_tick",this.properties.event),
this.inputs&&1<this.inputs.length&&this.inputs[1]&&this.setOutputData(1,!0))};y.prototype.onGetInputs=function(){return[["interval","number"]]};y.prototype.onGetOutputs=function(){return[["tick","boolean"]]};x.registerNodeType("events/timer",y);A.title="Data Store";A.desc="Stores data and only changes when event is received";A.prototype.onExecute=function(){this._last_value=this.getInputData(0);this.setOutputData(0,this.properties.data)};A.prototype.onAction=function(k,h){this.properties.data=this._last_value};
A.prototype.onSerialize=function(k){null!=k.data&&(!1==this.properties.serialize||k.data.constructor!==String&&k.data.constructor!==Number&&k.data.constructor!==Boolean&&k.data.constructor!==Array&&k.data.constructor!==Object)&&(k.data=null)};x.registerNodeType("basic/data_store",A)})(this);
(function(B){function n(){this.addOutput("left_x_axis","number");this.addOutput("left_y_axis","number");this.addOutput("button_pressed",u.EVENT);this.properties={gamepad_index:0,threshold:0.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 u=B.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 l=this.getGamepad(),r=this.properties.threshold||0;l&&(this._left_axis[0]=Math.abs(l.xbox.axes.lx)>r?l.xbox.axes.lx:0,this._left_axis[1]=Math.abs(l.xbox.axes.ly)>r?l.xbox.axes.ly:0,this._right_axis[0]=Math.abs(l.xbox.axes.rx)>r?l.xbox.axes.rx:0,this._right_axis[1]=Math.abs(l.xbox.axes.ry)>r?l.xbox.axes.ry:0,this._triggers[0]=Math.abs(l.xbox.axes.ltrigger)>r?l.xbox.axes.ltrigger:
0,this._triggers[1]=Math.abs(l.xbox.axes.rtrigger)>r?l.xbox.axes.rtrigger:0);if(this.outputs)for(r=0;r<this.outputs.length;r++){var v=this.outputs[r];if(v.links&&v.links.length){var k=null;if(l)switch(v.name){case "left_axis":k=this._left_axis;break;case "right_axis":k=this._right_axis;break;case "left_x_axis":k=this._left_axis[0];break;case "left_y_axis":k=this._left_axis[1];break;case "right_x_axis":k=this._right_axis[0];break;case "right_y_axis":k=this._right_axis[1];break;case "trigger_left":k=
this._triggers[0];break;case "trigger_right":k=this._triggers[1];break;case "a_button":k=l.xbox.buttons.a?1:0;break;case "b_button":k=l.xbox.buttons.b?1:0;break;case "x_button":k=l.xbox.buttons.x?1:0;break;case "y_button":k=l.xbox.buttons.y?1:0;break;case "lb_button":k=l.xbox.buttons.lb?1:0;break;case "rb_button":k=l.xbox.buttons.rb?1:0;break;case "ls_button":k=l.xbox.buttons.ls?1:0;break;case "rs_button":k=l.xbox.buttons.rs?1:0;break;case "hat_left":k=l.xbox.hatmap&n.LEFT;break;case "hat_right":k=
l.xbox.hatmap&n.RIGHT;break;case "hat_up":k=l.xbox.hatmap&n.UP;break;case "hat_down":k=l.xbox.hatmap&n.DOWN;break;case "hat":k=l.xbox.hatmap;break;case "start_button":k=l.xbox.buttons.start?1:0;break;case "back_button":k=l.xbox.buttons.back?1:0;break;case "button_pressed":for(v=0;v<this._current_buttons.length;++v)this._current_buttons[v]&&!this._previous_buttons[v]&&this.triggerSlot(r,n.buttons[v])}else switch(v.name){case "button_pressed":break;case "left_axis":case "right_axis":k=n.zero;break;
default:k=0}this.setOutputData(r,k)}}};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 l=navigator.getGamepads||navigator.webkitGetGamepads||navigator.mozGetGamepads;if(!l)return null;var r=l.call(navigator),l=null;this._previous_buttons.set(this._current_buttons);for(l=this.properties.gamepad_index;4>l;l++)if(r[l]){l=r[l];r=this.xbox_mapping;r||(r=this.xbox_mapping={axes:[],
buttons:{},hat:"",hatmap:n.CENTER});r.axes.lx=l.axes[0];r.axes.ly=l.axes[1];r.axes.rx=l.axes[2];r.axes.ry=l.axes[3];r.axes.ltrigger=l.buttons[6].value;r.axes.rtrigger=l.buttons[7].value;r.hat="";r.hatmap=n.CENTER;for(var v=0;v<l.buttons.length;v++)if(this._current_buttons[v]=l.buttons[v].pressed,12>v)r.buttons[n.mapping_array[v]]=l.buttons[v].pressed,l.buttons[v].was_pressed&&this.trigger(n.mapping_array[v]+"_button_event");else switch(v){case 12:l.buttons[v].pressed&&(r.hat+="up",r.hatmap|=n.UP);
break;case 13:l.buttons[v].pressed&&(r.hat+="down",r.hatmap|=n.DOWN);break;case 14:l.buttons[v].pressed&&(r.hat+="left",r.hatmap|=n.LEFT);break;case 15:l.buttons[v].pressed&&(r.hat+="right",r.hatmap|=n.RIGHT);break;case 16:r.buttons.home=l.buttons[v].pressed}l.xbox=r;return l}};n.prototype.onDrawBackground=function(l){if(!this.flags.collapsed){var r=this._left_axis,n=this._right_axis;l.strokeStyle="#88A";l.strokeRect(0.5*(r[0]+1)*this.size[0]-4,0.5*(r[1]+1)*this.size[1]-4,8,8);l.strokeStyle="#8A8";
l.strokeRect(0.5*(n[0]+1)*this.size[0]-4,0.5*(n[1]+1)*this.size[1]-4,8,8);r=this.size[1]/this._current_buttons.length;l.fillStyle="#AEB";for(n=0;n<this._current_buttons.length;++n)this._current_buttons[n]&&l.fillRect(0,r*n,6,r)}};n.prototype.onGetOutputs=function(){return[["left_axis","vec2"],["right_axis","vec2"],["left_x_axis","number"],["left_y_axis","number"],["right_x_axis","number"],["right_y_axis","number"],["trigger_left","number"],["trigger_right","number"],["a_button","number"],["b_button",
"number"],["x_button","number"],["y_button","number"],["lb_button","number"],["rb_button","number"],["ls_button","number"],["rs_button","number"],["start_button","number"],["back_button","number"],["a_button_event",u.EVENT],["b_button_event",u.EVENT],["x_button_event",u.EVENT],["y_button_event",u.EVENT],["lb_button_event",u.EVENT],["rb_button_event",u.EVENT],["ls_button_event",u.EVENT],["rs_button_event",u.EVENT],["start_button_event",u.EVENT],["back_button_event",u.EVENT],["hat_left","number"],["hat_right",
"number"],["hat_up","number"],["hat_down","number"],["hat","number"],["button_pressed",u.EVENT]]};u.registerNodeType("input/gamepad",n)})(this);
(function(B){function n(){this.addInput("in","*");this.addOutput("out");this.size=[80,30]}function u(){this.addInput("in");this.addOutput("out");this.size=[80,30]}function l(){this.addInput("in");this.addOutput("out")}function r(){this.addInput("in","number",{locked:!0});this.addOutput("out","number",{locked:!0});this.addOutput("clamped","number",{locked:!0});this.addProperty("in",0);this.addProperty("in_min",0);this.addProperty("in_max",1);this.addProperty("out_min",0);this.addProperty("out_max",
1);this.size=[120,50]}function v(){this.addOutput("value","number");this.addProperty("min",0);this.addProperty("max",1);this.size=[80,30]}function k(){this.addInput("in","number");this.addOutput("out","number");this.addProperty("min",0);this.addProperty("max",1);this.addProperty("smooth",!0);this.addProperty("seed",0);this.addProperty("octaves",1);this.addProperty("persistence",0.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",0.2);this.size=[90,30];this._blink_time=this._remaining_time=0}function y(){this.addInput("in","number");this.addOutput("out","number");this.size=[80,30];this.addProperty("min",0);this.addProperty("max",1)}function A(){this.properties={f:0.5};this.addInput("A","number");this.addInput("B","number");this.addOutput("out","number")}function x(){this.addInput("in","number");this.addOutput("out","number");this.size=[80,30]}function I(){this.addInput("in",
"number");this.addOutput("out","number");this.size=[80,30]}function h(){this.addInput("in","number");this.addOutput("out","number");this.size=[80,30]}function L(){this.addInput("in","number");this.addOutput("out","number");this.size=[80,30];this.properties={A:0,B:1}}function G(){this.addInput("in","number",{label:""});this.addOutput("out","number",{label:""});this.size=[80,30];this.addProperty("factor",1)}function z(){this.addInput("v","boolean");this.addInput("A");this.addInput("B");this.addOutput("out")}
function K(){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 C(){this.addInput("in","number");this.addOutput("out","number");this.addProperty("factor",0.1);this.size=[80,30];this._value=null}function H(){this.addInput("A","number,array,object");this.addInput("B","number");this.addOutput("=","number");this.addProperty("A",1);this.addProperty("B",1);this.addProperty("OP","+","enum",
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()}};m.prototype.getNodeById=function(a){return null==a?null:this._nodes_by_id[a]};m.prototype.findNodesByClass=function(a,b){b=b||[];for(var c=b.length=
0,d=this._nodes.length;c<d;++c)this._nodes[c].constructor===a&&b.push(this._nodes[c]);return b};m.prototype.findNodesByType=function(a,b){a=a.toLowerCase();b=b||[];for(var c=b.length=0,d=this._nodes.length;c<d;++c)this._nodes[c].type.toLowerCase()==a&&b.push(this._nodes[c]);return b};m.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};m.prototype.findNodesByTitle=function(a){for(var b=[],c=0,d=this._nodes.length;c<
d;++c)this._nodes[c].title==a&&b.push(this._nodes[c]);return b};m.prototype.getNodeOnPos=function(a,b,c,d){c=c||this._nodes;for(var e=c.length-1;0<=e;e--){var f=c[e];if(f.isPointInside(a,b,d))return f}return null};m.prototype.getGroupOnPos=function(a,b){for(var c=this._groups.length-1;0<=c;c--){var d=this._groups[c];if(d.isPointInside(a,b,2,!0))return d}return null};m.prototype.checkNodeTypes=function(){for(var a=0;a<this._nodes.length;a++){var b=this._nodes[a];if(b.constructor!=l.registered_node_types[b.type]){console.log("node being replaced by newer version: "+
b.type);var c=l.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()};m.prototype.onAction=function(a,b){this._input_nodes=this.findNodesByClass(l.GraphInput,this._input_nodes);for(var c=0;c<this._input_nodes.length;++c){var d=this._input_nodes[c];if(d.properties.name==a){d.onAction(a,b);break}}};m.prototype.trigger=function(a,b){if(this.onTrigger)this.onTrigger(a,
b)};m.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()}};m.prototype.setInputData=function(a,b){if(a=this.inputs[a])a.value=b};m.prototype.getInputData=function(a){return(a=this.inputs[a])?a.value:null};m.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()}};m.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)};m.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};m.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()};m.prototype.setOutputData=function(a,b){if(a=this.outputs[a])a.value=b};m.prototype.getOutputData=function(a){return(a=this.outputs[a])?a.value:null};
m.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()};m.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)};m.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};m.prototype.triggerInput=function(a,b){a=this.findNodesByTitle(a);for(var c=0;c<a.length;++c)a[c].onTrigger(b)};m.prototype.setCallback=function(a,b){a=this.findNodesByTitle(a);for(var c=0;c<a.length;++c)a[c].setTrigger(b)};
m.prototype.beforeChange=function(a){if(this.onBeforeChange)this.onBeforeChange(this,a);this.sendActionToCanvas("onBeforeChange",this)};m.prototype.afterChange=function(a){if(this.onAfterChange)this.onAfterChange(this,a);this.sendActionToCanvas("onAfterChange",this)};m.prototype.connectionChange=function(a,b){this.updateExecutionOrder();if(this.onConnectionChange)this.onConnectionChange(a);this._version++;this.sendActionToCanvas("onConnectionChange")};m.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};m.prototype.clearTriggeredSlots=function(){for(var a in this.links){var b=this.links[a];b&&b._last_time&&(b._last_time=0)}};m.prototype.change=function(){l.debug&&console.log("Graph changed");this.sendActionToCanvas("setDirty",[!0,!0]);if(this.on_change)this.on_change(this)};m.prototype.setDirtyCanvas=function(a,b){this.sendActionToCanvas("setDirty",[a,b])};m.prototype.removeLink=function(a){if(a=
this.links[a]){var b=this.getNodeById(a.target_id);b&&b.disconnectInput(a.target_slot)}};m.prototype.serialize=function(){for(var a=[],b=0,c=this._nodes.length;b<c;++b)a.push(this._nodes[b].serialize());c=[];for(b in this.links){var d=this.links[b];if(!d.serialize){console.warn("weird LLink bug, link info is not a LLink but a regular object");var e=new q;for(f in d)e[f]=d[f];d=this.links[b]=e}c.push(d.serialize())}var f=[];for(b=0;b<this._groups.length;++b)f.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:f,config:this.config,extra:this.extra,version:l.VERSION};if(this.onSerialize)this.onSerialize(a);return a};m.prototype.configure=function(a,b){if(a){b||this.clear();b=a.nodes;if(a.links&&a.links.constructor===Array){for(var c=[],d=0;d<a.links.length;++d){var e=a.links[d];if(e){var f=new q;f.configure(e);c[f.id]=f}else console.warn("serialized graph link data contains errors, skipping.")}a.links=c}for(d in a)"nodes"!=d&&"groups"!=d&&(this[d]=a[d]);
c=!1;this._nodes=[];if(b){d=0;for(e=b.length;d<e;++d){f=b[d];var g=l.createNode(f.type,f.title);g||(l.debug&&console.log("Node not found or has errors: "+f.type),g=new k,g.last_serialization=f,c=g.has_errors=!0);g.id=f.id;this.add(g,!0)}d=0;for(e=b.length;d<e;++d)f=b[d],(g=this.getNodeById(f.id))&&g.configure(f)}this._groups.length=0;if(a.groups)for(d=0;d<a.groups.length;++d)b=new l.LGraphGroup,b.configure(a.groups[d]),this.add(b);this.updateExecutionOrder();this.extra=a.extra||{};if(this.onConfigure)this.onConfigure(a);
this._version++;this.setDirtyCanvas(!0,!0);return c}};m.prototype.load=function(a,b){var c=this;if(a.constructor===File||a.constructor===Blob){var d=new FileReader;d.addEventListener("load",function(a){a=JSON.parse(a.target.result);c.configure(a);b&&b()});d.readAsText(a)}else{var e=new XMLHttpRequest;e.open("GET",a,!0);e.send(null);e.onload=function(a){200!==e.status?console.error("Error loading graph:",e.status,e.response):(a=JSON.parse(e.response),c.configure(a),b&&b())};e.onerror=function(a){console.error("Error loading graph:",
a)}}};m.prototype.onNodeTrace=function(a,b,c){};q.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)};q.prototype.serialize=function(){return[this.id,this.origin_id,this.origin_slot,this.target_id,this.target_slot,this.type]};l.LLink=q;
v.LGraphNode=l.LGraphNode=k;k.prototype._ctor=function(a){this.title=a||"Unnamed";this.size=[l.NODE_WIDTH,60];this.graph=null;this._pos=new Float32Array(10,10);Object.defineProperty(this,"pos",{set:function(a){!a||2>a.length||(this._pos[0]=a[0],this._pos[1]=a[1])},get:function(){return this._pos},enumerable:!0});this.id=-1;this.type=null;this.inputs=[];this.outputs=[];this.connections=[];this.properties={};this.properties_info=[];this.flags={}};k.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]=l.cloneObject(a[b],this[b]):this[b]=a[b]);a.title||(this.title=this.constructor.title);if(this.onConnectionsChange){if(this.inputs)for(c=0;c<this.inputs.length;++c){b=this.inputs[c];var d=this.graph?this.graph.links[b.link]:null;this.onConnectionsChange(l.INPUT,
c,!0,d,b)}if(this.outputs)for(c=0;c<this.outputs.length;++c){var e=this.outputs[c];if(e.links)for(b=0;b<e.links.length;++b)d=this.graph?this.graph.links[e.links[b]]:null,this.onConnectionsChange(l.OUTPUT,c,!0,d,e)}}if(this.widgets){for(c=0;c<this.widgets.length;++c)(b=this.widgets[c])&&b.options&&b.options.property&&this.properties[b.options.property]&&(b.value=JSON.parse(JSON.stringify(this.properties[b.options.property])));if(a.widgets_values)for(c=0;c<a.widgets_values.length;++c)this.widgets[c]&&
(this.widgets[c].value=a.widgets_values[c])}if(this.onConfigure)this.onConfigure(a)};k.prototype.serialize=function(){var a={id:this.id,type:this.type,pos:this.pos,size:this.size,flags:l.cloneObject(this.flags),order:this.order,mode:this.mode};if(this.constructor===k&&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=l.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};k.prototype.clone=function(){var a=l.createNode(this.type);if(!a)return null;var b=l.cloneObject(this.serialize());if(b.inputs)for(var c=0;c<b.inputs.length;++c)b.inputs[c].link=null;if(b.outputs)for(c=0;c<b.outputs.length;++c)b.outputs[c].links&&(b.outputs[c].links.length=0);delete b.id;a.configure(b);return a};k.prototype.toString=function(){return JSON.stringify(this.serialize())};k.prototype.getTitle=function(){return this.title||this.constructor.title};k.prototype.setProperty=function(a,
b){this.properties||(this.properties={});if(b!==this.properties[a]){var c=this.properties[a];this.properties[a]=b;this.onPropertyChanged&&!1===this.onPropertyChanged(a,b,c)&&(this.properties[a]=c);if(this.widgets)for(c=0;c<this.widgets.length;++c){var d=this.widgets[c];if(d&&d.options.property==a){d.value=b;break}}}};k.prototype.setOutputData=function(a,b){if(this.outputs&&!(-1==a||a>=this.outputs.length)){var c=this.outputs[a];if(c&&(c._data=b,this.outputs[a].links))for(c=0;c<this.outputs[a].links.length;c++){var d=
this.graph.links[this.outputs[a].links[c]];d&&(d.data=b)}}};k.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}};k.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}};k.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};k.prototype.getInputDataByName=function(a,b){a=this.findInputSlot(a);return-1==a?null:this.getInputData(a,
b)};k.prototype.isInputConnected=function(a){return this.inputs?a<this.inputs.length&&null!=this.inputs[a].link:!1};k.prototype.getInputInfo=function(a){return this.inputs?a<this.inputs.length?this.inputs[a]:null:null};k.prototype.getInputLink=function(a){return this.inputs?a<this.inputs.length?this.graph.links[this.inputs[a].link]:null:null};k.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};k.prototype.getInputOrProperty=function(a){if(!this.inputs||!this.inputs.length)return this.properties?this.properties[a]:null;for(var b=0,c=this.inputs.length;b<c;++b){var d=this.inputs[b];if(a==d.name&&null!=d.link&&(d=this.graph.links[d.link]))return d.data}return this.properties[a]};k.prototype.getOutputData=function(a){return!this.outputs||a>=this.outputs.length?null:this.outputs[a]._data};k.prototype.getOutputInfo=function(a){return this.outputs?
a<this.outputs.length?this.outputs[a]:null:null};k.prototype.isOutputConnected=function(a){return this.outputs?a<this.outputs.length&&this.outputs[a].links&&this.outputs[a].links.length:!1};k.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};k.prototype.getOutputNodes=function(a){if(!this.outputs||0==this.outputs.length||a>=this.outputs.length)return null;a=this.outputs[a];
if(!a.links||0==a.links.length)return null;for(var b=[],c=0;c<a.links.length;c++){var d=this.graph.links[a.links[c]];d&&(d=this.graph.getNodeById(d.target_id))&&b.push(d)}return b};k.prototype.trigger=function(a,b){if(this.outputs&&this.outputs.length){this.graph&&(this.graph._last_trigger_time=l.getTime());for(var c=0;c<this.outputs.length;++c){var d=this.outputs[c];!d||d.type!==l.EVENT||a&&d.name!=a||this.triggerSlot(c,b)}}};k.prototype.triggerSlot=function(a,b,c){if(this.outputs&&(a=this.outputs[a])&&
(a=a.links)&&a.length){this.graph&&(this.graph._last_trigger_time=l.getTime());for(var d=0;d<a.length;++d){var e=a[d];if(null==c||c==e){var f=this.graph.links[a[d]];if(f&&(f._last_time=l.getTime(),e=this.graph.getNodeById(f.target_id)))if(f=e.inputs[f.target_slot],e.mode===l.ON_TRIGGER){if(e.onExecute)e.onExecute(b)}else if(e.onAction)e.onAction(f.name,b)}}}};k.prototype.clearTriggeredSlot=function(a,b){if(this.outputs&&(a=this.outputs[a])&&(a=a.links)&&a.length)for(var c=0;c<a.length;++c){var d=
a[c];if(null==b||b==d)if(d=this.graph.links[a[c]])d._last_time=0}};k.prototype.setSize=function(a){this.size=a;if(this.onResize)this.onResize(this.size)};k.prototype.addProperty=function(a,b,c,d){c={name:a,type:c,default_value:b};if(d)for(var e in d)c[e]=d[e];this.properties_info||(this.properties_info=[]);this.properties_info.push(c);this.properties||(this.properties={});this.properties[a]=b;return c};k.prototype.addOutput=function(a,b,c){a={name:a,type:b,links:null};if(c)for(var d in c)a[d]=c[d];
this.outputs||(this.outputs=[]);this.outputs.push(a);if(this.onOutputAdded)this.onOutputAdded(a);this.setSize(this.computeSize());this.setDirtyCanvas(!0,!0);return a};k.prototype.addOutputs=function(a){for(var b=0;b<a.length;++b){var c=a[b],d={name:c[0],type:c[1],link:null};if(a[2])for(var e in c[2])d[e]=c[2][e];this.outputs||(this.outputs=[]);this.outputs.push(d);if(this.onOutputAdded)this.onOutputAdded(d)}this.setSize(this.computeSize());this.setDirtyCanvas(!0,!0)};k.prototype.removeOutput=function(a){this.disconnectOutput(a);
this.outputs.splice(a,1);for(var b=a;b<this.outputs.length;++b)if(this.outputs[b]&&this.outputs[b].links)for(var c=this.outputs[b].links,d=0;d<c.length;++d){var e=this.graph.links[c[d]];e&&--e.origin_slot}this.setSize(this.computeSize());if(this.onOutputRemoved)this.onOutputRemoved(a);this.setDirtyCanvas(!0,!0)};k.prototype.addInput=function(a,b,c){a={name:a,type:b||0,link:null};if(c)for(var d in c)a[d]=c[d];this.inputs||(this.inputs=[]);this.inputs.push(a);this.setSize(this.computeSize());if(this.onInputAdded)this.onInputAdded(a);
this.setDirtyCanvas(!0,!0);return a};k.prototype.addInputs=function(a){for(var b=0;b<a.length;++b){var c=a[b],d={name:c[0],type:c[1],link:null};if(a[2])for(var e in c[2])d[e]=c[2][e];this.inputs||(this.inputs=[]);this.inputs.push(d);if(this.onInputAdded)this.onInputAdded(d)}this.setSize(this.computeSize());this.setDirtyCanvas(!0,!0)};k.prototype.removeInput=function(a){this.disconnectInput(a);for(var b=this.inputs.splice(a,1),c=a;c<this.inputs.length;++c)if(this.inputs[c]){var d=this.graph.links[this.inputs[c].link];
d&&--d.target_slot}this.setSize(this.computeSize());if(this.onInputRemoved)this.onInputRemoved(a,b[0]);this.setDirtyCanvas(!0,!0)};k.prototype.addConnection=function(a,b,c,d){a={name:a,type:b,pos:c,direction:d,links:null};this.connections.push(a);return a};k.prototype.computeSize=function(a){function b(a){return a?d*a.length*.6:0}if(this.constructor.size)return this.constructor.size.concat();var c=Math.max(this.inputs?this.inputs.length:1,this.outputs?this.outputs.length:1);a=a||new Float32Array([0,
0]);c=Math.max(c,1);var d=l.NODE_TEXT_SIZE,e=b(this.title),f=0,g=0;if(this.inputs)for(var n=0,r=this.inputs.length;n<r;++n){var h=this.inputs[n];h=h.label||h.name||"";h=b(h);f<h&&(f=h)}if(this.outputs)for(n=0,r=this.outputs.length;n<r;++n)h=this.outputs[n],h=h.label||h.name||"",h=b(h),g<h&&(g=h);a[0]=Math.max(f+g+10,e);a[0]=Math.max(a[0],l.NODE_WIDTH);this.widgets&&this.widgets.length&&(a[0]=Math.max(a[0],1.5*l.NODE_WIDTH));a[1]=(this.constructor.slot_start_y||0)+c*l.NODE_SLOT_HEIGHT;c=0;if(this.widgets&&
this.widgets.length){n=0;for(r=this.widgets.length;n<r;++n)c=this.widgets[n].computeSize?c+(this.widgets[n].computeSize(a[0])[1]+4):c+(l.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};k.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};k.prototype.addWidget=function(a,b,c,d,e){this.widgets||(this.widgets=[]);!e&&d&&d.constructor===Object&&(e=d,d=null);e&&e.constructor===String&&(e={property:e});
d&&d.constructor===String&&(e||(e={}),e.property=d,d=null);d&&d.constructor!==Function&&(console.warn("addWidget: callback must be a function"),d=null);b={type:a.toLowerCase(),name:b,value:c,callback:d,options:e||{}};void 0!==b.options.y&&(b.y=b.options.y);d||b.options.callback||b.options.property||console.warn("LiteGraph addWidget(...) without a callback or property assigned");if("combo"==a&&!b.options.values)throw"LiteGraph addWidget('combo',...) requires to pass values in options: { values:['red','blue'] }";
this.widgets.push(b);this.setSize(this.computeSize());return b};k.prototype.addCustomWidget=function(a){this.widgets||(this.widgets=[]);this.widgets.push(a);return a};k.prototype.getBounding=function(a){a=a||new Float32Array(4);a[0]=this.pos[0]-4;a[1]=this.pos[1]-l.NODE_TITLE_HEIGHT;a[2]=this.size[0]+4;a[3]=this.flags.collapsed?l.NODE_TITLE_HEIGHT:this.size[1]+l.NODE_TITLE_HEIGHT;if(this.onBounding)this.onBounding(a);return a};k.prototype.isPointInside=function(a,b,c,d){c=c||0;var e=this.graph&&this.graph.isLive()?
0:l.NODE_TITLE_HEIGHT;d&&(e=0);if(this.flags&&this.flags.collapsed){if(C(a,b,this.pos[0]-c,this.pos[1]-l.NODE_TITLE_HEIGHT-c,(this._collapsed_width||l.NODE_COLLAPSED_WIDTH)+2*c,l.NODE_TITLE_HEIGHT+2*c))return!0}else if(this.pos[0]-4-c<a&&this.pos[0]+this.size[0]+4+c>a&&this.pos[1]-e-c<b&&this.pos[1]+this.size[1]+c>b)return!0;return!1};k.prototype.getSlotInPosition=function(a,b){var c=new Float32Array(2);if(this.inputs)for(var d=0,e=this.inputs.length;d<e;++d){var f=this.inputs[d];this.getConnectionPos(!0,
d,c);if(C(a,b,c[0]-10,c[1]-5,20,10))return{input:f,slot:d,link_pos:c}}if(this.outputs)for(d=0,e=this.outputs.length;d<e;++d)if(f=this.outputs[d],this.getConnectionPos(!1,d,c),C(a,b,c[0]-10,c[1]-5,20,10))return{output:f,slot:d,link_pos:c};return null};k.prototype.findInputSlot=function(a){if(!this.inputs)return-1;for(var b=0,c=this.inputs.length;b<c;++b)if(a==this.inputs[b].name)return b;return-1};k.prototype.findOutputSlot=function(a){if(!this.outputs)return-1;for(var b=0,c=this.outputs.length;b<
c;++b)if(a==this.outputs[b].name)return b;return-1};k.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 l.debug&&console.log("Connect: Error, no slot of name "+a),null}else if(!this.outputs||a>=this.outputs.length)return l.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 l.debug&&console.log("Connect: Error, no slot of name "+c),null}else{if(c===l.EVENT)return null;if(!b.inputs||c>=b.inputs.length)return l.debug&&console.log("Connect: Error, slot number not found"),null}var d=!1;null!=b.inputs[c].link&&(this.graph.beforeChange(),b.disconnectInput(c),d=!0);var e=this.outputs[a];if(b.onConnectInput&&
!1===b.onConnectInput(c,e.type,e,this,a))return null;var f=b.inputs[c],g=null;if(!l.isValidConnection(e.type,f.type))return this.setDirtyCanvas(!1,!0),d&&this.graph.connectionChange(this,g),null;d||this.graph.beforeChange();g=new q(++this.graph.last_link_id,f.type,this.id,a,b.id,c);this.graph.links[g.id]=g;null==e.links&&(e.links=[]);e.links.push(g.id);b.inputs[c].link=g.id;this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(l.OUTPUT,a,!0,g,e);if(b.onConnectionsChange)b.onConnectionsChange(l.INPUT,
c,!0,g,f);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(l.INPUT,b,c,this,a),this.graph.onNodeConnectionChange(l.OUTPUT,this,a,b,c));this.setDirtyCanvas(!1,!0);this.graph.afterChange();this.graph.connectionChange(this,g);return g};k.prototype.disconnectOutput=function(a,b){if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return l.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.outputs||a>=this.outputs.length)return l.debug&&
console.log("Connect: Error, slot number not found"),!1;var c=this.outputs[a];if(!c||!c.links||0==c.links.length)return!1;if(b){b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"Target Node not found";for(var d=0,e=c.links.length;d<e;d++){var f=c.links[d],g=this.graph.links[f];if(g.target_id==b.id){c.links.splice(d,1);var n=b.inputs[g.target_slot];n.link=null;delete this.graph.links[f];this.graph&&this.graph._version++;if(b.onConnectionsChange)b.onConnectionsChange(l.INPUT,g.target_slot,
!1,g,n);if(this.onConnectionsChange)this.onConnectionsChange(l.OUTPUT,a,!1,g,c);if(this.graph&&this.graph.onNodeConnectionChange)this.graph.onNodeConnectionChange(l.OUTPUT,this,a);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(l.OUTPUT,this,a),this.graph.onNodeConnectionChange(l.INPUT,b,g.target_slot));break}}}else{d=0;for(e=c.links.length;d<e;d++)if(f=c.links[d],g=this.graph.links[f]){b=this.graph.getNodeById(g.target_id);this.graph&&this.graph._version++;if(b){n=
b.inputs[g.target_slot];n.link=null;if(b.onConnectionsChange)b.onConnectionsChange(l.INPUT,g.target_slot,!1,g,n);if(this.graph&&this.graph.onNodeConnectionChange)this.graph.onNodeConnectionChange(l.INPUT,b,g.target_slot)}delete this.graph.links[f];if(this.onConnectionsChange)this.onConnectionsChange(l.OUTPUT,a,!1,g,c);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(l.OUTPUT,this,a),this.graph.onNodeConnectionChange(l.INPUT,b,g.target_slot))}c.links=null}this.setDirtyCanvas(!1,
!0);this.graph.connectionChange(this);return!0};k.prototype.disconnectInput=function(a){if(a.constructor===String){if(a=this.findInputSlot(a),-1==a)return l.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.inputs||a>=this.inputs.length)return l.debug&&console.log("Connect: Error, slot number not found"),!1;var b=this.inputs[a];if(!b)return!1;var c=this.inputs[a].link;if(null!=c){this.inputs[a].link=null;var d=this.graph.links[c];if(d){var e=this.graph.getNodeById(d.origin_id);
if(!e)return!1;var f=e.outputs[d.origin_slot];if(!f||!f.links||0==f.links.length)return!1;for(var g=0,n=f.links.length;g<n;g++)if(f.links[g]==c){f.links.splice(g,1);break}delete this.graph.links[c];this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(l.INPUT,a,!1,d,b);if(e.onConnectionsChange)e.onConnectionsChange(l.OUTPUT,g,!1,d,f);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(l.OUTPUT,e,g),this.graph.onNodeConnectionChange(l.INPUT,
this,a))}}this.setDirtyCanvas(!1,!0);this.graph&&this.graph.connectionChange(this);return!0};k.prototype.getConnectionPos=function(a,b,c){c=c||new Float32Array(2);var d=0;a&&this.inputs&&(d=this.inputs.length);!a&&this.outputs&&(d=this.outputs.length);var e=.5*l.NODE_SLOT_HEIGHT;if(this.flags.collapsed)return b=this._collapsed_width||l.NODE_COLLAPSED_WIDTH,this.horizontal?(c[0]=this.pos[0]+.5*b,c[1]=a?this.pos[1]-l.NODE_TITLE_HEIGHT:this.pos[1]):(c[0]=a?this.pos[0]:this.pos[0]+b,c[1]=this.pos[1]-
.5*l.NODE_TITLE_HEIGHT),c;if(a&&-1==b)return c[0]=this.pos[0]+.5*l.NODE_TITLE_HEIGHT,c[1]=this.pos[1]+.5*l.NODE_TITLE_HEIGHT,c;if(a&&d>b&&this.inputs[b].pos)return c[0]=this.pos[0]+this.inputs[b].pos[0],c[1]=this.pos[1]+this.inputs[b].pos[1],c;if(!a&&d>b&&this.outputs[b].pos)return c[0]=this.pos[0]+this.outputs[b].pos[0],c[1]=this.pos[1]+this.outputs[b].pos[1],c;if(this.horizontal)return c[0]=this.pos[0]+this.size[0]/d*(b+.5),c[1]=a?this.pos[1]-l.NODE_TITLE_HEIGHT:this.pos[1]+this.size[1],c;c[0]=
a?this.pos[0]+e:this.pos[0]+this.size[0]+1-e;c[1]=this.pos[1]+(b+.7)*l.NODE_SLOT_HEIGHT+(this.constructor.slot_start_y||0);return c};k.prototype.alignToGrid=function(){this.pos[0]=l.CANVAS_GRID_SIZE*Math.round(this.pos[0]/l.CANVAS_GRID_SIZE);this.pos[1]=l.CANVAS_GRID_SIZE*Math.round(this.pos[1]/l.CANVAS_GRID_SIZE)};k.prototype.trace=function(a){this.console||(this.console=[]);this.console.push(a);this.console.length>k.MAX_CONSOLE&&this.console.shift();if(this.graph.onNodeTrace)this.graph.onNodeTrace(this,
a)};k.prototype.setDirtyCanvas=function(a,b){this.graph&&this.graph.sendActionToCanvas("setDirty",[a,b])};k.prototype.loadImage=function(a){var b=new Image;b.src=l.node_images_path+a;b.ready=!1;var c=this;b.onload=function(){this.ready=!0;c.setDirtyCanvas(!0)};return b};k.prototype.captureInput=function(a){if(this.graph&&this.graph.list_of_graphcanvas)for(var b=this.graph.list_of_graphcanvas,c=0;c<b.length;++c){var d=b[c];if(a||d.node_capturing_input==this)d.node_capturing_input=a?this:null}};k.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)};k.prototype.pin=function(a){this.graph._version++;this.flags.pinned=void 0===a?!this.flags.pinned:a};k.prototype.localToScreen=function(a,b,c){return[(a+this.pos[0])*c.scale+c.offset[0],(b+this.pos[1])*c.scale+c.offset[1]]};v.LGraphGroup=l.LGraphGroup=t;t.prototype._ctor=function(a){this.title=a||"Group";this.font_size=24;this.color=h.node_colors.pale_blue?
h.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})};t.prototype.configure=function(a){this.title=a.title;this._bounding.set(a.bounding);this.color=a.color;this.font=a.font};t.prototype.serialize=function(){var a=this._bounding;return{title:this.title,bounding:[Math.round(a[0]),Math.round(a[1]),Math.round(a[2]),Math.round(a[3])],color:this.color,font:this.font}};t.prototype.move=function(a,b,c){this._pos[0]+=a;this._pos[1]+=b;if(!c)for(c=0;c<this._nodes.length;++c){var d=this._nodes[c];d.pos[0]+=a;d.pos[1]+=b}};t.prototype.recomputeInsideNodes=
function(){this._nodes.length=0;for(var a=this.graph._nodes,b=new Float32Array(4),c=0;c<a.length;++c){var d=a[c];d.getBounding(b);B(this._bounding,b)&&this._nodes.push(d)}};t.prototype.isPointInside=k.prototype.isPointInside;t.prototype.setDirtyCanvas=k.prototype.setDirtyCanvas;l.DragAndScale=w;w.prototype.bindEvents=function(a){this.last_mouse=new Float32Array(2);this._binded_mouse_callback=this.onMouse.bind(this);a.addEventListener("mousedown",this._binded_mouse_callback);a.addEventListener("mousemove",
this._binded_mouse_callback);a.addEventListener("mousewheel",this._binded_mouse_callback,!1);a.addEventListener("wheel",this._binded_mouse_callback,!1)};w.prototype.computeVisibleArea=function(a){if(this.element){var b=this.element.width,c=this.element.height,d=-this.offset[0],e=-this.offset[1];a&&(d+=a[0]/this.scale,e+=a[1]/this.scale,b=a[2],c=a[3]);a=d+b/this.scale;c=e+c/this.scale;this.visible_area[0]=d;this.visible_area[1]=e;this.visible_area[2]=a-d;this.visible_area[3]=c-e}else this.visible_area[0]=
this.visible_area[1]=this.visible_area[2]=this.visible_area[3]=0};w.prototype.onMouse=function(a){if(this.enabled){var b=this.element,c=b.getBoundingClientRect(),d=a.clientX-c.left;c=a.clientY-c.top;a.canvasx=d;a.canvasy=c;a.dragging=this.dragging;var e=!this.viewport||this.viewport&&d>=this.viewport[0]&&d<this.viewport[0]+this.viewport[2]&&c>=this.viewport[1]&&c<this.viewport[1]+this.viewport[3],f=!1;this.onmouse&&(f=this.onmouse(a));"mousedown"==a.type&&e?(this.dragging=!0,b.removeEventListener("mousemove",
this._binded_mouse_callback),document.body.addEventListener("mousemove",this._binded_mouse_callback),document.body.addEventListener("mouseup",this._binded_mouse_callback)):"mousemove"==a.type?f||(b=d-this.last_mouse[0],f=c-this.last_mouse[1],this.dragging&&this.mouseDrag(b,f)):"mouseup"==a.type?(this.dragging=!1,document.body.removeEventListener("mousemove",this._binded_mouse_callback),document.body.removeEventListener("mouseup",this._binded_mouse_callback),b.addEventListener("mousemove",this._binded_mouse_callback)):
!e||"mousewheel"!=a.type&&"wheel"!=a.type&&"DOMMouseScroll"!=a.type||(a.eventType="mousewheel",a.wheel="wheel"==a.type?-a.deltaY:null!=a.wheelDeltaY?a.wheelDeltaY:-60*a.detail,a.delta=a.wheelDelta?a.wheelDelta/40:a.deltaY?-a.deltaY/3:0,this.changeDeltaScale(1+.05*a.delta));this.last_mouse[0]=d;this.last_mouse[1]=c;if(e)return a.preventDefault(),a.stopPropagation(),!1}};w.prototype.toCanvasContext=function(a){a.scale(this.scale,this.scale);a.translate(this.offset[0],this.offset[1])};w.prototype.convertOffsetToCanvas=
function(a){return[(a[0]+this.offset[0])*this.scale,(a[1]+this.offset[1])*this.scale]};w.prototype.convertCanvasToOffset=function(a,b){b=b||[0,0];b[0]=a[0]/this.scale-this.offset[0];b[1]=a[1]/this.scale-this.offset[1];return b};w.prototype.mouseDrag=function(a,b){this.offset[0]+=a/this.scale;this.offset[1]+=b/this.scale;if(this.onredraw)this.onredraw(this)};w.prototype.changeScale=function(a,b){a<this.min_scale?a=this.min_scale:a>this.max_scale&&(a=this.max_scale);if(a!=this.scale&&this.element){var c=
this.element.getBoundingClientRect();if(c&&(b=b||[.5*c.width,.5*c.height],c=this.convertCanvasToOffset(b),this.scale=a,.01>Math.abs(this.scale-1)&&(this.scale=1),a=this.convertCanvasToOffset(b),a=[a[0]-c[0],a[1]-c[1]],this.offset[0]+=a[0],this.offset[1]+=a[1],this.onredraw))this.onredraw(this)}};w.prototype.changeDeltaScale=function(a,b){this.changeScale(this.scale*a,b)};w.prototype.reset=function(){this.scale=1;this.offset[0]=0;this.offset[1]=0};v.LGraphCanvas=l.LGraphCanvas=h;h.DEFAULT_BACKGROUND_IMAGE=
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQBJREFUeNrs1rEKwjAUhlETUkj3vP9rdmr1Ysammk2w5wdxuLgcMHyptfawuZX4pJSWZTnfnu/lnIe/jNNxHHGNn//HNbbv+4dr6V+11uF527arU7+u63qfa/bnmh8sWLBgwYJlqRf8MEptXPBXJXa37BSl3ixYsGDBMliwFLyCV/DeLIMFCxYsWLBMwSt4Be/NggXLYMGCBUvBK3iNruC9WbBgwYJlsGApeAWv4L1ZBgsWLFiwYJmCV/AK3psFC5bBggULloJX8BpdwXuzYMGCBctgwVLwCl7Be7MMFixYsGDBsu8FH1FaSmExVfAxBa/gvVmwYMGCZbBg/W4vAQYA5tRF9QYlv/QAAAAASUVORK5CYII=";h.link_type_colors=
{"-1":l.EVENT_LINK_COLOR,number:"#AAA",node:"#DCA"};h.gradients={};h.prototype.clear=function(){this.fps=this.render_time=this.last_draw_time=this.frame=0;this.dragging_rectangle=null;this.selected_nodes={};this.selected_group=null;this.visible_nodes=[];this.connecting_node=this.node_capturing_input=this.node_over=this.node_dragged=null;this.highlighted_links={};this.dragging_canvas=!1;this.dirty_bgcanvas=this.dirty_canvas=!0;this.node_widget=this.node_in_panel=this.dirty_area=null;this.last_mouse=
[0,0];this.last_mouseclick=0;this.visible_area.set([0,0,0,0]);if(this.onClear)this.onClear()};h.prototype.setGraph=function(a,b){this.graph!=a&&(b||this.clear(),!a&&this.graph?this.graph.detachCanvas(this):(a.attachCanvas(this),this._graph_stack&&(this._graph_stack=null),this.setDirty(!0,!0)))};h.prototype.getTopGraph=function(){return this._graph_stack.length?this._graph_stack[0]:this.graph};h.prototype.openSubgraph=function(a){if(!a)throw"graph cannot be null";if(this.graph==a)throw"graph cannot be the same";
this.clear();this.graph&&(this._graph_stack||(this._graph_stack=[]),this._graph_stack.push(this.graph));a.attachCanvas(this);this.checkPanels();this.setDirty(!0,!0)};h.prototype.closeSubgraph=function(){if(this._graph_stack&&0!=this._graph_stack.length){var a=this.graph._subgraph_node,b=this._graph_stack.pop();this.selected_nodes={};this.highlighted_links={};b.attachCanvas(this);this.setDirty(!0,!0);a&&(this.centerOnNode(a),this.selectNodes([a]))}};h.prototype.getCurrentGraph=function(){return this.graph};
h.prototype.setCanvas=function(a,b){if(a&&a.constructor===String&&(a=document.getElementById(a),!a))throw"Error creating LiteGraph canvas: Canvas not found";if(a!==this.canvas&&(!a&&this.canvas&&(b||this.unbindEvents()),this.canvas=a,this.ds.element=a)){a.className+=" lgraphcanvas";a.data=this;a.tabindex="1";this.bgcanvas=null;this.bgcanvas||(this.bgcanvas=document.createElement("canvas"),this.bgcanvas.width=this.canvas.width,this.bgcanvas.height=this.canvas.height);if(null==a.getContext){if("canvas"!=
a.localName)throw"Element supplied for LGraphCanvas must be a <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());this._mousemove_callback=this.processMouseMove.bind(this);this._mouseup_callback=this.processMouseUp.bind(this);b||this.bindEvents()}};h.prototype._doNothing=function(a){a.preventDefault();return!1};h.prototype._doReturnTrue=
function(a){a.preventDefault();return!0};h.prototype.bindEvents=function(){if(this._events_binded)console.warn("LGraphCanvas: events already binded");else{var a=this.canvas,b=this.getCanvasWindow().document;this._mousedown_callback=this.processMouseDown.bind(this);this._mousewheel_callback=this.processMouseWheel.bind(this);a.addEventListener("mousedown",this._mousedown_callback,!0);a.addEventListener("mousemove",this._mousemove_callback);a.addEventListener("mousewheel",this._mousewheel_callback,!1);
a.addEventListener("contextmenu",this._doNothing);a.addEventListener("DOMMouseScroll",this._mousewheel_callback,!1);a.addEventListener("touchstart",this.touchHandler,!0);a.addEventListener("touchmove",this.touchHandler,!0);a.addEventListener("touchend",this.touchHandler,!0);a.addEventListener("touchcancel",this.touchHandler,!0);this._key_callback=this.processKey.bind(this);a.addEventListener("keydown",this._key_callback,!0);b.addEventListener("keyup",this._key_callback,!0);this._ondrop_callback=this.processDrop.bind(this);
a.addEventListener("dragover",this._doNothing,!1);a.addEventListener("dragend",this._doNothing,!1);a.addEventListener("drop",this._ondrop_callback,!1);a.addEventListener("dragenter",this._doReturnTrue,!1);this._events_binded=!0}};h.prototype.unbindEvents=function(){if(this._events_binded){var a=this.getCanvasWindow().document;this.canvas.removeEventListener("mousedown",this._mousedown_callback);this.canvas.removeEventListener("mousewheel",this._mousewheel_callback);this.canvas.removeEventListener("DOMMouseScroll",
this._mousewheel_callback);this.canvas.removeEventListener("keydown",this._key_callback);a.removeEventListener("keyup",this._key_callback);this.canvas.removeEventListener("contextmenu",this._doNothing);this.canvas.removeEventListener("drop",this._ondrop_callback);this.canvas.removeEventListener("dragenter",this._doReturnTrue);this.canvas.removeEventListener("touchstart",this.touchHandler);this.canvas.removeEventListener("touchmove",this.touchHandler);this.canvas.removeEventListener("touchend",this.touchHandler);
this.canvas.removeEventListener("touchcancel",this.touchHandler);this._ondrop_callback=this._key_callback=this._mousewheel_callback=this._mousedown_callback=null;this._events_binded=!1}else console.warn("LGraphCanvas: no events binded")};h.getFileExtension=function(a){var b=a.indexOf("?");-1!=b&&(a=a.substr(0,b));b=a.lastIndexOf(".");return-1==b?"":a.substr(b+1).toLowerCase()};h.prototype.enableWebGL=function(){this.gl=this.ctx=enableWebGLCanvas(this.canvas);this.ctx.webgl=!0;this.bgcanvas=this.canvas;
this.bgctx=this.gl;this.canvas.webgl_enabled=!0};h.prototype.setDirty=function(a,b){a&&(this.dirty_canvas=!0);b&&(this.dirty_bgcanvas=!0)};h.prototype.getCanvasWindow=function(){if(!this.canvas)return window;var a=this.canvas.ownerDocument;return a.defaultView||a.parentWindow};h.prototype.startRendering=function(){function a(){this.pause_rendering||this.draw();var b=this.getCanvasWindow();this.is_rendering&&b.requestAnimationFrame(a.bind(this))}this.is_rendering||(this.is_rendering=!0,a.call(this))};
h.prototype.stopRendering=function(){this.is_rendering=!1};h.prototype.blockClick=function(){this.block_click=!0;this.last_mouseclick=0};h.prototype.processMouseDown=function(a){this.set_canvas_dirty_on_mouse_event&&(this.dirty_canvas=!0);if(this.graph){this.adjustMouseEvent(a);var b=this.getCanvasWindow();h.active_canvas=this;var c=this,d=a.localX,e=a.localY;this.ds.viewport=this.viewport;d=!this.viewport||this.viewport&&d>=this.viewport[0]&&d<this.viewport[0]+this.viewport[2]&&e>=this.viewport[1]&&
e<this.viewport[1]+this.viewport[3];this.options.skip_events||(this.canvas.removeEventListener("mousemove",this._mousemove_callback),b.document.addEventListener("mousemove",this._mousemove_callback,!0),b.document.addEventListener("mouseup",this._mouseup_callback,!0));if(d){var f=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes,5);e=!1;d=300>l.getTime()-this.last_mouseclick;this.mouse[0]=a.localX;this.mouse[1]=a.localY;this.graph_mouse[0]=a.canvasX;this.graph_mouse[1]=a.canvasY;this.last_click_position=
[this.mouse[0],this.mouse[1]];this.canvas.focus();l.closeAllContextMenus(b);if(!this.onMouse||1!=this.onMouse(a)){if(1==a.which){a.ctrlKey&&(this.dragging_rectangle=new Float32Array(4),this.dragging_rectangle[0]=a.canvasX,this.dragging_rectangle[1]=a.canvasY,this.dragging_rectangle[2]=1,this.dragging_rectangle[3]=1,e=!0);var g=!1;if(f&&this.allow_interaction&&!e&&!this.read_only){this.live_mode||f.flags.pinned||this.bringToFront(f);if(!this.connecting_node&&!f.flags.collapsed&&!this.live_mode)if(!e&&
!1!==f.resizable&&C(a.canvasX,a.canvasY,f.pos[0]+f.size[0]-5,f.pos[1]+f.size[1]-5,10,10))this.graph.beforeChange(),this.resizing_node=f,this.canvas.style.cursor="se-resize",e=!0;else{if(f.outputs)for(var n=0,r=f.outputs.length;n<r;++n){var k=f.outputs[n],u=f.getConnectionPos(!1,n);if(C(a.canvasX,a.canvasY,u[0]-15,u[1]-10,30,20)){this.connecting_node=f;this.connecting_output=k;this.connecting_pos=f.getConnectionPos(!1,n);this.connecting_slot=n;a.shiftKey&&f.disconnectOutput(n);if(d){if(f.onOutputDblClick)f.onOutputDblClick(n,
a)}else if(f.onOutputClick)f.onOutputClick(n,a);e=!0;break}}if(f.inputs)for(n=0,r=f.inputs.length;n<r;++n)if(k=f.inputs[n],u=f.getConnectionPos(!0,n),C(a.canvasX,a.canvasY,u[0]-15,u[1]-10,30,20)){if(d){if(f.onInputDblClick)f.onInputDblClick(n,a)}else if(f.onInputClick)f.onInputClick(n,a);if(null!==k.link){e=this.graph.links[k.link];f.disconnectInput(n);if(this.allow_reconnect_links||a.shiftKey)this.connecting_node=this.graph._nodes_by_id[e.origin_id],this.connecting_slot=e.origin_slot,this.connecting_output=
this.connecting_node.outputs[this.connecting_slot],this.connecting_pos=this.connecting_node.getConnectionPos(!1,this.connecting_slot);e=this.dirty_bgcanvas=!0}}}if(!e){n=!1;r=[a.canvasX-f.pos[0],a.canvasY-f.pos[1]];if(u=this.processNodeWidgets(f,this.graph_mouse,a))n=!0,this.node_widget=[f,u];if(d&&this.selected_nodes[f.id]){if(f.onDblClick)f.onDblClick(a,r,this);this.processNodeDblClicked(f);n=!0}f.onMouseDown&&f.onMouseDown(a,r,this)?n=!0:(f.subgraph&&!f.skip_subgraph_button&&!f.flags.collapsed&&
r[0]>f.size[0]-l.NODE_TITLE_HEIGHT&&0>r[1]&&(c=this,setTimeout(function(){c.openSubgraph(f.subgraph)},10)),this.live_mode&&(n=g=!0));n||(this.allow_dragnodes&&(this.graph.beforeChange(),this.node_dragged=f),this.selected_nodes[f.id]||this.processNodeSelected(f,a));this.dirty_canvas=!0}}else{if(!this.read_only)for(n=0;n<this.visible_links.length;++n)if(g=this.visible_links[n],r=g._pos,!(!r||a.canvasX<r[0]-4||a.canvasX>r[0]+4||a.canvasY<r[1]-4||a.canvasY>r[1]+4)){this.showLinkMenu(g,a);this.over_link_center=
null;break}this.selected_group=this.graph.getGroupOnPos(a.canvasX,a.canvasY);this.selected_group_resizing=!1;this.selected_group&&!this.read_only&&(a.ctrlKey&&(this.dragging_rectangle=null),10>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);g=!0}!e&&g&&this.allow_dragcanvas&&
(this.dragging_canvas=!0)}else 2!=a.which&&3==a.which&&(this.read_only||this.processContextMenu(f,a));this.last_mouse[0]=a.localX;this.last_mouse[1]=a.localY;this.last_mouseclick=l.getTime();this.last_mouse_dragging=!0;this.graph.change();(!b.document.activeElement||"input"!=b.document.activeElement.nodeName.toLowerCase()&&"textarea"!=b.document.activeElement.nodeName.toLowerCase())&&a.preventDefault();a.stopPropagation();if(this.onMouseDown)this.onMouseDown(a);return!1}}}};h.prototype.processMouseMove=
function(a){this.autoresize&&this.resize();this.set_canvas_dirty_on_mouse_event&&(this.dirty_canvas=!0);if(this.graph){h.active_canvas=this;this.adjustMouseEvent(a);var b=[a.localX,a.localY];this.mouse[0]=b[0];this.mouse[1]=b[1];var c=[b[0]-this.last_mouse[0],b[1]-this.last_mouse[1]];this.last_mouse=b;this.graph_mouse[0]=a.canvasX;this.graph_mouse[1]=a.canvasY;if(this.block_click)return a.preventDefault(),!1;a.dragging=this.last_mouse_dragging;this.node_widget&&(this.processNodeWidgets(this.node_widget[0],
this.graph_mouse,a,this.node_widget[1]),this.dirty_canvas=!0);if(this.dragging_rectangle)this.dragging_rectangle[2]=a.canvasX-this.dragging_rectangle[0],this.dragging_rectangle[3]=a.canvasY-this.dragging_rectangle[1],this.dirty_canvas=!0;else if(this.selected_group&&!this.read_only)this.selected_group_resizing?this.selected_group.size=[a.canvasX-this.selected_group.pos[0],a.canvasY-this.selected_group.pos[1]]:(this.selected_group.move(c[0]/this.ds.scale,c[1]/this.ds.scale,a.ctrlKey),this.selected_group._nodes.length&&
(this.dirty_canvas=!0)),this.dirty_bgcanvas=!0;else if(this.dragging_canvas)this.ds.offset[0]+=c[0]/this.ds.scale,this.ds.offset[1]+=c[1]/this.ds.scale,this.dirty_bgcanvas=this.dirty_canvas=!0;else if(this.allow_interaction&&!this.read_only){this.connecting_node&&(this.dirty_canvas=!0);var d=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes);b=0;for(var e=this.graph._nodes.length;b<e;++b)if(this.graph._nodes[b].mouseOver&&d!=this.graph._nodes[b]){this.graph._nodes[b].mouseOver=!1;if(this.node_over&&
this.node_over.onMouseLeave)this.node_over.onMouseLeave(a);this.node_over=null;this.dirty_canvas=!0}if(d){d.redraw_on_mouse&&(this.dirty_canvas=!0);if(!d.mouseOver&&(d.mouseOver=!0,this.node_over=d,this.dirty_canvas=!0,d.onMouseEnter))d.onMouseEnter(a);if(d.onMouseMove)d.onMouseMove(a,[a.canvasX-d.pos[0],a.canvasY-d.pos[1]],this);if(this.connecting_node&&(e=this._highlight_input||[0,0],!this.isOverNodeBox(d,a.canvasX,a.canvasY))){var f=this.isOverNodeInput(d,a.canvasX,a.canvasY,e);-1!=f&&d.inputs[f]?
l.isValidConnection(this.connecting_output.type,d.inputs[f].type)&&(this._highlight_input=e):this._highlight_input=null}this.canvas&&(C(a.canvasX,a.canvasY,d.pos[0]+d.size[0]-5,d.pos[1]+d.size[1]-5,5,5)?this.canvas.style.cursor="se-resize":this.canvas.style.cursor="crosshair")}else{e=null;for(b=0;b<this.visible_links.length;++b){f=this.visible_links[b];var g=f._pos;if(!(!g||a.canvasX<g[0]-4||a.canvasX>g[0]+4||a.canvasY<g[1]-4||a.canvasY>g[1]+4)){e=f;break}}e!=this.over_link_center&&(this.over_link_center=
e,this.dirty_canvas=!0);this.canvas&&(this.canvas.style.cursor="")}if(this.node_capturing_input&&this.node_capturing_input!=d&&this.node_capturing_input.onMouseMove)this.node_capturing_input.onMouseMove(a,[a.canvasX-this.node_capturing_input.pos[0],a.canvasY-this.node_capturing_input.pos[1]],this);if(this.node_dragged&&!this.live_mode){for(b in this.selected_nodes)d=this.selected_nodes[b],d.pos[0]+=c[0]/this.ds.scale,d.pos[1]+=c[1]/this.ds.scale;this.dirty_bgcanvas=this.dirty_canvas=!0}this.resizing_node&&
!this.live_mode&&(c=[a.canvasX-this.resizing_node.pos[0],a.canvasY-this.resizing_node.pos[1]],b=this.resizing_node.computeSize(),c[0]=Math.max(b[0],c[0]),c[1]=Math.max(b[1],c[1]),this.resizing_node.setSize(c),this.canvas.style.cursor="se-resize",this.dirty_bgcanvas=this.dirty_canvas=!0)}a.preventDefault();return!1}};h.prototype.processMouseUp=function(a){this.set_canvas_dirty_on_mouse_event&&(this.dirty_canvas=!0);if(this.graph){var b=this.getCanvasWindow().document;h.active_canvas=this;this.options.skip_events||
(b.removeEventListener("mousemove",this._mousemove_callback,!0),this.canvas.addEventListener("mousemove",this._mousemove_callback,!0),b.removeEventListener("mouseup",this._mouseup_callback,!0));this.adjustMouseEvent(a);b=l.getTime();a.click_time=b-this.last_mouseclick;this.last_mouse_dragging=!1;this.last_click_position=null;this.block_click&&(console.log("foo"),this.block_click=!1);if(1==a.which)if(this.node_widget&&this.processNodeWidgets(this.node_widget[0],this.graph_mouse,a),this.node_widget=
null,this.selected_group&&(this.selected_group.move(this.selected_group.pos[0]-Math.round(this.selected_group.pos[0]),this.selected_group.pos[1]-Math.round(this.selected_group.pos[1]),a.ctrlKey),this.selected_group.pos[0]=Math.round(this.selected_group.pos[0]),this.selected_group.pos[1]=Math.round(this.selected_group.pos[1]),this.selected_group._nodes.length&&(this.dirty_canvas=!0),this.selected_group=null),this.selected_group_resizing=!1,this.dragging_rectangle){if(this.graph){b=this.graph._nodes;
var c=new Float32Array(4);this.deselectAllNodes();var d=Math.abs(this.dragging_rectangle[2]),e=Math.abs(this.dragging_rectangle[3]),f=0>this.dragging_rectangle[3]?this.dragging_rectangle[1]-e:this.dragging_rectangle[1];this.dragging_rectangle[0]=0>this.dragging_rectangle[2]?this.dragging_rectangle[0]-d:this.dragging_rectangle[0];this.dragging_rectangle[1]=f;this.dragging_rectangle[2]=d;this.dragging_rectangle[3]=e;e=[];for(f=0;f<b.length;++f)d=b[f],d.getBounding(c),B(this.dragging_rectangle,c)&&e.push(d);
e.length&&this.selectNodes(e)}this.dragging_rectangle=null}else if(this.connecting_node){this.dirty_bgcanvas=this.dirty_canvas=!0;if(d=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes))this.connecting_output.type==l.EVENT&&this.isOverNodeBox(d,a.canvasX,a.canvasY)?this.connecting_node.connect(this.connecting_slot,d,l.EVENT):(b=this.isOverNodeInput(d,a.canvasX,a.canvasY),-1!=b?this.connecting_node.connect(this.connecting_slot,d,b):(b=d.getInputInfo(0),this.connecting_output.type==l.EVENT?
this.connecting_node.connect(this.connecting_slot,d,l.EVENT):b&&!b.link&&l.isValidConnection(b.type&&this.connecting_output.type)&&this.connecting_node.connect(this.connecting_slot,d,0)));this.connecting_node=this.connecting_pos=this.connecting_output=null;this.connecting_slot=-1}else if(this.resizing_node)this.dirty_bgcanvas=this.dirty_canvas=!0,this.graph.afterChange(this.resizing_node),this.resizing_node=null;else if(this.node_dragged){(d=this.node_dragged)&&300>a.click_time&&C(a.canvasX,a.canvasY,
d.pos[0],d.pos[1]-l.NODE_TITLE_HEIGHT,l.NODE_TITLE_HEIGHT,l.NODE_TITLE_HEIGHT)&&d.collapse();this.dirty_bgcanvas=this.dirty_canvas=!0;this.node_dragged.pos[0]=Math.round(this.node_dragged.pos[0]);this.node_dragged.pos[1]=Math.round(this.node_dragged.pos[1]);(this.graph.config.align_to_grid||this.align_to_grid)&&this.node_dragged.alignToGrid();if(this.onNodeMoved)this.onNodeMoved(this.node_dragged);this.graph.afterChange(this.node_dragged);this.node_dragged=null}else{d=this.graph.getNodeOnPos(a.canvasX,
a.canvasY,this.visible_nodes);!d&&300>a.click_time&&this.deselectAllNodes();this.dirty_canvas=!0;this.dragging_canvas=!1;if(this.node_over&&this.node_over.onMouseUp)this.node_over.onMouseUp(a,[a.canvasX-this.node_over.pos[0],a.canvasY-this.node_over.pos[1]],this);if(this.node_capturing_input&&this.node_capturing_input.onMouseUp)this.node_capturing_input.onMouseUp(a,[a.canvasX-this.node_capturing_input.pos[0],a.canvasY-this.node_capturing_input.pos[1]])}else 2==a.which?(this.dirty_canvas=!0,this.dragging_canvas=
!1):3==a.which&&(this.dirty_canvas=!0,this.dragging_canvas=!1);this.graph.change();a.stopPropagation();a.preventDefault();return!1}};h.prototype.processMouseWheel=function(a){if(this.graph&&this.allow_dragcanvas){var b=null!=a.wheelDeltaY?a.wheelDeltaY:-60*a.detail;this.adjustMouseEvent(a);var c=a.localX,d=a.localY;if(!this.viewport||this.viewport&&c>=this.viewport[0]&&c<this.viewport[0]+this.viewport[2]&&d>=this.viewport[1]&&d<this.viewport[1]+this.viewport[3])return c=this.ds.scale,0<b?c*=1.1:0>
b&&(c*=1/1.1),this.ds.changeScale(c,[a.localX,a.localY]),this.graph.change(),a.preventDefault(),!1}};h.prototype.isOverNodeBox=function(a,b,c){var d=l.NODE_TITLE_HEIGHT;return C(b,c,a.pos[0]+2,a.pos[1]+2-d,d-4,d-4)?!0:!1};h.prototype.isOverNodeInput=function(a,b,c,d){if(a.inputs)for(var e=0,f=a.inputs.length;e<f;++e){var g=a.getConnectionPos(!0,e);if(a.horizontal?C(b,c,g[0]-5,g[1]-10,10,20):C(b,c,g[0]-10,g[1]-5,40,10))return d&&(d[0]=g[0],d[1]=g[1]),e}return-1};h.prototype.processKey=function(a){if(this.graph){var b=
!1;if("input"!=a.target.localName){if("keydown"==a.type){if(32==a.keyCode&&(b=this.dragging_canvas=!0),65==a.keyCode&&a.ctrlKey&&(this.selectNodes(),b=!0),"KeyC"==a.code&&(a.metaKey||a.ctrlKey)&&!a.shiftKey&&this.selected_nodes&&(this.copyToClipboard(),b=!0),"KeyV"!=a.code||!a.metaKey&&!a.ctrlKey||a.shiftKey||this.pasteFromClipboard(),46!=a.keyCode&&8!=a.keyCode||"input"==a.target.localName||"textarea"==a.target.localName||(this.deleteSelectedNodes(),b=!0),this.selected_nodes)for(var c in this.selected_nodes)if(this.selected_nodes[c].onKeyDown)this.selected_nodes[c].onKeyDown(a)}else if("keyup"==
a.type&&(32==a.keyCode&&(this.dragging_canvas=!1),this.selected_nodes))for(c in this.selected_nodes)if(this.selected_nodes[c].onKeyUp)this.selected_nodes[c].onKeyUp(a);this.graph.change();if(b)return a.preventDefault(),a.stopImmediatePropagation(),!1}}};h.prototype.copyToClipboard=function(){var a={nodes:[],links:[]},b=0,c=[],d;for(d in this.selected_nodes){var e=this.selected_nodes[d];e._relative_id=b;c.push(e);b+=1}for(d=0;d<c.length;++d)if(e=c[d],b=e.clone()){if(a.nodes.push(b.serialize()),e.inputs&&
e.inputs.length)for(b=0;b<e.inputs.length;++b){var f=e.inputs[b];if(f&&null!=f.link&&(f=this.graph.links[f.link])){var g=this.graph.getNodeById(f.origin_id);g&&this.selected_nodes[g.id]&&a.links.push([g._relative_id,f.origin_slot,e._relative_id,f.target_slot])}}}else console.warn("node type not found: "+e.type);localStorage.setItem("litegrapheditor_clipboard",JSON.stringify(a))};h.prototype.pasteFromClipboard=function(){var a=localStorage.getItem("litegrapheditor_clipboard");if(a){this.graph.beforeChange();
a=JSON.parse(a);for(var b=[],c=0;c<a.nodes.length;++c){var d=a.nodes[c],e=l.createNode(d.type);e&&(e.configure(d),e.pos[0]+=5,e.pos[1]+=5,this.graph.add(e),b.push(e))}for(c=0;c<a.links.length;++c){d=a.links[c];e=b[d[0]];var f=b[d[2]];e&&f?e.connect(d[1],f,d[3]):console.warn("Warning, nodes missing on pasting")}this.selectNodes(b);this.graph.afterChange()}};h.prototype.processDrop=function(a){a.preventDefault();this.adjustMouseEvent(a);var b=a.localX,c=a.localY;if(!this.viewport||this.viewport&&b>=
this.viewport[0]&&b<this.viewport[0]+this.viewport[2]&&c>=this.viewport[1]&&c<this.viewport[1]+this.viewport[3]){b=[a.canvasX,a.canvasY];var d=this.graph?this.graph.getNodeOnPos(b[0],b[1]):null;if(d){if((d.onDropFile||d.onDropData)&&(b=a.dataTransfer.files)&&b.length)for(c=0;c<b.length;c++){var e=a.dataTransfer.files[0],f=e.name;h.getFileExtension(f);if(d.onDropFile)d.onDropFile(e);if(d.onDropData){var g=new FileReader;g.onload=function(a){d.onDropData(a.target.result,f,e)};var n=e.type.split("/")[0];
"text"==n||""==n?g.readAsText(e):"image"==n?g.readAsDataURL(e):g.readAsArrayBuffer(e)}}return d.onDropItem&&d.onDropItem(event)?!0:this.onDropItem?this.onDropItem(event):!1}b=null;this.onDropItem&&(b=this.onDropItem(event));b||this.checkDropItem(a)}};h.prototype.checkDropItem=function(a){if(a.dataTransfer.files.length){var b=a.dataTransfer.files[0],c=h.getFileExtension(b.name).toLowerCase();if(c=l.node_types_by_file_extension[c]){this.graph.beforeChange();c=l.createNode(c.type);c.pos=[a.canvasX,a.canvasY];
this.graph.add(c);if(c.onDropFile)c.onDropFile(b);this.graph.afterChange()}}};h.prototype.processNodeDblClicked=function(a){if(this.onShowNodePanel)this.onShowNodePanel(a);else this.showShowNodePanel(a);if(this.onNodeDblClicked)this.onNodeDblClicked(a);this.setDirty(!0)};h.prototype.processNodeSelected=function(a,b){this.selectNode(a,b&&b.shiftKey);if(this.onNodeSelected)this.onNodeSelected(a)};h.prototype.selectNode=function(a,b){null==a?this.deselectAllNodes():this.selectNodes([a],b)};h.prototype.selectNodes=
function(a,b){b||this.deselectAllNodes();a=a||this.graph._nodes;for(b=0;b<a.length;++b){var c=a[b];if(!c.is_selected){if(!c.is_selected&&c.onSelected)c.onSelected();c.is_selected=!0;this.selected_nodes[c.id]=c;if(c.inputs)for(var d=0;d<c.inputs.length;++d)this.highlighted_links[c.inputs[d].link]=!0;if(c.outputs)for(d=0;d<c.outputs.length;++d){var e=c.outputs[d];if(e.links)for(var f=0;f<e.links.length;++f)this.highlighted_links[e.links[f]]=!0}}}if(this.onSelectionChange)this.onSelectionChange(this.selected_nodes);
this.setDirty(!0)};h.prototype.deselectNode=function(a){if(a.is_selected){if(a.onDeselected)a.onDeselected();a.is_selected=!1;if(this.onNodeDeselected)this.onNodeDeselected(a);if(a.inputs)for(var b=0;b<a.inputs.length;++b)delete this.highlighted_links[a.inputs[b].link];if(a.outputs)for(b=0;b<a.outputs.length;++b){var c=a.outputs[b];if(c.links)for(var d=0;d<c.links.length;++d)delete this.highlighted_links[c.links[d]]}}};h.prototype.deselectAllNodes=function(){if(this.graph){for(var a=this.graph._nodes,
b=0,c=a.length;b<c;++b){var d=a[b];if(d.is_selected){if(d.onDeselected)d.onDeselected();d.is_selected=!1;if(this.onNodeDeselected)this.onNodeDeselected(d)}}this.selected_nodes={};this.current_node=null;this.highlighted_links={};if(this.onSelectionChange)this.onSelectionChange(this.selected_nodes);this.setDirty(!0)}};h.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&&l.isValidConnection(b.inputs[0].type,b.outputs[0].type)&&b.inputs[0].link&&b.outputs[0].links&&b.outputs[0].links.length){var c=b.graph.links[b.inputs[0].link],d=b.graph.links[b.outputs[0].links[0]],e=b.getInputNode(0),f=b.getOutputNodes(0)[0];e&&f&&e.connect(c.origin_slot,f,d.target_slot)}this.graph.remove(b);if(this.onNodeDeselected)this.onNodeDeselected(b)}}this.selected_nodes={};this.current_node=null;this.highlighted_links={};this.setDirty(!0);this.graph.afterChange()};h.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)};h.prototype.adjustMouseEvent=function(a){if(this.canvas){var b=this.canvas.getBoundingClientRect();a.localX=a.clientX-b.left;a.localY=a.clientY-b.top}else a.localX=a.clientX,a.localY=a.clientY;a.deltaX=a.localX-this.last_mouse_position[0];a.deltaY=a.localY-this.last_mouse_position[1];this.last_mouse_position[0]=a.localX;
this.last_mouse_position[1]=a.localY;a.canvasX=a.localX/this.ds.scale-this.ds.offset[0];a.canvasY=a.localY/this.ds.scale-this.ds.offset[1]};h.prototype.setZoom=function(a,b){this.ds.changeScale(a,b);this.dirty_bgcanvas=this.dirty_canvas=!0};h.prototype.convertOffsetToCanvas=function(a,b){return this.ds.convertOffsetToCanvas(a,b)};h.prototype.convertCanvasToOffset=function(a,b){return this.ds.convertCanvasToOffset(a,b)};h.prototype.convertEventToCanvasOffset=function(a){var b=this.canvas.getBoundingClientRect();
return this.convertCanvasToOffset([a.clientX-b.left,a.clientY-b.top])};h.prototype.bringToFront=function(a){var b=this.graph._nodes.indexOf(a);-1!=b&&(this.graph._nodes.splice(b,1),this.graph._nodes.push(a))};h.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);h.prototype.computeVisibleNodes=function(a,b){b=b||[];b.length=0;a=a||this.graph._nodes;for(var c=0,d=a.length;c<d;++c){var e=a[c];
(!this.live_mode||e.onDrawBackground||e.onDrawForeground)&&B(this.visible_area,e.getBounding(L))&&b.push(e)}return b};h.prototype.draw=function(a,b){if(this.canvas&&0!=this.canvas.width&&0!=this.canvas.height){var c=l.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}};h.prototype.drawFrontCanvas=function(){this.dirty_canvas=!1;this.ctx||(this.ctx=this.bgcanvas.getContext("2d"));var a=this.ctx;if(a){var b=this.canvas;a.start2D&&!this.viewport&&(a.start2D(),a.restore(),a.setTransform(1,0,0,1,0,0));var c=this.viewport||this.dirty_area;c&&(a.save(),a.beginPath(),a.rect(c[0],c[1],c[2],c[3]),a.clip());this.clear_background&&(c?a.clearRect(c[0],c[1],c[2],c[3]):
a.clearRect(0,0,b.width,b.height));this.bgcanvas==this.canvas?this.drawBackCanvas():a.drawImage(this.bgcanvas,0,0);if(this.onRender)this.onRender(b,a);this.show_info&&this.renderInfo(a,c?c[0]:0,c?c[1]:0);if(this.graph){a.save();this.ds.toCanvasContext(a);b=this.computeVisibleNodes(null,this.visible_nodes);for(var d=0;d<b.length;++d){var e=b[d];a.save();a.translate(e.pos[0],e.pos[1]);this.drawNode(e,a);a.restore()}this.render_execution_order&&this.drawExecutionOrder(a);this.graph.config.links_ontop&&
(this.live_mode||this.drawConnections(a));if(null!=this.connecting_pos){a.lineWidth=this.connections_width;switch(this.connecting_output.type){case l.EVENT:b=l.EVENT_LINK_COLOR;break;default:b=l.CONNECTING_LINK_COLOR}this.renderLink(a,this.connecting_pos,[this.graph_mouse[0],this.graph_mouse[1]],null,!1,null,b,this.connecting_output.dir||(this.connecting_node.horizontal?l.DOWN:l.RIGHT),l.CENTER);a.beginPath();this.connecting_output.type===l.EVENT||this.connecting_output.shape===l.BOX_SHAPE?a.rect(this.connecting_pos[0]-
6+.5,this.connecting_pos[1]-5+.5,14,10):a.arc(this.connecting_pos[0],this.connecting_pos[1],4,0,2*Math.PI);a.fill();a.fillStyle="#ffcc00";this._highlight_input&&(a.beginPath(),a.arc(this._highlight_input[0],this._highlight_input[1],6,0,2*Math.PI),a.fill())}this.dragging_rectangle&&(a.strokeStyle="#FFF",a.strokeRect(this.dragging_rectangle[0],this.dragging_rectangle[1],this.dragging_rectangle[2],this.dragging_rectangle[3]));if(this.over_link_center&&this.render_link_tooltip)this.drawLinkTooltip(a,
this.over_link_center);else if(this.onDrawLinkTooltip)this.onDrawLinkTooltip(a,null);if(this.onDrawForeground)this.onDrawForeground(a,this.visible_rect);a.restore()}this._graph_stack&&this._graph_stack.length&&this.drawSubgraphPanel(a);if(this.onDrawOverlay)this.onDrawOverlay(a);c&&a.restore();a.finish2D&&a.finish2D()}};h.prototype.drawSubgraphPanel=function(a){var b=this.graph,c=b._subgraph_node;if(c){var d=c.inputs?c.inputs.length:0,e=Math.floor(1.6*l.NODE_SLOT_HEIGHT);a.fillStyle="#111";a.globalAlpha=
.8;a.beginPath();a.roundRect(10,10,300,(d+1)*e+50,8);a.fill();a.globalAlpha=1;a.fillStyle="#888";a.font="14px Arial";a.textAlign="left";a.fillText("Graph Inputs",20,34);if(this.drawButton(280,20,20,20,"X","#151515"))this.closeSubgraph();else{d=50;a.font="20px Arial";if(c.inputs)for(var f=0;f<c.inputs.length;++f){var g=c.inputs[f];if(!g.not_subgraph_input){if(this.drawButton(20,d+2,280,e-2)){var n=c.constructor.input_node_type||"graph/input";this.graph.beforeChange();var r=l.createNode(n);r?(b.add(r),
this.block_click=!1,this.last_click_position=null,this.selectNodes([r]),this.node_dragged=r,this.dragging_canvas=!1,r.setProperty("name",g.name),r.setProperty("type",g.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:",n)}a.fillStyle="#9C9";a.beginPath();a.arc(284,d+.5*e,5,0,2*Math.PI);a.fill();a.fillStyle="#AAA";a.fillText(g.name,50,d+.75*e);n=a.measureText(g.name);a.fillStyle="#777";
a.fillText(g.type,50+n.width+10,d+.75*e);d+=e}}this.drawButton(20,d+2,280,e-2,"+","#151515","#222")&&this.showSubgraphPropertiesDialog(c)}}else console.warn("subgraph without subnode")};h.prototype.drawButton=function(a,b,c,d,e,f,g,n){var r=this.ctx;f=f||l.NODE_DEFAULT_COLOR;g=g||"#555";n=n||l.NODE_TEXT_COLOR;var h=this.mouse,u=l.isInsideRectangle(h[0],h[1],a,b,c,d);h=(h=this.last_click_position)&&l.isInsideRectangle(h[0],h[1],a,b,c,d);r.fillStyle=u?g:f;h&&(r.fillStyle="#AAA");r.beginPath();r.roundRect(a,
b,c,d,4);r.fill();null!=e&&e.constructor==String&&(r.fillStyle=n,r.textAlign="center",r.font=(.65*d|0)+"px Arial",r.fillText(e,a+.5*c,b+.75*d),r.textAlign="left");a=h&&!this.block_click;h&&this.blockClick();return a};h.prototype.isAreaClicked=function(a,b,c,d,e){var f=this.mouse;l.isInsideRectangle(f[0],f[1],a,b,c,d);b=(a=(f=this.last_click_position)&&l.isInsideRectangle(f[0],f[1],a,b,c,d))&&!this.block_click;a&&e&&this.blockClick();return b};h.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()};h.prototype.drawBackCanvas=function(){var a=this.bgcanvas;if(a.width!=this.canvas.width||
a.height!=this.canvas.height)a.width=this.canvas.width,a.height=this.canvas.height;this.bgctx||(this.bgctx=this.bgcanvas.getContext("2d"));var b=this.bgctx;b.start&&b.start();var c=this.viewport||[0,0,b.canvas.width,b.canvas.height];this.clear_background&&b.clearRect(c[0],c[1],c[2],c[3]);if(this._graph_stack&&this._graph_stack.length){b.save();c=this.graph._subgraph_node;b.strokeStyle=c.bgcolor;b.lineWidth=10;b.strokeRect(1,1,a.width-2,a.height-2);b.lineWidth=1;b.font="40px Arial";b.textAlign="center";
b.fillStyle=c.bgcolor||"#AAA";for(var d="",e=1;e<this._graph_stack.length;++e)d+=this._graph_stack[e]._subgraph_node.getTitle()+" >> ";b.fillText(d+c.getTitle(),.5*a.width,40);b.restore()}c=!1;this.onRenderBackground&&(c=this.onRenderBackground(a,b));this.viewport||(b.restore(),b.setTransform(1,0,0,1,0,0));this.visible_links.length=0;if(this.graph){b.save();this.ds.toCanvasContext(b);if(this.background_image&&.5<this.ds.scale&&!c){b.globalAlpha=this.zoom_modify_alpha?(1-.5/this.ds.scale)*this.editor_alpha:
this.editor_alpha;b.imageSmoothingEnabled=b.mozImageSmoothingEnabled=b.imageSmoothingEnabled=!1;if(!this._bg_img||this._bg_img.name!=this.background_image){this._bg_img=new Image;this._bg_img.name=this.background_image;this._bg_img.src=this.background_image;var f=this;this._bg_img.onload=function(){f.draw(!0,!0)}}c=null;null==this._pattern&&0<this._bg_img.width?(c=b.createPattern(this._bg_img,"repeat"),this._pattern_img=this._bg_img,this._pattern=c):c=this._pattern;c&&(b.fillStyle=c,b.fillRect(this.visible_area[0],
this.visible_area[1],this.visible_area[2],this.visible_area[3]),b.fillStyle="transparent");b.globalAlpha=1;b.imageSmoothingEnabled=b.mozImageSmoothingEnabled=b.imageSmoothingEnabled=!0}this.graph._groups.length&&!this.live_mode&&this.drawGroups(a,b);if(this.onDrawBackground)this.onDrawBackground(b,this.visible_area);this.onBackgroundRender&&(console.error("WARNING! onBackgroundRender deprecated, now is named onDrawBackground "),this.onBackgroundRender=null);this.render_canvas_border&&(b.strokeStyle=
"#235",b.strokeRect(0,0,a.width,a.height));this.render_connections_shadows?(b.shadowColor="#000",b.shadowOffsetX=0,b.shadowOffsetY=0,b.shadowBlur=6):b.shadowColor="rgba(0,0,0,0)";this.live_mode||this.drawConnections(b);b.shadowColor="rgba(0,0,0,0)";b.restore()}b.finish&&b.finish();this.dirty_bgcanvas=!1;this.dirty_canvas=!0};var G=new Float32Array(2);h.prototype.drawNode=function(a,b){this.current_node=a;var c=a.color||a.constructor.color||l.NODE_DEFAULT_COLOR,d=a.bgcolor||a.constructor.bgcolor||
l.NODE_DEFAULT_BGCOLOR,e=.6>this.ds.scale;if(this.live_mode){if(!a.flags.collapsed&&(b.shadowColor="transparent",a.onDrawForeground))a.onDrawForeground(b,this,this.canvas)}else{var f=this.editor_alpha;b.globalAlpha=f;this.render_shadows&&!e?(b.shadowColor=l.DEFAULT_SHADOW_COLOR,b.shadowOffsetX=2*this.ds.scale,b.shadowOffsetY=2*this.ds.scale,b.shadowBlur=3*this.ds.scale):b.shadowColor="transparent";if(!a.flags.collapsed||!a.onDrawCollapsed||1!=a.onDrawCollapsed(b,this)){var g=a._shape||l.BOX_SHAPE;
G.set(a.size);var n=a.horizontal;if(a.flags.collapsed){b.font=this.inner_text_font;var r=a.getTitle?a.getTitle():a.title;null!=r&&(a._collapsed_width=Math.min(a.size[0],b.measureText(r).width+2*l.NODE_TITLE_HEIGHT),G[0]=a._collapsed_width,G[1]=0)}a.clip_area&&(b.save(),b.beginPath(),g==l.BOX_SHAPE?b.rect(0,0,G[0],G[1]):g==l.ROUND_SHAPE?b.roundRect(0,0,G[0],G[1],10):g==l.CIRCLE_SHAPE&&b.arc(.5*G[0],.5*G[1],.5*G[0],0,2*Math.PI),b.clip());a.has_errors&&(d="red");this.drawNodeShape(a,b,G,c,d,a.is_selected,
a.mouseOver);b.shadowColor="transparent";if(a.onDrawForeground)a.onDrawForeground(b,this,this.canvas);b.textAlign=n?"center":"left";b.font=this.inner_text_font;d=!e;g=this.connecting_output;b.lineWidth=1;r=0;var h=new Float32Array(2);if(!a.flags.collapsed){if(a.inputs)for(c=0;c<a.inputs.length;c++){var u=a.inputs[c];b.globalAlpha=f;this.connecting_node&&!l.isValidConnection(u.type,g.type)&&(b.globalAlpha=.4*f);b.fillStyle=null!=u.link?u.color_on||this.default_connection_color.input_on:u.color_off||
this.default_connection_color.input_off;var p=a.getConnectionPos(!0,c,h);p[0]-=a.pos[0];p[1]-=a.pos[1];r<p[1]+.5*l.NODE_SLOT_HEIGHT&&(r=p[1]+.5*l.NODE_SLOT_HEIGHT);b.beginPath();u.type===l.EVENT||u.shape===l.BOX_SHAPE?n?b.rect(p[0]-5+.5,p[1]-8+.5,10,14):b.rect(p[0]-6+.5,p[1]-5+.5,14,10):u.shape===l.ARROW_SHAPE?(b.moveTo(p[0]+8,p[1]+.5),b.lineTo(p[0]-4,p[1]+6+.5),b.lineTo(p[0]-4,p[1]-6+.5),b.closePath()):e?b.rect(p[0]-4,p[1]-4,8,8):b.arc(p[0],p[1],4,0,2*Math.PI);b.fill();if(d){var z=null!=u.label?
u.label:u.name;z&&(b.fillStyle=l.NODE_TEXT_COLOR,n||u.dir==l.UP?b.fillText(z,p[0],p[1]-10):b.fillText(z,p[0]+10,p[1]+5))}}this.connecting_node&&(b.globalAlpha=.4*f);b.textAlign=n?"center":"right";b.strokeStyle="black";if(a.outputs)for(c=0;c<a.outputs.length;c++)if(u=a.outputs[c],p=a.getConnectionPos(!1,c,h),p[0]-=a.pos[0],p[1]-=a.pos[1],r<p[1]+.5*l.NODE_SLOT_HEIGHT&&(r=p[1]+.5*l.NODE_SLOT_HEIGHT),b.fillStyle=u.links&&u.links.length?u.color_on||this.default_connection_color.output_on:u.color_off||
this.default_connection_color.output_off,b.beginPath(),u.type===l.EVENT||u.shape===l.BOX_SHAPE?n?b.rect(p[0]-5+.5,p[1]-8+.5,10,14):b.rect(p[0]-6+.5,p[1]-5+.5,14,10):u.shape===l.ARROW_SHAPE?(b.moveTo(p[0]+8,p[1]+.5),b.lineTo(p[0]-4,p[1]+6+.5),b.lineTo(p[0]-4,p[1]-6+.5),b.closePath()):e?b.rect(p[0]-4,p[1]-4,8,8):b.arc(p[0],p[1],4,0,2*Math.PI),b.fill(),e||b.stroke(),d&&(z=null!=u.label?u.label:u.name))b.fillStyle=l.NODE_TEXT_COLOR,n||u.dir==l.DOWN?b.fillText(z,p[0],p[1]-8):b.fillText(z,p[0]-10,p[1]+
5);b.textAlign="left";b.globalAlpha=1;if(a.widgets){u=r;if(n||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){e=f=null;if(a.inputs)for(c=0;c<a.inputs.length;c++)if(u=a.inputs[c],null!=u.link){f=u;break}if(a.outputs)for(c=0;c<a.outputs.length;c++)u=a.outputs[c],u.links&&u.links.length&&(e=u);f&&(f=0,c=-.5*l.NODE_TITLE_HEIGHT,n&&(f=.5*a._collapsed_width,
c=-l.NODE_TITLE_HEIGHT),b.fillStyle="#686",b.beginPath(),u.type===l.EVENT||u.shape===l.BOX_SHAPE?b.rect(f-7+.5,c-4,14,8):u.shape===l.ARROW_SHAPE?(b.moveTo(f+8,c),b.lineTo(f+-4,c-4),b.lineTo(f+-4,c+4),b.closePath()):b.arc(f,c,4,0,2*Math.PI),b.fill());e&&(f=a._collapsed_width,c=-.5*l.NODE_TITLE_HEIGHT,n&&(f=.5*a._collapsed_width,c=0),b.fillStyle="#686",b.strokeStyle="black",b.beginPath(),u.type===l.EVENT||u.shape===l.BOX_SHAPE?b.rect(f-7+.5,c-4,14,8):u.shape===l.ARROW_SHAPE?(b.moveTo(f+6,c),b.lineTo(f-
6,c-4),b.lineTo(f-6,c+4),b.closePath()):b.arc(f,c,4,0,2*Math.PI),b.fill())}a.clip_area&&b.restore();b.globalAlpha=1}}};h.prototype.drawLinkTooltip=function(a,b){var c=b._pos;a.fillStyle="black";a.beginPath();a.arc(c[0],c[1],3,0,2*Math.PI);a.fill();if(null!=b.data&&(!this.onDrawLinkTooltip||1!=this.onDrawLinkTooltip(a,b,this))&&(b=b.data,b=b.constructor===Number?b.toFixed(2):b.constructor===String?'"'+b+'"':b.constructor===Boolean?String(b):b.toToolTip?b.toToolTip():"["+b.constructor.name+"]",null!=
b)){b=b.substr(0,30);a.font="14px Courier New";var d=a.measureText(b).width+20;a.shadowColor="black";a.shadowOffsetX=2;a.shadowOffsetY=2;a.shadowBlur=3;a.fillStyle="#454";a.beginPath();a.roundRect(c[0]-.5*d,c[1]-15-24,d,24,3,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);h.prototype.drawNodeShape=function(a,b,c,d,e,f,g){b.strokeStyle=
d;b.fillStyle=e;e=l.NODE_TITLE_HEIGHT;var n=.5>this.ds.scale,r=a._shape||a.constructor.shape||l.ROUND_SHAPE,k=a.constructor.title_mode,u=!0;k==l.TRANSPARENT_TITLE?u=!1:k==l.AUTOHIDE_TITLE&&g&&(u=!0);A[0]=0;A[1]=u?-e:0;A[2]=c[0]+1;A[3]=u?c[1]+e:c[1];g=b.globalAlpha;b.beginPath();r==l.BOX_SHAPE||n?b.fillRect(A[0],A[1],A[2],A[3]):r==l.ROUND_SHAPE||r==l.CARD_SHAPE?b.roundRect(A[0],A[1],A[2],A[3],this.round_radius,r==l.CARD_SHAPE?0:this.round_radius):r==l.CIRCLE_SHAPE&&b.arc(.5*c[0],.5*c[1],.5*c[0],0,
2*Math.PI);b.fill();a.flags.collapsed||(b.shadowColor="transparent",b.fillStyle="rgba(0,0,0,0.2)",b.fillRect(0,-1,A[2],2));b.shadowColor="transparent";if(a.onDrawBackground)a.onDrawBackground(b,this,this.canvas,this.graph_mouse);if(u||k==l.TRANSPARENT_TITLE){if(a.onDrawTitleBar)a.onDrawTitleBar(b,e,c,this.ds.scale,d);else if(k!=l.TRANSPARENT_TITLE&&(a.constructor.title_color||this.render_title_colored)){u=a.constructor.title_color||d;a.flags.collapsed&&(b.shadowColor=l.DEFAULT_SHADOW_COLOR);if(this.use_gradients){var p=
h.gradients[u];p||(p=h.gradients[u]=b.createLinearGradient(0,0,400,0),p.addColorStop(0,u),p.addColorStop(1,"#000"));b.fillStyle=p}else b.fillStyle=u;b.beginPath();r==l.BOX_SHAPE||n?b.rect(0,-e,c[0]+1,e):(r==l.ROUND_SHAPE||r==l.CARD_SHAPE)&&b.roundRect(0,-e,c[0]+1,e,this.round_radius,a.flags.collapsed?this.round_radius:0);b.fill();b.shadowColor="transparent"}if(a.onDrawTitleBox)a.onDrawTitleBox(b,e,c,this.ds.scale);else r==l.ROUND_SHAPE||r==l.CIRCLE_SHAPE||r==l.CARD_SHAPE?(n&&(b.fillStyle="black",
b.beginPath(),b.arc(.5*e,-.5*e,6,0,2*Math.PI),b.fill()),b.fillStyle=a.boxcolor||l.NODE_DEFAULT_BOXCOLOR,n?b.fillRect(.5*e-5,-.5*e-5,10,10):(b.beginPath(),b.arc(.5*e,-.5*e,5,0,2*Math.PI),b.fill())):(n&&(b.fillStyle="black",b.fillRect(.5*(e-10)-1,-.5*(e+10)-1,12,12)),b.fillStyle=a.boxcolor||l.NODE_DEFAULT_BOXCOLOR,b.fillRect(.5*(e-10),-.5*(e+10),10,10));b.globalAlpha=g;if(a.onDrawTitleText)a.onDrawTitleText(b,e,c,this.ds.scale,this.title_text_font,f);!n&&(b.font=this.title_text_font,g=String(a.getTitle()))&&
(b.fillStyle=f?l.NODE_SELECTED_TITLE_COLOR:a.constructor.title_text_color||this.node_title_color,a.flags.collapsed?(b.textAlign="left",b.measureText(g),b.fillText(g.substr(0,20),e,l.NODE_TITLE_TEXT_Y-e),b.textAlign="left"):(b.textAlign="left",b.fillText(g,e,l.NODE_TITLE_TEXT_Y-e)));a.flags.collapsed||!a.subgraph||a.skip_subgraph_button||(g=l.NODE_TITLE_HEIGHT,u=a.size[0]-g,p=l.isInsideRectangle(this.graph_mouse[0]-a.pos[0],this.graph_mouse[1]-a.pos[1],u+2,-g+2,g-4,g-4),b.fillStyle=p?"#888":"#555",
r==l.BOX_SHAPE||n?b.fillRect(u+2,-g+2,g-4,g-4):(b.beginPath(),b.roundRect(u+2,-g+2,g-4,g-4,4),b.fill()),b.fillStyle="#333",b.beginPath(),b.moveTo(u+.2*g,.6*-g),b.lineTo(u+.8*g,.6*-g),b.lineTo(u+.5*g,.3*-g),b.fill());if(a.onDrawTitle)a.onDrawTitle(b)}if(f){if(a.onBounding)a.onBounding(A);k==l.TRANSPARENT_TITLE&&(A[1]-=e,A[3]+=e);b.lineWidth=1;b.globalAlpha=.8;b.beginPath();r==l.BOX_SHAPE?b.rect(-6+A[0],-6+A[1],12+A[2],12+A[3]):r==l.ROUND_SHAPE||r==l.CARD_SHAPE&&a.flags.collapsed?b.roundRect(-6+A[0],
-6+A[1],12+A[2],12+A[3],2*this.round_radius):r==l.CARD_SHAPE?b.roundRect(-6+A[0],-6+A[1],12+A[2],12+A[3],2*this.round_radius,2):r==l.CIRCLE_SHAPE&&b.arc(.5*c[0],.5*c[1],.5*c[0]+6,0,2*Math.PI);b.strokeStyle=l.NODE_BOX_OUTLINE_COLOR;b.stroke();b.strokeStyle=d;b.globalAlpha=1}};var J=new Float32Array(4),D=new Float32Array(4),H=new Float32Array(2),F=new Float32Array(2);h.prototype.drawConnections=function(a){var b=l.getTime(),c=this.visible_area;J[0]=c[0]-20;J[1]=c[1]-20;J[2]=c[2]+40;J[3]=c[3]+40;a.lineWidth=
this.connections_width;a.fillStyle="#AAA";a.strokeStyle="#AAA";a.globalAlpha=this.editor_alpha;c=this.graph._nodes;for(var d=0,e=c.length;d<e;++d){var f=c[d];if(f.inputs&&f.inputs.length)for(var g=0;g<f.inputs.length;++g){var n=f.inputs[g];if(n&&null!=n.link&&(n=this.graph.links[n.link])){var r=this.graph.getNodeById(n.origin_id);if(null!=r){var h=n.origin_slot;var u=-1==h?[r.pos[0]+10,r.pos[1]+10]:r.getConnectionPos(!1,h,H);var p=f.getConnectionPos(!0,g,F);D[0]=u[0];D[1]=u[1];D[2]=p[0]-u[0];D[3]=
p[1]-u[1];0>D[2]&&(D[0]+=D[2],D[2]=Math.abs(D[2]));0>D[3]&&(D[1]+=D[3],D[3]=Math.abs(D[3]));if(B(D,J)){var z=r.outputs[h];h=f.inputs[g];if(z&&h&&(r=z.dir||(r.horizontal?l.DOWN:l.RIGHT),h=h.dir||(f.horizontal?l.UP:l.LEFT),this.renderLink(a,u,p,n,!1,0,null,r,h),n&&n._last_time&&1E3>b-n._last_time)){z=2-.002*(b-n._last_time);var k=a.globalAlpha;a.globalAlpha=k*z;this.renderLink(a,u,p,n,!0,z,"white",r,h);a.globalAlpha=k}}}}}}a.globalAlpha=1};h.prototype.renderLink=function(a,b,c,d,e,f,g,n,r,k){d&&this.visible_links.push(d);
!g&&d&&(g=d.color||h.link_type_colors[d.type]);g||(g=this.default_link_color);null!=d&&this.highlighted_links[d.id]&&(g="#FFF");n=n||l.RIGHT;r=r||l.LEFT;var u=E(b,c);this.render_connections_border&&.6<this.ds.scale&&(a.lineWidth=this.connections_width+4);a.lineJoin="round";k=k||1;1<k&&(a.lineWidth=.5);a.beginPath();for(var p=0;p<k;p+=1){var z=5*(p-.5*(k-1));if(this.links_render_mode==l.SPLINE_LINK){a.moveTo(b[0],b[1]+z);var y=0,t=0,m=0,K=0;switch(n){case l.LEFT:y=-.25*u;break;case l.RIGHT:y=.25*u;
break;case l.UP:t=-.25*u;break;case l.DOWN:t=.25*u}switch(r){case l.LEFT:m=-.25*u;break;case l.RIGHT:m=.25*u;break;case l.UP:K=-.25*u;break;case l.DOWN:K=.25*u}a.bezierCurveTo(b[0]+y,b[1]+t+z,c[0]+m,c[1]+K+z,c[0],c[1]+z)}else if(this.links_render_mode==l.LINEAR_LINK){a.moveTo(b[0],b[1]+z);K=m=t=y=0;switch(n){case l.LEFT:y=-1;break;case l.RIGHT:y=1;break;case l.UP:t=-1;break;case l.DOWN:t=1}switch(r){case l.LEFT:m=-1;break;case l.RIGHT:m=1;break;case l.UP:K=-1;break;case l.DOWN:K=1}a.lineTo(b[0]+15*
y,b[1]+15*t+z);a.lineTo(c[0]+15*m,c[1]+15*K+z);a.lineTo(c[0],c[1]+z)}else if(this.links_render_mode==l.STRAIGHT_LINK)a.moveTo(b[0],b[1]),z=b[0],y=b[1],t=c[0],m=c[1],n==l.RIGHT?z+=10:y+=10,r==l.LEFT?t-=10:m-=10,a.lineTo(z,y),a.lineTo(.5*(z+t),y),a.lineTo(.5*(z+t),m),a.lineTo(t,m),a.lineTo(c[0],c[1]);else return}this.render_connections_border&&.6<this.ds.scale&&!e&&(a.strokeStyle="rgba(0,0,0,0.5)",a.stroke());a.lineWidth=this.connections_width;a.fillStyle=a.strokeStyle=g;a.stroke();e=this.computeConnectionPoint(b,
c,.5,n,r);d&&d._pos&&(d._pos[0]=e[0],d._pos[1]=e[1]);.6<=this.ds.scale&&this.highquality_render&&r!=l.CENTER&&(this.render_connection_arrows&&(p=this.computeConnectionPoint(b,c,.25,n,r),u=this.computeConnectionPoint(b,c,.26,n,r),d=this.computeConnectionPoint(b,c,.75,n,r),k=this.computeConnectionPoint(b,c,.76,n,r),this.render_curved_connections?(u=-Math.atan2(u[0]-p[0],u[1]-p[1]),k=-Math.atan2(k[0]-d[0],k[1]-d[1])):k=u=c[1]>b[1]?0:Math.PI,a.save(),a.translate(p[0],p[1]),a.rotate(u),a.beginPath(),a.moveTo(-5,
-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore(),a.save(),a.translate(d[0],d[1]),a.rotate(k),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore()),a.beginPath(),a.arc(e[0],e[1],5,0,2*Math.PI),a.fill());if(f)for(a.fillStyle=g,p=0;5>p;++p)f=(.001*l.getTime()+.2*p)%1,e=this.computeConnectionPoint(b,c,f,n,r),a.beginPath(),a.arc(e[0],e[1],5,0,2*Math.PI),a.fill()};h.prototype.computeConnectionPoint=function(a,b,c,d,e){d=d||l.RIGHT;e=e||l.LEFT;var f=E(a,b),g=[a[0],a[1]],n=
[b[0],b[1]];switch(d){case l.LEFT:g[0]+=-.25*f;break;case l.RIGHT:g[0]+=.25*f;break;case l.UP:g[1]+=-.25*f;break;case l.DOWN:g[1]+=.25*f}switch(e){case l.LEFT:n[0]+=-.25*f;break;case l.RIGHT:n[0]+=.25*f;break;case l.UP:n[1]+=-.25*f;break;case l.DOWN:n[1]+=.25*f}d=(1-c)*(1-c)*(1-c);e=3*(1-c)*(1-c)*c;f=3*(1-c)*c*c;c*=c*c;return[d*a[0]+e*g[0]+f*n[0]+c*b[0],d*a[1]+e*g[1]+f*n[1]+c*b[1]]};h.prototype.drawExecutionOrder=function(a){a.shadowColor="transparent";a.globalAlpha=.25;a.textAlign="center";a.strokeStyle=
"white";a.globalAlpha=.75;for(var b=this.visible_nodes,c=0;c<b.length;++c){var d=b[c];a.fillStyle="black";a.fillRect(d.pos[0]-l.NODE_TITLE_HEIGHT,d.pos[1]-l.NODE_TITLE_HEIGHT,l.NODE_TITLE_HEIGHT,l.NODE_TITLE_HEIGHT);0==d.order&&a.strokeRect(d.pos[0]-l.NODE_TITLE_HEIGHT+.5,d.pos[1]-l.NODE_TITLE_HEIGHT+.5,l.NODE_TITLE_HEIGHT,l.NODE_TITLE_HEIGHT);a.fillStyle="#FFF";a.fillText(d.order,d.pos[0]+-.5*l.NODE_TITLE_HEIGHT,d.pos[1]-6)}a.globalAlpha=1};h.prototype.drawNodeWidgets=function(a,b,c,d){if(!a.widgets||
!a.widgets.length)return 0;var e=a.size[0],f=a.widgets;b+=2;var g=l.NODE_WIDGET_HEIGHT,n=.5<this.ds.scale;c.save();c.globalAlpha=this.editor_alpha;for(var r=l.WIDGET_OUTLINE_COLOR,h=l.WIDGET_BGCOLOR,k=l.WIDGET_TEXT_COLOR,p=l.WIDGET_SECONDARY_TEXT_COLOR,z=0;z<f.length;++z){var y=f[z],t=b;y.y&&(t=y.y);y.last_y=t;c.strokeStyle=r;c.fillStyle="#222";c.textAlign="left";y.disabled&&(c.globalAlpha*=.5);var m=y.width||e;switch(y.type){case "button":y.clicked&&(c.fillStyle="#AAA",y.clicked=!1,this.dirty_canvas=
!0);c.fillRect(15,t,m-30,g);n&&!y.disabled&&c.strokeRect(15,t,m-30,g);n&&(c.textAlign="center",c.fillStyle=k,c.fillText(y.name,.5*m,t+.7*g));break;case "toggle":c.textAlign="left";c.strokeStyle=r;c.fillStyle=h;c.beginPath();n?c.roundRect(15,b,m-30,g,.5*g):c.rect(15,b,m-30,g);c.fill();n&&!y.disabled&&c.stroke();c.fillStyle=y.value?"#89A":"#333";c.beginPath();c.arc(m-30,t+.5*g,.36*g,0,2*Math.PI);c.fill();n&&(c.fillStyle=p,null!=y.name&&c.fillText(y.name,30,t+.7*g),c.fillStyle=y.value?k:p,c.textAlign=
"right",c.fillText(y.value?y.options.on||"true":y.options.off||"false",m-40,t+.7*g));break;case "slider":c.fillStyle=h;c.fillRect(15,t,m-30,g);var q=y.options.max-y.options.min,w=(y.value-y.options.min)/q;c.fillStyle=d==y?"#89A":"#678";c.fillRect(15,t,w*(m-30),g);n&&!y.disabled&&c.strokeRect(15,t,m-30,g);y.marker&&(q=(y.marker-y.options.min)/q,c.fillStyle="#AA9",c.fillRect(15+q*(m-30),t,2,g));n&&(c.textAlign="center",c.fillStyle=k,c.fillText(y.name+" "+Number(y.value).toFixed(3),.5*m,t+.7*g));break;
case "number":case "combo":c.textAlign="left";c.strokeStyle=r;c.fillStyle=h;c.beginPath();n?c.roundRect(15,b,m-30,g,.5*g):c.rect(15,b,m-30,g);c.fill();n&&(y.disabled||c.stroke(),c.fillStyle=k,y.disabled||(c.beginPath(),c.moveTo(31,b+5),c.lineTo(21,b+.5*g),c.lineTo(31,b+g-5),c.fill(),c.beginPath(),c.moveTo(m-15-16,b+5),c.lineTo(m-15-6,b+.5*g),c.lineTo(m-15-16,b+g-5),c.fill()),c.fillStyle=p,c.fillText(y.name,35,t+.7*g),c.fillStyle=k,c.textAlign="right","number"==y.type?c.fillText(Number(y.value).toFixed(void 0!==
y.options.precision?y.options.precision:3),m-30-20,t+.7*g):(q=y.value,y.options.values&&(w=y.options.values,w.constructor===Function&&(w=w()),w&&w.constructor!==Array&&(q=w[y.value])),c.fillText(q,m-30-20,t+.7*g)));break;case "string":case "text":c.textAlign="left";c.strokeStyle=r;c.fillStyle=h;c.beginPath();n?c.roundRect(15,b,m-30,g,.5*g):c.rect(15,b,m-30,g);c.fill();n&&(y.disabled||c.stroke(),c.save(),c.beginPath(),c.rect(15,b,m-30,g),c.clip(),c.fillStyle=p,null!=y.name&&c.fillText(y.name,30,t+
.7*g),c.fillStyle=k,c.textAlign="right",c.fillText(String(y.value).substr(0,30),m-30,t+.7*g),c.restore());break;default:y.draw&&y.draw(c,a,m,t,g)}b+=(y.computeSize?y.computeSize(m)[1]:g)+4;c.globalAlpha=this.editor_alpha}c.restore();c.textAlign="left"};h.prototype.processNodeWidgets=function(a,b,c,d){function e(d,e){d.value=e;d.options&&d.options.property&&void 0!==a.properties[d.options.property]&&a.setProperty(d.options.property,e);d.callback&&d.callback(d.value,r,a,b,c)}if(!a.widgets||!a.widgets.length)return null;
for(var f=b[0]-a.pos[0],g=b[1]-a.pos[1],n=a.size[0],r=this,h=this.getCanvasWindow(),k=0;k<a.widgets.length;++k){var p=a.widgets[k];if(p&&!p.disabled){var z=p.computeSize?p.computeSize(n)[1]:l.NODE_WIDGET_HEIGHT,t=p.width||n;if(p==d||!(6>f||f>t-12||g<p.last_y||g>p.last_y+z||void 0===p.last_y)){d=p.value;switch(p.type){case "button":if("mousemove"===c.type)break;p.callback&&setTimeout(function(){p.callback(p,r,a,b,c)},20);this.dirty_canvas=p.clicked=!0;break;case "slider":h=Math.clamp((f-15)/(t-30),
0,1);p.value=p.options.min+(p.options.max-p.options.min)*h;p.callback&&setTimeout(function(){e(p,p.value)},20);this.dirty_canvas=!0;break;case "number":case "combo":d=p.value;if("mousemove"==c.type&&"number"==p.type)p.value+=.1*c.deltaX*(p.options.step||1),null!=p.options.min&&p.value<p.options.min&&(p.value=p.options.min),null!=p.options.max&&p.value>p.options.max&&(p.value=p.options.max);else if("mousedown"==c.type){var m=p.options.values;m&&m.constructor===Function&&(m=p.options.values(p,a));var q=
null;"number"!=p.type&&(q=m.constructor===Array?m:Object.keys(m));f=40>f?-1:f>t-40?1:0;if("number"==p.type)p.value+=.1*f*(p.options.step||1),null!=p.options.min&&p.value<p.options.min&&(p.value=p.options.min),null!=p.options.max&&p.value>p.options.max&&(p.value=p.options.max);else if(f)h=-1,this.last_mouseclick=0,h=m.constructor===Object?q.indexOf(String(p.value))+f:q.indexOf(p.value)+f,h>=q.length&&(h=q.length-1),0>h&&(h=0),p.value=m.constructor===Array?m[h]:h;else{var w=m!=q?Object.values(m):m;
new l.ContextMenu(w,{scale:Math.max(1,this.ds.scale),event:c,className:"dark",callback:function(a,b,c){m!=q&&(a=w.indexOf(a));this.value=a;e(this,a);r.dirty_canvas=!0;return!1}.bind(p)},h)}}else"mouseup"==c.type&&"number"==p.type&&(f=40>f?-1:f>t-40?1:0,200>c.click_time&&0==f&&this.prompt("Value",p.value,function(a){this.value=Number(a);e(this,this.value)}.bind(p),c));d!=p.value&&setTimeout(function(){e(this,this.value)}.bind(p),20);this.dirty_canvas=!0;break;case "toggle":"mousedown"==c.type&&(p.value=
!p.value,setTimeout(function(){e(p,p.value)},20));break;case "string":case "text":"mousedown"==c.type&&this.prompt("Value",p.value,function(a){this.value=a;e(this,a)}.bind(p),c,p.options?p.options.multiline:!1);break;default:p.mouse&&(this.dirty_canvas=p.mouse(c,[f,g],a))}if(d!=p.value){if(a.onWidgetChanged)a.onWidgetChanged(p.name,p.value,d,p);a.graph._version++}return p}}}return null};h.prototype.drawGroups=function(a,b){if(this.graph){a=this.graph._groups;b.save();b.globalAlpha=.5*this.editor_alpha;
for(var c=0;c<a.length;++c){var d=a[c];if(B(this.visible_area,d._bounding)){b.fillStyle=d.color||"#335";b.strokeStyle=d.color||"#335";var e=d._pos,f=d._size;b.globalAlpha=.25*this.editor_alpha;b.beginPath();b.rect(e[0]+.5,e[1]+.5,f[0],f[1]);b.fill();b.globalAlpha=this.editor_alpha;b.stroke();b.beginPath();b.moveTo(e[0]+f[0],e[1]+f[1]);b.lineTo(e[0]+f[0]-10,e[1]+f[1]);b.lineTo(e[0]+f[0],e[1]+f[1]-10);b.fill();f=d.font_size||l.DEFAULT_GROUP_FONT_SIZE;b.font=f+"px Arial";b.fillText(d.title,e[0]+4,e[1]+
f)}}b.restore()}};h.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)};h.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)};h.prototype.switchLiveMode=function(a){if(a){var b=this,c=this.live_mode?
1.1:.9;this.live_mode&&(this.live_mode=!1,this.editor_alpha=.1);var d=setInterval(function(){b.editor_alpha*=c;b.dirty_canvas=!0;b.dirty_bgcanvas=!0;1>c&&.01>b.editor_alpha&&(clearInterval(d),1>c&&(b.live_mode=!0));1<c&&.99<b.editor_alpha&&(clearInterval(d),b.editor_alpha=1)},1)}else this.live_mode=!this.live_mode,this.dirty_bgcanvas=this.dirty_canvas=!0};h.prototype.onNodeSelectionChange=function(a){};h.prototype.touchHandler=function(a){var b=a.changedTouches[0];switch(a.type){case "touchstart":var c=
"mousedown";break;case "touchmove":c="mousemove";break;case "touchend":c="mouseup";break;default:return}var d=this.getCanvasWindow(),e=d.document.createEvent("MouseEvent");e.initMouseEvent(c,!0,!0,d,1,b.screenX,b.screenY,b.clientX,b.clientY,!1,!1,!1,!1,0,null);b.target.dispatchEvent(e);a.preventDefault()};h.onGroupAdd=function(a,b,c){a=h.active_canvas;a.getCanvasWindow();b=new l.LGraphGroup;b.pos=a.convertEventToCanvasOffset(c);a.graph.add(b)};h.onMenuAdd=function(a,b,c,d,e){function f(a,b){var d=
[];l.getNodeTypesCategories(g.filter||r.filter).filter(function(b){return b.startsWith(a)}).map(function(b){if(b){b=b.replace(new RegExp("^("+a+")"),"").split("/")[0];var c=""===a?b+"/":a+b+"/";-1!=b.indexOf("::")&&(b=b.split("::")[1]);-1===d.findIndex(function(a){return a.value===c})&&d.push({value:c,content:b,has_submenu:!0,callback:function(a,b,c,d){f(a.value,d)}})}});l.getNodeTypesInCategory(a.slice(0,-1),g.filter||r.filter).map(function(a){a.skip_list||d.push({value:a.type,content:a.title,has_submenu:!1,
callback:function(a,b,c,d){b=d.getFirstEvent();g.graph.beforeChange();if(a=l.createNode(a.value))a.pos=g.convertEventToCanvasOffset(b),g.graph.add(a);e&&e(a);g.graph.afterChange()}})});new l.ContextMenu(d,{event:c,parentMenu:b},n)}var g=h.active_canvas,n=g.getCanvasWindow(),r=g.graph;if(r)return f("",d),!1};h.onMenuCollapseAll=function(){};h.onMenuNodeEdit=function(){};h.showMenuNodeOptionalInputs=function(a,b,c,d,e){if(e){var f=this;a=h.active_canvas.getCanvasWindow();b=e.optional_inputs;e.onGetInputs&&
(b=e.onGetInputs());var g=[];if(b)for(var n=0;n<b.length;n++){var r=b[n];if(r){var k=r[0];r[2]&&r[2].label&&(k=r[2].label);k={content:k,value:r};r[1]==l.ACTION&&(k.className="event");g.push(k)}else g.push(null)}this.onMenuNodeInputs&&(g=this.onMenuNodeInputs(g));if(g.length)return new l.ContextMenu(g,{event:c,callback:function(a,b,c){e&&(a.callback&&a.callback.call(f,e,a,b,c),a.value&&(e.graph.beforeChange(),e.addInput(a.value[0],a.value[1],a.value[2]),e.setDirtyCanvas(!0,!0),e.graph.afterChange()))},
parentMenu:d,node:e},a),!1;console.log("no input entries")}};h.showMenuNodeOptionalOutputs=function(a,b,c,d,e){function f(a,b,c){if(e&&(a.callback&&a.callback.call(g,e,a,b,c),a.value))if(c=a.value[1],!c||c.constructor!==Object&&c.constructor!==Array)e.graph.beforeChange(),e.addOutput(a.value[0],a.value[1],a.value[2]),e.setDirtyCanvas(!0,!0),e.graph.afterChange();else{a=[];for(var n in c)a.push({content:n,value:c[n]});new l.ContextMenu(a,{event:b,callback:f,parentMenu:d,node:e});return!1}}if(e){var g=
this;a=h.active_canvas.getCanvasWindow();b=e.optional_outputs;e.onGetOutputs&&(b=e.onGetOutputs());var n=[];if(b)for(var r=0;r<b.length;r++){var k=b[r];if(!k)n.push(null);else if(!e.flags||!e.flags.skip_repeated_outputs||-1==e.findOutputSlot(k[0])){var m=k[0];k[2]&&k[2].label&&(m=k[2].label);m={content:m,value:k};k[1]==l.EVENT&&(m.className="event");n.push(m)}}this.onMenuNodeOutputs&&(n=this.onMenuNodeOutputs(n));if(n.length)return new l.ContextMenu(n,{event:c,callback:f,parentMenu:d,node:e},a),!1}};
h.onShowMenuNodeProperties=function(a,b,c,d,e){if(e&&e.properties){var f=h.active_canvas;b=f.getCanvasWindow();var g=[],n;for(n in e.properties){a=void 0!==e.properties[n]?e.properties[n]:" ";"object"==typeof a&&(a=JSON.stringify(a));var r=e.getPropertyInfo(n);if("enum"==r.type||"combo"==r.type)a=h.getPropertyPrintableValue(a,r.values);a=h.decodeHTML(a);g.push({content:"<span class='property_name'>"+(r.label?r.label:n)+"</span><span class='property_value'>"+a+"</span>",value:n})}if(g.length)return new l.ContextMenu(g,
{event:c,callback:function(a,b,c,d){e&&(b=this.getBoundingClientRect(),f.showEditPropertyValue(e,a.value,{position:[b.left,b.top]}))},parentMenu:d,allow_html:!0,node:e},b),!1}};h.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};h.onResizeNode=function(a,b,c,d,e){if(e){e.size=e.computeSize();if(e.onResize)e.onResize(e.size);e.setDirtyCanvas(!0,!0)}};h.prototype.showLinkMenu=function(a,b){var c=this;console.log(a);var d=new l.ContextMenu(["Add Node",null,
"Delete"],{event:b,title:null!=a.data?a.data.constructor.name:null,callback:function(b,f,g){switch(b){case "Add Node":h.onMenuAdd(null,null,g,d,function(b){console.log("node autoconnect");var d=c.graph.getNodeById(a.origin_id),e=c.graph.getNodeById(a.target_id);b.inputs&&b.inputs.length&&b.outputs&&b.outputs.length&&d.outputs[a.origin_slot].type==b.inputs[0].type&&b.outputs[0].type==e.inputs[0].type&&(d.connect(a.origin_slot,b,0),b.connect(0,e,a.target_slot),b.pos[0]-=.5*b.size[0])});break;case "Delete":c.graph.removeLink(a.id)}}});
return!1};h.onShowPropertyEditor=function(a,b,c,d,e){function f(){var b=l.value;"Number"==a.type?b=Number(b):"Boolean"==a.type&&(b=!!b);e[g]=b;n.parentNode&&n.parentNode.removeChild(n);e.setDirtyCanvas(!0,!0)}var g=a.property||"title";b=e[g];var n=document.createElement("div");n.className="graphdialog";n.innerHTML="<span class='name'></span><input autofocus type='text' class='value'/><button>OK</button>";n.querySelector(".name").innerText=g;var l=n.querySelector(".value");l&&(l.value=b,l.addEventListener("blur",
function(a){this.focus()}),l.addEventListener("keydown",function(a){if(13==a.keyCode||"textarea"==a.target.localName)f(),a.preventDefault(),a.stopPropagation()}));b=h.active_canvas.canvas;c=b.getBoundingClientRect();var k=d=-20;c&&(d-=c.left,k-=c.top);event?(n.style.left=event.clientX+d+"px",n.style.top=event.clientY+k+"px"):(n.style.left=.5*b.width+d+"px",n.style.top=.5*b.height+k+"px");n.querySelector("button").addEventListener("click",f);b.parentNode.appendChild(n)};h.prototype.prompt=function(a,
b,c,d,e){var f=this;a=a||"";var g=!1,n=document.createElement("div");n.className="graphdialog rounded";n.innerHTML=e?"<span class='name'></span> <textarea autofocus class='value'></textarea><button class='rounded'>OK</button>":"<span class='name'></span> <input autofocus type='text' class='value'/><button class='rounded'>OK</button>";n.close=function(){f.prompt_box=null;n.parentNode&&n.parentNode.removeChild(n)};1<this.ds.scale&&(n.style.transform="scale("+this.ds.scale+")");n.addEventListener("mouseleave",
function(a){g||n.close()});f.prompt_box&&f.prompt_box.close();f.prompt_box=n;n.querySelector(".name").innerText=a;var l=n.querySelector(".value");l.value=b;l.addEventListener("keydown",function(a){g=!0;if(27==a.keyCode)n.close();else if(13==a.keyCode&&"textarea"!=a.target.localName)c&&c(this.value),n.close();else return;a.preventDefault();a.stopPropagation()});n.querySelector("button").addEventListener("click",function(a){c&&c(l.value);f.setDirty(!0);n.close()});a=h.active_canvas.canvas;b=a.getBoundingClientRect();
var k=e=-20;b&&(e-=b.left,k-=b.top);d?(n.style.left=d.clientX+e+"px",n.style.top=d.clientY+k+"px"):(n.style.left=.5*a.width+e+"px",n.style.top=.5*a.height+k+"px");a.parentNode.appendChild(n);setTimeout(function(){l.focus()},10);return n};h.search_limit=-1;h.prototype.showSearchBox=function(a){function b(b){if(b)if(e.onSearchBoxSelection)e.onSearchBoxSelection(b,a,f);else{var c=l.searchbox_extras[b.toLowerCase()];c&&(b=c.type);f.graph.beforeChange();if(b=l.createNode(b))b.pos=f.convertEventToCanvasOffset(a),
f.graph.add(b);if(c&&c.data){if(c.data.properties)for(var d in c.data.properties)b.addProperty(d,c.data.properties[d]);if(c.data.inputs)for(d in b.inputs=[],c.data.inputs)b.addOutput(c.data.inputs[d][0],c.data.inputs[d][1]);if(c.data.outputs)for(d in b.outputs=[],c.data.outputs)b.addOutput(c.data.outputs[d][0],c.data.outputs[d][1]);c.data.title&&(b.title=c.data.title);c.data.json&&b.configure(c.data.json);f.graph.afterChange()}}r.close()}function c(a){var b=t;t&&t.classList.remove("selected");t?(t=
a?t.nextSibling:t.previousSibling)||(t=b):t=a?m.childNodes[0]:m.childNodes[m.childNodes.length];t&&(t.classList.add("selected"),t.scrollIntoView({block:"end",behavior:"smooth"}))}function d(){function a(a,c){var d=document.createElement("div");p||(p=a);d.innerText=a;d.dataset.type=escape(a);d.className="litegraph lite-search-item";c&&(d.className+=" "+c);d.addEventListener("click",function(a){b(unescape(this.dataset.type))});m.appendChild(d)}z=null;var c=q.value;p=null;m.innerHTML="";if(c)if(e.onSearchBox){var d=
e.onSearchBox(m,c,f);if(d)for(var n=0;n<d.length;++n)a(d[n])}else{d=function(a){var b=l.registered_node_types[a];return r&&b.filter!=r?!1:-1!==a.toLowerCase().indexOf(c)};var g=0;c=c.toLowerCase();var r=f.filter||f.graph.filter;for(n in l.searchbox_extras){var k=l.searchbox_extras[n];if(-1!==k.desc.toLowerCase().indexOf(c)){var t=l.registered_node_types[k.type];if(!t||t.filter==r)if(a(k.desc,"searchbox_extra"),-1!==h.search_limit&&g++>h.search_limit)break}}k=null;if(Array.prototype.filter)k=Object.keys(l.registered_node_types).filter(d);
else for(n in k=[],l.registered_node_types)d(n)&&k.push(n);for(n=0;n<k.length&&!(a(k[n]),-1!==h.search_limit&&g++>h.search_limit);n++);}}var e=this,f=h.active_canvas,g=f.canvas,n=g.ownerDocument||document,r=document.createElement("div");r.className="litegraph litesearchbox graphdialog rounded";r.innerHTML="<span class='name'>Search</span> <input autofocus type='text' class='value rounded'/><div class='helper'></div>";r.close=function(){e.search_box=null;n.body.focus();n.body.style.overflow="";setTimeout(function(){e.canvas.focus()},
20);r.parentNode&&r.parentNode.removeChild(r)};var k=null;1<this.ds.scale&&(r.style.transform="scale("+this.ds.scale+")");r.addEventListener("mouseenter",function(a){k&&(clearTimeout(k),k=null)});r.addEventListener("mouseleave",function(a){k=setTimeout(function(){r.close()},500)});e.search_box&&e.search_box.close();e.search_box=r;var m=r.querySelector(".helper"),p=null,z=null,t=null,q=r.querySelector("input");q&&(q.addEventListener("blur",function(a){this.focus()}),q.addEventListener("keydown",function(a){if(38==
a.keyCode)c(!1);else if(40==a.keyCode)c(!0);else if(27==a.keyCode)r.close();else if(13==a.keyCode)t?b(t.innerHTML):p?b(p):r.close();else{z&&clearInterval(z);z=setTimeout(d,10);return}a.preventDefault();a.stopPropagation();a.stopImmediatePropagation();return!0}));n.fullscreenElement?n.fullscreenElement.appendChild(r):(n.body.appendChild(r),n.body.style.overflow="hidden");g=g.getBoundingClientRect();var w=(a?a.clientY:g.top+.5*g.height)-20;r.style.left=(a?a.clientX:g.left+.5*g.width)-80+"px";r.style.top=
w+"px";a.layerY>g.height-200&&(m.style.maxHeight=g.height-a.layerY-20+"px");q.focus();return r};h.prototype.showEditPropertyValue=function(a,b,c){function d(){e(p.value)}function e(d){f&&f.values&&f.values.constructor===Object&&void 0!=f.values[d]&&(d=f.values[d]);"number"==typeof a.properties[b]&&(d=Number(d));if("array"==g||"object"==g)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();k.close();a.setDirtyCanvas(!0,
!0)}if(a&&void 0!==a.properties[b]){c=c||{};var f=a.getPropertyInfo(b),g=f.type,n="";if("string"==g||"number"==g||"array"==g||"object"==g)n="<input autofocus type='text' class='value'/>";else if("enum"!=g&&"combo"!=g||!f.values)if("boolean"==g)n="<input autofocus type='checkbox' class='value' "+(a.properties[b]?"checked":"")+"/>";else{console.warn("unknown type: "+g);return}else{n="<select autofocus type='text' class='value'>";for(var l in f.values){var h=l;f.values.constructor===Array&&(h=f.values[l]);
n+="<option value='"+h+"' "+(h==a.properties[b]?"selected":"")+">"+f.values[l]+"</option>"}n+="</select>"}var k=this.createDialog("<span class='name'>"+(f.label?f.label:b)+"</span>"+n+"<button>OK</button>",c);if("enum"!=g&&"combo"!=g||!f.values)if("boolean"==g)(p=k.querySelector("input"))&&p.addEventListener("click",function(a){e(!!p.checked)});else{if(p=k.querySelector("input"))p.addEventListener("blur",function(a){this.focus()}),h=void 0!==a.properties[b]?a.properties[b]:"","string"!==g&&(h=JSON.stringify(h)),
p.value=h,p.addEventListener("keydown",function(a){13==a.keyCode&&(d(),a.preventDefault(),a.stopPropagation())})}else{var p=k.querySelector("select");p.addEventListener("change",function(a){e(a.target.value)})}k.querySelector("button").addEventListener("click",d);return k}};h.prototype.createDialog=function(a,b){b=b||{};var c=document.createElement("div");c.className="graphdialog";c.innerHTML=a;a=this.canvas.getBoundingClientRect();var d=-20,e=-20;a&&(d-=a.left,e-=a.top);b.position?(d+=b.position[0],
e+=b.position[1]):b.event?(d+=b.event.clientX,e+=b.event.clientY):(d+=.5*this.canvas.width,e+=.5*this.canvas.height);c.style.left=d+"px";c.style.top=e+"px";this.canvas.parentNode.appendChild(c);c.close=function(){this.parentNode&&this.parentNode.removeChild(this)};return c};h.prototype.createPanel=function(a,b){b=b||{};var c=b.window||window,d=document.createElement("div");d.className="litegraph dialog";d.innerHTML="<div class='dialog-header'><span class='dialog-title'></span></div><div class='dialog-content'></div><div class='dialog-footer'></div>";
d.header=d.querySelector(".dialog-header");b.width&&(d.style.width=b.width+(b.width.constructor===Number?"px":""));b.height&&(d.style.height=b.height+(b.height.constructor===Number?"px":""));b.closable&&(b=document.createElement("span"),b.innerHTML="&#10005;",b.classList.add("close"),b.addEventListener("click",function(){d.close()}),d.header.appendChild(b));d.title_element=d.querySelector(".dialog-title");d.title_element.innerText=a;d.content=d.querySelector(".dialog-content");d.footer=d.querySelector(".dialog-footer");
d.close=function(){this.parentNode&&this.parentNode.removeChild(this)};d.clear=function(){this.content.innerHTML=""};d.addHTML=function(a,b,c){var e=document.createElement("div");b&&(e.className=b);e.innerHTML=a;c?d.footer.appendChild(e):d.content.appendChild(e);return e};d.addButton=function(a,b,c){var e=document.createElement("button");e.innerText=a;e.options=c;e.classList.add("btn");e.addEventListener("click",b);d.footer.appendChild(e);return e};d.addSeparator=function(){var a=document.createElement("div");
a.className="separator";d.content.appendChild(a)};d.addWidget=function(a,b,g,n,r){function e(a,b){console.log("change",a,b);n.callback&&n.callback(a,b);r&&r(a,b)}n=n||{};var f=String(g);a=a.toLowerCase();"number"==a&&(f=g.toFixed(3));var k=document.createElement("div");k.className="property";k.innerHTML="<span class='property_name'></span><span class='property_value'></span>";k.querySelector(".property_name").innerText=n.label||b;var z=k.querySelector(".property_value");z.innerText=f;k.dataset.property=
b;k.dataset.type=n.type||a;k.options=n;k.value=g;if("boolean"==a)k.classList.add("boolean"),g&&k.classList.add("bool-on"),k.addEventListener("click",function(){var a=this.dataset.property;this.value=!this.value;this.classList.toggle("bool-on");this.querySelector(".property_value").innerText=this.value?"true":"false";e(a,this.value)});else if("string"==a||"number"==a)z.setAttribute("contenteditable",!0),z.addEventListener("keydown",function(a){"Enter"==a.code&&(a.preventDefault(),this.blur())}),z.addEventListener("blur",
function(){var a=this.innerText,b=this.parentNode.dataset.property;"number"==this.parentNode.dataset.type&&(a=Number(a));e(b,a)});else if("enum"==a||"combo"==a)f=h.getPropertyPrintableValue(g,n.values),z.innerText=f,z.addEventListener("click",function(a){var b=this.parentNode.dataset.property,d=this;new l.ContextMenu(n.values||[],{event:a,className:"dark",callback:function(a,c,n){d.innerText=a;e(b,a);return!1}},c)});d.content.appendChild(k);return k};return d};h.getPropertyPrintableValue=function(a,
b){if(!b||b.constructor===Array)return String(a);if(b.constructor===Object){var c="",d;for(d in b)if(b[d]==a){c=d;break}return String(a)+" ("+c+")"}};h.prototype.showShowNodePanel=function(a){window.SELECTED_NODE=a;var b=document.querySelector("#node-panel");b&&b.close();var c=this.getCanvasWindow();b=this.createPanel(a.title||"",{closable:!0,window:c});b.id="node-panel";b.node=a;b.classList.add("settings");var d=this;(function(){b.content.innerHTML="";b.addHTML("<span class='node_type'>"+a.type+
"</span><span class='node_desc'>"+(a.constructor.desc||"")+"</span><span class='separator'></span>");b.addHTML("<h3>Properties</h3>");for(var c in a.properties){var f=a.properties[c],g=a.getPropertyInfo(c);a.onAddPropertyToPanel&&a.onAddPropertyToPanel(c,b)||b.addWidget(g.widget||g.type,c,f,g,function(b,c){d.graph.beforeChange(a);a.setProperty(b,c);d.graph.afterChange();d.dirty_canvas=!0})}b.addSeparator();if(a.onShowCustomPanelInfo)a.onShowCustomPanelInfo(b);b.addButton("Delete",function(){a.block_delete||
(a.graph.remove(a),b.close())}).classList.add("delete")})();this.canvas.parentNode.appendChild(b)};h.prototype.showSubgraphPropertiesDialog=function(a){function b(){d.clear();if(a.inputs)for(var c=0;c<a.inputs.length;++c){var f=a.inputs[c];if(!f.not_subgraph_input){var g=d.addHTML("<button>&#10005;</button> <span class='bullet_icon'></span><span class='name'></span><span class='type'></span>","subgraph_property");g.dataset.name=f.name;g.dataset.slot=c;g.querySelector(".name").innerText=f.name;g.querySelector(".type").innerText=
f.type;g.querySelector("button").addEventListener("click",function(c){a.removeInput(Number(this.parentNode.dataset.slot));b()})}}}console.log("showing subgraph properties dialog");var c=this.canvas.parentNode.querySelector(".subgraph_dialog");c&&c.close();var d=this.createPanel("Subgraph Inputs",{closable:!0,width:500});d.node=a;d.classList.add("subgraph_dialog");d.addHTML(" + <span class='label'>Name</span><input class='name'/><span class='label'>Type</span><input class='type'></input><button>+</button>",
"subgraph_property extra",!0).querySelector("button").addEventListener("click",function(c){c=this.parentNode;var d=c.querySelector(".name").value,e=c.querySelector(".type").value;d&&-1==a.findInputSlot(d)&&(a.addInput(d,e),c.querySelector(".name").value="",c.querySelector(".type").value="",b())});b();this.canvas.parentNode.appendChild(d);return d};h.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())}};h.onMenuNodeCollapse=function(a,b,c,d,e){e.graph.beforeChange(e);e.collapse();e.graph.afterChange(e)};h.onMenuNodePin=function(a,b,c,d,e){e.pin()};h.onMenuNodeMode=function(a,b,c,d,e){new l.ContextMenu(["Always","On Event","On Trigger","Never"],{event:c,callback:function(a){if(e)switch(a){case "On Event":e.mode=l.ON_EVENT;break;case "On Trigger":e.mode=l.ON_TRIGGER;break;case "Never":e.mode=l.NEVER;break;default:e.mode=l.ALWAYS}},parentMenu:d,
node:e});return!1};h.onMenuNodeColors=function(a,b,c,d,e){if(!e)throw"no node for color";b=[];b.push({value:null,content:"<span style='display: block; padding-left: 4px;'>No color</span>"});for(var f in h.node_colors)a=h.node_colors[f],a={value:f,content:"<span style='display: block; color: #999; padding-left: 4px; border-left: 8px solid "+a.color+"; background-color:"+a.bgcolor+"'>"+f+"</span>"},b.push(a);new l.ContextMenu(b,{event:c,callback:function(a){e&&((a=a.value?h.node_colors[a.value]:null)?
e.constructor===l.LGraphGroup?e.color=a.groupcolor:(e.color=a.color,e.bgcolor=a.bgcolor):(delete e.color,delete e.bgcolor),e.setDirtyCanvas(!0,!0))},parentMenu:d,node:e});return!1};h.onMenuNodeShapes=function(a,b,c,d,e){if(!e)throw"no node passed";new l.ContextMenu(l.VALID_SHAPES,{event:c,callback:function(a){e&&(e.graph.beforeChange(e),e.shape=a,e.graph.afterChange(e),e.setDirtyCanvas(!0))},parentMenu:d,node:e});return!1};h.onMenuNodeRemove=function(a,b,c,d,e){if(!e)throw"no node passed";!1!==e.removable&&
(a=e.graph,a.beforeChange(),a.remove(e),a.afterChange(),e.setDirtyCanvas(!0,!0))};h.onMenuNodeToSubgraph=function(a,b,c,d,e){a=e.graph;if(b=h.active_canvas)c=Object.values(b.selected_nodes||{}),c.length||(c=[e]),d=l.createNode("graph/subgraph"),d.pos=e.pos.concat(),a.add(d),d.buildFromNodes(c),b.deselectAllNodes(),e.setDirtyCanvas(!0,!0)};h.onMenuNodeClone=function(a,b,c,d,e){0!=e.clonable&&(a=e.clone())&&(a.pos=[e.pos[0]+5,e.pos[1]+5],e.graph.beforeChange(),e.graph.add(a),e.graph.afterChange(),e.setDirtyCanvas(!0,
!0))};h.node_colors={red:{color:"#322",bgcolor:"#533",groupcolor:"#A88"},brown:{color:"#332922",bgcolor:"#593930",groupcolor:"#b06634"},green:{color:"#232",bgcolor:"#353",groupcolor:"#8A8"},blue:{color:"#223",bgcolor:"#335",groupcolor:"#88A"},pale_blue:{color:"#2a363b",bgcolor:"#3f5159",groupcolor:"#3f789e"},cyan:{color:"#233",bgcolor:"#355",groupcolor:"#8AA"},purple:{color:"#323",bgcolor:"#535",groupcolor:"#a1309b"},yellow:{color:"#432",bgcolor:"#653",groupcolor:"#b58b2a"},black:{color:"#222",bgcolor:"#000",
groupcolor:"#444"}};h.prototype.getCanvasMenuOptions=function(){if(this.getMenuOptions)var a=this.getMenuOptions();else a=[{content:"Add Node",has_submenu:!0,callback:h.onMenuAdd},{content:"Add Group",callback:h.onGroupAdd}],this._graph_stack&&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};h.prototype.getNodeMenuOptions=function(a){var b=null;
b=a.getMenuOptions?a.getMenuOptions(this):[{content:"Inputs",has_submenu:!0,disabled:!0,callback:h.showMenuNodeOptionalInputs},{content:"Outputs",has_submenu:!0,disabled:!0,callback:h.showMenuNodeOptionalOutputs},null,{content:"Properties",has_submenu:!0,callback:h.onShowMenuNodeProperties},null,{content:"Title",callback:h.onShowPropertyEditor},{content:"Mode",has_submenu:!0,callback:h.onMenuNodeMode},{content:"Resize",callback:function(){if(a.resizable)return h.onResizeNode}},{content:"Collapse",
callback:h.onMenuNodeCollapse},{content:"Pin",callback:h.onMenuNodePin},{content:"Colors",has_submenu:!0,callback:h.onMenuNodeColors},{content:"Shapes",has_submenu:!0,callback:h.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:h.onMenuNodeClone});b.push(null,
{content:"Remove",disabled:!(!1!==a.removable&&!a.block_delete),callback:h.onMenuNodeRemove});if(a.graph&&a.graph.onGetNodeMenuOptions)a.graph.onGetNodeMenuOptions(b,a);return b};h.prototype.getGroupMenuOptions=function(a){return[{content:"Title",callback:h.onShowPropertyEditor},{content:"Color",has_submenu:!0,callback:h.onMenuNodeColors},{content:"Font size",property:"font_size",type:"Number",callback:h.onShowPropertyEditor},null,{content:"Remove",callback:h.onMenuNodeRemove}]};h.prototype.processContextMenu=
function(a,b){var c=this,d=h.active_canvas.getCanvasWindow(),e=null,f={event:b,callback:function(b,d,e){if(b)if("Remove Slot"==b.content)b=b.slot,b.input?a.removeInput(b.slot):b.output&&a.removeOutput(b.slot);else if("Disconnect Links"==b.content)b=b.slot,b.output?a.disconnectOutput(b.slot):b.input&&a.disconnectInput(b.slot);else if("Rename Slot"==b.content){b=b.slot;var n=b.input?a.getInputInfo(b.slot):a.getOutputInfo(b.slot),f=c.createDialog("<span class='name'>Name</span><input autofocus type='text'/><button>OK</button>",
d),g=f.querySelector("input");g&&n&&(g.value=n.label||"");f.querySelector("button").addEventListener("click",function(a){g.value&&(n&&(n.label=g.value),c.setDirty(!0));f.close()})}},extra:a};a&&(f.title=a.type);var g=null;a&&(g=a.getSlotInPosition(b.canvasX,b.canvasY),h.active_node=a);g?(e=[],a.getSlotMenuOptions?e=a.getSlotMenuOptions(g):(g&&g.output&&g.output.links&&g.output.links.length&&e.push({content:"Disconnect Links",slot:g}),b=g.input||g.output,e.push(b.locked?"Cannot remove":{content:"Remove Slot",
slot:g}),e.push(b.nameLocked?"Cannot rename":{content:"Rename Slot",slot:g})),f.title=(g.input?g.input.type:g.output.type)||"*",g.input&&g.input.type==l.ACTION&&(f.title="Action"),g.output&&g.output.type==l.EVENT&&(f.title="Event")):a?e=this.getNodeMenuOptions(a):(e=this.getCanvasMenuOptions(),(g=this.graph.getGroupOnPos(b.canvasX,b.canvasY))&&e.push(null,{content:"Edit Group",has_submenu:!0,submenu:{title:"Group",extra:g,options:this.getGroupMenuOptions(g)}}));e&&new l.ContextMenu(e,f,d)};"undefined"!=
typeof window&&window.CanvasRenderingContext2D&&(window.CanvasRenderingContext2D.prototype.roundRect=function(a,b,c,d,e,f){void 0===e&&(e=5);void 0===f&&(f=e);this.moveTo(a+e,b);this.lineTo(a+c-e,b);this.quadraticCurveTo(a+c,b,a+c,b+e);this.lineTo(a+c,b+d-f);this.quadraticCurveTo(a+c,b+d,a+c-f,b+d);this.lineTo(a+f,b+d);this.quadraticCurveTo(a,b+d,a,b+d-f);this.lineTo(a,b+e);this.quadraticCurveTo(a,b,a+e,b)});l.compareObjects=function(a,b){for(var c in a)if(a[c]!=b[c])return!1;return!0};l.distance=
E;l.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")+")"};l.isInsideRectangle=C;l.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)};l.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};l.overlapBounding=B;l.hex2num=function(a){"#"==a.charAt(0)&&(a=a.slice(1));a=a.toUpperCase();
for(var b=Array(3),c=0,d,e,f=0;6>f;f+=2)d="0123456789ABCDEF".indexOf(a.charAt(f)),e="0123456789ABCDEF".indexOf(a.charAt(f+1)),b[c]=16*d+e,c++;return b};l.num2hex=function(a){for(var b="#",c,d,e=0;3>e;e++)c=a[e]/16,d=a[e]%16,b+="0123456789ABCDEF".charAt(c)+"0123456789ABCDEF".charAt(d);return b};x.prototype.addItem=function(a,b,c){function d(a){var b=this.value;b&&b.has_submenu&&e.call(this,a)}function e(a){var b=this.value,d=!0;f.current_submenu&&f.current_submenu.close(a);if(c.callback){var e=c.callback.call(this,
b,c,a,f,c.node);!0===e&&(d=!1)}if(b&&(b.callback&&!c.ignore_item_callbacks&&!0!==b.disabled&&(e=b.callback.call(this,b,c,a,f,c.extra),!0===e&&(d=!1)),b.submenu)){if(!b.submenu.options)throw"ContextMenu submenu needs options";new f.constructor(b.submenu.options,{callback:b.submenu.callback,event:a,parentMenu:f,ignore_item_callbacks:b.submenu.ignore_item_callbacks,title:b.submenu.title,extra:b.submenu.extra,autoopen:c.autoopen});d=!1}d&&!f.lock&&f.close()}var f=this;c=c||{};var g=document.createElement("div");
g.className="litemenu-entry submenu";var n=!1;if(null===b)g.classList.add("separator");else{g.innerHTML=b&&b.title?b.title:a;if(g.value=b)b.disabled&&(n=!0,g.classList.add("disabled")),(b.submenu||b.has_submenu)&&g.classList.add("has_submenu");"function"==typeof b?(g.dataset.value=a,g.onclick_callback=b):g.dataset.value=b;b.className&&(g.className+=" "+b.className)}this.root.appendChild(g);n||g.addEventListener("click",e);c.autoopen&&g.addEventListener("mouseenter",d);return g};x.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&&!x.isCursorOverElement(a,this.parentMenu.root)&&x.trigger(this.parentMenu.root,"mouseleave",a));this.current_submenu&&this.current_submenu.close(a,!0);this.root.closing_timer&&clearTimeout(this.root.closing_timer)};x.trigger=function(a,b,c,d){var e=document.createEvent("CustomEvent");e.initCustomEvent(b,
!0,!0,c);e.srcElement=d;a.dispatchEvent?a.dispatchEvent(e):a.__events&&a.__events.dispatchEvent(e);return e};x.prototype.getTopMenu=function(){return this.options.parentMenu?this.options.parentMenu.getTopMenu():this};x.prototype.getFirstEvent=function(){return this.options.parentMenu?this.options.parentMenu.getFirstEvent():this.options.event};x.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};l.ContextMenu=x;l.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])}};l.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)))};I.sampleCurve=function(a,b){if(b){for(var c=0;c<b.length-1;++c){var d=b[c],e=b[c+1];if(!(e[0]<a)){b=e[0]-d[0];if(1E-5>Math.abs(b))return d[1];a=(a-d[0])/b;return d[1]*(1-a)+e[1]*a}}return 0}};I.prototype.draw=function(a,b,c,d,e,f){if(c=this.points){this.size=b;var g=b[0]-2*this.margin;b=b[1]-2*this.margin;e=e||"#666";a.save();a.translate(this.margin,
this.margin);d&&(a.fillStyle="#111",a.fillRect(0,0,g,b),a.fillStyle="#222",a.fillRect(.5*g,0,1,b),a.strokeStyle="#333",a.strokeRect(0,0,g,b));a.strokeStyle=e;f&&(a.globalAlpha=.5);a.beginPath();for(d=0;d<c.length;++d)e=c[d],a.lineTo(e[0]*g,(1-e[1])*b);a.stroke();a.globalAlpha=1;if(!f)for(d=0;d<c.length;++d)e=c[d],a.fillStyle=this.selected==d?"#FFF":this.nearest==d?"#DDD":"#AAA",a.beginPath(),a.arc(e[0]*g,(1-e[1])*b,2,0,2*Math.PI),a.fill();a.restore()}};I.prototype.onMouseDown=function(a,b){var c=
this.points;if(c&&!(0>a[1])){var d=this.size[0]-2*this.margin,e=this.size[1]-2*this.margin,f=a[0]-this.margin;a=a[1]-this.margin;this.selected=this.getCloserPoint([f,a],30/b.ds.scale);-1==this.selected&&(b=[f/d,1-a/e],c.push(b),c.sort(function(a,b){return a[0]-b[0]}),this.selected=c.indexOf(b),this.must_update=!0);if(-1!=this.selected)return!0}};I.prototype.onMouseMove=function(a,b){var c=this.points;if(c){var d=this.selected;if(!(0>d)){var e=(a[0]-this.margin)/(this.size[0]-2*this.margin),f=(a[1]-
this.margin)/(this.size[1]-2*this.margin);this._nearest=this.getCloserPoint([a[0]-this.margin,a[1]-this.margin],30/b.ds.scale);if(b=c[d]){var g=0==d||d==c.length-1;!g&&(-10>a[0]||a[0]>this.size[0]+10||-10>a[1]||a[1]>this.size[1]+10)?(c.splice(d,1),this.selected=-1):(b[0]=g?0==d?0:1:Math.clamp(e,0,1),b[1]=1-Math.clamp(f,0,1),c.sort(function(a,b){return a[0]-b[0]}),this.selected=c.indexOf(b),this.must_update=!0)}}}};I.prototype.onMouseUp=function(a,b){this.selected=-1;return!1};I.prototype.getCloserPoint=
function(a,b){var c=this.points;if(!c)return-1;b=b||30;for(var d=this.size[0]-2*this.margin,e=this.size[1]-2*this.margin,f=c.length,g=[0,0],n=1E6,l=-1,h=0;h<f;++h){var k=c[h];g[0]=k[0]*d;g[1]=(1-k[1])*e;k=vec2.distance(a,g);k>n||k>b||(l=h,n=k)}return l};l.CurveEditor=I;l.getParameterNames=function(a){return(a+"").replace(/[/][/].*$/gm,"").replace(/\s+/g,"").replace(/[/][*][^/*]*[*][/]/g,"").split("){",1)[0].replace(/^[^(]*[(]/,"").replace(/=[^,]+/g,"").split(",").filter(Boolean)};Math.clamp=function(a,
b,c){return b>a?b:c<a?c:a};"undefined"==typeof window||window.requestAnimationFrame||(window.requestAnimationFrame=window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(a){window.setTimeout(a,1E3/60)})})(this);"undefined"!=typeof exports&&(exports.LiteGraph=this.LiteGraph);
(function(v){function m(){this.addOutput("in ms","number");this.addOutput("in sec","number")}function q(){this.size=[140,80];this.properties={enabled:!0};this.enabled=!0;this.subgraph=new g.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 k(){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 t(){this.addInput("","");this.name_in_graph="";this.properties={};var a=this;Object.defineProperty(this.properties,"name",{get:function(){return a.name_in_graph},set:function(b){""!=
b&&b!=a.name_in_graph&&(a.name_in_graph?a.graph.renameOutput(a.name_in_graph,b):a.graph.addOutput(b,a.properties.type),a.name_widget.value=b,a.name_in_graph=b)},enumerable:!0});Object.defineProperty(this.properties,"type",{get:function(){return a.inputs[0].type},set:function(b){if("action"==b||"event"==b)b=g.ACTION;g.isValidConnection(a.inputs[0].type,b)||a.disconnectInput(0);a.inputs[0].type=b;a.name_in_graph&&a.graph.changeOutputType(a.name_in_graph,a.inputs[0].type);a.type_widget.value=b||""},
enumerable:!0});this.name_widget=this.addWidget("text","Name",this.properties.name,"name");this.type_widget=this.addWidget("text","Type",this.properties.type,"type");this.widgets_up=!0;this.size=[180,60]}function w(){this.addOutput("value","number");this.addProperty("value",1);this.widget=this.addWidget("number","value",1,"value");this.widgets_up=!0;this.size=[180,30]}function h(){this.addOutput("","boolean");this.addProperty("value",!0);this.widget=this.addWidget("toggle","value",!0,"value");this.widgets_up=
!0;this.size=[140,30]}function E(){this.addOutput("","string");this.addProperty("value","");this.widget=this.addWidget("text","value","","value");this.widgets_up=!0;this.size=[180,30]}function C(){this.addOutput("obj","object");this.size=[120,30];this._object={}}function B(){this.addInput("url","");this.addOutput("","");this.addProperty("url","");this.addProperty("type","text");this.widget=this.addWidget("text","url","","url");this._data=null}function x(){this.addOutput("","");this.addProperty("value",
"");this.widget=this.addWidget("text","json","","value");this.widgets_up=!0;this.size=[140,30];this._value=null}function I(){this._value=[];this.addInput("","");this.addOutput("","array");this.addOutput("length","number");this.addProperty("value","[]");this.widget=this.addWidget("text","array",this.properties.value,"value");this.widgets_up=!0;this.size=[140,50]}function l(){this.addInput("arr","array");this.addInput("value","");this.addOutput("arr","array");this.properties={index:0};this.widget=this.addWidget("number",
"i",this.properties.index,"index")}function L(){this.addInput("array","array,table,string");this.addInput("index","number");this.addOutput("value","");this.addProperty("index",0)}function G(){this.addInput("table","table");this.addInput("row","number");this.addInput("col","number");this.addOutput("value","");this.addProperty("row",0);this.addProperty("column",0)}function A(){this.addInput("obj","");this.addOutput("","");this.addProperty("value","");this.widget=this.addWidget("text","prop.","",this.setValue.bind(this));
this.widgets_up=!0;this.size=[140,30];this._value=null}function J(){this.addInput("obj","");this.addOutput("keys","array");this.size=[140,30]}function D(){this.addInput("obj","");this.addInput("value","");this.addOutput("obj","");this.properties={property:""};this.name_widget=this.addWidget("text","prop.",this.properties.property,"property")}function H(){this.addInput("A","");this.addInput("B","");this.addOutput("","");this._result={};var a=this;this.addWidget("button","clear","",function(){a._result=
{}});this.size=this.computeSize()}function F(){this.size=[60,30];this.addInput("in");this.addOutput("out");this.properties={varname:"myname",container:F.LITEGRAPH};this.value=null}function a(){this.size=[60,30];this.addInput("data",0);this.addInput("download",g.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 d(){this.mode=g.ON_EVENT;this.size=[80,30];this.addProperty("msg","");this.addInput("log",g.EVENT);this.addInput("msg",0)}function e(){this.mode=g.ON_EVENT;this.addProperty("msg","");this.addInput("",g.EVENT);this.widget=this.addWidget("text","Text","","msg");this.widgets_up=!0;this.size=[200,30]}function f(){this.size=[60,30];this.addProperty("onExecute","return A;");this.addInput("A","");this.addInput("B","");this.addOutput("out","");this._func=
null;this.data={}}var g=v.LiteGraph;m.title="Time";m.desc="Time";m.prototype.onExecute=function(){this.setOutputData(0,1E3*this.graph.globaltime);this.setOutputData(1,this.graph.globaltime)};g.registerNodeType("basic/time",m);q.title="Subgraph";q.desc="Graph inside a node";q.title_color="#334";q.prototype.onGetInputs=function(){return[["enabled","boolean"]]};q.prototype.onDblClick=function(a,b,c){var d=this;setTimeout(function(){c.openSubgraph(d.subgraph)},10)};q.prototype.onAction=function(a,b){this.subgraph.onAction(a,
b)};q.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)}};q.prototype.sendEventToAllNodes=function(a,b,c){this.enabled&&this.subgraph.sendEventToAllNodes(a,b,c)};q.prototype.onDrawBackground=
function(a,b,c,d){this.flags.collapsed||(b=this.size[1]-g.NODE_TITLE_HEIGHT+.5,d=g.isInsideRectangle(d[0],d[1],this.pos[0],this.pos[1]+b,this.size[0],g.NODE_TITLE_HEIGHT),a.fillStyle=d?"#555":"#222",a.beginPath(),this._shape==g.BOX_SHAPE?a.rect(0,b,this.size[0]+1,g.NODE_TITLE_HEIGHT):a.roundRect(0,b,this.size[0]+1,g.NODE_TITLE_HEIGHT,0,8),a.fill(),a.textAlign="center",a.font="24px Arial",a.fillStyle=d?"#DDD":"#999",a.fillText("+",.5*this.size[0],b+24))};q.prototype.onMouseDown=function(a,b,c){b[1]>
this.size[1]-g.NODE_TITLE_HEIGHT+.5&&c.showSubgraphPropertiesDialog(this)};q.prototype.computeSize=function(){return[200,Math.max(this.inputs?this.inputs.length:0,this.outputs?this.outputs.length:0)*g.NODE_SLOT_HEIGHT+g.NODE_TITLE_HEIGHT]};q.prototype.onSubgraphTrigger=function(a,b){a=this.findOutputSlot(a);-1!=a&&this.triggerSlot(a)};q.prototype.onSubgraphNewInput=function(a,b){-1==this.findInputSlot(a)&&this.addInput(a,b)};q.prototype.onSubgraphRenamedInput=function(a,b){a=this.findInputSlot(a);
-1!=a&&(this.getInputInfo(a).name=b)};q.prototype.onSubgraphTypeChangeInput=function(a,b){a=this.findInputSlot(a);-1!=a&&(this.getInputInfo(a).type=b)};q.prototype.onSubgraphRemovedInput=function(a){a=this.findInputSlot(a);-1!=a&&this.removeInput(a)};q.prototype.onSubgraphNewOutput=function(a,b){-1==this.findOutputSlot(a)&&this.addOutput(a,b)};q.prototype.onSubgraphRenamedOutput=function(a,b){a=this.findOutputSlot(a);-1!=a&&(this.getOutputInfo(a).name=b)};q.prototype.onSubgraphTypeChangeOutput=function(a,
b){a=this.findOutputSlot(a);-1!=a&&(this.getOutputInfo(a).type=b)};q.prototype.onSubgraphRemovedOutput=function(a){a=this.findInputSlot(a);-1!=a&&this.removeOutput(a)};q.prototype.getExtraMenuOptions=function(a){var b=this;return[{content:"Open",callback:function(){a.openSubgraph(b.subgraph)}}]};q.prototype.onResize=function(a){a[1]+=20};q.prototype.serialize=function(){var a=g.LGraphNode.prototype.serialize.call(this);a.subgraph=this.subgraph.serialize();return a};q.prototype.clone=function(){var a=
g.createNode(this.type),b=this.serialize();delete b.id;delete b.inputs;delete b.outputs;a.configure(b);return a};q.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 n=
0;n<f.links.length&&(!(g=d.graph.links[f.links[n]])||b[g.target_id]);++n);}};g.Subgraph=q;g.registerNodeType("graph/subgraph",q);k.title="Input";k.desc="Input of the graph";k.prototype.onConfigure=function(){this.updateType()};k.prototype.updateType=function(){var a=this.properties.type;this.type_widget.value=a;this.outputs[0].type!=a&&(g.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)};k.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()};k.prototype.getTitle=function(){return this.flags.collapsed?this.properties.name:this.title};k.prototype.onAction=function(a,b){this.properties.type==g.EVENT&&this.triggerSlot(0,b)};k.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)};
k.prototype.onRemoved=function(){this.name_in_graph&&this.graph.removeInput(this.name_in_graph)};g.GraphInput=k;g.registerNodeType("graph/input",k);t.title="Output";t.desc="Output of the graph";t.prototype.onExecute=function(){this._value=this.getInputData(0);this.graph.setOutputData(this.properties.name,this._value)};t.prototype.onAction=function(a,b){this.properties.type==g.ACTION&&this.graph.trigger(this.properties.name,b)};t.prototype.onRemoved=function(){this.name_in_graph&&this.graph.removeOutput(this.name_in_graph)};
t.prototype.getTitle=function(){return this.flags.collapsed?this.properties.name:this.title};g.GraphOutput=t;g.registerNodeType("graph/output",t);w.title="Const Number";w.desc="Constant number";w.prototype.onExecute=function(){this.setOutputData(0,parseFloat(this.properties.value))};w.prototype.getTitle=function(){return this.flags.collapsed?this.properties.value:this.title};w.prototype.setValue=function(a){this.setProperty("value",a)};w.prototype.onDrawBackground=function(a){this.outputs[0].label=
this.properties.value.toFixed(3)};g.registerNodeType("basic/const",w);h.title="Const Boolean";h.desc="Constant boolean";h.prototype.getTitle=w.prototype.getTitle;h.prototype.onExecute=function(){this.setOutputData(0,this.properties.value)};h.prototype.setValue=w.prototype.setValue;h.prototype.onGetInputs=function(){return[["toggle",g.ACTION]]};h.prototype.onAction=function(a){this.setValue(!this.properties.value)};g.registerNodeType("basic/boolean",h);E.title="Const String";E.desc="Constant string";
E.prototype.getTitle=w.prototype.getTitle;E.prototype.onExecute=function(){this.setOutputData(0,this.properties.value)};E.prototype.setValue=w.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)};g.registerNodeType("basic/string",E);C.title="Const Object";C.desc="Constant Object";C.prototype.onExecute=function(){this.setOutputData(0,this._object)};g.registerNodeType("basic/object",C);B.title=
"Const File";B.desc="Fetches a file from an url";B["@type"]={type:"enum",values:["text","arraybuffer","blob","json"]};B.prototype.onPropertyChanged=function(a,b){"url"==a&&(null==b||""==b?this._data=null:this.fetchFile(b))};B.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)};B.prototype.setValue=w.prototype.setValue;B.prototype.fetchFile=function(a){var b=this;a&&a.constructor===
String?(this._url=a,this._type=this.properties.type,"http"==a.substr(0,4)&&g.proxy&&(a=g.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)};B.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)};g.registerNodeType("basic/file",
B);x.title="Const Data";x.desc="Constant Data";x.prototype.onPropertyChanged=function(a,b){this.widget.value=b;if(null!=b&&""!=b)try{this._value=JSON.parse(b),this.boxcolor="#AEA"}catch(K){this.boxcolor="red"}};x.prototype.onExecute=function(){this.setOutputData(0,this._value)};x.prototype.setValue=w.prototype.setValue;g.registerNodeType("basic/data",x);I.title="Const Array";I.desc="Constant Array";I.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(K){this.boxcolor="red"}};I.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)};I.prototype.setValue=w.prototype.setValue;g.registerNodeType("basic/array",I);l.title="Set Array";l.desc="Sets index of array";l.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))}};g.registerNodeType("basic/set_array",l);L.title="Array[i]";L.desc="Returns an element from an array";L.prototype.onExecute=function(){var a=this.getInputData(0),b=this.getInputData(1);null==b&&(b=this.properties.index);null!=a&&null!=b&&this.setOutputData(0,a[Math.floor(Number(b))])};g.registerNodeType("basic/array[]",L);G.title=
"Table[row][col]";G.desc="Returns an element from a table";G.prototype.onExecute=function(){var a=this.getInputData(0),b=this.getInputData(1),c=this.getInputData(2);null==b&&(b=this.properties.row);null==c&&(c=this.properties.column);null!=a&&null!=b&&null!=c&&((b=a[Math.floor(Number(b))])?this.setOutputData(0,b[Math.floor(Number(c))]):this.setOutputData(0,null))};g.registerNodeType("basic/table[][]",G);A.title="Object property";A.desc="Outputs the property of an object";A.prototype.setValue=function(a){this.properties.value=
a;this.widget.value=a};A.prototype.getTitle=function(){return this.flags.collapsed?"in."+this.properties.value:this.title};A.prototype.onPropertyChanged=function(a,b){this.widget.value=b};A.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,a[this.properties.value])};g.registerNodeType("basic/object_property",A);J.title="Object keys";J.desc="Outputs an array with the keys of an object";J.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,
Object.keys(a))};g.registerNodeType("basic/object_keys",J);D.title="Set Object";D.desc="Adds propertiesrty to object";D.prototype.onExecute=function(){var a=this.getInputData(0);if(a){var b=this.getInputData(1);void 0!==b&&(this.properties.property&&(a[this.properties.property]=b),this.setOutputData(0,a))}};g.registerNodeType("basic/set_object",D);H.title="Merge Objects";H.desc="Creates an object copying properties from others";H.prototype.onExecute=function(){var a=this.getInputData(0),b=this.getInputData(1),
c=this._result;if(a)for(var d in a)c[d]=a[d];if(b)for(d in b)c[d]=b[d];this.setOutputData(0,c)};g.registerNodeType("basic/merge_objects",H);F.title="Variable";F.desc="store/read variable value";F.LITEGRAPH=0;F.GRAPH=1;F.GLOBALSCOPE=2;F["@container"]={type:"enum",values:{litegraph:F.LITEGRAPH,graph:F.GRAPH,global:F.GLOBALSCOPE}};F.prototype.onExecute=function(){var a=this.getContainer();this.isInputConnected(0)?(this.value=this.getInputData(0),a[this.properties.varname]=this.value,this.setOutputData(0,
this.value)):this.setOutputData(0,a[this.properties.varname])};F.prototype.getContainer=function(){switch(this.properties.container){case F.GRAPH:return this.graph?this.graph.vars:{};case F.GLOBALSCOPE:return v;default:return g.Globals}};F.prototype.getTitle=function(){return this.properties.varname};g.registerNodeType("basic/variable",F);g.wrapFunctionAsNode("basic/length",function(a){return a&&null!=a.length?Number(a.length):0},[""],"number");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};g.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)};g.registerNodeType("basic/watch",b);c.title="Cast";c.desc="Allows to connect different types";c.prototype.onExecute=function(){this.setOutputData(0,this.getInputData(0))};g.registerNodeType("basic/cast",c);d.title="Console";d.desc="Show value inside the console";
d.prototype.onAction=function(a,b){"log"==a?console.log(b):"warn"==a?console.warn(b):"error"==a&&console.error(b)};d.prototype.onExecute=function(){var a=this.getInputData(1);null!==a&&(this.properties.msg=a);console.log(a)};d.prototype.onGetInputs=function(){return[["log",g.ACTION],["warn",g.ACTION],["error",g.ACTION]]};g.registerNodeType("basic/console",d);e.title="Alert";e.desc="Show an alert window";e.color="#510";e.prototype.onConfigure=function(a){this.widget.value=a.properties.msg};e.prototype.onAction=
function(a,b){var c=this.properties.msg;setTimeout(function(){alert(c)},10)};g.registerNodeType("basic/alert",e);f.prototype.onConfigure=function(a){a.properties.onExecute&&g.allow_scripts?this.compileCode(a.properties.onExecute):console.warn("Script not compiled, LiteGraph.allow_scripts is false")};f.title="Script";f.desc="executes a code (max 100 characters)";f.widgets_info={onExecute:{type:"code"}};f.prototype.onPropertyChanged=function(a,b){"onExecute"==a&&g.allow_scripts?this.compileCode(b):
console.warn("Script not compiled, LiteGraph.allow_scripts is false")};f.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(p){console.error("Error parsing script"),console.error(p)}}};f.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)}};f.prototype.onGetOutputs=function(){return[["C",""]]};g.registerNodeType("basic/script",f)})(this);
(function(v){function m(){this.size=[60,30];this.addInput("event",x.ACTION)}function q(){this.size=[60,30];this.addInput("if","");this.addOutput("true",x.EVENT);this.addOutput("change",x.EVENT);this.addOutput("false",x.EVENT);this.properties={only_on_change:!0};this.prev=0}function k(){this.addInput("",x.ACTION);this.addInput("",x.ACTION);this.addInput("",x.ACTION);this.addInput("",x.ACTION);this.addInput("",x.ACTION);this.addInput("",x.ACTION);this.addOutput("",x.EVENT);this.addOutput("",x.EVENT);
this.addOutput("",x.EVENT);this.addOutput("",x.EVENT);this.addOutput("",x.EVENT);this.addOutput("",x.EVENT);this.size=[120,30];this.flags={horizontal:!0,render_box:!1}}function t(){this.size=[60,30];this.addInput("event",x.ACTION);this.addOutput("event",x.EVENT);this.properties={equal_to:"",has_property:"",property_equal_to:""}}function w(){this.addInput("in",x.ACTION);this.addInput("cond","boolean");this.addOutput("true",x.EVENT);this.addOutput("false",x.EVENT);this.size=[120,60];this._value=!1}
function h(){this.addInput("inc",x.ACTION);this.addInput("dec",x.ACTION);this.addInput("reset",x.ACTION);this.addOutput("change",x.EVENT);this.addOutput("num","number");this.num=0}function E(){this.size=[60,30];this.addProperty("time_in_ms",1E3);this.addInput("event",x.ACTION);this.addOutput("on_time",x.EVENT);this._pending=[]}function C(){this.addProperty("interval",1E3);this.addProperty("event","tick");this.addOutput("on_tick",x.EVENT);this.time=0;this.last_interval=1E3;this.triggered=!1}function B(){this.addInput("data",
"");this.addInput("assign",x.ACTION);this.addOutput("data","");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 x=v.LiteGraph;m.title="Log Event";m.desc="Log event in console";m.prototype.onAction=function(h,l){console.log(h,l)};x.registerNodeType("events/log",m);q.title="TriggerEvent";q.desc="Triggers event if input evaluates to true";q.prototype.onExecute=function(h,l){h=this.getInputData(0);
var k=h!=this.prev;0===this.prev&&(k=!1);var t=k&&this.properties.only_on_change||!k&&!this.properties.only_on_change;h&&t&&this.triggerSlot(0,l);!h&&t&&this.triggerSlot(2,l);k&&this.triggerSlot(1,l);this.prev=h};x.registerNodeType("events/trigger",q);k.title="Sequencer";k.desc="Trigger events when an event arrives";k.prototype.getTitle=function(){return""};k.prototype.onAction=function(h,l){if(this.outputs)for(h=0;h<this.outputs.length;++h)this.triggerSlot(h,l)};x.registerNodeType("events/sequencer",
k);t.title="Filter Event";t.desc="Blocks events that do not match the filter";t.prototype.onAction=function(h,l){if(null!=l&&(!this.properties.equal_to||this.properties.equal_to==l)){if(this.properties.has_property&&(h=l[this.properties.has_property],null==h||this.properties.property_equal_to&&this.properties.property_equal_to!=h))return;this.triggerSlot(0,l)}};x.registerNodeType("events/filter",t);w.title="Branch";w.desc="If condition is true, outputs triggers true, otherwise false";w.prototype.onExecute=
function(){this._value=this.getInputData(1)};w.prototype.onAction=function(h,l){this.triggerSlot(this._value?0:1)};x.registerNodeType("events/branch",w);h.title="Counter";h.desc="Counts events";h.prototype.getTitle=function(){return this.flags.collapsed?String(this.num):this.title};h.prototype.onAction=function(h,l){l=this.num;"inc"==h?this.num+=1:"dec"==h?--this.num:"reset"==h&&(this.num=0);this.num!=l&&this.trigger("change",this.num)};h.prototype.onDrawBackground=function(h){this.flags.collapsed||
(h.fillStyle="#AAA",h.font="20px Arial",h.textAlign="center",h.fillText(this.num,.5*this.size[0],.5*this.size[1]))};h.prototype.onExecute=function(){this.setOutputData(1,this.num)};x.registerNodeType("events/counter",h);E.title="Delay";E.desc="Delays one event";E.prototype.onAction=function(h,l){h=this.properties.time_in_ms;0>=h?this.trigger(null,l):this._pending.push([h,l])};E.prototype.onExecute=function(){var h=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 k=this._pending[l];k[0]-=h;0<k[0]||(this._pending.splice(l,1),--l,this.trigger(null,k[1]))}};E.prototype.onGetInputs=function(){return[["event",x.ACTION],["time_in_ms","number"]]};x.registerNodeType("events/delay",E);C.title="Timer";C.desc="Sends an event every N milliseconds";C.prototype.onStart=function(){this.time=0};C.prototype.getTitle=function(){return"Timer: "+this.last_interval.toString()+"ms"};C.on_color="#AAA";C.off_color="#222";C.prototype.onDrawBackground=
function(){this.boxcolor=this.triggered?C.on_color:C.off_color;this.triggered=!1};C.prototype.onExecute=function(){var h=0==this.time;this.time+=1E3*this.graph.elapsed_time;this.last_interval=Math.max(1,this.getInputOrProperty("interval")|0);!h&&(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))};C.prototype.onGetInputs=function(){return[["interval","number"]]};C.prototype.onGetOutputs=function(){return[["tick","boolean"]]};x.registerNodeType("events/timer",C);B.title="Data Store";B.desc="Stores data and only changes when event is received";B.prototype.onExecute=function(){this._last_value=this.getInputData(0);this.setOutputData(0,this.properties.data)};B.prototype.onAction=function(h,l){this.properties.data=this._last_value};B.prototype.onSerialize=
function(h){null!=h.data&&(0==this.properties.serialize||h.data.constructor!==String&&h.data.constructor!==Number&&h.data.constructor!==Boolean&&h.data.constructor!==Array&&h.data.constructor!==Object)&&(h.data=null)};x.registerNodeType("basic/data_store",B)})(this);
(function(v){function m(){this.addOutput("left_x_axis","number");this.addOutput("left_y_axis","number");this.addOutput("button_pressed",q.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 q=v.LiteGraph;m.title="Gamepad";m.desc="gets the input of the gamepad";m.CENTER=0;m.LEFT=1;m.RIGHT=2;m.UP=4;m.DOWN=
8;m.zero=new Float32Array(2);m.buttons="a b x y lb rb lt rt back start ls rs home".split(" ");m.prototype.onExecute=function(){var k=this.getGamepad(),t=this.properties.threshold||0;k&&(this._left_axis[0]=Math.abs(k.xbox.axes.lx)>t?k.xbox.axes.lx:0,this._left_axis[1]=Math.abs(k.xbox.axes.ly)>t?k.xbox.axes.ly:0,this._right_axis[0]=Math.abs(k.xbox.axes.rx)>t?k.xbox.axes.rx:0,this._right_axis[1]=Math.abs(k.xbox.axes.ry)>t?k.xbox.axes.ry:0,this._triggers[0]=Math.abs(k.xbox.axes.ltrigger)>t?k.xbox.axes.ltrigger:
0,this._triggers[1]=Math.abs(k.xbox.axes.rtrigger)>t?k.xbox.axes.rtrigger:0);if(this.outputs)for(t=0;t<this.outputs.length;t++){var q=this.outputs[t];if(q.links&&q.links.length){var h=null;if(k)switch(q.name){case "left_axis":h=this._left_axis;break;case "right_axis":h=this._right_axis;break;case "left_x_axis":h=this._left_axis[0];break;case "left_y_axis":h=this._left_axis[1];break;case "right_x_axis":h=this._right_axis[0];break;case "right_y_axis":h=this._right_axis[1];break;case "trigger_left":h=
this._triggers[0];break;case "trigger_right":h=this._triggers[1];break;case "a_button":h=k.xbox.buttons.a?1:0;break;case "b_button":h=k.xbox.buttons.b?1:0;break;case "x_button":h=k.xbox.buttons.x?1:0;break;case "y_button":h=k.xbox.buttons.y?1:0;break;case "lb_button":h=k.xbox.buttons.lb?1:0;break;case "rb_button":h=k.xbox.buttons.rb?1:0;break;case "ls_button":h=k.xbox.buttons.ls?1:0;break;case "rs_button":h=k.xbox.buttons.rs?1:0;break;case "hat_left":h=k.xbox.hatmap&m.LEFT;break;case "hat_right":h=
k.xbox.hatmap&m.RIGHT;break;case "hat_up":h=k.xbox.hatmap&m.UP;break;case "hat_down":h=k.xbox.hatmap&m.DOWN;break;case "hat":h=k.xbox.hatmap;break;case "start_button":h=k.xbox.buttons.start?1:0;break;case "back_button":h=k.xbox.buttons.back?1:0;break;case "button_pressed":for(q=0;q<this._current_buttons.length;++q)this._current_buttons[q]&&!this._previous_buttons[q]&&this.triggerSlot(t,m.buttons[q])}else switch(q.name){case "button_pressed":break;case "left_axis":case "right_axis":h=m.zero;break;
default:h=0}this.setOutputData(t,h)}}};m.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};m.mapping_array="a b x y lb rb lt rt back start ls rs".split(" ");m.prototype.getGamepad=function(){var k=navigator.getGamepads||navigator.webkitGetGamepads||navigator.mozGetGamepads;if(!k)return null;k=k.call(navigator);this._previous_buttons.set(this._current_buttons);for(var t=this.properties.gamepad_index;4>t;t++)if(k[t]){k=k[t];t=this.xbox_mapping;t||(t=this.xbox_mapping={axes:[],
buttons:{},hat:"",hatmap:m.CENTER});t.axes.lx=k.axes[0];t.axes.ly=k.axes[1];t.axes.rx=k.axes[2];t.axes.ry=k.axes[3];t.axes.ltrigger=k.buttons[6].value;t.axes.rtrigger=k.buttons[7].value;t.hat="";t.hatmap=m.CENTER;for(var q=0;q<k.buttons.length;q++)if(this._current_buttons[q]=k.buttons[q].pressed,12>q)t.buttons[m.mapping_array[q]]=k.buttons[q].pressed,k.buttons[q].was_pressed&&this.trigger(m.mapping_array[q]+"_button_event");else switch(q){case 12:k.buttons[q].pressed&&(t.hat+="up",t.hatmap|=m.UP);
break;case 13:k.buttons[q].pressed&&(t.hat+="down",t.hatmap|=m.DOWN);break;case 14:k.buttons[q].pressed&&(t.hat+="left",t.hatmap|=m.LEFT);break;case 15:k.buttons[q].pressed&&(t.hat+="right",t.hatmap|=m.RIGHT);break;case 16:t.buttons.home=k.buttons[q].pressed}k.xbox=t;return k}};m.prototype.onDrawBackground=function(k){if(!this.flags.collapsed){var t=this._left_axis,m=this._right_axis;k.strokeStyle="#88A";k.strokeRect(.5*(t[0]+1)*this.size[0]-4,.5*(t[1]+1)*this.size[1]-4,8,8);k.strokeStyle="#8A8";
k.strokeRect(.5*(m[0]+1)*this.size[0]-4,.5*(m[1]+1)*this.size[1]-4,8,8);t=this.size[1]/this._current_buttons.length;k.fillStyle="#AEB";for(m=0;m<this._current_buttons.length;++m)this._current_buttons[m]&&k.fillRect(0,t*m,6,t)}};m.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",q.EVENT],["b_button_event",q.EVENT],["x_button_event",q.EVENT],["y_button_event",q.EVENT],["lb_button_event",q.EVENT],["rb_button_event",q.EVENT],["ls_button_event",q.EVENT],["rs_button_event",q.EVENT],["start_button_event",q.EVENT],["back_button_event",q.EVENT],["hat_left","number"],["hat_right",
"number"],["hat_up","number"],["hat_down","number"],["hat","number"],["button_pressed",q.EVENT]]};q.registerNodeType("input/gamepad",m)})(this);
(function(v){function m(){this.addInput("in","*");this.addOutput("out");this.size=[80,30]}function q(){this.addInput("in");this.addOutput("out");this.size=[80,30]}function k(){this.addInput("in");this.addOutput("out")}function t(){this.addInput("in","number",{locked:!0});this.addOutput("out","number",{locked:!0});this.addOutput("clamped","number",{locked:!0});this.addProperty("in",0);this.addProperty("in_min",0);this.addProperty("in_max",1);this.addProperty("out_min",0);this.addProperty("out_max",
1);this.size=[120,50]}function w(){this.addOutput("value","number");this.addProperty("min",0);this.addProperty("max",1);this.size=[80,30]}function h(){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 C(){this.addInput("in","number");this.addOutput("out","number");this.size=[80,30];this.addProperty("min",0);this.addProperty("max",1)}function B(){this.properties={f:.5};this.addInput("A","number");this.addInput("B","number");this.addOutput("out","number")}function x(){this.addInput("in","number");this.addOutput("out","number");this.size=[80,30]}function I(){this.addInput("in",
"number");this.addOutput("out","number");this.size=[80,30]}function l(){this.addInput("in","number");this.addOutput("out","number");this.size=[80,30]}function L(){this.addInput("in","number");this.addOutput("out","number");this.size=[80,30];this.properties={A:0,B:1}}function G(){this.addInput("in","number",{label:""});this.addOutput("out","number",{label:""});this.size=[80,30];this.addProperty("factor",1)}function A(){this.addInput("v","boolean");this.addInput("A");this.addInput("B");this.addOutput("out")}
function J(){this.addInput("in","number");this.addOutput("out","number");this.size=[80,30];this.addProperty("samples",10);this._values=new Float32Array(10);this._current=0}function D(){this.addInput("in","number");this.addOutput("out","number");this.addProperty("factor",.1);this.size=[80,30];this._value=null}function H(){this.addInput("A","number,array,object");this.addInput("B","number");this.addOutput("=","number");this.addProperty("A",1);this.addProperty("B",1);this.addProperty("OP","+","enum",
{values:H.values});this._func=function(a,b){return a+b};this._result=[]}function F(){this.addInput("A","number");this.addInput("B","number");this.addOutput("A==B","boolean");this.addOutput("A!=B","boolean");this.addProperty("A",0);this.addProperty("B",0)}function a(){this.addInput("A","number");this.addInput("B","number");this.addOutput("true","boolean");this.addOutput("false","boolean");this.addProperty("A",1);this.addProperty("B",1);this.addProperty("OP",">","enum",{values:a.values});this.addWidget("combo",
"Cond.",this.properties.OP,{property:"OP",values:a.values});this.size=[80,60]}function b(){this.addInput("in","");this.addInput("cond","boolean");this.addOutput("true","");this.addOutput("false","");this.size=[80,60]}function c(){this.addInput("inc","number");this.addOutput("total","number");this.addProperty("increment",1);this.addProperty("value",0)}function d(){this.addInput("v","number");this.addOutput("sin","number");this.addProperty("amplitude",1);this.addProperty("offset",0);this.bgImageUrl=
"nodes/imgs/icon-sin.png"}function e(){this.addInput("x","number");this.addInput("y","number");this.addOutput("","number");this.properties={x:1,y:1,formula:"x+y"};this.code_widget=this.addWidget("text","F(x,y)",this.properties.formula,function(a,b,c){c.properties.formula=a});this.addWidget("toggle","allow",p.allow_scripts,function(a){p.allow_scripts=a});this._func=null}function g(){this.addInput("vec2","vec2");this.addOutput("x","number");this.addOutput("y","number")}function f(){this.addInputs([["x",
"number"],["y","number"]]);this.addOutput("vec2","vec2");this.properties={x:0,y:0};this._data=new Float32Array(2)}function m(){this.addInput("vec3","vec3");this.addOutput("x","number");this.addOutput("y","number");this.addOutput("z","number")}function q(){this.addInputs([["x","number"],["y","number"],["z","number"]]);this.addOutput("vec3","vec3");this.properties={x:0,y:0,z:0};this._data=new Float32Array(3)}function D(){this.addInput("vec4","vec4");this.addOutput("x","number");this.addOutput("y","number");
this.addOutput("z","number");this.addOutput("w","number")}function s(){this.addInputs([["x","number"],["y","number"],["z","number"],["w","number"]]);this.addOutput("vec4","vec4");this.properties={x:0,y:0,z:0,w:0};this._data=new Float32Array(4)}var p=B.LiteGraph;n.title="Converter";n.desc="type A to type B";n.prototype.onExecute=function(){var a=this.getInputData(0);if(null!=a&&this.outputs)for(var b=0;b<this.outputs.length;b++){var c=this.outputs[b];if(c.links&&c.links.length){var d=null;switch(c.name){case "number":d=
a.length?a[0]:parseFloat(a);break;case "vec2":case "vec3":case "vec4":d=1;switch(c.name){case "vec2":d=2;break;case "vec3":d=3;break;case "vec4":d=4}d=new Float32Array(d);if(a.length)for(c=0;c<a.length&&c<d.length;c++)d[c]=a[c];else d[0]=parseFloat(a)}this.setOutputData(b,d)}}};n.prototype.onGetOutputs=function(){return[["number","number"],["vec2","vec2"],["vec3","vec3"],["vec4","vec4"]]};p.registerNodeType("math/converter",n);u.title="Bypass";u.desc="removes the type";u.prototype.onExecute=function(){var a=
this.getInputData(0);this.setOutputData(0,a)};p.registerNodeType("math/bypass",u);l.title="to Number";l.desc="Cast to number";l.prototype.onExecute=function(){var a=this.getInputData(0);this.setOutputData(0,Number(a))};p.registerNodeType("math/to_number",l);r.title="Range";r.desc="Convert a number from one range to another";r.prototype.getTitle=function(){return this.flags.collapsed?(this._last_v||0).toFixed(2):this.title};r.prototype.onExecute=function(){if(this.inputs)for(var a=0;a<this.inputs.length;a++){var b=
this.inputs[a],c=this.getInputData(a);void 0!==c&&(this.properties[b.name]=c)}c=this.properties["in"];if(void 0===c||null===c||c.constructor!==Number)c=0;var a=this.properties.in_min,b=this.properties.out_min,d=this.properties.out_max;this._last_v=(c-a)/(this.properties.in_max-a)*(d-b)+b;this.setOutputData(0,this._last_v);this.setOutputData(1,Math.clamp(this._last_v,b,d))};r.prototype.onDrawBackground=function(a){this.outputs[0].label=this._last_v?this._last_v.toFixed(3):"?"};r.prototype.onGetInputs=
function(){return[["in_min","number"],["in_max","number"],["out_min","number"],["out_max","number"]]};p.registerNodeType("math/range",r);v.title="Rand";v.desc="Random number";v.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;b=this.properties.max;this._last_v=Math.random()*(b-a)+a;this.setOutputData(0,this._last_v)};v.prototype.onDrawBackground=function(a){this.outputs[0].label=
(this._last_v||0).toFixed(3)};v.prototype.onGetInputs=function(){return[["min","number"],["max","number"]]};p.registerNodeType("math/rand",v);k.title="Noise";k.desc="Random number with temporal continuity";k.data=null;k.getValue=function(a,b){if(!k.data){k.data=new Float32Array(1024);for(var c=0;c<k.data.length;++c)k.data[c]=Math.random()}a%=1024;0>a&&(a+=1024);var d=Math.floor(a);a-=d;c=k.data[d];d=k.data[1023==d?0:d+1];b&&(a=a*a*a*(a*(6*a-15)+10));return c*(1-a)+d*a};k.prototype.onExecute=function(){for(var a=
this.getInputData(0)||0,b=this.properties.octaves||1,c=0,d=1,a=a+(this.properties.seed||0),e=this.properties.speed||1,f=0,g=0;g<b&&!(c+=k.getValue(a*(1+g)*e,this.properties.smooth)*d,f+=d,d*=this.properties.persistence,0.001>d);++g);a=this.properties.min;this._last_v=c/f*(this.properties.max-a)+a;this.setOutputData(0,this._last_v)};k.prototype.onDrawBackground=function(a){this.outputs[0].label=(this._last_v||0).toFixed(3)};p.registerNodeType("math/noise",k);E.title="Spikes";E.desc="spike every random time";
E.prototype.onExecute=function(){var a=this.graph.elapsed_time;this._remaining_time-=a;this._blink_time-=a;a=0;0<this._blink_time&&(a=1/(Math.pow(this._blink_time/this.properties.duration*8-4,4)+1));0>this._remaining_time?(this._remaining_time=Math.random()*(this.properties.max_time-this.properties.min_time)+this.properties.min_time,this._blink_time=this.properties.duration,this.boxcolor="#FFF"):this.boxcolor="#000";this.setOutputData(0,a)};p.registerNodeType("math/spikes",E);y.title="Clamp";y.desc=
"Clamp number between min and max";y.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))};y.prototype.getCode=function(a){a="";this.isInputConnected(0)&&(a+="clamp({{0}},"+this.properties.min+","+this.properties.max+")");return a};p.registerNodeType("math/clamp",y);A.title="Lerp";A.desc="Linear Interpolation";A.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=0);var b=
this.getInputData(1);null==b&&(b=0);var c=this.properties.f,d=this.getInputData(2);void 0!==d&&(c=d);this.setOutputData(0,a*(1-c)+b*c)};A.prototype.onGetInputs=function(){return[["f","number"]]};p.registerNodeType("math/lerp",A);x.title="Abs";x.desc="Absolute";x.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,Math.abs(a))};p.registerNodeType("math/abs",x);I.title="Floor";I.desc="Floor number to remove fractional part";I.prototype.onExecute=function(){var a=
this.getInputData(0);null!=a&&this.setOutputData(0,Math.floor(a))};p.registerNodeType("math/floor",I);h.title="Frac";h.desc="Returns fractional part";h.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,a%1)};p.registerNodeType("math/frac",h);L.title="Smoothstep";L.desc="Smoothstep";L.prototype.onExecute=function(){var a=this.getInputData(0);if(void 0!==a){var b=this.properties.A,a=Math.clamp((a-b)/(this.properties.B-b),0,1);this.setOutputData(0,a*a*(3-2*a))}};
p.registerNodeType("math/smoothstep",L);G.title="Scale";G.desc="v * factor";G.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,a*this.properties.factor)};p.registerNodeType("math/scale",G);z.title="Gate";z.desc="if v is true, then outputs A, otherwise B";z.prototype.onExecute=function(){var a=this.getInputData(0);this.setOutputData(0,this.getInputData(a?1:2))};p.registerNodeType("math/gate",z);K.title="Average";K.desc="Average Filter";K.prototype.onExecute=function(){var a=
this.getInputData(0);null==a&&(a=0);var b=this._values.length;this._values[this._current%b]=a;this._current+=1;this._current>b&&(this._current=0);for(var c=a=0;c<b;++c)a+=this._values[c];this.setOutputData(0,a/b)};K.prototype.onPropertyChanged=function(a,b){1>b&&(b=1);this.properties.samples=Math.round(b);var c=this._values;this._values=new Float32Array(this.properties.samples);c.length<=this._values.length?this._values.set(c):this._values.set(c.subarray(0,this._values.length))};p.registerNodeType("math/average",
K);C.title="TendTo";C.desc="moves the output value always closer to the input";C.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=0);var b=this.properties.factor;this._value=null==this._value?a:this._value*(1-b)+a*b;this.setOutputData(0,this._value)};p.registerNodeType("math/tendTo",C);H.values="+ - * / % ^ max min".split(" ");H.title="Operation";H.desc="Easy math operators";H["@OP"]={type:"enum",title:"operation",values:H.values};H.size=[100,60];H.prototype.getTitle=function(){return"max"==
"nodes/imgs/icon-sin.png"}function e(){this.addInput("x","number");this.addInput("y","number");this.addOutput("","number");this.properties={x:1,y:1,formula:"x+y"};this.code_widget=this.addWidget("text","F(x,y)",this.properties.formula,function(a,b,c){c.properties.formula=a});this.addWidget("toggle","allow",p.allow_scripts,function(a){p.allow_scripts=a});this._func=null}function f(){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 n(){this.addInput("vec3","vec3");this.addOutput("x","number");this.addOutput("y","number");this.addOutput("z","number")}function r(){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 K(){this.addInput("vec4","vec4");this.addOutput("x","number");this.addOutput("y","number");
this.addOutput("z","number");this.addOutput("w","number")}function u(){this.addInputs([["x","number"],["y","number"],["z","number"],["w","number"]]);this.addOutput("vec4","vec4");this.properties={x:0,y:0,z:0,w:0};this._data=new Float32Array(4)}var p=v.LiteGraph;m.title="Converter";m.desc="type A to type B";m.prototype.onExecute=function(){var a=this.getInputData(0);if(null!=a&&this.outputs)for(var b=0;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)}}};m.prototype.onGetOutputs=function(){return[["number","number"],["vec2","vec2"],["vec3","vec3"],["vec4","vec4"]]};p.registerNodeType("math/converter",m);q.title="Bypass";q.desc="removes the type";q.prototype.onExecute=function(){var a=
this.getInputData(0);this.setOutputData(0,a)};p.registerNodeType("math/bypass",q);k.title="to Number";k.desc="Cast to number";k.prototype.onExecute=function(){var a=this.getInputData(0);this.setOutputData(0,Number(a))};p.registerNodeType("math/to_number",k);t.title="Range";t.desc="Convert a number from one range to another";t.prototype.getTitle=function(){return this.flags.collapsed?(this._last_v||0).toFixed(2):this.title};t.prototype.onExecute=function(){if(this.inputs)for(var a=0;a<this.inputs.length;a++){var b=
this.inputs[a],c=this.getInputData(a);void 0!==c&&(this.properties[b.name]=c)}c=this.properties["in"];if(void 0===c||null===c||c.constructor!==Number)c=0;a=this.properties.in_min;b=this.properties.out_min;var d=this.properties.out_max;this._last_v=(c-a)/(this.properties.in_max-a)*(d-b)+b;this.setOutputData(0,this._last_v);this.setOutputData(1,Math.clamp(this._last_v,b,d))};t.prototype.onDrawBackground=function(a){this.outputs[0].label=this._last_v?this._last_v.toFixed(3):"?"};t.prototype.onGetInputs=
function(){return[["in_min","number"],["in_max","number"],["out_min","number"],["out_max","number"]]};p.registerNodeType("math/range",t);w.title="Rand";w.desc="Random number";w.prototype.onExecute=function(){if(this.inputs)for(var a=0;a<this.inputs.length;a++){var b=this.inputs[a],c=this.getInputData(a);void 0!==c&&(this.properties[b.name]=c)}a=this.properties.min;this._last_v=Math.random()*(this.properties.max-a)+a;this.setOutputData(0,this._last_v)};w.prototype.onDrawBackground=function(a){this.outputs[0].label=
(this._last_v||0).toFixed(3)};w.prototype.onGetInputs=function(){return[["min","number"],["max","number"]]};p.registerNodeType("math/rand",w);h.title="Noise";h.desc="Random number with temporal continuity";h.data=null;h.getValue=function(a,b){if(!h.data){h.data=new Float32Array(1024);for(var c=0;c<h.data.length;++c)h.data[c]=Math.random()}a%=1024;0>a&&(a+=1024);var d=Math.floor(a);a-=d;c=h.data[d];d=h.data[1023==d?0:d+1];b&&(a=a*a*a*(a*(6*a-15)+10));return c*(1-a)+d*a};h.prototype.onExecute=function(){var a=
this.getInputData(0)||0,b=this.properties.octaves||1,c=0,d=1;a+=this.properties.seed||0;for(var e=this.properties.speed||1,f=0,g=0;g<b&&!(c+=h.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)};h.prototype.onDrawBackground=function(a){this.outputs[0].label=(this._last_v||0).toFixed(3)};p.registerNodeType("math/noise",h);E.title="Spikes";E.desc="spike every random time";
E.prototype.onExecute=function(){var a=this.graph.elapsed_time;this._remaining_time-=a;this._blink_time-=a;a=0;0<this._blink_time&&(a=1/(Math.pow(this._blink_time/this.properties.duration*8-4,4)+1));0>this._remaining_time?(this._remaining_time=Math.random()*(this.properties.max_time-this.properties.min_time)+this.properties.min_time,this._blink_time=this.properties.duration,this.boxcolor="#FFF"):this.boxcolor="#000";this.setOutputData(0,a)};p.registerNodeType("math/spikes",E);C.title="Clamp";C.desc=
"Clamp number between min and max";C.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&(a=Math.max(this.properties.min,a),a=Math.min(this.properties.max,a),this.setOutputData(0,a))};C.prototype.getCode=function(a){a="";this.isInputConnected(0)&&(a+="clamp({{0}},"+this.properties.min+","+this.properties.max+")");return a};p.registerNodeType("math/clamp",C);B.title="Lerp";B.desc="Linear Interpolation";B.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=0);var b=
this.getInputData(1);null==b&&(b=0);var c=this.properties.f,d=this.getInputData(2);void 0!==d&&(c=d);this.setOutputData(0,a*(1-c)+b*c)};B.prototype.onGetInputs=function(){return[["f","number"]]};p.registerNodeType("math/lerp",B);x.title="Abs";x.desc="Absolute";x.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,Math.abs(a))};p.registerNodeType("math/abs",x);I.title="Floor";I.desc="Floor number to remove fractional part";I.prototype.onExecute=function(){var a=
this.getInputData(0);null!=a&&this.setOutputData(0,Math.floor(a))};p.registerNodeType("math/floor",I);l.title="Frac";l.desc="Returns fractional part";l.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,a%1)};p.registerNodeType("math/frac",l);L.title="Smoothstep";L.desc="Smoothstep";L.prototype.onExecute=function(){var a=this.getInputData(0);if(void 0!==a){var b=this.properties.A;a=Math.clamp((a-b)/(this.properties.B-b),0,1);this.setOutputData(0,a*a*(3-2*a))}};
p.registerNodeType("math/smoothstep",L);G.title="Scale";G.desc="v * factor";G.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,a*this.properties.factor)};p.registerNodeType("math/scale",G);A.title="Gate";A.desc="if v is true, then outputs A, otherwise B";A.prototype.onExecute=function(){var a=this.getInputData(0);this.setOutputData(0,this.getInputData(a?1:2))};p.registerNodeType("math/gate",A);J.title="Average";J.desc="Average Filter";J.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)};J.prototype.onPropertyChanged=function(a,b){1>b&&(b=1);this.properties.samples=Math.round(b);a=this._values;this._values=new Float32Array(this.properties.samples);a.length<=this._values.length?this._values.set(a):this._values.set(a.subarray(0,this._values.length))};p.registerNodeType("math/average",
J);D.title="TendTo";D.desc="moves the output value always closer to the input";D.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=0);var b=this.properties.factor;this._value=null==this._value?a:this._value*(1-b)+a*b;this.setOutputData(0,this._value)};p.registerNodeType("math/tendTo",D);H.values="+ - * / % ^ max min".split(" ");H.title="Operation";H.desc="Easy math operators";H["@OP"]={type:"enum",title:"operation",values:H.values};H.size=[100,60];H.prototype.getTitle=function(){return"max"==
this.properties.OP||"min"==this.properties.OP?this.properties.OP+"(A,B)":"A "+this.properties.OP+" B"};H.prototype.setValue=function(a){"string"==typeof a&&(a=parseFloat(a));this.properties.value=a};H.prototype.onPropertyChanged=function(a,b){if("OP"==a)switch(this.properties.OP){case "+":this._func=function(a,b){return a+b};break;case "-":this._func=function(a,b){return a-b};break;case "x":case "X":case "*":this._func=function(a,b){return a*b};break;case "/":this._func=function(a,b){return a/b};
break;case "%":this._func=function(a,b){return a%b};break;case "^":this._func=function(a,b){return Math.pow(a,b)};break;case "max":this._func=function(a,b){return Math.max(a,b)};break;case "min":this._func=function(a,b){return Math.min(a,b)};break;default:console.warn("Unknown operation: "+this.properties.OP),this._func=function(a){return a}}};H.prototype.onExecute=function(){var a=this.getInputData(0),b=this.getInputData(1);null!=a?a.constructor===Number&&(this.properties.A=a):a=this.properties.A;
null!=b?this.properties.B=b:b=this.properties.B;var c;if(a.constructor===Number)c=this._func(a,b);else if(a.constructor===Array){c=this._result;c.length=a.length;for(var d=0;d<a.length;++d)c[d]=this._func(a[d],b)}else for(d in c={},a)c[d]=this._func(a[d],b);this.setOutputData(0,c)};H.prototype.onDrawBackground=function(a){this.flags.collapsed||(a.font="40px Arial",a.fillStyle="#666",a.textAlign="center",a.fillText(this.properties.OP,0.5*this.size[0],0.5*(this.size[1]+p.NODE_TITLE_HEIGHT)),a.textAlign=
null!=b?this.properties.B=b:b=this.properties.B;if(a.constructor===Number)var c=this._func(a,b);else if(a.constructor===Array){c=this._result;c.length=a.length;for(var d=0;d<a.length;++d)c[d]=this._func(a[d],b)}else for(d in c={},a)c[d]=this._func(a[d],b);this.setOutputData(0,c)};H.prototype.onDrawBackground=function(a){this.flags.collapsed||(a.font="40px Arial",a.fillStyle="#666",a.textAlign="center",a.fillText(this.properties.OP,.5*this.size[0],.5*(this.size[1]+p.NODE_TITLE_HEIGHT)),a.textAlign=
"left")};p.registerNodeType("math/operation",H);p.registerSearchboxExtra("math/operation","MAX",{properties:{OP:"max"},title:"MAX()"});p.registerSearchboxExtra("math/operation","MIN",{properties:{OP:"min"},title:"MIN()"});F.title="Compare";F.desc="compares between two values";F.prototype.onExecute=function(){var a=this.getInputData(0),b=this.getInputData(1);void 0!==a?this.properties.A=a:a=this.properties.A;void 0!==b?this.properties.B=b:b=this.properties.B;for(var c=0,d=this.outputs.length;c<d;++c){var e=
this.outputs[c];if(e.links&&e.links.length){var f;switch(e.name){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;break;case "A>=B":f=a>=b}this.setOutputData(c,f)}}};F.prototype.onGetOutputs=function(){return[["A==B","boolean"],["A!=B","boolean"],["A>B","boolean"],["A<B","boolean"],["A>=B","boolean"],["A<=B","boolean"]]};p.registerNodeType("math/compare",F);p.registerSearchboxExtra("math/compare","==",{outputs:[["A==B","boolean"]],
title:"A==B"});p.registerSearchboxExtra("math/compare","!=",{outputs:[["A!=B","boolean"]],title:"A!=B"});p.registerSearchboxExtra("math/compare",">",{outputs:[["A>B","boolean"]],title:"A>B"});p.registerSearchboxExtra("math/compare","<",{outputs:[["A<B","boolean"]],title:"A<B"});p.registerSearchboxExtra("math/compare",">=",{outputs:[["A>=B","boolean"]],title:"A>=B"});p.registerSearchboxExtra("math/compare","<=",{outputs:[["A<=B","boolean"]],title:"A<=B"});a.values="> < == != <= >= || &&".split(" ");
a["@OP"]={type:"enum",title:"operation",values:a.values};a.title="Condition";a.desc="evaluates condition between A and B";a.prototype.getTitle=function(){return"A "+this.properties.OP+" B"};a.prototype.onExecute=function(){var a=this.getInputData(0);void 0===a?a=this.properties.A:this.properties.A=a;var b=this.getInputData(1);void 0===b?b=this.properties.B:this.properties.B=b;var c=!0;switch(this.properties.OP){case ">":c=a>b;break;case "<":c=a<b;break;case "==":c=a==b;break;case "!=":c=a!=b;break;
case "<=":c=a<=b;break;case ">=":c=a>=b;break;case "||":c=a||b;break;case "&&":c=a&&b}this.setOutputData(0,c);this.setOutputData(1,!c)};p.registerNodeType("math/condition",a);b.title="Branch";b.desc="If condition is true, outputs IN in true, otherwise in false";b.prototype.onExecute=function(){var a=this.getInputData(0);this.getInputData(1)?(this.setOutputData(0,a),this.setOutputData(1,null)):(this.setOutputData(0,null),this.setOutputData(1,a))};p.registerNodeType("math/branch",b);c.title="Accumulate";
c.desc="Increments a value every time";c.prototype.onExecute=function(){null===this.properties.value&&(this.properties.value=0);var a=this.getInputData(0);this.properties.value=null!==a?this.properties.value+a:this.properties.value+this.properties.increment;this.setOutputData(0,this.properties.value)};p.registerNodeType("math/accumulate",c);d.title="Trigonometry";d.desc="Sin Cos Tan";d.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=0);var b=this.properties.amplitude,c=this.findInputSlot("amplitude");
-1!=c&&(b=this.getInputData(c));var d=this.properties.offset,c=this.findInputSlot("offset");-1!=c&&(d=this.getInputData(c));for(var c=0,e=this.outputs.length;c<e;++c){var f;switch(this.outputs[c].name){case "sin":f=Math.sin(a);break;case "cos":f=Math.cos(a);break;case "tan":f=Math.tan(a);break;case "asin":f=Math.asin(a);break;case "acos":f=Math.acos(a);break;case "atan":f=Math.atan(a)}this.setOutputData(c,b*f+d)}};d.prototype.onGetInputs=function(){return[["v","number"],["amplitude","number"],["offset",
"number"]]};d.prototype.onGetOutputs=function(){return[["sin","number"],["cos","number"],["tan","number"],["asin","number"],["acos","number"],["atan","number"]]};p.registerNodeType("math/trigonometry",d);p.registerSearchboxExtra("math/trigonometry","SIN()",{outputs:[["sin","number"]],title:"SIN()"});p.registerSearchboxExtra("math/trigonometry","COS()",{outputs:[["cos","number"]],title:"COS()"});p.registerSearchboxExtra("math/trigonometry","TAN()",{outputs:[["tan","number"]],title:"TAN()"});e.title=
"Formula";e.desc="Compute formula";e.size=[160,100];K.prototype.onPropertyChanged=function(a,b){"formula"==a&&(this.code_widget.value=b)};e.prototype.onExecute=function(){if(p.allow_scripts){var a=this.getInputData(0),b=this.getInputData(1);null!=a?this.properties.x=a:a=this.properties.x;null!=b?this.properties.y=b:b=this.properties.y;var c;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),
c=this._func(a,b,this.graph.globaltime),this.boxcolor=null}catch(d){this.boxcolor="red"}this.setOutputData(0,c)}};e.prototype.getTitle=function(){return this._func_code||"Formula"};e.prototype.onDrawBackground=function(){var a=this.properties.formula;this.outputs&&this.outputs.length&&(this.outputs[0].label=a)};p.registerNodeType("math/formula",e);g.title="Vec2->XY";g.desc="vector 2 to components";g.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&(this.setOutputData(0,a[0]),this.setOutputData(1,
a[1]))};p.registerNodeType("math3d/vec2-to-xy",g);f.title="XY->Vec2";f.desc="components to vector2";f.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=this.properties.x);var b=this.getInputData(1);null==b&&(b=this.properties.y);var c=this._data;c[0]=a;c[1]=b;this.setOutputData(0,c)};p.registerNodeType("math3d/xy-to-vec2",f);m.title="Vec3->XYZ";m.desc="vector 3 to components";m.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&(this.setOutputData(0,a[0]),this.setOutputData(1,
a[1]),this.setOutputData(2,a[2]))};p.registerNodeType("math3d/vec3-to-xyz",m);q.title="XYZ->Vec3";q.desc="components to vector3";q.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=this.properties.x);var b=this.getInputData(1);null==b&&(b=this.properties.y);var c=this.getInputData(2);null==c&&(c=this.properties.z);var d=this._data;d[0]=a;d[1]=b;d[2]=c;this.setOutputData(0,d)};p.registerNodeType("math3d/xyz-to-vec3",q);D.title="Vec4->XYZW";D.desc="vector 4 to components";D.prototype.onExecute=
function(){var a=this.getInputData(0);null!=a&&(this.setOutputData(0,a[0]),this.setOutputData(1,a[1]),this.setOutputData(2,a[2]),this.setOutputData(3,a[3]))};p.registerNodeType("math3d/vec4-to-xyzw",D);s.title="XYZW->Vec4";s.desc="components to vector4";s.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=this.properties.x);var b=this.getInputData(1);null==b&&(b=this.properties.y);var c=this.getInputData(2);null==c&&(c=this.properties.z);var d=this.getInputData(3);null==d&&(d=this.properties.w);
var e=this._data;e[0]=a;e[1]=b;e[2]=c;e[3]=d;this.setOutputData(0,e)};p.registerNodeType("math3d/xyzw-to-vec4",s)})(this);
(function(B){function n(){this.addInput("","string");this.addOutput("table","table");this.addOutput("rows","number");this.addProperty("value","");this.addProperty("separator",",");this._table=null}B=B.LiteGraph;B.wrapFunctionAsNode("string/toString",function(n){if(n&&n.constructor===Object)try{return JSON.stringify(n)}catch(l){}return String(n)},[""],"String");B.wrapFunctionAsNode("string/compare",function(n,l){return n==l},["string","string"],"boolean");B.wrapFunctionAsNode("string/concatenate",
function(n,l){return void 0===n?l:void 0===l?n:n+l},["string","string"],"string");B.wrapFunctionAsNode("string/contains",function(n,l){return void 0===n||void 0===l?!1:-1!=n.indexOf(l)},["string","string"],"boolean");B.wrapFunctionAsNode("string/toUpperCase",function(n){return null!=n&&n.constructor===String?n.toUpperCase():n},["string"],"string");B.wrapFunctionAsNode("string/split",function(n,l){null==l&&(l=this.properties.separator);if(null==n)return[];if(n.constructor===String)return n.split(l||
" ");if(n.constructor===Array){for(var r=[],v=0;v<n.length;++v)r[v]=n[v].split(l||" ");return r}return null},["string,array","string"],"array",{separator:","});B.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 l=this.properties.separator||",";if(n!=this._str||l!=this._last_separator)this._last_separator=
l,this._str=n,this._table=n.split("\n").map(function(r){return r.trim().split(l)});this.setOutputData(0,this._table);this.setOutputData(1,this._table?this._table.length:0)}};B.registerNodeType("string/toTable",n)})(this);
(function(B){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 u(){this.properties={sequence:"A,B,C"};this.addInput("index","number");this.addInput("seq");this.addOutput("out");this.index=0;this.values=this.properties.sequence.split(",")}var l=B.LiteGraph;n.title="Selector";n.desc="selects an output";n.prototype.onDrawBackground=function(r){if(!this.flags.collapsed){r.fillStyle="#AFB";
var n=(this.selected+1)*l.NODE_SLOT_HEIGHT+6;r.beginPath();r.moveTo(50,n);r.lineTo(50,n+l.NODE_SLOT_HEIGHT);r.lineTo(34,n+0.5*l.NODE_SLOT_HEIGHT);r.fill()}};n.prototype.onExecute=function(){var l=this.getInputData(0);if(null==l||l.constructor!==Number)l=0;this.selected=l=Math.round(l)%(this.inputs.length-1);l=this.getInputData(l+1);void 0!==l&&this.setOutputData(0,l)};n.prototype.onGetInputs=function(){return[["E",0],["F",0],["G",0],["H",0]]};l.registerNodeType("logic/selector",n);u.title="Sequence";
u.desc="select one element from a sequence from a string";u.prototype.onPropertyChanged=function(l,n){"sequence"==l&&(this.values=n.split(","))};u.prototype.onExecute=function(){var l=this.getInputData(1);l&&l!=this.current_sequence&&(this.values=l.split(","),this.current_sequence=l);l=this.getInputData(0);null==l&&(l=0);this.index=l=Math.round(l)%this.values.length;this.setOutputData(0,this.values[l])};l.registerNodeType("logic/sequence",u)})(this);
(function(B){function n(){this.size=[60,20];this.addInput("send",l.ACTION);this.addOutput("received",l.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 u(){this.room_widget=this.addWidget("text","Room","lgraph",this.setRoom.bind(this));this.addWidget("button","Reconnect",null,this.connectSocket.bind(this));this.addInput("send",l.ACTION);this.addOutput("received",
l.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 l=B.LiteGraph;n.title="WebSocket";n.desc="Send data through a websocket";n.prototype.onPropertyChanged=function(l,n){"url"==
l&&this.connectSocket()};n.prototype.onExecute=function(){!this._ws&&this.properties.url&&this.connectSocket();if(this._ws&&this._ws.readyState==WebSocket.OPEN){for(var l=this.properties.room,n=this.properties.only_send_changes,k=1;k<this.inputs.length;++k){var u=this.getInputData(k);if(null!=u){var y;try{y=JSON.stringify({type:0,room:l,channel:k,data:u})}catch(A){continue}n&&this._last_sent_data[k]==y||(this._last_sent_data[k]=y,this._ws.send(y))}}for(k=1;k<this.outputs.length;++k)this.setOutputData(k,
this._last_received_data[k]);"#AFA"==this.boxcolor&&(this.boxcolor="#6C6")}};n.prototype.connectSocket=function(){var r=this,n=this.properties.url;"ws"!=n.substr(0,2)&&(n="ws://"+n);this._ws=new WebSocket(n);this._ws.onopen=function(){console.log("ready");r.boxcolor="#6C6"};this._ws.onmessage=function(k){r.boxcolor="#AFA";k=JSON.parse(k.data);if(!k.room||k.room==r.properties.room)if(1==k.type)if(k.data.object_class&&l[k.data.object_class]){var n=null;try{n=new l[k.data.object_class](k.data),r.triggerSlot(0,
n)}catch(v){}}else r.triggerSlot(0,k.data);else r._last_received_data[k.channel||0]=k.data};this._ws.onerror=function(k){console.log("couldnt connect to websocket");r.boxcolor="#E88"};this._ws.onclose=function(k){console.log("connection closed");r.boxcolor="#000"}};n.prototype.send=function(l){this._ws&&this._ws.readyState==WebSocket.OPEN&&this._ws.send(JSON.stringify({type:1,msg:l}))};n.prototype.onAction=function(l,n){this._ws&&this._ws.readyState==WebSocket.OPEN&&this._ws.send({type:1,room:this.properties.room,
action:l,data:n})};n.prototype.onGetInputs=function(){return[["in",0]]};n.prototype.onGetOutputs=function(){return[["out",0]]};l.registerNodeType("network/websocket",n);u.title="SillyClient";u.desc="Connects to SillyServer to broadcast messages";u.prototype.onPropertyChanged=function(l,n){"room"==l&&(this.room_widget.value=n);this.connectSocket()};u.prototype.setRoom=function(l){this.properties.room=l;this.room_widget.value=l;this.connectSocket()};u.prototype.onDrawForeground=function(){for(var l=
1;l<this.inputs.length;++l){var n=this.inputs[l];n.label="in_"+l}for(l=1;l<this.outputs.length;++l)n=this.outputs[l],n.label="out_"+l};u.prototype.onExecute=function(){if(this._server&&this._server.is_connected){for(var l=this.properties.only_send_changes,n=1;n<this.inputs.length;++n){var k=this.getInputData(n),u=this._last_sent_data[n];if(null!=k){if(l){var y=!0;if(k&&k.length&&u&&u.length==k.length&&k.constructor!==String)for(var A=0;A<k.length;++A){if(u[A]!=k[A]){y=!1;break}}else this._last_sent_data[n]!=
k&&(y=!1);if(y)continue}this._server.sendMessage({type:0,channel:n,data:k});if(k.length&&k.constructor!==String)if(this._last_sent_data[n])for(this._last_sent_data[n].length=k.length,A=0;A<k.length;++A)this._last_sent_data[n][A]=k[A];else this._last_sent_data[n]=k.constructor===Array?k.concat():new k.constructor(k);else this._last_sent_data[n]=k}}for(n=1;n<this.outputs.length;++n)this.setOutputData(n,this._last_received_data[n]);"#AFA"==this.boxcolor&&(this.boxcolor="#6C6")}};u.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(k,v){var u=null;try{u=JSON.parse(v)}catch(A){return}if(1==u.type)if(u.data.object_class&&l[u.data.object_class]){var x=null;try{x=new l[u.data.object_class](u.data),n.triggerSlot(0,x)}catch(B){return}}else n.triggerSlot(0,
u.data);else n._last_received_data[u.channel||0]=u.data;n.boxcolor="#AFA"},this._server.on_error=function(k){console.log("couldnt connect to websocket");n.boxcolor="#E88"},this._server.on_close=function(k){console.log("connection closed");n.boxcolor="#000"},this.properties.url&&this.properties.room){try{this._server.connect(this.properties.url,this.properties.room)}catch(v){console.error("SillyServer error: "+v);this._server=null;return}this._final_url=this.properties.url+"/"+this.properties.room}};
u.prototype.send=function(l){this._server&&this._server.is_connected&&this._server.sendMessage({type:1,data:l})};u.prototype.onAction=function(l,n){this._server&&this._server.is_connected&&this._server.sendMessage({type:1,action:l,data:n})};u.prototype.onGetInputs=function(){return[["in",0]]};u.prototype.onGetOutputs=function(){return[["out",0]]};l.registerNodeType("network/sillyclient",u)})(this);
this.outputs[c];if(e.links&&e.links.length){switch(e.name){case "A==B":var f=a==b;break;case "A!=B":f=a!=b;break;case "A>B":f=a>b;break;case "A<B":f=a<b;break;case "A<=B":f=a<=b;break;case "A>=B":f=a>=b}this.setOutputData(c,f)}}};F.prototype.onGetOutputs=function(){return[["A==B","boolean"],["A!=B","boolean"],["A>B","boolean"],["A<B","boolean"],["A>=B","boolean"],["A<=B","boolean"]]};p.registerNodeType("math/compare",F);p.registerSearchboxExtra("math/compare","==",{outputs:[["A==B","boolean"]],title:"A==B"});
p.registerSearchboxExtra("math/compare","!=",{outputs:[["A!=B","boolean"]],title:"A!=B"});p.registerSearchboxExtra("math/compare",">",{outputs:[["A>B","boolean"]],title:"A>B"});p.registerSearchboxExtra("math/compare","<",{outputs:[["A<B","boolean"]],title:"A<B"});p.registerSearchboxExtra("math/compare",">=",{outputs:[["A>=B","boolean"]],title:"A>=B"});p.registerSearchboxExtra("math/compare","<=",{outputs:[["A<=B","boolean"]],title:"A<=B"});a.values="> < == != <= >= || &&".split(" ");a["@OP"]={type:"enum",
title:"operation",values:a.values};a.title="Condition";a.desc="evaluates condition between A and B";a.prototype.getTitle=function(){return"A "+this.properties.OP+" B"};a.prototype.onExecute=function(){var a=this.getInputData(0);void 0===a?a=this.properties.A:this.properties.A=a;var b=this.getInputData(1);void 0===b?b=this.properties.B:this.properties.B=b;var c=!0;switch(this.properties.OP){case ">":c=a>b;break;case "<":c=a<b;break;case "==":c=a==b;break;case "!=":c=a!=b;break;case "<=":c=a<=b;break;
case ">=":c=a>=b;break;case "||":c=a||b;break;case "&&":c=a&&b}this.setOutputData(0,c);this.setOutputData(1,!c)};p.registerNodeType("math/condition",a);b.title="Branch";b.desc="If condition is true, outputs IN in true, otherwise in false";b.prototype.onExecute=function(){var a=this.getInputData(0);this.getInputData(1)?(this.setOutputData(0,a),this.setOutputData(1,null)):(this.setOutputData(0,null),this.setOutputData(1,a))};p.registerNodeType("math/branch",b);c.title="Accumulate";c.desc="Increments a value every time";
c.prototype.onExecute=function(){null===this.properties.value&&(this.properties.value=0);var a=this.getInputData(0);this.properties.value=null!==a?this.properties.value+a:this.properties.value+this.properties.increment;this.setOutputData(0,this.properties.value)};p.registerNodeType("math/accumulate",c);d.title="Trigonometry";d.desc="Sin Cos Tan";d.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=0);var b=this.properties.amplitude,c=this.findInputSlot("amplitude");-1!=c&&(b=this.getInputData(c));
var d=this.properties.offset;c=this.findInputSlot("offset");-1!=c&&(d=this.getInputData(c));c=0;for(var e=this.outputs.length;c<e;++c){switch(this.outputs[c].name){case "sin":var f=Math.sin(a);break;case "cos":f=Math.cos(a);break;case "tan":f=Math.tan(a);break;case "asin":f=Math.asin(a);break;case "acos":f=Math.acos(a);break;case "atan":f=Math.atan(a)}this.setOutputData(c,b*f+d)}};d.prototype.onGetInputs=function(){return[["v","number"],["amplitude","number"],["offset","number"]]};d.prototype.onGetOutputs=
function(){return[["sin","number"],["cos","number"],["tan","number"],["asin","number"],["acos","number"],["atan","number"]]};p.registerNodeType("math/trigonometry",d);p.registerSearchboxExtra("math/trigonometry","SIN()",{outputs:[["sin","number"]],title:"SIN()"});p.registerSearchboxExtra("math/trigonometry","COS()",{outputs:[["cos","number"]],title:"COS()"});p.registerSearchboxExtra("math/trigonometry","TAN()",{outputs:[["tan","number"]],title:"TAN()"});e.title="Formula";e.desc="Compute formula";
e.size=[160,100];J.prototype.onPropertyChanged=function(a,b){"formula"==a&&(this.code_widget.value=b)};e.prototype.onExecute=function(){if(p.allow_scripts){var a=this.getInputData(0),b=this.getInputData(1);null!=a?this.properties.x=a:a=this.properties.x;null!=b?this.properties.y=b:b=this.properties.y;try{this._func&&this._func_code==this.properties.formula||(this._func=new Function("x","y","TIME","return "+this.properties.formula),this._func_code=this.properties.formula);var c=this._func(a,b,this.graph.globaltime);
this.boxcolor=null}catch(M){this.boxcolor="red"}this.setOutputData(0,c)}};e.prototype.getTitle=function(){return this._func_code||"Formula"};e.prototype.onDrawBackground=function(){var a=this.properties.formula;this.outputs&&this.outputs.length&&(this.outputs[0].label=a)};p.registerNodeType("math/formula",e);f.title="Vec2->XY";f.desc="vector 2 to components";f.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&(this.setOutputData(0,a[0]),this.setOutputData(1,a[1]))};p.registerNodeType("math3d/vec2-to-xy",
f);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)};p.registerNodeType("math3d/xy-to-vec2",g);n.title="Vec3->XYZ";n.desc="vector 3 to components";n.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&(this.setOutputData(0,a[0]),this.setOutputData(1,a[1]),this.setOutputData(2,a[2]))};
p.registerNodeType("math3d/vec3-to-xyz",n);r.title="XYZ->Vec3";r.desc="components to vector3";r.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=this.properties.x);var b=this.getInputData(1);null==b&&(b=this.properties.y);var c=this.getInputData(2);null==c&&(c=this.properties.z);var d=this._data;d[0]=a;d[1]=b;d[2]=c;this.setOutputData(0,d)};p.registerNodeType("math3d/xyz-to-vec3",r);K.title="Vec4->XYZW";K.desc="vector 4 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]),this.setOutputData(3,a[3]))};p.registerNodeType("math3d/vec4-to-xyzw",K);u.title="XYZW->Vec4";u.desc="components to vector4";u.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=this.properties.x);var b=this.getInputData(1);null==b&&(b=this.properties.y);var c=this.getInputData(2);null==c&&(c=this.properties.z);var d=this.getInputData(3);null==d&&(d=this.properties.w);var e=this._data;e[0]=
a;e[1]=b;e[2]=c;e[3]=d;this.setOutputData(0,e)};p.registerNodeType("math3d/xyzw-to-vec4",u)})(this);
(function(v){function m(){this.addInput("","string");this.addOutput("table","table");this.addOutput("rows","number");this.addProperty("value","");this.addProperty("separator",",");this._table=null}v=v.LiteGraph;v.wrapFunctionAsNode("string/toString",function(m){if(m&&m.constructor===Object)try{return JSON.stringify(m)}catch(k){}return String(m)},[""],"String");v.wrapFunctionAsNode("string/compare",function(m,k){return m==k},["string","string"],"boolean");v.wrapFunctionAsNode("string/concatenate",
function(m,k){return void 0===m?k:void 0===k?m:m+k},["string","string"],"string");v.wrapFunctionAsNode("string/contains",function(m,k){return void 0===m||void 0===k?!1:-1!=m.indexOf(k)},["string","string"],"boolean");v.wrapFunctionAsNode("string/toUpperCase",function(m){return null!=m&&m.constructor===String?m.toUpperCase():m},["string"],"string");v.wrapFunctionAsNode("string/split",function(m,k){null==k&&(k=this.properties.separator);if(null==m)return[];if(m.constructor===String)return m.split(k||
" ");if(m.constructor===Array){for(var t=[],q=0;q<m.length;++q)t[q]=m[q].split(k||" ");return t}return null},["string,array","string"],"array",{separator:","});v.wrapFunctionAsNode("string/toFixed",function(m){return null!=m&&m.constructor===Number?m.toFixed(this.properties.precision):m},["number"],"string",{precision:0});m.title="toTable";m.desc="Splits a string to table";m.prototype.onExecute=function(){var m=this.getInputData(0);if(m){var k=this.properties.separator||",";if(m!=this._str||k!=this._last_separator)this._last_separator=
k,this._str=m,this._table=m.split("\n").map(function(m){return m.trim().split(k)});this.setOutputData(0,this._table);this.setOutputData(1,this._table?this._table.length:0)}};v.registerNodeType("string/toTable",m)})(this);
(function(v){function m(){this.addInput("sel","number");this.addInput("A");this.addInput("B");this.addInput("C");this.addInput("D");this.addOutput("out");this.selected=0}function q(){this.properties={sequence:"A,B,C"};this.addInput("index","number");this.addInput("seq");this.addOutput("out");this.index=0;this.values=this.properties.sequence.split(",")}var k=v.LiteGraph;m.title="Selector";m.desc="selects an output";m.prototype.onDrawBackground=function(m){if(!this.flags.collapsed){m.fillStyle="#AFB";
var t=(this.selected+1)*k.NODE_SLOT_HEIGHT+6;m.beginPath();m.moveTo(50,t);m.lineTo(50,t+k.NODE_SLOT_HEIGHT);m.lineTo(34,t+.5*k.NODE_SLOT_HEIGHT);m.fill()}};m.prototype.onExecute=function(){var k=this.getInputData(0);if(null==k||k.constructor!==Number)k=0;this.selected=k=Math.round(k)%(this.inputs.length-1);k=this.getInputData(k+1);void 0!==k&&this.setOutputData(0,k)};m.prototype.onGetInputs=function(){return[["E",0],["F",0],["G",0],["H",0]]};k.registerNodeType("logic/selector",m);q.title="Sequence";
q.desc="select one element from a sequence from a string";q.prototype.onPropertyChanged=function(k,m){"sequence"==k&&(this.values=m.split(","))};q.prototype.onExecute=function(){var k=this.getInputData(1);k&&k!=this.current_sequence&&(this.values=k.split(","),this.current_sequence=k);k=this.getInputData(0);null==k&&(k=0);this.index=k=Math.round(k)%this.values.length;this.setOutputData(0,this.values[k])};k.registerNodeType("logic/sequence",q)})(this);
(function(v){function m(){this.size=[60,20];this.addInput("send",k.ACTION);this.addOutput("received",k.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 q(){this.room_widget=this.addWidget("text","Room","lgraph",this.setRoom.bind(this));this.addWidget("button","Reconnect",null,this.connectSocket.bind(this));this.addInput("send",k.ACTION);this.addOutput("received",
k.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 k=v.LiteGraph;m.title="WebSocket";m.desc="Send data through a websocket";m.prototype.onPropertyChanged=function(k,m){"url"==
k&&this.connectSocket()};m.prototype.onExecute=function(){!this._ws&&this.properties.url&&this.connectSocket();if(this._ws&&this._ws.readyState==WebSocket.OPEN){for(var k=this.properties.room,m=this.properties.only_send_changes,h=1;h<this.inputs.length;++h){var q=this.getInputData(h);if(null!=q){try{var v=JSON.stringify({type:0,room:k,channel:h,data:q})}catch(B){continue}m&&this._last_sent_data[h]==v||(this._last_sent_data[h]=v,this._ws.send(v))}}for(h=1;h<this.outputs.length;++h)this.setOutputData(h,
this._last_received_data[h]);"#AFA"==this.boxcolor&&(this.boxcolor="#6C6")}};m.prototype.connectSocket=function(){var m=this,q=this.properties.url;"ws"!=q.substr(0,2)&&(q="ws://"+q);this._ws=new WebSocket(q);this._ws.onopen=function(){console.log("ready");m.boxcolor="#6C6"};this._ws.onmessage=function(h){m.boxcolor="#AFA";h=JSON.parse(h.data);if(!h.room||h.room==m.properties.room)if(1==h.type)if(h.data.object_class&&k[h.data.object_class]){var t=null;try{t=new k[h.data.object_class](h.data),m.triggerSlot(0,
t)}catch(C){}}else m.triggerSlot(0,h.data);else m._last_received_data[h.channel||0]=h.data};this._ws.onerror=function(h){console.log("couldnt connect to websocket");m.boxcolor="#E88"};this._ws.onclose=function(h){console.log("connection closed");m.boxcolor="#000"}};m.prototype.send=function(k){this._ws&&this._ws.readyState==WebSocket.OPEN&&this._ws.send(JSON.stringify({type:1,msg:k}))};m.prototype.onAction=function(k,m){this._ws&&this._ws.readyState==WebSocket.OPEN&&this._ws.send({type:1,room:this.properties.room,
action:k,data:m})};m.prototype.onGetInputs=function(){return[["in",0]]};m.prototype.onGetOutputs=function(){return[["out",0]]};k.registerNodeType("network/websocket",m);q.title="SillyClient";q.desc="Connects to SillyServer to broadcast messages";q.prototype.onPropertyChanged=function(k,m){"room"==k&&(this.room_widget.value=m);this.connectSocket()};q.prototype.setRoom=function(k){this.properties.room=k;this.room_widget.value=k;this.connectSocket()};q.prototype.onDrawForeground=function(){for(var k=
1;k<this.inputs.length;++k){var m=this.inputs[k];m.label="in_"+k}for(k=1;k<this.outputs.length;++k)m=this.outputs[k],m.label="out_"+k};q.prototype.onExecute=function(){if(this._server&&this._server.is_connected){for(var k=this.properties.only_send_changes,m=1;m<this.inputs.length;++m){var h=this.getInputData(m),q=this._last_sent_data[m];if(null!=h){if(k){var v=!0;if(h&&h.length&&q&&q.length==h.length&&h.constructor!==String)for(var B=0;B<h.length;++B){if(q[B]!=h[B]){v=!1;break}}else this._last_sent_data[m]!=
h&&(v=!1);if(v)continue}this._server.sendMessage({type:0,channel:m,data:h});if(h.length&&h.constructor!==String)if(this._last_sent_data[m])for(this._last_sent_data[m].length=h.length,B=0;B<h.length;++B)this._last_sent_data[m][B]=h[B];else this._last_sent_data[m]=h.constructor===Array?h.concat():new h.constructor(h);else this._last_sent_data[m]=h}}for(m=1;m<this.outputs.length;++m)this.setOutputData(m,this._last_received_data[m]);"#AFA"==this.boxcolor&&(this.boxcolor="#6C6")}};q.prototype.connectSocket=
function(){var m=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");m.boxcolor="#6C6"},this._server.on_message=function(q,h){q=null;try{q=JSON.parse(h)}catch(E){return}if(1==q.type)if(q.data.object_class&&k[q.data.object_class]){h=null;try{h=new k[q.data.object_class](q.data),m.triggerSlot(0,h)}catch(E){return}}else m.triggerSlot(0,
q.data);else m._last_received_data[q.channel||0]=q.data;m.boxcolor="#AFA"},this._server.on_error=function(k){console.log("couldnt connect to websocket");m.boxcolor="#E88"},this._server.on_close=function(k){console.log("connection closed");m.boxcolor="#000"},this.properties.url&&this.properties.room){try{this._server.connect(this.properties.url,this.properties.room)}catch(w){console.error("SillyServer error: "+w);this._server=null;return}this._final_url=this.properties.url+"/"+this.properties.room}};
q.prototype.send=function(k){this._server&&this._server.is_connected&&this._server.sendMessage({type:1,data:k})};q.prototype.onAction=function(k,m){this._server&&this._server.is_connected&&this._server.sendMessage({type:1,action:k,data:m})};q.prototype.onGetInputs=function(){return[["in",0]]};q.prototype.onGetOutputs=function(){return[["out",0]]};k.registerNodeType("network/sillyclient",q)})(this);

View File

@@ -10284,7 +10284,7 @@ LGraphNode.prototype.executeAction = function(action)
var elem = document.createElement("div");
elem.className = "property";
elem.innerHTML = "<span class='property_name'></span><span class='property_value'></span>";
elem.querySelector(".property_name").innerText = name;
elem.querySelector(".property_name").innerText = options.label || name;
var value_element = elem.querySelector(".property_value");
value_element.innerText = str_value;
elem.dataset["property"] = name;

View File

@@ -1,4 +1,5 @@
cd "$(dirname "$0")"
python builder.py deploy_files.txt -o ../build/litegraph.min.js -o2 ../build/litegraph.js
python builder.py deploy_files_mini.txt -o ../build/litegraph_mini.min.js -o2 ../build/litegraph_mini.js
python builder.py deploy_files_core.txt -o ../build/litegraph.core.min.js -o2 ../build/litegraph.core.js
chmod a+rw ../build/*

View File

@@ -4,7 +4,7 @@ import re, os, sys, time, tempfile, shutil
import argparse
from datetime import date
compiler_path = "/usr/local/bin/compiler.jar"
compiler_path = "../node_modules/google-closure-compiler/compiler.jar"
root_path = "./"
#arguments

View File

@@ -0,0 +1 @@
../src/litegraph.js