This commit is contained in:
tamat
2019-05-10 19:50:01 +02:00
parent 0b0a795ebb
commit 610d4fdb71
2 changed files with 215 additions and 193 deletions

View File

@@ -4309,6 +4309,7 @@ LGraphNode.prototype.executeAction = function(action)
this.pause_rendering = false;
this.clear_background = true;
this.read_only = false; //if set to true users cannot modify the graph
this.render_only_selected = true;
this.live_mode = false;
this.show_info = true;
@@ -4869,7 +4870,7 @@ LGraphNode.prototype.executeAction = function(action)
//when clicked on top of a node
//and it is not interactive
if (node && this.allow_interaction && !skip_action) {
if (node && this.allow_interaction && !skip_action && !this.read_only) {
if (!this.live_mode && !node.flags.pinned) {
this.bringToFront(node);
} //if it wasn't selected?
@@ -5076,29 +5077,30 @@ LGraphNode.prototype.executeAction = function(action)
} //clicked outside of nodes
else {
//search for link connector
for (var i = 0; i < this.visible_links.length; ++i) {
var link = this.visible_links[i];
var center = link._pos;
if (
!center ||
e.canvasX < center[0] - 4 ||
e.canvasX > center[0] + 4 ||
e.canvasY < center[1] - 4 ||
e.canvasY > center[1] + 4
) {
continue;
}
//link clicked
this.showLinkMenu(link, e);
break;
}
if(!this.read_only)
for (var i = 0; i < this.visible_links.length; ++i) {
var link = this.visible_links[i];
var center = link._pos;
if (
!center ||
e.canvasX < center[0] - 4 ||
e.canvasX > center[0] + 4 ||
e.canvasY < center[1] - 4 ||
e.canvasY > center[1] + 4
) {
continue;
}
//link clicked
this.showLinkMenu(link, e);
break;
}
this.selected_group = this.graph.getGroupOnPos(
e.canvasX,
e.canvasY
);
this.selected_group_resizing = false;
if (this.selected_group) {
if (this.selected_group && !this.read_only ) {
if (e.ctrlKey) {
this.dragging_rectangle = null;
}
@@ -5119,7 +5121,7 @@ LGraphNode.prototype.executeAction = function(action)
}
}
if (is_double_click) {
if (is_double_click && !this.read_only ) {
this.showSearchBox(e);
}
@@ -5133,7 +5135,8 @@ LGraphNode.prototype.executeAction = function(action)
//middle button
} else if (e.which == 3) {
//right button
this.processContextMenu(node, e);
if(!this.read_only)
this.processContextMenu(node, e);
}
//TODO
@@ -5210,7 +5213,7 @@ LGraphNode.prototype.executeAction = function(action)
this.dragging_rectangle[2] = e.canvasX - this.dragging_rectangle[0];
this.dragging_rectangle[3] = e.canvasY - this.dragging_rectangle[1];
this.dirty_canvas = true;
} else if (this.selected_group) {
} else if (this.selected_group && !this.read_only) {
//moving/resizing a group
if (this.selected_group_resizing) {
this.selected_group.size = [
@@ -5231,7 +5234,7 @@ LGraphNode.prototype.executeAction = function(action)
this.ds.offset[1] += delta[1] / this.ds.scale;
this.dirty_canvas = true;
this.dirty_bgcanvas = true;
} else if (this.allow_interaction) {
} else if (this.allow_interaction && !this.read_only) {
if (this.connecting_node) {
this.dirty_canvas = true;
}
@@ -16109,14 +16112,13 @@ if (typeof exports != "undefined") {
this.addInput("value", "number");
this.addOutput("Texture", "Texture");
this.help =
"<p>pixelcode must be vec3</p>\
<p>uvcode must be vec2, is optional</p>\
<p><strong>uv:</strong> tex. coords</p><p><strong>color:</strong> texture</p><p><strong>colorB:</strong> textureB</p><p><strong>time:</strong> scene time</p><p><strong>value:</strong> input value</p><p>For multiline you must type: result = ...</p>";
"<p>pixelcode must be vec3, uvcode must be vec2, is optional</p>\
<p><strong>uv:</strong> tex. coords</p><p><strong>color:</strong> texture <strong>colorB:</strong> textureB</p><p><strong>time:</strong> scene time <strong>value:</strong> input value</p><p>For multiline you must type: result = ...</p>";
this.properties = {
value: 1,
uvcode: "",
pixelcode: "color + colorB * value",
uvcode: "",
precision: LGraphTexture.DEFAULT
};
@@ -16124,8 +16126,8 @@ if (typeof exports != "undefined") {
}
LGraphTextureOperation.widgets_info = {
uvcode: { widget: "textarea", height: 100 },
pixelcode: { widget: "textarea", height: 100 },
uvcode: { widget: "code" },
pixelcode: { widget: "code" },
precision: { widget: "combo", values: LGraphTexture.MODE_VALUES }
};
@@ -17156,14 +17158,13 @@ if (typeof exports != "undefined") {
this.addOutput("avg", "vec4");
this.addOutput("lum", "number");
this.properties = {
use_previous_frame: true,
mipmap_offset: 0,
low_precision: false
use_previous_frame: true, //to avoid stalls
high_quality: false //to use as much pixels as possible
};
this._uniforms = {
u_texture: 0,
u_mipmap_offset: this.properties.mipmap_offset
u_mipmap_offset: 0
};
this._luminance = new Float32Array(4);
}
@@ -17234,6 +17235,25 @@ if (typeof exports != "undefined") {
});
}
this._uniforms.u_mipmap_offset = 0;
if(this.properties.high_quality)
{
if( !this._temp_pot2_texture || this._temp_pot2_texture.type != type )
this._temp_pot2_texture = new GL.Texture(512, 512, {
type: type,
format: gl.RGBA,
minFilter: gl.LINEAR_MIPMAP_LINEAR,
magFilter: gl.LINEAR
});
tex.copyTo( this._temp_pot2_texture );
tex = this._temp_pot2_texture;
tex.bind(0);
gl.generateMipmap(GL_TEXTURE_2D);
this._uniforms.u_mipmap_offset = 9;
}
var shader = LGraphTextureAverage._shader;
var uniforms = this._uniforms;
uniforms.u_mipmap_offset = this.properties.mipmap_offset;
@@ -17273,8 +17293,8 @@ if (typeof exports != "undefined") {
void main() {\n\
vec4 color = vec4(0.0);\n\
//random average\n\
for(int i = 0; i <= 4; ++i)\n\
for(int j = 0; j <= 4; ++j)\n\
for(int i = 0; i < 4; ++i)\n\
for(int j = 0; j < 4; ++j)\n\
{\n\
color += texture2D(u_texture, vec2( u_samples_a[i][j], u_samples_b[i][j] ), u_mipmap_offset );\n\
color += texture2D(u_texture, vec2( 1.0 - u_samples_a[i][j], 1.0 - u_samples_b[i][j] ), u_mipmap_offset );\n\

320
build/litegraph.min.js vendored
View File

@@ -1,34 +1,34 @@
(function(v){function e(a){c.debug&&console.log("Graph created");this.list_of_graphcanvas=null;this.clear();a&&this.configure(a)}function h(a,b,d,u,k,c){this.id=a;this.type=b;this.origin_id=d;this.origin_slot=u;this.target_id=k;this.target_slot=c;this._data=null;this._pos=new Float32Array(2)}function r(a){this._ctor(a)}function m(a){this._ctor(a)}function s(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 f(a,b,d){d=d||{};this.background_image="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQBJREFUeNrs1rEKwjAUhlETUkj3vP9rdmr1Ysammk2w5wdxuLgcMHyptfawuZX4pJSWZTnfnu/lnIe/jNNxHHGNn//HNbbv+4dr6V+11uF527arU7+u63qfa/bnmh8sWLBgwYJlqRf8MEptXPBXJXa37BSl3ixYsGDBMliwFLyCV/DeLIMFCxYsWLBMwSt4Be/NggXLYMGCBUvBK3iNruC9WbBgwYJlsGApeAWv4L1ZBgsWLFiwYJmCV/AK3psFC5bBggULloJX8BpdwXuzYMGCBctgwVLwCl7Be7MMFixYsGDBsu8FH1FaSmExVfAxBa/gvVmwYMGCZbBg/W4vAQYA5tRF9QYlv/QAAAAASUVORK5CYII=";
a&&a.constructor===String&&(a=document.querySelector(a));this.ds=new s;this.zoom_modify_alpha=!0;this.title_text_font=""+c.NODE_TEXT_SIZE+"px Arial";this.inner_text_font="normal "+c.NODE_SUBTEXT_SIZE+"px Arial";this.node_title_color=c.NODE_TITLE_COLOR;this.default_link_color=c.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.render_only_selected=
this.clear_background=!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.allow_reconnect_links=!1;this.filter=this.dragging_rectangle=null;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_title_colored=!0;this.links_render_mode=c.SPLINE_LINK;this.canvas_mouse=[0,0];this.onDrawOverlay=this.onDrawForeground=this.onDrawBackground=this.onMouse=this.onSearchBoxSelection=this.onSearchBox=null;this.connections_width=3;this.round_radius=8;this.node_widget=this.current_node=null;this.last_mouse_position=[0,0];this.visible_area=this.ds.visible_area;this.visible_links=[];b&&b.attachCanvas(this);this.setCanvas(a);this.clear();d.skip_render||this.startRendering();this.autoresize=
d.autoresize}function y(a,b){return Math.sqrt((b[0]-a[0])*(b[0]-a[0])+(b[1]-a[1])*(b[1]-a[1]))}function B(a,b,d,u,k,c){return d<a&&d+k>a&&u<b&&u+c>b?!0:!1}function A(a,b){var d=a[0]+a[2],u=a[1]+a[3],k=b[1]+b[3];return a[0]>b[0]+b[2]||a[1]>k||d<b[0]||u<b[1]?!1:!0}function z(a,b){function d(a){var d=parseInt(k.style.top);k.style.top=(d+a.deltaY*b.scroll_speed).toFixed()+"px";a.preventDefault();return!0}this.options=b=b||{};var u=this;b.parentMenu&&(b.parentMenu.constructor!==this.constructor?(console.error("parentMenu must be of class ContextMenu, ignoring it"),
b.parentMenu=null):(this.parentMenu=b.parentMenu,this.parentMenu.lock=!0,this.parentMenu.current_submenu=this));b.event&&b.event.constructor!==MouseEvent&&b.event.constructor!==CustomEvent&&(console.error("Event passed to ContextMenu is not of type MouseEvent or CustomEvent. Ignoring it."),b.event=null);var k=document.createElement("div");k.className="litegraph litecontextmenu litemenubar-panel";b.className&&(k.className+=" "+b.className);k.style.minWidth=100;k.style.minHeight=100;k.style.pointerEvents=
"none";setTimeout(function(){k.style.pointerEvents="auto"},100);k.addEventListener("mouseup",function(a){a.preventDefault();return!0},!0);k.addEventListener("contextmenu",function(a){if(2!=a.button)return!1;a.preventDefault();return!1},!0);k.addEventListener("mousedown",function(a){if(2==a.button)return u.close(),a.preventDefault(),!0},!0);b.scroll_speed||(b.scroll_speed=0.1);k.addEventListener("wheel",d,!0);k.addEventListener("mousewheel",d,!0);this.root=k;if(b.title){var c=document.createElement("div");
c.className="litemenu-title";c.innerHTML=b.title;k.appendChild(c)}var c=0,g;for(g in a){var e=a.constructor==Array?a[g]:g;null!=e&&e.constructor!==String&&(e=void 0===e.content?String(e):e.content);this.addItem(e,a[g],b);c++}k.addEventListener("mouseleave",function(a){u.lock||(k.closing_timer&&clearTimeout(k.closing_timer),k.closing_timer=setTimeout(u.close.bind(u,a),500))});k.addEventListener("mouseenter",function(a){k.closing_timer&&clearTimeout(k.closing_timer)});g=document;b.event&&(g=b.event.target.ownerDocument);
g||(g=document);g.body.appendChild(k);c=b.left||0;g=b.top||0;if(b.event){c=b.event.clientX-10;g=b.event.clientY-10;b.title&&(g-=20);b.parentMenu&&(c=b.parentMenu.root.getBoundingClientRect(),c=c.left+c.width);var e=document.body.getBoundingClientRect(),f=k.getBoundingClientRect();c>e.width-f.width-10&&(c=e.width-f.width-10);g>e.height-f.height-10&&(g=e.height-f.height-10)}k.style.left=c+"px";k.style.top=g+"px";b.scale&&(k.style.transform="scale("+b.scale+")")}var c=v.LiteGraph={VERSION:0.4,CANVAS_GRID_SIZE:10,
NODE_TITLE_HEIGHT:30,NODE_TITLE_TEXT_Y:20,NODE_SLOT_HEIGHT:20,NODE_WIDGET_HEIGHT:20,NODE_WIDTH:140,NODE_MIN_WIDTH:50,NODE_COLLAPSED_RADIUS:10,NODE_COLLAPSED_WIDTH:80,NODE_TITLE_COLOR:"#999",NODE_TEXT_SIZE:14,NODE_TEXT_COLOR:"#AAA",NODE_SUBTEXT_SIZE:12,NODE_DEFAULT_COLOR:"#333",NODE_DEFAULT_BGCOLOR:"#353535",NODE_DEFAULT_BOXCOLOR:"#666",NODE_DEFAULT_SHAPE:"box",DEFAULT_SHADOW_COLOR:"rgba(0,0,0,0.5)",DEFAULT_GROUP_FONT:24,LINK_COLOR:"#9A9",EVENT_LINK_COLOR:"#A86",CONNECTING_LINK_COLOR:"#AFA",MAX_NUMBER_OF_NODES:1E3,
DEFAULT_POSITION:[100,100],VALID_SHAPES:["default","box","round","card"],BOX_SHAPE:1,ROUND_SHAPE:2,CIRCLE_SHAPE:3,CARD_SHAPE:4,ARROW_SHAPE:5,INPUT:1,OUTPUT:2,EVENT:-1,ACTION:-1,ALWAYS:0,ON_EVENT:1,NEVER:2,ON_TRIGGER:3,UP:1,DOWN:2,LEFT:3,RIGHT:4,CENTER:5,STRAIGHT_LINK:0,LINEAR_LINK:1,SPLINE_LINK:2,NORMAL_TITLE:0,NO_TITLE:1,TRANSPARENT_TITLE:2,AUTOHIDE_TITLE:3,proxy:null,node_images_path:"",debug:!1,catch_exceptions:!0,throw_errors:!0,allow_scripts:!1,registered_node_types:{},node_types_by_file_extension:{},
Nodes:{},searchbox_extras:{},registerNodeType:function(a,b){if(!b.prototype)throw"Cannot register a simple object, it must be a class with a prototype";b.type=a;c.debug&&console.log("Node registered: "+a);a.split("/");var d=b.name,u=a.lastIndexOf("/");b.category=a.substr(0,u);b.title||(b.title=d);if(b.prototype)for(var k in r.prototype)b.prototype[k]||(b.prototype[k]=r.prototype[k]);Object.defineProperty(b.prototype,"shape",{set:function(a){switch(a){case "default":delete this._shape;break;case "box":this._shape=
c.BOX_SHAPE;break;case "round":this._shape=c.ROUND_SHAPE;break;case "circle":this._shape=c.CIRCLE_SHAPE;break;case "card":this._shape=c.CARD_SHAPE;break;default:this._shape=a}},get:function(a){return this._shape},enumerable:!0});u=this.registered_node_types[a];this.registered_node_types[a]=b;b.constructor.name&&(this.Nodes[d]=b);if(c.onNodeTypeRegistered)c.onNodeTypeRegistered(a,b);if(u&&c.onNodeTypeReplaced)c.onNodeTypeReplaced(a,b,u);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(k in b.supported_extensions)this.node_types_by_file_extension[b.supported_extensions[k].toLowerCase()]=b},wrapFunctionAsNode:function(a,b,d,u,k){for(var g=Array(b.length),e="",f=c.getParameterNames(b),p=0;p<f.length;++p)e+="this.addInput('"+f[p]+"',"+(d&&d[p]?"'"+d[p]+"'":"0")+");\n";e+="this.addOutput('out',"+(u?"'"+u+"'":0)+");\n";k&&(e+="this.properties = "+JSON.stringify(k)+";\n");
d=Function(e);d.title=a.split("/").pop();d.desc="Generated from "+b.name;d.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,d)},addNodeMethod:function(a,b){r.prototype[a]=b;for(var d in this.registered_node_types){var u=this.registered_node_types[d];u.prototype[a]&&(u.prototype["_"+a]=u.prototype[a]);u.prototype[a]=b}},createNode:function(a,b,d){var u=this.registered_node_types[a];if(!u)return c.debug&&
console.log('GraphNode type "'+a+'" not registered.'),null;b=b||u.title||a;var k=null;if(c.catch_exceptions)try{k=new u(b)}catch(g){return console.error(g),null}else k=new u(b);k.type=a;!k.title&&b&&(k.title=b);k.properties||(k.properties={});k.properties_info||(k.properties_info=[]);k.flags||(k.flags={});k.size||(k.size=k.computeSize());k.pos||(k.pos=c.DEFAULT_POSITION.concat());k.mode||(k.mode=c.ALWAYS);if(d)for(var e in d)k[e]=d[e];return k},getNodeType:function(a){return this.registered_node_types[a]},
getNodeTypesInCategory:function(a,b){var d=[],u;for(u in this.registered_node_types){var c=this.registered_node_types[u];b&&c.filter&&c.filter!=b||(""==a?null==c.category&&d.push(c):c.category==a&&d.push(c))}return d},getNodeTypesCategories:function(){var a={"":1},b;for(b in this.registered_node_types)this.registered_node_types[b].category&&!this.registered_node_types[b].skip_list&&(a[this.registered_node_types[b].category]=1);var d=[];for(b in a)d.push(b);return d},reloadNodes:function(a){var b=
document.getElementsByTagName("script"),d=[],u;for(u in b)d.push(b[u]);b=document.getElementsByTagName("head")[0];a=document.location.href+a;for(u in d){var k=d[u].src;if(k&&k.substr(0,a.length)==a)try{c.debug&&console.log("Reloading: "+k);var g=document.createElement("script");g.type="text/javascript";g.src=k;b.appendChild(g);b.removeChild(d[u])}catch(e){if(c.throw_errors)throw e;c.debug&&console.log("Error while reloading "+k)}}c.debug&&console.log("Nodes reloaded")},cloneObject:function(a,b){if(null==
a)return null;var d=JSON.parse(JSON.stringify(a));if(!b)return d;for(var u in d)b[u]=d[u];return b},isValidConnection:function(a,b){if(!a||!b||a==b||a==c.EVENT&&b==c.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 d=a.split(","),u=b.split(","),k=0;k<d.length;++k)for(var g=0;g<u.length;++g)if(d[k]==u[g])return!0;return!1},registerSearchboxExtra:function(a,b,d){this.searchbox_extras[b]={type:a,desc:b,data:d}}};
c.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()};v.LGraph=c.LGraph=e;e.supported_types=["number","string","boolean"];e.prototype.getSupportedTypes=function(){return this.supported_types||e.supported_types};e.STATUS_STOPPED=1;e.STATUS_RUNNING=2;e.prototype.clear=function(){this.stop();this.status=
e.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.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")};e.prototype.attachCanvas=function(a){if(a.constructor!=f)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)};e.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))}};e.prototype.start=function(a){if(this.status!=
e.STATUS_RUNNING){this.status=e.STATUS_RUNNING;if(this.onPlayEvent)this.onPlayEvent();this.sendEventToAllNodes("onStart");this.last_update_time=this.starttime=c.getTime();a=a||0;var b=this;if(0==a&&"undefined"!=typeof window&&window.requestAnimationFrame){var d=function(){-1==b.execution_timer_id&&(window.requestAnimationFrame(d),b.runStep(1,!this.catch_errors))};this.execution_timer_id=-1;d()}else this.execution_timer_id=setInterval(function(){b.runStep(1,!this.catch_errors)},a)}};e.prototype.stop=
function(){if(this.status!=e.STATUS_STOPPED){this.status=e.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")}};e.prototype.runStep=function(a,b){a=a||1;var d=c.getTime();this.globaltime=0.001*(d-this.starttime);var u=this._nodes_executable?this._nodes_executable:this._nodes;if(u){if(b){for(var k=0;k<a;k++){for(var g=0,e=u.length;g<
e;++g){var f=u[g];if(f.mode==c.ALWAYS&&f.onExecute)f.onExecute()}this.fixedtime+=this.fixedtime_lapse;if(this.onExecuteStep)this.onExecuteStep()}if(this.onAfterExecute)this.onAfterExecute()}else try{for(k=0;k<a;k++){g=0;for(e=u.length;g<e;++g)if(f=u[g],f.mode==c.ALWAYS&&f.onExecute)f.onExecute();this.fixedtime+=this.fixedtime_lapse;if(this.onExecuteStep)this.onExecuteStep()}if(this.onAfterExecute)this.onAfterExecute();this.errors_in_execution=!1}catch(p){this.errors_in_execution=!0;if(c.throw_errors)throw p;
c.debug&&console.log("Error during execution: "+p);this.stop()}u=c.getTime();d=u-d;0==d&&(d=1);this.execution_time=0.001*d;this.globaltime+=0.001*d;this.iteration+=1;this.elapsed_time=0.001*(u-this.last_update_time);this.last_update_time=u}};e.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])};e.prototype.computeExecutionOrder=
function(a,b){for(var d=[],u=[],k={},g={},e={},f=0,p=this._nodes.length;f<p;++f){var n=this._nodes[f];if(!a||n.onExecute){k[n.id]=n;var q=0;if(n.inputs)for(var t=0,D=n.inputs.length;t<D;t++)n.inputs[t]&&null!=n.inputs[t].link&&(q+=1);0==q?(u.push(n),b&&(n._level=1)):(b&&(n._level=0),e[n.id]=q)}}for(;0!=u.length;)if(n=u.shift(),d.push(n),delete k[n.id],n.outputs)for(f=0;f<n.outputs.length;f++)if(p=n.outputs[f],null!=p&&null!=p.links&&0!=p.links.length)for(t=0;t<p.links.length;t++)(q=this.links[p.links[t]])&&
!g[q.id]&&(D=this.getNodeById(q.target_id),null==D?g[q.id]=!0:(b&&(!D._level||D._level<=n._level)&&(D._level=n._level+1),g[q.id]=!0,e[D.id]-=1,0==e[D.id]&&u.push(D)));for(f in k)d.push(k[f]);d.length!=this._nodes.length&&c.debug&&console.warn("something went wrong, nodes missing");p=d.length;for(f=0;f<p;++f)d[f].order=f;d=d.sort(function(a,b){var d=a.constructor.priority||a.priority||0,t=b.constructor.priority||b.priority||0;return d==t?a.order-b.order:d-t});for(f=0;f<p;++f)d[f].order=f;return d};
e.prototype.getAncestors=function(a){for(var b=[],d=[a],u={};d.length;){var c=d.shift();if(c.inputs){u[c.id]||c==a||(u[c.id]=!0,b.push(c));for(var g=0;g<c.inputs.length;++g){var e=c.getInputNode(g);e&&-1==b.indexOf(e)&&d.push(e)}}}b.sort(function(a,b){return a.order-b.order});return b};e.prototype.arrange=function(a){a=a||40;for(var b=this.computeExecutionOrder(!1,!0),d=[],c=0;c<b.length;++c){var k=b[c],g=k._level||1;d[g]||(d[g]=[]);d[g].push(k)}b=a;for(c=0;c<d.length;++c)if(g=d[c]){for(var e=100,
f=a,p=0;p<g.length;++p)k=g[p],k.pos[0]=b,k.pos[1]=f,k.size[0]>e&&(e=k.size[0]),f+=k.size[1]+a;b+=e+a}this.setDirtyCanvas(!0,!0)};e.prototype.getTime=function(){return this.globaltime};e.prototype.getFixedTime=function(){return this.fixedtime};e.prototype.getElapsedTime=function(){return this.elapsed_time};e.prototype.sendEventToAllNodes=function(a,b,d){d=d||c.ALWAYS;var u=this._nodes_in_order?this._nodes_in_order:this._nodes;if(u)for(var k=0,g=u.length;k<g;++k){var e=u[k];if(e.constructor===c.Subgraph&&
a&&a.constructor===String&&(a=document.querySelector(a));this.ds=new s;this.zoom_modify_alpha=!0;this.title_text_font=""+c.NODE_TEXT_SIZE+"px Arial";this.inner_text_font="normal "+c.NODE_SUBTEXT_SIZE+"px Arial";this.node_title_color=c.NODE_TITLE_COLOR;this.default_link_color=c.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.allow_reconnect_links=!1;this.filter=this.dragging_rectangle=null;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_title_colored=!0;this.links_render_mode=c.SPLINE_LINK;this.canvas_mouse=[0,0];this.onDrawOverlay=this.onDrawForeground=this.onDrawBackground=this.onMouse=this.onSearchBoxSelection=this.onSearchBox=null;this.connections_width=3;this.round_radius=8;this.node_widget=this.current_node=null;this.last_mouse_position=[0,0];this.visible_area=this.ds.visible_area;this.visible_links=[];b&&b.attachCanvas(this);this.setCanvas(a);this.clear();d.skip_render||this.startRendering();
this.autoresize=d.autoresize}function y(a,b){return Math.sqrt((b[0]-a[0])*(b[0]-a[0])+(b[1]-a[1])*(b[1]-a[1]))}function B(a,b,d,u,k,c){return d<a&&d+k>a&&u<b&&u+c>b?!0:!1}function A(a,b){var d=a[0]+a[2],u=a[1]+a[3],k=b[1]+b[3];return a[0]>b[0]+b[2]||a[1]>k||d<b[0]||u<b[1]?!1:!0}function z(a,b){function d(a){var d=parseInt(k.style.top);k.style.top=(d+a.deltaY*b.scroll_speed).toFixed()+"px";a.preventDefault();return!0}this.options=b=b||{};var u=this;b.parentMenu&&(b.parentMenu.constructor!==this.constructor?
(console.error("parentMenu must be of class ContextMenu, ignoring it"),b.parentMenu=null):(this.parentMenu=b.parentMenu,this.parentMenu.lock=!0,this.parentMenu.current_submenu=this));b.event&&b.event.constructor!==MouseEvent&&b.event.constructor!==CustomEvent&&(console.error("Event passed to ContextMenu is not of type MouseEvent or CustomEvent. Ignoring it."),b.event=null);var k=document.createElement("div");k.className="litegraph litecontextmenu litemenubar-panel";b.className&&(k.className+=" "+
b.className);k.style.minWidth=100;k.style.minHeight=100;k.style.pointerEvents="none";setTimeout(function(){k.style.pointerEvents="auto"},100);k.addEventListener("mouseup",function(a){a.preventDefault();return!0},!0);k.addEventListener("contextmenu",function(a){if(2!=a.button)return!1;a.preventDefault();return!1},!0);k.addEventListener("mousedown",function(a){if(2==a.button)return u.close(),a.preventDefault(),!0},!0);b.scroll_speed||(b.scroll_speed=0.1);k.addEventListener("wheel",d,!0);k.addEventListener("mousewheel",
d,!0);this.root=k;if(b.title){var c=document.createElement("div");c.className="litemenu-title";c.innerHTML=b.title;k.appendChild(c)}var c=0,g;for(g in a){var e=a.constructor==Array?a[g]:g;null!=e&&e.constructor!==String&&(e=void 0===e.content?String(e):e.content);this.addItem(e,a[g],b);c++}k.addEventListener("mouseleave",function(a){u.lock||(k.closing_timer&&clearTimeout(k.closing_timer),k.closing_timer=setTimeout(u.close.bind(u,a),500))});k.addEventListener("mouseenter",function(a){k.closing_timer&&
clearTimeout(k.closing_timer)});g=document;b.event&&(g=b.event.target.ownerDocument);g||(g=document);g.body.appendChild(k);c=b.left||0;g=b.top||0;if(b.event){c=b.event.clientX-10;g=b.event.clientY-10;b.title&&(g-=20);b.parentMenu&&(c=b.parentMenu.root.getBoundingClientRect(),c=c.left+c.width);var e=document.body.getBoundingClientRect(),f=k.getBoundingClientRect();c>e.width-f.width-10&&(c=e.width-f.width-10);g>e.height-f.height-10&&(g=e.height-f.height-10)}k.style.left=c+"px";k.style.top=g+"px";b.scale&&
(k.style.transform="scale("+b.scale+")")}var c=v.LiteGraph={VERSION:0.4,CANVAS_GRID_SIZE:10,NODE_TITLE_HEIGHT:30,NODE_TITLE_TEXT_Y:20,NODE_SLOT_HEIGHT:20,NODE_WIDGET_HEIGHT:20,NODE_WIDTH:140,NODE_MIN_WIDTH:50,NODE_COLLAPSED_RADIUS:10,NODE_COLLAPSED_WIDTH:80,NODE_TITLE_COLOR:"#999",NODE_TEXT_SIZE:14,NODE_TEXT_COLOR:"#AAA",NODE_SUBTEXT_SIZE:12,NODE_DEFAULT_COLOR:"#333",NODE_DEFAULT_BGCOLOR:"#353535",NODE_DEFAULT_BOXCOLOR:"#666",NODE_DEFAULT_SHAPE:"box",DEFAULT_SHADOW_COLOR:"rgba(0,0,0,0.5)",DEFAULT_GROUP_FONT:24,
LINK_COLOR:"#9A9",EVENT_LINK_COLOR:"#A86",CONNECTING_LINK_COLOR:"#AFA",MAX_NUMBER_OF_NODES:1E3,DEFAULT_POSITION:[100,100],VALID_SHAPES:["default","box","round","card"],BOX_SHAPE:1,ROUND_SHAPE:2,CIRCLE_SHAPE:3,CARD_SHAPE:4,ARROW_SHAPE:5,INPUT:1,OUTPUT:2,EVENT:-1,ACTION:-1,ALWAYS:0,ON_EVENT:1,NEVER:2,ON_TRIGGER:3,UP:1,DOWN:2,LEFT:3,RIGHT:4,CENTER:5,STRAIGHT_LINK:0,LINEAR_LINK:1,SPLINE_LINK:2,NORMAL_TITLE:0,NO_TITLE:1,TRANSPARENT_TITLE:2,AUTOHIDE_TITLE:3,proxy:null,node_images_path:"",debug:!1,catch_exceptions:!0,
throw_errors:!0,allow_scripts:!1,registered_node_types:{},node_types_by_file_extension:{},Nodes:{},searchbox_extras:{},registerNodeType:function(a,b){if(!b.prototype)throw"Cannot register a simple object, it must be a class with a prototype";b.type=a;c.debug&&console.log("Node registered: "+a);a.split("/");var d=b.name,u=a.lastIndexOf("/");b.category=a.substr(0,u);b.title||(b.title=d);if(b.prototype)for(var k in r.prototype)b.prototype[k]||(b.prototype[k]=r.prototype[k]);Object.defineProperty(b.prototype,
"shape",{set:function(a){switch(a){case "default":delete this._shape;break;case "box":this._shape=c.BOX_SHAPE;break;case "round":this._shape=c.ROUND_SHAPE;break;case "circle":this._shape=c.CIRCLE_SHAPE;break;case "card":this._shape=c.CARD_SHAPE;break;default:this._shape=a}},get:function(a){return this._shape},enumerable:!0});u=this.registered_node_types[a];this.registered_node_types[a]=b;b.constructor.name&&(this.Nodes[d]=b);if(c.onNodeTypeRegistered)c.onNodeTypeRegistered(a,b);if(u&&c.onNodeTypeReplaced)c.onNodeTypeReplaced(a,
b,u);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(k in b.supported_extensions)this.node_types_by_file_extension[b.supported_extensions[k].toLowerCase()]=b},wrapFunctionAsNode:function(a,b,d,u,k){for(var g=Array(b.length),e="",f=c.getParameterNames(b),p=0;p<f.length;++p)e+="this.addInput('"+f[p]+"',"+(d&&d[p]?"'"+d[p]+"'":"0")+");\n";e+="this.addOutput('out',"+
(u?"'"+u+"'":0)+");\n";k&&(e+="this.properties = "+JSON.stringify(k)+";\n");d=Function(e);d.title=a.split("/").pop();d.desc="Generated from "+b.name;d.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,d)},addNodeMethod:function(a,b){r.prototype[a]=b;for(var d in this.registered_node_types){var u=this.registered_node_types[d];u.prototype[a]&&(u.prototype["_"+a]=u.prototype[a]);u.prototype[a]=b}},createNode:function(a,
b,d){var u=this.registered_node_types[a];if(!u)return c.debug&&console.log('GraphNode type "'+a+'" not registered.'),null;b=b||u.title||a;var k=null;if(c.catch_exceptions)try{k=new u(b)}catch(g){return console.error(g),null}else k=new u(b);k.type=a;!k.title&&b&&(k.title=b);k.properties||(k.properties={});k.properties_info||(k.properties_info=[]);k.flags||(k.flags={});k.size||(k.size=k.computeSize());k.pos||(k.pos=c.DEFAULT_POSITION.concat());k.mode||(k.mode=c.ALWAYS);if(d)for(var e in d)k[e]=d[e];
return k},getNodeType:function(a){return this.registered_node_types[a]},getNodeTypesInCategory:function(a,b){var d=[],u;for(u in this.registered_node_types){var c=this.registered_node_types[u];b&&c.filter&&c.filter!=b||(""==a?null==c.category&&d.push(c):c.category==a&&d.push(c))}return d},getNodeTypesCategories:function(){var a={"":1},b;for(b in this.registered_node_types)this.registered_node_types[b].category&&!this.registered_node_types[b].skip_list&&(a[this.registered_node_types[b].category]=1);
var d=[];for(b in a)d.push(b);return d},reloadNodes:function(a){var b=document.getElementsByTagName("script"),d=[],u;for(u in b)d.push(b[u]);b=document.getElementsByTagName("head")[0];a=document.location.href+a;for(u in d){var k=d[u].src;if(k&&k.substr(0,a.length)==a)try{c.debug&&console.log("Reloading: "+k);var g=document.createElement("script");g.type="text/javascript";g.src=k;b.appendChild(g);b.removeChild(d[u])}catch(e){if(c.throw_errors)throw e;c.debug&&console.log("Error while reloading "+k)}}c.debug&&
console.log("Nodes reloaded")},cloneObject:function(a,b){if(null==a)return null;var d=JSON.parse(JSON.stringify(a));if(!b)return d;for(var u in d)b[u]=d[u];return b},isValidConnection:function(a,b){if(!a||!b||a==b||a==c.EVENT&&b==c.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 d=a.split(","),u=b.split(","),k=0;k<d.length;++k)for(var g=0;g<u.length;++g)if(d[k]==u[g])return!0;return!1},registerSearchboxExtra:function(a,
b,d){this.searchbox_extras[b]={type:a,desc:b,data:d}}};c.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()};v.LGraph=c.LGraph=e;e.supported_types=["number","string","boolean"];e.prototype.getSupportedTypes=function(){return this.supported_types||e.supported_types};e.STATUS_STOPPED=1;e.STATUS_RUNNING=
2;e.prototype.clear=function(){this.stop();this.status=e.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.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")};e.prototype.attachCanvas=function(a){if(a.constructor!=f)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)};e.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))}};e.prototype.start=function(a){if(this.status!=e.STATUS_RUNNING){this.status=e.STATUS_RUNNING;if(this.onPlayEvent)this.onPlayEvent();this.sendEventToAllNodes("onStart");this.last_update_time=this.starttime=c.getTime();a=a||0;var b=this;if(0==a&&"undefined"!=typeof window&&window.requestAnimationFrame){var d=function(){-1==b.execution_timer_id&&(window.requestAnimationFrame(d),b.runStep(1,!this.catch_errors))};this.execution_timer_id=-1;d()}else this.execution_timer_id=setInterval(function(){b.runStep(1,
!this.catch_errors)},a)}};e.prototype.stop=function(){if(this.status!=e.STATUS_STOPPED){this.status=e.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")}};e.prototype.runStep=function(a,b){a=a||1;var d=c.getTime();this.globaltime=0.001*(d-this.starttime);var u=this._nodes_executable?this._nodes_executable:this._nodes;if(u){if(b){for(var k=
0;k<a;k++){for(var g=0,e=u.length;g<e;++g){var f=u[g];if(f.mode==c.ALWAYS&&f.onExecute)f.onExecute()}this.fixedtime+=this.fixedtime_lapse;if(this.onExecuteStep)this.onExecuteStep()}if(this.onAfterExecute)this.onAfterExecute()}else try{for(k=0;k<a;k++){g=0;for(e=u.length;g<e;++g)if(f=u[g],f.mode==c.ALWAYS&&f.onExecute)f.onExecute();this.fixedtime+=this.fixedtime_lapse;if(this.onExecuteStep)this.onExecuteStep()}if(this.onAfterExecute)this.onAfterExecute();this.errors_in_execution=!1}catch(p){this.errors_in_execution=
!0;if(c.throw_errors)throw p;c.debug&&console.log("Error during execution: "+p);this.stop()}u=c.getTime();d=u-d;0==d&&(d=1);this.execution_time=0.001*d;this.globaltime+=0.001*d;this.iteration+=1;this.elapsed_time=0.001*(u-this.last_update_time);this.last_update_time=u}};e.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])};
e.prototype.computeExecutionOrder=function(a,b){for(var d=[],u=[],k={},g={},e={},f=0,p=this._nodes.length;f<p;++f){var n=this._nodes[f];if(!a||n.onExecute){k[n.id]=n;var q=0;if(n.inputs)for(var t=0,D=n.inputs.length;t<D;t++)n.inputs[t]&&null!=n.inputs[t].link&&(q+=1);0==q?(u.push(n),b&&(n._level=1)):(b&&(n._level=0),e[n.id]=q)}}for(;0!=u.length;)if(n=u.shift(),d.push(n),delete k[n.id],n.outputs)for(f=0;f<n.outputs.length;f++)if(p=n.outputs[f],null!=p&&null!=p.links&&0!=p.links.length)for(t=0;t<p.links.length;t++)(q=
this.links[p.links[t]])&&!g[q.id]&&(D=this.getNodeById(q.target_id),null==D?g[q.id]=!0:(b&&(!D._level||D._level<=n._level)&&(D._level=n._level+1),g[q.id]=!0,e[D.id]-=1,0==e[D.id]&&u.push(D)));for(f in k)d.push(k[f]);d.length!=this._nodes.length&&c.debug&&console.warn("something went wrong, nodes missing");p=d.length;for(f=0;f<p;++f)d[f].order=f;d=d.sort(function(a,b){var d=a.constructor.priority||a.priority||0,t=b.constructor.priority||b.priority||0;return d==t?a.order-b.order:d-t});for(f=0;f<p;++f)d[f].order=
f;return d};e.prototype.getAncestors=function(a){for(var b=[],d=[a],u={};d.length;){var c=d.shift();if(c.inputs){u[c.id]||c==a||(u[c.id]=!0,b.push(c));for(var g=0;g<c.inputs.length;++g){var e=c.getInputNode(g);e&&-1==b.indexOf(e)&&d.push(e)}}}b.sort(function(a,b){return a.order-b.order});return b};e.prototype.arrange=function(a){a=a||40;for(var b=this.computeExecutionOrder(!1,!0),d=[],c=0;c<b.length;++c){var k=b[c],g=k._level||1;d[g]||(d[g]=[]);d[g].push(k)}b=a;for(c=0;c<d.length;++c)if(g=d[c]){for(var e=
100,f=a,p=0;p<g.length;++p)k=g[p],k.pos[0]=b,k.pos[1]=f,k.size[0]>e&&(e=k.size[0]),f+=k.size[1]+a;b+=e+a}this.setDirtyCanvas(!0,!0)};e.prototype.getTime=function(){return this.globaltime};e.prototype.getFixedTime=function(){return this.fixedtime};e.prototype.getElapsedTime=function(){return this.elapsed_time};e.prototype.sendEventToAllNodes=function(a,b,d){d=d||c.ALWAYS;var u=this._nodes_in_order?this._nodes_in_order:this._nodes;if(u)for(var k=0,g=u.length;k<g;++k){var e=u[k];if(e.constructor===c.Subgraph&&
"onExecute"!=a)e.mode==d&&e.sendEventToAllNodes(a,b,d);else if(e[a]&&e.mode==d)if(void 0===b)e[a]();else if(b&&b.constructor===Array)e[a].apply(e,b);else e[a](b)}};e.prototype.sendActionToCanvas=function(a,b){if(this.list_of_graphcanvas)for(var d=0;d<this.list_of_graphcanvas.length;++d){var c=this.list_of_graphcanvas[d];c[a]&&c[a].apply(c,b)}};e.prototype.add=function(a,b){if(a)if(a.constructor===m)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>=c.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}};e.prototype.remove=function(a){if(a.constructor===c.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){if(a.inputs)for(b=0;b<a.inputs.length;b++){var d=a.inputs[b];null!=d.link&&a.disconnectInput(b)}if(a.outputs)for(b=0;b<a.outputs.length;b++)d=a.outputs[b],null!=
@@ -104,126 +104,127 @@ this._ondrop_callback);this.canvas.removeEventListener("dragenter",this._doRetur
f.getFileExtension=function(a){var b=a.indexOf("?");-1!=b&&(a=a.substr(0,b));b=a.lastIndexOf(".");return-1==b?"":a.substr(b+1).toLowerCase()};f.prototype.enableWebGL=function(){if(void 0===typeof GL)throw"litegl.js must be included to use a WebGL canvas";if(void 0===typeof enableWebGLCanvas)throw"webglCanvas.js must be included to use this feature";this.gl=this.ctx=enableWebGLCanvas(this.canvas);this.ctx.webgl=!0;this.bgcanvas=this.canvas;this.bgctx=this.gl;this.canvas.webgl_enabled=!0};f.prototype.setDirty=
function(a,b){a&&(this.dirty_canvas=!0);b&&(this.dirty_bgcanvas=!0)};f.prototype.getCanvasWindow=function(){if(!this.canvas)return window;var a=this.canvas.ownerDocument;return a.defaultView||a.parentWindow};f.prototype.startRendering=function(){function a(){this.pause_rendering||this.draw();var b=this.getCanvasWindow();this.is_rendering&&b.requestAnimationFrame(a.bind(this))}this.is_rendering||(this.is_rendering=!0,a.call(this))};f.prototype.stopRendering=function(){this.is_rendering=!1};f.prototype.processMouseDown=
function(a){if(this.graph){this.adjustMouseEvent(a);var b=this.getCanvasWindow();f.active_canvas=this;this.canvas.removeEventListener("mousemove",this._mousemove_callback);b.document.addEventListener("mousemove",this._mousemove_callback,!0);b.document.addEventListener("mouseup",this._mouseup_callback,!0);var d=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes,5),g=!1,k=300>c.getTime()-this.last_mouseclick;this.canvas_mouse[0]=a.canvasX;this.canvas_mouse[1]=a.canvasY;this.canvas.focus();
c.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,g=!0);var e=!1;if(d&&this.allow_interaction&&!g){this.live_mode||d.flags.pinned||this.bringToFront(d);if(!this.connecting_node&&!d.flags.collapsed&&!this.live_mode)if(!g&&!1!==d.resizable&&B(a.canvasX,a.canvasY,d.pos[0]+d.size[0]-5,d.pos[1]+
d.size[1]-5,10,10))this.resizing_node=d,this.canvas.style.cursor="se-resize",g=!0;else{if(d.outputs)for(var p=0,n=d.outputs.length;p<n;++p){var q=d.outputs[p],l=d.getConnectionPos(!1,p);if(B(a.canvasX,a.canvasY,l[0]-15,l[1]-10,30,20)){this.connecting_node=d;this.connecting_output=q;this.connecting_pos=d.getConnectionPos(!1,p);this.connecting_slot=p;a.shiftKey&&d.disconnectOutput(p);if(k){if(d.onOutputDblClick)d.onOutputDblClick(p,a)}else if(d.onOutputClick)d.onOutputClick(p,a);g=!0;break}}if(d.inputs)for(p=
0,n=d.inputs.length;p<n;++p)if(q=d.inputs[p],l=d.getConnectionPos(!0,p),B(a.canvasX,a.canvasY,l[0]-15,l[1]-10,30,20)){if(k){if(d.onInputDblClick)d.onInputDblClick(p,a)}else if(d.onInputClick)d.onInputClick(p,a);if(null!==q.link){g=this.graph.links[q.link];d.disconnectInput(p);if(this.allow_reconnect_links||a.shiftKey)this.connecting_node=this.graph._nodes_by_id[g.origin_id],this.connecting_slot=g.origin_slot,this.connecting_output=this.connecting_node.outputs[this.connecting_slot],this.connecting_pos=
this.connecting_node.getConnectionPos(!1,this.connecting_slot);g=this.dirty_bgcanvas=!0}}}if(!g){p=!1;if(n=this.processNodeWidgets(d,this.canvas_mouse,a))p=!0,this.node_widget=[d,n];if(k&&this.selected_nodes[d.id]){if(d.onDblClick)d.onDblClick(a,[a.canvasX-d.pos[0],a.canvasY-d.pos[1]],this);this.processNodeDblClicked(d);p=!0}d.onMouseDown&&d.onMouseDown(a,[a.canvasX-d.pos[0],a.canvasY-d.pos[1]],this)?p=!0:this.live_mode&&(p=e=!0);p||(this.allow_dragnodes&&(this.node_dragged=d),this.selected_nodes[d.id]||
this.processNodeSelected(d,a));this.dirty_canvas=!0}}else{for(p=0;p<this.visible_links.length;++p)if(d=this.visible_links[p],(e=d._pos)&&!(a.canvasX<e[0]-4||a.canvasX>e[0]+4||a.canvasY<e[1]-4||a.canvasY>e[1]+4)){this.showLinkMenu(d,a);break}this.selected_group=this.graph.getGroupOnPos(a.canvasX,a.canvasY);this.selected_group_resizing=!1;this.selected_group&&(a.ctrlKey&&(this.dragging_rectangle=null),10>y([a.canvasX,a.canvasY],[this.selected_group.pos[0]+this.selected_group.size[0],this.selected_group.pos[1]+
this.selected_group.size[1]])*this.ds.scale?this.selected_group_resizing=!0:this.selected_group.recomputeInsideNodes());k&&this.showSearchBox(a);e=!0}!g&&e&&this.allow_dragcanvas&&(this.dragging_canvas=!0)}else 2!=a.which&&3==a.which&&this.processContextMenu(d,a);this.last_mouse[0]=a.localX;this.last_mouse[1]=a.localY;this.last_mouseclick=c.getTime();this.last_mouse_dragging=!0;this.graph.change();(!b.document.activeElement||"input"!=b.document.activeElement.nodeName.toLowerCase()&&"textarea"!=b.document.activeElement.nodeName.toLowerCase())&&
a.preventDefault();a.stopPropagation();if(this.onMouseDown)this.onMouseDown(a);return!1}}};f.prototype.processMouseMove=function(a){this.autoresize&&this.resize();if(this.graph){f.active_canvas=this;this.adjustMouseEvent(a);var b=[a.localX,a.localY],d=[b[0]-this.last_mouse[0],b[1]-this.last_mouse[1]];this.last_mouse=b;this.canvas_mouse[0]=a.canvasX;this.canvas_mouse[1]=a.canvasY;a.dragging=this.last_mouse_dragging;this.node_widget&&(this.processNodeWidgets(this.node_widget[0],this.canvas_mouse,a,
this.node_widget[1]),this.dirty_canvas=!0);if(this.dragging_rectangle)this.dragging_rectangle[2]=a.canvasX-this.dragging_rectangle[0],this.dragging_rectangle[3]=a.canvasY-this.dragging_rectangle[1],this.dirty_canvas=!0;else if(this.selected_group)this.selected_group_resizing?this.selected_group.size=[a.canvasX-this.selected_group.pos[0],a.canvasY-this.selected_group.pos[1]]:(this.selected_group.move(d[0]/this.ds.scale,d[1]/this.ds.scale,a.ctrlKey),this.selected_group._nodes.length&&(this.dirty_canvas=
!0)),this.dirty_bgcanvas=!0;else if(this.dragging_canvas)this.ds.offset[0]+=d[0]/this.ds.scale,this.ds.offset[1]+=d[1]/this.ds.scale,this.dirty_bgcanvas=this.dirty_canvas=!0;else if(this.allow_interaction){this.connecting_node&&(this.dirty_canvas=!0);for(var g=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes),b=0,k=this.graph._nodes.length;b<k;++b)if(this.graph._nodes[b].mouseOver&&g!=this.graph._nodes[b]){this.graph._nodes[b].mouseOver=!1;if(this.node_over&&this.node_over.onMouseLeave)this.node_over.onMouseLeave(a);
this.node_over=null;this.dirty_canvas=!0}if(g){if(!g.mouseOver&&(g.mouseOver=!0,this.node_over=g,this.dirty_canvas=!0,g.onMouseEnter))g.onMouseEnter(a);if(g.onMouseMove)g.onMouseMove(a,[a.canvasX-g.pos[0],a.canvasY-g.pos[1]],this);if(this.connecting_node&&(k=this._highlight_input||[0,0],!this.isOverNodeBox(g,a.canvasX,a.canvasY))){var e=this.isOverNodeInput(g,a.canvasX,a.canvasY,k);-1!=e&&g.inputs[e]?c.isValidConnection(this.connecting_output.type,g.inputs[e].type)&&(this._highlight_input=k):this._highlight_input=
null}this.canvas&&(B(a.canvasX,a.canvasY,g.pos[0]+g.size[0]-5,g.pos[1]+g.size[1]-5,5,5)?this.canvas.style.cursor="se-resize":this.canvas.style.cursor="crosshair")}else this.canvas&&(this.canvas.style.cursor="");if(this.node_capturing_input&&this.node_capturing_input!=g&&this.node_capturing_input.onMouseMove)this.node_capturing_input.onMouseMove(a);if(this.node_dragged&&!this.live_mode){for(b in this.selected_nodes)g=this.selected_nodes[b],g.pos[0]+=d[0]/this.ds.scale,g.pos[1]+=d[1]/this.ds.scale;
this.dirty_bgcanvas=this.dirty_canvas=!0}this.resizing_node&&!this.live_mode&&(this.resizing_node.size[0]=a.canvasX-this.resizing_node.pos[0],this.resizing_node.size[1]=a.canvasY-this.resizing_node.pos[1],d=Math.max(this.resizing_node.inputs?this.resizing_node.inputs.length:0,this.resizing_node.outputs?this.resizing_node.outputs.length:0)*c.NODE_SLOT_HEIGHT+(this.resizing_node.widgets?this.resizing_node.widgets.length:0)*(c.NODE_WIDGET_HEIGHT+4)+4,this.resizing_node.size[1]<d&&(this.resizing_node.size[1]=
d),this.resizing_node.size[0]<c.NODE_MIN_WIDTH&&(this.resizing_node.size[0]=c.NODE_MIN_WIDTH),this.canvas.style.cursor="se-resize",this.dirty_bgcanvas=this.dirty_canvas=!0)}a.preventDefault();return!1}};f.prototype.processMouseUp=function(a){if(this.graph){var b=this.getCanvasWindow().document;f.active_canvas=this;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=c.getTime();a.click_time=b-this.last_mouseclick;this.last_mouse_dragging=!1;if(1==a.which){this.node_widget=null;if(this.selected_group){var b=this.selected_group.pos[0]-Math.round(this.selected_group.pos[0]),d=this.selected_group.pos[1]-Math.round(this.selected_group.pos[1]);this.selected_group.move(b,d,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;d=new Float32Array(4);this.deselectAllNodes();var g=Math.abs(this.dragging_rectangle[2]),k=Math.abs(this.dragging_rectangle[3]),e=0>this.dragging_rectangle[3]?this.dragging_rectangle[1]-k:this.dragging_rectangle[1];this.dragging_rectangle[0]=0>this.dragging_rectangle[2]?this.dragging_rectangle[0]-g:this.dragging_rectangle[0];this.dragging_rectangle[1]=e;this.dragging_rectangle[2]=
g;this.dragging_rectangle[3]=k;k=[];for(e=0;e<b.length;++e)g=b[e],g.getBounding(d),A(this.dragging_rectangle,d)&&k.push(g);k.length&&this.selectNodes(k)}this.dragging_rectangle=null}else if(this.connecting_node){this.dirty_bgcanvas=this.dirty_canvas=!0;if(g=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes))this.connecting_output.type==c.EVENT&&this.isOverNodeBox(g,a.canvasX,a.canvasY)?this.connecting_node.connect(this.connecting_slot,g,c.EVENT):(b=this.isOverNodeInput(g,a.canvasX,a.canvasY),
-1!=b?this.connecting_node.connect(this.connecting_slot,g,b):(b=g.getInputInfo(0),this.connecting_output.type==c.EVENT?this.connecting_node.connect(this.connecting_slot,g,c.EVENT):b&&!b.link&&c.isValidConnection(b.type&&this.connecting_output.type)&&this.connecting_node.connect(this.connecting_slot,g,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.resizing_node=null;else if(this.node_dragged)(g=
this.node_dragged)&&300>a.click_time&&B(a.canvasX,a.canvasY,g.pos[0],g.pos[1]-c.NODE_TITLE_HEIGHT,c.NODE_TITLE_HEIGHT,c.NODE_TITLE_HEIGHT)&&g.collapse(),this.dirty_bgcanvas=this.dirty_canvas=!0,this.node_dragged.pos[0]=Math.round(this.node_dragged.pos[0]),this.node_dragged.pos[1]=Math.round(this.node_dragged.pos[1]),this.graph.config.align_to_grid&&this.node_dragged.alignToGrid(),this.node_dragged=null;else{g=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes);!g&&300>a.click_time&&this.deselectAllNodes();
this.dirty_canvas=!0;this.dragging_canvas=!1;if(this.node_over&&this.node_over.onMouseUp)this.node_over.onMouseUp(a,[a.canvasX-this.node_over.pos[0],a.canvasY-this.node_over.pos[1]],this);if(this.node_capturing_input&&this.node_capturing_input.onMouseUp)this.node_capturing_input.onMouseUp(a,[a.canvasX-this.node_capturing_input.pos[0],a.canvasY-this.node_capturing_input.pos[1]])}}else 2==a.which?(this.dirty_canvas=!0,this.dragging_canvas=!1):3==a.which&&(this.dirty_canvas=!0,this.dragging_canvas=!1);
this.graph.change();a.stopPropagation();a.preventDefault();return!1}};f.prototype.processMouseWheel=function(a){if(this.graph&&this.allow_dragcanvas){var b=null!=a.wheelDeltaY?a.wheelDeltaY:-60*a.detail;this.adjustMouseEvent(a);var d=this.ds.scale;0<b?d*=1.1:0>b&&(d*=1/1.1);this.ds.changeScale(d,[a.localX,a.localY]);this.graph.change();a.preventDefault();return!1}};f.prototype.isOverNodeBox=function(a,b,d){var g=c.NODE_TITLE_HEIGHT;return B(b,d,a.pos[0]+2,a.pos[1]+2-g,g-4,g-4)?!0:!1};f.prototype.isOverNodeInput=
function(a,b,d,c){if(a.inputs)for(var g=0,e=a.inputs.length;g<e;++g){var f=a.getConnectionPos(!0,g),p=!1;if(p=a.horizontal?B(b,d,f[0]-5,f[1]-10,10,20):B(b,d,f[0]-10,f[1]-5,40,10))return c&&(c[0]=f[0],c[1]=f[1]),g}return-1};f.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 d in this.selected_nodes)if(this.selected_nodes[d].onKeyDown)this.selected_nodes[d].onKeyDown(a)}else if("keyup"==a.type&&(32==a.keyCode&&(this.dragging_canvas=!1),this.selected_nodes))for(d in this.selected_nodes)if(this.selected_nodes[d].onKeyUp)this.selected_nodes[d].onKeyUp(a);
this.graph.change();if(b)return a.preventDefault(),a.stopImmediatePropagation(),!1}}};f.prototype.copyToClipboard=function(){var a={nodes:[],links:[]},b=0,d=[],c;for(c in this.selected_nodes){var g=this.selected_nodes[c];g._relative_id=b;d.push(g);b+=1}for(c=0;c<d.length;++c)if(g=d[c],a.nodes.push(g.clone().serialize()),g.inputs&&g.inputs.length)for(b=0;b<g.inputs.length;++b){var e=g.inputs[b];if(e&&null!=e.link&&(e=this.graph.links[e.link])){var f=this.graph.getNodeById(e.origin_id);f&&this.selected_nodes[f.id]&&
a.links.push([f._relative_id,b,g._relative_id,e.target_slot])}}localStorage.setItem("litegrapheditor_clipboard",JSON.stringify(a))};f.prototype.pasteFromClipboard=function(){var a=localStorage.getItem("litegrapheditor_clipboard");if(a){for(var a=JSON.parse(a),b=[],d=0;d<a.nodes.length;++d){var g=a.nodes[d],k=c.createNode(g.type);k&&(k.configure(g),k.pos[0]+=5,k.pos[1]+=5,this.graph.add(k),b.push(k))}for(d=0;d<a.links.length;++d)g=a.links[d],b[g[0]].connect(g[1],b[g[2]],g[3]);this.selectNodes(b)}};
f.prototype.processDrop=function(a){a.preventDefault();this.adjustMouseEvent(a);var b=[a.canvasX,a.canvasY],d=this.graph.getNodeOnPos(b[0],b[1]);if(d){if((d.onDropFile||d.onDropData)&&(b=a.dataTransfer.files)&&b.length)for(var c=0;c<b.length;c++){var g=a.dataTransfer.files[0],e=g.name;f.getFileExtension(e);if(d.onDropFile)d.onDropFile(g);if(d.onDropData){var p=new FileReader;p.onload=function(a){d.onDropData(a.target.result,e,g)};var n=g.type.split("/")[0];"text"==n||""==n?p.readAsText(g):"image"==
n?p.readAsDataURL(g):p.readAsArrayBuffer(g)}}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)};f.prototype.checkDropItem=function(a){if(a.dataTransfer.files.length){var b=a.dataTransfer.files[0],d=f.getFileExtension(b.name).toLowerCase();if(d=c.node_types_by_file_extension[d])if(d=c.createNode(d.type),d.pos=[a.canvasX,a.canvasY],this.graph.add(d),d.onDropFile)d.onDropFile(b)}};f.prototype.processNodeDblClicked=
function(a){if(this.onShowNodePanel)this.onShowNodePanel(a);if(this.onNodeDblClicked)this.onNodeDblClicked(a);this.setDirty(!0)};f.prototype.processNodeSelected=function(a,b){this.selectNode(a,b&&b.shiftKey);if(this.onNodeSelected)this.onNodeSelected(a)};f.prototype.processNodeDeselected=function(a){this.deselectNode(a);if(this.onNodeDeselected)this.onNodeDeselected(a)};f.prototype.selectNode=function(a,b){null==a?this.deselectAllNodes():this.selectNodes([a],b)};f.prototype.selectNodes=function(a,
b){b||this.deselectAllNodes();a=a||this.graph._nodes;for(var d=0;d<a.length;++d){var c=a[d];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 g=0;g<c.inputs.length;++g)this.highlighted_links[c.inputs[g].link]=!0;if(c.outputs)for(g=0;g<c.outputs.length;++g){var e=c.outputs[g];if(e.links)for(var f=0;f<e.links.length;++f)this.highlighted_links[e.links[f]]=!0}}}this.setDirty(!0)};f.prototype.deselectNode=function(a){if(a.is_selected){if(a.onDeselected)a.onDeselected();
a.is_selected=!1;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 d=a.outputs[b];if(d.links)for(var c=0;c<d.links.length;++c)delete this.highlighted_links[d.links[c]]}}};f.prototype.deselectAllNodes=function(){if(this.graph){for(var a=this.graph._nodes,b=0,d=a.length;b<d;++b){var c=a[b];if(c.is_selected){if(c.onDeselected)c.onDeselected();c.is_selected=!1}}this.selected_nodes={};this.current_node=null;this.highlighted_links=
{};this.setDirty(!0)}};f.prototype.deleteSelectedNodes=function(){for(var a in this.selected_nodes)this.graph.remove(this.selected_nodes[a]);this.selected_nodes={};this.current_node=null;this.highlighted_links={};this.setDirty(!0)};f.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)};f.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]};f.prototype.setZoom=function(a,b){this.ds.changeScale(a,b);this.dirty_bgcanvas=this.dirty_canvas=!0};f.prototype.convertOffsetToCanvas=
function(a,b){return this.ds.convertOffsetToCanvas(a,b)};f.prototype.convertCanvasToOffset=function(a,b){return this.ds.convertCanvasToOffset(a,b)};f.prototype.convertEventToCanvasOffset=function(a){var b=this.canvas.getBoundingClientRect();return this.convertCanvasToOffset([a.clientX-b.left,a.clientY-b.top])};f.prototype.bringToFront=function(a){var b=this.graph._nodes.indexOf(a);-1!=b&&(this.graph._nodes.splice(b,1),this.graph._nodes.push(a))};f.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 x=new Float32Array(4);f.prototype.computeVisibleNodes=function(a,b){var d=b||[];d.length=0;a=a||this.graph._nodes;for(var c=0,g=a.length;c<g;++c){var e=a[c];(!this.live_mode||e.onDrawBackground||e.onDrawForeground)&&A(this.visible_area,e.getBounding(x))&&d.push(e)}return d};f.prototype.draw=function(a,b){if(this.canvas){var d=c.getTime();this.render_time=0.001*(d-this.last_draw_time);this.last_draw_time=d;this.graph&&this.ds.computeVisibleArea();
(this.dirty_bgcanvas||b||this.always_render_background||this.graph&&this.graph._last_trigger_time&&1E3>d-this.graph._last_trigger_time)&&this.drawBackCanvas();(this.dirty_canvas||a)&&this.drawFrontCanvas();this.fps=this.render_time?1/this.render_time:0;this.frame+=1}};f.prototype.drawFrontCanvas=function(){this.dirty_canvas=!1;this.ctx||(this.ctx=this.bgcanvas.getContext("2d"));var a=this.ctx;if(a){a.start2D&&a.start2D();var b=this.canvas;a.restore();a.setTransform(1,0,0,1,0,0);this.dirty_area&&(a.save(),
a.beginPath(),a.rect(this.dirty_area[0],this.dirty_area[1],this.dirty_area[2],this.dirty_area[3]),a.clip());this.clear_background&&a.clearRect(0,0,b.width,b.height);this.bgcanvas==this.canvas?this.drawBackCanvas():a.drawImage(this.bgcanvas,0,0);if(this.onRender)this.onRender(b,a);this.show_info&&this.renderInfo(a);if(this.graph){a.save();this.ds.toCanvasContext(a);for(var b=this.computeVisibleNodes(null,this.visible_nodes),d=0;d<b.length;++d){var g=b[d];a.save();a.translate(g.pos[0],g.pos[1]);this.drawNode(g,
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 c.EVENT:b=c.EVENT_LINK_COLOR;break;default:b=c.CONNECTING_LINK_COLOR}this.renderLink(a,this.connecting_pos,[this.canvas_mouse[0],this.canvas_mouse[1]],null,!1,null,b,this.connecting_output.dir||(this.connecting_node.horizontal?c.DOWN:c.RIGHT),c.CENTER);
a.beginPath();this.connecting_output.type===c.EVENT||this.connecting_output.shape===c.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.onDrawForeground)this.onDrawForeground(a,this.visible_rect);a.restore()}if(this.onDrawOverlay)this.onDrawOverlay(a);this.dirty_area&&a.restore();a.finish2D&&a.finish2D()}};f.prototype.renderInfo=function(a,b,d){b=b||0;d=d||0;a.save();a.translate(b,d);a.font="10px Arial";a.fillStyle="#888";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()};f.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();this.clear_background&&b.clearRect(0,0,a.width,a.height);if(this._graph_stack&&this._graph_stack.length){b.save();
var d=this.graph._subgraph_node;b.strokeStyle=d.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=d.bgcolor||"#AAA";for(var c="",g=1;g<this._graph_stack.length;++g)c+=this._graph_stack[g]._subgraph_node.getTitle()+" >> ";b.fillText(c+d.getTitle(),0.5*a.width,40);b.restore()}d=!1;this.onRenderBackground&&(d=this.onRenderBackground(a,b));b.restore();b.setTransform(1,0,0,1,0,0);this.visible_links.length=0;if(this.graph){b.save();
this.ds.toCanvasContext(b);if(this.background_image&&0.5<this.ds.scale&&!d){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 e=this;this._bg_img.onload=function(){e.draw(!0,!0)}}d=null;null==this._pattern&&0<this._bg_img.width?
(d=b.createPattern(this._bg_img,"repeat"),this._pattern_img=this._bg_img,this._pattern=d):d=this._pattern;d&&(b.fillStyle=d,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 p=new Float32Array(2);f.prototype.drawNode=function(a,b){this.current_node=a;var d=a.color||a.constructor.color||
c.NODE_DEFAULT_COLOR,g=a.bgcolor||a.constructor.bgcolor||c.NODE_DEFAULT_BGCOLOR;if(this.live_mode){if(!a.flags.collapsed&&(b.shadowColor="transparent",a.onDrawForeground))a.onDrawForeground(b,this,this.canvas)}else{var k=this.editor_alpha;b.globalAlpha=k;this.render_shadows?(b.shadowColor=c.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 e=a._shape||c.BOX_SHAPE;p.set(a.size);var f=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*c.NODE_TITLE_HEIGHT),p[0]=a._collapsed_width,p[1]=0)}a.clip_area&&(b.save(),b.beginPath(),e==c.BOX_SHAPE?b.rect(0,0,p[0],p[1]):e==c.ROUND_SHAPE?b.roundRect(0,0,p[0],p[1],10):e==c.CIRCLE_SHAPE&&b.arc(0.5*p[0],0.5*p[1],0.5*p[0],0,2*Math.PI),b.clip());a.has_errors&&(g="red");
this.drawNodeShape(a,b,p,d,g,a.is_selected,a.mouseOver);b.shadowColor="transparent";if(a.onDrawForeground)a.onDrawForeground(b,this,this.canvas);b.textAlign=f?"center":"left";b.font=this.inner_text_font;g=0.6<this.ds.scale;e=this.connecting_output;b.lineWidth=1;var n=0,q=new Float32Array(2);if(!a.flags.collapsed){if(a.inputs)for(d=0;d<a.inputs.length;d++){var l=a.inputs[d];b.globalAlpha=k;this.connecting_node&&c.isValidConnection(l.type&&e.type)&&(b.globalAlpha=0.4*k);b.fillStyle=null!=l.link?l.color_on||
this.default_connection_color.input_on:l.color_off||this.default_connection_color.input_off;var h=a.getConnectionPos(!0,d,q);h[0]-=a.pos[0];h[1]-=a.pos[1];n<h[1]+0.5*c.NODE_SLOT_HEIGHT&&(n=h[1]+0.5*c.NODE_SLOT_HEIGHT);b.beginPath();l.type===c.EVENT||l.shape===c.BOX_SHAPE?f?b.rect(h[0]-5+0.5,h[1]-8+0.5,10,14):b.rect(h[0]-6+0.5,h[1]-5+0.5,14,10):l.shape===c.ARROW_SHAPE?(b.moveTo(h[0]+8,h[1]+0.5),b.lineTo(h[0]-4,h[1]+6+0.5),b.lineTo(h[0]-4,h[1]-6+0.5),b.closePath()):b.arc(h[0],h[1],4,0,2*Math.PI);b.fill();
if(g){var t=null!=l.label?l.label:l.name;t&&(b.fillStyle=c.NODE_TEXT_COLOR,f||l.dir==c.UP?b.fillText(t,h[0],h[1]-10):b.fillText(t,h[0]+10,h[1]+5))}}this.connecting_node&&(b.globalAlpha=0.4*k);b.textAlign=f?"center":"right";b.strokeStyle="black";if(a.outputs)for(d=0;d<a.outputs.length;d++)if(l=a.outputs[d],h=a.getConnectionPos(!1,d,q),h[0]-=a.pos[0],h[1]-=a.pos[1],n<h[1]+0.5*c.NODE_SLOT_HEIGHT&&(n=h[1]+0.5*c.NODE_SLOT_HEIGHT),b.fillStyle=l.links&&l.links.length?l.color_on||this.default_connection_color.output_on:
l.color_off||this.default_connection_color.output_off,b.beginPath(),l.type===c.EVENT||l.shape===c.BOX_SHAPE?f?b.rect(h[0]-5+0.5,h[1]-8+0.5,10,14):b.rect(h[0]-6+0.5,h[1]-5+0.5,14,10):l.shape===c.ARROW_SHAPE?(b.moveTo(h[0]+8,h[1]+0.5),b.lineTo(h[0]-4,h[1]+6+0.5),b.lineTo(h[0]-4,h[1]-6+0.5),b.closePath()):b.arc(h[0],h[1],4,0,2*Math.PI),b.fill(),b.stroke(),g&&(t=null!=l.label?l.label:l.name))b.fillStyle=c.NODE_TEXT_COLOR,f||l.dir==c.DOWN?b.fillText(t,h[0],h[1]-8):b.fillText(t,h[0]-10,h[1]+5);b.textAlign=
"left";b.globalAlpha=1;if(a.widgets){if(f||a.widgets_up)n=2;this.drawNodeWidgets(a,n,b,this.node_widget&&this.node_widget[0]==a?this.node_widget[1]:null)}}else if(this.render_collapsed_slots){k=g=null;if(a.inputs)for(d=0;d<a.inputs.length;d++)if(l=a.inputs[d],null!=l.link){g=l;break}if(a.outputs)for(d=0;d<a.outputs.length;d++)l=a.outputs[d],l.links&&l.links.length&&(k=l);g&&(d=0,g=-0.5*c.NODE_TITLE_HEIGHT,f&&(d=0.5*a._collapsed_width,g=-c.NODE_TITLE_HEIGHT),b.fillStyle="#686",b.beginPath(),l.type===
c.EVENT||l.shape===c.BOX_SHAPE?b.rect(d-7+0.5,g-4,14,8):l.shape===c.ARROW_SHAPE?(b.moveTo(d+8,g),b.lineTo(d+-4,g-4),b.lineTo(d+-4,g+4),b.closePath()):b.arc(d,g,4,0,2*Math.PI),b.fill());k&&(d=a._collapsed_width,g=-0.5*c.NODE_TITLE_HEIGHT,f&&(d=0.5*a._collapsed_width,g=0),b.fillStyle="#686",b.strokeStyle="black",b.beginPath(),l.type===c.EVENT||l.shape===c.BOX_SHAPE?b.rect(d-7+0.5,g-4,14,8):l.shape===c.ARROW_SHAPE?(b.moveTo(d+6,g),b.lineTo(d-6,g-4),b.lineTo(d-6,g+4),b.closePath()):b.arc(d,g,4,0,2*Math.PI),
b.fill())}a.clip_area&&b.restore();b.globalAlpha=1}}};var n=new Float32Array(4);f.prototype.drawNodeShape=function(a,b,d,g,k,e,p){b.strokeStyle=g;b.fillStyle=k;k=c.NODE_TITLE_HEIGHT;var q=0.5>this.ds.scale,l=a._shape||a.constructor.shape||c.ROUND_SHAPE,h=a.constructor.title_mode,m=!0;h==c.TRANSPARENT_TITLE?m=!1:h==c.AUTOHIDE_TITLE&&p&&(m=!0);n[0]=0;n[1]=m?-k:0;n[2]=d[0]+1;n[3]=m?d[1]+k:d[1];p=b.globalAlpha;b.beginPath();l==c.BOX_SHAPE||q?b.fillRect(n[0],n[1],n[2],n[3]):l==c.ROUND_SHAPE||l==c.CARD_SHAPE?
b.roundRect(n[0],n[1],n[2],n[3],this.round_radius,l==c.CARD_SHAPE?0:this.round_radius):l==c.CIRCLE_SHAPE&&b.arc(0.5*d[0],0.5*d[1],0.5*d[0],0,2*Math.PI);b.fill();b.shadowColor="transparent";b.fillStyle="rgba(0,0,0,0.2)";b.fillRect(0,-1,n[2],2);b.shadowColor="transparent";if(a.onDrawBackground)a.onDrawBackground(b,this,this.canvas);if(m||h==c.TRANSPARENT_TITLE){if(a.onDrawTitleBar)a.onDrawTitleBar(b,k,d,this.ds.scale,g);else if(h!=c.TRANSPARENT_TITLE&&(a.constructor.title_color||this.render_title_colored)){m=
a.constructor.title_color||g;a.flags.collapsed&&(b.shadowColor=c.DEFAULT_SHADOW_COLOR);if(this.use_gradients){var t=f.gradients[m];t||(t=f.gradients[m]=b.createLinearGradient(0,0,400,0),t.addColorStop(0,m),t.addColorStop(1,"#000"));b.fillStyle=t}else b.fillStyle=m;b.beginPath();l==c.BOX_SHAPE||q?b.rect(0,-k,d[0]+1,k):l!=c.ROUND_SHAPE&&l!=c.CARD_SHAPE||b.roundRect(0,-k,d[0]+1,k,this.round_radius,a.flags.collapsed?this.round_radius:0);b.fill();b.shadowColor="transparent"}if(a.onDrawTitleBox)a.onDrawTitleBox(b,
k,d,this.ds.scale);else l==c.ROUND_SHAPE||l==c.CIRCLE_SHAPE||l==c.CARD_SHAPE?(q&&(b.fillStyle="black",b.beginPath(),b.arc(0.5*k,-0.5*k,6,0,2*Math.PI),b.fill()),b.fillStyle=a.boxcolor||c.NODE_DEFAULT_BOXCOLOR,b.beginPath(),b.arc(0.5*k,-0.5*k,5,0,2*Math.PI),b.fill()):(q&&(b.fillStyle="black",b.fillRect(0.5*(k-10)-1,-0.5*(k+10)-1,12,12)),b.fillStyle=a.boxcolor||c.NODE_DEFAULT_BOXCOLOR,b.fillRect(0.5*(k-10),-0.5*(k+10),10,10));b.globalAlpha=p;if(a.onDrawTitleText)a.onDrawTitleText(b,k,d,this.ds.scale,
this.title_text_font,e);!q&&(b.font=this.title_text_font,q=a.getTitle())&&(b.fillStyle=e?"white":a.constructor.title_text_color||this.node_title_color,a.flags.collapsed?(b.textAlign="center",p=b.measureText(q),b.fillText(q,k+0.5*p.width,c.NODE_TITLE_TEXT_Y-k),b.textAlign="left"):(b.textAlign="left",b.fillText(q,k,c.NODE_TITLE_TEXT_Y-k)));if(a.onDrawTitle)a.onDrawTitle(b)}if(e){if(a.onBounding)a.onBounding(n);h==c.TRANSPARENT_TITLE&&(n[1]-=k,n[3]+=k);b.lineWidth=1;b.globalAlpha=0.8;b.beginPath();l==
c.BOX_SHAPE?b.rect(-6+n[0],-6+n[1],12+n[2],12+n[3]):l==c.ROUND_SHAPE||l==c.CARD_SHAPE&&a.flags.collapsed?b.roundRect(-6+n[0],-6+n[1],12+n[2],12+n[3],2*this.round_radius):l==c.CARD_SHAPE?b.roundRect(-6+n[0],-6+n[1],12+n[2],12+n[3],2*this.round_radius,2):l==c.CIRCLE_SHAPE&&b.arc(0.5*d[0],0.5*d[1],0.5*d[0]+6,0,2*Math.PI);b.strokeStyle="#FFF";b.stroke();b.strokeStyle=g;b.globalAlpha=1}};var l=new Float32Array(4),g=new Float32Array(4),q=new Float32Array(2),w=new Float32Array(2);f.prototype.drawConnections=
function(a){var b=c.getTime(),d=this.visible_area;l[0]=d[0]-20;l[1]=d[1]-20;l[2]=d[2]+40;l[3]=d[3]+40;a.lineWidth=this.connections_width;a.fillStyle="#AAA";a.strokeStyle="#AAA";a.globalAlpha=this.editor_alpha;for(var d=this.graph._nodes,e=0,k=d.length;e<k;++e){var f=d[e];if(f.inputs&&f.inputs.length)for(var p=0;p<f.inputs.length;++p){var n=f.inputs[p];if(n&&null!=n.link&&(n=this.graph.links[n.link])){var h=this.graph.getNodeById(n.origin_id);if(null!=h){var m=n.origin_slot,r=null,r=-1==m?[h.pos[0]+
10,h.pos[1]+10]:h.getConnectionPos(!1,m,q),t=f.getConnectionPos(!0,p,w);g[0]=r[0];g[1]=r[1];g[2]=t[0]-r[0];g[3]=t[1]-r[1];0>g[2]&&(g[0]+=g[2],g[2]=Math.abs(g[2]));0>g[3]&&(g[1]+=g[3],g[3]=Math.abs(g[3]));if(A(g,l)){var D=h.outputs[m],m=f.inputs[p];if(D&&m&&(h=D.dir||(h.horizontal?c.DOWN:c.RIGHT),m=m.dir||(f.horizontal?c.UP:c.LEFT),this.renderLink(a,r,t,n,!1,0,null,h,m),n&&n._last_time&&1E3>b-n._last_time)){var D=2-0.002*(b-n._last_time),E=a.globalAlpha;a.globalAlpha=E*D;this.renderLink(a,r,t,n,!0,
D,"white",h,m);a.globalAlpha=E}}}}}}a.globalAlpha=1};f.prototype.renderLink=function(a,b,d,g,k,e,p,n,l,q){g&&this.visible_links.push(g);!p&&g&&(p=g.color||f.link_type_colors[g.type]);p||(p=this.default_link_color);null!=g&&this.highlighted_links[g.id]&&(p="#FFF");n=n||c.RIGHT;l=l||c.LEFT;var h=y(b,d);this.render_connections_border&&0.6<this.ds.scale&&(a.lineWidth=this.connections_width+4);a.lineJoin="round";q=q||1;1<q&&(a.lineWidth=0.5);a.beginPath();for(var t=0;t<q;t+=1){var D=5*(t-0.5*(q-1));if(this.links_render_mode==
c.SPLINE_LINK){a.moveTo(b[0],b[1]+D);var E=0,m=0,r=0,w=0;switch(n){case c.LEFT:E=-0.25*h;break;case c.RIGHT:E=0.25*h;break;case c.UP:m=-0.25*h;break;case c.DOWN:m=0.25*h}switch(l){case c.LEFT:r=-0.25*h;break;case c.RIGHT:r=0.25*h;break;case c.UP:w=-0.25*h;break;case c.DOWN:w=0.25*h}a.bezierCurveTo(b[0]+E,b[1]+m+D,d[0]+r,d[1]+w+D,d[0],d[1]+D)}else if(this.links_render_mode==c.LINEAR_LINK){a.moveTo(b[0],b[1]+D);w=r=m=E=0;switch(n){case c.LEFT:E=-1;break;case c.RIGHT:E=1;break;case c.UP:m=-1;break;case c.DOWN:m=
1}switch(l){case c.LEFT:r=-1;break;case c.RIGHT:r=1;break;case c.UP:w=-1;break;case c.DOWN:w=1}a.lineTo(b[0]+15*E,b[1]+15*m+D);a.lineTo(d[0]+15*r,d[1]+15*w+D);a.lineTo(d[0],d[1]+D)}else if(this.links_render_mode==c.STRAIGHT_LINK)a.moveTo(b[0],b[1]),D=b[0],E=b[1],m=d[0],r=d[1],n==c.RIGHT?D+=10:E+=10,l==c.LEFT?m-=10:r-=10,a.lineTo(D,E),a.lineTo(0.5*(D+m),E),a.lineTo(0.5*(D+m),r),a.lineTo(m,r),a.lineTo(d[0],d[1]);else return}this.render_connections_border&&0.6<this.ds.scale&&!k&&(a.strokeStyle="rgba(0,0,0,0.5)",
a.stroke());a.lineWidth=this.connections_width;a.fillStyle=a.strokeStyle=p;a.stroke();k=this.computeConnectionPoint(b,d,0.5,n,l);g&&g._pos&&(g._pos[0]=k[0],g._pos[1]=k[1]);0.6<=this.ds.scale&&this.highquality_render&&l!=c.CENTER&&(this.render_connection_arrows&&(t=this.computeConnectionPoint(b,d,0.25,n,l),g=this.computeConnectionPoint(b,d,0.26,n,l),q=this.computeConnectionPoint(b,d,0.75,n,l),h=this.computeConnectionPoint(b,d,0.76,n,l),E=D=0,this.render_curved_connections?(D=-Math.atan2(g[0]-t[0],
g[1]-t[1]),E=-Math.atan2(h[0]-q[0],h[1]-q[1])):E=D=d[1]>b[1]?0:Math.PI,a.save(),a.translate(t[0],t[1]),a.rotate(D),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore(),a.save(),a.translate(q[0],q[1]),a.rotate(E),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore()),a.beginPath(),a.arc(k[0],k[1],5,0,2*Math.PI),a.fill());if(e)for(a.fillStyle=p,t=0;5>t;++t)e=(0.001*c.getTime()+0.2*t)%1,k=this.computeConnectionPoint(b,d,e,n,l),a.beginPath(),a.arc(k[0],
k[1],5,0,2*Math.PI),a.fill()};f.prototype.computeConnectionPoint=function(a,b,d,g,k){g=g||c.RIGHT;k=k||c.LEFT;var e=y(a,b),f=[a[0],a[1]],p=[b[0],b[1]];switch(g){case c.LEFT:f[0]+=-0.25*e;break;case c.RIGHT:f[0]+=0.25*e;break;case c.UP:f[1]+=-0.25*e;break;case c.DOWN:f[1]+=0.25*e}switch(k){case c.LEFT:p[0]+=-0.25*e;break;case c.RIGHT:p[0]+=0.25*e;break;case c.UP:p[1]+=-0.25*e;break;case c.DOWN:p[1]+=0.25*e}g=(1-d)*(1-d)*(1-d);k=3*(1-d)*(1-d)*d;e=3*(1-d)*d*d;d*=d*d;return[g*a[0]+k*f[0]+e*p[0]+d*b[0],
g*a[1]+k*f[1]+e*p[1]+d*b[1]]};f.prototype.drawExecutionOrder=function(a){a.shadowColor="transparent";a.globalAlpha=0.25;a.textAlign="center";a.strokeStyle="white";a.globalAlpha=0.75;for(var b=this.visible_nodes,d=0;d<b.length;++d){var g=b[d];a.fillStyle="black";a.fillRect(g.pos[0]-c.NODE_TITLE_HEIGHT,g.pos[1]-c.NODE_TITLE_HEIGHT,c.NODE_TITLE_HEIGHT,c.NODE_TITLE_HEIGHT);0==g.order&&a.strokeRect(g.pos[0]-c.NODE_TITLE_HEIGHT+0.5,g.pos[1]-c.NODE_TITLE_HEIGHT+0.5,c.NODE_TITLE_HEIGHT,c.NODE_TITLE_HEIGHT);
a.fillStyle="#FFF";a.fillText(g.order,g.pos[0]+-0.5*c.NODE_TITLE_HEIGHT,g.pos[1]-6)}a.globalAlpha=1};f.prototype.drawNodeWidgets=function(a,b,d,g){if(!a.widgets||!a.widgets.length)return 0;var k=a.size[0],e=a.widgets;b+=2;var f=c.NODE_WIDGET_HEIGHT,p=0.5<this.ds.scale;d.save();d.globalAlpha=this.editor_alpha;for(var n=0;n<e.length;++n){var l=e[n],q=b;l.y&&(q=l.y);l.last_y=q;d.strokeStyle="#666";d.fillStyle="#222";d.textAlign="left";switch(l.type){case "button":l.clicked&&(d.fillStyle="#AAA",l.clicked=
!1,this.dirty_canvas=!0);d.fillRect(15,q,k-30,f);d.strokeRect(15,q,k-30,f);p&&(d.textAlign="center",d.fillStyle="#AAA",d.fillText(l.name,0.5*k,q+0.7*f));break;case "toggle":d.textAlign="left";d.strokeStyle="#666";d.fillStyle="#222";d.beginPath();d.roundRect(15,b,k-30,f,0.5*f);d.fill();d.stroke();d.fillStyle=l.value?"#89A":"#333";d.beginPath();d.arc(k-30,q+0.5*f,0.36*f,0,2*Math.PI);d.fill();p&&(d.fillStyle="#999",null!=l.name&&d.fillText(l.name,30,q+0.7*f),d.fillStyle=l.value?"#DDD":"#888",d.textAlign=
"right",d.fillText(l.value?l.options.on||"true":l.options.off||"false",k-40,q+0.7*f));break;case "slider":d.fillStyle="#222";d.fillRect(15,q,k-30,f);var t=l.options.max-l.options.min,D=(l.value-l.options.min)/t;d.fillStyle=g==l?"#89A":"#678";d.fillRect(15,q,D*(k-30),f);d.strokeRect(15,q,k-30,f);l.marker&&(t=(l.marker-l.options.min)/t,d.fillStyle="#AA9",d.fillRect(15+t*(k-30),q,2,f));p&&(d.textAlign="center",d.fillStyle="#DDD",d.fillText(l.name+" "+Number(l.value).toFixed(3),0.5*k,q+0.7*f));break;
case "number":case "combo":d.textAlign="left";d.strokeStyle="#666";d.fillStyle="#222";d.beginPath();d.roundRect(15,b,k-30,f,0.5*f);d.fill();d.stroke();p&&(d.fillStyle="#AAA",d.beginPath(),d.moveTo(31,b+5),d.lineTo(21,b+0.5*f),d.lineTo(31,b+f-5),d.moveTo(k-15-16,b+5),d.lineTo(k-15-6,b+0.5*f),d.lineTo(k-15-16,b+f-5),d.fill(),d.fillStyle="#999",d.fillText(l.name,35,q+0.7*f),d.fillStyle="#DDD",d.textAlign="right","number"==l.type?d.fillText(Number(l.value).toFixed(void 0!==l.options.precision?l.options.precision:
3),k-30-20,q+0.7*f):d.fillText(l.value,k-30-20,q+0.7*f));break;case "string":case "text":d.textAlign="left";d.strokeStyle="#666";d.fillStyle="#222";d.beginPath();d.roundRect(15,b,k-30,f,0.5*f);d.fill();d.stroke();p&&(d.fillStyle="#999",null!=l.name&&d.fillText(l.name,30,q+0.7*f),d.fillStyle="#DDD",d.textAlign="right",d.fillText(l.value,k-30,q+0.7*f));break;default:l.draw&&l.draw(d,a,l,q,f)}b+=f+4}d.restore()};f.prototype.processNodeWidgets=function(a,b,d,g){function k(t,c){t.value=c;t.property&&void 0!==
a.properties[t.property]&&(a.properties[t.property]=c);t.callback&&t.callback(t.value,l,a,b,d)}if(!a.widgets||!a.widgets.length)return null;for(var e=b[0]-a.pos[0],f=b[1]-a.pos[1],p=a.size[0],l=this,n=this.getCanvasWindow(),q=0;q<a.widgets.length;++q){var t=a.widgets[q];if(t==g||6<e&&e<p-12&&f>t.last_y&&f<t.last_y+c.NODE_WIDGET_HEIGHT){switch(t.type){case "button":if("mousemove"===d.type)break;t.callback&&setTimeout(function(){t.callback(t,l,a,b)},20);this.dirty_canvas=t.clicked=!0;break;case "slider":n=
Math.clamp((e-10)/(p-20),0,1);t.value=t.options.min+(t.options.max-t.options.min)*n;t.callback&&setTimeout(function(){k(t,t.value)},20);this.dirty_canvas=!0;break;case "number":case "combo":if("mousemove"==d.type&&"number"==t.type)t.value+=0.1*d.deltaX*(t.options.step||1),null!=t.options.min&&t.value<t.options.min&&(t.value=t.options.min),null!=t.options.max&&t.value>t.options.max&&(t.value=t.options.max);else if("mousedown"==d.type)if((g=t.options.values)&&g.constructor===Function&&(g=t.options.values(t,
a)),e=40>e?-1:e>p-40?1:0,"number"==t.type)t.value+=0.1*e*(t.options.step||1),null!=t.options.min&&t.value<t.options.min&&(t.value=t.options.min),null!=t.options.max&&t.value>t.options.max&&(t.value=t.options.max);else if(e)n=g.indexOf(t.value)+e,n>=g.length&&(n=0),0>n&&(n=g.length-1),t.value=g[n];else{new c.ContextMenu(g,{scale:Math.max(1,this.ds.scale),event:d,className:"dark",callback:D.bind(t)},n);var D=function(a,b,d){this.value=a;k(this,a);l.dirty_canvas=!0;return!1}}setTimeout(function(){k(this,
this.value)}.bind(t),20);this.dirty_canvas=!0;break;case "toggle":"mousedown"==d.type&&(t.value=!t.value,t.callback&&setTimeout(function(){k(t,t.value)},20));break;case "string":case "text":"mousedown"==d.type&&this.prompt("Value",t.value,function(a){this.value=a;k(this,a)}.bind(t),d);break;default:t.mouse&&t.mouse(ctx,d,[e,f],a)}return t}}return null};f.prototype.drawGroups=function(a,b){if(this.graph){var d=this.graph._groups;b.save();b.globalAlpha=0.5*this.editor_alpha;for(var g=0;g<d.length;++g){var k=
d[g];if(A(this.visible_area,k._bounding)){b.fillStyle=k.color||"#335";b.strokeStyle=k.color||"#335";var e=k._pos,f=k._size;b.globalAlpha=0.25*this.editor_alpha;b.beginPath();b.rect(e[0]+0.5,e[1]+0.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=k.font_size||c.DEFAULT_GROUP_FONT_SIZE;b.font=f+"px Arial";b.fillText(k.title,e[0]+4,e[1]+f)}}b.restore()}};f.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)};f.prototype.resize=function(a,b){if(!a&&!b){var d=this.canvas.parentNode;a=d.offsetWidth;b=d.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)};f.prototype.switchLiveMode=function(a){if(a){var b=this,d=this.live_mode?1.1:0.9;this.live_mode&&(this.live_mode=
!1,this.editor_alpha=0.1);var c=setInterval(function(){b.editor_alpha*=d;b.dirty_canvas=!0;b.dirty_bgcanvas=!0;1>d&&0.01>b.editor_alpha&&(clearInterval(c),1>d&&(b.live_mode=!0));1<d&&0.99<b.editor_alpha&&(clearInterval(c),b.editor_alpha=1)},1)}else this.live_mode=!this.live_mode,this.dirty_bgcanvas=this.dirty_canvas=!0};f.prototype.onNodeSelectionChange=function(a){};f.prototype.touchHandler=function(a){var b=a.changedTouches[0],d="";switch(a.type){case "touchstart":d="mousedown";break;case "touchmove":d=
"mousemove";break;case "touchend":d="mouseup";break;default:return}var c=this.getCanvasWindow(),g=c.document.createEvent("MouseEvent");g.initMouseEvent(d,!0,!0,c,1,b.screenX,b.screenY,b.clientX,b.clientY,!1,!1,!1,!1,0,null);b.target.dispatchEvent(g);a.preventDefault()};f.onGroupAdd=function(a,b,d){a=f.active_canvas;a.getCanvasWindow();b=new c.LGraphGroup;b.pos=a.convertEventToCanvasOffset(d);a.graph.add(b)};f.onMenuAdd=function(a,b,d,g){function k(a,b){var d=g.getFirstEvent(),k=c.createNode(a.value);
k&&(k.pos=e.convertEventToCanvasOffset(d),e.graph.add(k))}var e=f.active_canvas,p=e.getCanvasWindow();a=c.getNodeTypesCategories();b=[];for(var l in a)a[l]&&b.push({value:a[l],content:a[l],has_submenu:!0});var n=new c.ContextMenu(b,{event:d,callback:function(a,b,d){a=c.getNodeTypesInCategory(a.value,e.filter);b=[];for(var g in a)a[g].skip_list||b.push({content:a[g].title,value:a[g].type});new c.ContextMenu(b,{event:d,callback:k,parentMenu:n},p);return!1},parentMenu:g},p);return!1};f.onMenuCollapseAll=
function(){};f.onMenuNodeEdit=function(){};f.showMenuNodeOptionalInputs=function(a,b,d,g,k){function e(a,b,d){k&&(a.callback&&a.callback.call(p,k,a,b,d),a.value&&(k.addInput(a.value[0],a.value[1],a.value[2]),k.setDirtyCanvas(!0,!0)))}if(k){var p=this;a=f.active_canvas.getCanvasWindow();b=k.optional_inputs;k.onGetInputs&&(b=k.onGetInputs());var l=[];if(b)for(var n in b){var q=b[n];if(q){var h=q[0];q[2]&&q[2].label&&(h=q[2].label);h={content:h,value:q};q[1]==c.ACTION&&(h.className="event");l.push(h)}else l.push(null)}this.onMenuNodeInputs&&
(l=this.onMenuNodeInputs(l));if(l.length)return new c.ContextMenu(l,{event:d,callback:e,parentMenu:g,node:k},a),!1}};f.showMenuNodeOptionalOutputs=function(a,b,d,g,k){function e(a,b,d){if(k&&(a.callback&&a.callback.call(p,k,a,b,d),a.value))if(d=a.value[1],!d||d.constructor!==Object&&d.constructor!==Array)k.addOutput(a.value[0],a.value[1],a.value[2]),k.setDirtyCanvas(!0,!0);else{a=[];for(var f in d)a.push({content:f,value:d[f]});new c.ContextMenu(a,{event:b,callback:e,parentMenu:g,node:k});return!1}}
if(k){var p=this;a=f.active_canvas.getCanvasWindow();b=k.optional_outputs;k.onGetOutputs&&(b=k.onGetOutputs());var l=[];if(b)for(var n in b){var q=b[n];if(!q)l.push(null);else if(!k.flags||!k.flags.skip_repeated_outputs||-1==k.findOutputSlot(q[0])){var h=q[0];q[2]&&q[2].label&&(h=q[2].label);h={content:h,value:q};q[1]==c.EVENT&&(h.className="event");l.push(h)}}this.onMenuNodeOutputs&&(l=this.onMenuNodeOutputs(l));if(l.length)return new c.ContextMenu(l,{event:d,callback:e,parentMenu:g,node:k},a),!1}};
f.onShowMenuNodeProperties=function(a,b,d,g,k){function e(a,b,d,c){k&&(b=this.getBoundingClientRect(),p.showEditPropertyValue(k,a.value,{position:[b.left,b.top]}))}if(k&&k.properties){var p=f.active_canvas;b=p.getCanvasWindow();var l=[],q;for(q in k.properties)a=void 0!==k.properties[q]?k.properties[q]:" ",a=f.decodeHTML(a),l.push({content:"<span class='property_name'>"+q+"</span><span class='property_value'>"+a+"</span>",value:q});if(l.length)return new c.ContextMenu(l,{event:d,callback:e,parentMenu:g,
allow_html:!0,node:k},b),!1}};f.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};f.onResizeNode=function(a,b,d,c,g){g&&(g.size=g.computeSize(),g.setDirtyCanvas(!0,!0))};f.prototype.showLinkMenu=function(a,b){var d=this;new c.ContextMenu(["Delete"],{event:b,callback:function(b){switch(b){case "Delete":d.graph.removeLink(a.id)}}});return!1};f.onShowPropertyEditor=function(a,b,d,c,g){function e(){var b=q.value;"Number"==a.type?b=Number(b):"Boolean"==a.type&&
(b=Boolean(b));g[p]=b;l.parentNode&&l.parentNode.removeChild(l);g.setDirtyCanvas(!0,!0)}var p=a.property||"title";b=g[p];var l=document.createElement("div");l.className="graphdialog";l.innerHTML="<span class='name'></span><input autofocus type='text' class='value'/><button>OK</button>";l.querySelector(".name").innerText=p;var q=l.querySelector("input");q&&(q.value=b,q.addEventListener("blur",function(a){this.focus()}),q.addEventListener("keydown",function(a){13==a.keyCode&&(e(),a.preventDefault(),
a.stopPropagation())}));b=f.active_canvas.canvas;d=b.getBoundingClientRect();var n=c=-20;d&&(c-=d.left,n-=d.top);event?(l.style.left=event.clientX+c+"px",l.style.top=event.clientY+n+"px"):(l.style.left=0.5*b.width+c+"px",l.style.top=0.5*b.height+n+"px");l.querySelector("button").addEventListener("click",e);b.parentNode.appendChild(l)};f.prototype.prompt=function(a,b,d,c){var g=this;a=a||"";var e=!1,l=document.createElement("div");l.className="graphdialog rounded";l.innerHTML="<span class='name'></span> <input autofocus type='text' class='value'/><button class='rounded'>OK</button>";
l.close=function(){g.prompt_box=null;l.parentNode&&l.parentNode.removeChild(l)};1<this.ds.scale&&(l.style.transform="scale("+this.ds.scale+")");l.addEventListener("mouseleave",function(a){e||l.close()});g.prompt_box&&g.prompt_box.close();g.prompt_box=l;l.querySelector(".name").innerText=a;l.querySelector(".value").value=b;var p=l.querySelector("input");p.addEventListener("keydown",function(a){e=!0;if(27==a.keyCode)l.close();else if(13==a.keyCode)d&&d(this.value),l.close();else return;a.preventDefault();
a.stopPropagation()});l.querySelector("button").addEventListener("click",function(a){d&&d(p.value);g.setDirty(!0);l.close()});a=f.active_canvas.canvas;b=a.getBoundingClientRect();var q=-20,n=-20;b&&(q-=b.left,n-=b.top);c?(l.style.left=c.clientX+q+"px",l.style.top=c.clientY+n+"px"):(l.style.left=0.5*a.width+q+"px",l.style.top=0.5*a.height+n+"px");a.parentNode.appendChild(l);setTimeout(function(){p.focus()},10);return l};f.search_limit=-1;f.prototype.showSearchBox=function(a){function b(b){if(b)if(e.onSearchBoxSelection)e.onSearchBoxSelection(b,
a,D);else{var d=c.searchbox_extras[b];d&&(b=d.type);if(b=c.createNode(b))b.pos=D.convertEventToCanvasOffset(a),D.graph.add(b);if(d&&d.data){if(d.data.properties)for(var t in d.data.properties)b.addProperty(d.data.properties[t][0],d.data.properties[t][0]);if(d.data.inputs)for(t in b.inputs=[],d.data.inputs)b.addOutput(d.data.inputs[t][0],d.data.inputs[t][1]);if(d.data.outputs)for(t in b.outputs=[],d.data.outputs)b.addOutput(d.data.outputs[t][0],d.data.outputs[t][1]);d.data.title&&(b.title=d.data.title);
d.data.json&&b.configure(d.data.json)}}l.close()}function d(a){var b=m;m&&m.classList.remove("selected");m?(m=a?m.nextSibling:m.previousSibling)||(m=b):m=a?q.childNodes[0]:q.childNodes[q.childNodes.length];m&&(m.classList.add("selected"),m.scrollIntoView())}function g(){function a(d,t){var c=document.createElement("div");n||(n=d);c.innerText=d;c.dataset.type=escape(d);c.className="litegraph lite-search-item";t&&(c.className+=" "+t);c.addEventListener("click",function(a){b(unescape(this.dataset.type))});
q.appendChild(c)}h=null;var d=t.value;n=null;q.innerHTML="";if(d)if(e.onSearchBox){var l=e.onSearchBox(q,d,D);if(l)for(var p=0;p<l.length;++p)a(l[p])}else{l=0;d=d.toLowerCase();for(p in c.searchbox_extras){var m=c.searchbox_extras[p];if(-1!==m.desc.toLowerCase().indexOf(d)&&(a(m.desc,"searchbox_extra"),-1!==f.search_limit&&l++>f.search_limit))break}if(Array.prototype.filter)for(m=Object.keys(c.registered_node_types).filter(function(a){return-1!==a.toLowerCase().indexOf(d)}),p=0;p<m.length&&!(a(m[p]),
-1!==f.search_limit&&l++>f.search_limit);p++);else for(p in c.registered_node_types)if(-1!=p.indexOf(d)&&(a(p),-1!==f.search_limit&&l++>f.search_limit))break}}var e=this,l=document.createElement("div");l.className="litegraph litesearchbox graphdialog rounded";l.innerHTML="<span class='name'>Search</span> <input autofocus type='text' class='value rounded'/><div class='helper'></div>";l.close=function(){e.search_box=null;document.body.focus();setTimeout(function(){e.canvas.focus()},20);l.parentNode&&
l.parentNode.removeChild(l)};var p=null;1<this.ds.scale&&(l.style.transform="scale("+this.ds.scale+")");l.addEventListener("mouseenter",function(a){p&&(clearTimeout(p),p=null)});l.addEventListener("mouseleave",function(a){p=setTimeout(function(){l.close()},500)});e.search_box&&e.search_box.close();e.search_box=l;var q=l.querySelector(".helper"),n=null,h=null,m=null,t=l.querySelector("input");t&&(t.addEventListener("blur",function(a){this.focus()}),t.addEventListener("keydown",function(a){if(38==a.keyCode)d(!1);
else if(40==a.keyCode)d(!0);else if(27==a.keyCode)l.close();else if(13==a.keyCode)m?b(m.innerHTML):n?b(n):l.close();else{h&&clearInterval(h);h=setTimeout(g,10);return}a.preventDefault();a.stopPropagation()}));var D=f.active_canvas,E=D.canvas,r=E.getBoundingClientRect(),w=-20,x=-20;r&&(w-=r.left,x-=r.top);a?(l.style.left=a.clientX+w+"px",l.style.top=a.clientY+x+"px"):(l.style.left=0.5*E.width+w+"px",l.style.top=0.5*E.height+x+"px");E.parentNode.appendChild(l);t.focus();return l};f.prototype.showEditPropertyValue=
function(a,b,d){function c(){g(t.value)}function g(d){"number"==typeof a.properties[b]&&(d=Number(d));"array"==e&&(d=d.split(",").map(Number));a.properties[b]=d;a._graph&&a._graph._version++;if(a.onPropertyChanged)a.onPropertyChanged(b,d);n.close();a.setDirtyCanvas(!0,!0)}if(a&&void 0!==a.properties[b]){d=d||{};var e="string";null!==a.properties[b]&&(e=typeof a.properties[b]);"object"==e&&a.properties[b].length&&(e="array");var l=null;a.getPropertyInfo&&(l=a.getPropertyInfo(b));if(a.properties_info)for(var f=
0;f<a.properties_info.length;++f)if(a.properties_info[f].name==b){l=a.properties_info[f];break}void 0!==l&&null!==l&&l.type&&(e=l.type);var p="";if("string"==e||"number"==e||"array"==e)p="<input autofocus type='text' class='value'/>";else if("enum"==e&&l.values){p="<select autofocus type='text' class='value'>";for(f in l.values)var q=l.values.constructor===Array?l.values[f]:f,p=p+("<option value='"+q+"' "+(q==a.properties[b]?"selected":"")+">"+l.values[f]+"</option>");p+="</select>"}else if("boolean"==
e)p="<input autofocus type='checkbox' class='value' "+(a.properties[b]?"checked":"")+"/>";else{console.warn("unknown type: "+e);return}var n=this.createDialog("<span class='name'>"+b+"</span>"+p+"<button>OK</button>",d);if("enum"==e&&l.values){var t=n.querySelector("select");t.addEventListener("change",function(a){g(a.target.value)})}else if("boolean"==e)(t=n.querySelector("input"))&&t.addEventListener("click",function(a){g(!!t.checked)});else if(t=n.querySelector("input"))t.addEventListener("blur",
function(a){this.focus()}),t.value=void 0!==a.properties[b]?a.properties[b]:"",t.addEventListener("keydown",function(a){13==a.keyCode&&(c(),a.preventDefault(),a.stopPropagation())});n.querySelector("button").addEventListener("click",c)}};f.prototype.createDialog=function(a,b){b=b||{};var d=document.createElement("div");d.className="graphdialog";d.innerHTML=a;var c=this.canvas.getBoundingClientRect(),g=-20,e=-20;c&&(g-=c.left,e-=c.top);b.position?(g+=b.position[0],e+=b.position[1]):b.event?(g+=b.event.clientX,
e+=b.event.clientY):(g+=0.5*this.canvas.width,e+=0.5*this.canvas.height);d.style.left=g+"px";d.style.top=e+"px";this.canvas.parentNode.appendChild(d);d.close=function(){this.parentNode&&this.parentNode.removeChild(this)};return d};f.onMenuNodeCollapse=function(a,b,d,c,g){g.collapse()};f.onMenuNodePin=function(a,b,d,c,g){g.pin()};f.onMenuNodeMode=function(a,b,d,g,e){new c.ContextMenu(["Always","On Event","On Trigger","Never"],{event:d,callback:function(a){if(e)switch(a){case "On Event":e.mode=c.ON_EVENT;
break;case "On Trigger":e.mode=c.ON_TRIGGER;break;case "Never":e.mode=c.NEVER;break;default:e.mode=c.ALWAYS}},parentMenu:g,node:e});return!1};f.onMenuNodeColors=function(a,b,d,g,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 l in f.node_colors)a=f.node_colors[l],a={value:l,content:"<span style='display: block; color: #999; padding-left: 4px; border-left: 8px solid "+a.color+"; background-color:"+a.bgcolor+
"'>"+l+"</span>"},b.push(a);new c.ContextMenu(b,{event:d,callback:function(a){e&&((a=a.value?f.node_colors[a.value]:null)?e.constructor===c.LGraphGroup?e.color=a.groupcolor:(e.color=a.color,e.bgcolor=a.bgcolor):(delete e.color,delete e.bgcolor),e.setDirtyCanvas(!0,!0))},parentMenu:g,node:e});return!1};f.onMenuNodeShapes=function(a,b,d,g,e){if(!e)throw"no node passed";new c.ContextMenu(c.VALID_SHAPES,{event:d,callback:function(a){e&&(e.shape=a,e.setDirtyCanvas(!0))},parentMenu:g,node:e});return!1};
f.onMenuNodeRemove=function(a,b,d,c,g){if(!g)throw"no node passed";!1!==g.removable&&(g.graph.remove(g),g.setDirtyCanvas(!0,!0))};f.onMenuNodeClone=function(a,b,d,c,g){!1!=g.clonable&&(a=g.clone())&&(a.pos=[g.pos[0]+5,g.pos[1]+5],g.graph.add(a),g.setDirtyCanvas(!0,!0))};f.node_colors={red:{color:"#322",bgcolor:"#533",groupcolor:"#A88"},brown:{color:"#332922",bgcolor:"#593930",groupcolor:"#b06634"},green:{color:"#232",bgcolor:"#353",groupcolor:"#8A8"},blue:{color:"#223",bgcolor:"#335",groupcolor:"#88A"},
pale_blue:{color:"#2a363b",bgcolor:"#3f5159",groupcolor:"#3f789e"},cyan:{color:"#233",bgcolor:"#355",groupcolor:"#8AA"},purple:{color:"#323",bgcolor:"#535",groupcolor:"#a1309b"},yellow:{color:"#432",bgcolor:"#653",groupcolor:"#b58b2a"},black:{color:"#222",bgcolor:"#000",groupcolor:"#444"}};f.prototype.getCanvasMenuOptions=function(){var a=null;this.getMenuOptions?a=this.getMenuOptions():(a=[{content:"Add Node",has_submenu:!0,callback:f.onMenuAdd},{content:"Add Group",callback:f.onGroupAdd}],this._graph_stack&&
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};f.prototype.getNodeMenuOptions=function(a){var b=null,b=a.getMenuOptions?a.getMenuOptions(this):[{content:"Inputs",has_submenu:!0,disabled:!0,callback:f.showMenuNodeOptionalInputs},{content:"Outputs",has_submenu:!0,disabled:!0,callback:f.showMenuNodeOptionalOutputs},null,{content:"Properties",has_submenu:!0,
callback:f.onShowMenuNodeProperties},null,{content:"Title",callback:f.onShowPropertyEditor},{content:"Mode",has_submenu:!0,callback:f.onMenuNodeMode},{content:"Resize",callback:f.onResizeNode},{content:"Collapse",callback:f.onMenuNodeCollapse},{content:"Pin",callback:f.onMenuNodePin},{content:"Colors",has_submenu:!0,callback:f.onMenuNodeColors},{content:"Shapes",has_submenu:!0,callback:f.onMenuNodeShapes},null];if(a.onGetInputs){var d=a.onGetInputs();d&&d.length&&(b[0].disabled=!1)}a.onGetOutputs&&
(d=a.onGetOutputs())&&d.length&&(b[1].disabled=!1);a.getExtraMenuOptions&&(d=a.getExtraMenuOptions(this))&&(d.push(null),b=d.concat(b));!1!==a.clonable&&b.push({content:"Clone",callback:f.onMenuNodeClone});!1!==a.removable&&b.push(null,{content:"Remove",callback:f.onMenuNodeRemove});if(a.graph&&a.graph.onGetNodeMenuOptions)a.graph.onGetNodeMenuOptions(b,a);return b};f.prototype.getGroupMenuOptions=function(a){return[{content:"Title",callback:f.onShowPropertyEditor},{content:"Color",has_submenu:!0,
callback:f.onMenuNodeColors},{content:"Font size",property:"font_size",type:"Number",callback:f.onShowPropertyEditor},null,{content:"Remove",callback:f.onMenuNodeRemove}]};f.prototype.processContextMenu=function(a,b){var d=this,g=f.active_canvas.getCanvasWindow(),e=null,l={event:b,callback:function(b,c,g){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 t=b.input?a.getInputInfo(b.slot):a.getOutputInfo(b.slot),e=d.createDialog("<span class='name'>Name</span><input autofocus type='text'/><button>OK</button>",c),l=e.querySelector("input");l&&t&&(l.value=t.label||"");e.querySelector("button").addEventListener("click",function(a){l.value&&(t&&(t.label=l.value),d.setDirty(!0));e.close()})}},extra:a},p=null;a&&(p=a.getSlotInPosition(b.canvasX,b.canvasY),f.active_node=a);if(p){e=[];
p&&p.output&&p.output.links&&p.output.links.length&&e.push({content:"Disconnect Links",slot:p});var q=p.input||p.output;e.push(q.locked?"Cannot remove":{content:"Remove Slot",slot:p});e.push(q.nameLocked?"Cannot rename":{content:"Rename Slot",slot:p});l.title=(p.input?p.input.type:p.output.type)||"*";p.input&&p.input.type==c.ACTION&&(l.title="Action");p.output&&p.output.type==c.EVENT&&(l.title="Event")}else a?e=this.getNodeMenuOptions(a):(e=this.getCanvasMenuOptions(),(p=this.graph.getGroupOnPos(b.canvasX,
b.canvasY))&&e.push(null,{content:"Edit Group",has_submenu:!0,submenu:{title:"Group",extra:p,options:this.getGroupMenuOptions(p)}}));e&&new c.ContextMenu(e,l,g)};this.CanvasRenderingContext2D&&(CanvasRenderingContext2D.prototype.roundRect=function(a,b,d,c,g,e){void 0===g&&(g=5);void 0===e&&(e=g);this.moveTo(a+g,b);this.lineTo(a+d-g,b);this.quadraticCurveTo(a+d,b,a+d,b+g);this.lineTo(a+d,b+c-e);this.quadraticCurveTo(a+d,b+c,a+d-e,b+c);this.lineTo(a+e,b+c);this.quadraticCurveTo(a,b+c,a,b+c-e);this.lineTo(a,
b+g);this.quadraticCurveTo(a,b,a+g,b)});c.compareObjects=function(a,b){for(var d in a)if(a[d]!=b[d])return!1;return!0};c.distance=y;c.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")+")"};c.isInsideRectangle=B;c.growBounding=function(a,b,d){b<a[0]?a[0]=b:b>a[2]&&(a[2]=b);d<a[1]?a[1]=d:d>a[3]&&(a[3]=d)};c.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};c.overlapBounding=A;c.hex2num=function(a){"#"==a.charAt(0)&&(a=a.slice(1));a=a.toUpperCase();for(var b=Array(3),d=0,c,g,e=0;6>e;e+=2)c="0123456789ABCDEF".indexOf(a.charAt(e)),g="0123456789ABCDEF".indexOf(a.charAt(e+1)),b[d]=16*c+g,d++;return b};c.num2hex=function(a){for(var b="#",d,c,g=0;3>g;g++)d=a[g]/16,c=a[g]%16,b+="0123456789ABCDEF".charAt(d)+"0123456789ABCDEF".charAt(c);return b};z.prototype.addItem=function(a,b,d){function c(a){var b=this.value;b&&b.has_submenu&&
g.call(this,a)}function g(a){var b=this.value,c=!0;e.current_submenu&&e.current_submenu.close(a);if(d.callback){var t=d.callback.call(this,b,d,a,e,d.node);!0===t&&(c=!1)}if(b&&(b.callback&&!d.ignore_item_callbacks&&!0!==b.disabled&&(t=b.callback.call(this,b,d,a,e,d.extra),!0===t&&(c=!1)),b.submenu)){if(!b.submenu.options)throw"ContextMenu submenu needs options";new e.constructor(b.submenu.options,{callback:b.submenu.callback,event:a,parentMenu:e,ignore_item_callbacks:b.submenu.ignore_item_callbacks,
title:b.submenu.title,extra:b.submenu.extra,autoopen:d.autoopen});c=!1}c&&!e.lock&&e.close()}var e=this;d=d||{};var l=document.createElement("div");l.className="litemenu-entry submenu";var f=!1;if(null===b)l.classList.add("separator");else{l.innerHTML=b&&b.title?b.title:a;if(l.value=b)b.disabled&&(f=!0,l.classList.add("disabled")),(b.submenu||b.has_submenu)&&l.classList.add("has_submenu");"function"==typeof b?(l.dataset.value=a,l.onclick_callback=b):l.dataset.value=b;b.className&&(l.className+=" "+
b.className)}this.root.appendChild(l);f||l.addEventListener("click",g);d.autoopen&&l.addEventListener("mouseenter",c);return l};z.prototype.close=function(a,b){this.root.parentNode&&this.root.parentNode.removeChild(this.root);this.parentMenu&&!b&&(this.parentMenu.lock=!1,this.parentMenu.current_submenu=null,void 0===a?this.parentMenu.close():a&&!z.isCursorOverElement(a,this.parentMenu.root)&&z.trigger(this.parentMenu.root,"mouseleave",a));this.current_submenu&&this.current_submenu.close(a,!0);this.root.closing_timer&&
clearTimeout(this.root.closing_timer)};z.trigger=function(a,b,d,c){var g=document.createEvent("CustomEvent");g.initCustomEvent(b,!0,!0,d);g.srcElement=c;a.dispatchEvent?a.dispatchEvent(g):a.__events&&a.__events.dispatchEvent(g);return g};z.prototype.getTopMenu=function(){return this.options.parentMenu?this.options.parentMenu.getTopMenu():this};z.prototype.getFirstEvent=function(){return this.options.parentMenu?this.options.parentMenu.getFirstEvent():this.options.event};z.isCursorOverElement=function(a,
b){var d=a.clientX,c=a.clientY,g=b.getBoundingClientRect();return g?c>g.top&&c<g.top+g.height&&d>g.left&&d<g.left+g.width?!0:!1:!1};c.ContextMenu=z;c.closeAllContextMenus=function(a){a=a||window;a=a.document.querySelectorAll(".litecontextmenu");if(a.length){for(var b=[],d=0;d<a.length;d++)b.push(a[d]);for(d in b)b[d].close?b[d].close():b[d].parentNode&&b[d].parentNode.removeChild(b[d])}};c.extendClass=function(a,b){for(var d in b)a.hasOwnProperty(d)||(a[d]=b[d]);if(b.prototype)for(d in b.prototype)b.prototype.hasOwnProperty(d)&&
!a.prototype.hasOwnProperty(d)&&(b.prototype.__lookupGetter__(d)?a.prototype.__defineGetter__(d,b.prototype.__lookupGetter__(d)):a.prototype[d]=b.prototype[d],b.prototype.__lookupSetter__(d)&&a.prototype.__defineSetter__(d,b.prototype.__lookupSetter__(d)))};c.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,d){return b>
a?b:d<a?d: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);
c.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,g=!0);var e=!1;if(d&&this.allow_interaction&&!g&&!this.read_only){this.live_mode||d.flags.pinned||this.bringToFront(d);if(!this.connecting_node&&!d.flags.collapsed&&!this.live_mode)if(!g&&!1!==d.resizable&&B(a.canvasX,a.canvasY,d.pos[0]+
d.size[0]-5,d.pos[1]+d.size[1]-5,10,10))this.resizing_node=d,this.canvas.style.cursor="se-resize",g=!0;else{if(d.outputs)for(var p=0,n=d.outputs.length;p<n;++p){var q=d.outputs[p],l=d.getConnectionPos(!1,p);if(B(a.canvasX,a.canvasY,l[0]-15,l[1]-10,30,20)){this.connecting_node=d;this.connecting_output=q;this.connecting_pos=d.getConnectionPos(!1,p);this.connecting_slot=p;a.shiftKey&&d.disconnectOutput(p);if(k){if(d.onOutputDblClick)d.onOutputDblClick(p,a)}else if(d.onOutputClick)d.onOutputClick(p,a);
g=!0;break}}if(d.inputs)for(p=0,n=d.inputs.length;p<n;++p)if(q=d.inputs[p],l=d.getConnectionPos(!0,p),B(a.canvasX,a.canvasY,l[0]-15,l[1]-10,30,20)){if(k){if(d.onInputDblClick)d.onInputDblClick(p,a)}else if(d.onInputClick)d.onInputClick(p,a);if(null!==q.link){g=this.graph.links[q.link];d.disconnectInput(p);if(this.allow_reconnect_links||a.shiftKey)this.connecting_node=this.graph._nodes_by_id[g.origin_id],this.connecting_slot=g.origin_slot,this.connecting_output=this.connecting_node.outputs[this.connecting_slot],
this.connecting_pos=this.connecting_node.getConnectionPos(!1,this.connecting_slot);g=this.dirty_bgcanvas=!0}}}if(!g){p=!1;if(n=this.processNodeWidgets(d,this.canvas_mouse,a))p=!0,this.node_widget=[d,n];if(k&&this.selected_nodes[d.id]){if(d.onDblClick)d.onDblClick(a,[a.canvasX-d.pos[0],a.canvasY-d.pos[1]],this);this.processNodeDblClicked(d);p=!0}d.onMouseDown&&d.onMouseDown(a,[a.canvasX-d.pos[0],a.canvasY-d.pos[1]],this)?p=!0:this.live_mode&&(p=e=!0);p||(this.allow_dragnodes&&(this.node_dragged=d),
this.selected_nodes[d.id]||this.processNodeSelected(d,a));this.dirty_canvas=!0}}else{if(!this.read_only)for(p=0;p<this.visible_links.length;++p)if(d=this.visible_links[p],(e=d._pos)&&!(a.canvasX<e[0]-4||a.canvasX>e[0]+4||a.canvasY<e[1]-4||a.canvasY>e[1]+4)){this.showLinkMenu(d,a);break}this.selected_group=this.graph.getGroupOnPos(a.canvasX,a.canvasY);this.selected_group_resizing=!1;this.selected_group&&!this.read_only&&(a.ctrlKey&&(this.dragging_rectangle=null),10>y([a.canvasX,a.canvasY],[this.selected_group.pos[0]+
this.selected_group.size[0],this.selected_group.pos[1]+this.selected_group.size[1]])*this.ds.scale?this.selected_group_resizing=!0:this.selected_group.recomputeInsideNodes());k&&!this.read_only&&this.showSearchBox(a);e=!0}!g&&e&&this.allow_dragcanvas&&(this.dragging_canvas=!0)}else 2!=a.which&&3==a.which&&(this.read_only||this.processContextMenu(d,a));this.last_mouse[0]=a.localX;this.last_mouse[1]=a.localY;this.last_mouseclick=c.getTime();this.last_mouse_dragging=!0;this.graph.change();(!b.document.activeElement||
"input"!=b.document.activeElement.nodeName.toLowerCase()&&"textarea"!=b.document.activeElement.nodeName.toLowerCase())&&a.preventDefault();a.stopPropagation();if(this.onMouseDown)this.onMouseDown(a);return!1}}};f.prototype.processMouseMove=function(a){this.autoresize&&this.resize();if(this.graph){f.active_canvas=this;this.adjustMouseEvent(a);var b=[a.localX,a.localY],d=[b[0]-this.last_mouse[0],b[1]-this.last_mouse[1]];this.last_mouse=b;this.canvas_mouse[0]=a.canvasX;this.canvas_mouse[1]=a.canvasY;
a.dragging=this.last_mouse_dragging;this.node_widget&&(this.processNodeWidgets(this.node_widget[0],this.canvas_mouse,a,this.node_widget[1]),this.dirty_canvas=!0);if(this.dragging_rectangle)this.dragging_rectangle[2]=a.canvasX-this.dragging_rectangle[0],this.dragging_rectangle[3]=a.canvasY-this.dragging_rectangle[1],this.dirty_canvas=!0;else if(this.selected_group&&!this.read_only)this.selected_group_resizing?this.selected_group.size=[a.canvasX-this.selected_group.pos[0],a.canvasY-this.selected_group.pos[1]]:
(this.selected_group.move(d[0]/this.ds.scale,d[1]/this.ds.scale,a.ctrlKey),this.selected_group._nodes.length&&(this.dirty_canvas=!0)),this.dirty_bgcanvas=!0;else if(this.dragging_canvas)this.ds.offset[0]+=d[0]/this.ds.scale,this.ds.offset[1]+=d[1]/this.ds.scale,this.dirty_bgcanvas=this.dirty_canvas=!0;else if(this.allow_interaction&&!this.read_only){this.connecting_node&&(this.dirty_canvas=!0);for(var g=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes),b=0,k=this.graph._nodes.length;b<
k;++b)if(this.graph._nodes[b].mouseOver&&g!=this.graph._nodes[b]){this.graph._nodes[b].mouseOver=!1;if(this.node_over&&this.node_over.onMouseLeave)this.node_over.onMouseLeave(a);this.node_over=null;this.dirty_canvas=!0}if(g){if(!g.mouseOver&&(g.mouseOver=!0,this.node_over=g,this.dirty_canvas=!0,g.onMouseEnter))g.onMouseEnter(a);if(g.onMouseMove)g.onMouseMove(a,[a.canvasX-g.pos[0],a.canvasY-g.pos[1]],this);if(this.connecting_node&&(k=this._highlight_input||[0,0],!this.isOverNodeBox(g,a.canvasX,a.canvasY))){var e=
this.isOverNodeInput(g,a.canvasX,a.canvasY,k);-1!=e&&g.inputs[e]?c.isValidConnection(this.connecting_output.type,g.inputs[e].type)&&(this._highlight_input=k):this._highlight_input=null}this.canvas&&(B(a.canvasX,a.canvasY,g.pos[0]+g.size[0]-5,g.pos[1]+g.size[1]-5,5,5)?this.canvas.style.cursor="se-resize":this.canvas.style.cursor="crosshair")}else this.canvas&&(this.canvas.style.cursor="");if(this.node_capturing_input&&this.node_capturing_input!=g&&this.node_capturing_input.onMouseMove)this.node_capturing_input.onMouseMove(a);
if(this.node_dragged&&!this.live_mode){for(b in this.selected_nodes)g=this.selected_nodes[b],g.pos[0]+=d[0]/this.ds.scale,g.pos[1]+=d[1]/this.ds.scale;this.dirty_bgcanvas=this.dirty_canvas=!0}this.resizing_node&&!this.live_mode&&(this.resizing_node.size[0]=a.canvasX-this.resizing_node.pos[0],this.resizing_node.size[1]=a.canvasY-this.resizing_node.pos[1],d=Math.max(this.resizing_node.inputs?this.resizing_node.inputs.length:0,this.resizing_node.outputs?this.resizing_node.outputs.length:0)*c.NODE_SLOT_HEIGHT+
(this.resizing_node.widgets?this.resizing_node.widgets.length:0)*(c.NODE_WIDGET_HEIGHT+4)+4,this.resizing_node.size[1]<d&&(this.resizing_node.size[1]=d),this.resizing_node.size[0]<c.NODE_MIN_WIDTH&&(this.resizing_node.size[0]=c.NODE_MIN_WIDTH),this.canvas.style.cursor="se-resize",this.dirty_bgcanvas=this.dirty_canvas=!0)}a.preventDefault();return!1}};f.prototype.processMouseUp=function(a){if(this.graph){var b=this.getCanvasWindow().document;f.active_canvas=this;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=c.getTime();a.click_time=b-this.last_mouseclick;this.last_mouse_dragging=!1;if(1==a.which){this.node_widget=null;if(this.selected_group){var b=this.selected_group.pos[0]-Math.round(this.selected_group.pos[0]),d=this.selected_group.pos[1]-Math.round(this.selected_group.pos[1]);this.selected_group.move(b,d,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;d=new Float32Array(4);this.deselectAllNodes();var g=Math.abs(this.dragging_rectangle[2]),k=Math.abs(this.dragging_rectangle[3]),e=0>this.dragging_rectangle[3]?this.dragging_rectangle[1]-k:this.dragging_rectangle[1];this.dragging_rectangle[0]=
0>this.dragging_rectangle[2]?this.dragging_rectangle[0]-g:this.dragging_rectangle[0];this.dragging_rectangle[1]=e;this.dragging_rectangle[2]=g;this.dragging_rectangle[3]=k;k=[];for(e=0;e<b.length;++e)g=b[e],g.getBounding(d),A(this.dragging_rectangle,d)&&k.push(g);k.length&&this.selectNodes(k)}this.dragging_rectangle=null}else if(this.connecting_node){this.dirty_bgcanvas=this.dirty_canvas=!0;if(g=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes))this.connecting_output.type==c.EVENT&&
this.isOverNodeBox(g,a.canvasX,a.canvasY)?this.connecting_node.connect(this.connecting_slot,g,c.EVENT):(b=this.isOverNodeInput(g,a.canvasX,a.canvasY),-1!=b?this.connecting_node.connect(this.connecting_slot,g,b):(b=g.getInputInfo(0),this.connecting_output.type==c.EVENT?this.connecting_node.connect(this.connecting_slot,g,c.EVENT):b&&!b.link&&c.isValidConnection(b.type&&this.connecting_output.type)&&this.connecting_node.connect(this.connecting_slot,g,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.resizing_node=null;else if(this.node_dragged)(g=this.node_dragged)&&300>a.click_time&&B(a.canvasX,a.canvasY,g.pos[0],g.pos[1]-c.NODE_TITLE_HEIGHT,c.NODE_TITLE_HEIGHT,c.NODE_TITLE_HEIGHT)&&g.collapse(),this.dirty_bgcanvas=this.dirty_canvas=!0,this.node_dragged.pos[0]=Math.round(this.node_dragged.pos[0]),this.node_dragged.pos[1]=Math.round(this.node_dragged.pos[1]),this.graph.config.align_to_grid&&
this.node_dragged.alignToGrid(),this.node_dragged=null;else{g=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes);!g&&300>a.click_time&&this.deselectAllNodes();this.dirty_canvas=!0;this.dragging_canvas=!1;if(this.node_over&&this.node_over.onMouseUp)this.node_over.onMouseUp(a,[a.canvasX-this.node_over.pos[0],a.canvasY-this.node_over.pos[1]],this);if(this.node_capturing_input&&this.node_capturing_input.onMouseUp)this.node_capturing_input.onMouseUp(a,[a.canvasX-this.node_capturing_input.pos[0],
a.canvasY-this.node_capturing_input.pos[1]])}}else 2==a.which?(this.dirty_canvas=!0,this.dragging_canvas=!1):3==a.which&&(this.dirty_canvas=!0,this.dragging_canvas=!1);this.graph.change();a.stopPropagation();a.preventDefault();return!1}};f.prototype.processMouseWheel=function(a){if(this.graph&&this.allow_dragcanvas){var b=null!=a.wheelDeltaY?a.wheelDeltaY:-60*a.detail;this.adjustMouseEvent(a);var d=this.ds.scale;0<b?d*=1.1:0>b&&(d*=1/1.1);this.ds.changeScale(d,[a.localX,a.localY]);this.graph.change();
a.preventDefault();return!1}};f.prototype.isOverNodeBox=function(a,b,d){var g=c.NODE_TITLE_HEIGHT;return B(b,d,a.pos[0]+2,a.pos[1]+2-g,g-4,g-4)?!0:!1};f.prototype.isOverNodeInput=function(a,b,d,c){if(a.inputs)for(var g=0,e=a.inputs.length;g<e;++g){var f=a.getConnectionPos(!0,g),p=!1;if(p=a.horizontal?B(b,d,f[0]-5,f[1]-10,10,20):B(b,d,f[0]-10,f[1]-5,40,10))return c&&(c[0]=f[0],c[1]=f[1]),g}return-1};f.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 d in this.selected_nodes)if(this.selected_nodes[d].onKeyDown)this.selected_nodes[d].onKeyDown(a)}else if("keyup"==
a.type&&(32==a.keyCode&&(this.dragging_canvas=!1),this.selected_nodes))for(d in this.selected_nodes)if(this.selected_nodes[d].onKeyUp)this.selected_nodes[d].onKeyUp(a);this.graph.change();if(b)return a.preventDefault(),a.stopImmediatePropagation(),!1}}};f.prototype.copyToClipboard=function(){var a={nodes:[],links:[]},b=0,d=[],c;for(c in this.selected_nodes){var g=this.selected_nodes[c];g._relative_id=b;d.push(g);b+=1}for(c=0;c<d.length;++c)if(g=d[c],a.nodes.push(g.clone().serialize()),g.inputs&&g.inputs.length)for(b=
0;b<g.inputs.length;++b){var e=g.inputs[b];if(e&&null!=e.link&&(e=this.graph.links[e.link])){var f=this.graph.getNodeById(e.origin_id);f&&this.selected_nodes[f.id]&&a.links.push([f._relative_id,b,g._relative_id,e.target_slot])}}localStorage.setItem("litegrapheditor_clipboard",JSON.stringify(a))};f.prototype.pasteFromClipboard=function(){var a=localStorage.getItem("litegrapheditor_clipboard");if(a){for(var a=JSON.parse(a),b=[],d=0;d<a.nodes.length;++d){var g=a.nodes[d],k=c.createNode(g.type);k&&(k.configure(g),
k.pos[0]+=5,k.pos[1]+=5,this.graph.add(k),b.push(k))}for(d=0;d<a.links.length;++d)g=a.links[d],b[g[0]].connect(g[1],b[g[2]],g[3]);this.selectNodes(b)}};f.prototype.processDrop=function(a){a.preventDefault();this.adjustMouseEvent(a);var b=[a.canvasX,a.canvasY],d=this.graph.getNodeOnPos(b[0],b[1]);if(d){if((d.onDropFile||d.onDropData)&&(b=a.dataTransfer.files)&&b.length)for(var c=0;c<b.length;c++){var g=a.dataTransfer.files[0],e=g.name;f.getFileExtension(e);if(d.onDropFile)d.onDropFile(g);if(d.onDropData){var p=
new FileReader;p.onload=function(a){d.onDropData(a.target.result,e,g)};var n=g.type.split("/")[0];"text"==n||""==n?p.readAsText(g):"image"==n?p.readAsDataURL(g):p.readAsArrayBuffer(g)}}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)};f.prototype.checkDropItem=function(a){if(a.dataTransfer.files.length){var b=a.dataTransfer.files[0],d=f.getFileExtension(b.name).toLowerCase();if(d=c.node_types_by_file_extension[d])if(d=
c.createNode(d.type),d.pos=[a.canvasX,a.canvasY],this.graph.add(d),d.onDropFile)d.onDropFile(b)}};f.prototype.processNodeDblClicked=function(a){if(this.onShowNodePanel)this.onShowNodePanel(a);if(this.onNodeDblClicked)this.onNodeDblClicked(a);this.setDirty(!0)};f.prototype.processNodeSelected=function(a,b){this.selectNode(a,b&&b.shiftKey);if(this.onNodeSelected)this.onNodeSelected(a)};f.prototype.processNodeDeselected=function(a){this.deselectNode(a);if(this.onNodeDeselected)this.onNodeDeselected(a)};
f.prototype.selectNode=function(a,b){null==a?this.deselectAllNodes():this.selectNodes([a],b)};f.prototype.selectNodes=function(a,b){b||this.deselectAllNodes();a=a||this.graph._nodes;for(var d=0;d<a.length;++d){var c=a[d];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 g=0;g<c.inputs.length;++g)this.highlighted_links[c.inputs[g].link]=!0;if(c.outputs)for(g=0;g<c.outputs.length;++g){var e=c.outputs[g];if(e.links)for(var f=
0;f<e.links.length;++f)this.highlighted_links[e.links[f]]=!0}}}this.setDirty(!0)};f.prototype.deselectNode=function(a){if(a.is_selected){if(a.onDeselected)a.onDeselected();a.is_selected=!1;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 d=a.outputs[b];if(d.links)for(var c=0;c<d.links.length;++c)delete this.highlighted_links[d.links[c]]}}};f.prototype.deselectAllNodes=function(){if(this.graph){for(var a=
this.graph._nodes,b=0,d=a.length;b<d;++b){var c=a[b];if(c.is_selected){if(c.onDeselected)c.onDeselected();c.is_selected=!1}}this.selected_nodes={};this.current_node=null;this.highlighted_links={};this.setDirty(!0)}};f.prototype.deleteSelectedNodes=function(){for(var a in this.selected_nodes)this.graph.remove(this.selected_nodes[a]);this.selected_nodes={};this.current_node=null;this.highlighted_links={};this.setDirty(!0)};f.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)};f.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]};f.prototype.setZoom=function(a,b){this.ds.changeScale(a,b);this.dirty_bgcanvas=this.dirty_canvas=!0};f.prototype.convertOffsetToCanvas=function(a,b){return this.ds.convertOffsetToCanvas(a,b)};f.prototype.convertCanvasToOffset=function(a,b){return this.ds.convertCanvasToOffset(a,b)};f.prototype.convertEventToCanvasOffset=function(a){var b=this.canvas.getBoundingClientRect();return this.convertCanvasToOffset([a.clientX-
b.left,a.clientY-b.top])};f.prototype.bringToFront=function(a){var b=this.graph._nodes.indexOf(a);-1!=b&&(this.graph._nodes.splice(b,1),this.graph._nodes.push(a))};f.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 x=new Float32Array(4);f.prototype.computeVisibleNodes=function(a,b){var d=b||[];d.length=0;a=a||this.graph._nodes;for(var c=0,g=a.length;c<g;++c){var e=a[c];(!this.live_mode||e.onDrawBackground||
e.onDrawForeground)&&A(this.visible_area,e.getBounding(x))&&d.push(e)}return d};f.prototype.draw=function(a,b){if(this.canvas){var d=c.getTime();this.render_time=0.001*(d-this.last_draw_time);this.last_draw_time=d;this.graph&&this.ds.computeVisibleArea();(this.dirty_bgcanvas||b||this.always_render_background||this.graph&&this.graph._last_trigger_time&&1E3>d-this.graph._last_trigger_time)&&this.drawBackCanvas();(this.dirty_canvas||a)&&this.drawFrontCanvas();this.fps=this.render_time?1/this.render_time:
0;this.frame+=1}};f.prototype.drawFrontCanvas=function(){this.dirty_canvas=!1;this.ctx||(this.ctx=this.bgcanvas.getContext("2d"));var a=this.ctx;if(a){a.start2D&&a.start2D();var b=this.canvas;a.restore();a.setTransform(1,0,0,1,0,0);this.dirty_area&&(a.save(),a.beginPath(),a.rect(this.dirty_area[0],this.dirty_area[1],this.dirty_area[2],this.dirty_area[3]),a.clip());this.clear_background&&a.clearRect(0,0,b.width,b.height);this.bgcanvas==this.canvas?this.drawBackCanvas():a.drawImage(this.bgcanvas,0,
0);if(this.onRender)this.onRender(b,a);this.show_info&&this.renderInfo(a);if(this.graph){a.save();this.ds.toCanvasContext(a);for(var b=this.computeVisibleNodes(null,this.visible_nodes),d=0;d<b.length;++d){var g=b[d];a.save();a.translate(g.pos[0],g.pos[1]);this.drawNode(g,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 c.EVENT:b=
c.EVENT_LINK_COLOR;break;default:b=c.CONNECTING_LINK_COLOR}this.renderLink(a,this.connecting_pos,[this.canvas_mouse[0],this.canvas_mouse[1]],null,!1,null,b,this.connecting_output.dir||(this.connecting_node.horizontal?c.DOWN:c.RIGHT),c.CENTER);a.beginPath();this.connecting_output.type===c.EVENT||this.connecting_output.shape===c.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.onDrawForeground)this.onDrawForeground(a,this.visible_rect);a.restore()}if(this.onDrawOverlay)this.onDrawOverlay(a);this.dirty_area&&a.restore();a.finish2D&&a.finish2D()}};f.prototype.renderInfo=function(a,
b,d){b=b||0;d=d||0;a.save();a.translate(b,d);a.font="10px Arial";a.fillStyle="#888";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()};f.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();this.clear_background&&b.clearRect(0,0,a.width,a.height);if(this._graph_stack&&this._graph_stack.length){b.save();var d=this.graph._subgraph_node;b.strokeStyle=d.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=d.bgcolor||"#AAA";for(var c="",g=1;g<
this._graph_stack.length;++g)c+=this._graph_stack[g]._subgraph_node.getTitle()+" >> ";b.fillText(c+d.getTitle(),0.5*a.width,40);b.restore()}d=!1;this.onRenderBackground&&(d=this.onRenderBackground(a,b));b.restore();b.setTransform(1,0,0,1,0,0);this.visible_links.length=0;if(this.graph){b.save();this.ds.toCanvasContext(b);if(this.background_image&&0.5<this.ds.scale&&!d){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 e=this;this._bg_img.onload=function(){e.draw(!0,!0)}}d=null;null==this._pattern&&0<this._bg_img.width?(d=b.createPattern(this._bg_img,"repeat"),this._pattern_img=this._bg_img,this._pattern=d):d=this._pattern;d&&(b.fillStyle=d,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 p=new Float32Array(2);f.prototype.drawNode=function(a,b){this.current_node=a;var d=a.color||a.constructor.color||c.NODE_DEFAULT_COLOR,g=a.bgcolor||a.constructor.bgcolor||c.NODE_DEFAULT_BGCOLOR;if(this.live_mode){if(!a.flags.collapsed&&(b.shadowColor=
"transparent",a.onDrawForeground))a.onDrawForeground(b,this,this.canvas)}else{var k=this.editor_alpha;b.globalAlpha=k;this.render_shadows?(b.shadowColor=c.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 e=a._shape||c.BOX_SHAPE;p.set(a.size);var f=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*c.NODE_TITLE_HEIGHT),p[0]=a._collapsed_width,p[1]=0)}a.clip_area&&(b.save(),b.beginPath(),e==c.BOX_SHAPE?b.rect(0,0,p[0],p[1]):e==c.ROUND_SHAPE?b.roundRect(0,0,p[0],p[1],10):e==c.CIRCLE_SHAPE&&b.arc(0.5*p[0],0.5*p[1],0.5*p[0],0,2*Math.PI),b.clip());a.has_errors&&(g="red");this.drawNodeShape(a,b,p,d,g,a.is_selected,a.mouseOver);b.shadowColor="transparent";if(a.onDrawForeground)a.onDrawForeground(b,this,this.canvas);b.textAlign=
f?"center":"left";b.font=this.inner_text_font;g=0.6<this.ds.scale;e=this.connecting_output;b.lineWidth=1;var n=0,q=new Float32Array(2);if(!a.flags.collapsed){if(a.inputs)for(d=0;d<a.inputs.length;d++){var l=a.inputs[d];b.globalAlpha=k;this.connecting_node&&c.isValidConnection(l.type&&e.type)&&(b.globalAlpha=0.4*k);b.fillStyle=null!=l.link?l.color_on||this.default_connection_color.input_on:l.color_off||this.default_connection_color.input_off;var h=a.getConnectionPos(!0,d,q);h[0]-=a.pos[0];h[1]-=a.pos[1];
n<h[1]+0.5*c.NODE_SLOT_HEIGHT&&(n=h[1]+0.5*c.NODE_SLOT_HEIGHT);b.beginPath();l.type===c.EVENT||l.shape===c.BOX_SHAPE?f?b.rect(h[0]-5+0.5,h[1]-8+0.5,10,14):b.rect(h[0]-6+0.5,h[1]-5+0.5,14,10):l.shape===c.ARROW_SHAPE?(b.moveTo(h[0]+8,h[1]+0.5),b.lineTo(h[0]-4,h[1]+6+0.5),b.lineTo(h[0]-4,h[1]-6+0.5),b.closePath()):b.arc(h[0],h[1],4,0,2*Math.PI);b.fill();if(g){var t=null!=l.label?l.label:l.name;t&&(b.fillStyle=c.NODE_TEXT_COLOR,f||l.dir==c.UP?b.fillText(t,h[0],h[1]-10):b.fillText(t,h[0]+10,h[1]+5))}}this.connecting_node&&
(b.globalAlpha=0.4*k);b.textAlign=f?"center":"right";b.strokeStyle="black";if(a.outputs)for(d=0;d<a.outputs.length;d++)if(l=a.outputs[d],h=a.getConnectionPos(!1,d,q),h[0]-=a.pos[0],h[1]-=a.pos[1],n<h[1]+0.5*c.NODE_SLOT_HEIGHT&&(n=h[1]+0.5*c.NODE_SLOT_HEIGHT),b.fillStyle=l.links&&l.links.length?l.color_on||this.default_connection_color.output_on:l.color_off||this.default_connection_color.output_off,b.beginPath(),l.type===c.EVENT||l.shape===c.BOX_SHAPE?f?b.rect(h[0]-5+0.5,h[1]-8+0.5,10,14):b.rect(h[0]-
6+0.5,h[1]-5+0.5,14,10):l.shape===c.ARROW_SHAPE?(b.moveTo(h[0]+8,h[1]+0.5),b.lineTo(h[0]-4,h[1]+6+0.5),b.lineTo(h[0]-4,h[1]-6+0.5),b.closePath()):b.arc(h[0],h[1],4,0,2*Math.PI),b.fill(),b.stroke(),g&&(t=null!=l.label?l.label:l.name))b.fillStyle=c.NODE_TEXT_COLOR,f||l.dir==c.DOWN?b.fillText(t,h[0],h[1]-8):b.fillText(t,h[0]-10,h[1]+5);b.textAlign="left";b.globalAlpha=1;if(a.widgets){if(f||a.widgets_up)n=2;this.drawNodeWidgets(a,n,b,this.node_widget&&this.node_widget[0]==a?this.node_widget[1]:null)}}else if(this.render_collapsed_slots){k=
g=null;if(a.inputs)for(d=0;d<a.inputs.length;d++)if(l=a.inputs[d],null!=l.link){g=l;break}if(a.outputs)for(d=0;d<a.outputs.length;d++)l=a.outputs[d],l.links&&l.links.length&&(k=l);g&&(d=0,g=-0.5*c.NODE_TITLE_HEIGHT,f&&(d=0.5*a._collapsed_width,g=-c.NODE_TITLE_HEIGHT),b.fillStyle="#686",b.beginPath(),l.type===c.EVENT||l.shape===c.BOX_SHAPE?b.rect(d-7+0.5,g-4,14,8):l.shape===c.ARROW_SHAPE?(b.moveTo(d+8,g),b.lineTo(d+-4,g-4),b.lineTo(d+-4,g+4),b.closePath()):b.arc(d,g,4,0,2*Math.PI),b.fill());k&&(d=
a._collapsed_width,g=-0.5*c.NODE_TITLE_HEIGHT,f&&(d=0.5*a._collapsed_width,g=0),b.fillStyle="#686",b.strokeStyle="black",b.beginPath(),l.type===c.EVENT||l.shape===c.BOX_SHAPE?b.rect(d-7+0.5,g-4,14,8):l.shape===c.ARROW_SHAPE?(b.moveTo(d+6,g),b.lineTo(d-6,g-4),b.lineTo(d-6,g+4),b.closePath()):b.arc(d,g,4,0,2*Math.PI),b.fill())}a.clip_area&&b.restore();b.globalAlpha=1}}};var n=new Float32Array(4);f.prototype.drawNodeShape=function(a,b,d,g,k,e,p){b.strokeStyle=g;b.fillStyle=k;k=c.NODE_TITLE_HEIGHT;var q=
0.5>this.ds.scale,l=a._shape||a.constructor.shape||c.ROUND_SHAPE,h=a.constructor.title_mode,m=!0;h==c.TRANSPARENT_TITLE?m=!1:h==c.AUTOHIDE_TITLE&&p&&(m=!0);n[0]=0;n[1]=m?-k:0;n[2]=d[0]+1;n[3]=m?d[1]+k:d[1];p=b.globalAlpha;b.beginPath();l==c.BOX_SHAPE||q?b.fillRect(n[0],n[1],n[2],n[3]):l==c.ROUND_SHAPE||l==c.CARD_SHAPE?b.roundRect(n[0],n[1],n[2],n[3],this.round_radius,l==c.CARD_SHAPE?0:this.round_radius):l==c.CIRCLE_SHAPE&&b.arc(0.5*d[0],0.5*d[1],0.5*d[0],0,2*Math.PI);b.fill();b.shadowColor="transparent";
b.fillStyle="rgba(0,0,0,0.2)";b.fillRect(0,-1,n[2],2);b.shadowColor="transparent";if(a.onDrawBackground)a.onDrawBackground(b,this,this.canvas);if(m||h==c.TRANSPARENT_TITLE){if(a.onDrawTitleBar)a.onDrawTitleBar(b,k,d,this.ds.scale,g);else if(h!=c.TRANSPARENT_TITLE&&(a.constructor.title_color||this.render_title_colored)){m=a.constructor.title_color||g;a.flags.collapsed&&(b.shadowColor=c.DEFAULT_SHADOW_COLOR);if(this.use_gradients){var t=f.gradients[m];t||(t=f.gradients[m]=b.createLinearGradient(0,0,
400,0),t.addColorStop(0,m),t.addColorStop(1,"#000"));b.fillStyle=t}else b.fillStyle=m;b.beginPath();l==c.BOX_SHAPE||q?b.rect(0,-k,d[0]+1,k):l!=c.ROUND_SHAPE&&l!=c.CARD_SHAPE||b.roundRect(0,-k,d[0]+1,k,this.round_radius,a.flags.collapsed?this.round_radius:0);b.fill();b.shadowColor="transparent"}if(a.onDrawTitleBox)a.onDrawTitleBox(b,k,d,this.ds.scale);else l==c.ROUND_SHAPE||l==c.CIRCLE_SHAPE||l==c.CARD_SHAPE?(q&&(b.fillStyle="black",b.beginPath(),b.arc(0.5*k,-0.5*k,6,0,2*Math.PI),b.fill()),b.fillStyle=
a.boxcolor||c.NODE_DEFAULT_BOXCOLOR,b.beginPath(),b.arc(0.5*k,-0.5*k,5,0,2*Math.PI),b.fill()):(q&&(b.fillStyle="black",b.fillRect(0.5*(k-10)-1,-0.5*(k+10)-1,12,12)),b.fillStyle=a.boxcolor||c.NODE_DEFAULT_BOXCOLOR,b.fillRect(0.5*(k-10),-0.5*(k+10),10,10));b.globalAlpha=p;if(a.onDrawTitleText)a.onDrawTitleText(b,k,d,this.ds.scale,this.title_text_font,e);!q&&(b.font=this.title_text_font,q=a.getTitle())&&(b.fillStyle=e?"white":a.constructor.title_text_color||this.node_title_color,a.flags.collapsed?(b.textAlign=
"center",p=b.measureText(q),b.fillText(q,k+0.5*p.width,c.NODE_TITLE_TEXT_Y-k),b.textAlign="left"):(b.textAlign="left",b.fillText(q,k,c.NODE_TITLE_TEXT_Y-k)));if(a.onDrawTitle)a.onDrawTitle(b)}if(e){if(a.onBounding)a.onBounding(n);h==c.TRANSPARENT_TITLE&&(n[1]-=k,n[3]+=k);b.lineWidth=1;b.globalAlpha=0.8;b.beginPath();l==c.BOX_SHAPE?b.rect(-6+n[0],-6+n[1],12+n[2],12+n[3]):l==c.ROUND_SHAPE||l==c.CARD_SHAPE&&a.flags.collapsed?b.roundRect(-6+n[0],-6+n[1],12+n[2],12+n[3],2*this.round_radius):l==c.CARD_SHAPE?
b.roundRect(-6+n[0],-6+n[1],12+n[2],12+n[3],2*this.round_radius,2):l==c.CIRCLE_SHAPE&&b.arc(0.5*d[0],0.5*d[1],0.5*d[0]+6,0,2*Math.PI);b.strokeStyle="#FFF";b.stroke();b.strokeStyle=g;b.globalAlpha=1}};var l=new Float32Array(4),g=new Float32Array(4),q=new Float32Array(2),w=new Float32Array(2);f.prototype.drawConnections=function(a){var b=c.getTime(),d=this.visible_area;l[0]=d[0]-20;l[1]=d[1]-20;l[2]=d[2]+40;l[3]=d[3]+40;a.lineWidth=this.connections_width;a.fillStyle="#AAA";a.strokeStyle="#AAA";a.globalAlpha=
this.editor_alpha;for(var d=this.graph._nodes,e=0,k=d.length;e<k;++e){var f=d[e];if(f.inputs&&f.inputs.length)for(var p=0;p<f.inputs.length;++p){var n=f.inputs[p];if(n&&null!=n.link&&(n=this.graph.links[n.link])){var h=this.graph.getNodeById(n.origin_id);if(null!=h){var m=n.origin_slot,r=null,r=-1==m?[h.pos[0]+10,h.pos[1]+10]:h.getConnectionPos(!1,m,q),t=f.getConnectionPos(!0,p,w);g[0]=r[0];g[1]=r[1];g[2]=t[0]-r[0];g[3]=t[1]-r[1];0>g[2]&&(g[0]+=g[2],g[2]=Math.abs(g[2]));0>g[3]&&(g[1]+=g[3],g[3]=Math.abs(g[3]));
if(A(g,l)){var D=h.outputs[m],m=f.inputs[p];if(D&&m&&(h=D.dir||(h.horizontal?c.DOWN:c.RIGHT),m=m.dir||(f.horizontal?c.UP:c.LEFT),this.renderLink(a,r,t,n,!1,0,null,h,m),n&&n._last_time&&1E3>b-n._last_time)){var D=2-0.002*(b-n._last_time),E=a.globalAlpha;a.globalAlpha=E*D;this.renderLink(a,r,t,n,!0,D,"white",h,m);a.globalAlpha=E}}}}}}a.globalAlpha=1};f.prototype.renderLink=function(a,b,d,g,k,e,p,n,l,q){g&&this.visible_links.push(g);!p&&g&&(p=g.color||f.link_type_colors[g.type]);p||(p=this.default_link_color);
null!=g&&this.highlighted_links[g.id]&&(p="#FFF");n=n||c.RIGHT;l=l||c.LEFT;var h=y(b,d);this.render_connections_border&&0.6<this.ds.scale&&(a.lineWidth=this.connections_width+4);a.lineJoin="round";q=q||1;1<q&&(a.lineWidth=0.5);a.beginPath();for(var t=0;t<q;t+=1){var D=5*(t-0.5*(q-1));if(this.links_render_mode==c.SPLINE_LINK){a.moveTo(b[0],b[1]+D);var E=0,m=0,r=0,w=0;switch(n){case c.LEFT:E=-0.25*h;break;case c.RIGHT:E=0.25*h;break;case c.UP:m=-0.25*h;break;case c.DOWN:m=0.25*h}switch(l){case c.LEFT:r=
-0.25*h;break;case c.RIGHT:r=0.25*h;break;case c.UP:w=-0.25*h;break;case c.DOWN:w=0.25*h}a.bezierCurveTo(b[0]+E,b[1]+m+D,d[0]+r,d[1]+w+D,d[0],d[1]+D)}else if(this.links_render_mode==c.LINEAR_LINK){a.moveTo(b[0],b[1]+D);w=r=m=E=0;switch(n){case c.LEFT:E=-1;break;case c.RIGHT:E=1;break;case c.UP:m=-1;break;case c.DOWN:m=1}switch(l){case c.LEFT:r=-1;break;case c.RIGHT:r=1;break;case c.UP:w=-1;break;case c.DOWN:w=1}a.lineTo(b[0]+15*E,b[1]+15*m+D);a.lineTo(d[0]+15*r,d[1]+15*w+D);a.lineTo(d[0],d[1]+D)}else if(this.links_render_mode==
c.STRAIGHT_LINK)a.moveTo(b[0],b[1]),D=b[0],E=b[1],m=d[0],r=d[1],n==c.RIGHT?D+=10:E+=10,l==c.LEFT?m-=10:r-=10,a.lineTo(D,E),a.lineTo(0.5*(D+m),E),a.lineTo(0.5*(D+m),r),a.lineTo(m,r),a.lineTo(d[0],d[1]);else return}this.render_connections_border&&0.6<this.ds.scale&&!k&&(a.strokeStyle="rgba(0,0,0,0.5)",a.stroke());a.lineWidth=this.connections_width;a.fillStyle=a.strokeStyle=p;a.stroke();k=this.computeConnectionPoint(b,d,0.5,n,l);g&&g._pos&&(g._pos[0]=k[0],g._pos[1]=k[1]);0.6<=this.ds.scale&&this.highquality_render&&
l!=c.CENTER&&(this.render_connection_arrows&&(t=this.computeConnectionPoint(b,d,0.25,n,l),g=this.computeConnectionPoint(b,d,0.26,n,l),q=this.computeConnectionPoint(b,d,0.75,n,l),h=this.computeConnectionPoint(b,d,0.76,n,l),E=D=0,this.render_curved_connections?(D=-Math.atan2(g[0]-t[0],g[1]-t[1]),E=-Math.atan2(h[0]-q[0],h[1]-q[1])):E=D=d[1]>b[1]?0:Math.PI,a.save(),a.translate(t[0],t[1]),a.rotate(D),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore(),a.save(),a.translate(q[0],
q[1]),a.rotate(E),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore()),a.beginPath(),a.arc(k[0],k[1],5,0,2*Math.PI),a.fill());if(e)for(a.fillStyle=p,t=0;5>t;++t)e=(0.001*c.getTime()+0.2*t)%1,k=this.computeConnectionPoint(b,d,e,n,l),a.beginPath(),a.arc(k[0],k[1],5,0,2*Math.PI),a.fill()};f.prototype.computeConnectionPoint=function(a,b,d,g,k){g=g||c.RIGHT;k=k||c.LEFT;var e=y(a,b),f=[a[0],a[1]],p=[b[0],b[1]];switch(g){case c.LEFT:f[0]+=-0.25*e;break;case c.RIGHT:f[0]+=0.25*
e;break;case c.UP:f[1]+=-0.25*e;break;case c.DOWN:f[1]+=0.25*e}switch(k){case c.LEFT:p[0]+=-0.25*e;break;case c.RIGHT:p[0]+=0.25*e;break;case c.UP:p[1]+=-0.25*e;break;case c.DOWN:p[1]+=0.25*e}g=(1-d)*(1-d)*(1-d);k=3*(1-d)*(1-d)*d;e=3*(1-d)*d*d;d*=d*d;return[g*a[0]+k*f[0]+e*p[0]+d*b[0],g*a[1]+k*f[1]+e*p[1]+d*b[1]]};f.prototype.drawExecutionOrder=function(a){a.shadowColor="transparent";a.globalAlpha=0.25;a.textAlign="center";a.strokeStyle="white";a.globalAlpha=0.75;for(var b=this.visible_nodes,d=0;d<
b.length;++d){var g=b[d];a.fillStyle="black";a.fillRect(g.pos[0]-c.NODE_TITLE_HEIGHT,g.pos[1]-c.NODE_TITLE_HEIGHT,c.NODE_TITLE_HEIGHT,c.NODE_TITLE_HEIGHT);0==g.order&&a.strokeRect(g.pos[0]-c.NODE_TITLE_HEIGHT+0.5,g.pos[1]-c.NODE_TITLE_HEIGHT+0.5,c.NODE_TITLE_HEIGHT,c.NODE_TITLE_HEIGHT);a.fillStyle="#FFF";a.fillText(g.order,g.pos[0]+-0.5*c.NODE_TITLE_HEIGHT,g.pos[1]-6)}a.globalAlpha=1};f.prototype.drawNodeWidgets=function(a,b,d,g){if(!a.widgets||!a.widgets.length)return 0;var k=a.size[0],e=a.widgets;
b+=2;var f=c.NODE_WIDGET_HEIGHT,p=0.5<this.ds.scale;d.save();d.globalAlpha=this.editor_alpha;for(var n=0;n<e.length;++n){var l=e[n],q=b;l.y&&(q=l.y);l.last_y=q;d.strokeStyle="#666";d.fillStyle="#222";d.textAlign="left";switch(l.type){case "button":l.clicked&&(d.fillStyle="#AAA",l.clicked=!1,this.dirty_canvas=!0);d.fillRect(15,q,k-30,f);d.strokeRect(15,q,k-30,f);p&&(d.textAlign="center",d.fillStyle="#AAA",d.fillText(l.name,0.5*k,q+0.7*f));break;case "toggle":d.textAlign="left";d.strokeStyle="#666";
d.fillStyle="#222";d.beginPath();d.roundRect(15,b,k-30,f,0.5*f);d.fill();d.stroke();d.fillStyle=l.value?"#89A":"#333";d.beginPath();d.arc(k-30,q+0.5*f,0.36*f,0,2*Math.PI);d.fill();p&&(d.fillStyle="#999",null!=l.name&&d.fillText(l.name,30,q+0.7*f),d.fillStyle=l.value?"#DDD":"#888",d.textAlign="right",d.fillText(l.value?l.options.on||"true":l.options.off||"false",k-40,q+0.7*f));break;case "slider":d.fillStyle="#222";d.fillRect(15,q,k-30,f);var t=l.options.max-l.options.min,D=(l.value-l.options.min)/
t;d.fillStyle=g==l?"#89A":"#678";d.fillRect(15,q,D*(k-30),f);d.strokeRect(15,q,k-30,f);l.marker&&(t=(l.marker-l.options.min)/t,d.fillStyle="#AA9",d.fillRect(15+t*(k-30),q,2,f));p&&(d.textAlign="center",d.fillStyle="#DDD",d.fillText(l.name+" "+Number(l.value).toFixed(3),0.5*k,q+0.7*f));break;case "number":case "combo":d.textAlign="left";d.strokeStyle="#666";d.fillStyle="#222";d.beginPath();d.roundRect(15,b,k-30,f,0.5*f);d.fill();d.stroke();p&&(d.fillStyle="#AAA",d.beginPath(),d.moveTo(31,b+5),d.lineTo(21,
b+0.5*f),d.lineTo(31,b+f-5),d.moveTo(k-15-16,b+5),d.lineTo(k-15-6,b+0.5*f),d.lineTo(k-15-16,b+f-5),d.fill(),d.fillStyle="#999",d.fillText(l.name,35,q+0.7*f),d.fillStyle="#DDD",d.textAlign="right","number"==l.type?d.fillText(Number(l.value).toFixed(void 0!==l.options.precision?l.options.precision:3),k-30-20,q+0.7*f):d.fillText(l.value,k-30-20,q+0.7*f));break;case "string":case "text":d.textAlign="left";d.strokeStyle="#666";d.fillStyle="#222";d.beginPath();d.roundRect(15,b,k-30,f,0.5*f);d.fill();d.stroke();
p&&(d.fillStyle="#999",null!=l.name&&d.fillText(l.name,30,q+0.7*f),d.fillStyle="#DDD",d.textAlign="right",d.fillText(l.value,k-30,q+0.7*f));break;default:l.draw&&l.draw(d,a,l,q,f)}b+=f+4}d.restore()};f.prototype.processNodeWidgets=function(a,b,d,g){function k(t,c){t.value=c;t.property&&void 0!==a.properties[t.property]&&(a.properties[t.property]=c);t.callback&&t.callback(t.value,l,a,b,d)}if(!a.widgets||!a.widgets.length)return null;for(var e=b[0]-a.pos[0],f=b[1]-a.pos[1],p=a.size[0],l=this,n=this.getCanvasWindow(),
q=0;q<a.widgets.length;++q){var t=a.widgets[q];if(t==g||6<e&&e<p-12&&f>t.last_y&&f<t.last_y+c.NODE_WIDGET_HEIGHT){switch(t.type){case "button":if("mousemove"===d.type)break;t.callback&&setTimeout(function(){t.callback(t,l,a,b)},20);this.dirty_canvas=t.clicked=!0;break;case "slider":n=Math.clamp((e-10)/(p-20),0,1);t.value=t.options.min+(t.options.max-t.options.min)*n;t.callback&&setTimeout(function(){k(t,t.value)},20);this.dirty_canvas=!0;break;case "number":case "combo":if("mousemove"==d.type&&"number"==
t.type)t.value+=0.1*d.deltaX*(t.options.step||1),null!=t.options.min&&t.value<t.options.min&&(t.value=t.options.min),null!=t.options.max&&t.value>t.options.max&&(t.value=t.options.max);else if("mousedown"==d.type)if((g=t.options.values)&&g.constructor===Function&&(g=t.options.values(t,a)),e=40>e?-1:e>p-40?1:0,"number"==t.type)t.value+=0.1*e*(t.options.step||1),null!=t.options.min&&t.value<t.options.min&&(t.value=t.options.min),null!=t.options.max&&t.value>t.options.max&&(t.value=t.options.max);else if(e)n=
g.indexOf(t.value)+e,n>=g.length&&(n=0),0>n&&(n=g.length-1),t.value=g[n];else{new c.ContextMenu(g,{scale:Math.max(1,this.ds.scale),event:d,className:"dark",callback:D.bind(t)},n);var D=function(a,b,d){this.value=a;k(this,a);l.dirty_canvas=!0;return!1}}setTimeout(function(){k(this,this.value)}.bind(t),20);this.dirty_canvas=!0;break;case "toggle":"mousedown"==d.type&&(t.value=!t.value,t.callback&&setTimeout(function(){k(t,t.value)},20));break;case "string":case "text":"mousedown"==d.type&&this.prompt("Value",
t.value,function(a){this.value=a;k(this,a)}.bind(t),d);break;default:t.mouse&&t.mouse(ctx,d,[e,f],a)}return t}}return null};f.prototype.drawGroups=function(a,b){if(this.graph){var d=this.graph._groups;b.save();b.globalAlpha=0.5*this.editor_alpha;for(var g=0;g<d.length;++g){var k=d[g];if(A(this.visible_area,k._bounding)){b.fillStyle=k.color||"#335";b.strokeStyle=k.color||"#335";var e=k._pos,f=k._size;b.globalAlpha=0.25*this.editor_alpha;b.beginPath();b.rect(e[0]+0.5,e[1]+0.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=k.font_size||c.DEFAULT_GROUP_FONT_SIZE;b.font=f+"px Arial";b.fillText(k.title,e[0]+4,e[1]+f)}}b.restore()}};f.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)};f.prototype.resize=function(a,b){if(!a&&!b){var d=this.canvas.parentNode;a=d.offsetWidth;b=d.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)};f.prototype.switchLiveMode=function(a){if(a){var b=this,d=this.live_mode?1.1:0.9;this.live_mode&&(this.live_mode=!1,this.editor_alpha=0.1);var c=setInterval(function(){b.editor_alpha*=d;b.dirty_canvas=!0;b.dirty_bgcanvas=!0;1>d&&0.01>b.editor_alpha&&(clearInterval(c),1>d&&(b.live_mode=!0));1<d&&0.99<b.editor_alpha&&(clearInterval(c),
b.editor_alpha=1)},1)}else this.live_mode=!this.live_mode,this.dirty_bgcanvas=this.dirty_canvas=!0};f.prototype.onNodeSelectionChange=function(a){};f.prototype.touchHandler=function(a){var b=a.changedTouches[0],d="";switch(a.type){case "touchstart":d="mousedown";break;case "touchmove":d="mousemove";break;case "touchend":d="mouseup";break;default:return}var c=this.getCanvasWindow(),g=c.document.createEvent("MouseEvent");g.initMouseEvent(d,!0,!0,c,1,b.screenX,b.screenY,b.clientX,b.clientY,!1,!1,!1,
!1,0,null);b.target.dispatchEvent(g);a.preventDefault()};f.onGroupAdd=function(a,b,d){a=f.active_canvas;a.getCanvasWindow();b=new c.LGraphGroup;b.pos=a.convertEventToCanvasOffset(d);a.graph.add(b)};f.onMenuAdd=function(a,b,d,g){function k(a,b){var d=g.getFirstEvent(),k=c.createNode(a.value);k&&(k.pos=e.convertEventToCanvasOffset(d),e.graph.add(k))}var e=f.active_canvas,p=e.getCanvasWindow();a=c.getNodeTypesCategories();b=[];for(var l in a)a[l]&&b.push({value:a[l],content:a[l],has_submenu:!0});var n=
new c.ContextMenu(b,{event:d,callback:function(a,b,d){a=c.getNodeTypesInCategory(a.value,e.filter);b=[];for(var g in a)a[g].skip_list||b.push({content:a[g].title,value:a[g].type});new c.ContextMenu(b,{event:d,callback:k,parentMenu:n},p);return!1},parentMenu:g},p);return!1};f.onMenuCollapseAll=function(){};f.onMenuNodeEdit=function(){};f.showMenuNodeOptionalInputs=function(a,b,d,g,k){function e(a,b,d){k&&(a.callback&&a.callback.call(p,k,a,b,d),a.value&&(k.addInput(a.value[0],a.value[1],a.value[2]),
k.setDirtyCanvas(!0,!0)))}if(k){var p=this;a=f.active_canvas.getCanvasWindow();b=k.optional_inputs;k.onGetInputs&&(b=k.onGetInputs());var l=[];if(b)for(var n in b){var q=b[n];if(q){var h=q[0];q[2]&&q[2].label&&(h=q[2].label);h={content:h,value:q};q[1]==c.ACTION&&(h.className="event");l.push(h)}else l.push(null)}this.onMenuNodeInputs&&(l=this.onMenuNodeInputs(l));if(l.length)return new c.ContextMenu(l,{event:d,callback:e,parentMenu:g,node:k},a),!1}};f.showMenuNodeOptionalOutputs=function(a,b,d,g,k){function e(a,
b,d){if(k&&(a.callback&&a.callback.call(p,k,a,b,d),a.value))if(d=a.value[1],!d||d.constructor!==Object&&d.constructor!==Array)k.addOutput(a.value[0],a.value[1],a.value[2]),k.setDirtyCanvas(!0,!0);else{a=[];for(var f in d)a.push({content:f,value:d[f]});new c.ContextMenu(a,{event:b,callback:e,parentMenu:g,node:k});return!1}}if(k){var p=this;a=f.active_canvas.getCanvasWindow();b=k.optional_outputs;k.onGetOutputs&&(b=k.onGetOutputs());var l=[];if(b)for(var n in b){var q=b[n];if(!q)l.push(null);else if(!k.flags||
!k.flags.skip_repeated_outputs||-1==k.findOutputSlot(q[0])){var h=q[0];q[2]&&q[2].label&&(h=q[2].label);h={content:h,value:q};q[1]==c.EVENT&&(h.className="event");l.push(h)}}this.onMenuNodeOutputs&&(l=this.onMenuNodeOutputs(l));if(l.length)return new c.ContextMenu(l,{event:d,callback:e,parentMenu:g,node:k},a),!1}};f.onShowMenuNodeProperties=function(a,b,d,g,k){function e(a,b,d,c){k&&(b=this.getBoundingClientRect(),p.showEditPropertyValue(k,a.value,{position:[b.left,b.top]}))}if(k&&k.properties){var p=
f.active_canvas;b=p.getCanvasWindow();var l=[],q;for(q in k.properties)a=void 0!==k.properties[q]?k.properties[q]:" ",a=f.decodeHTML(a),l.push({content:"<span class='property_name'>"+q+"</span><span class='property_value'>"+a+"</span>",value:q});if(l.length)return new c.ContextMenu(l,{event:d,callback:e,parentMenu:g,allow_html:!0,node:k},b),!1}};f.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};f.onResizeNode=function(a,b,d,c,g){g&&(g.size=g.computeSize(),
g.setDirtyCanvas(!0,!0))};f.prototype.showLinkMenu=function(a,b){var d=this;new c.ContextMenu(["Delete"],{event:b,callback:function(b){switch(b){case "Delete":d.graph.removeLink(a.id)}}});return!1};f.onShowPropertyEditor=function(a,b,d,c,g){function e(){var b=q.value;"Number"==a.type?b=Number(b):"Boolean"==a.type&&(b=Boolean(b));g[p]=b;l.parentNode&&l.parentNode.removeChild(l);g.setDirtyCanvas(!0,!0)}var p=a.property||"title";b=g[p];var l=document.createElement("div");l.className="graphdialog";l.innerHTML=
"<span class='name'></span><input autofocus type='text' class='value'/><button>OK</button>";l.querySelector(".name").innerText=p;var q=l.querySelector("input");q&&(q.value=b,q.addEventListener("blur",function(a){this.focus()}),q.addEventListener("keydown",function(a){13==a.keyCode&&(e(),a.preventDefault(),a.stopPropagation())}));b=f.active_canvas.canvas;d=b.getBoundingClientRect();var n=c=-20;d&&(c-=d.left,n-=d.top);event?(l.style.left=event.clientX+c+"px",l.style.top=event.clientY+n+"px"):(l.style.left=
0.5*b.width+c+"px",l.style.top=0.5*b.height+n+"px");l.querySelector("button").addEventListener("click",e);b.parentNode.appendChild(l)};f.prototype.prompt=function(a,b,d,c){var g=this;a=a||"";var e=!1,l=document.createElement("div");l.className="graphdialog rounded";l.innerHTML="<span class='name'></span> <input autofocus type='text' class='value'/><button class='rounded'>OK</button>";l.close=function(){g.prompt_box=null;l.parentNode&&l.parentNode.removeChild(l)};1<this.ds.scale&&(l.style.transform=
"scale("+this.ds.scale+")");l.addEventListener("mouseleave",function(a){e||l.close()});g.prompt_box&&g.prompt_box.close();g.prompt_box=l;l.querySelector(".name").innerText=a;l.querySelector(".value").value=b;var p=l.querySelector("input");p.addEventListener("keydown",function(a){e=!0;if(27==a.keyCode)l.close();else if(13==a.keyCode)d&&d(this.value),l.close();else return;a.preventDefault();a.stopPropagation()});l.querySelector("button").addEventListener("click",function(a){d&&d(p.value);g.setDirty(!0);
l.close()});a=f.active_canvas.canvas;b=a.getBoundingClientRect();var q=-20,n=-20;b&&(q-=b.left,n-=b.top);c?(l.style.left=c.clientX+q+"px",l.style.top=c.clientY+n+"px"):(l.style.left=0.5*a.width+q+"px",l.style.top=0.5*a.height+n+"px");a.parentNode.appendChild(l);setTimeout(function(){p.focus()},10);return l};f.search_limit=-1;f.prototype.showSearchBox=function(a){function b(b){if(b)if(e.onSearchBoxSelection)e.onSearchBoxSelection(b,a,D);else{var d=c.searchbox_extras[b];d&&(b=d.type);if(b=c.createNode(b))b.pos=
D.convertEventToCanvasOffset(a),D.graph.add(b);if(d&&d.data){if(d.data.properties)for(var t in d.data.properties)b.addProperty(d.data.properties[t][0],d.data.properties[t][0]);if(d.data.inputs)for(t in b.inputs=[],d.data.inputs)b.addOutput(d.data.inputs[t][0],d.data.inputs[t][1]);if(d.data.outputs)for(t in b.outputs=[],d.data.outputs)b.addOutput(d.data.outputs[t][0],d.data.outputs[t][1]);d.data.title&&(b.title=d.data.title);d.data.json&&b.configure(d.data.json)}}l.close()}function d(a){var b=m;m&&
m.classList.remove("selected");m?(m=a?m.nextSibling:m.previousSibling)||(m=b):m=a?q.childNodes[0]:q.childNodes[q.childNodes.length];m&&(m.classList.add("selected"),m.scrollIntoView())}function g(){function a(d,t){var c=document.createElement("div");n||(n=d);c.innerText=d;c.dataset.type=escape(d);c.className="litegraph lite-search-item";t&&(c.className+=" "+t);c.addEventListener("click",function(a){b(unescape(this.dataset.type))});q.appendChild(c)}h=null;var d=t.value;n=null;q.innerHTML="";if(d)if(e.onSearchBox){var l=
e.onSearchBox(q,d,D);if(l)for(var p=0;p<l.length;++p)a(l[p])}else{l=0;d=d.toLowerCase();for(p in c.searchbox_extras){var m=c.searchbox_extras[p];if(-1!==m.desc.toLowerCase().indexOf(d)&&(a(m.desc,"searchbox_extra"),-1!==f.search_limit&&l++>f.search_limit))break}if(Array.prototype.filter)for(m=Object.keys(c.registered_node_types).filter(function(a){return-1!==a.toLowerCase().indexOf(d)}),p=0;p<m.length&&!(a(m[p]),-1!==f.search_limit&&l++>f.search_limit);p++);else for(p in c.registered_node_types)if(-1!=
p.indexOf(d)&&(a(p),-1!==f.search_limit&&l++>f.search_limit))break}}var e=this,l=document.createElement("div");l.className="litegraph litesearchbox graphdialog rounded";l.innerHTML="<span class='name'>Search</span> <input autofocus type='text' class='value rounded'/><div class='helper'></div>";l.close=function(){e.search_box=null;document.body.focus();setTimeout(function(){e.canvas.focus()},20);l.parentNode&&l.parentNode.removeChild(l)};var p=null;1<this.ds.scale&&(l.style.transform="scale("+this.ds.scale+
")");l.addEventListener("mouseenter",function(a){p&&(clearTimeout(p),p=null)});l.addEventListener("mouseleave",function(a){p=setTimeout(function(){l.close()},500)});e.search_box&&e.search_box.close();e.search_box=l;var q=l.querySelector(".helper"),n=null,h=null,m=null,t=l.querySelector("input");t&&(t.addEventListener("blur",function(a){this.focus()}),t.addEventListener("keydown",function(a){if(38==a.keyCode)d(!1);else if(40==a.keyCode)d(!0);else if(27==a.keyCode)l.close();else if(13==a.keyCode)m?
b(m.innerHTML):n?b(n):l.close();else{h&&clearInterval(h);h=setTimeout(g,10);return}a.preventDefault();a.stopPropagation()}));var D=f.active_canvas,E=D.canvas,r=E.getBoundingClientRect(),w=-20,x=-20;r&&(w-=r.left,x-=r.top);a?(l.style.left=a.clientX+w+"px",l.style.top=a.clientY+x+"px"):(l.style.left=0.5*E.width+w+"px",l.style.top=0.5*E.height+x+"px");E.parentNode.appendChild(l);t.focus();return l};f.prototype.showEditPropertyValue=function(a,b,d){function c(){g(t.value)}function g(d){"number"==typeof a.properties[b]&&
(d=Number(d));"array"==e&&(d=d.split(",").map(Number));a.properties[b]=d;a._graph&&a._graph._version++;if(a.onPropertyChanged)a.onPropertyChanged(b,d);n.close();a.setDirtyCanvas(!0,!0)}if(a&&void 0!==a.properties[b]){d=d||{};var e="string";null!==a.properties[b]&&(e=typeof a.properties[b]);"object"==e&&a.properties[b].length&&(e="array");var l=null;a.getPropertyInfo&&(l=a.getPropertyInfo(b));if(a.properties_info)for(var f=0;f<a.properties_info.length;++f)if(a.properties_info[f].name==b){l=a.properties_info[f];
break}void 0!==l&&null!==l&&l.type&&(e=l.type);var p="";if("string"==e||"number"==e||"array"==e)p="<input autofocus type='text' class='value'/>";else if("enum"==e&&l.values){p="<select autofocus type='text' class='value'>";for(f in l.values)var q=l.values.constructor===Array?l.values[f]:f,p=p+("<option value='"+q+"' "+(q==a.properties[b]?"selected":"")+">"+l.values[f]+"</option>");p+="</select>"}else if("boolean"==e)p="<input autofocus type='checkbox' class='value' "+(a.properties[b]?"checked":"")+
"/>";else{console.warn("unknown type: "+e);return}var n=this.createDialog("<span class='name'>"+b+"</span>"+p+"<button>OK</button>",d);if("enum"==e&&l.values){var t=n.querySelector("select");t.addEventListener("change",function(a){g(a.target.value)})}else if("boolean"==e)(t=n.querySelector("input"))&&t.addEventListener("click",function(a){g(!!t.checked)});else if(t=n.querySelector("input"))t.addEventListener("blur",function(a){this.focus()}),t.value=void 0!==a.properties[b]?a.properties[b]:"",t.addEventListener("keydown",
function(a){13==a.keyCode&&(c(),a.preventDefault(),a.stopPropagation())});n.querySelector("button").addEventListener("click",c)}};f.prototype.createDialog=function(a,b){b=b||{};var d=document.createElement("div");d.className="graphdialog";d.innerHTML=a;var c=this.canvas.getBoundingClientRect(),g=-20,e=-20;c&&(g-=c.left,e-=c.top);b.position?(g+=b.position[0],e+=b.position[1]):b.event?(g+=b.event.clientX,e+=b.event.clientY):(g+=0.5*this.canvas.width,e+=0.5*this.canvas.height);d.style.left=g+"px";d.style.top=
e+"px";this.canvas.parentNode.appendChild(d);d.close=function(){this.parentNode&&this.parentNode.removeChild(this)};return d};f.onMenuNodeCollapse=function(a,b,d,c,g){g.collapse()};f.onMenuNodePin=function(a,b,d,c,g){g.pin()};f.onMenuNodeMode=function(a,b,d,g,e){new c.ContextMenu(["Always","On Event","On Trigger","Never"],{event:d,callback:function(a){if(e)switch(a){case "On Event":e.mode=c.ON_EVENT;break;case "On Trigger":e.mode=c.ON_TRIGGER;break;case "Never":e.mode=c.NEVER;break;default:e.mode=
c.ALWAYS}},parentMenu:g,node:e});return!1};f.onMenuNodeColors=function(a,b,d,g,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 l in f.node_colors)a=f.node_colors[l],a={value:l,content:"<span style='display: block; color: #999; padding-left: 4px; border-left: 8px solid "+a.color+"; background-color:"+a.bgcolor+"'>"+l+"</span>"},b.push(a);new c.ContextMenu(b,{event:d,callback:function(a){e&&((a=a.value?f.node_colors[a.value]:
null)?e.constructor===c.LGraphGroup?e.color=a.groupcolor:(e.color=a.color,e.bgcolor=a.bgcolor):(delete e.color,delete e.bgcolor),e.setDirtyCanvas(!0,!0))},parentMenu:g,node:e});return!1};f.onMenuNodeShapes=function(a,b,d,g,e){if(!e)throw"no node passed";new c.ContextMenu(c.VALID_SHAPES,{event:d,callback:function(a){e&&(e.shape=a,e.setDirtyCanvas(!0))},parentMenu:g,node:e});return!1};f.onMenuNodeRemove=function(a,b,d,c,g){if(!g)throw"no node passed";!1!==g.removable&&(g.graph.remove(g),g.setDirtyCanvas(!0,
!0))};f.onMenuNodeClone=function(a,b,d,c,g){!1!=g.clonable&&(a=g.clone())&&(a.pos=[g.pos[0]+5,g.pos[1]+5],g.graph.add(a),g.setDirtyCanvas(!0,!0))};f.node_colors={red:{color:"#322",bgcolor:"#533",groupcolor:"#A88"},brown:{color:"#332922",bgcolor:"#593930",groupcolor:"#b06634"},green:{color:"#232",bgcolor:"#353",groupcolor:"#8A8"},blue:{color:"#223",bgcolor:"#335",groupcolor:"#88A"},pale_blue:{color:"#2a363b",bgcolor:"#3f5159",groupcolor:"#3f789e"},cyan:{color:"#233",bgcolor:"#355",groupcolor:"#8AA"},
purple:{color:"#323",bgcolor:"#535",groupcolor:"#a1309b"},yellow:{color:"#432",bgcolor:"#653",groupcolor:"#b58b2a"},black:{color:"#222",bgcolor:"#000",groupcolor:"#444"}};f.prototype.getCanvasMenuOptions=function(){var a=null;this.getMenuOptions?a=this.getMenuOptions():(a=[{content:"Add Node",has_submenu:!0,callback:f.onMenuAdd},{content:"Add Group",callback:f.onGroupAdd}],this._graph_stack&&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};f.prototype.getNodeMenuOptions=function(a){var b=null,b=a.getMenuOptions?a.getMenuOptions(this):[{content:"Inputs",has_submenu:!0,disabled:!0,callback:f.showMenuNodeOptionalInputs},{content:"Outputs",has_submenu:!0,disabled:!0,callback:f.showMenuNodeOptionalOutputs},null,{content:"Properties",has_submenu:!0,callback:f.onShowMenuNodeProperties},null,{content:"Title",callback:f.onShowPropertyEditor},{content:"Mode",
has_submenu:!0,callback:f.onMenuNodeMode},{content:"Resize",callback:f.onResizeNode},{content:"Collapse",callback:f.onMenuNodeCollapse},{content:"Pin",callback:f.onMenuNodePin},{content:"Colors",has_submenu:!0,callback:f.onMenuNodeColors},{content:"Shapes",has_submenu:!0,callback:f.onMenuNodeShapes},null];if(a.onGetInputs){var d=a.onGetInputs();d&&d.length&&(b[0].disabled=!1)}a.onGetOutputs&&(d=a.onGetOutputs())&&d.length&&(b[1].disabled=!1);a.getExtraMenuOptions&&(d=a.getExtraMenuOptions(this))&&
(d.push(null),b=d.concat(b));!1!==a.clonable&&b.push({content:"Clone",callback:f.onMenuNodeClone});!1!==a.removable&&b.push(null,{content:"Remove",callback:f.onMenuNodeRemove});if(a.graph&&a.graph.onGetNodeMenuOptions)a.graph.onGetNodeMenuOptions(b,a);return b};f.prototype.getGroupMenuOptions=function(a){return[{content:"Title",callback:f.onShowPropertyEditor},{content:"Color",has_submenu:!0,callback:f.onMenuNodeColors},{content:"Font size",property:"font_size",type:"Number",callback:f.onShowPropertyEditor},
null,{content:"Remove",callback:f.onMenuNodeRemove}]};f.prototype.processContextMenu=function(a,b){var d=this,g=f.active_canvas.getCanvasWindow(),e=null,l={event:b,callback:function(b,c,g){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 t=b.input?a.getInputInfo(b.slot):a.getOutputInfo(b.slot),
e=d.createDialog("<span class='name'>Name</span><input autofocus type='text'/><button>OK</button>",c),l=e.querySelector("input");l&&t&&(l.value=t.label||"");e.querySelector("button").addEventListener("click",function(a){l.value&&(t&&(t.label=l.value),d.setDirty(!0));e.close()})}},extra:a},p=null;a&&(p=a.getSlotInPosition(b.canvasX,b.canvasY),f.active_node=a);if(p){e=[];p&&p.output&&p.output.links&&p.output.links.length&&e.push({content:"Disconnect Links",slot:p});var q=p.input||p.output;e.push(q.locked?
"Cannot remove":{content:"Remove Slot",slot:p});e.push(q.nameLocked?"Cannot rename":{content:"Rename Slot",slot:p});l.title=(p.input?p.input.type:p.output.type)||"*";p.input&&p.input.type==c.ACTION&&(l.title="Action");p.output&&p.output.type==c.EVENT&&(l.title="Event")}else a?e=this.getNodeMenuOptions(a):(e=this.getCanvasMenuOptions(),(p=this.graph.getGroupOnPos(b.canvasX,b.canvasY))&&e.push(null,{content:"Edit Group",has_submenu:!0,submenu:{title:"Group",extra:p,options:this.getGroupMenuOptions(p)}}));
e&&new c.ContextMenu(e,l,g)};this.CanvasRenderingContext2D&&(CanvasRenderingContext2D.prototype.roundRect=function(a,b,d,c,g,e){void 0===g&&(g=5);void 0===e&&(e=g);this.moveTo(a+g,b);this.lineTo(a+d-g,b);this.quadraticCurveTo(a+d,b,a+d,b+g);this.lineTo(a+d,b+c-e);this.quadraticCurveTo(a+d,b+c,a+d-e,b+c);this.lineTo(a+e,b+c);this.quadraticCurveTo(a,b+c,a,b+c-e);this.lineTo(a,b+g);this.quadraticCurveTo(a,b,a+g,b)});c.compareObjects=function(a,b){for(var d in a)if(a[d]!=b[d])return!1;return!0};c.distance=
y;c.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")+")"};c.isInsideRectangle=B;c.growBounding=function(a,b,d){b<a[0]?a[0]=b:b>a[2]&&(a[2]=b);d<a[1]?a[1]=d:d>a[3]&&(a[3]=d)};c.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};c.overlapBounding=A;c.hex2num=function(a){"#"==a.charAt(0)&&(a=a.slice(1));a=a.toUpperCase();
for(var b=Array(3),d=0,c,g,e=0;6>e;e+=2)c="0123456789ABCDEF".indexOf(a.charAt(e)),g="0123456789ABCDEF".indexOf(a.charAt(e+1)),b[d]=16*c+g,d++;return b};c.num2hex=function(a){for(var b="#",d,c,g=0;3>g;g++)d=a[g]/16,c=a[g]%16,b+="0123456789ABCDEF".charAt(d)+"0123456789ABCDEF".charAt(c);return b};z.prototype.addItem=function(a,b,d){function c(a){var b=this.value;b&&b.has_submenu&&g.call(this,a)}function g(a){var b=this.value,c=!0;e.current_submenu&&e.current_submenu.close(a);if(d.callback){var t=d.callback.call(this,
b,d,a,e,d.node);!0===t&&(c=!1)}if(b&&(b.callback&&!d.ignore_item_callbacks&&!0!==b.disabled&&(t=b.callback.call(this,b,d,a,e,d.extra),!0===t&&(c=!1)),b.submenu)){if(!b.submenu.options)throw"ContextMenu submenu needs options";new e.constructor(b.submenu.options,{callback:b.submenu.callback,event:a,parentMenu:e,ignore_item_callbacks:b.submenu.ignore_item_callbacks,title:b.submenu.title,extra:b.submenu.extra,autoopen:d.autoopen});c=!1}c&&!e.lock&&e.close()}var e=this;d=d||{};var l=document.createElement("div");
l.className="litemenu-entry submenu";var f=!1;if(null===b)l.classList.add("separator");else{l.innerHTML=b&&b.title?b.title:a;if(l.value=b)b.disabled&&(f=!0,l.classList.add("disabled")),(b.submenu||b.has_submenu)&&l.classList.add("has_submenu");"function"==typeof b?(l.dataset.value=a,l.onclick_callback=b):l.dataset.value=b;b.className&&(l.className+=" "+b.className)}this.root.appendChild(l);f||l.addEventListener("click",g);d.autoopen&&l.addEventListener("mouseenter",c);return l};z.prototype.close=
function(a,b){this.root.parentNode&&this.root.parentNode.removeChild(this.root);this.parentMenu&&!b&&(this.parentMenu.lock=!1,this.parentMenu.current_submenu=null,void 0===a?this.parentMenu.close():a&&!z.isCursorOverElement(a,this.parentMenu.root)&&z.trigger(this.parentMenu.root,"mouseleave",a));this.current_submenu&&this.current_submenu.close(a,!0);this.root.closing_timer&&clearTimeout(this.root.closing_timer)};z.trigger=function(a,b,d,c){var g=document.createEvent("CustomEvent");g.initCustomEvent(b,
!0,!0,d);g.srcElement=c;a.dispatchEvent?a.dispatchEvent(g):a.__events&&a.__events.dispatchEvent(g);return g};z.prototype.getTopMenu=function(){return this.options.parentMenu?this.options.parentMenu.getTopMenu():this};z.prototype.getFirstEvent=function(){return this.options.parentMenu?this.options.parentMenu.getFirstEvent():this.options.event};z.isCursorOverElement=function(a,b){var d=a.clientX,c=a.clientY,g=b.getBoundingClientRect();return g?c>g.top&&c<g.top+g.height&&d>g.left&&d<g.left+g.width?!0:
!1:!1};c.ContextMenu=z;c.closeAllContextMenus=function(a){a=a||window;a=a.document.querySelectorAll(".litecontextmenu");if(a.length){for(var b=[],d=0;d<a.length;d++)b.push(a[d]);for(d in b)b[d].close?b[d].close():b[d].parentNode&&b[d].parentNode.removeChild(b[d])}};c.extendClass=function(a,b){for(var d in b)a.hasOwnProperty(d)||(a[d]=b[d]);if(b.prototype)for(d in b.prototype)b.prototype.hasOwnProperty(d)&&!a.prototype.hasOwnProperty(d)&&(b.prototype.__lookupGetter__(d)?a.prototype.__defineGetter__(d,
b.prototype.__lookupGetter__(d)):a.prototype[d]=b.prototype[d],b.prototype.__lookupSetter__(d)&&a.prototype.__defineSetter__(d,b.prototype.__lookupSetter__(d)))};c.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,d){return b>a?b:d<a?d: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 e(){this.addOutput("in ms","number");this.addOutput("in sec","number")}function h(){this.size=[140,80];this.properties={enabled:!0};this.enabled=!0;this.subgraph=new 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 r(){this.addOutput("","");this.name_in_graph="";this.properties={};var c=this;Object.defineProperty(this.properties,"name",{get:function(){return c.name_in_graph},
set:function(g){""!=g&&g!=c.name_in_graph&&"enabled"!=g&&(c.name_in_graph?c.graph.renameInput(c.name_in_graph,g):c.graph.addInput(g,c.properties.type),c.name_widget.value=g,c.name_in_graph=g)},enumerable:!0});Object.defineProperty(this.properties,"type",{get:function(){return c.outputs[0].type},set:function(g){"event"==g&&(g=n.EVENT);c.outputs[0].type=g;c.name_in_graph&&c.graph.changeInputType(c.name_in_graph,c.outputs[0].type);c.type_widget.value=g},enumerable:!0});this.name_widget=this.addWidget("text",
@@ -387,12 +388,12 @@ this._last_tex;this._canvas=cloneCanvas(b)}this._canvas&&(a.save(),a.webgl||(a.t
a||(this._preview_canvas=a=createCanvas(b,b));c&&c.toCanvas(a);return a};h.prototype.getResources=function(a){a[this.properties.name]=GL.Texture;return a};h.prototype.onGetInputs=function(){return[["in","Texture"]]};h.prototype.onGetOutputs=function(){return[["width","number"],["height","number"],["aspect","number"]]};h.replaceCode=function(a,b){return a.replace(/\{\{[a-zA-Z0-9_]*\}\}/g,function(a){a=a.replace(/[\{\}]/g,"");return b[a]||""})};e.registerNodeType("texture/texture",h);var r=function(){this.addInput("Texture",
"Texture");this.properties={flipY:!1};this.size=[h.image_preview_size,h.image_preview_size]};r.title="Preview";r.desc="Show a texture in the graph canvas";r.allow_preview=!1;r.prototype.onDrawBackground=function(a){if(!this.flags.collapsed&&(a.webgl||r.allow_preview)){var b=this.getInputData(0);if(b){var c=null,c=!b.handle&&a.webgl?b:h.generateLowResTexturePreview(b);a.save();this.properties.flipY&&(a.translate(0,this.size[1]),a.scale(1,-1));a.drawImage(c,0,0,this.size[0],this.size[1]);a.restore()}}};
e.registerNodeType("texture/preview",r);var m=function(){this.addInput("Texture","Texture");this.addOutput("","Texture");this.properties={name:""}};m.title="Save";m.desc="Save a texture in the repository";m.prototype.onExecute=function(){var a=this.getInputData(0);a&&(this.properties.name&&(h.storeTexture?h.storeTexture(this.properties.name,a):h.getTexturesContainer()[this.properties.name]=a),this.setOutputData(0,a))};e.registerNodeType("texture/save",m);var s=function(){this.addInput("Texture","Texture");
this.addInput("TextureB","Texture");this.addInput("value","number");this.addOutput("Texture","Texture");this.help="<p>pixelcode must be vec3</p>\t\t\t<p>uvcode must be vec2, is optional</p>\t\t\t<p><strong>uv:</strong> tex. coords</p><p><strong>color:</strong> texture</p><p><strong>colorB:</strong> textureB</p><p><strong>time:</strong> scene time</p><p><strong>value:</strong> input value</p><p>For multiline you must type: result = ...</p>";this.properties={value:1,uvcode:"",pixelcode:"color + colorB * value",
precision:h.DEFAULT};this.has_error=!1};s.widgets_info={uvcode:{widget:"textarea",height:100},pixelcode:{widget:"textarea",height:100},precision:{widget:"combo",values:h.MODE_VALUES}};s.title="Operation";s.desc="Texture shader operation";s.prototype.getExtraMenuOptions=function(a){var b=this;return[{content:b.properties.show?"Hide Texture":"Show Texture",callback:function(){b.properties.show=!b.properties.show}}]};s.prototype.onPropertyChanged=function(){this.has_error=!1};s.prototype.onDrawBackground=
function(a){this.flags.collapsed||20>=this.size[1]||!this.properties.show||!this._tex||this._tex.gl!=a||(a.save(),a.drawImage(this._tex,0,0,this.size[0],this.size[1]),a.restore())};s.prototype.onExecute=function(){var a=this.getInputData(0);if(this.isOutputConnected(0))if(this.properties.precision===h.PASS_THROUGH)this.setOutputData(0,a);else{var b=this.getInputData(1);if(this.properties.uvcode||this.properties.pixelcode){var c=512,d=512;a?(c=a.width,d=a.height):b&&(c=b.width,d=b.height);var e=h.getTextureType(this.properties.precision,
a);this._tex=a||this._tex?h.getTargetTexture(a||this._tex,this._tex,this.properties.precision):new GL.Texture(c,d,{type:e,format:gl.RGBA,filter:gl.LINEAR});e="";this.properties.uvcode&&(e="uv = "+this.properties.uvcode,-1!=this.properties.uvcode.indexOf(";")&&(e=this.properties.uvcode));var g="";this.properties.pixelcode&&(g="result = "+this.properties.pixelcode,-1!=this.properties.pixelcode.indexOf(";")&&(g=this.properties.pixelcode));var f=this._shader;if(!(this.has_error||f&&this._shader_code==
e+"|"+g)){var k=h.replaceCode(s.pixel_shader,{UV_CODE:e,PIXEL_CODE:g});try{f=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,k),this.boxcolor="#00FF00"}catch(q){console.log("Error compiling shader: ",q,k);this.boxcolor="#FF0000";this.has_error=!0;return}this._shader=f;this._shader_code=e+"|"+g}var l=this.getInputData(2);null!=l?this.properties.value=l:l=parseFloat(this.properties.value);var m=this.graph.getTime();this._tex.drawTo(function(){gl.disable(gl.DEPTH_TEST);gl.disable(gl.CULL_FACE);gl.disable(gl.BLEND);
a&&a.bind(0);b&&b.bind(1);var e=Mesh.getScreenQuad();f.uniforms({u_texture:0,u_textureB:1,value:l,texSize:[c,d],time:m}).draw(e)});this.setOutputData(0,this._tex)}}};s.pixel_shader="precision highp float;\n\t\t\t\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform sampler2D u_textureB;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform vec2 texSize;\n\t\t\tuniform float time;\n\t\t\tuniform float value;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec2 uv = v_coord;\n\t\t\t\t{{UV_CODE}};\n\t\t\t\tvec4 color4 = texture2D(u_texture, uv);\n\t\t\t\tvec3 color = color4.rgb;\n\t\t\t\tvec4 color4B = texture2D(u_textureB, uv);\n\t\t\t\tvec3 colorB = color4B.rgb;\n\t\t\t\tvec3 result = color;\n\t\t\t\tfloat alpha = 1.0;\n\t\t\t\t{{PIXEL_CODE}};\n\t\t\t\tgl_FragColor = vec4(result, alpha);\n\t\t\t}\n\t\t\t";
this.addInput("TextureB","Texture");this.addInput("value","number");this.addOutput("Texture","Texture");this.help="<p>pixelcode must be vec3, uvcode must be vec2, is optional</p>\t\t\t<p><strong>uv:</strong> tex. coords</p><p><strong>color:</strong> texture <strong>colorB:</strong> textureB</p><p><strong>time:</strong> scene time <strong>value:</strong> input value</p><p>For multiline you must type: result = ...</p>";this.properties={value:1,pixelcode:"color + colorB * value",uvcode:"",precision:h.DEFAULT};
this.has_error=!1};s.widgets_info={uvcode:{widget:"code"},pixelcode:{widget:"code"},precision:{widget:"combo",values:h.MODE_VALUES}};s.title="Operation";s.desc="Texture shader operation";s.prototype.getExtraMenuOptions=function(a){var b=this;return[{content:b.properties.show?"Hide Texture":"Show Texture",callback:function(){b.properties.show=!b.properties.show}}]};s.prototype.onPropertyChanged=function(){this.has_error=!1};s.prototype.onDrawBackground=function(a){this.flags.collapsed||20>=this.size[1]||
!this.properties.show||!this._tex||this._tex.gl!=a||(a.save(),a.drawImage(this._tex,0,0,this.size[0],this.size[1]),a.restore())};s.prototype.onExecute=function(){var a=this.getInputData(0);if(this.isOutputConnected(0))if(this.properties.precision===h.PASS_THROUGH)this.setOutputData(0,a);else{var b=this.getInputData(1);if(this.properties.uvcode||this.properties.pixelcode){var c=512,d=512;a?(c=a.width,d=a.height):b&&(c=b.width,d=b.height);var e=h.getTextureType(this.properties.precision,a);this._tex=
a||this._tex?h.getTargetTexture(a||this._tex,this._tex,this.properties.precision):new GL.Texture(c,d,{type:e,format:gl.RGBA,filter:gl.LINEAR});e="";this.properties.uvcode&&(e="uv = "+this.properties.uvcode,-1!=this.properties.uvcode.indexOf(";")&&(e=this.properties.uvcode));var g="";this.properties.pixelcode&&(g="result = "+this.properties.pixelcode,-1!=this.properties.pixelcode.indexOf(";")&&(g=this.properties.pixelcode));var f=this._shader;if(!(this.has_error||f&&this._shader_code==e+"|"+g)){var k=
h.replaceCode(s.pixel_shader,{UV_CODE:e,PIXEL_CODE:g});try{f=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,k),this.boxcolor="#00FF00"}catch(q){console.log("Error compiling shader: ",q,k);this.boxcolor="#FF0000";this.has_error=!0;return}this._shader=f;this._shader_code=e+"|"+g}var l=this.getInputData(2);null!=l?this.properties.value=l:l=parseFloat(this.properties.value);var m=this.graph.getTime();this._tex.drawTo(function(){gl.disable(gl.DEPTH_TEST);gl.disable(gl.CULL_FACE);gl.disable(gl.BLEND);a&&a.bind(0);
b&&b.bind(1);var e=Mesh.getScreenQuad();f.uniforms({u_texture:0,u_textureB:1,value:l,texSize:[c,d],time:m}).draw(e)});this.setOutputData(0,this._tex)}}};s.pixel_shader="precision highp float;\n\t\t\t\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform sampler2D u_textureB;\n\t\t\tvarying vec2 v_coord;\n\t\t\tuniform vec2 texSize;\n\t\t\tuniform float time;\n\t\t\tuniform float value;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec2 uv = v_coord;\n\t\t\t\t{{UV_CODE}};\n\t\t\t\tvec4 color4 = texture2D(u_texture, uv);\n\t\t\t\tvec3 color = color4.rgb;\n\t\t\t\tvec4 color4B = texture2D(u_textureB, uv);\n\t\t\t\tvec3 colorB = color4B.rgb;\n\t\t\t\tvec3 result = color;\n\t\t\t\tfloat alpha = 1.0;\n\t\t\t\t{{PIXEL_CODE}};\n\t\t\t\tgl_FragColor = vec4(result, alpha);\n\t\t\t}\n\t\t\t";
e.registerNodeType("texture/operation",s);var f=function(){this.addOutput("out","Texture");this.properties={code:"",width:512,height:512,precision:h.DEFAULT};this.properties.code="\nvoid main() {\n vec2 uv = v_coord;\n vec3 color = vec3(0.0);\n//your code here\n\ngl_FragColor = vec4(color, 1.0);\n}\n";this._uniforms={in_texture:0,texSize:vec2.create(),time:0}};f.title="Shader";f.desc="Texture shader";f.widgets_info={code:{type:"code"},precision:{widget:"combo",values:h.MODE_VALUES}};f.prototype.onPropertyChanged=
function(a,b){if("code"==a){var c=this.getShader();if(c){var d=c.uniformInfo;if(this.inputs)for(var e={},g=0;g<this.inputs.length;++g){var f=this.getInputInfo(g);f&&(d[f.name]&&!e[f.name]?e[f.name]=!0:(this.removeInput(g),g--))}for(g in d)if(f=c.uniformInfo[g],null!==f.loc&&"time"!=g){d="number";if(this._shader.samplers[g])d="texture";else switch(f.size){case 1:d="number";break;case 2:d="vec2";break;case 3:d="vec3";break;case 4:d="vec4";break;case 9:d="mat3";break;case 16:d="mat4";break;default:continue}f=
this.findInputSlot(g);-1==f?this.addInput(g,d):(e=this.getInputInfo(f),e)?e.type!=d&&(this.removeInput(f,d),this.addInput(g,d)):this.addInput(g,d)}}}};f.prototype.getShader=function(){if(this._shader&&this._shader_code==this.properties.code)return this._shader;this._shader_code=this.properties.code;if(this._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,f.pixel_shader+this.properties.code))this.boxcolor="green";else return this.boxcolor="red",null;return this._shader};f.prototype.onExecute=function(){if(this.isOutputConnected(0)){var a=
@@ -413,10 +414,11 @@ precision:h.DEFAULT}};m.title="Copy";m.desc="Copy Texture";m.widgets_info={size:
m);var z=function(){this.addInput("Texture","Texture");this.addOutput("","Texture");this.properties={iterations:1,generate_mipmaps:!1,precision:h.DEFAULT}};z.title="Downsample";z.desc="Downsample Texture";z.widgets_info={iterations:{type:"number",step:1,precision:0,min:0},precision:{widget:"combo",values:h.MODE_VALUES}};z.prototype.onExecute=function(){var a=this.getInputData(0);if((a||this._temp_texture)&&this.isOutputConnected(0)&&a&&a.texture_type===GL.TEXTURE_2D)if(1>this.properties.iterations)this.setOutputData(0,
a);else{var b=z._shader;b||(z._shader=b=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,z.pixel_shader));var c=a.width|0,d=a.height|0,e=a.type;this.properties.precision===h.LOW?e=gl.UNSIGNED_BYTE:this.properties.precision===h.HIGH&&(e=gl.HIGH_PRECISION_FORMAT);var g=this.properties.iterations||1,f=a,k=null,q=[],a={type:e,format:a.format},e=vec2.create(),l={u_offset:e};this._texture&&GL.Texture.releaseTemporary(this._texture);for(var m=0;m<g;++m){e[0]=1/c;e[1]=1/d;c=c>>1||0;d=d>>1||0;k=GL.Texture.getTemporary(c,
d,a);q.push(k);f.setParameter(GL.TEXTURE_MAG_FILTER,GL.NEAREST);f.copyTo(k,b,l);if(1==c&&1==d)break;f=k}this._texture=q.pop();for(m=0;m<q.length;++m)GL.Texture.releaseTemporary(q[m]);this.properties.generate_mipmaps&&(this._texture.bind(0),gl.generateMipmap(this._texture.texture_type),this._texture.unbind(0));this.setOutputData(0,this._texture)}};z.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform vec2 u_offset;\n\t\t\tvarying vec2 v_coord;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec4 color = texture2D(u_texture, v_coord );\n\t\t\t\tcolor += texture2D(u_texture, v_coord + vec2( u_offset.x, 0.0 ) );\n\t\t\t\tcolor += texture2D(u_texture, v_coord + vec2( 0.0, u_offset.y ) );\n\t\t\t\tcolor += texture2D(u_texture, v_coord + vec2( u_offset.x, u_offset.y ) );\n\t\t\t gl_FragColor = color * 0.25;\n\t\t\t}\n\t\t\t";
e.registerNodeType("texture/downsample",z);var c=function(){this.addInput("Texture","Texture");this.addOutput("tex","Texture");this.addOutput("avg","vec4");this.addOutput("lum","number");this.properties={use_previous_frame:!0,mipmap_offset:0,low_precision:!1};this._uniforms={u_texture:0,u_mipmap_offset:this.properties.mipmap_offset};this._luminance=new Float32Array(4)};c.title="Average";c.desc="Compute a partial average (32 random samples) of a texture and stores it as a 1x1 pixel texture";c.prototype.onExecute=
function(){this.properties.use_previous_frame||this.updateAverage();var a=this._luminance;this.setOutputData(0,this._temp_texture);this.setOutputData(1,a);this.setOutputData(2,(a[0]+a[1]+a[2])/3)};c.prototype.onPreRenderExecute=function(){this.updateAverage()};c.prototype.updateAverage=function(){var a=this.getInputData(0);if(a&&(this.isOutputConnected(0)||this.isOutputConnected(1)||this.isOutputConnected(2))){if(!c._shader){c._shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,c.pixel_shader);for(var b=
new Float32Array(16),d=0;d<b.length;++d)b[d]=Math.random();c._shader.uniforms({u_samples_a:b.subarray(0,16),u_samples_b:b.subarray(16,32)})}d=this._temp_texture;b=gl.UNSIGNED_BYTE;a.type!=b&&(b=gl.FLOAT);d&&d.type==b||(this._temp_texture=new GL.Texture(1,1,{type:b,format:gl.RGBA,filter:gl.NEAREST}));var e=c._shader,g=this._uniforms;g.u_mipmap_offset=this.properties.mipmap_offset;gl.disable(gl.DEPTH_TEST);gl.disable(gl.BLEND);this._temp_texture.drawTo(function(){a.toViewport(e,g)});if(this.isOutputConnected(1)||
this.isOutputConnected(2))if(d=this._temp_texture.getPixels()){var f=this._luminance,b=this._temp_texture.type;f.set(d);b==gl.UNSIGNED_BYTE&&vec4.scale(f,f,1/255)}}};c.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tuniform mat4 u_samples_a;\n\t\t\tuniform mat4 u_samples_b;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform float u_mipmap_offset;\n\t\t\tvarying vec2 v_coord;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec4 color = vec4(0.0);\n\t\t\t\t//random average\n\t\t\t\tfor(int i = 0; i <= 4; ++i)\n\t\t\t\t\tfor(int j = 0; j <= 4; ++j)\n\t\t\t\t\t{\n\t\t\t\t\t\tcolor += texture2D(u_texture, vec2( u_samples_a[i][j], u_samples_b[i][j] ), u_mipmap_offset );\n\t\t\t\t\t\tcolor += texture2D(u_texture, vec2( 1.0 - u_samples_a[i][j], 1.0 - u_samples_b[i][j] ), u_mipmap_offset );\n\t\t\t\t\t}\n\t\t\t gl_FragColor = color * 0.03125;\n\t\t\t}\n\t\t\t";
e.registerNodeType("texture/downsample",z);var c=function(){this.addInput("Texture","Texture");this.addOutput("tex","Texture");this.addOutput("avg","vec4");this.addOutput("lum","number");this.properties={use_previous_frame:!0,high_quality:!1};this._uniforms={u_texture:0,u_mipmap_offset:0};this._luminance=new Float32Array(4)};c.title="Average";c.desc="Compute a partial average (32 random samples) of a texture and stores it as a 1x1 pixel texture";c.prototype.onExecute=function(){this.properties.use_previous_frame||
this.updateAverage();var a=this._luminance;this.setOutputData(0,this._temp_texture);this.setOutputData(1,a);this.setOutputData(2,(a[0]+a[1]+a[2])/3)};c.prototype.onPreRenderExecute=function(){this.updateAverage()};c.prototype.updateAverage=function(){var a=this.getInputData(0);if(a&&(this.isOutputConnected(0)||this.isOutputConnected(1)||this.isOutputConnected(2))){if(!c._shader){c._shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,c.pixel_shader);for(var b=new Float32Array(16),d=0;d<b.length;++d)b[d]=
Math.random();c._shader.uniforms({u_samples_a:b.subarray(0,16),u_samples_b:b.subarray(16,32)})}d=this._temp_texture;b=gl.UNSIGNED_BYTE;a.type!=b&&(b=gl.FLOAT);d&&d.type==b||(this._temp_texture=new GL.Texture(1,1,{type:b,format:gl.RGBA,filter:gl.NEAREST}));this._uniforms.u_mipmap_offset=0;this.properties.high_quality&&(this._temp_pot2_texture&&this._temp_pot2_texture.type==b||(this._temp_pot2_texture=new GL.Texture(512,512,{type:b,format:gl.RGBA,minFilter:gl.LINEAR_MIPMAP_LINEAR,magFilter:gl.LINEAR})),
a.copyTo(this._temp_pot2_texture),a=this._temp_pot2_texture,a.bind(0),gl.generateMipmap(GL_TEXTURE_2D),this._uniforms.u_mipmap_offset=9);var e=c._shader,g=this._uniforms;g.u_mipmap_offset=this.properties.mipmap_offset;gl.disable(gl.DEPTH_TEST);gl.disable(gl.BLEND);this._temp_texture.drawTo(function(){a.toViewport(e,g)});if(this.isOutputConnected(1)||this.isOutputConnected(2))if(d=this._temp_texture.getPixels()){var f=this._luminance,b=this._temp_texture.type;f.set(d);b==gl.UNSIGNED_BYTE&&vec4.scale(f,
f,1/255)}}};c.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tuniform mat4 u_samples_a;\n\t\t\tuniform mat4 u_samples_b;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform float u_mipmap_offset;\n\t\t\tvarying vec2 v_coord;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvec4 color = vec4(0.0);\n\t\t\t\t//random average\n\t\t\t\tfor(int i = 0; i < 4; ++i)\n\t\t\t\t\tfor(int j = 0; j < 4; ++j)\n\t\t\t\t\t{\n\t\t\t\t\t\tcolor += texture2D(u_texture, vec2( u_samples_a[i][j], u_samples_b[i][j] ), u_mipmap_offset );\n\t\t\t\t\t\tcolor += texture2D(u_texture, vec2( 1.0 - u_samples_a[i][j], 1.0 - u_samples_b[i][j] ), u_mipmap_offset );\n\t\t\t\t\t}\n\t\t\t gl_FragColor = color * 0.03125;\n\t\t\t}\n\t\t\t";
e.registerNodeType("texture/average",c);var x=function(){this.addInput("in","Texture");this.addInput("factor","Number");this.addOutput("out","Texture");this.properties={factor:0.5};this._uniforms={u_texture:0,u_textureB:1,u_factor:this.properties.factor}};x.title="Smooth";x.desc="Smooth texture over time";x.prototype.onExecute=function(){var a=this.getInputData(0);if(a&&this.isOutputConnected(0)){x._shader||(x._shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,x.pixel_shader));var b=this._temp_texture;
b&&b.type==a.type&&b.width==a.width&&b.height==a.height||(this._temp_texture=new GL.Texture(a.width,a.height,{type:a.type,format:gl.RGBA,filter:gl.NEAREST}),this._temp_texture2=new GL.Texture(a.width,a.height,{type:a.type,format:gl.RGBA,filter:gl.NEAREST}),a.copyTo(this._temp_texture2));var b=this._temp_texture,c=this._temp_texture2,d=x._shader,e=this._uniforms;e.u_factor=1-this.getInputOrProperty("factor");gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);b.drawTo(function(){c.bind(1);a.toViewport(d,
e)});this.setOutputData(0,b);this._temp_texture=c;this._temp_texture2=b}};x.pixel_shader="precision highp float;\n\t\t\tprecision highp float;\n\t\t\tuniform sampler2D u_texture;\n\t\t\tuniform sampler2D u_textureB;\n\t\t\tuniform float u_factor;\n\t\t\tvarying vec2 v_coord;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tgl_FragColor = mix( texture2D( u_texture, v_coord ), texture2D( u_textureB, v_coord ), u_factor );\n\t\t\t}\n\t\t\t";e.registerNodeType("texture/temporal_smooth",x);m=function(){this.addInput("Image",