mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-03 06:47:33 +00:00
fix
This commit is contained in:
@@ -6214,9 +6214,12 @@ LGraphNode.prototype.executeAction = function(action)
|
||||
**/
|
||||
LGraphCanvas.prototype.deleteSelectedNodes = function() {
|
||||
for (var i in this.selected_nodes) {
|
||||
var m = this.selected_nodes[i];
|
||||
var node = this.selected_nodes[i];
|
||||
//if(m == this.node_in_panel) this.showNodePanel(null);
|
||||
this.graph.remove(m);
|
||||
this.graph.remove(node);
|
||||
if (this.onNodeDeselected) {
|
||||
this.onNodeDeselected(node);
|
||||
}
|
||||
}
|
||||
this.selected_nodes = {};
|
||||
this.current_node = null;
|
||||
|
||||
189
build/litegraph.min.js
vendored
189
build/litegraph.min.js
vendored
@@ -136,100 +136,101 @@ if(d.onDropData){var g=new FileReader;g.onload=function(a){d.onDropData(a.target
|
||||
if(d=e.node_types_by_file_extension[d])if(d=e.createNode(d.type),d.pos=[a.canvasX,a.canvasY],this.graph.add(d),d.onDropFile)d.onDropFile(b)}};k.prototype.processNodeDblClicked=function(a){if(this.onShowNodePanel)this.onShowNodePanel(a);if(this.onNodeDblClicked)this.onNodeDblClicked(a);this.setDirty(!0)};k.prototype.processNodeSelected=function(a,b){this.selectNode(a,b&&b.shiftKey);if(this.onNodeSelected)this.onNodeSelected(a)};k.prototype.selectNode=function(a,b){null==a?this.deselectAllNodes():this.selectNodes([a],
|
||||
b)};k.prototype.selectNodes=function(a,b){b||this.deselectAllNodes();a=a||this.graph._nodes;for(var d=0;d<a.length;++d){var e=a[d];if(!e.is_selected){if(!e.is_selected&&e.onSelected)e.onSelected();e.is_selected=!0;this.selected_nodes[e.id]=e;if(e.inputs)for(var c=0;c<e.inputs.length;++c)this.highlighted_links[e.inputs[c].link]=!0;if(e.outputs)for(c=0;c<e.outputs.length;++c){var h=e.outputs[c];if(h.links)for(var g=0;g<h.links.length;++g)this.highlighted_links[h.links[g]]=!0}}}if(this.onSelectionChange)this.onSelectionChange(this.selected_nodes);
|
||||
this.setDirty(!0)};k.prototype.deselectNode=function(a){if(a.is_selected){if(a.onDeselected)a.onDeselected();a.is_selected=!1;if(this.onNodeDeselected)this.onNodeDeselected(a);if(a.inputs)for(var b=0;b<a.inputs.length;++b)delete this.highlighted_links[a.inputs[b].link];if(a.outputs)for(b=0;b<a.outputs.length;++b){var d=a.outputs[b];if(d.links)for(var e=0;e<d.links.length;++e)delete this.highlighted_links[d.links[e]]}}};k.prototype.deselectAllNodes=function(){if(this.graph){for(var a=this.graph._nodes,
|
||||
b=0,d=a.length;b<d;++b){var e=a[b];if(e.is_selected){if(e.onDeselected)e.onDeselected();e.is_selected=!1;if(this.onNodeDeselected)this.onNodeDeselected(e)}}this.selected_nodes={};this.current_node=null;this.highlighted_links={};if(this.onSelectionChange)this.onSelectionChange(this.selected_nodes);this.setDirty(!0)}};k.prototype.deleteSelectedNodes=function(){for(var a in this.selected_nodes)this.graph.remove(this.selected_nodes[a]);this.selected_nodes={};this.current_node=null;this.highlighted_links=
|
||||
{};this.setDirty(!0)};k.prototype.centerOnNode=function(a){this.ds.offset[0]=-a.pos[0]-0.5*a.size[0]+0.5*this.canvas.width/this.ds.scale;this.ds.offset[1]=-a.pos[1]-0.5*a.size[1]+0.5*this.canvas.height/this.ds.scale;this.setDirty(!0,!0)};k.prototype.adjustMouseEvent=function(a){if(this.canvas){var b=this.canvas.getBoundingClientRect();a.localX=a.clientX-b.left;a.localY=a.clientY-b.top}else a.localX=a.clientX,a.localY=a.clientY;a.deltaX=a.localX-this.last_mouse_position[0];a.deltaY=a.localY-this.last_mouse_position[1];
|
||||
this.last_mouse_position[0]=a.localX;this.last_mouse_position[1]=a.localY;a.canvasX=a.localX/this.ds.scale-this.ds.offset[0];a.canvasY=a.localY/this.ds.scale-this.ds.offset[1]};k.prototype.setZoom=function(a,b){this.ds.changeScale(a,b);this.dirty_bgcanvas=this.dirty_canvas=!0};k.prototype.convertOffsetToCanvas=function(a,b){return this.ds.convertOffsetToCanvas(a,b)};k.prototype.convertCanvasToOffset=function(a,b){return this.ds.convertCanvasToOffset(a,b)};k.prototype.convertEventToCanvasOffset=function(a){var b=
|
||||
this.canvas.getBoundingClientRect();return this.convertCanvasToOffset([a.clientX-b.left,a.clientY-b.top])};k.prototype.bringToFront=function(a){var b=this.graph._nodes.indexOf(a);-1!=b&&(this.graph._nodes.splice(b,1),this.graph._nodes.push(a))};k.prototype.sendToBack=function(a){var b=this.graph._nodes.indexOf(a);-1!=b&&(this.graph._nodes.splice(b,1),this.graph._nodes.unshift(a))};var x=new Float32Array(4);k.prototype.computeVisibleNodes=function(a,b){var d=b||[];d.length=0;a=a||this.graph._nodes;
|
||||
for(var e=0,c=a.length;e<c;++e){var h=a[e];(!this.live_mode||h.onDrawBackground||h.onDrawForeground)&&v(this.visible_area,h.getBounding(x))&&d.push(h)}return d};k.prototype.draw=function(a,b){if(this.canvas){var d=e.getTime();this.render_time=0.001*(d-this.last_draw_time);this.last_draw_time=d;this.graph&&this.ds.computeVisibleArea();(this.dirty_bgcanvas||b||this.always_render_background||this.graph&&this.graph._last_trigger_time&&1E3>d-this.graph._last_trigger_time)&&this.drawBackCanvas();(this.dirty_canvas||
|
||||
a)&&this.drawFrontCanvas();this.fps=this.render_time?1/this.render_time:0;this.frame+=1}};k.prototype.drawFrontCanvas=function(){this.dirty_canvas=!1;this.ctx||(this.ctx=this.bgcanvas.getContext("2d"));var a=this.ctx;if(a){a.start2D&&a.start2D();var b=this.canvas;a.restore();a.setTransform(1,0,0,1,0,0);this.dirty_area&&(a.save(),a.beginPath(),a.rect(this.dirty_area[0],this.dirty_area[1],this.dirty_area[2],this.dirty_area[3]),a.clip());this.clear_background&&a.clearRect(0,0,b.width,b.height);this.bgcanvas==
|
||||
this.canvas?this.drawBackCanvas():a.drawImage(this.bgcanvas,0,0);if(this.onRender)this.onRender(b,a);this.show_info&&this.renderInfo(a);if(this.graph){a.save();this.ds.toCanvasContext(a);for(var b=this.computeVisibleNodes(null,this.visible_nodes),d=0;d<b.length;++d){var c=b[d];a.save();a.translate(c.pos[0],c.pos[1]);this.drawNode(c,a);a.restore()}this.render_execution_order&&this.drawExecutionOrder(a);this.graph.config.links_ontop&&(this.live_mode||this.drawConnections(a));if(null!=this.connecting_pos){a.lineWidth=
|
||||
this.connections_width;b=null;switch(this.connecting_output.type){case e.EVENT:b=e.EVENT_LINK_COLOR;break;default:b=e.CONNECTING_LINK_COLOR}this.renderLink(a,this.connecting_pos,[this.canvas_mouse[0],this.canvas_mouse[1]],null,!1,null,b,this.connecting_output.dir||(this.connecting_node.horizontal?e.DOWN:e.RIGHT),e.CENTER);a.beginPath();this.connecting_output.type===e.EVENT||this.connecting_output.shape===e.BOX_SHAPE?a.rect(this.connecting_pos[0]-6+0.5,this.connecting_pos[1]-5+0.5,14,10):a.arc(this.connecting_pos[0],
|
||||
this.connecting_pos[1],4,0,2*Math.PI);a.fill();a.fillStyle="#ffcc00";this._highlight_input&&(a.beginPath(),a.arc(this._highlight_input[0],this._highlight_input[1],6,0,2*Math.PI),a.fill())}this.dragging_rectangle&&(a.strokeStyle="#FFF",a.strokeRect(this.dragging_rectangle[0],this.dragging_rectangle[1],this.dragging_rectangle[2],this.dragging_rectangle[3]));if(this.over_link_center&&this.render_link_tooltip)this.drawLinkTooltip(a,this.over_link_center);else if(this.onDrawLinkTooltip)this.onDrawLinkTooltip(a,
|
||||
null);if(this.onDrawForeground)this.onDrawForeground(a,this.visible_rect);a.restore()}if(this.onDrawOverlay)this.onDrawOverlay(a);this.dirty_area&&a.restore();a.finish2D&&a.finish2D()}};k.prototype.renderInfo=function(a,b,d){b=b||0;d=d||0;a.save();a.translate(b,d);a.font="10px Arial";a.fillStyle="#888";this.graph?(a.fillText("T: "+this.graph.globaltime.toFixed(2)+"s",5,13),a.fillText("I: "+this.graph.iteration,5,26),a.fillText("N: "+this.graph._nodes.length+" ["+this.visible_nodes.length+"]",5,39),
|
||||
a.fillText("V: "+this.graph._version,5,52),a.fillText("FPS:"+this.fps.toFixed(2),5,65)):a.fillText("No graph selected",5,13);a.restore()};k.prototype.drawBackCanvas=function(){var a=this.bgcanvas;if(a.width!=this.canvas.width||a.height!=this.canvas.height)a.width=this.canvas.width,a.height=this.canvas.height;this.bgctx||(this.bgctx=this.bgcanvas.getContext("2d"));var b=this.bgctx;b.start&&b.start();this.clear_background&&b.clearRect(0,0,a.width,a.height);if(this._graph_stack&&this._graph_stack.length){b.save();
|
||||
var d=this.graph._subgraph_node;b.strokeStyle=d.bgcolor;b.lineWidth=10;b.strokeRect(1,1,a.width-2,a.height-2);b.lineWidth=1;b.font="40px Arial";b.textAlign="center";b.fillStyle=d.bgcolor||"#AAA";for(var e="",c=1;c<this._graph_stack.length;++c)e+=this._graph_stack[c]._subgraph_node.getTitle()+" >> ";b.fillText(e+d.getTitle(),0.5*a.width,40);b.restore()}d=!1;this.onRenderBackground&&(d=this.onRenderBackground(a,b));b.restore();b.setTransform(1,0,0,1,0,0);this.visible_links.length=0;if(this.graph){b.save();
|
||||
this.ds.toCanvasContext(b);if(this.background_image&&0.5<this.ds.scale&&!d){b.globalAlpha=this.zoom_modify_alpha?(1-0.5/this.ds.scale)*this.editor_alpha:this.editor_alpha;b.imageSmoothingEnabled=b.mozImageSmoothingEnabled=b.imageSmoothingEnabled=!1;if(!this._bg_img||this._bg_img.name!=this.background_image){this._bg_img=new Image;this._bg_img.name=this.background_image;this._bg_img.src=this.background_image;var h=this;this._bg_img.onload=function(){h.draw(!0,!0)}}d=null;null==this._pattern&&0<this._bg_img.width?
|
||||
(d=b.createPattern(this._bg_img,"repeat"),this._pattern_img=this._bg_img,this._pattern=d):d=this._pattern;d&&(b.fillStyle=d,b.fillRect(this.visible_area[0],this.visible_area[1],this.visible_area[2],this.visible_area[3]),b.fillStyle="transparent");b.globalAlpha=1;b.imageSmoothingEnabled=b.mozImageSmoothingEnabled=b.imageSmoothingEnabled=!0}this.graph._groups.length&&!this.live_mode&&this.drawGroups(a,b);if(this.onDrawBackground)this.onDrawBackground(b,this.visible_area);this.onBackgroundRender&&(console.error("WARNING! onBackgroundRender deprecated, now is named onDrawBackground "),
|
||||
this.onBackgroundRender=null);this.render_canvas_border&&(b.strokeStyle="#235",b.strokeRect(0,0,a.width,a.height));this.render_connections_shadows?(b.shadowColor="#000",b.shadowOffsetX=0,b.shadowOffsetY=0,b.shadowBlur=6):b.shadowColor="rgba(0,0,0,0)";this.live_mode||this.drawConnections(b);b.shadowColor="rgba(0,0,0,0)";b.restore()}b.finish&&b.finish();this.dirty_bgcanvas=!1;this.dirty_canvas=!0};var g=new Float32Array(2);k.prototype.drawNode=function(a,b){this.current_node=a;var d=a.color||a.constructor.color||
|
||||
e.NODE_DEFAULT_COLOR,c=a.bgcolor||a.constructor.bgcolor||e.NODE_DEFAULT_BGCOLOR;if(this.live_mode){if(!a.flags.collapsed&&(b.shadowColor="transparent",a.onDrawForeground))a.onDrawForeground(b,this,this.canvas)}else{var n=this.editor_alpha;b.globalAlpha=n;this.render_shadows?(b.shadowColor=e.DEFAULT_SHADOW_COLOR,b.shadowOffsetX=2*this.ds.scale,b.shadowOffsetY=2*this.ds.scale,b.shadowBlur=3*this.ds.scale):b.shadowColor="transparent";if(!a.flags.collapsed||!a.onDrawCollapsed||!0!=a.onDrawCollapsed(b,
|
||||
this)){var h=a._shape||e.BOX_SHAPE;g.set(a.size);var m=a.horizontal;if(a.flags.collapsed){b.font=this.inner_text_font;var k=a.getTitle?a.getTitle():a.title;null!=k&&(a._collapsed_width=Math.min(a.size[0],b.measureText(k).width+2*e.NODE_TITLE_HEIGHT),g[0]=a._collapsed_width,g[1]=0)}a.clip_area&&(b.save(),b.beginPath(),h==e.BOX_SHAPE?b.rect(0,0,g[0],g[1]):h==e.ROUND_SHAPE?b.roundRect(0,0,g[0],g[1],10):h==e.CIRCLE_SHAPE&&b.arc(0.5*g[0],0.5*g[1],0.5*g[0],0,2*Math.PI),b.clip());a.has_errors&&(c="red");
|
||||
this.drawNodeShape(a,b,g,d,c,a.is_selected,a.mouseOver);b.shadowColor="transparent";if(a.onDrawForeground)a.onDrawForeground(b,this,this.canvas);b.textAlign=m?"center":"left";b.font=this.inner_text_font;c=0.6<this.ds.scale;h=this.connecting_output;b.lineWidth=1;var k=0,q=new Float32Array(2);if(!a.flags.collapsed){if(a.inputs)for(d=0;d<a.inputs.length;d++){var p=a.inputs[d];b.globalAlpha=n;this.connecting_node&&!e.isValidConnection(p.type,h.type)&&(b.globalAlpha=0.4*n);b.fillStyle=null!=p.link?p.color_on||
|
||||
this.default_connection_color.input_on:p.color_off||this.default_connection_color.input_off;var f=a.getConnectionPos(!0,d,q);f[0]-=a.pos[0];f[1]-=a.pos[1];k<f[1]+0.5*e.NODE_SLOT_HEIGHT&&(k=f[1]+0.5*e.NODE_SLOT_HEIGHT);b.beginPath();p.type===e.EVENT||p.shape===e.BOX_SHAPE?m?b.rect(f[0]-5+0.5,f[1]-8+0.5,10,14):b.rect(f[0]-6+0.5,f[1]-5+0.5,14,10):p.shape===e.ARROW_SHAPE?(b.moveTo(f[0]+8,f[1]+0.5),b.lineTo(f[0]-4,f[1]+6+0.5),b.lineTo(f[0]-4,f[1]-6+0.5),b.closePath()):b.arc(f[0],f[1],4,0,2*Math.PI);b.fill();
|
||||
if(c){var l=null!=p.label?p.label:p.name;l&&(b.fillStyle=e.NODE_TEXT_COLOR,m||p.dir==e.UP?b.fillText(l,f[0],f[1]-10):b.fillText(l,f[0]+10,f[1]+5))}}this.connecting_node&&(b.globalAlpha=0.4*n);b.textAlign=m?"center":"right";b.strokeStyle="black";if(a.outputs)for(d=0;d<a.outputs.length;d++)if(p=a.outputs[d],f=a.getConnectionPos(!1,d,q),f[0]-=a.pos[0],f[1]-=a.pos[1],k<f[1]+0.5*e.NODE_SLOT_HEIGHT&&(k=f[1]+0.5*e.NODE_SLOT_HEIGHT),b.fillStyle=p.links&&p.links.length?p.color_on||this.default_connection_color.output_on:
|
||||
p.color_off||this.default_connection_color.output_off,b.beginPath(),p.type===e.EVENT||p.shape===e.BOX_SHAPE?m?b.rect(f[0]-5+0.5,f[1]-8+0.5,10,14):b.rect(f[0]-6+0.5,f[1]-5+0.5,14,10):p.shape===e.ARROW_SHAPE?(b.moveTo(f[0]+8,f[1]+0.5),b.lineTo(f[0]-4,f[1]+6+0.5),b.lineTo(f[0]-4,f[1]-6+0.5),b.closePath()):b.arc(f[0],f[1],4,0,2*Math.PI),b.fill(),b.stroke(),c&&(l=null!=p.label?p.label:p.name))b.fillStyle=e.NODE_TEXT_COLOR,m||p.dir==e.DOWN?b.fillText(l,f[0],f[1]-8):b.fillText(l,f[0]-10,f[1]+5);b.textAlign=
|
||||
"left";b.globalAlpha=1;if(a.widgets){if(m||a.widgets_up)k=2;this.drawNodeWidgets(a,k,b,this.node_widget&&this.node_widget[0]==a?this.node_widget[1]:null)}}else if(this.render_collapsed_slots){n=c=null;if(a.inputs)for(d=0;d<a.inputs.length;d++)if(p=a.inputs[d],null!=p.link){c=p;break}if(a.outputs)for(d=0;d<a.outputs.length;d++)p=a.outputs[d],p.links&&p.links.length&&(n=p);c&&(d=0,c=-0.5*e.NODE_TITLE_HEIGHT,m&&(d=0.5*a._collapsed_width,c=-e.NODE_TITLE_HEIGHT),b.fillStyle="#686",b.beginPath(),p.type===
|
||||
e.EVENT||p.shape===e.BOX_SHAPE?b.rect(d-7+0.5,c-4,14,8):p.shape===e.ARROW_SHAPE?(b.moveTo(d+8,c),b.lineTo(d+-4,c-4),b.lineTo(d+-4,c+4),b.closePath()):b.arc(d,c,4,0,2*Math.PI),b.fill());n&&(d=a._collapsed_width,c=-0.5*e.NODE_TITLE_HEIGHT,m&&(d=0.5*a._collapsed_width,c=0),b.fillStyle="#686",b.strokeStyle="black",b.beginPath(),p.type===e.EVENT||p.shape===e.BOX_SHAPE?b.rect(d-7+0.5,c-4,14,8):p.shape===e.ARROW_SHAPE?(b.moveTo(d+6,c),b.lineTo(d-6,c-4),b.lineTo(d-6,c+4),b.closePath()):b.arc(d,c,4,0,2*Math.PI),
|
||||
b.fill())}a.clip_area&&b.restore();b.globalAlpha=1}}};k.prototype.drawLinkTooltip=function(a,b){var d=b._pos;a.fillStyle="black";a.beginPath();a.arc(d[0],d[1],3,0,2*Math.PI);a.fill();if(null!=b.data&&(!this.onDrawLinkTooltip||!0!=this.onDrawLinkTooltip(a,b,this))){var e=b.data,c=null,c=e.constructor===Number?e.toFixed(2):e.constructor===String?'"'+e+'"':e.constructor===Boolean?String(e):e.toToolTip?e.toToolTip():"["+e.constructor.name+"]";null!=c&&(a.font="14px Courier New",e=a.measureText(c).width+
|
||||
20,a.shadowColor="black",a.shadowOffsetX=2,a.shadowOffsetY=2,a.shadowBlur=3,a.fillStyle="#454",a.beginPath(),a.roundRect(d[0]-0.5*e,d[1]-15-24,e,24,3,3),a.moveTo(d[0]-10,d[1]-15),a.lineTo(d[0]+10,d[1]-15),a.lineTo(d[0],d[1]-5),a.fill(),a.shadowColor="transparent",a.textAlign="center",a.fillStyle="#CEC",a.fillText(c,d[0],d[1]-15-24*0.3))}};var m=new Float32Array(4);k.prototype.drawNodeShape=function(a,b,d,c,n,h,g){b.strokeStyle=c;b.fillStyle=n;n=e.NODE_TITLE_HEIGHT;var p=0.5>this.ds.scale,q=a._shape||
|
||||
a.constructor.shape||e.ROUND_SHAPE,f=a.constructor.title_mode,l=!0;f==e.TRANSPARENT_TITLE?l=!1:f==e.AUTOHIDE_TITLE&&g&&(l=!0);m[0]=0;m[1]=l?-n:0;m[2]=d[0]+1;m[3]=l?d[1]+n:d[1];g=b.globalAlpha;b.beginPath();q==e.BOX_SHAPE||p?b.fillRect(m[0],m[1],m[2],m[3]):q==e.ROUND_SHAPE||q==e.CARD_SHAPE?b.roundRect(m[0],m[1],m[2],m[3],this.round_radius,q==e.CARD_SHAPE?0:this.round_radius):q==e.CIRCLE_SHAPE&&b.arc(0.5*d[0],0.5*d[1],0.5*d[0],0,2*Math.PI);b.fill();a.flags.collapsed||(b.shadowColor="transparent",b.fillStyle=
|
||||
"rgba(0,0,0,0.2)",b.fillRect(0,-1,m[2],2));b.shadowColor="transparent";if(a.onDrawBackground)a.onDrawBackground(b,this,this.canvas);if(l||f==e.TRANSPARENT_TITLE){if(a.onDrawTitleBar)a.onDrawTitleBar(b,n,d,this.ds.scale,c);else if(f!=e.TRANSPARENT_TITLE&&(a.constructor.title_color||this.render_title_colored)){l=a.constructor.title_color||c;a.flags.collapsed&&(b.shadowColor=e.DEFAULT_SHADOW_COLOR);if(this.use_gradients){var u=k.gradients[l];u||(u=k.gradients[l]=b.createLinearGradient(0,0,400,0),u.addColorStop(0,
|
||||
l),u.addColorStop(1,"#000"));b.fillStyle=u}else b.fillStyle=l;b.beginPath();q==e.BOX_SHAPE||p?b.rect(0,-n,d[0]+1,n):q!=e.ROUND_SHAPE&&q!=e.CARD_SHAPE||b.roundRect(0,-n,d[0]+1,n,this.round_radius,a.flags.collapsed?this.round_radius:0);b.fill();b.shadowColor="transparent"}if(a.onDrawTitleBox)a.onDrawTitleBox(b,n,d,this.ds.scale);else q==e.ROUND_SHAPE||q==e.CIRCLE_SHAPE||q==e.CARD_SHAPE?(p&&(b.fillStyle="black",b.beginPath(),b.arc(0.5*n,-0.5*n,6,0,2*Math.PI),b.fill()),b.fillStyle=a.boxcolor||e.NODE_DEFAULT_BOXCOLOR,
|
||||
b.beginPath(),b.arc(0.5*n,-0.5*n,5,0,2*Math.PI),b.fill()):(p&&(b.fillStyle="black",b.fillRect(0.5*(n-10)-1,-0.5*(n+10)-1,12,12)),b.fillStyle=a.boxcolor||e.NODE_DEFAULT_BOXCOLOR,b.fillRect(0.5*(n-10),-0.5*(n+10),10,10));b.globalAlpha=g;if(a.onDrawTitleText)a.onDrawTitleText(b,n,d,this.ds.scale,this.title_text_font,h);!p&&(b.font=this.title_text_font,p=a.getTitle())&&(b.fillStyle=h?"white":a.constructor.title_text_color||this.node_title_color,a.flags.collapsed?(b.textAlign="center",g=b.measureText(p),
|
||||
b.fillText(p,n+0.5*g.width,e.NODE_TITLE_TEXT_Y-n),b.textAlign="left"):(b.textAlign="left",b.fillText(p,n,e.NODE_TITLE_TEXT_Y-n)));if(a.onDrawTitle)a.onDrawTitle(b)}if(h){if(a.onBounding)a.onBounding(m);f==e.TRANSPARENT_TITLE&&(m[1]-=n,m[3]+=n);b.lineWidth=1;b.globalAlpha=0.8;b.beginPath();q==e.BOX_SHAPE?b.rect(-6+m[0],-6+m[1],12+m[2],12+m[3]):q==e.ROUND_SHAPE||q==e.CARD_SHAPE&&a.flags.collapsed?b.roundRect(-6+m[0],-6+m[1],12+m[2],12+m[3],2*this.round_radius):q==e.CARD_SHAPE?b.roundRect(-6+m[0],-6+
|
||||
m[1],12+m[2],12+m[3],2*this.round_radius,2):q==e.CIRCLE_SHAPE&&b.arc(0.5*d[0],0.5*d[1],0.5*d[0]+6,0,2*Math.PI);b.strokeStyle="#FFF";b.stroke();b.strokeStyle=c;b.globalAlpha=1}};var C=new Float32Array(4),h=new Float32Array(4),q=new Float32Array(2),p=new Float32Array(2);k.prototype.drawConnections=function(a){var b=e.getTime(),d=this.visible_area;C[0]=d[0]-20;C[1]=d[1]-20;C[2]=d[2]+40;C[3]=d[3]+40;a.lineWidth=this.connections_width;a.fillStyle="#AAA";a.strokeStyle="#AAA";a.globalAlpha=this.editor_alpha;
|
||||
for(var d=this.graph._nodes,c=0,n=d.length;c<n;++c){var g=d[c];if(g.inputs&&g.inputs.length)for(var m=0;m<g.inputs.length;++m){var k=g.inputs[m];if(k&&null!=k.link&&(k=this.graph.links[k.link])){var f=this.graph.getNodeById(k.origin_id);if(null!=f){var l=k.origin_slot,u=null,u=-1==l?[f.pos[0]+10,f.pos[1]+10]:f.getConnectionPos(!1,l,q),x=g.getConnectionPos(!0,m,p);h[0]=u[0];h[1]=u[1];h[2]=x[0]-u[0];h[3]=x[1]-u[1];0>h[2]&&(h[0]+=h[2],h[2]=Math.abs(h[2]));0>h[3]&&(h[1]+=h[3],h[3]=Math.abs(h[3]));if(v(h,
|
||||
C)){var A=f.outputs[l],l=g.inputs[m];if(A&&l&&(f=A.dir||(f.horizontal?e.DOWN:e.RIGHT),l=l.dir||(g.horizontal?e.UP:e.LEFT),this.renderLink(a,u,x,k,!1,0,null,f,l),k&&k._last_time&&1E3>b-k._last_time)){var A=2-0.002*(b-k._last_time),J=a.globalAlpha;a.globalAlpha=J*A;this.renderLink(a,u,x,k,!0,A,"white",f,l);a.globalAlpha=J}}}}}}a.globalAlpha=1};k.prototype.renderLink=function(a,b,d,c,n,h,g,m,p,q){c&&this.visible_links.push(c);!g&&c&&(g=c.color||k.link_type_colors[c.type]);g||(g=this.default_link_color);
|
||||
null!=c&&this.highlighted_links[c.id]&&(g="#FFF");m=m||e.RIGHT;p=p||e.LEFT;var f=y(b,d);this.render_connections_border&&0.6<this.ds.scale&&(a.lineWidth=this.connections_width+4);a.lineJoin="round";q=q||1;1<q&&(a.lineWidth=0.5);a.beginPath();for(var l=0;l<q;l+=1){var A=5*(l-0.5*(q-1));if(this.links_render_mode==e.SPLINE_LINK){a.moveTo(b[0],b[1]+A);var u=0,x=0,v=0,r=0;switch(m){case e.LEFT:u=-0.25*f;break;case e.RIGHT:u=0.25*f;break;case e.UP:x=-0.25*f;break;case e.DOWN:x=0.25*f}switch(p){case e.LEFT:v=
|
||||
-0.25*f;break;case e.RIGHT:v=0.25*f;break;case e.UP:r=-0.25*f;break;case e.DOWN:r=0.25*f}a.bezierCurveTo(b[0]+u,b[1]+x+A,d[0]+v,d[1]+r+A,d[0],d[1]+A)}else if(this.links_render_mode==e.LINEAR_LINK){a.moveTo(b[0],b[1]+A);r=v=x=u=0;switch(m){case e.LEFT:u=-1;break;case e.RIGHT:u=1;break;case e.UP:x=-1;break;case e.DOWN:x=1}switch(p){case e.LEFT:v=-1;break;case e.RIGHT:v=1;break;case e.UP:r=-1;break;case e.DOWN:r=1}a.lineTo(b[0]+15*u,b[1]+15*x+A);a.lineTo(d[0]+15*v,d[1]+15*r+A);a.lineTo(d[0],d[1]+A)}else if(this.links_render_mode==
|
||||
e.STRAIGHT_LINK)a.moveTo(b[0],b[1]),A=b[0],u=b[1],x=d[0],v=d[1],m==e.RIGHT?A+=10:u+=10,p==e.LEFT?x-=10:v-=10,a.lineTo(A,u),a.lineTo(0.5*(A+x),u),a.lineTo(0.5*(A+x),v),a.lineTo(x,v),a.lineTo(d[0],d[1]);else return}this.render_connections_border&&0.6<this.ds.scale&&!n&&(a.strokeStyle="rgba(0,0,0,0.5)",a.stroke());a.lineWidth=this.connections_width;a.fillStyle=a.strokeStyle=g;a.stroke();n=this.computeConnectionPoint(b,d,0.5,m,p);c&&c._pos&&(c._pos[0]=n[0],c._pos[1]=n[1]);0.6<=this.ds.scale&&this.highquality_render&&
|
||||
p!=e.CENTER&&(this.render_connection_arrows&&(l=this.computeConnectionPoint(b,d,0.25,m,p),c=this.computeConnectionPoint(b,d,0.26,m,p),q=this.computeConnectionPoint(b,d,0.75,m,p),f=this.computeConnectionPoint(b,d,0.76,m,p),u=A=0,this.render_curved_connections?(A=-Math.atan2(c[0]-l[0],c[1]-l[1]),u=-Math.atan2(f[0]-q[0],f[1]-q[1])):u=A=d[1]>b[1]?0:Math.PI,a.save(),a.translate(l[0],l[1]),a.rotate(A),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore(),a.save(),a.translate(q[0],
|
||||
q[1]),a.rotate(u),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore()),a.beginPath(),a.arc(n[0],n[1],5,0,2*Math.PI),a.fill());if(h)for(a.fillStyle=g,l=0;5>l;++l)h=(0.001*e.getTime()+0.2*l)%1,n=this.computeConnectionPoint(b,d,h,m,p),a.beginPath(),a.arc(n[0],n[1],5,0,2*Math.PI),a.fill()};k.prototype.computeConnectionPoint=function(a,b,d,c,n){c=c||e.RIGHT;n=n||e.LEFT;var h=y(a,b),g=[a[0],a[1]],m=[b[0],b[1]];switch(c){case e.LEFT:g[0]+=-0.25*h;break;case e.RIGHT:g[0]+=0.25*
|
||||
h;break;case e.UP:g[1]+=-0.25*h;break;case e.DOWN:g[1]+=0.25*h}switch(n){case e.LEFT:m[0]+=-0.25*h;break;case e.RIGHT:m[0]+=0.25*h;break;case e.UP:m[1]+=-0.25*h;break;case e.DOWN:m[1]+=0.25*h}c=(1-d)*(1-d)*(1-d);n=3*(1-d)*(1-d)*d;h=3*(1-d)*d*d;d*=d*d;return[c*a[0]+n*g[0]+h*m[0]+d*b[0],c*a[1]+n*g[1]+h*m[1]+d*b[1]]};k.prototype.drawExecutionOrder=function(a){a.shadowColor="transparent";a.globalAlpha=0.25;a.textAlign="center";a.strokeStyle="white";a.globalAlpha=0.75;for(var b=this.visible_nodes,d=0;d<
|
||||
b.length;++d){var c=b[d];a.fillStyle="black";a.fillRect(c.pos[0]-e.NODE_TITLE_HEIGHT,c.pos[1]-e.NODE_TITLE_HEIGHT,e.NODE_TITLE_HEIGHT,e.NODE_TITLE_HEIGHT);0==c.order&&a.strokeRect(c.pos[0]-e.NODE_TITLE_HEIGHT+0.5,c.pos[1]-e.NODE_TITLE_HEIGHT+0.5,e.NODE_TITLE_HEIGHT,e.NODE_TITLE_HEIGHT);a.fillStyle="#FFF";a.fillText(c.order,c.pos[0]+-0.5*e.NODE_TITLE_HEIGHT,c.pos[1]-6)}a.globalAlpha=1};k.prototype.drawNodeWidgets=function(a,b,d,c){if(!a.widgets||!a.widgets.length)return 0;var n=a.size[0],h=a.widgets;
|
||||
b+=2;var g=e.NODE_WIDGET_HEIGHT,m=0.5<this.ds.scale;d.save();d.globalAlpha=this.editor_alpha;for(var k=e.WIDGET_OUTLINE_COLOR,p=e.WIDGET_BGCOLOR,q=e.WIDGET_TEXT_COLOR,f=e.WIDGET_SECONDARY_TEXT_COLOR,A=0;A<h.length;++A){var l=h[A],u=b;l.y&&(u=l.y);l.last_y=u;d.strokeStyle=k;d.fillStyle="#222";d.textAlign="left";switch(l.type){case "button":l.clicked&&(d.fillStyle="#AAA",l.clicked=!1,this.dirty_canvas=!0);d.fillRect(15,u,n-30,g);d.strokeRect(15,u,n-30,g);m&&(d.textAlign="center",d.fillStyle=q,d.fillText(l.name,
|
||||
0.5*n,u+0.7*g));break;case "toggle":d.textAlign="left";d.strokeStyle=k;d.fillStyle=p;d.beginPath();d.roundRect(15,b,n-30,g,0.5*g);d.fill();d.stroke();d.fillStyle=l.value?"#89A":"#333";d.beginPath();d.arc(n-30,u+0.5*g,0.36*g,0,2*Math.PI);d.fill();m&&(d.fillStyle=f,null!=l.name&&d.fillText(l.name,30,u+0.7*g),d.fillStyle=l.value?q:f,d.textAlign="right",d.fillText(l.value?l.options.on||"true":l.options.off||"false",n-40,u+0.7*g));break;case "slider":d.fillStyle=p;d.fillRect(15,u,n-30,g);var x=l.options.max-
|
||||
l.options.min,v=(l.value-l.options.min)/x;d.fillStyle=c==l?"#89A":"#678";d.fillRect(15,u,v*(n-30),g);d.strokeRect(15,u,n-30,g);l.marker&&(x=(l.marker-l.options.min)/x,d.fillStyle="#AA9",d.fillRect(15+x*(n-30),u,2,g));m&&(d.textAlign="center",d.fillStyle=q,d.fillText(l.name+" "+Number(l.value).toFixed(3),0.5*n,u+0.7*g));break;case "number":case "combo":d.textAlign="left";d.strokeStyle=k;d.fillStyle=p;d.beginPath();d.roundRect(15,b,n-30,g,0.5*g);d.fill();d.stroke();m&&(d.fillStyle=q,d.beginPath(),
|
||||
d.moveTo(31,b+5),d.lineTo(21,b+0.5*g),d.lineTo(31,b+g-5),d.fill(),d.beginPath(),d.moveTo(n-15-16,b+5),d.lineTo(n-15-6,b+0.5*g),d.lineTo(n-15-16,b+g-5),d.fill(),d.fillStyle=f,d.fillText(l.name,35,u+0.7*g),d.fillStyle=q,d.textAlign="right","number"==l.type?d.fillText(Number(l.value).toFixed(void 0!==l.options.precision?l.options.precision:3),n-30-20,u+0.7*g):d.fillText(l.value,n-30-20,u+0.7*g));break;case "string":case "text":d.textAlign="left";d.strokeStyle=k;d.fillStyle=p;d.beginPath();d.roundRect(15,
|
||||
b,n-30,g,0.5*g);d.fill();d.stroke();m&&(d.fillStyle=f,null!=l.name&&d.fillText(l.name,30,u+0.7*g),d.fillStyle=q,d.textAlign="right",d.fillText(l.value,n-30,u+0.7*g));break;default:l.draw&&l.draw(d,a,l,u,g)}b+=g+4}d.restore();d.textAlign="left"};k.prototype.processNodeWidgets=function(a,b,d,c){function n(e,c){e.value=c;e.options&&e.options.property&&void 0!==a.properties[e.options.property]&&a.setProperty(e.options.property,c);e.callback&&e.callback(e.value,k,a,b,d)}if(!a.widgets||!a.widgets.length)return null;
|
||||
for(var g=b[0]-a.pos[0],h=b[1]-a.pos[1],m=a.size[0],k=this,p=this.getCanvasWindow(),q=0;q<a.widgets.length;++q){var f=a.widgets[q];if(f==c||6<g&&g<m-12&&h>f.last_y&&h<f.last_y+e.NODE_WIDGET_HEIGHT){switch(f.type){case "button":if("mousemove"===d.type)break;f.callback&&setTimeout(function(){f.callback(f,k,a,b)},20);this.dirty_canvas=f.clicked=!0;break;case "slider":p=Math.clamp((g-10)/(m-20),0,1);f.value=f.options.min+(f.options.max-f.options.min)*p;f.callback&&setTimeout(function(){n(f,f.value)},
|
||||
20);this.dirty_canvas=!0;break;case "number":case "combo":if("mousemove"==d.type&&"number"==f.type)f.value+=0.1*d.deltaX*(f.options.step||1),null!=f.options.min&&f.value<f.options.min&&(f.value=f.options.min),null!=f.options.max&&f.value>f.options.max&&(f.value=f.options.max);else if("mousedown"==d.type)if((c=f.options.values)&&c.constructor===Function&&(c=f.options.values(f,a)),g=40>g?-1:g>m-40?1:0,"number"==f.type)f.value+=0.1*g*(f.options.step||1),null!=f.options.min&&f.value<f.options.min&&(f.value=
|
||||
f.options.min),null!=f.options.max&&f.value>f.options.max&&(f.value=f.options.max);else if(g)p=c.indexOf(f.value)+g,p>=c.length&&(p=0),0>p&&(p=c.length-1),f.value=c[p];else{new e.ContextMenu(c,{scale:Math.max(1,this.ds.scale),event:d,className:"dark",callback:l.bind(f)},p);var l=function(a,b,d){this.value=a;n(this,a);k.dirty_canvas=!0;return!1}}setTimeout(function(){n(this,this.value)}.bind(f),20);this.dirty_canvas=!0;break;case "toggle":"mousedown"==d.type&&(f.value=!f.value,f.callback&&setTimeout(function(){n(f,
|
||||
f.value)},20));break;case "string":case "text":"mousedown"==d.type&&this.prompt("Value",f.value,function(a){this.value=a;n(this,a)}.bind(f),d);break;default:f.mouse&&f.mouse(ctx,d,[g,h],a)}return f}}return null};k.prototype.drawGroups=function(a,b){if(this.graph){var d=this.graph._groups;b.save();b.globalAlpha=0.5*this.editor_alpha;for(var c=0;c<d.length;++c){var g=d[c];if(v(this.visible_area,g._bounding)){b.fillStyle=g.color||"#335";b.strokeStyle=g.color||"#335";var h=g._pos,m=g._size;b.globalAlpha=
|
||||
0.25*this.editor_alpha;b.beginPath();b.rect(h[0]+0.5,h[1]+0.5,m[0],m[1]);b.fill();b.globalAlpha=this.editor_alpha;b.stroke();b.beginPath();b.moveTo(h[0]+m[0],h[1]+m[1]);b.lineTo(h[0]+m[0]-10,h[1]+m[1]);b.lineTo(h[0]+m[0],h[1]+m[1]-10);b.fill();m=g.font_size||e.DEFAULT_GROUP_FONT_SIZE;b.font=m+"px Arial";b.fillText(g.title,h[0]+4,h[1]+m)}}b.restore()}};k.prototype.adjustNodesSize=function(){for(var a=this.graph._nodes,b=0;b<a.length;++b)a[b].size=a[b].computeSize();this.setDirty(!0,!0)};k.prototype.resize=
|
||||
function(a,b){if(!a&&!b){var d=this.canvas.parentNode;a=d.offsetWidth;b=d.offsetHeight}if(this.canvas.width!=a||this.canvas.height!=b)this.canvas.width=a,this.canvas.height=b,this.bgcanvas.width=this.canvas.width,this.bgcanvas.height=this.canvas.height,this.setDirty(!0,!0)};k.prototype.switchLiveMode=function(a){if(a){var b=this,d=this.live_mode?1.1:0.9;this.live_mode&&(this.live_mode=!1,this.editor_alpha=0.1);var e=setInterval(function(){b.editor_alpha*=d;b.dirty_canvas=!0;b.dirty_bgcanvas=!0;1>
|
||||
d&&0.01>b.editor_alpha&&(clearInterval(e),1>d&&(b.live_mode=!0));1<d&&0.99<b.editor_alpha&&(clearInterval(e),b.editor_alpha=1)},1)}else this.live_mode=!this.live_mode,this.dirty_bgcanvas=this.dirty_canvas=!0};k.prototype.onNodeSelectionChange=function(a){};k.prototype.touchHandler=function(a){var b=a.changedTouches[0],d="";switch(a.type){case "touchstart":d="mousedown";break;case "touchmove":d="mousemove";break;case "touchend":d="mouseup";break;default:return}var e=this.getCanvasWindow(),c=e.document.createEvent("MouseEvent");
|
||||
c.initMouseEvent(d,!0,!0,e,1,b.screenX,b.screenY,b.clientX,b.clientY,!1,!1,!1,!1,0,null);b.target.dispatchEvent(c);a.preventDefault()};k.onGroupAdd=function(a,b,d){a=k.active_canvas;a.getCanvasWindow();b=new e.LGraphGroup;b.pos=a.convertEventToCanvasOffset(d);a.graph.add(b)};k.onMenuAdd=function(a,b,d,c){function g(a,b){var d=c.getFirstEvent(),n=e.createNode(a.value);n&&(n.pos=h.convertEventToCanvasOffset(d),h.graph.add(n))}var h=k.active_canvas,m=h.getCanvasWindow();a=e.getNodeTypesCategories(h.filter);
|
||||
b=[];for(var f in a)a[f]&&b.push({value:a[f],content:a[f],has_submenu:!0});var p=new e.ContextMenu(b,{event:d,callback:function(a,b,d){a=e.getNodeTypesInCategory(a.value,h.filter);b=[];for(var c in a)a[c].skip_list||b.push({content:a[c].title,value:a[c].type});new e.ContextMenu(b,{event:d,callback:g,parentMenu:p},m);return!1},parentMenu:c},m);return!1};k.onMenuCollapseAll=function(){};k.onMenuNodeEdit=function(){};k.showMenuNodeOptionalInputs=function(a,b,d,c,g){function h(a,b,d){g&&(a.callback&&
|
||||
a.callback.call(m,g,a,b,d),a.value&&(g.addInput(a.value[0],a.value[1],a.value[2]),g.setDirtyCanvas(!0,!0)))}if(g){var m=this;a=k.active_canvas.getCanvasWindow();b=g.optional_inputs;g.onGetInputs&&(b=g.onGetInputs());var f=[];if(b)for(var p in b){var q=b[p];if(q){var l=q[0];q[2]&&q[2].label&&(l=q[2].label);l={content:l,value:q};q[1]==e.ACTION&&(l.className="event");f.push(l)}else f.push(null)}this.onMenuNodeInputs&&(f=this.onMenuNodeInputs(f));if(f.length)return new e.ContextMenu(f,{event:d,callback:h,
|
||||
parentMenu:c,node:g},a),!1}};k.showMenuNodeOptionalOutputs=function(a,b,d,c,g){function h(a,b,d){if(g&&(a.callback&&a.callback.call(m,g,a,b,d),a.value))if(d=a.value[1],!d||d.constructor!==Object&&d.constructor!==Array)g.addOutput(a.value[0],a.value[1],a.value[2]),g.setDirtyCanvas(!0,!0);else{a=[];for(var f in d)a.push({content:f,value:d[f]});new e.ContextMenu(a,{event:b,callback:h,parentMenu:c,node:g});return!1}}if(g){var m=this;a=k.active_canvas.getCanvasWindow();b=g.optional_outputs;g.onGetOutputs&&
|
||||
(b=g.onGetOutputs());var f=[];if(b)for(var p in b){var q=b[p];if(!q)f.push(null);else if(!g.flags||!g.flags.skip_repeated_outputs||-1==g.findOutputSlot(q[0])){var l=q[0];q[2]&&q[2].label&&(l=q[2].label);l={content:l,value:q};q[1]==e.EVENT&&(l.className="event");f.push(l)}}this.onMenuNodeOutputs&&(f=this.onMenuNodeOutputs(f));if(f.length)return new e.ContextMenu(f,{event:d,callback:h,parentMenu:c,node:g},a),!1}};k.onShowMenuNodeProperties=function(a,b,d,c,g){function h(a,b,d,e){g&&(b=this.getBoundingClientRect(),
|
||||
m.showEditPropertyValue(g,a.value,{position:[b.left,b.top]}))}if(g&&g.properties){var m=k.active_canvas;b=m.getCanvasWindow();var f=[],q;for(q in g.properties)a=void 0!==g.properties[q]?g.properties[q]:" ","object"==typeof a&&(a=JSON.stringify(a)),a=k.decodeHTML(a),f.push({content:"<span class='property_name'>"+q+"</span><span class='property_value'>"+a+"</span>",value:q});if(f.length)return new e.ContextMenu(f,{event:d,callback:h,parentMenu:c,allow_html:!0,node:g},b),!1}};k.decodeHTML=function(a){var b=
|
||||
document.createElement("div");b.innerText=a;return b.innerHTML};k.onResizeNode=function(a,b,d,e,c){c&&(c.size=c.computeSize(),c.setDirtyCanvas(!0,!0))};k.prototype.showLinkMenu=function(a,b){var d=this;console.log(a.data);new e.ContextMenu(["Delete"],{event:b,title:null!=a.data?a.data.constructor.name:null,callback:function(b){switch(b){case "Delete":d.graph.removeLink(a.id)}}});return!1};k.onShowPropertyEditor=function(a,b,d,e,c){function g(){var b=f.value;"Number"==a.type?b=Number(b):"Boolean"==
|
||||
a.type&&(b=Boolean(b));c[h]=b;m.parentNode&&m.parentNode.removeChild(m);c.setDirtyCanvas(!0,!0)}var h=a.property||"title";b=c[h];var m=document.createElement("div");m.className="graphdialog";m.innerHTML="<span class='name'></span><input autofocus type='text' class='value'/><button>OK</button>";m.querySelector(".name").innerText=h;var f=m.querySelector("input");f&&(f.value=b,f.addEventListener("blur",function(a){this.focus()}),f.addEventListener("keydown",function(a){13==a.keyCode&&(g(),a.preventDefault(),
|
||||
a.stopPropagation())}));b=k.active_canvas.canvas;d=b.getBoundingClientRect();var q=e=-20;d&&(e-=d.left,q-=d.top);event?(m.style.left=event.clientX+e+"px",m.style.top=event.clientY+q+"px"):(m.style.left=0.5*b.width+e+"px",m.style.top=0.5*b.height+q+"px");m.querySelector("button").addEventListener("click",g);b.parentNode.appendChild(m)};k.prototype.prompt=function(a,b,d,e){var c=this;a=a||"";var g=!1,h=document.createElement("div");h.className="graphdialog rounded";h.innerHTML="<span class='name'></span> <input autofocus type='text' class='value'/><button class='rounded'>OK</button>";
|
||||
h.close=function(){c.prompt_box=null;h.parentNode&&h.parentNode.removeChild(h)};1<this.ds.scale&&(h.style.transform="scale("+this.ds.scale+")");h.addEventListener("mouseleave",function(a){g||h.close()});c.prompt_box&&c.prompt_box.close();c.prompt_box=h;h.querySelector(".name").innerText=a;h.querySelector(".value").value=b;var m=h.querySelector("input");m.addEventListener("keydown",function(a){g=!0;if(27==a.keyCode)h.close();else if(13==a.keyCode)d&&d(this.value),h.close();else return;a.preventDefault();
|
||||
a.stopPropagation()});h.querySelector("button").addEventListener("click",function(a){d&&d(m.value);c.setDirty(!0);h.close()});a=k.active_canvas.canvas;b=a.getBoundingClientRect();var f=-20,q=-20;b&&(f-=b.left,q-=b.top);e?(h.style.left=e.clientX+f+"px",h.style.top=e.clientY+q+"px"):(h.style.left=0.5*a.width+f+"px",h.style.top=0.5*a.height+q+"px");a.parentNode.appendChild(h);setTimeout(function(){m.focus()},10);return h};k.search_limit=-1;k.prototype.showSearchBox=function(a){function b(b){if(b)if(g.onSearchBoxSelection)g.onSearchBoxSelection(b,
|
||||
a,A);else{var d=e.searchbox_extras[b.toLowerCase()];d&&(b=d.type);if(b=e.createNode(b))b.pos=A.convertEventToCanvasOffset(a),A.graph.add(b);if(d&&d.data){if(d.data.properties)for(var c in d.data.properties)b.addProperty(c,d.data.properties[c]);if(d.data.inputs)for(c in b.inputs=[],d.data.inputs)b.addOutput(d.data.inputs[c][0],d.data.inputs[c][1]);if(d.data.outputs)for(c in b.outputs=[],d.data.outputs)b.addOutput(d.data.outputs[c][0],d.data.outputs[c][1]);d.data.title&&(b.title=d.data.title);d.data.json&&
|
||||
b.configure(d.data.json)}}h.close()}function d(a){var b=l;l&&l.classList.remove("selected");l?(l=a?l.nextSibling:l.previousSibling)||(l=b):l=a?f.childNodes[0]:f.childNodes[f.childNodes.length];l&&(l.classList.add("selected"),l.scrollIntoView())}function c(){function a(d,e){var c=document.createElement("div");q||(q=d);c.innerText=d;c.dataset.type=escape(d);c.className="litegraph lite-search-item";e&&(c.className+=" "+e);c.addEventListener("click",function(a){b(unescape(this.dataset.type))});f.appendChild(c)}
|
||||
p=null;var d=u.value;q=null;f.innerHTML="";if(d)if(g.onSearchBox){var h=g.onSearchBox(f,d,A);if(h)for(var m=0;m<h.length;++m)a(h[m])}else{var h=0,d=d.toLowerCase(),l=A.filter||A.graph.filter;for(m in e.searchbox_extras){var t=e.searchbox_extras[m];if(-1!==t.desc.toLowerCase().indexOf(d)){var x=e.registered_node_types[t.type];if(!x||!x.filter||x.filter==l)if(a(t.desc,"searchbox_extra"),-1!==k.search_limit&&h++>k.search_limit)break}}t=null;if(Array.prototype.filter)t=Object.keys(e.registered_node_types).filter(v);
|
||||
else for(m in t=[],e.registered_node_types)v(m)&&t.push(m);for(m=0;m<t.length&&!(a(t[m]),-1!==k.search_limit&&h++>k.search_limit);m++);var v=function(a){var b=e.registered_node_types[a];return l&&b.filter!=l?!1:-1!==a.toLowerCase().indexOf(d)}}}var g=this,h=document.createElement("div");h.className="litegraph litesearchbox graphdialog rounded";h.innerHTML="<span class='name'>Search</span> <input autofocus type='text' class='value rounded'/><div class='helper'></div>";h.close=function(){g.search_box=
|
||||
null;document.body.focus();setTimeout(function(){g.canvas.focus()},20);h.parentNode&&h.parentNode.removeChild(h)};var m=null;1<this.ds.scale&&(h.style.transform="scale("+this.ds.scale+")");h.addEventListener("mouseenter",function(a){m&&(clearTimeout(m),m=null)});h.addEventListener("mouseleave",function(a){m=setTimeout(function(){h.close()},500)});g.search_box&&g.search_box.close();g.search_box=h;var f=h.querySelector(".helper"),q=null,p=null,l=null,u=h.querySelector("input");u&&(u.addEventListener("blur",
|
||||
function(a){this.focus()}),u.addEventListener("keydown",function(a){if(38==a.keyCode)d(!1);else if(40==a.keyCode)d(!0);else if(27==a.keyCode)h.close();else if(13==a.keyCode)l?b(l.innerHTML):q?b(q):h.close();else{p&&clearInterval(p);p=setTimeout(c,10);return}a.preventDefault();a.stopPropagation()}));var A=k.active_canvas,x=A.canvas,v=x.ownerDocument||document;v.fullscreenElement?v.fullscreenElement.appendChild(h):v.body.appendChild(h);x=x.getBoundingClientRect();v=(a?a.clientY:x.top+0.5*x.height)-
|
||||
20;h.style.left=(a?a.clientX:x.left+0.5*x.width)-80+"px";h.style.top=v+"px";u.focus();return h};k.prototype.showEditPropertyValue=function(a,b,d){function e(){c(p.value)}function c(d){"number"==typeof a.properties[b]&&(d=Number(d));if("array"==g||"object"==g)d=JSON.parse(d);a.properties[b]=d;a._graph&&a._graph._version++;if(a.onPropertyChanged)a.onPropertyChanged(b,d);k.close();a.setDirtyCanvas(!0,!0)}if(a&&void 0!==a.properties[b]){d=d||{};var g="string";null!==a.properties[b]&&(g=typeof a.properties[b]);
|
||||
var h=null;a.getPropertyInfo&&(h=a.getPropertyInfo(b));if(a.properties_info)for(var m=0;m<a.properties_info.length;++m)if(a.properties_info[m].name==b){h=a.properties_info[m];break}void 0!==h&&null!==h&&h.type&&(g=h.type);var f="";if("string"==g||"number"==g||"array"==g||"object"==g)f="<input autofocus type='text' class='value'/>";else if("enum"==g&&h.values){f="<select autofocus type='text' class='value'>";for(m in h.values)var q=h.values.constructor===Array?h.values[m]:m,f=f+("<option value='"+
|
||||
q+"' "+(q==a.properties[b]?"selected":"")+">"+h.values[m]+"</option>");f+="</select>"}else if("boolean"==g)f="<input autofocus type='checkbox' class='value' "+(a.properties[b]?"checked":"")+"/>";else{console.warn("unknown type: "+g);return}var k=this.createDialog("<span class='name'>"+b+"</span>"+f+"<button>OK</button>",d);if("enum"==g&&h.values){var p=k.querySelector("select");p.addEventListener("change",function(a){c(a.target.value)})}else if("boolean"==g)(p=k.querySelector("input"))&&p.addEventListener("click",
|
||||
function(a){c(!!p.checked)});else if(p=k.querySelector("input"))p.addEventListener("blur",function(a){this.focus()}),q=void 0!==a.properties[b]?a.properties[b]:"",q=JSON.stringify(q),p.value=q,p.addEventListener("keydown",function(a){13==a.keyCode&&(e(),a.preventDefault(),a.stopPropagation())});k.querySelector("button").addEventListener("click",e)}};k.prototype.createDialog=function(a,b){b=b||{};var d=document.createElement("div");d.className="graphdialog";d.innerHTML=a;var e=this.canvas.getBoundingClientRect(),
|
||||
c=-20,g=-20;e&&(c-=e.left,g-=e.top);b.position?(c+=b.position[0],g+=b.position[1]):b.event?(c+=b.event.clientX,g+=b.event.clientY):(c+=0.5*this.canvas.width,g+=0.5*this.canvas.height);d.style.left=c+"px";d.style.top=g+"px";this.canvas.parentNode.appendChild(d);d.close=function(){this.parentNode&&this.parentNode.removeChild(this)};return d};k.onMenuNodeCollapse=function(a,b,d,e,c){c.collapse()};k.onMenuNodePin=function(a,b,d,e,c){c.pin()};k.onMenuNodeMode=function(a,b,d,c,g){new e.ContextMenu(["Always",
|
||||
"On Event","On Trigger","Never"],{event:d,callback:function(a){if(g)switch(a){case "On Event":g.mode=e.ON_EVENT;break;case "On Trigger":g.mode=e.ON_TRIGGER;break;case "Never":g.mode=e.NEVER;break;default:g.mode=e.ALWAYS}},parentMenu:c,node:g});return!1};k.onMenuNodeColors=function(a,b,d,c,g){if(!g)throw"no node for color";b=[];b.push({value:null,content:"<span style='display: block; padding-left: 4px;'>No color</span>"});for(var h in k.node_colors)a=k.node_colors[h],a={value:h,content:"<span style='display: block; color: #999; padding-left: 4px; border-left: 8px solid "+
|
||||
a.color+"; background-color:"+a.bgcolor+"'>"+h+"</span>"},b.push(a);new e.ContextMenu(b,{event:d,callback:function(a){g&&((a=a.value?k.node_colors[a.value]:null)?g.constructor===e.LGraphGroup?g.color=a.groupcolor:(g.color=a.color,g.bgcolor=a.bgcolor):(delete g.color,delete g.bgcolor),g.setDirtyCanvas(!0,!0))},parentMenu:c,node:g});return!1};k.onMenuNodeShapes=function(a,b,d,c,g){if(!g)throw"no node passed";new e.ContextMenu(e.VALID_SHAPES,{event:d,callback:function(a){g&&(g.shape=a,g.setDirtyCanvas(!0))},
|
||||
parentMenu:c,node:g});return!1};k.onMenuNodeRemove=function(a,b,d,e,c){if(!c)throw"no node passed";!1!==c.removable&&(c.graph.remove(c),c.setDirtyCanvas(!0,!0))};k.onMenuNodeClone=function(a,b,d,e,c){!1!=c.clonable&&(a=c.clone())&&(a.pos=[c.pos[0]+5,c.pos[1]+5],c.graph.add(a),c.setDirtyCanvas(!0,!0))};k.node_colors={red:{color:"#322",bgcolor:"#533",groupcolor:"#A88"},brown:{color:"#332922",bgcolor:"#593930",groupcolor:"#b06634"},green:{color:"#232",bgcolor:"#353",groupcolor:"#8A8"},blue:{color:"#223",
|
||||
bgcolor:"#335",groupcolor:"#88A"},pale_blue:{color:"#2a363b",bgcolor:"#3f5159",groupcolor:"#3f789e"},cyan:{color:"#233",bgcolor:"#355",groupcolor:"#8AA"},purple:{color:"#323",bgcolor:"#535",groupcolor:"#a1309b"},yellow:{color:"#432",bgcolor:"#653",groupcolor:"#b58b2a"},black:{color:"#222",bgcolor:"#000",groupcolor:"#444"}};k.prototype.getCanvasMenuOptions=function(){var a=null;this.getMenuOptions?a=this.getMenuOptions():(a=[{content:"Add Node",has_submenu:!0,callback:k.onMenuAdd},{content:"Add Group",
|
||||
callback:k.onGroupAdd}],this._graph_stack&&0<this._graph_stack.length&&a.push(null,{content:"Close subgraph",callback:this.closeSubgraph.bind(this)}));if(this.getExtraMenuOptions){var b=this.getExtraMenuOptions(this,a);b&&(a=a.concat(b))}return a};k.prototype.getNodeMenuOptions=function(a){var b=null,b=a.getMenuOptions?a.getMenuOptions(this):[{content:"Inputs",has_submenu:!0,disabled:!0,callback:k.showMenuNodeOptionalInputs},{content:"Outputs",has_submenu:!0,disabled:!0,callback:k.showMenuNodeOptionalOutputs},
|
||||
null,{content:"Properties",has_submenu:!0,callback:k.onShowMenuNodeProperties},null,{content:"Title",callback:k.onShowPropertyEditor},{content:"Mode",has_submenu:!0,callback:k.onMenuNodeMode},{content:"Resize",callback:k.onResizeNode},{content:"Collapse",callback:k.onMenuNodeCollapse},{content:"Pin",callback:k.onMenuNodePin},{content:"Colors",has_submenu:!0,callback:k.onMenuNodeColors},{content:"Shapes",has_submenu:!0,callback:k.onMenuNodeShapes},null];if(a.onGetInputs){var d=a.onGetInputs();d&&d.length&&
|
||||
(b[0].disabled=!1)}a.onGetOutputs&&(d=a.onGetOutputs())&&d.length&&(b[1].disabled=!1);a.getExtraMenuOptions&&(d=a.getExtraMenuOptions(this))&&(d.push(null),b=d.concat(b));!1!==a.clonable&&b.push({content:"Clone",callback:k.onMenuNodeClone});!1!==a.removable&&b.push(null,{content:"Remove",callback:k.onMenuNodeRemove});if(a.graph&&a.graph.onGetNodeMenuOptions)a.graph.onGetNodeMenuOptions(b,a);return b};k.prototype.getGroupMenuOptions=function(a){return[{content:"Title",callback:k.onShowPropertyEditor},
|
||||
{content:"Color",has_submenu:!0,callback:k.onMenuNodeColors},{content:"Font size",property:"font_size",type:"Number",callback:k.onShowPropertyEditor},null,{content:"Remove",callback:k.onMenuNodeRemove}]};k.prototype.processContextMenu=function(a,b){var d=this,c=k.active_canvas.getCanvasWindow(),g=null,h={event:b,callback:function(b,c,e){if(b)if("Remove Slot"==b.content)b=b.slot,b.input?a.removeInput(b.slot):b.output&&a.removeOutput(b.slot);else if("Disconnect Links"==b.content)b=b.slot,b.output?a.disconnectOutput(b.slot):
|
||||
b.input&&a.disconnectInput(b.slot);else if("Rename Slot"==b.content){b=b.slot;var g=b.input?a.getInputInfo(b.slot):a.getOutputInfo(b.slot),h=d.createDialog("<span class='name'>Name</span><input autofocus type='text'/><button>OK</button>",c),m=h.querySelector("input");m&&g&&(m.value=g.label||"");h.querySelector("button").addEventListener("click",function(a){m.value&&(g&&(g.label=m.value),d.setDirty(!0));h.close()})}},extra:a};a&&(h.title=a.type);var m=null;a&&(m=a.getSlotInPosition(b.canvasX,b.canvasY),
|
||||
k.active_node=a);if(m){g=[];m&&m.output&&m.output.links&&m.output.links.length&&g.push({content:"Disconnect Links",slot:m});var f=m.input||m.output;g.push(f.locked?"Cannot remove":{content:"Remove Slot",slot:m});g.push(f.nameLocked?"Cannot rename":{content:"Rename Slot",slot:m});h.title=(m.input?m.input.type:m.output.type)||"*";m.input&&m.input.type==e.ACTION&&(h.title="Action");m.output&&m.output.type==e.EVENT&&(h.title="Event")}else a?g=this.getNodeMenuOptions(a):(g=this.getCanvasMenuOptions(),
|
||||
(m=this.graph.getGroupOnPos(b.canvasX,b.canvasY))&&g.push(null,{content:"Edit Group",has_submenu:!0,submenu:{title:"Group",extra:m,options:this.getGroupMenuOptions(m)}}));g&&new e.ContextMenu(g,h,c)};this.CanvasRenderingContext2D&&(CanvasRenderingContext2D.prototype.roundRect=function(a,b,d,c,e,g){void 0===e&&(e=5);void 0===g&&(g=e);this.moveTo(a+e,b);this.lineTo(a+d-e,b);this.quadraticCurveTo(a+d,b,a+d,b+e);this.lineTo(a+d,b+c-g);this.quadraticCurveTo(a+d,b+c,a+d-g,b+c);this.lineTo(a+g,b+c);this.quadraticCurveTo(a,
|
||||
b+c,a,b+c-g);this.lineTo(a,b+e);this.quadraticCurveTo(a,b,a+e,b)});e.compareObjects=function(a,b){for(var d in a)if(a[d]!=b[d])return!1;return!0};e.distance=y;e.colorToString=function(a){return"rgba("+Math.round(255*a[0]).toFixed()+","+Math.round(255*a[1]).toFixed()+","+Math.round(255*a[2]).toFixed()+","+(4==a.length?a[3].toFixed(2):"1.0")+")"};e.isInsideRectangle=u;e.growBounding=function(a,b,d){b<a[0]?a[0]=b:b>a[2]&&(a[2]=b);d<a[1]?a[1]=d:d>a[3]&&(a[3]=d)};e.isInsideBounding=function(a,b){return a[0]<
|
||||
b[0][0]||a[1]<b[0][1]||a[0]>b[1][0]||a[1]>b[1][1]?!1:!0};e.overlapBounding=v;e.hex2num=function(a){"#"==a.charAt(0)&&(a=a.slice(1));a=a.toUpperCase();for(var b=Array(3),d=0,c,e,g=0;6>g;g+=2)c="0123456789ABCDEF".indexOf(a.charAt(g)),e="0123456789ABCDEF".indexOf(a.charAt(g+1)),b[d]=16*c+e,d++;return b};e.num2hex=function(a){for(var b="#",d,c,e=0;3>e;e++)d=a[e]/16,c=a[e]%16,b+="0123456789ABCDEF".charAt(d)+"0123456789ABCDEF".charAt(c);return b};z.prototype.addItem=function(a,b,d){function c(a){var b=
|
||||
this.value;b&&b.has_submenu&&e.call(this,a)}function e(a){var b=this.value,c=!0;g.current_submenu&&g.current_submenu.close(a);if(d.callback){var h=d.callback.call(this,b,d,a,g,d.node);!0===h&&(c=!1)}if(b&&(b.callback&&!d.ignore_item_callbacks&&!0!==b.disabled&&(h=b.callback.call(this,b,d,a,g,d.extra),!0===h&&(c=!1)),b.submenu)){if(!b.submenu.options)throw"ContextMenu submenu needs options";new g.constructor(b.submenu.options,{callback:b.submenu.callback,event:a,parentMenu:g,ignore_item_callbacks:b.submenu.ignore_item_callbacks,
|
||||
title:b.submenu.title,extra:b.submenu.extra,autoopen:d.autoopen});c=!1}c&&!g.lock&&g.close()}var g=this;d=d||{};var h=document.createElement("div");h.className="litemenu-entry submenu";var m=!1;if(null===b)h.classList.add("separator");else{h.innerHTML=b&&b.title?b.title:a;if(h.value=b)b.disabled&&(m=!0,h.classList.add("disabled")),(b.submenu||b.has_submenu)&&h.classList.add("has_submenu");"function"==typeof b?(h.dataset.value=a,h.onclick_callback=b):h.dataset.value=b;b.className&&(h.className+=" "+
|
||||
b.className)}this.root.appendChild(h);m||h.addEventListener("click",e);d.autoopen&&h.addEventListener("mouseenter",c);return h};z.prototype.close=function(a,b){this.root.parentNode&&this.root.parentNode.removeChild(this.root);this.parentMenu&&!b&&(this.parentMenu.lock=!1,this.parentMenu.current_submenu=null,void 0===a?this.parentMenu.close():a&&!z.isCursorOverElement(a,this.parentMenu.root)&&z.trigger(this.parentMenu.root,"mouseleave",a));this.current_submenu&&this.current_submenu.close(a,!0);this.root.closing_timer&&
|
||||
clearTimeout(this.root.closing_timer)};z.trigger=function(a,b,d,c){var e=document.createEvent("CustomEvent");e.initCustomEvent(b,!0,!0,d);e.srcElement=c;a.dispatchEvent?a.dispatchEvent(e):a.__events&&a.__events.dispatchEvent(e);return e};z.prototype.getTopMenu=function(){return this.options.parentMenu?this.options.parentMenu.getTopMenu():this};z.prototype.getFirstEvent=function(){return this.options.parentMenu?this.options.parentMenu.getFirstEvent():this.options.event};z.isCursorOverElement=function(a,
|
||||
b){var d=a.clientX,c=a.clientY,e=b.getBoundingClientRect();return e?c>e.top&&c<e.top+e.height&&d>e.left&&d<e.left+e.width?!0:!1:!1};e.ContextMenu=z;e.closeAllContextMenus=function(a){a=a||window;a=a.document.querySelectorAll(".litecontextmenu");if(a.length){for(var b=[],d=0;d<a.length;d++)b.push(a[d]);for(d in b)b[d].close?b[d].close():b[d].parentNode&&b[d].parentNode.removeChild(b[d])}};e.extendClass=function(a,b){for(var d in b)a.hasOwnProperty(d)||(a[d]=b[d]);if(b.prototype)for(d in b.prototype)b.prototype.hasOwnProperty(d)&&
|
||||
!a.prototype.hasOwnProperty(d)&&(b.prototype.__lookupGetter__(d)?a.prototype.__defineGetter__(d,b.prototype.__lookupGetter__(d)):a.prototype[d]=b.prototype[d],b.prototype.__lookupSetter__(d)&&a.prototype.__defineSetter__(d,b.prototype.__lookupSetter__(d)))};e.getParameterNames=function(a){return(a+"").replace(/[/][/].*$/gm,"").replace(/\s+/g,"").replace(/[/][*][^/*]*[*][/]/g,"").split("){",1)[0].replace(/^[^(]*[(]/,"").replace(/=[^,]+/g,"").split(",").filter(Boolean)};Math.clamp=function(a,b,d){return b>
|
||||
a?b:d<a?d:a};"undefined"==typeof window||window.requestAnimationFrame||(window.requestAnimationFrame=window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(a){window.setTimeout(a,1E3/60)})})(this);"undefined"!=typeof exports&&(exports.LiteGraph=this.LiteGraph);
|
||||
b=0,d=a.length;b<d;++b){var e=a[b];if(e.is_selected){if(e.onDeselected)e.onDeselected();e.is_selected=!1;if(this.onNodeDeselected)this.onNodeDeselected(e)}}this.selected_nodes={};this.current_node=null;this.highlighted_links={};if(this.onSelectionChange)this.onSelectionChange(this.selected_nodes);this.setDirty(!0)}};k.prototype.deleteSelectedNodes=function(){for(var a in this.selected_nodes){var b=this.selected_nodes[a];this.graph.remove(b);if(this.onNodeDeselected)this.onNodeDeselected(b)}this.selected_nodes=
|
||||
{};this.current_node=null;this.highlighted_links={};this.setDirty(!0)};k.prototype.centerOnNode=function(a){this.ds.offset[0]=-a.pos[0]-0.5*a.size[0]+0.5*this.canvas.width/this.ds.scale;this.ds.offset[1]=-a.pos[1]-0.5*a.size[1]+0.5*this.canvas.height/this.ds.scale;this.setDirty(!0,!0)};k.prototype.adjustMouseEvent=function(a){if(this.canvas){var b=this.canvas.getBoundingClientRect();a.localX=a.clientX-b.left;a.localY=a.clientY-b.top}else a.localX=a.clientX,a.localY=a.clientY;a.deltaX=a.localX-this.last_mouse_position[0];
|
||||
a.deltaY=a.localY-this.last_mouse_position[1];this.last_mouse_position[0]=a.localX;this.last_mouse_position[1]=a.localY;a.canvasX=a.localX/this.ds.scale-this.ds.offset[0];a.canvasY=a.localY/this.ds.scale-this.ds.offset[1]};k.prototype.setZoom=function(a,b){this.ds.changeScale(a,b);this.dirty_bgcanvas=this.dirty_canvas=!0};k.prototype.convertOffsetToCanvas=function(a,b){return this.ds.convertOffsetToCanvas(a,b)};k.prototype.convertCanvasToOffset=function(a,b){return this.ds.convertCanvasToOffset(a,
|
||||
b)};k.prototype.convertEventToCanvasOffset=function(a){var b=this.canvas.getBoundingClientRect();return this.convertCanvasToOffset([a.clientX-b.left,a.clientY-b.top])};k.prototype.bringToFront=function(a){var b=this.graph._nodes.indexOf(a);-1!=b&&(this.graph._nodes.splice(b,1),this.graph._nodes.push(a))};k.prototype.sendToBack=function(a){var b=this.graph._nodes.indexOf(a);-1!=b&&(this.graph._nodes.splice(b,1),this.graph._nodes.unshift(a))};var x=new Float32Array(4);k.prototype.computeVisibleNodes=
|
||||
function(a,b){var d=b||[];d.length=0;a=a||this.graph._nodes;for(var e=0,c=a.length;e<c;++e){var h=a[e];(!this.live_mode||h.onDrawBackground||h.onDrawForeground)&&v(this.visible_area,h.getBounding(x))&&d.push(h)}return d};k.prototype.draw=function(a,b){if(this.canvas){var d=e.getTime();this.render_time=0.001*(d-this.last_draw_time);this.last_draw_time=d;this.graph&&this.ds.computeVisibleArea();(this.dirty_bgcanvas||b||this.always_render_background||this.graph&&this.graph._last_trigger_time&&1E3>d-
|
||||
this.graph._last_trigger_time)&&this.drawBackCanvas();(this.dirty_canvas||a)&&this.drawFrontCanvas();this.fps=this.render_time?1/this.render_time:0;this.frame+=1}};k.prototype.drawFrontCanvas=function(){this.dirty_canvas=!1;this.ctx||(this.ctx=this.bgcanvas.getContext("2d"));var a=this.ctx;if(a){a.start2D&&a.start2D();var b=this.canvas;a.restore();a.setTransform(1,0,0,1,0,0);this.dirty_area&&(a.save(),a.beginPath(),a.rect(this.dirty_area[0],this.dirty_area[1],this.dirty_area[2],this.dirty_area[3]),
|
||||
a.clip());this.clear_background&&a.clearRect(0,0,b.width,b.height);this.bgcanvas==this.canvas?this.drawBackCanvas():a.drawImage(this.bgcanvas,0,0);if(this.onRender)this.onRender(b,a);this.show_info&&this.renderInfo(a);if(this.graph){a.save();this.ds.toCanvasContext(a);for(var b=this.computeVisibleNodes(null,this.visible_nodes),d=0;d<b.length;++d){var c=b[d];a.save();a.translate(c.pos[0],c.pos[1]);this.drawNode(c,a);a.restore()}this.render_execution_order&&this.drawExecutionOrder(a);this.graph.config.links_ontop&&
|
||||
(this.live_mode||this.drawConnections(a));if(null!=this.connecting_pos){a.lineWidth=this.connections_width;b=null;switch(this.connecting_output.type){case e.EVENT:b=e.EVENT_LINK_COLOR;break;default:b=e.CONNECTING_LINK_COLOR}this.renderLink(a,this.connecting_pos,[this.canvas_mouse[0],this.canvas_mouse[1]],null,!1,null,b,this.connecting_output.dir||(this.connecting_node.horizontal?e.DOWN:e.RIGHT),e.CENTER);a.beginPath();this.connecting_output.type===e.EVENT||this.connecting_output.shape===e.BOX_SHAPE?
|
||||
a.rect(this.connecting_pos[0]-6+0.5,this.connecting_pos[1]-5+0.5,14,10):a.arc(this.connecting_pos[0],this.connecting_pos[1],4,0,2*Math.PI);a.fill();a.fillStyle="#ffcc00";this._highlight_input&&(a.beginPath(),a.arc(this._highlight_input[0],this._highlight_input[1],6,0,2*Math.PI),a.fill())}this.dragging_rectangle&&(a.strokeStyle="#FFF",a.strokeRect(this.dragging_rectangle[0],this.dragging_rectangle[1],this.dragging_rectangle[2],this.dragging_rectangle[3]));if(this.over_link_center&&this.render_link_tooltip)this.drawLinkTooltip(a,
|
||||
this.over_link_center);else if(this.onDrawLinkTooltip)this.onDrawLinkTooltip(a,null);if(this.onDrawForeground)this.onDrawForeground(a,this.visible_rect);a.restore()}if(this.onDrawOverlay)this.onDrawOverlay(a);this.dirty_area&&a.restore();a.finish2D&&a.finish2D()}};k.prototype.renderInfo=function(a,b,d){b=b||0;d=d||0;a.save();a.translate(b,d);a.font="10px Arial";a.fillStyle="#888";this.graph?(a.fillText("T: "+this.graph.globaltime.toFixed(2)+"s",5,13),a.fillText("I: "+this.graph.iteration,5,26),a.fillText("N: "+
|
||||
this.graph._nodes.length+" ["+this.visible_nodes.length+"]",5,39),a.fillText("V: "+this.graph._version,5,52),a.fillText("FPS:"+this.fps.toFixed(2),5,65)):a.fillText("No graph selected",5,13);a.restore()};k.prototype.drawBackCanvas=function(){var a=this.bgcanvas;if(a.width!=this.canvas.width||a.height!=this.canvas.height)a.width=this.canvas.width,a.height=this.canvas.height;this.bgctx||(this.bgctx=this.bgcanvas.getContext("2d"));var b=this.bgctx;b.start&&b.start();this.clear_background&&b.clearRect(0,
|
||||
0,a.width,a.height);if(this._graph_stack&&this._graph_stack.length){b.save();var d=this.graph._subgraph_node;b.strokeStyle=d.bgcolor;b.lineWidth=10;b.strokeRect(1,1,a.width-2,a.height-2);b.lineWidth=1;b.font="40px Arial";b.textAlign="center";b.fillStyle=d.bgcolor||"#AAA";for(var e="",c=1;c<this._graph_stack.length;++c)e+=this._graph_stack[c]._subgraph_node.getTitle()+" >> ";b.fillText(e+d.getTitle(),0.5*a.width,40);b.restore()}d=!1;this.onRenderBackground&&(d=this.onRenderBackground(a,b));b.restore();
|
||||
b.setTransform(1,0,0,1,0,0);this.visible_links.length=0;if(this.graph){b.save();this.ds.toCanvasContext(b);if(this.background_image&&0.5<this.ds.scale&&!d){b.globalAlpha=this.zoom_modify_alpha?(1-0.5/this.ds.scale)*this.editor_alpha:this.editor_alpha;b.imageSmoothingEnabled=b.mozImageSmoothingEnabled=b.imageSmoothingEnabled=!1;if(!this._bg_img||this._bg_img.name!=this.background_image){this._bg_img=new Image;this._bg_img.name=this.background_image;this._bg_img.src=this.background_image;var h=this;
|
||||
this._bg_img.onload=function(){h.draw(!0,!0)}}d=null;null==this._pattern&&0<this._bg_img.width?(d=b.createPattern(this._bg_img,"repeat"),this._pattern_img=this._bg_img,this._pattern=d):d=this._pattern;d&&(b.fillStyle=d,b.fillRect(this.visible_area[0],this.visible_area[1],this.visible_area[2],this.visible_area[3]),b.fillStyle="transparent");b.globalAlpha=1;b.imageSmoothingEnabled=b.mozImageSmoothingEnabled=b.imageSmoothingEnabled=!0}this.graph._groups.length&&!this.live_mode&&this.drawGroups(a,b);
|
||||
if(this.onDrawBackground)this.onDrawBackground(b,this.visible_area);this.onBackgroundRender&&(console.error("WARNING! onBackgroundRender deprecated, now is named onDrawBackground "),this.onBackgroundRender=null);this.render_canvas_border&&(b.strokeStyle="#235",b.strokeRect(0,0,a.width,a.height));this.render_connections_shadows?(b.shadowColor="#000",b.shadowOffsetX=0,b.shadowOffsetY=0,b.shadowBlur=6):b.shadowColor="rgba(0,0,0,0)";this.live_mode||this.drawConnections(b);b.shadowColor="rgba(0,0,0,0)";
|
||||
b.restore()}b.finish&&b.finish();this.dirty_bgcanvas=!1;this.dirty_canvas=!0};var g=new Float32Array(2);k.prototype.drawNode=function(a,b){this.current_node=a;var d=a.color||a.constructor.color||e.NODE_DEFAULT_COLOR,c=a.bgcolor||a.constructor.bgcolor||e.NODE_DEFAULT_BGCOLOR;if(this.live_mode){if(!a.flags.collapsed&&(b.shadowColor="transparent",a.onDrawForeground))a.onDrawForeground(b,this,this.canvas)}else{var n=this.editor_alpha;b.globalAlpha=n;this.render_shadows?(b.shadowColor=e.DEFAULT_SHADOW_COLOR,
|
||||
b.shadowOffsetX=2*this.ds.scale,b.shadowOffsetY=2*this.ds.scale,b.shadowBlur=3*this.ds.scale):b.shadowColor="transparent";if(!a.flags.collapsed||!a.onDrawCollapsed||!0!=a.onDrawCollapsed(b,this)){var h=a._shape||e.BOX_SHAPE;g.set(a.size);var m=a.horizontal;if(a.flags.collapsed){b.font=this.inner_text_font;var k=a.getTitle?a.getTitle():a.title;null!=k&&(a._collapsed_width=Math.min(a.size[0],b.measureText(k).width+2*e.NODE_TITLE_HEIGHT),g[0]=a._collapsed_width,g[1]=0)}a.clip_area&&(b.save(),b.beginPath(),
|
||||
h==e.BOX_SHAPE?b.rect(0,0,g[0],g[1]):h==e.ROUND_SHAPE?b.roundRect(0,0,g[0],g[1],10):h==e.CIRCLE_SHAPE&&b.arc(0.5*g[0],0.5*g[1],0.5*g[0],0,2*Math.PI),b.clip());a.has_errors&&(c="red");this.drawNodeShape(a,b,g,d,c,a.is_selected,a.mouseOver);b.shadowColor="transparent";if(a.onDrawForeground)a.onDrawForeground(b,this,this.canvas);b.textAlign=m?"center":"left";b.font=this.inner_text_font;c=0.6<this.ds.scale;h=this.connecting_output;b.lineWidth=1;var k=0,q=new Float32Array(2);if(!a.flags.collapsed){if(a.inputs)for(d=
|
||||
0;d<a.inputs.length;d++){var p=a.inputs[d];b.globalAlpha=n;this.connecting_node&&!e.isValidConnection(p.type,h.type)&&(b.globalAlpha=0.4*n);b.fillStyle=null!=p.link?p.color_on||this.default_connection_color.input_on:p.color_off||this.default_connection_color.input_off;var f=a.getConnectionPos(!0,d,q);f[0]-=a.pos[0];f[1]-=a.pos[1];k<f[1]+0.5*e.NODE_SLOT_HEIGHT&&(k=f[1]+0.5*e.NODE_SLOT_HEIGHT);b.beginPath();p.type===e.EVENT||p.shape===e.BOX_SHAPE?m?b.rect(f[0]-5+0.5,f[1]-8+0.5,10,14):b.rect(f[0]-6+
|
||||
0.5,f[1]-5+0.5,14,10):p.shape===e.ARROW_SHAPE?(b.moveTo(f[0]+8,f[1]+0.5),b.lineTo(f[0]-4,f[1]+6+0.5),b.lineTo(f[0]-4,f[1]-6+0.5),b.closePath()):b.arc(f[0],f[1],4,0,2*Math.PI);b.fill();if(c){var l=null!=p.label?p.label:p.name;l&&(b.fillStyle=e.NODE_TEXT_COLOR,m||p.dir==e.UP?b.fillText(l,f[0],f[1]-10):b.fillText(l,f[0]+10,f[1]+5))}}this.connecting_node&&(b.globalAlpha=0.4*n);b.textAlign=m?"center":"right";b.strokeStyle="black";if(a.outputs)for(d=0;d<a.outputs.length;d++)if(p=a.outputs[d],f=a.getConnectionPos(!1,
|
||||
d,q),f[0]-=a.pos[0],f[1]-=a.pos[1],k<f[1]+0.5*e.NODE_SLOT_HEIGHT&&(k=f[1]+0.5*e.NODE_SLOT_HEIGHT),b.fillStyle=p.links&&p.links.length?p.color_on||this.default_connection_color.output_on:p.color_off||this.default_connection_color.output_off,b.beginPath(),p.type===e.EVENT||p.shape===e.BOX_SHAPE?m?b.rect(f[0]-5+0.5,f[1]-8+0.5,10,14):b.rect(f[0]-6+0.5,f[1]-5+0.5,14,10):p.shape===e.ARROW_SHAPE?(b.moveTo(f[0]+8,f[1]+0.5),b.lineTo(f[0]-4,f[1]+6+0.5),b.lineTo(f[0]-4,f[1]-6+0.5),b.closePath()):b.arc(f[0],
|
||||
f[1],4,0,2*Math.PI),b.fill(),b.stroke(),c&&(l=null!=p.label?p.label:p.name))b.fillStyle=e.NODE_TEXT_COLOR,m||p.dir==e.DOWN?b.fillText(l,f[0],f[1]-8):b.fillText(l,f[0]-10,f[1]+5);b.textAlign="left";b.globalAlpha=1;if(a.widgets){if(m||a.widgets_up)k=2;this.drawNodeWidgets(a,k,b,this.node_widget&&this.node_widget[0]==a?this.node_widget[1]:null)}}else if(this.render_collapsed_slots){n=c=null;if(a.inputs)for(d=0;d<a.inputs.length;d++)if(p=a.inputs[d],null!=p.link){c=p;break}if(a.outputs)for(d=0;d<a.outputs.length;d++)p=
|
||||
a.outputs[d],p.links&&p.links.length&&(n=p);c&&(d=0,c=-0.5*e.NODE_TITLE_HEIGHT,m&&(d=0.5*a._collapsed_width,c=-e.NODE_TITLE_HEIGHT),b.fillStyle="#686",b.beginPath(),p.type===e.EVENT||p.shape===e.BOX_SHAPE?b.rect(d-7+0.5,c-4,14,8):p.shape===e.ARROW_SHAPE?(b.moveTo(d+8,c),b.lineTo(d+-4,c-4),b.lineTo(d+-4,c+4),b.closePath()):b.arc(d,c,4,0,2*Math.PI),b.fill());n&&(d=a._collapsed_width,c=-0.5*e.NODE_TITLE_HEIGHT,m&&(d=0.5*a._collapsed_width,c=0),b.fillStyle="#686",b.strokeStyle="black",b.beginPath(),p.type===
|
||||
e.EVENT||p.shape===e.BOX_SHAPE?b.rect(d-7+0.5,c-4,14,8):p.shape===e.ARROW_SHAPE?(b.moveTo(d+6,c),b.lineTo(d-6,c-4),b.lineTo(d-6,c+4),b.closePath()):b.arc(d,c,4,0,2*Math.PI),b.fill())}a.clip_area&&b.restore();b.globalAlpha=1}}};k.prototype.drawLinkTooltip=function(a,b){var d=b._pos;a.fillStyle="black";a.beginPath();a.arc(d[0],d[1],3,0,2*Math.PI);a.fill();if(null!=b.data&&(!this.onDrawLinkTooltip||!0!=this.onDrawLinkTooltip(a,b,this))){var e=b.data,c=null,c=e.constructor===Number?e.toFixed(2):e.constructor===
|
||||
String?'"'+e+'"':e.constructor===Boolean?String(e):e.toToolTip?e.toToolTip():"["+e.constructor.name+"]";null!=c&&(a.font="14px Courier New",e=a.measureText(c).width+20,a.shadowColor="black",a.shadowOffsetX=2,a.shadowOffsetY=2,a.shadowBlur=3,a.fillStyle="#454",a.beginPath(),a.roundRect(d[0]-0.5*e,d[1]-15-24,e,24,3,3),a.moveTo(d[0]-10,d[1]-15),a.lineTo(d[0]+10,d[1]-15),a.lineTo(d[0],d[1]-5),a.fill(),a.shadowColor="transparent",a.textAlign="center",a.fillStyle="#CEC",a.fillText(c,d[0],d[1]-15-24*0.3))}};
|
||||
var m=new Float32Array(4);k.prototype.drawNodeShape=function(a,b,d,c,n,h,g){b.strokeStyle=c;b.fillStyle=n;n=e.NODE_TITLE_HEIGHT;var p=0.5>this.ds.scale,q=a._shape||a.constructor.shape||e.ROUND_SHAPE,f=a.constructor.title_mode,l=!0;f==e.TRANSPARENT_TITLE?l=!1:f==e.AUTOHIDE_TITLE&&g&&(l=!0);m[0]=0;m[1]=l?-n:0;m[2]=d[0]+1;m[3]=l?d[1]+n:d[1];g=b.globalAlpha;b.beginPath();q==e.BOX_SHAPE||p?b.fillRect(m[0],m[1],m[2],m[3]):q==e.ROUND_SHAPE||q==e.CARD_SHAPE?b.roundRect(m[0],m[1],m[2],m[3],this.round_radius,
|
||||
q==e.CARD_SHAPE?0:this.round_radius):q==e.CIRCLE_SHAPE&&b.arc(0.5*d[0],0.5*d[1],0.5*d[0],0,2*Math.PI);b.fill();a.flags.collapsed||(b.shadowColor="transparent",b.fillStyle="rgba(0,0,0,0.2)",b.fillRect(0,-1,m[2],2));b.shadowColor="transparent";if(a.onDrawBackground)a.onDrawBackground(b,this,this.canvas);if(l||f==e.TRANSPARENT_TITLE){if(a.onDrawTitleBar)a.onDrawTitleBar(b,n,d,this.ds.scale,c);else if(f!=e.TRANSPARENT_TITLE&&(a.constructor.title_color||this.render_title_colored)){l=a.constructor.title_color||
|
||||
c;a.flags.collapsed&&(b.shadowColor=e.DEFAULT_SHADOW_COLOR);if(this.use_gradients){var u=k.gradients[l];u||(u=k.gradients[l]=b.createLinearGradient(0,0,400,0),u.addColorStop(0,l),u.addColorStop(1,"#000"));b.fillStyle=u}else b.fillStyle=l;b.beginPath();q==e.BOX_SHAPE||p?b.rect(0,-n,d[0]+1,n):q!=e.ROUND_SHAPE&&q!=e.CARD_SHAPE||b.roundRect(0,-n,d[0]+1,n,this.round_radius,a.flags.collapsed?this.round_radius:0);b.fill();b.shadowColor="transparent"}if(a.onDrawTitleBox)a.onDrawTitleBox(b,n,d,this.ds.scale);
|
||||
else q==e.ROUND_SHAPE||q==e.CIRCLE_SHAPE||q==e.CARD_SHAPE?(p&&(b.fillStyle="black",b.beginPath(),b.arc(0.5*n,-0.5*n,6,0,2*Math.PI),b.fill()),b.fillStyle=a.boxcolor||e.NODE_DEFAULT_BOXCOLOR,b.beginPath(),b.arc(0.5*n,-0.5*n,5,0,2*Math.PI),b.fill()):(p&&(b.fillStyle="black",b.fillRect(0.5*(n-10)-1,-0.5*(n+10)-1,12,12)),b.fillStyle=a.boxcolor||e.NODE_DEFAULT_BOXCOLOR,b.fillRect(0.5*(n-10),-0.5*(n+10),10,10));b.globalAlpha=g;if(a.onDrawTitleText)a.onDrawTitleText(b,n,d,this.ds.scale,this.title_text_font,
|
||||
h);!p&&(b.font=this.title_text_font,p=a.getTitle())&&(b.fillStyle=h?"white":a.constructor.title_text_color||this.node_title_color,a.flags.collapsed?(b.textAlign="center",g=b.measureText(p),b.fillText(p,n+0.5*g.width,e.NODE_TITLE_TEXT_Y-n),b.textAlign="left"):(b.textAlign="left",b.fillText(p,n,e.NODE_TITLE_TEXT_Y-n)));if(a.onDrawTitle)a.onDrawTitle(b)}if(h){if(a.onBounding)a.onBounding(m);f==e.TRANSPARENT_TITLE&&(m[1]-=n,m[3]+=n);b.lineWidth=1;b.globalAlpha=0.8;b.beginPath();q==e.BOX_SHAPE?b.rect(-6+
|
||||
m[0],-6+m[1],12+m[2],12+m[3]):q==e.ROUND_SHAPE||q==e.CARD_SHAPE&&a.flags.collapsed?b.roundRect(-6+m[0],-6+m[1],12+m[2],12+m[3],2*this.round_radius):q==e.CARD_SHAPE?b.roundRect(-6+m[0],-6+m[1],12+m[2],12+m[3],2*this.round_radius,2):q==e.CIRCLE_SHAPE&&b.arc(0.5*d[0],0.5*d[1],0.5*d[0]+6,0,2*Math.PI);b.strokeStyle="#FFF";b.stroke();b.strokeStyle=c;b.globalAlpha=1}};var C=new Float32Array(4),h=new Float32Array(4),q=new Float32Array(2),p=new Float32Array(2);k.prototype.drawConnections=function(a){var b=
|
||||
e.getTime(),d=this.visible_area;C[0]=d[0]-20;C[1]=d[1]-20;C[2]=d[2]+40;C[3]=d[3]+40;a.lineWidth=this.connections_width;a.fillStyle="#AAA";a.strokeStyle="#AAA";a.globalAlpha=this.editor_alpha;for(var d=this.graph._nodes,c=0,n=d.length;c<n;++c){var g=d[c];if(g.inputs&&g.inputs.length)for(var m=0;m<g.inputs.length;++m){var k=g.inputs[m];if(k&&null!=k.link&&(k=this.graph.links[k.link])){var f=this.graph.getNodeById(k.origin_id);if(null!=f){var l=k.origin_slot,u=null,u=-1==l?[f.pos[0]+10,f.pos[1]+10]:
|
||||
f.getConnectionPos(!1,l,q),x=g.getConnectionPos(!0,m,p);h[0]=u[0];h[1]=u[1];h[2]=x[0]-u[0];h[3]=x[1]-u[1];0>h[2]&&(h[0]+=h[2],h[2]=Math.abs(h[2]));0>h[3]&&(h[1]+=h[3],h[3]=Math.abs(h[3]));if(v(h,C)){var A=f.outputs[l],l=g.inputs[m];if(A&&l&&(f=A.dir||(f.horizontal?e.DOWN:e.RIGHT),l=l.dir||(g.horizontal?e.UP:e.LEFT),this.renderLink(a,u,x,k,!1,0,null,f,l),k&&k._last_time&&1E3>b-k._last_time)){var A=2-0.002*(b-k._last_time),J=a.globalAlpha;a.globalAlpha=J*A;this.renderLink(a,u,x,k,!0,A,"white",f,l);
|
||||
a.globalAlpha=J}}}}}}a.globalAlpha=1};k.prototype.renderLink=function(a,b,d,c,n,h,g,m,p,q){c&&this.visible_links.push(c);!g&&c&&(g=c.color||k.link_type_colors[c.type]);g||(g=this.default_link_color);null!=c&&this.highlighted_links[c.id]&&(g="#FFF");m=m||e.RIGHT;p=p||e.LEFT;var f=y(b,d);this.render_connections_border&&0.6<this.ds.scale&&(a.lineWidth=this.connections_width+4);a.lineJoin="round";q=q||1;1<q&&(a.lineWidth=0.5);a.beginPath();for(var l=0;l<q;l+=1){var A=5*(l-0.5*(q-1));if(this.links_render_mode==
|
||||
e.SPLINE_LINK){a.moveTo(b[0],b[1]+A);var u=0,x=0,v=0,r=0;switch(m){case e.LEFT:u=-0.25*f;break;case e.RIGHT:u=0.25*f;break;case e.UP:x=-0.25*f;break;case e.DOWN:x=0.25*f}switch(p){case e.LEFT:v=-0.25*f;break;case e.RIGHT:v=0.25*f;break;case e.UP:r=-0.25*f;break;case e.DOWN:r=0.25*f}a.bezierCurveTo(b[0]+u,b[1]+x+A,d[0]+v,d[1]+r+A,d[0],d[1]+A)}else if(this.links_render_mode==e.LINEAR_LINK){a.moveTo(b[0],b[1]+A);r=v=x=u=0;switch(m){case e.LEFT:u=-1;break;case e.RIGHT:u=1;break;case e.UP:x=-1;break;case e.DOWN:x=
|
||||
1}switch(p){case e.LEFT:v=-1;break;case e.RIGHT:v=1;break;case e.UP:r=-1;break;case e.DOWN:r=1}a.lineTo(b[0]+15*u,b[1]+15*x+A);a.lineTo(d[0]+15*v,d[1]+15*r+A);a.lineTo(d[0],d[1]+A)}else if(this.links_render_mode==e.STRAIGHT_LINK)a.moveTo(b[0],b[1]),A=b[0],u=b[1],x=d[0],v=d[1],m==e.RIGHT?A+=10:u+=10,p==e.LEFT?x-=10:v-=10,a.lineTo(A,u),a.lineTo(0.5*(A+x),u),a.lineTo(0.5*(A+x),v),a.lineTo(x,v),a.lineTo(d[0],d[1]);else return}this.render_connections_border&&0.6<this.ds.scale&&!n&&(a.strokeStyle="rgba(0,0,0,0.5)",
|
||||
a.stroke());a.lineWidth=this.connections_width;a.fillStyle=a.strokeStyle=g;a.stroke();n=this.computeConnectionPoint(b,d,0.5,m,p);c&&c._pos&&(c._pos[0]=n[0],c._pos[1]=n[1]);0.6<=this.ds.scale&&this.highquality_render&&p!=e.CENTER&&(this.render_connection_arrows&&(l=this.computeConnectionPoint(b,d,0.25,m,p),c=this.computeConnectionPoint(b,d,0.26,m,p),q=this.computeConnectionPoint(b,d,0.75,m,p),f=this.computeConnectionPoint(b,d,0.76,m,p),u=A=0,this.render_curved_connections?(A=-Math.atan2(c[0]-l[0],
|
||||
c[1]-l[1]),u=-Math.atan2(f[0]-q[0],f[1]-q[1])):u=A=d[1]>b[1]?0:Math.PI,a.save(),a.translate(l[0],l[1]),a.rotate(A),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore(),a.save(),a.translate(q[0],q[1]),a.rotate(u),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore()),a.beginPath(),a.arc(n[0],n[1],5,0,2*Math.PI),a.fill());if(h)for(a.fillStyle=g,l=0;5>l;++l)h=(0.001*e.getTime()+0.2*l)%1,n=this.computeConnectionPoint(b,d,h,m,p),a.beginPath(),a.arc(n[0],
|
||||
n[1],5,0,2*Math.PI),a.fill()};k.prototype.computeConnectionPoint=function(a,b,d,c,n){c=c||e.RIGHT;n=n||e.LEFT;var h=y(a,b),g=[a[0],a[1]],m=[b[0],b[1]];switch(c){case e.LEFT:g[0]+=-0.25*h;break;case e.RIGHT:g[0]+=0.25*h;break;case e.UP:g[1]+=-0.25*h;break;case e.DOWN:g[1]+=0.25*h}switch(n){case e.LEFT:m[0]+=-0.25*h;break;case e.RIGHT:m[0]+=0.25*h;break;case e.UP:m[1]+=-0.25*h;break;case e.DOWN:m[1]+=0.25*h}c=(1-d)*(1-d)*(1-d);n=3*(1-d)*(1-d)*d;h=3*(1-d)*d*d;d*=d*d;return[c*a[0]+n*g[0]+h*m[0]+d*b[0],
|
||||
c*a[1]+n*g[1]+h*m[1]+d*b[1]]};k.prototype.drawExecutionOrder=function(a){a.shadowColor="transparent";a.globalAlpha=0.25;a.textAlign="center";a.strokeStyle="white";a.globalAlpha=0.75;for(var b=this.visible_nodes,d=0;d<b.length;++d){var c=b[d];a.fillStyle="black";a.fillRect(c.pos[0]-e.NODE_TITLE_HEIGHT,c.pos[1]-e.NODE_TITLE_HEIGHT,e.NODE_TITLE_HEIGHT,e.NODE_TITLE_HEIGHT);0==c.order&&a.strokeRect(c.pos[0]-e.NODE_TITLE_HEIGHT+0.5,c.pos[1]-e.NODE_TITLE_HEIGHT+0.5,e.NODE_TITLE_HEIGHT,e.NODE_TITLE_HEIGHT);
|
||||
a.fillStyle="#FFF";a.fillText(c.order,c.pos[0]+-0.5*e.NODE_TITLE_HEIGHT,c.pos[1]-6)}a.globalAlpha=1};k.prototype.drawNodeWidgets=function(a,b,d,c){if(!a.widgets||!a.widgets.length)return 0;var n=a.size[0],h=a.widgets;b+=2;var g=e.NODE_WIDGET_HEIGHT,m=0.5<this.ds.scale;d.save();d.globalAlpha=this.editor_alpha;for(var k=e.WIDGET_OUTLINE_COLOR,p=e.WIDGET_BGCOLOR,q=e.WIDGET_TEXT_COLOR,f=e.WIDGET_SECONDARY_TEXT_COLOR,A=0;A<h.length;++A){var l=h[A],u=b;l.y&&(u=l.y);l.last_y=u;d.strokeStyle=k;d.fillStyle=
|
||||
"#222";d.textAlign="left";switch(l.type){case "button":l.clicked&&(d.fillStyle="#AAA",l.clicked=!1,this.dirty_canvas=!0);d.fillRect(15,u,n-30,g);d.strokeRect(15,u,n-30,g);m&&(d.textAlign="center",d.fillStyle=q,d.fillText(l.name,0.5*n,u+0.7*g));break;case "toggle":d.textAlign="left";d.strokeStyle=k;d.fillStyle=p;d.beginPath();d.roundRect(15,b,n-30,g,0.5*g);d.fill();d.stroke();d.fillStyle=l.value?"#89A":"#333";d.beginPath();d.arc(n-30,u+0.5*g,0.36*g,0,2*Math.PI);d.fill();m&&(d.fillStyle=f,null!=l.name&&
|
||||
d.fillText(l.name,30,u+0.7*g),d.fillStyle=l.value?q:f,d.textAlign="right",d.fillText(l.value?l.options.on||"true":l.options.off||"false",n-40,u+0.7*g));break;case "slider":d.fillStyle=p;d.fillRect(15,u,n-30,g);var x=l.options.max-l.options.min,v=(l.value-l.options.min)/x;d.fillStyle=c==l?"#89A":"#678";d.fillRect(15,u,v*(n-30),g);d.strokeRect(15,u,n-30,g);l.marker&&(x=(l.marker-l.options.min)/x,d.fillStyle="#AA9",d.fillRect(15+x*(n-30),u,2,g));m&&(d.textAlign="center",d.fillStyle=q,d.fillText(l.name+
|
||||
" "+Number(l.value).toFixed(3),0.5*n,u+0.7*g));break;case "number":case "combo":d.textAlign="left";d.strokeStyle=k;d.fillStyle=p;d.beginPath();d.roundRect(15,b,n-30,g,0.5*g);d.fill();d.stroke();m&&(d.fillStyle=q,d.beginPath(),d.moveTo(31,b+5),d.lineTo(21,b+0.5*g),d.lineTo(31,b+g-5),d.fill(),d.beginPath(),d.moveTo(n-15-16,b+5),d.lineTo(n-15-6,b+0.5*g),d.lineTo(n-15-16,b+g-5),d.fill(),d.fillStyle=f,d.fillText(l.name,35,u+0.7*g),d.fillStyle=q,d.textAlign="right","number"==l.type?d.fillText(Number(l.value).toFixed(void 0!==
|
||||
l.options.precision?l.options.precision:3),n-30-20,u+0.7*g):d.fillText(l.value,n-30-20,u+0.7*g));break;case "string":case "text":d.textAlign="left";d.strokeStyle=k;d.fillStyle=p;d.beginPath();d.roundRect(15,b,n-30,g,0.5*g);d.fill();d.stroke();m&&(d.fillStyle=f,null!=l.name&&d.fillText(l.name,30,u+0.7*g),d.fillStyle=q,d.textAlign="right",d.fillText(l.value,n-30,u+0.7*g));break;default:l.draw&&l.draw(d,a,l,u,g)}b+=g+4}d.restore();d.textAlign="left"};k.prototype.processNodeWidgets=function(a,b,d,c){function n(e,
|
||||
c){e.value=c;e.options&&e.options.property&&void 0!==a.properties[e.options.property]&&a.setProperty(e.options.property,c);e.callback&&e.callback(e.value,k,a,b,d)}if(!a.widgets||!a.widgets.length)return null;for(var g=b[0]-a.pos[0],h=b[1]-a.pos[1],m=a.size[0],k=this,p=this.getCanvasWindow(),q=0;q<a.widgets.length;++q){var f=a.widgets[q];if(f==c||6<g&&g<m-12&&h>f.last_y&&h<f.last_y+e.NODE_WIDGET_HEIGHT){switch(f.type){case "button":if("mousemove"===d.type)break;f.callback&&setTimeout(function(){f.callback(f,
|
||||
k,a,b)},20);this.dirty_canvas=f.clicked=!0;break;case "slider":p=Math.clamp((g-10)/(m-20),0,1);f.value=f.options.min+(f.options.max-f.options.min)*p;f.callback&&setTimeout(function(){n(f,f.value)},20);this.dirty_canvas=!0;break;case "number":case "combo":if("mousemove"==d.type&&"number"==f.type)f.value+=0.1*d.deltaX*(f.options.step||1),null!=f.options.min&&f.value<f.options.min&&(f.value=f.options.min),null!=f.options.max&&f.value>f.options.max&&(f.value=f.options.max);else if("mousedown"==d.type)if((c=
|
||||
f.options.values)&&c.constructor===Function&&(c=f.options.values(f,a)),g=40>g?-1:g>m-40?1:0,"number"==f.type)f.value+=0.1*g*(f.options.step||1),null!=f.options.min&&f.value<f.options.min&&(f.value=f.options.min),null!=f.options.max&&f.value>f.options.max&&(f.value=f.options.max);else if(g)p=c.indexOf(f.value)+g,p>=c.length&&(p=0),0>p&&(p=c.length-1),f.value=c[p];else{new e.ContextMenu(c,{scale:Math.max(1,this.ds.scale),event:d,className:"dark",callback:l.bind(f)},p);var l=function(a,b,d){this.value=
|
||||
a;n(this,a);k.dirty_canvas=!0;return!1}}setTimeout(function(){n(this,this.value)}.bind(f),20);this.dirty_canvas=!0;break;case "toggle":"mousedown"==d.type&&(f.value=!f.value,f.callback&&setTimeout(function(){n(f,f.value)},20));break;case "string":case "text":"mousedown"==d.type&&this.prompt("Value",f.value,function(a){this.value=a;n(this,a)}.bind(f),d);break;default:f.mouse&&f.mouse(ctx,d,[g,h],a)}return f}}return null};k.prototype.drawGroups=function(a,b){if(this.graph){var d=this.graph._groups;
|
||||
b.save();b.globalAlpha=0.5*this.editor_alpha;for(var c=0;c<d.length;++c){var g=d[c];if(v(this.visible_area,g._bounding)){b.fillStyle=g.color||"#335";b.strokeStyle=g.color||"#335";var h=g._pos,m=g._size;b.globalAlpha=0.25*this.editor_alpha;b.beginPath();b.rect(h[0]+0.5,h[1]+0.5,m[0],m[1]);b.fill();b.globalAlpha=this.editor_alpha;b.stroke();b.beginPath();b.moveTo(h[0]+m[0],h[1]+m[1]);b.lineTo(h[0]+m[0]-10,h[1]+m[1]);b.lineTo(h[0]+m[0],h[1]+m[1]-10);b.fill();m=g.font_size||e.DEFAULT_GROUP_FONT_SIZE;
|
||||
b.font=m+"px Arial";b.fillText(g.title,h[0]+4,h[1]+m)}}b.restore()}};k.prototype.adjustNodesSize=function(){for(var a=this.graph._nodes,b=0;b<a.length;++b)a[b].size=a[b].computeSize();this.setDirty(!0,!0)};k.prototype.resize=function(a,b){if(!a&&!b){var d=this.canvas.parentNode;a=d.offsetWidth;b=d.offsetHeight}if(this.canvas.width!=a||this.canvas.height!=b)this.canvas.width=a,this.canvas.height=b,this.bgcanvas.width=this.canvas.width,this.bgcanvas.height=this.canvas.height,this.setDirty(!0,!0)};k.prototype.switchLiveMode=
|
||||
function(a){if(a){var b=this,d=this.live_mode?1.1:0.9;this.live_mode&&(this.live_mode=!1,this.editor_alpha=0.1);var e=setInterval(function(){b.editor_alpha*=d;b.dirty_canvas=!0;b.dirty_bgcanvas=!0;1>d&&0.01>b.editor_alpha&&(clearInterval(e),1>d&&(b.live_mode=!0));1<d&&0.99<b.editor_alpha&&(clearInterval(e),b.editor_alpha=1)},1)}else this.live_mode=!this.live_mode,this.dirty_bgcanvas=this.dirty_canvas=!0};k.prototype.onNodeSelectionChange=function(a){};k.prototype.touchHandler=function(a){var b=a.changedTouches[0],
|
||||
d="";switch(a.type){case "touchstart":d="mousedown";break;case "touchmove":d="mousemove";break;case "touchend":d="mouseup";break;default:return}var e=this.getCanvasWindow(),c=e.document.createEvent("MouseEvent");c.initMouseEvent(d,!0,!0,e,1,b.screenX,b.screenY,b.clientX,b.clientY,!1,!1,!1,!1,0,null);b.target.dispatchEvent(c);a.preventDefault()};k.onGroupAdd=function(a,b,d){a=k.active_canvas;a.getCanvasWindow();b=new e.LGraphGroup;b.pos=a.convertEventToCanvasOffset(d);a.graph.add(b)};k.onMenuAdd=function(a,
|
||||
b,d,c){function g(a,b){var d=c.getFirstEvent(),n=e.createNode(a.value);n&&(n.pos=h.convertEventToCanvasOffset(d),h.graph.add(n))}var h=k.active_canvas,m=h.getCanvasWindow();a=e.getNodeTypesCategories(h.filter);b=[];for(var f in a)a[f]&&b.push({value:a[f],content:a[f],has_submenu:!0});var p=new e.ContextMenu(b,{event:d,callback:function(a,b,d){a=e.getNodeTypesInCategory(a.value,h.filter);b=[];for(var c in a)a[c].skip_list||b.push({content:a[c].title,value:a[c].type});new e.ContextMenu(b,{event:d,callback:g,
|
||||
parentMenu:p},m);return!1},parentMenu:c},m);return!1};k.onMenuCollapseAll=function(){};k.onMenuNodeEdit=function(){};k.showMenuNodeOptionalInputs=function(a,b,d,c,g){function h(a,b,d){g&&(a.callback&&a.callback.call(m,g,a,b,d),a.value&&(g.addInput(a.value[0],a.value[1],a.value[2]),g.setDirtyCanvas(!0,!0)))}if(g){var m=this;a=k.active_canvas.getCanvasWindow();b=g.optional_inputs;g.onGetInputs&&(b=g.onGetInputs());var f=[];if(b)for(var p in b){var q=b[p];if(q){var l=q[0];q[2]&&q[2].label&&(l=q[2].label);
|
||||
l={content:l,value:q};q[1]==e.ACTION&&(l.className="event");f.push(l)}else f.push(null)}this.onMenuNodeInputs&&(f=this.onMenuNodeInputs(f));if(f.length)return new e.ContextMenu(f,{event:d,callback:h,parentMenu:c,node:g},a),!1}};k.showMenuNodeOptionalOutputs=function(a,b,d,c,g){function h(a,b,d){if(g&&(a.callback&&a.callback.call(m,g,a,b,d),a.value))if(d=a.value[1],!d||d.constructor!==Object&&d.constructor!==Array)g.addOutput(a.value[0],a.value[1],a.value[2]),g.setDirtyCanvas(!0,!0);else{a=[];for(var f in d)a.push({content:f,
|
||||
value:d[f]});new e.ContextMenu(a,{event:b,callback:h,parentMenu:c,node:g});return!1}}if(g){var m=this;a=k.active_canvas.getCanvasWindow();b=g.optional_outputs;g.onGetOutputs&&(b=g.onGetOutputs());var f=[];if(b)for(var p in b){var q=b[p];if(!q)f.push(null);else if(!g.flags||!g.flags.skip_repeated_outputs||-1==g.findOutputSlot(q[0])){var l=q[0];q[2]&&q[2].label&&(l=q[2].label);l={content:l,value:q};q[1]==e.EVENT&&(l.className="event");f.push(l)}}this.onMenuNodeOutputs&&(f=this.onMenuNodeOutputs(f));
|
||||
if(f.length)return new e.ContextMenu(f,{event:d,callback:h,parentMenu:c,node:g},a),!1}};k.onShowMenuNodeProperties=function(a,b,d,c,g){function h(a,b,d,e){g&&(b=this.getBoundingClientRect(),m.showEditPropertyValue(g,a.value,{position:[b.left,b.top]}))}if(g&&g.properties){var m=k.active_canvas;b=m.getCanvasWindow();var f=[],q;for(q in g.properties)a=void 0!==g.properties[q]?g.properties[q]:" ","object"==typeof a&&(a=JSON.stringify(a)),a=k.decodeHTML(a),f.push({content:"<span class='property_name'>"+
|
||||
q+"</span><span class='property_value'>"+a+"</span>",value:q});if(f.length)return new e.ContextMenu(f,{event:d,callback:h,parentMenu:c,allow_html:!0,node:g},b),!1}};k.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};k.onResizeNode=function(a,b,d,e,c){c&&(c.size=c.computeSize(),c.setDirtyCanvas(!0,!0))};k.prototype.showLinkMenu=function(a,b){var d=this;console.log(a.data);new e.ContextMenu(["Delete"],{event:b,title:null!=a.data?a.data.constructor.name:null,
|
||||
callback:function(b){switch(b){case "Delete":d.graph.removeLink(a.id)}}});return!1};k.onShowPropertyEditor=function(a,b,d,e,c){function g(){var b=f.value;"Number"==a.type?b=Number(b):"Boolean"==a.type&&(b=Boolean(b));c[h]=b;m.parentNode&&m.parentNode.removeChild(m);c.setDirtyCanvas(!0,!0)}var h=a.property||"title";b=c[h];var m=document.createElement("div");m.className="graphdialog";m.innerHTML="<span class='name'></span><input autofocus type='text' class='value'/><button>OK</button>";m.querySelector(".name").innerText=
|
||||
h;var f=m.querySelector("input");f&&(f.value=b,f.addEventListener("blur",function(a){this.focus()}),f.addEventListener("keydown",function(a){13==a.keyCode&&(g(),a.preventDefault(),a.stopPropagation())}));b=k.active_canvas.canvas;d=b.getBoundingClientRect();var q=e=-20;d&&(e-=d.left,q-=d.top);event?(m.style.left=event.clientX+e+"px",m.style.top=event.clientY+q+"px"):(m.style.left=0.5*b.width+e+"px",m.style.top=0.5*b.height+q+"px");m.querySelector("button").addEventListener("click",g);b.parentNode.appendChild(m)};
|
||||
k.prototype.prompt=function(a,b,d,e){var c=this;a=a||"";var g=!1,h=document.createElement("div");h.className="graphdialog rounded";h.innerHTML="<span class='name'></span> <input autofocus type='text' class='value'/><button class='rounded'>OK</button>";h.close=function(){c.prompt_box=null;h.parentNode&&h.parentNode.removeChild(h)};1<this.ds.scale&&(h.style.transform="scale("+this.ds.scale+")");h.addEventListener("mouseleave",function(a){g||h.close()});c.prompt_box&&c.prompt_box.close();c.prompt_box=
|
||||
h;h.querySelector(".name").innerText=a;h.querySelector(".value").value=b;var m=h.querySelector("input");m.addEventListener("keydown",function(a){g=!0;if(27==a.keyCode)h.close();else if(13==a.keyCode)d&&d(this.value),h.close();else return;a.preventDefault();a.stopPropagation()});h.querySelector("button").addEventListener("click",function(a){d&&d(m.value);c.setDirty(!0);h.close()});a=k.active_canvas.canvas;b=a.getBoundingClientRect();var f=-20,q=-20;b&&(f-=b.left,q-=b.top);e?(h.style.left=e.clientX+
|
||||
f+"px",h.style.top=e.clientY+q+"px"):(h.style.left=0.5*a.width+f+"px",h.style.top=0.5*a.height+q+"px");a.parentNode.appendChild(h);setTimeout(function(){m.focus()},10);return h};k.search_limit=-1;k.prototype.showSearchBox=function(a){function b(b){if(b)if(g.onSearchBoxSelection)g.onSearchBoxSelection(b,a,A);else{var d=e.searchbox_extras[b.toLowerCase()];d&&(b=d.type);if(b=e.createNode(b))b.pos=A.convertEventToCanvasOffset(a),A.graph.add(b);if(d&&d.data){if(d.data.properties)for(var c in d.data.properties)b.addProperty(c,
|
||||
d.data.properties[c]);if(d.data.inputs)for(c in b.inputs=[],d.data.inputs)b.addOutput(d.data.inputs[c][0],d.data.inputs[c][1]);if(d.data.outputs)for(c in b.outputs=[],d.data.outputs)b.addOutput(d.data.outputs[c][0],d.data.outputs[c][1]);d.data.title&&(b.title=d.data.title);d.data.json&&b.configure(d.data.json)}}h.close()}function d(a){var b=l;l&&l.classList.remove("selected");l?(l=a?l.nextSibling:l.previousSibling)||(l=b):l=a?f.childNodes[0]:f.childNodes[f.childNodes.length];l&&(l.classList.add("selected"),
|
||||
l.scrollIntoView())}function c(){function a(d,e){var c=document.createElement("div");q||(q=d);c.innerText=d;c.dataset.type=escape(d);c.className="litegraph lite-search-item";e&&(c.className+=" "+e);c.addEventListener("click",function(a){b(unescape(this.dataset.type))});f.appendChild(c)}p=null;var d=u.value;q=null;f.innerHTML="";if(d)if(g.onSearchBox){var h=g.onSearchBox(f,d,A);if(h)for(var m=0;m<h.length;++m)a(h[m])}else{var h=0,d=d.toLowerCase(),l=A.filter||A.graph.filter;for(m in e.searchbox_extras){var t=
|
||||
e.searchbox_extras[m];if(-1!==t.desc.toLowerCase().indexOf(d)){var x=e.registered_node_types[t.type];if(!x||!x.filter||x.filter==l)if(a(t.desc,"searchbox_extra"),-1!==k.search_limit&&h++>k.search_limit)break}}t=null;if(Array.prototype.filter)t=Object.keys(e.registered_node_types).filter(v);else for(m in t=[],e.registered_node_types)v(m)&&t.push(m);for(m=0;m<t.length&&!(a(t[m]),-1!==k.search_limit&&h++>k.search_limit);m++);var v=function(a){var b=e.registered_node_types[a];return l&&b.filter!=l?!1:
|
||||
-1!==a.toLowerCase().indexOf(d)}}}var g=this,h=document.createElement("div");h.className="litegraph litesearchbox graphdialog rounded";h.innerHTML="<span class='name'>Search</span> <input autofocus type='text' class='value rounded'/><div class='helper'></div>";h.close=function(){g.search_box=null;document.body.focus();setTimeout(function(){g.canvas.focus()},20);h.parentNode&&h.parentNode.removeChild(h)};var m=null;1<this.ds.scale&&(h.style.transform="scale("+this.ds.scale+")");h.addEventListener("mouseenter",
|
||||
function(a){m&&(clearTimeout(m),m=null)});h.addEventListener("mouseleave",function(a){m=setTimeout(function(){h.close()},500)});g.search_box&&g.search_box.close();g.search_box=h;var f=h.querySelector(".helper"),q=null,p=null,l=null,u=h.querySelector("input");u&&(u.addEventListener("blur",function(a){this.focus()}),u.addEventListener("keydown",function(a){if(38==a.keyCode)d(!1);else if(40==a.keyCode)d(!0);else if(27==a.keyCode)h.close();else if(13==a.keyCode)l?b(l.innerHTML):q?b(q):h.close();else{p&&
|
||||
clearInterval(p);p=setTimeout(c,10);return}a.preventDefault();a.stopPropagation()}));var A=k.active_canvas,x=A.canvas,v=x.ownerDocument||document;v.fullscreenElement?v.fullscreenElement.appendChild(h):v.body.appendChild(h);x=x.getBoundingClientRect();v=(a?a.clientY:x.top+0.5*x.height)-20;h.style.left=(a?a.clientX:x.left+0.5*x.width)-80+"px";h.style.top=v+"px";u.focus();return h};k.prototype.showEditPropertyValue=function(a,b,d){function e(){c(p.value)}function c(d){"number"==typeof a.properties[b]&&
|
||||
(d=Number(d));if("array"==g||"object"==g)d=JSON.parse(d);a.properties[b]=d;a._graph&&a._graph._version++;if(a.onPropertyChanged)a.onPropertyChanged(b,d);k.close();a.setDirtyCanvas(!0,!0)}if(a&&void 0!==a.properties[b]){d=d||{};var g="string";null!==a.properties[b]&&(g=typeof a.properties[b]);var h=null;a.getPropertyInfo&&(h=a.getPropertyInfo(b));if(a.properties_info)for(var m=0;m<a.properties_info.length;++m)if(a.properties_info[m].name==b){h=a.properties_info[m];break}void 0!==h&&null!==h&&h.type&&
|
||||
(g=h.type);var f="";if("string"==g||"number"==g||"array"==g||"object"==g)f="<input autofocus type='text' class='value'/>";else if("enum"==g&&h.values){f="<select autofocus type='text' class='value'>";for(m in h.values)var q=h.values.constructor===Array?h.values[m]:m,f=f+("<option value='"+q+"' "+(q==a.properties[b]?"selected":"")+">"+h.values[m]+"</option>");f+="</select>"}else if("boolean"==g)f="<input autofocus type='checkbox' class='value' "+(a.properties[b]?"checked":"")+"/>";else{console.warn("unknown type: "+
|
||||
g);return}var k=this.createDialog("<span class='name'>"+b+"</span>"+f+"<button>OK</button>",d);if("enum"==g&&h.values){var p=k.querySelector("select");p.addEventListener("change",function(a){c(a.target.value)})}else if("boolean"==g)(p=k.querySelector("input"))&&p.addEventListener("click",function(a){c(!!p.checked)});else if(p=k.querySelector("input"))p.addEventListener("blur",function(a){this.focus()}),q=void 0!==a.properties[b]?a.properties[b]:"",q=JSON.stringify(q),p.value=q,p.addEventListener("keydown",
|
||||
function(a){13==a.keyCode&&(e(),a.preventDefault(),a.stopPropagation())});k.querySelector("button").addEventListener("click",e)}};k.prototype.createDialog=function(a,b){b=b||{};var d=document.createElement("div");d.className="graphdialog";d.innerHTML=a;var e=this.canvas.getBoundingClientRect(),c=-20,g=-20;e&&(c-=e.left,g-=e.top);b.position?(c+=b.position[0],g+=b.position[1]):b.event?(c+=b.event.clientX,g+=b.event.clientY):(c+=0.5*this.canvas.width,g+=0.5*this.canvas.height);d.style.left=c+"px";d.style.top=
|
||||
g+"px";this.canvas.parentNode.appendChild(d);d.close=function(){this.parentNode&&this.parentNode.removeChild(this)};return d};k.onMenuNodeCollapse=function(a,b,d,e,c){c.collapse()};k.onMenuNodePin=function(a,b,d,e,c){c.pin()};k.onMenuNodeMode=function(a,b,d,c,g){new e.ContextMenu(["Always","On Event","On Trigger","Never"],{event:d,callback:function(a){if(g)switch(a){case "On Event":g.mode=e.ON_EVENT;break;case "On Trigger":g.mode=e.ON_TRIGGER;break;case "Never":g.mode=e.NEVER;break;default:g.mode=
|
||||
e.ALWAYS}},parentMenu:c,node:g});return!1};k.onMenuNodeColors=function(a,b,d,c,g){if(!g)throw"no node for color";b=[];b.push({value:null,content:"<span style='display: block; padding-left: 4px;'>No color</span>"});for(var h in k.node_colors)a=k.node_colors[h],a={value:h,content:"<span style='display: block; color: #999; padding-left: 4px; border-left: 8px solid "+a.color+"; background-color:"+a.bgcolor+"'>"+h+"</span>"},b.push(a);new e.ContextMenu(b,{event:d,callback:function(a){g&&((a=a.value?k.node_colors[a.value]:
|
||||
null)?g.constructor===e.LGraphGroup?g.color=a.groupcolor:(g.color=a.color,g.bgcolor=a.bgcolor):(delete g.color,delete g.bgcolor),g.setDirtyCanvas(!0,!0))},parentMenu:c,node:g});return!1};k.onMenuNodeShapes=function(a,b,d,c,g){if(!g)throw"no node passed";new e.ContextMenu(e.VALID_SHAPES,{event:d,callback:function(a){g&&(g.shape=a,g.setDirtyCanvas(!0))},parentMenu:c,node:g});return!1};k.onMenuNodeRemove=function(a,b,d,e,c){if(!c)throw"no node passed";!1!==c.removable&&(c.graph.remove(c),c.setDirtyCanvas(!0,
|
||||
!0))};k.onMenuNodeClone=function(a,b,d,e,c){!1!=c.clonable&&(a=c.clone())&&(a.pos=[c.pos[0]+5,c.pos[1]+5],c.graph.add(a),c.setDirtyCanvas(!0,!0))};k.node_colors={red:{color:"#322",bgcolor:"#533",groupcolor:"#A88"},brown:{color:"#332922",bgcolor:"#593930",groupcolor:"#b06634"},green:{color:"#232",bgcolor:"#353",groupcolor:"#8A8"},blue:{color:"#223",bgcolor:"#335",groupcolor:"#88A"},pale_blue:{color:"#2a363b",bgcolor:"#3f5159",groupcolor:"#3f789e"},cyan:{color:"#233",bgcolor:"#355",groupcolor:"#8AA"},
|
||||
purple:{color:"#323",bgcolor:"#535",groupcolor:"#a1309b"},yellow:{color:"#432",bgcolor:"#653",groupcolor:"#b58b2a"},black:{color:"#222",bgcolor:"#000",groupcolor:"#444"}};k.prototype.getCanvasMenuOptions=function(){var a=null;this.getMenuOptions?a=this.getMenuOptions():(a=[{content:"Add Node",has_submenu:!0,callback:k.onMenuAdd},{content:"Add Group",callback:k.onGroupAdd}],this._graph_stack&&0<this._graph_stack.length&&a.push(null,{content:"Close subgraph",callback:this.closeSubgraph.bind(this)}));
|
||||
if(this.getExtraMenuOptions){var b=this.getExtraMenuOptions(this,a);b&&(a=a.concat(b))}return a};k.prototype.getNodeMenuOptions=function(a){var b=null,b=a.getMenuOptions?a.getMenuOptions(this):[{content:"Inputs",has_submenu:!0,disabled:!0,callback:k.showMenuNodeOptionalInputs},{content:"Outputs",has_submenu:!0,disabled:!0,callback:k.showMenuNodeOptionalOutputs},null,{content:"Properties",has_submenu:!0,callback:k.onShowMenuNodeProperties},null,{content:"Title",callback:k.onShowPropertyEditor},{content:"Mode",
|
||||
has_submenu:!0,callback:k.onMenuNodeMode},{content:"Resize",callback:k.onResizeNode},{content:"Collapse",callback:k.onMenuNodeCollapse},{content:"Pin",callback:k.onMenuNodePin},{content:"Colors",has_submenu:!0,callback:k.onMenuNodeColors},{content:"Shapes",has_submenu:!0,callback:k.onMenuNodeShapes},null];if(a.onGetInputs){var d=a.onGetInputs();d&&d.length&&(b[0].disabled=!1)}a.onGetOutputs&&(d=a.onGetOutputs())&&d.length&&(b[1].disabled=!1);a.getExtraMenuOptions&&(d=a.getExtraMenuOptions(this))&&
|
||||
(d.push(null),b=d.concat(b));!1!==a.clonable&&b.push({content:"Clone",callback:k.onMenuNodeClone});!1!==a.removable&&b.push(null,{content:"Remove",callback:k.onMenuNodeRemove});if(a.graph&&a.graph.onGetNodeMenuOptions)a.graph.onGetNodeMenuOptions(b,a);return b};k.prototype.getGroupMenuOptions=function(a){return[{content:"Title",callback:k.onShowPropertyEditor},{content:"Color",has_submenu:!0,callback:k.onMenuNodeColors},{content:"Font size",property:"font_size",type:"Number",callback:k.onShowPropertyEditor},
|
||||
null,{content:"Remove",callback:k.onMenuNodeRemove}]};k.prototype.processContextMenu=function(a,b){var d=this,c=k.active_canvas.getCanvasWindow(),g=null,h={event:b,callback:function(b,c,e){if(b)if("Remove Slot"==b.content)b=b.slot,b.input?a.removeInput(b.slot):b.output&&a.removeOutput(b.slot);else if("Disconnect Links"==b.content)b=b.slot,b.output?a.disconnectOutput(b.slot):b.input&&a.disconnectInput(b.slot);else if("Rename Slot"==b.content){b=b.slot;var g=b.input?a.getInputInfo(b.slot):a.getOutputInfo(b.slot),
|
||||
h=d.createDialog("<span class='name'>Name</span><input autofocus type='text'/><button>OK</button>",c),m=h.querySelector("input");m&&g&&(m.value=g.label||"");h.querySelector("button").addEventListener("click",function(a){m.value&&(g&&(g.label=m.value),d.setDirty(!0));h.close()})}},extra:a};a&&(h.title=a.type);var m=null;a&&(m=a.getSlotInPosition(b.canvasX,b.canvasY),k.active_node=a);if(m){g=[];m&&m.output&&m.output.links&&m.output.links.length&&g.push({content:"Disconnect Links",slot:m});var f=m.input||
|
||||
m.output;g.push(f.locked?"Cannot remove":{content:"Remove Slot",slot:m});g.push(f.nameLocked?"Cannot rename":{content:"Rename Slot",slot:m});h.title=(m.input?m.input.type:m.output.type)||"*";m.input&&m.input.type==e.ACTION&&(h.title="Action");m.output&&m.output.type==e.EVENT&&(h.title="Event")}else a?g=this.getNodeMenuOptions(a):(g=this.getCanvasMenuOptions(),(m=this.graph.getGroupOnPos(b.canvasX,b.canvasY))&&g.push(null,{content:"Edit Group",has_submenu:!0,submenu:{title:"Group",extra:m,options:this.getGroupMenuOptions(m)}}));
|
||||
g&&new e.ContextMenu(g,h,c)};this.CanvasRenderingContext2D&&(CanvasRenderingContext2D.prototype.roundRect=function(a,b,d,c,e,g){void 0===e&&(e=5);void 0===g&&(g=e);this.moveTo(a+e,b);this.lineTo(a+d-e,b);this.quadraticCurveTo(a+d,b,a+d,b+e);this.lineTo(a+d,b+c-g);this.quadraticCurveTo(a+d,b+c,a+d-g,b+c);this.lineTo(a+g,b+c);this.quadraticCurveTo(a,b+c,a,b+c-g);this.lineTo(a,b+e);this.quadraticCurveTo(a,b,a+e,b)});e.compareObjects=function(a,b){for(var d in a)if(a[d]!=b[d])return!1;return!0};e.distance=
|
||||
y;e.colorToString=function(a){return"rgba("+Math.round(255*a[0]).toFixed()+","+Math.round(255*a[1]).toFixed()+","+Math.round(255*a[2]).toFixed()+","+(4==a.length?a[3].toFixed(2):"1.0")+")"};e.isInsideRectangle=u;e.growBounding=function(a,b,d){b<a[0]?a[0]=b:b>a[2]&&(a[2]=b);d<a[1]?a[1]=d:d>a[3]&&(a[3]=d)};e.isInsideBounding=function(a,b){return a[0]<b[0][0]||a[1]<b[0][1]||a[0]>b[1][0]||a[1]>b[1][1]?!1:!0};e.overlapBounding=v;e.hex2num=function(a){"#"==a.charAt(0)&&(a=a.slice(1));a=a.toUpperCase();
|
||||
for(var b=Array(3),d=0,c,e,g=0;6>g;g+=2)c="0123456789ABCDEF".indexOf(a.charAt(g)),e="0123456789ABCDEF".indexOf(a.charAt(g+1)),b[d]=16*c+e,d++;return b};e.num2hex=function(a){for(var b="#",d,c,e=0;3>e;e++)d=a[e]/16,c=a[e]%16,b+="0123456789ABCDEF".charAt(d)+"0123456789ABCDEF".charAt(c);return b};z.prototype.addItem=function(a,b,d){function c(a){var b=this.value;b&&b.has_submenu&&e.call(this,a)}function e(a){var b=this.value,c=!0;g.current_submenu&&g.current_submenu.close(a);if(d.callback){var h=d.callback.call(this,
|
||||
b,d,a,g,d.node);!0===h&&(c=!1)}if(b&&(b.callback&&!d.ignore_item_callbacks&&!0!==b.disabled&&(h=b.callback.call(this,b,d,a,g,d.extra),!0===h&&(c=!1)),b.submenu)){if(!b.submenu.options)throw"ContextMenu submenu needs options";new g.constructor(b.submenu.options,{callback:b.submenu.callback,event:a,parentMenu:g,ignore_item_callbacks:b.submenu.ignore_item_callbacks,title:b.submenu.title,extra:b.submenu.extra,autoopen:d.autoopen});c=!1}c&&!g.lock&&g.close()}var g=this;d=d||{};var h=document.createElement("div");
|
||||
h.className="litemenu-entry submenu";var m=!1;if(null===b)h.classList.add("separator");else{h.innerHTML=b&&b.title?b.title:a;if(h.value=b)b.disabled&&(m=!0,h.classList.add("disabled")),(b.submenu||b.has_submenu)&&h.classList.add("has_submenu");"function"==typeof b?(h.dataset.value=a,h.onclick_callback=b):h.dataset.value=b;b.className&&(h.className+=" "+b.className)}this.root.appendChild(h);m||h.addEventListener("click",e);d.autoopen&&h.addEventListener("mouseenter",c);return h};z.prototype.close=
|
||||
function(a,b){this.root.parentNode&&this.root.parentNode.removeChild(this.root);this.parentMenu&&!b&&(this.parentMenu.lock=!1,this.parentMenu.current_submenu=null,void 0===a?this.parentMenu.close():a&&!z.isCursorOverElement(a,this.parentMenu.root)&&z.trigger(this.parentMenu.root,"mouseleave",a));this.current_submenu&&this.current_submenu.close(a,!0);this.root.closing_timer&&clearTimeout(this.root.closing_timer)};z.trigger=function(a,b,d,c){var e=document.createEvent("CustomEvent");e.initCustomEvent(b,
|
||||
!0,!0,d);e.srcElement=c;a.dispatchEvent?a.dispatchEvent(e):a.__events&&a.__events.dispatchEvent(e);return e};z.prototype.getTopMenu=function(){return this.options.parentMenu?this.options.parentMenu.getTopMenu():this};z.prototype.getFirstEvent=function(){return this.options.parentMenu?this.options.parentMenu.getFirstEvent():this.options.event};z.isCursorOverElement=function(a,b){var d=a.clientX,c=a.clientY,e=b.getBoundingClientRect();return e?c>e.top&&c<e.top+e.height&&d>e.left&&d<e.left+e.width?!0:
|
||||
!1:!1};e.ContextMenu=z;e.closeAllContextMenus=function(a){a=a||window;a=a.document.querySelectorAll(".litecontextmenu");if(a.length){for(var b=[],d=0;d<a.length;d++)b.push(a[d]);for(d in b)b[d].close?b[d].close():b[d].parentNode&&b[d].parentNode.removeChild(b[d])}};e.extendClass=function(a,b){for(var d in b)a.hasOwnProperty(d)||(a[d]=b[d]);if(b.prototype)for(d in b.prototype)b.prototype.hasOwnProperty(d)&&!a.prototype.hasOwnProperty(d)&&(b.prototype.__lookupGetter__(d)?a.prototype.__defineGetter__(d,
|
||||
b.prototype.__lookupGetter__(d)):a.prototype[d]=b.prototype[d],b.prototype.__lookupSetter__(d)&&a.prototype.__defineSetter__(d,b.prototype.__lookupSetter__(d)))};e.getParameterNames=function(a){return(a+"").replace(/[/][/].*$/gm,"").replace(/\s+/g,"").replace(/[/][*][^/*]*[*][/]/g,"").split("){",1)[0].replace(/^[^(]*[(]/,"").replace(/=[^,]+/g,"").split(",").filter(Boolean)};Math.clamp=function(a,b,d){return b>a?b:d<a?d:a};"undefined"==typeof window||window.requestAnimationFrame||(window.requestAnimationFrame=
|
||||
window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(a){window.setTimeout(a,1E3/60)})})(this);"undefined"!=typeof exports&&(exports.LiteGraph=this.LiteGraph);
|
||||
(function(w){function c(){this.addOutput("in ms","number");this.addOutput("in sec","number")}function s(){this.size=[140,80];this.properties={enabled:!0};this.enabled=!0;this.subgraph=new p.LGraph;this.subgraph._subgraph_node=this;this.subgraph._is_subgraph=!0;this.subgraph.onTrigger=this.onSubgraphTrigger.bind(this);this.subgraph.onInputAdded=this.onSubgraphNewInput.bind(this);this.subgraph.onInputRenamed=this.onSubgraphRenamedInput.bind(this);this.subgraph.onInputTypeChanged=this.onSubgraphTypeChangeInput.bind(this);
|
||||
this.subgraph.onInputRemoved=this.onSubgraphRemovedInput.bind(this);this.subgraph.onOutputAdded=this.onSubgraphNewOutput.bind(this);this.subgraph.onOutputRenamed=this.onSubgraphRenamedOutput.bind(this);this.subgraph.onOutputTypeChanged=this.onSubgraphTypeChangeOutput.bind(this);this.subgraph.onOutputRemoved=this.onSubgraphRemovedOutput.bind(this)}function l(){this.addOutput("","number");this.name_in_graph="";this.properties={name:"",type:"number",value:0};var a=this;this.name_widget=this.addWidget("text",
|
||||
"Name",this.properties.name,function(b){b&&a.setProperty("name",b)});this.type_widget=this.addWidget("text","Type",this.properties.type,function(b){a.setProperty("type",b)});this.value_widget=this.addWidget("number","Value",this.properties.value,function(b){a.setProperty("value",b)});this.widgets_up=!0;this.size=[180,90]}function f(){this.addInput("","");this.name_in_graph="";this.properties={};var a=this;Object.defineProperty(this.properties,"name",{get:function(){return a.name_in_graph},set:function(b){""!=
|
||||
|
||||
@@ -6212,9 +6212,12 @@ LGraphNode.prototype.executeAction = function(action)
|
||||
**/
|
||||
LGraphCanvas.prototype.deleteSelectedNodes = function() {
|
||||
for (var i in this.selected_nodes) {
|
||||
var m = this.selected_nodes[i];
|
||||
var node = this.selected_nodes[i];
|
||||
//if(m == this.node_in_panel) this.showNodePanel(null);
|
||||
this.graph.remove(m);
|
||||
this.graph.remove(node);
|
||||
if (this.onNodeDeselected) {
|
||||
this.onNodeDeselected(node);
|
||||
}
|
||||
}
|
||||
this.selected_nodes = {};
|
||||
this.current_node = null;
|
||||
|
||||
Reference in New Issue
Block a user