mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-29 10:42:44 +00:00
fixes in mouse events
This commit is contained in:
246
build/litegraph.core.min.js
vendored
246
build/litegraph.core.min.js
vendored
@@ -46,7 +46,7 @@ this._nodes;if(e){c=c||e.length;if(b){for(var f=0;f<a;f++){for(var h=0;h<c;++h){
|
||||
!1}catch(n){this.errors_in_execution=!0;if(g.throw_errors)throw n;g.debug&&console.log("Error during execution: "+n);this.stop()}a=g.getTime();d=a-d;0==d&&(d=1);this.execution_time=.001*d;this.globaltime+=.001*d;this.iteration+=1;this.elapsed_time=.001*(a-this.last_update_time);this.last_update_time=a;this.nodes_executing=[];this.nodes_actioning=[];this.nodes_executedAction=[]}};v.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])};v.prototype.computeExecutionOrder=function(a,b){for(var c=[],d=[],e={},f={},h={},k=0,n=this._nodes.length;k<n;++k){var q=this._nodes[k];if(!a||q.onExecute){e[q.id]=q;var u=0;if(q.inputs)for(var r=0,m=q.inputs.length;r<m;r++)q.inputs[r]&&null!=q.inputs[r].link&&(u+=1);0==u?(d.push(q),b&&(q._level=1)):(b&&(q._level=0),h[q.id]=u)}}for(;0!=d.length;)if(q=d.shift(),
|
||||
c.push(q),delete e[q.id],q.outputs)for(k=0;k<q.outputs.length;k++)if(a=q.outputs[k],null!=a&&null!=a.links&&0!=a.links.length)for(r=0;r<a.links.length;r++)(n=this.links[a.links[r]])&&!f[n.id]&&(u=this.getNodeById(n.target_id),null==u?f[n.id]=!0:(b&&(!u._level||u._level<=q._level)&&(u._level=q._level+1),f[n.id]=!0,--h[u.id],0==h[u.id]&&d.push(u)));for(k in e)c.push(e[k]);c.length!=this._nodes.length&&g.debug&&console.warn("something went wrong, nodes missing");n=c.length;for(k=0;k<n;++k)c[k].order=
|
||||
k;c=c.sort(function(a,b){var c=a.constructor.priority||a.priority||0,e=b.constructor.priority||b.priority||0;return c==e?a.order-b.order:c-e});for(k=0;k<n;++k)c[k].order=k;return c};v.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 h=e.getInputNode(f);h&&-1==b.indexOf(h)&&c.push(h)}}}b.sort(function(a,b){return a.order-b.order});return b};v.prototype.arrange=function(a){a=
|
||||
k;c=c.sort(function(a,b){var c=a.constructor.priority||a.priority||0,d=b.constructor.priority||b.priority||0;return c==d?a.order-b.order:c-d});for(k=0;k<n;++k)c[k].order=k;return c};v.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 h=e.getInputNode(f);h&&-1==b.indexOf(h)&&c.push(h)}}}b.sort(function(a,b){return a.order-b.order});return b};v.prototype.arrange=function(a){a=
|
||||
a||100;for(var b=this.computeExecutionOrder(!1,!0),c=[],d=0;d<b.length;++d){var e=b[d],f=e._level||1;c[f]||(c[f]=[]);c[f].push(e)}b=a;for(d=0;d<c.length;++d)if(f=c[d]){for(var h=100,k=a+g.NODE_TITLE_HEIGHT,n=0;n<f.length;++n)e=f[n],e.pos[0]=b,e.pos[1]=k,e.size[0]>h&&(h=e.size[0]),k+=e.size[1]+a+g.NODE_TITLE_HEIGHT;b+=h+a}this.setDirtyCanvas(!0,!0)};v.prototype.getTime=function(){return this.globaltime};v.prototype.getFixedTime=function(){return this.fixedtime};v.prototype.getElapsedTime=function(){return this.elapsed_time};
|
||||
v.prototype.sendEventToAllNodes=function(a,b,c){c=c||g.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 h=d[e];if(h.constructor===g.Subgraph&&"onExecute"!=a)h.mode==c&&h.sendEventToAllNodes(a,b,c);else if(h[a]&&h.mode==c)if(void 0===b)h[a]();else if(b&&b.constructor===Array)h[a].apply(h,b);else h[a](b)}};v.prototype.sendActionToCanvas=function(a,b){if(this.list_of_graphcanvas)for(var c=0;c<this.list_of_graphcanvas.length;++c){var d=this.list_of_graphcanvas[c];
|
||||
d[a]&&d[a].apply(d,b)}};v.prototype.add=function(a,b){if(a)if(a.constructor===x)this._groups.push(a),this.setDirtyCanvas(!0),this.change(),a.graph=this,this._version++;else{-1!=a.id&&null!=this._nodes_by_id[a.id]&&(console.warn("LiteGraph: there is already a node with this ID, changing it"),a.id=++this.last_node_id);if(this._nodes.length>=g.MAX_NUMBER_OF_NODES)throw"LiteGraph: max number of nodes in a graph reached";null==a.id||-1==a.id?a.id=++this.last_node_id:this.last_node_id<a.id&&(this.last_node_id=
|
||||
@@ -141,122 +141,122 @@ this.canvas.removeEventListener("DOMMouseScroll",this._mousewheel_callback);this
|
||||
m.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()};m.prototype.enableWebGL=function(){this.gl=this.ctx=enableWebGLCanvas(this.canvas);this.ctx.webgl=!0;this.bgcanvas=this.canvas;this.bgctx=this.gl;this.canvas.webgl_enabled=!0};m.prototype.setDirty=function(a,b){a&&(this.dirty_canvas=!0);b&&(this.dirty_bgcanvas=!0)};m.prototype.getCanvasWindow=function(){if(!this.canvas)return window;var a=this.canvas.ownerDocument;
|
||||
return a.defaultView||a.parentWindow};m.prototype.startRendering=function(){function a(){this.pause_rendering||this.draw();var b=this.getCanvasWindow();this.is_rendering&&b.requestAnimationFrame(a.bind(this))}this.is_rendering||(this.is_rendering=!0,a.call(this))};m.prototype.stopRendering=function(){this.is_rendering=!1};m.prototype.blockClick=function(){this.block_click=!0;this.last_mouseclick=0};m.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();m.active_canvas=this;var c=this,d=a.clientX,e=a.clientY;this.ds.viewport=this.viewport;d=!this.viewport||this.viewport&&d>=this.viewport[0]&&d<this.viewport[0]+this.viewport[2]&&e>=this.viewport[1]&&e<this.viewport[1]+this.viewport[3];this.options.skip_events||(g.pointerListenerRemove(this.canvas,"move",this._mousemove_callback),g.pointerListenerAdd(b.document,"move",this._mousemove_callback,!0),g.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=300>g.getTime()-this.last_mouseclick&&void 0!==a.isPrimary&&a.isPrimary;this.mouse[0]=a.clientX;this.mouse[1]=a.clientY;this.graph_mouse[0]=a.canvasX;this.graph_mouse[1]=a.canvasY;this.last_click_position=[this.mouse[0],this.mouse[1]];this.pointer_is_double=this.pointer_is_down&&void 0!==a.isPrimary&&!a.isPrimary?!0:!1;this.pointer_is_down=!0;this.canvas.focus();g.closeAllContextMenus(b);
|
||||
if(!this.onMouse||1!=this.onMouse(a)){if(1!=a.which||this.pointer_is_double)if(2==a.which){if(g.middle_click_slot_add_default_node&&f&&this.allow_interaction&&!d&&!this.read_only&&!this.connecting_node&&!f.flags.collapsed&&!this.live_mode){e=d=h=!1;if(f.outputs)for(u=0,k=f.outputs.length;u<k;++u)if(n=f.outputs[u],q=f.getConnectionPos(!1,u),C(a.canvasX,a.canvasY,q[0]-15,q[1]-10,30,20)){h=n;d=u;e=!0;break}if(f.inputs)for(u=0,k=f.inputs.length;u<k;++u)if(n=f.inputs[u],q=f.getConnectionPos(!0,u),C(a.canvasX,
|
||||
a.canvasY,q[0]-15,q[1]-10,30,20)){h=n;d=u;e=!1;break}h&&!1!==d&&(u=.5-(d+1)/(e?f.outputs.length:f.inputs.length),h=f.getBounding(),this.createDefaultNodeForSlot({nodeFrom:e?f:null,slotFrom:e?d:null,nodeTo:e?null:f,slotTo:e?null:d,position:[e?h[0]+h[2]:h[0],a.canvasY-80],nodeType:"AUTO",posAdd:[e?30:-30,130*-u],posSizeFix:[e?0:-1,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]=a.canvasX,this.dragging_rectangle[1]=a.canvasY,this.dragging_rectangle[2]=1,this.dragging_rectangle[3]=1,d=!0);g.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,u||(this.allow_dragnodes&&(this.graph.beforeChange(),this.node_dragged=f),this.selected_nodes[f.id]||this.processNodeSelected(f,a)));var h=!1;if(f&&this.allow_interaction&&!d&&!this.read_only){this.live_mode||f.flags.pinned||this.bringToFront(f);if(!this.connecting_node&&!f.flags.collapsed&&!this.live_mode)if(!d&&!1!==f.resizable&&C(a.canvasX,a.canvasY,f.pos[0]+f.size[0]-5,f.pos[1]+f.size[1]-5,10,10))this.graph.beforeChange(),this.resizing_node=f,this.canvas.style.cursor="se-resize",
|
||||
d=!0;else{if(f.outputs){u=0;for(var k=f.outputs.length;u<k;++u){var n=f.outputs[u],q=f.getConnectionPos(!1,u);if(C(a.canvasX,a.canvasY,q[0]-15,q[1]-10,30,20)){this.connecting_node=f;this.connecting_output=n;this.connecting_output.slot_index=u;this.connecting_pos=f.getConnectionPos(!1,u);this.connecting_slot=u;g.shift_click_do_break_link_from&&a.shiftKey&&f.disconnectOutput(u);if(e){if(f.onOutputDblClick)f.onOutputDblClick(u,a)}else if(f.onOutputClick)f.onOutputClick(u,a);d=!0;break}}}if(f.inputs)for(u=
|
||||
0,k=f.inputs.length;u<k;++u)if(n=f.inputs[u],q=f.getConnectionPos(!0,u),C(a.canvasX,a.canvasY,q[0]-15,q[1]-10,30,20)){if(e){if(f.onInputDblClick)f.onInputDblClick(u,a)}else if(f.onInputClick)f.onInputClick(u,a);null!==n.link&&(q=this.graph.links[n.link],g.click_do_break_link_to&&(f.disconnectInput(u),d=this.dirty_bgcanvas=!0),this.allow_reconnect_links||a.shiftKey)&&(g.click_do_break_link_to||f.disconnectInput(u),this.connecting_node=this.graph._nodes_by_id[q.origin_id],this.connecting_slot=q.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=f,this.connecting_input=n,this.connecting_input.slot_index=u,this.connecting_pos=f.getConnectionPos(!0,u),this.connecting_slot=u,d=this.dirty_bgcanvas=!0)}}if(!d){var u=!1;k=[a.canvasX-f.pos[0],a.canvasY-f.pos[1]];if(q=this.processNodeWidgets(f,this.graph_mouse,a))u=!0,this.node_widget=[f,q];
|
||||
if(e&&this.selected_nodes[f.id]){if(f.onDblClick)f.onDblClick(a,k,this);this.processNodeDblClicked(f);u=!0}f.onMouseDown&&f.onMouseDown(a,k,this)?u=!0:(f.subgraph&&!f.skip_subgraph_button&&!f.flags.collapsed&&k[0]>f.size[0]-g.NODE_TITLE_HEIGHT&&0>k[1]&&(c=this,setTimeout(function(){c.openSubgraph(f.subgraph)},10)),this.live_mode&&(u=h=!0));u||(this.allow_dragnodes&&(this.graph.beforeChange(),this.node_dragged=f),this.selected_nodes[f.id]||this.processNodeSelected(f,a));this.dirty_canvas=!0}}else if(!d){if(!this.read_only)for(u=
|
||||
0;u<this.visible_links.length;++u)if(h=this.visible_links[u],k=h._pos,!(!k||a.canvasX<k[0]-4||a.canvasX>k[0]+4||a.canvasY<k[1]-4||a.canvasY>k[1]+4)){this.showLinkMenu(h,a);this.over_link_center=null;break}this.selected_group=this.graph.getGroupOnPos(a.canvasX,a.canvasY);this.selected_group_resizing=!1;this.selected_group&&!this.read_only&&(a.ctrlKey&&(this.dragging_rectangle=null),10>H([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&&(this.showSearchBox(a),a.preventDefault(),a.stopPropagation());h=!0}!d&&h&&this.allow_dragcanvas&&(this.dragging_canvas=!0)}this.last_mouse[0]=a.clientX;this.last_mouse[1]=a.clientY;this.last_mouseclick=g.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}}}};m.prototype.processMouseMove=function(a){this.autoresize&&this.resize();this.set_canvas_dirty_on_mouse_event&&(this.dirty_canvas=!0);if(this.graph){m.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(),
|
||||
this._mouseup_callback,!0));if(d){var f=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes,5);d=!1;e=g.getTime();var h=void 0===a.isPrimary||!a.isPrimary;e=300>e-this.last_mouseclick&&h;this.mouse[0]=a.clientX;this.mouse[1]=a.clientY;this.graph_mouse[0]=a.canvasX;this.graph_mouse[1]=a.canvasY;this.last_click_position=[this.mouse[0],this.mouse[1]];this.pointer_is_double=this.pointer_is_down&&h?!0:!1;this.pointer_is_down=!0;this.canvas.focus();g.closeAllContextMenus(b);if(!this.onMouse||
|
||||
1!=this.onMouse(a)){if(1!=a.which||this.pointer_is_double)if(2==a.which){if(g.middle_click_slot_add_default_node&&f&&this.allow_interaction&&!d&&!this.read_only&&!this.connecting_node&&!f.flags.collapsed&&!this.live_mode){e=d=h=!1;if(f.outputs)for(u=0,k=f.outputs.length;u<k;++u)if(n=f.outputs[u],q=f.getConnectionPos(!1,u),C(a.canvasX,a.canvasY,q[0]-15,q[1]-10,30,20)){h=n;d=u;e=!0;break}if(f.inputs)for(u=0,k=f.inputs.length;u<k;++u)if(n=f.inputs[u],q=f.getConnectionPos(!0,u),C(a.canvasX,a.canvasY,
|
||||
q[0]-15,q[1]-10,30,20)){h=n;d=u;e=!1;break}h&&!1!==d&&(u=.5-(d+1)/(e?f.outputs.length:f.inputs.length),h=f.getBounding(),this.createDefaultNodeForSlot({nodeFrom:e?f:null,slotFrom:e?d:null,nodeTo:e?null:f,slotTo:e?null:d,position:[e?h[0]+h[2]:h[0],a.canvasY-80],nodeType:"AUTO",posAdd:[e?30:-30,130*-u],posSizeFix:[e?0:-1,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]=a.canvasX,this.dragging_rectangle[1]=a.canvasY,this.dragging_rectangle[2]=1,this.dragging_rectangle[3]=1,d=!0);g.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,u||(this.allow_dragnodes&&(this.graph.beforeChange(),this.node_dragged=f),this.selected_nodes[f.id]||this.processNodeSelected(f,a)));h=!1;if(f&&this.allow_interaction&&!d&&!this.read_only){this.live_mode||f.flags.pinned||this.bringToFront(f);if(!this.connecting_node&&!f.flags.collapsed&&!this.live_mode)if(!d&&!1!==f.resizable&&C(a.canvasX,a.canvasY,f.pos[0]+f.size[0]-5,f.pos[1]+f.size[1]-5,10,10))this.graph.beforeChange(),this.resizing_node=f,this.canvas.style.cursor="se-resize",d=!0;else{if(f.outputs){u=
|
||||
0;for(var k=f.outputs.length;u<k;++u){var n=f.outputs[u],q=f.getConnectionPos(!1,u);if(C(a.canvasX,a.canvasY,q[0]-15,q[1]-10,30,20)){this.connecting_node=f;this.connecting_output=n;this.connecting_output.slot_index=u;this.connecting_pos=f.getConnectionPos(!1,u);this.connecting_slot=u;g.shift_click_do_break_link_from&&a.shiftKey&&f.disconnectOutput(u);if(e){if(f.onOutputDblClick)f.onOutputDblClick(u,a)}else if(f.onOutputClick)f.onOutputClick(u,a);d=!0;break}}}if(f.inputs)for(u=0,k=f.inputs.length;u<
|
||||
k;++u)if(n=f.inputs[u],q=f.getConnectionPos(!0,u),C(a.canvasX,a.canvasY,q[0]-15,q[1]-10,30,20)){if(e){if(f.onInputDblClick)f.onInputDblClick(u,a)}else if(f.onInputClick)f.onInputClick(u,a);null!==n.link&&(q=this.graph.links[n.link],g.click_do_break_link_to&&(f.disconnectInput(u),d=this.dirty_bgcanvas=!0),this.allow_reconnect_links||a.shiftKey)&&(g.click_do_break_link_to||f.disconnectInput(u),this.connecting_node=this.graph._nodes_by_id[q.origin_id],this.connecting_slot=q.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=f,this.connecting_input=n,this.connecting_input.slot_index=u,this.connecting_pos=f.getConnectionPos(!0,u),this.connecting_slot=u,d=this.dirty_bgcanvas=!0)}}if(!d){var u=!1;k=[a.canvasX-f.pos[0],a.canvasY-f.pos[1]];if(q=this.processNodeWidgets(f,this.graph_mouse,a))u=!0,this.node_widget=[f,q];if(e&&this.selected_nodes[f.id]){if(f.onDblClick)f.onDblClick(a,
|
||||
k,this);this.processNodeDblClicked(f);u=!0}f.onMouseDown&&f.onMouseDown(a,k,this)?u=!0:(f.subgraph&&!f.skip_subgraph_button&&!f.flags.collapsed&&k[0]>f.size[0]-g.NODE_TITLE_HEIGHT&&0>k[1]&&(c=this,setTimeout(function(){c.openSubgraph(f.subgraph)},10)),this.live_mode&&(u=h=!0));u||(this.allow_dragnodes&&(this.graph.beforeChange(),this.node_dragged=f),this.selected_nodes[f.id]||this.processNodeSelected(f,a));this.dirty_canvas=!0}}else if(!d){if(!this.read_only)for(u=0;u<this.visible_links.length;++u)if(h=
|
||||
this.visible_links[u],k=h._pos,!(!k||a.canvasX<k[0]-4||a.canvasX>k[0]+4||a.canvasY<k[1]-4||a.canvasY>k[1]+4)){this.showLinkMenu(h,a);this.over_link_center=null;break}this.selected_group=this.graph.getGroupOnPos(a.canvasX,a.canvasY);this.selected_group_resizing=!1;this.selected_group&&!this.read_only&&(a.ctrlKey&&(this.dragging_rectangle=null),10>H([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&&(this.showSearchBox(a),a.preventDefault(),a.stopPropagation());h=!0}!d&&h&&this.allow_dragcanvas&&(this.dragging_canvas=!0)}this.last_mouse[0]=a.clientX;this.last_mouse[1]=a.clientY;this.last_mouseclick=g.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}}}};m.prototype.processMouseMove=function(a){this.autoresize&&this.resize();this.set_canvas_dirty_on_mouse_event&&(this.dirty_canvas=!0);if(this.graph){m.active_canvas=this;this.adjustMouseEvent(a);var b=[a.clientX,a.clientY];this.mouse[0]=b[0];this.mouse[1]=b[1];var c=[b[0]-this.last_mouse[0],b[1]-this.last_mouse[1]];this.last_mouse=b;this.graph_mouse[0]=a.canvasX;this.graph_mouse[1]=a.canvasY;if(this.block_click)return a.preventDefault(),
|
||||
!1;a.dragging=this.last_mouse_dragging;this.node_widget&&(this.processNodeWidgets(this.node_widget[0],this.graph_mouse,a,this.node_widget[1]),this.dirty_canvas=!0);if(this.dragging_rectangle)this.dragging_rectangle[2]=a.canvasX-this.dragging_rectangle[0],this.dragging_rectangle[3]=a.canvasY-this.dragging_rectangle[1],this.dirty_canvas=!0;else if(this.selected_group&&!this.read_only)this.selected_group_resizing?this.selected_group.size=[a.canvasX-this.selected_group.pos[0],a.canvasY-this.selected_group.pos[1]]:
|
||||
(this.selected_group.move(c[0]/this.ds.scale,c[1]/this.ds.scale,a.ctrlKey),this.selected_group._nodes.length&&(this.dirty_canvas=!0)),this.dirty_bgcanvas=!0;else if(this.dragging_canvas)this.ds.offset[0]+=c[0]/this.ds.scale,this.ds.offset[1]+=c[1]/this.ds.scale,this.dirty_bgcanvas=this.dirty_canvas=!0;else if(this.allow_interaction&&!this.read_only){this.connecting_node&&(this.dirty_canvas=!0);var d=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes);b=0;for(var e=this.graph._nodes.length;b<
|
||||
e;++b)if(this.graph._nodes[b].mouseOver&&d!=this.graph._nodes[b]){this.graph._nodes[b].mouseOver=!1;if(this.node_over&&this.node_over.onMouseLeave)this.node_over.onMouseLeave(a);this.node_over=null;this.dirty_canvas=!0}if(d){d.redraw_on_mouse&&(this.dirty_canvas=!0);if(!d.mouseOver&&(d.mouseOver=!0,this.node_over=d,this.dirty_canvas=!0,d.onMouseEnter))d.onMouseEnter(a);if(d.onMouseMove)d.onMouseMove(a,[a.canvasX-d.pos[0],a.canvasY-d.pos[1]],this);if(this.connecting_node)if(this.connecting_output){if(e=
|
||||
this._highlight_input||[0,0],!this.isOverNodeBox(d,a.canvasX,a.canvasY)){var f=this.isOverNodeInput(d,a.canvasX,a.canvasY,e);if(-1!=f&&d.inputs[f]){var h=d.inputs[f].type;g.isValidConnection(this.connecting_output.type,h)&&(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]?(h=d.outputs[f].type,g.isValidConnection(this.connecting_input.type,h)&&(this._highlight_output=e)):this._highlight_output=null));this.canvas&&(C(a.canvasX,a.canvasY,d.pos[0]+d.size[0]-5,d.pos[1]+d.size[1]-5,5,5)?this.canvas.style.cursor="se-resize":this.canvas.style.cursor="crosshair")}else{e=null;for(b=0;b<this.visible_links.length;++b)if(f=this.visible_links[b],h=f._pos,!(!h||a.canvasX<h[0]-4||a.canvasX>h[0]+4||a.canvasY<h[1]-4||a.canvasY>h[1]+4)){e=f;break}e!=this.over_link_center&&
|
||||
(this.over_link_center=e,this.dirty_canvas=!0);this.canvas&&(this.canvas.style.cursor="")}if(this.node_capturing_input&&this.node_capturing_input!=d&&this.node_capturing_input.onMouseMove)this.node_capturing_input.onMouseMove(a,[a.canvasX-this.node_capturing_input.pos[0],a.canvasY-this.node_capturing_input.pos[1]],this);if(this.node_dragged&&!this.live_mode){for(b in this.selected_nodes)d=this.selected_nodes[b],d.pos[0]+=c[0]/this.ds.scale,d.pos[1]+=c[1]/this.ds.scale;this.dirty_bgcanvas=this.dirty_canvas=
|
||||
!0}this.resizing_node&&!this.live_mode&&(c=[a.canvasX-this.resizing_node.pos[0],a.canvasY-this.resizing_node.pos[1]],b=this.resizing_node.computeSize(),c[0]=Math.max(b[0],c[0]),c[1]=Math.max(b[1],c[1]),this.resizing_node.setSize(c),this.canvas.style.cursor="se-resize",this.dirty_bgcanvas=this.dirty_canvas=!0)}a.preventDefault();return!1}};m.prototype.processMouseUp=function(a){if(void 0!==a.isPrimary&&!a.isPrimary)return!1;this.set_canvas_dirty_on_mouse_event&&(this.dirty_canvas=!0);if(this.graph){var b=
|
||||
this.getCanvasWindow().document;m.active_canvas=this;this.options.skip_events||(g.pointerListenerRemove(b,"move",this._mousemove_callback,!0),g.pointerListenerAdd(this.canvas,"move",this._mousemove_callback,!0),g.pointerListenerRemove(b,"up",this._mouseup_callback,!0));this.adjustMouseEvent(a);b=g.getTime();a.click_time=b-this.last_mouseclick;this.last_mouse_dragging=!1;this.last_click_position=null;this.block_click&&(this.block_click=!1);if(1==a.which){this.node_widget&&this.processNodeWidgets(this.node_widget[0],
|
||||
this.graph_mouse,a);this.node_widget=null;this.selected_group&&(this.selected_group.move(this.selected_group.pos[0]-Math.round(this.selected_group.pos[0]),this.selected_group.pos[1]-Math.round(this.selected_group.pos[1]),a.ctrlKey),this.selected_group.pos[0]=Math.round(this.selected_group.pos[0]),this.selected_group.pos[1]=Math.round(this.selected_group.pos[1]),this.selected_group._nodes.length&&(this.dirty_canvas=!0),this.selected_group=null);this.selected_group_resizing=!1;var c=this.graph.getNodeOnPos(a.canvasX,
|
||||
a.canvasY,this.visible_nodes);if(this.dragging_rectangle){if(this.graph){b=this.graph._nodes;var d=new Float32Array(4),e=Math.abs(this.dragging_rectangle[2]),f=Math.abs(this.dragging_rectangle[3]),h=0>this.dragging_rectangle[3]?this.dragging_rectangle[1]-f:this.dragging_rectangle[1];this.dragging_rectangle[0]=0>this.dragging_rectangle[2]?this.dragging_rectangle[0]-e:this.dragging_rectangle[0];this.dragging_rectangle[1]=h;this.dragging_rectangle[2]=e;this.dragging_rectangle[3]=f;if(!c||10<e&&10<f){c=
|
||||
[];for(e=0;e<b.length;++e)f=b[e],f.getBounding(d),F(this.dragging_rectangle,d)&&c.push(f);c.length&&this.selectNodes(c,a.shiftKey)}else this.selectNodes([c],a.shiftKey||a.ctrlKey)}this.dragging_rectangle=null}else if(this.connecting_node)this.dirty_bgcanvas=this.dirty_canvas=!0,b=(this.connecting_output||this.connecting_input).type,c?this.connecting_output?(d=this.isOverNodeInput(c,a.canvasX,a.canvasY),-1!=d?this.connecting_node.connect(this.connecting_slot,c,d):this.connecting_node.connectByType(this.connecting_slot,
|
||||
c,b)):this.connecting_input&&(d=this.isOverNodeOutput(c,a.canvasX,a.canvasY),-1!=d?c.connect(d,this.connecting_node,this.connecting_slot):this.connecting_node.connectByTypeOutput(this.connecting_slot,c,b)):g.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,
|
||||
!0}this.resizing_node&&!this.live_mode&&(c=[a.canvasX-this.resizing_node.pos[0],a.canvasY-this.resizing_node.pos[1]],b=this.resizing_node.computeSize(),c[0]=Math.max(b[0],c[0]),c[1]=Math.max(b[1],c[1]),this.resizing_node.setSize(c),this.canvas.style.cursor="se-resize",this.dirty_bgcanvas=this.dirty_canvas=!0)}a.preventDefault();return!1}};m.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;m.active_canvas=this;this.options.skip_events||(g.pointerListenerRemove(c,"move",this._mousemove_callback,!0),g.pointerListenerAdd(this.canvas,"move",this._mousemove_callback,!0),g.pointerListenerRemove(c,"up",this._mouseup_callback,!0));this.adjustMouseEvent(a);c=g.getTime();a.click_time=c-this.last_mouseclick;this.last_mouse_dragging=!1;this.last_click_position=null;this.block_click&&(this.block_click=!1);if(1==a.which){this.node_widget&&this.processNodeWidgets(this.node_widget[0],
|
||||
this.graph_mouse,a);this.node_widget=null;this.selected_group&&(this.selected_group.move(this.selected_group.pos[0]-Math.round(this.selected_group.pos[0]),this.selected_group.pos[1]-Math.round(this.selected_group.pos[1]),a.ctrlKey),this.selected_group.pos[0]=Math.round(this.selected_group.pos[0]),this.selected_group.pos[1]=Math.round(this.selected_group.pos[1]),this.selected_group._nodes.length&&(this.dirty_canvas=!0),this.selected_group=null);this.selected_group_resizing=!1;var d=this.graph.getNodeOnPos(a.canvasX,
|
||||
a.canvasY,this.visible_nodes);if(this.dragging_rectangle){if(this.graph){c=this.graph._nodes;var e=new Float32Array(4),f=Math.abs(this.dragging_rectangle[2]),h=Math.abs(this.dragging_rectangle[3]),k=0>this.dragging_rectangle[3]?this.dragging_rectangle[1]-h: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]=h;if(!d||10<f&&10<h){d=
|
||||
[];for(f=0;f<c.length;++f)h=c[f],h.getBounding(e),F(this.dragging_rectangle,e)&&d.push(h);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,a.canvasX,a.canvasY),-1!=e?d.connect(e,this.connecting_node,this.connecting_slot):this.connecting_node.connectByTypeOutput(this.connecting_slot,d,c)):g.release_link_on_empty_shows_menu&&(a.shiftKey&&this.allow_searchbox?this.connecting_output?this.showSearchBox(a,{node_from:this.connecting_node,slot_from:this.connecting_output,type_filter_in:this.connecting_output.type}):this.connecting_input&&this.showSearchBox(a,{node_to:this.connecting_node,
|
||||
slot_from:this.connecting_input,type_filter_out:this.connecting_input.type}):this.connecting_output?this.showConnectionMenu({nodeFrom:this.connecting_node,slotFrom:this.connecting_output,e:a}):this.connecting_input&&this.showConnectionMenu({nodeTo:this.connecting_node,slotTo:this.connecting_input,e:a})),this.connecting_node=this.connecting_pos=this.connecting_input=this.connecting_output=null,this.connecting_slot=-1;else if(this.resizing_node)this.dirty_bgcanvas=this.dirty_canvas=!0,this.graph.afterChange(this.resizing_node),
|
||||
this.resizing_node=null;else if(this.node_dragged){(c=this.node_dragged)&&300>a.click_time&&C(a.canvasX,a.canvasY,c.pos[0],c.pos[1]-g.NODE_TITLE_HEIGHT,g.NODE_TITLE_HEIGHT,g.NODE_TITLE_HEIGHT)&&c.collapse();this.dirty_bgcanvas=this.dirty_canvas=!0;this.node_dragged.pos[0]=Math.round(this.node_dragged.pos[0]);this.node_dragged.pos[1]=Math.round(this.node_dragged.pos[1]);(this.graph.config.align_to_grid||this.align_to_grid)&&this.node_dragged.alignToGrid();if(this.onNodeMoved)this.onNodeMoved(this.node_dragged);
|
||||
this.graph.afterChange(this.node_dragged);this.node_dragged=null}else{c=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes);!c&&300>a.click_time&&this.deselectAllNodes();this.dirty_canvas=!0;this.dragging_canvas=!1;if(this.node_over&&this.node_over.onMouseUp)this.node_over.onMouseUp(a,[a.canvasX-this.node_over.pos[0],a.canvasY-this.node_over.pos[1]],this);if(this.node_capturing_input&&this.node_capturing_input.onMouseUp)this.node_capturing_input.onMouseUp(a,[a.canvasX-this.node_capturing_input.pos[0],
|
||||
a.canvasY-this.node_capturing_input.pos[1]])}}else 2==a.which?(this.dirty_canvas=!0,this.dragging_canvas=!1):3==a.which&&(this.dirty_canvas=!0,this.dragging_canvas=!1);void 0!==a.isPrimary&&a.isPrimary&&(this.pointer_is_double=this.pointer_is_down=!1);this.graph.change();a.stopPropagation();a.preventDefault();return!1}};m.prototype.processMouseWheel=function(a){if(this.graph&&this.allow_dragcanvas){var b=null!=a.wheelDeltaY?a.wheelDeltaY:-60*a.detail;this.adjustMouseEvent(a);var c=a.clientX,d=a.clientY;
|
||||
if(!this.viewport||this.viewport&&c>=this.viewport[0]&&c<this.viewport[0]+this.viewport[2]&&d>=this.viewport[1]&&d<this.viewport[1]+this.viewport[3])return c=this.ds.scale,0<b?c*=1.1:0>b&&(c*=1/1.1),this.ds.changeScale(c,[a.clientX,a.clientY]),this.graph.change(),a.preventDefault(),!1}};m.prototype.isOverNodeBox=function(a,b,c){var d=g.NODE_TITLE_HEIGHT;return C(b,c,a.pos[0]+2,a.pos[1]+2-d,d-4,d-4)?!0:!1};m.prototype.isOverNodeInput=function(a,b,c,d){if(a.inputs)for(var e=0,f=a.inputs.length;e<f;++e){var h=
|
||||
a.getConnectionPos(!0,e);if(a.horizontal?C(b,c,h[0]-5,h[1]-10,10,20):C(b,c,h[0]-10,h[1]-5,40,10))return d&&(d[0]=h[0],d[1]=h[1]),e}return-1};m.prototype.isOverNodeOutput=function(a,b,c,d){if(a.outputs)for(var e=0,f=a.outputs.length;e<f;++e){var h=a.getConnectionPos(!1,e);if(a.horizontal?C(b,c,h[0]-5,h[1]-10,10,20):C(b,c,h[0]-10,h[1]-5,40,10))return d&&(d[0]=h[0],d[1]=h[1]),e}return-1};m.prototype.processKey=function(a){if(this.graph){var b=!1;if("input"!=a.target.localName){if("keydown"==a.type){if(32==
|
||||
a.keyCode&&(b=this.dragging_canvas=!0),27==a.keyCode&&(this.node_panel&&this.node_panel.close(),this.options_panel&&this.options_panel.close(),b=!0),65==a.keyCode&&a.ctrlKey&&(this.selectNodes(),b=!0),"KeyC"==a.code&&(a.metaKey||a.ctrlKey)&&!a.shiftKey&&this.selected_nodes&&(this.copyToClipboard(),b=!0),"KeyV"!=a.code||!a.metaKey&&!a.ctrlKey||a.shiftKey||this.pasteFromClipboard(),46!=a.keyCode&&8!=a.keyCode||"input"==a.target.localName||"textarea"==a.target.localName||(this.deleteSelectedNodes(),
|
||||
b=!0),this.selected_nodes)for(var c in this.selected_nodes)if(this.selected_nodes[c].onKeyDown)this.selected_nodes[c].onKeyDown(a)}else if("keyup"==a.type&&(32==a.keyCode&&(this.dragging_canvas=!1),this.selected_nodes))for(c in this.selected_nodes)if(this.selected_nodes[c].onKeyUp)this.selected_nodes[c].onKeyUp(a);this.graph.change();if(b)return a.preventDefault(),a.stopImmediatePropagation(),!1}}};m.prototype.copyToClipboard=function(){var a={nodes:[],links:[]},b=0,c=[],d;for(d in this.selected_nodes){var e=
|
||||
this.selected_nodes[d];e._relative_id=b;c.push(e);b+=1}for(d=0;d<c.length;++d)if(e=c[d],b=e.clone()){if(a.nodes.push(b.serialize()),e.inputs&&e.inputs.length)for(b=0;b<e.inputs.length;++b){var f=e.inputs[b];if(f&&null!=f.link&&(f=this.graph.links[f.link])){var h=this.graph.getNodeById(f.origin_id);h&&this.selected_nodes[h.id]&&a.links.push([h._relative_id,f.origin_slot,e._relative_id,f.target_slot])}}}else console.warn("node type not found: "+e.type);localStorage.setItem("litegrapheditor_clipboard",
|
||||
JSON.stringify(a))};m.prototype.pasteFromClipboard=function(){var a=localStorage.getItem("litegrapheditor_clipboard");if(a){this.graph.beforeChange();a=JSON.parse(a);for(var b=!1,c=!1,d=0;d<a.nodes.length;++d)b?(b[0]>a.nodes[d].pos[0]&&(b[0]=a.nodes[d].pos[0],c[0]=d),b[1]>a.nodes[d].pos[1]&&(b[1]=a.nodes[d].pos[1],c[1]=d)):(b=[a.nodes[d].pos[0],a.nodes[d].pos[1]],c=[d,d]);c=[];for(d=0;d<a.nodes.length;++d){var e=a.nodes[d],f=g.createNode(e.type);f&&(f.configure(e),f.pos[0]+=this.graph_mouse[0]-b[0],
|
||||
f.pos[1]+=this.graph_mouse[1]-b[1],this.graph.add(f,{doProcessChange:!1}),c.push(f))}for(d=0;d<a.links.length;++d)b=a.links[d],e=c[b[0]],f=c[b[2]],e&&f?e.connect(b[1],f,b[3]):console.warn("Warning, nodes missing on pasting");this.selectNodes(c);this.graph.afterChange()}};m.prototype.processDrop=function(a){a.preventDefault();this.adjustMouseEvent(a);var b=a.clientX,c=a.clientY;if(!this.viewport||this.viewport&&b>=this.viewport[0]&&b<this.viewport[0]+this.viewport[2]&&c>=this.viewport[1]&&c<this.viewport[1]+
|
||||
this.viewport[3]){b=[a.canvasX,a.canvasY];var d=this.graph?this.graph.getNodeOnPos(b[0],b[1]):null;if(d){if((d.onDropFile||d.onDropData)&&(b=a.dataTransfer.files)&&b.length)for(c=0;c<b.length;c++){var e=a.dataTransfer.files[0],f=e.name;m.getFileExtension(f);if(d.onDropFile)d.onDropFile(e);if(d.onDropData){var h=new FileReader;h.onload=function(a){d.onDropData(a.target.result,f,e)};var g=e.type.split("/")[0];"text"==g||""==g?h.readAsText(e):"image"==g?h.readAsDataURL(e):h.readAsArrayBuffer(e)}}return d.onDropItem&&
|
||||
d.onDropItem(event)?!0:this.onDropItem?this.onDropItem(event):!1}b=null;this.onDropItem&&(b=this.onDropItem(event));b||this.checkDropItem(a)}};m.prototype.checkDropItem=function(a){if(a.dataTransfer.files.length){var b=a.dataTransfer.files[0],c=m.getFileExtension(b.name).toLowerCase();if(c=g.node_types_by_file_extension[c]){this.graph.beforeChange();c=g.createNode(c.type);c.pos=[a.canvasX,a.canvasY];this.graph.add(c);if(c.onDropFile)c.onDropFile(b);this.graph.afterChange()}}};m.prototype.processNodeDblClicked=
|
||||
function(a){if(this.onShowNodePanel)this.onShowNodePanel(a);else this.showShowNodePanel(a);if(this.onNodeDblClicked)this.onNodeDblClicked(a);this.setDirty(!0)};m.prototype.processNodeSelected=function(a,b){this.selectNode(a,b&&(b.shiftKey||b.ctrlKey));if(this.onNodeSelected)this.onNodeSelected(a)};m.prototype.selectNode=function(a,b){null==a?this.deselectAllNodes():this.selectNodes([a],b)};m.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){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)};m.prototype.deselectNode=function(a){if(a.is_selected){if(a.onDeselected)a.onDeselected();
|
||||
a.is_selected=!1;if(this.onNodeDeselected)this.onNodeDeselected(a);if(a.inputs)for(var b=0;b<a.inputs.length;++b)delete this.highlighted_links[a.inputs[b].link];if(a.outputs)for(b=0;b<a.outputs.length;++b){var c=a.outputs[b];if(c.links)for(var d=0;d<c.links.length;++d)delete this.highlighted_links[c.links[d]]}}};m.prototype.deselectAllNodes=function(){if(this.graph){for(var a=this.graph._nodes,b=0,c=a.length;b<c;++b){var d=a[b];if(d.is_selected){if(d.onDeselected)d.onDeselected();d.is_selected=!1;
|
||||
if(this.onNodeDeselected)this.onNodeDeselected(d)}}this.selected_nodes={};this.current_node=null;this.highlighted_links={};if(this.onSelectionChange)this.onSelectionChange(this.selected_nodes);this.setDirty(!0)}};m.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&&g.isValidConnection(b.inputs[0].type,b.outputs[0].type)&&b.inputs[0].link&&b.outputs[0].links&&
|
||||
b.outputs[0].links.length){var c=b.graph.links[b.inputs[0].link],d=b.graph.links[b.outputs[0].links[0]],e=b.getInputNode(0),f=b.getOutputNodes(0)[0];e&&f&&e.connect(c.origin_slot,f,d.target_slot)}this.graph.remove(b);if(this.onNodeDeselected)this.onNodeDeselected(b)}}this.selected_nodes={};this.current_node=null;this.highlighted_links={};this.setDirty(!0);this.graph.afterChange()};m.prototype.centerOnNode=function(a){this.ds.offset[0]=-a.pos[0]-.5*a.size[0]+.5*this.canvas.width/this.ds.scale;this.ds.offset[1]=
|
||||
-a.pos[1]-.5*a.size[1]+.5*this.canvas.height/this.ds.scale;this.setDirty(!0,!0)};m.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;a.deltaX=c-this.last_mouse_position[0];a.deltaY=b-this.last_mouse_position[1];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]};m.prototype.setZoom=function(a,
|
||||
b){this.ds.changeScale(a,b);this.dirty_bgcanvas=this.dirty_canvas=!0};m.prototype.convertOffsetToCanvas=function(a,b){return this.ds.convertOffsetToCanvas(a,b)};m.prototype.convertCanvasToOffset=function(a,b){return this.ds.convertCanvasToOffset(a,b)};m.prototype.convertEventToCanvasOffset=function(a){var b=this.canvas.getBoundingClientRect();return this.convertCanvasToOffset([a.clientX-b.left,a.clientY-b.top])};m.prototype.bringToFront=function(a){var b=this.graph._nodes.indexOf(a);-1!=b&&(this.graph._nodes.splice(b,
|
||||
1),this.graph._nodes.push(a))};m.prototype.sendToBack=function(a){var b=this.graph._nodes.indexOf(a);-1!=b&&(this.graph._nodes.splice(b,1),this.graph._nodes.unshift(a))};var I=new Float32Array(4);m.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)&&F(this.visible_area,e.getBounding(I))&&b.push(e)}return b};m.prototype.draw=function(a,b){if(this.canvas&&0!=this.canvas.width&&
|
||||
0!=this.canvas.height){var c=g.getTime();this.render_time=.001*(c-this.last_draw_time);this.last_draw_time=c;this.graph&&this.ds.computeVisibleArea(this.viewport);(this.dirty_bgcanvas||b||this.always_render_background||this.graph&&this.graph._last_trigger_time&&1E3>c-this.graph._last_trigger_time)&&this.drawBackCanvas();(this.dirty_canvas||a)&&this.drawFrontCanvas();this.fps=this.render_time?1/this.render_time:0;this.frame+=1}};m.prototype.drawFrontCanvas=function(){this.dirty_canvas=!1;this.ctx||
|
||||
(this.ctx=this.bgcanvas.getContext("2d"));var a=this.ctx;if(a){var b=this.canvas;a.start2D&&!this.viewport&&(a.start2D(),a.restore(),a.setTransform(1,0,0,1,0,0));var c=this.viewport||this.dirty_area;c&&(a.save(),a.beginPath(),a.rect(c[0],c[1],c[2],c[3]),a.clip());this.clear_background&&(c?a.clearRect(c[0],c[1],c[2],c[3]):a.clearRect(0,0,b.width,b.height));this.bgcanvas==this.canvas?this.drawBackCanvas():a.drawImage(this.bgcanvas,0,0);if(this.onRender)this.onRender(b,a);this.show_info&&this.renderInfo(a,
|
||||
c?c[0]:0,c?c[1]:0);if(this.graph){a.save();this.ds.toCanvasContext(a);b=this.computeVisibleNodes(null,this.visible_nodes);for(var d=0;d<b.length;++d){var e=b[d];a.save();a.translate(e.pos[0],e.pos[1]);this.drawNode(e,a);a.restore()}this.render_execution_order&&this.drawExecutionOrder(a);this.graph.config.links_ontop&&(this.live_mode||this.drawConnections(a));if(null!=this.connecting_pos){a.lineWidth=this.connections_width;e=this.connecting_output||this.connecting_input;b=e.type;d=e.dir;null==d&&(d=
|
||||
this.connecting_output?this.connecting_node.horizontal?g.DOWN:g.RIGHT:this.connecting_node.horizontal?g.UP:g.LEFT);var f=e.shape;switch(b){case g.EVENT:e=g.EVENT_LINK_COLOR;break;default:e=g.CONNECTING_LINK_COLOR}this.renderLink(a,this.connecting_pos,[this.graph_mouse[0],this.graph_mouse[1]],null,!1,null,e,d,g.CENTER);a.beginPath();b===g.EVENT||f===g.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===g.ARROW_SHAPE?(a.moveTo(this.connecting_pos[0]+8,this.connecting_pos[1]+.5),a.lineTo(this.connecting_pos[0]-4,this.connecting_pos[1]+6+.5),a.lineTo(this.connecting_pos[0]-4,this.connecting_pos[1]-6+.5),a.closePath()):(a.arc(this.connecting_pos[0],this.connecting_pos[1],4,0,2*Math.PI),a.fill(),a.beginPath(),a.arc(this.graph_mouse[0],this.graph_mouse[1],4,0,2*Math.PI));a.fill();a.fillStyle="#ffcc00";if(this._highlight_input){a.beginPath();var h=this._highlight_input_slot.shape;h===
|
||||
g.ARROW_SHAPE?(a.moveTo(this._highlight_input[0]+8,this._highlight_input[1]+.5),a.lineTo(this._highlight_input[0]-4,this._highlight_input[1]+6+.5),a.lineTo(this._highlight_input[0]-4,this._highlight_input[1]-6+.5),a.closePath()):a.arc(this._highlight_input[0],this._highlight_input[1],6,0,2*Math.PI);a.fill()}this._highlight_output&&(a.beginPath(),h===g.ARROW_SHAPE?(a.moveTo(this._highlight_output[0]+8,this._highlight_output[1]+.5),a.lineTo(this._highlight_output[0]-4,this._highlight_output[1]+6+.5),
|
||||
a.lineTo(this._highlight_output[0]-4,this._highlight_output[1]-6+.5),a.closePath()):a.arc(this._highlight_output[0],this._highlight_output[1],6,0,2*Math.PI),a.fill())}this.dragging_rectangle&&(a.strokeStyle="#FFF",a.strokeRect(this.dragging_rectangle[0],this.dragging_rectangle[1],this.dragging_rectangle[2],this.dragging_rectangle[3]));if(this.over_link_center&&this.render_link_tooltip)this.drawLinkTooltip(a,this.over_link_center);else if(this.onDrawLinkTooltip)this.onDrawLinkTooltip(a,null);if(this.onDrawForeground)this.onDrawForeground(a,
|
||||
this.visible_rect);a.restore()}this._graph_stack&&this._graph_stack.length&&this.drawSubgraphPanel(a);if(this.onDrawOverlay)this.onDrawOverlay(a);c&&a.restore();a.finish2D&&a.finish2D()}};m.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")};m.prototype.drawSubgraphPanelLeft=function(a,b,c){var d=b.inputs?b.inputs.length:0,e=Math.floor(1.6*g.NODE_SLOT_HEIGHT);
|
||||
c.fillStyle="#111";c.globalAlpha=.8;c.beginPath();c.roundRect(10,10,200,(d+1)*e+50,[8]);c.fill();c.globalAlpha=1;c.fillStyle="#888";c.font="14px Arial";c.textAlign="left";c.fillText("Graph Inputs",20,34);if(this.drawButton(180,20,20,20,"X","#151515"))this.closeSubgraph();else{d=50;c.font="14px Arial";if(b.inputs)for(var f=0;f<b.inputs.length;++f){var h=b.inputs[f];if(!h.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 n=g.createNode(k);n?(a.add(n),this.block_click=!1,this.last_click_position=null,this.selectNodes([n]),this.node_dragged=n,this.dragging_canvas=!1,n.setProperty("name",h.name),n.setProperty("type",h.type),this.node_dragged.pos[0]=this.graph_mouse[0]-5,this.node_dragged.pos[1]=this.graph_mouse[1]-5,this.graph.afterChange()):console.error("graph input node not found:",k)}c.fillStyle="#9C9";c.beginPath();c.arc(184,d+.5*e,5,0,2*Math.PI);c.fill();c.fillStyle="#AAA";c.fillText(h.name,30,d+.75*e);c.fillStyle=
|
||||
"#777";c.fillText(h.type,130,d+.75*e);d+=e}}this.drawButton(20,d+2,180,e-2,"+","#151515","#222")&&this.showSubgraphPropertiesDialog(b)}};m.prototype.drawSubgraphPanelRight=function(a,b,c){var d=b.outputs?b.outputs.length:0,e=this.bgcanvas.width,f=Math.floor(1.6*g.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();else{d=50;c.font="14px Arial";if(b.outputs)for(var h=0;h<b.outputs.length;++h){var k=b.outputs[h];if(!k.not_subgraph_input){if(this.drawButton(e-200,d+2,180,f-2)){var n=b.constructor.output_node_type||"graph/output";this.graph.beforeChange();var q=g.createNode(n);q?(a.add(q),this.block_click=!1,this.last_click_position=null,this.selectNodes([q]),this.node_dragged=q,this.dragging_canvas=!1,q.setProperty("name",k.name),
|
||||
q.setProperty("type",k.type),this.node_dragged.pos[0]=this.graph_mouse[0]-5,this.node_dragged.pos[1]=this.graph_mouse[1]-5,this.graph.afterChange()):console.error("graph input node not found:",n)}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)}};m.prototype.drawButton=
|
||||
function(a,b,c,d,e,f,h,k){var n=this.ctx;f=f||g.NODE_DEFAULT_COLOR;h=h||"#555";k=k||g.NODE_TEXT_COLOR;var q=b+g.NODE_TITLE_HEIGHT+2,u=this.mouse,r=g.isInsideRectangle(u[0],u[1],a,q,c,d);q=(u=this.last_click_position)&&g.isInsideRectangle(u[0],u[1],a,q,c,d);n.fillStyle=r?h:f;q&&(n.fillStyle="#AAA");n.beginPath();n.roundRect(a,b,c,d,[4]);n.fill();null!=e&&e.constructor==String&&(n.fillStyle=k,n.textAlign="center",n.font=(.65*d|0)+"px Arial",n.fillText(e,a+.5*c,b+.75*d),n.textAlign="left");a=q&&!this.block_click;
|
||||
q&&this.blockClick();return a};m.prototype.isAreaClicked=function(a,b,c,d,e){var f=this.mouse;g.isInsideRectangle(f[0],f[1],a,b,c,d);b=(a=(f=this.last_click_position)&&g.isInsideRectangle(f[0],f[1],a,b,c,d))&&!this.block_click;a&&e&&this.blockClick();return b};m.prototype.renderInfo=function(a,b,c){b=b||10;c=c||this.canvas.height-80;a.save();a.translate(b,c);a.font="10px Arial";a.fillStyle="#888";a.textAlign="left";this.graph?(a.fillText("T: "+this.graph.globaltime.toFixed(2)+"s",5,13),a.fillText("I: "+
|
||||
this.graph.iteration,5,26),a.fillText("N: "+this.graph._nodes.length+" ["+this.visible_nodes.length+"]",5,39),a.fillText("V: "+this.graph._version,5,52),a.fillText("FPS:"+this.fps.toFixed(2),5,65)):a.fillText("No graph selected",5,13);a.restore()};m.prototype.drawBackCanvas=function(){var a=this.bgcanvas;if(a.width!=this.canvas.width||a.height!=this.canvas.height)a.width=this.canvas.width,a.height=this.canvas.height;this.bgctx||(this.bgctx=this.bgcanvas.getContext("2d"));var b=this.bgctx;b.start&&
|
||||
b.start();var c=this.viewport||[0,0,b.canvas.width,b.canvas.height];this.clear_background&&b.clearRect(c[0],c[1],c[2],c[3]);if(this._graph_stack&&this._graph_stack.length){b.save();c=this.graph._subgraph_node;b.strokeStyle=c.bgcolor;b.lineWidth=10;b.strokeRect(1,1,a.width-2,a.height-2);b.lineWidth=1;b.font="40px Arial";b.textAlign="center";b.fillStyle=c.bgcolor||"#AAA";for(var d="",e=1;e<this._graph_stack.length;++e)d+=this._graph_stack[e]._subgraph_node.getTitle()+" >> ";b.fillText(d+c.getTitle(),
|
||||
.5*a.width,40);b.restore()}c=!1;this.onRenderBackground&&(c=this.onRenderBackground(a,b));this.viewport||(b.restore(),b.setTransform(1,0,0,1,0,0));this.visible_links.length=0;if(this.graph){b.save();this.ds.toCanvasContext(b);if(this.background_image&&.5<this.ds.scale&&!c){b.globalAlpha=this.zoom_modify_alpha?(1-.5/this.ds.scale)*this.editor_alpha:this.editor_alpha;b.imageSmoothingEnabled=b.imageSmoothingEnabled=!1;if(!this._bg_img||this._bg_img.name!=this.background_image){this._bg_img=new Image;
|
||||
this._bg_img.name=this.background_image;this._bg_img.src=this.background_image;var f=this;this._bg_img.onload=function(){f.draw(!0,!0)}}c=null;null==this._pattern&&0<this._bg_img.width?(c=b.createPattern(this._bg_img,"repeat"),this._pattern_img=this._bg_img,this._pattern=c):c=this._pattern;c&&(b.fillStyle=c,b.fillRect(this.visible_area[0],this.visible_area[1],this.visible_area[2],this.visible_area[3]),b.fillStyle="transparent");b.globalAlpha=1;b.imageSmoothingEnabled=b.imageSmoothingEnabled=!0}this.graph._groups.length&&
|
||||
!this.live_mode&&this.drawGroups(a,b);if(this.onDrawBackground)this.onDrawBackground(b,this.visible_area);this.onBackgroundRender&&(console.error("WARNING! onBackgroundRender deprecated, now is named onDrawBackground "),this.onBackgroundRender=null);this.render_canvas_border&&(b.strokeStyle="#235",b.strokeRect(0,0,a.width,a.height));this.render_connections_shadows?(b.shadowColor="#000",b.shadowOffsetX=0,b.shadowOffsetY=0,b.shadowBlur=6):b.shadowColor="rgba(0,0,0,0)";this.live_mode||this.drawConnections(b);
|
||||
b.shadowColor="rgba(0,0,0,0)";b.restore()}b.finish&&b.finish();this.dirty_bgcanvas=!1;this.dirty_canvas=!0};var B=new Float32Array(2);m.prototype.drawNode=function(a,b){this.current_node=a;var c=a.color||a.constructor.color||g.NODE_DEFAULT_COLOR,d=a.bgcolor||a.constructor.bgcolor||g.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=g.DEFAULT_SHADOW_COLOR,b.shadowOffsetX=2*this.ds.scale,b.shadowOffsetY=2*this.ds.scale,b.shadowBlur=3*this.ds.scale):b.shadowColor="transparent";if(!a.flags.collapsed||!a.onDrawCollapsed||1!=a.onDrawCollapsed(b,this)){var h=a._shape||g.BOX_SHAPE;B.set(a.size);var k=a.horizontal;if(a.flags.collapsed){b.font=this.inner_text_font;var n=a.getTitle?a.getTitle():a.title;null!=n&&(a._collapsed_width=Math.min(a.size[0],b.measureText(n).width+2*g.NODE_TITLE_HEIGHT),B[0]=a._collapsed_width,
|
||||
B[1]=0)}a.clip_area&&(b.save(),b.beginPath(),h==g.BOX_SHAPE?b.rect(0,0,B[0],B[1]):h==g.ROUND_SHAPE?b.roundRect(0,0,B[0],B[1],[10]):h==g.CIRCLE_SHAPE&&b.arc(.5*B[0],.5*B[1],.5*B[0],0,2*Math.PI),b.clip());a.has_errors&&(d="red");this.drawNodeShape(a,b,B,c,d,a.is_selected,a.mouseOver);b.shadowColor="transparent";if(a.onDrawForeground)a.onDrawForeground(b,this,this.canvas);b.textAlign=k?"center":"left";b.font=this.inner_text_font;d=!e;var q=this.connecting_output;h=this.connecting_input;b.lineWidth=1;
|
||||
n=0;var u=new Float32Array(2);if(!a.flags.collapsed){if(a.inputs)for(c=0;c<a.inputs.length;c++){var r=a.inputs[c],m=r.type,l=r.shape;b.globalAlpha=f;this.connecting_output&&!g.isValidConnection(r.type,q.type)&&(b.globalAlpha=.4*f);b.fillStyle=null!=r.link?r.color_on||this.default_connection_color_byType[m]||this.default_connection_color.input_on:r.color_off||this.default_connection_color_byTypeOff[m]||this.default_connection_color_byType[m]||this.default_connection_color.input_off;var t=a.getConnectionPos(!0,
|
||||
c,u);t[0]-=a.pos[0];t[1]-=a.pos[1];n<t[1]+.5*g.NODE_SLOT_HEIGHT&&(n=t[1]+.5*g.NODE_SLOT_HEIGHT);b.beginPath();"array"==m&&(l=g.GRID_SHAPE);r.type===g.EVENT||r.shape===g.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):l===g.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()):l===g.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&&(m=null!=r.label?r.label:r.name)&&(b.fillStyle=g.NODE_TEXT_COLOR,k||r.dir==g.UP?b.fillText(m,t[0],t[1]-10):b.fillText(m,t[0]+10,t[1]+5))}b.textAlign=k?"center":"right";b.strokeStyle="black";if(a.outputs)for(c=0;c<a.outputs.length;c++)if(r=a.outputs[c],m=r.type,l=r.shape,this.connecting_input&&!g.isValidConnection(m,h.type)&&
|
||||
(b.globalAlpha=.4*f),t=a.getConnectionPos(!1,c,u),t[0]-=a.pos[0],t[1]-=a.pos[1],n<t[1]+.5*g.NODE_SLOT_HEIGHT&&(n=t[1]+.5*g.NODE_SLOT_HEIGHT),b.fillStyle=r.links&&r.links.length?r.color_on||this.default_connection_color_byType[m]||this.default_connection_color.output_on:r.color_off||this.default_connection_color_byTypeOff[m]||this.default_connection_color_byType[m]||this.default_connection_color.output_off,b.beginPath(),"array"==m&&(l=g.GRID_SHAPE),q=!0,m===g.EVENT||l===g.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):l===g.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()):l===g.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),q=!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&&q&&b.stroke(),
|
||||
d&&(m=null!=r.label?r.label:r.name))b.fillStyle=g.NODE_TEXT_COLOR,k||r.dir==g.DOWN?b.fillText(m,t[0],t[1]-8):b.fillText(m,t[0]-10,t[1]+5);b.textAlign="left";b.globalAlpha=1;if(a.widgets){r=n;if(k||a.widgets_up)r=2;null!=a.widgets_start_y&&(r=a.widgets_start_y);this.drawNodeWidgets(a,r,b,this.node_widget&&this.node_widget[0]==a?this.node_widget[1]:null)}}else if(this.render_collapsed_slots){e=f=null;if(a.inputs)for(c=0;c<a.inputs.length;c++)if(r=a.inputs[c],null!=r.link){f=r;break}if(a.outputs)for(c=
|
||||
0;c<a.outputs.length;c++)r=a.outputs[c],r.links&&r.links.length&&(e=r);f&&(f=0,c=-.5*g.NODE_TITLE_HEIGHT,k&&(f=.5*a._collapsed_width,c=-g.NODE_TITLE_HEIGHT),b.fillStyle="#686",b.beginPath(),r.type===g.EVENT||r.shape===g.BOX_SHAPE?b.rect(f-7+.5,c-4,14,8):r.shape===g.ARROW_SHAPE?(b.moveTo(f+8,c),b.lineTo(f+-4,c-4),b.lineTo(f+-4,c+4),b.closePath()):b.arc(f,c,4,0,2*Math.PI),b.fill());e&&(f=a._collapsed_width,c=-.5*g.NODE_TITLE_HEIGHT,k&&(f=.5*a._collapsed_width,c=0),b.fillStyle="#686",b.strokeStyle="black",
|
||||
b.beginPath(),r.type===g.EVENT||r.shape===g.BOX_SHAPE?b.rect(f-7+.5,c-4,14,8):r.shape===g.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}}};m.prototype.drawLinkTooltip=function(a,b){var c=b._pos;a.fillStyle="black";a.beginPath();a.arc(c[0],c[1],3,0,2*Math.PI);a.fill();if(null!=b.data&&(!this.onDrawLinkTooltip||1!=this.onDrawLinkTooltip(a,b,this))&&(b=b.data,b=b.constructor===Number?b.toFixed(2):
|
||||
b.constructor===String?'"'+b+'"':b.constructor===Boolean?String(b):b.toToolTip?b.toToolTip():"["+b.constructor.name+"]",null!=b)){b=b.substr(0,30);a.font="14px Courier New";var d=a.measureText(b).width+20;a.shadowColor="black";a.shadowOffsetX=2;a.shadowOffsetY=2;a.shadowBlur=3;a.fillStyle="#454";a.beginPath();a.roundRect(c[0]-.5*d,c[1]-15-24,d,24,[3]);a.moveTo(c[0]-10,c[1]-15);a.lineTo(c[0]+10,c[1]-15);a.lineTo(c[0],c[1]-5);a.fill();a.shadowColor="transparent";a.textAlign="center";a.fillStyle="#CEC";
|
||||
a.fillText(b,c[0],c[1]-15-24*.3)}};var y=new Float32Array(4);m.prototype.drawNodeShape=function(a,b,c,d,e,f,h){b.strokeStyle=d;b.fillStyle=e;e=g.NODE_TITLE_HEIGHT;var k=.5>this.ds.scale,n=a._shape||a.constructor.shape||g.ROUND_SHAPE,q=a.constructor.title_mode,u=!0;q==g.TRANSPARENT_TITLE||q==g.NO_TITLE?u=!1:q==g.AUTOHIDE_TITLE&&h&&(u=!0);y[0]=0;y[1]=u?-e:0;y[2]=c[0]+1;y[3]=u?c[1]+e:c[1];h=b.globalAlpha;b.beginPath();n==g.BOX_SHAPE||k?b.fillRect(y[0],y[1],y[2],y[3]):n==g.ROUND_SHAPE||n==g.CARD_SHAPE?
|
||||
b.roundRect(y[0],y[1],y[2],y[3],n==g.CARD_SHAPE?[this.round_radius,this.round_radius,0,0]:[this.round_radius]):n==g.CIRCLE_SHAPE&&b.arc(.5*c[0],.5*c[1],.5*c[0],0,2*Math.PI);b.fill();!a.flags.collapsed&&u&&(b.shadowColor="transparent",b.fillStyle="rgba(0,0,0,0.2)",b.fillRect(0,-1,y[2],2));b.shadowColor="transparent";if(a.onDrawBackground)a.onDrawBackground(b,this,this.canvas,this.graph_mouse);if(u||q==g.TRANSPARENT_TITLE){if(a.onDrawTitleBar)a.onDrawTitleBar(b,e,c,this.ds.scale,d);else if(q!=g.TRANSPARENT_TITLE&&
|
||||
(a.constructor.title_color||this.render_title_colored)){u=a.constructor.title_color||d;a.flags.collapsed&&(b.shadowColor=g.DEFAULT_SHADOW_COLOR);if(this.use_gradients){var r=m.gradients[u];r||(r=m.gradients[u]=b.createLinearGradient(0,0,400,0),r.addColorStop(0,u),r.addColorStop(1,"#000"));b.fillStyle=r}else b.fillStyle=u;b.beginPath();n==g.BOX_SHAPE||k?b.rect(0,-e,c[0]+1,e):(n==g.ROUND_SHAPE||n==g.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"}u=!1;g.node_box_coloured_by_mode&&g.NODE_MODES_COLORS[a.mode]&&(u=g.NODE_MODES_COLORS[a.mode]);g.node_box_coloured_when_on&&(u=a.action_triggered?"#FFF":a.execute_triggered?"#AAA":u);if(a.onDrawTitleBox)a.onDrawTitleBox(b,e,c,this.ds.scale);else n==g.ROUND_SHAPE||n==g.CIRCLE_SHAPE||n==g.CARD_SHAPE?(k&&(b.fillStyle="black",b.beginPath(),b.arc(.5*e,-.5*e,6,0,2*Math.PI),b.fill()),b.fillStyle=a.boxcolor||u||g.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||u||g.NODE_DEFAULT_BOXCOLOR,b.fillRect(.5*(e-10),-.5*(e+10),10,10));b.globalAlpha=h;if(a.onDrawTitleText)a.onDrawTitleText(b,e,c,this.ds.scale,this.title_text_font,f);!k&&(b.font=this.title_text_font,h=String(a.getTitle()))&&(b.fillStyle=f?g.NODE_SELECTED_TITLE_COLOR:a.constructor.title_text_color||this.node_title_color,a.flags.collapsed?(b.textAlign=
|
||||
"left",b.measureText(h),b.fillText(h.substr(0,20),e,g.NODE_TITLE_TEXT_Y-e),b.textAlign="left"):(b.textAlign="left",b.fillText(h,e,g.NODE_TITLE_TEXT_Y-e)));a.flags.collapsed||!a.subgraph||a.skip_subgraph_button||(h=g.NODE_TITLE_HEIGHT,u=a.size[0]-h,r=g.isInsideRectangle(this.graph_mouse[0]-a.pos[0],this.graph_mouse[1]-a.pos[1],u+2,-h+2,h-4,h-4),b.fillStyle=r?"#888":"#555",n==g.BOX_SHAPE||k?b.fillRect(u+2,-h+2,h-4,h-4):(b.beginPath(),b.roundRect(u+2,-h+2,h-4,h-4,[4]),b.fill()),b.fillStyle="#333",b.beginPath(),
|
||||
b.moveTo(u+.2*h,.6*-h),b.lineTo(u+.8*h,.6*-h),b.lineTo(u+.5*h,.3*-h),b.fill());if(a.onDrawTitle)a.onDrawTitle(b)}if(f){if(a.onBounding)a.onBounding(y);q==g.TRANSPARENT_TITLE&&(y[1]-=e,y[3]+=e);b.lineWidth=1;b.globalAlpha=.8;b.beginPath();n==g.BOX_SHAPE?b.rect(-6+y[0],-6+y[1],12+y[2],12+y[3]):n==g.ROUND_SHAPE||n==g.CARD_SHAPE&&a.flags.collapsed?b.roundRect(-6+y[0],-6+y[1],12+y[2],12+y[3],[2*this.round_radius]):n==g.CARD_SHAPE?b.roundRect(-6+y[0],-6+y[1],12+y[2],12+y[3],[2*this.round_radius,2,2*this.round_radius,
|
||||
2]):n==g.CIRCLE_SHAPE&&b.arc(.5*c[0],.5*c[1],.5*c[0]+6,0,2*Math.PI);b.strokeStyle=g.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 G=new Float32Array(4),A=new Float32Array(4),J=new Float32Array(2),K=new Float32Array(2);m.prototype.drawConnections=function(a){var b=g.getTime(),c=this.visible_area;G[0]=c[0]-20;G[1]=c[1]-20;G[2]=c[2]+40;G[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 h=0;h<f.inputs.length;++h){var k=f.inputs[h];if(k&&null!=k.link&&(k=this.graph.links[k.link])){var n=this.graph.getNodeById(k.origin_id);if(null!=n){var q=k.origin_slot;var u=-1==q?[n.pos[0]+10,n.pos[1]+10]:n.getConnectionPos(!1,q,J);var r=f.getConnectionPos(!0,h,K);A[0]=u[0];A[1]=u[1];A[2]=r[0]-u[0];A[3]=r[1]-u[1];0>A[2]&&(A[0]+=A[2],A[2]=
|
||||
Math.abs(A[2]));0>A[3]&&(A[1]+=A[3],A[3]=Math.abs(A[3]));if(F(A,G)){var m=n.outputs[q];q=f.inputs[h];if(m&&q&&(n=m.dir||(n.horizontal?g.DOWN:g.RIGHT),q=q.dir||(f.horizontal?g.UP:g.LEFT),this.renderLink(a,u,r,k,!1,0,null,n,q),k&&k._last_time&&1E3>b-k._last_time)){m=2-.002*(b-k._last_time);var l=a.globalAlpha;a.globalAlpha=l*m;this.renderLink(a,u,r,k,!0,m,"white",n,q);a.globalAlpha=l}}}}}}a.globalAlpha=1};m.prototype.renderLink=function(a,b,c,d,e,f,h,k,n,q){d&&this.visible_links.push(d);!h&&d&&(h=d.color||
|
||||
m.link_type_colors[d.type]);h||(h=this.default_link_color);null!=d&&this.highlighted_links[d.id]&&(h="#FFF");k=k||g.RIGHT;n=n||g.LEFT;var u=H(b,c);this.render_connections_border&&.6<this.ds.scale&&(a.lineWidth=this.connections_width+4);a.lineJoin="round";q=q||1;1<q&&(a.lineWidth=.5);a.beginPath();for(var r=0;r<q;r+=1){var l=5*(r-.5*(q-1));if(this.links_render_mode==g.SPLINE_LINK){a.moveTo(b[0],b[1]+l);var p=0,t=0,v=0,w=0;switch(k){case g.LEFT:p=-.25*u;break;case g.RIGHT:p=.25*u;break;case g.UP:t=
|
||||
-.25*u;break;case g.DOWN:t=.25*u}switch(n){case g.LEFT:v=-.25*u;break;case g.RIGHT:v=.25*u;break;case g.UP:w=-.25*u;break;case g.DOWN:w=.25*u}a.bezierCurveTo(b[0]+p,b[1]+t+l,c[0]+v,c[1]+w+l,c[0],c[1]+l)}else if(this.links_render_mode==g.LINEAR_LINK){a.moveTo(b[0],b[1]+l);w=v=t=p=0;switch(k){case g.LEFT:p=-1;break;case g.RIGHT:p=1;break;case g.UP:t=-1;break;case g.DOWN:t=1}switch(n){case g.LEFT:v=-1;break;case g.RIGHT:v=1;break;case g.UP:w=-1;break;case g.DOWN:w=1}a.lineTo(b[0]+15*p,b[1]+15*t+l);a.lineTo(c[0]+
|
||||
15*v,c[1]+15*w+l);a.lineTo(c[0],c[1]+l)}else if(this.links_render_mode==g.STRAIGHT_LINK)a.moveTo(b[0],b[1]),l=b[0],p=b[1],t=c[0],v=c[1],k==g.RIGHT?l+=10:p+=10,n==g.LEFT?t-=10:v-=10,a.lineTo(l,p),a.lineTo(.5*(l+t),p),a.lineTo(.5*(l+t),v),a.lineTo(t,v),a.lineTo(c[0],c[1]);else return}this.render_connections_border&&.6<this.ds.scale&&!e&&(a.strokeStyle="rgba(0,0,0,0.5)",a.stroke());a.lineWidth=this.connections_width;a.fillStyle=a.strokeStyle=h;a.stroke();e=this.computeConnectionPoint(b,c,.5,k,n);d&&
|
||||
d._pos&&(d._pos[0]=e[0],d._pos[1]=e[1]);.6<=this.ds.scale&&this.highquality_render&&n!=g.CENTER&&(this.render_connection_arrows&&(r=this.computeConnectionPoint(b,c,.25,k,n),u=this.computeConnectionPoint(b,c,.26,k,n),d=this.computeConnectionPoint(b,c,.75,k,n),q=this.computeConnectionPoint(b,c,.76,k,n),this.render_curved_connections?(u=-Math.atan2(u[0]-r[0],u[1]-r[1]),q=-Math.atan2(q[0]-d[0],q[1]-d[1])):q=u=c[1]>b[1]?0:Math.PI,a.save(),a.translate(r[0],r[1]),a.rotate(u),a.beginPath(),a.moveTo(-5,-3),
|
||||
a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore(),a.save(),a.translate(d[0],d[1]),a.rotate(q),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=h,r=0;5>r;++r)f=(.001*g.getTime()+.2*r)%1,e=this.computeConnectionPoint(b,c,f,k,n),a.beginPath(),a.arc(e[0],e[1],5,0,2*Math.PI),a.fill()};m.prototype.computeConnectionPoint=function(a,b,c,d,e){d=d||g.RIGHT;e=e||g.LEFT;var f=H(a,b),h=[a[0],a[1]],k=[b[0],
|
||||
b[1]];switch(d){case g.LEFT:h[0]+=-.25*f;break;case g.RIGHT:h[0]+=.25*f;break;case g.UP:h[1]+=-.25*f;break;case g.DOWN:h[1]+=.25*f}switch(e){case g.LEFT:k[0]+=-.25*f;break;case g.RIGHT:k[0]+=.25*f;break;case g.UP:k[1]+=-.25*f;break;case g.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]+e*h[0]+f*k[0]+c*b[0],d*a[1]+e*h[1]+f*k[1]+c*b[1]]};m.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]-g.NODE_TITLE_HEIGHT,d.pos[1]-g.NODE_TITLE_HEIGHT,g.NODE_TITLE_HEIGHT,g.NODE_TITLE_HEIGHT);0==d.order&&a.strokeRect(d.pos[0]-g.NODE_TITLE_HEIGHT+.5,d.pos[1]-g.NODE_TITLE_HEIGHT+.5,g.NODE_TITLE_HEIGHT,g.NODE_TITLE_HEIGHT);a.fillStyle="#FFF";a.fillText(d.order,d.pos[0]+-.5*g.NODE_TITLE_HEIGHT,d.pos[1]-6)}a.globalAlpha=1};m.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 h=g.NODE_WIDGET_HEIGHT,k=.5<this.ds.scale;c.save();c.globalAlpha=this.editor_alpha;for(var n=g.WIDGET_OUTLINE_COLOR,q=g.WIDGET_BGCOLOR,u=g.WIDGET_TEXT_COLOR,r=g.WIDGET_SECONDARY_TEXT_COLOR,m=0;m<f.length;++m){var l=f[m],t=b;l.y&&(t=l.y);l.last_y=t;c.strokeStyle=n;c.fillStyle="#222";c.textAlign="left";l.disabled&&(c.globalAlpha*=.5);var p=l.width||e;switch(l.type){case "button":l.clicked&&(c.fillStyle="#AAA",l.clicked=!1,this.dirty_canvas=
|
||||
!0);c.fillRect(15,t,p-30,h);k&&!l.disabled&&c.strokeRect(15,t,p-30,h);k&&(c.textAlign="center",c.fillStyle=u,c.fillText(l.name,.5*p,t+.7*h));break;case "toggle":c.textAlign="left";c.strokeStyle=n;c.fillStyle=q;c.beginPath();k?c.roundRect(15,t,p-30,h,[.5*h]):c.rect(15,t,p-30,h);c.fill();k&&!l.disabled&&c.stroke();c.fillStyle=l.value?"#89A":"#333";c.beginPath();c.arc(p-30,t+.5*h,.36*h,0,2*Math.PI);c.fill();k&&(c.fillStyle=r,null!=l.name&&c.fillText(l.name,30,t+.7*h),c.fillStyle=l.value?u:r,c.textAlign=
|
||||
"right",c.fillText(l.value?l.options.on||"true":l.options.off||"false",p-40,t+.7*h));break;case "slider":c.fillStyle=q;c.fillRect(15,t,p-30,h);var v=l.options.max-l.options.min,w=(l.value-l.options.min)/v;c.fillStyle=d==l?"#89A":"#678";c.fillRect(15,t,w*(p-30),h);k&&!l.disabled&&c.strokeRect(15,t,p-30,h);l.marker&&(v=(l.marker-l.options.min)/v,c.fillStyle="#AA9",c.fillRect(15+v*(p-30),t,2,h));k&&(c.textAlign="center",c.fillStyle=u,c.fillText(l.name+" "+Number(l.value).toFixed(3),.5*p,t+.7*h));break;
|
||||
case "number":case "combo":c.textAlign="left";c.strokeStyle=n;c.fillStyle=q;c.beginPath();k?c.roundRect(15,t,p-30,h,[.5*h]):c.rect(15,t,p-30,h);c.fill();k&&(l.disabled||c.stroke(),c.fillStyle=u,l.disabled||(c.beginPath(),c.moveTo(31,t+5),c.lineTo(21,t+.5*h),c.lineTo(31,t+h-5),c.fill(),c.beginPath(),c.moveTo(p-15-16,t+5),c.lineTo(p-15-6,t+.5*h),c.lineTo(p-15-16,t+h-5),c.fill()),c.fillStyle=r,c.fillText(l.name,35,t+.7*h),c.fillStyle=u,c.textAlign="right","number"==l.type?c.fillText(Number(l.value).toFixed(void 0!==
|
||||
l.options.precision?l.options.precision:3),p-30-20,t+.7*h):(v=l.value,l.options.values&&(w=l.options.values,w.constructor===Function&&(w=w()),w&&w.constructor!==Array&&(v=w[l.value])),c.fillText(v,p-30-20,t+.7*h)));break;case "string":case "text":c.textAlign="left";c.strokeStyle=n;c.fillStyle=q;c.beginPath();k?c.roundRect(15,t,p-30,h,[.5*h]):c.rect(15,t,p-30,h);c.fill();k&&(l.disabled||c.stroke(),c.save(),c.beginPath(),c.rect(15,t,p-30,h),c.clip(),c.fillStyle=r,null!=l.name&&c.fillText(l.name,30,
|
||||
t+.7*h),c.fillStyle=u,c.textAlign="right",c.fillText(String(l.value).substr(0,30),p-30,t+.7*h),c.restore());break;default:l.draw&&l.draw(c,a,p,t,h)}b+=(l.computeSize?l.computeSize(p)[1]:h)+4;c.globalAlpha=this.editor_alpha}c.restore();c.textAlign="left"};m.prototype.processNodeWidgets=function(a,b,c,d){function e(e,d){e.value=d;e.options&&e.options.property&&void 0!==a.properties[e.options.property]&&a.setProperty(e.options.property,d);e.callback&&e.callback(e.value,n,a,b,c)}if(!a.widgets||!a.widgets.length)return null;
|
||||
for(var f=b[0]-a.pos[0],h=b[1]-a.pos[1],k=a.size[0],n=this,q=this.getCanvasWindow(),u=0;u<a.widgets.length;++u){var r=a.widgets[u];if(r&&!r.disabled){var m=r.computeSize?r.computeSize(k)[1]:g.NODE_WIDGET_HEIGHT,l=r.width||k;if(r==d||!(6>f||f>l-12||h<r.last_y||h>r.last_y+m||void 0===r.last_y)){d=r.value;switch(r.type){case "button":c.type===g.pointerevents_method+"down"&&(r.callback&&setTimeout(function(){r.callback(r,n,a,b,c)},20),this.dirty_canvas=r.clicked=!0);break;case "slider":q=Math.clamp((f-
|
||||
15)/(l-30),0,1);r.value=r.options.min+(r.options.max-r.options.min)*q;r.callback&&setTimeout(function(){e(r,r.value)},20);this.dirty_canvas=!0;break;case "number":case "combo":d=r.value;if(c.type==g.pointerevents_method+"move"&&"number"==r.type)r.value+=.1*c.deltaX*(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==g.pointerevents_method+"down"){var t=r.options.values;t&&t.constructor===
|
||||
Function&&(t=r.options.values(r,a));var p=null;"number"!=r.type&&(p=t.constructor===Array?t:Object.keys(t));f=40>f?-1:f>l-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)q=-1,this.last_mouseclick=0,q=t.constructor===Object?p.indexOf(String(r.value))+f:p.indexOf(r.value)+f,q>=p.length&&(q=p.length-1),0>q&&(q=0),r.value=t.constructor===Array?
|
||||
t[q]:q;else{var v=t!=p?Object.values(t):t;new g.ContextMenu(v,{scale:Math.max(1,this.ds.scale),event:c,className:"dark",callback:function(a,b,c){t!=p&&(a=v.indexOf(a));this.value=a;e(this,a);n.dirty_canvas=!0;return!1}.bind(r)},q)}}else c.type==g.pointerevents_method+"up"&&"number"==r.type&&(f=40>f?-1:f>l-40?1:0,200>c.click_time&&0==f&&this.prompt("Value",r.value,function(a){this.value=Number(a);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==g.pointerevents_method+"down"&&(r.value=!r.value,setTimeout(function(){e(r,r.value)},20));break;case "string":case "text":c.type==g.pointerevents_method+"down"&&this.prompt("Value",r.value,function(a){this.value=a;e(this,a)}.bind(r),c,r.options?r.options.multiline:!1);break;default:r.mouse&&(this.dirty_canvas=r.mouse(c,[f,h],a))}if(d!=r.value){if(a.onWidgetChanged)a.onWidgetChanged(r.name,r.value,d,r);a.graph._version++}return r}}}return null};m.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(F(this.visible_area,d._bounding)){b.fillStyle=d.color||"#335";b.strokeStyle=d.color||"#335";var e=d._pos,f=d._size;b.globalAlpha=.25*this.editor_alpha;b.beginPath();b.rect(e[0]+.5,e[1]+.5,f[0],f[1]);b.fill();b.globalAlpha=this.editor_alpha;b.stroke();b.beginPath();b.moveTo(e[0]+f[0],e[1]+f[1]);b.lineTo(e[0]+f[0]-10,e[1]+f[1]);b.lineTo(e[0]+f[0],e[1]+f[1]-10);b.fill();
|
||||
f=d.font_size||g.DEFAULT_GROUP_FONT_SIZE;b.font=f+"px Arial";b.textAlign="left";b.fillText(d.title,e[0]+4,e[1]+f)}}b.restore()}};m.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)};m.prototype.resize=function(a,b){a||b||(b=this.canvas.parentNode,a=b.offsetWidth,b=b.offsetHeight);if(this.canvas.width!=a||this.canvas.height!=b)this.canvas.width=a,this.canvas.height=b,this.bgcanvas.width=this.canvas.width,this.bgcanvas.height=
|
||||
this.canvas.height,this.setDirty(!0,!0)};m.prototype.switchLiveMode=function(a){if(a){var b=this,c=this.live_mode?1.1:.9;this.live_mode&&(this.live_mode=!1,this.editor_alpha=.1);var d=setInterval(function(){b.editor_alpha*=c;b.dirty_canvas=!0;b.dirty_bgcanvas=!0;1>c&&.01>b.editor_alpha&&(clearInterval(d),1>c&&(b.live_mode=!0));1<c&&.99<b.editor_alpha&&(clearInterval(d),b.editor_alpha=1)},1)}else this.live_mode=!this.live_mode,this.dirty_bgcanvas=this.dirty_canvas=!0};m.prototype.onNodeSelectionChange=
|
||||
function(a){};m.onGroupAdd=function(a,b,c){a=m.active_canvas;a.getCanvasWindow();b=new g.LGraphGroup;b.pos=a.convertEventToCanvasOffset(c);a.graph.add(b)};m.onMenuAdd=function(a,b,c,d,e){function f(a,b){var d=[];g.getNodeTypesCategories(h.filter||n.filter).filter(function(b){return b.startsWith(a)}).map(function(b){if(b){b=b.replace(new RegExp("^("+a+")"),"").split("/")[0];var c=""===a?b+"/":a+b+"/";-1!=b.indexOf("::")&&(b=b.split("::")[1]);-1===d.findIndex(function(a){return a.value===c})&&d.push({value:c,
|
||||
content:b,has_submenu:!0,callback:function(a,b,c,e){f(a.value,e)}})}});g.getNodeTypesInCategory(a.slice(0,-1),h.filter||n.filter).map(function(a){a.skip_list||d.push({value:a.type,content:a.title,has_submenu:!1,callback:function(a,b,c,d){b=d.getFirstEvent();h.graph.beforeChange();if(a=g.createNode(a.value))a.pos=h.convertEventToCanvasOffset(b),h.graph.add(a);e&&e(a);h.graph.afterChange()}})});new g.ContextMenu(d,{event:c,parentMenu:b},k)}var h=m.active_canvas,k=h.getCanvasWindow(),n=h.graph;if(n)return f("",
|
||||
d),!1};m.onMenuCollapseAll=function(){};m.onMenuNodeEdit=function(){};m.showMenuNodeOptionalInputs=function(a,b,c,d,e){if(e){var f=this;a=m.active_canvas.getCanvasWindow();b=e.optional_inputs;e.onGetInputs&&(b=e.onGetInputs());var h=[];if(b)for(var k=0;k<b.length;k++){var n=b[k];if(n){var q=n[0];n[2]||(n[2]={});n[2].label&&(q=n[2].label);n[2].removable=!0;q={content:q,value:n};n[1]==g.ACTION&&(q.className="event");h.push(q)}else h.push(null)}e.onMenuNodeInputs&&(b=e.onMenuNodeInputs(h))&&(h=b);if(h.length)return new g.ContextMenu(h,
|
||||
{event:c,callback:function(a,b,c){if(e&&(a.callback&&a.callback.call(f,e,a,b,c),a.value)){e.graph.beforeChange();e.addInput(a.value[0],a.value[1],a.value[2]);if(e.onNodeInputAdd)e.onNodeInputAdd(a.value);e.setDirtyCanvas(!0,!0);e.graph.afterChange()}},parentMenu:d,node:e},a),!1;console.log("no input entries")}};m.showMenuNodeOptionalOutputs=function(a,b,c,d,e){function f(a,b,c){if(e&&(a.callback&&a.callback.call(h,e,a,b,c),a.value))if(c=a.value[1],!c||c.constructor!==Object&&c.constructor!==Array){e.graph.beforeChange();
|
||||
e.addOutput(a.value[0],a.value[1],a.value[2]);if(e.onNodeOutputAdd)e.onNodeOutputAdd(a.value);e.setDirtyCanvas(!0,!0);e.graph.afterChange()}else{a=[];for(var k in c)a.push({content:k,value:c[k]});new g.ContextMenu(a,{event:b,callback:f,parentMenu:d,node:e});return!1}}if(e){var h=this;a=m.active_canvas.getCanvasWindow();b=e.optional_outputs;e.onGetOutputs&&(b=e.onGetOutputs());var k=[];if(b)for(var n=0;n<b.length;n++){var q=b[n];if(!q)k.push(null);else if(!e.flags||!e.flags.skip_repeated_outputs||
|
||||
-1==e.findOutputSlot(q[0])){var u=q[0];q[2]||(q[2]={});q[2].label&&(u=q[2].label);q[2].removable=!0;u={content:u,value:q};q[1]==g.EVENT&&(u.className="event");k.push(u)}}this.onMenuNodeOutputs&&(k=this.onMenuNodeOutputs(k));g.do_add_triggers_slots&&-1==e.findOutputSlot("onExecuted")&&k.push({content:"On Executed",value:["onExecuted",g.EVENT,{nameLocked:!0}],className:"event"});e.onMenuNodeOutputs&&(b=e.onMenuNodeOutputs(k))&&(k=b);if(k.length)return new g.ContextMenu(k,{event:c,callback:f,parentMenu:d,
|
||||
node:e},a),!1}};m.onShowMenuNodeProperties=function(a,b,c,d,e){if(e&&e.properties){var f=m.active_canvas;b=f.getCanvasWindow();var h=[],k;for(k in e.properties){a=void 0!==e.properties[k]?e.properties[k]:" ";"object"==typeof a&&(a=JSON.stringify(a));var n=e.getPropertyInfo(k);if("enum"==n.type||"combo"==n.type)a=m.getPropertyPrintableValue(a,n.values);a=m.decodeHTML(a);h.push({content:"<span class='property_name'>"+(n.label?n.label:k)+"</span><span class='property_value'>"+a+"</span>",value:k})}if(h.length)return new g.ContextMenu(h,
|
||||
{event:c,callback:function(a,b,c,d){e&&(b=this.getBoundingClientRect(),f.showEditPropertyValue(e,a.value,{position:[b.left,b.top]}))},parentMenu:d,allow_html:!0,node:e},b),!1}};m.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};m.onMenuResizeNode=function(a,b,c,d,e){if(e){a=function(a){a.size=a.computeSize();if(a.onResize)a.onResize(a.size)};b=m.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]);
|
||||
this.resizing_node=null;else if(this.node_dragged){(d=this.node_dragged)&&300>a.click_time&&C(a.canvasX,a.canvasY,d.pos[0],d.pos[1]-g.NODE_TITLE_HEIGHT,g.NODE_TITLE_HEIGHT,g.NODE_TITLE_HEIGHT)&&d.collapse();this.dirty_bgcanvas=this.dirty_canvas=!0;this.node_dragged.pos[0]=Math.round(this.node_dragged.pos[0]);this.node_dragged.pos[1]=Math.round(this.node_dragged.pos[1]);(this.graph.config.align_to_grid||this.align_to_grid)&&this.node_dragged.alignToGrid();if(this.onNodeMoved)this.onNodeMoved(this.node_dragged);
|
||||
this.graph.afterChange(this.node_dragged);this.node_dragged=null}else{d=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes);!d&&300>a.click_time&&this.deselectAllNodes();this.dirty_canvas=!0;this.dragging_canvas=!1;if(this.node_over&&this.node_over.onMouseUp)this.node_over.onMouseUp(a,[a.canvasX-this.node_over.pos[0],a.canvasY-this.node_over.pos[1]],this);if(this.node_capturing_input&&this.node_capturing_input.onMouseUp)this.node_capturing_input.onMouseUp(a,[a.canvasX-this.node_capturing_input.pos[0],
|
||||
a.canvasY-this.node_capturing_input.pos[1]])}}else 2==a.which?(this.dirty_canvas=!0,this.dragging_canvas=!1):3==a.which&&(this.dirty_canvas=!0,this.dragging_canvas=!1);b&&(this.pointer_is_double=this.pointer_is_down=!1);this.graph.change();a.stopPropagation();a.preventDefault();return!1}};m.prototype.processMouseWheel=function(a){if(this.graph&&this.allow_dragcanvas){var b=null!=a.wheelDeltaY?a.wheelDeltaY:-60*a.detail;this.adjustMouseEvent(a);var c=a.clientX,d=a.clientY;if(!this.viewport||this.viewport&&
|
||||
c>=this.viewport[0]&&c<this.viewport[0]+this.viewport[2]&&d>=this.viewport[1]&&d<this.viewport[1]+this.viewport[3])return c=this.ds.scale,0<b?c*=1.1:0>b&&(c*=1/1.1),this.ds.changeScale(c,[a.clientX,a.clientY]),this.graph.change(),a.preventDefault(),!1}};m.prototype.isOverNodeBox=function(a,b,c){var d=g.NODE_TITLE_HEIGHT;return C(b,c,a.pos[0]+2,a.pos[1]+2-d,d-4,d-4)?!0:!1};m.prototype.isOverNodeInput=function(a,b,c,d){if(a.inputs)for(var e=0,f=a.inputs.length;e<f;++e){var h=a.getConnectionPos(!0,e);
|
||||
if(a.horizontal?C(b,c,h[0]-5,h[1]-10,10,20):C(b,c,h[0]-10,h[1]-5,40,10))return d&&(d[0]=h[0],d[1]=h[1]),e}return-1};m.prototype.isOverNodeOutput=function(a,b,c,d){if(a.outputs)for(var e=0,f=a.outputs.length;e<f;++e){var h=a.getConnectionPos(!1,e);if(a.horizontal?C(b,c,h[0]-5,h[1]-10,10,20):C(b,c,h[0]-10,h[1]-5,40,10))return d&&(d[0]=h[0],d[1]=h[1]),e}return-1};m.prototype.processKey=function(a){if(this.graph){var b=!1;if("input"!=a.target.localName){if("keydown"==a.type){if(32==a.keyCode&&(b=this.dragging_canvas=
|
||||
!0),27==a.keyCode&&(this.node_panel&&this.node_panel.close(),this.options_panel&&this.options_panel.close(),b=!0),65==a.keyCode&&a.ctrlKey&&(this.selectNodes(),b=!0),"KeyC"==a.code&&(a.metaKey||a.ctrlKey)&&!a.shiftKey&&this.selected_nodes&&(this.copyToClipboard(),b=!0),"KeyV"!=a.code||!a.metaKey&&!a.ctrlKey||a.shiftKey||this.pasteFromClipboard(),46!=a.keyCode&&8!=a.keyCode||"input"==a.target.localName||"textarea"==a.target.localName||(this.deleteSelectedNodes(),b=!0),this.selected_nodes)for(var c in this.selected_nodes)if(this.selected_nodes[c].onKeyDown)this.selected_nodes[c].onKeyDown(a)}else if("keyup"==
|
||||
a.type&&(32==a.keyCode&&(this.dragging_canvas=!1),this.selected_nodes))for(c in this.selected_nodes)if(this.selected_nodes[c].onKeyUp)this.selected_nodes[c].onKeyUp(a);this.graph.change();if(b)return a.preventDefault(),a.stopImmediatePropagation(),!1}}};m.prototype.copyToClipboard=function(){var a={nodes:[],links:[]},b=0,c=[],d;for(d in this.selected_nodes){var e=this.selected_nodes[d];e._relative_id=b;c.push(e);b+=1}for(d=0;d<c.length;++d)if(e=c[d],b=e.clone()){if(a.nodes.push(b.serialize()),e.inputs&&
|
||||
e.inputs.length)for(b=0;b<e.inputs.length;++b){var f=e.inputs[b];if(f&&null!=f.link&&(f=this.graph.links[f.link])){var h=this.graph.getNodeById(f.origin_id);h&&this.selected_nodes[h.id]&&a.links.push([h._relative_id,f.origin_slot,e._relative_id,f.target_slot])}}}else console.warn("node type not found: "+e.type);localStorage.setItem("litegrapheditor_clipboard",JSON.stringify(a))};m.prototype.pasteFromClipboard=function(){var a=localStorage.getItem("litegrapheditor_clipboard");if(a){this.graph.beforeChange();
|
||||
a=JSON.parse(a);for(var b=!1,c=!1,d=0;d<a.nodes.length;++d)b?(b[0]>a.nodes[d].pos[0]&&(b[0]=a.nodes[d].pos[0],c[0]=d),b[1]>a.nodes[d].pos[1]&&(b[1]=a.nodes[d].pos[1],c[1]=d)):(b=[a.nodes[d].pos[0],a.nodes[d].pos[1]],c=[d,d]);c=[];for(d=0;d<a.nodes.length;++d){var e=a.nodes[d],f=g.createNode(e.type);f&&(f.configure(e),f.pos[0]+=this.graph_mouse[0]-b[0],f.pos[1]+=this.graph_mouse[1]-b[1],this.graph.add(f,{doProcessChange:!1}),c.push(f))}for(d=0;d<a.links.length;++d)b=a.links[d],e=c[b[0]],f=c[b[2]],
|
||||
e&&f?e.connect(b[1],f,b[3]):console.warn("Warning, nodes missing on pasting");this.selectNodes(c);this.graph.afterChange()}};m.prototype.processDrop=function(a){a.preventDefault();this.adjustMouseEvent(a);var b=a.clientX,c=a.clientY;if(!this.viewport||this.viewport&&b>=this.viewport[0]&&b<this.viewport[0]+this.viewport[2]&&c>=this.viewport[1]&&c<this.viewport[1]+this.viewport[3]){b=[a.canvasX,a.canvasY];var d=this.graph?this.graph.getNodeOnPos(b[0],b[1]):null;if(d){if((d.onDropFile||d.onDropData)&&
|
||||
(b=a.dataTransfer.files)&&b.length)for(c=0;c<b.length;c++){var e=a.dataTransfer.files[0],f=e.name;m.getFileExtension(f);if(d.onDropFile)d.onDropFile(e);if(d.onDropData){var h=new FileReader;h.onload=function(a){d.onDropData(a.target.result,f,e)};var g=e.type.split("/")[0];"text"==g||""==g?h.readAsText(e):"image"==g?h.readAsDataURL(e):h.readAsArrayBuffer(e)}}return d.onDropItem&&d.onDropItem(event)?!0:this.onDropItem?this.onDropItem(event):!1}b=null;this.onDropItem&&(b=this.onDropItem(event));b||this.checkDropItem(a)}};
|
||||
m.prototype.checkDropItem=function(a){if(a.dataTransfer.files.length){var b=a.dataTransfer.files[0],c=m.getFileExtension(b.name).toLowerCase();if(c=g.node_types_by_file_extension[c]){this.graph.beforeChange();c=g.createNode(c.type);c.pos=[a.canvasX,a.canvasY];this.graph.add(c);if(c.onDropFile)c.onDropFile(b);this.graph.afterChange()}}};m.prototype.processNodeDblClicked=function(a){if(this.onShowNodePanel)this.onShowNodePanel(a);else this.showShowNodePanel(a);if(this.onNodeDblClicked)this.onNodeDblClicked(a);
|
||||
this.setDirty(!0)};m.prototype.processNodeSelected=function(a,b){this.selectNode(a,b&&(b.shiftKey||b.ctrlKey));if(this.onNodeSelected)this.onNodeSelected(a)};m.prototype.selectNode=function(a,b){null==a?this.deselectAllNodes():this.selectNodes([a],b)};m.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){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)};m.prototype.deselectNode=function(a){if(a.is_selected){if(a.onDeselected)a.onDeselected();a.is_selected=!1;if(this.onNodeDeselected)this.onNodeDeselected(a);if(a.inputs)for(var b=
|
||||
0;b<a.inputs.length;++b)delete this.highlighted_links[a.inputs[b].link];if(a.outputs)for(b=0;b<a.outputs.length;++b){var c=a.outputs[b];if(c.links)for(var d=0;d<c.links.length;++d)delete this.highlighted_links[c.links[d]]}}};m.prototype.deselectAllNodes=function(){if(this.graph){for(var a=this.graph._nodes,b=0,c=a.length;b<c;++b){var d=a[b];if(d.is_selected){if(d.onDeselected)d.onDeselected();d.is_selected=!1;if(this.onNodeDeselected)this.onNodeDeselected(d)}}this.selected_nodes={};this.current_node=
|
||||
null;this.highlighted_links={};if(this.onSelectionChange)this.onSelectionChange(this.selected_nodes);this.setDirty(!0)}};m.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&&g.isValidConnection(b.inputs[0].type,b.outputs[0].type)&&b.inputs[0].link&&b.outputs[0].links&&b.outputs[0].links.length){var c=b.graph.links[b.inputs[0].link],d=b.graph.links[b.outputs[0].links[0]],
|
||||
e=b.getInputNode(0),f=b.getOutputNodes(0)[0];e&&f&&e.connect(c.origin_slot,f,d.target_slot)}this.graph.remove(b);if(this.onNodeDeselected)this.onNodeDeselected(b)}}this.selected_nodes={};this.current_node=null;this.highlighted_links={};this.setDirty(!0);this.graph.afterChange()};m.prototype.centerOnNode=function(a){this.ds.offset[0]=-a.pos[0]-.5*a.size[0]+.5*this.canvas.width/this.ds.scale;this.ds.offset[1]=-a.pos[1]-.5*a.size[1]+.5*this.canvas.height/this.ds.scale;this.setDirty(!0,!0)};m.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;a.deltaX=c-this.last_mouse_position[0];a.deltaY=b-this.last_mouse_position[1];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]};m.prototype.setZoom=function(a,b){this.ds.changeScale(a,b);this.dirty_bgcanvas=this.dirty_canvas=!0};m.prototype.convertOffsetToCanvas=
|
||||
function(a,b){return this.ds.convertOffsetToCanvas(a,b)};m.prototype.convertCanvasToOffset=function(a,b){return this.ds.convertCanvasToOffset(a,b)};m.prototype.convertEventToCanvasOffset=function(a){var b=this.canvas.getBoundingClientRect();return this.convertCanvasToOffset([a.clientX-b.left,a.clientY-b.top])};m.prototype.bringToFront=function(a){var b=this.graph._nodes.indexOf(a);-1!=b&&(this.graph._nodes.splice(b,1),this.graph._nodes.push(a))};m.prototype.sendToBack=function(a){var b=this.graph._nodes.indexOf(a);
|
||||
-1!=b&&(this.graph._nodes.splice(b,1),this.graph._nodes.unshift(a))};var I=new Float32Array(4);m.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)&&F(this.visible_area,e.getBounding(I))&&b.push(e)}return b};m.prototype.draw=function(a,b){if(this.canvas&&0!=this.canvas.width&&0!=this.canvas.height){var c=g.getTime();this.render_time=.001*(c-this.last_draw_time);this.last_draw_time=
|
||||
c;this.graph&&this.ds.computeVisibleArea(this.viewport);(this.dirty_bgcanvas||b||this.always_render_background||this.graph&&this.graph._last_trigger_time&&1E3>c-this.graph._last_trigger_time)&&this.drawBackCanvas();(this.dirty_canvas||a)&&this.drawFrontCanvas();this.fps=this.render_time?1/this.render_time:0;this.frame+=1}};m.prototype.drawFrontCanvas=function(){this.dirty_canvas=!1;this.ctx||(this.ctx=this.bgcanvas.getContext("2d"));var a=this.ctx;if(a){var b=this.canvas;a.start2D&&!this.viewport&&
|
||||
(a.start2D(),a.restore(),a.setTransform(1,0,0,1,0,0));var c=this.viewport||this.dirty_area;c&&(a.save(),a.beginPath(),a.rect(c[0],c[1],c[2],c[3]),a.clip());this.clear_background&&(c?a.clearRect(c[0],c[1],c[2],c[3]):a.clearRect(0,0,b.width,b.height));this.bgcanvas==this.canvas?this.drawBackCanvas():a.drawImage(this.bgcanvas,0,0);if(this.onRender)this.onRender(b,a);this.show_info&&this.renderInfo(a,c?c[0]:0,c?c[1]:0);if(this.graph){a.save();this.ds.toCanvasContext(a);b=this.computeVisibleNodes(null,
|
||||
this.visible_nodes);for(var d=0;d<b.length;++d){var e=b[d];a.save();a.translate(e.pos[0],e.pos[1]);this.drawNode(e,a);a.restore()}this.render_execution_order&&this.drawExecutionOrder(a);this.graph.config.links_ontop&&(this.live_mode||this.drawConnections(a));if(null!=this.connecting_pos){a.lineWidth=this.connections_width;e=this.connecting_output||this.connecting_input;b=e.type;d=e.dir;null==d&&(d=this.connecting_output?this.connecting_node.horizontal?g.DOWN:g.RIGHT:this.connecting_node.horizontal?
|
||||
g.UP:g.LEFT);var f=e.shape;switch(b){case g.EVENT:e=g.EVENT_LINK_COLOR;break;default:e=g.CONNECTING_LINK_COLOR}this.renderLink(a,this.connecting_pos,[this.graph_mouse[0],this.graph_mouse[1]],null,!1,null,e,d,g.CENTER);a.beginPath();b===g.EVENT||f===g.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===g.ARROW_SHAPE?(a.moveTo(this.connecting_pos[0]+8,this.connecting_pos[1]+.5),a.lineTo(this.connecting_pos[0]-
|
||||
4,this.connecting_pos[1]+6+.5),a.lineTo(this.connecting_pos[0]-4,this.connecting_pos[1]-6+.5),a.closePath()):(a.arc(this.connecting_pos[0],this.connecting_pos[1],4,0,2*Math.PI),a.fill(),a.beginPath(),a.arc(this.graph_mouse[0],this.graph_mouse[1],4,0,2*Math.PI));a.fill();a.fillStyle="#ffcc00";if(this._highlight_input){a.beginPath();var h=this._highlight_input_slot.shape;h===g.ARROW_SHAPE?(a.moveTo(this._highlight_input[0]+8,this._highlight_input[1]+.5),a.lineTo(this._highlight_input[0]-4,this._highlight_input[1]+
|
||||
6+.5),a.lineTo(this._highlight_input[0]-4,this._highlight_input[1]-6+.5),a.closePath()):a.arc(this._highlight_input[0],this._highlight_input[1],6,0,2*Math.PI);a.fill()}this._highlight_output&&(a.beginPath(),h===g.ARROW_SHAPE?(a.moveTo(this._highlight_output[0]+8,this._highlight_output[1]+.5),a.lineTo(this._highlight_output[0]-4,this._highlight_output[1]+6+.5),a.lineTo(this._highlight_output[0]-4,this._highlight_output[1]-6+.5),a.closePath()):a.arc(this._highlight_output[0],this._highlight_output[1],
|
||||
6,0,2*Math.PI),a.fill())}this.dragging_rectangle&&(a.strokeStyle="#FFF",a.strokeRect(this.dragging_rectangle[0],this.dragging_rectangle[1],this.dragging_rectangle[2],this.dragging_rectangle[3]));if(this.over_link_center&&this.render_link_tooltip)this.drawLinkTooltip(a,this.over_link_center);else if(this.onDrawLinkTooltip)this.onDrawLinkTooltip(a,null);if(this.onDrawForeground)this.onDrawForeground(a,this.visible_rect);a.restore()}this._graph_stack&&this._graph_stack.length&&this.drawSubgraphPanel(a);
|
||||
if(this.onDrawOverlay)this.onDrawOverlay(a);c&&a.restore();a.finish2D&&a.finish2D()}};m.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")};m.prototype.drawSubgraphPanelLeft=function(a,b,c){var d=b.inputs?b.inputs.length:0,e=Math.floor(1.6*g.NODE_SLOT_HEIGHT);c.fillStyle="#111";c.globalAlpha=.8;c.beginPath();c.roundRect(10,10,200,(d+1)*e+50,[8]);c.fill();c.globalAlpha=
|
||||
1;c.fillStyle="#888";c.font="14px Arial";c.textAlign="left";c.fillText("Graph Inputs",20,34);if(this.drawButton(180,20,20,20,"X","#151515"))this.closeSubgraph();else{d=50;c.font="14px Arial";if(b.inputs)for(var f=0;f<b.inputs.length;++f){var h=b.inputs[f];if(!h.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 n=g.createNode(k);n?(a.add(n),this.block_click=!1,this.last_click_position=null,this.selectNodes([n]),
|
||||
this.node_dragged=n,this.dragging_canvas=!1,n.setProperty("name",h.name),n.setProperty("type",h.type),this.node_dragged.pos[0]=this.graph_mouse[0]-5,this.node_dragged.pos[1]=this.graph_mouse[1]-5,this.graph.afterChange()):console.error("graph input node not found:",k)}c.fillStyle="#9C9";c.beginPath();c.arc(184,d+.5*e,5,0,2*Math.PI);c.fill();c.fillStyle="#AAA";c.fillText(h.name,30,d+.75*e);c.fillStyle="#777";c.fillText(h.type,130,d+.75*e);d+=e}}this.drawButton(20,d+2,180,e-2,"+","#151515","#222")&&
|
||||
this.showSubgraphPropertiesDialog(b)}};m.prototype.drawSubgraphPanelRight=function(a,b,c){var d=b.outputs?b.outputs.length:0,e=this.bgcanvas.width,f=Math.floor(1.6*g.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();
|
||||
else{d=50;c.font="14px Arial";if(b.outputs)for(var h=0;h<b.outputs.length;++h){var k=b.outputs[h];if(!k.not_subgraph_input){if(this.drawButton(e-200,d+2,180,f-2)){var n=b.constructor.output_node_type||"graph/output";this.graph.beforeChange();var q=g.createNode(n);q?(a.add(q),this.block_click=!1,this.last_click_position=null,this.selectNodes([q]),this.node_dragged=q,this.dragging_canvas=!1,q.setProperty("name",k.name),q.setProperty("type",k.type),this.node_dragged.pos[0]=this.graph_mouse[0]-5,this.node_dragged.pos[1]=
|
||||
this.graph_mouse[1]-5,this.graph.afterChange()):console.error("graph input node not found:",n)}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)}};m.prototype.drawButton=function(a,b,c,d,e,f,h,k){var n=this.ctx;f=f||g.NODE_DEFAULT_COLOR;h=h||"#555";k=k||g.NODE_TEXT_COLOR;
|
||||
var q=b+g.NODE_TITLE_HEIGHT+2,u=this.mouse,r=g.isInsideRectangle(u[0],u[1],a,q,c,d);q=(u=this.last_click_position)&&g.isInsideRectangle(u[0],u[1],a,q,c,d);n.fillStyle=r?h:f;q&&(n.fillStyle="#AAA");n.beginPath();n.roundRect(a,b,c,d,[4]);n.fill();null!=e&&e.constructor==String&&(n.fillStyle=k,n.textAlign="center",n.font=(.65*d|0)+"px Arial",n.fillText(e,a+.5*c,b+.75*d),n.textAlign="left");a=q&&!this.block_click;q&&this.blockClick();return a};m.prototype.isAreaClicked=function(a,b,c,d,e){var f=this.mouse;
|
||||
g.isInsideRectangle(f[0],f[1],a,b,c,d);b=(a=(f=this.last_click_position)&&g.isInsideRectangle(f[0],f[1],a,b,c,d))&&!this.block_click;a&&e&&this.blockClick();return b};m.prototype.renderInfo=function(a,b,c){b=b||10;c=c||this.canvas.height-80;a.save();a.translate(b,c);a.font="10px Arial";a.fillStyle="#888";a.textAlign="left";this.graph?(a.fillText("T: "+this.graph.globaltime.toFixed(2)+"s",5,13),a.fillText("I: "+this.graph.iteration,5,26),a.fillText("N: "+this.graph._nodes.length+" ["+this.visible_nodes.length+
|
||||
"]",5,39),a.fillText("V: "+this.graph._version,5,52),a.fillText("FPS:"+this.fps.toFixed(2),5,65)):a.fillText("No graph selected",5,13);a.restore()};m.prototype.drawBackCanvas=function(){var a=this.bgcanvas;if(a.width!=this.canvas.width||a.height!=this.canvas.height)a.width=this.canvas.width,a.height=this.canvas.height;this.bgctx||(this.bgctx=this.bgcanvas.getContext("2d"));var b=this.bgctx;b.start&&b.start();var c=this.viewport||[0,0,b.canvas.width,b.canvas.height];this.clear_background&&b.clearRect(c[0],
|
||||
c[1],c[2],c[3]);if(this._graph_stack&&this._graph_stack.length){b.save();c=this.graph._subgraph_node;b.strokeStyle=c.bgcolor;b.lineWidth=10;b.strokeRect(1,1,a.width-2,a.height-2);b.lineWidth=1;b.font="40px Arial";b.textAlign="center";b.fillStyle=c.bgcolor||"#AAA";for(var d="",e=1;e<this._graph_stack.length;++e)d+=this._graph_stack[e]._subgraph_node.getTitle()+" >> ";b.fillText(d+c.getTitle(),.5*a.width,40);b.restore()}c=!1;this.onRenderBackground&&(c=this.onRenderBackground(a,b));this.viewport||(b.restore(),
|
||||
b.setTransform(1,0,0,1,0,0));this.visible_links.length=0;if(this.graph){b.save();this.ds.toCanvasContext(b);if(this.background_image&&.5<this.ds.scale&&!c){b.globalAlpha=this.zoom_modify_alpha?(1-.5/this.ds.scale)*this.editor_alpha:this.editor_alpha;b.imageSmoothingEnabled=b.imageSmoothingEnabled=!1;if(!this._bg_img||this._bg_img.name!=this.background_image){this._bg_img=new Image;this._bg_img.name=this.background_image;this._bg_img.src=this.background_image;var f=this;this._bg_img.onload=function(){f.draw(!0,
|
||||
!0)}}c=null;null==this._pattern&&0<this._bg_img.width?(c=b.createPattern(this._bg_img,"repeat"),this._pattern_img=this._bg_img,this._pattern=c):c=this._pattern;c&&(b.fillStyle=c,b.fillRect(this.visible_area[0],this.visible_area[1],this.visible_area[2],this.visible_area[3]),b.fillStyle="transparent");b.globalAlpha=1;b.imageSmoothingEnabled=b.imageSmoothingEnabled=!0}this.graph._groups.length&&!this.live_mode&&this.drawGroups(a,b);if(this.onDrawBackground)this.onDrawBackground(b,this.visible_area);
|
||||
this.onBackgroundRender&&(console.error("WARNING! onBackgroundRender deprecated, now is named onDrawBackground "),this.onBackgroundRender=null);this.render_canvas_border&&(b.strokeStyle="#235",b.strokeRect(0,0,a.width,a.height));this.render_connections_shadows?(b.shadowColor="#000",b.shadowOffsetX=0,b.shadowOffsetY=0,b.shadowBlur=6):b.shadowColor="rgba(0,0,0,0)";this.live_mode||this.drawConnections(b);b.shadowColor="rgba(0,0,0,0)";b.restore()}b.finish&&b.finish();this.dirty_bgcanvas=!1;this.dirty_canvas=
|
||||
!0};var B=new Float32Array(2);m.prototype.drawNode=function(a,b){this.current_node=a;var c=a.color||a.constructor.color||g.NODE_DEFAULT_COLOR,d=a.bgcolor||a.constructor.bgcolor||g.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=g.DEFAULT_SHADOW_COLOR,b.shadowOffsetX=2*this.ds.scale,b.shadowOffsetY=
|
||||
2*this.ds.scale,b.shadowBlur=3*this.ds.scale):b.shadowColor="transparent";if(!a.flags.collapsed||!a.onDrawCollapsed||1!=a.onDrawCollapsed(b,this)){var h=a._shape||g.BOX_SHAPE;B.set(a.size);var k=a.horizontal;if(a.flags.collapsed){b.font=this.inner_text_font;var n=a.getTitle?a.getTitle():a.title;null!=n&&(a._collapsed_width=Math.min(a.size[0],b.measureText(n).width+2*g.NODE_TITLE_HEIGHT),B[0]=a._collapsed_width,B[1]=0)}a.clip_area&&(b.save(),b.beginPath(),h==g.BOX_SHAPE?b.rect(0,0,B[0],B[1]):h==g.ROUND_SHAPE?
|
||||
b.roundRect(0,0,B[0],B[1],[10]):h==g.CIRCLE_SHAPE&&b.arc(.5*B[0],.5*B[1],.5*B[0],0,2*Math.PI),b.clip());a.has_errors&&(d="red");this.drawNodeShape(a,b,B,c,d,a.is_selected,a.mouseOver);b.shadowColor="transparent";if(a.onDrawForeground)a.onDrawForeground(b,this,this.canvas);b.textAlign=k?"center":"left";b.font=this.inner_text_font;d=!e;var q=this.connecting_output;h=this.connecting_input;b.lineWidth=1;n=0;var u=new Float32Array(2);if(!a.flags.collapsed){if(a.inputs)for(c=0;c<a.inputs.length;c++){var r=
|
||||
a.inputs[c],m=r.type,l=r.shape;b.globalAlpha=f;this.connecting_output&&!g.isValidConnection(r.type,q.type)&&(b.globalAlpha=.4*f);b.fillStyle=null!=r.link?r.color_on||this.default_connection_color_byType[m]||this.default_connection_color.input_on:r.color_off||this.default_connection_color_byTypeOff[m]||this.default_connection_color_byType[m]||this.default_connection_color.input_off;var t=a.getConnectionPos(!0,c,u);t[0]-=a.pos[0];t[1]-=a.pos[1];n<t[1]+.5*g.NODE_SLOT_HEIGHT&&(n=t[1]+.5*g.NODE_SLOT_HEIGHT);
|
||||
b.beginPath();"array"==m&&(l=g.GRID_SHAPE);r.type===g.EVENT||r.shape===g.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):l===g.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()):l===g.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&&(m=null!=r.label?r.label:r.name)&&(b.fillStyle=g.NODE_TEXT_COLOR,k||r.dir==g.UP?b.fillText(m,t[0],t[1]-10):b.fillText(m,t[0]+10,t[1]+5))}b.textAlign=k?"center":"right";b.strokeStyle="black";if(a.outputs)for(c=0;c<a.outputs.length;c++)if(r=a.outputs[c],m=r.type,l=r.shape,this.connecting_input&&!g.isValidConnection(m,h.type)&&(b.globalAlpha=.4*f),t=a.getConnectionPos(!1,c,u),t[0]-=a.pos[0],t[1]-=a.pos[1],n<t[1]+.5*
|
||||
g.NODE_SLOT_HEIGHT&&(n=t[1]+.5*g.NODE_SLOT_HEIGHT),b.fillStyle=r.links&&r.links.length?r.color_on||this.default_connection_color_byType[m]||this.default_connection_color.output_on:r.color_off||this.default_connection_color_byTypeOff[m]||this.default_connection_color_byType[m]||this.default_connection_color.output_off,b.beginPath(),"array"==m&&(l=g.GRID_SHAPE),q=!0,m===g.EVENT||l===g.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):l===g.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()):l===g.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),q=!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&&q&&b.stroke(),d&&(m=null!=r.label?r.label:r.name))b.fillStyle=g.NODE_TEXT_COLOR,k||r.dir==g.DOWN?
|
||||
b.fillText(m,t[0],t[1]-8):b.fillText(m,t[0]-10,t[1]+5);b.textAlign="left";b.globalAlpha=1;if(a.widgets){r=n;if(k||a.widgets_up)r=2;null!=a.widgets_start_y&&(r=a.widgets_start_y);this.drawNodeWidgets(a,r,b,this.node_widget&&this.node_widget[0]==a?this.node_widget[1]:null)}}else if(this.render_collapsed_slots){e=f=null;if(a.inputs)for(c=0;c<a.inputs.length;c++)if(r=a.inputs[c],null!=r.link){f=r;break}if(a.outputs)for(c=0;c<a.outputs.length;c++)r=a.outputs[c],r.links&&r.links.length&&(e=r);f&&(f=0,c=
|
||||
-.5*g.NODE_TITLE_HEIGHT,k&&(f=.5*a._collapsed_width,c=-g.NODE_TITLE_HEIGHT),b.fillStyle="#686",b.beginPath(),r.type===g.EVENT||r.shape===g.BOX_SHAPE?b.rect(f-7+.5,c-4,14,8):r.shape===g.ARROW_SHAPE?(b.moveTo(f+8,c),b.lineTo(f+-4,c-4),b.lineTo(f+-4,c+4),b.closePath()):b.arc(f,c,4,0,2*Math.PI),b.fill());e&&(f=a._collapsed_width,c=-.5*g.NODE_TITLE_HEIGHT,k&&(f=.5*a._collapsed_width,c=0),b.fillStyle="#686",b.strokeStyle="black",b.beginPath(),r.type===g.EVENT||r.shape===g.BOX_SHAPE?b.rect(f-7+.5,c-4,14,
|
||||
8):r.shape===g.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}}};m.prototype.drawLinkTooltip=function(a,b){var c=b._pos;a.fillStyle="black";a.beginPath();a.arc(c[0],c[1],3,0,2*Math.PI);a.fill();if(null!=b.data&&(!this.onDrawLinkTooltip||1!=this.onDrawLinkTooltip(a,b,this))&&(b=b.data,b=b.constructor===Number?b.toFixed(2):b.constructor===String?'"'+b+'"':b.constructor===Boolean?String(b):b.toToolTip?
|
||||
b.toToolTip():"["+b.constructor.name+"]",null!=b)){b=b.substr(0,30);a.font="14px Courier New";var d=a.measureText(b).width+20;a.shadowColor="black";a.shadowOffsetX=2;a.shadowOffsetY=2;a.shadowBlur=3;a.fillStyle="#454";a.beginPath();a.roundRect(c[0]-.5*d,c[1]-15-24,d,24,[3]);a.moveTo(c[0]-10,c[1]-15);a.lineTo(c[0]+10,c[1]-15);a.lineTo(c[0],c[1]-5);a.fill();a.shadowColor="transparent";a.textAlign="center";a.fillStyle="#CEC";a.fillText(b,c[0],c[1]-15-24*.3)}};var y=new Float32Array(4);m.prototype.drawNodeShape=
|
||||
function(a,b,c,d,e,f,h){b.strokeStyle=d;b.fillStyle=e;e=g.NODE_TITLE_HEIGHT;var k=.5>this.ds.scale,n=a._shape||a.constructor.shape||g.ROUND_SHAPE,q=a.constructor.title_mode,u=!0;q==g.TRANSPARENT_TITLE||q==g.NO_TITLE?u=!1:q==g.AUTOHIDE_TITLE&&h&&(u=!0);y[0]=0;y[1]=u?-e:0;y[2]=c[0]+1;y[3]=u?c[1]+e:c[1];h=b.globalAlpha;b.beginPath();n==g.BOX_SHAPE||k?b.fillRect(y[0],y[1],y[2],y[3]):n==g.ROUND_SHAPE||n==g.CARD_SHAPE?b.roundRect(y[0],y[1],y[2],y[3],n==g.CARD_SHAPE?[this.round_radius,this.round_radius,
|
||||
0,0]:[this.round_radius]):n==g.CIRCLE_SHAPE&&b.arc(.5*c[0],.5*c[1],.5*c[0],0,2*Math.PI);b.fill();!a.flags.collapsed&&u&&(b.shadowColor="transparent",b.fillStyle="rgba(0,0,0,0.2)",b.fillRect(0,-1,y[2],2));b.shadowColor="transparent";if(a.onDrawBackground)a.onDrawBackground(b,this,this.canvas,this.graph_mouse);if(u||q==g.TRANSPARENT_TITLE){if(a.onDrawTitleBar)a.onDrawTitleBar(b,e,c,this.ds.scale,d);else if(q!=g.TRANSPARENT_TITLE&&(a.constructor.title_color||this.render_title_colored)){u=a.constructor.title_color||
|
||||
d;a.flags.collapsed&&(b.shadowColor=g.DEFAULT_SHADOW_COLOR);if(this.use_gradients){var r=m.gradients[u];r||(r=m.gradients[u]=b.createLinearGradient(0,0,400,0),r.addColorStop(0,u),r.addColorStop(1,"#000"));b.fillStyle=r}else b.fillStyle=u;b.beginPath();n==g.BOX_SHAPE||k?b.rect(0,-e,c[0]+1,e):(n==g.ROUND_SHAPE||n==g.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"}u=!1;g.node_box_coloured_by_mode&&
|
||||
g.NODE_MODES_COLORS[a.mode]&&(u=g.NODE_MODES_COLORS[a.mode]);g.node_box_coloured_when_on&&(u=a.action_triggered?"#FFF":a.execute_triggered?"#AAA":u);if(a.onDrawTitleBox)a.onDrawTitleBox(b,e,c,this.ds.scale);else n==g.ROUND_SHAPE||n==g.CIRCLE_SHAPE||n==g.CARD_SHAPE?(k&&(b.fillStyle="black",b.beginPath(),b.arc(.5*e,-.5*e,6,0,2*Math.PI),b.fill()),b.fillStyle=a.boxcolor||u||g.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||u||g.NODE_DEFAULT_BOXCOLOR,b.fillRect(.5*(e-10),-.5*(e+10),10,10));b.globalAlpha=h;if(a.onDrawTitleText)a.onDrawTitleText(b,e,c,this.ds.scale,this.title_text_font,f);!k&&(b.font=this.title_text_font,h=String(a.getTitle()))&&(b.fillStyle=f?g.NODE_SELECTED_TITLE_COLOR:a.constructor.title_text_color||this.node_title_color,a.flags.collapsed?(b.textAlign="left",b.measureText(h),b.fillText(h.substr(0,20),e,g.NODE_TITLE_TEXT_Y-e),
|
||||
b.textAlign="left"):(b.textAlign="left",b.fillText(h,e,g.NODE_TITLE_TEXT_Y-e)));a.flags.collapsed||!a.subgraph||a.skip_subgraph_button||(h=g.NODE_TITLE_HEIGHT,u=a.size[0]-h,r=g.isInsideRectangle(this.graph_mouse[0]-a.pos[0],this.graph_mouse[1]-a.pos[1],u+2,-h+2,h-4,h-4),b.fillStyle=r?"#888":"#555",n==g.BOX_SHAPE||k?b.fillRect(u+2,-h+2,h-4,h-4):(b.beginPath(),b.roundRect(u+2,-h+2,h-4,h-4,[4]),b.fill()),b.fillStyle="#333",b.beginPath(),b.moveTo(u+.2*h,.6*-h),b.lineTo(u+.8*h,.6*-h),b.lineTo(u+.5*h,.3*
|
||||
-h),b.fill());if(a.onDrawTitle)a.onDrawTitle(b)}if(f){if(a.onBounding)a.onBounding(y);q==g.TRANSPARENT_TITLE&&(y[1]-=e,y[3]+=e);b.lineWidth=1;b.globalAlpha=.8;b.beginPath();n==g.BOX_SHAPE?b.rect(-6+y[0],-6+y[1],12+y[2],12+y[3]):n==g.ROUND_SHAPE||n==g.CARD_SHAPE&&a.flags.collapsed?b.roundRect(-6+y[0],-6+y[1],12+y[2],12+y[3],[2*this.round_radius]):n==g.CARD_SHAPE?b.roundRect(-6+y[0],-6+y[1],12+y[2],12+y[3],[2*this.round_radius,2,2*this.round_radius,2]):n==g.CIRCLE_SHAPE&&b.arc(.5*c[0],.5*c[1],.5*c[0]+
|
||||
6,0,2*Math.PI);b.strokeStyle=g.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 G=new Float32Array(4),A=new Float32Array(4),J=new Float32Array(2),K=new Float32Array(2);m.prototype.drawConnections=function(a){var b=g.getTime(),c=this.visible_area;G[0]=c[0]-20;G[1]=c[1]-20;G[2]=c[2]+40;G[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 h=0;h<f.inputs.length;++h){var k=f.inputs[h];if(k&&null!=k.link&&(k=this.graph.links[k.link])){var n=this.graph.getNodeById(k.origin_id);if(null!=n){var q=k.origin_slot;var u=-1==q?[n.pos[0]+10,n.pos[1]+10]:n.getConnectionPos(!1,q,J);var r=f.getConnectionPos(!0,h,K);A[0]=u[0];A[1]=u[1];A[2]=r[0]-u[0];A[3]=r[1]-u[1];0>A[2]&&(A[0]+=A[2],A[2]=Math.abs(A[2]));0>A[3]&&(A[1]+=A[3],A[3]=Math.abs(A[3]));if(F(A,
|
||||
G)){var m=n.outputs[q];q=f.inputs[h];if(m&&q&&(n=m.dir||(n.horizontal?g.DOWN:g.RIGHT),q=q.dir||(f.horizontal?g.UP:g.LEFT),this.renderLink(a,u,r,k,!1,0,null,n,q),k&&k._last_time&&1E3>b-k._last_time)){m=2-.002*(b-k._last_time);var l=a.globalAlpha;a.globalAlpha=l*m;this.renderLink(a,u,r,k,!0,m,"white",n,q);a.globalAlpha=l}}}}}}a.globalAlpha=1};m.prototype.renderLink=function(a,b,c,d,e,f,h,k,n,q){d&&this.visible_links.push(d);!h&&d&&(h=d.color||m.link_type_colors[d.type]);h||(h=this.default_link_color);
|
||||
null!=d&&this.highlighted_links[d.id]&&(h="#FFF");k=k||g.RIGHT;n=n||g.LEFT;var u=H(b,c);this.render_connections_border&&.6<this.ds.scale&&(a.lineWidth=this.connections_width+4);a.lineJoin="round";q=q||1;1<q&&(a.lineWidth=.5);a.beginPath();for(var r=0;r<q;r+=1){var l=5*(r-.5*(q-1));if(this.links_render_mode==g.SPLINE_LINK){a.moveTo(b[0],b[1]+l);var p=0,t=0,v=0,w=0;switch(k){case g.LEFT:p=-.25*u;break;case g.RIGHT:p=.25*u;break;case g.UP:t=-.25*u;break;case g.DOWN:t=.25*u}switch(n){case g.LEFT:v=-.25*
|
||||
u;break;case g.RIGHT:v=.25*u;break;case g.UP:w=-.25*u;break;case g.DOWN:w=.25*u}a.bezierCurveTo(b[0]+p,b[1]+t+l,c[0]+v,c[1]+w+l,c[0],c[1]+l)}else if(this.links_render_mode==g.LINEAR_LINK){a.moveTo(b[0],b[1]+l);w=v=t=p=0;switch(k){case g.LEFT:p=-1;break;case g.RIGHT:p=1;break;case g.UP:t=-1;break;case g.DOWN:t=1}switch(n){case g.LEFT:v=-1;break;case g.RIGHT:v=1;break;case g.UP:w=-1;break;case g.DOWN:w=1}a.lineTo(b[0]+15*p,b[1]+15*t+l);a.lineTo(c[0]+15*v,c[1]+15*w+l);a.lineTo(c[0],c[1]+l)}else if(this.links_render_mode==
|
||||
g.STRAIGHT_LINK)a.moveTo(b[0],b[1]),l=b[0],p=b[1],t=c[0],v=c[1],k==g.RIGHT?l+=10:p+=10,n==g.LEFT?t-=10:v-=10,a.lineTo(l,p),a.lineTo(.5*(l+t),p),a.lineTo(.5*(l+t),v),a.lineTo(t,v),a.lineTo(c[0],c[1]);else return}this.render_connections_border&&.6<this.ds.scale&&!e&&(a.strokeStyle="rgba(0,0,0,0.5)",a.stroke());a.lineWidth=this.connections_width;a.fillStyle=a.strokeStyle=h;a.stroke();e=this.computeConnectionPoint(b,c,.5,k,n);d&&d._pos&&(d._pos[0]=e[0],d._pos[1]=e[1]);.6<=this.ds.scale&&this.highquality_render&&
|
||||
n!=g.CENTER&&(this.render_connection_arrows&&(r=this.computeConnectionPoint(b,c,.25,k,n),u=this.computeConnectionPoint(b,c,.26,k,n),d=this.computeConnectionPoint(b,c,.75,k,n),q=this.computeConnectionPoint(b,c,.76,k,n),this.render_curved_connections?(u=-Math.atan2(u[0]-r[0],u[1]-r[1]),q=-Math.atan2(q[0]-d[0],q[1]-d[1])):q=u=c[1]>b[1]?0:Math.PI,a.save(),a.translate(r[0],r[1]),a.rotate(u),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore(),a.save(),a.translate(d[0],d[1]),
|
||||
a.rotate(q),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=h,r=0;5>r;++r)f=(.001*g.getTime()+.2*r)%1,e=this.computeConnectionPoint(b,c,f,k,n),a.beginPath(),a.arc(e[0],e[1],5,0,2*Math.PI),a.fill()};m.prototype.computeConnectionPoint=function(a,b,c,d,e){d=d||g.RIGHT;e=e||g.LEFT;var f=H(a,b),h=[a[0],a[1]],k=[b[0],b[1]];switch(d){case g.LEFT:h[0]+=-.25*f;break;case g.RIGHT:h[0]+=.25*f;break;case g.UP:h[1]+=
|
||||
-.25*f;break;case g.DOWN:h[1]+=.25*f}switch(e){case g.LEFT:k[0]+=-.25*f;break;case g.RIGHT:k[0]+=.25*f;break;case g.UP:k[1]+=-.25*f;break;case g.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]+e*h[0]+f*k[0]+c*b[0],d*a[1]+e*h[1]+f*k[1]+c*b[1]]};m.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]-g.NODE_TITLE_HEIGHT,d.pos[1]-g.NODE_TITLE_HEIGHT,g.NODE_TITLE_HEIGHT,g.NODE_TITLE_HEIGHT);0==d.order&&a.strokeRect(d.pos[0]-g.NODE_TITLE_HEIGHT+.5,d.pos[1]-g.NODE_TITLE_HEIGHT+.5,g.NODE_TITLE_HEIGHT,g.NODE_TITLE_HEIGHT);a.fillStyle="#FFF";a.fillText(d.order,d.pos[0]+-.5*g.NODE_TITLE_HEIGHT,d.pos[1]-6)}a.globalAlpha=1};m.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 h=g.NODE_WIDGET_HEIGHT,k=.5<
|
||||
this.ds.scale;c.save();c.globalAlpha=this.editor_alpha;for(var n=g.WIDGET_OUTLINE_COLOR,q=g.WIDGET_BGCOLOR,u=g.WIDGET_TEXT_COLOR,r=g.WIDGET_SECONDARY_TEXT_COLOR,m=0;m<f.length;++m){var l=f[m],t=b;l.y&&(t=l.y);l.last_y=t;c.strokeStyle=n;c.fillStyle="#222";c.textAlign="left";l.disabled&&(c.globalAlpha*=.5);var p=l.width||e;switch(l.type){case "button":l.clicked&&(c.fillStyle="#AAA",l.clicked=!1,this.dirty_canvas=!0);c.fillRect(15,t,p-30,h);k&&!l.disabled&&c.strokeRect(15,t,p-30,h);k&&(c.textAlign="center",
|
||||
c.fillStyle=u,c.fillText(l.name,.5*p,t+.7*h));break;case "toggle":c.textAlign="left";c.strokeStyle=n;c.fillStyle=q;c.beginPath();k?c.roundRect(15,t,p-30,h,[.5*h]):c.rect(15,t,p-30,h);c.fill();k&&!l.disabled&&c.stroke();c.fillStyle=l.value?"#89A":"#333";c.beginPath();c.arc(p-30,t+.5*h,.36*h,0,2*Math.PI);c.fill();k&&(c.fillStyle=r,null!=l.name&&c.fillText(l.name,30,t+.7*h),c.fillStyle=l.value?u:r,c.textAlign="right",c.fillText(l.value?l.options.on||"true":l.options.off||"false",p-40,t+.7*h));break;
|
||||
case "slider":c.fillStyle=q;c.fillRect(15,t,p-30,h);var v=l.options.max-l.options.min,w=(l.value-l.options.min)/v;c.fillStyle=d==l?"#89A":"#678";c.fillRect(15,t,w*(p-30),h);k&&!l.disabled&&c.strokeRect(15,t,p-30,h);l.marker&&(v=(l.marker-l.options.min)/v,c.fillStyle="#AA9",c.fillRect(15+v*(p-30),t,2,h));k&&(c.textAlign="center",c.fillStyle=u,c.fillText(l.name+" "+Number(l.value).toFixed(3),.5*p,t+.7*h));break;case "number":case "combo":c.textAlign="left";c.strokeStyle=n;c.fillStyle=q;c.beginPath();
|
||||
k?c.roundRect(15,t,p-30,h,[.5*h]):c.rect(15,t,p-30,h);c.fill();k&&(l.disabled||c.stroke(),c.fillStyle=u,l.disabled||(c.beginPath(),c.moveTo(31,t+5),c.lineTo(21,t+.5*h),c.lineTo(31,t+h-5),c.fill(),c.beginPath(),c.moveTo(p-15-16,t+5),c.lineTo(p-15-6,t+.5*h),c.lineTo(p-15-16,t+h-5),c.fill()),c.fillStyle=r,c.fillText(l.name,35,t+.7*h),c.fillStyle=u,c.textAlign="right","number"==l.type?c.fillText(Number(l.value).toFixed(void 0!==l.options.precision?l.options.precision:3),p-30-20,t+.7*h):(v=l.value,l.options.values&&
|
||||
(w=l.options.values,w.constructor===Function&&(w=w()),w&&w.constructor!==Array&&(v=w[l.value])),c.fillText(v,p-30-20,t+.7*h)));break;case "string":case "text":c.textAlign="left";c.strokeStyle=n;c.fillStyle=q;c.beginPath();k?c.roundRect(15,t,p-30,h,[.5*h]):c.rect(15,t,p-30,h);c.fill();k&&(l.disabled||c.stroke(),c.save(),c.beginPath(),c.rect(15,t,p-30,h),c.clip(),c.fillStyle=r,null!=l.name&&c.fillText(l.name,30,t+.7*h),c.fillStyle=u,c.textAlign="right",c.fillText(String(l.value).substr(0,30),p-30,t+
|
||||
.7*h),c.restore());break;default:l.draw&&l.draw(c,a,p,t,h)}b+=(l.computeSize?l.computeSize(p)[1]:h)+4;c.globalAlpha=this.editor_alpha}c.restore();c.textAlign="left"};m.prototype.processNodeWidgets=function(a,b,c,d){function e(d,e){d.value=e;d.options&&d.options.property&&void 0!==a.properties[d.options.property]&&a.setProperty(d.options.property,e);d.callback&&d.callback(d.value,n,a,b,c)}if(!a.widgets||!a.widgets.length)return null;for(var f=b[0]-a.pos[0],h=b[1]-a.pos[1],k=a.size[0],n=this,q=this.getCanvasWindow(),
|
||||
u=0;u<a.widgets.length;++u){var r=a.widgets[u];if(r&&!r.disabled){var m=r.computeSize?r.computeSize(k)[1]:g.NODE_WIDGET_HEIGHT,l=r.width||k;if(r==d||!(6>f||f>l-12||h<r.last_y||h>r.last_y+m||void 0===r.last_y)){d=r.value;switch(r.type){case "button":c.type===g.pointerevents_method+"down"&&(r.callback&&setTimeout(function(){r.callback(r,n,a,b,c)},20),this.dirty_canvas=r.clicked=!0);break;case "slider":q=Math.clamp((f-15)/(l-30),0,1);r.value=r.options.min+(r.options.max-r.options.min)*q;r.callback&&
|
||||
setTimeout(function(){e(r,r.value)},20);this.dirty_canvas=!0;break;case "number":case "combo":d=r.value;if(c.type==g.pointerevents_method+"move"&&"number"==r.type)r.value+=.1*c.deltaX*(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==g.pointerevents_method+"down"){var t=r.options.values;t&&t.constructor===Function&&(t=r.options.values(r,a));var p=null;"number"!=r.type&&(p=t.constructor===
|
||||
Array?t:Object.keys(t));f=40>f?-1:f>l-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)q=-1,this.last_mouseclick=0,q=t.constructor===Object?p.indexOf(String(r.value))+f:p.indexOf(r.value)+f,q>=p.length&&(q=p.length-1),0>q&&(q=0),r.value=t.constructor===Array?t[q]:q;else{var v=t!=p?Object.values(t):t;new g.ContextMenu(v,{scale:Math.max(1,this.ds.scale),
|
||||
event:c,className:"dark",callback:function(a,b,c){t!=p&&(a=v.indexOf(a));this.value=a;e(this,a);n.dirty_canvas=!0;return!1}.bind(r)},q)}}else c.type==g.pointerevents_method+"up"&&"number"==r.type&&(f=40>f?-1:f>l-40?1:0,200>c.click_time&&0==f&&this.prompt("Value",r.value,function(a){this.value=Number(a);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==g.pointerevents_method+"down"&&(r.value=!r.value,setTimeout(function(){e(r,
|
||||
r.value)},20));break;case "string":case "text":c.type==g.pointerevents_method+"down"&&this.prompt("Value",r.value,function(a){this.value=a;e(this,a)}.bind(r),c,r.options?r.options.multiline:!1);break;default:r.mouse&&(this.dirty_canvas=r.mouse(c,[f,h],a))}if(d!=r.value){if(a.onWidgetChanged)a.onWidgetChanged(r.name,r.value,d,r);a.graph._version++}return r}}}return null};m.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(F(this.visible_area,d._bounding)){b.fillStyle=d.color||"#335";b.strokeStyle=d.color||"#335";var e=d._pos,f=d._size;b.globalAlpha=.25*this.editor_alpha;b.beginPath();b.rect(e[0]+.5,e[1]+.5,f[0],f[1]);b.fill();b.globalAlpha=this.editor_alpha;b.stroke();b.beginPath();b.moveTo(e[0]+f[0],e[1]+f[1]);b.lineTo(e[0]+f[0]-10,e[1]+f[1]);b.lineTo(e[0]+f[0],e[1]+f[1]-10);b.fill();f=d.font_size||g.DEFAULT_GROUP_FONT_SIZE;b.font=f+"px Arial";b.textAlign="left";b.fillText(d.title,e[0]+
|
||||
4,e[1]+f)}}b.restore()}};m.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)};m.prototype.resize=function(a,b){a||b||(b=this.canvas.parentNode,a=b.offsetWidth,b=b.offsetHeight);if(this.canvas.width!=a||this.canvas.height!=b)this.canvas.width=a,this.canvas.height=b,this.bgcanvas.width=this.canvas.width,this.bgcanvas.height=this.canvas.height,this.setDirty(!0,!0)};m.prototype.switchLiveMode=function(a){if(a){var b=this,
|
||||
c=this.live_mode?1.1:.9;this.live_mode&&(this.live_mode=!1,this.editor_alpha=.1);var d=setInterval(function(){b.editor_alpha*=c;b.dirty_canvas=!0;b.dirty_bgcanvas=!0;1>c&&.01>b.editor_alpha&&(clearInterval(d),1>c&&(b.live_mode=!0));1<c&&.99<b.editor_alpha&&(clearInterval(d),b.editor_alpha=1)},1)}else this.live_mode=!this.live_mode,this.dirty_bgcanvas=this.dirty_canvas=!0};m.prototype.onNodeSelectionChange=function(a){};m.onGroupAdd=function(a,b,c){a=m.active_canvas;a.getCanvasWindow();b=new g.LGraphGroup;
|
||||
b.pos=a.convertEventToCanvasOffset(c);a.graph.add(b)};m.onMenuAdd=function(a,b,c,d,e){function f(a,b){var d=[];g.getNodeTypesCategories(h.filter||n.filter).filter(function(b){return b.startsWith(a)}).map(function(b){if(b){b=b.replace(new RegExp("^("+a+")"),"").split("/")[0];var c=""===a?b+"/":a+b+"/";-1!=b.indexOf("::")&&(b=b.split("::")[1]);-1===d.findIndex(function(a){return a.value===c})&&d.push({value:c,content:b,has_submenu:!0,callback:function(a,b,c,d){f(a.value,d)}})}});g.getNodeTypesInCategory(a.slice(0,
|
||||
-1),h.filter||n.filter).map(function(a){a.skip_list||d.push({value:a.type,content:a.title,has_submenu:!1,callback:function(a,b,c,d){b=d.getFirstEvent();h.graph.beforeChange();if(a=g.createNode(a.value))a.pos=h.convertEventToCanvasOffset(b),h.graph.add(a);e&&e(a);h.graph.afterChange()}})});new g.ContextMenu(d,{event:c,parentMenu:b},k)}var h=m.active_canvas,k=h.getCanvasWindow(),n=h.graph;if(n)return f("",d),!1};m.onMenuCollapseAll=function(){};m.onMenuNodeEdit=function(){};m.showMenuNodeOptionalInputs=
|
||||
function(a,b,c,d,e){if(e){var f=this;a=m.active_canvas.getCanvasWindow();b=e.optional_inputs;e.onGetInputs&&(b=e.onGetInputs());var h=[];if(b)for(var k=0;k<b.length;k++){var n=b[k];if(n){var q=n[0];n[2]||(n[2]={});n[2].label&&(q=n[2].label);n[2].removable=!0;q={content:q,value:n};n[1]==g.ACTION&&(q.className="event");h.push(q)}else h.push(null)}e.onMenuNodeInputs&&(b=e.onMenuNodeInputs(h))&&(h=b);if(h.length)return new g.ContextMenu(h,{event:c,callback:function(a,b,c){if(e&&(a.callback&&a.callback.call(f,
|
||||
e,a,b,c),a.value)){e.graph.beforeChange();e.addInput(a.value[0],a.value[1],a.value[2]);if(e.onNodeInputAdd)e.onNodeInputAdd(a.value);e.setDirtyCanvas(!0,!0);e.graph.afterChange()}},parentMenu:d,node:e},a),!1;console.log("no input entries")}};m.showMenuNodeOptionalOutputs=function(a,b,c,d,e){function f(a,b,c){if(e&&(a.callback&&a.callback.call(h,e,a,b,c),a.value))if(c=a.value[1],!c||c.constructor!==Object&&c.constructor!==Array){e.graph.beforeChange();e.addOutput(a.value[0],a.value[1],a.value[2]);
|
||||
if(e.onNodeOutputAdd)e.onNodeOutputAdd(a.value);e.setDirtyCanvas(!0,!0);e.graph.afterChange()}else{a=[];for(var k in c)a.push({content:k,value:c[k]});new g.ContextMenu(a,{event:b,callback:f,parentMenu:d,node:e});return!1}}if(e){var h=this;a=m.active_canvas.getCanvasWindow();b=e.optional_outputs;e.onGetOutputs&&(b=e.onGetOutputs());var k=[];if(b)for(var n=0;n<b.length;n++){var q=b[n];if(!q)k.push(null);else if(!e.flags||!e.flags.skip_repeated_outputs||-1==e.findOutputSlot(q[0])){var u=q[0];q[2]||(q[2]=
|
||||
{});q[2].label&&(u=q[2].label);q[2].removable=!0;u={content:u,value:q};q[1]==g.EVENT&&(u.className="event");k.push(u)}}this.onMenuNodeOutputs&&(k=this.onMenuNodeOutputs(k));g.do_add_triggers_slots&&-1==e.findOutputSlot("onExecuted")&&k.push({content:"On Executed",value:["onExecuted",g.EVENT,{nameLocked:!0}],className:"event"});e.onMenuNodeOutputs&&(b=e.onMenuNodeOutputs(k))&&(k=b);if(k.length)return new g.ContextMenu(k,{event:c,callback:f,parentMenu:d,node:e},a),!1}};m.onShowMenuNodeProperties=function(a,
|
||||
b,c,d,e){if(e&&e.properties){var f=m.active_canvas;b=f.getCanvasWindow();var h=[],k;for(k in e.properties){a=void 0!==e.properties[k]?e.properties[k]:" ";"object"==typeof a&&(a=JSON.stringify(a));var n=e.getPropertyInfo(k);if("enum"==n.type||"combo"==n.type)a=m.getPropertyPrintableValue(a,n.values);a=m.decodeHTML(a);h.push({content:"<span class='property_name'>"+(n.label?n.label:k)+"</span><span class='property_value'>"+a+"</span>",value:k})}if(h.length)return new g.ContextMenu(h,{event:c,callback:function(a,
|
||||
b,c,d){e&&(b=this.getBoundingClientRect(),f.showEditPropertyValue(e,a.value,{position:[b.left,b.top]}))},parentMenu:d,allow_html:!0,node:e},b),!1}};m.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};m.onMenuResizeNode=function(a,b,c,d,e){if(e){a=function(a){a.size=a.computeSize();if(a.onResize)a.onResize(a.size)};b=m.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)}};m.prototype.showLinkMenu=function(a,b){var c=this,d=c.graph.getNodeById(a.origin_id),e=c.graph.getNodeById(a.target_id),f=!1;d&&d.outputs&&d.outputs[a.origin_slot]&&(f=d.outputs[a.origin_slot].type);var h=!1;e&&e.outputs&&e.outputs[a.target_slot]&&(h=e.inputs[a.target_slot].type);var k=new g.ContextMenu(["Add Node",null,"Delete",null],{event:b,title:null!=a.data?a.data.constructor.name:null,callback:function(b,g,u){switch(b){case "Add Node":m.onMenuAdd(null,null,u,k,function(b){b.inputs&&
|
||||
b.inputs.length&&b.outputs&&b.outputs.length&&d.connectByType(a.origin_slot,b,f)&&(b.connectByType(a.target_slot,e,h),b.pos[0]-=.5*b.size[0])});break;case "Delete":c.graph.removeLink(a.id)}}});return!1};m.prototype.createDefaultNodeForSlot=function(a){a=a||{};a=Object.assign({nodeFrom:null,slotFrom:null,nodeTo:null,slotTo:null,position:[],nodeType:null,posAdd:[0,0],posSizeFix:[0,0]},a);var b=a.nodeFrom&&null!==a.slotFrom,c=!b&&a.nodeTo&&null!==a.slotTo;if(!b&&!c)return console.warn("No data passed to createDefaultNodeForSlot "+
|
||||
a.nodeFrom+" "+a.slotFrom+" "+a.nodeTo+" "+a.slotTo),!1;if(!a.nodeType)return console.warn("No type to createDefaultNodeForSlot"),!1;var 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!==
|
||||
@@ -271,21 +271,21 @@ f);b.parentNode.appendChild(k);n&&n.focus();var l=null;k.addEventListener("mouse
|
||||
"<span class='name'></span> <input autofocus type='text' class='value'/><button class='rounded'>OK</button>";h.close=function(){f.prompt_box=null;h.parentNode&&h.parentNode.removeChild(h)};e=m.active_canvas.canvas;e.parentNode.appendChild(h);1<this.ds.scale&&(h.style.transform="scale("+this.ds.scale+")");var k=null,n=!1;g.pointerListenerAdd(h,"leave",function(a){n||g.dialog_close_on_mouse_leave&&!h.is_modified&&g.dialog_close_on_mouse_leave&&(k=setTimeout(h.close,g.dialog_close_on_mouse_leave_delay))});
|
||||
g.pointerListenerAdd(h,"enter",function(a){g.dialog_close_on_mouse_leave&&k&&clearTimeout(k)});var q=h.querySelectorAll("select");q&&q.forEach(function(a){a.addEventListener("click",function(a){n++});a.addEventListener("blur",function(a){n=0});a.addEventListener("change",function(a){n=-1})});f.prompt_box&&f.prompt_box.close();f.prompt_box=h;h.querySelector(".name").innerText=a;var l=h.querySelector(".value");l.value=b;l.addEventListener("keydown",function(a){h.is_modified=!0;if(27==a.keyCode)h.close();
|
||||
else if(13==a.keyCode&&"textarea"!=a.target.localName)c&&c(this.value),h.close();else return;a.preventDefault();a.stopPropagation()});h.querySelector("button").addEventListener("click",function(a){c&&c(l.value);f.setDirty(!0);h.close()});a=e.getBoundingClientRect();q=b=-20;a&&(b-=a.left,q-=a.top);d?(h.style.left=d.clientX+b+"px",h.style.top=d.clientY+q+"px"):(h.style.left=.5*e.width+b+"px",h.style.top=.5*e.height+q+"px");setTimeout(function(){l.focus()},10);return h};m.search_limit=-1;m.prototype.showSearchBox=
|
||||
function(a,b){function c(c){if(c)if(f.onSearchBoxSelection)f.onSearchBoxSelection(c,a,h);else{var e=g.searchbox_extras[c.toLowerCase()];e&&(c=e.type);h.graph.beforeChange();if(c=g.createNode(c))c.pos=h.convertEventToCanvasOffset(a),h.graph.add(c,!1);if(e&&e.data){if(e.data.properties)for(var d in e.data.properties)c.addProperty(d,e.data.properties[d]);if(e.data.inputs)for(d in c.inputs=[],e.data.inputs)c.addOutput(e.data.inputs[d][0],e.data.inputs[d][1]);if(e.data.outputs)for(d in c.outputs=[],e.data.outputs)c.addOutput(e.data.outputs[d][0],
|
||||
e.data.outputs[d][1]);e.data.title&&(c.title=e.data.title);e.data.json&&c.configure(e.data.json)}if(b.node_from){switch(typeof b.slot_from){case "string":e=b.node_from.findOutputSlot(b.slot_from);break;case "object":e=b.slot_from.name?b.node_from.findOutputSlot(b.slot_from.name):-1;-1==e&&"undefined"!==typeof b.slot_from.slot_index&&(e=b.slot_from.slot_index);break;case "number":e=b.slot_from;break;default:e=0}!1!==e&&-1<e&&b.node_from.connectByType(e,c,b.node_from.outputs[e].type)}if(b.node_to){switch(typeof b.slot_from){case "string":e=
|
||||
b.node_to.findInputSlot(b.slot_from);break;case "object":e=b.slot_from.name?b.node_to.findInputSlot(b.slot_from.name):-1;-1==e&&"undefined"!==typeof b.slot_from.slot_index&&(e=b.slot_from.slot_index);break;case "number":e=b.slot_from;break;default:e=0}!1!==e&&-1<e&&b.node_to.connectByTypeOutput(e,c,b.node_to.inputs[e].type)}h.graph.afterChange()}q.close()}function d(a){var b=x;x&&x.classList.remove("selected");x?(x=a?x.nextSibling:x.previousSibling)||(x=b):x=a?t.childNodes[0]:t.childNodes[t.childNodes.length];
|
||||
x&&(x.classList.add("selected"),x.scrollIntoView({block:"end",behavior:"smooth"}))}function e(){function a(a,b){var e=document.createElement("div");w||(w=a);e.innerText=a;e.dataset.type=escape(a);e.className="litegraph lite-search-item";b&&(e.className+=" "+b);e.addEventListener("click",function(a){c(unescape(this.dataset.type))});t.appendChild(e)}y=null;var e=z.value;w=null;t.innerHTML="";if(e||b.show_all_if_empty)if(f.onSearchBox){var d=f.onSearchBox(t,e,h);if(d)for(var k=0;k<d.length;++k)a(d[k])}else{d=
|
||||
function(a,c){c=c||{};c=Object.assign({skipFilter:!1,inTypeOverride:!1,outTypeOverride:!1},c);var d=g.registered_node_types[a];if(q&&d.filter!=q||(!b.show_all_if_empty||e)&&-1===a.toLowerCase().indexOf(e))return!1;if(b.do_type_filter&&!c.skipFilter){d=l.value;!1!==c.inTypeOverride&&(d=c.inTypeOverride);if(l&&d&&g.registered_slot_in_types[d]&&g.registered_slot_in_types[d].nodes&&(d=g.registered_slot_in_types[d].nodes.includes(a),!1===d))return!1;d=r.value;!1!==c.outTypeOverride&&(d=c.outTypeOverride);
|
||||
if(r&&d&&g.registered_slot_out_types[d]&&g.registered_slot_out_types[d].nodes&&(d=g.registered_slot_out_types[d].nodes.includes(a),!1===d))return!1}return!0};var n=0;e=e.toLowerCase();var q=h.filter||h.graph.filter;if(b.do_type_filter&&f.search_box)var l=f.search_box.querySelector(".slot_in_type_filter"),r=f.search_box.querySelector(".slot_out_type_filter");else r=l=!1;for(k in g.searchbox_extras){var u=g.searchbox_extras[k];if(b.show_all_if_empty&&!e||-1!==u.desc.toLowerCase().indexOf(e)){var p=
|
||||
g.registered_node_types[u.type];if((!p||p.filter==q)&&d(u.type)&&(a(u.desc,"searchbox_extra"),-1!==m.search_limit&&n++>m.search_limit))break}}u=null;if(Array.prototype.filter)u=Object.keys(g.registered_node_types).filter(d);else for(k in u=[],g.registered_node_types)d(k)&&u.push(k);for(k=0;k<u.length&&!(a(u[k]),-1!==m.search_limit&&n++>m.search_limit);k++);if(b.show_general_after_typefiltered&&(l.value||r.value)){filtered_extra=[];for(k in g.registered_node_types)d(k,{inTypeOverride:l&&l.value?"*":
|
||||
!1,outTypeOverride:r&&r.value?"*":!1})&&filtered_extra.push(k);for(k=0;k<filtered_extra.length&&!(a(filtered_extra[k],"generic_type"),-1!==m.search_limit&&n++>m.search_limit);k++);}if((l.value||r.value)&&0==t.childNodes.length&&b.show_general_if_none_on_typefilter){filtered_extra=[];for(k in g.registered_node_types)d(k,{skipFilter:!0})&&filtered_extra.push(k);for(k=0;k<filtered_extra.length&&!(a(filtered_extra[k],"not_in_filter"),-1!==m.search_limit&&n++>m.search_limit);k++);}}}def_options={slot_from:null,
|
||||
function(a,b){function c(c){if(c)if(f.onSearchBoxSelection)f.onSearchBoxSelection(c,a,h);else{var d=g.searchbox_extras[c.toLowerCase()];d&&(c=d.type);h.graph.beforeChange();if(c=g.createNode(c))c.pos=h.convertEventToCanvasOffset(a),h.graph.add(c,!1);if(d&&d.data){if(d.data.properties)for(var e in d.data.properties)c.addProperty(e,d.data.properties[e]);if(d.data.inputs)for(e in c.inputs=[],d.data.inputs)c.addOutput(d.data.inputs[e][0],d.data.inputs[e][1]);if(d.data.outputs)for(e in c.outputs=[],d.data.outputs)c.addOutput(d.data.outputs[e][0],
|
||||
d.data.outputs[e][1]);d.data.title&&(c.title=d.data.title);d.data.json&&c.configure(d.data.json)}if(b.node_from){switch(typeof b.slot_from){case "string":d=b.node_from.findOutputSlot(b.slot_from);break;case "object":d=b.slot_from.name?b.node_from.findOutputSlot(b.slot_from.name):-1;-1==d&&"undefined"!==typeof b.slot_from.slot_index&&(d=b.slot_from.slot_index);break;case "number":d=b.slot_from;break;default:d=0}!1!==d&&-1<d&&b.node_from.connectByType(d,c,b.node_from.outputs[d].type)}if(b.node_to){switch(typeof b.slot_from){case "string":d=
|
||||
b.node_to.findInputSlot(b.slot_from);break;case "object":d=b.slot_from.name?b.node_to.findInputSlot(b.slot_from.name):-1;-1==d&&"undefined"!==typeof b.slot_from.slot_index&&(d=b.slot_from.slot_index);break;case "number":d=b.slot_from;break;default:d=0}!1!==d&&-1<d&&b.node_to.connectByTypeOutput(d,c,b.node_to.inputs[d].type)}h.graph.afterChange()}q.close()}function d(a){var b=x;x&&x.classList.remove("selected");x?(x=a?x.nextSibling:x.previousSibling)||(x=b):x=a?t.childNodes[0]:t.childNodes[t.childNodes.length];
|
||||
x&&(x.classList.add("selected"),x.scrollIntoView({block:"end",behavior:"smooth"}))}function e(){function a(a,b){var d=document.createElement("div");w||(w=a);d.innerText=a;d.dataset.type=escape(a);d.className="litegraph lite-search-item";b&&(d.className+=" "+b);d.addEventListener("click",function(a){c(unescape(this.dataset.type))});t.appendChild(d)}y=null;var d=z.value;w=null;t.innerHTML="";if(d||b.show_all_if_empty)if(f.onSearchBox){var e=f.onSearchBox(t,d,h);if(e)for(var k=0;k<e.length;++k)a(e[k])}else{e=
|
||||
function(a,c){c=c||{};c=Object.assign({skipFilter:!1,inTypeOverride:!1,outTypeOverride:!1},c);var e=g.registered_node_types[a];if(q&&e.filter!=q||(!b.show_all_if_empty||d)&&-1===a.toLowerCase().indexOf(d))return!1;if(b.do_type_filter&&!c.skipFilter){e=l.value;!1!==c.inTypeOverride&&(e=c.inTypeOverride);if(l&&e&&g.registered_slot_in_types[e]&&g.registered_slot_in_types[e].nodes&&(e=g.registered_slot_in_types[e].nodes.includes(a),!1===e))return!1;e=r.value;!1!==c.outTypeOverride&&(e=c.outTypeOverride);
|
||||
if(r&&e&&g.registered_slot_out_types[e]&&g.registered_slot_out_types[e].nodes&&(e=g.registered_slot_out_types[e].nodes.includes(a),!1===e))return!1}return!0};var n=0;d=d.toLowerCase();var q=h.filter||h.graph.filter;if(b.do_type_filter&&f.search_box)var l=f.search_box.querySelector(".slot_in_type_filter"),r=f.search_box.querySelector(".slot_out_type_filter");else r=l=!1;for(k in g.searchbox_extras){var u=g.searchbox_extras[k];if(b.show_all_if_empty&&!d||-1!==u.desc.toLowerCase().indexOf(d)){var p=
|
||||
g.registered_node_types[u.type];if((!p||p.filter==q)&&e(u.type)&&(a(u.desc,"searchbox_extra"),-1!==m.search_limit&&n++>m.search_limit))break}}u=null;if(Array.prototype.filter)u=Object.keys(g.registered_node_types).filter(e);else for(k in u=[],g.registered_node_types)e(k)&&u.push(k);for(k=0;k<u.length&&!(a(u[k]),-1!==m.search_limit&&n++>m.search_limit);k++);if(b.show_general_after_typefiltered&&(l.value||r.value)){filtered_extra=[];for(k in g.registered_node_types)e(k,{inTypeOverride:l&&l.value?"*":
|
||||
!1,outTypeOverride:r&&r.value?"*":!1})&&filtered_extra.push(k);for(k=0;k<filtered_extra.length&&!(a(filtered_extra[k],"generic_type"),-1!==m.search_limit&&n++>m.search_limit);k++);}if((l.value||r.value)&&0==t.childNodes.length&&b.show_general_if_none_on_typefilter){filtered_extra=[];for(k in g.registered_node_types)e(k,{skipFilter:!0})&&filtered_extra.push(k);for(k=0;k<filtered_extra.length&&!(a(filtered_extra[k],"not_in_filter"),-1!==m.search_limit&&n++>m.search_limit);k++);}}}def_options={slot_from:null,
|
||||
node_from:null,node_to:null,do_type_filter:g.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:g.search_hide_on_mouse_leave,show_all_if_empty:!0,show_all_on_open:g.search_show_all_on_open};b=Object.assign(def_options,b||{});var f=this,h=m.active_canvas,k=h.canvas,n=k.ownerDocument||document,q=document.createElement("div");q.className="litegraph litesearchbox graphdialog rounded";q.innerHTML="<span class='name'>Search</span> <input autofocus type='text' class='value rounded'/>";
|
||||
b.do_type_filter&&(q.innerHTML+="<select class='slot_in_type_filter'><option value=''></option></select>",q.innerHTML+="<select class='slot_out_type_filter'><option value=''></option></select>");q.innerHTML+="<div class='helper'></div>";n.fullscreenElement?n.fullscreenElement.appendChild(q):(n.body.appendChild(q),n.body.style.overflow="hidden");if(b.do_type_filter)var l=q.querySelector(".slot_in_type_filter"),r=q.querySelector(".slot_out_type_filter");q.close=function(){f.search_box=null;n.body.focus();
|
||||
n.body.style.overflow="";setTimeout(function(){f.canvas.focus()},20);q.parentNode&&q.parentNode.removeChild(q)};1<this.ds.scale&&(q.style.transform="scale("+this.ds.scale+")");if(b.hide_on_mouse_leave){var p=!1,v=null;g.pointerListenerAdd(q,"enter",function(a){v&&(clearTimeout(v),v=null)});g.pointerListenerAdd(q,"leave",function(a){p||(v=setTimeout(function(){q.close()},500))});b.do_type_filter&&(l.addEventListener("click",function(a){p++}),l.addEventListener("blur",function(a){p=0}),l.addEventListener("change",
|
||||
function(a){p=-1}),r.addEventListener("click",function(a){p++}),r.addEventListener("blur",function(a){p=0}),r.addEventListener("change",function(a){p=-1}))}f.search_box&&f.search_box.close();f.search_box=q;var t=q.querySelector(".helper"),w=null,y=null,x=null,z=q.querySelector("input");z&&(z.addEventListener("blur",function(a){this.focus()}),z.addEventListener("keydown",function(a){if(38==a.keyCode)d(!1);else if(40==a.keyCode)d(!0);else if(27==a.keyCode)q.close();else if(13==a.keyCode)x?c(x.innerHTML):
|
||||
w?c(w):q.close();else{y&&clearInterval(y);y=setTimeout(e,250);return}a.preventDefault();a.stopPropagation();a.stopImmediatePropagation();return!0}));if(b.do_type_filter){if(l){var A=g.slot_types_in,C=A.length;if(b.type_filter_in==g.EVENT||b.type_filter_in==g.ACTION)b.type_filter_in="_event_";for(var B=0;B<C;B++){var D=document.createElement("option");D.value=A[B];D.innerHTML=A[B];l.appendChild(D);!1!==b.type_filter_in&&(b.type_filter_in+"").toLowerCase()==(A[B]+"").toLowerCase()&&(D.selected=!0)}l.addEventListener("change",
|
||||
function(){e()})}if(r){A=g.slot_types_out;C=A.length;if(b.type_filter_out==g.EVENT||b.type_filter_out==g.ACTION)b.type_filter_out="_event_";for(B=0;B<C;B++)D=document.createElement("option"),D.value=A[B],D.innerHTML=A[B],r.appendChild(D),!1!==b.type_filter_out&&(b.type_filter_out+"").toLowerCase()==(A[B]+"").toLowerCase()&&(D.selected=!0);r.addEventListener("change",function(){e()})}}k=k.getBoundingClientRect();l=(a?a.clientY:k.top+.5*k.height)-20;q.style.left=(a?a.clientX:k.left+.5*k.width)-80+"px";
|
||||
q.style.top=l+"px";a.layerY>k.height-200&&(t.style.maxHeight=k.height-a.layerY-20+"px");z.focus();b.show_all_on_open&&e();return q};m.prototype.showEditPropertyValue=function(a,b,c){function d(){e(m.value)}function e(e){f&&f.values&&f.values.constructor===Object&&void 0!=f.values[e]&&(e=f.values[e]);"number"==typeof a.properties[b]&&(e=Number(e));if("array"==h||"object"==h)e=JSON.parse(e);a.properties[b]=e;a.graph&&a.graph._version++;if(a.onPropertyChanged)a.onPropertyChanged(b,e);if(c.onclose)c.onclose();
|
||||
q.style.top=l+"px";a.layerY>k.height-200&&(t.style.maxHeight=k.height-a.layerY-20+"px");z.focus();b.show_all_on_open&&e();return q};m.prototype.showEditPropertyValue=function(a,b,c){function d(){e(m.value)}function e(d){f&&f.values&&f.values.constructor===Object&&void 0!=f.values[d]&&(d=f.values[d]);"number"==typeof a.properties[b]&&(d=Number(d));if("array"==h||"object"==h)d=JSON.parse(d);a.properties[b]=d;a.graph&&a.graph._version++;if(a.onPropertyChanged)a.onPropertyChanged(b,d);if(c.onclose)c.onclose();
|
||||
l.close();a.setDirtyCanvas(!0,!0)}if(a&&void 0!==a.properties[b]){c=c||{};var f=a.getPropertyInfo(b),h=f.type,g="";if("string"==h||"number"==h||"array"==h||"object"==h)g="<input autofocus type='text' class='value'/>";else if("enum"!=h&&"combo"!=h||!f.values)if("boolean"==h||"toggle"==h)g="<input autofocus type='checkbox' class='value' "+(a.properties[b]?"checked":"")+"/>";else{console.warn("unknown type: "+h);return}else{g="<select autofocus type='text' class='value'>";for(var n in f.values){var q=
|
||||
n;f.values.constructor===Array&&(q=f.values[n]);g+="<option value='"+q+"' "+(q==a.properties[b]?"selected":"")+">"+f.values[n]+"</option>"}g+="</select>"}var l=this.createDialog("<span class='name'>"+(f.label?f.label:b)+"</span>"+g+"<button>OK</button>",c),m=!1;if("enum"!=h&&"combo"!=h||!f.values)if("boolean"==h||"toggle"==h)(m=l.querySelector("input"))&&m.addEventListener("click",function(a){l.modified();e(!!m.checked)});else{if(m=l.querySelector("input"))m.addEventListener("blur",function(a){this.focus()}),
|
||||
q=void 0!==a.properties[b]?a.properties[b]:"","string"!==h&&(q=JSON.stringify(q)),m.value=q,m.addEventListener("keydown",function(a){if(27==a.keyCode)l.close();else if(13==a.keyCode)d();else if(13!=a.keyCode){l.modified();return}a.preventDefault();a.stopPropagation()})}else m=l.querySelector("select"),m.addEventListener("change",function(a){l.modified();e(a.target.value)});m&&m.focus();l.querySelector("button").addEventListener("click",d);return l}};m.prototype.createDialog=function(a,b){def_options=
|
||||
@@ -305,12 +305,12 @@ on:"True",off:"False"},a)}panel.addWidget("combo","Render mode",g.LINK_RENDER_MO
|
||||
var b=function(b,c){d.graph.beforeChange(a);switch(b){case "Title":a.title=c;break;case "Mode":b=Object.values(g.NODE_MODES).indexOf(c);0<=b&&g.NODE_MODES[b]?a.changeMode(b):console.warn("unexpected mode: "+c);break;case "Color":m.node_colors[c]?(a.color=m.node_colors[c].color,a.bgcolor=m.node_colors[c].bgcolor):console.warn("unexpected color: "+c);break;default:a.setProperty(b,c)}d.graph.afterChange();d.dirty_canvas=!0};panel.addWidget("string","Title",a.title,{},b);panel.addWidget("combo","Mode",
|
||||
g.NODE_MODES[a.mode],{values:g.NODE_MODES},b);var c="";void 0!==a.color&&(c=Object.keys(m.node_colors).filter(function(b){return m.node_colors[b].color==a.color}));panel.addWidget("combo","Color",c,{values:Object.keys(m.node_colors)},b);for(var h in a.properties){c=a.properties[h];var k=a.getPropertyInfo(h);a.onAddPropertyToPanel&&a.onAddPropertyToPanel(h,panel)||panel.addWidget(k.widget||k.type,h,c,k,b)}panel.addSeparator();if(a.onShowCustomPanelInfo)a.onShowCustomPanelInfo(panel);panel.footer.innerHTML=
|
||||
"";panel.addButton("Delete",function(){a.block_delete||(a.graph.remove(a),panel.close())}).classList.add("delete")}this.SELECTED_NODE=a;this.closePanels();var c=this.getCanvasWindow(),d=this;panel=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=panel;panel.id="node-panel";panel.node=a;panel.classList.add("settings");panel.inner_showCodePad=function(c){panel.classList.remove("settings");
|
||||
panel.classList.add("centered");panel.alt_content.innerHTML="<textarea class='code'></textarea>";var e=panel.alt_content.querySelector("textarea"),d=function(){panel.toggleAltContent(!1);panel.toggleFooterVisibility(!0);e.parentNode.removeChild(e);panel.classList.add("settings");panel.classList.remove("centered");b()};e.value=a.properties[c];e.addEventListener("keydown",function(b){"Enter"==b.code&&b.ctrlKey&&(a.setProperty(c,e.value),d())});panel.toggleAltContent(!0);panel.toggleFooterVisibility(!1);
|
||||
e.style.height="calc(100% - 40px)";var g=panel.addButton("Assign",function(){a.setProperty(c,e.value);d()});panel.alt_content.appendChild(g);g=panel.addButton("Close",d);g.style.float="right";panel.alt_content.appendChild(g)};b();this.canvas.parentNode.appendChild(panel)};m.prototype.showSubgraphPropertiesDialog=function(a){function b(){d.clear();if(a.inputs)for(var c=0;c<a.inputs.length;++c){var f=a.inputs[c];if(!f.not_subgraph_input){var g=d.addHTML("<button>✕</button> <span class='bullet_icon'></span><span class='name'></span><span class='type'></span>",
|
||||
panel.classList.add("centered");panel.alt_content.innerHTML="<textarea class='code'></textarea>";var d=panel.alt_content.querySelector("textarea"),e=function(){panel.toggleAltContent(!1);panel.toggleFooterVisibility(!0);d.parentNode.removeChild(d);panel.classList.add("settings");panel.classList.remove("centered");b()};d.value=a.properties[c];d.addEventListener("keydown",function(b){"Enter"==b.code&&b.ctrlKey&&(a.setProperty(c,d.value),e())});panel.toggleAltContent(!0);panel.toggleFooterVisibility(!1);
|
||||
d.style.height="calc(100% - 40px)";var g=panel.addButton("Assign",function(){a.setProperty(c,d.value);e()});panel.alt_content.appendChild(g);g=panel.addButton("Close",e);g.style.float="right";panel.alt_content.appendChild(g)};b();this.canvas.parentNode.appendChild(panel)};m.prototype.showSubgraphPropertiesDialog=function(a){function b(){d.clear();if(a.inputs)for(var c=0;c<a.inputs.length;++c){var f=a.inputs[c];if(!f.not_subgraph_input){var g=d.addHTML("<button>✕</button> <span class='bullet_icon'></span><span class='name'></span><span class='type'></span>",
|
||||
"subgraph_property");g.dataset.name=f.name;g.dataset.slot=c;g.querySelector(".name").innerText=f.name;g.querySelector(".type").innerText=f.type;g.querySelector("button").addEventListener("click",function(c){a.removeInput(Number(this.parentNode.dataset.slot));b()})}}}console.log("showing subgraph properties dialog");var c=this.canvas.parentNode.querySelector(".subgraph_dialog");c&&c.close();var d=this.createPanel("Subgraph Inputs",{closable:!0,width:500});d.node=a;d.classList.add("subgraph_dialog");
|
||||
d.addHTML(" + <span class='label'>Name</span><input class='name'/><span class='label'>Type</span><input class='type'></input><button>+</button>","subgraph_property extra",!0).querySelector("button").addEventListener("click",function(c){c=this.parentNode;var e=c.querySelector(".name").value,d=c.querySelector(".type").value;e&&-1==a.findInputSlot(e)&&(a.addInput(e,d),c.querySelector(".name").value="",c.querySelector(".type").value="",b())});b();this.canvas.parentNode.appendChild(d);return d};m.prototype.showSubgraphPropertiesDialogRight=
|
||||
d.addHTML(" + <span class='label'>Name</span><input class='name'/><span class='label'>Type</span><input class='type'></input><button>+</button>","subgraph_property extra",!0).querySelector("button").addEventListener("click",function(c){c=this.parentNode;var d=c.querySelector(".name").value,e=c.querySelector(".type").value;d&&-1==a.findInputSlot(d)&&(a.addInput(d,e),c.querySelector(".name").value="",c.querySelector(".type").value="",b())});b();this.canvas.parentNode.appendChild(d);return d};m.prototype.showSubgraphPropertiesDialogRight=
|
||||
function(a){function b(){e.clear();if(a.outputs)for(var c=0;c<a.outputs.length;++c){var d=a.outputs[c];if(!d.not_subgraph_output){var g=e.addHTML("<button>✕</button> <span class='bullet_icon'></span><span class='name'></span><span class='type'></span>","subgraph_property");g.dataset.name=d.name;g.dataset.slot=c;g.querySelector(".name").innerText=d.name;g.querySelector(".type").innerText=d.type;g.querySelector("button").addEventListener("click",function(c){a.removeOutput(Number(this.parentNode.dataset.slot));
|
||||
b()})}}}function c(){var c=this.parentNode,e=c.querySelector(".name").value,d=c.querySelector(".type").value;e&&-1==a.findOutputSlot(e)&&(a.addOutput(e,d),c.querySelector(".name").value="",c.querySelector(".type").value="",b())}var d=this.canvas.parentNode.querySelector(".subgraph_dialog");d&&d.close();var e=this.createPanel("Subgraph Outputs",{closable:!0,width:500});e.node=a;e.classList.add("subgraph_dialog");d=e.addHTML(" + <span class='label'>Name</span><input class='name'/><span class='label'>Type</span><input class='type'></input><button>+</button>",
|
||||
b()})}}}function c(){var c=this.parentNode,d=c.querySelector(".name").value,e=c.querySelector(".type").value;d&&-1==a.findOutputSlot(d)&&(a.addOutput(d,e),c.querySelector(".name").value="",c.querySelector(".type").value="",b())}var d=this.canvas.parentNode.querySelector(".subgraph_dialog");d&&d.close();var e=this.createPanel("Subgraph Outputs",{closable:!0,width:500});e.node=a;e.classList.add("subgraph_dialog");d=e.addHTML(" + <span class='label'>Name</span><input class='name'/><span class='label'>Type</span><input class='type'></input><button>+</button>",
|
||||
"subgraph_property extra",!0);d.querySelector(".name").addEventListener("keydown",function(a){13==a.keyCode&&c.apply(this)});d.querySelector("button").addEventListener("click",function(a){c.apply(this)});b();this.canvas.parentNode.appendChild(e);return e};m.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())}};m.onMenuNodeCollapse=function(a,b,c,
|
||||
d,e){e.graph.beforeChange();a=m.active_canvas;if(!a.selected_nodes||1>=Object.keys(a.selected_nodes).length)e.collapse();else for(var f in a.selected_nodes)a.selected_nodes[f].collapse();e.graph.afterChange()};m.onMenuNodePin=function(a,b,c,d,e){e.pin()};m.onMenuNodeMode=function(a,b,c,d,e){new g.ContextMenu(g.NODE_MODES,{event:c,callback:function(a){if(e){var b=Object.values(g.NODE_MODES).indexOf(a),c=function(c){0<=b&&g.NODE_MODES[b]?c.changeMode(b):(console.warn("unexpected mode: "+a),c.changeMode(g.ALWAYS))},
|
||||
d=m.active_canvas;if(!d.selected_nodes||1>=Object.keys(d.selected_nodes).length)c(e);else for(var f in d.selected_nodes)c(d.selected_nodes[f])}},parentMenu:d,node:e});return!1};m.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 m.node_colors)a=m.node_colors[f],a={value:f,content:"<span style='display: block; color: #999; padding-left: 4px; border-left: 8px solid "+a.color+
|
||||
|
||||
Reference in New Issue
Block a user