kenryu 0.2.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- kenryu-0.2.1.dist-info/METADATA +72 -0
- kenryu-0.2.1.dist-info/RECORD +17 -0
- kenryu-0.2.1.dist-info/WHEEL +5 -0
- kenryu-0.2.1.dist-info/entry_points.txt +3 -0
- kenryu-0.2.1.dist-info/top_level.txt +1 -0
- nagare/__init__.py +15 -0
- nagare/__main__.py +70 -0
- nagare/engine.py +221 -0
- nagare/preview.py +54 -0
- nagare/registry.py +239 -0
- nagare/server.py +168 -0
- nagare/static/app.css +59 -0
- nagare/static/app.js +473 -0
- nagare/static/index.html +39 -0
- nagare/static/vendor/LITEGRAPH-LICENSE +19 -0
- nagare/static/vendor/litegraph.core.min.js +342 -0
- nagare/static/vendor/litegraph.css +680 -0
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
(function(X){function w(a){h.debug&&console.log("Graph created");this.list_of_graphcanvas=null;this.clear();a&&this.configure(a)}function Y(a,b,c,d,e,f){this.id=a;this.type=b;this.origin_id=c;this.origin_slot=d;this.target_id=e;this.target_slot=f;this._data=null;this._pos=new Float32Array(2)}function v(a){this._ctor(a)}function P(a){this._ctor(a)}function L(a,b){this.offset=new Float32Array([0,0]);this.scale=1;this.max_scale=10;this.min_scale=.1;this.onredraw=null;this.enabled=!0;this.last_mouse=
|
|
2
|
+
[0,0];this.element=null;this.visible_area=new Float32Array(4);a&&(this.element=a,b||this.bindEvents(a))}function q(a,b,c){this.options=c=c||{};this.background_image=q.DEFAULT_BACKGROUND_IMAGE;a&&a.constructor===String&&(a=document.querySelector(a));this.ds=new L;this.zoom_modify_alpha=!0;this.title_text_font=""+h.NODE_TEXT_SIZE+"px Arial";this.inner_text_font="normal "+h.NODE_SUBTEXT_SIZE+"px Arial";this.node_title_color=h.NODE_TITLE_COLOR;this.default_link_color=h.LINK_COLOR;this.default_connection_color=
|
|
3
|
+
{input_off:"#778",input_on:"#7F7",output_off:"#778",output_on:"#7F7"};this.default_connection_color_byType={};this.default_connection_color_byTypeOff={};this.highquality_render=!0;this.use_gradients=!1;this.editor_alpha=1;this.pause_rendering=!1;this.clear_background=!0;this.clear_background_color="#222";this.read_only=!1;this.render_only_selected=!0;this.live_mode=!1;this.allow_interaction=this.allow_dragnodes=this.allow_dragcanvas=this.show_info=!0;this.multi_select=!1;this.allow_reconnect_links=
|
|
4
|
+
this.allow_searchbox=!0;this.drag_mode=this.align_to_grid=!1;this.filter=this.dragging_rectangle=null;this.set_canvas_dirty_on_mouse_event=!0;this.always_render_background=!1;this.render_canvas_border=this.render_shadows=!0;this.render_connections_shadows=!1;this.render_connections_border=!0;this.render_connection_arrows=this.render_curved_connections=!1;this.render_collapsed_slots=!0;this.render_execution_order=!1;this.render_link_tooltip=this.render_title_colored=!0;this.links_render_mode=h.SPLINE_LINK;
|
|
5
|
+
this.mouse=[0,0];this.canvas_mouse=this.graph_mouse=[0,0];this.onAfterChange=this.onBeforeChange=this.onConnectingChange=this.onSelectionChange=this.onNodeMoved=this.onDrawLinkTooltip=this.onDrawOverlay=this.onDrawForeground=this.onDrawBackground=this.onMouse=this.onSearchBoxSelection=this.onSearchBox=null;this.connections_width=3;this.round_radius=8;this.over_link_center=this.node_widget=this.current_node=null;this.last_mouse_position=[0,0];this.visible_area=this.ds.visible_area;this.visible_links=
|
|
6
|
+
[];this.viewport=c.viewport||null;b&&b.attachCanvas(this);this.setCanvas(a,c.skip_events);this.clear();c.skip_render||this.startRendering();this.autoresize=c.autoresize}function ba(a,b){return Math.sqrt((b[0]-a[0])*(b[0]-a[0])+(b[1]-a[1])*(b[1]-a[1]))}function K(a,b,c,d,e,f){return c<a&&c+e>a&&d<b&&d+f>b?!0:!1}function Z(a,b){var c=a[0]+a[2],d=a[1]+a[3],e=b[1]+b[3];return a[0]>b[0]+b[2]||a[1]>e||c<b[0]||d<b[1]?!1:!0}function Q(a,b){function c(m){var l=parseInt(f.style.top);f.style.top=(l+m.deltaY*
|
|
7
|
+
b.scroll_speed).toFixed()+"px";m.preventDefault();return!0}this.options=b=b||{};var d=this;b.parentMenu&&(b.parentMenu.constructor!==this.constructor?(console.error("parentMenu must be of class ContextMenu, ignoring it"),b.parentMenu=null):(this.parentMenu=b.parentMenu,this.parentMenu.lock=!0,this.parentMenu.current_submenu=this));var e=null;b.event&&(e=b.event.constructor.name);"MouseEvent"!==e&&"CustomEvent"!==e&&"PointerEvent"!==e&&(console.error("Event passed to ContextMenu is not of type MouseEvent or CustomEvent. Ignoring it. ("+
|
|
8
|
+
e+")"),b.event=null);var f=document.createElement("div");f.className="litegraph litecontextmenu litemenubar-panel";b.className&&(f.className+=" "+b.className);f.style.minWidth=100;f.style.minHeight=100;f.style.pointerEvents="none";setTimeout(function(){f.style.pointerEvents="auto"},100);h.pointerListenerAdd(f,"up",function(m){m.preventDefault();return!0},!0);f.addEventListener("contextmenu",function(m){if(2!=m.button)return!1;m.preventDefault();return!1},!0);h.pointerListenerAdd(f,"down",function(m){if(2==
|
|
9
|
+
m.button)return d.close(),m.preventDefault(),!0},!0);b.scroll_speed||(b.scroll_speed=.1);f.addEventListener("wheel",c,!0);f.addEventListener("mousewheel",c,!0);this.root=f;b.title&&(e=document.createElement("div"),e.className="litemenu-title",e.innerHTML=b.title,f.appendChild(e));for(var g=e=0;g<a.length;g++){var k=a.constructor==Array?a[g]:g;null!=k&&k.constructor!==String&&(k=void 0===k.content?String(k):k.content);this.addItem(k,a[g],b);e++}h.pointerListenerAdd(f,"enter",function(m){f.closing_timer&&
|
|
10
|
+
clearTimeout(f.closing_timer)});a=document;b.event&&(a=b.event.target.ownerDocument);a||=document;a.fullscreenElement?a.fullscreenElement.appendChild(f):a.body.appendChild(f);e=b.left||0;a=b.top||0;b.event&&(e=b.event.clientX-10,a=b.event.clientY-10,b.title&&(a-=20),b.parentMenu&&(e=b.parentMenu.root.getBoundingClientRect(),e=e.left+e.width),g=document.body.getBoundingClientRect(),k=f.getBoundingClientRect(),0==g.height&&console.error("document.body height is 0. That is dangerous, set html,body { height: 100%; }"),
|
|
11
|
+
g.width&&e>g.width-k.width-10&&(e=g.width-k.width-10),g.height&&a>g.height-k.height-10&&(a=g.height-k.height-10));f.style.left=e+"px";f.style.top=a+"px";b.scale&&(f.style.transform="scale("+b.scale+")")}function T(a){this.points=a;this.nearest=this.selected=-1;this.size=null;this.must_update=!0;this.margin=5}function ca(a,b,c){return b>a?b:c<a?c:a}var h=X.LiteGraph={VERSION:.4,CANVAS_GRID_SIZE:10,NODE_TITLE_HEIGHT:30,NODE_TITLE_TEXT_Y:20,NODE_SLOT_HEIGHT:20,NODE_WIDGET_HEIGHT:20,NODE_WIDTH:140,NODE_MIN_WIDTH:50,
|
|
12
|
+
NODE_COLLAPSED_RADIUS:10,NODE_COLLAPSED_WIDTH:80,NODE_TITLE_COLOR:"#999",NODE_SELECTED_TITLE_COLOR:"#FFF",NODE_TEXT_SIZE:14,NODE_TEXT_COLOR:"#AAA",NODE_SUBTEXT_SIZE:12,NODE_DEFAULT_COLOR:"#333",NODE_DEFAULT_BGCOLOR:"#353535",NODE_DEFAULT_BOXCOLOR:"#666",NODE_DEFAULT_SHAPE:"box",NODE_BOX_OUTLINE_COLOR:"#FFF",DEFAULT_SHADOW_COLOR:"rgba(0,0,0,0.5)",DEFAULT_GROUP_FONT:24,WIDGET_BGCOLOR:"#222",WIDGET_OUTLINE_COLOR:"#666",WIDGET_TEXT_COLOR:"#DDD",WIDGET_SECONDARY_TEXT_COLOR:"#999",LINK_COLOR:"#9A9",EVENT_LINK_COLOR:"#A86",
|
|
13
|
+
CONNECTING_LINK_COLOR:"#AFA",MAX_NUMBER_OF_NODES:1E3,DEFAULT_POSITION:[100,100],VALID_SHAPES:["default","box","round","card"],BOX_SHAPE:1,ROUND_SHAPE:2,CIRCLE_SHAPE:3,CARD_SHAPE:4,ARROW_SHAPE:5,GRID_SHAPE:6,INPUT:1,OUTPUT:2,EVENT:-1,ACTION:-1,NODE_MODES:["Always","On Event","Never","On Trigger"],NODE_MODES_COLORS:["#666","#422","#333","#224","#626"],ALWAYS:0,ON_EVENT:1,NEVER:2,ON_TRIGGER:3,UP:1,DOWN:2,LEFT:3,RIGHT:4,CENTER:5,LINK_RENDER_MODES:["Straight","Linear","Spline"],STRAIGHT_LINK:0,LINEAR_LINK:1,
|
|
14
|
+
SPLINE_LINK:2,NORMAL_TITLE:0,NO_TITLE:1,TRANSPARENT_TITLE:2,AUTOHIDE_TITLE:3,VERTICAL_LAYOUT:"vertical",proxy:null,node_images_path:"",debug:!1,catch_exceptions:!0,throw_errors:!0,allow_scripts:!1,use_deferred_actions:!0,registered_node_types:{},node_types_by_file_extension:{},Nodes:{},Globals:{},searchbox_extras:{},auto_sort_node_types:!1,node_box_coloured_when_on:!1,node_box_coloured_by_mode:!1,dialog_close_on_mouse_leave:!0,dialog_close_on_mouse_leave_delay:500,shift_click_do_break_link_from:!1,
|
|
15
|
+
click_do_break_link_to:!1,search_hide_on_mouse_leave:!0,search_filter_enabled:!1,search_show_all_on_open:!0,auto_load_slot_types:!1,registered_slot_in_types:{},registered_slot_out_types:{},slot_types_in:[],slot_types_out:[],slot_types_default_in:[],slot_types_default_out:[],alt_drag_do_clone_nodes:!1,do_add_triggers_slots:!1,allow_multi_output_for_events:!0,middle_click_slot_add_default_node:!1,release_link_on_empty_shows_menu:!1,pointerevents_method:"mouse",ctrl_shift_v_paste_connect_unselected_outputs:!1,
|
|
16
|
+
use_uuids:!1,registerNodeType:function(a,b){if(!b.prototype)throw"Cannot register a simple object, it must be a class with a prototype";b.type=a;h.debug&&console.log("Node registered: "+a);const c=b.name;var d=a.lastIndexOf("/");b.category=a.substring(0,d);b.title||(b.title=c);for(var e in v.prototype)b.prototype[e]||(b.prototype[e]=v.prototype[e]);(d=this.registered_node_types[a])&&console.log("replacing node type: "+a);if(!Object.prototype.hasOwnProperty.call(b.prototype,"shape")&&(Object.defineProperty(b.prototype,
|
|
17
|
+
"shape",{set:function(f){switch(f){case "default":delete this._shape;break;case "box":this._shape=h.BOX_SHAPE;break;case "round":this._shape=h.ROUND_SHAPE;break;case "circle":this._shape=h.CIRCLE_SHAPE;break;case "card":this._shape=h.CARD_SHAPE;break;default:this._shape=f}},get:function(){return this._shape},enumerable:!0,configurable:!0}),b.supported_extensions))for(let f in b.supported_extensions)(e=b.supported_extensions[f])&&e.constructor===String&&(this.node_types_by_file_extension[e.toLowerCase()]=
|
|
18
|
+
b);this.registered_node_types[a]=b;b.constructor.name&&(this.Nodes[c]=b);if(h.onNodeTypeRegistered)h.onNodeTypeRegistered(a,b);if(d&&h.onNodeTypeReplaced)h.onNodeTypeReplaced(a,b,d);b.prototype.onPropertyChange&&console.warn("LiteGraph node class "+a+" has onPropertyChange method, it must be called onPropertyChanged with d at the end");this.auto_load_slot_types&&new b(b.title||"tmpnode")},unregisterNodeType:function(a){const b=a.constructor===String?this.registered_node_types[a]:a;if(!b)throw"node type not found: "+
|
|
19
|
+
a;delete this.registered_node_types[b.type];b.constructor.name&&delete this.Nodes[b.constructor.name]},registerNodeAndSlotType:function(a,b,c){c=c||!1;a=(a.constructor===String&&"anonymous"!==this.registered_node_types[a]?this.registered_node_types[a]:a).constructor.type;b="string"===typeof b?b.split(","):b==this.EVENT||b==this.ACTION?["_event_"]:["*"];for(let d=0;d<b.length;++d){let e=b[d];""===e&&(e="*");const f=c?"registered_slot_out_types":"registered_slot_in_types";void 0===this[f][e]&&(this[f][e]=
|
|
20
|
+
{nodes:[]});this[f][e].nodes.includes(a)||this[f][e].nodes.push(a);c?this.slot_types_out.includes(e.toLowerCase())||(this.slot_types_out.push(e.toLowerCase()),this.slot_types_out.sort()):this.slot_types_in.includes(e.toLowerCase())||(this.slot_types_in.push(e.toLowerCase()),this.slot_types_in.sort())}},buildNodeClassFromObject:function(a,b){var c="";if(b.inputs)for(var d=0;d<b.inputs.length;++d){var e=b.inputs[d][0],f=b.inputs[d][1];f&&f.constructor===String&&(f='"'+f+'"');c+="this.addInput('"+e+
|
|
21
|
+
"',"+f+");\n"}if(b.outputs)for(d=0;d<b.outputs.length;++d)e=b.outputs[d][0],(f=b.outputs[d][1])&&f.constructor===String&&(f='"'+f+'"'),c+="this.addOutput('"+e+"',"+f+");\n";if(b.properties)for(d in b.properties)(e=b.properties[d])&&e.constructor===String&&(e='"'+e+'"'),c+="this.addProperty('"+d+"',"+e+");\n";c=Function(c+"if(this.onCreate)this.onCreate()");for(d in b)"inputs"!=d&&"outputs"!=d&&"properties"!=d&&(c.prototype[d]=b[d]);c.title=b.title||a.split("/").pop();c.desc=b.desc||"Generated from object";
|
|
22
|
+
this.registerNodeType(a,c);return c},wrapFunctionAsNode:function(a,b,c,d,e){var f=Array(b.length),g="";if(null!==c)for(var k=h.getParameterNames(b),m=0;m<k.length;++m){var l=0;c&&(null!=c[m]&&c[m].constructor===String?l="'"+c[m]+"'":null!=c[m]&&(l=c[m]));g+="this.addInput('"+k[m]+"',"+l+");\n"}null!==d&&(g+="this.addOutput('out',"+(null!=d?d.constructor===String?"'"+d+"'":d:0)+");\n");e&&(g+="this.properties = "+JSON.stringify(e)+";\n");c=Function(g);c.title=a.split("/").pop();c.desc="Generated from "+
|
|
23
|
+
b.name;c.prototype.onExecute=function(){for(var n=0;n<f.length;++n)f[n]=this.getInputData(n);n=b.apply(this,f);this.setOutputData(0,n)};this.registerNodeType(a,c);return c},clearRegisteredTypes:function(){this.registered_node_types={};this.node_types_by_file_extension={};this.Nodes={};this.searchbox_extras={}},addNodeMethod:function(a,b){v.prototype[a]=b;for(var c in this.registered_node_types){var d=this.registered_node_types[c];d.prototype[a]&&(d.prototype["_"+a]=d.prototype[a]);d.prototype[a]=
|
|
24
|
+
b}},createNode:function(a,b,c){var d=this.registered_node_types[a];if(!d)return h.debug&&console.log('GraphNode type "'+a+'" not registered.'),null;b=b||d.title||a;var e=null;if(h.catch_exceptions)try{e=new d(b)}catch(g){return console.error(g),null}else e=new d(b);e.type=a;!e.title&&b&&(e.title=b);e.properties||(e.properties={});e.properties_info||(e.properties_info=[]);e.flags||(e.flags={});e.size||(e.size=e.computeSize());e.pos||(e.pos=h.DEFAULT_POSITION.concat());e.mode||(e.mode=h.ALWAYS);if(c)for(var f in c)e[f]=
|
|
25
|
+
c[f];if(e.onNodeCreated)e.onNodeCreated();return e},getNodeType:function(a){return this.registered_node_types[a]},getNodeTypesInCategory:function(a,b){var c=[],d;for(d in this.registered_node_types){var e=this.registered_node_types[d];e.filter==b&&(""==a?null==e.category&&c.push(e):e.category==a&&c.push(e))}this.auto_sort_node_types&&c.sort(function(f,g){return f.title.localeCompare(g.title)});return c},getNodeTypesCategories:function(a){var b={"":1},c;for(c in this.registered_node_types){var d=this.registered_node_types[c];
|
|
26
|
+
d.category&&!d.skip_list&&d.filter==a&&(b[d.category]=1)}a=[];for(c in b)a.push(c);return this.auto_sort_node_types?a.sort():a},reloadNodes:function(a){for(var b=document.getElementsByTagName("script"),c=[],d=0;d<b.length;d++)c.push(b[d]);b=document.getElementsByTagName("head")[0];a=document.location.href+a;for(d=0;d<c.length;d++){var e=c[d].src;if(e&&e.substr(0,a.length)==a)try{h.debug&&console.log("Reloading: "+e);var f=document.createElement("script");f.type="text/javascript";f.src=e;b.appendChild(f);
|
|
27
|
+
b.removeChild(c[d])}catch(g){if(h.throw_errors)throw g;h.debug&&console.log("Error while reloading "+e)}}h.debug&&console.log("Nodes reloaded")},cloneObject:function(a,b){if(null==a)return null;a=JSON.parse(JSON.stringify(a));if(!b)return a;for(var c in a)b[c]=a[c];return b},uuidv4:function(){return"10000000-1000-4000-8000-100000000000".replace(/[018]/g,a=>(a^16*Math.random()>>a/4).toString(16))},isValidConnection:function(a,b){if(""==a||"*"===a)a=0;if(""==b||"*"===b)b=0;if(!a||!b||a==b||a==h.EVENT&&
|
|
28
|
+
b==h.ACTION)return!0;a=String(a);b=String(b);a=a.toLowerCase();b=b.toLowerCase();if(-1==a.indexOf(",")&&-1==b.indexOf(","))return a==b;a=a.split(",");b=b.split(",");for(var c=0;c<a.length;++c)for(var d=0;d<b.length;++d)if(this.isValidConnection(a[c],b[d]))return!0;return!1},registerSearchboxExtra:function(a,b,c){this.searchbox_extras[b.toLowerCase()]={type:a,desc:b,data:c}},fetchFile:function(a,b,c,d){if(!a)return null;b=b||"text";if(a.constructor===String)return"http"==a.substr(0,4)&&h.proxy&&(a=
|
|
29
|
+
h.proxy+a.substr(a.indexOf(":")+3)),fetch(a).then(function(f){if(!f.ok)throw Error("File not found");if("arraybuffer"==b)return f.arrayBuffer();if("text"==b||"string"==b)return f.text();if("json"==b)return f.json();if("blob"==b)return f.blob()}).then(function(f){c&&c(f)}).catch(function(f){console.error("error fetching file:",a);d&&d(f)});if(a.constructor===File||a.constructor===Blob){var e=new FileReader;e.onload=function(f){f=f.target.result;"json"==b&&(f=JSON.parse(f));c&&c(f)};if("arraybuffer"==
|
|
30
|
+
b)return e.readAsArrayBuffer(a);if("text"==b||"json"==b)return e.readAsText(a);if("blob"==b)return e.readAsBinaryString(a)}return null}};h.getTime="undefined"!=typeof performance?performance.now.bind(performance):"undefined"!=typeof Date&&Date.now?Date.now.bind(Date):"undefined"!=typeof process?function(){var a=process.hrtime();return.001*a[0]+1E-6*a[1]}:function(){return(new Date).getTime()};X.LGraph=h.LGraph=w;w.supported_types=["number","string","boolean"];w.prototype.getSupportedTypes=function(){return this.supported_types||
|
|
31
|
+
w.supported_types};w.STATUS_STOPPED=1;w.STATUS_RUNNING=2;w.prototype.clear=function(){this.stop();this.status=w.STATUS_STOPPED;this.last_link_id=this.last_node_id=0;this._version=-1;if(this._nodes)for(var a=0;a<this._nodes.length;++a){var b=this._nodes[a];if(b.onRemoved)b.onRemoved()}this._nodes=[];this._nodes_by_id={};this._nodes_in_order=[];this._nodes_executable=null;this._groups=[];this.links={};this.iteration=0;this.config={};this.vars={};this.extra={};this.fixedtime=this.runningtime=this.globaltime=
|
|
32
|
+
0;this.elapsed_time=this.fixedtime_lapse=.01;this.starttime=this.last_update_time=0;this.catch_errors=!0;this.nodes_executing=[];this.nodes_actioning=[];this.nodes_executedAction=[];this.inputs={};this.outputs={};this.change();this.sendActionToCanvas("clear")};w.prototype.attachCanvas=function(a){if(a.constructor!=q)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)};
|
|
33
|
+
w.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))}};w.prototype.start=function(a){if(this.status!=w.STATUS_RUNNING){this.status=w.STATUS_RUNNING;if(this.onPlayEvent)this.onPlayEvent();this.sendEventToAllNodes("onStart");this.last_update_time=this.starttime=h.getTime();a=a||0;var b=this;if(0==a&&"undefined"!=typeof window&&window.requestAnimationFrame){function c(){if(-1==b.execution_timer_id){window.requestAnimationFrame(c);
|
|
34
|
+
if(b.onBeforeStep)b.onBeforeStep();b.runStep(1,!b.catch_errors);if(b.onAfterStep)b.onAfterStep()}}this.execution_timer_id=-1;c()}else this.execution_timer_id=setInterval(function(){if(b.onBeforeStep)b.onBeforeStep();b.runStep(1,!b.catch_errors);if(b.onAfterStep)b.onAfterStep()},a)}};w.prototype.stop=function(){if(this.status!=w.STATUS_STOPPED){this.status=w.STATUS_STOPPED;if(this.onStopEvent)this.onStopEvent();null!=this.execution_timer_id&&(-1!=this.execution_timer_id&&clearInterval(this.execution_timer_id),
|
|
35
|
+
this.execution_timer_id=null);this.sendEventToAllNodes("onStop")}};w.prototype.runStep=function(a,b,c){a=a||1;var d=h.getTime();this.globaltime=.001*(d-this.starttime);var e=this._nodes_executable?this._nodes_executable:this._nodes;if(e){c=c||e.length;if(b){for(var f=0;f<a;f++){for(var g=0;g<c;++g){var k=e[g];h.use_deferred_actions&&k._waiting_actions&&k._waiting_actions.length&&k.executePendingActions();k.mode==h.ALWAYS&&k.onExecute&&k.doExecute()}this.fixedtime+=this.fixedtime_lapse;if(this.onExecuteStep)this.onExecuteStep()}if(this.onAfterExecute)this.onAfterExecute()}else try{for(f=
|
|
36
|
+
0;f<a;f++){for(g=0;g<c;++g)if(k=e[g],h.use_deferred_actions&&k._waiting_actions&&k._waiting_actions.length&&k.executePendingActions(),k.mode==h.ALWAYS&&k.onExecute)k.onExecute();this.fixedtime+=this.fixedtime_lapse;if(this.onExecuteStep)this.onExecuteStep()}if(this.onAfterExecute)this.onAfterExecute();this.errors_in_execution=!1}catch(m){this.errors_in_execution=!0;if(h.throw_errors)throw m;h.debug&&console.log("Error during execution: "+m);this.stop()}a=h.getTime();d=a-d;0==d&&(d=1);this.execution_time=
|
|
37
|
+
.001*d;this.globaltime+=.001*d;this.iteration+=1;this.elapsed_time=.001*(a-this.last_update_time);this.last_update_time=a;this.nodes_executing=[];this.nodes_actioning=[];this.nodes_executedAction=[]}};w.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])};w.prototype.computeExecutionOrder=function(a,
|
|
38
|
+
b){for(var c=[],d=[],e={},f={},g={},k=0,m=this._nodes.length;k<m;++k){var l=this._nodes[k];if(!a||l.onExecute){e[l.id]=l;var n=0;if(l.inputs)for(var p=0,r=l.inputs.length;p<r;p++)l.inputs[p]&&null!=l.inputs[p].link&&(n+=1);0==n?(d.push(l),b&&(l._level=1)):(b&&(l._level=0),g[l.id]=n)}}for(;0!=d.length;)if(l=d.shift(),c.push(l),delete e[l.id],l.outputs)for(k=0;k<l.outputs.length;k++)if(a=l.outputs[k],null!=a&&null!=a.links&&0!=a.links.length)for(p=0;p<a.links.length;p++)(m=this.links[a.links[p]])&&
|
|
39
|
+
!f[m.id]&&(n=this.getNodeById(m.target_id),null==n?f[m.id]=!0:(b&&(!n._level||n._level<=l._level)&&(n._level=l._level+1),f[m.id]=!0,--g[n.id],0==g[n.id]&&d.push(n)));for(k in e)c.push(e[k]);c.length!=this._nodes.length&&h.debug&&console.warn("something went wrong, nodes missing");m=c.length;for(k=0;k<m;++k)c[k].order=k;c=c.sort(function(u,t){var x=u.constructor.priority||u.priority||0,z=t.constructor.priority||t.priority||0;return x==z?u.order-t.order:x-z});for(k=0;k<m;++k)c[k].order=k;return c};
|
|
40
|
+
w.prototype.getAncestors=function(a){for(var b=[],c=[a],d={};c.length;){var e=c.shift();if(e.inputs){d[e.id]||e==a||(d[e.id]=!0,b.push(e));for(var f=0;f<e.inputs.length;++f){var g=e.getInputNode(f);g&&-1==b.indexOf(g)&&c.push(g)}}}b.sort(function(k,m){return k.order-m.order});return b};w.prototype.arrange=function(a,b){a=a||100;var c=this.computeExecutionOrder(!1,!0);const d=[];for(var e=0;e<c.length;++e){var f=c[e],g=f._level||1;d[g]||(d[g]=[]);d[g].push(f)}c=a;for(e=0;e<d.length;++e){f=d[e];if(!f)continue;
|
|
41
|
+
g=100;let k=a+h.NODE_TITLE_HEIGHT;for(let m=0;m<f.length;++m){const l=f[m];l.pos[0]=b==h.VERTICAL_LAYOUT?k:c;l.pos[1]=b==h.VERTICAL_LAYOUT?c:k;const n=b==h.VERTICAL_LAYOUT?1:0;l.size[n]>g&&(g=l.size[n]);k+=l.size[b==h.VERTICAL_LAYOUT?0:1]+a+h.NODE_TITLE_HEIGHT}c+=g+a}this.setDirtyCanvas(!0,!0)};w.prototype.getTime=function(){return this.globaltime};w.prototype.getFixedTime=function(){return this.fixedtime};w.prototype.getElapsedTime=function(){return this.elapsed_time};w.prototype.sendEventToAllNodes=
|
|
42
|
+
function(a,b,c){c=c||h.ALWAYS;var d=this._nodes_in_order?this._nodes_in_order:this._nodes;if(d)for(var e=0,f=d.length;e<f;++e){var g=d[e];if(g.constructor===h.Subgraph&&"onExecute"!=a)g.mode==c&&g.sendEventToAllNodes(a,b,c);else if(g[a]&&g.mode==c)if(void 0===b)g[a]();else if(b&&b.constructor===Array)g[a].apply(g,b);else g[a](b)}};w.prototype.sendActionToCanvas=function(a,b){if(this.list_of_graphcanvas)for(var c=0;c<this.list_of_graphcanvas.length;++c){var d=this.list_of_graphcanvas[c];d[a]&&d[a].apply(d,
|
|
43
|
+
b)}};w.prototype.add=function(a,b){if(a)if(a.constructor===P)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=h.use_uuids?h.uuidv4():++this.last_node_id);if(this._nodes.length>=h.MAX_NUMBER_OF_NODES)throw"LiteGraph: max number of nodes in a graph reached";if(h.use_uuids){if(null==a.id||-1==a.id)a.id=h.uuidv4()}else null==a.id||-1==
|
|
44
|
+
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}};w.prototype.remove=function(a){if(a.constructor===h.LGraphGroup){var b=this._groups.indexOf(a);-1!=b&&this._groups.splice(b,1);a.graph=null;this._version++;
|
|
45
|
+
this.setDirtyCanvas(!0,!0);this.change()}else if(null!=this._nodes_by_id[a.id]&&!a.ignore_remove){this.beforeChange();if(a.inputs)for(b=0;b<a.inputs.length;b++){var c=a.inputs[b];null!=c.link&&a.disconnectInput(b)}if(a.outputs)for(b=0;b<a.outputs.length;b++)c=a.outputs[b],null!=c.links&&c.links.length&&a.disconnectOutput(b);if(a.onRemoved)a.onRemoved();a.graph=null;this._version++;if(this.list_of_graphcanvas)for(b=0;b<this.list_of_graphcanvas.length;++b)c=this.list_of_graphcanvas[b],c.selected_nodes[a.id]&&
|
|
46
|
+
delete c.selected_nodes[a.id],c.node_dragged==a&&(c.node_dragged=null);b=this._nodes.indexOf(a);-1!=b&&this._nodes.splice(b,1);delete this._nodes_by_id[a.id];if(this.onNodeRemoved)this.onNodeRemoved(a);this.sendActionToCanvas("checkPanels");this.setDirtyCanvas(!0,!0);this.afterChange();this.change();this.updateExecutionOrder()}};w.prototype.getNodeById=function(a){return null==a?null:this._nodes_by_id[a]};w.prototype.findNodesByClass=function(a,b){b=b||[];for(var c=b.length=0,d=this._nodes.length;c<
|
|
47
|
+
d;++c)this._nodes[c].constructor===a&&b.push(this._nodes[c]);return b};w.prototype.findNodesByType=function(a,b){a=a.toLowerCase();b=b||[];for(var c=b.length=0,d=this._nodes.length;c<d;++c)this._nodes[c].type.toLowerCase()==a&&b.push(this._nodes[c]);return b};w.prototype.findNodeByTitle=function(a){for(var b=0,c=this._nodes.length;b<c;++b)if(this._nodes[b].title==a)return this._nodes[b];return null};w.prototype.findNodesByTitle=function(a){for(var b=[],c=0,d=this._nodes.length;c<d;++c)this._nodes[c].title==
|
|
48
|
+
a&&b.push(this._nodes[c]);return b};w.prototype.getNodeOnPos=function(a,b,c,d){c=c||this._nodes;for(var e=c.length-1;0<=e;e--){var f=c[e];if(f.isPointInside(a,b,d))return f}return null};w.prototype.getGroupOnPos=function(a,b){for(var c=this._groups.length-1;0<=c;c--){var d=this._groups[c];if(d.isPointInside(a,b,2,!0))return d}return null};w.prototype.checkNodeTypes=function(){for(var a=0;a<this._nodes.length;a++){var b=this._nodes[a];if(b.constructor!=h.registered_node_types[b.type]){console.log("node being replaced by newer version: "+
|
|
49
|
+
b.type);var c=h.createNode(b.type);this._nodes[a]=c;c.configure(b.serialize());c.graph=this;this._nodes_by_id[c.id]=c;b.inputs&&(c.inputs=b.inputs.concat());b.outputs&&(c.outputs=b.outputs.concat())}}this.updateExecutionOrder()};w.prototype.onAction=function(a,b,c){this._input_nodes=this.findNodesByClass(h.GraphInput,this._input_nodes);for(var d=0;d<this._input_nodes.length;++d){var e=this._input_nodes[d];if(e.properties.name==a){e.actionDo(a,b,c);break}}};w.prototype.trigger=function(a,b){if(this.onTrigger)this.onTrigger(a,
|
|
50
|
+
b)};w.prototype.addInput=function(a,b,c){if(!this.inputs[a]){this.beforeChange();this.inputs[a]={name:a,type:b,value:c};this._version++;this.afterChange();if(this.onInputAdded)this.onInputAdded(a,b);if(this.onInputsOutputsChange)this.onInputsOutputsChange()}};w.prototype.setInputData=function(a,b){if(a=this.inputs[a])a.value=b};w.prototype.getInputData=function(a){return(a=this.inputs[a])?a.value:null};w.prototype.renameInput=function(a,b){if(b!=a){if(!this.inputs[a])return!1;if(this.inputs[b])return console.error("there is already one input with that name"),
|
|
51
|
+
!1;this.inputs[b]=this.inputs[a];delete this.inputs[a];this._version++;if(this.onInputRenamed)this.onInputRenamed(a,b);if(this.onInputsOutputsChange)this.onInputsOutputsChange()}};w.prototype.changeInputType=function(a,b){if(!this.inputs[a])return!1;if(!this.inputs[a].type||String(this.inputs[a].type).toLowerCase()!=String(b).toLowerCase())if(this.inputs[a].type=b,this._version++,this.onInputTypeChanged)this.onInputTypeChanged(a,b)};w.prototype.removeInput=function(a){if(!this.inputs[a])return!1;
|
|
52
|
+
delete this.inputs[a];this._version++;if(this.onInputRemoved)this.onInputRemoved(a);if(this.onInputsOutputsChange)this.onInputsOutputsChange();return!0};w.prototype.addOutput=function(a,b,c){this.outputs[a]={name:a,type:b,value:c};this._version++;if(this.onOutputAdded)this.onOutputAdded(a,b);if(this.onInputsOutputsChange)this.onInputsOutputsChange()};w.prototype.setOutputData=function(a,b){if(a=this.outputs[a])a.value=b};w.prototype.getOutputData=function(a){return(a=this.outputs[a])?a.value:null};
|
|
53
|
+
w.prototype.renameOutput=function(a,b){if(!this.outputs[a])return!1;if(this.outputs[b])return console.error("there is already one output with that name"),!1;this.outputs[b]=this.outputs[a];delete this.outputs[a];this._version++;if(this.onOutputRenamed)this.onOutputRenamed(a,b);if(this.onInputsOutputsChange)this.onInputsOutputsChange()};w.prototype.changeOutputType=function(a,b){if(!this.outputs[a])return!1;if(!this.outputs[a].type||String(this.outputs[a].type).toLowerCase()!=String(b).toLowerCase())if(this.outputs[a].type=
|
|
54
|
+
b,this._version++,this.onOutputTypeChanged)this.onOutputTypeChanged(a,b)};w.prototype.removeOutput=function(a){if(!this.outputs[a])return!1;delete this.outputs[a];this._version++;if(this.onOutputRemoved)this.onOutputRemoved(a);if(this.onInputsOutputsChange)this.onInputsOutputsChange();return!0};w.prototype.triggerInput=function(a,b){a=this.findNodesByTitle(a);for(var c=0;c<a.length;++c)a[c].onTrigger(b)};w.prototype.setCallback=function(a,b){a=this.findNodesByTitle(a);for(var c=0;c<a.length;++c)a[c].setTrigger(b)};
|
|
55
|
+
w.prototype.beforeChange=function(a){if(this.onBeforeChange)this.onBeforeChange(this,a);this.sendActionToCanvas("onBeforeChange",this)};w.prototype.afterChange=function(a){if(this.onAfterChange)this.onAfterChange(this,a);this.sendActionToCanvas("onAfterChange",this)};w.prototype.connectionChange=function(a,b){this.updateExecutionOrder();if(this.onConnectionChange)this.onConnectionChange(a);this._version++;this.sendActionToCanvas("onConnectionChange")};w.prototype.isLive=function(){if(!this.list_of_graphcanvas)return!1;
|
|
56
|
+
for(var a=0;a<this.list_of_graphcanvas.length;++a)if(this.list_of_graphcanvas[a].live_mode)return!0;return!1};w.prototype.clearTriggeredSlots=function(){for(var a in this.links){var b=this.links[a];b&&b._last_time&&(b._last_time=0)}};w.prototype.change=function(){h.debug&&console.log("Graph changed");this.sendActionToCanvas("setDirty",[!0,!0]);if(this.on_change)this.on_change(this)};w.prototype.setDirtyCanvas=function(a,b){this.sendActionToCanvas("setDirty",[a,b])};w.prototype.removeLink=function(a){if(a=
|
|
57
|
+
this.links[a]){var b=this.getNodeById(a.target_id);b&&b.disconnectInput(a.target_slot)}};w.prototype.serialize=function(){for(var a=[],b=0,c=this._nodes.length;b<c;++b)a.push(this._nodes[b].serialize());c=[];for(b in this.links){var d=this.links[b];if(!d.serialize){console.warn("weird LLink bug, link info is not a LLink but a regular object");var e=new Y;for(f in d)e[f]=d[f];d=this.links[b]=e}c.push(d.serialize())}var f=[];for(b=0;b<this._groups.length;++b)f.push(this._groups[b].serialize());a={last_node_id:this.last_node_id,
|
|
58
|
+
last_link_id:this.last_link_id,nodes:a,links:c,groups:f,config:this.config,extra:this.extra,version:h.VERSION};if(this.onSerialize)this.onSerialize(a);return a};w.prototype.configure=function(a,b){if(a){b||this.clear();b=a.nodes;if(a.links&&a.links.constructor===Array){for(var c=[],d=0;d<a.links.length;++d){var e=a.links[d];if(e){var f=new Y;f.configure(e);c[f.id]=f}else console.warn("serialized graph link data contains errors, skipping.")}a.links=c}for(d in a)"nodes"!=d&&"groups"!=d&&(this[d]=a[d]);
|
|
59
|
+
c=!1;this._nodes=[];if(b){d=0;for(e=b.length;d<e;++d){f=b[d];var g=h.createNode(f.type,f.title);g||(h.debug&&console.log("Node not found or has errors: "+f.type),g=new v,g.last_serialization=f,c=g.has_errors=!0);g.id=f.id;this.add(g,!0)}d=0;for(e=b.length;d<e;++d)f=b[d],(g=this.getNodeById(f.id))&&g.configure(f)}this._groups.length=0;if(a.groups)for(d=0;d<a.groups.length;++d)b=new h.LGraphGroup,b.configure(a.groups[d]),this.add(b);this.updateExecutionOrder();this.extra=a.extra||{};if(this.onConfigure)this.onConfigure(a);
|
|
60
|
+
this._version++;this.setDirtyCanvas(!0,!0);return c}};w.prototype.load=function(a,b){var c=this;if(a.constructor===File||a.constructor===Blob){var d=new FileReader;d.addEventListener("load",function(f){f=JSON.parse(f.target.result);c.configure(f);b&&b()});d.readAsText(a)}else{var e=new XMLHttpRequest;e.open("GET",a,!0);e.send(null);e.onload=function(f){200!==e.status?console.error("Error loading graph:",e.status,e.response):(f=JSON.parse(e.response),c.configure(f),b&&b())};e.onerror=function(f){console.error("Error loading graph:",
|
|
61
|
+
f)}}};w.prototype.onNodeTrace=function(a,b,c){};Y.prototype.configure=function(a){a.constructor===Array?(this.id=a[0],this.origin_id=a[1],this.origin_slot=a[2],this.target_id=a[3],this.target_slot=a[4],this.type=a[5]):(this.id=a.id,this.type=a.type,this.origin_id=a.origin_id,this.origin_slot=a.origin_slot,this.target_id=a.target_id,this.target_slot=a.target_slot)};Y.prototype.serialize=function(){return[this.id,this.origin_id,this.origin_slot,this.target_id,this.target_slot,this.type]};h.LLink=Y;
|
|
62
|
+
X.LGraphNode=h.LGraphNode=v;v.prototype._ctor=function(a){this.title=a||"Unnamed";this.size=[h.NODE_WIDTH,60];this.graph=null;this._pos=new Float32Array(10,10);Object.defineProperty(this,"pos",{set:function(b){!b||2>b.length||(this._pos[0]=b[0],this._pos[1]=b[1])},get:function(){return this._pos},enumerable:!0});this.id=h.use_uuids?h.uuidv4():-1;this.type=null;this.inputs=[];this.outputs=[];this.connections=[];this.properties={};this.properties_info=[];this.flags={}};v.prototype.configure=function(a){this.graph&&
|
|
63
|
+
this.graph._version++;for(var b in a)if("properties"==b)for(var c in a.properties){if(this.properties[c]=a.properties[c],this.onPropertyChanged)this.onPropertyChanged(c,a.properties[c])}else null!=a[b]&&("object"==typeof a[b]?this[b]&&this[b].configure?this[b].configure(a[b]):this[b]=h.cloneObject(a[b],this[b]):this[b]=a[b]);a.title||(this.title=this.constructor.title);if(this.inputs)for(c=0;c<this.inputs.length;++c){b=this.inputs[c];var d=this.graph?this.graph.links[b.link]:null;if(this.onConnectionsChange)this.onConnectionsChange(h.INPUT,
|
|
64
|
+
c,!0,d,b);if(this.onInputAdded)this.onInputAdded(b)}if(this.outputs)for(c=0;c<this.outputs.length;++c){var e=this.outputs[c];if(e.links){for(b=0;b<e.links.length;++b)if(d=this.graph?this.graph.links[e.links[b]]:null,this.onConnectionsChange)this.onConnectionsChange(h.OUTPUT,c,!0,d,e);if(this.onOutputAdded)this.onOutputAdded(e)}}if(this.widgets){for(c=0;c<this.widgets.length;++c)(b=this.widgets[c])&&b.options&&b.options.property&&void 0!=this.properties[b.options.property]&&(b.value=JSON.parse(JSON.stringify(this.properties[b.options.property])));
|
|
65
|
+
if(a.widgets_values)for(c=0;c<a.widgets_values.length;++c)this.widgets[c]&&(this.widgets[c].value=a.widgets_values[c])}if(this.onConfigure)this.onConfigure(a)};v.prototype.serialize=function(){var a={id:this.id,type:this.type,pos:this.pos,size:this.size,flags:h.cloneObject(this.flags),order:this.order,mode:this.mode};if(this.constructor===v&&this.last_serialization)return this.last_serialization;this.inputs&&(a.inputs=this.inputs);if(this.outputs){for(var b=0;b<this.outputs.length;b++)delete this.outputs[b]._data;
|
|
66
|
+
a.outputs=this.outputs}this.title&&this.title!=this.constructor.title&&(a.title=this.title);this.properties&&(a.properties=h.cloneObject(this.properties));if(this.widgets&&this.serialize_widgets)for(a.widgets_values=[],b=0;b<this.widgets.length;++b)a.widgets_values[b]=this.widgets[b]?this.widgets[b].value:null;a.type||(a.type=this.constructor.type);this.color&&(a.color=this.color);this.bgcolor&&(a.bgcolor=this.bgcolor);this.boxcolor&&(a.boxcolor=this.boxcolor);this.shape&&(a.shape=this.shape);this.onSerialize&&
|
|
67
|
+
this.onSerialize(a)&&console.warn("node onSerialize shouldnt return anything, data should be stored in the object pass in the first parameter");return a};v.prototype.clone=function(){var a=h.createNode(this.type);if(!a)return null;var b=h.cloneObject(this.serialize());if(b.inputs)for(var c=0;c<b.inputs.length;++c)b.inputs[c].link=null;if(b.outputs)for(c=0;c<b.outputs.length;++c)b.outputs[c].links&&(b.outputs[c].links.length=0);delete b.id;h.use_uuids&&(b.id=h.uuidv4());a.configure(b);return a};v.prototype.toString=
|
|
68
|
+
function(){return JSON.stringify(this.serialize())};v.prototype.getTitle=function(){return this.title||this.constructor.title};v.prototype.setProperty=function(a,b){this.properties||(this.properties={});if(b!==this.properties[a]){var c=this.properties[a];this.properties[a]=b;this.onPropertyChanged&&!1===this.onPropertyChanged(a,b,c)&&(this.properties[a]=c);if(this.widgets)for(c=0;c<this.widgets.length;++c){var d=this.widgets[c];if(d&&d.options.property==a){d.value=b;break}}}};v.prototype.setOutputData=
|
|
69
|
+
function(a,b){if(this.outputs&&!(-1==a||a>=this.outputs.length)){var c=this.outputs[a];if(c&&(c._data=b,this.outputs[a].links))for(c=0;c<this.outputs[a].links.length;c++){var d=this.graph.links[this.outputs[a].links[c]];d&&(d.data=b)}}};v.prototype.setOutputDataType=function(a,b){if(this.outputs&&!(-1==a||a>=this.outputs.length)){var c=this.outputs[a];if(c&&(c.type=b,this.outputs[a].links))for(c=0;c<this.outputs[a].links.length;c++)this.graph.links[this.outputs[a].links[c]].type=b}};v.prototype.getInputData=
|
|
70
|
+
function(a,b){if(this.inputs&&!(a>=this.inputs.length||null==this.inputs[a].link)){a=this.graph.links[this.inputs[a].link];if(!a)return null;if(!b)return a.data;b=this.graph.getNodeById(a.origin_id);if(!b)return a.data;if(b.updateOutputData)b.updateOutputData(a.origin_slot);else if(b.onExecute)b.onExecute();return a.data}};v.prototype.getInputDataType=function(a){if(!this.inputs||a>=this.inputs.length||null==this.inputs[a].link)return null;a=this.graph.links[this.inputs[a].link];if(!a)return null;
|
|
71
|
+
var b=this.graph.getNodeById(a.origin_id);return b?(a=b.outputs[a.origin_slot])?a.type:null:a.type};v.prototype.getInputDataByName=function(a,b){a=this.findInputSlot(a);return-1==a?null:this.getInputData(a,b)};v.prototype.isInputConnected=function(a){return this.inputs?a<this.inputs.length&&null!=this.inputs[a].link:!1};v.prototype.getInputInfo=function(a){return this.inputs?a<this.inputs.length?this.inputs[a]:null:null};v.prototype.getInputLink=function(a){return this.inputs?a<this.inputs.length?
|
|
72
|
+
this.graph.links[this.inputs[a].link]:null:null};v.prototype.getInputNode=function(a){if(!this.inputs||a>=this.inputs.length)return null;a=this.inputs[a];return a&&null!==a.link?(a=this.graph.links[a.link])?this.graph.getNodeById(a.origin_id):null:null};v.prototype.getInputOrProperty=function(a){if(!this.inputs||!this.inputs.length)return this.properties?this.properties[a]:null;for(var b=0,c=this.inputs.length;b<c;++b){var d=this.inputs[b];if(a==d.name&&null!=d.link&&(d=this.graph.links[d.link]))return d.data}return this.properties[a]};
|
|
73
|
+
v.prototype.getOutputData=function(a){return!this.outputs||a>=this.outputs.length?null:this.outputs[a]._data};v.prototype.getOutputInfo=function(a){return this.outputs?a<this.outputs.length?this.outputs[a]:null:null};v.prototype.isOutputConnected=function(a){return this.outputs?a<this.outputs.length&&this.outputs[a].links&&this.outputs[a].links.length:!1};v.prototype.isAnyOutputConnected=function(){if(!this.outputs)return!1;for(var a=0;a<this.outputs.length;++a)if(this.outputs[a].links&&this.outputs[a].links.length)return!0;
|
|
74
|
+
return!1};v.prototype.getOutputNodes=function(a){if(!this.outputs||0==this.outputs.length||a>=this.outputs.length)return null;a=this.outputs[a];if(!a.links||0==a.links.length)return null;for(var b=[],c=0;c<a.links.length;c++){var d=this.graph.links[a.links[c]];d&&(d=this.graph.getNodeById(d.target_id))&&b.push(d)}return b};v.prototype.addOnTriggerInput=function(){var a=this.findInputSlot("onTrigger");return-1==a?(this.addInput("onTrigger",h.EVENT,{optional:!0,nameLocked:!0}),this.findInputSlot("onTrigger")):
|
|
75
|
+
a};v.prototype.addOnExecutedOutput=function(){var a=this.findOutputSlot("onExecuted");return-1==a?(this.addOutput("onExecuted",h.ACTION,{optional:!0,nameLocked:!0}),this.findOutputSlot("onExecuted")):a};v.prototype.onAfterExecuteNode=function(a,b){var c=this.findOutputSlot("onExecuted");-1!=c&&this.triggerSlot(c,a,null,b)};v.prototype.changeMode=function(a){switch(a){case h.ON_EVENT:break;case h.ON_TRIGGER:this.addOnTriggerInput();this.addOnExecutedOutput();break;case h.NEVER:break;case h.ALWAYS:break;
|
|
76
|
+
case h.ON_REQUEST:break;default:return!1}this.mode=a;return!0};v.prototype.executePendingActions=function(){if(this._waiting_actions&&this._waiting_actions.length){for(var a=0;a<this._waiting_actions.length;++a){var b=this._waiting_actions[a];this.onAction(b[0],b[1],b[2],b[3],b[4])}this._waiting_actions.length=0}};v.prototype.doExecute=function(a,b){b=b||{};this.onExecute&&(b.action_call||(b.action_call=this.id+"_exec_"+Math.floor(9999*Math.random())),this.graph.nodes_executing[this.id]=!0,this.onExecute(a,
|
|
77
|
+
b),this.graph.nodes_executing[this.id]=!1,this.exec_version=this.graph.iteration,b&&b.action_call&&(this.action_call=b.action_call,this.graph.nodes_executedAction[this.id]=b.action_call));this.execute_triggered=2;if(this.onAfterExecuteNode)this.onAfterExecuteNode(a,b)};v.prototype.actionDo=function(a,b,c,d){c=c||{};this.onAction&&(c.action_call||(c.action_call=this.id+"_"+(a?a:"action")+"_"+Math.floor(9999*Math.random())),this.graph.nodes_actioning[this.id]=a?a:"actioning",this.onAction(a,b,c,d),
|
|
78
|
+
this.graph.nodes_actioning[this.id]=!1,c&&c.action_call&&(this.action_call=c.action_call,this.graph.nodes_executedAction[this.id]=c.action_call));this.action_triggered=2;if(this.onAfterExecuteNode)this.onAfterExecuteNode(b,c)};v.prototype.trigger=function(a,b,c){if(this.outputs&&this.outputs.length){this.graph&&(this.graph._last_trigger_time=h.getTime());for(var d=0;d<this.outputs.length;++d){var e=this.outputs[d];!e||e.type!==h.EVENT||a&&e.name!=a||this.triggerSlot(d,b,null,c)}}};v.prototype.triggerSlot=
|
|
79
|
+
function(a,b,c,d){d=d||{};if(this.outputs)if(null==a)console.error("slot must be a number");else if(a.constructor!==Number&&console.warn("slot must be a number, use node.trigger('name') if you want to use a string"),(a=this.outputs[a])&&(a=a.links)&&a.length){this.graph&&(this.graph._last_trigger_time=h.getTime());for(var e=0;e<a.length;++e){var f=a[e];if(null==c||c==f)if(f=this.graph.links[a[e]]){f._last_time=h.getTime();var g=this.graph.getNodeById(f.target_id);if(g)if(g.mode===h.ON_TRIGGER)d.action_call||
|
|
80
|
+
(d.action_call=this.id+"_trigg_"+Math.floor(9999*Math.random())),g.onExecute&&g.doExecute(b,d);else if(g.onAction){d.action_call||(d.action_call=this.id+"_act_"+Math.floor(9999*Math.random()));var k=g.inputs[f.target_slot];h.use_deferred_actions&&g.onExecute?(g._waiting_actions||(g._waiting_actions=[]),g._waiting_actions.push([k.name,b,d,f.target_slot])):g.actionDo(k.name,b,d,f.target_slot)}}}}};v.prototype.clearTriggeredSlot=function(a,b){if(this.outputs&&(a=this.outputs[a])&&(a=a.links)&&a.length)for(var c=
|
|
81
|
+
0;c<a.length;++c){var d=a[c];if(null==b||b==d)if(d=this.graph.links[a[c]])d._last_time=0}};v.prototype.setSize=function(a){this.size=a;if(this.onResize)this.onResize(this.size)};v.prototype.addProperty=function(a,b,c,d){c={name:a,type:c,default_value:b};if(d)for(var e in d)c[e]=d[e];this.properties_info||(this.properties_info=[]);this.properties_info.push(c);this.properties||(this.properties={});this.properties[a]=b;return c};v.prototype.addOutput=function(a,b,c){a={name:a,type:b,links:null};if(c)for(var d in c)a[d]=
|
|
82
|
+
c[d];this.outputs||(this.outputs=[]);this.outputs.push(a);if(this.onOutputAdded)this.onOutputAdded(a);h.auto_load_slot_types&&h.registerNodeAndSlotType(this,b,!0);this.setSize(this.computeSize());this.setDirtyCanvas(!0,!0);return a};v.prototype.addOutputs=function(a){for(var b=0;b<a.length;++b){var c=a[b],d={name:c[0],type:c[1],link:null};if(a[2])for(var e in c[2])d[e]=c[2][e];this.outputs||(this.outputs=[]);this.outputs.push(d);if(this.onOutputAdded)this.onOutputAdded(d);h.auto_load_slot_types&&
|
|
83
|
+
h.registerNodeAndSlotType(this,c[1],!0)}this.setSize(this.computeSize());this.setDirtyCanvas(!0,!0)};v.prototype.removeOutput=function(a){this.disconnectOutput(a);this.outputs.splice(a,1);for(var b=a;b<this.outputs.length;++b)if(this.outputs[b]&&this.outputs[b].links)for(var c=this.outputs[b].links,d=0;d<c.length;++d){var e=this.graph.links[c[d]];e&&--e.origin_slot}this.setSize(this.computeSize());if(this.onOutputRemoved)this.onOutputRemoved(a);this.setDirtyCanvas(!0,!0)};v.prototype.addInput=function(a,
|
|
84
|
+
b,c){b=b||0;a={name:a,type:b,link:null};if(c)for(var d in c)a[d]=c[d];this.inputs||(this.inputs=[]);this.inputs.push(a);this.setSize(this.computeSize());if(this.onInputAdded)this.onInputAdded(a);h.registerNodeAndSlotType(this,b);this.setDirtyCanvas(!0,!0);return a};v.prototype.addInputs=function(a){for(var b=0;b<a.length;++b){var c=a[b],d={name:c[0],type:c[1],link:null};if(a[2])for(var e in c[2])d[e]=c[2][e];this.inputs||(this.inputs=[]);this.inputs.push(d);if(this.onInputAdded)this.onInputAdded(d);
|
|
85
|
+
h.registerNodeAndSlotType(this,c[1])}this.setSize(this.computeSize());this.setDirtyCanvas(!0,!0)};v.prototype.removeInput=function(a){this.disconnectInput(a);for(var b=this.inputs.splice(a,1),c=a;c<this.inputs.length;++c)if(this.inputs[c]){var d=this.graph.links[this.inputs[c].link];d&&--d.target_slot}this.setSize(this.computeSize());if(this.onInputRemoved)this.onInputRemoved(a,b[0]);this.setDirtyCanvas(!0,!0)};v.prototype.addConnection=function(a,b,c,d){a={name:a,type:b,pos:c,direction:d,links:null};
|
|
86
|
+
this.connections.push(a);return a};v.prototype.computeSize=function(a){function b(n){return n?d*n.length*.6:0}if(this.constructor.size)return this.constructor.size.concat();var c=Math.max(this.inputs?this.inputs.length:1,this.outputs?this.outputs.length:1);a=a||new Float32Array([0,0]);c=Math.max(c,1);var d=h.NODE_TEXT_SIZE,e=b(this.title),f=0,g=0;if(this.inputs)for(var k=0,m=this.inputs.length;k<m;++k){var l=this.inputs[k];l=l.label||l.name||"";l=b(l);f<l&&(f=l)}if(this.outputs)for(k=0,m=this.outputs.length;k<
|
|
87
|
+
m;++k)l=this.outputs[k],l=l.label||l.name||"",l=b(l),g<l&&(g=l);a[0]=Math.max(f+g+10,e);a[0]=Math.max(a[0],h.NODE_WIDTH);this.widgets&&this.widgets.length&&(a[0]=Math.max(a[0],1.5*h.NODE_WIDTH));a[1]=(this.constructor.slot_start_y||0)+c*h.NODE_SLOT_HEIGHT;c=0;if(this.widgets&&this.widgets.length){k=0;for(m=this.widgets.length;k<m;++k)c=this.widgets[k].computeSize?c+(this.widgets[k].computeSize(a[0])[1]+4):c+(h.NODE_WIDGET_HEIGHT+4);c+=8}a[1]=this.widgets_up?Math.max(a[1],c):null!=this.widgets_start_y?
|
|
88
|
+
Math.max(a[1],c+this.widgets_start_y):a[1]+c;this.constructor.min_height&&a[1]<this.constructor.min_height&&(a[1]=this.constructor.min_height);a[1]+=6;return a};v.prototype.getPropertyInfo=function(a){var b=null;if(this.properties_info)for(var c=0;c<this.properties_info.length;++c)if(this.properties_info[c].name==a){b=this.properties_info[c];break}this.constructor["@"+a]&&(b=this.constructor["@"+a]);this.constructor.widgets_info&&this.constructor.widgets_info[a]&&(b=this.constructor.widgets_info[a]);
|
|
89
|
+
!b&&this.onGetPropertyInfo&&(b=this.onGetPropertyInfo(a));b||={};b.type||(b.type=typeof this.properties[a]);"combo"==b.widget&&(b.type="enum");return b};v.prototype.addWidget=function(a,b,c,d,e){this.widgets||(this.widgets=[]);!e&&d&&d.constructor===Object&&(e=d,d=null);e&&e.constructor===String&&(e={property:e});d&&d.constructor===String&&(e||={},e.property=d,d=null);d&&d.constructor!==Function&&(console.warn("addWidget: callback must be a function"),d=null);b={type:a.toLowerCase(),name:b,value:c,
|
|
90
|
+
callback:d,options:e||{}};void 0!==b.options.y&&(b.y=b.options.y);d||b.options.callback||b.options.property||console.warn("LiteGraph addWidget(...) without a callback or property assigned");if("combo"==a&&!b.options.values)throw"LiteGraph addWidget('combo',...) requires to pass values in options: { values:['red','blue'] }";this.widgets.push(b);this.setSize(this.computeSize());return b};v.prototype.addCustomWidget=function(a){this.widgets||(this.widgets=[]);this.widgets.push(a);return a};v.prototype.getBounding=
|
|
91
|
+
function(a,b){a=a||new Float32Array(4);const c=this.pos,d=this.flags.collapsed,e=this.size;let f=0,g=1,k=0,m=0;b&&(f=4,g=6+f,k=4,m=5+k);a[0]=c[0]-f;a[1]=c[1]-h.NODE_TITLE_HEIGHT-k;a[2]=d?(this._collapsed_width||h.NODE_COLLAPSED_WIDTH)+g:e[0]+g;a[3]=d?h.NODE_TITLE_HEIGHT+m:e[1]+h.NODE_TITLE_HEIGHT+m;if(this.onBounding)this.onBounding(a);return a};v.prototype.isPointInside=function(a,b,c,d){c=c||0;var e=this.graph&&this.graph.isLive()?0:h.NODE_TITLE_HEIGHT;d&&(e=0);if(this.flags&&this.flags.collapsed){if(K(a,
|
|
92
|
+
b,this.pos[0]-c,this.pos[1]-h.NODE_TITLE_HEIGHT-c,(this._collapsed_width||h.NODE_COLLAPSED_WIDTH)+2*c,h.NODE_TITLE_HEIGHT+2*c))return!0}else if(this.pos[0]-4-c<a&&this.pos[0]+this.size[0]+4+c>a&&this.pos[1]-e-c<b&&this.pos[1]+this.size[1]+c>b)return!0;return!1};v.prototype.getSlotInPosition=function(a,b){var c=new Float32Array(2);if(this.inputs)for(var d=0,e=this.inputs.length;d<e;++d){var f=this.inputs[d];this.getConnectionPos(!0,d,c);if(K(a,b,c[0]-10,c[1]-5,20,10))return{input:f,slot:d,link_pos:c}}if(this.outputs)for(d=
|
|
93
|
+
0,e=this.outputs.length;d<e;++d)if(f=this.outputs[d],this.getConnectionPos(!1,d,c),K(a,b,c[0]-10,c[1]-5,20,10))return{output:f,slot:d,link_pos:c};return null};v.prototype.findInputSlot=function(a,b){if(!this.inputs)return-1;for(var c=0,d=this.inputs.length;c<d;++c)if(a==this.inputs[c].name)return b?this.inputs[c]:c;return-1};v.prototype.findOutputSlot=function(a,b){b=b||!1;if(!this.outputs)return-1;for(var c=0,d=this.outputs.length;c<d;++c)if(a==this.outputs[c].name)return b?this.outputs[c]:c;return-1};
|
|
94
|
+
v.prototype.findInputSlotFree=function(a){a=a||{};a=Object.assign({returnObj:!1,typesNotAccepted:[]},a);if(!this.inputs)return-1;for(var b=0,c=this.inputs.length;b<c;++b)if(!(this.inputs[b].link&&null!=this.inputs[b].link||a.typesNotAccepted&&a.typesNotAccepted.includes&&a.typesNotAccepted.includes(this.inputs[b].type)))return a.returnObj?this.inputs[b]:b;return-1};v.prototype.findOutputSlotFree=function(a){a=a||{};a=Object.assign({returnObj:!1,typesNotAccepted:[]},a);if(!this.outputs)return-1;for(var b=
|
|
95
|
+
0,c=this.outputs.length;b<c;++b)if(!(this.outputs[b].links&&null!=this.outputs[b].links||a.typesNotAccepted&&a.typesNotAccepted.includes&&a.typesNotAccepted.includes(this.outputs[b].type)))return a.returnObj?this.outputs[b]:b;return-1};v.prototype.findInputSlotByType=function(a,b,c,d){return this.findSlotByType(!0,a,b,c,d)};v.prototype.findOutputSlotByType=function(a,b,c,d){return this.findSlotByType(!1,a,b,c,d)};v.prototype.findSlotByType=function(a,b,c,d,e){c=c||!1;d=d||!1;e=e||!1;a=a?this.inputs:
|
|
96
|
+
this.outputs;if(!a)return-1;if(""==b||"*"==b)b=0;for(var f=0,g=a.length;f<g;++f){var k=(b+"").toLowerCase().split(","),m="0"==a[f].type||"*"==a[f].type?"0":a[f].type;m=(m+"").toLowerCase().split(",");for(var l=0;l<k.length;l++)for(var n=0;n<m.length;n++)if("_event_"==k[l]&&(k[l]=h.EVENT),"_event_"==m[l]&&(m[l]=h.EVENT),"*"==k[l]&&(k[l]=0),"*"==m[l]&&(m[l]=0),!(k[l]!=m[n]||d&&a[f].links&&null!==a[f].links))return c?a[f]:f}if(d&&!e)for(f=0,g=a.length;f<g;++f)for(k=(b+"").toLowerCase().split(","),m=
|
|
97
|
+
"0"==a[f].type||"*"==a[f].type?"0":a[f].type,m=(m+"").toLowerCase().split(","),l=0;l<k.length;l++)for(n=0;n<m.length;n++)if("*"==k[l]&&(k[l]=0),"*"==m[l]&&(m[l]=0),k[l]==m[n])return c?a[f]:f;return-1};v.prototype.connectByType=function(a,b,c,d){d=d||{};d=Object.assign({createEventInCase:!0,firstFreeIfOutputGeneralInCase:!0,generalTypeInCase:!0},d);b&&b.constructor===Number&&(b=this.graph.getNodeById(b));var e=b.findInputSlotByType(c,!1,!0);if(0<=e&&null!==e)return this.connect(a,b,e);if(d.createEventInCase&&
|
|
98
|
+
c==h.EVENT)return this.connect(a,b,-1);if(d.generalTypeInCase&&(e=b.findInputSlotByType(0,!1,!0,!0),0<=e)||d.firstFreeIfOutputGeneralInCase&&(0==c||"*"==c||""==c)&&(e=b.findInputSlotFree({typesNotAccepted:[h.EVENT]}),0<=e))return this.connect(a,b,e);console.debug("no way to connect type: ",c," to targetNODE ",b);return null};v.prototype.connectByTypeOutput=function(a,b,c,d){d=d||{};d=Object.assign({createEventInCase:!0,firstFreeIfInputGeneralInCase:!0,generalTypeInCase:!0},d);b&&b.constructor===Number&&
|
|
99
|
+
(b=this.graph.getNodeById(b));var e=b.findOutputSlotByType(c,!1,!0);if(0<=e&&null!==e||d.generalTypeInCase&&(e=b.findOutputSlotByType(0,!1,!0,!0),0<=e))return b.connect(e,this,a);if(d.createEventInCase&&c==h.EVENT&&h.do_add_triggers_slots)return e=b.addOnExecutedOutput(),b.connect(e,this,a);if(d.firstFreeIfInputGeneralInCase&&(0==c||"*"==c||""==c)&&(e=b.findOutputSlotFree({typesNotAccepted:[h.EVENT]}),0<=e))return b.connect(e,this,a);console.debug("no way to connect byOUT type: ",c," to sourceNODE ",
|
|
100
|
+
b);return null};v.prototype.connect=function(a,b,c){c=c||0;if(!this.graph)return console.log("Connect: Error, node doesn't belong to any graph. Nodes must be added first to a graph before connecting them."),null;if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return h.debug&&console.log("Connect: Error, no slot of name "+a),null}else if(!this.outputs||a>=this.outputs.length)return h.debug&&console.log("Connect: Error, slot number not found"),null;b&&b.constructor===Number&&(b=this.graph.getNodeById(b));
|
|
101
|
+
if(!b)throw"target node is null";if(b==this)return null;if(c.constructor===String){if(c=b.findInputSlot(c),-1==c)return h.debug&&console.log("Connect: Error, no slot of name "+c),null}else if(c===h.EVENT)if(h.do_add_triggers_slots)b.changeMode(h.ON_TRIGGER),c=b.findInputSlot("onTrigger");else return null;else if(!b.inputs||c>=b.inputs.length)return h.debug&&console.log("Connect: Error, slot number not found"),null;var d=b.inputs[c],e=this.outputs[a];if(!this.outputs[a])return null;b.onBeforeConnectInput&&
|
|
102
|
+
(c=b.onBeforeConnectInput(c));if(!1===c||null===c||!h.isValidConnection(e.type,d.type))return this.setDirtyCanvas(!1,!0),null;if(b.onConnectInput&&!1===b.onConnectInput(c,e.type,e,this,a)||this.onConnectOutput&&!1===this.onConnectOutput(a,d.type,d,b,c))return null;b.inputs[c]&&null!=b.inputs[c].link&&(this.graph.beforeChange(),b.disconnectInput(c,{doProcessChange:!1}));if(null!==e.links&&e.links.length)switch(e.type){case h.EVENT:h.allow_multi_output_for_events||(this.graph.beforeChange(),this.disconnectOutput(a,
|
|
103
|
+
!1,{doProcessChange:!1}))}var f=h.use_uuids?h.uuidv4():++this.graph.last_link_id;f=new Y(f,d.type||e.type,this.id,a,b.id,c);this.graph.links[f.id]=f;null==e.links&&(e.links=[]);e.links.push(f.id);b.inputs[c].link=f.id;this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(h.OUTPUT,a,!0,f,e);if(b.onConnectionsChange)b.onConnectionsChange(h.INPUT,c,!0,f,d);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(h.INPUT,b,c,this,a),this.graph.onNodeConnectionChange(h.OUTPUT,
|
|
104
|
+
this,a,b,c));this.setDirtyCanvas(!1,!0);this.graph.afterChange();this.graph.connectionChange(this,f);return f};v.prototype.disconnectOutput=function(a,b){if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return h.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.outputs||a>=this.outputs.length)return h.debug&&console.log("Connect: Error, slot number not found"),!1;var c=this.outputs[a];if(!c||!c.links||0==c.links.length)return!1;if(b){b.constructor===Number&&(b=
|
|
105
|
+
this.graph.getNodeById(b));if(!b)throw"Target Node not found";for(var d=0,e=c.links.length;d<e;d++){var f=c.links[d],g=this.graph.links[f];if(g.target_id==b.id){c.links.splice(d,1);var k=b.inputs[g.target_slot];k.link=null;delete this.graph.links[f];this.graph&&this.graph._version++;if(b.onConnectionsChange)b.onConnectionsChange(h.INPUT,g.target_slot,!1,g,k);if(this.onConnectionsChange)this.onConnectionsChange(h.OUTPUT,a,!1,g,c);if(this.graph&&this.graph.onNodeConnectionChange)this.graph.onNodeConnectionChange(h.OUTPUT,
|
|
106
|
+
this,a);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(h.OUTPUT,this,a),this.graph.onNodeConnectionChange(h.INPUT,b,g.target_slot));break}}}else{d=0;for(e=c.links.length;d<e;d++)if(f=c.links[d],g=this.graph.links[f]){b=this.graph.getNodeById(g.target_id);this.graph&&this.graph._version++;if(b){k=b.inputs[g.target_slot];k.link=null;if(b.onConnectionsChange)b.onConnectionsChange(h.INPUT,g.target_slot,!1,g,k);if(this.graph&&this.graph.onNodeConnectionChange)this.graph.onNodeConnectionChange(h.INPUT,
|
|
107
|
+
b,g.target_slot)}delete this.graph.links[f];if(this.onConnectionsChange)this.onConnectionsChange(h.OUTPUT,a,!1,g,c);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(h.OUTPUT,this,a),this.graph.onNodeConnectionChange(h.INPUT,b,g.target_slot))}c.links=null}this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this);return!0};v.prototype.disconnectInput=function(a){if(a.constructor===String){if(a=this.findInputSlot(a),-1==a)return h.debug&&console.log("Connect: Error, no slot of name "+
|
|
108
|
+
a),!1}else if(!this.inputs||a>=this.inputs.length)return h.debug&&console.log("Connect: Error, slot number not found"),!1;var b=this.inputs[a];if(!b)return!1;var c=this.inputs[a].link;if(null!=c){this.inputs[a].link=null;var d=this.graph.links[c];if(d){var e=this.graph.getNodeById(d.origin_id);if(!e)return!1;var f=e.outputs[d.origin_slot];if(!f||!f.links||0==f.links.length)return!1;for(var g=0,k=f.links.length;g<k;g++)if(f.links[g]==c){f.links.splice(g,1);break}delete this.graph.links[c];this.graph&&
|
|
109
|
+
this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(h.INPUT,a,!1,d,b);if(e.onConnectionsChange)e.onConnectionsChange(h.OUTPUT,g,!1,d,f);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(h.OUTPUT,e,g),this.graph.onNodeConnectionChange(h.INPUT,this,a))}}this.setDirtyCanvas(!1,!0);this.graph&&this.graph.connectionChange(this);return!0};v.prototype.getConnectionPos=function(a,b,c){c=c||new Float32Array(2);var d=0;a&&this.inputs&&(d=this.inputs.length);
|
|
110
|
+
!a&&this.outputs&&(d=this.outputs.length);var e=.5*h.NODE_SLOT_HEIGHT;if(this.flags.collapsed)return b=this._collapsed_width||h.NODE_COLLAPSED_WIDTH,this.horizontal?(c[0]=this.pos[0]+.5*b,c[1]=a?this.pos[1]-h.NODE_TITLE_HEIGHT:this.pos[1]):(c[0]=a?this.pos[0]:this.pos[0]+b,c[1]=this.pos[1]-.5*h.NODE_TITLE_HEIGHT),c;if(a&&-1==b)return c[0]=this.pos[0]+.5*h.NODE_TITLE_HEIGHT,c[1]=this.pos[1]+.5*h.NODE_TITLE_HEIGHT,c;if(a&&d>b&&this.inputs[b].pos)return c[0]=this.pos[0]+this.inputs[b].pos[0],c[1]=this.pos[1]+
|
|
111
|
+
this.inputs[b].pos[1],c;if(!a&&d>b&&this.outputs[b].pos)return c[0]=this.pos[0]+this.outputs[b].pos[0],c[1]=this.pos[1]+this.outputs[b].pos[1],c;if(this.horizontal)return c[0]=this.pos[0]+this.size[0]/d*(b+.5),c[1]=a?this.pos[1]-h.NODE_TITLE_HEIGHT:this.pos[1]+this.size[1],c;c[0]=a?this.pos[0]+e:this.pos[0]+this.size[0]+1-e;c[1]=this.pos[1]+(b+.7)*h.NODE_SLOT_HEIGHT+(this.constructor.slot_start_y||0);return c};v.prototype.alignToGrid=function(){this.pos[0]=h.CANVAS_GRID_SIZE*Math.round(this.pos[0]/
|
|
112
|
+
h.CANVAS_GRID_SIZE);this.pos[1]=h.CANVAS_GRID_SIZE*Math.round(this.pos[1]/h.CANVAS_GRID_SIZE)};v.prototype.trace=function(a){this.console||(this.console=[]);this.console.push(a);this.console.length>v.MAX_CONSOLE&&this.console.shift();if(this.graph.onNodeTrace)this.graph.onNodeTrace(this,a)};v.prototype.setDirtyCanvas=function(a,b){this.graph&&this.graph.sendActionToCanvas("setDirty",[a,b])};v.prototype.loadImage=function(a){var b=new Image;b.src=h.node_images_path+a;b.ready=!1;var c=this;b.onload=
|
|
113
|
+
function(){this.ready=!0;c.setDirtyCanvas(!0)};return b};v.prototype.captureInput=function(a){if(this.graph&&this.graph.list_of_graphcanvas)for(var b=this.graph.list_of_graphcanvas,c=0;c<b.length;++c){var d=b[c];if(a||d.node_capturing_input==this)d.node_capturing_input=a?this:null}};v.prototype.collapse=function(a){this.graph._version++;if(!1!==this.constructor.collapsable||a)this.flags.collapsed=this.flags.collapsed?!1:!0,this.setDirtyCanvas(!0,!0)};v.prototype.pin=function(a){this.graph._version++;
|
|
114
|
+
this.flags.pinned=void 0===a?!this.flags.pinned:a};v.prototype.localToScreen=function(a,b,c){return[(a+this.pos[0])*c.scale+c.offset[0],(b+this.pos[1])*c.scale+c.offset[1]]};X.LGraphGroup=h.LGraphGroup=P;P.prototype._ctor=function(a){this.title=a||"Group";this.font_size=24;this.color=q.node_colors.pale_blue?q.node_colors.pale_blue.groupcolor:"#AAA";this._bounding=new Float32Array([10,10,140,80]);this._pos=this._bounding.subarray(0,2);this._size=this._bounding.subarray(2,4);this._nodes=[];this.graph=
|
|
115
|
+
null;Object.defineProperty(this,"pos",{set:function(b){!b||2>b.length||(this._pos[0]=b[0],this._pos[1]=b[1])},get:function(){return this._pos},enumerable:!0});Object.defineProperty(this,"size",{set:function(b){!b||2>b.length||(this._size[0]=Math.max(140,b[0]),this._size[1]=Math.max(80,b[1]))},get:function(){return this._size},enumerable:!0})};P.prototype.configure=function(a){this.title=a.title;this._bounding.set(a.bounding);this.color=a.color;this.font_size=a.font_size};P.prototype.serialize=function(){var a=
|
|
116
|
+
this._bounding;return{title:this.title,bounding:[Math.round(a[0]),Math.round(a[1]),Math.round(a[2]),Math.round(a[3])],color:this.color,font_size:this.font_size}};P.prototype.move=function(a,b,c){this._pos[0]+=a;this._pos[1]+=b;if(!c)for(c=0;c<this._nodes.length;++c){var d=this._nodes[c];d.pos[0]+=a;d.pos[1]+=b}};P.prototype.recomputeInsideNodes=function(){this._nodes.length=0;for(var a=this.graph._nodes,b=new Float32Array(4),c=0;c<a.length;++c){var d=a[c];d.getBounding(b);Z(this._bounding,b)&&this._nodes.push(d)}};
|
|
117
|
+
P.prototype.isPointInside=v.prototype.isPointInside;P.prototype.setDirtyCanvas=v.prototype.setDirtyCanvas;h.DragAndScale=L;L.prototype.bindEvents=function(a){this.last_mouse=new Float32Array(2);this._binded_mouse_callback=this.onMouse.bind(this);h.pointerListenerAdd(a,"down",this._binded_mouse_callback);h.pointerListenerAdd(a,"move",this._binded_mouse_callback);h.pointerListenerAdd(a,"up",this._binded_mouse_callback);a.addEventListener("mousewheel",this._binded_mouse_callback,!1);a.addEventListener("wheel",
|
|
118
|
+
this._binded_mouse_callback,!1)};L.prototype.computeVisibleArea=function(a){if(this.element){var b=this.element.width,c=this.element.height,d=-this.offset[0],e=-this.offset[1];a&&(d+=a[0]/this.scale,e+=a[1]/this.scale,b=a[2],c=a[3]);a=d+b/this.scale;c=e+c/this.scale;this.visible_area[0]=d;this.visible_area[1]=e;this.visible_area[2]=a-d;this.visible_area[3]=c-e}else this.visible_area[0]=this.visible_area[1]=this.visible_area[2]=this.visible_area[3]=0};L.prototype.onMouse=function(a){if(this.enabled){var b=
|
|
119
|
+
this.element,c=b.getBoundingClientRect(),d=a.clientX-c.left;c=a.clientY-c.top;a.canvasx=d;a.canvasy=c;a.dragging=this.dragging;var e=!this.viewport||this.viewport&&d>=this.viewport[0]&&d<this.viewport[0]+this.viewport[2]&&c>=this.viewport[1]&&c<this.viewport[1]+this.viewport[3],f=!1;this.onmouse&&(f=this.onmouse(a));a.type==h.pointerevents_method+"down"&&e?(this.dragging=!0,h.pointerListenerRemove(b,"move",this._binded_mouse_callback),h.pointerListenerAdd(document,"move",this._binded_mouse_callback),
|
|
120
|
+
h.pointerListenerAdd(document,"up",this._binded_mouse_callback)):a.type==h.pointerevents_method+"move"?f||(b=d-this.last_mouse[0],f=c-this.last_mouse[1],this.dragging&&this.mouseDrag(b,f)):a.type==h.pointerevents_method+"up"?(this.dragging=!1,h.pointerListenerRemove(document,"move",this._binded_mouse_callback),h.pointerListenerRemove(document,"up",this._binded_mouse_callback),h.pointerListenerAdd(b,"move",this._binded_mouse_callback)):!e||"mousewheel"!=a.type&&"wheel"!=a.type&&"DOMMouseScroll"!=a.type||
|
|
121
|
+
(a.eventType="mousewheel",a.wheel="wheel"==a.type?-a.deltaY:null!=a.wheelDeltaY?a.wheelDeltaY:-60*a.detail,a.delta=a.wheelDelta?a.wheelDelta/40:a.deltaY?-a.deltaY/3:0,this.changeDeltaScale(1+.05*a.delta));this.last_mouse[0]=d;this.last_mouse[1]=c;if(e)return a.preventDefault(),a.stopPropagation(),!1}};L.prototype.toCanvasContext=function(a){a.scale(this.scale,this.scale);a.translate(this.offset[0],this.offset[1])};L.prototype.convertOffsetToCanvas=function(a){return[(a[0]+this.offset[0])*this.scale,
|
|
122
|
+
(a[1]+this.offset[1])*this.scale]};L.prototype.convertCanvasToOffset=function(a,b){b=b||[0,0];b[0]=a[0]/this.scale-this.offset[0];b[1]=a[1]/this.scale-this.offset[1];return b};L.prototype.mouseDrag=function(a,b){this.offset[0]+=a/this.scale;this.offset[1]+=b/this.scale;if(this.onredraw)this.onredraw(this)};L.prototype.changeScale=function(a,b){a<this.min_scale?a=this.min_scale:a>this.max_scale&&(a=this.max_scale);if(a!=this.scale&&this.element){var c=this.element.getBoundingClientRect();if(c&&(b=
|
|
123
|
+
b||[.5*c.width,.5*c.height],c=this.convertCanvasToOffset(b),this.scale=a,.01>Math.abs(this.scale-1)&&(this.scale=1),a=this.convertCanvasToOffset(b),a=[a[0]-c[0],a[1]-c[1]],this.offset[0]+=a[0],this.offset[1]+=a[1],this.onredraw))this.onredraw(this)}};L.prototype.changeDeltaScale=function(a,b){this.changeScale(this.scale*a,b)};L.prototype.reset=function(){this.scale=1;this.offset[0]=0;this.offset[1]=0};X.LGraphCanvas=h.LGraphCanvas=q;q.DEFAULT_BACKGROUND_IMAGE="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQBJREFUeNrs1rEKwjAUhlETUkj3vP9rdmr1Ysammk2w5wdxuLgcMHyptfawuZX4pJSWZTnfnu/lnIe/jNNxHHGNn//HNbbv+4dr6V+11uF527arU7+u63qfa/bnmh8sWLBgwYJlqRf8MEptXPBXJXa37BSl3ixYsGDBMliwFLyCV/DeLIMFCxYsWLBMwSt4Be/NggXLYMGCBUvBK3iNruC9WbBgwYJlsGApeAWv4L1ZBgsWLFiwYJmCV/AK3psFC5bBggULloJX8BpdwXuzYMGCBctgwVLwCl7Be7MMFixYsGDBsu8FH1FaSmExVfAxBa/gvVmwYMGCZbBg/W4vAQYA5tRF9QYlv/QAAAAASUVORK5CYII=";
|
|
124
|
+
q.link_type_colors={"-1":h.EVENT_LINK_COLOR,number:"#AAA",node:"#DCA"};q.gradients={};q.prototype.clear=function(){this.fps=this.render_time=this.last_draw_time=this.frame=0;this.dragging_rectangle=null;this.selected_nodes={};this.selected_group=null;this.visible_nodes=[];this.connecting_node=this.node_capturing_input=this.node_over=this.node_dragged=null;this.highlighted_links={};this.dragging_canvas=!1;this.dirty_bgcanvas=this.dirty_canvas=!0;this.node_widget=this.node_in_panel=this.dirty_area=
|
|
125
|
+
null;this.last_mouse=[0,0];this.last_mouseclick=0;this.pointer_is_double=this.pointer_is_down=!1;this.visible_area.set([0,0,0,0]);if(this.onClear)this.onClear()};q.prototype.setGraph=function(a,b){this.graph!=a&&(b||this.clear(),!a&&this.graph?this.graph.detachCanvas(this):(a.attachCanvas(this),this._graph_stack&&(this._graph_stack=null),this.setDirty(!0,!0)))};q.prototype.getTopGraph=function(){return this._graph_stack.length?this._graph_stack[0]:this.graph};q.prototype.openSubgraph=function(a){if(!a)throw"graph cannot be null";
|
|
126
|
+
if(this.graph==a)throw"graph cannot be the same";this.clear();this.graph&&(this._graph_stack||(this._graph_stack=[]),this._graph_stack.push(this.graph));a.attachCanvas(this);this.checkPanels();this.setDirty(!0,!0)};q.prototype.closeSubgraph=function(){if(this._graph_stack&&0!=this._graph_stack.length){var a=this.graph._subgraph_node,b=this._graph_stack.pop();this.selected_nodes={};this.highlighted_links={};b.attachCanvas(this);this.setDirty(!0,!0);a&&(this.centerOnNode(a),this.selectNodes([a]));this.ds.offset=
|
|
127
|
+
[0,0];this.ds.scale=1}};q.prototype.getCurrentGraph=function(){return this.graph};q.prototype.setCanvas=function(a,b){if(a&&a.constructor===String&&(a=document.getElementById(a),!a))throw"Error creating LiteGraph canvas: Canvas not found";if(a!==this.canvas&&(!a&&this.canvas&&(b||this.unbindEvents()),this.canvas=a,this.ds.element=a)){a.className+=" lgraphcanvas";a.data=this;a.tabindex="1";this.bgcanvas=null;this.bgcanvas||(this.bgcanvas=document.createElement("canvas"),this.bgcanvas.width=this.canvas.width,
|
|
128
|
+
this.bgcanvas.height=this.canvas.height);if(null==a.getContext){if("canvas"!=a.localName)throw"Element supplied for LGraphCanvas must be a <canvas> element, you passed a "+a.localName;throw"This browser doesn't support Canvas";}null==(this.ctx=a.getContext("2d"))&&(a.webgl_enabled||console.warn("This canvas seems to be WebGL, enabling WebGL renderer"),this.enableWebGL());b||this.bindEvents()}};q.prototype._doNothing=function(a){a.preventDefault();return!1};q.prototype._doReturnTrue=function(a){a.preventDefault();
|
|
129
|
+
return!0};q.prototype.bindEvents=function(){if(this._events_binded)console.warn("LGraphCanvas: events already binded");else{var a=this.canvas,b=this.getCanvasWindow().document;this._mousedown_callback=this.processMouseDown.bind(this);this._mousewheel_callback=this.processMouseWheel.bind(this);this._mousemove_callback=this.processMouseMove.bind(this);this._mouseup_callback=this.processMouseUp.bind(this);h.pointerListenerAdd(a,"down",this._mousedown_callback,!0);a.addEventListener("mousewheel",this._mousewheel_callback,
|
|
130
|
+
!1);h.pointerListenerAdd(a,"up",this._mouseup_callback,!0);h.pointerListenerAdd(a,"move",this._mousemove_callback);a.addEventListener("contextmenu",this._doNothing);a.addEventListener("DOMMouseScroll",this._mousewheel_callback,!1);this._key_callback=this.processKey.bind(this);a.setAttribute("tabindex",1);a.addEventListener("keydown",this._key_callback,!0);b.addEventListener("keyup",this._key_callback,!0);this._ondrop_callback=this.processDrop.bind(this);a.addEventListener("dragover",this._doNothing,
|
|
131
|
+
!1);a.addEventListener("dragend",this._doNothing,!1);a.addEventListener("drop",this._ondrop_callback,!1);a.addEventListener("dragenter",this._doReturnTrue,!1);this._events_binded=!0}};q.prototype.unbindEvents=function(){if(this._events_binded){var a=this.getCanvasWindow().document;h.pointerListenerRemove(this.canvas,"move",this._mousedown_callback);h.pointerListenerRemove(this.canvas,"up",this._mousedown_callback);h.pointerListenerRemove(this.canvas,"down",this._mousedown_callback);this.canvas.removeEventListener("mousewheel",
|
|
132
|
+
this._mousewheel_callback);this.canvas.removeEventListener("DOMMouseScroll",this._mousewheel_callback);this.canvas.removeEventListener("keydown",this._key_callback);a.removeEventListener("keyup",this._key_callback);this.canvas.removeEventListener("contextmenu",this._doNothing);this.canvas.removeEventListener("drop",this._ondrop_callback);this.canvas.removeEventListener("dragenter",this._doReturnTrue);this._ondrop_callback=this._key_callback=this._mousewheel_callback=this._mousedown_callback=null;
|
|
133
|
+
this._events_binded=!1}else console.warn("LGraphCanvas: no events binded")};q.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()};q.prototype.enableWebGL=function(){if("undefined"===typeof GL)throw"litegl.js must be included to use a WebGL canvas";if("undefined"===typeof enableWebGLCanvas)throw"webglCanvas.js must be included to use this feature";this.gl=this.ctx=enableWebGLCanvas(this.canvas);this.ctx.webgl=!0;
|
|
134
|
+
this.bgcanvas=this.canvas;this.bgctx=this.gl;this.canvas.webgl_enabled=!0};q.prototype.setDirty=function(a,b){a&&(this.dirty_canvas=!0);b&&(this.dirty_bgcanvas=!0)};q.prototype.getCanvasWindow=function(){if(!this.canvas)return window;var a=this.canvas.ownerDocument;return a.defaultView||a.parentWindow};q.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=
|
|
135
|
+
!0,a.call(this))};q.prototype.stopRendering=function(){this.is_rendering=!1};q.prototype.blockClick=function(){this.block_click=!0;this.last_mouseclick=0};q.prototype.processMouseDown=function(a){this.set_canvas_dirty_on_mouse_event&&(this.dirty_canvas=!0);if(this.graph){this.adjustMouseEvent(a);var b=this.getCanvasWindow();q.active_canvas=this;var c=this,d=a.clientX,e=a.clientY;this.ds.viewport=this.viewport;d=!this.viewport||this.viewport&&d>=this.viewport[0]&&d<this.viewport[0]+this.viewport[2]&&
|
|
136
|
+
e>=this.viewport[1]&&e<this.viewport[1]+this.viewport[3];this.options.skip_events||(h.pointerListenerRemove(this.canvas,"move",this._mousemove_callback),h.pointerListenerAdd(b.document,"move",this._mousemove_callback,!0),h.pointerListenerAdd(b.document,"up",this._mouseup_callback,!0));if(d){var f=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes,5);d=!1;e=h.getTime();var g=void 0===a.isPrimary||!a.isPrimary;e=300>e-this.last_mouseclick&&g;this.mouse[0]=a.clientX;this.mouse[1]=a.clientY;
|
|
137
|
+
this.graph_mouse[0]=a.canvasX;this.graph_mouse[1]=a.canvasY;this.last_click_position=[this.mouse[0],this.mouse[1]];this.pointer_is_double=this.pointer_is_down&&g?!0:!1;this.pointer_is_down=!0;this.canvas.focus();h.closeAllContextMenus(b);if(!this.onMouse||1!=this.onMouse(a)){if(1!=a.which||this.pointer_is_double)if(2==a.which)if(h.middle_click_slot_add_default_node){if(f&&this.allow_interaction&&!d&&!this.read_only&&!this.connecting_node&&!f.flags.collapsed&&!this.live_mode){e=d=g=!1;if(f.outputs)for(n=
|
|
138
|
+
0,k=f.outputs.length;n<k;++n)if(m=f.outputs[n],l=f.getConnectionPos(!1,n),K(a.canvasX,a.canvasY,l[0]-15,l[1]-10,30,20)){g=m;d=n;e=!0;break}if(f.inputs)for(n=0,k=f.inputs.length;n<k;++n)if(m=f.inputs[n],l=f.getConnectionPos(!0,n),K(a.canvasX,a.canvasY,l[0]-15,l[1]-10,30,20)){g=m;d=n;e=!1;break}g&&!1!==d&&(n=.5-(d+1)/(e?f.outputs.length:f.inputs.length),g=f.getBounding(),this.createDefaultNodeForSlot({nodeFrom:e?f:null,slotFrom:e?d:null,nodeTo:e?null:f,slotTo:e?null:d,position:[e?g[0]+g[2]:g[0],a.canvasY-
|
|
139
|
+
80],nodeType:"AUTO",posAdd:[e?30:-30,130*-n],posSizeFix:[e?0:-1,0]}))}}else!d&&this.allow_dragcanvas&&(this.dragging_canvas=!0);else 3!=a.which&&!this.pointer_is_double||!this.allow_interaction||d||this.read_only||(f&&(Object.keys(this.selected_nodes).length&&(this.selected_nodes[f.id]||a.shiftKey||a.ctrlKey||a.metaKey)?this.selected_nodes[f.id]||this.selectNodes([f],!0):this.selectNodes([f])),this.processContextMenu(f,a));else{a.ctrlKey&&(this.dragging_rectangle=new Float32Array(4),this.dragging_rectangle[0]=
|
|
140
|
+
a.canvasX,this.dragging_rectangle[1]=a.canvasY,this.dragging_rectangle[2]=1,this.dragging_rectangle[3]=1,d=!0);h.alt_drag_do_clone_nodes&&a.altKey&&f&&this.allow_interaction&&!d&&!this.read_only&&(cloned=f.clone())&&(cloned.pos[0]+=5,cloned.pos[1]+=5,this.graph.add(cloned,!1,{doCalcSize:!1}),f=cloned,d=!0,n||(this.allow_dragnodes&&(this.graph.beforeChange(),this.node_dragged=f),this.selected_nodes[f.id]||this.processNodeSelected(f,a)));g=!1;if(f&&(this.allow_interaction||f.flags.allow_interaction)&&
|
|
141
|
+
!d&&!this.read_only){this.live_mode||f.flags.pinned||this.bringToFront(f);if(this.allow_interaction&&!this.connecting_node&&!f.flags.collapsed&&!this.live_mode)if(!d&&!1!==f.resizable&&K(a.canvasX,a.canvasY,f.pos[0]+f.size[0]-5,f.pos[1]+f.size[1]-5,10,10))this.graph.beforeChange(),this.resizing_node=f,this.canvas.style.cursor="se-resize",d=!0;else{if(f.outputs){n=0;for(var k=f.outputs.length;n<k;++n){var m=f.outputs[n],l=f.getConnectionPos(!1,n);if(K(a.canvasX,a.canvasY,l[0]-15,l[1]-10,30,20)){this.connecting_node=
|
|
142
|
+
f;this.connecting_output=m;this.connecting_output.slot_index=n;this.connecting_pos=f.getConnectionPos(!1,n);this.connecting_slot=n;h.shift_click_do_break_link_from&&a.shiftKey&&f.disconnectOutput(n);if(e){if(f.onOutputDblClick)f.onOutputDblClick(n,a)}else if(f.onOutputClick)f.onOutputClick(n,a);d=!0;break}}}if(f.inputs)for(n=0,k=f.inputs.length;n<k;++n)if(m=f.inputs[n],l=f.getConnectionPos(!0,n),K(a.canvasX,a.canvasY,l[0]-15,l[1]-10,30,20)){if(e){if(f.onInputDblClick)f.onInputDblClick(n,a)}else if(f.onInputClick)f.onInputClick(n,
|
|
143
|
+
a);null!==m.link&&(l=this.graph.links[m.link],h.click_do_break_link_to&&(f.disconnectInput(n),d=this.dirty_bgcanvas=!0),this.allow_reconnect_links||a.shiftKey)&&(h.click_do_break_link_to||f.disconnectInput(n),this.connecting_node=this.graph._nodes_by_id[l.origin_id],this.connecting_slot=l.origin_slot,this.connecting_output=this.connecting_node.outputs[this.connecting_slot],this.connecting_pos=this.connecting_node.getConnectionPos(!1,this.connecting_slot),d=this.dirty_bgcanvas=!0);d||(this.connecting_node=
|
|
144
|
+
f,this.connecting_input=m,this.connecting_input.slot_index=n,this.connecting_pos=f.getConnectionPos(!0,n),this.connecting_slot=n,d=this.dirty_bgcanvas=!0)}}if(!d){var n=!1;k=[a.canvasX-f.pos[0],a.canvasY-f.pos[1]];if(l=this.processNodeWidgets(f,this.graph_mouse,a))n=!0,this.node_widget=[f,l];if(this.allow_interaction&&e&&this.selected_nodes[f.id]){if(f.onDblClick)f.onDblClick(a,k,this);this.processNodeDblClicked(f);n=!0}f.onMouseDown&&f.onMouseDown(a,k,this)?n=!0:(f.subgraph&&!f.skip_subgraph_button&&
|
|
145
|
+
!f.flags.collapsed&&k[0]>f.size[0]-h.NODE_TITLE_HEIGHT&&0>k[1]&&(c=this,setTimeout(function(){c.openSubgraph(f.subgraph)},10)),this.live_mode&&(n=g=!0));n?f.is_selected||this.processNodeSelected(f,a):(this.allow_dragnodes&&(this.graph.beforeChange(),this.node_dragged=f),this.processNodeSelected(f,a));this.dirty_canvas=!0}}else if(!d){if(!this.read_only)for(n=0;n<this.visible_links.length;++n)if(g=this.visible_links[n],k=g._pos,!(!k||a.canvasX<k[0]-4||a.canvasX>k[0]+4||a.canvasY<k[1]-4||a.canvasY>
|
|
146
|
+
k[1]+4)){this.showLinkMenu(g,a);this.over_link_center=null;break}this.selected_group=this.graph.getGroupOnPos(a.canvasX,a.canvasY);this.selected_group_resizing=!1;this.selected_group&&!this.read_only&&(a.ctrlKey&&(this.dragging_rectangle=null),10>ba([a.canvasX,a.canvasY],[this.selected_group.pos[0]+this.selected_group.size[0],this.selected_group.pos[1]+this.selected_group.size[1]])*this.ds.scale?this.selected_group_resizing=!0:this.selected_group.recomputeInsideNodes());e&&!this.read_only&&this.allow_searchbox&&
|
|
147
|
+
(this.showSearchBox(a),a.preventDefault(),a.stopPropagation());g=!0}!d&&g&&this.allow_dragcanvas&&(this.dragging_canvas=!0)}this.last_mouse[0]=a.clientX;this.last_mouse[1]=a.clientY;this.last_mouseclick=h.getTime();this.last_mouse_dragging=!0;this.graph.change();(!b.document.activeElement||"input"!=b.document.activeElement.nodeName.toLowerCase()&&"textarea"!=b.document.activeElement.nodeName.toLowerCase())&&a.preventDefault();a.stopPropagation();if(this.onMouseDown)this.onMouseDown(a);return!1}}}};
|
|
148
|
+
q.prototype.processMouseMove=function(a){this.autoresize&&this.resize();this.set_canvas_dirty_on_mouse_event&&(this.dirty_canvas=!0);if(this.graph){q.active_canvas=this;this.adjustMouseEvent(a);var b=[a.clientX,a.clientY];this.mouse[0]=b[0];this.mouse[1]=b[1];var c=[b[0]-this.last_mouse[0],b[1]-this.last_mouse[1]];this.last_mouse=b;this.graph_mouse[0]=a.canvasX;this.graph_mouse[1]=a.canvasY;if(this.block_click)return a.preventDefault(),!1;a.dragging=this.last_mouse_dragging;this.node_widget&&(this.processNodeWidgets(this.node_widget[0],
|
|
149
|
+
this.graph_mouse,a,this.node_widget[1]),this.dirty_canvas=!0);var d=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes);if(this.dragging_rectangle)this.dragging_rectangle[2]=a.canvasX-this.dragging_rectangle[0],this.dragging_rectangle[3]=a.canvasY-this.dragging_rectangle[1],this.dirty_canvas=!0;else if(this.selected_group&&!this.read_only)this.selected_group_resizing?this.selected_group.size=[a.canvasX-this.selected_group.pos[0],a.canvasY-this.selected_group.pos[1]]:(this.selected_group.move(c[0]/
|
|
150
|
+
this.ds.scale,c[1]/this.ds.scale,a.ctrlKey),this.selected_group._nodes.length&&(this.dirty_canvas=!0)),this.dirty_bgcanvas=!0;else if(this.dragging_canvas)this.ds.offset[0]+=c[0]/this.ds.scale,this.ds.offset[1]+=c[1]/this.ds.scale,this.dirty_bgcanvas=this.dirty_canvas=!0;else if((this.allow_interaction||d&&d.flags.allow_interaction)&&!this.read_only){this.connecting_node&&(this.dirty_canvas=!0);b=0;for(var e=this.graph._nodes.length;b<e;++b)if(this.graph._nodes[b].mouseOver&&d!=this.graph._nodes[b]){this.graph._nodes[b].mouseOver=
|
|
151
|
+
!1;if(this.node_over&&this.node_over.onMouseLeave)this.node_over.onMouseLeave(a);this.node_over=null;this.dirty_canvas=!0}if(d){d.redraw_on_mouse&&(this.dirty_canvas=!0);if(!d.mouseOver&&(d.mouseOver=!0,this.node_over=d,this.dirty_canvas=!0,d.onMouseEnter))d.onMouseEnter(a);if(d.onMouseMove)d.onMouseMove(a,[a.canvasX-d.pos[0],a.canvasY-d.pos[1]],this);if(this.connecting_node)if(this.connecting_output){if(e=this._highlight_input||[0,0],!this.isOverNodeBox(d,a.canvasX,a.canvasY)){var f=this.isOverNodeInput(d,
|
|
152
|
+
a.canvasX,a.canvasY,e);if(-1!=f&&d.inputs[f]){var g=d.inputs[f].type;h.isValidConnection(this.connecting_output.type,g)&&(this._highlight_input=e,this._highlight_input_slot=d.inputs[f])}else this._highlight_input_slot=this._highlight_input=null}}else this.connecting_input&&(e=this._highlight_output||[0,0],this.isOverNodeBox(d,a.canvasX,a.canvasY)||(f=this.isOverNodeOutput(d,a.canvasX,a.canvasY,e),-1!=f&&d.outputs[f]?(g=d.outputs[f].type,h.isValidConnection(this.connecting_input.type,g)&&(this._highlight_output=
|
|
153
|
+
e)):this._highlight_output=null));this.canvas&&(K(a.canvasX,a.canvasY,d.pos[0]+d.size[0]-5,d.pos[1]+d.size[1]-5,5,5)?this.canvas.style.cursor="se-resize":this.canvas.style.cursor="crosshair")}else{e=null;for(b=0;b<this.visible_links.length;++b)if(f=this.visible_links[b],g=f._pos,!(!g||a.canvasX<g[0]-4||a.canvasX>g[0]+4||a.canvasY<g[1]-4||a.canvasY>g[1]+4)){e=f;break}e!=this.over_link_center&&(this.over_link_center=e,this.dirty_canvas=!0);this.canvas&&(this.canvas.style.cursor="")}if(this.node_capturing_input&&
|
|
154
|
+
this.node_capturing_input!=d&&this.node_capturing_input.onMouseMove)this.node_capturing_input.onMouseMove(a,[a.canvasX-this.node_capturing_input.pos[0],a.canvasY-this.node_capturing_input.pos[1]],this);if(this.node_dragged&&!this.live_mode){for(b in this.selected_nodes)d=this.selected_nodes[b],d.pos[0]+=c[0]/this.ds.scale,d.pos[1]+=c[1]/this.ds.scale,d.is_selected||this.processNodeSelected(d,a);this.dirty_bgcanvas=this.dirty_canvas=!0}this.resizing_node&&!this.live_mode&&(c=[a.canvasX-this.resizing_node.pos[0],
|
|
155
|
+
a.canvasY-this.resizing_node.pos[1]],b=this.resizing_node.computeSize(),c[0]=Math.max(b[0],c[0]),c[1]=Math.max(b[1],c[1]),this.resizing_node.setSize(c),this.canvas.style.cursor="se-resize",this.dirty_bgcanvas=this.dirty_canvas=!0)}a.preventDefault();return!1}};q.prototype.processMouseUp=function(a){var b=void 0===a.isPrimary||a.isPrimary;if(!b)return!1;this.set_canvas_dirty_on_mouse_event&&(this.dirty_canvas=!0);if(this.graph){var c=this.getCanvasWindow().document;q.active_canvas=this;this.options.skip_events||
|
|
156
|
+
(h.pointerListenerRemove(c,"move",this._mousemove_callback,!0),h.pointerListenerAdd(this.canvas,"move",this._mousemove_callback,!0),h.pointerListenerRemove(c,"up",this._mouseup_callback,!0));this.adjustMouseEvent(a);c=h.getTime();a.click_time=c-this.last_mouseclick;this.last_mouse_dragging=!1;this.last_click_position=null;this.block_click&&(this.block_click=!1);if(1==a.which){this.node_widget&&this.processNodeWidgets(this.node_widget[0],this.graph_mouse,a);this.node_widget=null;this.selected_group&&
|
|
157
|
+
(this.selected_group.move(this.selected_group.pos[0]-Math.round(this.selected_group.pos[0]),this.selected_group.pos[1]-Math.round(this.selected_group.pos[1]),a.ctrlKey),this.selected_group.pos[0]=Math.round(this.selected_group.pos[0]),this.selected_group.pos[1]=Math.round(this.selected_group.pos[1]),this.selected_group._nodes.length&&(this.dirty_canvas=!0),this.selected_group=null);this.selected_group_resizing=!1;var d=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes);if(this.dragging_rectangle){if(this.graph){c=
|
|
158
|
+
this.graph._nodes;var e=new Float32Array(4),f=Math.abs(this.dragging_rectangle[2]),g=Math.abs(this.dragging_rectangle[3]),k=0>this.dragging_rectangle[3]?this.dragging_rectangle[1]-g:this.dragging_rectangle[1];this.dragging_rectangle[0]=0>this.dragging_rectangle[2]?this.dragging_rectangle[0]-f:this.dragging_rectangle[0];this.dragging_rectangle[1]=k;this.dragging_rectangle[2]=f;this.dragging_rectangle[3]=g;if(!d||10<f&&10<g){d=[];for(f=0;f<c.length;++f)g=c[f],g.getBounding(e),Z(this.dragging_rectangle,
|
|
159
|
+
e)&&d.push(g);d.length&&this.selectNodes(d,a.shiftKey)}else this.selectNodes([d],a.shiftKey||a.ctrlKey)}this.dragging_rectangle=null}else if(this.connecting_node)this.dirty_bgcanvas=this.dirty_canvas=!0,c=(this.connecting_output||this.connecting_input).type,d?this.connecting_output?(e=this.isOverNodeInput(d,a.canvasX,a.canvasY),-1!=e?this.connecting_node.connect(this.connecting_slot,d,e):this.connecting_node.connectByType(this.connecting_slot,d,c)):this.connecting_input&&(e=this.isOverNodeOutput(d,
|
|
160
|
+
a.canvasX,a.canvasY),-1!=e?d.connect(e,this.connecting_node,this.connecting_slot):this.connecting_node.connectByTypeOutput(this.connecting_slot,d,c)):h.release_link_on_empty_shows_menu&&(a.shiftKey&&this.allow_searchbox?this.connecting_output?this.showSearchBox(a,{node_from:this.connecting_node,slot_from:this.connecting_output,type_filter_in:this.connecting_output.type}):this.connecting_input&&this.showSearchBox(a,{node_to:this.connecting_node,slot_from:this.connecting_input,type_filter_out:this.connecting_input.type}):
|
|
161
|
+
this.connecting_output?this.showConnectionMenu({nodeFrom:this.connecting_node,slotFrom:this.connecting_output,e:a}):this.connecting_input&&this.showConnectionMenu({nodeTo:this.connecting_node,slotTo:this.connecting_input,e:a})),this.connecting_node=this.connecting_pos=this.connecting_input=this.connecting_output=null,this.connecting_slot=-1;else if(this.resizing_node)this.dirty_bgcanvas=this.dirty_canvas=!0,this.graph.afterChange(this.resizing_node),this.resizing_node=null;else if(this.node_dragged){(d=
|
|
162
|
+
this.node_dragged)&&300>a.click_time&&K(a.canvasX,a.canvasY,d.pos[0],d.pos[1]-h.NODE_TITLE_HEIGHT,h.NODE_TITLE_HEIGHT,h.NODE_TITLE_HEIGHT)&&d.collapse();this.dirty_bgcanvas=this.dirty_canvas=!0;this.node_dragged.pos[0]=Math.round(this.node_dragged.pos[0]);this.node_dragged.pos[1]=Math.round(this.node_dragged.pos[1]);(this.graph.config.align_to_grid||this.align_to_grid)&&this.node_dragged.alignToGrid();if(this.onNodeMoved)this.onNodeMoved(this.node_dragged);this.graph.afterChange(this.node_dragged);
|
|
163
|
+
this.node_dragged=null}else{d=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes);!d&&300>a.click_time&&this.deselectAllNodes();this.dirty_canvas=!0;this.dragging_canvas=!1;if(this.node_over&&this.node_over.onMouseUp)this.node_over.onMouseUp(a,[a.canvasX-this.node_over.pos[0],a.canvasY-this.node_over.pos[1]],this);if(this.node_capturing_input&&this.node_capturing_input.onMouseUp)this.node_capturing_input.onMouseUp(a,[a.canvasX-this.node_capturing_input.pos[0],a.canvasY-this.node_capturing_input.pos[1]])}}else 2==
|
|
164
|
+
a.which?(this.dirty_canvas=!0,this.dragging_canvas=!1):3==a.which&&(this.dirty_canvas=!0,this.dragging_canvas=!1);b&&(this.pointer_is_double=this.pointer_is_down=!1);this.graph.change();a.stopPropagation();a.preventDefault();return!1}};q.prototype.processMouseWheel=function(a){if(this.graph&&this.allow_dragcanvas){var b=null!=a.wheelDeltaY?a.wheelDeltaY:-60*a.detail;this.adjustMouseEvent(a);var c=a.clientX,d=a.clientY;if(!this.viewport||this.viewport&&c>=this.viewport[0]&&c<this.viewport[0]+this.viewport[2]&&
|
|
165
|
+
d>=this.viewport[1]&&d<this.viewport[1]+this.viewport[3])return c=this.ds.scale,0<b?c*=1.1:0>b&&(c*=1/1.1),this.ds.changeScale(c,[a.clientX,a.clientY]),this.graph.change(),a.preventDefault(),!1}};q.prototype.isOverNodeBox=function(a,b,c){var d=h.NODE_TITLE_HEIGHT;return K(b,c,a.pos[0]+2,a.pos[1]+2-d,d-4,d-4)?!0:!1};q.prototype.isOverNodeInput=function(a,b,c,d){if(a.inputs)for(var e=0,f=a.inputs.length;e<f;++e){var g=a.getConnectionPos(!0,e);if(a.horizontal?K(b,c,g[0]-5,g[1]-10,10,20):K(b,c,g[0]-10,
|
|
166
|
+
g[1]-5,40,10))return d&&(d[0]=g[0],d[1]=g[1]),e}return-1};q.prototype.isOverNodeOutput=function(a,b,c,d){if(a.outputs)for(var e=0,f=a.outputs.length;e<f;++e){var g=a.getConnectionPos(!1,e);if(a.horizontal?K(b,c,g[0]-5,g[1]-10,10,20):K(b,c,g[0]-10,g[1]-5,40,10))return d&&(d[0]=g[0],d[1]=g[1]),e}return-1};q.prototype.processKey=function(a){if(this.graph){var b=!1;if("input"!=a.target.localName){if("keydown"==a.type){if(32==a.keyCode&&(b=this.dragging_canvas=!0),27==a.keyCode&&(this.node_panel&&this.node_panel.close(),
|
|
167
|
+
this.options_panel&&this.options_panel.close(),b=!0),65==a.keyCode&&a.ctrlKey&&(this.selectNodes(),b=!0),67===a.keyCode&&(a.metaKey||a.ctrlKey)&&!a.shiftKey&&this.selected_nodes&&(this.copyToClipboard(),b=!0),86===a.keyCode&&(a.metaKey||a.ctrlKey)&&this.pasteFromClipboard(a.shiftKey),46!=a.keyCode&&8!=a.keyCode||"input"==a.target.localName||"textarea"==a.target.localName||(this.deleteSelectedNodes(),b=!0),this.selected_nodes)for(var c in this.selected_nodes)if(this.selected_nodes[c].onKeyDown)this.selected_nodes[c].onKeyDown(a)}else if("keyup"==
|
|
168
|
+
a.type&&(32==a.keyCode&&(this.dragging_canvas=!1),this.selected_nodes))for(c in this.selected_nodes)if(this.selected_nodes[c].onKeyUp)this.selected_nodes[c].onKeyUp(a);this.graph.change();if(b)return a.preventDefault(),a.stopImmediatePropagation(),!1}}};q.prototype.copyToClipboard=function(){var a={nodes:[],links:[]},b=0,c=[],d;for(d in this.selected_nodes){var e=this.selected_nodes[d];!1!==e.clonable&&(e._relative_id=b,c.push(e),b+=1)}for(d=0;d<c.length;++d)if(e=c[d],!1!==e.clonable)if(b=e.clone()){if(a.nodes.push(b.serialize()),
|
|
169
|
+
e.inputs&&e.inputs.length)for(b=0;b<e.inputs.length;++b){var f=e.inputs[b];if(f&&null!=f.link&&(f=this.graph.links[f.link])){var g=this.graph.getNodeById(f.origin_id);g&&a.links.push([g._relative_id,f.origin_slot,e._relative_id,f.target_slot,g.id])}}}else console.warn("node type not found: "+e.type);localStorage.setItem("litegrapheditor_clipboard",JSON.stringify(a))};q.prototype.pasteFromClipboard=function(a=!1){if(h.ctrl_shift_v_paste_connect_unselected_outputs||!a){var b=localStorage.getItem("litegrapheditor_clipboard");
|
|
170
|
+
if(b){this.graph.beforeChange();b=JSON.parse(b);for(var c=!1,d=0;d<b.nodes.length;++d)c?(c[0]>b.nodes[d].pos[0]&&(c[0]=b.nodes[d].pos[0]),c[1]>b.nodes[d].pos[1]&&(c[1]=b.nodes[d].pos[1])):c=[b.nodes[d].pos[0],b.nodes[d].pos[1]];var e=[];for(d=0;d<b.nodes.length;++d){var f=b.nodes[d],g=h.createNode(f.type);g&&(g.configure(f),g.pos[0]+=this.graph_mouse[0]-c[0],g.pos[1]+=this.graph_mouse[1]-c[1],this.graph.add(g,{doProcessChange:!1}),e.push(g))}for(d=0;d<b.links.length;++d){c=b.links[d];f=c[0];if(null!=
|
|
171
|
+
f)var k=e[f];else h.ctrl_shift_v_paste_connect_unselected_outputs&&a&&(f=c[4])&&(k=this.graph.getNodeById(f));f=e[c[2]];k&&f?k.connect(c[1],f,c[3]):console.warn("Warning, nodes missing on pasting")}this.selectNodes(e);this.graph.afterChange()}}};q.prototype.processDrop=function(a){a.preventDefault();this.adjustMouseEvent(a);var b=a.clientX,c=a.clientY;if(!this.viewport||this.viewport&&b>=this.viewport[0]&&b<this.viewport[0]+this.viewport[2]&&c>=this.viewport[1]&&c<this.viewport[1]+this.viewport[3]){b=
|
|
172
|
+
[a.canvasX,a.canvasY];var d=this.graph?this.graph.getNodeOnPos(b[0],b[1]):null;if(d){if((d.onDropFile||d.onDropData)&&(b=a.dataTransfer.files)&&b.length)for(c=0;c<b.length;c++){var e=a.dataTransfer.files[0],f=e.name;q.getFileExtension(f);if(d.onDropFile)d.onDropFile(e);if(d.onDropData){var g=new FileReader;g.onload=function(m){d.onDropData(m.target.result,f,e)};var k=e.type.split("/")[0];"text"==k||""==k?g.readAsText(e):"image"==k?g.readAsDataURL(e):g.readAsArrayBuffer(e)}}return d.onDropItem&&d.onDropItem(event)?
|
|
173
|
+
!0:this.onDropItem?this.onDropItem(event):!1}b=null;this.onDropItem&&(b=this.onDropItem(event));b||this.checkDropItem(a)}};q.prototype.checkDropItem=function(a){if(a.dataTransfer.files.length){var b=a.dataTransfer.files[0],c=q.getFileExtension(b.name).toLowerCase();if(c=h.node_types_by_file_extension[c]){this.graph.beforeChange();c=h.createNode(c.type);c.pos=[a.canvasX,a.canvasY];this.graph.add(c);if(c.onDropFile)c.onDropFile(b);this.graph.afterChange()}}};q.prototype.processNodeDblClicked=function(a){if(this.onShowNodePanel)this.onShowNodePanel(a);
|
|
174
|
+
else this.showShowNodePanel(a);if(this.onNodeDblClicked)this.onNodeDblClicked(a);this.setDirty(!0)};q.prototype.processNodeSelected=function(a,b){this.selectNode(a,b&&(b.shiftKey||b.ctrlKey||this.multi_select));if(this.onNodeSelected)this.onNodeSelected(a)};q.prototype.selectNode=function(a,b){null==a?this.deselectAllNodes():this.selectNodes([a],b)};q.prototype.selectNodes=function(a,b){b||this.deselectAllNodes();a=a||this.graph._nodes;"string"==typeof a&&(a=[a]);for(var c in a)if(b=a[c],b.is_selected)this.deselectNode(b);
|
|
175
|
+
else{if(!b.is_selected&&b.onSelected)b.onSelected();b.is_selected=!0;this.selected_nodes[b.id]=b;if(b.inputs)for(var d=0;d<b.inputs.length;++d)this.highlighted_links[b.inputs[d].link]=!0;if(b.outputs)for(d=0;d<b.outputs.length;++d){var e=b.outputs[d];if(e.links)for(var f=0;f<e.links.length;++f)this.highlighted_links[e.links[f]]=!0}}if(this.onSelectionChange)this.onSelectionChange(this.selected_nodes);this.setDirty(!0)};q.prototype.deselectNode=function(a){if(a.is_selected){if(a.onDeselected)a.onDeselected();
|
|
176
|
+
a.is_selected=!1;if(this.onNodeDeselected)this.onNodeDeselected(a);if(a.inputs)for(var b=0;b<a.inputs.length;++b)delete this.highlighted_links[a.inputs[b].link];if(a.outputs)for(b=0;b<a.outputs.length;++b){var c=a.outputs[b];if(c.links)for(var d=0;d<c.links.length;++d)delete this.highlighted_links[c.links[d]]}}};q.prototype.deselectAllNodes=function(){if(this.graph){for(var a=this.graph._nodes,b=0,c=a.length;b<c;++b){var d=a[b];if(d.is_selected){if(d.onDeselected)d.onDeselected();d.is_selected=!1;
|
|
177
|
+
if(this.onNodeDeselected)this.onNodeDeselected(d)}}this.selected_nodes={};this.current_node=null;this.highlighted_links={};if(this.onSelectionChange)this.onSelectionChange(this.selected_nodes);this.setDirty(!0)}};q.prototype.deleteSelectedNodes=function(){this.graph.beforeChange();for(var a in this.selected_nodes){var b=this.selected_nodes[a];if(!b.block_delete){if(b.inputs&&b.inputs.length&&b.outputs&&b.outputs.length&&h.isValidConnection(b.inputs[0].type,b.outputs[0].type)&&b.inputs[0].link&&b.outputs[0].links&&
|
|
178
|
+
b.outputs[0].links.length){var c=b.graph.links[b.inputs[0].link],d=b.graph.links[b.outputs[0].links[0]],e=b.getInputNode(0),f=b.getOutputNodes(0)[0];e&&f&&e.connect(c.origin_slot,f,d.target_slot)}this.graph.remove(b);if(this.onNodeDeselected)this.onNodeDeselected(b)}}this.selected_nodes={};this.current_node=null;this.highlighted_links={};this.setDirty(!0);this.graph.afterChange()};q.prototype.centerOnNode=function(a){this.ds.offset[0]=-a.pos[0]-.5*a.size[0]+.5*this.canvas.width/this.ds.scale;this.ds.offset[1]=
|
|
179
|
+
-a.pos[1]-.5*a.size[1]+.5*this.canvas.height/this.ds.scale;this.setDirty(!0,!0)};q.prototype.adjustMouseEvent=function(a){if(this.canvas){var b=this.canvas.getBoundingClientRect();var c=a.clientX-b.left;b=a.clientY-b.top}else c=a.clientX,b=a.clientY;this.last_mouse_position[0]=c;this.last_mouse_position[1]=b;a.canvasX=c/this.ds.scale-this.ds.offset[0];a.canvasY=b/this.ds.scale-this.ds.offset[1]};q.prototype.setZoom=function(a,b){this.ds.changeScale(a,b);this.dirty_bgcanvas=this.dirty_canvas=!0};q.prototype.convertOffsetToCanvas=
|
|
180
|
+
function(a,b){return this.ds.convertOffsetToCanvas(a,b)};q.prototype.convertCanvasToOffset=function(a,b){return this.ds.convertCanvasToOffset(a,b)};q.prototype.convertEventToCanvasOffset=function(a){var b=this.canvas.getBoundingClientRect();return this.convertCanvasToOffset([a.clientX-b.left,a.clientY-b.top])};q.prototype.bringToFront=function(a){var b=this.graph._nodes.indexOf(a);-1!=b&&(this.graph._nodes.splice(b,1),this.graph._nodes.push(a))};q.prototype.sendToBack=function(a){var b=this.graph._nodes.indexOf(a);
|
|
181
|
+
-1!=b&&(this.graph._nodes.splice(b,1),this.graph._nodes.unshift(a))};var ha=new Float32Array(4);q.prototype.computeVisibleNodes=function(a,b){b=b||[];b.length=0;a=a||this.graph._nodes;for(var c=0,d=a.length;c<d;++c){var e=a[c];(!this.live_mode||e.onDrawBackground||e.onDrawForeground)&&Z(this.visible_area,e.getBounding(ha,!0))&&b.push(e)}return b};q.prototype.draw=function(a,b){if(this.canvas&&0!=this.canvas.width&&0!=this.canvas.height){var c=h.getTime();this.render_time=.001*(c-this.last_draw_time);
|
|
182
|
+
this.last_draw_time=c;this.graph&&this.ds.computeVisibleArea(this.viewport);(this.dirty_bgcanvas||b||this.always_render_background||this.graph&&this.graph._last_trigger_time&&1E3>c-this.graph._last_trigger_time)&&this.drawBackCanvas();(this.dirty_canvas||a)&&this.drawFrontCanvas();this.fps=this.render_time?1/this.render_time:0;this.frame+=1}};q.prototype.drawFrontCanvas=function(){this.dirty_canvas=!1;this.ctx||(this.ctx=this.bgcanvas.getContext("2d"));var a=this.ctx;if(a){var b=this.canvas;a.start2D&&
|
|
183
|
+
!this.viewport&&(a.start2D(),a.restore(),a.setTransform(1,0,0,1,0,0));var c=this.viewport||this.dirty_area;c&&(a.save(),a.beginPath(),a.rect(c[0],c[1],c[2],c[3]),a.clip());this.clear_background&&(c?a.clearRect(c[0],c[1],c[2],c[3]):a.clearRect(0,0,b.width,b.height));this.bgcanvas==this.canvas?this.drawBackCanvas():a.drawImage(this.bgcanvas,0,0);if(this.onRender)this.onRender(b,a);this.show_info&&this.renderInfo(a,c?c[0]:0,c?c[1]:0);if(this.graph){a.save();this.ds.toCanvasContext(a);b=this.computeVisibleNodes(null,
|
|
184
|
+
this.visible_nodes);for(var d=0;d<b.length;++d){var e=b[d];a.save();a.translate(e.pos[0],e.pos[1]);this.drawNode(e,a);a.restore()}this.render_execution_order&&this.drawExecutionOrder(a);this.graph.config.links_ontop&&(this.live_mode||this.drawConnections(a));if(null!=this.connecting_pos){a.lineWidth=this.connections_width;e=this.connecting_output||this.connecting_input;b=e.type;d=e.dir;null==d&&(d=this.connecting_output?this.connecting_node.horizontal?h.DOWN:h.RIGHT:this.connecting_node.horizontal?
|
|
185
|
+
h.UP:h.LEFT);var f=e.shape;switch(b){case h.EVENT:e=h.EVENT_LINK_COLOR;break;default:e=h.CONNECTING_LINK_COLOR}this.renderLink(a,this.connecting_pos,[this.graph_mouse[0],this.graph_mouse[1]],null,!1,null,e,d,h.CENTER);a.beginPath();b===h.EVENT||f===h.BOX_SHAPE?(a.rect(this.connecting_pos[0]-6+.5,this.connecting_pos[1]-5+.5,14,10),a.fill(),a.beginPath(),a.rect(this.graph_mouse[0]-6+.5,this.graph_mouse[1]-5+.5,14,10)):f===h.ARROW_SHAPE?(a.moveTo(this.connecting_pos[0]+8,this.connecting_pos[1]+.5),a.lineTo(this.connecting_pos[0]-
|
|
186
|
+
4,this.connecting_pos[1]+6+.5),a.lineTo(this.connecting_pos[0]-4,this.connecting_pos[1]-6+.5),a.closePath()):(a.arc(this.connecting_pos[0],this.connecting_pos[1],4,0,2*Math.PI),a.fill(),a.beginPath(),a.arc(this.graph_mouse[0],this.graph_mouse[1],4,0,2*Math.PI));a.fill();a.fillStyle="#ffcc00";if(this._highlight_input){a.beginPath();var g=this._highlight_input_slot.shape;g===h.ARROW_SHAPE?(a.moveTo(this._highlight_input[0]+8,this._highlight_input[1]+.5),a.lineTo(this._highlight_input[0]-4,this._highlight_input[1]+
|
|
187
|
+
6+.5),a.lineTo(this._highlight_input[0]-4,this._highlight_input[1]-6+.5),a.closePath()):a.arc(this._highlight_input[0],this._highlight_input[1],6,0,2*Math.PI);a.fill()}this._highlight_output&&(a.beginPath(),g===h.ARROW_SHAPE?(a.moveTo(this._highlight_output[0]+8,this._highlight_output[1]+.5),a.lineTo(this._highlight_output[0]-4,this._highlight_output[1]+6+.5),a.lineTo(this._highlight_output[0]-4,this._highlight_output[1]-6+.5),a.closePath()):a.arc(this._highlight_output[0],this._highlight_output[1],
|
|
188
|
+
6,0,2*Math.PI),a.fill())}this.dragging_rectangle&&(a.strokeStyle="#FFF",a.strokeRect(this.dragging_rectangle[0],this.dragging_rectangle[1],this.dragging_rectangle[2],this.dragging_rectangle[3]));if(this.over_link_center&&this.render_link_tooltip)this.drawLinkTooltip(a,this.over_link_center);else if(this.onDrawLinkTooltip)this.onDrawLinkTooltip(a,null);if(this.onDrawForeground)this.onDrawForeground(a,this.visible_rect);a.restore()}this._graph_stack&&this._graph_stack.length&&this.drawSubgraphPanel(a);
|
|
189
|
+
if(this.onDrawOverlay)this.onDrawOverlay(a);c&&a.restore();a.finish2D&&a.finish2D()}};q.prototype.drawSubgraphPanel=function(a){var b=this.graph,c=b._subgraph_node;c?(this.drawSubgraphPanelLeft(b,c,a),this.drawSubgraphPanelRight(b,c,a)):console.warn("subgraph without subnode")};q.prototype.drawSubgraphPanelLeft=function(a,b,c){var d=b.inputs?b.inputs.length:0,e=Math.floor(1.6*h.NODE_SLOT_HEIGHT);c.fillStyle="#111";c.globalAlpha=.8;c.beginPath();c.roundRect(10,10,200,(d+1)*e+50,[8]);c.fill();c.globalAlpha=
|
|
190
|
+
1;c.fillStyle="#888";c.font="14px Arial";c.textAlign="left";c.fillText("Graph Inputs",20,34);if(this.drawButton(180,20,20,20,"X","#151515"))this.closeSubgraph();else{d=50;c.font="14px Arial";if(b.inputs)for(var f=0;f<b.inputs.length;++f){var g=b.inputs[f];if(!g.not_subgraph_input){if(this.drawButton(20,d+2,180,e-2)){var k=b.constructor.input_node_type||"graph/input";this.graph.beforeChange();var m=h.createNode(k);m?(a.add(m),this.block_click=!1,this.last_click_position=null,this.selectNodes([m]),
|
|
191
|
+
this.node_dragged=m,this.dragging_canvas=!1,m.setProperty("name",g.name),m.setProperty("type",g.type),this.node_dragged.pos[0]=this.graph_mouse[0]-5,this.node_dragged.pos[1]=this.graph_mouse[1]-5,this.graph.afterChange()):console.error("graph input node not found:",k)}c.fillStyle="#9C9";c.beginPath();c.arc(184,d+.5*e,5,0,2*Math.PI);c.fill();c.fillStyle="#AAA";c.fillText(g.name,30,d+.75*e);c.fillStyle="#777";c.fillText(g.type,130,d+.75*e);d+=e}}this.drawButton(20,d+2,180,e-2,"+","#151515","#222")&&
|
|
192
|
+
this.showSubgraphPropertiesDialog(b)}};q.prototype.drawSubgraphPanelRight=function(a,b,c){var d=b.outputs?b.outputs.length:0,e=this.bgcanvas.width,f=Math.floor(1.6*h.NODE_SLOT_HEIGHT);c.fillStyle="#111";c.globalAlpha=.8;c.beginPath();c.roundRect(e-200-10,10,200,(d+1)*f+50,[8]);c.fill();c.globalAlpha=1;c.fillStyle="#888";c.font="14px Arial";c.textAlign="left";d=c.measureText("Graph Outputs").width;c.fillText("Graph Outputs",e-d-20,34);if(this.drawButton(e-200,20,20,20,"X","#151515"))this.closeSubgraph();
|
|
193
|
+
else{d=50;c.font="14px Arial";if(b.outputs)for(var g=0;g<b.outputs.length;++g){var k=b.outputs[g];if(!k.not_subgraph_input){if(this.drawButton(e-200,d+2,180,f-2)){var m=b.constructor.output_node_type||"graph/output";this.graph.beforeChange();var l=h.createNode(m);l?(a.add(l),this.block_click=!1,this.last_click_position=null,this.selectNodes([l]),this.node_dragged=l,this.dragging_canvas=!1,l.setProperty("name",k.name),l.setProperty("type",k.type),this.node_dragged.pos[0]=this.graph_mouse[0]-5,this.node_dragged.pos[1]=
|
|
194
|
+
this.graph_mouse[1]-5,this.graph.afterChange()):console.error("graph input node not found:",m)}c.fillStyle="#9C9";c.beginPath();c.arc(e-200+16,d+.5*f,5,0,2*Math.PI);c.fill();c.fillStyle="#AAA";c.fillText(k.name,e-200+30,d+.75*f);c.fillStyle="#777";c.fillText(k.type,e-200+130,d+.75*f);d+=f}}this.drawButton(e-200,d+2,180,f-2,"+","#151515","#222")&&this.showSubgraphPropertiesDialogRight(b)}};q.prototype.drawButton=function(a,b,c,d,e,f,g,k){var m=this.ctx;f=f||h.NODE_DEFAULT_COLOR;g=g||"#555";k=k||h.NODE_TEXT_COLOR;
|
|
195
|
+
var l=this.ds.convertOffsetToCanvas(this.graph_mouse),n=h.isInsideRectangle(l[0],l[1],a,b,c,d);if(l=this.last_click_position?[this.last_click_position[0],this.last_click_position[1]]:null){var p=this.canvas.getBoundingClientRect();l[0]-=p.left;l[1]-=p.top}l=l&&h.isInsideRectangle(l[0],l[1],a,b,c,d);m.fillStyle=n?g:f;l&&(m.fillStyle="#AAA");m.beginPath();m.roundRect(a,b,c,d,[4]);m.fill();null!=e&&e.constructor==String&&(m.fillStyle=k,m.textAlign="center",m.font=(.65*d|0)+"px Arial",m.fillText(e,a+
|
|
196
|
+
.5*c,b+.75*d),m.textAlign="left");a=l&&!this.block_click;l&&this.blockClick();return a};q.prototype.isAreaClicked=function(a,b,c,d,e){var f=this.mouse;h.isInsideRectangle(f[0],f[1],a,b,c,d);b=(a=(f=this.last_click_position)&&h.isInsideRectangle(f[0],f[1],a,b,c,d))&&!this.block_click;a&&e&&this.blockClick();return b};q.prototype.renderInfo=function(a,b,c){b=b||10;c=c||this.canvas.height-80;a.save();a.translate(b,c);a.font="10px Arial";a.fillStyle="#888";a.textAlign="left";this.graph?(a.fillText("T: "+
|
|
197
|
+
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()};q.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=
|
|
198
|
+
this.bgcanvas.getContext("2d"));var b=this.bgctx;b.start&&b.start();var c=this.viewport||[0,0,b.canvas.width,b.canvas.height];this.clear_background&&b.clearRect(c[0],c[1],c[2],c[3]);if(this._graph_stack&&this._graph_stack.length){b.save();c=this.graph._subgraph_node;b.strokeStyle=c.bgcolor;b.lineWidth=10;b.strokeRect(1,1,a.width-2,a.height-2);b.lineWidth=1;b.font="40px Arial";b.textAlign="center";b.fillStyle=c.bgcolor||"#AAA";for(var d="",e=1;e<this._graph_stack.length;++e)d+=this._graph_stack[e]._subgraph_node.getTitle()+
|
|
199
|
+
" >> ";b.fillText(d+c.getTitle(),.5*a.width,40);b.restore()}c=!1;this.onRenderBackground&&(c=this.onRenderBackground(a,b));this.viewport||(b.restore(),b.setTransform(1,0,0,1,0,0));this.visible_links.length=0;if(this.graph){b.save();this.ds.toCanvasContext(b);1.5>this.ds.scale&&!c&&this.clear_background_color&&(b.fillStyle=this.clear_background_color,b.fillRect(this.visible_area[0],this.visible_area[1],this.visible_area[2],this.visible_area[3]));if(this.background_image&&.5<this.ds.scale&&!c){b.globalAlpha=
|
|
200
|
+
this.zoom_modify_alpha?(1-.5/this.ds.scale)*this.editor_alpha:this.editor_alpha;b.imageSmoothingEnabled=b.imageSmoothingEnabled=!1;if(!this._bg_img||this._bg_img.name!=this.background_image){this._bg_img=new Image;this._bg_img.name=this.background_image;this._bg_img.src=this.background_image;var f=this;this._bg_img.onload=function(){f.draw(!0,!0)}}c=null;null==this._pattern&&0<this._bg_img.width?(c=b.createPattern(this._bg_img,"repeat"),this._pattern_img=this._bg_img,this._pattern=c):c=this._pattern;
|
|
201
|
+
c&&(b.fillStyle=c,b.fillRect(this.visible_area[0],this.visible_area[1],this.visible_area[2],this.visible_area[3]),b.fillStyle="transparent");b.globalAlpha=1;b.imageSmoothingEnabled=b.imageSmoothingEnabled=!0}this.graph._groups.length&&!this.live_mode&&this.drawGroups(a,b);if(this.onDrawBackground)this.onDrawBackground(b,this.visible_area);this.onBackgroundRender&&(console.error("WARNING! onBackgroundRender deprecated, now is named onDrawBackground "),this.onBackgroundRender=null);this.render_canvas_border&&
|
|
202
|
+
(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 N=new Float32Array(2);q.prototype.drawNode=function(a,b){this.current_node=a;var c=a.color||a.constructor.color||h.NODE_DEFAULT_COLOR,d=a.bgcolor||a.constructor.bgcolor||
|
|
203
|
+
h.NODE_DEFAULT_BGCOLOR,e=.6>this.ds.scale;if(this.live_mode){if(!a.flags.collapsed&&(b.shadowColor="transparent",a.onDrawForeground))a.onDrawForeground(b,this,this.canvas)}else{var f=this.editor_alpha;b.globalAlpha=f;this.render_shadows&&!e?(b.shadowColor=h.DEFAULT_SHADOW_COLOR,b.shadowOffsetX=2*this.ds.scale,b.shadowOffsetY=2*this.ds.scale,b.shadowBlur=3*this.ds.scale):b.shadowColor="transparent";if(!a.flags.collapsed||!a.onDrawCollapsed||1!=a.onDrawCollapsed(b,this)){var g=a._shape||h.BOX_SHAPE;
|
|
204
|
+
N.set(a.size);var k=a.horizontal;if(a.flags.collapsed){b.font=this.inner_text_font;var m=a.getTitle?a.getTitle():a.title;null!=m&&(a._collapsed_width=Math.min(a.size[0],b.measureText(m).width+2*h.NODE_TITLE_HEIGHT),N[0]=a._collapsed_width,N[1]=0)}a.clip_area&&(b.save(),b.beginPath(),g==h.BOX_SHAPE?b.rect(0,0,N[0],N[1]):g==h.ROUND_SHAPE?b.roundRect(0,0,N[0],N[1],[10]):g==h.CIRCLE_SHAPE&&b.arc(.5*N[0],.5*N[1],.5*N[0],0,2*Math.PI),b.clip());a.has_errors&&(d="red");this.drawNodeShape(a,b,N,c,d,a.is_selected,
|
|
205
|
+
a.mouseOver);b.shadowColor="transparent";if(a.onDrawForeground)a.onDrawForeground(b,this,this.canvas);b.textAlign=k?"center":"left";b.font=this.inner_text_font;d=!e;var l=this.connecting_output;g=this.connecting_input;b.lineWidth=1;m=0;var n=new Float32Array(2);if(!a.flags.collapsed){if(a.inputs)for(c=0;c<a.inputs.length;c++){var p=a.inputs[c],r=p.type,u=p.shape;b.globalAlpha=f;this.connecting_output&&!h.isValidConnection(p.type,l.type)&&(b.globalAlpha=.4*f);b.fillStyle=null!=p.link?p.color_on||this.default_connection_color_byType[r]||
|
|
206
|
+
this.default_connection_color.input_on:p.color_off||this.default_connection_color_byTypeOff[r]||this.default_connection_color_byType[r]||this.default_connection_color.input_off;var t=a.getConnectionPos(!0,c,n);t[0]-=a.pos[0];t[1]-=a.pos[1];m<t[1]+.5*h.NODE_SLOT_HEIGHT&&(m=t[1]+.5*h.NODE_SLOT_HEIGHT);b.beginPath();"array"==r&&(u=h.GRID_SHAPE);p.type===h.EVENT||p.shape===h.BOX_SHAPE?k?b.rect(t[0]-5+.5,t[1]-8+.5,10,14):b.rect(t[0]-6+.5,t[1]-5+.5,14,10):u===h.ARROW_SHAPE?(b.moveTo(t[0]+8,t[1]+.5),b.lineTo(t[0]-
|
|
207
|
+
4,t[1]+6+.5),b.lineTo(t[0]-4,t[1]-6+.5),b.closePath()):u===h.GRID_SHAPE?(b.rect(t[0]-4,t[1]-4,2,2),b.rect(t[0]-1,t[1]-4,2,2),b.rect(t[0]+2,t[1]-4,2,2),b.rect(t[0]-4,t[1]-1,2,2),b.rect(t[0]-1,t[1]-1,2,2),b.rect(t[0]+2,t[1]-1,2,2),b.rect(t[0]-4,t[1]+2,2,2),b.rect(t[0]-1,t[1]+2,2,2),b.rect(t[0]+2,t[1]+2,2,2)):e?b.rect(t[0]-4,t[1]-4,8,8):b.arc(t[0],t[1],4,0,2*Math.PI);b.fill();d&&(r=null!=p.label?p.label:p.name)&&(b.fillStyle=h.NODE_TEXT_COLOR,k||p.dir==h.UP?b.fillText(r,t[0],t[1]-10):b.fillText(r,t[0]+
|
|
208
|
+
10,t[1]+5))}b.textAlign=k?"center":"right";b.strokeStyle="black";if(a.outputs)for(c=0;c<a.outputs.length;c++)if(p=a.outputs[c],r=p.type,u=p.shape,this.connecting_input&&!h.isValidConnection(r,g.type)&&(b.globalAlpha=.4*f),t=a.getConnectionPos(!1,c,n),t[0]-=a.pos[0],t[1]-=a.pos[1],m<t[1]+.5*h.NODE_SLOT_HEIGHT&&(m=t[1]+.5*h.NODE_SLOT_HEIGHT),b.fillStyle=p.links&&p.links.length?p.color_on||this.default_connection_color_byType[r]||this.default_connection_color.output_on:p.color_off||this.default_connection_color_byTypeOff[r]||
|
|
209
|
+
this.default_connection_color_byType[r]||this.default_connection_color.output_off,b.beginPath(),"array"==r&&(u=h.GRID_SHAPE),l=!0,r===h.EVENT||u===h.BOX_SHAPE?k?b.rect(t[0]-5+.5,t[1]-8+.5,10,14):b.rect(t[0]-6+.5,t[1]-5+.5,14,10):u===h.ARROW_SHAPE?(b.moveTo(t[0]+8,t[1]+.5),b.lineTo(t[0]-4,t[1]+6+.5),b.lineTo(t[0]-4,t[1]-6+.5),b.closePath()):u===h.GRID_SHAPE?(b.rect(t[0]-4,t[1]-4,2,2),b.rect(t[0]-1,t[1]-4,2,2),b.rect(t[0]+2,t[1]-4,2,2),b.rect(t[0]-4,t[1]-1,2,2),b.rect(t[0]-1,t[1]-1,2,2),b.rect(t[0]+
|
|
210
|
+
2,t[1]-1,2,2),b.rect(t[0]-4,t[1]+2,2,2),b.rect(t[0]-1,t[1]+2,2,2),b.rect(t[0]+2,t[1]+2,2,2),l=!1):e?b.rect(t[0]-4,t[1]-4,8,8):b.arc(t[0],t[1],4,0,2*Math.PI),b.fill(),!e&&l&&b.stroke(),d&&(r=null!=p.label?p.label:p.name))b.fillStyle=h.NODE_TEXT_COLOR,k||p.dir==h.DOWN?b.fillText(r,t[0],t[1]-8):b.fillText(r,t[0]-10,t[1]+5);b.textAlign="left";b.globalAlpha=1;if(a.widgets){p=m;if(k||a.widgets_up)p=2;null!=a.widgets_start_y&&(p=a.widgets_start_y);this.drawNodeWidgets(a,p,b,this.node_widget&&this.node_widget[0]==
|
|
211
|
+
a?this.node_widget[1]:null)}}else if(this.render_collapsed_slots){e=f=null;if(a.inputs)for(c=0;c<a.inputs.length;c++)if(p=a.inputs[c],null!=p.link){f=p;break}if(a.outputs)for(c=0;c<a.outputs.length;c++)p=a.outputs[c],p.links&&p.links.length&&(e=p);f&&(f=0,c=-.5*h.NODE_TITLE_HEIGHT,k&&(f=.5*a._collapsed_width,c=-h.NODE_TITLE_HEIGHT),b.fillStyle="#686",b.beginPath(),p.type===h.EVENT||p.shape===h.BOX_SHAPE?b.rect(f-7+.5,c-4,14,8):p.shape===h.ARROW_SHAPE?(b.moveTo(f+8,c),b.lineTo(f+-4,c-4),b.lineTo(f+
|
|
212
|
+
-4,c+4),b.closePath()):b.arc(f,c,4,0,2*Math.PI),b.fill());e&&(f=a._collapsed_width,c=-.5*h.NODE_TITLE_HEIGHT,k&&(f=.5*a._collapsed_width,c=0),b.fillStyle="#686",b.strokeStyle="black",b.beginPath(),p.type===h.EVENT||p.shape===h.BOX_SHAPE?b.rect(f-7+.5,c-4,14,8):p.shape===h.ARROW_SHAPE?(b.moveTo(f+6,c),b.lineTo(f-6,c-4),b.lineTo(f-6,c+4),b.closePath()):b.arc(f,c,4,0,2*Math.PI),b.fill())}a.clip_area&&b.restore();b.globalAlpha=1}}};q.prototype.drawLinkTooltip=function(a,b){var c=b._pos;a.fillStyle="black";
|
|
213
|
+
a.beginPath();a.arc(c[0],c[1],3,0,2*Math.PI);a.fill();if(null!=b.data&&(!this.onDrawLinkTooltip||1!=this.onDrawLinkTooltip(a,b,this))&&(b=b.data,b=b.constructor===Number?b.toFixed(2):b.constructor===String?'"'+b+'"':b.constructor===Boolean?String(b):b.toToolTip?b.toToolTip():"["+b.constructor.name+"]",null!=b)){b=b.substr(0,30);a.font="14px Courier New";var d=a.measureText(b).width+20;a.shadowColor="black";a.shadowOffsetX=2;a.shadowOffsetY=2;a.shadowBlur=3;a.fillStyle="#454";a.beginPath();a.roundRect(c[0]-
|
|
214
|
+
.5*d,c[1]-15-24,d,24,[3]);a.moveTo(c[0]-10,c[1]-15);a.lineTo(c[0]+10,c[1]-15);a.lineTo(c[0],c[1]-5);a.fill();a.shadowColor="transparent";a.textAlign="center";a.fillStyle="#CEC";a.fillText(b,c[0],c[1]-15-24*.3)}};var C=new Float32Array(4);q.prototype.drawNodeShape=function(a,b,c,d,e,f,g){b.strokeStyle=d;b.fillStyle=e;e=h.NODE_TITLE_HEIGHT;var k=.5>this.ds.scale,m=a._shape||a.constructor.shape||h.ROUND_SHAPE,l=a.constructor.title_mode,n=!0;l==h.TRANSPARENT_TITLE||l==h.NO_TITLE?n=!1:l==h.AUTOHIDE_TITLE&&
|
|
215
|
+
g&&(n=!0);C[0]=0;C[1]=n?-e:0;C[2]=c[0]+1;C[3]=n?c[1]+e:c[1];g=b.globalAlpha;b.beginPath();m==h.BOX_SHAPE||k?b.fillRect(C[0],C[1],C[2],C[3]):m==h.ROUND_SHAPE||m==h.CARD_SHAPE?b.roundRect(C[0],C[1],C[2],C[3],m==h.CARD_SHAPE?[this.round_radius,this.round_radius,0,0]:[this.round_radius]):m==h.CIRCLE_SHAPE&&b.arc(.5*c[0],.5*c[1],.5*c[0],0,2*Math.PI);b.fill();!a.flags.collapsed&&n&&(b.shadowColor="transparent",b.fillStyle="rgba(0,0,0,0.2)",b.fillRect(0,-1,C[2],2));b.shadowColor="transparent";if(a.onDrawBackground)a.onDrawBackground(b,
|
|
216
|
+
this,this.canvas,this.graph_mouse);if(n||l==h.TRANSPARENT_TITLE){if(a.onDrawTitleBar)a.onDrawTitleBar(b,e,c,this.ds.scale,d);else if(l!=h.TRANSPARENT_TITLE&&(a.constructor.title_color||this.render_title_colored)){n=a.constructor.title_color||d;a.flags.collapsed&&(b.shadowColor=h.DEFAULT_SHADOW_COLOR);if(this.use_gradients){var p=q.gradients[n];p||(p=q.gradients[n]=b.createLinearGradient(0,0,400,0),p.addColorStop(0,n),p.addColorStop(1,"#000"));b.fillStyle=p}else b.fillStyle=n;b.beginPath();m==h.BOX_SHAPE||
|
|
217
|
+
k?b.rect(0,-e,c[0]+1,e):(m==h.ROUND_SHAPE||m==h.CARD_SHAPE)&&b.roundRect(0,-e,c[0]+1,e,a.flags.collapsed?[this.round_radius]:[this.round_radius,this.round_radius,0,0]);b.fill();b.shadowColor="transparent"}n=!1;h.node_box_coloured_by_mode&&h.NODE_MODES_COLORS[a.mode]&&(n=h.NODE_MODES_COLORS[a.mode]);h.node_box_coloured_when_on&&(n=a.action_triggered?"#FFF":a.execute_triggered?"#AAA":n);if(a.onDrawTitleBox)a.onDrawTitleBox(b,e,c,this.ds.scale);else m==h.ROUND_SHAPE||m==h.CIRCLE_SHAPE||m==h.CARD_SHAPE?
|
|
218
|
+
(k&&(b.fillStyle="black",b.beginPath(),b.arc(.5*e,-.5*e,6,0,2*Math.PI),b.fill()),b.fillStyle=a.boxcolor||n||h.NODE_DEFAULT_BOXCOLOR,k?b.fillRect(.5*e-5,-.5*e-5,10,10):(b.beginPath(),b.arc(.5*e,-.5*e,5,0,2*Math.PI),b.fill())):(k&&(b.fillStyle="black",b.fillRect(.5*(e-10)-1,-.5*(e+10)-1,12,12)),b.fillStyle=a.boxcolor||n||h.NODE_DEFAULT_BOXCOLOR,b.fillRect(.5*(e-10),-.5*(e+10),10,10));b.globalAlpha=g;if(a.onDrawTitleText)a.onDrawTitleText(b,e,c,this.ds.scale,this.title_text_font,f);!k&&(b.font=this.title_text_font,
|
|
219
|
+
g=String(a.getTitle()))&&(b.fillStyle=f?h.NODE_SELECTED_TITLE_COLOR:a.constructor.title_text_color||this.node_title_color,a.flags.collapsed?(b.textAlign="left",b.measureText(g),b.fillText(g.substr(0,20),e,h.NODE_TITLE_TEXT_Y-e),b.textAlign="left"):(b.textAlign="left",b.fillText(g,e,h.NODE_TITLE_TEXT_Y-e)));a.flags.collapsed||!a.subgraph||a.skip_subgraph_button||(g=h.NODE_TITLE_HEIGHT,n=a.size[0]-g,p=h.isInsideRectangle(this.graph_mouse[0]-a.pos[0],this.graph_mouse[1]-a.pos[1],n+2,-g+2,g-4,g-4),b.fillStyle=
|
|
220
|
+
p?"#888":"#555",m==h.BOX_SHAPE||k?b.fillRect(n+2,-g+2,g-4,g-4):(b.beginPath(),b.roundRect(n+2,-g+2,g-4,g-4,[4]),b.fill()),b.fillStyle="#333",b.beginPath(),b.moveTo(n+.2*g,.6*-g),b.lineTo(n+.8*g,.6*-g),b.lineTo(n+.5*g,.3*-g),b.fill());if(a.onDrawTitle)a.onDrawTitle(b)}if(f){if(a.onBounding)a.onBounding(C);l==h.TRANSPARENT_TITLE&&(C[1]-=e,C[3]+=e);b.lineWidth=1;b.globalAlpha=.8;b.beginPath();m==h.BOX_SHAPE?b.rect(-6+C[0],-6+C[1],12+C[2],12+C[3]):m==h.ROUND_SHAPE||m==h.CARD_SHAPE&&a.flags.collapsed?
|
|
221
|
+
b.roundRect(-6+C[0],-6+C[1],12+C[2],12+C[3],[2*this.round_radius]):m==h.CARD_SHAPE?b.roundRect(-6+C[0],-6+C[1],12+C[2],12+C[3],[2*this.round_radius,2,2*this.round_radius,2]):m==h.CIRCLE_SHAPE&&b.arc(.5*c[0],.5*c[1],.5*c[0]+6,0,2*Math.PI);b.strokeStyle=h.NODE_BOX_OUTLINE_COLOR;b.stroke();b.strokeStyle=d;b.globalAlpha=1}0<a.execute_triggered&&a.execute_triggered--;0<a.action_triggered&&a.action_triggered--};var aa=new Float32Array(4),H=new Float32Array(4),ia=new Float32Array(2),ja=new Float32Array(2);
|
|
222
|
+
q.prototype.drawConnections=function(a){var b=h.getTime(),c=this.visible_area;aa[0]=c[0]-20;aa[1]=c[1]-20;aa[2]=c[2]+40;aa[3]=c[3]+40;a.lineWidth=this.connections_width;a.fillStyle="#AAA";a.strokeStyle="#AAA";a.globalAlpha=this.editor_alpha;c=this.graph._nodes;for(var d=0,e=c.length;d<e;++d){var f=c[d];if(f.inputs&&f.inputs.length)for(var g=0;g<f.inputs.length;++g){var k=f.inputs[g];if(k&&null!=k.link&&(k=this.graph.links[k.link])){var m=this.graph.getNodeById(k.origin_id);if(null!=m){var l=k.origin_slot;
|
|
223
|
+
var n=-1==l?[m.pos[0]+10,m.pos[1]+10]:m.getConnectionPos(!1,l,ia);var p=f.getConnectionPos(!0,g,ja);H[0]=n[0];H[1]=n[1];H[2]=p[0]-n[0];H[3]=p[1]-n[1];0>H[2]&&(H[0]+=H[2],H[2]=Math.abs(H[2]));0>H[3]&&(H[1]+=H[3],H[3]=Math.abs(H[3]));if(Z(H,aa)){var r=m.outputs[l];l=f.inputs[g];if(r&&l&&(m=r.dir||(m.horizontal?h.DOWN:h.RIGHT),l=l.dir||(f.horizontal?h.UP:h.LEFT),this.renderLink(a,n,p,k,!1,0,null,m,l),k&&k._last_time&&1E3>b-k._last_time)){r=2-.002*(b-k._last_time);var u=a.globalAlpha;a.globalAlpha=u*
|
|
224
|
+
r;this.renderLink(a,n,p,k,!0,r,"white",m,l);a.globalAlpha=u}}}}}}a.globalAlpha=1};q.prototype.renderLink=function(a,b,c,d,e,f,g,k,m,l){d&&this.visible_links.push(d);!g&&d&&(g=d.color||q.link_type_colors[d.type]);g||(g=this.default_link_color);null!=d&&this.highlighted_links[d.id]&&(g="#FFF");k=k||h.RIGHT;m=m||h.LEFT;var n=ba(b,c);this.render_connections_border&&.6<this.ds.scale&&(a.lineWidth=this.connections_width+4);a.lineJoin="round";l=l||1;1<l&&(a.lineWidth=.5);a.beginPath();for(var p=0;p<l;p+=
|
|
225
|
+
1){var r=5*(p-.5*(l-1));if(this.links_render_mode==h.SPLINE_LINK){a.moveTo(b[0],b[1]+r);var u=0,t=0,x=0,z=0;switch(k){case h.LEFT:u=-.25*n;break;case h.RIGHT:u=.25*n;break;case h.UP:t=-.25*n;break;case h.DOWN:t=.25*n}switch(m){case h.LEFT:x=-.25*n;break;case h.RIGHT:x=.25*n;break;case h.UP:z=-.25*n;break;case h.DOWN:z=.25*n}a.bezierCurveTo(b[0]+u,b[1]+t+r,c[0]+x,c[1]+z+r,c[0],c[1]+r)}else if(this.links_render_mode==h.LINEAR_LINK){a.moveTo(b[0],b[1]+r);z=x=t=u=0;switch(k){case h.LEFT:u=-1;break;case h.RIGHT:u=
|
|
226
|
+
1;break;case h.UP:t=-1;break;case h.DOWN:t=1}switch(m){case h.LEFT:x=-1;break;case h.RIGHT:x=1;break;case h.UP:z=-1;break;case h.DOWN:z=1}a.lineTo(b[0]+15*u,b[1]+15*t+r);a.lineTo(c[0]+15*x,c[1]+15*z+r);a.lineTo(c[0],c[1]+r)}else if(this.links_render_mode==h.STRAIGHT_LINK)a.moveTo(b[0],b[1]),r=b[0],u=b[1],t=c[0],x=c[1],k==h.RIGHT?r+=10:u+=10,m==h.LEFT?t-=10:x-=10,a.lineTo(r,u),a.lineTo(.5*(r+t),u),a.lineTo(.5*(r+t),x),a.lineTo(t,x),a.lineTo(c[0],c[1]);else return}this.render_connections_border&&.6<
|
|
227
|
+
this.ds.scale&&!e&&(a.strokeStyle="rgba(0,0,0,0.5)",a.stroke());a.lineWidth=this.connections_width;a.fillStyle=a.strokeStyle=g;a.stroke();e=this.computeConnectionPoint(b,c,.5,k,m);d&&d._pos&&(d._pos[0]=e[0],d._pos[1]=e[1]);.6<=this.ds.scale&&this.highquality_render&&m!=h.CENTER&&(this.render_connection_arrows&&(p=this.computeConnectionPoint(b,c,.25,k,m),n=this.computeConnectionPoint(b,c,.26,k,m),d=this.computeConnectionPoint(b,c,.75,k,m),l=this.computeConnectionPoint(b,c,.76,k,m),this.render_curved_connections?
|
|
228
|
+
(n=-Math.atan2(n[0]-p[0],n[1]-p[1]),l=-Math.atan2(l[0]-d[0],l[1]-d[1])):l=n=c[1]>b[1]?0:Math.PI,a.save(),a.translate(p[0],p[1]),a.rotate(n),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore(),a.save(),a.translate(d[0],d[1]),a.rotate(l),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore()),a.beginPath(),a.arc(e[0],e[1],5,0,2*Math.PI),a.fill());if(f)for(a.fillStyle=g,p=0;5>p;++p)f=(.001*h.getTime()+.2*p)%1,e=this.computeConnectionPoint(b,c,f,k,
|
|
229
|
+
m),a.beginPath(),a.arc(e[0],e[1],5,0,2*Math.PI),a.fill()};q.prototype.computeConnectionPoint=function(a,b,c,d,e){d=d||h.RIGHT;e=e||h.LEFT;var f=ba(a,b),g=[a[0],a[1]],k=[b[0],b[1]];switch(d){case h.LEFT:g[0]+=-.25*f;break;case h.RIGHT:g[0]+=.25*f;break;case h.UP:g[1]+=-.25*f;break;case h.DOWN:g[1]+=.25*f}switch(e){case h.LEFT:k[0]+=-.25*f;break;case h.RIGHT:k[0]+=.25*f;break;case h.UP:k[1]+=-.25*f;break;case h.DOWN:k[1]+=.25*f}d=(1-c)*(1-c)*(1-c);e=3*(1-c)*(1-c)*c;f=3*(1-c)*c*c;c*=c*c;return[d*a[0]+
|
|
230
|
+
e*g[0]+f*k[0]+c*b[0],d*a[1]+e*g[1]+f*k[1]+c*b[1]]};q.prototype.drawExecutionOrder=function(a){a.shadowColor="transparent";a.globalAlpha=.25;a.textAlign="center";a.strokeStyle="white";a.globalAlpha=.75;for(var b=this.visible_nodes,c=0;c<b.length;++c){var d=b[c];a.fillStyle="black";a.fillRect(d.pos[0]-h.NODE_TITLE_HEIGHT,d.pos[1]-h.NODE_TITLE_HEIGHT,h.NODE_TITLE_HEIGHT,h.NODE_TITLE_HEIGHT);0==d.order&&a.strokeRect(d.pos[0]-h.NODE_TITLE_HEIGHT+.5,d.pos[1]-h.NODE_TITLE_HEIGHT+.5,h.NODE_TITLE_HEIGHT,h.NODE_TITLE_HEIGHT);
|
|
231
|
+
a.fillStyle="#FFF";a.fillText(d.order,d.pos[0]+-.5*h.NODE_TITLE_HEIGHT,d.pos[1]-6)}a.globalAlpha=1};q.prototype.drawNodeWidgets=function(a,b,c,d){if(!a.widgets||!a.widgets.length)return 0;var e=a.size[0],f=a.widgets;b+=2;var g=h.NODE_WIDGET_HEIGHT,k=.5<this.ds.scale;c.save();c.globalAlpha=this.editor_alpha;for(var m=h.WIDGET_OUTLINE_COLOR,l=h.WIDGET_BGCOLOR,n=h.WIDGET_TEXT_COLOR,p=h.WIDGET_SECONDARY_TEXT_COLOR,r=0;r<f.length;++r){var u=f[r],t=b;u.y&&(t=u.y);u.last_y=t;c.strokeStyle=m;c.fillStyle=
|
|
232
|
+
"#222";c.textAlign="left";u.disabled&&(c.globalAlpha*=.5);var x=u.width||e;switch(u.type){case "button":u.clicked&&(c.fillStyle="#AAA",u.clicked=!1,this.dirty_canvas=!0);c.fillRect(15,t,x-30,g);k&&!u.disabled&&c.strokeRect(15,t,x-30,g);k&&(c.textAlign="center",c.fillStyle=n,c.fillText(u.label||u.name,.5*x,t+.7*g));break;case "toggle":c.textAlign="left";c.strokeStyle=m;c.fillStyle=l;c.beginPath();k?c.roundRect(15,t,x-30,g,[.5*g]):c.rect(15,t,x-30,g);c.fill();k&&!u.disabled&&c.stroke();c.fillStyle=
|
|
233
|
+
u.value?"#89A":"#333";c.beginPath();c.arc(x-30,t+.5*g,.36*g,0,2*Math.PI);c.fill();if(k){c.fillStyle=p;var z=u.label||u.name;null!=z&&c.fillText(z,30,t+.7*g);c.fillStyle=u.value?n:p;c.textAlign="right";c.fillText(u.value?u.options.on||"true":u.options.off||"false",x-40,t+.7*g)}break;case "slider":c.fillStyle=l;c.fillRect(15,t,x-30,g);z=u.options.max-u.options.min;var B=(u.value-u.options.min)/z;0>B&&(B=0);1<B&&(B=1);c.fillStyle=u.options.hasOwnProperty("slider_color")?u.options.slider_color:d==u?"#89A":
|
|
234
|
+
"#678";c.fillRect(15,t,B*(x-30),g);k&&!u.disabled&&c.strokeRect(15,t,x-30,g);u.marker&&(z=(u.marker-u.options.min)/z,0>z&&(z=0),1<z&&(z=1),c.fillStyle=u.options.hasOwnProperty("marker_color")?u.options.marker_color:"#AA9",c.fillRect(15+z*(x-30),t,2,g));k&&(c.textAlign="center",c.fillStyle=n,c.fillText(u.label||u.name+" "+Number(u.value).toFixed(null!=u.options.precision?u.options.precision:3),.5*x,t+.7*g));break;case "number":case "combo":c.textAlign="left";c.strokeStyle=m;c.fillStyle=l;c.beginPath();
|
|
235
|
+
k?c.roundRect(15,t,x-30,g,[.5*g]):c.rect(15,t,x-30,g);c.fill();k&&(u.disabled||c.stroke(),c.fillStyle=n,u.disabled||(c.beginPath(),c.moveTo(31,t+5),c.lineTo(21,t+.5*g),c.lineTo(31,t+g-5),c.fill(),c.beginPath(),c.moveTo(x-15-16,t+5),c.lineTo(x-15-6,t+.5*g),c.lineTo(x-15-16,t+g-5),c.fill()),c.fillStyle=p,c.fillText(u.label||u.name,35,t+.7*g),c.fillStyle=n,c.textAlign="right","number"==u.type?c.fillText(Number(u.value).toFixed(void 0!==u.options.precision?u.options.precision:3),x-30-20,t+.7*g):(z=u.value,
|
|
236
|
+
u.options.values&&(B=u.options.values,B.constructor===Function&&(B=B()),B&&B.constructor!==Array&&(z=B[u.value])),c.fillText(z,x-30-20,t+.7*g)));break;case "string":case "text":c.textAlign="left";c.strokeStyle=m;c.fillStyle=l;c.beginPath();k?c.roundRect(15,t,x-30,g,[.5*g]):c.rect(15,t,x-30,g);c.fill();k&&(u.disabled||c.stroke(),c.save(),c.beginPath(),c.rect(15,t,x-30,g),c.clip(),c.fillStyle=p,z=u.label||u.name,null!=z&&c.fillText(z,30,t+.7*g),c.fillStyle=n,c.textAlign="right",c.fillText(String(u.value).substr(0,
|
|
237
|
+
30),x-30,t+.7*g),c.restore());break;default:u.draw&&u.draw(c,a,x,t,g)}b+=(u.computeSize?u.computeSize(x)[1]:g)+4;c.globalAlpha=this.editor_alpha}c.restore();c.textAlign="left"};q.prototype.processNodeWidgets=function(a,b,c,d){function e(E,F){"number"==E.type&&(F=Number(F));E.value=F;E.options&&E.options.property&&void 0!==a.properties[E.options.property]&&a.setProperty(E.options.property,F);E.callback&&E.callback(E.value,l,a,b,c)}if(!a.widgets||!a.widgets.length||!this.allow_interaction&&!a.flags.allow_interaction)return null;
|
|
238
|
+
for(var f=b[0]-a.pos[0],g=b[1]-a.pos[1],k=a.size[0],m=c.deltaX||c.deltax||0,l=this,n=this.getCanvasWindow(),p=0;p<a.widgets.length;++p){var r=a.widgets[p];if(r&&!r.disabled){var u=r.computeSize?r.computeSize(k)[1]:h.NODE_WIDGET_HEIGHT,t=r.width||k;if(r==d||!(6>f||f>t-12||g<r.last_y||g>r.last_y+u||void 0===r.last_y)){d=r.value;switch(r.type){case "button":c.type===h.pointerevents_method+"down"&&(r.callback&&setTimeout(function(){r.callback(r,l,a,b,c)},20),this.dirty_canvas=r.clicked=!0);break;case "slider":d=
|
|
239
|
+
r.value;n=ca((f-15)/(t-30),0,1);if(r.options.read_only)break;r.value=r.options.min+(r.options.max-r.options.min)*n;d!=r.value&&setTimeout(function(){e(r,r.value)},20);this.dirty_canvas=!0;break;case "number":case "combo":d=r.value;if(c.type==h.pointerevents_method+"move"&&"number"==r.type)m&&(r.value+=.1*m*(r.options.step||1)),null!=r.options.min&&r.value<r.options.min&&(r.value=r.options.min),null!=r.options.max&&r.value>r.options.max&&(r.value=r.options.max);else if(c.type==h.pointerevents_method+
|
|
240
|
+
"down"){var x=r.options.values;x&&x.constructor===Function&&(x=r.options.values(r,a));var z=null;"number"!=r.type&&(z=x.constructor===Array?x:Object.keys(x));f=40>f?-1:f>t-40?1:0;if("number"==r.type)r.value+=.1*f*(r.options.step||1),null!=r.options.min&&r.value<r.options.min&&(r.value=r.options.min),null!=r.options.max&&r.value>r.options.max&&(r.value=r.options.max);else if(f)n=-1,this.last_mouseclick=0,n=x.constructor===Object?z.indexOf(String(r.value))+f:z.indexOf(r.value)+f,n>=z.length&&(n=z.length-
|
|
241
|
+
1),0>n&&(n=0),r.value=x.constructor===Array?x[n]:n;else{var B=x!=z?Object.values(x):x;new h.ContextMenu(B,{scale:Math.max(1,this.ds.scale),event:c,className:"dark",callback:E.bind(r)},n);function E(F,da,M){x!=z&&(F=B.indexOf(F));this.value=F;e(this,F);l.dirty_canvas=!0;return!1}}}else c.type==h.pointerevents_method+"up"&&"number"==r.type&&(f=40>f?-1:f>t-40?1:0,200>c.click_time&&0==f&&this.prompt("Value",r.value,function(E){if(/^[0-9+\-*/()\s]+|\d+\.\d+$/.test(E))try{E=eval(E)}catch(F){}this.value=
|
|
242
|
+
Number(E);e(this,this.value)}.bind(r),c));d!=r.value&&setTimeout(function(){e(this,this.value)}.bind(r),20);this.dirty_canvas=!0;break;case "toggle":c.type==h.pointerevents_method+"down"&&(r.value=!r.value,setTimeout(function(){e(r,r.value)},20));break;case "string":case "text":c.type==h.pointerevents_method+"down"&&this.prompt("Value",r.value,function(E){e(this,E)}.bind(r),c,r.options?r.options.multiline:!1);break;default:r.mouse&&(this.dirty_canvas=r.mouse(c,[f,g],a))}if(d!=r.value){if(a.onWidgetChanged)a.onWidgetChanged(r.name,
|
|
243
|
+
r.value,d,r);a.graph._version++}return r}}}return null};q.prototype.drawGroups=function(a,b){if(this.graph){a=this.graph._groups;b.save();b.globalAlpha=.5*this.editor_alpha;for(var c=0;c<a.length;++c){var d=a[c];if(Z(this.visible_area,d._bounding)){b.fillStyle=d.color||"#335";b.strokeStyle=d.color||"#335";var e=d._pos,f=d._size;b.globalAlpha=.25*this.editor_alpha;b.beginPath();b.rect(e[0]+.5,e[1]+.5,f[0],f[1]);b.fill();b.globalAlpha=this.editor_alpha;b.stroke();b.beginPath();b.moveTo(e[0]+f[0],e[1]+
|
|
244
|
+
f[1]);b.lineTo(e[0]+f[0]-10,e[1]+f[1]);b.lineTo(e[0]+f[0],e[1]+f[1]-10);b.fill();f=d.font_size||h.DEFAULT_GROUP_FONT_SIZE;b.font=f+"px Arial";b.textAlign="left";b.fillText(d.title,e[0]+4,e[1]+f)}}b.restore()}};q.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)};q.prototype.resize=function(a,b){a||b||(b=this.canvas.parentNode,a=b.offsetWidth,b=b.offsetHeight);if(this.canvas.width!=a||this.canvas.height!=b)this.canvas.width=
|
|
245
|
+
a,this.canvas.height=b,this.bgcanvas.width=this.canvas.width,this.bgcanvas.height=this.canvas.height,this.setDirty(!0,!0)};q.prototype.switchLiveMode=function(a){if(a){var b=this,c=this.live_mode?1.1:.9;this.live_mode&&(this.live_mode=!1,this.editor_alpha=.1);var d=setInterval(function(){b.editor_alpha*=c;b.dirty_canvas=!0;b.dirty_bgcanvas=!0;1>c&&.01>b.editor_alpha&&(clearInterval(d),1>c&&(b.live_mode=!0));1<c&&.99<b.editor_alpha&&(clearInterval(d),b.editor_alpha=1)},1)}else this.live_mode=!this.live_mode,
|
|
246
|
+
this.dirty_bgcanvas=this.dirty_canvas=!0};q.prototype.onNodeSelectionChange=function(a){};q.onGroupAdd=function(a,b,c){a=q.active_canvas;a.getCanvasWindow();b=new h.LGraphGroup;b.pos=a.convertEventToCanvasOffset(c);a.graph.add(b)};q.getBoundaryNodes=function(a){let b=null,c=null,d=null,e=null;for(const f in a){const g=a[f],[k,m]=g.pos,[l,n]=g.size;if(null===b||m<b.pos[1])b=g;if(null===c||k+l>c.pos[0]+c.size[0])c=g;if(null===d||m+n>d.pos[1]+d.size[1])d=g;if(null===e||k<e.pos[0])e=g}return{top:b,right:c,
|
|
247
|
+
bottom:d,left:e}};q.prototype.boundaryNodesForSelection=function(){return q.getBoundaryNodes(Object.values(this.selected_nodes))};q.alignNodes=function(a,b,c){if(a){var d=q.active_canvas;a=void 0===c?q.getBoundaryNodes(a):{top:c,right:c,bottom:c,left:c};for(const [,e]of Object.entries(d.selected_nodes))switch(b){case "right":e.pos[0]=a.right.pos[0]+a.right.size[0]-e.size[0];break;case "left":e.pos[0]=a.left.pos[0];break;case "top":e.pos[1]=a.top.pos[1];break;case "bottom":e.pos[1]=a.bottom.pos[1]+
|
|
248
|
+
a.bottom.size[1]-e.size[1]}d.dirty_canvas=!0;d.dirty_bgcanvas=!0}};q.onNodeAlign=function(a,b,c,d,e){new h.ContextMenu(["Top","Bottom","Left","Right"],{event:c,callback:function(f){q.alignNodes(q.active_canvas.selected_nodes,f.toLowerCase(),e)},parentMenu:d})};q.onGroupAlign=function(a,b,c,d){new h.ContextMenu(["Top","Bottom","Left","Right"],{event:c,callback:function(e){q.alignNodes(q.active_canvas.selected_nodes,e.toLowerCase())},parentMenu:d})};q.onMenuAdd=function(a,b,c,d,e){function f(l,n){var p=
|
|
249
|
+
[];h.getNodeTypesCategories(g.filter||m.filter).filter(function(r){return r.startsWith(l)}).map(function(r){if(r){r=r.replace(new RegExp("^("+l+")"),"").split("/")[0];var u=""===l?r+"/":l+r+"/";-1!=r.indexOf("::")&&(r=r.split("::")[1]);-1===p.findIndex(function(t){return t.value===u})&&p.push({value:u,content:r,has_submenu:!0,callback:function(t,x,z,B){f(t.value,B)}})}});h.getNodeTypesInCategory(l.slice(0,-1),g.filter||m.filter).map(function(r){r.skip_list||p.push({value:r.type,content:r.title,has_submenu:!1,
|
|
250
|
+
callback:function(u,t,x,z){t=z.getFirstEvent();g.graph.beforeChange();if(u=h.createNode(u.value))u.pos=g.convertEventToCanvasOffset(t),g.graph.add(u);e&&e(u);g.graph.afterChange()}})});new h.ContextMenu(p,{event:c,parentMenu:n},k)}var g=q.active_canvas,k=g.getCanvasWindow(),m=g.graph;if(m)return f("",d),!1};q.onMenuCollapseAll=function(){};q.onMenuNodeEdit=function(){};q.showMenuNodeOptionalInputs=function(a,b,c,d,e){if(e){var f=this;a=q.active_canvas.getCanvasWindow();b=e.optional_inputs;e.onGetInputs&&
|
|
251
|
+
(b=e.onGetInputs());var g=[];if(b)for(var k=0;k<b.length;k++){var m=b[k];if(m){var l=m[0];m[2]||(m[2]={});m[2].label&&(l=m[2].label);m[2].removable=!0;l={content:l,value:m};m[1]==h.ACTION&&(l.className="event");g.push(l)}else g.push(null)}e.onMenuNodeInputs&&(b=e.onMenuNodeInputs(g))&&(g=b);if(g.length)return new h.ContextMenu(g,{event:c,callback:function(n,p,r){if(e&&(n.callback&&n.callback.call(f,e,n,p,r),n.value)){e.graph.beforeChange();e.addInput(n.value[0],n.value[1],n.value[2]);if(e.onNodeInputAdd)e.onNodeInputAdd(n.value);
|
|
252
|
+
e.setDirtyCanvas(!0,!0);e.graph.afterChange()}},parentMenu:d,node:e},a),!1;console.log("no input entries")}};q.showMenuNodeOptionalOutputs=function(a,b,c,d,e){function f(p,r,u){if(e&&(p.callback&&p.callback.call(g,e,p,r,u),p.value))if(u=p.value[1],!u||u.constructor!==Object&&u.constructor!==Array){e.graph.beforeChange();e.addOutput(p.value[0],p.value[1],p.value[2]);if(e.onNodeOutputAdd)e.onNodeOutputAdd(p.value);e.setDirtyCanvas(!0,!0);e.graph.afterChange()}else{p=[];for(var t in u)p.push({content:t,
|
|
253
|
+
value:u[t]});new h.ContextMenu(p,{event:r,callback:f,parentMenu:d,node:e});return!1}}if(e){var g=this;a=q.active_canvas.getCanvasWindow();b=e.optional_outputs;e.onGetOutputs&&(b=e.onGetOutputs());var k=[];if(b)for(var m=0;m<b.length;m++){var l=b[m];if(!l)k.push(null);else if(!e.flags||!e.flags.skip_repeated_outputs||-1==e.findOutputSlot(l[0])){var n=l[0];l[2]||(l[2]={});l[2].label&&(n=l[2].label);l[2].removable=!0;n={content:n,value:l};l[1]==h.EVENT&&(n.className="event");k.push(n)}}this.onMenuNodeOutputs&&
|
|
254
|
+
(k=this.onMenuNodeOutputs(k));h.do_add_triggers_slots&&-1==e.findOutputSlot("onExecuted")&&k.push({content:"On Executed",value:["onExecuted",h.EVENT,{nameLocked:!0}],className:"event"});e.onMenuNodeOutputs&&(b=e.onMenuNodeOutputs(k))&&(k=b);if(k.length)return new h.ContextMenu(k,{event:c,callback:f,parentMenu:d,node:e},a),!1}};q.onShowMenuNodeProperties=function(a,b,c,d,e){if(e&&e.properties){var f=q.active_canvas;b=f.getCanvasWindow();var g=[],k;for(k in e.properties){a=void 0!==e.properties[k]?
|
|
255
|
+
e.properties[k]:" ";"object"==typeof a&&(a=JSON.stringify(a));var m=e.getPropertyInfo(k);if("enum"==m.type||"combo"==m.type)a=q.getPropertyPrintableValue(a,m.values);a=q.decodeHTML(a);g.push({content:"<span class='property_name'>"+(m.label?m.label:k)+"</span><span class='property_value'>"+a+"</span>",value:k})}if(g.length)return new h.ContextMenu(g,{event:c,callback:function(l,n,p,r){e&&(n=this.getBoundingClientRect(),f.showEditPropertyValue(e,l.value,{position:[n.left,n.top]}))},parentMenu:d,allow_html:!0,
|
|
256
|
+
node:e},b),!1}};q.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};q.onMenuResizeNode=function(a,b,c,d,e){if(e){a=function(g){g.size=g.computeSize();if(g.onResize)g.onResize(g.size)};b=q.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)a(e);else for(var f in b.selected_nodes)a(b.selected_nodes[f]);e.setDirtyCanvas(!0,!0)}};q.prototype.showLinkMenu=function(a,b){var c=this,d=c.graph.getNodeById(a.origin_id),e=c.graph.getNodeById(a.target_id),
|
|
257
|
+
f=!1;d&&d.outputs&&d.outputs[a.origin_slot]&&(f=d.outputs[a.origin_slot].type);var g=!1;e&&e.outputs&&e.outputs[a.target_slot]&&(g=e.inputs[a.target_slot].type);var k=new h.ContextMenu(["Add Node",null,"Delete",null],{event:b,title:null!=a.data?a.data.constructor.name:null,callback:function(m,l,n){switch(m){case "Add Node":q.onMenuAdd(null,null,n,k,function(p){p.inputs&&p.inputs.length&&p.outputs&&p.outputs.length&&d.connectByType(a.origin_slot,p,f)&&(p.connectByType(a.target_slot,e,g),p.pos[0]-=
|
|
258
|
+
.5*p.size[0])});break;case "Delete":c.graph.removeLink(a.id)}}});return!1};q.prototype.createDefaultNodeForSlot=function(a){a=a||{};a=Object.assign({nodeFrom:null,slotFrom:null,nodeTo:null,slotTo:null,position:[],nodeType:null,posAdd:[0,0],posSizeFix:[0,0]},a);var b=a.nodeFrom&&null!==a.slotFrom,c=!b&&a.nodeTo&&null!==a.slotTo;if(!b&&!c)return console.warn("No data passed to createDefaultNodeForSlot "+a.nodeFrom+" "+a.slotFrom+" "+a.nodeTo+" "+a.slotTo),!1;if(!a.nodeType)return console.warn("No type to createDefaultNodeForSlot"),
|
|
259
|
+
!1;var d=b?a.nodeFrom:a.nodeTo,e=b?a.slotFrom:a.slotTo;switch(typeof e){case "string":c=b?d.findOutputSlot(e,!1):d.findInputSlot(e,!1);e=b?d.outputs[e]:d.inputs[e];break;case "object":c=b?d.findOutputSlot(e.name):d.findInputSlot(e.name);break;case "number":c=e;e=b?d.outputs[e]:d.inputs[e];break;default:return console.warn("Cant get slot information "+e),!1}!1!==e&&!1!==c||console.warn("createDefaultNodeForSlot bad slotX "+e+" "+c);d=e.type==h.EVENT?"_event_":e.type;if((e=b?h.slot_types_default_out:
|
|
260
|
+
h.slot_types_default_in)&&e[d]){nodeNewType=!1;if("object"==typeof e[d]||"array"==typeof e[d])for(var f in e[d]){if(a.nodeType==e[d][f]||"AUTO"==a.nodeType){nodeNewType=e[d][f];break}}else if(a.nodeType==e[d]||"AUTO"==a.nodeType)nodeNewType=e[d];if(nodeNewType){f=!1;"object"==typeof nodeNewType&&nodeNewType.node&&(f=nodeNewType,nodeNewType=nodeNewType.node);if(e=h.createNode(nodeNewType)){if(f){if(f.properties)for(var g in f.properties)e.addProperty(g,f.properties[g]);if(f.inputs)for(g in e.inputs=
|
|
261
|
+
[],f.inputs)e.addOutput(f.inputs[g][0],f.inputs[g][1]);if(f.outputs)for(g in e.outputs=[],f.outputs)e.addOutput(f.outputs[g][0],f.outputs[g][1]);f.title&&(e.title=f.title);f.json&&e.configure(f.json)}this.graph.add(e);e.pos=[a.position[0]+a.posAdd[0]+(a.posSizeFix[0]?a.posSizeFix[0]*e.size[0]:0),a.position[1]+a.posAdd[1]+(a.posSizeFix[1]?a.posSizeFix[1]*e.size[1]:0)];b?a.nodeFrom.connectByType(c,e,d):a.nodeTo.connectByTypeOutput(c,e,d);return!0}console.log("failed creating "+nodeNewType)}}return!1};
|
|
262
|
+
q.prototype.showConnectionMenu=function(a){a=a||{};var b=Object.assign({nodeFrom:null,slotFrom:null,nodeTo:null,slotTo:null,e:null},a),c=this,d=b.nodeFrom&&b.slotFrom;a=!d&&b.nodeTo&&b.slotTo;if(!d&&!a)return console.warn("No data passed to showConnectionMenu"),!1;a=d?b.nodeFrom:b.nodeTo;var e=d?b.slotFrom:b.slotTo,f=!1;switch(typeof e){case "string":f=d?a.findOutputSlot(e,!1):a.findInputSlot(e,!1);e=d?a.outputs[e]:a.inputs[e];break;case "object":f=d?a.findOutputSlot(e.name):a.findInputSlot(e.name);
|
|
263
|
+
break;case "number":f=e;e=d?a.outputs[e]:a.inputs[e];break;default:return console.warn("Cant get slot information "+e),!1}a=["Add Node",null];c.allow_searchbox&&(a.push("Search"),a.push(null));var g=e.type==h.EVENT?"_event_":e.type,k=d?h.slot_types_default_out:h.slot_types_default_in;if(k&&k[g])if("object"==typeof k[g]||"array"==typeof k[g])for(var m in k[g])a.push(k[g][m]);else a.push(k[g]);var l=new h.ContextMenu(a,{event:b.e,title:(e&&""!=e.name?e.name+(g?" | ":""):"")+(e&&g?g:""),callback:function(n,
|
|
264
|
+
p,r){switch(n){case "Add Node":q.onMenuAdd(null,null,r,l,function(u){d?b.nodeFrom.connectByType(f,u,g):b.nodeTo.connectByTypeOutput(f,u,g)});break;case "Search":d?c.showSearchBox(r,{node_from:b.nodeFrom,slot_from:e,type_filter_in:g}):c.showSearchBox(r,{node_to:b.nodeTo,slot_from:e,type_filter_out:g});break;default:c.createDefaultNodeForSlot(Object.assign(b,{position:[b.e.canvasX,b.e.canvasY],nodeType:n}))}}});return!1};q.onShowPropertyEditor=function(a,b,c,d,e){function f(){if(m){var p=m.value;"Number"==
|
|
265
|
+
a.type?p=Number(p):"Boolean"==a.type&&(p=!!p);e[g]=p;k.parentNode&&k.parentNode.removeChild(k);e.setDirtyCanvas(!0,!0)}}var g=a.property||"title";b=e[g];var k=document.createElement("div");k.is_modified=!1;k.className="graphdialog";k.innerHTML="<span class='name'></span><input autofocus type='text' class='value'/><button>OK</button>";k.close=function(){k.parentNode&&k.parentNode.removeChild(k)};k.querySelector(".name").innerText=g;var m=k.querySelector(".value");m&&(m.value=b,m.addEventListener("blur",
|
|
266
|
+
function(p){this.focus()}),m.addEventListener("keydown",function(p){k.is_modified=!0;if(27==p.keyCode)k.close();else if(13==p.keyCode)f();else if(13!=p.keyCode&&"textarea"!=p.target.localName)return;p.preventDefault();p.stopPropagation()}));b=q.active_canvas.canvas;c=b.getBoundingClientRect();var l=d=-20;c&&(d-=c.left,l-=c.top);event?(k.style.left=event.clientX+d+"px",k.style.top=event.clientY+l+"px"):(k.style.left=.5*b.width+d+"px",k.style.top=.5*b.height+l+"px");k.querySelector("button").addEventListener("click",
|
|
267
|
+
f);b.parentNode.appendChild(k);m&&m.focus();var n=null;k.addEventListener("mouseleave",function(p){h.dialog_close_on_mouse_leave&&!k.is_modified&&h.dialog_close_on_mouse_leave&&(n=setTimeout(k.close,h.dialog_close_on_mouse_leave_delay))});k.addEventListener("mouseenter",function(p){h.dialog_close_on_mouse_leave&&n&&clearTimeout(n)})};q.prototype.prompt=function(a,b,c,d,e){var f=this;a=a||"";var g=document.createElement("div");g.is_modified=!1;g.className="graphdialog rounded";g.innerHTML=e?"<span class='name'></span> <textarea autofocus class='value'></textarea><button class='rounded'>OK</button>":
|
|
268
|
+
"<span class='name'></span> <input autofocus type='text' class='value'/><button class='rounded'>OK</button>";g.close=function(){f.prompt_box=null;g.parentNode&&g.parentNode.removeChild(g)};e=q.active_canvas.canvas;e.parentNode.appendChild(g);1<this.ds.scale&&(g.style.transform="scale("+this.ds.scale+")");var k=null,m=!1;h.pointerListenerAdd(g,"leave",function(p){m||h.dialog_close_on_mouse_leave&&!g.is_modified&&h.dialog_close_on_mouse_leave&&(k=setTimeout(g.close,h.dialog_close_on_mouse_leave_delay))});
|
|
269
|
+
h.pointerListenerAdd(g,"enter",function(p){h.dialog_close_on_mouse_leave&&k&&clearTimeout(k)});var l=g.querySelectorAll("select");l&&l.forEach(function(p){p.addEventListener("click",function(r){m++});p.addEventListener("blur",function(r){m=0});p.addEventListener("change",function(r){m=-1})});f.prompt_box&&f.prompt_box.close();f.prompt_box=g;g.querySelector(".name").innerText=a;var n=g.querySelector(".value");n.value=b;n.addEventListener("keydown",function(p){g.is_modified=!0;if(27==p.keyCode)g.close();
|
|
270
|
+
else if(13==p.keyCode&&"textarea"!=p.target.localName)c&&c(this.value),g.close();else return;p.preventDefault();p.stopPropagation()});g.querySelector("button").addEventListener("click",function(p){c&&c(n.value);f.setDirty(!0);g.close()});a=e.getBoundingClientRect();l=b=-20;a&&(b-=a.left,l-=a.top);d?(g.style.left=d.clientX+b+"px",g.style.top=d.clientY+l+"px"):(g.style.left=.5*e.width+b+"px",g.style.top=.5*e.height+l+"px");setTimeout(function(){n.focus()},10);return g};q.search_limit=-1;q.prototype.showSearchBox=
|
|
271
|
+
function(a,b){function c(A){if(A)if(f.onSearchBoxSelection)f.onSearchBoxSelection(A,a,g);else{var y=h.searchbox_extras[A.toLowerCase()];y&&(A=y.type);g.graph.beforeChange();if(A=h.createNode(A))A.pos=g.convertEventToCanvasOffset(a),g.graph.add(A,!1);if(y&&y.data){if(y.data.properties)for(var I in y.data.properties)A.addProperty(I,y.data.properties[I]);if(y.data.inputs)for(I in A.inputs=[],y.data.inputs)A.addOutput(y.data.inputs[I][0],y.data.inputs[I][1]);if(y.data.outputs)for(I in A.outputs=[],y.data.outputs)A.addOutput(y.data.outputs[I][0],
|
|
272
|
+
y.data.outputs[I][1]);y.data.title&&(A.title=y.data.title);y.data.json&&A.configure(y.data.json)}if(b.node_from){switch(typeof b.slot_from){case "string":y=b.node_from.findOutputSlot(b.slot_from);break;case "object":y=b.slot_from.name?b.node_from.findOutputSlot(b.slot_from.name):-1;-1==y&&"undefined"!==typeof b.slot_from.slot_index&&(y=b.slot_from.slot_index);break;case "number":y=b.slot_from;break;default:y=0}"undefined"!==typeof b.node_from.outputs[y]&&!1!==y&&-1<y&&b.node_from.connectByType(y,
|
|
273
|
+
A,b.node_from.outputs[y].type)}if(b.node_to){switch(typeof b.slot_from){case "string":y=b.node_to.findInputSlot(b.slot_from);break;case "object":y=b.slot_from.name?b.node_to.findInputSlot(b.slot_from.name):-1;-1==y&&"undefined"!==typeof b.slot_from.slot_index&&(y=b.slot_from.slot_index);break;case "number":y=b.slot_from;break;default:y=0}"undefined"!==typeof b.node_to.inputs[y]&&!1!==y&&-1<y&&b.node_to.connectByTypeOutput(y,A,b.node_to.inputs[y].type)}g.graph.afterChange()}l.close()}function d(A){var y=
|
|
274
|
+
B;B&&B.classList.remove("selected");B?(B=A?B.nextSibling:B.previousSibling)||(B=y):B=A?t.childNodes[0]:t.childNodes[t.childNodes.length];B&&(B.classList.add("selected"),B.scrollIntoView({block:"end",behavior:"smooth"}))}function e(){function A(R,U){var J=document.createElement("div");x||=R;J.innerText=R;J.dataset.type=escape(R);J.className="litegraph lite-search-item";U&&(J.className+=" "+U);J.addEventListener("click",function(G){c(unescape(this.dataset.type))});t.appendChild(J)}z=null;var y=E.value;
|
|
275
|
+
x=null;t.innerHTML="";if(y||b.show_all_if_empty)if(f.onSearchBox){var I=f.onSearchBox(t,y,g);if(I)for(var D=0;D<I.length;++D)A(I[D])}else{I=0;y=y.toLowerCase();var ea=g.filter||g.graph.filter;if(b.do_type_filter&&f.search_box)var V=f.search_box.querySelector(".slot_in_type_filter"),W=f.search_box.querySelector(".slot_out_type_filter");else W=V=!1;for(D in h.searchbox_extras){var O=h.searchbox_extras[D];if(b.show_all_if_empty&&!y||-1!==O.desc.toLowerCase().indexOf(y)){var fa=h.registered_node_types[O.type];
|
|
276
|
+
if((!fa||fa.filter==ea)&&R(O.type)&&(A(O.desc,"searchbox_extra"),-1!==q.search_limit&&I++>q.search_limit))break}}O=null;if(Array.prototype.filter)O=Object.keys(h.registered_node_types).filter(R);else for(D in O=[],h.registered_node_types)R(D)&&O.push(D);for(D=0;D<O.length&&!(A(O[D]),-1!==q.search_limit&&I++>q.search_limit);D++);if(b.show_general_after_typefiltered&&(V.value||W.value)){filtered_extra=[];for(D in h.registered_node_types)R(D,{inTypeOverride:V&&V.value?"*":!1,outTypeOverride:W&&W.value?
|
|
277
|
+
"*":!1})&&filtered_extra.push(D);for(D=0;D<filtered_extra.length&&!(A(filtered_extra[D],"generic_type"),-1!==q.search_limit&&I++>q.search_limit);D++);}if((V.value||W.value)&&0==t.childNodes.length&&b.show_general_if_none_on_typefilter){filtered_extra=[];for(D in h.registered_node_types)R(D,{skipFilter:!0})&&filtered_extra.push(D);for(D=0;D<filtered_extra.length&&!(A(filtered_extra[D],"not_in_filter"),-1!==q.search_limit&&I++>q.search_limit);D++);}function R(U,J){J=J||{};J=Object.assign({skipFilter:!1,
|
|
278
|
+
inTypeOverride:!1,outTypeOverride:!1},J);var G=h.registered_node_types[U];if(ea&&G.filter!=ea||(!b.show_all_if_empty||y)&&-1===U.toLowerCase().indexOf(y))return!1;if(b.do_type_filter&&!J.skipFilter){G=V.value;!1!==J.inTypeOverride&&(G=J.inTypeOverride);if(V&&G&&h.registered_slot_in_types[G]&&h.registered_slot_in_types[G].nodes&&(G=h.registered_slot_in_types[G].nodes.includes(U),!1===G))return!1;G=W.value;!1!==J.outTypeOverride&&(G=J.outTypeOverride);if(W&&G&&h.registered_slot_out_types[G]&&h.registered_slot_out_types[G].nodes&&
|
|
279
|
+
(G=h.registered_slot_out_types[G].nodes.includes(U),!1===G))return!1}return!0}}}b=Object.assign({slot_from:null,node_from:null,node_to:null,do_type_filter:h.search_filter_enabled,type_filter_in:!1,type_filter_out:!1,show_general_if_none_on_typefilter:!0,show_general_after_typefiltered:!0,hide_on_mouse_leave:h.search_hide_on_mouse_leave,show_all_if_empty:!0,show_all_on_open:h.search_show_all_on_open},b||{});var f=this,g=q.active_canvas,k=g.canvas,m=k.ownerDocument||document,l=document.createElement("div");
|
|
280
|
+
l.className="litegraph litesearchbox graphdialog rounded";l.innerHTML="<span class='name'>Search</span> <input autofocus type='text' class='value rounded'/>";b.do_type_filter&&(l.innerHTML+="<select class='slot_in_type_filter'><option value=''></option></select>",l.innerHTML+="<select class='slot_out_type_filter'><option value=''></option></select>");l.innerHTML+="<div class='helper'></div>";m.fullscreenElement?m.fullscreenElement.appendChild(l):(m.body.appendChild(l),m.body.style.overflow="hidden");
|
|
281
|
+
if(b.do_type_filter)var n=l.querySelector(".slot_in_type_filter"),p=l.querySelector(".slot_out_type_filter");l.close=function(){f.search_box=null;this.blur();k.focus();m.body.style.overflow="";setTimeout(function(){f.canvas.focus()},20);l.parentNode&&l.parentNode.removeChild(l)};1<this.ds.scale&&(l.style.transform="scale("+this.ds.scale+")");if(b.hide_on_mouse_leave){var r=!1,u=null;h.pointerListenerAdd(l,"enter",function(A){u&&(clearTimeout(u),u=null)});h.pointerListenerAdd(l,"leave",function(A){r||
|
|
282
|
+
(u=setTimeout(function(){l.close()},500))});b.do_type_filter&&(n.addEventListener("click",function(A){r++}),n.addEventListener("blur",function(A){r=0}),n.addEventListener("change",function(A){r=-1}),p.addEventListener("click",function(A){r++}),p.addEventListener("blur",function(A){r=0}),p.addEventListener("change",function(A){r=-1}))}f.search_box&&f.search_box.close();f.search_box=l;var t=l.querySelector(".helper"),x=null,z=null,B=null,E=l.querySelector("input");E&&(E.addEventListener("blur",function(A){f.search_box&&
|
|
283
|
+
this.focus()}),E.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)e(),B?c(B.innerHTML):x?c(x):l.close();else{z&&clearInterval(z);z=setTimeout(e,250);return}A.preventDefault();A.stopPropagation();A.stopImmediatePropagation();return!0}));if(b.do_type_filter){if(n){var F=h.slot_types_in,da=F.length;if(b.type_filter_in==h.EVENT||b.type_filter_in==h.ACTION)b.type_filter_in="_event_";for(var M=0;M<da;M++){var S=
|
|
284
|
+
document.createElement("option");S.value=F[M];S.innerHTML=F[M];n.appendChild(S);!1!==b.type_filter_in&&(b.type_filter_in+"").toLowerCase()==(F[M]+"").toLowerCase()&&(S.selected=!0)}n.addEventListener("change",function(){e()})}if(p){F=h.slot_types_out;da=F.length;if(b.type_filter_out==h.EVENT||b.type_filter_out==h.ACTION)b.type_filter_out="_event_";for(M=0;M<da;M++)S=document.createElement("option"),S.value=F[M],S.innerHTML=F[M],p.appendChild(S),!1!==b.type_filter_out&&(b.type_filter_out+"").toLowerCase()==
|
|
285
|
+
(F[M]+"").toLowerCase()&&(S.selected=!0);p.addEventListener("change",function(){e()})}}n=k.getBoundingClientRect();p=(a?a.clientY:n.top+.5*n.height)-20;l.style.left=(a?a.clientX:n.left+.5*n.width)-80+"px";l.style.top=p+"px";a.layerY>n.height-200&&(t.style.maxHeight=n.height-a.layerY-20+"px");E.focus();b.show_all_on_open&&e();return l};q.prototype.showEditPropertyValue=function(a,b,c){function d(){e(p.value)}function e(r){f&&f.values&&f.values.constructor===Object&&void 0!=f.values[r]&&(r=f.values[r]);
|
|
286
|
+
"number"==typeof a.properties[b]&&(r=Number(r));if("array"==g||"object"==g)r=JSON.parse(r);a.properties[b]=r;a.graph&&a.graph._version++;if(a.onPropertyChanged)a.onPropertyChanged(b,r);if(c.onclose)c.onclose();n.close();a.setDirtyCanvas(!0,!0)}if(a&&void 0!==a.properties[b]){c=c||{};var f=a.getPropertyInfo(b),g=f.type,k="";if("string"==g||"number"==g||"array"==g||"object"==g)k="<input autofocus type='text' class='value'/>";else if("enum"!=g&&"combo"!=g||!f.values)if("boolean"==g||"toggle"==g)k="<input autofocus type='checkbox' class='value' "+
|
|
287
|
+
(a.properties[b]?"checked":"")+"/>";else{console.warn("unknown type: "+g);return}else{k="<select autofocus type='text' class='value'>";for(var m in f.values){var l=m;f.values.constructor===Array&&(l=f.values[m]);k+="<option value='"+l+"' "+(l==a.properties[b]?"selected":"")+">"+f.values[m]+"</option>"}k+="</select>"}var n=this.createDialog("<span class='name'>"+(f.label?f.label:b)+"</span>"+k+"<button>OK</button>",c),p=!1;if("enum"!=g&&"combo"!=g||!f.values)if("boolean"==g||"toggle"==g)(p=n.querySelector("input"))&&
|
|
288
|
+
p.addEventListener("click",function(r){n.modified();e(!!p.checked)});else{if(p=n.querySelector("input"))p.addEventListener("blur",function(r){this.focus()}),l=void 0!==a.properties[b]?a.properties[b]:"","string"!==g&&(l=JSON.stringify(l)),p.value=l,p.addEventListener("keydown",function(r){if(27==r.keyCode)n.close();else if(13==r.keyCode)d();else if(13!=r.keyCode){n.modified();return}r.preventDefault();r.stopPropagation()})}else p=n.querySelector("select"),p.addEventListener("change",function(r){n.modified();
|
|
289
|
+
e(r.target.value)});p&&p.focus();n.querySelector("button").addEventListener("click",d);return n}};q.prototype.createDialog=function(a,b){b=Object.assign({checkForInput:!1,closeOnLeave:!0,closeOnLeave_checkModified:!0},b||{});var c=document.createElement("div");c.className="graphdialog";c.innerHTML=a;c.is_modified=!1;a=this.canvas.getBoundingClientRect();var d=-20,e=-20;a&&(d-=a.left,e-=a.top);b.position?(d+=b.position[0],e+=b.position[1]):b.event?(d+=b.event.clientX,e+=b.event.clientY):(d+=.5*this.canvas.width,
|
|
290
|
+
e+=.5*this.canvas.height);c.style.left=d+"px";c.style.top=e+"px";this.canvas.parentNode.appendChild(c);b.checkForInput&&(a=[],(a=c.querySelectorAll("input"))&&a.forEach(function(k){k.addEventListener("keydown",function(m){c.modified();if(27==m.keyCode)c.close();else if(13!=m.keyCode)return;m.preventDefault();m.stopPropagation()});k.focus()}));c.modified=function(){c.is_modified=!0};c.close=function(){c.parentNode&&c.parentNode.removeChild(c)};var f=null,g=!1;c.addEventListener("mouseleave",function(k){g||
|
|
291
|
+
(b.closeOnLeave||h.dialog_close_on_mouse_leave)&&!c.is_modified&&h.dialog_close_on_mouse_leave&&(f=setTimeout(c.close,h.dialog_close_on_mouse_leave_delay))});c.addEventListener("mouseenter",function(k){(b.closeOnLeave||h.dialog_close_on_mouse_leave)&&f&&clearTimeout(f)});(a=c.querySelectorAll("select"))&&a.forEach(function(k){k.addEventListener("click",function(m){g++});k.addEventListener("blur",function(m){g=0});k.addEventListener("change",function(m){g=-1})});return c};q.prototype.createPanel=function(a,
|
|
292
|
+
b){b=b||{};var c=b.window||window,d=document.createElement("div");d.className="litegraph dialog";d.innerHTML="<div class='dialog-header'><span class='dialog-title'></span></div><div class='dialog-content'></div><div style='display:none;' class='dialog-alt-content'></div><div class='dialog-footer'></div>";d.header=d.querySelector(".dialog-header");b.width&&(d.style.width=b.width+(b.width.constructor===Number?"px":""));b.height&&(d.style.height=b.height+(b.height.constructor===Number?"px":""));b.closable&&
|
|
293
|
+
(b=document.createElement("span"),b.innerHTML="✕",b.classList.add("close"),b.addEventListener("click",function(){d.close()}),d.header.appendChild(b));d.title_element=d.querySelector(".dialog-title");d.title_element.innerText=a;d.content=d.querySelector(".dialog-content");d.alt_content=d.querySelector(".dialog-alt-content");d.footer=d.querySelector(".dialog-footer");d.close=function(){if(d.onClose&&"function"==typeof d.onClose)d.onClose();d.parentNode&&d.parentNode.removeChild(d);this.parentNode&&
|
|
294
|
+
this.parentNode.removeChild(this)};d.toggleAltContent=function(e){if("undefined"!=typeof e){var f=e?"block":"none";e=e?"none":"block"}else f="block"!=d.alt_content.style.display?"block":"none",e="block"!=d.alt_content.style.display?"none":"block";d.alt_content.style.display=f;d.content.style.display=e};d.toggleFooterVisibility=function(e){d.footer.style.display="undefined"!=typeof e?e?"block":"none":"block"!=d.footer.style.display?"block":"none"};d.clear=function(){this.content.innerHTML=""};d.addHTML=
|
|
295
|
+
function(e,f,g){var k=document.createElement("div");f&&(k.className=f);k.innerHTML=e;g?d.footer.appendChild(k):d.content.appendChild(k);return k};d.addButton=function(e,f,g){var k=document.createElement("button");k.innerText=e;k.options=g;k.classList.add("btn");k.addEventListener("click",f);d.footer.appendChild(k);return k};d.addSeparator=function(){var e=document.createElement("div");e.className="separator";d.content.appendChild(e)};d.addWidget=function(e,f,g,k,m){function l(u,t){k.callback&&k.callback(u,
|
|
296
|
+
t,k);m&&m(u,t,k)}k=k||{};var n=String(g);e=e.toLowerCase();"number"==e&&(n=g.toFixed(3));var p=document.createElement("div");p.className="property";p.innerHTML="<span class='property_name'></span><span class='property_value'></span>";p.querySelector(".property_name").innerText=k.label||f;var r=p.querySelector(".property_value");r.innerText=n;p.dataset.property=f;p.dataset.type=k.type||e;p.options=k;p.value=g;if("code"==e)p.addEventListener("click",function(u){d.inner_showCodePad(this.dataset.property)});
|
|
297
|
+
else if("boolean"==e)p.classList.add("boolean"),g&&p.classList.add("bool-on"),p.addEventListener("click",function(){var u=this.dataset.property;this.value=!this.value;this.classList.toggle("bool-on");this.querySelector(".property_value").innerText=this.value?"true":"false";l(u,this.value)});else if("string"==e||"number"==e)r.setAttribute("contenteditable",!0),r.addEventListener("keydown",function(u){"Enter"!=u.code||"string"==e&&u.shiftKey||(u.preventDefault(),this.blur())}),r.addEventListener("blur",
|
|
298
|
+
function(){var u=this.innerText,t=this.parentNode.dataset.property;"number"==this.parentNode.dataset.type&&(u=Number(u));l(t,u)});else if("enum"==e||"combo"==e)n=q.getPropertyPrintableValue(g,k.values),r.innerText=n,r.addEventListener("click",function(u){var t=this.parentNode.dataset.property,x=this;new h.ContextMenu(k.values||[],{event:u,className:"dark",callback:function(z,B,E){x.innerText=z;l(t,z);return!1}},c)});d.content.appendChild(p);return p};if(d.onOpen&&"function"==typeof d.onOpen)d.onOpen();
|
|
299
|
+
return d};q.getPropertyPrintableValue=function(a,b){if(!b||b.constructor===Array)return String(a);if(b.constructor===Object){var c="",d;for(d in b)if(b[d]==a){c=d;break}return String(a)+" ("+c+")"}};q.prototype.closePanels=function(){var a=document.querySelector("#node-panel");a&&a.close();(a=document.querySelector("#option-panel"))&&a.close()};q.prototype.showShowGraphOptionsPanel=function(a,b,c,d){if(this.constructor&&"HTMLDivElement"==this.constructor.name){if(!(b&&b.event&&b.event.target&&b.event.target.lgraphcanvas)){console.warn("Canvas not found");
|
|
300
|
+
return}var e=b.event.target.lgraphcanvas}else e=this;e.closePanels();a=e.getCanvasWindow();panel=e.createPanel("Options",{closable:!0,window:a,onOpen:function(){e.OPTIONPANEL_IS_OPEN=!0},onClose:function(){e.OPTIONPANEL_IS_OPEN=!1;e.options_panel=null}});e.options_panel=panel;panel.id="option-panel";panel.classList.add("settings");(function(){panel.content.innerHTML="";var f=function(l,n,p){p&&p.key&&(l=p.key);p.values&&(n=Object.values(p.values).indexOf(n));e[l]=n},g=h.availableCanvasOptions;g.sort();
|
|
301
|
+
for(var k in g){var m=g[k];panel.addWidget("boolean",m,e[m],{key:m,on:"True",off:"False"},f)}panel.addWidget("combo","Render mode",h.LINK_RENDER_MODES[e.links_render_mode],{key:"links_render_mode",values:h.LINK_RENDER_MODES},f);panel.addSeparator();panel.footer.innerHTML=""})();e.canvas.parentNode.appendChild(panel)};q.prototype.showShowNodePanel=function(a){function b(){e.content.innerHTML="";e.addHTML("<span class='node_type'>"+a.type+"</span><span class='node_desc'>"+(a.constructor.desc||"")+"</span><span class='separator'></span>");
|
|
302
|
+
e.addHTML("<h3>Properties</h3>");var f=function(l,n){d.graph.beforeChange(a);switch(l){case "Title":a.title=n;break;case "Mode":l=Object.values(h.NODE_MODES).indexOf(n);0<=l&&h.NODE_MODES[l]?a.changeMode(l):console.warn("unexpected mode: "+n);break;case "Color":q.node_colors[n]?(a.color=q.node_colors[n].color,a.bgcolor=q.node_colors[n].bgcolor):console.warn("unexpected color: "+n);break;default:a.setProperty(l,n)}d.graph.afterChange();d.dirty_canvas=!0};e.addWidget("string","Title",a.title,{},f);
|
|
303
|
+
e.addWidget("combo","Mode",h.NODE_MODES[a.mode],{values:h.NODE_MODES},f);var g="";void 0!==a.color&&(g=Object.keys(q.node_colors).filter(function(l){return q.node_colors[l].color==a.color}));e.addWidget("combo","Color",g,{values:Object.keys(q.node_colors)},f);for(var k in a.properties){g=a.properties[k];var m=a.getPropertyInfo(k);a.onAddPropertyToPanel&&a.onAddPropertyToPanel(k,e)||e.addWidget(m.widget||m.type,k,g,m,f)}e.addSeparator();if(a.onShowCustomPanelInfo)a.onShowCustomPanelInfo(e);e.footer.innerHTML=
|
|
304
|
+
"";e.addButton("Delete",function(){a.block_delete||(a.graph.remove(a),e.close())}).classList.add("delete")}this.SELECTED_NODE=a;this.closePanels();var c=this.getCanvasWindow(),d=this,e=this.createPanel(a.title||"",{closable:!0,window:c,onOpen:function(){d.NODEPANEL_IS_OPEN=!0},onClose:function(){d.NODEPANEL_IS_OPEN=!1;d.node_panel=null}});d.node_panel=e;e.id="node-panel";e.node=a;e.classList.add("settings");e.inner_showCodePad=function(f){e.classList.remove("settings");e.classList.add("centered");
|
|
305
|
+
e.alt_content.innerHTML="<textarea class='code'></textarea>";var g=e.alt_content.querySelector("textarea"),k=function(){e.toggleAltContent(!1);e.toggleFooterVisibility(!0);g.parentNode.removeChild(g);e.classList.add("settings");e.classList.remove("centered");b()};g.value=a.properties[f];g.addEventListener("keydown",function(l){"Enter"==l.code&&l.ctrlKey&&(a.setProperty(f,g.value),k())});e.toggleAltContent(!0);e.toggleFooterVisibility(!1);g.style.height="calc(100% - 40px)";var m=e.addButton("Assign",
|
|
306
|
+
function(){a.setProperty(f,g.value);k()});e.alt_content.appendChild(m);m=e.addButton("Close",k);m.style.float="right";e.alt_content.appendChild(m)};b();this.canvas.parentNode.appendChild(e)};q.prototype.showSubgraphPropertiesDialog=function(a){function b(){d.clear();if(a.inputs)for(var e=0;e<a.inputs.length;++e){var f=a.inputs[e];if(!f.not_subgraph_input){var g=d.addHTML("<button>✕</button> <span class='bullet_icon'></span><span class='name'></span><span class='type'></span>","subgraph_property");
|
|
307
|
+
g.dataset.name=f.name;g.dataset.slot=e;g.querySelector(".name").innerText=f.name;g.querySelector(".type").innerText=f.type;g.querySelector("button").addEventListener("click",function(k){a.removeInput(Number(this.parentNode.dataset.slot));b()})}}}console.log("showing subgraph properties dialog");var c=this.canvas.parentNode.querySelector(".subgraph_dialog");c&&c.close();var d=this.createPanel("Subgraph Inputs",{closable:!0,width:500});d.node=a;d.classList.add("subgraph_dialog");d.addHTML(" + <span class='label'>Name</span><input class='name'/><span class='label'>Type</span><input class='type'></input><button>+</button>",
|
|
308
|
+
"subgraph_property extra",!0).querySelector("button").addEventListener("click",function(e){e=this.parentNode;var f=e.querySelector(".name").value,g=e.querySelector(".type").value;f&&-1==a.findInputSlot(f)&&(a.addInput(f,g),e.querySelector(".name").value="",e.querySelector(".type").value="",b())});b();this.canvas.parentNode.appendChild(d);return d};q.prototype.showSubgraphPropertiesDialogRight=function(a){function b(){e.clear();if(a.outputs)for(var f=0;f<a.outputs.length;++f){var g=a.outputs[f];if(!g.not_subgraph_output){var k=
|
|
309
|
+
e.addHTML("<button>✕</button> <span class='bullet_icon'></span><span class='name'></span><span class='type'></span>","subgraph_property");k.dataset.name=g.name;k.dataset.slot=f;k.querySelector(".name").innerText=g.name;k.querySelector(".type").innerText=g.type;k.querySelector("button").addEventListener("click",function(m){a.removeOutput(Number(this.parentNode.dataset.slot));b()})}}}function c(){var f=this.parentNode,g=f.querySelector(".name").value,k=f.querySelector(".type").value;g&&-1==a.findOutputSlot(g)&&
|
|
310
|
+
(a.addOutput(g,k),f.querySelector(".name").value="",f.querySelector(".type").value="",b())}var d=this.canvas.parentNode.querySelector(".subgraph_dialog");d&&d.close();var e=this.createPanel("Subgraph Outputs",{closable:!0,width:500});e.node=a;e.classList.add("subgraph_dialog");d=e.addHTML(" + <span class='label'>Name</span><input class='name'/><span class='label'>Type</span><input class='type'></input><button>+</button>","subgraph_property extra",!0);d.querySelector(".name").addEventListener("keydown",
|
|
311
|
+
function(f){13==f.keyCode&&c.apply(this)});d.querySelector("button").addEventListener("click",function(f){c.apply(this)});b();this.canvas.parentNode.appendChild(e);return e};q.prototype.checkPanels=function(){if(this.canvas)for(var a=this.canvas.parentNode.querySelectorAll(".litegraph.dialog"),b=0;b<a.length;++b){var c=a[b];c.node&&(c.node.graph&&c.graph==this.graph||c.close())}};q.onMenuNodeCollapse=function(a,b,c,d,e){e.graph.beforeChange();a=q.active_canvas;if(!a.selected_nodes||1>=Object.keys(a.selected_nodes).length)e.collapse();
|
|
312
|
+
else for(var f in a.selected_nodes)a.selected_nodes[f].collapse();e.graph.afterChange()};q.onMenuNodePin=function(a,b,c,d,e){e.pin()};q.onMenuNodeMode=function(a,b,c,d,e){new h.ContextMenu(h.NODE_MODES,{event:c,callback:function(f){if(e){var g=Object.values(h.NODE_MODES).indexOf(f),k=function(n){0<=g&&h.NODE_MODES[g]?n.changeMode(g):(console.warn("unexpected mode: "+f),n.changeMode(h.ALWAYS))},m=q.active_canvas;if(!m.selected_nodes||1>=Object.keys(m.selected_nodes).length)k(e);else for(var l in m.selected_nodes)k(m.selected_nodes[l])}},
|
|
313
|
+
parentMenu:d,node:e});return!1};q.onMenuNodeColors=function(a,b,c,d,e){if(!e)throw"no node for color";b=[];b.push({value:null,content:"<span style='display: block; padding-left: 4px;'>No color</span>"});for(var f in q.node_colors)a=q.node_colors[f],a={value:f,content:"<span style='display: block; color: #999; padding-left: 4px; border-left: 8px solid "+a.color+"; background-color:"+a.bgcolor+"'>"+f+"</span>"},b.push(a);new h.ContextMenu(b,{event:c,callback:function(g){if(e){var k=g.value?q.node_colors[g.value]:
|
|
314
|
+
null;g=function(n){k?n.constructor===h.LGraphGroup?n.color=k.groupcolor:(n.color=k.color,n.bgcolor=k.bgcolor):(delete n.color,delete n.bgcolor)};var m=q.active_canvas;if(!m.selected_nodes||1>=Object.keys(m.selected_nodes).length)g(e);else for(var l in m.selected_nodes)g(m.selected_nodes[l]);e.setDirtyCanvas(!0,!0)}},parentMenu:d,node:e});return!1};q.onMenuNodeShapes=function(a,b,c,d,e){if(!e)throw"no node passed";new h.ContextMenu(h.VALID_SHAPES,{event:c,callback:function(f){if(e){e.graph.beforeChange();
|
|
315
|
+
var g=q.active_canvas;if(!g.selected_nodes||1>=Object.keys(g.selected_nodes).length)e.shape=f;else for(var k in g.selected_nodes)g.selected_nodes[k].shape=f;e.graph.afterChange();e.setDirtyCanvas(!0)}},parentMenu:d,node:e});return!1};q.onMenuNodeRemove=function(a,b,c,d,e){if(!e)throw"no node passed";a=e.graph;a.beforeChange();b=q.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)!1!==e.removable&&a.remove(e);else for(var f in b.selected_nodes)c=b.selected_nodes[f],!1!==c.removable&&
|
|
316
|
+
a.remove(c);a.afterChange();e.setDirtyCanvas(!0,!0)};q.onMenuNodeToSubgraph=function(a,b,c,d,e){a=e.graph;if(b=q.active_canvas)c=Object.values(b.selected_nodes||{}),c.length||(c=[e]),d=h.createNode("graph/subgraph"),d.pos=e.pos.concat(),a.add(d),d.buildFromNodes(c),b.deselectAllNodes(),e.setDirtyCanvas(!0,!0)};q.onMenuNodeClone=function(a,b,c,d,e){e.graph.beforeChange();var f={};a=function(k){if(!1!==k.clonable){var m=k.clone();m&&(m.pos=[k.pos[0]+5,k.pos[1]+5],k.graph.add(m),f[m.id]=m)}};b=q.active_canvas;
|
|
317
|
+
if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)a(e);else for(var g in b.selected_nodes)a(b.selected_nodes[g]);Object.keys(f).length&&b.selectNodes(f);e.graph.afterChange();e.setDirtyCanvas(!0,!0)};q.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"},
|
|
318
|
+
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"}};q.prototype.getCanvasMenuOptions=function(){if(this.getMenuOptions)var a=this.getMenuOptions();else a=[{content:"Add Node",has_submenu:!0,callback:q.onMenuAdd},{content:"Add Group",callback:q.onGroupAdd}],1<Object.keys(this.selected_nodes).length&&a.push({content:"Align",has_submenu:!0,
|
|
319
|
+
callback:q.onGroupAlign}),this._graph_stack&&0<this._graph_stack.length&&a.push(null,{content:"Close subgraph",callback:this.closeSubgraph.bind(this)});if(this.getExtraMenuOptions){var b=this.getExtraMenuOptions(this,a);b&&(a=a.concat(b))}return a};q.prototype.getNodeMenuOptions=function(a){if(a.getMenuOptions)var b=a.getMenuOptions(this);else b=[{content:"Inputs",has_submenu:!0,disabled:!0,callback:q.showMenuNodeOptionalInputs},{content:"Outputs",has_submenu:!0,disabled:!0,callback:q.showMenuNodeOptionalOutputs},
|
|
320
|
+
null,{content:"Properties",has_submenu:!0,callback:q.onShowMenuNodeProperties},null,{content:"Title",callback:q.onShowPropertyEditor},{content:"Mode",has_submenu:!0,callback:q.onMenuNodeMode}],!1!==a.resizable&&b.push({content:"Resize",callback:q.onMenuResizeNode}),b.push({content:"Collapse",callback:q.onMenuNodeCollapse},{content:"Pin",callback:q.onMenuNodePin},{content:"Colors",has_submenu:!0,callback:q.onMenuNodeColors},{content:"Shapes",has_submenu:!0,callback:q.onMenuNodeShapes},null);if(a.onGetInputs){var c=
|
|
321
|
+
a.onGetInputs();c&&c.length&&(b[0].disabled=!1)}a.onGetOutputs&&(c=a.onGetOutputs())&&c.length&&(b[1].disabled=!1);a.getExtraMenuOptions&&(c=a.getExtraMenuOptions(this,b))&&(c.push(null),b=c.concat(b));!1!==a.clonable&&b.push({content:"Clone",callback:q.onMenuNodeClone});1<Object.keys(this.selected_nodes).length&&b.push({content:"Align Selected To",has_submenu:!0,callback:q.onNodeAlign});b.push(null,{content:"Remove",disabled:!(!1!==a.removable&&!a.block_delete),callback:q.onMenuNodeRemove});if(a.graph&&
|
|
322
|
+
a.graph.onGetNodeMenuOptions)a.graph.onGetNodeMenuOptions(b,a);return b};q.prototype.getGroupMenuOptions=function(a){return[{content:"Title",callback:q.onShowPropertyEditor},{content:"Color",has_submenu:!0,callback:q.onMenuNodeColors},{content:"Font size",property:"font_size",type:"Number",callback:q.onShowPropertyEditor},null,{content:"Remove",callback:q.onMenuNodeRemove}]};q.prototype.processContextMenu=function(a,b){var c=this,d=q.active_canvas.getCanvasWindow(),e=null,f={event:b,callback:function(k,
|
|
323
|
+
m,l){if(k)if("Remove Slot"==k.content)k=k.slot,a.graph.beforeChange(),k.input?a.removeInput(k.slot):k.output&&a.removeOutput(k.slot),a.graph.afterChange();else if("Disconnect Links"==k.content)k=k.slot,a.graph.beforeChange(),k.output?a.disconnectOutput(k.slot):k.input&&a.disconnectInput(k.slot),a.graph.afterChange();else if("Rename Slot"==k.content){k=k.slot;var n=k.input?a.getInputInfo(k.slot):a.getOutputInfo(k.slot),p=c.createDialog("<span class='name'>Name</span><input autofocus type='text'/><button>OK</button>",
|
|
324
|
+
m),r=p.querySelector("input");r&&n&&(r.value=n.label||"");var u=function(){a.graph.beforeChange();r.value&&(n&&(n.label=r.value),c.setDirty(!0));p.close();a.graph.afterChange()};p.querySelector("button").addEventListener("click",u);r.addEventListener("keydown",function(t){p.is_modified=!0;if(27==t.keyCode)p.close();else if(13==t.keyCode)u();else if(13!=t.keyCode&&"textarea"!=t.target.localName)return;t.preventDefault();t.stopPropagation()});r.focus()}},extra:a};a&&(f.title=a.type);var g=null;a&&(g=
|
|
325
|
+
a.getSlotInPosition(b.canvasX,b.canvasY),q.active_node=a);g?(e=[],a.getSlotMenuOptions?e=a.getSlotMenuOptions(g):(g&&g.output&&g.output.links&&g.output.links.length&&e.push({content:"Disconnect Links",slot:g}),b=g.input||g.output,b.removable&&e.push(b.locked?"Cannot remove":{content:"Remove Slot",slot:g}),b.nameLocked||e.push({content:"Rename Slot",slot:g})),f.title=(g.input?g.input.type:g.output.type)||"*",g.input&&g.input.type==h.ACTION&&(f.title="Action"),g.output&&g.output.type==h.EVENT&&(f.title=
|
|
326
|
+
"Event")):a?e=this.getNodeMenuOptions(a):(e=this.getCanvasMenuOptions(),(g=this.graph.getGroupOnPos(b.canvasX,b.canvasY))&&e.push(null,{content:"Edit Group",has_submenu:!0,submenu:{title:"Group",extra:g,options:this.getGroupMenuOptions(g)}}));e&&new h.ContextMenu(e,f,d)};h.compareObjects=function(a,b){for(var c in a)if(a[c]!=b[c])return!1;return!0};h.distance=ba;h.colorToString=function(a){return"rgba("+Math.round(255*a[0]).toFixed()+","+Math.round(255*a[1]).toFixed()+","+Math.round(255*a[2]).toFixed()+
|
|
327
|
+
","+(4==a.length?a[3].toFixed(2):"1.0")+")"};h.isInsideRectangle=K;h.growBounding=function(a,b,c){b<a[0]?a[0]=b:b>a[2]&&(a[2]=b);c<a[1]?a[1]=c:c>a[3]&&(a[3]=c)};h.isInsideBounding=function(a,b){return a[0]<b[0][0]||a[1]<b[0][1]||a[0]>b[1][0]||a[1]>b[1][1]?!1:!0};h.overlapBounding=Z;h.hex2num=function(a){"#"==a.charAt(0)&&(a=a.slice(1));a=a.toUpperCase();for(var b=Array(3),c=0,d,e,f=0;6>f;f+=2)d="0123456789ABCDEF".indexOf(a.charAt(f)),e="0123456789ABCDEF".indexOf(a.charAt(f+1)),b[c]=16*d+e,c++;return b};
|
|
328
|
+
h.num2hex=function(a){for(var b="#",c,d,e=0;3>e;e++)c=a[e]/16,d=a[e]%16,b+="0123456789ABCDEF".charAt(c)+"0123456789ABCDEF".charAt(d);return b};Q.prototype.addItem=function(a,b,c){function d(m){var l=this.value;l&&l.has_submenu&&e.call(this,m)}function e(m){var l=this.value,n=!0;f.current_submenu&&f.current_submenu.close(m);if(c.callback){var p=c.callback.call(this,l,c,m,f,c.node);!0===p&&(n=!1)}if(l&&(l.callback&&!c.ignore_item_callbacks&&!0!==l.disabled&&(p=l.callback.call(this,l,c,m,f,c.extra),
|
|
329
|
+
!0===p&&(n=!1)),l.submenu)){if(!l.submenu.options)throw"ContextMenu submenu needs options";new f.constructor(l.submenu.options,{callback:l.submenu.callback,event:m,parentMenu:f,ignore_item_callbacks:l.submenu.ignore_item_callbacks,title:l.submenu.title,extra:l.submenu.extra,autoopen:c.autoopen});n=!1}n&&!f.lock&&f.close()}var f=this;c=c||{};var g=document.createElement("div");g.className="litemenu-entry submenu";var k=!1;if(null===b)g.classList.add("separator");else{g.innerHTML=b&&b.title?b.title:
|
|
330
|
+
a;if(g.value=b)b.disabled&&(k=!0,g.classList.add("disabled")),(b.submenu||b.has_submenu)&&g.classList.add("has_submenu");"function"==typeof b?(g.dataset.value=a,g.onclick_callback=b):g.dataset.value=b;b.className&&(g.className+=" "+b.className)}this.root.appendChild(g);k||g.addEventListener("click",e);!k&&c.autoopen&&h.pointerListenerAdd(g,"enter",d);return g};Q.prototype.close=function(a,b){this.root.parentNode&&this.root.parentNode.removeChild(this.root);this.parentMenu&&!b&&(this.parentMenu.lock=
|
|
331
|
+
!1,this.parentMenu.current_submenu=null,void 0===a?this.parentMenu.close():a&&!Q.isCursorOverElement(a,this.parentMenu.root)&&Q.trigger(this.parentMenu.root,h.pointerevents_method+"leave",a));this.current_submenu&&this.current_submenu.close(a,!0);this.root.closing_timer&&clearTimeout(this.root.closing_timer)};Q.trigger=function(a,b,c,d){var e=document.createEvent("CustomEvent");e.initCustomEvent(b,!0,!0,c);e.srcElement=d;a.dispatchEvent?a.dispatchEvent(e):a.__events&&a.__events.dispatchEvent(e);return e};
|
|
332
|
+
Q.prototype.getTopMenu=function(){return this.options.parentMenu?this.options.parentMenu.getTopMenu():this};Q.prototype.getFirstEvent=function(){return this.options.parentMenu?this.options.parentMenu.getFirstEvent():this.options.event};Q.isCursorOverElement=function(a,b){var c=a.clientX;a=a.clientY;return(b=b.getBoundingClientRect())?a>b.top&&a<b.top+b.height&&c>b.left&&c<b.left+b.width?!0:!1:!1};h.ContextMenu=Q;h.closeAllContextMenus=function(a){a=a||window;a=a.document.querySelectorAll(".litecontextmenu");
|
|
333
|
+
if(a.length){for(var b=[],c=0;c<a.length;c++)b.push(a[c]);for(c=0;c<b.length;c++)b[c].close?b[c].close():b[c].parentNode&&b[c].parentNode.removeChild(b[c])}};h.extendClass=function(a,b){for(var c in b)a.hasOwnProperty(c)||(a[c]=b[c]);if(b.prototype)for(c in b.prototype)b.prototype.hasOwnProperty(c)&&!a.prototype.hasOwnProperty(c)&&(b.prototype.__lookupGetter__(c)?a.prototype.__defineGetter__(c,b.prototype.__lookupGetter__(c)):a.prototype[c]=b.prototype[c],b.prototype.__lookupSetter__(c)&&a.prototype.__defineSetter__(c,
|
|
334
|
+
b.prototype.__lookupSetter__(c)))};T.sampleCurve=function(a,b){if(b){for(var c=0;c<b.length-1;++c){var d=b[c],e=b[c+1];if(!(e[0]<a)){b=e[0]-d[0];if(1E-5>Math.abs(b))return d[1];a=(a-d[0])/b;return d[1]*(1-a)+e[1]*a}}return 0}};T.prototype.draw=function(a,b,c,d,e,f){if(c=this.points){this.size=b;var g=b[0]-2*this.margin;b=b[1]-2*this.margin;e=e||"#666";a.save();a.translate(this.margin,this.margin);d&&(a.fillStyle="#111",a.fillRect(0,0,g,b),a.fillStyle="#222",a.fillRect(.5*g,0,1,b),a.strokeStyle="#333",
|
|
335
|
+
a.strokeRect(0,0,g,b));a.strokeStyle=e;f&&(a.globalAlpha=.5);a.beginPath();for(d=0;d<c.length;++d)e=c[d],a.lineTo(e[0]*g,(1-e[1])*b);a.stroke();a.globalAlpha=1;if(!f)for(d=0;d<c.length;++d)e=c[d],a.fillStyle=this.selected==d?"#FFF":this.nearest==d?"#DDD":"#AAA",a.beginPath(),a.arc(e[0]*g,(1-e[1])*b,2,0,2*Math.PI),a.fill();a.restore()}};T.prototype.onMouseDown=function(a,b){var c=this.points;if(c&&!(0>a[1])){var d=this.size[0]-2*this.margin,e=this.size[1]-2*this.margin,f=a[0]-this.margin;a=a[1]-this.margin;
|
|
336
|
+
this.selected=this.getCloserPoint([f,a],30/b.ds.scale);-1==this.selected&&(b=[f/d,1-a/e],c.push(b),c.sort(function(g,k){return g[0]-k[0]}),this.selected=c.indexOf(b),this.must_update=!0);if(-1!=this.selected)return!0}};T.prototype.onMouseMove=function(a,b){var c=this.points;if(c){var d=this.selected;if(!(0>d)){var e=(a[0]-this.margin)/(this.size[0]-2*this.margin),f=(a[1]-this.margin)/(this.size[1]-2*this.margin);this._nearest=this.getCloserPoint([a[0]-this.margin,a[1]-this.margin],30/b.ds.scale);
|
|
337
|
+
if(b=c[d]){var g=0==d||d==c.length-1;!g&&(-10>a[0]||a[0]>this.size[0]+10||-10>a[1]||a[1]>this.size[1]+10)?(c.splice(d,1),this.selected=-1):(b[0]=g?0==d?0:1:ca(e,0,1),b[1]=1-ca(f,0,1),c.sort(function(k,m){return k[0]-m[0]}),this.selected=c.indexOf(b),this.must_update=!0)}}}};T.prototype.onMouseUp=function(a,b){this.selected=-1;return!1};T.prototype.getCloserPoint=function(a,b){var c=this.points;if(!c)return-1;b=b||30;for(var d=this.size[0]-2*this.margin,e=this.size[1]-2*this.margin,f=c.length,g=[0,
|
|
338
|
+
0],k=1E6,m=-1,l=0;l<f;++l){var n=c[l];g[0]=n[0]*d;g[1]=(1-n[1])*e;n=vec2.distance(a,g);n>k||n>b||(m=l,k=n)}return m};h.CurveEditor=T;h.getParameterNames=function(a){return(a+"").replace(/[/][/].*$/gm,"").replace(/\s+/g,"").replace(/[/][*][^/*]*[*][/]/g,"").split("){",1)[0].replace(/^[^(]*[(]/,"").replace(/=[^,]+/g,"").split(",").filter(Boolean)};h.pointerListenerAdd=function(a,b,c,d=!1){if(a&&a.addEventListener&&b&&"function"===typeof c){var e=h.pointerevents_method;if("pointer"==e&&!window.PointerEvent)switch(console.warn("sMethod=='pointer' && !window.PointerEvent"),
|
|
339
|
+
console.log("Converting pointer["+b+"] : down move up cancel enter TO touchstart touchmove touchend, etc .."),b){case "down":e="touch";b="start";break;case "move":e="touch";break;case "up":e="touch";b="end";break;case "cancel":e="touch";break;case "enter":console.log("debug: Should I send a move event?");break;default:console.warn("PointerEvent not available in this browser ? The event "+b+" would not be called")}switch(b){case "down":case "up":case "move":case "over":case "out":case "enter":a.addEventListener(e+
|
|
340
|
+
b,c,d);case "leave":case "cancel":case "gotpointercapture":case "lostpointercapture":if("mouse"!=e)return a.addEventListener(e+b,c,d);default:return a.addEventListener(b,c,d)}}};h.pointerListenerRemove=function(a,b,c,d=!1){if(a&&a.removeEventListener&&b&&"function"===typeof c)switch(b){case "down":case "up":case "move":case "over":case "out":case "enter":"pointer"!=h.pointerevents_method&&"mouse"!=h.pointerevents_method||a.removeEventListener(h.pointerevents_method+b,c,d);case "leave":case "cancel":case "gotpointercapture":case "lostpointercapture":if("pointer"==
|
|
341
|
+
h.pointerevents_method)return a.removeEventListener(h.pointerevents_method+b,c,d);default:return a.removeEventListener(b,c,d)}};X.clamp=ca;"undefined"==typeof window||window.requestAnimationFrame||(window.requestAnimationFrame=window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(a){window.setTimeout(a,1E3/60)})})(this);
|
|
342
|
+
"undefined"!=typeof exports&&(exports.LiteGraph=this.LiteGraph,exports.LGraph=this.LGraph,exports.LLink=this.LLink,exports.LGraphNode=this.LGraphNode,exports.LGraphGroup=this.LGraphGroup,exports.DragAndScale=this.DragAndScale,exports.LGraphCanvas=this.LGraphCanvas,exports.ContextMenu=this.ContextMenu);
|