mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-03 22:59:14 +00:00
merge
This commit is contained in:
@@ -7473,7 +7473,9 @@ LGraphNode.prototype.executeAction = function(action)
|
||||
* @method adjustMouseEvent
|
||||
**/
|
||||
LGraphCanvas.prototype.adjustMouseEvent = function(e) {
|
||||
|
||||
var clientX_rel = 0;
|
||||
var clientY_rel = 0;
|
||||
|
||||
if (this.canvas) {
|
||||
var b = this.canvas.getBoundingClientRect();
|
||||
clientX_rel = e.clientX - b.left;
|
||||
|
||||
322
build/litegraph.core.min.js
vendored
322
build/litegraph.core.min.js
vendored
@@ -183,164 +183,164 @@ function(a){if(this.onShowNodePanel)this.onShowNodePanel(a);else this.showShowNo
|
||||
a.is_selected=!1;if(this.onNodeDeselected)this.onNodeDeselected(a);if(a.inputs)for(var b=0;b<a.inputs.length;++b)delete this.highlighted_links[a.inputs[b].link];if(a.outputs)for(b=0;b<a.outputs.length;++b){var c=a.outputs[b];if(c.links)for(var d=0;d<c.links.length;++d)delete this.highlighted_links[c.links[d]]}}};m.prototype.deselectAllNodes=function(){if(this.graph){for(var a=this.graph._nodes,b=0,c=a.length;b<c;++b){var d=a[b];if(d.is_selected){if(d.onDeselected)d.onDeselected();d.is_selected=!1;
|
||||
if(this.onNodeDeselected)this.onNodeDeselected(d)}}this.selected_nodes={};this.current_node=null;this.highlighted_links={};if(this.onSelectionChange)this.onSelectionChange(this.selected_nodes);this.setDirty(!0)}};m.prototype.deleteSelectedNodes=function(){this.graph.beforeChange();for(var a in this.selected_nodes){var b=this.selected_nodes[a];if(!b.block_delete){if(b.inputs&&b.inputs.length&&b.outputs&&b.outputs.length&&g.isValidConnection(b.inputs[0].type,b.outputs[0].type)&&b.inputs[0].link&&b.outputs[0].links&&
|
||||
b.outputs[0].links.length){var c=b.graph.links[b.inputs[0].link],d=b.graph.links[b.outputs[0].links[0]],e=b.getInputNode(0),f=b.getOutputNodes(0)[0];e&&f&&e.connect(c.origin_slot,f,d.target_slot)}this.graph.remove(b);if(this.onNodeDeselected)this.onNodeDeselected(b)}}this.selected_nodes={};this.current_node=null;this.highlighted_links={};this.setDirty(!0);this.graph.afterChange()};m.prototype.centerOnNode=function(a){this.ds.offset[0]=-a.pos[0]-.5*a.size[0]+.5*this.canvas.width/this.ds.scale;this.ds.offset[1]=
|
||||
-a.pos[1]-.5*a.size[1]+.5*this.canvas.height/this.ds.scale;this.setDirty(!0,!0)};m.prototype.adjustMouseEvent=function(a){if(this.canvas){var b=this.canvas.getBoundingClientRect();clientX_rel=a.clientX-b.left;clientY_rel=a.clientY-b.top}else clientX_rel=a.clientX,clientY_rel=a.clientY;a.deltaX=clientX_rel-this.last_mouse_position[0];a.deltaY=clientY_rel-this.last_mouse_position[1];this.last_mouse_position[0]=clientX_rel;this.last_mouse_position[1]=clientY_rel;a.canvasX=clientX_rel/this.ds.scale-this.ds.offset[0];
|
||||
a.canvasY=clientY_rel/this.ds.scale-this.ds.offset[1]};m.prototype.setZoom=function(a,b){this.ds.changeScale(a,b);this.dirty_bgcanvas=this.dirty_canvas=!0};m.prototype.convertOffsetToCanvas=function(a,b){return this.ds.convertOffsetToCanvas(a,b)};m.prototype.convertCanvasToOffset=function(a,b){return this.ds.convertCanvasToOffset(a,b)};m.prototype.convertEventToCanvasOffset=function(a){var b=this.canvas.getBoundingClientRect();return this.convertCanvasToOffset([a.clientX-b.left,a.clientY-b.top])};
|
||||
m.prototype.bringToFront=function(a){var b=this.graph._nodes.indexOf(a);-1!=b&&(this.graph._nodes.splice(b,1),this.graph._nodes.push(a))};m.prototype.sendToBack=function(a){var b=this.graph._nodes.indexOf(a);-1!=b&&(this.graph._nodes.splice(b,1),this.graph._nodes.unshift(a))};var I=new Float32Array(4);m.prototype.computeVisibleNodes=function(a,b){b=b||[];b.length=0;a=a||this.graph._nodes;for(var c=0,d=a.length;c<d;++c){var e=a[c];(!this.live_mode||e.onDrawBackground||e.onDrawForeground)&&F(this.visible_area,
|
||||
e.getBounding(I))&&b.push(e)}return b};m.prototype.draw=function(a,b){if(this.canvas&&0!=this.canvas.width&&0!=this.canvas.height){var c=g.getTime();this.render_time=.001*(c-this.last_draw_time);this.last_draw_time=c;this.graph&&this.ds.computeVisibleArea(this.viewport);(this.dirty_bgcanvas||b||this.always_render_background||this.graph&&this.graph._last_trigger_time&&1E3>c-this.graph._last_trigger_time)&&this.drawBackCanvas();(this.dirty_canvas||a)&&this.drawFrontCanvas();this.fps=this.render_time?
|
||||
1/this.render_time:0;this.frame+=1}};m.prototype.drawFrontCanvas=function(){this.dirty_canvas=!1;this.ctx||(this.ctx=this.bgcanvas.getContext("2d"));var a=this.ctx;if(a){var b=this.canvas;a.start2D&&!this.viewport&&(a.start2D(),a.restore(),a.setTransform(1,0,0,1,0,0));var c=this.viewport||this.dirty_area;c&&(a.save(),a.beginPath(),a.rect(c[0],c[1],c[2],c[3]),a.clip());this.clear_background&&(c?a.clearRect(c[0],c[1],c[2],c[3]):a.clearRect(0,0,b.width,b.height));this.bgcanvas==this.canvas?this.drawBackCanvas():
|
||||
a.drawImage(this.bgcanvas,0,0);if(this.onRender)this.onRender(b,a);this.show_info&&this.renderInfo(a,c?c[0]:0,c?c[1]:0);if(this.graph){a.save();this.ds.toCanvasContext(a);b=this.computeVisibleNodes(null,this.visible_nodes);for(var d=0;d<b.length;++d){var e=b[d];a.save();a.translate(e.pos[0],e.pos[1]);this.drawNode(e,a);a.restore()}this.render_execution_order&&this.drawExecutionOrder(a);this.graph.config.links_ontop&&(this.live_mode||this.drawConnections(a));if(null!=this.connecting_pos){a.lineWidth=
|
||||
this.connections_width;e=this.connecting_output||this.connecting_input;b=e.type;d=e.dir;null==d&&(d=this.connecting_output?this.connecting_node.horizontal?g.DOWN:g.RIGHT:this.connecting_node.horizontal?g.UP:g.LEFT);var f=e.shape;switch(b){case g.EVENT:e=g.EVENT_LINK_COLOR;break;default:e=g.CONNECTING_LINK_COLOR}this.renderLink(a,this.connecting_pos,[this.graph_mouse[0],this.graph_mouse[1]],null,!1,null,e,d,g.CENTER);a.beginPath();b===g.EVENT||f===g.BOX_SHAPE?(a.rect(this.connecting_pos[0]-6+.5,this.connecting_pos[1]-
|
||||
5+.5,14,10),a.fill(),a.beginPath(),a.rect(this.graph_mouse[0]-6+.5,this.graph_mouse[1]-5+.5,14,10)):f===g.ARROW_SHAPE?(a.moveTo(this.connecting_pos[0]+8,this.connecting_pos[1]+.5),a.lineTo(this.connecting_pos[0]-4,this.connecting_pos[1]+6+.5),a.lineTo(this.connecting_pos[0]-4,this.connecting_pos[1]-6+.5),a.closePath()):(a.arc(this.connecting_pos[0],this.connecting_pos[1],4,0,2*Math.PI),a.fill(),a.beginPath(),a.arc(this.graph_mouse[0],this.graph_mouse[1],4,0,2*Math.PI));a.fill();a.fillStyle="#ffcc00";
|
||||
if(this._highlight_input){a.beginPath();var h=this._highlight_input_slot.shape;h===g.ARROW_SHAPE?(a.moveTo(this._highlight_input[0]+8,this._highlight_input[1]+.5),a.lineTo(this._highlight_input[0]-4,this._highlight_input[1]+6+.5),a.lineTo(this._highlight_input[0]-4,this._highlight_input[1]-6+.5),a.closePath()):a.arc(this._highlight_input[0],this._highlight_input[1],6,0,2*Math.PI);a.fill()}this._highlight_output&&(a.beginPath(),h===g.ARROW_SHAPE?(a.moveTo(this._highlight_output[0]+8,this._highlight_output[1]+
|
||||
.5),a.lineTo(this._highlight_output[0]-4,this._highlight_output[1]+6+.5),a.lineTo(this._highlight_output[0]-4,this._highlight_output[1]-6+.5),a.closePath()):a.arc(this._highlight_output[0],this._highlight_output[1],6,0,2*Math.PI),a.fill())}this.dragging_rectangle&&(a.strokeStyle="#FFF",a.strokeRect(this.dragging_rectangle[0],this.dragging_rectangle[1],this.dragging_rectangle[2],this.dragging_rectangle[3]));if(this.over_link_center&&this.render_link_tooltip)this.drawLinkTooltip(a,this.over_link_center);
|
||||
else if(this.onDrawLinkTooltip)this.onDrawLinkTooltip(a,null);if(this.onDrawForeground)this.onDrawForeground(a,this.visible_rect);a.restore()}this._graph_stack&&this._graph_stack.length&&this.drawSubgraphPanel(a);if(this.onDrawOverlay)this.onDrawOverlay(a);c&&a.restore();a.finish2D&&a.finish2D()}};m.prototype.drawSubgraphPanel=function(a){var b=this.graph,c=b._subgraph_node;c?(this.drawSubgraphPanelLeft(b,c,a),this.drawSubgraphPanelRight(b,c,a)):console.warn("subgraph without subnode")};m.prototype.drawSubgraphPanelLeft=
|
||||
function(a,b,c){var d=b.inputs?b.inputs.length:0,e=Math.floor(1.6*g.NODE_SLOT_HEIGHT);c.fillStyle="#111";c.globalAlpha=.8;c.beginPath();c.roundRect(10,10,200,(d+1)*e+50,[8]);c.fill();c.globalAlpha=1;c.fillStyle="#888";c.font="14px Arial";c.textAlign="left";c.fillText("Graph Inputs",20,34);if(this.drawButton(180,20,20,20,"X","#151515"))this.closeSubgraph();else{d=50;c.font="14px Arial";if(b.inputs)for(var f=0;f<b.inputs.length;++f){var h=b.inputs[f];if(!h.not_subgraph_input){if(this.drawButton(20,
|
||||
d+2,180,e-2)){var k=b.constructor.input_node_type||"graph/input";this.graph.beforeChange();var n=g.createNode(k);n?(a.add(n),this.block_click=!1,this.last_click_position=null,this.selectNodes([n]),this.node_dragged=n,this.dragging_canvas=!1,n.setProperty("name",h.name),n.setProperty("type",h.type),this.node_dragged.pos[0]=this.graph_mouse[0]-5,this.node_dragged.pos[1]=this.graph_mouse[1]-5,this.graph.afterChange()):console.error("graph input node not found:",k)}c.fillStyle="#9C9";c.beginPath();c.arc(184,
|
||||
d+.5*e,5,0,2*Math.PI);c.fill();c.fillStyle="#AAA";c.fillText(h.name,30,d+.75*e);c.fillStyle="#777";c.fillText(h.type,130,d+.75*e);d+=e}}this.drawButton(20,d+2,180,e-2,"+","#151515","#222")&&this.showSubgraphPropertiesDialog(b)}};m.prototype.drawSubgraphPanelRight=function(a,b,c){var d=b.outputs?b.outputs.length:0,e=this.bgcanvas.width,f=Math.floor(1.6*g.NODE_SLOT_HEIGHT);c.fillStyle="#111";c.globalAlpha=.8;c.beginPath();c.roundRect(e-200-10,10,200,(d+1)*f+50,[8]);c.fill();c.globalAlpha=1;c.fillStyle=
|
||||
"#888";c.font="14px Arial";c.textAlign="left";d=c.measureText("Graph Outputs").width;c.fillText("Graph Outputs",e-d-20,34);if(this.drawButton(e-200,20,20,20,"X","#151515"))this.closeSubgraph();else{d=50;c.font="14px Arial";if(b.outputs)for(var h=0;h<b.outputs.length;++h){var k=b.outputs[h];if(!k.not_subgraph_input){if(this.drawButton(e-200,d+2,180,f-2)){var n=b.constructor.output_node_type||"graph/output";this.graph.beforeChange();var q=g.createNode(n);q?(a.add(q),this.block_click=!1,this.last_click_position=
|
||||
null,this.selectNodes([q]),this.node_dragged=q,this.dragging_canvas=!1,q.setProperty("name",k.name),q.setProperty("type",k.type),this.node_dragged.pos[0]=this.graph_mouse[0]-5,this.node_dragged.pos[1]=this.graph_mouse[1]-5,this.graph.afterChange()):console.error("graph input node not found:",n)}c.fillStyle="#9C9";c.beginPath();c.arc(e-200+16,d+.5*f,5,0,2*Math.PI);c.fill();c.fillStyle="#AAA";c.fillText(k.name,e-200+30,d+.75*f);c.fillStyle="#777";c.fillText(k.type,e-200+130,d+.75*f);d+=f}}this.drawButton(e-
|
||||
200,d+2,180,f-2,"+","#151515","#222")&&this.showSubgraphPropertiesDialogRight(b)}};m.prototype.drawButton=function(a,b,c,d,e,f,h,k){var n=this.ctx;f=f||g.NODE_DEFAULT_COLOR;h=h||"#555";k=k||g.NODE_TEXT_COLOR;var q=b+g.NODE_TITLE_HEIGHT+2,u=this.mouse,r=g.isInsideRectangle(u[0],u[1],a,q,c,d);q=(u=this.last_click_position)&&g.isInsideRectangle(u[0],u[1],a,q,c,d);n.fillStyle=r?h:f;q&&(n.fillStyle="#AAA");n.beginPath();n.roundRect(a,b,c,d,[4]);n.fill();null!=e&&e.constructor==String&&(n.fillStyle=k,n.textAlign=
|
||||
"center",n.font=(.65*d|0)+"px Arial",n.fillText(e,a+.5*c,b+.75*d),n.textAlign="left");a=q&&!this.block_click;q&&this.blockClick();return a};m.prototype.isAreaClicked=function(a,b,c,d,e){var f=this.mouse;g.isInsideRectangle(f[0],f[1],a,b,c,d);b=(a=(f=this.last_click_position)&&g.isInsideRectangle(f[0],f[1],a,b,c,d))&&!this.block_click;a&&e&&this.blockClick();return b};m.prototype.renderInfo=function(a,b,c){b=b||10;c=c||this.canvas.height-80;a.save();a.translate(b,c);a.font="10px Arial";a.fillStyle=
|
||||
"#888";a.textAlign="left";this.graph?(a.fillText("T: "+this.graph.globaltime.toFixed(2)+"s",5,13),a.fillText("I: "+this.graph.iteration,5,26),a.fillText("N: "+this.graph._nodes.length+" ["+this.visible_nodes.length+"]",5,39),a.fillText("V: "+this.graph._version,5,52),a.fillText("FPS:"+this.fps.toFixed(2),5,65)):a.fillText("No graph selected",5,13);a.restore()};m.prototype.drawBackCanvas=function(){var a=this.bgcanvas;if(a.width!=this.canvas.width||a.height!=this.canvas.height)a.width=this.canvas.width,
|
||||
a.height=this.canvas.height;this.bgctx||(this.bgctx=this.bgcanvas.getContext("2d"));var b=this.bgctx;b.start&&b.start();var c=this.viewport||[0,0,b.canvas.width,b.canvas.height];this.clear_background&&b.clearRect(c[0],c[1],c[2],c[3]);if(this._graph_stack&&this._graph_stack.length){b.save();c=this.graph._subgraph_node;b.strokeStyle=c.bgcolor;b.lineWidth=10;b.strokeRect(1,1,a.width-2,a.height-2);b.lineWidth=1;b.font="40px Arial";b.textAlign="center";b.fillStyle=c.bgcolor||"#AAA";for(var d="",e=1;e<
|
||||
this._graph_stack.length;++e)d+=this._graph_stack[e]._subgraph_node.getTitle()+" >> ";b.fillText(d+c.getTitle(),.5*a.width,40);b.restore()}c=!1;this.onRenderBackground&&(c=this.onRenderBackground(a,b));this.viewport||(b.restore(),b.setTransform(1,0,0,1,0,0));this.visible_links.length=0;if(this.graph){b.save();this.ds.toCanvasContext(b);if(this.background_image&&.5<this.ds.scale&&!c){b.globalAlpha=this.zoom_modify_alpha?(1-.5/this.ds.scale)*this.editor_alpha:this.editor_alpha;b.imageSmoothingEnabled=
|
||||
b.imageSmoothingEnabled=!1;if(!this._bg_img||this._bg_img.name!=this.background_image){this._bg_img=new Image;this._bg_img.name=this.background_image;this._bg_img.src=this.background_image;var f=this;this._bg_img.onload=function(){f.draw(!0,!0)}}c=null;null==this._pattern&&0<this._bg_img.width?(c=b.createPattern(this._bg_img,"repeat"),this._pattern_img=this._bg_img,this._pattern=c):c=this._pattern;c&&(b.fillStyle=c,b.fillRect(this.visible_area[0],this.visible_area[1],this.visible_area[2],this.visible_area[3]),
|
||||
b.fillStyle="transparent");b.globalAlpha=1;b.imageSmoothingEnabled=b.imageSmoothingEnabled=!0}this.graph._groups.length&&!this.live_mode&&this.drawGroups(a,b);if(this.onDrawBackground)this.onDrawBackground(b,this.visible_area);this.onBackgroundRender&&(console.error("WARNING! onBackgroundRender deprecated, now is named onDrawBackground "),this.onBackgroundRender=null);this.render_canvas_border&&(b.strokeStyle="#235",b.strokeRect(0,0,a.width,a.height));this.render_connections_shadows?(b.shadowColor=
|
||||
"#000",b.shadowOffsetX=0,b.shadowOffsetY=0,b.shadowBlur=6):b.shadowColor="rgba(0,0,0,0)";this.live_mode||this.drawConnections(b);b.shadowColor="rgba(0,0,0,0)";b.restore()}b.finish&&b.finish();this.dirty_bgcanvas=!1;this.dirty_canvas=!0};var B=new Float32Array(2);m.prototype.drawNode=function(a,b){this.current_node=a;var c=a.color||a.constructor.color||g.NODE_DEFAULT_COLOR,d=a.bgcolor||a.constructor.bgcolor||g.NODE_DEFAULT_BGCOLOR,e=.6>this.ds.scale;if(this.live_mode){if(!a.flags.collapsed&&(b.shadowColor=
|
||||
"transparent",a.onDrawForeground))a.onDrawForeground(b,this,this.canvas)}else{var f=this.editor_alpha;b.globalAlpha=f;this.render_shadows&&!e?(b.shadowColor=g.DEFAULT_SHADOW_COLOR,b.shadowOffsetX=2*this.ds.scale,b.shadowOffsetY=2*this.ds.scale,b.shadowBlur=3*this.ds.scale):b.shadowColor="transparent";if(!a.flags.collapsed||!a.onDrawCollapsed||1!=a.onDrawCollapsed(b,this)){var h=a._shape||g.BOX_SHAPE;B.set(a.size);var k=a.horizontal;if(a.flags.collapsed){b.font=this.inner_text_font;var n=a.getTitle?
|
||||
a.getTitle():a.title;null!=n&&(a._collapsed_width=Math.min(a.size[0],b.measureText(n).width+2*g.NODE_TITLE_HEIGHT),B[0]=a._collapsed_width,B[1]=0)}a.clip_area&&(b.save(),b.beginPath(),h==g.BOX_SHAPE?b.rect(0,0,B[0],B[1]):h==g.ROUND_SHAPE?b.roundRect(0,0,B[0],B[1],[10]):h==g.CIRCLE_SHAPE&&b.arc(.5*B[0],.5*B[1],.5*B[0],0,2*Math.PI),b.clip());a.has_errors&&(d="red");this.drawNodeShape(a,b,B,c,d,a.is_selected,a.mouseOver);b.shadowColor="transparent";if(a.onDrawForeground)a.onDrawForeground(b,this,this.canvas);
|
||||
b.textAlign=k?"center":"left";b.font=this.inner_text_font;d=!e;var q=this.connecting_output;h=this.connecting_input;b.lineWidth=1;n=0;var u=new Float32Array(2);if(!a.flags.collapsed){if(a.inputs)for(c=0;c<a.inputs.length;c++){var r=a.inputs[c],m=r.type,l=r.shape;b.globalAlpha=f;this.connecting_output&&!g.isValidConnection(r.type,q.type)&&(b.globalAlpha=.4*f);b.fillStyle=null!=r.link?r.color_on||this.default_connection_color_byType[m]||this.default_connection_color.input_on:r.color_off||this.default_connection_color_byTypeOff[m]||
|
||||
this.default_connection_color_byType[m]||this.default_connection_color.input_off;var t=a.getConnectionPos(!0,c,u);t[0]-=a.pos[0];t[1]-=a.pos[1];n<t[1]+.5*g.NODE_SLOT_HEIGHT&&(n=t[1]+.5*g.NODE_SLOT_HEIGHT);b.beginPath();"array"==m&&(l=g.GRID_SHAPE);r.type===g.EVENT||r.shape===g.BOX_SHAPE?k?b.rect(t[0]-5+.5,t[1]-8+.5,10,14):b.rect(t[0]-6+.5,t[1]-5+.5,14,10):l===g.ARROW_SHAPE?(b.moveTo(t[0]+8,t[1]+.5),b.lineTo(t[0]-4,t[1]+6+.5),b.lineTo(t[0]-4,t[1]-6+.5),b.closePath()):l===g.GRID_SHAPE?(b.rect(t[0]-
|
||||
4,t[1]-4,2,2),b.rect(t[0]-1,t[1]-4,2,2),b.rect(t[0]+2,t[1]-4,2,2),b.rect(t[0]-4,t[1]-1,2,2),b.rect(t[0]-1,t[1]-1,2,2),b.rect(t[0]+2,t[1]-1,2,2),b.rect(t[0]-4,t[1]+2,2,2),b.rect(t[0]-1,t[1]+2,2,2),b.rect(t[0]+2,t[1]+2,2,2)):e?b.rect(t[0]-4,t[1]-4,8,8):b.arc(t[0],t[1],4,0,2*Math.PI);b.fill();d&&(m=null!=r.label?r.label:r.name)&&(b.fillStyle=g.NODE_TEXT_COLOR,k||r.dir==g.UP?b.fillText(m,t[0],t[1]-10):b.fillText(m,t[0]+10,t[1]+5))}b.textAlign=k?"center":"right";b.strokeStyle="black";if(a.outputs)for(c=
|
||||
0;c<a.outputs.length;c++)if(r=a.outputs[c],m=r.type,l=r.shape,this.connecting_input&&!g.isValidConnection(m,h.type)&&(b.globalAlpha=.4*f),t=a.getConnectionPos(!1,c,u),t[0]-=a.pos[0],t[1]-=a.pos[1],n<t[1]+.5*g.NODE_SLOT_HEIGHT&&(n=t[1]+.5*g.NODE_SLOT_HEIGHT),b.fillStyle=r.links&&r.links.length?r.color_on||this.default_connection_color_byType[m]||this.default_connection_color.output_on:r.color_off||this.default_connection_color_byTypeOff[m]||this.default_connection_color_byType[m]||this.default_connection_color.output_off,
|
||||
b.beginPath(),"array"==m&&(l=g.GRID_SHAPE),q=!0,m===g.EVENT||l===g.BOX_SHAPE?k?b.rect(t[0]-5+.5,t[1]-8+.5,10,14):b.rect(t[0]-6+.5,t[1]-5+.5,14,10):l===g.ARROW_SHAPE?(b.moveTo(t[0]+8,t[1]+.5),b.lineTo(t[0]-4,t[1]+6+.5),b.lineTo(t[0]-4,t[1]-6+.5),b.closePath()):l===g.GRID_SHAPE?(b.rect(t[0]-4,t[1]-4,2,2),b.rect(t[0]-1,t[1]-4,2,2),b.rect(t[0]+2,t[1]-4,2,2),b.rect(t[0]-4,t[1]-1,2,2),b.rect(t[0]-1,t[1]-1,2,2),b.rect(t[0]+2,t[1]-1,2,2),b.rect(t[0]-4,t[1]+2,2,2),b.rect(t[0]-1,t[1]+2,2,2),b.rect(t[0]+2,t[1]+
|
||||
2,2,2),q=!1):e?b.rect(t[0]-4,t[1]-4,8,8):b.arc(t[0],t[1],4,0,2*Math.PI),b.fill(),!e&&q&&b.stroke(),d&&(m=null!=r.label?r.label:r.name))b.fillStyle=g.NODE_TEXT_COLOR,k||r.dir==g.DOWN?b.fillText(m,t[0],t[1]-8):b.fillText(m,t[0]-10,t[1]+5);b.textAlign="left";b.globalAlpha=1;if(a.widgets){r=n;if(k||a.widgets_up)r=2;null!=a.widgets_start_y&&(r=a.widgets_start_y);this.drawNodeWidgets(a,r,b,this.node_widget&&this.node_widget[0]==a?this.node_widget[1]:null)}}else if(this.render_collapsed_slots){e=f=null;
|
||||
if(a.inputs)for(c=0;c<a.inputs.length;c++)if(r=a.inputs[c],null!=r.link){f=r;break}if(a.outputs)for(c=0;c<a.outputs.length;c++)r=a.outputs[c],r.links&&r.links.length&&(e=r);f&&(f=0,c=-.5*g.NODE_TITLE_HEIGHT,k&&(f=.5*a._collapsed_width,c=-g.NODE_TITLE_HEIGHT),b.fillStyle="#686",b.beginPath(),r.type===g.EVENT||r.shape===g.BOX_SHAPE?b.rect(f-7+.5,c-4,14,8):r.shape===g.ARROW_SHAPE?(b.moveTo(f+8,c),b.lineTo(f+-4,c-4),b.lineTo(f+-4,c+4),b.closePath()):b.arc(f,c,4,0,2*Math.PI),b.fill());e&&(f=a._collapsed_width,
|
||||
c=-.5*g.NODE_TITLE_HEIGHT,k&&(f=.5*a._collapsed_width,c=0),b.fillStyle="#686",b.strokeStyle="black",b.beginPath(),r.type===g.EVENT||r.shape===g.BOX_SHAPE?b.rect(f-7+.5,c-4,14,8):r.shape===g.ARROW_SHAPE?(b.moveTo(f+6,c),b.lineTo(f-6,c-4),b.lineTo(f-6,c+4),b.closePath()):b.arc(f,c,4,0,2*Math.PI),b.fill())}a.clip_area&&b.restore();b.globalAlpha=1}}};m.prototype.drawLinkTooltip=function(a,b){var c=b._pos;a.fillStyle="black";a.beginPath();a.arc(c[0],c[1],3,0,2*Math.PI);a.fill();if(null!=b.data&&(!this.onDrawLinkTooltip||
|
||||
1!=this.onDrawLinkTooltip(a,b,this))&&(b=b.data,b=b.constructor===Number?b.toFixed(2):b.constructor===String?'"'+b+'"':b.constructor===Boolean?String(b):b.toToolTip?b.toToolTip():"["+b.constructor.name+"]",null!=b)){b=b.substr(0,30);a.font="14px Courier New";var d=a.measureText(b).width+20;a.shadowColor="black";a.shadowOffsetX=2;a.shadowOffsetY=2;a.shadowBlur=3;a.fillStyle="#454";a.beginPath();a.roundRect(c[0]-.5*d,c[1]-15-24,d,24,[3]);a.moveTo(c[0]-10,c[1]-15);a.lineTo(c[0]+10,c[1]-15);a.lineTo(c[0],
|
||||
c[1]-5);a.fill();a.shadowColor="transparent";a.textAlign="center";a.fillStyle="#CEC";a.fillText(b,c[0],c[1]-15-24*.3)}};var y=new Float32Array(4);m.prototype.drawNodeShape=function(a,b,c,d,e,f,h){b.strokeStyle=d;b.fillStyle=e;e=g.NODE_TITLE_HEIGHT;var k=.5>this.ds.scale,n=a._shape||a.constructor.shape||g.ROUND_SHAPE,q=a.constructor.title_mode,u=!0;q==g.TRANSPARENT_TITLE||q==g.NO_TITLE?u=!1:q==g.AUTOHIDE_TITLE&&h&&(u=!0);y[0]=0;y[1]=u?-e:0;y[2]=c[0]+1;y[3]=u?c[1]+e:c[1];h=b.globalAlpha;b.beginPath();
|
||||
n==g.BOX_SHAPE||k?b.fillRect(y[0],y[1],y[2],y[3]):n==g.ROUND_SHAPE||n==g.CARD_SHAPE?b.roundRect(y[0],y[1],y[2],y[3],n==g.CARD_SHAPE?[this.round_radius,this.round_radius,0,0]:[this.round_radius]):n==g.CIRCLE_SHAPE&&b.arc(.5*c[0],.5*c[1],.5*c[0],0,2*Math.PI);b.fill();!a.flags.collapsed&&u&&(b.shadowColor="transparent",b.fillStyle="rgba(0,0,0,0.2)",b.fillRect(0,-1,y[2],2));b.shadowColor="transparent";if(a.onDrawBackground)a.onDrawBackground(b,this,this.canvas,this.graph_mouse);if(u||q==g.TRANSPARENT_TITLE){if(a.onDrawTitleBar)a.onDrawTitleBar(b,
|
||||
e,c,this.ds.scale,d);else if(q!=g.TRANSPARENT_TITLE&&(a.constructor.title_color||this.render_title_colored)){u=a.constructor.title_color||d;a.flags.collapsed&&(b.shadowColor=g.DEFAULT_SHADOW_COLOR);if(this.use_gradients){var r=m.gradients[u];r||(r=m.gradients[u]=b.createLinearGradient(0,0,400,0),r.addColorStop(0,u),r.addColorStop(1,"#000"));b.fillStyle=r}else b.fillStyle=u;b.beginPath();n==g.BOX_SHAPE||k?b.rect(0,-e,c[0]+1,e):(n==g.ROUND_SHAPE||n==g.CARD_SHAPE)&&b.roundRect(0,-e,c[0]+1,e,a.flags.collapsed?
|
||||
[this.round_radius]:[this.round_radius,this.round_radius,0,0]);b.fill();b.shadowColor="transparent"}u=!1;g.node_box_coloured_by_mode&&g.NODE_MODES_COLORS[a.mode]&&(u=g.NODE_MODES_COLORS[a.mode]);g.node_box_coloured_when_on&&(u=a.action_triggered?"#FFF":a.execute_triggered?"#AAA":u);if(a.onDrawTitleBox)a.onDrawTitleBox(b,e,c,this.ds.scale);else n==g.ROUND_SHAPE||n==g.CIRCLE_SHAPE||n==g.CARD_SHAPE?(k&&(b.fillStyle="black",b.beginPath(),b.arc(.5*e,-.5*e,6,0,2*Math.PI),b.fill()),b.fillStyle=a.boxcolor||
|
||||
u||g.NODE_DEFAULT_BOXCOLOR,k?b.fillRect(.5*e-5,-.5*e-5,10,10):(b.beginPath(),b.arc(.5*e,-.5*e,5,0,2*Math.PI),b.fill())):(k&&(b.fillStyle="black",b.fillRect(.5*(e-10)-1,-.5*(e+10)-1,12,12)),b.fillStyle=a.boxcolor||u||g.NODE_DEFAULT_BOXCOLOR,b.fillRect(.5*(e-10),-.5*(e+10),10,10));b.globalAlpha=h;if(a.onDrawTitleText)a.onDrawTitleText(b,e,c,this.ds.scale,this.title_text_font,f);!k&&(b.font=this.title_text_font,h=String(a.getTitle()))&&(b.fillStyle=f?g.NODE_SELECTED_TITLE_COLOR:a.constructor.title_text_color||
|
||||
this.node_title_color,a.flags.collapsed?(b.textAlign="left",b.measureText(h),b.fillText(h.substr(0,20),e,g.NODE_TITLE_TEXT_Y-e),b.textAlign="left"):(b.textAlign="left",b.fillText(h,e,g.NODE_TITLE_TEXT_Y-e)));a.flags.collapsed||!a.subgraph||a.skip_subgraph_button||(h=g.NODE_TITLE_HEIGHT,u=a.size[0]-h,r=g.isInsideRectangle(this.graph_mouse[0]-a.pos[0],this.graph_mouse[1]-a.pos[1],u+2,-h+2,h-4,h-4),b.fillStyle=r?"#888":"#555",n==g.BOX_SHAPE||k?b.fillRect(u+2,-h+2,h-4,h-4):(b.beginPath(),b.roundRect(u+
|
||||
2,-h+2,h-4,h-4,[4]),b.fill()),b.fillStyle="#333",b.beginPath(),b.moveTo(u+.2*h,.6*-h),b.lineTo(u+.8*h,.6*-h),b.lineTo(u+.5*h,.3*-h),b.fill());if(a.onDrawTitle)a.onDrawTitle(b)}if(f){if(a.onBounding)a.onBounding(y);q==g.TRANSPARENT_TITLE&&(y[1]-=e,y[3]+=e);b.lineWidth=1;b.globalAlpha=.8;b.beginPath();n==g.BOX_SHAPE?b.rect(-6+y[0],-6+y[1],12+y[2],12+y[3]):n==g.ROUND_SHAPE||n==g.CARD_SHAPE&&a.flags.collapsed?b.roundRect(-6+y[0],-6+y[1],12+y[2],12+y[3],[2*this.round_radius]):n==g.CARD_SHAPE?b.roundRect(-6+
|
||||
y[0],-6+y[1],12+y[2],12+y[3],[2*this.round_radius,2,2*this.round_radius,2]):n==g.CIRCLE_SHAPE&&b.arc(.5*c[0],.5*c[1],.5*c[0]+6,0,2*Math.PI);b.strokeStyle=g.NODE_BOX_OUTLINE_COLOR;b.stroke();b.strokeStyle=d;b.globalAlpha=1}0<a.execute_triggered&&a.execute_triggered--;0<a.action_triggered&&a.action_triggered--};var G=new Float32Array(4),A=new Float32Array(4),J=new Float32Array(2),K=new Float32Array(2);m.prototype.drawConnections=function(a){var b=g.getTime(),c=this.visible_area;G[0]=c[0]-20;G[1]=c[1]-
|
||||
20;G[2]=c[2]+40;G[3]=c[3]+40;a.lineWidth=this.connections_width;a.fillStyle="#AAA";a.strokeStyle="#AAA";a.globalAlpha=this.editor_alpha;c=this.graph._nodes;for(var d=0,e=c.length;d<e;++d){var f=c[d];if(f.inputs&&f.inputs.length)for(var h=0;h<f.inputs.length;++h){var k=f.inputs[h];if(k&&null!=k.link&&(k=this.graph.links[k.link])){var n=this.graph.getNodeById(k.origin_id);if(null!=n){var q=k.origin_slot;var u=-1==q?[n.pos[0]+10,n.pos[1]+10]:n.getConnectionPos(!1,q,J);var r=f.getConnectionPos(!0,h,K);
|
||||
A[0]=u[0];A[1]=u[1];A[2]=r[0]-u[0];A[3]=r[1]-u[1];0>A[2]&&(A[0]+=A[2],A[2]=Math.abs(A[2]));0>A[3]&&(A[1]+=A[3],A[3]=Math.abs(A[3]));if(F(A,G)){var m=n.outputs[q];q=f.inputs[h];if(m&&q&&(n=m.dir||(n.horizontal?g.DOWN:g.RIGHT),q=q.dir||(f.horizontal?g.UP:g.LEFT),this.renderLink(a,u,r,k,!1,0,null,n,q),k&&k._last_time&&1E3>b-k._last_time)){m=2-.002*(b-k._last_time);var l=a.globalAlpha;a.globalAlpha=l*m;this.renderLink(a,u,r,k,!0,m,"white",n,q);a.globalAlpha=l}}}}}}a.globalAlpha=1};m.prototype.renderLink=
|
||||
function(a,b,c,d,e,f,h,k,n,q){d&&this.visible_links.push(d);!h&&d&&(h=d.color||m.link_type_colors[d.type]);h||(h=this.default_link_color);null!=d&&this.highlighted_links[d.id]&&(h="#FFF");k=k||g.RIGHT;n=n||g.LEFT;var u=H(b,c);this.render_connections_border&&.6<this.ds.scale&&(a.lineWidth=this.connections_width+4);a.lineJoin="round";q=q||1;1<q&&(a.lineWidth=.5);a.beginPath();for(var r=0;r<q;r+=1){var l=5*(r-.5*(q-1));if(this.links_render_mode==g.SPLINE_LINK){a.moveTo(b[0],b[1]+l);var p=0,t=0,v=0,w=
|
||||
0;switch(k){case g.LEFT:p=-.25*u;break;case g.RIGHT:p=.25*u;break;case g.UP:t=-.25*u;break;case g.DOWN:t=.25*u}switch(n){case g.LEFT:v=-.25*u;break;case g.RIGHT:v=.25*u;break;case g.UP:w=-.25*u;break;case g.DOWN:w=.25*u}a.bezierCurveTo(b[0]+p,b[1]+t+l,c[0]+v,c[1]+w+l,c[0],c[1]+l)}else if(this.links_render_mode==g.LINEAR_LINK){a.moveTo(b[0],b[1]+l);w=v=t=p=0;switch(k){case g.LEFT:p=-1;break;case g.RIGHT:p=1;break;case g.UP:t=-1;break;case g.DOWN:t=1}switch(n){case g.LEFT:v=-1;break;case g.RIGHT:v=
|
||||
1;break;case g.UP:w=-1;break;case g.DOWN:w=1}a.lineTo(b[0]+15*p,b[1]+15*t+l);a.lineTo(c[0]+15*v,c[1]+15*w+l);a.lineTo(c[0],c[1]+l)}else if(this.links_render_mode==g.STRAIGHT_LINK)a.moveTo(b[0],b[1]),l=b[0],p=b[1],t=c[0],v=c[1],k==g.RIGHT?l+=10:p+=10,n==g.LEFT?t-=10:v-=10,a.lineTo(l,p),a.lineTo(.5*(l+t),p),a.lineTo(.5*(l+t),v),a.lineTo(t,v),a.lineTo(c[0],c[1]);else return}this.render_connections_border&&.6<this.ds.scale&&!e&&(a.strokeStyle="rgba(0,0,0,0.5)",a.stroke());a.lineWidth=this.connections_width;
|
||||
a.fillStyle=a.strokeStyle=h;a.stroke();e=this.computeConnectionPoint(b,c,.5,k,n);d&&d._pos&&(d._pos[0]=e[0],d._pos[1]=e[1]);.6<=this.ds.scale&&this.highquality_render&&n!=g.CENTER&&(this.render_connection_arrows&&(r=this.computeConnectionPoint(b,c,.25,k,n),u=this.computeConnectionPoint(b,c,.26,k,n),d=this.computeConnectionPoint(b,c,.75,k,n),q=this.computeConnectionPoint(b,c,.76,k,n),this.render_curved_connections?(u=-Math.atan2(u[0]-r[0],u[1]-r[1]),q=-Math.atan2(q[0]-d[0],q[1]-d[1])):q=u=c[1]>b[1]?
|
||||
0:Math.PI,a.save(),a.translate(r[0],r[1]),a.rotate(u),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore(),a.save(),a.translate(d[0],d[1]),a.rotate(q),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore()),a.beginPath(),a.arc(e[0],e[1],5,0,2*Math.PI),a.fill());if(f)for(a.fillStyle=h,r=0;5>r;++r)f=(.001*g.getTime()+.2*r)%1,e=this.computeConnectionPoint(b,c,f,k,n),a.beginPath(),a.arc(e[0],e[1],5,0,2*Math.PI),a.fill()};m.prototype.computeConnectionPoint=
|
||||
function(a,b,c,d,e){d=d||g.RIGHT;e=e||g.LEFT;var f=H(a,b),h=[a[0],a[1]],k=[b[0],b[1]];switch(d){case g.LEFT:h[0]+=-.25*f;break;case g.RIGHT:h[0]+=.25*f;break;case g.UP:h[1]+=-.25*f;break;case g.DOWN:h[1]+=.25*f}switch(e){case g.LEFT:k[0]+=-.25*f;break;case g.RIGHT:k[0]+=.25*f;break;case g.UP:k[1]+=-.25*f;break;case g.DOWN:k[1]+=.25*f}d=(1-c)*(1-c)*(1-c);e=3*(1-c)*(1-c)*c;f=3*(1-c)*c*c;c*=c*c;return[d*a[0]+e*h[0]+f*k[0]+c*b[0],d*a[1]+e*h[1]+f*k[1]+c*b[1]]};m.prototype.drawExecutionOrder=function(a){a.shadowColor=
|
||||
"transparent";a.globalAlpha=.25;a.textAlign="center";a.strokeStyle="white";a.globalAlpha=.75;for(var b=this.visible_nodes,c=0;c<b.length;++c){var d=b[c];a.fillStyle="black";a.fillRect(d.pos[0]-g.NODE_TITLE_HEIGHT,d.pos[1]-g.NODE_TITLE_HEIGHT,g.NODE_TITLE_HEIGHT,g.NODE_TITLE_HEIGHT);0==d.order&&a.strokeRect(d.pos[0]-g.NODE_TITLE_HEIGHT+.5,d.pos[1]-g.NODE_TITLE_HEIGHT+.5,g.NODE_TITLE_HEIGHT,g.NODE_TITLE_HEIGHT);a.fillStyle="#FFF";a.fillText(d.order,d.pos[0]+-.5*g.NODE_TITLE_HEIGHT,d.pos[1]-6)}a.globalAlpha=
|
||||
1};m.prototype.drawNodeWidgets=function(a,b,c,d){if(!a.widgets||!a.widgets.length)return 0;var e=a.size[0],f=a.widgets;b+=2;var h=g.NODE_WIDGET_HEIGHT,k=.5<this.ds.scale;c.save();c.globalAlpha=this.editor_alpha;for(var n=g.WIDGET_OUTLINE_COLOR,q=g.WIDGET_BGCOLOR,u=g.WIDGET_TEXT_COLOR,r=g.WIDGET_SECONDARY_TEXT_COLOR,m=0;m<f.length;++m){var l=f[m],t=b;l.y&&(t=l.y);l.last_y=t;c.strokeStyle=n;c.fillStyle="#222";c.textAlign="left";l.disabled&&(c.globalAlpha*=.5);var p=l.width||e;switch(l.type){case "button":l.clicked&&
|
||||
(c.fillStyle="#AAA",l.clicked=!1,this.dirty_canvas=!0);c.fillRect(15,t,p-30,h);k&&!l.disabled&&c.strokeRect(15,t,p-30,h);k&&(c.textAlign="center",c.fillStyle=u,c.fillText(l.name,.5*p,t+.7*h));break;case "toggle":c.textAlign="left";c.strokeStyle=n;c.fillStyle=q;c.beginPath();k?c.roundRect(15,t,p-30,h,[.5*h]):c.rect(15,t,p-30,h);c.fill();k&&!l.disabled&&c.stroke();c.fillStyle=l.value?"#89A":"#333";c.beginPath();c.arc(p-30,t+.5*h,.36*h,0,2*Math.PI);c.fill();k&&(c.fillStyle=r,null!=l.name&&c.fillText(l.name,
|
||||
30,t+.7*h),c.fillStyle=l.value?u:r,c.textAlign="right",c.fillText(l.value?l.options.on||"true":l.options.off||"false",p-40,t+.7*h));break;case "slider":c.fillStyle=q;c.fillRect(15,t,p-30,h);var v=l.options.max-l.options.min,w=(l.value-l.options.min)/v;c.fillStyle=d==l?"#89A":"#678";c.fillRect(15,t,w*(p-30),h);k&&!l.disabled&&c.strokeRect(15,t,p-30,h);l.marker&&(v=(l.marker-l.options.min)/v,c.fillStyle="#AA9",c.fillRect(15+v*(p-30),t,2,h));k&&(c.textAlign="center",c.fillStyle=u,c.fillText(l.name+" "+
|
||||
Number(l.value).toFixed(3),.5*p,t+.7*h));break;case "number":case "combo":c.textAlign="left";c.strokeStyle=n;c.fillStyle=q;c.beginPath();k?c.roundRect(15,t,p-30,h,[.5*h]):c.rect(15,t,p-30,h);c.fill();k&&(l.disabled||c.stroke(),c.fillStyle=u,l.disabled||(c.beginPath(),c.moveTo(31,t+5),c.lineTo(21,t+.5*h),c.lineTo(31,t+h-5),c.fill(),c.beginPath(),c.moveTo(p-15-16,t+5),c.lineTo(p-15-6,t+.5*h),c.lineTo(p-15-16,t+h-5),c.fill()),c.fillStyle=r,c.fillText(l.name,35,t+.7*h),c.fillStyle=u,c.textAlign="right",
|
||||
"number"==l.type?c.fillText(Number(l.value).toFixed(void 0!==l.options.precision?l.options.precision:3),p-30-20,t+.7*h):(v=l.value,l.options.values&&(w=l.options.values,w.constructor===Function&&(w=w()),w&&w.constructor!==Array&&(v=w[l.value])),c.fillText(v,p-30-20,t+.7*h)));break;case "string":case "text":c.textAlign="left";c.strokeStyle=n;c.fillStyle=q;c.beginPath();k?c.roundRect(15,t,p-30,h,[.5*h]):c.rect(15,t,p-30,h);c.fill();k&&(l.disabled||c.stroke(),c.save(),c.beginPath(),c.rect(15,t,p-30,
|
||||
h),c.clip(),c.fillStyle=r,null!=l.name&&c.fillText(l.name,30,t+.7*h),c.fillStyle=u,c.textAlign="right",c.fillText(String(l.value).substr(0,30),p-30,t+.7*h),c.restore());break;default:l.draw&&l.draw(c,a,p,t,h)}b+=(l.computeSize?l.computeSize(p)[1]:h)+4;c.globalAlpha=this.editor_alpha}c.restore();c.textAlign="left"};m.prototype.processNodeWidgets=function(a,b,c,d){function e(e,d){e.value=d;e.options&&e.options.property&&void 0!==a.properties[e.options.property]&&a.setProperty(e.options.property,d);
|
||||
e.callback&&e.callback(e.value,n,a,b,c)}if(!a.widgets||!a.widgets.length)return null;for(var f=b[0]-a.pos[0],h=b[1]-a.pos[1],k=a.size[0],n=this,q=this.getCanvasWindow(),u=0;u<a.widgets.length;++u){var r=a.widgets[u];if(r&&!r.disabled){var m=r.computeSize?r.computeSize(k)[1]:g.NODE_WIDGET_HEIGHT,l=r.width||k;if(r==d||!(6>f||f>l-12||h<r.last_y||h>r.last_y+m||void 0===r.last_y)){d=r.value;switch(r.type){case "button":c.type===g.pointerevents_method+"down"&&(r.callback&&setTimeout(function(){r.callback(r,
|
||||
n,a,b,c)},20),this.dirty_canvas=r.clicked=!0);break;case "slider":q=Math.clamp((f-15)/(l-30),0,1);r.value=r.options.min+(r.options.max-r.options.min)*q;r.callback&&setTimeout(function(){e(r,r.value)},20);this.dirty_canvas=!0;break;case "number":case "combo":d=r.value;if(c.type==g.pointerevents_method+"move"&&"number"==r.type)r.value+=.1*c.deltaX*(r.options.step||1),null!=r.options.min&&r.value<r.options.min&&(r.value=r.options.min),null!=r.options.max&&r.value>r.options.max&&(r.value=r.options.max);
|
||||
else if(c.type==g.pointerevents_method+"down"){var t=r.options.values;t&&t.constructor===Function&&(t=r.options.values(r,a));var p=null;"number"!=r.type&&(p=t.constructor===Array?t:Object.keys(t));f=40>f?-1:f>l-40?1:0;if("number"==r.type)r.value+=.1*f*(r.options.step||1),null!=r.options.min&&r.value<r.options.min&&(r.value=r.options.min),null!=r.options.max&&r.value>r.options.max&&(r.value=r.options.max);else if(f)q=-1,this.last_mouseclick=0,q=t.constructor===Object?p.indexOf(String(r.value))+f:p.indexOf(r.value)+
|
||||
f,q>=p.length&&(q=p.length-1),0>q&&(q=0),r.value=t.constructor===Array?t[q]:q;else{var v=t!=p?Object.values(t):t;new g.ContextMenu(v,{scale:Math.max(1,this.ds.scale),event:c,className:"dark",callback:function(a,b,c){t!=p&&(a=v.indexOf(a));this.value=a;e(this,a);n.dirty_canvas=!0;return!1}.bind(r)},q)}}else c.type==g.pointerevents_method+"up"&&"number"==r.type&&(f=40>f?-1:f>l-40?1:0,200>c.click_time&&0==f&&this.prompt("Value",r.value,function(a){this.value=Number(a);e(this,this.value)}.bind(r),c));
|
||||
d!=r.value&&setTimeout(function(){e(this,this.value)}.bind(r),20);this.dirty_canvas=!0;break;case "toggle":c.type==g.pointerevents_method+"down"&&(r.value=!r.value,setTimeout(function(){e(r,r.value)},20));break;case "string":case "text":c.type==g.pointerevents_method+"down"&&this.prompt("Value",r.value,function(a){this.value=a;e(this,a)}.bind(r),c,r.options?r.options.multiline:!1);break;default:r.mouse&&(this.dirty_canvas=r.mouse(c,[f,h],a))}if(d!=r.value){if(a.onWidgetChanged)a.onWidgetChanged(r.name,
|
||||
r.value,d,r);a.graph._version++}return r}}}return null};m.prototype.drawGroups=function(a,b){if(this.graph){a=this.graph._groups;b.save();b.globalAlpha=.5*this.editor_alpha;for(var c=0;c<a.length;++c){var d=a[c];if(F(this.visible_area,d._bounding)){b.fillStyle=d.color||"#335";b.strokeStyle=d.color||"#335";var e=d._pos,f=d._size;b.globalAlpha=.25*this.editor_alpha;b.beginPath();b.rect(e[0]+.5,e[1]+.5,f[0],f[1]);b.fill();b.globalAlpha=this.editor_alpha;b.stroke();b.beginPath();b.moveTo(e[0]+f[0],e[1]+
|
||||
f[1]);b.lineTo(e[0]+f[0]-10,e[1]+f[1]);b.lineTo(e[0]+f[0],e[1]+f[1]-10);b.fill();f=d.font_size||g.DEFAULT_GROUP_FONT_SIZE;b.font=f+"px Arial";b.textAlign="left";b.fillText(d.title,e[0]+4,e[1]+f)}}b.restore()}};m.prototype.adjustNodesSize=function(){for(var a=this.graph._nodes,b=0;b<a.length;++b)a[b].size=a[b].computeSize();this.setDirty(!0,!0)};m.prototype.resize=function(a,b){a||b||(b=this.canvas.parentNode,a=b.offsetWidth,b=b.offsetHeight);if(this.canvas.width!=a||this.canvas.height!=b)this.canvas.width=
|
||||
a,this.canvas.height=b,this.bgcanvas.width=this.canvas.width,this.bgcanvas.height=this.canvas.height,this.setDirty(!0,!0)};m.prototype.switchLiveMode=function(a){if(a){var b=this,c=this.live_mode?1.1:.9;this.live_mode&&(this.live_mode=!1,this.editor_alpha=.1);var d=setInterval(function(){b.editor_alpha*=c;b.dirty_canvas=!0;b.dirty_bgcanvas=!0;1>c&&.01>b.editor_alpha&&(clearInterval(d),1>c&&(b.live_mode=!0));1<c&&.99<b.editor_alpha&&(clearInterval(d),b.editor_alpha=1)},1)}else this.live_mode=!this.live_mode,
|
||||
this.dirty_bgcanvas=this.dirty_canvas=!0};m.prototype.onNodeSelectionChange=function(a){};m.onGroupAdd=function(a,b,c){a=m.active_canvas;a.getCanvasWindow();b=new g.LGraphGroup;b.pos=a.convertEventToCanvasOffset(c);a.graph.add(b)};m.onMenuAdd=function(a,b,c,d,e){function f(a,b){var d=[];g.getNodeTypesCategories(h.filter||n.filter).filter(function(b){return b.startsWith(a)}).map(function(b){if(b){b=b.replace(new RegExp("^("+a+")"),"").split("/")[0];var c=""===a?b+"/":a+b+"/";-1!=b.indexOf("::")&&(b=
|
||||
b.split("::")[1]);-1===d.findIndex(function(a){return a.value===c})&&d.push({value:c,content:b,has_submenu:!0,callback:function(a,b,c,e){f(a.value,e)}})}});g.getNodeTypesInCategory(a.slice(0,-1),h.filter||n.filter).map(function(a){a.skip_list||d.push({value:a.type,content:a.title,has_submenu:!1,callback:function(a,b,c,d){b=d.getFirstEvent();h.graph.beforeChange();if(a=g.createNode(a.value))a.pos=h.convertEventToCanvasOffset(b),h.graph.add(a);e&&e(a);h.graph.afterChange()}})});new g.ContextMenu(d,
|
||||
{event:c,parentMenu:b},k)}var h=m.active_canvas,k=h.getCanvasWindow(),n=h.graph;if(n)return f("",d),!1};m.onMenuCollapseAll=function(){};m.onMenuNodeEdit=function(){};m.showMenuNodeOptionalInputs=function(a,b,c,d,e){if(e){var f=this;a=m.active_canvas.getCanvasWindow();b=e.optional_inputs;e.onGetInputs&&(b=e.onGetInputs());var h=[];if(b)for(var k=0;k<b.length;k++){var n=b[k];if(n){var q=n[0];n[2]||(n[2]={});n[2].label&&(q=n[2].label);n[2].removable=!0;q={content:q,value:n};n[1]==g.ACTION&&(q.className=
|
||||
"event");h.push(q)}else h.push(null)}e.onMenuNodeInputs&&(b=e.onMenuNodeInputs(h))&&(h=b);if(h.length)return new g.ContextMenu(h,{event:c,callback:function(a,b,c){if(e&&(a.callback&&a.callback.call(f,e,a,b,c),a.value)){e.graph.beforeChange();e.addInput(a.value[0],a.value[1],a.value[2]);if(e.onNodeInputAdd)e.onNodeInputAdd(a.value);e.setDirtyCanvas(!0,!0);e.graph.afterChange()}},parentMenu:d,node:e},a),!1;console.log("no input entries")}};m.showMenuNodeOptionalOutputs=function(a,b,c,d,e){function f(a,
|
||||
b,c){if(e&&(a.callback&&a.callback.call(h,e,a,b,c),a.value))if(c=a.value[1],!c||c.constructor!==Object&&c.constructor!==Array){e.graph.beforeChange();e.addOutput(a.value[0],a.value[1],a.value[2]);if(e.onNodeOutputAdd)e.onNodeOutputAdd(a.value);e.setDirtyCanvas(!0,!0);e.graph.afterChange()}else{a=[];for(var k in c)a.push({content:k,value:c[k]});new g.ContextMenu(a,{event:b,callback:f,parentMenu:d,node:e});return!1}}if(e){var h=this;a=m.active_canvas.getCanvasWindow();b=e.optional_outputs;e.onGetOutputs&&
|
||||
(b=e.onGetOutputs());var k=[];if(b)for(var n=0;n<b.length;n++){var q=b[n];if(!q)k.push(null);else if(!e.flags||!e.flags.skip_repeated_outputs||-1==e.findOutputSlot(q[0])){var u=q[0];q[2]||(q[2]={});q[2].label&&(u=q[2].label);q[2].removable=!0;u={content:u,value:q};q[1]==g.EVENT&&(u.className="event");k.push(u)}}this.onMenuNodeOutputs&&(k=this.onMenuNodeOutputs(k));g.do_add_triggers_slots&&-1==e.findOutputSlot("onExecuted")&&k.push({content:"On Executed",value:["onExecuted",g.EVENT,{nameLocked:!0}],
|
||||
className:"event"});e.onMenuNodeOutputs&&(b=e.onMenuNodeOutputs(k))&&(k=b);if(k.length)return new g.ContextMenu(k,{event:c,callback:f,parentMenu:d,node:e},a),!1}};m.onShowMenuNodeProperties=function(a,b,c,d,e){if(e&&e.properties){var f=m.active_canvas;b=f.getCanvasWindow();var h=[],k;for(k in e.properties){a=void 0!==e.properties[k]?e.properties[k]:" ";"object"==typeof a&&(a=JSON.stringify(a));var n=e.getPropertyInfo(k);if("enum"==n.type||"combo"==n.type)a=m.getPropertyPrintableValue(a,n.values);
|
||||
a=m.decodeHTML(a);h.push({content:"<span class='property_name'>"+(n.label?n.label:k)+"</span><span class='property_value'>"+a+"</span>",value:k})}if(h.length)return new g.ContextMenu(h,{event:c,callback:function(a,b,c,d){e&&(b=this.getBoundingClientRect(),f.showEditPropertyValue(e,a.value,{position:[b.left,b.top]}))},parentMenu:d,allow_html:!0,node:e},b),!1}};m.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};m.onMenuResizeNode=function(a,b,c,d,e){if(e){a=
|
||||
function(a){a.size=a.computeSize();if(a.onResize)a.onResize(a.size)};b=m.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)a(e);else for(var f in b.selected_nodes)a(b.selected_nodes[f]);e.setDirtyCanvas(!0,!0)}};m.prototype.showLinkMenu=function(a,b){var c=this,d=c.graph.getNodeById(a.origin_id),e=c.graph.getNodeById(a.target_id),f=!1;d&&d.outputs&&d.outputs[a.origin_slot]&&(f=d.outputs[a.origin_slot].type);var h=!1;e&&e.outputs&&e.outputs[a.target_slot]&&(h=e.inputs[a.target_slot].type);
|
||||
var k=new g.ContextMenu(["Add Node",null,"Delete",null],{event:b,title:null!=a.data?a.data.constructor.name:null,callback:function(b,g,u){switch(b){case "Add Node":m.onMenuAdd(null,null,u,k,function(b){b.inputs&&b.inputs.length&&b.outputs&&b.outputs.length&&d.connectByType(a.origin_slot,b,f)&&(b.connectByType(a.target_slot,e,h),b.pos[0]-=.5*b.size[0])});break;case "Delete":c.graph.removeLink(a.id)}}});return!1};m.prototype.createDefaultNodeForSlot=function(a){a=a||{};a=Object.assign({nodeFrom:null,
|
||||
slotFrom:null,nodeTo:null,slotTo:null,position:[],nodeType:null,posAdd:[0,0],posSizeFix:[0,0]},a);var b=a.nodeFrom&&null!==a.slotFrom,c=!b&&a.nodeTo&&null!==a.slotTo;if(!b&&!c)return console.warn("No data passed to createDefaultNodeForSlot "+a.nodeFrom+" "+a.slotFrom+" "+a.nodeTo+" "+a.slotTo),!1;if(!a.nodeType)return console.warn("No type to createDefaultNodeForSlot"),!1;var d=b?a.nodeFrom:a.nodeTo,e=b?a.slotFrom:a.slotTo;switch(typeof e){case "string":c=b?d.findOutputSlot(e,!1):d.findInputSlot(e,
|
||||
!1);e=b?d.outputs[e]:d.inputs[e];break;case "object":c=b?d.findOutputSlot(e.name):d.findInputSlot(e.name);break;case "number":c=e;e=b?d.outputs[e]:d.inputs[e];break;default:return console.warn("Cant get slot information "+e),!1}!1!==e&&!1!==c||console.warn("createDefaultNodeForSlot bad slotX "+e+" "+c);d=e.type==g.EVENT?"_event_":e.type;if((e=b?g.slot_types_default_out:g.slot_types_default_in)&&e[d]){nodeNewType=!1;if("object"==typeof e[d]||"array"==typeof e[d])for(var f in e[d]){if(a.nodeType==e[d][f]||
|
||||
"AUTO"==a.nodeType){nodeNewType=e[d][f];break}}else if(a.nodeType==e[d]||"AUTO"==a.nodeType)nodeNewType=e[d];if(nodeNewType){f=!1;"object"==typeof nodeNewType&&nodeNewType.node&&(f=nodeNewType,nodeNewType=nodeNewType.node);if(e=g.createNode(nodeNewType)){if(f){if(f.properties)for(var h in f.properties)e.addProperty(h,f.properties[h]);if(f.inputs)for(h in e.inputs=[],f.inputs)e.addOutput(f.inputs[h][0],f.inputs[h][1]);if(f.outputs)for(h in e.outputs=[],f.outputs)e.addOutput(f.outputs[h][0],f.outputs[h][1]);
|
||||
f.title&&(e.title=f.title);f.json&&e.configure(f.json)}this.graph.add(e);e.pos=[a.position[0]+a.posAdd[0]+(a.posSizeFix[0]?a.posSizeFix[0]*e.size[0]:0),a.position[1]+a.posAdd[1]+(a.posSizeFix[1]?a.posSizeFix[1]*e.size[1]:0)];b?a.nodeFrom.connectByType(c,e,d):a.nodeTo.connectByTypeOutput(c,e,d);return!0}console.log("failed creating "+nodeNewType)}}return!1};m.prototype.showConnectionMenu=function(a){a=a||{};var b=Object.assign({nodeFrom:null,slotFrom:null,nodeTo:null,slotTo:null,e:null},a),c=this,
|
||||
d=b.nodeFrom&&b.slotFrom;a=!d&&b.nodeTo&&b.slotTo;if(!d&&!a)return console.warn("No data passed to showConnectionMenu"),!1;a=d?b.nodeFrom:b.nodeTo;var e=d?b.slotFrom:b.slotTo,f=!1;switch(typeof e){case "string":f=d?a.findOutputSlot(e,!1):a.findInputSlot(e,!1);e=d?a.outputs[e]:a.inputs[e];break;case "object":f=d?a.findOutputSlot(e.name):a.findInputSlot(e.name);break;case "number":f=e;e=d?a.outputs[e]:a.inputs[e];break;default:return console.warn("Cant get slot information "+e),!1}a=["Add Node",null];
|
||||
c.allow_searchbox&&(a.push("Search"),a.push(null));var h=e.type==g.EVENT?"_event_":e.type,k=d?g.slot_types_default_out:g.slot_types_default_in;if(k&&k[h])if("object"==typeof k[h]||"array"==typeof k[h])for(var n in k[h])a.push(k[h][n]);else a.push(k[h]);var q=new g.ContextMenu(a,{event:b.e,title:(e&&""!=e.name?e.name+(h?" | ":""):"")+(e&&h?h:""),callback:function(a,g,k){switch(a){case "Add Node":m.onMenuAdd(null,null,k,q,function(a){d?b.nodeFrom.connectByType(f,a,h):b.nodeTo.connectByTypeOutput(f,
|
||||
a,h)});break;case "Search":d?c.showSearchBox(k,{node_from:b.nodeFrom,slot_from:e,type_filter_in:h}):c.showSearchBox(k,{node_to:b.nodeTo,slot_from:e,type_filter_out:h});break;default:c.createDefaultNodeForSlot(Object.assign(b,{position:[b.e.canvasX,b.e.canvasY],nodeType:a}))}}});return!1};m.onShowPropertyEditor=function(a,b,c,d,e){function f(){if(n){var b=n.value;"Number"==a.type?b=Number(b):"Boolean"==a.type&&(b=!!b);e[h]=b;k.parentNode&&k.parentNode.removeChild(k);e.setDirtyCanvas(!0,!0)}}var h=
|
||||
a.property||"title";b=e[h];var k=document.createElement("div");k.is_modified=!1;k.className="graphdialog";k.innerHTML="<span class='name'></span><input autofocus type='text' class='value'/><button>OK</button>";k.close=function(){k.parentNode&&k.parentNode.removeChild(k)};k.querySelector(".name").innerText=h;var n=k.querySelector(".value");n&&(n.value=b,n.addEventListener("blur",function(a){this.focus()}),n.addEventListener("keydown",function(a){k.is_modified=!0;if(27==a.keyCode)k.close();else if(13==
|
||||
a.keyCode)f();else if(13!=a.keyCode&&"textarea"!=a.target.localName)return;a.preventDefault();a.stopPropagation()}));b=m.active_canvas.canvas;c=b.getBoundingClientRect();var q=d=-20;c&&(d-=c.left,q-=c.top);event?(k.style.left=event.clientX+d+"px",k.style.top=event.clientY+q+"px"):(k.style.left=.5*b.width+d+"px",k.style.top=.5*b.height+q+"px");k.querySelector("button").addEventListener("click",f);b.parentNode.appendChild(k);n&&n.focus();var l=null;k.addEventListener("mouseleave",function(a){g.dialog_close_on_mouse_leave&&
|
||||
!k.is_modified&&g.dialog_close_on_mouse_leave&&(l=setTimeout(k.close,g.dialog_close_on_mouse_leave_delay))});k.addEventListener("mouseenter",function(a){g.dialog_close_on_mouse_leave&&l&&clearTimeout(l)})};m.prototype.prompt=function(a,b,c,d,e){var f=this;a=a||"";var h=document.createElement("div");h.is_modified=!1;h.className="graphdialog rounded";h.innerHTML=e?"<span class='name'></span> <textarea autofocus class='value'></textarea><button class='rounded'>OK</button>":"<span class='name'></span> <input autofocus type='text' class='value'/><button class='rounded'>OK</button>";
|
||||
h.close=function(){f.prompt_box=null;h.parentNode&&h.parentNode.removeChild(h)};e=m.active_canvas.canvas;e.parentNode.appendChild(h);1<this.ds.scale&&(h.style.transform="scale("+this.ds.scale+")");var k=null,n=!1;g.pointerListenerAdd(h,"leave",function(a){n||g.dialog_close_on_mouse_leave&&!h.is_modified&&g.dialog_close_on_mouse_leave&&(k=setTimeout(h.close,g.dialog_close_on_mouse_leave_delay))});g.pointerListenerAdd(h,"enter",function(a){g.dialog_close_on_mouse_leave&&k&&clearTimeout(k)});var q=h.querySelectorAll("select");
|
||||
q&&q.forEach(function(a){a.addEventListener("click",function(a){n++});a.addEventListener("blur",function(a){n=0});a.addEventListener("change",function(a){n=-1})});f.prompt_box&&f.prompt_box.close();f.prompt_box=h;h.querySelector(".name").innerText=a;var l=h.querySelector(".value");l.value=b;l.addEventListener("keydown",function(a){h.is_modified=!0;if(27==a.keyCode)h.close();else if(13==a.keyCode&&"textarea"!=a.target.localName)c&&c(this.value),h.close();else return;a.preventDefault();a.stopPropagation()});
|
||||
h.querySelector("button").addEventListener("click",function(a){c&&c(l.value);f.setDirty(!0);h.close()});a=e.getBoundingClientRect();q=b=-20;a&&(b-=a.left,q-=a.top);d?(h.style.left=d.clientX+b+"px",h.style.top=d.clientY+q+"px"):(h.style.left=.5*e.width+b+"px",h.style.top=.5*e.height+q+"px");setTimeout(function(){l.focus()},10);return h};m.search_limit=-1;m.prototype.showSearchBox=function(a,b){function c(c){if(c)if(f.onSearchBoxSelection)f.onSearchBoxSelection(c,a,h);else{var e=g.searchbox_extras[c.toLowerCase()];
|
||||
e&&(c=e.type);h.graph.beforeChange();if(c=g.createNode(c))c.pos=h.convertEventToCanvasOffset(a),h.graph.add(c,!1);if(e&&e.data){if(e.data.properties)for(var d in e.data.properties)c.addProperty(d,e.data.properties[d]);if(e.data.inputs)for(d in c.inputs=[],e.data.inputs)c.addOutput(e.data.inputs[d][0],e.data.inputs[d][1]);if(e.data.outputs)for(d in c.outputs=[],e.data.outputs)c.addOutput(e.data.outputs[d][0],e.data.outputs[d][1]);e.data.title&&(c.title=e.data.title);e.data.json&&c.configure(e.data.json)}if(b.node_from){switch(typeof b.slot_from){case "string":e=
|
||||
b.node_from.findOutputSlot(b.slot_from);break;case "object":e=b.slot_from.name?b.node_from.findOutputSlot(b.slot_from.name):-1;-1==e&&"undefined"!==typeof b.slot_from.slot_index&&(e=b.slot_from.slot_index);break;case "number":e=b.slot_from;break;default:e=0}!1!==e&&-1<e&&b.node_from.connectByType(e,c,b.node_from.outputs[e].type)}if(b.node_to){switch(typeof b.slot_from){case "string":e=b.node_to.findInputSlot(b.slot_from);break;case "object":e=b.slot_from.name?b.node_to.findInputSlot(b.slot_from.name):
|
||||
-1;-1==e&&"undefined"!==typeof b.slot_from.slot_index&&(e=b.slot_from.slot_index);break;case "number":e=b.slot_from;break;default:e=0}!1!==e&&-1<e&&b.node_to.connectByTypeOutput(e,c,b.node_to.inputs[e].type)}h.graph.afterChange()}q.close()}function d(a){var b=x;x&&x.classList.remove("selected");x?(x=a?x.nextSibling:x.previousSibling)||(x=b):x=a?t.childNodes[0]:t.childNodes[t.childNodes.length];x&&(x.classList.add("selected"),x.scrollIntoView({block:"end",behavior:"smooth"}))}function e(){function a(a,
|
||||
b){var e=document.createElement("div");w||(w=a);e.innerText=a;e.dataset.type=escape(a);e.className="litegraph lite-search-item";b&&(e.className+=" "+b);e.addEventListener("click",function(a){c(unescape(this.dataset.type))});t.appendChild(e)}y=null;var e=z.value;w=null;t.innerHTML="";if(e||b.show_all_if_empty)if(f.onSearchBox){var d=f.onSearchBox(t,e,h);if(d)for(var k=0;k<d.length;++k)a(d[k])}else{d=function(a,c){c=c||{};c=Object.assign({skipFilter:!1,inTypeOverride:!1,outTypeOverride:!1},c);var d=
|
||||
g.registered_node_types[a];if(q&&d.filter!=q||(!b.show_all_if_empty||e)&&-1===a.toLowerCase().indexOf(e))return!1;if(b.do_type_filter&&!c.skipFilter){d=l.value;!1!==c.inTypeOverride&&(d=c.inTypeOverride);if(l&&d&&g.registered_slot_in_types[d]&&g.registered_slot_in_types[d].nodes&&(d=g.registered_slot_in_types[d].nodes.includes(a),!1===d))return!1;d=r.value;!1!==c.outTypeOverride&&(d=c.outTypeOverride);if(r&&d&&g.registered_slot_out_types[d]&&g.registered_slot_out_types[d].nodes&&(d=g.registered_slot_out_types[d].nodes.includes(a),
|
||||
!1===d))return!1}return!0};var n=0;e=e.toLowerCase();var q=h.filter||h.graph.filter;if(b.do_type_filter&&f.search_box)var l=f.search_box.querySelector(".slot_in_type_filter"),r=f.search_box.querySelector(".slot_out_type_filter");else r=l=!1;for(k in g.searchbox_extras){var u=g.searchbox_extras[k];if(b.show_all_if_empty&&!e||-1!==u.desc.toLowerCase().indexOf(e)){var p=g.registered_node_types[u.type];if((!p||p.filter==q)&&d(u.type)&&(a(u.desc,"searchbox_extra"),-1!==m.search_limit&&n++>m.search_limit))break}}u=
|
||||
null;if(Array.prototype.filter)u=Object.keys(g.registered_node_types).filter(d);else for(k in u=[],g.registered_node_types)d(k)&&u.push(k);for(k=0;k<u.length&&!(a(u[k]),-1!==m.search_limit&&n++>m.search_limit);k++);if(b.show_general_after_typefiltered&&(l.value||r.value)){filtered_extra=[];for(k in g.registered_node_types)d(k,{inTypeOverride:l&&l.value?"*":!1,outTypeOverride:r&&r.value?"*":!1})&&filtered_extra.push(k);for(k=0;k<filtered_extra.length&&!(a(filtered_extra[k],"generic_type"),-1!==m.search_limit&&
|
||||
n++>m.search_limit);k++);}if((l.value||r.value)&&0==t.childNodes.length&&b.show_general_if_none_on_typefilter){filtered_extra=[];for(k in g.registered_node_types)d(k,{skipFilter:!0})&&filtered_extra.push(k);for(k=0;k<filtered_extra.length&&!(a(filtered_extra[k],"not_in_filter"),-1!==m.search_limit&&n++>m.search_limit);k++);}}}def_options={slot_from:null,node_from:null,node_to:null,do_type_filter:g.search_filter_enabled,type_filter_in:!1,type_filter_out:!1,show_general_if_none_on_typefilter:!0,show_general_after_typefiltered:!0,
|
||||
hide_on_mouse_leave:g.search_hide_on_mouse_leave,show_all_if_empty:!0,show_all_on_open:g.search_show_all_on_open};b=Object.assign(def_options,b||{});var f=this,h=m.active_canvas,k=h.canvas,n=k.ownerDocument||document,q=document.createElement("div");q.className="litegraph litesearchbox graphdialog rounded";q.innerHTML="<span class='name'>Search</span> <input autofocus type='text' class='value rounded'/>";b.do_type_filter&&(q.innerHTML+="<select class='slot_in_type_filter'><option value=''></option></select>",
|
||||
q.innerHTML+="<select class='slot_out_type_filter'><option value=''></option></select>");q.innerHTML+="<div class='helper'></div>";n.fullscreenElement?n.fullscreenElement.appendChild(q):(n.body.appendChild(q),n.body.style.overflow="hidden");if(b.do_type_filter)var l=q.querySelector(".slot_in_type_filter"),r=q.querySelector(".slot_out_type_filter");q.close=function(){f.search_box=null;n.body.focus();n.body.style.overflow="";setTimeout(function(){f.canvas.focus()},20);q.parentNode&&q.parentNode.removeChild(q)};
|
||||
1<this.ds.scale&&(q.style.transform="scale("+this.ds.scale+")");if(b.hide_on_mouse_leave){var p=!1,v=null;g.pointerListenerAdd(q,"enter",function(a){v&&(clearTimeout(v),v=null)});g.pointerListenerAdd(q,"leave",function(a){p||(v=setTimeout(function(){q.close()},500))});b.do_type_filter&&(l.addEventListener("click",function(a){p++}),l.addEventListener("blur",function(a){p=0}),l.addEventListener("change",function(a){p=-1}),r.addEventListener("click",function(a){p++}),r.addEventListener("blur",function(a){p=
|
||||
0}),r.addEventListener("change",function(a){p=-1}))}f.search_box&&f.search_box.close();f.search_box=q;var t=q.querySelector(".helper"),w=null,y=null,x=null,z=q.querySelector("input");z&&(z.addEventListener("blur",function(a){this.focus()}),z.addEventListener("keydown",function(a){if(38==a.keyCode)d(!1);else if(40==a.keyCode)d(!0);else if(27==a.keyCode)q.close();else if(13==a.keyCode)x?c(x.innerHTML):w?c(w):q.close();else{y&&clearInterval(y);y=setTimeout(e,250);return}a.preventDefault();a.stopPropagation();
|
||||
a.stopImmediatePropagation();return!0}));if(b.do_type_filter){if(l){var A=g.slot_types_in,C=A.length;if(b.type_filter_in==g.EVENT||b.type_filter_in==g.ACTION)b.type_filter_in="_event_";for(var B=0;B<C;B++){var D=document.createElement("option");D.value=A[B];D.innerHTML=A[B];l.appendChild(D);!1!==b.type_filter_in&&(b.type_filter_in+"").toLowerCase()==(A[B]+"").toLowerCase()&&(D.selected=!0)}l.addEventListener("change",function(){e()})}if(r){A=g.slot_types_out;C=A.length;if(b.type_filter_out==g.EVENT||
|
||||
b.type_filter_out==g.ACTION)b.type_filter_out="_event_";for(B=0;B<C;B++)D=document.createElement("option"),D.value=A[B],D.innerHTML=A[B],r.appendChild(D),!1!==b.type_filter_out&&(b.type_filter_out+"").toLowerCase()==(A[B]+"").toLowerCase()&&(D.selected=!0);r.addEventListener("change",function(){e()})}}k=k.getBoundingClientRect();l=(a?a.clientY:k.top+.5*k.height)-20;q.style.left=(a?a.clientX:k.left+.5*k.width)-80+"px";q.style.top=l+"px";a.layerY>k.height-200&&(t.style.maxHeight=k.height-a.layerY-20+
|
||||
"px");z.focus();b.show_all_on_open&&e();return q};m.prototype.showEditPropertyValue=function(a,b,c){function d(){e(m.value)}function e(e){f&&f.values&&f.values.constructor===Object&&void 0!=f.values[e]&&(e=f.values[e]);"number"==typeof a.properties[b]&&(e=Number(e));if("array"==h||"object"==h)e=JSON.parse(e);a.properties[b]=e;a.graph&&a.graph._version++;if(a.onPropertyChanged)a.onPropertyChanged(b,e);if(c.onclose)c.onclose();l.close();a.setDirtyCanvas(!0,!0)}if(a&&void 0!==a.properties[b]){c=c||{};
|
||||
var f=a.getPropertyInfo(b),h=f.type,g="";if("string"==h||"number"==h||"array"==h||"object"==h)g="<input autofocus type='text' class='value'/>";else if("enum"!=h&&"combo"!=h||!f.values)if("boolean"==h||"toggle"==h)g="<input autofocus type='checkbox' class='value' "+(a.properties[b]?"checked":"")+"/>";else{console.warn("unknown type: "+h);return}else{g="<select autofocus type='text' class='value'>";for(var n in f.values){var q=n;f.values.constructor===Array&&(q=f.values[n]);g+="<option value='"+q+"' "+
|
||||
(q==a.properties[b]?"selected":"")+">"+f.values[n]+"</option>"}g+="</select>"}var l=this.createDialog("<span class='name'>"+(f.label?f.label:b)+"</span>"+g+"<button>OK</button>",c),m=!1;if("enum"!=h&&"combo"!=h||!f.values)if("boolean"==h||"toggle"==h)(m=l.querySelector("input"))&&m.addEventListener("click",function(a){l.modified();e(!!m.checked)});else{if(m=l.querySelector("input"))m.addEventListener("blur",function(a){this.focus()}),q=void 0!==a.properties[b]?a.properties[b]:"","string"!==h&&(q=
|
||||
JSON.stringify(q)),m.value=q,m.addEventListener("keydown",function(a){if(27==a.keyCode)l.close();else if(13==a.keyCode)d();else if(13!=a.keyCode){l.modified();return}a.preventDefault();a.stopPropagation()})}else m=l.querySelector("select"),m.addEventListener("change",function(a){l.modified();e(a.target.value)});m&&m.focus();l.querySelector("button").addEventListener("click",d);return l}};m.prototype.createDialog=function(a,b){def_options={checkForInput:!1,closeOnLeave:!0,closeOnLeave_checkModified:!0};
|
||||
b=Object.assign(def_options,b||{});var c=document.createElement("div");c.className="graphdialog";c.innerHTML=a;c.is_modified=!1;a=this.canvas.getBoundingClientRect();var d=-20,e=-20;a&&(d-=a.left,e-=a.top);b.position?(d+=b.position[0],e+=b.position[1]):b.event?(d+=b.event.clientX,e+=b.event.clientY):(d+=.5*this.canvas.width,e+=.5*this.canvas.height);c.style.left=d+"px";c.style.top=e+"px";this.canvas.parentNode.appendChild(c);b.checkForInput&&(a=[],(a=c.querySelectorAll("input"))&&a.forEach(function(a){a.addEventListener("keydown",
|
||||
function(a){c.modified();if(27==a.keyCode)c.close();else if(13!=a.keyCode)return;a.preventDefault();a.stopPropagation()});a.focus()}));c.modified=function(){c.is_modified=!0};c.close=function(){c.parentNode&&c.parentNode.removeChild(c)};var f=null,h=!1;c.addEventListener("mouseleave",function(a){h||(b.closeOnLeave||g.dialog_close_on_mouse_leave)&&!c.is_modified&&g.dialog_close_on_mouse_leave&&(f=setTimeout(c.close,g.dialog_close_on_mouse_leave_delay))});c.addEventListener("mouseenter",function(a){(b.closeOnLeave||
|
||||
g.dialog_close_on_mouse_leave)&&f&&clearTimeout(f)});(a=c.querySelectorAll("select"))&&a.forEach(function(a){a.addEventListener("click",function(a){h++});a.addEventListener("blur",function(a){h=0});a.addEventListener("change",function(a){h=-1})});return c};m.prototype.createPanel=function(a,b){b=b||{};var c=b.window||window,d=document.createElement("div");d.className="litegraph dialog";d.innerHTML="<div class='dialog-header'><span class='dialog-title'></span></div><div class='dialog-content'></div><div style='display:none;' class='dialog-alt-content'></div><div class='dialog-footer'></div>";
|
||||
d.header=d.querySelector(".dialog-header");b.width&&(d.style.width=b.width+(b.width.constructor===Number?"px":""));b.height&&(d.style.height=b.height+(b.height.constructor===Number?"px":""));b.closable&&(b=document.createElement("span"),b.innerHTML="✕",b.classList.add("close"),b.addEventListener("click",function(){d.close()}),d.header.appendChild(b));d.title_element=d.querySelector(".dialog-title");d.title_element.innerText=a;d.content=d.querySelector(".dialog-content");d.alt_content=d.querySelector(".dialog-alt-content");
|
||||
d.footer=d.querySelector(".dialog-footer");d.close=function(){if(d.onClose&&"function"==typeof d.onClose)d.onClose();d.parentNode.removeChild(d);this.parentNode&&this.parentNode.removeChild(this)};d.toggleAltContent=function(a){if("undefined"!=typeof a){var b=a?"block":"none";a=a?"none":"block"}else b="block"!=d.alt_content.style.display?"block":"none",a="block"!=d.alt_content.style.display?"none":"block";d.alt_content.style.display=b;d.content.style.display=a};d.toggleFooterVisibility=function(a){d.footer.style.display=
|
||||
"undefined"!=typeof a?a?"block":"none":"block"!=d.footer.style.display?"block":"none"};d.clear=function(){this.content.innerHTML=""};d.addHTML=function(a,b,c){var e=document.createElement("div");b&&(e.className=b);e.innerHTML=a;c?d.footer.appendChild(e):d.content.appendChild(e);return e};d.addButton=function(a,b,c){var e=document.createElement("button");e.innerText=a;e.options=c;e.classList.add("btn");e.addEventListener("click",b);d.footer.appendChild(e);return e};d.addSeparator=function(){var a=
|
||||
document.createElement("div");a.className="separator";d.content.appendChild(a)};d.addWidget=function(a,b,h,k,n){function e(a,b){k.callback&&k.callback(a,b,k);n&&n(a,b,k)}k=k||{};var f=String(h);a=a.toLowerCase();"number"==a&&(f=h.toFixed(3));var l=document.createElement("div");l.className="property";l.innerHTML="<span class='property_name'></span><span class='property_value'></span>";l.querySelector(".property_name").innerText=k.label||b;var p=l.querySelector(".property_value");p.innerText=f;l.dataset.property=
|
||||
b;l.dataset.type=k.type||a;l.options=k;l.value=h;if("code"==a)l.addEventListener("click",function(a){d.inner_showCodePad(this.dataset.property)});else if("boolean"==a)l.classList.add("boolean"),h&&l.classList.add("bool-on"),l.addEventListener("click",function(){var a=this.dataset.property;this.value=!this.value;this.classList.toggle("bool-on");this.querySelector(".property_value").innerText=this.value?"true":"false";e(a,this.value)});else if("string"==a||"number"==a)p.setAttribute("contenteditable",
|
||||
!0),p.addEventListener("keydown",function(b){"Enter"!=b.code||"string"==a&&b.shiftKey||(b.preventDefault(),this.blur())}),p.addEventListener("blur",function(){var a=this.innerText,b=this.parentNode.dataset.property;"number"==this.parentNode.dataset.type&&(a=Number(a));e(b,a)});else if("enum"==a||"combo"==a)f=m.getPropertyPrintableValue(h,k.values),p.innerText=f,p.addEventListener("click",function(a){var b=this.parentNode.dataset.property,d=this;new g.ContextMenu(k.values||[],{event:a,className:"dark",
|
||||
callback:function(a,c,f){d.innerText=a;e(b,a);return!1}},c)});d.content.appendChild(l);return l};if(d.onOpen&&"function"==typeof d.onOpen)d.onOpen();return d};m.getPropertyPrintableValue=function(a,b){if(!b||b.constructor===Array)return String(a);if(b.constructor===Object){var c="",d;for(d in b)if(b[d]==a){c=d;break}return String(a)+" ("+c+")"}};m.prototype.closePanels=function(){var a=document.querySelector("#node-panel");a&&a.close();(a=document.querySelector("#option-panel"))&&a.close()};m.prototype.showShowGraphOptionsPanel=
|
||||
function(a,b,c,d){if(this.constructor&&"HTMLDivElement"==this.constructor.name){if(!(b&&b.event&&b.event.target&&b.event.target.lgraphcanvas)){console.warn("Canvas not found");return}var e=b.event.target.lgraphcanvas}else e=this;e.closePanels();a=e.getCanvasWindow();panel=e.createPanel("Options",{closable:!0,window:a,onOpen:function(){e.OPTIONPANEL_IS_OPEN=!0},onClose:function(){e.OPTIONPANEL_IS_OPEN=!1;e.options_panel=null}});e.options_panel=panel;panel.id="option-panel";panel.classList.add("settings");
|
||||
(function(){panel.content.innerHTML="";var a=function(a,b,c){c&&c.key&&(a=c.key);c.values&&(b=Object.values(c.values).indexOf(b));e[a]=b},b=g.availableCanvasOptions;b.sort();for(pI in b){var c=b[pI];panel.addWidget("boolean",c,e[c],{key:c,on:"True",off:"False"},a)}panel.addWidget("combo","Render mode",g.LINK_RENDER_MODES[e.links_render_mode],{key:"links_render_mode",values:g.LINK_RENDER_MODES},a);panel.addSeparator();panel.footer.innerHTML=""})();e.canvas.parentNode.appendChild(panel)};m.prototype.showShowNodePanel=
|
||||
function(a){function b(){panel.content.innerHTML="";panel.addHTML("<span class='node_type'>"+a.type+"</span><span class='node_desc'>"+(a.constructor.desc||"")+"</span><span class='separator'></span>");panel.addHTML("<h3>Properties</h3>");var b=function(b,c){d.graph.beforeChange(a);switch(b){case "Title":a.title=c;break;case "Mode":b=Object.values(g.NODE_MODES).indexOf(c);0<=b&&g.NODE_MODES[b]?a.changeMode(b):console.warn("unexpected mode: "+c);break;case "Color":m.node_colors[c]?(a.color=m.node_colors[c].color,
|
||||
a.bgcolor=m.node_colors[c].bgcolor):console.warn("unexpected color: "+c);break;default:a.setProperty(b,c)}d.graph.afterChange();d.dirty_canvas=!0};panel.addWidget("string","Title",a.title,{},b);panel.addWidget("combo","Mode",g.NODE_MODES[a.mode],{values:g.NODE_MODES},b);var c="";void 0!==a.color&&(c=Object.keys(m.node_colors).filter(function(b){return m.node_colors[b].color==a.color}));panel.addWidget("combo","Color",c,{values:Object.keys(m.node_colors)},b);for(var h in a.properties){c=a.properties[h];
|
||||
var k=a.getPropertyInfo(h);a.onAddPropertyToPanel&&a.onAddPropertyToPanel(h,panel)||panel.addWidget(k.widget||k.type,h,c,k,b)}panel.addSeparator();if(a.onShowCustomPanelInfo)a.onShowCustomPanelInfo(panel);panel.footer.innerHTML="";panel.addButton("Delete",function(){a.block_delete||(a.graph.remove(a),panel.close())}).classList.add("delete")}this.SELECTED_NODE=a;this.closePanels();var c=this.getCanvasWindow(),d=this;panel=this.createPanel(a.title||"",{closable:!0,window:c,onOpen:function(){d.NODEPANEL_IS_OPEN=
|
||||
!0},onClose:function(){d.NODEPANEL_IS_OPEN=!1;d.node_panel=null}});d.node_panel=panel;panel.id="node-panel";panel.node=a;panel.classList.add("settings");panel.inner_showCodePad=function(c){panel.classList.remove("settings");panel.classList.add("centered");panel.alt_content.innerHTML="<textarea class='code'></textarea>";var e=panel.alt_content.querySelector("textarea"),d=function(){panel.toggleAltContent(!1);panel.toggleFooterVisibility(!0);e.parentNode.removeChild(e);panel.classList.add("settings");
|
||||
panel.classList.remove("centered");b()};e.value=a.properties[c];e.addEventListener("keydown",function(b){"Enter"==b.code&&b.ctrlKey&&(a.setProperty(c,e.value),d())});panel.toggleAltContent(!0);panel.toggleFooterVisibility(!1);e.style.height="calc(100% - 40px)";var g=panel.addButton("Assign",function(){a.setProperty(c,e.value);d()});panel.alt_content.appendChild(g);g=panel.addButton("Close",d);g.style.float="right";panel.alt_content.appendChild(g)};b();this.canvas.parentNode.appendChild(panel)};m.prototype.showSubgraphPropertiesDialog=
|
||||
function(a){function b(){d.clear();if(a.inputs)for(var c=0;c<a.inputs.length;++c){var f=a.inputs[c];if(!f.not_subgraph_input){var g=d.addHTML("<button>✕</button> <span class='bullet_icon'></span><span class='name'></span><span class='type'></span>","subgraph_property");g.dataset.name=f.name;g.dataset.slot=c;g.querySelector(".name").innerText=f.name;g.querySelector(".type").innerText=f.type;g.querySelector("button").addEventListener("click",function(c){a.removeInput(Number(this.parentNode.dataset.slot));
|
||||
b()})}}}console.log("showing subgraph properties dialog");var c=this.canvas.parentNode.querySelector(".subgraph_dialog");c&&c.close();var d=this.createPanel("Subgraph Inputs",{closable:!0,width:500});d.node=a;d.classList.add("subgraph_dialog");d.addHTML(" + <span class='label'>Name</span><input class='name'/><span class='label'>Type</span><input class='type'></input><button>+</button>","subgraph_property extra",!0).querySelector("button").addEventListener("click",function(c){c=this.parentNode;var e=
|
||||
c.querySelector(".name").value,d=c.querySelector(".type").value;e&&-1==a.findInputSlot(e)&&(a.addInput(e,d),c.querySelector(".name").value="",c.querySelector(".type").value="",b())});b();this.canvas.parentNode.appendChild(d);return d};m.prototype.showSubgraphPropertiesDialogRight=function(a){function b(){e.clear();if(a.outputs)for(var c=0;c<a.outputs.length;++c){var d=a.outputs[c];if(!d.not_subgraph_output){var g=e.addHTML("<button>✕</button> <span class='bullet_icon'></span><span class='name'></span><span class='type'></span>",
|
||||
"subgraph_property");g.dataset.name=d.name;g.dataset.slot=c;g.querySelector(".name").innerText=d.name;g.querySelector(".type").innerText=d.type;g.querySelector("button").addEventListener("click",function(c){a.removeOutput(Number(this.parentNode.dataset.slot));b()})}}}function c(){var c=this.parentNode,e=c.querySelector(".name").value,d=c.querySelector(".type").value;e&&-1==a.findOutputSlot(e)&&(a.addOutput(e,d),c.querySelector(".name").value="",c.querySelector(".type").value="",b())}var d=this.canvas.parentNode.querySelector(".subgraph_dialog");
|
||||
d&&d.close();var e=this.createPanel("Subgraph Outputs",{closable:!0,width:500});e.node=a;e.classList.add("subgraph_dialog");d=e.addHTML(" + <span class='label'>Name</span><input class='name'/><span class='label'>Type</span><input class='type'></input><button>+</button>","subgraph_property extra",!0);d.querySelector(".name").addEventListener("keydown",function(a){13==a.keyCode&&c.apply(this)});d.querySelector("button").addEventListener("click",function(a){c.apply(this)});b();this.canvas.parentNode.appendChild(e);
|
||||
return e};m.prototype.checkPanels=function(){if(this.canvas)for(var a=this.canvas.parentNode.querySelectorAll(".litegraph.dialog"),b=0;b<a.length;++b){var c=a[b];c.node&&(c.node.graph&&c.graph==this.graph||c.close())}};m.onMenuNodeCollapse=function(a,b,c,d,e){e.graph.beforeChange();a=m.active_canvas;if(!a.selected_nodes||1>=Object.keys(a.selected_nodes).length)e.collapse();else for(var f in a.selected_nodes)a.selected_nodes[f].collapse();e.graph.afterChange()};m.onMenuNodePin=function(a,b,c,d,e){e.pin()};
|
||||
m.onMenuNodeMode=function(a,b,c,d,e){new g.ContextMenu(g.NODE_MODES,{event:c,callback:function(a){if(e){var b=Object.values(g.NODE_MODES).indexOf(a),c=function(c){0<=b&&g.NODE_MODES[b]?c.changeMode(b):(console.warn("unexpected mode: "+a),c.changeMode(g.ALWAYS))},d=m.active_canvas;if(!d.selected_nodes||1>=Object.keys(d.selected_nodes).length)c(e);else for(var f in d.selected_nodes)c(d.selected_nodes[f])}},parentMenu:d,node:e});return!1};m.onMenuNodeColors=function(a,b,c,d,e){if(!e)throw"no node for color";
|
||||
b=[];b.push({value:null,content:"<span style='display: block; padding-left: 4px;'>No color</span>"});for(var f in m.node_colors)a=m.node_colors[f],a={value:f,content:"<span style='display: block; color: #999; padding-left: 4px; border-left: 8px solid "+a.color+"; background-color:"+a.bgcolor+"'>"+f+"</span>"},b.push(a);new g.ContextMenu(b,{event:c,callback:function(a){if(e){var b=a.value?m.node_colors[a.value]:null;a=function(a){b?a.constructor===g.LGraphGroup?a.color=b.groupcolor:(a.color=b.color,
|
||||
a.bgcolor=b.bgcolor):(delete a.color,delete a.bgcolor)};var c=m.active_canvas;if(!c.selected_nodes||1>=Object.keys(c.selected_nodes).length)a(e);else for(var d in c.selected_nodes)a(c.selected_nodes[d]);e.setDirtyCanvas(!0,!0)}},parentMenu:d,node:e});return!1};m.onMenuNodeShapes=function(a,b,c,d,e){if(!e)throw"no node passed";new g.ContextMenu(g.VALID_SHAPES,{event:c,callback:function(a){if(e){e.graph.beforeChange();var b=m.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)e.shape=
|
||||
a;else for(var c in b.selected_nodes)b.selected_nodes[c].shape=a;e.graph.afterChange();e.setDirtyCanvas(!0)}},parentMenu:d,node:e});return!1};m.onMenuNodeRemove=function(a,b,c,d,e){if(!e)throw"no node passed";a=e.graph;a.beforeChange();b=m.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)!1!==e.removable&&a.remove(e);else for(var f in b.selected_nodes)c=b.selected_nodes[f],!1!==c.removable&&a.remove(c);a.afterChange();e.setDirtyCanvas(!0,!0)};m.onMenuNodeToSubgraph=function(a,
|
||||
b,c,d,e){a=e.graph;if(b=m.active_canvas)c=Object.values(b.selected_nodes||{}),c.length||(c=[e]),d=g.createNode("graph/subgraph"),d.pos=e.pos.concat(),a.add(d),d.buildFromNodes(c),b.deselectAllNodes(),e.setDirtyCanvas(!0,!0)};m.onMenuNodeClone=function(a,b,c,d,e){e.graph.beforeChange();var f={};a=function(a){if(0!=a.clonable){var b=a.clone();b&&(b.pos=[a.pos[0]+5,a.pos[1]+5],a.graph.add(b),f[b.id]=b)}};b=m.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)a(e);else for(var g in b.selected_nodes)a(b.selected_nodes[g]);
|
||||
Object.keys(f).length&&b.selectNodes(f);e.graph.afterChange();e.setDirtyCanvas(!0,!0)};m.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"}};m.prototype.getCanvasMenuOptions=function(){if(this.getMenuOptions)var a=this.getMenuOptions();else a=[{content:"Add Node",has_submenu:!0,callback:m.onMenuAdd},{content:"Add Group",callback:m.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};m.prototype.getNodeMenuOptions=function(a){if(a.getMenuOptions)var b=a.getMenuOptions(this);else b=[{content:"Inputs",has_submenu:!0,disabled:!0,callback:m.showMenuNodeOptionalInputs},{content:"Outputs",has_submenu:!0,disabled:!0,callback:m.showMenuNodeOptionalOutputs},null,{content:"Properties",has_submenu:!0,callback:m.onShowMenuNodeProperties},null,{content:"Title",callback:m.onShowPropertyEditor},{content:"Mode",has_submenu:!0,callback:m.onMenuNodeMode}],!1!==a.resizable&&
|
||||
b.push({content:"Resize",callback:m.onMenuResizeNode}),b.push({content:"Collapse",callback:m.onMenuNodeCollapse},{content:"Pin",callback:m.onMenuNodePin},{content:"Colors",has_submenu:!0,callback:m.onMenuNodeColors},{content:"Shapes",has_submenu:!0,callback:m.onMenuNodeShapes},null);if(a.onGetInputs){var c=a.onGetInputs();c&&c.length&&(b[0].disabled=!1)}a.onGetOutputs&&(c=a.onGetOutputs())&&c.length&&(b[1].disabled=!1);a.getExtraMenuOptions&&(c=a.getExtraMenuOptions(this,b))&&(c.push(null),b=c.concat(b));
|
||||
!1!==a.clonable&&b.push({content:"Clone",callback:m.onMenuNodeClone});b.push(null,{content:"Remove",disabled:!(!1!==a.removable&&!a.block_delete),callback:m.onMenuNodeRemove});if(a.graph&&a.graph.onGetNodeMenuOptions)a.graph.onGetNodeMenuOptions(b,a);return b};m.prototype.getGroupMenuOptions=function(a){return[{content:"Title",callback:m.onShowPropertyEditor},{content:"Color",has_submenu:!0,callback:m.onMenuNodeColors},{content:"Font size",property:"font_size",type:"Number",callback:m.onShowPropertyEditor},
|
||||
null,{content:"Remove",callback:m.onMenuNodeRemove}]};m.prototype.processContextMenu=function(a,b){var c=this,d=m.active_canvas.getCanvasWindow(),e=null,f={event:b,callback:function(b,d,e){if(b)if("Remove Slot"==b.content)b=b.slot,a.graph.beforeChange(),b.input?a.removeInput(b.slot):b.output&&a.removeOutput(b.slot),a.graph.afterChange();else if("Disconnect Links"==b.content)b=b.slot,a.graph.beforeChange(),b.output?a.disconnectOutput(b.slot):b.input&&a.disconnectInput(b.slot),a.graph.afterChange();
|
||||
else if("Rename Slot"==b.content){b=b.slot;var f=b.input?a.getInputInfo(b.slot):a.getOutputInfo(b.slot),g=c.createDialog("<span class='name'>Name</span><input autofocus type='text'/><button>OK</button>",d),h=g.querySelector("input");h&&f&&(h.value=f.label||"");var k=function(){a.graph.beforeChange();h.value&&(f&&(f.label=h.value),c.setDirty(!0));g.close();a.graph.afterChange()};g.querySelector("button").addEventListener("click",k);h.addEventListener("keydown",function(a){g.is_modified=!0;if(27==a.keyCode)g.close();
|
||||
else if(13==a.keyCode)k();else if(13!=a.keyCode&&"textarea"!=a.target.localName)return;a.preventDefault();a.stopPropagation()});h.focus()}},extra:a};a&&(f.title=a.type);var h=null;a&&(h=a.getSlotInPosition(b.canvasX,b.canvasY),m.active_node=a);h?(e=[],a.getSlotMenuOptions?e=a.getSlotMenuOptions(h):(h&&h.output&&h.output.links&&h.output.links.length&&e.push({content:"Disconnect Links",slot:h}),b=h.input||h.output,b.removable&&e.push(b.locked?"Cannot remove":{content:"Remove Slot",slot:h}),b.nameLocked||
|
||||
e.push({content:"Rename Slot",slot:h})),f.title=(h.input?h.input.type:h.output.type)||"*",h.input&&h.input.type==g.ACTION&&(f.title="Action"),h.output&&h.output.type==g.EVENT&&(f.title="Event")):a?e=this.getNodeMenuOptions(a):(e=this.getCanvasMenuOptions(),(h=this.graph.getGroupOnPos(b.canvasX,b.canvasY))&&e.push(null,{content:"Edit Group",has_submenu:!0,submenu:{title:"Group",extra:h,options:this.getGroupMenuOptions(h)}}));e&&new g.ContextMenu(e,f,d)};"undefined"!=typeof window&&window.CanvasRenderingContext2D&&
|
||||
!window.CanvasRenderingContext2D.prototype.roundRect&&(window.CanvasRenderingContext2D.prototype.roundRect=function(a,b,c,d,e,f){var g,k;if(0===e)this.rect(a,b,c,d);else{void 0===f&&(f=e);if(null!=e&&e.constructor===Array)if(1==e.length)var l=g=k=f=e[0];else if(2==e.length)l=f=e[0],g=k=e[1];else if(4==e.length)l=e[0],g=e[1],k=e[2],f=e[3];else return;else l=e||0,g=e||0,k=f||0,f=f||0;this.moveTo(a+l,b);this.lineTo(a+c-g,b);this.quadraticCurveTo(a+c,b,a+c,b+g);this.lineTo(a+c,b+d-f);this.quadraticCurveTo(a+
|
||||
c,b+d,a+c-f,b+d);this.lineTo(a+f,b+d);this.quadraticCurveTo(a,b+d,a,b+d-k);this.lineTo(a,b+k);this.quadraticCurveTo(a,b,a+l,b)}});g.compareObjects=function(a,b){for(var c in a)if(a[c]!=b[c])return!1;return!0};g.distance=H;g.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")+")"};g.isInsideRectangle=C;g.growBounding=function(a,b,c){b<a[0]?a[0]=b:b>a[2]&&(a[2]=b);c<a[1]?
|
||||
a[1]=c:c>a[3]&&(a[3]=c)};g.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};g.overlapBounding=F;g.hex2num=function(a){"#"==a.charAt(0)&&(a=a.slice(1));a=a.toUpperCase();for(var b=Array(3),c=0,d,e,f=0;6>f;f+=2)d="0123456789ABCDEF".indexOf(a.charAt(f)),e="0123456789ABCDEF".indexOf(a.charAt(f+1)),b[c]=16*d+e,c++;return b};g.num2hex=function(a){for(var b="#",c,d,e=0;3>e;e++)c=a[e]/16,d=a[e]%16,b+="0123456789ABCDEF".charAt(c)+"0123456789ABCDEF".charAt(d);
|
||||
return b};D.prototype.addItem=function(a,b,c){function d(a){var b=this.value;b&&b.has_submenu&&e.call(this,a)}function e(a){var b=this.value,d=!0;f.current_submenu&&f.current_submenu.close(a);if(c.callback){var e=c.callback.call(this,b,c,a,f,c.node);!0===e&&(d=!1)}if(b&&(b.callback&&!c.ignore_item_callbacks&&!0!==b.disabled&&(e=b.callback.call(this,b,c,a,f,c.extra),!0===e&&(d=!1)),b.submenu)){if(!b.submenu.options)throw"ContextMenu submenu needs options";new f.constructor(b.submenu.options,{callback:b.submenu.callback,
|
||||
event:a,parentMenu:f,ignore_item_callbacks:b.submenu.ignore_item_callbacks,title:b.submenu.title,extra:b.submenu.extra,autoopen:c.autoopen});d=!1}d&&!f.lock&&f.close()}var f=this;c=c||{};var h=document.createElement("div");h.className="litemenu-entry submenu";var k=!1;if(null===b)h.classList.add("separator");else{h.innerHTML=b&&b.title?b.title:a;if(h.value=b)b.disabled&&(k=!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);k||h.addEventListener("click",e);c.autoopen&&g.pointerListenerAdd(h,"enter",d);return h};D.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&&!D.isCursorOverElement(a,this.parentMenu.root)&&D.trigger(this.parentMenu.root,g.pointerevents_method+
|
||||
"leave",a));this.current_submenu&&this.current_submenu.close(a,!0);this.root.closing_timer&&clearTimeout(this.root.closing_timer)};D.trigger=function(a,b,c,d){var e=document.createEvent("CustomEvent");e.initCustomEvent(b,!0,!0,c);e.srcElement=d;a.dispatchEvent?a.dispatchEvent(e):a.__events&&a.__events.dispatchEvent(e);return e};D.prototype.getTopMenu=function(){return this.options.parentMenu?this.options.parentMenu.getTopMenu():this};D.prototype.getFirstEvent=function(){return this.options.parentMenu?
|
||||
this.options.parentMenu.getFirstEvent():this.options.event};D.isCursorOverElement=function(a,b){var c=a.clientX;a=a.clientY;return(b=b.getBoundingClientRect())?a>b.top&&a<b.top+b.height&&c>b.left&&c<b.left+b.width?!0:!1:!1};g.ContextMenu=D;g.closeAllContextMenus=function(a){a=a||window;a=a.document.querySelectorAll(".litecontextmenu");if(a.length){for(var b=[],c=0;c<a.length;c++)b.push(a[c]);for(c=0;c<b.length;c++)b[c].close?b[c].close():b[c].parentNode&&b[c].parentNode.removeChild(b[c])}};g.extendClass=
|
||||
function(a,b){for(var c in b)a.hasOwnProperty(c)||(a[c]=b[c]);if(b.prototype)for(c in b.prototype)b.prototype.hasOwnProperty(c)&&!a.prototype.hasOwnProperty(c)&&(b.prototype.__lookupGetter__(c)?a.prototype.__defineGetter__(c,b.prototype.__lookupGetter__(c)):a.prototype[c]=b.prototype[c],b.prototype.__lookupSetter__(c)&&a.prototype.__defineSetter__(c,b.prototype.__lookupSetter__(c)))};E.sampleCurve=function(a,b){if(b){for(var c=0;c<b.length-1;++c){var d=b[c],e=b[c+1];if(!(e[0]<a)){b=e[0]-d[0];if(1E-5>
|
||||
Math.abs(b))return d[1];a=(a-d[0])/b;return d[1]*(1-a)+e[1]*a}}return 0}};E.prototype.draw=function(a,b,c,d,e,f){if(c=this.points){this.size=b;var g=b[0]-2*this.margin;b=b[1]-2*this.margin;e=e||"#666";a.save();a.translate(this.margin,this.margin);d&&(a.fillStyle="#111",a.fillRect(0,0,g,b),a.fillStyle="#222",a.fillRect(.5*g,0,1,b),a.strokeStyle="#333",a.strokeRect(0,0,g,b));a.strokeStyle=e;f&&(a.globalAlpha=.5);a.beginPath();for(d=0;d<c.length;++d)e=c[d],a.lineTo(e[0]*g,(1-e[1])*b);a.stroke();a.globalAlpha=
|
||||
1;if(!f)for(d=0;d<c.length;++d)e=c[d],a.fillStyle=this.selected==d?"#FFF":this.nearest==d?"#DDD":"#AAA",a.beginPath(),a.arc(e[0]*g,(1-e[1])*b,2,0,2*Math.PI),a.fill();a.restore()}};E.prototype.onMouseDown=function(a,b){var c=this.points;if(c&&!(0>a[1])){var d=this.size[0]-2*this.margin,e=this.size[1]-2*this.margin,f=a[0]-this.margin;a=a[1]-this.margin;this.selected=this.getCloserPoint([f,a],30/b.ds.scale);-1==this.selected&&(b=[f/d,1-a/e],c.push(b),c.sort(function(a,b){return a[0]-b[0]}),this.selected=
|
||||
c.indexOf(b),this.must_update=!0);if(-1!=this.selected)return!0}};E.prototype.onMouseMove=function(a,b){var c=this.points;if(c){var d=this.selected;if(!(0>d)){var e=(a[0]-this.margin)/(this.size[0]-2*this.margin),f=(a[1]-this.margin)/(this.size[1]-2*this.margin);this._nearest=this.getCloserPoint([a[0]-this.margin,a[1]-this.margin],30/b.ds.scale);if(b=c[d]){var g=0==d||d==c.length-1;!g&&(-10>a[0]||a[0]>this.size[0]+10||-10>a[1]||a[1]>this.size[1]+10)?(c.splice(d,1),this.selected=-1):(b[0]=g?0==d?0:
|
||||
1:Math.clamp(e,0,1),b[1]=1-Math.clamp(f,0,1),c.sort(function(a,b){return a[0]-b[0]}),this.selected=c.indexOf(b),this.must_update=!0)}}}};E.prototype.onMouseUp=function(a,b){this.selected=-1;return!1};E.prototype.getCloserPoint=function(a,b){var c=this.points;if(!c)return-1;b=b||30;for(var d=this.size[0]-2*this.margin,e=this.size[1]-2*this.margin,f=c.length,g=[0,0],k=1E6,l=-1,m=0;m<f;++m){var p=c[m];g[0]=p[0]*d;g[1]=(1-p[1])*e;p=vec2.distance(a,g);p>k||p>b||(l=m,k=p)}return l};g.CurveEditor=E;g.getParameterNames=
|
||||
function(a){return(a+"").replace(/[/][/].*$/gm,"").replace(/\s+/g,"").replace(/[/][*][^/*]*[*][/]/g,"").split("){",1)[0].replace(/^[^(]*[(]/,"").replace(/=[^,]+/g,"").split(",").filter(Boolean)};g.pointerListenerAdd=function(a,b,c,d){d=void 0===d?!1:d;if(a&&a.addEventListener&&b&&"function"===typeof c){var e=g.pointerevents_method;if("pointer"==e&&!window.PointerEvent)switch(console.warn("sMethod=='pointer' && !window.PointerEvent"),console.log("Converting pointer["+b+"] : down move up cancel enter TO touchstart touchmove touchend, etc .."),
|
||||
b){case "down":e="touch";b="start";break;case "move":e="touch";break;case "up":e="touch";b="end";break;case "cancel":e="touch";break;case "enter":console.log("debug: Should I send a move event?");break;default:console.warn("PointerEvent not available in this browser ? The event "+b+" would not be called")}switch(b){case "down":case "up":case "move":case "over":case "out":case "enter":a.addEventListener(e+b,c,d);case "leave":case "cancel":case "gotpointercapture":case "lostpointercapture":if("mouse"!=
|
||||
e)return a.addEventListener(e+b,c,d);default:return a.addEventListener(b,c,d)}}};g.pointerListenerRemove=function(a,b,c,d){d=void 0===d?!1:d;if(a&&a.removeEventListener&&b&&"function"===typeof c)switch(b){case "down":case "up":case "move":case "over":case "out":case "enter":"pointer"!=g.pointerevents_method&&"mouse"!=g.pointerevents_method||a.removeEventListener(g.pointerevents_method+b,c,d);case "leave":case "cancel":case "gotpointercapture":case "lostpointercapture":if("pointer"==g.pointerevents_method)return a.removeEventListener(g.pointerevents_method+
|
||||
b,c,d);default:return a.removeEventListener(b,c,d)}};Math.clamp=function(a,b,c){return b>a?b:c<a?c:a};"undefined"==typeof window||window.requestAnimationFrame||(window.requestAnimationFrame=window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(a){window.setTimeout(a,1E3/60)})})(this);"undefined"!=typeof exports&&(exports.LiteGraph=this.LiteGraph);
|
||||
-a.pos[1]-.5*a.size[1]+.5*this.canvas.height/this.ds.scale;this.setDirty(!0,!0)};m.prototype.adjustMouseEvent=function(a){if(this.canvas){var b=this.canvas.getBoundingClientRect();var c=a.clientX-b.left;b=a.clientY-b.top}else c=a.clientX,b=a.clientY;a.deltaX=c-this.last_mouse_position[0];a.deltaY=b-this.last_mouse_position[1];this.last_mouse_position[0]=c;this.last_mouse_position[1]=b;a.canvasX=c/this.ds.scale-this.ds.offset[0];a.canvasY=b/this.ds.scale-this.ds.offset[1]};m.prototype.setZoom=function(a,
|
||||
b){this.ds.changeScale(a,b);this.dirty_bgcanvas=this.dirty_canvas=!0};m.prototype.convertOffsetToCanvas=function(a,b){return this.ds.convertOffsetToCanvas(a,b)};m.prototype.convertCanvasToOffset=function(a,b){return this.ds.convertCanvasToOffset(a,b)};m.prototype.convertEventToCanvasOffset=function(a){var b=this.canvas.getBoundingClientRect();return this.convertCanvasToOffset([a.clientX-b.left,a.clientY-b.top])};m.prototype.bringToFront=function(a){var b=this.graph._nodes.indexOf(a);-1!=b&&(this.graph._nodes.splice(b,
|
||||
1),this.graph._nodes.push(a))};m.prototype.sendToBack=function(a){var b=this.graph._nodes.indexOf(a);-1!=b&&(this.graph._nodes.splice(b,1),this.graph._nodes.unshift(a))};var I=new Float32Array(4);m.prototype.computeVisibleNodes=function(a,b){b=b||[];b.length=0;a=a||this.graph._nodes;for(var c=0,d=a.length;c<d;++c){var e=a[c];(!this.live_mode||e.onDrawBackground||e.onDrawForeground)&&F(this.visible_area,e.getBounding(I))&&b.push(e)}return b};m.prototype.draw=function(a,b){if(this.canvas&&0!=this.canvas.width&&
|
||||
0!=this.canvas.height){var c=g.getTime();this.render_time=.001*(c-this.last_draw_time);this.last_draw_time=c;this.graph&&this.ds.computeVisibleArea(this.viewport);(this.dirty_bgcanvas||b||this.always_render_background||this.graph&&this.graph._last_trigger_time&&1E3>c-this.graph._last_trigger_time)&&this.drawBackCanvas();(this.dirty_canvas||a)&&this.drawFrontCanvas();this.fps=this.render_time?1/this.render_time:0;this.frame+=1}};m.prototype.drawFrontCanvas=function(){this.dirty_canvas=!1;this.ctx||
|
||||
(this.ctx=this.bgcanvas.getContext("2d"));var a=this.ctx;if(a){var b=this.canvas;a.start2D&&!this.viewport&&(a.start2D(),a.restore(),a.setTransform(1,0,0,1,0,0));var c=this.viewport||this.dirty_area;c&&(a.save(),a.beginPath(),a.rect(c[0],c[1],c[2],c[3]),a.clip());this.clear_background&&(c?a.clearRect(c[0],c[1],c[2],c[3]):a.clearRect(0,0,b.width,b.height));this.bgcanvas==this.canvas?this.drawBackCanvas():a.drawImage(this.bgcanvas,0,0);if(this.onRender)this.onRender(b,a);this.show_info&&this.renderInfo(a,
|
||||
c?c[0]:0,c?c[1]:0);if(this.graph){a.save();this.ds.toCanvasContext(a);b=this.computeVisibleNodes(null,this.visible_nodes);for(var d=0;d<b.length;++d){var e=b[d];a.save();a.translate(e.pos[0],e.pos[1]);this.drawNode(e,a);a.restore()}this.render_execution_order&&this.drawExecutionOrder(a);this.graph.config.links_ontop&&(this.live_mode||this.drawConnections(a));if(null!=this.connecting_pos){a.lineWidth=this.connections_width;e=this.connecting_output||this.connecting_input;b=e.type;d=e.dir;null==d&&(d=
|
||||
this.connecting_output?this.connecting_node.horizontal?g.DOWN:g.RIGHT:this.connecting_node.horizontal?g.UP:g.LEFT);var f=e.shape;switch(b){case g.EVENT:e=g.EVENT_LINK_COLOR;break;default:e=g.CONNECTING_LINK_COLOR}this.renderLink(a,this.connecting_pos,[this.graph_mouse[0],this.graph_mouse[1]],null,!1,null,e,d,g.CENTER);a.beginPath();b===g.EVENT||f===g.BOX_SHAPE?(a.rect(this.connecting_pos[0]-6+.5,this.connecting_pos[1]-5+.5,14,10),a.fill(),a.beginPath(),a.rect(this.graph_mouse[0]-6+.5,this.graph_mouse[1]-
|
||||
5+.5,14,10)):f===g.ARROW_SHAPE?(a.moveTo(this.connecting_pos[0]+8,this.connecting_pos[1]+.5),a.lineTo(this.connecting_pos[0]-4,this.connecting_pos[1]+6+.5),a.lineTo(this.connecting_pos[0]-4,this.connecting_pos[1]-6+.5),a.closePath()):(a.arc(this.connecting_pos[0],this.connecting_pos[1],4,0,2*Math.PI),a.fill(),a.beginPath(),a.arc(this.graph_mouse[0],this.graph_mouse[1],4,0,2*Math.PI));a.fill();a.fillStyle="#ffcc00";if(this._highlight_input){a.beginPath();var h=this._highlight_input_slot.shape;h===
|
||||
g.ARROW_SHAPE?(a.moveTo(this._highlight_input[0]+8,this._highlight_input[1]+.5),a.lineTo(this._highlight_input[0]-4,this._highlight_input[1]+6+.5),a.lineTo(this._highlight_input[0]-4,this._highlight_input[1]-6+.5),a.closePath()):a.arc(this._highlight_input[0],this._highlight_input[1],6,0,2*Math.PI);a.fill()}this._highlight_output&&(a.beginPath(),h===g.ARROW_SHAPE?(a.moveTo(this._highlight_output[0]+8,this._highlight_output[1]+.5),a.lineTo(this._highlight_output[0]-4,this._highlight_output[1]+6+.5),
|
||||
a.lineTo(this._highlight_output[0]-4,this._highlight_output[1]-6+.5),a.closePath()):a.arc(this._highlight_output[0],this._highlight_output[1],6,0,2*Math.PI),a.fill())}this.dragging_rectangle&&(a.strokeStyle="#FFF",a.strokeRect(this.dragging_rectangle[0],this.dragging_rectangle[1],this.dragging_rectangle[2],this.dragging_rectangle[3]));if(this.over_link_center&&this.render_link_tooltip)this.drawLinkTooltip(a,this.over_link_center);else if(this.onDrawLinkTooltip)this.onDrawLinkTooltip(a,null);if(this.onDrawForeground)this.onDrawForeground(a,
|
||||
this.visible_rect);a.restore()}this._graph_stack&&this._graph_stack.length&&this.drawSubgraphPanel(a);if(this.onDrawOverlay)this.onDrawOverlay(a);c&&a.restore();a.finish2D&&a.finish2D()}};m.prototype.drawSubgraphPanel=function(a){var b=this.graph,c=b._subgraph_node;c?(this.drawSubgraphPanelLeft(b,c,a),this.drawSubgraphPanelRight(b,c,a)):console.warn("subgraph without subnode")};m.prototype.drawSubgraphPanelLeft=function(a,b,c){var d=b.inputs?b.inputs.length:0,e=Math.floor(1.6*g.NODE_SLOT_HEIGHT);
|
||||
c.fillStyle="#111";c.globalAlpha=.8;c.beginPath();c.roundRect(10,10,200,(d+1)*e+50,[8]);c.fill();c.globalAlpha=1;c.fillStyle="#888";c.font="14px Arial";c.textAlign="left";c.fillText("Graph Inputs",20,34);if(this.drawButton(180,20,20,20,"X","#151515"))this.closeSubgraph();else{d=50;c.font="14px Arial";if(b.inputs)for(var f=0;f<b.inputs.length;++f){var h=b.inputs[f];if(!h.not_subgraph_input){if(this.drawButton(20,d+2,180,e-2)){var k=b.constructor.input_node_type||"graph/input";this.graph.beforeChange();
|
||||
var n=g.createNode(k);n?(a.add(n),this.block_click=!1,this.last_click_position=null,this.selectNodes([n]),this.node_dragged=n,this.dragging_canvas=!1,n.setProperty("name",h.name),n.setProperty("type",h.type),this.node_dragged.pos[0]=this.graph_mouse[0]-5,this.node_dragged.pos[1]=this.graph_mouse[1]-5,this.graph.afterChange()):console.error("graph input node not found:",k)}c.fillStyle="#9C9";c.beginPath();c.arc(184,d+.5*e,5,0,2*Math.PI);c.fill();c.fillStyle="#AAA";c.fillText(h.name,30,d+.75*e);c.fillStyle=
|
||||
"#777";c.fillText(h.type,130,d+.75*e);d+=e}}this.drawButton(20,d+2,180,e-2,"+","#151515","#222")&&this.showSubgraphPropertiesDialog(b)}};m.prototype.drawSubgraphPanelRight=function(a,b,c){var d=b.outputs?b.outputs.length:0,e=this.bgcanvas.width,f=Math.floor(1.6*g.NODE_SLOT_HEIGHT);c.fillStyle="#111";c.globalAlpha=.8;c.beginPath();c.roundRect(e-200-10,10,200,(d+1)*f+50,[8]);c.fill();c.globalAlpha=1;c.fillStyle="#888";c.font="14px Arial";c.textAlign="left";d=c.measureText("Graph Outputs").width;c.fillText("Graph Outputs",
|
||||
e-d-20,34);if(this.drawButton(e-200,20,20,20,"X","#151515"))this.closeSubgraph();else{d=50;c.font="14px Arial";if(b.outputs)for(var h=0;h<b.outputs.length;++h){var k=b.outputs[h];if(!k.not_subgraph_input){if(this.drawButton(e-200,d+2,180,f-2)){var n=b.constructor.output_node_type||"graph/output";this.graph.beforeChange();var q=g.createNode(n);q?(a.add(q),this.block_click=!1,this.last_click_position=null,this.selectNodes([q]),this.node_dragged=q,this.dragging_canvas=!1,q.setProperty("name",k.name),
|
||||
q.setProperty("type",k.type),this.node_dragged.pos[0]=this.graph_mouse[0]-5,this.node_dragged.pos[1]=this.graph_mouse[1]-5,this.graph.afterChange()):console.error("graph input node not found:",n)}c.fillStyle="#9C9";c.beginPath();c.arc(e-200+16,d+.5*f,5,0,2*Math.PI);c.fill();c.fillStyle="#AAA";c.fillText(k.name,e-200+30,d+.75*f);c.fillStyle="#777";c.fillText(k.type,e-200+130,d+.75*f);d+=f}}this.drawButton(e-200,d+2,180,f-2,"+","#151515","#222")&&this.showSubgraphPropertiesDialogRight(b)}};m.prototype.drawButton=
|
||||
function(a,b,c,d,e,f,h,k){var n=this.ctx;f=f||g.NODE_DEFAULT_COLOR;h=h||"#555";k=k||g.NODE_TEXT_COLOR;var q=b+g.NODE_TITLE_HEIGHT+2,u=this.mouse,r=g.isInsideRectangle(u[0],u[1],a,q,c,d);q=(u=this.last_click_position)&&g.isInsideRectangle(u[0],u[1],a,q,c,d);n.fillStyle=r?h:f;q&&(n.fillStyle="#AAA");n.beginPath();n.roundRect(a,b,c,d,[4]);n.fill();null!=e&&e.constructor==String&&(n.fillStyle=k,n.textAlign="center",n.font=(.65*d|0)+"px Arial",n.fillText(e,a+.5*c,b+.75*d),n.textAlign="left");a=q&&!this.block_click;
|
||||
q&&this.blockClick();return a};m.prototype.isAreaClicked=function(a,b,c,d,e){var f=this.mouse;g.isInsideRectangle(f[0],f[1],a,b,c,d);b=(a=(f=this.last_click_position)&&g.isInsideRectangle(f[0],f[1],a,b,c,d))&&!this.block_click;a&&e&&this.blockClick();return b};m.prototype.renderInfo=function(a,b,c){b=b||10;c=c||this.canvas.height-80;a.save();a.translate(b,c);a.font="10px Arial";a.fillStyle="#888";a.textAlign="left";this.graph?(a.fillText("T: "+this.graph.globaltime.toFixed(2)+"s",5,13),a.fillText("I: "+
|
||||
this.graph.iteration,5,26),a.fillText("N: "+this.graph._nodes.length+" ["+this.visible_nodes.length+"]",5,39),a.fillText("V: "+this.graph._version,5,52),a.fillText("FPS:"+this.fps.toFixed(2),5,65)):a.fillText("No graph selected",5,13);a.restore()};m.prototype.drawBackCanvas=function(){var a=this.bgcanvas;if(a.width!=this.canvas.width||a.height!=this.canvas.height)a.width=this.canvas.width,a.height=this.canvas.height;this.bgctx||(this.bgctx=this.bgcanvas.getContext("2d"));var b=this.bgctx;b.start&&
|
||||
b.start();var c=this.viewport||[0,0,b.canvas.width,b.canvas.height];this.clear_background&&b.clearRect(c[0],c[1],c[2],c[3]);if(this._graph_stack&&this._graph_stack.length){b.save();c=this.graph._subgraph_node;b.strokeStyle=c.bgcolor;b.lineWidth=10;b.strokeRect(1,1,a.width-2,a.height-2);b.lineWidth=1;b.font="40px Arial";b.textAlign="center";b.fillStyle=c.bgcolor||"#AAA";for(var d="",e=1;e<this._graph_stack.length;++e)d+=this._graph_stack[e]._subgraph_node.getTitle()+" >> ";b.fillText(d+c.getTitle(),
|
||||
.5*a.width,40);b.restore()}c=!1;this.onRenderBackground&&(c=this.onRenderBackground(a,b));this.viewport||(b.restore(),b.setTransform(1,0,0,1,0,0));this.visible_links.length=0;if(this.graph){b.save();this.ds.toCanvasContext(b);if(this.background_image&&.5<this.ds.scale&&!c){b.globalAlpha=this.zoom_modify_alpha?(1-.5/this.ds.scale)*this.editor_alpha:this.editor_alpha;b.imageSmoothingEnabled=b.imageSmoothingEnabled=!1;if(!this._bg_img||this._bg_img.name!=this.background_image){this._bg_img=new Image;
|
||||
this._bg_img.name=this.background_image;this._bg_img.src=this.background_image;var f=this;this._bg_img.onload=function(){f.draw(!0,!0)}}c=null;null==this._pattern&&0<this._bg_img.width?(c=b.createPattern(this._bg_img,"repeat"),this._pattern_img=this._bg_img,this._pattern=c):c=this._pattern;c&&(b.fillStyle=c,b.fillRect(this.visible_area[0],this.visible_area[1],this.visible_area[2],this.visible_area[3]),b.fillStyle="transparent");b.globalAlpha=1;b.imageSmoothingEnabled=b.imageSmoothingEnabled=!0}this.graph._groups.length&&
|
||||
!this.live_mode&&this.drawGroups(a,b);if(this.onDrawBackground)this.onDrawBackground(b,this.visible_area);this.onBackgroundRender&&(console.error("WARNING! onBackgroundRender deprecated, now is named onDrawBackground "),this.onBackgroundRender=null);this.render_canvas_border&&(b.strokeStyle="#235",b.strokeRect(0,0,a.width,a.height));this.render_connections_shadows?(b.shadowColor="#000",b.shadowOffsetX=0,b.shadowOffsetY=0,b.shadowBlur=6):b.shadowColor="rgba(0,0,0,0)";this.live_mode||this.drawConnections(b);
|
||||
b.shadowColor="rgba(0,0,0,0)";b.restore()}b.finish&&b.finish();this.dirty_bgcanvas=!1;this.dirty_canvas=!0};var B=new Float32Array(2);m.prototype.drawNode=function(a,b){this.current_node=a;var c=a.color||a.constructor.color||g.NODE_DEFAULT_COLOR,d=a.bgcolor||a.constructor.bgcolor||g.NODE_DEFAULT_BGCOLOR,e=.6>this.ds.scale;if(this.live_mode){if(!a.flags.collapsed&&(b.shadowColor="transparent",a.onDrawForeground))a.onDrawForeground(b,this,this.canvas)}else{var f=this.editor_alpha;b.globalAlpha=f;this.render_shadows&&
|
||||
!e?(b.shadowColor=g.DEFAULT_SHADOW_COLOR,b.shadowOffsetX=2*this.ds.scale,b.shadowOffsetY=2*this.ds.scale,b.shadowBlur=3*this.ds.scale):b.shadowColor="transparent";if(!a.flags.collapsed||!a.onDrawCollapsed||1!=a.onDrawCollapsed(b,this)){var h=a._shape||g.BOX_SHAPE;B.set(a.size);var k=a.horizontal;if(a.flags.collapsed){b.font=this.inner_text_font;var n=a.getTitle?a.getTitle():a.title;null!=n&&(a._collapsed_width=Math.min(a.size[0],b.measureText(n).width+2*g.NODE_TITLE_HEIGHT),B[0]=a._collapsed_width,
|
||||
B[1]=0)}a.clip_area&&(b.save(),b.beginPath(),h==g.BOX_SHAPE?b.rect(0,0,B[0],B[1]):h==g.ROUND_SHAPE?b.roundRect(0,0,B[0],B[1],[10]):h==g.CIRCLE_SHAPE&&b.arc(.5*B[0],.5*B[1],.5*B[0],0,2*Math.PI),b.clip());a.has_errors&&(d="red");this.drawNodeShape(a,b,B,c,d,a.is_selected,a.mouseOver);b.shadowColor="transparent";if(a.onDrawForeground)a.onDrawForeground(b,this,this.canvas);b.textAlign=k?"center":"left";b.font=this.inner_text_font;d=!e;var q=this.connecting_output;h=this.connecting_input;b.lineWidth=1;
|
||||
n=0;var u=new Float32Array(2);if(!a.flags.collapsed){if(a.inputs)for(c=0;c<a.inputs.length;c++){var r=a.inputs[c],m=r.type,l=r.shape;b.globalAlpha=f;this.connecting_output&&!g.isValidConnection(r.type,q.type)&&(b.globalAlpha=.4*f);b.fillStyle=null!=r.link?r.color_on||this.default_connection_color_byType[m]||this.default_connection_color.input_on:r.color_off||this.default_connection_color_byTypeOff[m]||this.default_connection_color_byType[m]||this.default_connection_color.input_off;var t=a.getConnectionPos(!0,
|
||||
c,u);t[0]-=a.pos[0];t[1]-=a.pos[1];n<t[1]+.5*g.NODE_SLOT_HEIGHT&&(n=t[1]+.5*g.NODE_SLOT_HEIGHT);b.beginPath();"array"==m&&(l=g.GRID_SHAPE);r.type===g.EVENT||r.shape===g.BOX_SHAPE?k?b.rect(t[0]-5+.5,t[1]-8+.5,10,14):b.rect(t[0]-6+.5,t[1]-5+.5,14,10):l===g.ARROW_SHAPE?(b.moveTo(t[0]+8,t[1]+.5),b.lineTo(t[0]-4,t[1]+6+.5),b.lineTo(t[0]-4,t[1]-6+.5),b.closePath()):l===g.GRID_SHAPE?(b.rect(t[0]-4,t[1]-4,2,2),b.rect(t[0]-1,t[1]-4,2,2),b.rect(t[0]+2,t[1]-4,2,2),b.rect(t[0]-4,t[1]-1,2,2),b.rect(t[0]-1,t[1]-
|
||||
1,2,2),b.rect(t[0]+2,t[1]-1,2,2),b.rect(t[0]-4,t[1]+2,2,2),b.rect(t[0]-1,t[1]+2,2,2),b.rect(t[0]+2,t[1]+2,2,2)):e?b.rect(t[0]-4,t[1]-4,8,8):b.arc(t[0],t[1],4,0,2*Math.PI);b.fill();d&&(m=null!=r.label?r.label:r.name)&&(b.fillStyle=g.NODE_TEXT_COLOR,k||r.dir==g.UP?b.fillText(m,t[0],t[1]-10):b.fillText(m,t[0]+10,t[1]+5))}b.textAlign=k?"center":"right";b.strokeStyle="black";if(a.outputs)for(c=0;c<a.outputs.length;c++)if(r=a.outputs[c],m=r.type,l=r.shape,this.connecting_input&&!g.isValidConnection(m,h.type)&&
|
||||
(b.globalAlpha=.4*f),t=a.getConnectionPos(!1,c,u),t[0]-=a.pos[0],t[1]-=a.pos[1],n<t[1]+.5*g.NODE_SLOT_HEIGHT&&(n=t[1]+.5*g.NODE_SLOT_HEIGHT),b.fillStyle=r.links&&r.links.length?r.color_on||this.default_connection_color_byType[m]||this.default_connection_color.output_on:r.color_off||this.default_connection_color_byTypeOff[m]||this.default_connection_color_byType[m]||this.default_connection_color.output_off,b.beginPath(),"array"==m&&(l=g.GRID_SHAPE),q=!0,m===g.EVENT||l===g.BOX_SHAPE?k?b.rect(t[0]-5+
|
||||
.5,t[1]-8+.5,10,14):b.rect(t[0]-6+.5,t[1]-5+.5,14,10):l===g.ARROW_SHAPE?(b.moveTo(t[0]+8,t[1]+.5),b.lineTo(t[0]-4,t[1]+6+.5),b.lineTo(t[0]-4,t[1]-6+.5),b.closePath()):l===g.GRID_SHAPE?(b.rect(t[0]-4,t[1]-4,2,2),b.rect(t[0]-1,t[1]-4,2,2),b.rect(t[0]+2,t[1]-4,2,2),b.rect(t[0]-4,t[1]-1,2,2),b.rect(t[0]-1,t[1]-1,2,2),b.rect(t[0]+2,t[1]-1,2,2),b.rect(t[0]-4,t[1]+2,2,2),b.rect(t[0]-1,t[1]+2,2,2),b.rect(t[0]+2,t[1]+2,2,2),q=!1):e?b.rect(t[0]-4,t[1]-4,8,8):b.arc(t[0],t[1],4,0,2*Math.PI),b.fill(),!e&&q&&b.stroke(),
|
||||
d&&(m=null!=r.label?r.label:r.name))b.fillStyle=g.NODE_TEXT_COLOR,k||r.dir==g.DOWN?b.fillText(m,t[0],t[1]-8):b.fillText(m,t[0]-10,t[1]+5);b.textAlign="left";b.globalAlpha=1;if(a.widgets){r=n;if(k||a.widgets_up)r=2;null!=a.widgets_start_y&&(r=a.widgets_start_y);this.drawNodeWidgets(a,r,b,this.node_widget&&this.node_widget[0]==a?this.node_widget[1]:null)}}else if(this.render_collapsed_slots){e=f=null;if(a.inputs)for(c=0;c<a.inputs.length;c++)if(r=a.inputs[c],null!=r.link){f=r;break}if(a.outputs)for(c=
|
||||
0;c<a.outputs.length;c++)r=a.outputs[c],r.links&&r.links.length&&(e=r);f&&(f=0,c=-.5*g.NODE_TITLE_HEIGHT,k&&(f=.5*a._collapsed_width,c=-g.NODE_TITLE_HEIGHT),b.fillStyle="#686",b.beginPath(),r.type===g.EVENT||r.shape===g.BOX_SHAPE?b.rect(f-7+.5,c-4,14,8):r.shape===g.ARROW_SHAPE?(b.moveTo(f+8,c),b.lineTo(f+-4,c-4),b.lineTo(f+-4,c+4),b.closePath()):b.arc(f,c,4,0,2*Math.PI),b.fill());e&&(f=a._collapsed_width,c=-.5*g.NODE_TITLE_HEIGHT,k&&(f=.5*a._collapsed_width,c=0),b.fillStyle="#686",b.strokeStyle="black",
|
||||
b.beginPath(),r.type===g.EVENT||r.shape===g.BOX_SHAPE?b.rect(f-7+.5,c-4,14,8):r.shape===g.ARROW_SHAPE?(b.moveTo(f+6,c),b.lineTo(f-6,c-4),b.lineTo(f-6,c+4),b.closePath()):b.arc(f,c,4,0,2*Math.PI),b.fill())}a.clip_area&&b.restore();b.globalAlpha=1}}};m.prototype.drawLinkTooltip=function(a,b){var c=b._pos;a.fillStyle="black";a.beginPath();a.arc(c[0],c[1],3,0,2*Math.PI);a.fill();if(null!=b.data&&(!this.onDrawLinkTooltip||1!=this.onDrawLinkTooltip(a,b,this))&&(b=b.data,b=b.constructor===Number?b.toFixed(2):
|
||||
b.constructor===String?'"'+b+'"':b.constructor===Boolean?String(b):b.toToolTip?b.toToolTip():"["+b.constructor.name+"]",null!=b)){b=b.substr(0,30);a.font="14px Courier New";var d=a.measureText(b).width+20;a.shadowColor="black";a.shadowOffsetX=2;a.shadowOffsetY=2;a.shadowBlur=3;a.fillStyle="#454";a.beginPath();a.roundRect(c[0]-.5*d,c[1]-15-24,d,24,[3]);a.moveTo(c[0]-10,c[1]-15);a.lineTo(c[0]+10,c[1]-15);a.lineTo(c[0],c[1]-5);a.fill();a.shadowColor="transparent";a.textAlign="center";a.fillStyle="#CEC";
|
||||
a.fillText(b,c[0],c[1]-15-24*.3)}};var y=new Float32Array(4);m.prototype.drawNodeShape=function(a,b,c,d,e,f,h){b.strokeStyle=d;b.fillStyle=e;e=g.NODE_TITLE_HEIGHT;var k=.5>this.ds.scale,n=a._shape||a.constructor.shape||g.ROUND_SHAPE,q=a.constructor.title_mode,u=!0;q==g.TRANSPARENT_TITLE||q==g.NO_TITLE?u=!1:q==g.AUTOHIDE_TITLE&&h&&(u=!0);y[0]=0;y[1]=u?-e:0;y[2]=c[0]+1;y[3]=u?c[1]+e:c[1];h=b.globalAlpha;b.beginPath();n==g.BOX_SHAPE||k?b.fillRect(y[0],y[1],y[2],y[3]):n==g.ROUND_SHAPE||n==g.CARD_SHAPE?
|
||||
b.roundRect(y[0],y[1],y[2],y[3],n==g.CARD_SHAPE?[this.round_radius,this.round_radius,0,0]:[this.round_radius]):n==g.CIRCLE_SHAPE&&b.arc(.5*c[0],.5*c[1],.5*c[0],0,2*Math.PI);b.fill();!a.flags.collapsed&&u&&(b.shadowColor="transparent",b.fillStyle="rgba(0,0,0,0.2)",b.fillRect(0,-1,y[2],2));b.shadowColor="transparent";if(a.onDrawBackground)a.onDrawBackground(b,this,this.canvas,this.graph_mouse);if(u||q==g.TRANSPARENT_TITLE){if(a.onDrawTitleBar)a.onDrawTitleBar(b,e,c,this.ds.scale,d);else if(q!=g.TRANSPARENT_TITLE&&
|
||||
(a.constructor.title_color||this.render_title_colored)){u=a.constructor.title_color||d;a.flags.collapsed&&(b.shadowColor=g.DEFAULT_SHADOW_COLOR);if(this.use_gradients){var r=m.gradients[u];r||(r=m.gradients[u]=b.createLinearGradient(0,0,400,0),r.addColorStop(0,u),r.addColorStop(1,"#000"));b.fillStyle=r}else b.fillStyle=u;b.beginPath();n==g.BOX_SHAPE||k?b.rect(0,-e,c[0]+1,e):(n==g.ROUND_SHAPE||n==g.CARD_SHAPE)&&b.roundRect(0,-e,c[0]+1,e,a.flags.collapsed?[this.round_radius]:[this.round_radius,this.round_radius,
|
||||
0,0]);b.fill();b.shadowColor="transparent"}u=!1;g.node_box_coloured_by_mode&&g.NODE_MODES_COLORS[a.mode]&&(u=g.NODE_MODES_COLORS[a.mode]);g.node_box_coloured_when_on&&(u=a.action_triggered?"#FFF":a.execute_triggered?"#AAA":u);if(a.onDrawTitleBox)a.onDrawTitleBox(b,e,c,this.ds.scale);else n==g.ROUND_SHAPE||n==g.CIRCLE_SHAPE||n==g.CARD_SHAPE?(k&&(b.fillStyle="black",b.beginPath(),b.arc(.5*e,-.5*e,6,0,2*Math.PI),b.fill()),b.fillStyle=a.boxcolor||u||g.NODE_DEFAULT_BOXCOLOR,k?b.fillRect(.5*e-5,-.5*e-5,
|
||||
10,10):(b.beginPath(),b.arc(.5*e,-.5*e,5,0,2*Math.PI),b.fill())):(k&&(b.fillStyle="black",b.fillRect(.5*(e-10)-1,-.5*(e+10)-1,12,12)),b.fillStyle=a.boxcolor||u||g.NODE_DEFAULT_BOXCOLOR,b.fillRect(.5*(e-10),-.5*(e+10),10,10));b.globalAlpha=h;if(a.onDrawTitleText)a.onDrawTitleText(b,e,c,this.ds.scale,this.title_text_font,f);!k&&(b.font=this.title_text_font,h=String(a.getTitle()))&&(b.fillStyle=f?g.NODE_SELECTED_TITLE_COLOR:a.constructor.title_text_color||this.node_title_color,a.flags.collapsed?(b.textAlign=
|
||||
"left",b.measureText(h),b.fillText(h.substr(0,20),e,g.NODE_TITLE_TEXT_Y-e),b.textAlign="left"):(b.textAlign="left",b.fillText(h,e,g.NODE_TITLE_TEXT_Y-e)));a.flags.collapsed||!a.subgraph||a.skip_subgraph_button||(h=g.NODE_TITLE_HEIGHT,u=a.size[0]-h,r=g.isInsideRectangle(this.graph_mouse[0]-a.pos[0],this.graph_mouse[1]-a.pos[1],u+2,-h+2,h-4,h-4),b.fillStyle=r?"#888":"#555",n==g.BOX_SHAPE||k?b.fillRect(u+2,-h+2,h-4,h-4):(b.beginPath(),b.roundRect(u+2,-h+2,h-4,h-4,[4]),b.fill()),b.fillStyle="#333",b.beginPath(),
|
||||
b.moveTo(u+.2*h,.6*-h),b.lineTo(u+.8*h,.6*-h),b.lineTo(u+.5*h,.3*-h),b.fill());if(a.onDrawTitle)a.onDrawTitle(b)}if(f){if(a.onBounding)a.onBounding(y);q==g.TRANSPARENT_TITLE&&(y[1]-=e,y[3]+=e);b.lineWidth=1;b.globalAlpha=.8;b.beginPath();n==g.BOX_SHAPE?b.rect(-6+y[0],-6+y[1],12+y[2],12+y[3]):n==g.ROUND_SHAPE||n==g.CARD_SHAPE&&a.flags.collapsed?b.roundRect(-6+y[0],-6+y[1],12+y[2],12+y[3],[2*this.round_radius]):n==g.CARD_SHAPE?b.roundRect(-6+y[0],-6+y[1],12+y[2],12+y[3],[2*this.round_radius,2,2*this.round_radius,
|
||||
2]):n==g.CIRCLE_SHAPE&&b.arc(.5*c[0],.5*c[1],.5*c[0]+6,0,2*Math.PI);b.strokeStyle=g.NODE_BOX_OUTLINE_COLOR;b.stroke();b.strokeStyle=d;b.globalAlpha=1}0<a.execute_triggered&&a.execute_triggered--;0<a.action_triggered&&a.action_triggered--};var G=new Float32Array(4),A=new Float32Array(4),J=new Float32Array(2),K=new Float32Array(2);m.prototype.drawConnections=function(a){var b=g.getTime(),c=this.visible_area;G[0]=c[0]-20;G[1]=c[1]-20;G[2]=c[2]+40;G[3]=c[3]+40;a.lineWidth=this.connections_width;a.fillStyle=
|
||||
"#AAA";a.strokeStyle="#AAA";a.globalAlpha=this.editor_alpha;c=this.graph._nodes;for(var d=0,e=c.length;d<e;++d){var f=c[d];if(f.inputs&&f.inputs.length)for(var h=0;h<f.inputs.length;++h){var k=f.inputs[h];if(k&&null!=k.link&&(k=this.graph.links[k.link])){var n=this.graph.getNodeById(k.origin_id);if(null!=n){var q=k.origin_slot;var u=-1==q?[n.pos[0]+10,n.pos[1]+10]:n.getConnectionPos(!1,q,J);var r=f.getConnectionPos(!0,h,K);A[0]=u[0];A[1]=u[1];A[2]=r[0]-u[0];A[3]=r[1]-u[1];0>A[2]&&(A[0]+=A[2],A[2]=
|
||||
Math.abs(A[2]));0>A[3]&&(A[1]+=A[3],A[3]=Math.abs(A[3]));if(F(A,G)){var m=n.outputs[q];q=f.inputs[h];if(m&&q&&(n=m.dir||(n.horizontal?g.DOWN:g.RIGHT),q=q.dir||(f.horizontal?g.UP:g.LEFT),this.renderLink(a,u,r,k,!1,0,null,n,q),k&&k._last_time&&1E3>b-k._last_time)){m=2-.002*(b-k._last_time);var l=a.globalAlpha;a.globalAlpha=l*m;this.renderLink(a,u,r,k,!0,m,"white",n,q);a.globalAlpha=l}}}}}}a.globalAlpha=1};m.prototype.renderLink=function(a,b,c,d,e,f,h,k,n,q){d&&this.visible_links.push(d);!h&&d&&(h=d.color||
|
||||
m.link_type_colors[d.type]);h||(h=this.default_link_color);null!=d&&this.highlighted_links[d.id]&&(h="#FFF");k=k||g.RIGHT;n=n||g.LEFT;var u=H(b,c);this.render_connections_border&&.6<this.ds.scale&&(a.lineWidth=this.connections_width+4);a.lineJoin="round";q=q||1;1<q&&(a.lineWidth=.5);a.beginPath();for(var r=0;r<q;r+=1){var l=5*(r-.5*(q-1));if(this.links_render_mode==g.SPLINE_LINK){a.moveTo(b[0],b[1]+l);var p=0,t=0,v=0,w=0;switch(k){case g.LEFT:p=-.25*u;break;case g.RIGHT:p=.25*u;break;case g.UP:t=
|
||||
-.25*u;break;case g.DOWN:t=.25*u}switch(n){case g.LEFT:v=-.25*u;break;case g.RIGHT:v=.25*u;break;case g.UP:w=-.25*u;break;case g.DOWN:w=.25*u}a.bezierCurveTo(b[0]+p,b[1]+t+l,c[0]+v,c[1]+w+l,c[0],c[1]+l)}else if(this.links_render_mode==g.LINEAR_LINK){a.moveTo(b[0],b[1]+l);w=v=t=p=0;switch(k){case g.LEFT:p=-1;break;case g.RIGHT:p=1;break;case g.UP:t=-1;break;case g.DOWN:t=1}switch(n){case g.LEFT:v=-1;break;case g.RIGHT:v=1;break;case g.UP:w=-1;break;case g.DOWN:w=1}a.lineTo(b[0]+15*p,b[1]+15*t+l);a.lineTo(c[0]+
|
||||
15*v,c[1]+15*w+l);a.lineTo(c[0],c[1]+l)}else if(this.links_render_mode==g.STRAIGHT_LINK)a.moveTo(b[0],b[1]),l=b[0],p=b[1],t=c[0],v=c[1],k==g.RIGHT?l+=10:p+=10,n==g.LEFT?t-=10:v-=10,a.lineTo(l,p),a.lineTo(.5*(l+t),p),a.lineTo(.5*(l+t),v),a.lineTo(t,v),a.lineTo(c[0],c[1]);else return}this.render_connections_border&&.6<this.ds.scale&&!e&&(a.strokeStyle="rgba(0,0,0,0.5)",a.stroke());a.lineWidth=this.connections_width;a.fillStyle=a.strokeStyle=h;a.stroke();e=this.computeConnectionPoint(b,c,.5,k,n);d&&
|
||||
d._pos&&(d._pos[0]=e[0],d._pos[1]=e[1]);.6<=this.ds.scale&&this.highquality_render&&n!=g.CENTER&&(this.render_connection_arrows&&(r=this.computeConnectionPoint(b,c,.25,k,n),u=this.computeConnectionPoint(b,c,.26,k,n),d=this.computeConnectionPoint(b,c,.75,k,n),q=this.computeConnectionPoint(b,c,.76,k,n),this.render_curved_connections?(u=-Math.atan2(u[0]-r[0],u[1]-r[1]),q=-Math.atan2(q[0]-d[0],q[1]-d[1])):q=u=c[1]>b[1]?0:Math.PI,a.save(),a.translate(r[0],r[1]),a.rotate(u),a.beginPath(),a.moveTo(-5,-3),
|
||||
a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore(),a.save(),a.translate(d[0],d[1]),a.rotate(q),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore()),a.beginPath(),a.arc(e[0],e[1],5,0,2*Math.PI),a.fill());if(f)for(a.fillStyle=h,r=0;5>r;++r)f=(.001*g.getTime()+.2*r)%1,e=this.computeConnectionPoint(b,c,f,k,n),a.beginPath(),a.arc(e[0],e[1],5,0,2*Math.PI),a.fill()};m.prototype.computeConnectionPoint=function(a,b,c,d,e){d=d||g.RIGHT;e=e||g.LEFT;var f=H(a,b),h=[a[0],a[1]],k=[b[0],
|
||||
b[1]];switch(d){case g.LEFT:h[0]+=-.25*f;break;case g.RIGHT:h[0]+=.25*f;break;case g.UP:h[1]+=-.25*f;break;case g.DOWN:h[1]+=.25*f}switch(e){case g.LEFT:k[0]+=-.25*f;break;case g.RIGHT:k[0]+=.25*f;break;case g.UP:k[1]+=-.25*f;break;case g.DOWN:k[1]+=.25*f}d=(1-c)*(1-c)*(1-c);e=3*(1-c)*(1-c)*c;f=3*(1-c)*c*c;c*=c*c;return[d*a[0]+e*h[0]+f*k[0]+c*b[0],d*a[1]+e*h[1]+f*k[1]+c*b[1]]};m.prototype.drawExecutionOrder=function(a){a.shadowColor="transparent";a.globalAlpha=.25;a.textAlign="center";a.strokeStyle=
|
||||
"white";a.globalAlpha=.75;for(var b=this.visible_nodes,c=0;c<b.length;++c){var d=b[c];a.fillStyle="black";a.fillRect(d.pos[0]-g.NODE_TITLE_HEIGHT,d.pos[1]-g.NODE_TITLE_HEIGHT,g.NODE_TITLE_HEIGHT,g.NODE_TITLE_HEIGHT);0==d.order&&a.strokeRect(d.pos[0]-g.NODE_TITLE_HEIGHT+.5,d.pos[1]-g.NODE_TITLE_HEIGHT+.5,g.NODE_TITLE_HEIGHT,g.NODE_TITLE_HEIGHT);a.fillStyle="#FFF";a.fillText(d.order,d.pos[0]+-.5*g.NODE_TITLE_HEIGHT,d.pos[1]-6)}a.globalAlpha=1};m.prototype.drawNodeWidgets=function(a,b,c,d){if(!a.widgets||
|
||||
!a.widgets.length)return 0;var e=a.size[0],f=a.widgets;b+=2;var h=g.NODE_WIDGET_HEIGHT,k=.5<this.ds.scale;c.save();c.globalAlpha=this.editor_alpha;for(var n=g.WIDGET_OUTLINE_COLOR,q=g.WIDGET_BGCOLOR,u=g.WIDGET_TEXT_COLOR,r=g.WIDGET_SECONDARY_TEXT_COLOR,m=0;m<f.length;++m){var l=f[m],t=b;l.y&&(t=l.y);l.last_y=t;c.strokeStyle=n;c.fillStyle="#222";c.textAlign="left";l.disabled&&(c.globalAlpha*=.5);var p=l.width||e;switch(l.type){case "button":l.clicked&&(c.fillStyle="#AAA",l.clicked=!1,this.dirty_canvas=
|
||||
!0);c.fillRect(15,t,p-30,h);k&&!l.disabled&&c.strokeRect(15,t,p-30,h);k&&(c.textAlign="center",c.fillStyle=u,c.fillText(l.name,.5*p,t+.7*h));break;case "toggle":c.textAlign="left";c.strokeStyle=n;c.fillStyle=q;c.beginPath();k?c.roundRect(15,t,p-30,h,[.5*h]):c.rect(15,t,p-30,h);c.fill();k&&!l.disabled&&c.stroke();c.fillStyle=l.value?"#89A":"#333";c.beginPath();c.arc(p-30,t+.5*h,.36*h,0,2*Math.PI);c.fill();k&&(c.fillStyle=r,null!=l.name&&c.fillText(l.name,30,t+.7*h),c.fillStyle=l.value?u:r,c.textAlign=
|
||||
"right",c.fillText(l.value?l.options.on||"true":l.options.off||"false",p-40,t+.7*h));break;case "slider":c.fillStyle=q;c.fillRect(15,t,p-30,h);var v=l.options.max-l.options.min,w=(l.value-l.options.min)/v;c.fillStyle=d==l?"#89A":"#678";c.fillRect(15,t,w*(p-30),h);k&&!l.disabled&&c.strokeRect(15,t,p-30,h);l.marker&&(v=(l.marker-l.options.min)/v,c.fillStyle="#AA9",c.fillRect(15+v*(p-30),t,2,h));k&&(c.textAlign="center",c.fillStyle=u,c.fillText(l.name+" "+Number(l.value).toFixed(3),.5*p,t+.7*h));break;
|
||||
case "number":case "combo":c.textAlign="left";c.strokeStyle=n;c.fillStyle=q;c.beginPath();k?c.roundRect(15,t,p-30,h,[.5*h]):c.rect(15,t,p-30,h);c.fill();k&&(l.disabled||c.stroke(),c.fillStyle=u,l.disabled||(c.beginPath(),c.moveTo(31,t+5),c.lineTo(21,t+.5*h),c.lineTo(31,t+h-5),c.fill(),c.beginPath(),c.moveTo(p-15-16,t+5),c.lineTo(p-15-6,t+.5*h),c.lineTo(p-15-16,t+h-5),c.fill()),c.fillStyle=r,c.fillText(l.name,35,t+.7*h),c.fillStyle=u,c.textAlign="right","number"==l.type?c.fillText(Number(l.value).toFixed(void 0!==
|
||||
l.options.precision?l.options.precision:3),p-30-20,t+.7*h):(v=l.value,l.options.values&&(w=l.options.values,w.constructor===Function&&(w=w()),w&&w.constructor!==Array&&(v=w[l.value])),c.fillText(v,p-30-20,t+.7*h)));break;case "string":case "text":c.textAlign="left";c.strokeStyle=n;c.fillStyle=q;c.beginPath();k?c.roundRect(15,t,p-30,h,[.5*h]):c.rect(15,t,p-30,h);c.fill();k&&(l.disabled||c.stroke(),c.save(),c.beginPath(),c.rect(15,t,p-30,h),c.clip(),c.fillStyle=r,null!=l.name&&c.fillText(l.name,30,
|
||||
t+.7*h),c.fillStyle=u,c.textAlign="right",c.fillText(String(l.value).substr(0,30),p-30,t+.7*h),c.restore());break;default:l.draw&&l.draw(c,a,p,t,h)}b+=(l.computeSize?l.computeSize(p)[1]:h)+4;c.globalAlpha=this.editor_alpha}c.restore();c.textAlign="left"};m.prototype.processNodeWidgets=function(a,b,c,d){function e(e,d){e.value=d;e.options&&e.options.property&&void 0!==a.properties[e.options.property]&&a.setProperty(e.options.property,d);e.callback&&e.callback(e.value,n,a,b,c)}if(!a.widgets||!a.widgets.length)return null;
|
||||
for(var f=b[0]-a.pos[0],h=b[1]-a.pos[1],k=a.size[0],n=this,q=this.getCanvasWindow(),u=0;u<a.widgets.length;++u){var r=a.widgets[u];if(r&&!r.disabled){var m=r.computeSize?r.computeSize(k)[1]:g.NODE_WIDGET_HEIGHT,l=r.width||k;if(r==d||!(6>f||f>l-12||h<r.last_y||h>r.last_y+m||void 0===r.last_y)){d=r.value;switch(r.type){case "button":c.type===g.pointerevents_method+"down"&&(r.callback&&setTimeout(function(){r.callback(r,n,a,b,c)},20),this.dirty_canvas=r.clicked=!0);break;case "slider":q=Math.clamp((f-
|
||||
15)/(l-30),0,1);r.value=r.options.min+(r.options.max-r.options.min)*q;r.callback&&setTimeout(function(){e(r,r.value)},20);this.dirty_canvas=!0;break;case "number":case "combo":d=r.value;if(c.type==g.pointerevents_method+"move"&&"number"==r.type)r.value+=.1*c.deltaX*(r.options.step||1),null!=r.options.min&&r.value<r.options.min&&(r.value=r.options.min),null!=r.options.max&&r.value>r.options.max&&(r.value=r.options.max);else if(c.type==g.pointerevents_method+"down"){var t=r.options.values;t&&t.constructor===
|
||||
Function&&(t=r.options.values(r,a));var p=null;"number"!=r.type&&(p=t.constructor===Array?t:Object.keys(t));f=40>f?-1:f>l-40?1:0;if("number"==r.type)r.value+=.1*f*(r.options.step||1),null!=r.options.min&&r.value<r.options.min&&(r.value=r.options.min),null!=r.options.max&&r.value>r.options.max&&(r.value=r.options.max);else if(f)q=-1,this.last_mouseclick=0,q=t.constructor===Object?p.indexOf(String(r.value))+f:p.indexOf(r.value)+f,q>=p.length&&(q=p.length-1),0>q&&(q=0),r.value=t.constructor===Array?
|
||||
t[q]:q;else{var v=t!=p?Object.values(t):t;new g.ContextMenu(v,{scale:Math.max(1,this.ds.scale),event:c,className:"dark",callback:function(a,b,c){t!=p&&(a=v.indexOf(a));this.value=a;e(this,a);n.dirty_canvas=!0;return!1}.bind(r)},q)}}else c.type==g.pointerevents_method+"up"&&"number"==r.type&&(f=40>f?-1:f>l-40?1:0,200>c.click_time&&0==f&&this.prompt("Value",r.value,function(a){this.value=Number(a);e(this,this.value)}.bind(r),c));d!=r.value&&setTimeout(function(){e(this,this.value)}.bind(r),20);this.dirty_canvas=
|
||||
!0;break;case "toggle":c.type==g.pointerevents_method+"down"&&(r.value=!r.value,setTimeout(function(){e(r,r.value)},20));break;case "string":case "text":c.type==g.pointerevents_method+"down"&&this.prompt("Value",r.value,function(a){this.value=a;e(this,a)}.bind(r),c,r.options?r.options.multiline:!1);break;default:r.mouse&&(this.dirty_canvas=r.mouse(c,[f,h],a))}if(d!=r.value){if(a.onWidgetChanged)a.onWidgetChanged(r.name,r.value,d,r);a.graph._version++}return r}}}return null};m.prototype.drawGroups=
|
||||
function(a,b){if(this.graph){a=this.graph._groups;b.save();b.globalAlpha=.5*this.editor_alpha;for(var c=0;c<a.length;++c){var d=a[c];if(F(this.visible_area,d._bounding)){b.fillStyle=d.color||"#335";b.strokeStyle=d.color||"#335";var e=d._pos,f=d._size;b.globalAlpha=.25*this.editor_alpha;b.beginPath();b.rect(e[0]+.5,e[1]+.5,f[0],f[1]);b.fill();b.globalAlpha=this.editor_alpha;b.stroke();b.beginPath();b.moveTo(e[0]+f[0],e[1]+f[1]);b.lineTo(e[0]+f[0]-10,e[1]+f[1]);b.lineTo(e[0]+f[0],e[1]+f[1]-10);b.fill();
|
||||
f=d.font_size||g.DEFAULT_GROUP_FONT_SIZE;b.font=f+"px Arial";b.textAlign="left";b.fillText(d.title,e[0]+4,e[1]+f)}}b.restore()}};m.prototype.adjustNodesSize=function(){for(var a=this.graph._nodes,b=0;b<a.length;++b)a[b].size=a[b].computeSize();this.setDirty(!0,!0)};m.prototype.resize=function(a,b){a||b||(b=this.canvas.parentNode,a=b.offsetWidth,b=b.offsetHeight);if(this.canvas.width!=a||this.canvas.height!=b)this.canvas.width=a,this.canvas.height=b,this.bgcanvas.width=this.canvas.width,this.bgcanvas.height=
|
||||
this.canvas.height,this.setDirty(!0,!0)};m.prototype.switchLiveMode=function(a){if(a){var b=this,c=this.live_mode?1.1:.9;this.live_mode&&(this.live_mode=!1,this.editor_alpha=.1);var d=setInterval(function(){b.editor_alpha*=c;b.dirty_canvas=!0;b.dirty_bgcanvas=!0;1>c&&.01>b.editor_alpha&&(clearInterval(d),1>c&&(b.live_mode=!0));1<c&&.99<b.editor_alpha&&(clearInterval(d),b.editor_alpha=1)},1)}else this.live_mode=!this.live_mode,this.dirty_bgcanvas=this.dirty_canvas=!0};m.prototype.onNodeSelectionChange=
|
||||
function(a){};m.onGroupAdd=function(a,b,c){a=m.active_canvas;a.getCanvasWindow();b=new g.LGraphGroup;b.pos=a.convertEventToCanvasOffset(c);a.graph.add(b)};m.onMenuAdd=function(a,b,c,d,e){function f(a,b){var d=[];g.getNodeTypesCategories(h.filter||n.filter).filter(function(b){return b.startsWith(a)}).map(function(b){if(b){b=b.replace(new RegExp("^("+a+")"),"").split("/")[0];var c=""===a?b+"/":a+b+"/";-1!=b.indexOf("::")&&(b=b.split("::")[1]);-1===d.findIndex(function(a){return a.value===c})&&d.push({value:c,
|
||||
content:b,has_submenu:!0,callback:function(a,b,c,e){f(a.value,e)}})}});g.getNodeTypesInCategory(a.slice(0,-1),h.filter||n.filter).map(function(a){a.skip_list||d.push({value:a.type,content:a.title,has_submenu:!1,callback:function(a,b,c,d){b=d.getFirstEvent();h.graph.beforeChange();if(a=g.createNode(a.value))a.pos=h.convertEventToCanvasOffset(b),h.graph.add(a);e&&e(a);h.graph.afterChange()}})});new g.ContextMenu(d,{event:c,parentMenu:b},k)}var h=m.active_canvas,k=h.getCanvasWindow(),n=h.graph;if(n)return f("",
|
||||
d),!1};m.onMenuCollapseAll=function(){};m.onMenuNodeEdit=function(){};m.showMenuNodeOptionalInputs=function(a,b,c,d,e){if(e){var f=this;a=m.active_canvas.getCanvasWindow();b=e.optional_inputs;e.onGetInputs&&(b=e.onGetInputs());var h=[];if(b)for(var k=0;k<b.length;k++){var n=b[k];if(n){var q=n[0];n[2]||(n[2]={});n[2].label&&(q=n[2].label);n[2].removable=!0;q={content:q,value:n};n[1]==g.ACTION&&(q.className="event");h.push(q)}else h.push(null)}e.onMenuNodeInputs&&(b=e.onMenuNodeInputs(h))&&(h=b);if(h.length)return new g.ContextMenu(h,
|
||||
{event:c,callback:function(a,b,c){if(e&&(a.callback&&a.callback.call(f,e,a,b,c),a.value)){e.graph.beforeChange();e.addInput(a.value[0],a.value[1],a.value[2]);if(e.onNodeInputAdd)e.onNodeInputAdd(a.value);e.setDirtyCanvas(!0,!0);e.graph.afterChange()}},parentMenu:d,node:e},a),!1;console.log("no input entries")}};m.showMenuNodeOptionalOutputs=function(a,b,c,d,e){function f(a,b,c){if(e&&(a.callback&&a.callback.call(h,e,a,b,c),a.value))if(c=a.value[1],!c||c.constructor!==Object&&c.constructor!==Array){e.graph.beforeChange();
|
||||
e.addOutput(a.value[0],a.value[1],a.value[2]);if(e.onNodeOutputAdd)e.onNodeOutputAdd(a.value);e.setDirtyCanvas(!0,!0);e.graph.afterChange()}else{a=[];for(var k in c)a.push({content:k,value:c[k]});new g.ContextMenu(a,{event:b,callback:f,parentMenu:d,node:e});return!1}}if(e){var h=this;a=m.active_canvas.getCanvasWindow();b=e.optional_outputs;e.onGetOutputs&&(b=e.onGetOutputs());var k=[];if(b)for(var n=0;n<b.length;n++){var q=b[n];if(!q)k.push(null);else if(!e.flags||!e.flags.skip_repeated_outputs||
|
||||
-1==e.findOutputSlot(q[0])){var u=q[0];q[2]||(q[2]={});q[2].label&&(u=q[2].label);q[2].removable=!0;u={content:u,value:q};q[1]==g.EVENT&&(u.className="event");k.push(u)}}this.onMenuNodeOutputs&&(k=this.onMenuNodeOutputs(k));g.do_add_triggers_slots&&-1==e.findOutputSlot("onExecuted")&&k.push({content:"On Executed",value:["onExecuted",g.EVENT,{nameLocked:!0}],className:"event"});e.onMenuNodeOutputs&&(b=e.onMenuNodeOutputs(k))&&(k=b);if(k.length)return new g.ContextMenu(k,{event:c,callback:f,parentMenu:d,
|
||||
node:e},a),!1}};m.onShowMenuNodeProperties=function(a,b,c,d,e){if(e&&e.properties){var f=m.active_canvas;b=f.getCanvasWindow();var h=[],k;for(k in e.properties){a=void 0!==e.properties[k]?e.properties[k]:" ";"object"==typeof a&&(a=JSON.stringify(a));var n=e.getPropertyInfo(k);if("enum"==n.type||"combo"==n.type)a=m.getPropertyPrintableValue(a,n.values);a=m.decodeHTML(a);h.push({content:"<span class='property_name'>"+(n.label?n.label:k)+"</span><span class='property_value'>"+a+"</span>",value:k})}if(h.length)return new g.ContextMenu(h,
|
||||
{event:c,callback:function(a,b,c,d){e&&(b=this.getBoundingClientRect(),f.showEditPropertyValue(e,a.value,{position:[b.left,b.top]}))},parentMenu:d,allow_html:!0,node:e},b),!1}};m.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};m.onMenuResizeNode=function(a,b,c,d,e){if(e){a=function(a){a.size=a.computeSize();if(a.onResize)a.onResize(a.size)};b=m.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)a(e);else for(var f in b.selected_nodes)a(b.selected_nodes[f]);
|
||||
e.setDirtyCanvas(!0,!0)}};m.prototype.showLinkMenu=function(a,b){var c=this,d=c.graph.getNodeById(a.origin_id),e=c.graph.getNodeById(a.target_id),f=!1;d&&d.outputs&&d.outputs[a.origin_slot]&&(f=d.outputs[a.origin_slot].type);var h=!1;e&&e.outputs&&e.outputs[a.target_slot]&&(h=e.inputs[a.target_slot].type);var k=new g.ContextMenu(["Add Node",null,"Delete",null],{event:b,title:null!=a.data?a.data.constructor.name:null,callback:function(b,g,u){switch(b){case "Add Node":m.onMenuAdd(null,null,u,k,function(b){b.inputs&&
|
||||
b.inputs.length&&b.outputs&&b.outputs.length&&d.connectByType(a.origin_slot,b,f)&&(b.connectByType(a.target_slot,e,h),b.pos[0]-=.5*b.size[0])});break;case "Delete":c.graph.removeLink(a.id)}}});return!1};m.prototype.createDefaultNodeForSlot=function(a){a=a||{};a=Object.assign({nodeFrom:null,slotFrom:null,nodeTo:null,slotTo:null,position:[],nodeType:null,posAdd:[0,0],posSizeFix:[0,0]},a);var b=a.nodeFrom&&null!==a.slotFrom,c=!b&&a.nodeTo&&null!==a.slotTo;if(!b&&!c)return console.warn("No data passed to createDefaultNodeForSlot "+
|
||||
a.nodeFrom+" "+a.slotFrom+" "+a.nodeTo+" "+a.slotTo),!1;if(!a.nodeType)return console.warn("No type to createDefaultNodeForSlot"),!1;var d=b?a.nodeFrom:a.nodeTo,e=b?a.slotFrom:a.slotTo;switch(typeof e){case "string":c=b?d.findOutputSlot(e,!1):d.findInputSlot(e,!1);e=b?d.outputs[e]:d.inputs[e];break;case "object":c=b?d.findOutputSlot(e.name):d.findInputSlot(e.name);break;case "number":c=e;e=b?d.outputs[e]:d.inputs[e];break;default:return console.warn("Cant get slot information "+e),!1}!1!==e&&!1!==
|
||||
c||console.warn("createDefaultNodeForSlot bad slotX "+e+" "+c);d=e.type==g.EVENT?"_event_":e.type;if((e=b?g.slot_types_default_out:g.slot_types_default_in)&&e[d]){nodeNewType=!1;if("object"==typeof e[d]||"array"==typeof e[d])for(var f in e[d]){if(a.nodeType==e[d][f]||"AUTO"==a.nodeType){nodeNewType=e[d][f];break}}else if(a.nodeType==e[d]||"AUTO"==a.nodeType)nodeNewType=e[d];if(nodeNewType){f=!1;"object"==typeof nodeNewType&&nodeNewType.node&&(f=nodeNewType,nodeNewType=nodeNewType.node);if(e=g.createNode(nodeNewType)){if(f){if(f.properties)for(var h in f.properties)e.addProperty(h,
|
||||
f.properties[h]);if(f.inputs)for(h in e.inputs=[],f.inputs)e.addOutput(f.inputs[h][0],f.inputs[h][1]);if(f.outputs)for(h in e.outputs=[],f.outputs)e.addOutput(f.outputs[h][0],f.outputs[h][1]);f.title&&(e.title=f.title);f.json&&e.configure(f.json)}this.graph.add(e);e.pos=[a.position[0]+a.posAdd[0]+(a.posSizeFix[0]?a.posSizeFix[0]*e.size[0]:0),a.position[1]+a.posAdd[1]+(a.posSizeFix[1]?a.posSizeFix[1]*e.size[1]:0)];b?a.nodeFrom.connectByType(c,e,d):a.nodeTo.connectByTypeOutput(c,e,d);return!0}console.log("failed creating "+
|
||||
nodeNewType)}}return!1};m.prototype.showConnectionMenu=function(a){a=a||{};var b=Object.assign({nodeFrom:null,slotFrom:null,nodeTo:null,slotTo:null,e:null},a),c=this,d=b.nodeFrom&&b.slotFrom;a=!d&&b.nodeTo&&b.slotTo;if(!d&&!a)return console.warn("No data passed to showConnectionMenu"),!1;a=d?b.nodeFrom:b.nodeTo;var e=d?b.slotFrom:b.slotTo,f=!1;switch(typeof e){case "string":f=d?a.findOutputSlot(e,!1):a.findInputSlot(e,!1);e=d?a.outputs[e]:a.inputs[e];break;case "object":f=d?a.findOutputSlot(e.name):
|
||||
a.findInputSlot(e.name);break;case "number":f=e;e=d?a.outputs[e]:a.inputs[e];break;default:return console.warn("Cant get slot information "+e),!1}a=["Add Node",null];c.allow_searchbox&&(a.push("Search"),a.push(null));var h=e.type==g.EVENT?"_event_":e.type,k=d?g.slot_types_default_out:g.slot_types_default_in;if(k&&k[h])if("object"==typeof k[h]||"array"==typeof k[h])for(var n in k[h])a.push(k[h][n]);else a.push(k[h]);var q=new g.ContextMenu(a,{event:b.e,title:(e&&""!=e.name?e.name+(h?" | ":""):"")+
|
||||
(e&&h?h:""),callback:function(a,g,k){switch(a){case "Add Node":m.onMenuAdd(null,null,k,q,function(a){d?b.nodeFrom.connectByType(f,a,h):b.nodeTo.connectByTypeOutput(f,a,h)});break;case "Search":d?c.showSearchBox(k,{node_from:b.nodeFrom,slot_from:e,type_filter_in:h}):c.showSearchBox(k,{node_to:b.nodeTo,slot_from:e,type_filter_out:h});break;default:c.createDefaultNodeForSlot(Object.assign(b,{position:[b.e.canvasX,b.e.canvasY],nodeType:a}))}}});return!1};m.onShowPropertyEditor=function(a,b,c,d,e){function f(){if(n){var b=
|
||||
n.value;"Number"==a.type?b=Number(b):"Boolean"==a.type&&(b=!!b);e[h]=b;k.parentNode&&k.parentNode.removeChild(k);e.setDirtyCanvas(!0,!0)}}var h=a.property||"title";b=e[h];var k=document.createElement("div");k.is_modified=!1;k.className="graphdialog";k.innerHTML="<span class='name'></span><input autofocus type='text' class='value'/><button>OK</button>";k.close=function(){k.parentNode&&k.parentNode.removeChild(k)};k.querySelector(".name").innerText=h;var n=k.querySelector(".value");n&&(n.value=b,n.addEventListener("blur",
|
||||
function(a){this.focus()}),n.addEventListener("keydown",function(a){k.is_modified=!0;if(27==a.keyCode)k.close();else if(13==a.keyCode)f();else if(13!=a.keyCode&&"textarea"!=a.target.localName)return;a.preventDefault();a.stopPropagation()}));b=m.active_canvas.canvas;c=b.getBoundingClientRect();var q=d=-20;c&&(d-=c.left,q-=c.top);event?(k.style.left=event.clientX+d+"px",k.style.top=event.clientY+q+"px"):(k.style.left=.5*b.width+d+"px",k.style.top=.5*b.height+q+"px");k.querySelector("button").addEventListener("click",
|
||||
f);b.parentNode.appendChild(k);n&&n.focus();var l=null;k.addEventListener("mouseleave",function(a){g.dialog_close_on_mouse_leave&&!k.is_modified&&g.dialog_close_on_mouse_leave&&(l=setTimeout(k.close,g.dialog_close_on_mouse_leave_delay))});k.addEventListener("mouseenter",function(a){g.dialog_close_on_mouse_leave&&l&&clearTimeout(l)})};m.prototype.prompt=function(a,b,c,d,e){var f=this;a=a||"";var h=document.createElement("div");h.is_modified=!1;h.className="graphdialog rounded";h.innerHTML=e?"<span class='name'></span> <textarea autofocus class='value'></textarea><button class='rounded'>OK</button>":
|
||||
"<span class='name'></span> <input autofocus type='text' class='value'/><button class='rounded'>OK</button>";h.close=function(){f.prompt_box=null;h.parentNode&&h.parentNode.removeChild(h)};e=m.active_canvas.canvas;e.parentNode.appendChild(h);1<this.ds.scale&&(h.style.transform="scale("+this.ds.scale+")");var k=null,n=!1;g.pointerListenerAdd(h,"leave",function(a){n||g.dialog_close_on_mouse_leave&&!h.is_modified&&g.dialog_close_on_mouse_leave&&(k=setTimeout(h.close,g.dialog_close_on_mouse_leave_delay))});
|
||||
g.pointerListenerAdd(h,"enter",function(a){g.dialog_close_on_mouse_leave&&k&&clearTimeout(k)});var q=h.querySelectorAll("select");q&&q.forEach(function(a){a.addEventListener("click",function(a){n++});a.addEventListener("blur",function(a){n=0});a.addEventListener("change",function(a){n=-1})});f.prompt_box&&f.prompt_box.close();f.prompt_box=h;h.querySelector(".name").innerText=a;var l=h.querySelector(".value");l.value=b;l.addEventListener("keydown",function(a){h.is_modified=!0;if(27==a.keyCode)h.close();
|
||||
else if(13==a.keyCode&&"textarea"!=a.target.localName)c&&c(this.value),h.close();else return;a.preventDefault();a.stopPropagation()});h.querySelector("button").addEventListener("click",function(a){c&&c(l.value);f.setDirty(!0);h.close()});a=e.getBoundingClientRect();q=b=-20;a&&(b-=a.left,q-=a.top);d?(h.style.left=d.clientX+b+"px",h.style.top=d.clientY+q+"px"):(h.style.left=.5*e.width+b+"px",h.style.top=.5*e.height+q+"px");setTimeout(function(){l.focus()},10);return h};m.search_limit=-1;m.prototype.showSearchBox=
|
||||
function(a,b){function c(c){if(c)if(f.onSearchBoxSelection)f.onSearchBoxSelection(c,a,h);else{var e=g.searchbox_extras[c.toLowerCase()];e&&(c=e.type);h.graph.beforeChange();if(c=g.createNode(c))c.pos=h.convertEventToCanvasOffset(a),h.graph.add(c,!1);if(e&&e.data){if(e.data.properties)for(var d in e.data.properties)c.addProperty(d,e.data.properties[d]);if(e.data.inputs)for(d in c.inputs=[],e.data.inputs)c.addOutput(e.data.inputs[d][0],e.data.inputs[d][1]);if(e.data.outputs)for(d in c.outputs=[],e.data.outputs)c.addOutput(e.data.outputs[d][0],
|
||||
e.data.outputs[d][1]);e.data.title&&(c.title=e.data.title);e.data.json&&c.configure(e.data.json)}if(b.node_from){switch(typeof b.slot_from){case "string":e=b.node_from.findOutputSlot(b.slot_from);break;case "object":e=b.slot_from.name?b.node_from.findOutputSlot(b.slot_from.name):-1;-1==e&&"undefined"!==typeof b.slot_from.slot_index&&(e=b.slot_from.slot_index);break;case "number":e=b.slot_from;break;default:e=0}!1!==e&&-1<e&&b.node_from.connectByType(e,c,b.node_from.outputs[e].type)}if(b.node_to){switch(typeof b.slot_from){case "string":e=
|
||||
b.node_to.findInputSlot(b.slot_from);break;case "object":e=b.slot_from.name?b.node_to.findInputSlot(b.slot_from.name):-1;-1==e&&"undefined"!==typeof b.slot_from.slot_index&&(e=b.slot_from.slot_index);break;case "number":e=b.slot_from;break;default:e=0}!1!==e&&-1<e&&b.node_to.connectByTypeOutput(e,c,b.node_to.inputs[e].type)}h.graph.afterChange()}q.close()}function d(a){var b=x;x&&x.classList.remove("selected");x?(x=a?x.nextSibling:x.previousSibling)||(x=b):x=a?t.childNodes[0]:t.childNodes[t.childNodes.length];
|
||||
x&&(x.classList.add("selected"),x.scrollIntoView({block:"end",behavior:"smooth"}))}function e(){function a(a,b){var e=document.createElement("div");w||(w=a);e.innerText=a;e.dataset.type=escape(a);e.className="litegraph lite-search-item";b&&(e.className+=" "+b);e.addEventListener("click",function(a){c(unescape(this.dataset.type))});t.appendChild(e)}y=null;var e=z.value;w=null;t.innerHTML="";if(e||b.show_all_if_empty)if(f.onSearchBox){var d=f.onSearchBox(t,e,h);if(d)for(var k=0;k<d.length;++k)a(d[k])}else{d=
|
||||
function(a,c){c=c||{};c=Object.assign({skipFilter:!1,inTypeOverride:!1,outTypeOverride:!1},c);var d=g.registered_node_types[a];if(q&&d.filter!=q||(!b.show_all_if_empty||e)&&-1===a.toLowerCase().indexOf(e))return!1;if(b.do_type_filter&&!c.skipFilter){d=l.value;!1!==c.inTypeOverride&&(d=c.inTypeOverride);if(l&&d&&g.registered_slot_in_types[d]&&g.registered_slot_in_types[d].nodes&&(d=g.registered_slot_in_types[d].nodes.includes(a),!1===d))return!1;d=r.value;!1!==c.outTypeOverride&&(d=c.outTypeOverride);
|
||||
if(r&&d&&g.registered_slot_out_types[d]&&g.registered_slot_out_types[d].nodes&&(d=g.registered_slot_out_types[d].nodes.includes(a),!1===d))return!1}return!0};var n=0;e=e.toLowerCase();var q=h.filter||h.graph.filter;if(b.do_type_filter&&f.search_box)var l=f.search_box.querySelector(".slot_in_type_filter"),r=f.search_box.querySelector(".slot_out_type_filter");else r=l=!1;for(k in g.searchbox_extras){var u=g.searchbox_extras[k];if(b.show_all_if_empty&&!e||-1!==u.desc.toLowerCase().indexOf(e)){var p=
|
||||
g.registered_node_types[u.type];if((!p||p.filter==q)&&d(u.type)&&(a(u.desc,"searchbox_extra"),-1!==m.search_limit&&n++>m.search_limit))break}}u=null;if(Array.prototype.filter)u=Object.keys(g.registered_node_types).filter(d);else for(k in u=[],g.registered_node_types)d(k)&&u.push(k);for(k=0;k<u.length&&!(a(u[k]),-1!==m.search_limit&&n++>m.search_limit);k++);if(b.show_general_after_typefiltered&&(l.value||r.value)){filtered_extra=[];for(k in g.registered_node_types)d(k,{inTypeOverride:l&&l.value?"*":
|
||||
!1,outTypeOverride:r&&r.value?"*":!1})&&filtered_extra.push(k);for(k=0;k<filtered_extra.length&&!(a(filtered_extra[k],"generic_type"),-1!==m.search_limit&&n++>m.search_limit);k++);}if((l.value||r.value)&&0==t.childNodes.length&&b.show_general_if_none_on_typefilter){filtered_extra=[];for(k in g.registered_node_types)d(k,{skipFilter:!0})&&filtered_extra.push(k);for(k=0;k<filtered_extra.length&&!(a(filtered_extra[k],"not_in_filter"),-1!==m.search_limit&&n++>m.search_limit);k++);}}}def_options={slot_from:null,
|
||||
node_from:null,node_to:null,do_type_filter:g.search_filter_enabled,type_filter_in:!1,type_filter_out:!1,show_general_if_none_on_typefilter:!0,show_general_after_typefiltered:!0,hide_on_mouse_leave:g.search_hide_on_mouse_leave,show_all_if_empty:!0,show_all_on_open:g.search_show_all_on_open};b=Object.assign(def_options,b||{});var f=this,h=m.active_canvas,k=h.canvas,n=k.ownerDocument||document,q=document.createElement("div");q.className="litegraph litesearchbox graphdialog rounded";q.innerHTML="<span class='name'>Search</span> <input autofocus type='text' class='value rounded'/>";
|
||||
b.do_type_filter&&(q.innerHTML+="<select class='slot_in_type_filter'><option value=''></option></select>",q.innerHTML+="<select class='slot_out_type_filter'><option value=''></option></select>");q.innerHTML+="<div class='helper'></div>";n.fullscreenElement?n.fullscreenElement.appendChild(q):(n.body.appendChild(q),n.body.style.overflow="hidden");if(b.do_type_filter)var l=q.querySelector(".slot_in_type_filter"),r=q.querySelector(".slot_out_type_filter");q.close=function(){f.search_box=null;n.body.focus();
|
||||
n.body.style.overflow="";setTimeout(function(){f.canvas.focus()},20);q.parentNode&&q.parentNode.removeChild(q)};1<this.ds.scale&&(q.style.transform="scale("+this.ds.scale+")");if(b.hide_on_mouse_leave){var p=!1,v=null;g.pointerListenerAdd(q,"enter",function(a){v&&(clearTimeout(v),v=null)});g.pointerListenerAdd(q,"leave",function(a){p||(v=setTimeout(function(){q.close()},500))});b.do_type_filter&&(l.addEventListener("click",function(a){p++}),l.addEventListener("blur",function(a){p=0}),l.addEventListener("change",
|
||||
function(a){p=-1}),r.addEventListener("click",function(a){p++}),r.addEventListener("blur",function(a){p=0}),r.addEventListener("change",function(a){p=-1}))}f.search_box&&f.search_box.close();f.search_box=q;var t=q.querySelector(".helper"),w=null,y=null,x=null,z=q.querySelector("input");z&&(z.addEventListener("blur",function(a){this.focus()}),z.addEventListener("keydown",function(a){if(38==a.keyCode)d(!1);else if(40==a.keyCode)d(!0);else if(27==a.keyCode)q.close();else if(13==a.keyCode)x?c(x.innerHTML):
|
||||
w?c(w):q.close();else{y&&clearInterval(y);y=setTimeout(e,250);return}a.preventDefault();a.stopPropagation();a.stopImmediatePropagation();return!0}));if(b.do_type_filter){if(l){var A=g.slot_types_in,C=A.length;if(b.type_filter_in==g.EVENT||b.type_filter_in==g.ACTION)b.type_filter_in="_event_";for(var B=0;B<C;B++){var D=document.createElement("option");D.value=A[B];D.innerHTML=A[B];l.appendChild(D);!1!==b.type_filter_in&&(b.type_filter_in+"").toLowerCase()==(A[B]+"").toLowerCase()&&(D.selected=!0)}l.addEventListener("change",
|
||||
function(){e()})}if(r){A=g.slot_types_out;C=A.length;if(b.type_filter_out==g.EVENT||b.type_filter_out==g.ACTION)b.type_filter_out="_event_";for(B=0;B<C;B++)D=document.createElement("option"),D.value=A[B],D.innerHTML=A[B],r.appendChild(D),!1!==b.type_filter_out&&(b.type_filter_out+"").toLowerCase()==(A[B]+"").toLowerCase()&&(D.selected=!0);r.addEventListener("change",function(){e()})}}k=k.getBoundingClientRect();l=(a?a.clientY:k.top+.5*k.height)-20;q.style.left=(a?a.clientX:k.left+.5*k.width)-80+"px";
|
||||
q.style.top=l+"px";a.layerY>k.height-200&&(t.style.maxHeight=k.height-a.layerY-20+"px");z.focus();b.show_all_on_open&&e();return q};m.prototype.showEditPropertyValue=function(a,b,c){function d(){e(m.value)}function e(e){f&&f.values&&f.values.constructor===Object&&void 0!=f.values[e]&&(e=f.values[e]);"number"==typeof a.properties[b]&&(e=Number(e));if("array"==h||"object"==h)e=JSON.parse(e);a.properties[b]=e;a.graph&&a.graph._version++;if(a.onPropertyChanged)a.onPropertyChanged(b,e);if(c.onclose)c.onclose();
|
||||
l.close();a.setDirtyCanvas(!0,!0)}if(a&&void 0!==a.properties[b]){c=c||{};var f=a.getPropertyInfo(b),h=f.type,g="";if("string"==h||"number"==h||"array"==h||"object"==h)g="<input autofocus type='text' class='value'/>";else if("enum"!=h&&"combo"!=h||!f.values)if("boolean"==h||"toggle"==h)g="<input autofocus type='checkbox' class='value' "+(a.properties[b]?"checked":"")+"/>";else{console.warn("unknown type: "+h);return}else{g="<select autofocus type='text' class='value'>";for(var n in f.values){var q=
|
||||
n;f.values.constructor===Array&&(q=f.values[n]);g+="<option value='"+q+"' "+(q==a.properties[b]?"selected":"")+">"+f.values[n]+"</option>"}g+="</select>"}var l=this.createDialog("<span class='name'>"+(f.label?f.label:b)+"</span>"+g+"<button>OK</button>",c),m=!1;if("enum"!=h&&"combo"!=h||!f.values)if("boolean"==h||"toggle"==h)(m=l.querySelector("input"))&&m.addEventListener("click",function(a){l.modified();e(!!m.checked)});else{if(m=l.querySelector("input"))m.addEventListener("blur",function(a){this.focus()}),
|
||||
q=void 0!==a.properties[b]?a.properties[b]:"","string"!==h&&(q=JSON.stringify(q)),m.value=q,m.addEventListener("keydown",function(a){if(27==a.keyCode)l.close();else if(13==a.keyCode)d();else if(13!=a.keyCode){l.modified();return}a.preventDefault();a.stopPropagation()})}else m=l.querySelector("select"),m.addEventListener("change",function(a){l.modified();e(a.target.value)});m&&m.focus();l.querySelector("button").addEventListener("click",d);return l}};m.prototype.createDialog=function(a,b){def_options=
|
||||
{checkForInput:!1,closeOnLeave:!0,closeOnLeave_checkModified:!0};b=Object.assign(def_options,b||{});var c=document.createElement("div");c.className="graphdialog";c.innerHTML=a;c.is_modified=!1;a=this.canvas.getBoundingClientRect();var d=-20,e=-20;a&&(d-=a.left,e-=a.top);b.position?(d+=b.position[0],e+=b.position[1]):b.event?(d+=b.event.clientX,e+=b.event.clientY):(d+=.5*this.canvas.width,e+=.5*this.canvas.height);c.style.left=d+"px";c.style.top=e+"px";this.canvas.parentNode.appendChild(c);b.checkForInput&&
|
||||
(a=[],(a=c.querySelectorAll("input"))&&a.forEach(function(a){a.addEventListener("keydown",function(a){c.modified();if(27==a.keyCode)c.close();else if(13!=a.keyCode)return;a.preventDefault();a.stopPropagation()});a.focus()}));c.modified=function(){c.is_modified=!0};c.close=function(){c.parentNode&&c.parentNode.removeChild(c)};var f=null,h=!1;c.addEventListener("mouseleave",function(a){h||(b.closeOnLeave||g.dialog_close_on_mouse_leave)&&!c.is_modified&&g.dialog_close_on_mouse_leave&&(f=setTimeout(c.close,
|
||||
g.dialog_close_on_mouse_leave_delay))});c.addEventListener("mouseenter",function(a){(b.closeOnLeave||g.dialog_close_on_mouse_leave)&&f&&clearTimeout(f)});(a=c.querySelectorAll("select"))&&a.forEach(function(a){a.addEventListener("click",function(a){h++});a.addEventListener("blur",function(a){h=0});a.addEventListener("change",function(a){h=-1})});return c};m.prototype.createPanel=function(a,b){b=b||{};var c=b.window||window,d=document.createElement("div");d.className="litegraph dialog";d.innerHTML=
|
||||
"<div class='dialog-header'><span class='dialog-title'></span></div><div class='dialog-content'></div><div style='display:none;' class='dialog-alt-content'></div><div class='dialog-footer'></div>";d.header=d.querySelector(".dialog-header");b.width&&(d.style.width=b.width+(b.width.constructor===Number?"px":""));b.height&&(d.style.height=b.height+(b.height.constructor===Number?"px":""));b.closable&&(b=document.createElement("span"),b.innerHTML="✕",b.classList.add("close"),b.addEventListener("click",
|
||||
function(){d.close()}),d.header.appendChild(b));d.title_element=d.querySelector(".dialog-title");d.title_element.innerText=a;d.content=d.querySelector(".dialog-content");d.alt_content=d.querySelector(".dialog-alt-content");d.footer=d.querySelector(".dialog-footer");d.close=function(){if(d.onClose&&"function"==typeof d.onClose)d.onClose();d.parentNode.removeChild(d);this.parentNode&&this.parentNode.removeChild(this)};d.toggleAltContent=function(a){if("undefined"!=typeof a){var b=a?"block":"none";a=
|
||||
a?"none":"block"}else b="block"!=d.alt_content.style.display?"block":"none",a="block"!=d.alt_content.style.display?"none":"block";d.alt_content.style.display=b;d.content.style.display=a};d.toggleFooterVisibility=function(a){d.footer.style.display="undefined"!=typeof a?a?"block":"none":"block"!=d.footer.style.display?"block":"none"};d.clear=function(){this.content.innerHTML=""};d.addHTML=function(a,b,c){var e=document.createElement("div");b&&(e.className=b);e.innerHTML=a;c?d.footer.appendChild(e):
|
||||
d.content.appendChild(e);return e};d.addButton=function(a,b,c){var e=document.createElement("button");e.innerText=a;e.options=c;e.classList.add("btn");e.addEventListener("click",b);d.footer.appendChild(e);return e};d.addSeparator=function(){var a=document.createElement("div");a.className="separator";d.content.appendChild(a)};d.addWidget=function(a,b,h,k,n){function e(a,b){k.callback&&k.callback(a,b,k);n&&n(a,b,k)}k=k||{};var f=String(h);a=a.toLowerCase();"number"==a&&(f=h.toFixed(3));var l=document.createElement("div");
|
||||
l.className="property";l.innerHTML="<span class='property_name'></span><span class='property_value'></span>";l.querySelector(".property_name").innerText=k.label||b;var p=l.querySelector(".property_value");p.innerText=f;l.dataset.property=b;l.dataset.type=k.type||a;l.options=k;l.value=h;if("code"==a)l.addEventListener("click",function(a){d.inner_showCodePad(this.dataset.property)});else if("boolean"==a)l.classList.add("boolean"),h&&l.classList.add("bool-on"),l.addEventListener("click",function(){var a=
|
||||
this.dataset.property;this.value=!this.value;this.classList.toggle("bool-on");this.querySelector(".property_value").innerText=this.value?"true":"false";e(a,this.value)});else if("string"==a||"number"==a)p.setAttribute("contenteditable",!0),p.addEventListener("keydown",function(b){"Enter"!=b.code||"string"==a&&b.shiftKey||(b.preventDefault(),this.blur())}),p.addEventListener("blur",function(){var a=this.innerText,b=this.parentNode.dataset.property;"number"==this.parentNode.dataset.type&&(a=Number(a));
|
||||
e(b,a)});else if("enum"==a||"combo"==a)f=m.getPropertyPrintableValue(h,k.values),p.innerText=f,p.addEventListener("click",function(a){var b=this.parentNode.dataset.property,d=this;new g.ContextMenu(k.values||[],{event:a,className:"dark",callback:function(a,c,f){d.innerText=a;e(b,a);return!1}},c)});d.content.appendChild(l);return l};if(d.onOpen&&"function"==typeof d.onOpen)d.onOpen();return d};m.getPropertyPrintableValue=function(a,b){if(!b||b.constructor===Array)return String(a);if(b.constructor===
|
||||
Object){var c="",d;for(d in b)if(b[d]==a){c=d;break}return String(a)+" ("+c+")"}};m.prototype.closePanels=function(){var a=document.querySelector("#node-panel");a&&a.close();(a=document.querySelector("#option-panel"))&&a.close()};m.prototype.showShowGraphOptionsPanel=function(a,b,c,d){if(this.constructor&&"HTMLDivElement"==this.constructor.name){if(!(b&&b.event&&b.event.target&&b.event.target.lgraphcanvas)){console.warn("Canvas not found");return}var e=b.event.target.lgraphcanvas}else e=this;e.closePanels();
|
||||
a=e.getCanvasWindow();panel=e.createPanel("Options",{closable:!0,window:a,onOpen:function(){e.OPTIONPANEL_IS_OPEN=!0},onClose:function(){e.OPTIONPANEL_IS_OPEN=!1;e.options_panel=null}});e.options_panel=panel;panel.id="option-panel";panel.classList.add("settings");(function(){panel.content.innerHTML="";var a=function(a,b,c){c&&c.key&&(a=c.key);c.values&&(b=Object.values(c.values).indexOf(b));e[a]=b},b=g.availableCanvasOptions;b.sort();for(pI in b){var c=b[pI];panel.addWidget("boolean",c,e[c],{key:c,
|
||||
on:"True",off:"False"},a)}panel.addWidget("combo","Render mode",g.LINK_RENDER_MODES[e.links_render_mode],{key:"links_render_mode",values:g.LINK_RENDER_MODES},a);panel.addSeparator();panel.footer.innerHTML=""})();e.canvas.parentNode.appendChild(panel)};m.prototype.showShowNodePanel=function(a){function b(){panel.content.innerHTML="";panel.addHTML("<span class='node_type'>"+a.type+"</span><span class='node_desc'>"+(a.constructor.desc||"")+"</span><span class='separator'></span>");panel.addHTML("<h3>Properties</h3>");
|
||||
var b=function(b,c){d.graph.beforeChange(a);switch(b){case "Title":a.title=c;break;case "Mode":b=Object.values(g.NODE_MODES).indexOf(c);0<=b&&g.NODE_MODES[b]?a.changeMode(b):console.warn("unexpected mode: "+c);break;case "Color":m.node_colors[c]?(a.color=m.node_colors[c].color,a.bgcolor=m.node_colors[c].bgcolor):console.warn("unexpected color: "+c);break;default:a.setProperty(b,c)}d.graph.afterChange();d.dirty_canvas=!0};panel.addWidget("string","Title",a.title,{},b);panel.addWidget("combo","Mode",
|
||||
g.NODE_MODES[a.mode],{values:g.NODE_MODES},b);var c="";void 0!==a.color&&(c=Object.keys(m.node_colors).filter(function(b){return m.node_colors[b].color==a.color}));panel.addWidget("combo","Color",c,{values:Object.keys(m.node_colors)},b);for(var h in a.properties){c=a.properties[h];var k=a.getPropertyInfo(h);a.onAddPropertyToPanel&&a.onAddPropertyToPanel(h,panel)||panel.addWidget(k.widget||k.type,h,c,k,b)}panel.addSeparator();if(a.onShowCustomPanelInfo)a.onShowCustomPanelInfo(panel);panel.footer.innerHTML=
|
||||
"";panel.addButton("Delete",function(){a.block_delete||(a.graph.remove(a),panel.close())}).classList.add("delete")}this.SELECTED_NODE=a;this.closePanels();var c=this.getCanvasWindow(),d=this;panel=this.createPanel(a.title||"",{closable:!0,window:c,onOpen:function(){d.NODEPANEL_IS_OPEN=!0},onClose:function(){d.NODEPANEL_IS_OPEN=!1;d.node_panel=null}});d.node_panel=panel;panel.id="node-panel";panel.node=a;panel.classList.add("settings");panel.inner_showCodePad=function(c){panel.classList.remove("settings");
|
||||
panel.classList.add("centered");panel.alt_content.innerHTML="<textarea class='code'></textarea>";var e=panel.alt_content.querySelector("textarea"),d=function(){panel.toggleAltContent(!1);panel.toggleFooterVisibility(!0);e.parentNode.removeChild(e);panel.classList.add("settings");panel.classList.remove("centered");b()};e.value=a.properties[c];e.addEventListener("keydown",function(b){"Enter"==b.code&&b.ctrlKey&&(a.setProperty(c,e.value),d())});panel.toggleAltContent(!0);panel.toggleFooterVisibility(!1);
|
||||
e.style.height="calc(100% - 40px)";var g=panel.addButton("Assign",function(){a.setProperty(c,e.value);d()});panel.alt_content.appendChild(g);g=panel.addButton("Close",d);g.style.float="right";panel.alt_content.appendChild(g)};b();this.canvas.parentNode.appendChild(panel)};m.prototype.showSubgraphPropertiesDialog=function(a){function b(){d.clear();if(a.inputs)for(var c=0;c<a.inputs.length;++c){var f=a.inputs[c];if(!f.not_subgraph_input){var g=d.addHTML("<button>✕</button> <span class='bullet_icon'></span><span class='name'></span><span class='type'></span>",
|
||||
"subgraph_property");g.dataset.name=f.name;g.dataset.slot=c;g.querySelector(".name").innerText=f.name;g.querySelector(".type").innerText=f.type;g.querySelector("button").addEventListener("click",function(c){a.removeInput(Number(this.parentNode.dataset.slot));b()})}}}console.log("showing subgraph properties dialog");var c=this.canvas.parentNode.querySelector(".subgraph_dialog");c&&c.close();var d=this.createPanel("Subgraph Inputs",{closable:!0,width:500});d.node=a;d.classList.add("subgraph_dialog");
|
||||
d.addHTML(" + <span class='label'>Name</span><input class='name'/><span class='label'>Type</span><input class='type'></input><button>+</button>","subgraph_property extra",!0).querySelector("button").addEventListener("click",function(c){c=this.parentNode;var e=c.querySelector(".name").value,d=c.querySelector(".type").value;e&&-1==a.findInputSlot(e)&&(a.addInput(e,d),c.querySelector(".name").value="",c.querySelector(".type").value="",b())});b();this.canvas.parentNode.appendChild(d);return d};m.prototype.showSubgraphPropertiesDialogRight=
|
||||
function(a){function b(){e.clear();if(a.outputs)for(var c=0;c<a.outputs.length;++c){var d=a.outputs[c];if(!d.not_subgraph_output){var g=e.addHTML("<button>✕</button> <span class='bullet_icon'></span><span class='name'></span><span class='type'></span>","subgraph_property");g.dataset.name=d.name;g.dataset.slot=c;g.querySelector(".name").innerText=d.name;g.querySelector(".type").innerText=d.type;g.querySelector("button").addEventListener("click",function(c){a.removeOutput(Number(this.parentNode.dataset.slot));
|
||||
b()})}}}function c(){var c=this.parentNode,e=c.querySelector(".name").value,d=c.querySelector(".type").value;e&&-1==a.findOutputSlot(e)&&(a.addOutput(e,d),c.querySelector(".name").value="",c.querySelector(".type").value="",b())}var d=this.canvas.parentNode.querySelector(".subgraph_dialog");d&&d.close();var e=this.createPanel("Subgraph Outputs",{closable:!0,width:500});e.node=a;e.classList.add("subgraph_dialog");d=e.addHTML(" + <span class='label'>Name</span><input class='name'/><span class='label'>Type</span><input class='type'></input><button>+</button>",
|
||||
"subgraph_property extra",!0);d.querySelector(".name").addEventListener("keydown",function(a){13==a.keyCode&&c.apply(this)});d.querySelector("button").addEventListener("click",function(a){c.apply(this)});b();this.canvas.parentNode.appendChild(e);return e};m.prototype.checkPanels=function(){if(this.canvas)for(var a=this.canvas.parentNode.querySelectorAll(".litegraph.dialog"),b=0;b<a.length;++b){var c=a[b];c.node&&(c.node.graph&&c.graph==this.graph||c.close())}};m.onMenuNodeCollapse=function(a,b,c,
|
||||
d,e){e.graph.beforeChange();a=m.active_canvas;if(!a.selected_nodes||1>=Object.keys(a.selected_nodes).length)e.collapse();else for(var f in a.selected_nodes)a.selected_nodes[f].collapse();e.graph.afterChange()};m.onMenuNodePin=function(a,b,c,d,e){e.pin()};m.onMenuNodeMode=function(a,b,c,d,e){new g.ContextMenu(g.NODE_MODES,{event:c,callback:function(a){if(e){var b=Object.values(g.NODE_MODES).indexOf(a),c=function(c){0<=b&&g.NODE_MODES[b]?c.changeMode(b):(console.warn("unexpected mode: "+a),c.changeMode(g.ALWAYS))},
|
||||
d=m.active_canvas;if(!d.selected_nodes||1>=Object.keys(d.selected_nodes).length)c(e);else for(var f in d.selected_nodes)c(d.selected_nodes[f])}},parentMenu:d,node:e});return!1};m.onMenuNodeColors=function(a,b,c,d,e){if(!e)throw"no node for color";b=[];b.push({value:null,content:"<span style='display: block; padding-left: 4px;'>No color</span>"});for(var f in m.node_colors)a=m.node_colors[f],a={value:f,content:"<span style='display: block; color: #999; padding-left: 4px; border-left: 8px solid "+a.color+
|
||||
"; background-color:"+a.bgcolor+"'>"+f+"</span>"},b.push(a);new g.ContextMenu(b,{event:c,callback:function(a){if(e){var b=a.value?m.node_colors[a.value]:null;a=function(a){b?a.constructor===g.LGraphGroup?a.color=b.groupcolor:(a.color=b.color,a.bgcolor=b.bgcolor):(delete a.color,delete a.bgcolor)};var c=m.active_canvas;if(!c.selected_nodes||1>=Object.keys(c.selected_nodes).length)a(e);else for(var d in c.selected_nodes)a(c.selected_nodes[d]);e.setDirtyCanvas(!0,!0)}},parentMenu:d,node:e});return!1};
|
||||
m.onMenuNodeShapes=function(a,b,c,d,e){if(!e)throw"no node passed";new g.ContextMenu(g.VALID_SHAPES,{event:c,callback:function(a){if(e){e.graph.beforeChange();var b=m.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)e.shape=a;else for(var c in b.selected_nodes)b.selected_nodes[c].shape=a;e.graph.afterChange();e.setDirtyCanvas(!0)}},parentMenu:d,node:e});return!1};m.onMenuNodeRemove=function(a,b,c,d,e){if(!e)throw"no node passed";a=e.graph;a.beforeChange();b=m.active_canvas;
|
||||
if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)!1!==e.removable&&a.remove(e);else for(var f in b.selected_nodes)c=b.selected_nodes[f],!1!==c.removable&&a.remove(c);a.afterChange();e.setDirtyCanvas(!0,!0)};m.onMenuNodeToSubgraph=function(a,b,c,d,e){a=e.graph;if(b=m.active_canvas)c=Object.values(b.selected_nodes||{}),c.length||(c=[e]),d=g.createNode("graph/subgraph"),d.pos=e.pos.concat(),a.add(d),d.buildFromNodes(c),b.deselectAllNodes(),e.setDirtyCanvas(!0,!0)};m.onMenuNodeClone=function(a,
|
||||
b,c,d,e){e.graph.beforeChange();var f={};a=function(a){if(0!=a.clonable){var b=a.clone();b&&(b.pos=[a.pos[0]+5,a.pos[1]+5],a.graph.add(b),f[b.id]=b)}};b=m.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)a(e);else for(var g in b.selected_nodes)a(b.selected_nodes[g]);Object.keys(f).length&&b.selectNodes(f);e.graph.afterChange();e.setDirtyCanvas(!0,!0)};m.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"}};m.prototype.getCanvasMenuOptions=function(){if(this.getMenuOptions)var a=this.getMenuOptions();else a=[{content:"Add Node",
|
||||
has_submenu:!0,callback:m.onMenuAdd},{content:"Add Group",callback:m.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};m.prototype.getNodeMenuOptions=function(a){if(a.getMenuOptions)var b=a.getMenuOptions(this);else b=[{content:"Inputs",has_submenu:!0,disabled:!0,callback:m.showMenuNodeOptionalInputs},{content:"Outputs",
|
||||
has_submenu:!0,disabled:!0,callback:m.showMenuNodeOptionalOutputs},null,{content:"Properties",has_submenu:!0,callback:m.onShowMenuNodeProperties},null,{content:"Title",callback:m.onShowPropertyEditor},{content:"Mode",has_submenu:!0,callback:m.onMenuNodeMode}],!1!==a.resizable&&b.push({content:"Resize",callback:m.onMenuResizeNode}),b.push({content:"Collapse",callback:m.onMenuNodeCollapse},{content:"Pin",callback:m.onMenuNodePin},{content:"Colors",has_submenu:!0,callback:m.onMenuNodeColors},{content:"Shapes",
|
||||
has_submenu:!0,callback:m.onMenuNodeShapes},null);if(a.onGetInputs){var c=a.onGetInputs();c&&c.length&&(b[0].disabled=!1)}a.onGetOutputs&&(c=a.onGetOutputs())&&c.length&&(b[1].disabled=!1);a.getExtraMenuOptions&&(c=a.getExtraMenuOptions(this,b))&&(c.push(null),b=c.concat(b));!1!==a.clonable&&b.push({content:"Clone",callback:m.onMenuNodeClone});b.push(null,{content:"Remove",disabled:!(!1!==a.removable&&!a.block_delete),callback:m.onMenuNodeRemove});if(a.graph&&a.graph.onGetNodeMenuOptions)a.graph.onGetNodeMenuOptions(b,
|
||||
a);return b};m.prototype.getGroupMenuOptions=function(a){return[{content:"Title",callback:m.onShowPropertyEditor},{content:"Color",has_submenu:!0,callback:m.onMenuNodeColors},{content:"Font size",property:"font_size",type:"Number",callback:m.onShowPropertyEditor},null,{content:"Remove",callback:m.onMenuNodeRemove}]};m.prototype.processContextMenu=function(a,b){var c=this,d=m.active_canvas.getCanvasWindow(),e=null,f={event:b,callback:function(b,d,e){if(b)if("Remove Slot"==b.content)b=b.slot,a.graph.beforeChange(),
|
||||
b.input?a.removeInput(b.slot):b.output&&a.removeOutput(b.slot),a.graph.afterChange();else if("Disconnect Links"==b.content)b=b.slot,a.graph.beforeChange(),b.output?a.disconnectOutput(b.slot):b.input&&a.disconnectInput(b.slot),a.graph.afterChange();else if("Rename Slot"==b.content){b=b.slot;var f=b.input?a.getInputInfo(b.slot):a.getOutputInfo(b.slot),g=c.createDialog("<span class='name'>Name</span><input autofocus type='text'/><button>OK</button>",d),h=g.querySelector("input");h&&f&&(h.value=f.label||
|
||||
"");var k=function(){a.graph.beforeChange();h.value&&(f&&(f.label=h.value),c.setDirty(!0));g.close();a.graph.afterChange()};g.querySelector("button").addEventListener("click",k);h.addEventListener("keydown",function(a){g.is_modified=!0;if(27==a.keyCode)g.close();else if(13==a.keyCode)k();else if(13!=a.keyCode&&"textarea"!=a.target.localName)return;a.preventDefault();a.stopPropagation()});h.focus()}},extra:a};a&&(f.title=a.type);var h=null;a&&(h=a.getSlotInPosition(b.canvasX,b.canvasY),m.active_node=
|
||||
a);h?(e=[],a.getSlotMenuOptions?e=a.getSlotMenuOptions(h):(h&&h.output&&h.output.links&&h.output.links.length&&e.push({content:"Disconnect Links",slot:h}),b=h.input||h.output,b.removable&&e.push(b.locked?"Cannot remove":{content:"Remove Slot",slot:h}),b.nameLocked||e.push({content:"Rename Slot",slot:h})),f.title=(h.input?h.input.type:h.output.type)||"*",h.input&&h.input.type==g.ACTION&&(f.title="Action"),h.output&&h.output.type==g.EVENT&&(f.title="Event")):a?e=this.getNodeMenuOptions(a):(e=this.getCanvasMenuOptions(),
|
||||
(h=this.graph.getGroupOnPos(b.canvasX,b.canvasY))&&e.push(null,{content:"Edit Group",has_submenu:!0,submenu:{title:"Group",extra:h,options:this.getGroupMenuOptions(h)}}));e&&new g.ContextMenu(e,f,d)};"undefined"!=typeof window&&window.CanvasRenderingContext2D&&!window.CanvasRenderingContext2D.prototype.roundRect&&(window.CanvasRenderingContext2D.prototype.roundRect=function(a,b,c,d,e,f){var g,k;if(0===e)this.rect(a,b,c,d);else{void 0===f&&(f=e);if(null!=e&&e.constructor===Array)if(1==e.length)var l=
|
||||
g=k=f=e[0];else if(2==e.length)l=f=e[0],g=k=e[1];else if(4==e.length)l=e[0],g=e[1],k=e[2],f=e[3];else return;else l=e||0,g=e||0,k=f||0,f=f||0;this.moveTo(a+l,b);this.lineTo(a+c-g,b);this.quadraticCurveTo(a+c,b,a+c,b+g);this.lineTo(a+c,b+d-f);this.quadraticCurveTo(a+c,b+d,a+c-f,b+d);this.lineTo(a+f,b+d);this.quadraticCurveTo(a,b+d,a,b+d-k);this.lineTo(a,b+k);this.quadraticCurveTo(a,b,a+l,b)}});g.compareObjects=function(a,b){for(var c in a)if(a[c]!=b[c])return!1;return!0};g.distance=H;g.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")+")"};g.isInsideRectangle=C;g.growBounding=function(a,b,c){b<a[0]?a[0]=b:b>a[2]&&(a[2]=b);c<a[1]?a[1]=c:c>a[3]&&(a[3]=c)};g.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};g.overlapBounding=F;g.hex2num=function(a){"#"==a.charAt(0)&&(a=a.slice(1));a=a.toUpperCase();for(var b=Array(3),
|
||||
c=0,d,e,f=0;6>f;f+=2)d="0123456789ABCDEF".indexOf(a.charAt(f)),e="0123456789ABCDEF".indexOf(a.charAt(f+1)),b[c]=16*d+e,c++;return b};g.num2hex=function(a){for(var b="#",c,d,e=0;3>e;e++)c=a[e]/16,d=a[e]%16,b+="0123456789ABCDEF".charAt(c)+"0123456789ABCDEF".charAt(d);return b};D.prototype.addItem=function(a,b,c){function d(a){var b=this.value;b&&b.has_submenu&&e.call(this,a)}function e(a){var b=this.value,d=!0;f.current_submenu&&f.current_submenu.close(a);if(c.callback){var e=c.callback.call(this,b,
|
||||
c,a,f,c.node);!0===e&&(d=!1)}if(b&&(b.callback&&!c.ignore_item_callbacks&&!0!==b.disabled&&(e=b.callback.call(this,b,c,a,f,c.extra),!0===e&&(d=!1)),b.submenu)){if(!b.submenu.options)throw"ContextMenu submenu needs options";new f.constructor(b.submenu.options,{callback:b.submenu.callback,event:a,parentMenu:f,ignore_item_callbacks:b.submenu.ignore_item_callbacks,title:b.submenu.title,extra:b.submenu.extra,autoopen:c.autoopen});d=!1}d&&!f.lock&&f.close()}var f=this;c=c||{};var h=document.createElement("div");
|
||||
h.className="litemenu-entry submenu";var k=!1;if(null===b)h.classList.add("separator");else{h.innerHTML=b&&b.title?b.title:a;if(h.value=b)b.disabled&&(k=!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);k||h.addEventListener("click",e);c.autoopen&&g.pointerListenerAdd(h,"enter",d);return h};D.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&&!D.isCursorOverElement(a,this.parentMenu.root)&&D.trigger(this.parentMenu.root,g.pointerevents_method+"leave",a));this.current_submenu&&this.current_submenu.close(a,!0);this.root.closing_timer&&clearTimeout(this.root.closing_timer)};D.trigger=function(a,b,c,d){var e=document.createEvent("CustomEvent");e.initCustomEvent(b,
|
||||
!0,!0,c);e.srcElement=d;a.dispatchEvent?a.dispatchEvent(e):a.__events&&a.__events.dispatchEvent(e);return e};D.prototype.getTopMenu=function(){return this.options.parentMenu?this.options.parentMenu.getTopMenu():this};D.prototype.getFirstEvent=function(){return this.options.parentMenu?this.options.parentMenu.getFirstEvent():this.options.event};D.isCursorOverElement=function(a,b){var c=a.clientX;a=a.clientY;return(b=b.getBoundingClientRect())?a>b.top&&a<b.top+b.height&&c>b.left&&c<b.left+b.width?!0:
|
||||
!1:!1};g.ContextMenu=D;g.closeAllContextMenus=function(a){a=a||window;a=a.document.querySelectorAll(".litecontextmenu");if(a.length){for(var b=[],c=0;c<a.length;c++)b.push(a[c]);for(c=0;c<b.length;c++)b[c].close?b[c].close():b[c].parentNode&&b[c].parentNode.removeChild(b[c])}};g.extendClass=function(a,b){for(var c in b)a.hasOwnProperty(c)||(a[c]=b[c]);if(b.prototype)for(c in b.prototype)b.prototype.hasOwnProperty(c)&&!a.prototype.hasOwnProperty(c)&&(b.prototype.__lookupGetter__(c)?a.prototype.__defineGetter__(c,
|
||||
b.prototype.__lookupGetter__(c)):a.prototype[c]=b.prototype[c],b.prototype.__lookupSetter__(c)&&a.prototype.__defineSetter__(c,b.prototype.__lookupSetter__(c)))};E.sampleCurve=function(a,b){if(b){for(var c=0;c<b.length-1;++c){var d=b[c],e=b[c+1];if(!(e[0]<a)){b=e[0]-d[0];if(1E-5>Math.abs(b))return d[1];a=(a-d[0])/b;return d[1]*(1-a)+e[1]*a}}return 0}};E.prototype.draw=function(a,b,c,d,e,f){if(c=this.points){this.size=b;var g=b[0]-2*this.margin;b=b[1]-2*this.margin;e=e||"#666";a.save();a.translate(this.margin,
|
||||
this.margin);d&&(a.fillStyle="#111",a.fillRect(0,0,g,b),a.fillStyle="#222",a.fillRect(.5*g,0,1,b),a.strokeStyle="#333",a.strokeRect(0,0,g,b));a.strokeStyle=e;f&&(a.globalAlpha=.5);a.beginPath();for(d=0;d<c.length;++d)e=c[d],a.lineTo(e[0]*g,(1-e[1])*b);a.stroke();a.globalAlpha=1;if(!f)for(d=0;d<c.length;++d)e=c[d],a.fillStyle=this.selected==d?"#FFF":this.nearest==d?"#DDD":"#AAA",a.beginPath(),a.arc(e[0]*g,(1-e[1])*b,2,0,2*Math.PI),a.fill();a.restore()}};E.prototype.onMouseDown=function(a,b){var c=
|
||||
this.points;if(c&&!(0>a[1])){var d=this.size[0]-2*this.margin,e=this.size[1]-2*this.margin,f=a[0]-this.margin;a=a[1]-this.margin;this.selected=this.getCloserPoint([f,a],30/b.ds.scale);-1==this.selected&&(b=[f/d,1-a/e],c.push(b),c.sort(function(a,b){return a[0]-b[0]}),this.selected=c.indexOf(b),this.must_update=!0);if(-1!=this.selected)return!0}};E.prototype.onMouseMove=function(a,b){var c=this.points;if(c){var d=this.selected;if(!(0>d)){var e=(a[0]-this.margin)/(this.size[0]-2*this.margin),f=(a[1]-
|
||||
this.margin)/(this.size[1]-2*this.margin);this._nearest=this.getCloserPoint([a[0]-this.margin,a[1]-this.margin],30/b.ds.scale);if(b=c[d]){var g=0==d||d==c.length-1;!g&&(-10>a[0]||a[0]>this.size[0]+10||-10>a[1]||a[1]>this.size[1]+10)?(c.splice(d,1),this.selected=-1):(b[0]=g?0==d?0:1:Math.clamp(e,0,1),b[1]=1-Math.clamp(f,0,1),c.sort(function(a,b){return a[0]-b[0]}),this.selected=c.indexOf(b),this.must_update=!0)}}}};E.prototype.onMouseUp=function(a,b){this.selected=-1;return!1};E.prototype.getCloserPoint=
|
||||
function(a,b){var c=this.points;if(!c)return-1;b=b||30;for(var d=this.size[0]-2*this.margin,e=this.size[1]-2*this.margin,f=c.length,g=[0,0],k=1E6,l=-1,m=0;m<f;++m){var p=c[m];g[0]=p[0]*d;g[1]=(1-p[1])*e;p=vec2.distance(a,g);p>k||p>b||(l=m,k=p)}return l};g.CurveEditor=E;g.getParameterNames=function(a){return(a+"").replace(/[/][/].*$/gm,"").replace(/\s+/g,"").replace(/[/][*][^/*]*[*][/]/g,"").split("){",1)[0].replace(/^[^(]*[(]/,"").replace(/=[^,]+/g,"").split(",").filter(Boolean)};g.pointerListenerAdd=
|
||||
function(a,b,c,d){d=void 0===d?!1:d;if(a&&a.addEventListener&&b&&"function"===typeof c){var e=g.pointerevents_method;if("pointer"==e&&!window.PointerEvent)switch(console.warn("sMethod=='pointer' && !window.PointerEvent"),console.log("Converting pointer["+b+"] : down move up cancel enter TO touchstart touchmove touchend, etc .."),b){case "down":e="touch";b="start";break;case "move":e="touch";break;case "up":e="touch";b="end";break;case "cancel":e="touch";break;case "enter":console.log("debug: Should I send a move event?");
|
||||
break;default:console.warn("PointerEvent not available in this browser ? The event "+b+" would not be called")}switch(b){case "down":case "up":case "move":case "over":case "out":case "enter":a.addEventListener(e+b,c,d);case "leave":case "cancel":case "gotpointercapture":case "lostpointercapture":if("mouse"!=e)return a.addEventListener(e+b,c,d);default:return a.addEventListener(b,c,d)}}};g.pointerListenerRemove=function(a,b,c,d){d=void 0===d?!1:d;if(a&&a.removeEventListener&&b&&"function"===typeof c)switch(b){case "down":case "up":case "move":case "over":case "out":case "enter":"pointer"!=
|
||||
g.pointerevents_method&&"mouse"!=g.pointerevents_method||a.removeEventListener(g.pointerevents_method+b,c,d);case "leave":case "cancel":case "gotpointercapture":case "lostpointercapture":if("pointer"==g.pointerevents_method)return a.removeEventListener(g.pointerevents_method+b,c,d);default:return a.removeEventListener(b,c,d)}};Math.clamp=function(a,b,c){return b>a?b:c<a?c:a};"undefined"==typeof window||window.requestAnimationFrame||(window.requestAnimationFrame=window.webkitRequestAnimationFrame||
|
||||
window.mozRequestAnimationFrame||function(a){window.setTimeout(a,1E3/60)})})(this);"undefined"!=typeof exports&&(exports.LiteGraph=this.LiteGraph);
|
||||
|
||||
@@ -7473,7 +7473,9 @@ LGraphNode.prototype.executeAction = function(action)
|
||||
* @method adjustMouseEvent
|
||||
**/
|
||||
LGraphCanvas.prototype.adjustMouseEvent = function(e) {
|
||||
|
||||
var clientX_rel = 0;
|
||||
var clientY_rel = 0;
|
||||
|
||||
if (this.canvas) {
|
||||
var b = this.canvas.getBoundingClientRect();
|
||||
clientX_rel = e.clientX - b.left;
|
||||
|
||||
322
build/litegraph.min.js
vendored
322
build/litegraph.min.js
vendored
@@ -183,167 +183,167 @@ function(a){if(this.onShowNodePanel)this.onShowNodePanel(a);else this.showShowNo
|
||||
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 g=0;g<d.links.length;++g)delete this.highlighted_links[d.links[g]]}}};h.prototype.deselectAllNodes=function(){if(this.graph){for(var a=this.graph._nodes,b=0,d=a.length;b<d;++b){var g=a[b];if(g.is_selected){if(g.onDeselected)g.onDeselected();g.is_selected=!1;
|
||||
if(this.onNodeDeselected)this.onNodeDeselected(g)}}this.selected_nodes={};this.current_node=null;this.highlighted_links={};if(this.onSelectionChange)this.onSelectionChange(this.selected_nodes);this.setDirty(!0)}};h.prototype.deleteSelectedNodes=function(){this.graph.beforeChange();for(var a in this.selected_nodes){var b=this.selected_nodes[a];if(!b.block_delete){if(b.inputs&&b.inputs.length&&b.outputs&&b.outputs.length&&e.isValidConnection(b.inputs[0].type,b.outputs[0].type)&&b.inputs[0].link&&b.outputs[0].links&&
|
||||
b.outputs[0].links.length){var d=b.graph.links[b.inputs[0].link],g=b.graph.links[b.outputs[0].links[0]],f=b.getInputNode(0),m=b.getOutputNodes(0)[0];f&&m&&f.connect(d.origin_slot,m,g.target_slot)}this.graph.remove(b);if(this.onNodeDeselected)this.onNodeDeselected(b)}}this.selected_nodes={};this.current_node=null;this.highlighted_links={};this.setDirty(!0);this.graph.afterChange()};h.prototype.centerOnNode=function(a){this.ds.offset[0]=-a.pos[0]-.5*a.size[0]+.5*this.canvas.width/this.ds.scale;this.ds.offset[1]=
|
||||
-a.pos[1]-.5*a.size[1]+.5*this.canvas.height/this.ds.scale;this.setDirty(!0,!0)};h.prototype.adjustMouseEvent=function(a){if(this.canvas){var b=this.canvas.getBoundingClientRect();clientX_rel=a.clientX-b.left;clientY_rel=a.clientY-b.top}else clientX_rel=a.clientX,clientY_rel=a.clientY;a.deltaX=clientX_rel-this.last_mouse_position[0];a.deltaY=clientY_rel-this.last_mouse_position[1];this.last_mouse_position[0]=clientX_rel;this.last_mouse_position[1]=clientY_rel;a.canvasX=clientX_rel/this.ds.scale-this.ds.offset[0];
|
||||
a.canvasY=clientY_rel/this.ds.scale-this.ds.offset[1]};h.prototype.setZoom=function(a,b){this.ds.changeScale(a,b);this.dirty_bgcanvas=this.dirty_canvas=!0};h.prototype.convertOffsetToCanvas=function(a,b){return this.ds.convertOffsetToCanvas(a,b)};h.prototype.convertCanvasToOffset=function(a,b){return this.ds.convertCanvasToOffset(a,b)};h.prototype.convertEventToCanvasOffset=function(a){var b=this.canvas.getBoundingClientRect();return this.convertCanvasToOffset([a.clientX-b.left,a.clientY-b.top])};
|
||||
h.prototype.bringToFront=function(a){var b=this.graph._nodes.indexOf(a);-1!=b&&(this.graph._nodes.splice(b,1),this.graph._nodes.push(a))};h.prototype.sendToBack=function(a){var b=this.graph._nodes.indexOf(a);-1!=b&&(this.graph._nodes.splice(b,1),this.graph._nodes.unshift(a))};var D=new Float32Array(4);h.prototype.computeVisibleNodes=function(a,b){b=b||[];b.length=0;a=a||this.graph._nodes;for(var d=0,g=a.length;d<g;++d){var f=a[d];(!this.live_mode||f.onDrawBackground||f.onDrawForeground)&&I(this.visible_area,
|
||||
f.getBounding(D))&&b.push(f)}return b};h.prototype.draw=function(a,b){if(this.canvas&&0!=this.canvas.width&&0!=this.canvas.height){var d=e.getTime();this.render_time=.001*(d-this.last_draw_time);this.last_draw_time=d;this.graph&&this.ds.computeVisibleArea(this.viewport);(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}};h.prototype.drawFrontCanvas=function(){this.dirty_canvas=!1;this.ctx||(this.ctx=this.bgcanvas.getContext("2d"));var a=this.ctx;if(a){var b=this.canvas;a.start2D&&!this.viewport&&(a.start2D(),a.restore(),a.setTransform(1,0,0,1,0,0));var d=this.viewport||this.dirty_area;d&&(a.save(),a.beginPath(),a.rect(d[0],d[1],d[2],d[3]),a.clip());this.clear_background&&(d?a.clearRect(d[0],d[1],d[2],d[3]):a.clearRect(0,0,b.width,b.height));this.bgcanvas==this.canvas?this.drawBackCanvas():
|
||||
a.drawImage(this.bgcanvas,0,0);if(this.onRender)this.onRender(b,a);this.show_info&&this.renderInfo(a,d?d[0]:0,d?d[1]:0);if(this.graph){a.save();this.ds.toCanvasContext(a);b=this.computeVisibleNodes(null,this.visible_nodes);for(var g=0;g<b.length;++g){var f=b[g];a.save();a.translate(f.pos[0],f.pos[1]);this.drawNode(f,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;f=this.connecting_output||this.connecting_input;b=f.type;g=f.dir;null==g&&(g=this.connecting_output?this.connecting_node.horizontal?e.DOWN:e.RIGHT:this.connecting_node.horizontal?e.UP:e.LEFT);var m=f.shape;switch(b){case e.EVENT:f=e.EVENT_LINK_COLOR;break;default:f=e.CONNECTING_LINK_COLOR}this.renderLink(a,this.connecting_pos,[this.graph_mouse[0],this.graph_mouse[1]],null,!1,null,f,g,e.CENTER);a.beginPath();b===e.EVENT||m===e.BOX_SHAPE?(a.rect(this.connecting_pos[0]-6+.5,this.connecting_pos[1]-
|
||||
5+.5,14,10),a.fill(),a.beginPath(),a.rect(this.graph_mouse[0]-6+.5,this.graph_mouse[1]-5+.5,14,10)):m===e.ARROW_SHAPE?(a.moveTo(this.connecting_pos[0]+8,this.connecting_pos[1]+.5),a.lineTo(this.connecting_pos[0]-4,this.connecting_pos[1]+6+.5),a.lineTo(this.connecting_pos[0]-4,this.connecting_pos[1]-6+.5),a.closePath()):(a.arc(this.connecting_pos[0],this.connecting_pos[1],4,0,2*Math.PI),a.fill(),a.beginPath(),a.arc(this.graph_mouse[0],this.graph_mouse[1],4,0,2*Math.PI));a.fill();a.fillStyle="#ffcc00";
|
||||
if(this._highlight_input){a.beginPath();var c=this._highlight_input_slot.shape;c===e.ARROW_SHAPE?(a.moveTo(this._highlight_input[0]+8,this._highlight_input[1]+.5),a.lineTo(this._highlight_input[0]-4,this._highlight_input[1]+6+.5),a.lineTo(this._highlight_input[0]-4,this._highlight_input[1]-6+.5),a.closePath()):a.arc(this._highlight_input[0],this._highlight_input[1],6,0,2*Math.PI);a.fill()}this._highlight_output&&(a.beginPath(),c===e.ARROW_SHAPE?(a.moveTo(this._highlight_output[0]+8,this._highlight_output[1]+
|
||||
.5),a.lineTo(this._highlight_output[0]-4,this._highlight_output[1]+6+.5),a.lineTo(this._highlight_output[0]-4,this._highlight_output[1]-6+.5),a.closePath()):a.arc(this._highlight_output[0],this._highlight_output[1],6,0,2*Math.PI),a.fill())}this.dragging_rectangle&&(a.strokeStyle="#FFF",a.strokeRect(this.dragging_rectangle[0],this.dragging_rectangle[1],this.dragging_rectangle[2],this.dragging_rectangle[3]));if(this.over_link_center&&this.render_link_tooltip)this.drawLinkTooltip(a,this.over_link_center);
|
||||
else if(this.onDrawLinkTooltip)this.onDrawLinkTooltip(a,null);if(this.onDrawForeground)this.onDrawForeground(a,this.visible_rect);a.restore()}this._graph_stack&&this._graph_stack.length&&this.drawSubgraphPanel(a);if(this.onDrawOverlay)this.onDrawOverlay(a);d&&a.restore();a.finish2D&&a.finish2D()}};h.prototype.drawSubgraphPanel=function(a){var b=this.graph,d=b._subgraph_node;d?(this.drawSubgraphPanelLeft(b,d,a),this.drawSubgraphPanelRight(b,d,a)):console.warn("subgraph without subnode")};h.prototype.drawSubgraphPanelLeft=
|
||||
function(a,b,d){var g=b.inputs?b.inputs.length:0,f=Math.floor(1.6*e.NODE_SLOT_HEIGHT);d.fillStyle="#111";d.globalAlpha=.8;d.beginPath();d.roundRect(10,10,200,(g+1)*f+50,[8]);d.fill();d.globalAlpha=1;d.fillStyle="#888";d.font="14px Arial";d.textAlign="left";d.fillText("Graph Inputs",20,34);if(this.drawButton(180,20,20,20,"X","#151515"))this.closeSubgraph();else{g=50;d.font="14px Arial";if(b.inputs)for(var m=0;m<b.inputs.length;++m){var c=b.inputs[m];if(!c.not_subgraph_input){if(this.drawButton(20,
|
||||
g+2,180,f-2)){var k=b.constructor.input_node_type||"graph/input";this.graph.beforeChange();var q=e.createNode(k);q?(a.add(q),this.block_click=!1,this.last_click_position=null,this.selectNodes([q]),this.node_dragged=q,this.dragging_canvas=!1,q.setProperty("name",c.name),q.setProperty("type",c.type),this.node_dragged.pos[0]=this.graph_mouse[0]-5,this.node_dragged.pos[1]=this.graph_mouse[1]-5,this.graph.afterChange()):console.error("graph input node not found:",k)}d.fillStyle="#9C9";d.beginPath();d.arc(184,
|
||||
g+.5*f,5,0,2*Math.PI);d.fill();d.fillStyle="#AAA";d.fillText(c.name,30,g+.75*f);d.fillStyle="#777";d.fillText(c.type,130,g+.75*f);g+=f}}this.drawButton(20,g+2,180,f-2,"+","#151515","#222")&&this.showSubgraphPropertiesDialog(b)}};h.prototype.drawSubgraphPanelRight=function(a,b,d){var g=b.outputs?b.outputs.length:0,f=this.bgcanvas.width,m=Math.floor(1.6*e.NODE_SLOT_HEIGHT);d.fillStyle="#111";d.globalAlpha=.8;d.beginPath();d.roundRect(f-200-10,10,200,(g+1)*m+50,[8]);d.fill();d.globalAlpha=1;d.fillStyle=
|
||||
"#888";d.font="14px Arial";d.textAlign="left";g=d.measureText("Graph Outputs").width;d.fillText("Graph Outputs",f-g-20,34);if(this.drawButton(f-200,20,20,20,"X","#151515"))this.closeSubgraph();else{g=50;d.font="14px Arial";if(b.outputs)for(var c=0;c<b.outputs.length;++c){var k=b.outputs[c];if(!k.not_subgraph_input){if(this.drawButton(f-200,g+2,180,m-2)){var q=b.constructor.output_node_type||"graph/output";this.graph.beforeChange();var x=e.createNode(q);x?(a.add(x),this.block_click=!1,this.last_click_position=
|
||||
null,this.selectNodes([x]),this.node_dragged=x,this.dragging_canvas=!1,x.setProperty("name",k.name),x.setProperty("type",k.type),this.node_dragged.pos[0]=this.graph_mouse[0]-5,this.node_dragged.pos[1]=this.graph_mouse[1]-5,this.graph.afterChange()):console.error("graph input node not found:",q)}d.fillStyle="#9C9";d.beginPath();d.arc(f-200+16,g+.5*m,5,0,2*Math.PI);d.fill();d.fillStyle="#AAA";d.fillText(k.name,f-200+30,g+.75*m);d.fillStyle="#777";d.fillText(k.type,f-200+130,g+.75*m);g+=m}}this.drawButton(f-
|
||||
200,g+2,180,m-2,"+","#151515","#222")&&this.showSubgraphPropertiesDialogRight(b)}};h.prototype.drawButton=function(a,b,d,g,f,m,c,k){var u=this.ctx;m=m||e.NODE_DEFAULT_COLOR;c=c||"#555";k=k||e.NODE_TEXT_COLOR;var x=b+e.NODE_TITLE_HEIGHT+2,C=this.mouse,w=e.isInsideRectangle(C[0],C[1],a,x,d,g);x=(C=this.last_click_position)&&e.isInsideRectangle(C[0],C[1],a,x,d,g);u.fillStyle=w?c:m;x&&(u.fillStyle="#AAA");u.beginPath();u.roundRect(a,b,d,g,[4]);u.fill();null!=f&&f.constructor==String&&(u.fillStyle=k,u.textAlign=
|
||||
"center",u.font=(.65*g|0)+"px Arial",u.fillText(f,a+.5*d,b+.75*g),u.textAlign="left");a=x&&!this.block_click;x&&this.blockClick();return a};h.prototype.isAreaClicked=function(a,b,d,g,f){var m=this.mouse;e.isInsideRectangle(m[0],m[1],a,b,d,g);b=(a=(m=this.last_click_position)&&e.isInsideRectangle(m[0],m[1],a,b,d,g))&&!this.block_click;a&&f&&this.blockClick();return b};h.prototype.renderInfo=function(a,b,d){b=b||10;d=d||this.canvas.height-80;a.save();a.translate(b,d);a.font="10px Arial";a.fillStyle=
|
||||
"#888";a.textAlign="left";this.graph?(a.fillText("T: "+this.graph.globaltime.toFixed(2)+"s",5,13),a.fillText("I: "+this.graph.iteration,5,26),a.fillText("N: "+this.graph._nodes.length+" ["+this.visible_nodes.length+"]",5,39),a.fillText("V: "+this.graph._version,5,52),a.fillText("FPS:"+this.fps.toFixed(2),5,65)):a.fillText("No graph selected",5,13);a.restore()};h.prototype.drawBackCanvas=function(){var a=this.bgcanvas;if(a.width!=this.canvas.width||a.height!=this.canvas.height)a.width=this.canvas.width,
|
||||
a.height=this.canvas.height;this.bgctx||(this.bgctx=this.bgcanvas.getContext("2d"));var b=this.bgctx;b.start&&b.start();var d=this.viewport||[0,0,b.canvas.width,b.canvas.height];this.clear_background&&b.clearRect(d[0],d[1],d[2],d[3]);if(this._graph_stack&&this._graph_stack.length){b.save();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 g="",f=1;f<
|
||||
this._graph_stack.length;++f)g+=this._graph_stack[f]._subgraph_node.getTitle()+" >> ";b.fillText(g+d.getTitle(),.5*a.width,40);b.restore()}d=!1;this.onRenderBackground&&(d=this.onRenderBackground(a,b));this.viewport||(b.restore(),b.setTransform(1,0,0,1,0,0));this.visible_links.length=0;if(this.graph){b.save();this.ds.toCanvasContext(b);if(this.background_image&&.5<this.ds.scale&&!d){b.globalAlpha=this.zoom_modify_alpha?(1-.5/this.ds.scale)*this.editor_alpha:this.editor_alpha;b.imageSmoothingEnabled=
|
||||
b.imageSmoothingEnabled=!1;if(!this._bg_img||this._bg_img.name!=this.background_image){this._bg_img=new Image;this._bg_img.name=this.background_image;this._bg_img.src=this.background_image;var e=this;this._bg_img.onload=function(){e.draw(!0,!0)}}d=null;null==this._pattern&&0<this._bg_img.width?(d=b.createPattern(this._bg_img,"repeat"),this._pattern_img=this._bg_img,this._pattern=d):d=this._pattern;d&&(b.fillStyle=d,b.fillRect(this.visible_area[0],this.visible_area[1],this.visible_area[2],this.visible_area[3]),
|
||||
b.fillStyle="transparent");b.globalAlpha=1;b.imageSmoothingEnabled=b.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 H=new Float32Array(2);h.prototype.drawNode=function(a,b){this.current_node=a;var d=a.color||a.constructor.color||e.NODE_DEFAULT_COLOR,g=a.bgcolor||a.constructor.bgcolor||e.NODE_DEFAULT_BGCOLOR,f=.6>this.ds.scale;if(this.live_mode){if(!a.flags.collapsed&&(b.shadowColor=
|
||||
"transparent",a.onDrawForeground))a.onDrawForeground(b,this,this.canvas)}else{var m=this.editor_alpha;b.globalAlpha=m;this.render_shadows&&!f?(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||1!=a.onDrawCollapsed(b,this)){var c=a._shape||e.BOX_SHAPE;H.set(a.size);var k=a.horizontal;if(a.flags.collapsed){b.font=this.inner_text_font;var q=a.getTitle?
|
||||
a.getTitle():a.title;null!=q&&(a._collapsed_width=Math.min(a.size[0],b.measureText(q).width+2*e.NODE_TITLE_HEIGHT),H[0]=a._collapsed_width,H[1]=0)}a.clip_area&&(b.save(),b.beginPath(),c==e.BOX_SHAPE?b.rect(0,0,H[0],H[1]):c==e.ROUND_SHAPE?b.roundRect(0,0,H[0],H[1],[10]):c==e.CIRCLE_SHAPE&&b.arc(.5*H[0],.5*H[1],.5*H[0],0,2*Math.PI),b.clip());a.has_errors&&(g="red");this.drawNodeShape(a,b,H,d,g,a.is_selected,a.mouseOver);b.shadowColor="transparent";if(a.onDrawForeground)a.onDrawForeground(b,this,this.canvas);
|
||||
b.textAlign=k?"center":"left";b.font=this.inner_text_font;g=!f;var x=this.connecting_output;c=this.connecting_input;b.lineWidth=1;q=0;var C=new Float32Array(2);if(!a.flags.collapsed){if(a.inputs)for(d=0;d<a.inputs.length;d++){var w=a.inputs[d],L=w.type,G=w.shape;b.globalAlpha=m;this.connecting_output&&!e.isValidConnection(w.type,x.type)&&(b.globalAlpha=.4*m);b.fillStyle=null!=w.link?w.color_on||this.default_connection_color_byType[L]||this.default_connection_color.input_on:w.color_off||this.default_connection_color_byTypeOff[L]||
|
||||
this.default_connection_color_byType[L]||this.default_connection_color.input_off;var y=a.getConnectionPos(!0,d,C);y[0]-=a.pos[0];y[1]-=a.pos[1];q<y[1]+.5*e.NODE_SLOT_HEIGHT&&(q=y[1]+.5*e.NODE_SLOT_HEIGHT);b.beginPath();"array"==L&&(G=e.GRID_SHAPE);w.type===e.EVENT||w.shape===e.BOX_SHAPE?k?b.rect(y[0]-5+.5,y[1]-8+.5,10,14):b.rect(y[0]-6+.5,y[1]-5+.5,14,10):G===e.ARROW_SHAPE?(b.moveTo(y[0]+8,y[1]+.5),b.lineTo(y[0]-4,y[1]+6+.5),b.lineTo(y[0]-4,y[1]-6+.5),b.closePath()):G===e.GRID_SHAPE?(b.rect(y[0]-
|
||||
4,y[1]-4,2,2),b.rect(y[0]-1,y[1]-4,2,2),b.rect(y[0]+2,y[1]-4,2,2),b.rect(y[0]-4,y[1]-1,2,2),b.rect(y[0]-1,y[1]-1,2,2),b.rect(y[0]+2,y[1]-1,2,2),b.rect(y[0]-4,y[1]+2,2,2),b.rect(y[0]-1,y[1]+2,2,2),b.rect(y[0]+2,y[1]+2,2,2)):f?b.rect(y[0]-4,y[1]-4,8,8):b.arc(y[0],y[1],4,0,2*Math.PI);b.fill();g&&(L=null!=w.label?w.label:w.name)&&(b.fillStyle=e.NODE_TEXT_COLOR,k||w.dir==e.UP?b.fillText(L,y[0],y[1]-10):b.fillText(L,y[0]+10,y[1]+5))}b.textAlign=k?"center":"right";b.strokeStyle="black";if(a.outputs)for(d=
|
||||
0;d<a.outputs.length;d++)if(w=a.outputs[d],L=w.type,G=w.shape,this.connecting_input&&!e.isValidConnection(L,c.type)&&(b.globalAlpha=.4*m),y=a.getConnectionPos(!1,d,C),y[0]-=a.pos[0],y[1]-=a.pos[1],q<y[1]+.5*e.NODE_SLOT_HEIGHT&&(q=y[1]+.5*e.NODE_SLOT_HEIGHT),b.fillStyle=w.links&&w.links.length?w.color_on||this.default_connection_color_byType[L]||this.default_connection_color.output_on:w.color_off||this.default_connection_color_byTypeOff[L]||this.default_connection_color_byType[L]||this.default_connection_color.output_off,
|
||||
b.beginPath(),"array"==L&&(G=e.GRID_SHAPE),x=!0,L===e.EVENT||G===e.BOX_SHAPE?k?b.rect(y[0]-5+.5,y[1]-8+.5,10,14):b.rect(y[0]-6+.5,y[1]-5+.5,14,10):G===e.ARROW_SHAPE?(b.moveTo(y[0]+8,y[1]+.5),b.lineTo(y[0]-4,y[1]+6+.5),b.lineTo(y[0]-4,y[1]-6+.5),b.closePath()):G===e.GRID_SHAPE?(b.rect(y[0]-4,y[1]-4,2,2),b.rect(y[0]-1,y[1]-4,2,2),b.rect(y[0]+2,y[1]-4,2,2),b.rect(y[0]-4,y[1]-1,2,2),b.rect(y[0]-1,y[1]-1,2,2),b.rect(y[0]+2,y[1]-1,2,2),b.rect(y[0]-4,y[1]+2,2,2),b.rect(y[0]-1,y[1]+2,2,2),b.rect(y[0]+2,y[1]+
|
||||
2,2,2),x=!1):f?b.rect(y[0]-4,y[1]-4,8,8):b.arc(y[0],y[1],4,0,2*Math.PI),b.fill(),!f&&x&&b.stroke(),g&&(L=null!=w.label?w.label:w.name))b.fillStyle=e.NODE_TEXT_COLOR,k||w.dir==e.DOWN?b.fillText(L,y[0],y[1]-8):b.fillText(L,y[0]-10,y[1]+5);b.textAlign="left";b.globalAlpha=1;if(a.widgets){w=q;if(k||a.widgets_up)w=2;null!=a.widgets_start_y&&(w=a.widgets_start_y);this.drawNodeWidgets(a,w,b,this.node_widget&&this.node_widget[0]==a?this.node_widget[1]:null)}}else if(this.render_collapsed_slots){f=m=null;
|
||||
if(a.inputs)for(d=0;d<a.inputs.length;d++)if(w=a.inputs[d],null!=w.link){m=w;break}if(a.outputs)for(d=0;d<a.outputs.length;d++)w=a.outputs[d],w.links&&w.links.length&&(f=w);m&&(m=0,d=-.5*e.NODE_TITLE_HEIGHT,k&&(m=.5*a._collapsed_width,d=-e.NODE_TITLE_HEIGHT),b.fillStyle="#686",b.beginPath(),w.type===e.EVENT||w.shape===e.BOX_SHAPE?b.rect(m-7+.5,d-4,14,8):w.shape===e.ARROW_SHAPE?(b.moveTo(m+8,d),b.lineTo(m+-4,d-4),b.lineTo(m+-4,d+4),b.closePath()):b.arc(m,d,4,0,2*Math.PI),b.fill());f&&(m=a._collapsed_width,
|
||||
d=-.5*e.NODE_TITLE_HEIGHT,k&&(m=.5*a._collapsed_width,d=0),b.fillStyle="#686",b.strokeStyle="black",b.beginPath(),w.type===e.EVENT||w.shape===e.BOX_SHAPE?b.rect(m-7+.5,d-4,14,8):w.shape===e.ARROW_SHAPE?(b.moveTo(m+6,d),b.lineTo(m-6,d-4),b.lineTo(m-6,d+4),b.closePath()):b.arc(m,d,4,0,2*Math.PI),b.fill())}a.clip_area&&b.restore();b.globalAlpha=1}}};h.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||
|
||||
1!=this.onDrawLinkTooltip(a,b,this))&&(b=b.data,b=b.constructor===Number?b.toFixed(2):b.constructor===String?'"'+b+'"':b.constructor===Boolean?String(b):b.toToolTip?b.toToolTip():"["+b.constructor.name+"]",null!=b)){b=b.substr(0,30);a.font="14px Courier New";var g=a.measureText(b).width+20;a.shadowColor="black";a.shadowOffsetX=2;a.shadowOffsetY=2;a.shadowBlur=3;a.fillStyle="#454";a.beginPath();a.roundRect(d[0]-.5*g,d[1]-15-24,g,24,[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(b,d[0],d[1]-15-24*.3)}};var z=new Float32Array(4);h.prototype.drawNodeShape=function(a,b,d,g,f,m,c){b.strokeStyle=g;b.fillStyle=f;f=e.NODE_TITLE_HEIGHT;var u=.5>this.ds.scale,k=a._shape||a.constructor.shape||e.ROUND_SHAPE,x=a.constructor.title_mode,C=!0;x==e.TRANSPARENT_TITLE||x==e.NO_TITLE?C=!1:x==e.AUTOHIDE_TITLE&&c&&(C=!0);z[0]=0;z[1]=C?-f:0;z[2]=d[0]+1;z[3]=C?d[1]+f:d[1];c=b.globalAlpha;b.beginPath();
|
||||
k==e.BOX_SHAPE||u?b.fillRect(z[0],z[1],z[2],z[3]):k==e.ROUND_SHAPE||k==e.CARD_SHAPE?b.roundRect(z[0],z[1],z[2],z[3],k==e.CARD_SHAPE?[this.round_radius,this.round_radius,0,0]:[this.round_radius]):k==e.CIRCLE_SHAPE&&b.arc(.5*d[0],.5*d[1],.5*d[0],0,2*Math.PI);b.fill();!a.flags.collapsed&&C&&(b.shadowColor="transparent",b.fillStyle="rgba(0,0,0,0.2)",b.fillRect(0,-1,z[2],2));b.shadowColor="transparent";if(a.onDrawBackground)a.onDrawBackground(b,this,this.canvas,this.graph_mouse);if(C||x==e.TRANSPARENT_TITLE){if(a.onDrawTitleBar)a.onDrawTitleBar(b,
|
||||
f,d,this.ds.scale,g);else if(x!=e.TRANSPARENT_TITLE&&(a.constructor.title_color||this.render_title_colored)){C=a.constructor.title_color||g;a.flags.collapsed&&(b.shadowColor=e.DEFAULT_SHADOW_COLOR);if(this.use_gradients){var w=h.gradients[C];w||(w=h.gradients[C]=b.createLinearGradient(0,0,400,0),w.addColorStop(0,C),w.addColorStop(1,"#000"));b.fillStyle=w}else b.fillStyle=C;b.beginPath();k==e.BOX_SHAPE||u?b.rect(0,-f,d[0]+1,f):(k==e.ROUND_SHAPE||k==e.CARD_SHAPE)&&b.roundRect(0,-f,d[0]+1,f,a.flags.collapsed?
|
||||
[this.round_radius]:[this.round_radius,this.round_radius,0,0]);b.fill();b.shadowColor="transparent"}C=!1;e.node_box_coloured_by_mode&&e.NODE_MODES_COLORS[a.mode]&&(C=e.NODE_MODES_COLORS[a.mode]);e.node_box_coloured_when_on&&(C=a.action_triggered?"#FFF":a.execute_triggered?"#AAA":C);if(a.onDrawTitleBox)a.onDrawTitleBox(b,f,d,this.ds.scale);else k==e.ROUND_SHAPE||k==e.CIRCLE_SHAPE||k==e.CARD_SHAPE?(u&&(b.fillStyle="black",b.beginPath(),b.arc(.5*f,-.5*f,6,0,2*Math.PI),b.fill()),b.fillStyle=a.boxcolor||
|
||||
C||e.NODE_DEFAULT_BOXCOLOR,u?b.fillRect(.5*f-5,-.5*f-5,10,10):(b.beginPath(),b.arc(.5*f,-.5*f,5,0,2*Math.PI),b.fill())):(u&&(b.fillStyle="black",b.fillRect(.5*(f-10)-1,-.5*(f+10)-1,12,12)),b.fillStyle=a.boxcolor||C||e.NODE_DEFAULT_BOXCOLOR,b.fillRect(.5*(f-10),-.5*(f+10),10,10));b.globalAlpha=c;if(a.onDrawTitleText)a.onDrawTitleText(b,f,d,this.ds.scale,this.title_text_font,m);!u&&(b.font=this.title_text_font,c=String(a.getTitle()))&&(b.fillStyle=m?e.NODE_SELECTED_TITLE_COLOR:a.constructor.title_text_color||
|
||||
this.node_title_color,a.flags.collapsed?(b.textAlign="left",b.measureText(c),b.fillText(c.substr(0,20),f,e.NODE_TITLE_TEXT_Y-f),b.textAlign="left"):(b.textAlign="left",b.fillText(c,f,e.NODE_TITLE_TEXT_Y-f)));a.flags.collapsed||!a.subgraph||a.skip_subgraph_button||(c=e.NODE_TITLE_HEIGHT,C=a.size[0]-c,w=e.isInsideRectangle(this.graph_mouse[0]-a.pos[0],this.graph_mouse[1]-a.pos[1],C+2,-c+2,c-4,c-4),b.fillStyle=w?"#888":"#555",k==e.BOX_SHAPE||u?b.fillRect(C+2,-c+2,c-4,c-4):(b.beginPath(),b.roundRect(C+
|
||||
2,-c+2,c-4,c-4,[4]),b.fill()),b.fillStyle="#333",b.beginPath(),b.moveTo(C+.2*c,.6*-c),b.lineTo(C+.8*c,.6*-c),b.lineTo(C+.5*c,.3*-c),b.fill());if(a.onDrawTitle)a.onDrawTitle(b)}if(m){if(a.onBounding)a.onBounding(z);x==e.TRANSPARENT_TITLE&&(z[1]-=f,z[3]+=f);b.lineWidth=1;b.globalAlpha=.8;b.beginPath();k==e.BOX_SHAPE?b.rect(-6+z[0],-6+z[1],12+z[2],12+z[3]):k==e.ROUND_SHAPE||k==e.CARD_SHAPE&&a.flags.collapsed?b.roundRect(-6+z[0],-6+z[1],12+z[2],12+z[3],[2*this.round_radius]):k==e.CARD_SHAPE?b.roundRect(-6+
|
||||
z[0],-6+z[1],12+z[2],12+z[3],[2*this.round_radius,2,2*this.round_radius,2]):k==e.CIRCLE_SHAPE&&b.arc(.5*d[0],.5*d[1],.5*d[0]+6,0,2*Math.PI);b.strokeStyle=e.NODE_BOX_OUTLINE_COLOR;b.stroke();b.strokeStyle=g;b.globalAlpha=1}0<a.execute_triggered&&a.execute_triggered--;0<a.action_triggered&&a.action_triggered--};var M=new Float32Array(4),k=new Float32Array(4),n=new Float32Array(2),q=new Float32Array(2);h.prototype.drawConnections=function(a){var b=e.getTime(),d=this.visible_area;M[0]=d[0]-20;M[1]=d[1]-
|
||||
20;M[2]=d[2]+40;M[3]=d[3]+40;a.lineWidth=this.connections_width;a.fillStyle="#AAA";a.strokeStyle="#AAA";a.globalAlpha=this.editor_alpha;d=this.graph._nodes;for(var g=0,f=d.length;g<f;++g){var c=d[g];if(c.inputs&&c.inputs.length)for(var u=0;u<c.inputs.length;++u){var h=c.inputs[u];if(h&&null!=h.link&&(h=this.graph.links[h.link])){var D=this.graph.getNodeById(h.origin_id);if(null!=D){var x=h.origin_slot;var C=-1==x?[D.pos[0]+10,D.pos[1]+10]:D.getConnectionPos(!1,x,n);var w=c.getConnectionPos(!0,u,q);
|
||||
k[0]=C[0];k[1]=C[1];k[2]=w[0]-C[0];k[3]=w[1]-C[1];0>k[2]&&(k[0]+=k[2],k[2]=Math.abs(k[2]));0>k[3]&&(k[1]+=k[3],k[3]=Math.abs(k[3]));if(I(k,M)){var L=D.outputs[x];x=c.inputs[u];if(L&&x&&(D=L.dir||(D.horizontal?e.DOWN:e.RIGHT),x=x.dir||(c.horizontal?e.UP:e.LEFT),this.renderLink(a,C,w,h,!1,0,null,D,x),h&&h._last_time&&1E3>b-h._last_time)){L=2-.002*(b-h._last_time);var G=a.globalAlpha;a.globalAlpha=G*L;this.renderLink(a,C,w,h,!0,L,"white",D,x);a.globalAlpha=G}}}}}}a.globalAlpha=1};h.prototype.renderLink=
|
||||
function(a,b,d,g,f,c,u,k,q,x){g&&this.visible_links.push(g);!u&&g&&(u=g.color||h.link_type_colors[g.type]);u||(u=this.default_link_color);null!=g&&this.highlighted_links[g.id]&&(u="#FFF");k=k||e.RIGHT;q=q||e.LEFT;var m=E(b,d);this.render_connections_border&&.6<this.ds.scale&&(a.lineWidth=this.connections_width+4);a.lineJoin="round";x=x||1;1<x&&(a.lineWidth=.5);a.beginPath();for(var w=0;w<x;w+=1){var L=5*(w-.5*(x-1));if(this.links_render_mode==e.SPLINE_LINK){a.moveTo(b[0],b[1]+L);var G=0,y=0,n=0,D=
|
||||
0;switch(k){case e.LEFT:G=-.25*m;break;case e.RIGHT:G=.25*m;break;case e.UP:y=-.25*m;break;case e.DOWN:y=.25*m}switch(q){case e.LEFT:n=-.25*m;break;case e.RIGHT:n=.25*m;break;case e.UP:D=-.25*m;break;case e.DOWN:D=.25*m}a.bezierCurveTo(b[0]+G,b[1]+y+L,d[0]+n,d[1]+D+L,d[0],d[1]+L)}else if(this.links_render_mode==e.LINEAR_LINK){a.moveTo(b[0],b[1]+L);D=n=y=G=0;switch(k){case e.LEFT:G=-1;break;case e.RIGHT:G=1;break;case e.UP:y=-1;break;case e.DOWN:y=1}switch(q){case e.LEFT:n=-1;break;case e.RIGHT:n=
|
||||
1;break;case e.UP:D=-1;break;case e.DOWN:D=1}a.lineTo(b[0]+15*G,b[1]+15*y+L);a.lineTo(d[0]+15*n,d[1]+15*D+L);a.lineTo(d[0],d[1]+L)}else if(this.links_render_mode==e.STRAIGHT_LINK)a.moveTo(b[0],b[1]),L=b[0],G=b[1],y=d[0],n=d[1],k==e.RIGHT?L+=10:G+=10,q==e.LEFT?y-=10:n-=10,a.lineTo(L,G),a.lineTo(.5*(L+y),G),a.lineTo(.5*(L+y),n),a.lineTo(y,n),a.lineTo(d[0],d[1]);else return}this.render_connections_border&&.6<this.ds.scale&&!f&&(a.strokeStyle="rgba(0,0,0,0.5)",a.stroke());a.lineWidth=this.connections_width;
|
||||
a.fillStyle=a.strokeStyle=u;a.stroke();f=this.computeConnectionPoint(b,d,.5,k,q);g&&g._pos&&(g._pos[0]=f[0],g._pos[1]=f[1]);.6<=this.ds.scale&&this.highquality_render&&q!=e.CENTER&&(this.render_connection_arrows&&(w=this.computeConnectionPoint(b,d,.25,k,q),m=this.computeConnectionPoint(b,d,.26,k,q),g=this.computeConnectionPoint(b,d,.75,k,q),x=this.computeConnectionPoint(b,d,.76,k,q),this.render_curved_connections?(m=-Math.atan2(m[0]-w[0],m[1]-w[1]),x=-Math.atan2(x[0]-g[0],x[1]-g[1])):x=m=d[1]>b[1]?
|
||||
0:Math.PI,a.save(),a.translate(w[0],w[1]),a.rotate(m),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore(),a.save(),a.translate(g[0],g[1]),a.rotate(x),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore()),a.beginPath(),a.arc(f[0],f[1],5,0,2*Math.PI),a.fill());if(c)for(a.fillStyle=u,w=0;5>w;++w)c=(.001*e.getTime()+.2*w)%1,f=this.computeConnectionPoint(b,d,c,k,q),a.beginPath(),a.arc(f[0],f[1],5,0,2*Math.PI),a.fill()};h.prototype.computeConnectionPoint=
|
||||
function(a,b,d,g,f){g=g||e.RIGHT;f=f||e.LEFT;var c=E(a,b),u=[a[0],a[1]],k=[b[0],b[1]];switch(g){case e.LEFT:u[0]+=-.25*c;break;case e.RIGHT:u[0]+=.25*c;break;case e.UP:u[1]+=-.25*c;break;case e.DOWN:u[1]+=.25*c}switch(f){case e.LEFT:k[0]+=-.25*c;break;case e.RIGHT:k[0]+=.25*c;break;case e.UP:k[1]+=-.25*c;break;case e.DOWN:k[1]+=.25*c}g=(1-d)*(1-d)*(1-d);f=3*(1-d)*(1-d)*d;c=3*(1-d)*d*d;d*=d*d;return[g*a[0]+f*u[0]+c*k[0]+d*b[0],g*a[1]+f*u[1]+c*k[1]+d*b[1]]};h.prototype.drawExecutionOrder=function(a){a.shadowColor=
|
||||
"transparent";a.globalAlpha=.25;a.textAlign="center";a.strokeStyle="white";a.globalAlpha=.75;for(var b=this.visible_nodes,d=0;d<b.length;++d){var g=b[d];a.fillStyle="black";a.fillRect(g.pos[0]-e.NODE_TITLE_HEIGHT,g.pos[1]-e.NODE_TITLE_HEIGHT,e.NODE_TITLE_HEIGHT,e.NODE_TITLE_HEIGHT);0==g.order&&a.strokeRect(g.pos[0]-e.NODE_TITLE_HEIGHT+.5,g.pos[1]-e.NODE_TITLE_HEIGHT+.5,e.NODE_TITLE_HEIGHT,e.NODE_TITLE_HEIGHT);a.fillStyle="#FFF";a.fillText(g.order,g.pos[0]+-.5*e.NODE_TITLE_HEIGHT,g.pos[1]-6)}a.globalAlpha=
|
||||
1};h.prototype.drawNodeWidgets=function(a,b,d,g){if(!a.widgets||!a.widgets.length)return 0;var f=a.size[0],c=a.widgets;b+=2;var u=e.NODE_WIDGET_HEIGHT,k=.5<this.ds.scale;d.save();d.globalAlpha=this.editor_alpha;for(var q=e.WIDGET_OUTLINE_COLOR,x=e.WIDGET_BGCOLOR,C=e.WIDGET_TEXT_COLOR,w=e.WIDGET_SECONDARY_TEXT_COLOR,L=0;L<c.length;++L){var G=c[L],y=b;G.y&&(y=G.y);G.last_y=y;d.strokeStyle=q;d.fillStyle="#222";d.textAlign="left";G.disabled&&(d.globalAlpha*=.5);var n=G.width||f;switch(G.type){case "button":G.clicked&&
|
||||
(d.fillStyle="#AAA",G.clicked=!1,this.dirty_canvas=!0);d.fillRect(15,y,n-30,u);k&&!G.disabled&&d.strokeRect(15,y,n-30,u);k&&(d.textAlign="center",d.fillStyle=C,d.fillText(G.name,.5*n,y+.7*u));break;case "toggle":d.textAlign="left";d.strokeStyle=q;d.fillStyle=x;d.beginPath();k?d.roundRect(15,y,n-30,u,[.5*u]):d.rect(15,y,n-30,u);d.fill();k&&!G.disabled&&d.stroke();d.fillStyle=G.value?"#89A":"#333";d.beginPath();d.arc(n-30,y+.5*u,.36*u,0,2*Math.PI);d.fill();k&&(d.fillStyle=w,null!=G.name&&d.fillText(G.name,
|
||||
30,y+.7*u),d.fillStyle=G.value?C:w,d.textAlign="right",d.fillText(G.value?G.options.on||"true":G.options.off||"false",n-40,y+.7*u));break;case "slider":d.fillStyle=x;d.fillRect(15,y,n-30,u);var D=G.options.max-G.options.min,h=(G.value-G.options.min)/D;d.fillStyle=g==G?"#89A":"#678";d.fillRect(15,y,h*(n-30),u);k&&!G.disabled&&d.strokeRect(15,y,n-30,u);G.marker&&(D=(G.marker-G.options.min)/D,d.fillStyle="#AA9",d.fillRect(15+D*(n-30),y,2,u));k&&(d.textAlign="center",d.fillStyle=C,d.fillText(G.name+" "+
|
||||
Number(G.value).toFixed(3),.5*n,y+.7*u));break;case "number":case "combo":d.textAlign="left";d.strokeStyle=q;d.fillStyle=x;d.beginPath();k?d.roundRect(15,y,n-30,u,[.5*u]):d.rect(15,y,n-30,u);d.fill();k&&(G.disabled||d.stroke(),d.fillStyle=C,G.disabled||(d.beginPath(),d.moveTo(31,y+5),d.lineTo(21,y+.5*u),d.lineTo(31,y+u-5),d.fill(),d.beginPath(),d.moveTo(n-15-16,y+5),d.lineTo(n-15-6,y+.5*u),d.lineTo(n-15-16,y+u-5),d.fill()),d.fillStyle=w,d.fillText(G.name,35,y+.7*u),d.fillStyle=C,d.textAlign="right",
|
||||
"number"==G.type?d.fillText(Number(G.value).toFixed(void 0!==G.options.precision?G.options.precision:3),n-30-20,y+.7*u):(D=G.value,G.options.values&&(h=G.options.values,h.constructor===Function&&(h=h()),h&&h.constructor!==Array&&(D=h[G.value])),d.fillText(D,n-30-20,y+.7*u)));break;case "string":case "text":d.textAlign="left";d.strokeStyle=q;d.fillStyle=x;d.beginPath();k?d.roundRect(15,y,n-30,u,[.5*u]):d.rect(15,y,n-30,u);d.fill();k&&(G.disabled||d.stroke(),d.save(),d.beginPath(),d.rect(15,y,n-30,
|
||||
u),d.clip(),d.fillStyle=w,null!=G.name&&d.fillText(G.name,30,y+.7*u),d.fillStyle=C,d.textAlign="right",d.fillText(String(G.value).substr(0,30),n-30,y+.7*u),d.restore());break;default:G.draw&&G.draw(d,a,n,y,u)}b+=(G.computeSize?G.computeSize(n)[1]:u)+4;d.globalAlpha=this.editor_alpha}d.restore();d.textAlign="left"};h.prototype.processNodeWidgets=function(a,b,d,g){function f(f,g){f.value=g;f.options&&f.options.property&&void 0!==a.properties[f.options.property]&&a.setProperty(f.options.property,g);
|
||||
f.callback&&f.callback(f.value,n,a,b,d)}if(!a.widgets||!a.widgets.length)return null;for(var c=b[0]-a.pos[0],k=b[1]-a.pos[1],q=a.size[0],n=this,x=this.getCanvasWindow(),C=0;C<a.widgets.length;++C){var w=a.widgets[C];if(w&&!w.disabled){var L=w.computeSize?w.computeSize(q)[1]:e.NODE_WIDGET_HEIGHT,G=w.width||q;if(w==g||!(6>c||c>G-12||k<w.last_y||k>w.last_y+L||void 0===w.last_y)){g=w.value;switch(w.type){case "button":d.type===e.pointerevents_method+"down"&&(w.callback&&setTimeout(function(){w.callback(w,
|
||||
n,a,b,d)},20),this.dirty_canvas=w.clicked=!0);break;case "slider":x=Math.clamp((c-15)/(G-30),0,1);w.value=w.options.min+(w.options.max-w.options.min)*x;w.callback&&setTimeout(function(){f(w,w.value)},20);this.dirty_canvas=!0;break;case "number":case "combo":g=w.value;if(d.type==e.pointerevents_method+"move"&&"number"==w.type)w.value+=.1*d.deltaX*(w.options.step||1),null!=w.options.min&&w.value<w.options.min&&(w.value=w.options.min),null!=w.options.max&&w.value>w.options.max&&(w.value=w.options.max);
|
||||
else if(d.type==e.pointerevents_method+"down"){var y=w.options.values;y&&y.constructor===Function&&(y=w.options.values(w,a));var D=null;"number"!=w.type&&(D=y.constructor===Array?y:Object.keys(y));c=40>c?-1:c>G-40?1:0;if("number"==w.type)w.value+=.1*c*(w.options.step||1),null!=w.options.min&&w.value<w.options.min&&(w.value=w.options.min),null!=w.options.max&&w.value>w.options.max&&(w.value=w.options.max);else if(c)x=-1,this.last_mouseclick=0,x=y.constructor===Object?D.indexOf(String(w.value))+c:D.indexOf(w.value)+
|
||||
c,x>=D.length&&(x=D.length-1),0>x&&(x=0),w.value=y.constructor===Array?y[x]:x;else{var h=y!=D?Object.values(y):y;new e.ContextMenu(h,{scale:Math.max(1,this.ds.scale),event:d,className:"dark",callback:function(a,b,d){y!=D&&(a=h.indexOf(a));this.value=a;f(this,a);n.dirty_canvas=!0;return!1}.bind(w)},x)}}else d.type==e.pointerevents_method+"up"&&"number"==w.type&&(c=40>c?-1:c>G-40?1:0,200>d.click_time&&0==c&&this.prompt("Value",w.value,function(a){this.value=Number(a);f(this,this.value)}.bind(w),d));
|
||||
g!=w.value&&setTimeout(function(){f(this,this.value)}.bind(w),20);this.dirty_canvas=!0;break;case "toggle":d.type==e.pointerevents_method+"down"&&(w.value=!w.value,setTimeout(function(){f(w,w.value)},20));break;case "string":case "text":d.type==e.pointerevents_method+"down"&&this.prompt("Value",w.value,function(a){this.value=a;f(this,a)}.bind(w),d,w.options?w.options.multiline:!1);break;default:w.mouse&&(this.dirty_canvas=w.mouse(d,[c,k],a))}if(g!=w.value){if(a.onWidgetChanged)a.onWidgetChanged(w.name,
|
||||
w.value,g,w);a.graph._version++}return w}}}return null};h.prototype.drawGroups=function(a,b){if(this.graph){a=this.graph._groups;b.save();b.globalAlpha=.5*this.editor_alpha;for(var d=0;d<a.length;++d){var g=a[d];if(I(this.visible_area,g._bounding)){b.fillStyle=g.color||"#335";b.strokeStyle=g.color||"#335";var f=g._pos,c=g._size;b.globalAlpha=.25*this.editor_alpha;b.beginPath();b.rect(f[0]+.5,f[1]+.5,c[0],c[1]);b.fill();b.globalAlpha=this.editor_alpha;b.stroke();b.beginPath();b.moveTo(f[0]+c[0],f[1]+
|
||||
c[1]);b.lineTo(f[0]+c[0]-10,f[1]+c[1]);b.lineTo(f[0]+c[0],f[1]+c[1]-10);b.fill();c=g.font_size||e.DEFAULT_GROUP_FONT_SIZE;b.font=c+"px Arial";b.textAlign="left";b.fillText(g.title,f[0]+4,f[1]+c)}}b.restore()}};h.prototype.adjustNodesSize=function(){for(var a=this.graph._nodes,b=0;b<a.length;++b)a[b].size=a[b].computeSize();this.setDirty(!0,!0)};h.prototype.resize=function(a,b){a||b||(b=this.canvas.parentNode,a=b.offsetWidth,b=b.offsetHeight);if(this.canvas.width!=a||this.canvas.height!=b)this.canvas.width=
|
||||
a,this.canvas.height=b,this.bgcanvas.width=this.canvas.width,this.bgcanvas.height=this.canvas.height,this.setDirty(!0,!0)};h.prototype.switchLiveMode=function(a){if(a){var b=this,d=this.live_mode?1.1:.9;this.live_mode&&(this.live_mode=!1,this.editor_alpha=.1);var g=setInterval(function(){b.editor_alpha*=d;b.dirty_canvas=!0;b.dirty_bgcanvas=!0;1>d&&.01>b.editor_alpha&&(clearInterval(g),1>d&&(b.live_mode=!0));1<d&&.99<b.editor_alpha&&(clearInterval(g),b.editor_alpha=1)},1)}else this.live_mode=!this.live_mode,
|
||||
this.dirty_bgcanvas=this.dirty_canvas=!0};h.prototype.onNodeSelectionChange=function(a){};h.onGroupAdd=function(a,b,d){a=h.active_canvas;a.getCanvasWindow();b=new e.LGraphGroup;b.pos=a.convertEventToCanvasOffset(d);a.graph.add(b)};h.onMenuAdd=function(a,b,d,g,f){function c(a,b){var g=[];e.getNodeTypesCategories(k.filter||n.filter).filter(function(b){return b.startsWith(a)}).map(function(b){if(b){b=b.replace(new RegExp("^("+a+")"),"").split("/")[0];var d=""===a?b+"/":a+b+"/";-1!=b.indexOf("::")&&(b=
|
||||
b.split("::")[1]);-1===g.findIndex(function(a){return a.value===d})&&g.push({value:d,content:b,has_submenu:!0,callback:function(a,b,d,f){c(a.value,f)}})}});e.getNodeTypesInCategory(a.slice(0,-1),k.filter||n.filter).map(function(a){a.skip_list||g.push({value:a.type,content:a.title,has_submenu:!1,callback:function(a,b,d,g){b=g.getFirstEvent();k.graph.beforeChange();if(a=e.createNode(a.value))a.pos=k.convertEventToCanvasOffset(b),k.graph.add(a);f&&f(a);k.graph.afterChange()}})});new e.ContextMenu(g,
|
||||
{event:d,parentMenu:b},q)}var k=h.active_canvas,q=k.getCanvasWindow(),n=k.graph;if(n)return c("",g),!1};h.onMenuCollapseAll=function(){};h.onMenuNodeEdit=function(){};h.showMenuNodeOptionalInputs=function(a,b,d,g,f){if(f){var c=this;a=h.active_canvas.getCanvasWindow();b=f.optional_inputs;f.onGetInputs&&(b=f.onGetInputs());var k=[];if(b)for(var n=0;n<b.length;n++){var q=b[n];if(q){var x=q[0];q[2]||(q[2]={});q[2].label&&(x=q[2].label);q[2].removable=!0;x={content:x,value:q};q[1]==e.ACTION&&(x.className=
|
||||
"event");k.push(x)}else k.push(null)}f.onMenuNodeInputs&&(b=f.onMenuNodeInputs(k))&&(k=b);if(k.length)return new e.ContextMenu(k,{event:d,callback:function(a,b,d){if(f&&(a.callback&&a.callback.call(c,f,a,b,d),a.value)){f.graph.beforeChange();f.addInput(a.value[0],a.value[1],a.value[2]);if(f.onNodeInputAdd)f.onNodeInputAdd(a.value);f.setDirtyCanvas(!0,!0);f.graph.afterChange()}},parentMenu:g,node:f},a),!1;console.log("no input entries")}};h.showMenuNodeOptionalOutputs=function(a,b,d,g,f){function c(a,
|
||||
b,d){if(f&&(a.callback&&a.callback.call(k,f,a,b,d),a.value))if(d=a.value[1],!d||d.constructor!==Object&&d.constructor!==Array){f.graph.beforeChange();f.addOutput(a.value[0],a.value[1],a.value[2]);if(f.onNodeOutputAdd)f.onNodeOutputAdd(a.value);f.setDirtyCanvas(!0,!0);f.graph.afterChange()}else{a=[];for(var m in d)a.push({content:m,value:d[m]});new e.ContextMenu(a,{event:b,callback:c,parentMenu:g,node:f});return!1}}if(f){var k=this;a=h.active_canvas.getCanvasWindow();b=f.optional_outputs;f.onGetOutputs&&
|
||||
(b=f.onGetOutputs());var q=[];if(b)for(var n=0;n<b.length;n++){var x=b[n];if(!x)q.push(null);else if(!f.flags||!f.flags.skip_repeated_outputs||-1==f.findOutputSlot(x[0])){var C=x[0];x[2]||(x[2]={});x[2].label&&(C=x[2].label);x[2].removable=!0;C={content:C,value:x};x[1]==e.EVENT&&(C.className="event");q.push(C)}}this.onMenuNodeOutputs&&(q=this.onMenuNodeOutputs(q));e.do_add_triggers_slots&&-1==f.findOutputSlot("onExecuted")&&q.push({content:"On Executed",value:["onExecuted",e.EVENT,{nameLocked:!0}],
|
||||
className:"event"});f.onMenuNodeOutputs&&(b=f.onMenuNodeOutputs(q))&&(q=b);if(q.length)return new e.ContextMenu(q,{event:d,callback:c,parentMenu:g,node:f},a),!1}};h.onShowMenuNodeProperties=function(a,b,d,g,f){if(f&&f.properties){var c=h.active_canvas;b=c.getCanvasWindow();var k=[],q;for(q in f.properties){a=void 0!==f.properties[q]?f.properties[q]:" ";"object"==typeof a&&(a=JSON.stringify(a));var n=f.getPropertyInfo(q);if("enum"==n.type||"combo"==n.type)a=h.getPropertyPrintableValue(a,n.values);
|
||||
a=h.decodeHTML(a);k.push({content:"<span class='property_name'>"+(n.label?n.label:q)+"</span><span class='property_value'>"+a+"</span>",value:q})}if(k.length)return new e.ContextMenu(k,{event:d,callback:function(a,b,d,g){f&&(b=this.getBoundingClientRect(),c.showEditPropertyValue(f,a.value,{position:[b.left,b.top]}))},parentMenu:g,allow_html:!0,node:f},b),!1}};h.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};h.onMenuResizeNode=function(a,b,d,g,f){if(f){a=
|
||||
function(a){a.size=a.computeSize();if(a.onResize)a.onResize(a.size)};b=h.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)a(f);else for(var e in b.selected_nodes)a(b.selected_nodes[e]);f.setDirtyCanvas(!0,!0)}};h.prototype.showLinkMenu=function(a,b){var d=this,g=d.graph.getNodeById(a.origin_id),f=d.graph.getNodeById(a.target_id),c=!1;g&&g.outputs&&g.outputs[a.origin_slot]&&(c=g.outputs[a.origin_slot].type);var k=!1;f&&f.outputs&&f.outputs[a.target_slot]&&(k=f.inputs[a.target_slot].type);
|
||||
var q=new e.ContextMenu(["Add Node",null,"Delete",null],{event:b,title:null!=a.data?a.data.constructor.name:null,callback:function(b,e,m){switch(b){case "Add Node":h.onMenuAdd(null,null,m,q,function(b){b.inputs&&b.inputs.length&&b.outputs&&b.outputs.length&&g.connectByType(a.origin_slot,b,c)&&(b.connectByType(a.target_slot,f,k),b.pos[0]-=.5*b.size[0])});break;case "Delete":d.graph.removeLink(a.id)}}});return!1};h.prototype.createDefaultNodeForSlot=function(a){a=a||{};a=Object.assign({nodeFrom:null,
|
||||
slotFrom:null,nodeTo:null,slotTo:null,position:[],nodeType:null,posAdd:[0,0],posSizeFix:[0,0]},a);var b=a.nodeFrom&&null!==a.slotFrom,d=!b&&a.nodeTo&&null!==a.slotTo;if(!b&&!d)return console.warn("No data passed to createDefaultNodeForSlot "+a.nodeFrom+" "+a.slotFrom+" "+a.nodeTo+" "+a.slotTo),!1;if(!a.nodeType)return console.warn("No type to createDefaultNodeForSlot"),!1;var g=b?a.nodeFrom:a.nodeTo,f=b?a.slotFrom:a.slotTo;switch(typeof f){case "string":d=b?g.findOutputSlot(f,!1):g.findInputSlot(f,
|
||||
!1);f=b?g.outputs[f]:g.inputs[f];break;case "object":d=b?g.findOutputSlot(f.name):g.findInputSlot(f.name);break;case "number":d=f;f=b?g.outputs[f]:g.inputs[f];break;default:return console.warn("Cant get slot information "+f),!1}!1!==f&&!1!==d||console.warn("createDefaultNodeForSlot bad slotX "+f+" "+d);g=f.type==e.EVENT?"_event_":f.type;if((f=b?e.slot_types_default_out:e.slot_types_default_in)&&f[g]){nodeNewType=!1;if("object"==typeof f[g]||"array"==typeof f[g])for(var c in f[g]){if(a.nodeType==f[g][c]||
|
||||
"AUTO"==a.nodeType){nodeNewType=f[g][c];break}}else if(a.nodeType==f[g]||"AUTO"==a.nodeType)nodeNewType=f[g];if(nodeNewType){c=!1;"object"==typeof nodeNewType&&nodeNewType.node&&(c=nodeNewType,nodeNewType=nodeNewType.node);if(f=e.createNode(nodeNewType)){if(c){if(c.properties)for(var k in c.properties)f.addProperty(k,c.properties[k]);if(c.inputs)for(k in f.inputs=[],c.inputs)f.addOutput(c.inputs[k][0],c.inputs[k][1]);if(c.outputs)for(k in f.outputs=[],c.outputs)f.addOutput(c.outputs[k][0],c.outputs[k][1]);
|
||||
c.title&&(f.title=c.title);c.json&&f.configure(c.json)}this.graph.add(f);f.pos=[a.position[0]+a.posAdd[0]+(a.posSizeFix[0]?a.posSizeFix[0]*f.size[0]:0),a.position[1]+a.posAdd[1]+(a.posSizeFix[1]?a.posSizeFix[1]*f.size[1]:0)];b?a.nodeFrom.connectByType(d,f,g):a.nodeTo.connectByTypeOutput(d,f,g);return!0}console.log("failed creating "+nodeNewType)}}return!1};h.prototype.showConnectionMenu=function(a){a=a||{};var b=Object.assign({nodeFrom:null,slotFrom:null,nodeTo:null,slotTo:null,e:null},a),d=this,
|
||||
g=b.nodeFrom&&b.slotFrom;a=!g&&b.nodeTo&&b.slotTo;if(!g&&!a)return console.warn("No data passed to showConnectionMenu"),!1;a=g?b.nodeFrom:b.nodeTo;var f=g?b.slotFrom:b.slotTo,c=!1;switch(typeof f){case "string":c=g?a.findOutputSlot(f,!1):a.findInputSlot(f,!1);f=g?a.outputs[f]:a.inputs[f];break;case "object":c=g?a.findOutputSlot(f.name):a.findInputSlot(f.name);break;case "number":c=f;f=g?a.outputs[f]:a.inputs[f];break;default:return console.warn("Cant get slot information "+f),!1}a=["Add Node",null];
|
||||
d.allow_searchbox&&(a.push("Search"),a.push(null));var k=f.type==e.EVENT?"_event_":f.type,q=g?e.slot_types_default_out:e.slot_types_default_in;if(q&&q[k])if("object"==typeof q[k]||"array"==typeof q[k])for(var n in q[k])a.push(q[k][n]);else a.push(q[k]);var x=new e.ContextMenu(a,{event:b.e,title:(f&&""!=f.name?f.name+(k?" | ":""):"")+(f&&k?k:""),callback:function(a,e,m){switch(a){case "Add Node":h.onMenuAdd(null,null,m,x,function(a){g?b.nodeFrom.connectByType(c,a,k):b.nodeTo.connectByTypeOutput(c,
|
||||
a,k)});break;case "Search":g?d.showSearchBox(m,{node_from:b.nodeFrom,slot_from:f,type_filter_in:k}):d.showSearchBox(m,{node_to:b.nodeTo,slot_from:f,type_filter_out:k});break;default:d.createDefaultNodeForSlot(Object.assign(b,{position:[b.e.canvasX,b.e.canvasY],nodeType:a}))}}});return!1};h.onShowPropertyEditor=function(a,b,d,g,f){function c(){if(n){var b=n.value;"Number"==a.type?b=Number(b):"Boolean"==a.type&&(b=!!b);f[k]=b;q.parentNode&&q.parentNode.removeChild(q);f.setDirtyCanvas(!0,!0)}}var k=
|
||||
a.property||"title";b=f[k];var q=document.createElement("div");q.is_modified=!1;q.className="graphdialog";q.innerHTML="<span class='name'></span><input autofocus type='text' class='value'/><button>OK</button>";q.close=function(){q.parentNode&&q.parentNode.removeChild(q)};q.querySelector(".name").innerText=k;var n=q.querySelector(".value");n&&(n.value=b,n.addEventListener("blur",function(a){this.focus()}),n.addEventListener("keydown",function(a){q.is_modified=!0;if(27==a.keyCode)q.close();else if(13==
|
||||
a.keyCode)c();else if(13!=a.keyCode&&"textarea"!=a.target.localName)return;a.preventDefault();a.stopPropagation()}));b=h.active_canvas.canvas;d=b.getBoundingClientRect();var x=g=-20;d&&(g-=d.left,x-=d.top);event?(q.style.left=event.clientX+g+"px",q.style.top=event.clientY+x+"px"):(q.style.left=.5*b.width+g+"px",q.style.top=.5*b.height+x+"px");q.querySelector("button").addEventListener("click",c);b.parentNode.appendChild(q);n&&n.focus();var C=null;q.addEventListener("mouseleave",function(a){e.dialog_close_on_mouse_leave&&
|
||||
!q.is_modified&&e.dialog_close_on_mouse_leave&&(C=setTimeout(q.close,e.dialog_close_on_mouse_leave_delay))});q.addEventListener("mouseenter",function(a){e.dialog_close_on_mouse_leave&&C&&clearTimeout(C)})};h.prototype.prompt=function(a,b,d,g,f){var c=this;a=a||"";var k=document.createElement("div");k.is_modified=!1;k.className="graphdialog rounded";k.innerHTML=f?"<span class='name'></span> <textarea autofocus class='value'></textarea><button class='rounded'>OK</button>":"<span class='name'></span> <input autofocus type='text' class='value'/><button class='rounded'>OK</button>";
|
||||
k.close=function(){c.prompt_box=null;k.parentNode&&k.parentNode.removeChild(k)};f=h.active_canvas.canvas;f.parentNode.appendChild(k);1<this.ds.scale&&(k.style.transform="scale("+this.ds.scale+")");var q=null,n=!1;e.pointerListenerAdd(k,"leave",function(a){n||e.dialog_close_on_mouse_leave&&!k.is_modified&&e.dialog_close_on_mouse_leave&&(q=setTimeout(k.close,e.dialog_close_on_mouse_leave_delay))});e.pointerListenerAdd(k,"enter",function(a){e.dialog_close_on_mouse_leave&&q&&clearTimeout(q)});var x=k.querySelectorAll("select");
|
||||
x&&x.forEach(function(a){a.addEventListener("click",function(a){n++});a.addEventListener("blur",function(a){n=0});a.addEventListener("change",function(a){n=-1})});c.prompt_box&&c.prompt_box.close();c.prompt_box=k;k.querySelector(".name").innerText=a;var C=k.querySelector(".value");C.value=b;C.addEventListener("keydown",function(a){k.is_modified=!0;if(27==a.keyCode)k.close();else if(13==a.keyCode&&"textarea"!=a.target.localName)d&&d(this.value),k.close();else return;a.preventDefault();a.stopPropagation()});
|
||||
k.querySelector("button").addEventListener("click",function(a){d&&d(C.value);c.setDirty(!0);k.close()});a=f.getBoundingClientRect();x=b=-20;a&&(b-=a.left,x-=a.top);g?(k.style.left=g.clientX+b+"px",k.style.top=g.clientY+x+"px"):(k.style.left=.5*f.width+b+"px",k.style.top=.5*f.height+x+"px");setTimeout(function(){C.focus()},10);return k};h.search_limit=-1;h.prototype.showSearchBox=function(a,b){function d(d){if(d)if(c.onSearchBoxSelection)c.onSearchBoxSelection(d,a,k);else{var f=e.searchbox_extras[d.toLowerCase()];
|
||||
f&&(d=f.type);k.graph.beforeChange();if(d=e.createNode(d))d.pos=k.convertEventToCanvasOffset(a),k.graph.add(d,!1);if(f&&f.data){if(f.data.properties)for(var g in f.data.properties)d.addProperty(g,f.data.properties[g]);if(f.data.inputs)for(g in d.inputs=[],f.data.inputs)d.addOutput(f.data.inputs[g][0],f.data.inputs[g][1]);if(f.data.outputs)for(g in d.outputs=[],f.data.outputs)d.addOutput(f.data.outputs[g][0],f.data.outputs[g][1]);f.data.title&&(d.title=f.data.title);f.data.json&&d.configure(f.data.json)}if(b.node_from){switch(typeof b.slot_from){case "string":f=
|
||||
b.node_from.findOutputSlot(b.slot_from);break;case "object":f=b.slot_from.name?b.node_from.findOutputSlot(b.slot_from.name):-1;-1==f&&"undefined"!==typeof b.slot_from.slot_index&&(f=b.slot_from.slot_index);break;case "number":f=b.slot_from;break;default:f=0}!1!==f&&-1<f&&b.node_from.connectByType(f,d,b.node_from.outputs[f].type)}if(b.node_to){switch(typeof b.slot_from){case "string":f=b.node_to.findInputSlot(b.slot_from);break;case "object":f=b.slot_from.name?b.node_to.findInputSlot(b.slot_from.name):
|
||||
-1;-1==f&&"undefined"!==typeof b.slot_from.slot_index&&(f=b.slot_from.slot_index);break;case "number":f=b.slot_from;break;default:f=0}!1!==f&&-1<f&&b.node_to.connectByTypeOutput(f,d,b.node_to.inputs[f].type)}k.graph.afterChange()}x.close()}function g(a){var b=t;t&&t.classList.remove("selected");t?(t=a?t.nextSibling:t.previousSibling)||(t=b):t=a?y.childNodes[0]:y.childNodes[y.childNodes.length];t&&(t.classList.add("selected"),t.scrollIntoView({block:"end",behavior:"smooth"}))}function f(){function a(a,
|
||||
b){var f=document.createElement("div");l||(l=a);f.innerText=a;f.dataset.type=escape(a);f.className="litegraph lite-search-item";b&&(f.className+=" "+b);f.addEventListener("click",function(a){d(unescape(this.dataset.type))});y.appendChild(f)}r=null;var f=H.value;l=null;y.innerHTML="";if(f||b.show_all_if_empty)if(c.onSearchBox){var g=c.onSearchBox(y,f,k);if(g)for(var m=0;m<g.length;++m)a(g[m])}else{g=function(a,d){d=d||{};d=Object.assign({skipFilter:!1,inTypeOverride:!1,outTypeOverride:!1},d);var g=
|
||||
e.registered_node_types[a];if(q&&g.filter!=q||(!b.show_all_if_empty||f)&&-1===a.toLowerCase().indexOf(f))return!1;if(b.do_type_filter&&!d.skipFilter){g=n.value;!1!==d.inTypeOverride&&(g=d.inTypeOverride);if(n&&g&&e.registered_slot_in_types[g]&&e.registered_slot_in_types[g].nodes&&(g=e.registered_slot_in_types[g].nodes.includes(a),!1===g))return!1;g=G.value;!1!==d.outTypeOverride&&(g=d.outTypeOverride);if(G&&g&&e.registered_slot_out_types[g]&&e.registered_slot_out_types[g].nodes&&(g=e.registered_slot_out_types[g].nodes.includes(a),
|
||||
!1===g))return!1}return!0};var x=0;f=f.toLowerCase();var q=k.filter||k.graph.filter;if(b.do_type_filter&&c.search_box)var n=c.search_box.querySelector(".slot_in_type_filter"),G=c.search_box.querySelector(".slot_out_type_filter");else G=n=!1;for(m in e.searchbox_extras){var u=e.searchbox_extras[m];if(b.show_all_if_empty&&!f||-1!==u.desc.toLowerCase().indexOf(f)){var C=e.registered_node_types[u.type];if((!C||C.filter==q)&&g(u.type)&&(a(u.desc,"searchbox_extra"),-1!==h.search_limit&&x++>h.search_limit))break}}u=
|
||||
null;if(Array.prototype.filter)u=Object.keys(e.registered_node_types).filter(g);else for(m in u=[],e.registered_node_types)g(m)&&u.push(m);for(m=0;m<u.length&&!(a(u[m]),-1!==h.search_limit&&x++>h.search_limit);m++);if(b.show_general_after_typefiltered&&(n.value||G.value)){filtered_extra=[];for(m in e.registered_node_types)g(m,{inTypeOverride:n&&n.value?"*":!1,outTypeOverride:G&&G.value?"*":!1})&&filtered_extra.push(m);for(m=0;m<filtered_extra.length&&!(a(filtered_extra[m],"generic_type"),-1!==h.search_limit&&
|
||||
x++>h.search_limit);m++);}if((n.value||G.value)&&0==y.childNodes.length&&b.show_general_if_none_on_typefilter){filtered_extra=[];for(m in e.registered_node_types)g(m,{skipFilter:!0})&&filtered_extra.push(m);for(m=0;m<filtered_extra.length&&!(a(filtered_extra[m],"not_in_filter"),-1!==h.search_limit&&x++>h.search_limit);m++);}}}def_options={slot_from:null,node_from:null,node_to:null,do_type_filter:e.search_filter_enabled,type_filter_in:!1,type_filter_out:!1,show_general_if_none_on_typefilter:!0,show_general_after_typefiltered:!0,
|
||||
hide_on_mouse_leave:e.search_hide_on_mouse_leave,show_all_if_empty:!0,show_all_on_open:e.search_show_all_on_open};b=Object.assign(def_options,b||{});var c=this,k=h.active_canvas,q=k.canvas,n=q.ownerDocument||document,x=document.createElement("div");x.className="litegraph litesearchbox graphdialog rounded";x.innerHTML="<span class='name'>Search</span> <input autofocus type='text' class='value rounded'/>";b.do_type_filter&&(x.innerHTML+="<select class='slot_in_type_filter'><option value=''></option></select>",
|
||||
x.innerHTML+="<select class='slot_out_type_filter'><option value=''></option></select>");x.innerHTML+="<div class='helper'></div>";n.fullscreenElement?n.fullscreenElement.appendChild(x):(n.body.appendChild(x),n.body.style.overflow="hidden");if(b.do_type_filter)var C=x.querySelector(".slot_in_type_filter"),D=x.querySelector(".slot_out_type_filter");x.close=function(){c.search_box=null;n.body.focus();n.body.style.overflow="";setTimeout(function(){c.canvas.focus()},20);x.parentNode&&x.parentNode.removeChild(x)};
|
||||
1<this.ds.scale&&(x.style.transform="scale("+this.ds.scale+")");if(b.hide_on_mouse_leave){var L=!1,G=null;e.pointerListenerAdd(x,"enter",function(a){G&&(clearTimeout(G),G=null)});e.pointerListenerAdd(x,"leave",function(a){L||(G=setTimeout(function(){x.close()},500))});b.do_type_filter&&(C.addEventListener("click",function(a){L++}),C.addEventListener("blur",function(a){L=0}),C.addEventListener("change",function(a){L=-1}),D.addEventListener("click",function(a){L++}),D.addEventListener("blur",function(a){L=
|
||||
0}),D.addEventListener("change",function(a){L=-1}))}c.search_box&&c.search_box.close();c.search_box=x;var y=x.querySelector(".helper"),l=null,r=null,t=null,H=x.querySelector("input");H&&(H.addEventListener("blur",function(a){this.focus()}),H.addEventListener("keydown",function(a){if(38==a.keyCode)g(!1);else if(40==a.keyCode)g(!0);else if(27==a.keyCode)x.close();else if(13==a.keyCode)t?d(t.innerHTML):l?d(l):x.close();else{r&&clearInterval(r);r=setTimeout(f,250);return}a.preventDefault();a.stopPropagation();
|
||||
a.stopImmediatePropagation();return!0}));if(b.do_type_filter){if(C){var z=e.slot_types_in,v=z.length;if(b.type_filter_in==e.EVENT||b.type_filter_in==e.ACTION)b.type_filter_in="_event_";for(var M=0;M<v;M++){var A=document.createElement("option");A.value=z[M];A.innerHTML=z[M];C.appendChild(A);!1!==b.type_filter_in&&(b.type_filter_in+"").toLowerCase()==(z[M]+"").toLowerCase()&&(A.selected=!0)}C.addEventListener("change",function(){f()})}if(D){z=e.slot_types_out;v=z.length;if(b.type_filter_out==e.EVENT||
|
||||
b.type_filter_out==e.ACTION)b.type_filter_out="_event_";for(M=0;M<v;M++)A=document.createElement("option"),A.value=z[M],A.innerHTML=z[M],D.appendChild(A),!1!==b.type_filter_out&&(b.type_filter_out+"").toLowerCase()==(z[M]+"").toLowerCase()&&(A.selected=!0);D.addEventListener("change",function(){f()})}}q=q.getBoundingClientRect();C=(a?a.clientY:q.top+.5*q.height)-20;x.style.left=(a?a.clientX:q.left+.5*q.width)-80+"px";x.style.top=C+"px";a.layerY>q.height-200&&(y.style.maxHeight=q.height-a.layerY-20+
|
||||
"px");H.focus();b.show_all_on_open&&f();return x};h.prototype.showEditPropertyValue=function(a,b,d){function g(){f(D.value)}function f(f){e&&e.values&&e.values.constructor===Object&&void 0!=e.values[f]&&(f=e.values[f]);"number"==typeof a.properties[b]&&(f=Number(f));if("array"==c||"object"==c)f=JSON.parse(f);a.properties[b]=f;a.graph&&a.graph._version++;if(a.onPropertyChanged)a.onPropertyChanged(b,f);if(d.onclose)d.onclose();n.close();a.setDirtyCanvas(!0,!0)}if(a&&void 0!==a.properties[b]){d=d||{};
|
||||
var e=a.getPropertyInfo(b),c=e.type,k="";if("string"==c||"number"==c||"array"==c||"object"==c)k="<input autofocus type='text' class='value'/>";else if("enum"!=c&&"combo"!=c||!e.values)if("boolean"==c||"toggle"==c)k="<input autofocus type='checkbox' class='value' "+(a.properties[b]?"checked":"")+"/>";else{console.warn("unknown type: "+c);return}else{k="<select autofocus type='text' class='value'>";for(var q in e.values){var x=q;e.values.constructor===Array&&(x=e.values[q]);k+="<option value='"+x+"' "+
|
||||
(x==a.properties[b]?"selected":"")+">"+e.values[q]+"</option>"}k+="</select>"}var n=this.createDialog("<span class='name'>"+(e.label?e.label:b)+"</span>"+k+"<button>OK</button>",d),D=!1;if("enum"!=c&&"combo"!=c||!e.values)if("boolean"==c||"toggle"==c)(D=n.querySelector("input"))&&D.addEventListener("click",function(a){n.modified();f(!!D.checked)});else{if(D=n.querySelector("input"))D.addEventListener("blur",function(a){this.focus()}),x=void 0!==a.properties[b]?a.properties[b]:"","string"!==c&&(x=
|
||||
JSON.stringify(x)),D.value=x,D.addEventListener("keydown",function(a){if(27==a.keyCode)n.close();else if(13==a.keyCode)g();else if(13!=a.keyCode){n.modified();return}a.preventDefault();a.stopPropagation()})}else D=n.querySelector("select"),D.addEventListener("change",function(a){n.modified();f(a.target.value)});D&&D.focus();n.querySelector("button").addEventListener("click",g);return n}};h.prototype.createDialog=function(a,b){def_options={checkForInput:!1,closeOnLeave:!0,closeOnLeave_checkModified:!0};
|
||||
b=Object.assign(def_options,b||{});var d=document.createElement("div");d.className="graphdialog";d.innerHTML=a;d.is_modified=!1;a=this.canvas.getBoundingClientRect();var g=-20,f=-20;a&&(g-=a.left,f-=a.top);b.position?(g+=b.position[0],f+=b.position[1]):b.event?(g+=b.event.clientX,f+=b.event.clientY):(g+=.5*this.canvas.width,f+=.5*this.canvas.height);d.style.left=g+"px";d.style.top=f+"px";this.canvas.parentNode.appendChild(d);b.checkForInput&&(a=[],(a=d.querySelectorAll("input"))&&a.forEach(function(a){a.addEventListener("keydown",
|
||||
function(a){d.modified();if(27==a.keyCode)d.close();else if(13!=a.keyCode)return;a.preventDefault();a.stopPropagation()});a.focus()}));d.modified=function(){d.is_modified=!0};d.close=function(){d.parentNode&&d.parentNode.removeChild(d)};var c=null,k=!1;d.addEventListener("mouseleave",function(a){k||(b.closeOnLeave||e.dialog_close_on_mouse_leave)&&!d.is_modified&&e.dialog_close_on_mouse_leave&&(c=setTimeout(d.close,e.dialog_close_on_mouse_leave_delay))});d.addEventListener("mouseenter",function(a){(b.closeOnLeave||
|
||||
e.dialog_close_on_mouse_leave)&&c&&clearTimeout(c)});(a=d.querySelectorAll("select"))&&a.forEach(function(a){a.addEventListener("click",function(a){k++});a.addEventListener("blur",function(a){k=0});a.addEventListener("change",function(a){k=-1})});return d};h.prototype.createPanel=function(a,b){b=b||{};var d=b.window||window,g=document.createElement("div");g.className="litegraph dialog";g.innerHTML="<div class='dialog-header'><span class='dialog-title'></span></div><div class='dialog-content'></div><div style='display:none;' class='dialog-alt-content'></div><div class='dialog-footer'></div>";
|
||||
g.header=g.querySelector(".dialog-header");b.width&&(g.style.width=b.width+(b.width.constructor===Number?"px":""));b.height&&(g.style.height=b.height+(b.height.constructor===Number?"px":""));b.closable&&(b=document.createElement("span"),b.innerHTML="✕",b.classList.add("close"),b.addEventListener("click",function(){g.close()}),g.header.appendChild(b));g.title_element=g.querySelector(".dialog-title");g.title_element.innerText=a;g.content=g.querySelector(".dialog-content");g.alt_content=g.querySelector(".dialog-alt-content");
|
||||
g.footer=g.querySelector(".dialog-footer");g.close=function(){if(g.onClose&&"function"==typeof g.onClose)g.onClose();g.parentNode.removeChild(g);this.parentNode&&this.parentNode.removeChild(this)};g.toggleAltContent=function(a){if("undefined"!=typeof a){var b=a?"block":"none";a=a?"none":"block"}else b="block"!=g.alt_content.style.display?"block":"none",a="block"!=g.alt_content.style.display?"none":"block";g.alt_content.style.display=b;g.content.style.display=a};g.toggleFooterVisibility=function(a){g.footer.style.display=
|
||||
"undefined"!=typeof a?a?"block":"none":"block"!=g.footer.style.display?"block":"none"};g.clear=function(){this.content.innerHTML=""};g.addHTML=function(a,b,d){var f=document.createElement("div");b&&(f.className=b);f.innerHTML=a;d?g.footer.appendChild(f):g.content.appendChild(f);return f};g.addButton=function(a,b,d){var f=document.createElement("button");f.innerText=a;f.options=d;f.classList.add("btn");f.addEventListener("click",b);g.footer.appendChild(f);return f};g.addSeparator=function(){var a=
|
||||
document.createElement("div");a.className="separator";g.content.appendChild(a)};g.addWidget=function(a,b,c,k,q){function f(a,b){k.callback&&k.callback(a,b,k);q&&q(a,b,k)}k=k||{};var m=String(c);a=a.toLowerCase();"number"==a&&(m=c.toFixed(3));var n=document.createElement("div");n.className="property";n.innerHTML="<span class='property_name'></span><span class='property_value'></span>";n.querySelector(".property_name").innerText=k.label||b;var u=n.querySelector(".property_value");u.innerText=m;n.dataset.property=
|
||||
b;n.dataset.type=k.type||a;n.options=k;n.value=c;if("code"==a)n.addEventListener("click",function(a){g.inner_showCodePad(this.dataset.property)});else if("boolean"==a)n.classList.add("boolean"),c&&n.classList.add("bool-on"),n.addEventListener("click",function(){var a=this.dataset.property;this.value=!this.value;this.classList.toggle("bool-on");this.querySelector(".property_value").innerText=this.value?"true":"false";f(a,this.value)});else if("string"==a||"number"==a)u.setAttribute("contenteditable",
|
||||
!0),u.addEventListener("keydown",function(b){"Enter"!=b.code||"string"==a&&b.shiftKey||(b.preventDefault(),this.blur())}),u.addEventListener("blur",function(){var a=this.innerText,b=this.parentNode.dataset.property;"number"==this.parentNode.dataset.type&&(a=Number(a));f(b,a)});else if("enum"==a||"combo"==a)m=h.getPropertyPrintableValue(c,k.values),u.innerText=m,u.addEventListener("click",function(a){var b=this.parentNode.dataset.property,g=this;new e.ContextMenu(k.values||[],{event:a,className:"dark",
|
||||
callback:function(a,d,e){g.innerText=a;f(b,a);return!1}},d)});g.content.appendChild(n);return n};if(g.onOpen&&"function"==typeof g.onOpen)g.onOpen();return g};h.getPropertyPrintableValue=function(a,b){if(!b||b.constructor===Array)return String(a);if(b.constructor===Object){var d="",g;for(g in b)if(b[g]==a){d=g;break}return String(a)+" ("+d+")"}};h.prototype.closePanels=function(){var a=document.querySelector("#node-panel");a&&a.close();(a=document.querySelector("#option-panel"))&&a.close()};h.prototype.showShowGraphOptionsPanel=
|
||||
function(a,b,d,g){if(this.constructor&&"HTMLDivElement"==this.constructor.name){if(!(b&&b.event&&b.event.target&&b.event.target.lgraphcanvas)){console.warn("Canvas not found");return}var f=b.event.target.lgraphcanvas}else f=this;f.closePanels();a=f.getCanvasWindow();panel=f.createPanel("Options",{closable:!0,window:a,onOpen:function(){f.OPTIONPANEL_IS_OPEN=!0},onClose:function(){f.OPTIONPANEL_IS_OPEN=!1;f.options_panel=null}});f.options_panel=panel;panel.id="option-panel";panel.classList.add("settings");
|
||||
(function(){panel.content.innerHTML="";var a=function(a,b,d){d&&d.key&&(a=d.key);d.values&&(b=Object.values(d.values).indexOf(b));f[a]=b},b=e.availableCanvasOptions;b.sort();for(pI in b){var d=b[pI];panel.addWidget("boolean",d,f[d],{key:d,on:"True",off:"False"},a)}panel.addWidget("combo","Render mode",e.LINK_RENDER_MODES[f.links_render_mode],{key:"links_render_mode",values:e.LINK_RENDER_MODES},a);panel.addSeparator();panel.footer.innerHTML=""})();f.canvas.parentNode.appendChild(panel)};h.prototype.showShowNodePanel=
|
||||
function(a){function b(){panel.content.innerHTML="";panel.addHTML("<span class='node_type'>"+a.type+"</span><span class='node_desc'>"+(a.constructor.desc||"")+"</span><span class='separator'></span>");panel.addHTML("<h3>Properties</h3>");var b=function(b,d){g.graph.beforeChange(a);switch(b){case "Title":a.title=d;break;case "Mode":b=Object.values(e.NODE_MODES).indexOf(d);0<=b&&e.NODE_MODES[b]?a.changeMode(b):console.warn("unexpected mode: "+d);break;case "Color":h.node_colors[d]?(a.color=h.node_colors[d].color,
|
||||
a.bgcolor=h.node_colors[d].bgcolor):console.warn("unexpected color: "+d);break;default:a.setProperty(b,d)}g.graph.afterChange();g.dirty_canvas=!0};panel.addWidget("string","Title",a.title,{},b);panel.addWidget("combo","Mode",e.NODE_MODES[a.mode],{values:e.NODE_MODES},b);var d="";void 0!==a.color&&(d=Object.keys(h.node_colors).filter(function(b){return h.node_colors[b].color==a.color}));panel.addWidget("combo","Color",d,{values:Object.keys(h.node_colors)},b);for(var c in a.properties){d=a.properties[c];
|
||||
var k=a.getPropertyInfo(c);a.onAddPropertyToPanel&&a.onAddPropertyToPanel(c,panel)||panel.addWidget(k.widget||k.type,c,d,k,b)}panel.addSeparator();if(a.onShowCustomPanelInfo)a.onShowCustomPanelInfo(panel);panel.footer.innerHTML="";panel.addButton("Delete",function(){a.block_delete||(a.graph.remove(a),panel.close())}).classList.add("delete")}this.SELECTED_NODE=a;this.closePanels();var d=this.getCanvasWindow(),g=this;panel=this.createPanel(a.title||"",{closable:!0,window:d,onOpen:function(){g.NODEPANEL_IS_OPEN=
|
||||
!0},onClose:function(){g.NODEPANEL_IS_OPEN=!1;g.node_panel=null}});g.node_panel=panel;panel.id="node-panel";panel.node=a;panel.classList.add("settings");panel.inner_showCodePad=function(d){panel.classList.remove("settings");panel.classList.add("centered");panel.alt_content.innerHTML="<textarea class='code'></textarea>";var f=panel.alt_content.querySelector("textarea"),g=function(){panel.toggleAltContent(!1);panel.toggleFooterVisibility(!0);f.parentNode.removeChild(f);panel.classList.add("settings");
|
||||
panel.classList.remove("centered");b()};f.value=a.properties[d];f.addEventListener("keydown",function(b){"Enter"==b.code&&b.ctrlKey&&(a.setProperty(d,f.value),g())});panel.toggleAltContent(!0);panel.toggleFooterVisibility(!1);f.style.height="calc(100% - 40px)";var e=panel.addButton("Assign",function(){a.setProperty(d,f.value);g()});panel.alt_content.appendChild(e);e=panel.addButton("Close",g);e.style.float="right";panel.alt_content.appendChild(e)};b();this.canvas.parentNode.appendChild(panel)};h.prototype.showSubgraphPropertiesDialog=
|
||||
function(a){function b(){g.clear();if(a.inputs)for(var d=0;d<a.inputs.length;++d){var e=a.inputs[d];if(!e.not_subgraph_input){var c=g.addHTML("<button>✕</button> <span class='bullet_icon'></span><span class='name'></span><span class='type'></span>","subgraph_property");c.dataset.name=e.name;c.dataset.slot=d;c.querySelector(".name").innerText=e.name;c.querySelector(".type").innerText=e.type;c.querySelector("button").addEventListener("click",function(d){a.removeInput(Number(this.parentNode.dataset.slot));
|
||||
b()})}}}console.log("showing subgraph properties dialog");var d=this.canvas.parentNode.querySelector(".subgraph_dialog");d&&d.close();var g=this.createPanel("Subgraph Inputs",{closable:!0,width:500});g.node=a;g.classList.add("subgraph_dialog");g.addHTML(" + <span class='label'>Name</span><input class='name'/><span class='label'>Type</span><input class='type'></input><button>+</button>","subgraph_property extra",!0).querySelector("button").addEventListener("click",function(d){d=this.parentNode;var f=
|
||||
d.querySelector(".name").value,g=d.querySelector(".type").value;f&&-1==a.findInputSlot(f)&&(a.addInput(f,g),d.querySelector(".name").value="",d.querySelector(".type").value="",b())});b();this.canvas.parentNode.appendChild(g);return g};h.prototype.showSubgraphPropertiesDialogRight=function(a){function b(){f.clear();if(a.outputs)for(var d=0;d<a.outputs.length;++d){var g=a.outputs[d];if(!g.not_subgraph_output){var e=f.addHTML("<button>✕</button> <span class='bullet_icon'></span><span class='name'></span><span class='type'></span>",
|
||||
"subgraph_property");e.dataset.name=g.name;e.dataset.slot=d;e.querySelector(".name").innerText=g.name;e.querySelector(".type").innerText=g.type;e.querySelector("button").addEventListener("click",function(d){a.removeOutput(Number(this.parentNode.dataset.slot));b()})}}}function d(){var d=this.parentNode,f=d.querySelector(".name").value,g=d.querySelector(".type").value;f&&-1==a.findOutputSlot(f)&&(a.addOutput(f,g),d.querySelector(".name").value="",d.querySelector(".type").value="",b())}var g=this.canvas.parentNode.querySelector(".subgraph_dialog");
|
||||
g&&g.close();var f=this.createPanel("Subgraph Outputs",{closable:!0,width:500});f.node=a;f.classList.add("subgraph_dialog");g=f.addHTML(" + <span class='label'>Name</span><input class='name'/><span class='label'>Type</span><input class='type'></input><button>+</button>","subgraph_property extra",!0);g.querySelector(".name").addEventListener("keydown",function(a){13==a.keyCode&&d.apply(this)});g.querySelector("button").addEventListener("click",function(a){d.apply(this)});b();this.canvas.parentNode.appendChild(f);
|
||||
return f};h.prototype.checkPanels=function(){if(this.canvas)for(var a=this.canvas.parentNode.querySelectorAll(".litegraph.dialog"),b=0;b<a.length;++b){var d=a[b];d.node&&(d.node.graph&&d.graph==this.graph||d.close())}};h.onMenuNodeCollapse=function(a,b,d,g,f){f.graph.beforeChange();a=h.active_canvas;if(!a.selected_nodes||1>=Object.keys(a.selected_nodes).length)f.collapse();else for(var e in a.selected_nodes)a.selected_nodes[e].collapse();f.graph.afterChange()};h.onMenuNodePin=function(a,b,d,g,f){f.pin()};
|
||||
h.onMenuNodeMode=function(a,b,d,g,f){new e.ContextMenu(e.NODE_MODES,{event:d,callback:function(a){if(f){var b=Object.values(e.NODE_MODES).indexOf(a),d=function(d){0<=b&&e.NODE_MODES[b]?d.changeMode(b):(console.warn("unexpected mode: "+a),d.changeMode(e.ALWAYS))},g=h.active_canvas;if(!g.selected_nodes||1>=Object.keys(g.selected_nodes).length)d(f);else for(var c in g.selected_nodes)d(g.selected_nodes[c])}},parentMenu:g,node:f});return!1};h.onMenuNodeColors=function(a,b,d,g,f){if(!f)throw"no node for color";
|
||||
b=[];b.push({value:null,content:"<span style='display: block; padding-left: 4px;'>No color</span>"});for(var c in h.node_colors)a=h.node_colors[c],a={value:c,content:"<span style='display: block; color: #999; padding-left: 4px; border-left: 8px solid "+a.color+"; background-color:"+a.bgcolor+"'>"+c+"</span>"},b.push(a);new e.ContextMenu(b,{event:d,callback:function(a){if(f){var b=a.value?h.node_colors[a.value]:null;a=function(a){b?a.constructor===e.LGraphGroup?a.color=b.groupcolor:(a.color=b.color,
|
||||
a.bgcolor=b.bgcolor):(delete a.color,delete a.bgcolor)};var d=h.active_canvas;if(!d.selected_nodes||1>=Object.keys(d.selected_nodes).length)a(f);else for(var g in d.selected_nodes)a(d.selected_nodes[g]);f.setDirtyCanvas(!0,!0)}},parentMenu:g,node:f});return!1};h.onMenuNodeShapes=function(a,b,d,g,f){if(!f)throw"no node passed";new e.ContextMenu(e.VALID_SHAPES,{event:d,callback:function(a){if(f){f.graph.beforeChange();var b=h.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)f.shape=
|
||||
a;else for(var d in b.selected_nodes)b.selected_nodes[d].shape=a;f.graph.afterChange();f.setDirtyCanvas(!0)}},parentMenu:g,node:f});return!1};h.onMenuNodeRemove=function(a,b,d,g,f){if(!f)throw"no node passed";a=f.graph;a.beforeChange();b=h.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)!1!==f.removable&&a.remove(f);else for(var e in b.selected_nodes)d=b.selected_nodes[e],!1!==d.removable&&a.remove(d);a.afterChange();f.setDirtyCanvas(!0,!0)};h.onMenuNodeToSubgraph=function(a,
|
||||
b,d,g,f){a=f.graph;if(b=h.active_canvas)d=Object.values(b.selected_nodes||{}),d.length||(d=[f]),g=e.createNode("graph/subgraph"),g.pos=f.pos.concat(),a.add(g),g.buildFromNodes(d),b.deselectAllNodes(),f.setDirtyCanvas(!0,!0)};h.onMenuNodeClone=function(a,b,d,g,f){f.graph.beforeChange();var e={};a=function(a){if(0!=a.clonable){var b=a.clone();b&&(b.pos=[a.pos[0]+5,a.pos[1]+5],a.graph.add(b),e[b.id]=b)}};b=h.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)a(f);else for(var c in b.selected_nodes)a(b.selected_nodes[c]);
|
||||
Object.keys(e).length&&b.selectNodes(e);f.graph.afterChange();f.setDirtyCanvas(!0,!0)};h.node_colors={red:{color:"#322",bgcolor:"#533",groupcolor:"#A88"},brown:{color:"#332922",bgcolor:"#593930",groupcolor:"#b06634"},green:{color:"#232",bgcolor:"#353",groupcolor:"#8A8"},blue:{color:"#223",bgcolor:"#335",groupcolor:"#88A"},pale_blue:{color:"#2a363b",bgcolor:"#3f5159",groupcolor:"#3f789e"},cyan:{color:"#233",bgcolor:"#355",groupcolor:"#8AA"},purple:{color:"#323",bgcolor:"#535",groupcolor:"#a1309b"},
|
||||
yellow:{color:"#432",bgcolor:"#653",groupcolor:"#b58b2a"},black:{color:"#222",bgcolor:"#000",groupcolor:"#444"}};h.prototype.getCanvasMenuOptions=function(){if(this.getMenuOptions)var a=this.getMenuOptions();else a=[{content:"Add Node",has_submenu:!0,callback:h.onMenuAdd},{content:"Add Group",callback:h.onGroupAdd}],this._graph_stack&&0<this._graph_stack.length&&a.push(null,{content:"Close subgraph",callback:this.closeSubgraph.bind(this)});if(this.getExtraMenuOptions){var b=this.getExtraMenuOptions(this,
|
||||
a);b&&(a=a.concat(b))}return a};h.prototype.getNodeMenuOptions=function(a){if(a.getMenuOptions)var b=a.getMenuOptions(this);else b=[{content:"Inputs",has_submenu:!0,disabled:!0,callback:h.showMenuNodeOptionalInputs},{content:"Outputs",has_submenu:!0,disabled:!0,callback:h.showMenuNodeOptionalOutputs},null,{content:"Properties",has_submenu:!0,callback:h.onShowMenuNodeProperties},null,{content:"Title",callback:h.onShowPropertyEditor},{content:"Mode",has_submenu:!0,callback:h.onMenuNodeMode}],!1!==a.resizable&&
|
||||
b.push({content:"Resize",callback:h.onMenuResizeNode}),b.push({content:"Collapse",callback:h.onMenuNodeCollapse},{content:"Pin",callback:h.onMenuNodePin},{content:"Colors",has_submenu:!0,callback:h.onMenuNodeColors},{content:"Shapes",has_submenu:!0,callback:h.onMenuNodeShapes},null);if(a.onGetInputs){var 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,b))&&(d.push(null),b=d.concat(b));
|
||||
!1!==a.clonable&&b.push({content:"Clone",callback:h.onMenuNodeClone});b.push(null,{content:"Remove",disabled:!(!1!==a.removable&&!a.block_delete),callback:h.onMenuNodeRemove});if(a.graph&&a.graph.onGetNodeMenuOptions)a.graph.onGetNodeMenuOptions(b,a);return b};h.prototype.getGroupMenuOptions=function(a){return[{content:"Title",callback:h.onShowPropertyEditor},{content:"Color",has_submenu:!0,callback:h.onMenuNodeColors},{content:"Font size",property:"font_size",type:"Number",callback:h.onShowPropertyEditor},
|
||||
null,{content:"Remove",callback:h.onMenuNodeRemove}]};h.prototype.processContextMenu=function(a,b){var d=this,g=h.active_canvas.getCanvasWindow(),f=null,c={event:b,callback:function(b,f,g){if(b)if("Remove Slot"==b.content)b=b.slot,a.graph.beforeChange(),b.input?a.removeInput(b.slot):b.output&&a.removeOutput(b.slot),a.graph.afterChange();else if("Disconnect Links"==b.content)b=b.slot,a.graph.beforeChange(),b.output?a.disconnectOutput(b.slot):b.input&&a.disconnectInput(b.slot),a.graph.afterChange();
|
||||
else if("Rename Slot"==b.content){b=b.slot;var e=b.input?a.getInputInfo(b.slot):a.getOutputInfo(b.slot),c=d.createDialog("<span class='name'>Name</span><input autofocus type='text'/><button>OK</button>",f),k=c.querySelector("input");k&&e&&(k.value=e.label||"");var m=function(){a.graph.beforeChange();k.value&&(e&&(e.label=k.value),d.setDirty(!0));c.close();a.graph.afterChange()};c.querySelector("button").addEventListener("click",m);k.addEventListener("keydown",function(a){c.is_modified=!0;if(27==a.keyCode)c.close();
|
||||
else if(13==a.keyCode)m();else if(13!=a.keyCode&&"textarea"!=a.target.localName)return;a.preventDefault();a.stopPropagation()});k.focus()}},extra:a};a&&(c.title=a.type);var k=null;a&&(k=a.getSlotInPosition(b.canvasX,b.canvasY),h.active_node=a);k?(f=[],a.getSlotMenuOptions?f=a.getSlotMenuOptions(k):(k&&k.output&&k.output.links&&k.output.links.length&&f.push({content:"Disconnect Links",slot:k}),b=k.input||k.output,b.removable&&f.push(b.locked?"Cannot remove":{content:"Remove Slot",slot:k}),b.nameLocked||
|
||||
f.push({content:"Rename Slot",slot:k})),c.title=(k.input?k.input.type:k.output.type)||"*",k.input&&k.input.type==e.ACTION&&(c.title="Action"),k.output&&k.output.type==e.EVENT&&(c.title="Event")):a?f=this.getNodeMenuOptions(a):(f=this.getCanvasMenuOptions(),(k=this.graph.getGroupOnPos(b.canvasX,b.canvasY))&&f.push(null,{content:"Edit Group",has_submenu:!0,submenu:{title:"Group",extra:k,options:this.getGroupMenuOptions(k)}}));f&&new e.ContextMenu(f,c,g)};"undefined"!=typeof window&&window.CanvasRenderingContext2D&&
|
||||
!window.CanvasRenderingContext2D.prototype.roundRect&&(window.CanvasRenderingContext2D.prototype.roundRect=function(a,b,d,g,f,e){var c,k;if(0===f)this.rect(a,b,d,g);else{void 0===e&&(e=f);if(null!=f&&f.constructor===Array)if(1==f.length)var m=c=k=e=f[0];else if(2==f.length)m=e=f[0],c=k=f[1];else if(4==f.length)m=f[0],c=f[1],k=f[2],e=f[3];else return;else m=f||0,c=f||0,k=e||0,e=e||0;this.moveTo(a+m,b);this.lineTo(a+d-c,b);this.quadraticCurveTo(a+d,b,a+d,b+c);this.lineTo(a+d,b+g-e);this.quadraticCurveTo(a+
|
||||
d,b+g,a+d-e,b+g);this.lineTo(a+e,b+g);this.quadraticCurveTo(a,b+g,a,b+g-k);this.lineTo(a,b+k);this.quadraticCurveTo(a,b,a+m,b)}});e.compareObjects=function(a,b){for(var d in a)if(a[d]!=b[d])return!1;return!0};e.distance=E;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=A;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=I;e.hex2num=function(a){"#"==a.charAt(0)&&(a=a.slice(1));a=a.toUpperCase();for(var b=Array(3),d=0,g,f,e=0;6>e;e+=2)g="0123456789ABCDEF".indexOf(a.charAt(e)),f="0123456789ABCDEF".indexOf(a.charAt(e+1)),b[d]=16*g+f,d++;return b};e.num2hex=function(a){for(var b="#",d,g,f=0;3>f;f++)d=a[f]/16,g=a[f]%16,b+="0123456789ABCDEF".charAt(d)+"0123456789ABCDEF".charAt(g);
|
||||
return b};J.prototype.addItem=function(a,b,d){function g(a){var b=this.value;b&&b.has_submenu&&f.call(this,a)}function f(a){var b=this.value,f=!0;c.current_submenu&&c.current_submenu.close(a);if(d.callback){var g=d.callback.call(this,b,d,a,c,d.node);!0===g&&(f=!1)}if(b&&(b.callback&&!d.ignore_item_callbacks&&!0!==b.disabled&&(g=b.callback.call(this,b,d,a,c,d.extra),!0===g&&(f=!1)),b.submenu)){if(!b.submenu.options)throw"ContextMenu submenu needs options";new c.constructor(b.submenu.options,{callback:b.submenu.callback,
|
||||
event:a,parentMenu:c,ignore_item_callbacks:b.submenu.ignore_item_callbacks,title:b.submenu.title,extra:b.submenu.extra,autoopen:d.autoopen});f=!1}f&&!c.lock&&c.close()}var c=this;d=d||{};var k=document.createElement("div");k.className="litemenu-entry submenu";var q=!1;if(null===b)k.classList.add("separator");else{k.innerHTML=b&&b.title?b.title:a;if(k.value=b)b.disabled&&(q=!0,k.classList.add("disabled")),(b.submenu||b.has_submenu)&&k.classList.add("has_submenu");"function"==typeof b?(k.dataset.value=
|
||||
a,k.onclick_callback=b):k.dataset.value=b;b.className&&(k.className+=" "+b.className)}this.root.appendChild(k);q||k.addEventListener("click",f);d.autoopen&&e.pointerListenerAdd(k,"enter",g);return k};J.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&&!J.isCursorOverElement(a,this.parentMenu.root)&&J.trigger(this.parentMenu.root,e.pointerevents_method+
|
||||
"leave",a));this.current_submenu&&this.current_submenu.close(a,!0);this.root.closing_timer&&clearTimeout(this.root.closing_timer)};J.trigger=function(a,b,d,g){var f=document.createEvent("CustomEvent");f.initCustomEvent(b,!0,!0,d);f.srcElement=g;a.dispatchEvent?a.dispatchEvent(f):a.__events&&a.__events.dispatchEvent(f);return f};J.prototype.getTopMenu=function(){return this.options.parentMenu?this.options.parentMenu.getTopMenu():this};J.prototype.getFirstEvent=function(){return this.options.parentMenu?
|
||||
this.options.parentMenu.getFirstEvent():this.options.event};J.isCursorOverElement=function(a,b){var d=a.clientX;a=a.clientY;return(b=b.getBoundingClientRect())?a>b.top&&a<b.top+b.height&&d>b.left&&d<b.left+b.width?!0:!1:!1};e.ContextMenu=J;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=0;d<b.length;d++)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)))};F.sampleCurve=function(a,b){if(b){for(var d=0;d<b.length-1;++d){var g=b[d],f=b[d+1];if(!(f[0]<a)){b=f[0]-g[0];if(1E-5>
|
||||
Math.abs(b))return g[1];a=(a-g[0])/b;return g[1]*(1-a)+f[1]*a}}return 0}};F.prototype.draw=function(a,b,d,g,f,e){if(d=this.points){this.size=b;var c=b[0]-2*this.margin;b=b[1]-2*this.margin;f=f||"#666";a.save();a.translate(this.margin,this.margin);g&&(a.fillStyle="#111",a.fillRect(0,0,c,b),a.fillStyle="#222",a.fillRect(.5*c,0,1,b),a.strokeStyle="#333",a.strokeRect(0,0,c,b));a.strokeStyle=f;e&&(a.globalAlpha=.5);a.beginPath();for(g=0;g<d.length;++g)f=d[g],a.lineTo(f[0]*c,(1-f[1])*b);a.stroke();a.globalAlpha=
|
||||
1;if(!e)for(g=0;g<d.length;++g)f=d[g],a.fillStyle=this.selected==g?"#FFF":this.nearest==g?"#DDD":"#AAA",a.beginPath(),a.arc(f[0]*c,(1-f[1])*b,2,0,2*Math.PI),a.fill();a.restore()}};F.prototype.onMouseDown=function(a,b){var d=this.points;if(d&&!(0>a[1])){var g=this.size[0]-2*this.margin,f=this.size[1]-2*this.margin,e=a[0]-this.margin;a=a[1]-this.margin;this.selected=this.getCloserPoint([e,a],30/b.ds.scale);-1==this.selected&&(b=[e/g,1-a/f],d.push(b),d.sort(function(a,b){return a[0]-b[0]}),this.selected=
|
||||
d.indexOf(b),this.must_update=!0);if(-1!=this.selected)return!0}};F.prototype.onMouseMove=function(a,b){var d=this.points;if(d){var g=this.selected;if(!(0>g)){var f=(a[0]-this.margin)/(this.size[0]-2*this.margin),e=(a[1]-this.margin)/(this.size[1]-2*this.margin);this._nearest=this.getCloserPoint([a[0]-this.margin,a[1]-this.margin],30/b.ds.scale);if(b=d[g]){var c=0==g||g==d.length-1;!c&&(-10>a[0]||a[0]>this.size[0]+10||-10>a[1]||a[1]>this.size[1]+10)?(d.splice(g,1),this.selected=-1):(b[0]=c?0==g?0:
|
||||
1:Math.clamp(f,0,1),b[1]=1-Math.clamp(e,0,1),d.sort(function(a,b){return a[0]-b[0]}),this.selected=d.indexOf(b),this.must_update=!0)}}}};F.prototype.onMouseUp=function(a,b){this.selected=-1;return!1};F.prototype.getCloserPoint=function(a,b){var d=this.points;if(!d)return-1;b=b||30;for(var g=this.size[0]-2*this.margin,f=this.size[1]-2*this.margin,e=d.length,c=[0,0],k=1E6,q=-1,x=0;x<e;++x){var n=d[x];c[0]=n[0]*g;c[1]=(1-n[1])*f;n=vec2.distance(a,c);n>k||n>b||(q=x,k=n)}return q};e.CurveEditor=F;e.getParameterNames=
|
||||
function(a){return(a+"").replace(/[/][/].*$/gm,"").replace(/\s+/g,"").replace(/[/][*][^/*]*[*][/]/g,"").split("){",1)[0].replace(/^[^(]*[(]/,"").replace(/=[^,]+/g,"").split(",").filter(Boolean)};e.pointerListenerAdd=function(a,b,d,g){g=void 0===g?!1:g;if(a&&a.addEventListener&&b&&"function"===typeof d){var f=e.pointerevents_method;if("pointer"==f&&!window.PointerEvent)switch(console.warn("sMethod=='pointer' && !window.PointerEvent"),console.log("Converting pointer["+b+"] : down move up cancel enter TO touchstart touchmove touchend, etc .."),
|
||||
b){case "down":f="touch";b="start";break;case "move":f="touch";break;case "up":f="touch";b="end";break;case "cancel":f="touch";break;case "enter":console.log("debug: Should I send a move event?");break;default:console.warn("PointerEvent not available in this browser ? The event "+b+" would not be called")}switch(b){case "down":case "up":case "move":case "over":case "out":case "enter":a.addEventListener(f+b,d,g);case "leave":case "cancel":case "gotpointercapture":case "lostpointercapture":if("mouse"!=
|
||||
f)return a.addEventListener(f+b,d,g);default:return a.addEventListener(b,d,g)}}};e.pointerListenerRemove=function(a,b,d,g){g=void 0===g?!1:g;if(a&&a.removeEventListener&&b&&"function"===typeof d)switch(b){case "down":case "up":case "move":case "over":case "out":case "enter":"pointer"!=e.pointerevents_method&&"mouse"!=e.pointerevents_method||a.removeEventListener(e.pointerevents_method+b,d,g);case "leave":case "cancel":case "gotpointercapture":case "lostpointercapture":if("pointer"==e.pointerevents_method)return a.removeEventListener(e.pointerevents_method+
|
||||
b,d,g);default:return a.removeEventListener(b,d,g)}};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);
|
||||
-a.pos[1]-.5*a.size[1]+.5*this.canvas.height/this.ds.scale;this.setDirty(!0,!0)};h.prototype.adjustMouseEvent=function(a){if(this.canvas){var b=this.canvas.getBoundingClientRect();var d=a.clientX-b.left;b=a.clientY-b.top}else d=a.clientX,b=a.clientY;a.deltaX=d-this.last_mouse_position[0];a.deltaY=b-this.last_mouse_position[1];this.last_mouse_position[0]=d;this.last_mouse_position[1]=b;a.canvasX=d/this.ds.scale-this.ds.offset[0];a.canvasY=b/this.ds.scale-this.ds.offset[1]};h.prototype.setZoom=function(a,
|
||||
b){this.ds.changeScale(a,b);this.dirty_bgcanvas=this.dirty_canvas=!0};h.prototype.convertOffsetToCanvas=function(a,b){return this.ds.convertOffsetToCanvas(a,b)};h.prototype.convertCanvasToOffset=function(a,b){return this.ds.convertCanvasToOffset(a,b)};h.prototype.convertEventToCanvasOffset=function(a){var b=this.canvas.getBoundingClientRect();return this.convertCanvasToOffset([a.clientX-b.left,a.clientY-b.top])};h.prototype.bringToFront=function(a){var b=this.graph._nodes.indexOf(a);-1!=b&&(this.graph._nodes.splice(b,
|
||||
1),this.graph._nodes.push(a))};h.prototype.sendToBack=function(a){var b=this.graph._nodes.indexOf(a);-1!=b&&(this.graph._nodes.splice(b,1),this.graph._nodes.unshift(a))};var D=new Float32Array(4);h.prototype.computeVisibleNodes=function(a,b){b=b||[];b.length=0;a=a||this.graph._nodes;for(var d=0,g=a.length;d<g;++d){var f=a[d];(!this.live_mode||f.onDrawBackground||f.onDrawForeground)&&I(this.visible_area,f.getBounding(D))&&b.push(f)}return b};h.prototype.draw=function(a,b){if(this.canvas&&0!=this.canvas.width&&
|
||||
0!=this.canvas.height){var d=e.getTime();this.render_time=.001*(d-this.last_draw_time);this.last_draw_time=d;this.graph&&this.ds.computeVisibleArea(this.viewport);(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}};h.prototype.drawFrontCanvas=function(){this.dirty_canvas=!1;this.ctx||
|
||||
(this.ctx=this.bgcanvas.getContext("2d"));var a=this.ctx;if(a){var b=this.canvas;a.start2D&&!this.viewport&&(a.start2D(),a.restore(),a.setTransform(1,0,0,1,0,0));var d=this.viewport||this.dirty_area;d&&(a.save(),a.beginPath(),a.rect(d[0],d[1],d[2],d[3]),a.clip());this.clear_background&&(d?a.clearRect(d[0],d[1],d[2],d[3]):a.clearRect(0,0,b.width,b.height));this.bgcanvas==this.canvas?this.drawBackCanvas():a.drawImage(this.bgcanvas,0,0);if(this.onRender)this.onRender(b,a);this.show_info&&this.renderInfo(a,
|
||||
d?d[0]:0,d?d[1]:0);if(this.graph){a.save();this.ds.toCanvasContext(a);b=this.computeVisibleNodes(null,this.visible_nodes);for(var g=0;g<b.length;++g){var f=b[g];a.save();a.translate(f.pos[0],f.pos[1]);this.drawNode(f,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;f=this.connecting_output||this.connecting_input;b=f.type;g=f.dir;null==g&&(g=
|
||||
this.connecting_output?this.connecting_node.horizontal?e.DOWN:e.RIGHT:this.connecting_node.horizontal?e.UP:e.LEFT);var m=f.shape;switch(b){case e.EVENT:f=e.EVENT_LINK_COLOR;break;default:f=e.CONNECTING_LINK_COLOR}this.renderLink(a,this.connecting_pos,[this.graph_mouse[0],this.graph_mouse[1]],null,!1,null,f,g,e.CENTER);a.beginPath();b===e.EVENT||m===e.BOX_SHAPE?(a.rect(this.connecting_pos[0]-6+.5,this.connecting_pos[1]-5+.5,14,10),a.fill(),a.beginPath(),a.rect(this.graph_mouse[0]-6+.5,this.graph_mouse[1]-
|
||||
5+.5,14,10)):m===e.ARROW_SHAPE?(a.moveTo(this.connecting_pos[0]+8,this.connecting_pos[1]+.5),a.lineTo(this.connecting_pos[0]-4,this.connecting_pos[1]+6+.5),a.lineTo(this.connecting_pos[0]-4,this.connecting_pos[1]-6+.5),a.closePath()):(a.arc(this.connecting_pos[0],this.connecting_pos[1],4,0,2*Math.PI),a.fill(),a.beginPath(),a.arc(this.graph_mouse[0],this.graph_mouse[1],4,0,2*Math.PI));a.fill();a.fillStyle="#ffcc00";if(this._highlight_input){a.beginPath();var c=this._highlight_input_slot.shape;c===
|
||||
e.ARROW_SHAPE?(a.moveTo(this._highlight_input[0]+8,this._highlight_input[1]+.5),a.lineTo(this._highlight_input[0]-4,this._highlight_input[1]+6+.5),a.lineTo(this._highlight_input[0]-4,this._highlight_input[1]-6+.5),a.closePath()):a.arc(this._highlight_input[0],this._highlight_input[1],6,0,2*Math.PI);a.fill()}this._highlight_output&&(a.beginPath(),c===e.ARROW_SHAPE?(a.moveTo(this._highlight_output[0]+8,this._highlight_output[1]+.5),a.lineTo(this._highlight_output[0]-4,this._highlight_output[1]+6+.5),
|
||||
a.lineTo(this._highlight_output[0]-4,this._highlight_output[1]-6+.5),a.closePath()):a.arc(this._highlight_output[0],this._highlight_output[1],6,0,2*Math.PI),a.fill())}this.dragging_rectangle&&(a.strokeStyle="#FFF",a.strokeRect(this.dragging_rectangle[0],this.dragging_rectangle[1],this.dragging_rectangle[2],this.dragging_rectangle[3]));if(this.over_link_center&&this.render_link_tooltip)this.drawLinkTooltip(a,this.over_link_center);else if(this.onDrawLinkTooltip)this.onDrawLinkTooltip(a,null);if(this.onDrawForeground)this.onDrawForeground(a,
|
||||
this.visible_rect);a.restore()}this._graph_stack&&this._graph_stack.length&&this.drawSubgraphPanel(a);if(this.onDrawOverlay)this.onDrawOverlay(a);d&&a.restore();a.finish2D&&a.finish2D()}};h.prototype.drawSubgraphPanel=function(a){var b=this.graph,d=b._subgraph_node;d?(this.drawSubgraphPanelLeft(b,d,a),this.drawSubgraphPanelRight(b,d,a)):console.warn("subgraph without subnode")};h.prototype.drawSubgraphPanelLeft=function(a,b,d){var g=b.inputs?b.inputs.length:0,f=Math.floor(1.6*e.NODE_SLOT_HEIGHT);
|
||||
d.fillStyle="#111";d.globalAlpha=.8;d.beginPath();d.roundRect(10,10,200,(g+1)*f+50,[8]);d.fill();d.globalAlpha=1;d.fillStyle="#888";d.font="14px Arial";d.textAlign="left";d.fillText("Graph Inputs",20,34);if(this.drawButton(180,20,20,20,"X","#151515"))this.closeSubgraph();else{g=50;d.font="14px Arial";if(b.inputs)for(var m=0;m<b.inputs.length;++m){var c=b.inputs[m];if(!c.not_subgraph_input){if(this.drawButton(20,g+2,180,f-2)){var k=b.constructor.input_node_type||"graph/input";this.graph.beforeChange();
|
||||
var q=e.createNode(k);q?(a.add(q),this.block_click=!1,this.last_click_position=null,this.selectNodes([q]),this.node_dragged=q,this.dragging_canvas=!1,q.setProperty("name",c.name),q.setProperty("type",c.type),this.node_dragged.pos[0]=this.graph_mouse[0]-5,this.node_dragged.pos[1]=this.graph_mouse[1]-5,this.graph.afterChange()):console.error("graph input node not found:",k)}d.fillStyle="#9C9";d.beginPath();d.arc(184,g+.5*f,5,0,2*Math.PI);d.fill();d.fillStyle="#AAA";d.fillText(c.name,30,g+.75*f);d.fillStyle=
|
||||
"#777";d.fillText(c.type,130,g+.75*f);g+=f}}this.drawButton(20,g+2,180,f-2,"+","#151515","#222")&&this.showSubgraphPropertiesDialog(b)}};h.prototype.drawSubgraphPanelRight=function(a,b,d){var g=b.outputs?b.outputs.length:0,f=this.bgcanvas.width,m=Math.floor(1.6*e.NODE_SLOT_HEIGHT);d.fillStyle="#111";d.globalAlpha=.8;d.beginPath();d.roundRect(f-200-10,10,200,(g+1)*m+50,[8]);d.fill();d.globalAlpha=1;d.fillStyle="#888";d.font="14px Arial";d.textAlign="left";g=d.measureText("Graph Outputs").width;d.fillText("Graph Outputs",
|
||||
f-g-20,34);if(this.drawButton(f-200,20,20,20,"X","#151515"))this.closeSubgraph();else{g=50;d.font="14px Arial";if(b.outputs)for(var c=0;c<b.outputs.length;++c){var k=b.outputs[c];if(!k.not_subgraph_input){if(this.drawButton(f-200,g+2,180,m-2)){var q=b.constructor.output_node_type||"graph/output";this.graph.beforeChange();var x=e.createNode(q);x?(a.add(x),this.block_click=!1,this.last_click_position=null,this.selectNodes([x]),this.node_dragged=x,this.dragging_canvas=!1,x.setProperty("name",k.name),
|
||||
x.setProperty("type",k.type),this.node_dragged.pos[0]=this.graph_mouse[0]-5,this.node_dragged.pos[1]=this.graph_mouse[1]-5,this.graph.afterChange()):console.error("graph input node not found:",q)}d.fillStyle="#9C9";d.beginPath();d.arc(f-200+16,g+.5*m,5,0,2*Math.PI);d.fill();d.fillStyle="#AAA";d.fillText(k.name,f-200+30,g+.75*m);d.fillStyle="#777";d.fillText(k.type,f-200+130,g+.75*m);g+=m}}this.drawButton(f-200,g+2,180,m-2,"+","#151515","#222")&&this.showSubgraphPropertiesDialogRight(b)}};h.prototype.drawButton=
|
||||
function(a,b,d,g,f,m,c,k){var u=this.ctx;m=m||e.NODE_DEFAULT_COLOR;c=c||"#555";k=k||e.NODE_TEXT_COLOR;var x=b+e.NODE_TITLE_HEIGHT+2,C=this.mouse,w=e.isInsideRectangle(C[0],C[1],a,x,d,g);x=(C=this.last_click_position)&&e.isInsideRectangle(C[0],C[1],a,x,d,g);u.fillStyle=w?c:m;x&&(u.fillStyle="#AAA");u.beginPath();u.roundRect(a,b,d,g,[4]);u.fill();null!=f&&f.constructor==String&&(u.fillStyle=k,u.textAlign="center",u.font=(.65*g|0)+"px Arial",u.fillText(f,a+.5*d,b+.75*g),u.textAlign="left");a=x&&!this.block_click;
|
||||
x&&this.blockClick();return a};h.prototype.isAreaClicked=function(a,b,d,g,f){var m=this.mouse;e.isInsideRectangle(m[0],m[1],a,b,d,g);b=(a=(m=this.last_click_position)&&e.isInsideRectangle(m[0],m[1],a,b,d,g))&&!this.block_click;a&&f&&this.blockClick();return b};h.prototype.renderInfo=function(a,b,d){b=b||10;d=d||this.canvas.height-80;a.save();a.translate(b,d);a.font="10px Arial";a.fillStyle="#888";a.textAlign="left";this.graph?(a.fillText("T: "+this.graph.globaltime.toFixed(2)+"s",5,13),a.fillText("I: "+
|
||||
this.graph.iteration,5,26),a.fillText("N: "+this.graph._nodes.length+" ["+this.visible_nodes.length+"]",5,39),a.fillText("V: "+this.graph._version,5,52),a.fillText("FPS:"+this.fps.toFixed(2),5,65)):a.fillText("No graph selected",5,13);a.restore()};h.prototype.drawBackCanvas=function(){var a=this.bgcanvas;if(a.width!=this.canvas.width||a.height!=this.canvas.height)a.width=this.canvas.width,a.height=this.canvas.height;this.bgctx||(this.bgctx=this.bgcanvas.getContext("2d"));var b=this.bgctx;b.start&&
|
||||
b.start();var d=this.viewport||[0,0,b.canvas.width,b.canvas.height];this.clear_background&&b.clearRect(d[0],d[1],d[2],d[3]);if(this._graph_stack&&this._graph_stack.length){b.save();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 g="",f=1;f<this._graph_stack.length;++f)g+=this._graph_stack[f]._subgraph_node.getTitle()+" >> ";b.fillText(g+d.getTitle(),
|
||||
.5*a.width,40);b.restore()}d=!1;this.onRenderBackground&&(d=this.onRenderBackground(a,b));this.viewport||(b.restore(),b.setTransform(1,0,0,1,0,0));this.visible_links.length=0;if(this.graph){b.save();this.ds.toCanvasContext(b);if(this.background_image&&.5<this.ds.scale&&!d){b.globalAlpha=this.zoom_modify_alpha?(1-.5/this.ds.scale)*this.editor_alpha:this.editor_alpha;b.imageSmoothingEnabled=b.imageSmoothingEnabled=!1;if(!this._bg_img||this._bg_img.name!=this.background_image){this._bg_img=new Image;
|
||||
this._bg_img.name=this.background_image;this._bg_img.src=this.background_image;var e=this;this._bg_img.onload=function(){e.draw(!0,!0)}}d=null;null==this._pattern&&0<this._bg_img.width?(d=b.createPattern(this._bg_img,"repeat"),this._pattern_img=this._bg_img,this._pattern=d):d=this._pattern;d&&(b.fillStyle=d,b.fillRect(this.visible_area[0],this.visible_area[1],this.visible_area[2],this.visible_area[3]),b.fillStyle="transparent");b.globalAlpha=1;b.imageSmoothingEnabled=b.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 H=new Float32Array(2);h.prototype.drawNode=function(a,b){this.current_node=a;var d=a.color||a.constructor.color||e.NODE_DEFAULT_COLOR,g=a.bgcolor||a.constructor.bgcolor||e.NODE_DEFAULT_BGCOLOR,f=.6>this.ds.scale;if(this.live_mode){if(!a.flags.collapsed&&(b.shadowColor="transparent",a.onDrawForeground))a.onDrawForeground(b,this,this.canvas)}else{var m=this.editor_alpha;b.globalAlpha=m;this.render_shadows&&
|
||||
!f?(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||1!=a.onDrawCollapsed(b,this)){var c=a._shape||e.BOX_SHAPE;H.set(a.size);var k=a.horizontal;if(a.flags.collapsed){b.font=this.inner_text_font;var q=a.getTitle?a.getTitle():a.title;null!=q&&(a._collapsed_width=Math.min(a.size[0],b.measureText(q).width+2*e.NODE_TITLE_HEIGHT),H[0]=a._collapsed_width,
|
||||
H[1]=0)}a.clip_area&&(b.save(),b.beginPath(),c==e.BOX_SHAPE?b.rect(0,0,H[0],H[1]):c==e.ROUND_SHAPE?b.roundRect(0,0,H[0],H[1],[10]):c==e.CIRCLE_SHAPE&&b.arc(.5*H[0],.5*H[1],.5*H[0],0,2*Math.PI),b.clip());a.has_errors&&(g="red");this.drawNodeShape(a,b,H,d,g,a.is_selected,a.mouseOver);b.shadowColor="transparent";if(a.onDrawForeground)a.onDrawForeground(b,this,this.canvas);b.textAlign=k?"center":"left";b.font=this.inner_text_font;g=!f;var x=this.connecting_output;c=this.connecting_input;b.lineWidth=1;
|
||||
q=0;var C=new Float32Array(2);if(!a.flags.collapsed){if(a.inputs)for(d=0;d<a.inputs.length;d++){var w=a.inputs[d],L=w.type,G=w.shape;b.globalAlpha=m;this.connecting_output&&!e.isValidConnection(w.type,x.type)&&(b.globalAlpha=.4*m);b.fillStyle=null!=w.link?w.color_on||this.default_connection_color_byType[L]||this.default_connection_color.input_on:w.color_off||this.default_connection_color_byTypeOff[L]||this.default_connection_color_byType[L]||this.default_connection_color.input_off;var y=a.getConnectionPos(!0,
|
||||
d,C);y[0]-=a.pos[0];y[1]-=a.pos[1];q<y[1]+.5*e.NODE_SLOT_HEIGHT&&(q=y[1]+.5*e.NODE_SLOT_HEIGHT);b.beginPath();"array"==L&&(G=e.GRID_SHAPE);w.type===e.EVENT||w.shape===e.BOX_SHAPE?k?b.rect(y[0]-5+.5,y[1]-8+.5,10,14):b.rect(y[0]-6+.5,y[1]-5+.5,14,10):G===e.ARROW_SHAPE?(b.moveTo(y[0]+8,y[1]+.5),b.lineTo(y[0]-4,y[1]+6+.5),b.lineTo(y[0]-4,y[1]-6+.5),b.closePath()):G===e.GRID_SHAPE?(b.rect(y[0]-4,y[1]-4,2,2),b.rect(y[0]-1,y[1]-4,2,2),b.rect(y[0]+2,y[1]-4,2,2),b.rect(y[0]-4,y[1]-1,2,2),b.rect(y[0]-1,y[1]-
|
||||
1,2,2),b.rect(y[0]+2,y[1]-1,2,2),b.rect(y[0]-4,y[1]+2,2,2),b.rect(y[0]-1,y[1]+2,2,2),b.rect(y[0]+2,y[1]+2,2,2)):f?b.rect(y[0]-4,y[1]-4,8,8):b.arc(y[0],y[1],4,0,2*Math.PI);b.fill();g&&(L=null!=w.label?w.label:w.name)&&(b.fillStyle=e.NODE_TEXT_COLOR,k||w.dir==e.UP?b.fillText(L,y[0],y[1]-10):b.fillText(L,y[0]+10,y[1]+5))}b.textAlign=k?"center":"right";b.strokeStyle="black";if(a.outputs)for(d=0;d<a.outputs.length;d++)if(w=a.outputs[d],L=w.type,G=w.shape,this.connecting_input&&!e.isValidConnection(L,c.type)&&
|
||||
(b.globalAlpha=.4*m),y=a.getConnectionPos(!1,d,C),y[0]-=a.pos[0],y[1]-=a.pos[1],q<y[1]+.5*e.NODE_SLOT_HEIGHT&&(q=y[1]+.5*e.NODE_SLOT_HEIGHT),b.fillStyle=w.links&&w.links.length?w.color_on||this.default_connection_color_byType[L]||this.default_connection_color.output_on:w.color_off||this.default_connection_color_byTypeOff[L]||this.default_connection_color_byType[L]||this.default_connection_color.output_off,b.beginPath(),"array"==L&&(G=e.GRID_SHAPE),x=!0,L===e.EVENT||G===e.BOX_SHAPE?k?b.rect(y[0]-5+
|
||||
.5,y[1]-8+.5,10,14):b.rect(y[0]-6+.5,y[1]-5+.5,14,10):G===e.ARROW_SHAPE?(b.moveTo(y[0]+8,y[1]+.5),b.lineTo(y[0]-4,y[1]+6+.5),b.lineTo(y[0]-4,y[1]-6+.5),b.closePath()):G===e.GRID_SHAPE?(b.rect(y[0]-4,y[1]-4,2,2),b.rect(y[0]-1,y[1]-4,2,2),b.rect(y[0]+2,y[1]-4,2,2),b.rect(y[0]-4,y[1]-1,2,2),b.rect(y[0]-1,y[1]-1,2,2),b.rect(y[0]+2,y[1]-1,2,2),b.rect(y[0]-4,y[1]+2,2,2),b.rect(y[0]-1,y[1]+2,2,2),b.rect(y[0]+2,y[1]+2,2,2),x=!1):f?b.rect(y[0]-4,y[1]-4,8,8):b.arc(y[0],y[1],4,0,2*Math.PI),b.fill(),!f&&x&&b.stroke(),
|
||||
g&&(L=null!=w.label?w.label:w.name))b.fillStyle=e.NODE_TEXT_COLOR,k||w.dir==e.DOWN?b.fillText(L,y[0],y[1]-8):b.fillText(L,y[0]-10,y[1]+5);b.textAlign="left";b.globalAlpha=1;if(a.widgets){w=q;if(k||a.widgets_up)w=2;null!=a.widgets_start_y&&(w=a.widgets_start_y);this.drawNodeWidgets(a,w,b,this.node_widget&&this.node_widget[0]==a?this.node_widget[1]:null)}}else if(this.render_collapsed_slots){f=m=null;if(a.inputs)for(d=0;d<a.inputs.length;d++)if(w=a.inputs[d],null!=w.link){m=w;break}if(a.outputs)for(d=
|
||||
0;d<a.outputs.length;d++)w=a.outputs[d],w.links&&w.links.length&&(f=w);m&&(m=0,d=-.5*e.NODE_TITLE_HEIGHT,k&&(m=.5*a._collapsed_width,d=-e.NODE_TITLE_HEIGHT),b.fillStyle="#686",b.beginPath(),w.type===e.EVENT||w.shape===e.BOX_SHAPE?b.rect(m-7+.5,d-4,14,8):w.shape===e.ARROW_SHAPE?(b.moveTo(m+8,d),b.lineTo(m+-4,d-4),b.lineTo(m+-4,d+4),b.closePath()):b.arc(m,d,4,0,2*Math.PI),b.fill());f&&(m=a._collapsed_width,d=-.5*e.NODE_TITLE_HEIGHT,k&&(m=.5*a._collapsed_width,d=0),b.fillStyle="#686",b.strokeStyle="black",
|
||||
b.beginPath(),w.type===e.EVENT||w.shape===e.BOX_SHAPE?b.rect(m-7+.5,d-4,14,8):w.shape===e.ARROW_SHAPE?(b.moveTo(m+6,d),b.lineTo(m-6,d-4),b.lineTo(m-6,d+4),b.closePath()):b.arc(m,d,4,0,2*Math.PI),b.fill())}a.clip_area&&b.restore();b.globalAlpha=1}}};h.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||1!=this.onDrawLinkTooltip(a,b,this))&&(b=b.data,b=b.constructor===Number?b.toFixed(2):
|
||||
b.constructor===String?'"'+b+'"':b.constructor===Boolean?String(b):b.toToolTip?b.toToolTip():"["+b.constructor.name+"]",null!=b)){b=b.substr(0,30);a.font="14px Courier New";var g=a.measureText(b).width+20;a.shadowColor="black";a.shadowOffsetX=2;a.shadowOffsetY=2;a.shadowBlur=3;a.fillStyle="#454";a.beginPath();a.roundRect(d[0]-.5*g,d[1]-15-24,g,24,[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(b,d[0],d[1]-15-24*.3)}};var z=new Float32Array(4);h.prototype.drawNodeShape=function(a,b,d,g,f,m,c){b.strokeStyle=g;b.fillStyle=f;f=e.NODE_TITLE_HEIGHT;var u=.5>this.ds.scale,k=a._shape||a.constructor.shape||e.ROUND_SHAPE,x=a.constructor.title_mode,C=!0;x==e.TRANSPARENT_TITLE||x==e.NO_TITLE?C=!1:x==e.AUTOHIDE_TITLE&&c&&(C=!0);z[0]=0;z[1]=C?-f:0;z[2]=d[0]+1;z[3]=C?d[1]+f:d[1];c=b.globalAlpha;b.beginPath();k==e.BOX_SHAPE||u?b.fillRect(z[0],z[1],z[2],z[3]):k==e.ROUND_SHAPE||k==e.CARD_SHAPE?
|
||||
b.roundRect(z[0],z[1],z[2],z[3],k==e.CARD_SHAPE?[this.round_radius,this.round_radius,0,0]:[this.round_radius]):k==e.CIRCLE_SHAPE&&b.arc(.5*d[0],.5*d[1],.5*d[0],0,2*Math.PI);b.fill();!a.flags.collapsed&&C&&(b.shadowColor="transparent",b.fillStyle="rgba(0,0,0,0.2)",b.fillRect(0,-1,z[2],2));b.shadowColor="transparent";if(a.onDrawBackground)a.onDrawBackground(b,this,this.canvas,this.graph_mouse);if(C||x==e.TRANSPARENT_TITLE){if(a.onDrawTitleBar)a.onDrawTitleBar(b,f,d,this.ds.scale,g);else if(x!=e.TRANSPARENT_TITLE&&
|
||||
(a.constructor.title_color||this.render_title_colored)){C=a.constructor.title_color||g;a.flags.collapsed&&(b.shadowColor=e.DEFAULT_SHADOW_COLOR);if(this.use_gradients){var w=h.gradients[C];w||(w=h.gradients[C]=b.createLinearGradient(0,0,400,0),w.addColorStop(0,C),w.addColorStop(1,"#000"));b.fillStyle=w}else b.fillStyle=C;b.beginPath();k==e.BOX_SHAPE||u?b.rect(0,-f,d[0]+1,f):(k==e.ROUND_SHAPE||k==e.CARD_SHAPE)&&b.roundRect(0,-f,d[0]+1,f,a.flags.collapsed?[this.round_radius]:[this.round_radius,this.round_radius,
|
||||
0,0]);b.fill();b.shadowColor="transparent"}C=!1;e.node_box_coloured_by_mode&&e.NODE_MODES_COLORS[a.mode]&&(C=e.NODE_MODES_COLORS[a.mode]);e.node_box_coloured_when_on&&(C=a.action_triggered?"#FFF":a.execute_triggered?"#AAA":C);if(a.onDrawTitleBox)a.onDrawTitleBox(b,f,d,this.ds.scale);else k==e.ROUND_SHAPE||k==e.CIRCLE_SHAPE||k==e.CARD_SHAPE?(u&&(b.fillStyle="black",b.beginPath(),b.arc(.5*f,-.5*f,6,0,2*Math.PI),b.fill()),b.fillStyle=a.boxcolor||C||e.NODE_DEFAULT_BOXCOLOR,u?b.fillRect(.5*f-5,-.5*f-5,
|
||||
10,10):(b.beginPath(),b.arc(.5*f,-.5*f,5,0,2*Math.PI),b.fill())):(u&&(b.fillStyle="black",b.fillRect(.5*(f-10)-1,-.5*(f+10)-1,12,12)),b.fillStyle=a.boxcolor||C||e.NODE_DEFAULT_BOXCOLOR,b.fillRect(.5*(f-10),-.5*(f+10),10,10));b.globalAlpha=c;if(a.onDrawTitleText)a.onDrawTitleText(b,f,d,this.ds.scale,this.title_text_font,m);!u&&(b.font=this.title_text_font,c=String(a.getTitle()))&&(b.fillStyle=m?e.NODE_SELECTED_TITLE_COLOR:a.constructor.title_text_color||this.node_title_color,a.flags.collapsed?(b.textAlign=
|
||||
"left",b.measureText(c),b.fillText(c.substr(0,20),f,e.NODE_TITLE_TEXT_Y-f),b.textAlign="left"):(b.textAlign="left",b.fillText(c,f,e.NODE_TITLE_TEXT_Y-f)));a.flags.collapsed||!a.subgraph||a.skip_subgraph_button||(c=e.NODE_TITLE_HEIGHT,C=a.size[0]-c,w=e.isInsideRectangle(this.graph_mouse[0]-a.pos[0],this.graph_mouse[1]-a.pos[1],C+2,-c+2,c-4,c-4),b.fillStyle=w?"#888":"#555",k==e.BOX_SHAPE||u?b.fillRect(C+2,-c+2,c-4,c-4):(b.beginPath(),b.roundRect(C+2,-c+2,c-4,c-4,[4]),b.fill()),b.fillStyle="#333",b.beginPath(),
|
||||
b.moveTo(C+.2*c,.6*-c),b.lineTo(C+.8*c,.6*-c),b.lineTo(C+.5*c,.3*-c),b.fill());if(a.onDrawTitle)a.onDrawTitle(b)}if(m){if(a.onBounding)a.onBounding(z);x==e.TRANSPARENT_TITLE&&(z[1]-=f,z[3]+=f);b.lineWidth=1;b.globalAlpha=.8;b.beginPath();k==e.BOX_SHAPE?b.rect(-6+z[0],-6+z[1],12+z[2],12+z[3]):k==e.ROUND_SHAPE||k==e.CARD_SHAPE&&a.flags.collapsed?b.roundRect(-6+z[0],-6+z[1],12+z[2],12+z[3],[2*this.round_radius]):k==e.CARD_SHAPE?b.roundRect(-6+z[0],-6+z[1],12+z[2],12+z[3],[2*this.round_radius,2,2*this.round_radius,
|
||||
2]):k==e.CIRCLE_SHAPE&&b.arc(.5*d[0],.5*d[1],.5*d[0]+6,0,2*Math.PI);b.strokeStyle=e.NODE_BOX_OUTLINE_COLOR;b.stroke();b.strokeStyle=g;b.globalAlpha=1}0<a.execute_triggered&&a.execute_triggered--;0<a.action_triggered&&a.action_triggered--};var M=new Float32Array(4),k=new Float32Array(4),n=new Float32Array(2),q=new Float32Array(2);h.prototype.drawConnections=function(a){var b=e.getTime(),d=this.visible_area;M[0]=d[0]-20;M[1]=d[1]-20;M[2]=d[2]+40;M[3]=d[3]+40;a.lineWidth=this.connections_width;a.fillStyle=
|
||||
"#AAA";a.strokeStyle="#AAA";a.globalAlpha=this.editor_alpha;d=this.graph._nodes;for(var g=0,f=d.length;g<f;++g){var c=d[g];if(c.inputs&&c.inputs.length)for(var u=0;u<c.inputs.length;++u){var h=c.inputs[u];if(h&&null!=h.link&&(h=this.graph.links[h.link])){var D=this.graph.getNodeById(h.origin_id);if(null!=D){var x=h.origin_slot;var C=-1==x?[D.pos[0]+10,D.pos[1]+10]:D.getConnectionPos(!1,x,n);var w=c.getConnectionPos(!0,u,q);k[0]=C[0];k[1]=C[1];k[2]=w[0]-C[0];k[3]=w[1]-C[1];0>k[2]&&(k[0]+=k[2],k[2]=
|
||||
Math.abs(k[2]));0>k[3]&&(k[1]+=k[3],k[3]=Math.abs(k[3]));if(I(k,M)){var L=D.outputs[x];x=c.inputs[u];if(L&&x&&(D=L.dir||(D.horizontal?e.DOWN:e.RIGHT),x=x.dir||(c.horizontal?e.UP:e.LEFT),this.renderLink(a,C,w,h,!1,0,null,D,x),h&&h._last_time&&1E3>b-h._last_time)){L=2-.002*(b-h._last_time);var G=a.globalAlpha;a.globalAlpha=G*L;this.renderLink(a,C,w,h,!0,L,"white",D,x);a.globalAlpha=G}}}}}}a.globalAlpha=1};h.prototype.renderLink=function(a,b,d,g,f,c,u,k,q,x){g&&this.visible_links.push(g);!u&&g&&(u=g.color||
|
||||
h.link_type_colors[g.type]);u||(u=this.default_link_color);null!=g&&this.highlighted_links[g.id]&&(u="#FFF");k=k||e.RIGHT;q=q||e.LEFT;var m=E(b,d);this.render_connections_border&&.6<this.ds.scale&&(a.lineWidth=this.connections_width+4);a.lineJoin="round";x=x||1;1<x&&(a.lineWidth=.5);a.beginPath();for(var w=0;w<x;w+=1){var L=5*(w-.5*(x-1));if(this.links_render_mode==e.SPLINE_LINK){a.moveTo(b[0],b[1]+L);var G=0,y=0,n=0,D=0;switch(k){case e.LEFT:G=-.25*m;break;case e.RIGHT:G=.25*m;break;case e.UP:y=
|
||||
-.25*m;break;case e.DOWN:y=.25*m}switch(q){case e.LEFT:n=-.25*m;break;case e.RIGHT:n=.25*m;break;case e.UP:D=-.25*m;break;case e.DOWN:D=.25*m}a.bezierCurveTo(b[0]+G,b[1]+y+L,d[0]+n,d[1]+D+L,d[0],d[1]+L)}else if(this.links_render_mode==e.LINEAR_LINK){a.moveTo(b[0],b[1]+L);D=n=y=G=0;switch(k){case e.LEFT:G=-1;break;case e.RIGHT:G=1;break;case e.UP:y=-1;break;case e.DOWN:y=1}switch(q){case e.LEFT:n=-1;break;case e.RIGHT:n=1;break;case e.UP:D=-1;break;case e.DOWN:D=1}a.lineTo(b[0]+15*G,b[1]+15*y+L);a.lineTo(d[0]+
|
||||
15*n,d[1]+15*D+L);a.lineTo(d[0],d[1]+L)}else if(this.links_render_mode==e.STRAIGHT_LINK)a.moveTo(b[0],b[1]),L=b[0],G=b[1],y=d[0],n=d[1],k==e.RIGHT?L+=10:G+=10,q==e.LEFT?y-=10:n-=10,a.lineTo(L,G),a.lineTo(.5*(L+y),G),a.lineTo(.5*(L+y),n),a.lineTo(y,n),a.lineTo(d[0],d[1]);else return}this.render_connections_border&&.6<this.ds.scale&&!f&&(a.strokeStyle="rgba(0,0,0,0.5)",a.stroke());a.lineWidth=this.connections_width;a.fillStyle=a.strokeStyle=u;a.stroke();f=this.computeConnectionPoint(b,d,.5,k,q);g&&
|
||||
g._pos&&(g._pos[0]=f[0],g._pos[1]=f[1]);.6<=this.ds.scale&&this.highquality_render&&q!=e.CENTER&&(this.render_connection_arrows&&(w=this.computeConnectionPoint(b,d,.25,k,q),m=this.computeConnectionPoint(b,d,.26,k,q),g=this.computeConnectionPoint(b,d,.75,k,q),x=this.computeConnectionPoint(b,d,.76,k,q),this.render_curved_connections?(m=-Math.atan2(m[0]-w[0],m[1]-w[1]),x=-Math.atan2(x[0]-g[0],x[1]-g[1])):x=m=d[1]>b[1]?0:Math.PI,a.save(),a.translate(w[0],w[1]),a.rotate(m),a.beginPath(),a.moveTo(-5,-3),
|
||||
a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore(),a.save(),a.translate(g[0],g[1]),a.rotate(x),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore()),a.beginPath(),a.arc(f[0],f[1],5,0,2*Math.PI),a.fill());if(c)for(a.fillStyle=u,w=0;5>w;++w)c=(.001*e.getTime()+.2*w)%1,f=this.computeConnectionPoint(b,d,c,k,q),a.beginPath(),a.arc(f[0],f[1],5,0,2*Math.PI),a.fill()};h.prototype.computeConnectionPoint=function(a,b,d,g,f){g=g||e.RIGHT;f=f||e.LEFT;var c=E(a,b),u=[a[0],a[1]],k=[b[0],
|
||||
b[1]];switch(g){case e.LEFT:u[0]+=-.25*c;break;case e.RIGHT:u[0]+=.25*c;break;case e.UP:u[1]+=-.25*c;break;case e.DOWN:u[1]+=.25*c}switch(f){case e.LEFT:k[0]+=-.25*c;break;case e.RIGHT:k[0]+=.25*c;break;case e.UP:k[1]+=-.25*c;break;case e.DOWN:k[1]+=.25*c}g=(1-d)*(1-d)*(1-d);f=3*(1-d)*(1-d)*d;c=3*(1-d)*d*d;d*=d*d;return[g*a[0]+f*u[0]+c*k[0]+d*b[0],g*a[1]+f*u[1]+c*k[1]+d*b[1]]};h.prototype.drawExecutionOrder=function(a){a.shadowColor="transparent";a.globalAlpha=.25;a.textAlign="center";a.strokeStyle=
|
||||
"white";a.globalAlpha=.75;for(var b=this.visible_nodes,d=0;d<b.length;++d){var g=b[d];a.fillStyle="black";a.fillRect(g.pos[0]-e.NODE_TITLE_HEIGHT,g.pos[1]-e.NODE_TITLE_HEIGHT,e.NODE_TITLE_HEIGHT,e.NODE_TITLE_HEIGHT);0==g.order&&a.strokeRect(g.pos[0]-e.NODE_TITLE_HEIGHT+.5,g.pos[1]-e.NODE_TITLE_HEIGHT+.5,e.NODE_TITLE_HEIGHT,e.NODE_TITLE_HEIGHT);a.fillStyle="#FFF";a.fillText(g.order,g.pos[0]+-.5*e.NODE_TITLE_HEIGHT,g.pos[1]-6)}a.globalAlpha=1};h.prototype.drawNodeWidgets=function(a,b,d,g){if(!a.widgets||
|
||||
!a.widgets.length)return 0;var f=a.size[0],c=a.widgets;b+=2;var u=e.NODE_WIDGET_HEIGHT,k=.5<this.ds.scale;d.save();d.globalAlpha=this.editor_alpha;for(var q=e.WIDGET_OUTLINE_COLOR,x=e.WIDGET_BGCOLOR,C=e.WIDGET_TEXT_COLOR,w=e.WIDGET_SECONDARY_TEXT_COLOR,L=0;L<c.length;++L){var G=c[L],y=b;G.y&&(y=G.y);G.last_y=y;d.strokeStyle=q;d.fillStyle="#222";d.textAlign="left";G.disabled&&(d.globalAlpha*=.5);var n=G.width||f;switch(G.type){case "button":G.clicked&&(d.fillStyle="#AAA",G.clicked=!1,this.dirty_canvas=
|
||||
!0);d.fillRect(15,y,n-30,u);k&&!G.disabled&&d.strokeRect(15,y,n-30,u);k&&(d.textAlign="center",d.fillStyle=C,d.fillText(G.name,.5*n,y+.7*u));break;case "toggle":d.textAlign="left";d.strokeStyle=q;d.fillStyle=x;d.beginPath();k?d.roundRect(15,y,n-30,u,[.5*u]):d.rect(15,y,n-30,u);d.fill();k&&!G.disabled&&d.stroke();d.fillStyle=G.value?"#89A":"#333";d.beginPath();d.arc(n-30,y+.5*u,.36*u,0,2*Math.PI);d.fill();k&&(d.fillStyle=w,null!=G.name&&d.fillText(G.name,30,y+.7*u),d.fillStyle=G.value?C:w,d.textAlign=
|
||||
"right",d.fillText(G.value?G.options.on||"true":G.options.off||"false",n-40,y+.7*u));break;case "slider":d.fillStyle=x;d.fillRect(15,y,n-30,u);var D=G.options.max-G.options.min,h=(G.value-G.options.min)/D;d.fillStyle=g==G?"#89A":"#678";d.fillRect(15,y,h*(n-30),u);k&&!G.disabled&&d.strokeRect(15,y,n-30,u);G.marker&&(D=(G.marker-G.options.min)/D,d.fillStyle="#AA9",d.fillRect(15+D*(n-30),y,2,u));k&&(d.textAlign="center",d.fillStyle=C,d.fillText(G.name+" "+Number(G.value).toFixed(3),.5*n,y+.7*u));break;
|
||||
case "number":case "combo":d.textAlign="left";d.strokeStyle=q;d.fillStyle=x;d.beginPath();k?d.roundRect(15,y,n-30,u,[.5*u]):d.rect(15,y,n-30,u);d.fill();k&&(G.disabled||d.stroke(),d.fillStyle=C,G.disabled||(d.beginPath(),d.moveTo(31,y+5),d.lineTo(21,y+.5*u),d.lineTo(31,y+u-5),d.fill(),d.beginPath(),d.moveTo(n-15-16,y+5),d.lineTo(n-15-6,y+.5*u),d.lineTo(n-15-16,y+u-5),d.fill()),d.fillStyle=w,d.fillText(G.name,35,y+.7*u),d.fillStyle=C,d.textAlign="right","number"==G.type?d.fillText(Number(G.value).toFixed(void 0!==
|
||||
G.options.precision?G.options.precision:3),n-30-20,y+.7*u):(D=G.value,G.options.values&&(h=G.options.values,h.constructor===Function&&(h=h()),h&&h.constructor!==Array&&(D=h[G.value])),d.fillText(D,n-30-20,y+.7*u)));break;case "string":case "text":d.textAlign="left";d.strokeStyle=q;d.fillStyle=x;d.beginPath();k?d.roundRect(15,y,n-30,u,[.5*u]):d.rect(15,y,n-30,u);d.fill();k&&(G.disabled||d.stroke(),d.save(),d.beginPath(),d.rect(15,y,n-30,u),d.clip(),d.fillStyle=w,null!=G.name&&d.fillText(G.name,30,
|
||||
y+.7*u),d.fillStyle=C,d.textAlign="right",d.fillText(String(G.value).substr(0,30),n-30,y+.7*u),d.restore());break;default:G.draw&&G.draw(d,a,n,y,u)}b+=(G.computeSize?G.computeSize(n)[1]:u)+4;d.globalAlpha=this.editor_alpha}d.restore();d.textAlign="left"};h.prototype.processNodeWidgets=function(a,b,d,g){function f(f,g){f.value=g;f.options&&f.options.property&&void 0!==a.properties[f.options.property]&&a.setProperty(f.options.property,g);f.callback&&f.callback(f.value,n,a,b,d)}if(!a.widgets||!a.widgets.length)return null;
|
||||
for(var c=b[0]-a.pos[0],k=b[1]-a.pos[1],q=a.size[0],n=this,x=this.getCanvasWindow(),C=0;C<a.widgets.length;++C){var w=a.widgets[C];if(w&&!w.disabled){var L=w.computeSize?w.computeSize(q)[1]:e.NODE_WIDGET_HEIGHT,G=w.width||q;if(w==g||!(6>c||c>G-12||k<w.last_y||k>w.last_y+L||void 0===w.last_y)){g=w.value;switch(w.type){case "button":d.type===e.pointerevents_method+"down"&&(w.callback&&setTimeout(function(){w.callback(w,n,a,b,d)},20),this.dirty_canvas=w.clicked=!0);break;case "slider":x=Math.clamp((c-
|
||||
15)/(G-30),0,1);w.value=w.options.min+(w.options.max-w.options.min)*x;w.callback&&setTimeout(function(){f(w,w.value)},20);this.dirty_canvas=!0;break;case "number":case "combo":g=w.value;if(d.type==e.pointerevents_method+"move"&&"number"==w.type)w.value+=.1*d.deltaX*(w.options.step||1),null!=w.options.min&&w.value<w.options.min&&(w.value=w.options.min),null!=w.options.max&&w.value>w.options.max&&(w.value=w.options.max);else if(d.type==e.pointerevents_method+"down"){var y=w.options.values;y&&y.constructor===
|
||||
Function&&(y=w.options.values(w,a));var D=null;"number"!=w.type&&(D=y.constructor===Array?y:Object.keys(y));c=40>c?-1:c>G-40?1:0;if("number"==w.type)w.value+=.1*c*(w.options.step||1),null!=w.options.min&&w.value<w.options.min&&(w.value=w.options.min),null!=w.options.max&&w.value>w.options.max&&(w.value=w.options.max);else if(c)x=-1,this.last_mouseclick=0,x=y.constructor===Object?D.indexOf(String(w.value))+c:D.indexOf(w.value)+c,x>=D.length&&(x=D.length-1),0>x&&(x=0),w.value=y.constructor===Array?
|
||||
y[x]:x;else{var h=y!=D?Object.values(y):y;new e.ContextMenu(h,{scale:Math.max(1,this.ds.scale),event:d,className:"dark",callback:function(a,b,d){y!=D&&(a=h.indexOf(a));this.value=a;f(this,a);n.dirty_canvas=!0;return!1}.bind(w)},x)}}else d.type==e.pointerevents_method+"up"&&"number"==w.type&&(c=40>c?-1:c>G-40?1:0,200>d.click_time&&0==c&&this.prompt("Value",w.value,function(a){this.value=Number(a);f(this,this.value)}.bind(w),d));g!=w.value&&setTimeout(function(){f(this,this.value)}.bind(w),20);this.dirty_canvas=
|
||||
!0;break;case "toggle":d.type==e.pointerevents_method+"down"&&(w.value=!w.value,setTimeout(function(){f(w,w.value)},20));break;case "string":case "text":d.type==e.pointerevents_method+"down"&&this.prompt("Value",w.value,function(a){this.value=a;f(this,a)}.bind(w),d,w.options?w.options.multiline:!1);break;default:w.mouse&&(this.dirty_canvas=w.mouse(d,[c,k],a))}if(g!=w.value){if(a.onWidgetChanged)a.onWidgetChanged(w.name,w.value,g,w);a.graph._version++}return w}}}return null};h.prototype.drawGroups=
|
||||
function(a,b){if(this.graph){a=this.graph._groups;b.save();b.globalAlpha=.5*this.editor_alpha;for(var d=0;d<a.length;++d){var g=a[d];if(I(this.visible_area,g._bounding)){b.fillStyle=g.color||"#335";b.strokeStyle=g.color||"#335";var f=g._pos,c=g._size;b.globalAlpha=.25*this.editor_alpha;b.beginPath();b.rect(f[0]+.5,f[1]+.5,c[0],c[1]);b.fill();b.globalAlpha=this.editor_alpha;b.stroke();b.beginPath();b.moveTo(f[0]+c[0],f[1]+c[1]);b.lineTo(f[0]+c[0]-10,f[1]+c[1]);b.lineTo(f[0]+c[0],f[1]+c[1]-10);b.fill();
|
||||
c=g.font_size||e.DEFAULT_GROUP_FONT_SIZE;b.font=c+"px Arial";b.textAlign="left";b.fillText(g.title,f[0]+4,f[1]+c)}}b.restore()}};h.prototype.adjustNodesSize=function(){for(var a=this.graph._nodes,b=0;b<a.length;++b)a[b].size=a[b].computeSize();this.setDirty(!0,!0)};h.prototype.resize=function(a,b){a||b||(b=this.canvas.parentNode,a=b.offsetWidth,b=b.offsetHeight);if(this.canvas.width!=a||this.canvas.height!=b)this.canvas.width=a,this.canvas.height=b,this.bgcanvas.width=this.canvas.width,this.bgcanvas.height=
|
||||
this.canvas.height,this.setDirty(!0,!0)};h.prototype.switchLiveMode=function(a){if(a){var b=this,d=this.live_mode?1.1:.9;this.live_mode&&(this.live_mode=!1,this.editor_alpha=.1);var g=setInterval(function(){b.editor_alpha*=d;b.dirty_canvas=!0;b.dirty_bgcanvas=!0;1>d&&.01>b.editor_alpha&&(clearInterval(g),1>d&&(b.live_mode=!0));1<d&&.99<b.editor_alpha&&(clearInterval(g),b.editor_alpha=1)},1)}else this.live_mode=!this.live_mode,this.dirty_bgcanvas=this.dirty_canvas=!0};h.prototype.onNodeSelectionChange=
|
||||
function(a){};h.onGroupAdd=function(a,b,d){a=h.active_canvas;a.getCanvasWindow();b=new e.LGraphGroup;b.pos=a.convertEventToCanvasOffset(d);a.graph.add(b)};h.onMenuAdd=function(a,b,d,g,f){function c(a,b){var g=[];e.getNodeTypesCategories(k.filter||n.filter).filter(function(b){return b.startsWith(a)}).map(function(b){if(b){b=b.replace(new RegExp("^("+a+")"),"").split("/")[0];var d=""===a?b+"/":a+b+"/";-1!=b.indexOf("::")&&(b=b.split("::")[1]);-1===g.findIndex(function(a){return a.value===d})&&g.push({value:d,
|
||||
content:b,has_submenu:!0,callback:function(a,b,d,f){c(a.value,f)}})}});e.getNodeTypesInCategory(a.slice(0,-1),k.filter||n.filter).map(function(a){a.skip_list||g.push({value:a.type,content:a.title,has_submenu:!1,callback:function(a,b,d,g){b=g.getFirstEvent();k.graph.beforeChange();if(a=e.createNode(a.value))a.pos=k.convertEventToCanvasOffset(b),k.graph.add(a);f&&f(a);k.graph.afterChange()}})});new e.ContextMenu(g,{event:d,parentMenu:b},q)}var k=h.active_canvas,q=k.getCanvasWindow(),n=k.graph;if(n)return c("",
|
||||
g),!1};h.onMenuCollapseAll=function(){};h.onMenuNodeEdit=function(){};h.showMenuNodeOptionalInputs=function(a,b,d,g,f){if(f){var c=this;a=h.active_canvas.getCanvasWindow();b=f.optional_inputs;f.onGetInputs&&(b=f.onGetInputs());var k=[];if(b)for(var n=0;n<b.length;n++){var q=b[n];if(q){var x=q[0];q[2]||(q[2]={});q[2].label&&(x=q[2].label);q[2].removable=!0;x={content:x,value:q};q[1]==e.ACTION&&(x.className="event");k.push(x)}else k.push(null)}f.onMenuNodeInputs&&(b=f.onMenuNodeInputs(k))&&(k=b);if(k.length)return new e.ContextMenu(k,
|
||||
{event:d,callback:function(a,b,d){if(f&&(a.callback&&a.callback.call(c,f,a,b,d),a.value)){f.graph.beforeChange();f.addInput(a.value[0],a.value[1],a.value[2]);if(f.onNodeInputAdd)f.onNodeInputAdd(a.value);f.setDirtyCanvas(!0,!0);f.graph.afterChange()}},parentMenu:g,node:f},a),!1;console.log("no input entries")}};h.showMenuNodeOptionalOutputs=function(a,b,d,g,f){function c(a,b,d){if(f&&(a.callback&&a.callback.call(k,f,a,b,d),a.value))if(d=a.value[1],!d||d.constructor!==Object&&d.constructor!==Array){f.graph.beforeChange();
|
||||
f.addOutput(a.value[0],a.value[1],a.value[2]);if(f.onNodeOutputAdd)f.onNodeOutputAdd(a.value);f.setDirtyCanvas(!0,!0);f.graph.afterChange()}else{a=[];for(var m in d)a.push({content:m,value:d[m]});new e.ContextMenu(a,{event:b,callback:c,parentMenu:g,node:f});return!1}}if(f){var k=this;a=h.active_canvas.getCanvasWindow();b=f.optional_outputs;f.onGetOutputs&&(b=f.onGetOutputs());var q=[];if(b)for(var n=0;n<b.length;n++){var x=b[n];if(!x)q.push(null);else if(!f.flags||!f.flags.skip_repeated_outputs||
|
||||
-1==f.findOutputSlot(x[0])){var C=x[0];x[2]||(x[2]={});x[2].label&&(C=x[2].label);x[2].removable=!0;C={content:C,value:x};x[1]==e.EVENT&&(C.className="event");q.push(C)}}this.onMenuNodeOutputs&&(q=this.onMenuNodeOutputs(q));e.do_add_triggers_slots&&-1==f.findOutputSlot("onExecuted")&&q.push({content:"On Executed",value:["onExecuted",e.EVENT,{nameLocked:!0}],className:"event"});f.onMenuNodeOutputs&&(b=f.onMenuNodeOutputs(q))&&(q=b);if(q.length)return new e.ContextMenu(q,{event:d,callback:c,parentMenu:g,
|
||||
node:f},a),!1}};h.onShowMenuNodeProperties=function(a,b,d,g,f){if(f&&f.properties){var c=h.active_canvas;b=c.getCanvasWindow();var k=[],q;for(q in f.properties){a=void 0!==f.properties[q]?f.properties[q]:" ";"object"==typeof a&&(a=JSON.stringify(a));var n=f.getPropertyInfo(q);if("enum"==n.type||"combo"==n.type)a=h.getPropertyPrintableValue(a,n.values);a=h.decodeHTML(a);k.push({content:"<span class='property_name'>"+(n.label?n.label:q)+"</span><span class='property_value'>"+a+"</span>",value:q})}if(k.length)return new e.ContextMenu(k,
|
||||
{event:d,callback:function(a,b,d,g){f&&(b=this.getBoundingClientRect(),c.showEditPropertyValue(f,a.value,{position:[b.left,b.top]}))},parentMenu:g,allow_html:!0,node:f},b),!1}};h.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};h.onMenuResizeNode=function(a,b,d,g,f){if(f){a=function(a){a.size=a.computeSize();if(a.onResize)a.onResize(a.size)};b=h.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)a(f);else for(var e in b.selected_nodes)a(b.selected_nodes[e]);
|
||||
f.setDirtyCanvas(!0,!0)}};h.prototype.showLinkMenu=function(a,b){var d=this,g=d.graph.getNodeById(a.origin_id),f=d.graph.getNodeById(a.target_id),c=!1;g&&g.outputs&&g.outputs[a.origin_slot]&&(c=g.outputs[a.origin_slot].type);var k=!1;f&&f.outputs&&f.outputs[a.target_slot]&&(k=f.inputs[a.target_slot].type);var q=new e.ContextMenu(["Add Node",null,"Delete",null],{event:b,title:null!=a.data?a.data.constructor.name:null,callback:function(b,e,m){switch(b){case "Add Node":h.onMenuAdd(null,null,m,q,function(b){b.inputs&&
|
||||
b.inputs.length&&b.outputs&&b.outputs.length&&g.connectByType(a.origin_slot,b,c)&&(b.connectByType(a.target_slot,f,k),b.pos[0]-=.5*b.size[0])});break;case "Delete":d.graph.removeLink(a.id)}}});return!1};h.prototype.createDefaultNodeForSlot=function(a){a=a||{};a=Object.assign({nodeFrom:null,slotFrom:null,nodeTo:null,slotTo:null,position:[],nodeType:null,posAdd:[0,0],posSizeFix:[0,0]},a);var b=a.nodeFrom&&null!==a.slotFrom,d=!b&&a.nodeTo&&null!==a.slotTo;if(!b&&!d)return console.warn("No data passed to createDefaultNodeForSlot "+
|
||||
a.nodeFrom+" "+a.slotFrom+" "+a.nodeTo+" "+a.slotTo),!1;if(!a.nodeType)return console.warn("No type to createDefaultNodeForSlot"),!1;var g=b?a.nodeFrom:a.nodeTo,f=b?a.slotFrom:a.slotTo;switch(typeof f){case "string":d=b?g.findOutputSlot(f,!1):g.findInputSlot(f,!1);f=b?g.outputs[f]:g.inputs[f];break;case "object":d=b?g.findOutputSlot(f.name):g.findInputSlot(f.name);break;case "number":d=f;f=b?g.outputs[f]:g.inputs[f];break;default:return console.warn("Cant get slot information "+f),!1}!1!==f&&!1!==
|
||||
d||console.warn("createDefaultNodeForSlot bad slotX "+f+" "+d);g=f.type==e.EVENT?"_event_":f.type;if((f=b?e.slot_types_default_out:e.slot_types_default_in)&&f[g]){nodeNewType=!1;if("object"==typeof f[g]||"array"==typeof f[g])for(var c in f[g]){if(a.nodeType==f[g][c]||"AUTO"==a.nodeType){nodeNewType=f[g][c];break}}else if(a.nodeType==f[g]||"AUTO"==a.nodeType)nodeNewType=f[g];if(nodeNewType){c=!1;"object"==typeof nodeNewType&&nodeNewType.node&&(c=nodeNewType,nodeNewType=nodeNewType.node);if(f=e.createNode(nodeNewType)){if(c){if(c.properties)for(var k in c.properties)f.addProperty(k,
|
||||
c.properties[k]);if(c.inputs)for(k in f.inputs=[],c.inputs)f.addOutput(c.inputs[k][0],c.inputs[k][1]);if(c.outputs)for(k in f.outputs=[],c.outputs)f.addOutput(c.outputs[k][0],c.outputs[k][1]);c.title&&(f.title=c.title);c.json&&f.configure(c.json)}this.graph.add(f);f.pos=[a.position[0]+a.posAdd[0]+(a.posSizeFix[0]?a.posSizeFix[0]*f.size[0]:0),a.position[1]+a.posAdd[1]+(a.posSizeFix[1]?a.posSizeFix[1]*f.size[1]:0)];b?a.nodeFrom.connectByType(d,f,g):a.nodeTo.connectByTypeOutput(d,f,g);return!0}console.log("failed creating "+
|
||||
nodeNewType)}}return!1};h.prototype.showConnectionMenu=function(a){a=a||{};var b=Object.assign({nodeFrom:null,slotFrom:null,nodeTo:null,slotTo:null,e:null},a),d=this,g=b.nodeFrom&&b.slotFrom;a=!g&&b.nodeTo&&b.slotTo;if(!g&&!a)return console.warn("No data passed to showConnectionMenu"),!1;a=g?b.nodeFrom:b.nodeTo;var f=g?b.slotFrom:b.slotTo,c=!1;switch(typeof f){case "string":c=g?a.findOutputSlot(f,!1):a.findInputSlot(f,!1);f=g?a.outputs[f]:a.inputs[f];break;case "object":c=g?a.findOutputSlot(f.name):
|
||||
a.findInputSlot(f.name);break;case "number":c=f;f=g?a.outputs[f]:a.inputs[f];break;default:return console.warn("Cant get slot information "+f),!1}a=["Add Node",null];d.allow_searchbox&&(a.push("Search"),a.push(null));var k=f.type==e.EVENT?"_event_":f.type,q=g?e.slot_types_default_out:e.slot_types_default_in;if(q&&q[k])if("object"==typeof q[k]||"array"==typeof q[k])for(var n in q[k])a.push(q[k][n]);else a.push(q[k]);var x=new e.ContextMenu(a,{event:b.e,title:(f&&""!=f.name?f.name+(k?" | ":""):"")+
|
||||
(f&&k?k:""),callback:function(a,e,m){switch(a){case "Add Node":h.onMenuAdd(null,null,m,x,function(a){g?b.nodeFrom.connectByType(c,a,k):b.nodeTo.connectByTypeOutput(c,a,k)});break;case "Search":g?d.showSearchBox(m,{node_from:b.nodeFrom,slot_from:f,type_filter_in:k}):d.showSearchBox(m,{node_to:b.nodeTo,slot_from:f,type_filter_out:k});break;default:d.createDefaultNodeForSlot(Object.assign(b,{position:[b.e.canvasX,b.e.canvasY],nodeType:a}))}}});return!1};h.onShowPropertyEditor=function(a,b,d,g,f){function c(){if(n){var b=
|
||||
n.value;"Number"==a.type?b=Number(b):"Boolean"==a.type&&(b=!!b);f[k]=b;q.parentNode&&q.parentNode.removeChild(q);f.setDirtyCanvas(!0,!0)}}var k=a.property||"title";b=f[k];var q=document.createElement("div");q.is_modified=!1;q.className="graphdialog";q.innerHTML="<span class='name'></span><input autofocus type='text' class='value'/><button>OK</button>";q.close=function(){q.parentNode&&q.parentNode.removeChild(q)};q.querySelector(".name").innerText=k;var n=q.querySelector(".value");n&&(n.value=b,n.addEventListener("blur",
|
||||
function(a){this.focus()}),n.addEventListener("keydown",function(a){q.is_modified=!0;if(27==a.keyCode)q.close();else if(13==a.keyCode)c();else if(13!=a.keyCode&&"textarea"!=a.target.localName)return;a.preventDefault();a.stopPropagation()}));b=h.active_canvas.canvas;d=b.getBoundingClientRect();var x=g=-20;d&&(g-=d.left,x-=d.top);event?(q.style.left=event.clientX+g+"px",q.style.top=event.clientY+x+"px"):(q.style.left=.5*b.width+g+"px",q.style.top=.5*b.height+x+"px");q.querySelector("button").addEventListener("click",
|
||||
c);b.parentNode.appendChild(q);n&&n.focus();var C=null;q.addEventListener("mouseleave",function(a){e.dialog_close_on_mouse_leave&&!q.is_modified&&e.dialog_close_on_mouse_leave&&(C=setTimeout(q.close,e.dialog_close_on_mouse_leave_delay))});q.addEventListener("mouseenter",function(a){e.dialog_close_on_mouse_leave&&C&&clearTimeout(C)})};h.prototype.prompt=function(a,b,d,g,f){var c=this;a=a||"";var k=document.createElement("div");k.is_modified=!1;k.className="graphdialog rounded";k.innerHTML=f?"<span class='name'></span> <textarea autofocus class='value'></textarea><button class='rounded'>OK</button>":
|
||||
"<span class='name'></span> <input autofocus type='text' class='value'/><button class='rounded'>OK</button>";k.close=function(){c.prompt_box=null;k.parentNode&&k.parentNode.removeChild(k)};f=h.active_canvas.canvas;f.parentNode.appendChild(k);1<this.ds.scale&&(k.style.transform="scale("+this.ds.scale+")");var q=null,n=!1;e.pointerListenerAdd(k,"leave",function(a){n||e.dialog_close_on_mouse_leave&&!k.is_modified&&e.dialog_close_on_mouse_leave&&(q=setTimeout(k.close,e.dialog_close_on_mouse_leave_delay))});
|
||||
e.pointerListenerAdd(k,"enter",function(a){e.dialog_close_on_mouse_leave&&q&&clearTimeout(q)});var x=k.querySelectorAll("select");x&&x.forEach(function(a){a.addEventListener("click",function(a){n++});a.addEventListener("blur",function(a){n=0});a.addEventListener("change",function(a){n=-1})});c.prompt_box&&c.prompt_box.close();c.prompt_box=k;k.querySelector(".name").innerText=a;var C=k.querySelector(".value");C.value=b;C.addEventListener("keydown",function(a){k.is_modified=!0;if(27==a.keyCode)k.close();
|
||||
else if(13==a.keyCode&&"textarea"!=a.target.localName)d&&d(this.value),k.close();else return;a.preventDefault();a.stopPropagation()});k.querySelector("button").addEventListener("click",function(a){d&&d(C.value);c.setDirty(!0);k.close()});a=f.getBoundingClientRect();x=b=-20;a&&(b-=a.left,x-=a.top);g?(k.style.left=g.clientX+b+"px",k.style.top=g.clientY+x+"px"):(k.style.left=.5*f.width+b+"px",k.style.top=.5*f.height+x+"px");setTimeout(function(){C.focus()},10);return k};h.search_limit=-1;h.prototype.showSearchBox=
|
||||
function(a,b){function d(d){if(d)if(c.onSearchBoxSelection)c.onSearchBoxSelection(d,a,k);else{var f=e.searchbox_extras[d.toLowerCase()];f&&(d=f.type);k.graph.beforeChange();if(d=e.createNode(d))d.pos=k.convertEventToCanvasOffset(a),k.graph.add(d,!1);if(f&&f.data){if(f.data.properties)for(var g in f.data.properties)d.addProperty(g,f.data.properties[g]);if(f.data.inputs)for(g in d.inputs=[],f.data.inputs)d.addOutput(f.data.inputs[g][0],f.data.inputs[g][1]);if(f.data.outputs)for(g in d.outputs=[],f.data.outputs)d.addOutput(f.data.outputs[g][0],
|
||||
f.data.outputs[g][1]);f.data.title&&(d.title=f.data.title);f.data.json&&d.configure(f.data.json)}if(b.node_from){switch(typeof b.slot_from){case "string":f=b.node_from.findOutputSlot(b.slot_from);break;case "object":f=b.slot_from.name?b.node_from.findOutputSlot(b.slot_from.name):-1;-1==f&&"undefined"!==typeof b.slot_from.slot_index&&(f=b.slot_from.slot_index);break;case "number":f=b.slot_from;break;default:f=0}!1!==f&&-1<f&&b.node_from.connectByType(f,d,b.node_from.outputs[f].type)}if(b.node_to){switch(typeof b.slot_from){case "string":f=
|
||||
b.node_to.findInputSlot(b.slot_from);break;case "object":f=b.slot_from.name?b.node_to.findInputSlot(b.slot_from.name):-1;-1==f&&"undefined"!==typeof b.slot_from.slot_index&&(f=b.slot_from.slot_index);break;case "number":f=b.slot_from;break;default:f=0}!1!==f&&-1<f&&b.node_to.connectByTypeOutput(f,d,b.node_to.inputs[f].type)}k.graph.afterChange()}x.close()}function g(a){var b=t;t&&t.classList.remove("selected");t?(t=a?t.nextSibling:t.previousSibling)||(t=b):t=a?y.childNodes[0]:y.childNodes[y.childNodes.length];
|
||||
t&&(t.classList.add("selected"),t.scrollIntoView({block:"end",behavior:"smooth"}))}function f(){function a(a,b){var f=document.createElement("div");l||(l=a);f.innerText=a;f.dataset.type=escape(a);f.className="litegraph lite-search-item";b&&(f.className+=" "+b);f.addEventListener("click",function(a){d(unescape(this.dataset.type))});y.appendChild(f)}r=null;var f=H.value;l=null;y.innerHTML="";if(f||b.show_all_if_empty)if(c.onSearchBox){var g=c.onSearchBox(y,f,k);if(g)for(var m=0;m<g.length;++m)a(g[m])}else{g=
|
||||
function(a,d){d=d||{};d=Object.assign({skipFilter:!1,inTypeOverride:!1,outTypeOverride:!1},d);var g=e.registered_node_types[a];if(q&&g.filter!=q||(!b.show_all_if_empty||f)&&-1===a.toLowerCase().indexOf(f))return!1;if(b.do_type_filter&&!d.skipFilter){g=n.value;!1!==d.inTypeOverride&&(g=d.inTypeOverride);if(n&&g&&e.registered_slot_in_types[g]&&e.registered_slot_in_types[g].nodes&&(g=e.registered_slot_in_types[g].nodes.includes(a),!1===g))return!1;g=G.value;!1!==d.outTypeOverride&&(g=d.outTypeOverride);
|
||||
if(G&&g&&e.registered_slot_out_types[g]&&e.registered_slot_out_types[g].nodes&&(g=e.registered_slot_out_types[g].nodes.includes(a),!1===g))return!1}return!0};var x=0;f=f.toLowerCase();var q=k.filter||k.graph.filter;if(b.do_type_filter&&c.search_box)var n=c.search_box.querySelector(".slot_in_type_filter"),G=c.search_box.querySelector(".slot_out_type_filter");else G=n=!1;for(m in e.searchbox_extras){var u=e.searchbox_extras[m];if(b.show_all_if_empty&&!f||-1!==u.desc.toLowerCase().indexOf(f)){var C=
|
||||
e.registered_node_types[u.type];if((!C||C.filter==q)&&g(u.type)&&(a(u.desc,"searchbox_extra"),-1!==h.search_limit&&x++>h.search_limit))break}}u=null;if(Array.prototype.filter)u=Object.keys(e.registered_node_types).filter(g);else for(m in u=[],e.registered_node_types)g(m)&&u.push(m);for(m=0;m<u.length&&!(a(u[m]),-1!==h.search_limit&&x++>h.search_limit);m++);if(b.show_general_after_typefiltered&&(n.value||G.value)){filtered_extra=[];for(m in e.registered_node_types)g(m,{inTypeOverride:n&&n.value?"*":
|
||||
!1,outTypeOverride:G&&G.value?"*":!1})&&filtered_extra.push(m);for(m=0;m<filtered_extra.length&&!(a(filtered_extra[m],"generic_type"),-1!==h.search_limit&&x++>h.search_limit);m++);}if((n.value||G.value)&&0==y.childNodes.length&&b.show_general_if_none_on_typefilter){filtered_extra=[];for(m in e.registered_node_types)g(m,{skipFilter:!0})&&filtered_extra.push(m);for(m=0;m<filtered_extra.length&&!(a(filtered_extra[m],"not_in_filter"),-1!==h.search_limit&&x++>h.search_limit);m++);}}}def_options={slot_from:null,
|
||||
node_from:null,node_to:null,do_type_filter:e.search_filter_enabled,type_filter_in:!1,type_filter_out:!1,show_general_if_none_on_typefilter:!0,show_general_after_typefiltered:!0,hide_on_mouse_leave:e.search_hide_on_mouse_leave,show_all_if_empty:!0,show_all_on_open:e.search_show_all_on_open};b=Object.assign(def_options,b||{});var c=this,k=h.active_canvas,q=k.canvas,n=q.ownerDocument||document,x=document.createElement("div");x.className="litegraph litesearchbox graphdialog rounded";x.innerHTML="<span class='name'>Search</span> <input autofocus type='text' class='value rounded'/>";
|
||||
b.do_type_filter&&(x.innerHTML+="<select class='slot_in_type_filter'><option value=''></option></select>",x.innerHTML+="<select class='slot_out_type_filter'><option value=''></option></select>");x.innerHTML+="<div class='helper'></div>";n.fullscreenElement?n.fullscreenElement.appendChild(x):(n.body.appendChild(x),n.body.style.overflow="hidden");if(b.do_type_filter)var C=x.querySelector(".slot_in_type_filter"),D=x.querySelector(".slot_out_type_filter");x.close=function(){c.search_box=null;n.body.focus();
|
||||
n.body.style.overflow="";setTimeout(function(){c.canvas.focus()},20);x.parentNode&&x.parentNode.removeChild(x)};1<this.ds.scale&&(x.style.transform="scale("+this.ds.scale+")");if(b.hide_on_mouse_leave){var L=!1,G=null;e.pointerListenerAdd(x,"enter",function(a){G&&(clearTimeout(G),G=null)});e.pointerListenerAdd(x,"leave",function(a){L||(G=setTimeout(function(){x.close()},500))});b.do_type_filter&&(C.addEventListener("click",function(a){L++}),C.addEventListener("blur",function(a){L=0}),C.addEventListener("change",
|
||||
function(a){L=-1}),D.addEventListener("click",function(a){L++}),D.addEventListener("blur",function(a){L=0}),D.addEventListener("change",function(a){L=-1}))}c.search_box&&c.search_box.close();c.search_box=x;var y=x.querySelector(".helper"),l=null,r=null,t=null,H=x.querySelector("input");H&&(H.addEventListener("blur",function(a){this.focus()}),H.addEventListener("keydown",function(a){if(38==a.keyCode)g(!1);else if(40==a.keyCode)g(!0);else if(27==a.keyCode)x.close();else if(13==a.keyCode)t?d(t.innerHTML):
|
||||
l?d(l):x.close();else{r&&clearInterval(r);r=setTimeout(f,250);return}a.preventDefault();a.stopPropagation();a.stopImmediatePropagation();return!0}));if(b.do_type_filter){if(C){var z=e.slot_types_in,v=z.length;if(b.type_filter_in==e.EVENT||b.type_filter_in==e.ACTION)b.type_filter_in="_event_";for(var M=0;M<v;M++){var A=document.createElement("option");A.value=z[M];A.innerHTML=z[M];C.appendChild(A);!1!==b.type_filter_in&&(b.type_filter_in+"").toLowerCase()==(z[M]+"").toLowerCase()&&(A.selected=!0)}C.addEventListener("change",
|
||||
function(){f()})}if(D){z=e.slot_types_out;v=z.length;if(b.type_filter_out==e.EVENT||b.type_filter_out==e.ACTION)b.type_filter_out="_event_";for(M=0;M<v;M++)A=document.createElement("option"),A.value=z[M],A.innerHTML=z[M],D.appendChild(A),!1!==b.type_filter_out&&(b.type_filter_out+"").toLowerCase()==(z[M]+"").toLowerCase()&&(A.selected=!0);D.addEventListener("change",function(){f()})}}q=q.getBoundingClientRect();C=(a?a.clientY:q.top+.5*q.height)-20;x.style.left=(a?a.clientX:q.left+.5*q.width)-80+"px";
|
||||
x.style.top=C+"px";a.layerY>q.height-200&&(y.style.maxHeight=q.height-a.layerY-20+"px");H.focus();b.show_all_on_open&&f();return x};h.prototype.showEditPropertyValue=function(a,b,d){function g(){f(D.value)}function f(f){e&&e.values&&e.values.constructor===Object&&void 0!=e.values[f]&&(f=e.values[f]);"number"==typeof a.properties[b]&&(f=Number(f));if("array"==c||"object"==c)f=JSON.parse(f);a.properties[b]=f;a.graph&&a.graph._version++;if(a.onPropertyChanged)a.onPropertyChanged(b,f);if(d.onclose)d.onclose();
|
||||
n.close();a.setDirtyCanvas(!0,!0)}if(a&&void 0!==a.properties[b]){d=d||{};var e=a.getPropertyInfo(b),c=e.type,k="";if("string"==c||"number"==c||"array"==c||"object"==c)k="<input autofocus type='text' class='value'/>";else if("enum"!=c&&"combo"!=c||!e.values)if("boolean"==c||"toggle"==c)k="<input autofocus type='checkbox' class='value' "+(a.properties[b]?"checked":"")+"/>";else{console.warn("unknown type: "+c);return}else{k="<select autofocus type='text' class='value'>";for(var q in e.values){var x=
|
||||
q;e.values.constructor===Array&&(x=e.values[q]);k+="<option value='"+x+"' "+(x==a.properties[b]?"selected":"")+">"+e.values[q]+"</option>"}k+="</select>"}var n=this.createDialog("<span class='name'>"+(e.label?e.label:b)+"</span>"+k+"<button>OK</button>",d),D=!1;if("enum"!=c&&"combo"!=c||!e.values)if("boolean"==c||"toggle"==c)(D=n.querySelector("input"))&&D.addEventListener("click",function(a){n.modified();f(!!D.checked)});else{if(D=n.querySelector("input"))D.addEventListener("blur",function(a){this.focus()}),
|
||||
x=void 0!==a.properties[b]?a.properties[b]:"","string"!==c&&(x=JSON.stringify(x)),D.value=x,D.addEventListener("keydown",function(a){if(27==a.keyCode)n.close();else if(13==a.keyCode)g();else if(13!=a.keyCode){n.modified();return}a.preventDefault();a.stopPropagation()})}else D=n.querySelector("select"),D.addEventListener("change",function(a){n.modified();f(a.target.value)});D&&D.focus();n.querySelector("button").addEventListener("click",g);return n}};h.prototype.createDialog=function(a,b){def_options=
|
||||
{checkForInput:!1,closeOnLeave:!0,closeOnLeave_checkModified:!0};b=Object.assign(def_options,b||{});var d=document.createElement("div");d.className="graphdialog";d.innerHTML=a;d.is_modified=!1;a=this.canvas.getBoundingClientRect();var g=-20,f=-20;a&&(g-=a.left,f-=a.top);b.position?(g+=b.position[0],f+=b.position[1]):b.event?(g+=b.event.clientX,f+=b.event.clientY):(g+=.5*this.canvas.width,f+=.5*this.canvas.height);d.style.left=g+"px";d.style.top=f+"px";this.canvas.parentNode.appendChild(d);b.checkForInput&&
|
||||
(a=[],(a=d.querySelectorAll("input"))&&a.forEach(function(a){a.addEventListener("keydown",function(a){d.modified();if(27==a.keyCode)d.close();else if(13!=a.keyCode)return;a.preventDefault();a.stopPropagation()});a.focus()}));d.modified=function(){d.is_modified=!0};d.close=function(){d.parentNode&&d.parentNode.removeChild(d)};var c=null,k=!1;d.addEventListener("mouseleave",function(a){k||(b.closeOnLeave||e.dialog_close_on_mouse_leave)&&!d.is_modified&&e.dialog_close_on_mouse_leave&&(c=setTimeout(d.close,
|
||||
e.dialog_close_on_mouse_leave_delay))});d.addEventListener("mouseenter",function(a){(b.closeOnLeave||e.dialog_close_on_mouse_leave)&&c&&clearTimeout(c)});(a=d.querySelectorAll("select"))&&a.forEach(function(a){a.addEventListener("click",function(a){k++});a.addEventListener("blur",function(a){k=0});a.addEventListener("change",function(a){k=-1})});return d};h.prototype.createPanel=function(a,b){b=b||{};var d=b.window||window,g=document.createElement("div");g.className="litegraph dialog";g.innerHTML=
|
||||
"<div class='dialog-header'><span class='dialog-title'></span></div><div class='dialog-content'></div><div style='display:none;' class='dialog-alt-content'></div><div class='dialog-footer'></div>";g.header=g.querySelector(".dialog-header");b.width&&(g.style.width=b.width+(b.width.constructor===Number?"px":""));b.height&&(g.style.height=b.height+(b.height.constructor===Number?"px":""));b.closable&&(b=document.createElement("span"),b.innerHTML="✕",b.classList.add("close"),b.addEventListener("click",
|
||||
function(){g.close()}),g.header.appendChild(b));g.title_element=g.querySelector(".dialog-title");g.title_element.innerText=a;g.content=g.querySelector(".dialog-content");g.alt_content=g.querySelector(".dialog-alt-content");g.footer=g.querySelector(".dialog-footer");g.close=function(){if(g.onClose&&"function"==typeof g.onClose)g.onClose();g.parentNode.removeChild(g);this.parentNode&&this.parentNode.removeChild(this)};g.toggleAltContent=function(a){if("undefined"!=typeof a){var b=a?"block":"none";a=
|
||||
a?"none":"block"}else b="block"!=g.alt_content.style.display?"block":"none",a="block"!=g.alt_content.style.display?"none":"block";g.alt_content.style.display=b;g.content.style.display=a};g.toggleFooterVisibility=function(a){g.footer.style.display="undefined"!=typeof a?a?"block":"none":"block"!=g.footer.style.display?"block":"none"};g.clear=function(){this.content.innerHTML=""};g.addHTML=function(a,b,d){var f=document.createElement("div");b&&(f.className=b);f.innerHTML=a;d?g.footer.appendChild(f):
|
||||
g.content.appendChild(f);return f};g.addButton=function(a,b,d){var f=document.createElement("button");f.innerText=a;f.options=d;f.classList.add("btn");f.addEventListener("click",b);g.footer.appendChild(f);return f};g.addSeparator=function(){var a=document.createElement("div");a.className="separator";g.content.appendChild(a)};g.addWidget=function(a,b,c,k,q){function f(a,b){k.callback&&k.callback(a,b,k);q&&q(a,b,k)}k=k||{};var m=String(c);a=a.toLowerCase();"number"==a&&(m=c.toFixed(3));var n=document.createElement("div");
|
||||
n.className="property";n.innerHTML="<span class='property_name'></span><span class='property_value'></span>";n.querySelector(".property_name").innerText=k.label||b;var u=n.querySelector(".property_value");u.innerText=m;n.dataset.property=b;n.dataset.type=k.type||a;n.options=k;n.value=c;if("code"==a)n.addEventListener("click",function(a){g.inner_showCodePad(this.dataset.property)});else if("boolean"==a)n.classList.add("boolean"),c&&n.classList.add("bool-on"),n.addEventListener("click",function(){var a=
|
||||
this.dataset.property;this.value=!this.value;this.classList.toggle("bool-on");this.querySelector(".property_value").innerText=this.value?"true":"false";f(a,this.value)});else if("string"==a||"number"==a)u.setAttribute("contenteditable",!0),u.addEventListener("keydown",function(b){"Enter"!=b.code||"string"==a&&b.shiftKey||(b.preventDefault(),this.blur())}),u.addEventListener("blur",function(){var a=this.innerText,b=this.parentNode.dataset.property;"number"==this.parentNode.dataset.type&&(a=Number(a));
|
||||
f(b,a)});else if("enum"==a||"combo"==a)m=h.getPropertyPrintableValue(c,k.values),u.innerText=m,u.addEventListener("click",function(a){var b=this.parentNode.dataset.property,g=this;new e.ContextMenu(k.values||[],{event:a,className:"dark",callback:function(a,d,e){g.innerText=a;f(b,a);return!1}},d)});g.content.appendChild(n);return n};if(g.onOpen&&"function"==typeof g.onOpen)g.onOpen();return g};h.getPropertyPrintableValue=function(a,b){if(!b||b.constructor===Array)return String(a);if(b.constructor===
|
||||
Object){var d="",g;for(g in b)if(b[g]==a){d=g;break}return String(a)+" ("+d+")"}};h.prototype.closePanels=function(){var a=document.querySelector("#node-panel");a&&a.close();(a=document.querySelector("#option-panel"))&&a.close()};h.prototype.showShowGraphOptionsPanel=function(a,b,d,g){if(this.constructor&&"HTMLDivElement"==this.constructor.name){if(!(b&&b.event&&b.event.target&&b.event.target.lgraphcanvas)){console.warn("Canvas not found");return}var f=b.event.target.lgraphcanvas}else f=this;f.closePanels();
|
||||
a=f.getCanvasWindow();panel=f.createPanel("Options",{closable:!0,window:a,onOpen:function(){f.OPTIONPANEL_IS_OPEN=!0},onClose:function(){f.OPTIONPANEL_IS_OPEN=!1;f.options_panel=null}});f.options_panel=panel;panel.id="option-panel";panel.classList.add("settings");(function(){panel.content.innerHTML="";var a=function(a,b,d){d&&d.key&&(a=d.key);d.values&&(b=Object.values(d.values).indexOf(b));f[a]=b},b=e.availableCanvasOptions;b.sort();for(pI in b){var d=b[pI];panel.addWidget("boolean",d,f[d],{key:d,
|
||||
on:"True",off:"False"},a)}panel.addWidget("combo","Render mode",e.LINK_RENDER_MODES[f.links_render_mode],{key:"links_render_mode",values:e.LINK_RENDER_MODES},a);panel.addSeparator();panel.footer.innerHTML=""})();f.canvas.parentNode.appendChild(panel)};h.prototype.showShowNodePanel=function(a){function b(){panel.content.innerHTML="";panel.addHTML("<span class='node_type'>"+a.type+"</span><span class='node_desc'>"+(a.constructor.desc||"")+"</span><span class='separator'></span>");panel.addHTML("<h3>Properties</h3>");
|
||||
var b=function(b,d){g.graph.beforeChange(a);switch(b){case "Title":a.title=d;break;case "Mode":b=Object.values(e.NODE_MODES).indexOf(d);0<=b&&e.NODE_MODES[b]?a.changeMode(b):console.warn("unexpected mode: "+d);break;case "Color":h.node_colors[d]?(a.color=h.node_colors[d].color,a.bgcolor=h.node_colors[d].bgcolor):console.warn("unexpected color: "+d);break;default:a.setProperty(b,d)}g.graph.afterChange();g.dirty_canvas=!0};panel.addWidget("string","Title",a.title,{},b);panel.addWidget("combo","Mode",
|
||||
e.NODE_MODES[a.mode],{values:e.NODE_MODES},b);var d="";void 0!==a.color&&(d=Object.keys(h.node_colors).filter(function(b){return h.node_colors[b].color==a.color}));panel.addWidget("combo","Color",d,{values:Object.keys(h.node_colors)},b);for(var c in a.properties){d=a.properties[c];var k=a.getPropertyInfo(c);a.onAddPropertyToPanel&&a.onAddPropertyToPanel(c,panel)||panel.addWidget(k.widget||k.type,c,d,k,b)}panel.addSeparator();if(a.onShowCustomPanelInfo)a.onShowCustomPanelInfo(panel);panel.footer.innerHTML=
|
||||
"";panel.addButton("Delete",function(){a.block_delete||(a.graph.remove(a),panel.close())}).classList.add("delete")}this.SELECTED_NODE=a;this.closePanels();var d=this.getCanvasWindow(),g=this;panel=this.createPanel(a.title||"",{closable:!0,window:d,onOpen:function(){g.NODEPANEL_IS_OPEN=!0},onClose:function(){g.NODEPANEL_IS_OPEN=!1;g.node_panel=null}});g.node_panel=panel;panel.id="node-panel";panel.node=a;panel.classList.add("settings");panel.inner_showCodePad=function(d){panel.classList.remove("settings");
|
||||
panel.classList.add("centered");panel.alt_content.innerHTML="<textarea class='code'></textarea>";var f=panel.alt_content.querySelector("textarea"),g=function(){panel.toggleAltContent(!1);panel.toggleFooterVisibility(!0);f.parentNode.removeChild(f);panel.classList.add("settings");panel.classList.remove("centered");b()};f.value=a.properties[d];f.addEventListener("keydown",function(b){"Enter"==b.code&&b.ctrlKey&&(a.setProperty(d,f.value),g())});panel.toggleAltContent(!0);panel.toggleFooterVisibility(!1);
|
||||
f.style.height="calc(100% - 40px)";var e=panel.addButton("Assign",function(){a.setProperty(d,f.value);g()});panel.alt_content.appendChild(e);e=panel.addButton("Close",g);e.style.float="right";panel.alt_content.appendChild(e)};b();this.canvas.parentNode.appendChild(panel)};h.prototype.showSubgraphPropertiesDialog=function(a){function b(){g.clear();if(a.inputs)for(var d=0;d<a.inputs.length;++d){var e=a.inputs[d];if(!e.not_subgraph_input){var c=g.addHTML("<button>✕</button> <span class='bullet_icon'></span><span class='name'></span><span class='type'></span>",
|
||||
"subgraph_property");c.dataset.name=e.name;c.dataset.slot=d;c.querySelector(".name").innerText=e.name;c.querySelector(".type").innerText=e.type;c.querySelector("button").addEventListener("click",function(d){a.removeInput(Number(this.parentNode.dataset.slot));b()})}}}console.log("showing subgraph properties dialog");var d=this.canvas.parentNode.querySelector(".subgraph_dialog");d&&d.close();var g=this.createPanel("Subgraph Inputs",{closable:!0,width:500});g.node=a;g.classList.add("subgraph_dialog");
|
||||
g.addHTML(" + <span class='label'>Name</span><input class='name'/><span class='label'>Type</span><input class='type'></input><button>+</button>","subgraph_property extra",!0).querySelector("button").addEventListener("click",function(d){d=this.parentNode;var f=d.querySelector(".name").value,g=d.querySelector(".type").value;f&&-1==a.findInputSlot(f)&&(a.addInput(f,g),d.querySelector(".name").value="",d.querySelector(".type").value="",b())});b();this.canvas.parentNode.appendChild(g);return g};h.prototype.showSubgraphPropertiesDialogRight=
|
||||
function(a){function b(){f.clear();if(a.outputs)for(var d=0;d<a.outputs.length;++d){var g=a.outputs[d];if(!g.not_subgraph_output){var e=f.addHTML("<button>✕</button> <span class='bullet_icon'></span><span class='name'></span><span class='type'></span>","subgraph_property");e.dataset.name=g.name;e.dataset.slot=d;e.querySelector(".name").innerText=g.name;e.querySelector(".type").innerText=g.type;e.querySelector("button").addEventListener("click",function(d){a.removeOutput(Number(this.parentNode.dataset.slot));
|
||||
b()})}}}function d(){var d=this.parentNode,f=d.querySelector(".name").value,g=d.querySelector(".type").value;f&&-1==a.findOutputSlot(f)&&(a.addOutput(f,g),d.querySelector(".name").value="",d.querySelector(".type").value="",b())}var g=this.canvas.parentNode.querySelector(".subgraph_dialog");g&&g.close();var f=this.createPanel("Subgraph Outputs",{closable:!0,width:500});f.node=a;f.classList.add("subgraph_dialog");g=f.addHTML(" + <span class='label'>Name</span><input class='name'/><span class='label'>Type</span><input class='type'></input><button>+</button>",
|
||||
"subgraph_property extra",!0);g.querySelector(".name").addEventListener("keydown",function(a){13==a.keyCode&&d.apply(this)});g.querySelector("button").addEventListener("click",function(a){d.apply(this)});b();this.canvas.parentNode.appendChild(f);return f};h.prototype.checkPanels=function(){if(this.canvas)for(var a=this.canvas.parentNode.querySelectorAll(".litegraph.dialog"),b=0;b<a.length;++b){var d=a[b];d.node&&(d.node.graph&&d.graph==this.graph||d.close())}};h.onMenuNodeCollapse=function(a,b,d,
|
||||
g,f){f.graph.beforeChange();a=h.active_canvas;if(!a.selected_nodes||1>=Object.keys(a.selected_nodes).length)f.collapse();else for(var e in a.selected_nodes)a.selected_nodes[e].collapse();f.graph.afterChange()};h.onMenuNodePin=function(a,b,d,g,f){f.pin()};h.onMenuNodeMode=function(a,b,d,g,f){new e.ContextMenu(e.NODE_MODES,{event:d,callback:function(a){if(f){var b=Object.values(e.NODE_MODES).indexOf(a),d=function(d){0<=b&&e.NODE_MODES[b]?d.changeMode(b):(console.warn("unexpected mode: "+a),d.changeMode(e.ALWAYS))},
|
||||
g=h.active_canvas;if(!g.selected_nodes||1>=Object.keys(g.selected_nodes).length)d(f);else for(var c in g.selected_nodes)d(g.selected_nodes[c])}},parentMenu:g,node:f});return!1};h.onMenuNodeColors=function(a,b,d,g,f){if(!f)throw"no node for color";b=[];b.push({value:null,content:"<span style='display: block; padding-left: 4px;'>No color</span>"});for(var c in h.node_colors)a=h.node_colors[c],a={value:c,content:"<span style='display: block; color: #999; padding-left: 4px; border-left: 8px solid "+a.color+
|
||||
"; background-color:"+a.bgcolor+"'>"+c+"</span>"},b.push(a);new e.ContextMenu(b,{event:d,callback:function(a){if(f){var b=a.value?h.node_colors[a.value]:null;a=function(a){b?a.constructor===e.LGraphGroup?a.color=b.groupcolor:(a.color=b.color,a.bgcolor=b.bgcolor):(delete a.color,delete a.bgcolor)};var d=h.active_canvas;if(!d.selected_nodes||1>=Object.keys(d.selected_nodes).length)a(f);else for(var g in d.selected_nodes)a(d.selected_nodes[g]);f.setDirtyCanvas(!0,!0)}},parentMenu:g,node:f});return!1};
|
||||
h.onMenuNodeShapes=function(a,b,d,g,f){if(!f)throw"no node passed";new e.ContextMenu(e.VALID_SHAPES,{event:d,callback:function(a){if(f){f.graph.beforeChange();var b=h.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)f.shape=a;else for(var d in b.selected_nodes)b.selected_nodes[d].shape=a;f.graph.afterChange();f.setDirtyCanvas(!0)}},parentMenu:g,node:f});return!1};h.onMenuNodeRemove=function(a,b,d,g,f){if(!f)throw"no node passed";a=f.graph;a.beforeChange();b=h.active_canvas;
|
||||
if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)!1!==f.removable&&a.remove(f);else for(var e in b.selected_nodes)d=b.selected_nodes[e],!1!==d.removable&&a.remove(d);a.afterChange();f.setDirtyCanvas(!0,!0)};h.onMenuNodeToSubgraph=function(a,b,d,g,f){a=f.graph;if(b=h.active_canvas)d=Object.values(b.selected_nodes||{}),d.length||(d=[f]),g=e.createNode("graph/subgraph"),g.pos=f.pos.concat(),a.add(g),g.buildFromNodes(d),b.deselectAllNodes(),f.setDirtyCanvas(!0,!0)};h.onMenuNodeClone=function(a,
|
||||
b,d,g,f){f.graph.beforeChange();var e={};a=function(a){if(0!=a.clonable){var b=a.clone();b&&(b.pos=[a.pos[0]+5,a.pos[1]+5],a.graph.add(b),e[b.id]=b)}};b=h.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)a(f);else for(var c in b.selected_nodes)a(b.selected_nodes[c]);Object.keys(e).length&&b.selectNodes(e);f.graph.afterChange();f.setDirtyCanvas(!0,!0)};h.node_colors={red:{color:"#322",bgcolor:"#533",groupcolor:"#A88"},brown:{color:"#332922",bgcolor:"#593930",groupcolor:"#b06634"},
|
||||
green:{color:"#232",bgcolor:"#353",groupcolor:"#8A8"},blue:{color:"#223",bgcolor:"#335",groupcolor:"#88A"},pale_blue:{color:"#2a363b",bgcolor:"#3f5159",groupcolor:"#3f789e"},cyan:{color:"#233",bgcolor:"#355",groupcolor:"#8AA"},purple:{color:"#323",bgcolor:"#535",groupcolor:"#a1309b"},yellow:{color:"#432",bgcolor:"#653",groupcolor:"#b58b2a"},black:{color:"#222",bgcolor:"#000",groupcolor:"#444"}};h.prototype.getCanvasMenuOptions=function(){if(this.getMenuOptions)var a=this.getMenuOptions();else a=[{content:"Add Node",
|
||||
has_submenu:!0,callback:h.onMenuAdd},{content:"Add Group",callback:h.onGroupAdd}],this._graph_stack&&0<this._graph_stack.length&&a.push(null,{content:"Close subgraph",callback:this.closeSubgraph.bind(this)});if(this.getExtraMenuOptions){var b=this.getExtraMenuOptions(this,a);b&&(a=a.concat(b))}return a};h.prototype.getNodeMenuOptions=function(a){if(a.getMenuOptions)var b=a.getMenuOptions(this);else b=[{content:"Inputs",has_submenu:!0,disabled:!0,callback:h.showMenuNodeOptionalInputs},{content:"Outputs",
|
||||
has_submenu:!0,disabled:!0,callback:h.showMenuNodeOptionalOutputs},null,{content:"Properties",has_submenu:!0,callback:h.onShowMenuNodeProperties},null,{content:"Title",callback:h.onShowPropertyEditor},{content:"Mode",has_submenu:!0,callback:h.onMenuNodeMode}],!1!==a.resizable&&b.push({content:"Resize",callback:h.onMenuResizeNode}),b.push({content:"Collapse",callback:h.onMenuNodeCollapse},{content:"Pin",callback:h.onMenuNodePin},{content:"Colors",has_submenu:!0,callback:h.onMenuNodeColors},{content:"Shapes",
|
||||
has_submenu:!0,callback:h.onMenuNodeShapes},null);if(a.onGetInputs){var 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,b))&&(d.push(null),b=d.concat(b));!1!==a.clonable&&b.push({content:"Clone",callback:h.onMenuNodeClone});b.push(null,{content:"Remove",disabled:!(!1!==a.removable&&!a.block_delete),callback:h.onMenuNodeRemove});if(a.graph&&a.graph.onGetNodeMenuOptions)a.graph.onGetNodeMenuOptions(b,
|
||||
a);return b};h.prototype.getGroupMenuOptions=function(a){return[{content:"Title",callback:h.onShowPropertyEditor},{content:"Color",has_submenu:!0,callback:h.onMenuNodeColors},{content:"Font size",property:"font_size",type:"Number",callback:h.onShowPropertyEditor},null,{content:"Remove",callback:h.onMenuNodeRemove}]};h.prototype.processContextMenu=function(a,b){var d=this,g=h.active_canvas.getCanvasWindow(),f=null,c={event:b,callback:function(b,f,g){if(b)if("Remove Slot"==b.content)b=b.slot,a.graph.beforeChange(),
|
||||
b.input?a.removeInput(b.slot):b.output&&a.removeOutput(b.slot),a.graph.afterChange();else if("Disconnect Links"==b.content)b=b.slot,a.graph.beforeChange(),b.output?a.disconnectOutput(b.slot):b.input&&a.disconnectInput(b.slot),a.graph.afterChange();else if("Rename Slot"==b.content){b=b.slot;var e=b.input?a.getInputInfo(b.slot):a.getOutputInfo(b.slot),c=d.createDialog("<span class='name'>Name</span><input autofocus type='text'/><button>OK</button>",f),k=c.querySelector("input");k&&e&&(k.value=e.label||
|
||||
"");var m=function(){a.graph.beforeChange();k.value&&(e&&(e.label=k.value),d.setDirty(!0));c.close();a.graph.afterChange()};c.querySelector("button").addEventListener("click",m);k.addEventListener("keydown",function(a){c.is_modified=!0;if(27==a.keyCode)c.close();else if(13==a.keyCode)m();else if(13!=a.keyCode&&"textarea"!=a.target.localName)return;a.preventDefault();a.stopPropagation()});k.focus()}},extra:a};a&&(c.title=a.type);var k=null;a&&(k=a.getSlotInPosition(b.canvasX,b.canvasY),h.active_node=
|
||||
a);k?(f=[],a.getSlotMenuOptions?f=a.getSlotMenuOptions(k):(k&&k.output&&k.output.links&&k.output.links.length&&f.push({content:"Disconnect Links",slot:k}),b=k.input||k.output,b.removable&&f.push(b.locked?"Cannot remove":{content:"Remove Slot",slot:k}),b.nameLocked||f.push({content:"Rename Slot",slot:k})),c.title=(k.input?k.input.type:k.output.type)||"*",k.input&&k.input.type==e.ACTION&&(c.title="Action"),k.output&&k.output.type==e.EVENT&&(c.title="Event")):a?f=this.getNodeMenuOptions(a):(f=this.getCanvasMenuOptions(),
|
||||
(k=this.graph.getGroupOnPos(b.canvasX,b.canvasY))&&f.push(null,{content:"Edit Group",has_submenu:!0,submenu:{title:"Group",extra:k,options:this.getGroupMenuOptions(k)}}));f&&new e.ContextMenu(f,c,g)};"undefined"!=typeof window&&window.CanvasRenderingContext2D&&!window.CanvasRenderingContext2D.prototype.roundRect&&(window.CanvasRenderingContext2D.prototype.roundRect=function(a,b,d,g,f,e){var c,k;if(0===f)this.rect(a,b,d,g);else{void 0===e&&(e=f);if(null!=f&&f.constructor===Array)if(1==f.length)var m=
|
||||
c=k=e=f[0];else if(2==f.length)m=e=f[0],c=k=f[1];else if(4==f.length)m=f[0],c=f[1],k=f[2],e=f[3];else return;else m=f||0,c=f||0,k=e||0,e=e||0;this.moveTo(a+m,b);this.lineTo(a+d-c,b);this.quadraticCurveTo(a+d,b,a+d,b+c);this.lineTo(a+d,b+g-e);this.quadraticCurveTo(a+d,b+g,a+d-e,b+g);this.lineTo(a+e,b+g);this.quadraticCurveTo(a,b+g,a,b+g-k);this.lineTo(a,b+k);this.quadraticCurveTo(a,b,a+m,b)}});e.compareObjects=function(a,b){for(var d in a)if(a[d]!=b[d])return!1;return!0};e.distance=E;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=A;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=I;e.hex2num=function(a){"#"==a.charAt(0)&&(a=a.slice(1));a=a.toUpperCase();for(var b=Array(3),
|
||||
d=0,g,f,e=0;6>e;e+=2)g="0123456789ABCDEF".indexOf(a.charAt(e)),f="0123456789ABCDEF".indexOf(a.charAt(e+1)),b[d]=16*g+f,d++;return b};e.num2hex=function(a){for(var b="#",d,g,f=0;3>f;f++)d=a[f]/16,g=a[f]%16,b+="0123456789ABCDEF".charAt(d)+"0123456789ABCDEF".charAt(g);return b};J.prototype.addItem=function(a,b,d){function g(a){var b=this.value;b&&b.has_submenu&&f.call(this,a)}function f(a){var b=this.value,f=!0;c.current_submenu&&c.current_submenu.close(a);if(d.callback){var g=d.callback.call(this,b,
|
||||
d,a,c,d.node);!0===g&&(f=!1)}if(b&&(b.callback&&!d.ignore_item_callbacks&&!0!==b.disabled&&(g=b.callback.call(this,b,d,a,c,d.extra),!0===g&&(f=!1)),b.submenu)){if(!b.submenu.options)throw"ContextMenu submenu needs options";new c.constructor(b.submenu.options,{callback:b.submenu.callback,event:a,parentMenu:c,ignore_item_callbacks:b.submenu.ignore_item_callbacks,title:b.submenu.title,extra:b.submenu.extra,autoopen:d.autoopen});f=!1}f&&!c.lock&&c.close()}var c=this;d=d||{};var k=document.createElement("div");
|
||||
k.className="litemenu-entry submenu";var q=!1;if(null===b)k.classList.add("separator");else{k.innerHTML=b&&b.title?b.title:a;if(k.value=b)b.disabled&&(q=!0,k.classList.add("disabled")),(b.submenu||b.has_submenu)&&k.classList.add("has_submenu");"function"==typeof b?(k.dataset.value=a,k.onclick_callback=b):k.dataset.value=b;b.className&&(k.className+=" "+b.className)}this.root.appendChild(k);q||k.addEventListener("click",f);d.autoopen&&e.pointerListenerAdd(k,"enter",g);return k};J.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&&!J.isCursorOverElement(a,this.parentMenu.root)&&J.trigger(this.parentMenu.root,e.pointerevents_method+"leave",a));this.current_submenu&&this.current_submenu.close(a,!0);this.root.closing_timer&&clearTimeout(this.root.closing_timer)};J.trigger=function(a,b,d,g){var f=document.createEvent("CustomEvent");f.initCustomEvent(b,
|
||||
!0,!0,d);f.srcElement=g;a.dispatchEvent?a.dispatchEvent(f):a.__events&&a.__events.dispatchEvent(f);return f};J.prototype.getTopMenu=function(){return this.options.parentMenu?this.options.parentMenu.getTopMenu():this};J.prototype.getFirstEvent=function(){return this.options.parentMenu?this.options.parentMenu.getFirstEvent():this.options.event};J.isCursorOverElement=function(a,b){var d=a.clientX;a=a.clientY;return(b=b.getBoundingClientRect())?a>b.top&&a<b.top+b.height&&d>b.left&&d<b.left+b.width?!0:
|
||||
!1:!1};e.ContextMenu=J;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=0;d<b.length;d++)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)))};F.sampleCurve=function(a,b){if(b){for(var d=0;d<b.length-1;++d){var g=b[d],f=b[d+1];if(!(f[0]<a)){b=f[0]-g[0];if(1E-5>Math.abs(b))return g[1];a=(a-g[0])/b;return g[1]*(1-a)+f[1]*a}}return 0}};F.prototype.draw=function(a,b,d,g,f,e){if(d=this.points){this.size=b;var c=b[0]-2*this.margin;b=b[1]-2*this.margin;f=f||"#666";a.save();a.translate(this.margin,
|
||||
this.margin);g&&(a.fillStyle="#111",a.fillRect(0,0,c,b),a.fillStyle="#222",a.fillRect(.5*c,0,1,b),a.strokeStyle="#333",a.strokeRect(0,0,c,b));a.strokeStyle=f;e&&(a.globalAlpha=.5);a.beginPath();for(g=0;g<d.length;++g)f=d[g],a.lineTo(f[0]*c,(1-f[1])*b);a.stroke();a.globalAlpha=1;if(!e)for(g=0;g<d.length;++g)f=d[g],a.fillStyle=this.selected==g?"#FFF":this.nearest==g?"#DDD":"#AAA",a.beginPath(),a.arc(f[0]*c,(1-f[1])*b,2,0,2*Math.PI),a.fill();a.restore()}};F.prototype.onMouseDown=function(a,b){var d=
|
||||
this.points;if(d&&!(0>a[1])){var g=this.size[0]-2*this.margin,f=this.size[1]-2*this.margin,e=a[0]-this.margin;a=a[1]-this.margin;this.selected=this.getCloserPoint([e,a],30/b.ds.scale);-1==this.selected&&(b=[e/g,1-a/f],d.push(b),d.sort(function(a,b){return a[0]-b[0]}),this.selected=d.indexOf(b),this.must_update=!0);if(-1!=this.selected)return!0}};F.prototype.onMouseMove=function(a,b){var d=this.points;if(d){var g=this.selected;if(!(0>g)){var f=(a[0]-this.margin)/(this.size[0]-2*this.margin),e=(a[1]-
|
||||
this.margin)/(this.size[1]-2*this.margin);this._nearest=this.getCloserPoint([a[0]-this.margin,a[1]-this.margin],30/b.ds.scale);if(b=d[g]){var c=0==g||g==d.length-1;!c&&(-10>a[0]||a[0]>this.size[0]+10||-10>a[1]||a[1]>this.size[1]+10)?(d.splice(g,1),this.selected=-1):(b[0]=c?0==g?0:1:Math.clamp(f,0,1),b[1]=1-Math.clamp(e,0,1),d.sort(function(a,b){return a[0]-b[0]}),this.selected=d.indexOf(b),this.must_update=!0)}}}};F.prototype.onMouseUp=function(a,b){this.selected=-1;return!1};F.prototype.getCloserPoint=
|
||||
function(a,b){var d=this.points;if(!d)return-1;b=b||30;for(var g=this.size[0]-2*this.margin,f=this.size[1]-2*this.margin,e=d.length,c=[0,0],k=1E6,q=-1,x=0;x<e;++x){var n=d[x];c[0]=n[0]*g;c[1]=(1-n[1])*f;n=vec2.distance(a,c);n>k||n>b||(q=x,k=n)}return q};e.CurveEditor=F;e.getParameterNames=function(a){return(a+"").replace(/[/][/].*$/gm,"").replace(/\s+/g,"").replace(/[/][*][^/*]*[*][/]/g,"").split("){",1)[0].replace(/^[^(]*[(]/,"").replace(/=[^,]+/g,"").split(",").filter(Boolean)};e.pointerListenerAdd=
|
||||
function(a,b,d,g){g=void 0===g?!1:g;if(a&&a.addEventListener&&b&&"function"===typeof d){var f=e.pointerevents_method;if("pointer"==f&&!window.PointerEvent)switch(console.warn("sMethod=='pointer' && !window.PointerEvent"),console.log("Converting pointer["+b+"] : down move up cancel enter TO touchstart touchmove touchend, etc .."),b){case "down":f="touch";b="start";break;case "move":f="touch";break;case "up":f="touch";b="end";break;case "cancel":f="touch";break;case "enter":console.log("debug: Should I send a move event?");
|
||||
break;default:console.warn("PointerEvent not available in this browser ? The event "+b+" would not be called")}switch(b){case "down":case "up":case "move":case "over":case "out":case "enter":a.addEventListener(f+b,d,g);case "leave":case "cancel":case "gotpointercapture":case "lostpointercapture":if("mouse"!=f)return a.addEventListener(f+b,d,g);default:return a.addEventListener(b,d,g)}}};e.pointerListenerRemove=function(a,b,d,g){g=void 0===g?!1:g;if(a&&a.removeEventListener&&b&&"function"===typeof d)switch(b){case "down":case "up":case "move":case "over":case "out":case "enter":"pointer"!=
|
||||
e.pointerevents_method&&"mouse"!=e.pointerevents_method||a.removeEventListener(e.pointerevents_method+b,d,g);case "leave":case "cancel":case "gotpointercapture":case "lostpointercapture":if("pointer"==e.pointerevents_method)return a.removeEventListener(e.pointerevents_method+b,d,g);default:return a.removeEventListener(b,d,g)}};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(B){function c(){this.addOutput("in ms","number");this.addOutput("in sec","number")}function l(){this.size=[140,80];this.properties={enabled:!0};this.enabled=!0;this.subgraph=new K.LGraph;this.subgraph._subgraph_node=this;this.subgraph._is_subgraph=!0;this.subgraph.onTrigger=this.onSubgraphTrigger.bind(this);this.subgraph.onInputAdded=this.onSubgraphNewInput.bind(this);this.subgraph.onInputRenamed=this.onSubgraphRenamedInput.bind(this);this.subgraph.onInputTypeChanged=this.onSubgraphTypeChangeInput.bind(this);
|
||||
this.subgraph.onInputRemoved=this.onSubgraphRemovedInput.bind(this);this.subgraph.onOutputAdded=this.onSubgraphNewOutput.bind(this);this.subgraph.onOutputRenamed=this.onSubgraphRenamedOutput.bind(this);this.subgraph.onOutputTypeChanged=this.onSubgraphTypeChangeOutput.bind(this);this.subgraph.onOutputRemoved=this.onSubgraphRemovedOutput.bind(this)}function r(){this.addOutput("","number");this.name_in_graph="";this.properties={name:"",type:"number",value:0};var a=this;this.name_widget=this.addWidget("text",
|
||||
"Name",this.properties.name,function(b){b&&a.setProperty("name",b)});this.type_widget=this.addWidget("text","Type",this.properties.type,function(b){a.setProperty("type",b)});this.value_widget=this.addWidget("number","Value",this.properties.value,function(b){a.setProperty("value",b)});this.widgets_up=!0;this.size=[180,90]}function t(){this.addInput("","");this.name_in_graph="";this.properties={};this.name_widget=this.addWidget("text","Name",this.properties.name,"name");this.type_widget=this.addWidget("text",
|
||||
|
||||
@@ -7473,7 +7473,9 @@ LGraphNode.prototype.executeAction = function(action)
|
||||
* @method adjustMouseEvent
|
||||
**/
|
||||
LGraphCanvas.prototype.adjustMouseEvent = function(e) {
|
||||
|
||||
var clientX_rel = 0;
|
||||
var clientY_rel = 0;
|
||||
|
||||
if (this.canvas) {
|
||||
var b = this.canvas.getBoundingClientRect();
|
||||
clientX_rel = e.clientX - b.left;
|
||||
|
||||
322
build/litegraph_mini.min.js
vendored
322
build/litegraph_mini.min.js
vendored
@@ -183,167 +183,167 @@ function(a){if(this.onShowNodePanel)this.onShowNodePanel(a);else this.showShowNo
|
||||
a.is_selected=!1;if(this.onNodeDeselected)this.onNodeDeselected(a);if(a.inputs)for(var b=0;b<a.inputs.length;++b)delete this.highlighted_links[a.inputs[b].link];if(a.outputs)for(b=0;b<a.outputs.length;++b){var c=a.outputs[b];if(c.links)for(var e=0;e<c.links.length;++e)delete this.highlighted_links[c.links[e]]}}};h.prototype.deselectAllNodes=function(){if(this.graph){for(var a=this.graph._nodes,b=0,c=a.length;b<c;++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)}};h.prototype.deleteSelectedNodes=function(){this.graph.beforeChange();for(var a in this.selected_nodes){var b=this.selected_nodes[a];if(!b.block_delete){if(b.inputs&&b.inputs.length&&b.outputs&&b.outputs.length&&f.isValidConnection(b.inputs[0].type,b.outputs[0].type)&&b.inputs[0].link&&b.outputs[0].links&&
|
||||
b.outputs[0].links.length){var c=b.graph.links[b.inputs[0].link],e=b.graph.links[b.outputs[0].links[0]],d=b.getInputNode(0),g=b.getOutputNodes(0)[0];d&&g&&d.connect(c.origin_slot,g,e.target_slot)}this.graph.remove(b);if(this.onNodeDeselected)this.onNodeDeselected(b)}}this.selected_nodes={};this.current_node=null;this.highlighted_links={};this.setDirty(!0);this.graph.afterChange()};h.prototype.centerOnNode=function(a){this.ds.offset[0]=-a.pos[0]-.5*a.size[0]+.5*this.canvas.width/this.ds.scale;this.ds.offset[1]=
|
||||
-a.pos[1]-.5*a.size[1]+.5*this.canvas.height/this.ds.scale;this.setDirty(!0,!0)};h.prototype.adjustMouseEvent=function(a){if(this.canvas){var b=this.canvas.getBoundingClientRect();clientX_rel=a.clientX-b.left;clientY_rel=a.clientY-b.top}else clientX_rel=a.clientX,clientY_rel=a.clientY;a.deltaX=clientX_rel-this.last_mouse_position[0];a.deltaY=clientY_rel-this.last_mouse_position[1];this.last_mouse_position[0]=clientX_rel;this.last_mouse_position[1]=clientY_rel;a.canvasX=clientX_rel/this.ds.scale-this.ds.offset[0];
|
||||
a.canvasY=clientY_rel/this.ds.scale-this.ds.offset[1]};h.prototype.setZoom=function(a,b){this.ds.changeScale(a,b);this.dirty_bgcanvas=this.dirty_canvas=!0};h.prototype.convertOffsetToCanvas=function(a,b){return this.ds.convertOffsetToCanvas(a,b)};h.prototype.convertCanvasToOffset=function(a,b){return this.ds.convertCanvasToOffset(a,b)};h.prototype.convertEventToCanvasOffset=function(a){var b=this.canvas.getBoundingClientRect();return this.convertCanvasToOffset([a.clientX-b.left,a.clientY-b.top])};
|
||||
h.prototype.bringToFront=function(a){var b=this.graph._nodes.indexOf(a);-1!=b&&(this.graph._nodes.splice(b,1),this.graph._nodes.push(a))};h.prototype.sendToBack=function(a){var b=this.graph._nodes.indexOf(a);-1!=b&&(this.graph._nodes.splice(b,1),this.graph._nodes.unshift(a))};var L=new Float32Array(4);h.prototype.computeVisibleNodes=function(a,b){b=b||[];b.length=0;a=a||this.graph._nodes;for(var c=0,e=a.length;c<e;++c){var d=a[c];(!this.live_mode||d.onDrawBackground||d.onDrawForeground)&&A(this.visible_area,
|
||||
d.getBounding(L))&&b.push(d)}return b};h.prototype.draw=function(a,b){if(this.canvas&&0!=this.canvas.width&&0!=this.canvas.height){var c=f.getTime();this.render_time=.001*(c-this.last_draw_time);this.last_draw_time=c;this.graph&&this.ds.computeVisibleArea(this.viewport);(this.dirty_bgcanvas||b||this.always_render_background||this.graph&&this.graph._last_trigger_time&&1E3>c-this.graph._last_trigger_time)&&this.drawBackCanvas();(this.dirty_canvas||a)&&this.drawFrontCanvas();this.fps=this.render_time?
|
||||
1/this.render_time:0;this.frame+=1}};h.prototype.drawFrontCanvas=function(){this.dirty_canvas=!1;this.ctx||(this.ctx=this.bgcanvas.getContext("2d"));var a=this.ctx;if(a){var b=this.canvas;a.start2D&&!this.viewport&&(a.start2D(),a.restore(),a.setTransform(1,0,0,1,0,0));var c=this.viewport||this.dirty_area;c&&(a.save(),a.beginPath(),a.rect(c[0],c[1],c[2],c[3]),a.clip());this.clear_background&&(c?a.clearRect(c[0],c[1],c[2],c[3]):a.clearRect(0,0,b.width,b.height));this.bgcanvas==this.canvas?this.drawBackCanvas():
|
||||
a.drawImage(this.bgcanvas,0,0);if(this.onRender)this.onRender(b,a);this.show_info&&this.renderInfo(a,c?c[0]:0,c?c[1]:0);if(this.graph){a.save();this.ds.toCanvasContext(a);b=this.computeVisibleNodes(null,this.visible_nodes);for(var e=0;e<b.length;++e){var d=b[e];a.save();a.translate(d.pos[0],d.pos[1]);this.drawNode(d,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;d=this.connecting_output||this.connecting_input;b=d.type;e=d.dir;null==e&&(e=this.connecting_output?this.connecting_node.horizontal?f.DOWN:f.RIGHT:this.connecting_node.horizontal?f.UP:f.LEFT);var g=d.shape;switch(b){case f.EVENT:d=f.EVENT_LINK_COLOR;break;default:d=f.CONNECTING_LINK_COLOR}this.renderLink(a,this.connecting_pos,[this.graph_mouse[0],this.graph_mouse[1]],null,!1,null,d,e,f.CENTER);a.beginPath();b===f.EVENT||g===f.BOX_SHAPE?(a.rect(this.connecting_pos[0]-6+.5,this.connecting_pos[1]-
|
||||
5+.5,14,10),a.fill(),a.beginPath(),a.rect(this.graph_mouse[0]-6+.5,this.graph_mouse[1]-5+.5,14,10)):g===f.ARROW_SHAPE?(a.moveTo(this.connecting_pos[0]+8,this.connecting_pos[1]+.5),a.lineTo(this.connecting_pos[0]-4,this.connecting_pos[1]+6+.5),a.lineTo(this.connecting_pos[0]-4,this.connecting_pos[1]-6+.5),a.closePath()):(a.arc(this.connecting_pos[0],this.connecting_pos[1],4,0,2*Math.PI),a.fill(),a.beginPath(),a.arc(this.graph_mouse[0],this.graph_mouse[1],4,0,2*Math.PI));a.fill();a.fillStyle="#ffcc00";
|
||||
if(this._highlight_input){a.beginPath();var k=this._highlight_input_slot.shape;k===f.ARROW_SHAPE?(a.moveTo(this._highlight_input[0]+8,this._highlight_input[1]+.5),a.lineTo(this._highlight_input[0]-4,this._highlight_input[1]+6+.5),a.lineTo(this._highlight_input[0]-4,this._highlight_input[1]-6+.5),a.closePath()):a.arc(this._highlight_input[0],this._highlight_input[1],6,0,2*Math.PI);a.fill()}this._highlight_output&&(a.beginPath(),k===f.ARROW_SHAPE?(a.moveTo(this._highlight_output[0]+8,this._highlight_output[1]+
|
||||
.5),a.lineTo(this._highlight_output[0]-4,this._highlight_output[1]+6+.5),a.lineTo(this._highlight_output[0]-4,this._highlight_output[1]-6+.5),a.closePath()):a.arc(this._highlight_output[0],this._highlight_output[1],6,0,2*Math.PI),a.fill())}this.dragging_rectangle&&(a.strokeStyle="#FFF",a.strokeRect(this.dragging_rectangle[0],this.dragging_rectangle[1],this.dragging_rectangle[2],this.dragging_rectangle[3]));if(this.over_link_center&&this.render_link_tooltip)this.drawLinkTooltip(a,this.over_link_center);
|
||||
else if(this.onDrawLinkTooltip)this.onDrawLinkTooltip(a,null);if(this.onDrawForeground)this.onDrawForeground(a,this.visible_rect);a.restore()}this._graph_stack&&this._graph_stack.length&&this.drawSubgraphPanel(a);if(this.onDrawOverlay)this.onDrawOverlay(a);c&&a.restore();a.finish2D&&a.finish2D()}};h.prototype.drawSubgraphPanel=function(a){var b=this.graph,c=b._subgraph_node;c?(this.drawSubgraphPanelLeft(b,c,a),this.drawSubgraphPanelRight(b,c,a)):console.warn("subgraph without subnode")};h.prototype.drawSubgraphPanelLeft=
|
||||
function(a,b,c){var e=b.inputs?b.inputs.length:0,d=Math.floor(1.6*f.NODE_SLOT_HEIGHT);c.fillStyle="#111";c.globalAlpha=.8;c.beginPath();c.roundRect(10,10,200,(e+1)*d+50,[8]);c.fill();c.globalAlpha=1;c.fillStyle="#888";c.font="14px Arial";c.textAlign="left";c.fillText("Graph Inputs",20,34);if(this.drawButton(180,20,20,20,"X","#151515"))this.closeSubgraph();else{e=50;c.font="14px Arial";if(b.inputs)for(var g=0;g<b.inputs.length;++g){var k=b.inputs[g];if(!k.not_subgraph_input){if(this.drawButton(20,
|
||||
e+2,180,d-2)){var n=b.constructor.input_node_type||"graph/input";this.graph.beforeChange();var p=f.createNode(n);p?(a.add(p),this.block_click=!1,this.last_click_position=null,this.selectNodes([p]),this.node_dragged=p,this.dragging_canvas=!1,p.setProperty("name",k.name),p.setProperty("type",k.type),this.node_dragged.pos[0]=this.graph_mouse[0]-5,this.node_dragged.pos[1]=this.graph_mouse[1]-5,this.graph.afterChange()):console.error("graph input node not found:",n)}c.fillStyle="#9C9";c.beginPath();c.arc(184,
|
||||
e+.5*d,5,0,2*Math.PI);c.fill();c.fillStyle="#AAA";c.fillText(k.name,30,e+.75*d);c.fillStyle="#777";c.fillText(k.type,130,e+.75*d);e+=d}}this.drawButton(20,e+2,180,d-2,"+","#151515","#222")&&this.showSubgraphPropertiesDialog(b)}};h.prototype.drawSubgraphPanelRight=function(a,b,c){var e=b.outputs?b.outputs.length:0,d=this.bgcanvas.width,g=Math.floor(1.6*f.NODE_SLOT_HEIGHT);c.fillStyle="#111";c.globalAlpha=.8;c.beginPath();c.roundRect(d-200-10,10,200,(e+1)*g+50,[8]);c.fill();c.globalAlpha=1;c.fillStyle=
|
||||
"#888";c.font="14px Arial";c.textAlign="left";e=c.measureText("Graph Outputs").width;c.fillText("Graph Outputs",d-e-20,34);if(this.drawButton(d-200,20,20,20,"X","#151515"))this.closeSubgraph();else{e=50;c.font="14px Arial";if(b.outputs)for(var k=0;k<b.outputs.length;++k){var n=b.outputs[k];if(!n.not_subgraph_input){if(this.drawButton(d-200,e+2,180,g-2)){var p=b.constructor.output_node_type||"graph/output";this.graph.beforeChange();var r=f.createNode(p);r?(a.add(r),this.block_click=!1,this.last_click_position=
|
||||
null,this.selectNodes([r]),this.node_dragged=r,this.dragging_canvas=!1,r.setProperty("name",n.name),r.setProperty("type",n.type),this.node_dragged.pos[0]=this.graph_mouse[0]-5,this.node_dragged.pos[1]=this.graph_mouse[1]-5,this.graph.afterChange()):console.error("graph input node not found:",p)}c.fillStyle="#9C9";c.beginPath();c.arc(d-200+16,e+.5*g,5,0,2*Math.PI);c.fill();c.fillStyle="#AAA";c.fillText(n.name,d-200+30,e+.75*g);c.fillStyle="#777";c.fillText(n.type,d-200+130,e+.75*g);e+=g}}this.drawButton(d-
|
||||
200,e+2,180,g-2,"+","#151515","#222")&&this.showSubgraphPropertiesDialogRight(b)}};h.prototype.drawButton=function(a,b,c,e,d,g,k,n){var p=this.ctx;g=g||f.NODE_DEFAULT_COLOR;k=k||"#555";n=n||f.NODE_TEXT_COLOR;var r=b+f.NODE_TITLE_HEIGHT+2,u=this.mouse,q=f.isInsideRectangle(u[0],u[1],a,r,c,e);r=(u=this.last_click_position)&&f.isInsideRectangle(u[0],u[1],a,r,c,e);p.fillStyle=q?k:g;r&&(p.fillStyle="#AAA");p.beginPath();p.roundRect(a,b,c,e,[4]);p.fill();null!=d&&d.constructor==String&&(p.fillStyle=n,p.textAlign=
|
||||
"center",p.font=(.65*e|0)+"px Arial",p.fillText(d,a+.5*c,b+.75*e),p.textAlign="left");a=r&&!this.block_click;r&&this.blockClick();return a};h.prototype.isAreaClicked=function(a,b,c,e,d){var g=this.mouse;f.isInsideRectangle(g[0],g[1],a,b,c,e);b=(a=(g=this.last_click_position)&&f.isInsideRectangle(g[0],g[1],a,b,c,e))&&!this.block_click;a&&d&&this.blockClick();return b};h.prototype.renderInfo=function(a,b,c){b=b||10;c=c||this.canvas.height-80;a.save();a.translate(b,c);a.font="10px Arial";a.fillStyle=
|
||||
"#888";a.textAlign="left";this.graph?(a.fillText("T: "+this.graph.globaltime.toFixed(2)+"s",5,13),a.fillText("I: "+this.graph.iteration,5,26),a.fillText("N: "+this.graph._nodes.length+" ["+this.visible_nodes.length+"]",5,39),a.fillText("V: "+this.graph._version,5,52),a.fillText("FPS:"+this.fps.toFixed(2),5,65)):a.fillText("No graph selected",5,13);a.restore()};h.prototype.drawBackCanvas=function(){var a=this.bgcanvas;if(a.width!=this.canvas.width||a.height!=this.canvas.height)a.width=this.canvas.width,
|
||||
a.height=this.canvas.height;this.bgctx||(this.bgctx=this.bgcanvas.getContext("2d"));var b=this.bgctx;b.start&&b.start();var c=this.viewport||[0,0,b.canvas.width,b.canvas.height];this.clear_background&&b.clearRect(c[0],c[1],c[2],c[3]);if(this._graph_stack&&this._graph_stack.length){b.save();c=this.graph._subgraph_node;b.strokeStyle=c.bgcolor;b.lineWidth=10;b.strokeRect(1,1,a.width-2,a.height-2);b.lineWidth=1;b.font="40px Arial";b.textAlign="center";b.fillStyle=c.bgcolor||"#AAA";for(var e="",d=1;d<
|
||||
this._graph_stack.length;++d)e+=this._graph_stack[d]._subgraph_node.getTitle()+" >> ";b.fillText(e+c.getTitle(),.5*a.width,40);b.restore()}c=!1;this.onRenderBackground&&(c=this.onRenderBackground(a,b));this.viewport||(b.restore(),b.setTransform(1,0,0,1,0,0));this.visible_links.length=0;if(this.graph){b.save();this.ds.toCanvasContext(b);if(this.background_image&&.5<this.ds.scale&&!c){b.globalAlpha=this.zoom_modify_alpha?(1-.5/this.ds.scale)*this.editor_alpha:this.editor_alpha;b.imageSmoothingEnabled=
|
||||
b.imageSmoothingEnabled=!1;if(!this._bg_img||this._bg_img.name!=this.background_image){this._bg_img=new Image;this._bg_img.name=this.background_image;this._bg_img.src=this.background_image;var g=this;this._bg_img.onload=function(){g.draw(!0,!0)}}c=null;null==this._pattern&&0<this._bg_img.width?(c=b.createPattern(this._bg_img,"repeat"),this._pattern_img=this._bg_img,this._pattern=c):c=this._pattern;c&&(b.fillStyle=c,b.fillRect(this.visible_area[0],this.visible_area[1],this.visible_area[2],this.visible_area[3]),
|
||||
b.fillStyle="transparent");b.globalAlpha=1;b.imageSmoothingEnabled=b.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 I=new Float32Array(2);h.prototype.drawNode=function(a,b){this.current_node=a;var c=a.color||a.constructor.color||f.NODE_DEFAULT_COLOR,e=a.bgcolor||a.constructor.bgcolor||f.NODE_DEFAULT_BGCOLOR,d=.6>this.ds.scale;if(this.live_mode){if(!a.flags.collapsed&&(b.shadowColor=
|
||||
"transparent",a.onDrawForeground))a.onDrawForeground(b,this,this.canvas)}else{var g=this.editor_alpha;b.globalAlpha=g;this.render_shadows&&!d?(b.shadowColor=f.DEFAULT_SHADOW_COLOR,b.shadowOffsetX=2*this.ds.scale,b.shadowOffsetY=2*this.ds.scale,b.shadowBlur=3*this.ds.scale):b.shadowColor="transparent";if(!a.flags.collapsed||!a.onDrawCollapsed||1!=a.onDrawCollapsed(b,this)){var k=a._shape||f.BOX_SHAPE;I.set(a.size);var n=a.horizontal;if(a.flags.collapsed){b.font=this.inner_text_font;var p=a.getTitle?
|
||||
a.getTitle():a.title;null!=p&&(a._collapsed_width=Math.min(a.size[0],b.measureText(p).width+2*f.NODE_TITLE_HEIGHT),I[0]=a._collapsed_width,I[1]=0)}a.clip_area&&(b.save(),b.beginPath(),k==f.BOX_SHAPE?b.rect(0,0,I[0],I[1]):k==f.ROUND_SHAPE?b.roundRect(0,0,I[0],I[1],[10]):k==f.CIRCLE_SHAPE&&b.arc(.5*I[0],.5*I[1],.5*I[0],0,2*Math.PI),b.clip());a.has_errors&&(e="red");this.drawNodeShape(a,b,I,c,e,a.is_selected,a.mouseOver);b.shadowColor="transparent";if(a.onDrawForeground)a.onDrawForeground(b,this,this.canvas);
|
||||
b.textAlign=n?"center":"left";b.font=this.inner_text_font;e=!d;var r=this.connecting_output;k=this.connecting_input;b.lineWidth=1;p=0;var u=new Float32Array(2);if(!a.flags.collapsed){if(a.inputs)for(c=0;c<a.inputs.length;c++){var q=a.inputs[c],y=q.type,h=q.shape;b.globalAlpha=g;this.connecting_output&&!f.isValidConnection(q.type,r.type)&&(b.globalAlpha=.4*g);b.fillStyle=null!=q.link?q.color_on||this.default_connection_color_byType[y]||this.default_connection_color.input_on:q.color_off||this.default_connection_color_byTypeOff[y]||
|
||||
this.default_connection_color_byType[y]||this.default_connection_color.input_off;var v=a.getConnectionPos(!0,c,u);v[0]-=a.pos[0];v[1]-=a.pos[1];p<v[1]+.5*f.NODE_SLOT_HEIGHT&&(p=v[1]+.5*f.NODE_SLOT_HEIGHT);b.beginPath();"array"==y&&(h=f.GRID_SHAPE);q.type===f.EVENT||q.shape===f.BOX_SHAPE?n?b.rect(v[0]-5+.5,v[1]-8+.5,10,14):b.rect(v[0]-6+.5,v[1]-5+.5,14,10):h===f.ARROW_SHAPE?(b.moveTo(v[0]+8,v[1]+.5),b.lineTo(v[0]-4,v[1]+6+.5),b.lineTo(v[0]-4,v[1]-6+.5),b.closePath()):h===f.GRID_SHAPE?(b.rect(v[0]-
|
||||
4,v[1]-4,2,2),b.rect(v[0]-1,v[1]-4,2,2),b.rect(v[0]+2,v[1]-4,2,2),b.rect(v[0]-4,v[1]-1,2,2),b.rect(v[0]-1,v[1]-1,2,2),b.rect(v[0]+2,v[1]-1,2,2),b.rect(v[0]-4,v[1]+2,2,2),b.rect(v[0]-1,v[1]+2,2,2),b.rect(v[0]+2,v[1]+2,2,2)):d?b.rect(v[0]-4,v[1]-4,8,8):b.arc(v[0],v[1],4,0,2*Math.PI);b.fill();e&&(y=null!=q.label?q.label:q.name)&&(b.fillStyle=f.NODE_TEXT_COLOR,n||q.dir==f.UP?b.fillText(y,v[0],v[1]-10):b.fillText(y,v[0]+10,v[1]+5))}b.textAlign=n?"center":"right";b.strokeStyle="black";if(a.outputs)for(c=
|
||||
0;c<a.outputs.length;c++)if(q=a.outputs[c],y=q.type,h=q.shape,this.connecting_input&&!f.isValidConnection(y,k.type)&&(b.globalAlpha=.4*g),v=a.getConnectionPos(!1,c,u),v[0]-=a.pos[0],v[1]-=a.pos[1],p<v[1]+.5*f.NODE_SLOT_HEIGHT&&(p=v[1]+.5*f.NODE_SLOT_HEIGHT),b.fillStyle=q.links&&q.links.length?q.color_on||this.default_connection_color_byType[y]||this.default_connection_color.output_on:q.color_off||this.default_connection_color_byTypeOff[y]||this.default_connection_color_byType[y]||this.default_connection_color.output_off,
|
||||
b.beginPath(),"array"==y&&(h=f.GRID_SHAPE),r=!0,y===f.EVENT||h===f.BOX_SHAPE?n?b.rect(v[0]-5+.5,v[1]-8+.5,10,14):b.rect(v[0]-6+.5,v[1]-5+.5,14,10):h===f.ARROW_SHAPE?(b.moveTo(v[0]+8,v[1]+.5),b.lineTo(v[0]-4,v[1]+6+.5),b.lineTo(v[0]-4,v[1]-6+.5),b.closePath()):h===f.GRID_SHAPE?(b.rect(v[0]-4,v[1]-4,2,2),b.rect(v[0]-1,v[1]-4,2,2),b.rect(v[0]+2,v[1]-4,2,2),b.rect(v[0]-4,v[1]-1,2,2),b.rect(v[0]-1,v[1]-1,2,2),b.rect(v[0]+2,v[1]-1,2,2),b.rect(v[0]-4,v[1]+2,2,2),b.rect(v[0]-1,v[1]+2,2,2),b.rect(v[0]+2,v[1]+
|
||||
2,2,2),r=!1):d?b.rect(v[0]-4,v[1]-4,8,8):b.arc(v[0],v[1],4,0,2*Math.PI),b.fill(),!d&&r&&b.stroke(),e&&(y=null!=q.label?q.label:q.name))b.fillStyle=f.NODE_TEXT_COLOR,n||q.dir==f.DOWN?b.fillText(y,v[0],v[1]-8):b.fillText(y,v[0]-10,v[1]+5);b.textAlign="left";b.globalAlpha=1;if(a.widgets){q=p;if(n||a.widgets_up)q=2;null!=a.widgets_start_y&&(q=a.widgets_start_y);this.drawNodeWidgets(a,q,b,this.node_widget&&this.node_widget[0]==a?this.node_widget[1]:null)}}else if(this.render_collapsed_slots){d=g=null;
|
||||
if(a.inputs)for(c=0;c<a.inputs.length;c++)if(q=a.inputs[c],null!=q.link){g=q;break}if(a.outputs)for(c=0;c<a.outputs.length;c++)q=a.outputs[c],q.links&&q.links.length&&(d=q);g&&(g=0,c=-.5*f.NODE_TITLE_HEIGHT,n&&(g=.5*a._collapsed_width,c=-f.NODE_TITLE_HEIGHT),b.fillStyle="#686",b.beginPath(),q.type===f.EVENT||q.shape===f.BOX_SHAPE?b.rect(g-7+.5,c-4,14,8):q.shape===f.ARROW_SHAPE?(b.moveTo(g+8,c),b.lineTo(g+-4,c-4),b.lineTo(g+-4,c+4),b.closePath()):b.arc(g,c,4,0,2*Math.PI),b.fill());d&&(g=a._collapsed_width,
|
||||
c=-.5*f.NODE_TITLE_HEIGHT,n&&(g=.5*a._collapsed_width,c=0),b.fillStyle="#686",b.strokeStyle="black",b.beginPath(),q.type===f.EVENT||q.shape===f.BOX_SHAPE?b.rect(g-7+.5,c-4,14,8):q.shape===f.ARROW_SHAPE?(b.moveTo(g+6,c),b.lineTo(g-6,c-4),b.lineTo(g-6,c+4),b.closePath()):b.arc(g,c,4,0,2*Math.PI),b.fill())}a.clip_area&&b.restore();b.globalAlpha=1}}};h.prototype.drawLinkTooltip=function(a,b){var c=b._pos;a.fillStyle="black";a.beginPath();a.arc(c[0],c[1],3,0,2*Math.PI);a.fill();if(null!=b.data&&(!this.onDrawLinkTooltip||
|
||||
1!=this.onDrawLinkTooltip(a,b,this))&&(b=b.data,b=b.constructor===Number?b.toFixed(2):b.constructor===String?'"'+b+'"':b.constructor===Boolean?String(b):b.toToolTip?b.toToolTip():"["+b.constructor.name+"]",null!=b)){b=b.substr(0,30);a.font="14px Courier New";var e=a.measureText(b).width+20;a.shadowColor="black";a.shadowOffsetX=2;a.shadowOffsetY=2;a.shadowBlur=3;a.fillStyle="#454";a.beginPath();a.roundRect(c[0]-.5*e,c[1]-15-24,e,24,[3]);a.moveTo(c[0]-10,c[1]-15);a.lineTo(c[0]+10,c[1]-15);a.lineTo(c[0],
|
||||
c[1]-5);a.fill();a.shadowColor="transparent";a.textAlign="center";a.fillStyle="#CEC";a.fillText(b,c[0],c[1]-15-24*.3)}};var B=new Float32Array(4);h.prototype.drawNodeShape=function(a,b,c,e,d,g,k){b.strokeStyle=e;b.fillStyle=d;d=f.NODE_TITLE_HEIGHT;var n=.5>this.ds.scale,p=a._shape||a.constructor.shape||f.ROUND_SHAPE,r=a.constructor.title_mode,u=!0;r==f.TRANSPARENT_TITLE||r==f.NO_TITLE?u=!1:r==f.AUTOHIDE_TITLE&&k&&(u=!0);B[0]=0;B[1]=u?-d:0;B[2]=c[0]+1;B[3]=u?c[1]+d:c[1];k=b.globalAlpha;b.beginPath();
|
||||
p==f.BOX_SHAPE||n?b.fillRect(B[0],B[1],B[2],B[3]):p==f.ROUND_SHAPE||p==f.CARD_SHAPE?b.roundRect(B[0],B[1],B[2],B[3],p==f.CARD_SHAPE?[this.round_radius,this.round_radius,0,0]:[this.round_radius]):p==f.CIRCLE_SHAPE&&b.arc(.5*c[0],.5*c[1],.5*c[0],0,2*Math.PI);b.fill();!a.flags.collapsed&&u&&(b.shadowColor="transparent",b.fillStyle="rgba(0,0,0,0.2)",b.fillRect(0,-1,B[2],2));b.shadowColor="transparent";if(a.onDrawBackground)a.onDrawBackground(b,this,this.canvas,this.graph_mouse);if(u||r==f.TRANSPARENT_TITLE){if(a.onDrawTitleBar)a.onDrawTitleBar(b,
|
||||
d,c,this.ds.scale,e);else if(r!=f.TRANSPARENT_TITLE&&(a.constructor.title_color||this.render_title_colored)){u=a.constructor.title_color||e;a.flags.collapsed&&(b.shadowColor=f.DEFAULT_SHADOW_COLOR);if(this.use_gradients){var q=h.gradients[u];q||(q=h.gradients[u]=b.createLinearGradient(0,0,400,0),q.addColorStop(0,u),q.addColorStop(1,"#000"));b.fillStyle=q}else b.fillStyle=u;b.beginPath();p==f.BOX_SHAPE||n?b.rect(0,-d,c[0]+1,d):(p==f.ROUND_SHAPE||p==f.CARD_SHAPE)&&b.roundRect(0,-d,c[0]+1,d,a.flags.collapsed?
|
||||
[this.round_radius]:[this.round_radius,this.round_radius,0,0]);b.fill();b.shadowColor="transparent"}u=!1;f.node_box_coloured_by_mode&&f.NODE_MODES_COLORS[a.mode]&&(u=f.NODE_MODES_COLORS[a.mode]);f.node_box_coloured_when_on&&(u=a.action_triggered?"#FFF":a.execute_triggered?"#AAA":u);if(a.onDrawTitleBox)a.onDrawTitleBox(b,d,c,this.ds.scale);else p==f.ROUND_SHAPE||p==f.CIRCLE_SHAPE||p==f.CARD_SHAPE?(n&&(b.fillStyle="black",b.beginPath(),b.arc(.5*d,-.5*d,6,0,2*Math.PI),b.fill()),b.fillStyle=a.boxcolor||
|
||||
u||f.NODE_DEFAULT_BOXCOLOR,n?b.fillRect(.5*d-5,-.5*d-5,10,10):(b.beginPath(),b.arc(.5*d,-.5*d,5,0,2*Math.PI),b.fill())):(n&&(b.fillStyle="black",b.fillRect(.5*(d-10)-1,-.5*(d+10)-1,12,12)),b.fillStyle=a.boxcolor||u||f.NODE_DEFAULT_BOXCOLOR,b.fillRect(.5*(d-10),-.5*(d+10),10,10));b.globalAlpha=k;if(a.onDrawTitleText)a.onDrawTitleText(b,d,c,this.ds.scale,this.title_text_font,g);!n&&(b.font=this.title_text_font,k=String(a.getTitle()))&&(b.fillStyle=g?f.NODE_SELECTED_TITLE_COLOR:a.constructor.title_text_color||
|
||||
this.node_title_color,a.flags.collapsed?(b.textAlign="left",b.measureText(k),b.fillText(k.substr(0,20),d,f.NODE_TITLE_TEXT_Y-d),b.textAlign="left"):(b.textAlign="left",b.fillText(k,d,f.NODE_TITLE_TEXT_Y-d)));a.flags.collapsed||!a.subgraph||a.skip_subgraph_button||(k=f.NODE_TITLE_HEIGHT,u=a.size[0]-k,q=f.isInsideRectangle(this.graph_mouse[0]-a.pos[0],this.graph_mouse[1]-a.pos[1],u+2,-k+2,k-4,k-4),b.fillStyle=q?"#888":"#555",p==f.BOX_SHAPE||n?b.fillRect(u+2,-k+2,k-4,k-4):(b.beginPath(),b.roundRect(u+
|
||||
2,-k+2,k-4,k-4,[4]),b.fill()),b.fillStyle="#333",b.beginPath(),b.moveTo(u+.2*k,.6*-k),b.lineTo(u+.8*k,.6*-k),b.lineTo(u+.5*k,.3*-k),b.fill());if(a.onDrawTitle)a.onDrawTitle(b)}if(g){if(a.onBounding)a.onBounding(B);r==f.TRANSPARENT_TITLE&&(B[1]-=d,B[3]+=d);b.lineWidth=1;b.globalAlpha=.8;b.beginPath();p==f.BOX_SHAPE?b.rect(-6+B[0],-6+B[1],12+B[2],12+B[3]):p==f.ROUND_SHAPE||p==f.CARD_SHAPE&&a.flags.collapsed?b.roundRect(-6+B[0],-6+B[1],12+B[2],12+B[3],[2*this.round_radius]):p==f.CARD_SHAPE?b.roundRect(-6+
|
||||
B[0],-6+B[1],12+B[2],12+B[3],[2*this.round_radius,2,2*this.round_radius,2]):p==f.CIRCLE_SHAPE&&b.arc(.5*c[0],.5*c[1],.5*c[0]+6,0,2*Math.PI);b.strokeStyle=f.NODE_BOX_OUTLINE_COLOR;b.stroke();b.strokeStyle=e;b.globalAlpha=1}0<a.execute_triggered&&a.execute_triggered--;0<a.action_triggered&&a.action_triggered--};var K=new Float32Array(4),F=new Float32Array(4),J=new Float32Array(2),H=new Float32Array(2);h.prototype.drawConnections=function(a){var b=f.getTime(),c=this.visible_area;K[0]=c[0]-20;K[1]=c[1]-
|
||||
20;K[2]=c[2]+40;K[3]=c[3]+40;a.lineWidth=this.connections_width;a.fillStyle="#AAA";a.strokeStyle="#AAA";a.globalAlpha=this.editor_alpha;c=this.graph._nodes;for(var e=0,d=c.length;e<d;++e){var g=c[e];if(g.inputs&&g.inputs.length)for(var k=0;k<g.inputs.length;++k){var n=g.inputs[k];if(n&&null!=n.link&&(n=this.graph.links[n.link])){var p=this.graph.getNodeById(n.origin_id);if(null!=p){var r=n.origin_slot;var u=-1==r?[p.pos[0]+10,p.pos[1]+10]:p.getConnectionPos(!1,r,J);var q=g.getConnectionPos(!0,k,H);
|
||||
F[0]=u[0];F[1]=u[1];F[2]=q[0]-u[0];F[3]=q[1]-u[1];0>F[2]&&(F[0]+=F[2],F[2]=Math.abs(F[2]));0>F[3]&&(F[1]+=F[3],F[3]=Math.abs(F[3]));if(A(F,K)){var y=p.outputs[r];r=g.inputs[k];if(y&&r&&(p=y.dir||(p.horizontal?f.DOWN:f.RIGHT),r=r.dir||(g.horizontal?f.UP:f.LEFT),this.renderLink(a,u,q,n,!1,0,null,p,r),n&&n._last_time&&1E3>b-n._last_time)){y=2-.002*(b-n._last_time);var h=a.globalAlpha;a.globalAlpha=h*y;this.renderLink(a,u,q,n,!0,y,"white",p,r);a.globalAlpha=h}}}}}}a.globalAlpha=1};h.prototype.renderLink=
|
||||
function(a,b,c,e,d,g,k,n,p,r){e&&this.visible_links.push(e);!k&&e&&(k=e.color||h.link_type_colors[e.type]);k||(k=this.default_link_color);null!=e&&this.highlighted_links[e.id]&&(k="#FFF");n=n||f.RIGHT;p=p||f.LEFT;var u=D(b,c);this.render_connections_border&&.6<this.ds.scale&&(a.lineWidth=this.connections_width+4);a.lineJoin="round";r=r||1;1<r&&(a.lineWidth=.5);a.beginPath();for(var q=0;q<r;q+=1){var y=5*(q-.5*(r-1));if(this.links_render_mode==f.SPLINE_LINK){a.moveTo(b[0],b[1]+y);var l=0,v=0,m=0,w=
|
||||
0;switch(n){case f.LEFT:l=-.25*u;break;case f.RIGHT:l=.25*u;break;case f.UP:v=-.25*u;break;case f.DOWN:v=.25*u}switch(p){case f.LEFT:m=-.25*u;break;case f.RIGHT:m=.25*u;break;case f.UP:w=-.25*u;break;case f.DOWN:w=.25*u}a.bezierCurveTo(b[0]+l,b[1]+v+y,c[0]+m,c[1]+w+y,c[0],c[1]+y)}else if(this.links_render_mode==f.LINEAR_LINK){a.moveTo(b[0],b[1]+y);w=m=v=l=0;switch(n){case f.LEFT:l=-1;break;case f.RIGHT:l=1;break;case f.UP:v=-1;break;case f.DOWN:v=1}switch(p){case f.LEFT:m=-1;break;case f.RIGHT:m=
|
||||
1;break;case f.UP:w=-1;break;case f.DOWN:w=1}a.lineTo(b[0]+15*l,b[1]+15*v+y);a.lineTo(c[0]+15*m,c[1]+15*w+y);a.lineTo(c[0],c[1]+y)}else if(this.links_render_mode==f.STRAIGHT_LINK)a.moveTo(b[0],b[1]),y=b[0],l=b[1],v=c[0],m=c[1],n==f.RIGHT?y+=10:l+=10,p==f.LEFT?v-=10:m-=10,a.lineTo(y,l),a.lineTo(.5*(y+v),l),a.lineTo(.5*(y+v),m),a.lineTo(v,m),a.lineTo(c[0],c[1]);else return}this.render_connections_border&&.6<this.ds.scale&&!d&&(a.strokeStyle="rgba(0,0,0,0.5)",a.stroke());a.lineWidth=this.connections_width;
|
||||
a.fillStyle=a.strokeStyle=k;a.stroke();d=this.computeConnectionPoint(b,c,.5,n,p);e&&e._pos&&(e._pos[0]=d[0],e._pos[1]=d[1]);.6<=this.ds.scale&&this.highquality_render&&p!=f.CENTER&&(this.render_connection_arrows&&(q=this.computeConnectionPoint(b,c,.25,n,p),u=this.computeConnectionPoint(b,c,.26,n,p),e=this.computeConnectionPoint(b,c,.75,n,p),r=this.computeConnectionPoint(b,c,.76,n,p),this.render_curved_connections?(u=-Math.atan2(u[0]-q[0],u[1]-q[1]),r=-Math.atan2(r[0]-e[0],r[1]-e[1])):r=u=c[1]>b[1]?
|
||||
0:Math.PI,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.save(),a.translate(e[0],e[1]),a.rotate(r),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore()),a.beginPath(),a.arc(d[0],d[1],5,0,2*Math.PI),a.fill());if(g)for(a.fillStyle=k,q=0;5>q;++q)g=(.001*f.getTime()+.2*q)%1,d=this.computeConnectionPoint(b,c,g,n,p),a.beginPath(),a.arc(d[0],d[1],5,0,2*Math.PI),a.fill()};h.prototype.computeConnectionPoint=
|
||||
function(a,b,c,e,d){e=e||f.RIGHT;d=d||f.LEFT;var g=D(a,b),k=[a[0],a[1]],n=[b[0],b[1]];switch(e){case f.LEFT:k[0]+=-.25*g;break;case f.RIGHT:k[0]+=.25*g;break;case f.UP:k[1]+=-.25*g;break;case f.DOWN:k[1]+=.25*g}switch(d){case f.LEFT:n[0]+=-.25*g;break;case f.RIGHT:n[0]+=.25*g;break;case f.UP:n[1]+=-.25*g;break;case f.DOWN:n[1]+=.25*g}e=(1-c)*(1-c)*(1-c);d=3*(1-c)*(1-c)*c;g=3*(1-c)*c*c;c*=c*c;return[e*a[0]+d*k[0]+g*n[0]+c*b[0],e*a[1]+d*k[1]+g*n[1]+c*b[1]]};h.prototype.drawExecutionOrder=function(a){a.shadowColor=
|
||||
"transparent";a.globalAlpha=.25;a.textAlign="center";a.strokeStyle="white";a.globalAlpha=.75;for(var b=this.visible_nodes,c=0;c<b.length;++c){var e=b[c];a.fillStyle="black";a.fillRect(e.pos[0]-f.NODE_TITLE_HEIGHT,e.pos[1]-f.NODE_TITLE_HEIGHT,f.NODE_TITLE_HEIGHT,f.NODE_TITLE_HEIGHT);0==e.order&&a.strokeRect(e.pos[0]-f.NODE_TITLE_HEIGHT+.5,e.pos[1]-f.NODE_TITLE_HEIGHT+.5,f.NODE_TITLE_HEIGHT,f.NODE_TITLE_HEIGHT);a.fillStyle="#FFF";a.fillText(e.order,e.pos[0]+-.5*f.NODE_TITLE_HEIGHT,e.pos[1]-6)}a.globalAlpha=
|
||||
1};h.prototype.drawNodeWidgets=function(a,b,c,e){if(!a.widgets||!a.widgets.length)return 0;var d=a.size[0],g=a.widgets;b+=2;var k=f.NODE_WIDGET_HEIGHT,n=.5<this.ds.scale;c.save();c.globalAlpha=this.editor_alpha;for(var p=f.WIDGET_OUTLINE_COLOR,r=f.WIDGET_BGCOLOR,u=f.WIDGET_TEXT_COLOR,q=f.WIDGET_SECONDARY_TEXT_COLOR,y=0;y<g.length;++y){var h=g[y],v=b;h.y&&(v=h.y);h.last_y=v;c.strokeStyle=p;c.fillStyle="#222";c.textAlign="left";h.disabled&&(c.globalAlpha*=.5);var l=h.width||d;switch(h.type){case "button":h.clicked&&
|
||||
(c.fillStyle="#AAA",h.clicked=!1,this.dirty_canvas=!0);c.fillRect(15,v,l-30,k);n&&!h.disabled&&c.strokeRect(15,v,l-30,k);n&&(c.textAlign="center",c.fillStyle=u,c.fillText(h.name,.5*l,v+.7*k));break;case "toggle":c.textAlign="left";c.strokeStyle=p;c.fillStyle=r;c.beginPath();n?c.roundRect(15,v,l-30,k,[.5*k]):c.rect(15,v,l-30,k);c.fill();n&&!h.disabled&&c.stroke();c.fillStyle=h.value?"#89A":"#333";c.beginPath();c.arc(l-30,v+.5*k,.36*k,0,2*Math.PI);c.fill();n&&(c.fillStyle=q,null!=h.name&&c.fillText(h.name,
|
||||
30,v+.7*k),c.fillStyle=h.value?u:q,c.textAlign="right",c.fillText(h.value?h.options.on||"true":h.options.off||"false",l-40,v+.7*k));break;case "slider":c.fillStyle=r;c.fillRect(15,v,l-30,k);var m=h.options.max-h.options.min,w=(h.value-h.options.min)/m;c.fillStyle=e==h?"#89A":"#678";c.fillRect(15,v,w*(l-30),k);n&&!h.disabled&&c.strokeRect(15,v,l-30,k);h.marker&&(m=(h.marker-h.options.min)/m,c.fillStyle="#AA9",c.fillRect(15+m*(l-30),v,2,k));n&&(c.textAlign="center",c.fillStyle=u,c.fillText(h.name+" "+
|
||||
Number(h.value).toFixed(3),.5*l,v+.7*k));break;case "number":case "combo":c.textAlign="left";c.strokeStyle=p;c.fillStyle=r;c.beginPath();n?c.roundRect(15,v,l-30,k,[.5*k]):c.rect(15,v,l-30,k);c.fill();n&&(h.disabled||c.stroke(),c.fillStyle=u,h.disabled||(c.beginPath(),c.moveTo(31,v+5),c.lineTo(21,v+.5*k),c.lineTo(31,v+k-5),c.fill(),c.beginPath(),c.moveTo(l-15-16,v+5),c.lineTo(l-15-6,v+.5*k),c.lineTo(l-15-16,v+k-5),c.fill()),c.fillStyle=q,c.fillText(h.name,35,v+.7*k),c.fillStyle=u,c.textAlign="right",
|
||||
"number"==h.type?c.fillText(Number(h.value).toFixed(void 0!==h.options.precision?h.options.precision:3),l-30-20,v+.7*k):(m=h.value,h.options.values&&(w=h.options.values,w.constructor===Function&&(w=w()),w&&w.constructor!==Array&&(m=w[h.value])),c.fillText(m,l-30-20,v+.7*k)));break;case "string":case "text":c.textAlign="left";c.strokeStyle=p;c.fillStyle=r;c.beginPath();n?c.roundRect(15,v,l-30,k,[.5*k]):c.rect(15,v,l-30,k);c.fill();n&&(h.disabled||c.stroke(),c.save(),c.beginPath(),c.rect(15,v,l-30,
|
||||
k),c.clip(),c.fillStyle=q,null!=h.name&&c.fillText(h.name,30,v+.7*k),c.fillStyle=u,c.textAlign="right",c.fillText(String(h.value).substr(0,30),l-30,v+.7*k),c.restore());break;default:h.draw&&h.draw(c,a,l,v,k)}b+=(h.computeSize?h.computeSize(l)[1]:k)+4;c.globalAlpha=this.editor_alpha}c.restore();c.textAlign="left"};h.prototype.processNodeWidgets=function(a,b,c,e){function d(d,e){d.value=e;d.options&&d.options.property&&void 0!==a.properties[d.options.property]&&a.setProperty(d.options.property,e);
|
||||
d.callback&&d.callback(d.value,h,a,b,c)}if(!a.widgets||!a.widgets.length)return null;for(var g=b[0]-a.pos[0],k=b[1]-a.pos[1],n=a.size[0],h=this,r=this.getCanvasWindow(),u=0;u<a.widgets.length;++u){var q=a.widgets[u];if(q&&!q.disabled){var y=q.computeSize?q.computeSize(n)[1]:f.NODE_WIDGET_HEIGHT,l=q.width||n;if(q==e||!(6>g||g>l-12||k<q.last_y||k>q.last_y+y||void 0===q.last_y)){e=q.value;switch(q.type){case "button":c.type===f.pointerevents_method+"down"&&(q.callback&&setTimeout(function(){q.callback(q,
|
||||
h,a,b,c)},20),this.dirty_canvas=q.clicked=!0);break;case "slider":r=Math.clamp((g-15)/(l-30),0,1);q.value=q.options.min+(q.options.max-q.options.min)*r;q.callback&&setTimeout(function(){d(q,q.value)},20);this.dirty_canvas=!0;break;case "number":case "combo":e=q.value;if(c.type==f.pointerevents_method+"move"&&"number"==q.type)q.value+=.1*c.deltaX*(q.options.step||1),null!=q.options.min&&q.value<q.options.min&&(q.value=q.options.min),null!=q.options.max&&q.value>q.options.max&&(q.value=q.options.max);
|
||||
else if(c.type==f.pointerevents_method+"down"){var v=q.options.values;v&&v.constructor===Function&&(v=q.options.values(q,a));var m=null;"number"!=q.type&&(m=v.constructor===Array?v:Object.keys(v));g=40>g?-1:g>l-40?1:0;if("number"==q.type)q.value+=.1*g*(q.options.step||1),null!=q.options.min&&q.value<q.options.min&&(q.value=q.options.min),null!=q.options.max&&q.value>q.options.max&&(q.value=q.options.max);else if(g)r=-1,this.last_mouseclick=0,r=v.constructor===Object?m.indexOf(String(q.value))+g:m.indexOf(q.value)+
|
||||
g,r>=m.length&&(r=m.length-1),0>r&&(r=0),q.value=v.constructor===Array?v[r]:r;else{var w=v!=m?Object.values(v):v;new f.ContextMenu(w,{scale:Math.max(1,this.ds.scale),event:c,className:"dark",callback:function(a,b,c){v!=m&&(a=w.indexOf(a));this.value=a;d(this,a);h.dirty_canvas=!0;return!1}.bind(q)},r)}}else c.type==f.pointerevents_method+"up"&&"number"==q.type&&(g=40>g?-1:g>l-40?1:0,200>c.click_time&&0==g&&this.prompt("Value",q.value,function(a){this.value=Number(a);d(this,this.value)}.bind(q),c));
|
||||
e!=q.value&&setTimeout(function(){d(this,this.value)}.bind(q),20);this.dirty_canvas=!0;break;case "toggle":c.type==f.pointerevents_method+"down"&&(q.value=!q.value,setTimeout(function(){d(q,q.value)},20));break;case "string":case "text":c.type==f.pointerevents_method+"down"&&this.prompt("Value",q.value,function(a){this.value=a;d(this,a)}.bind(q),c,q.options?q.options.multiline:!1);break;default:q.mouse&&(this.dirty_canvas=q.mouse(c,[g,k],a))}if(e!=q.value){if(a.onWidgetChanged)a.onWidgetChanged(q.name,
|
||||
q.value,e,q);a.graph._version++}return q}}}return null};h.prototype.drawGroups=function(a,b){if(this.graph){a=this.graph._groups;b.save();b.globalAlpha=.5*this.editor_alpha;for(var c=0;c<a.length;++c){var e=a[c];if(A(this.visible_area,e._bounding)){b.fillStyle=e.color||"#335";b.strokeStyle=e.color||"#335";var d=e._pos,g=e._size;b.globalAlpha=.25*this.editor_alpha;b.beginPath();b.rect(d[0]+.5,d[1]+.5,g[0],g[1]);b.fill();b.globalAlpha=this.editor_alpha;b.stroke();b.beginPath();b.moveTo(d[0]+g[0],d[1]+
|
||||
g[1]);b.lineTo(d[0]+g[0]-10,d[1]+g[1]);b.lineTo(d[0]+g[0],d[1]+g[1]-10);b.fill();g=e.font_size||f.DEFAULT_GROUP_FONT_SIZE;b.font=g+"px Arial";b.textAlign="left";b.fillText(e.title,d[0]+4,d[1]+g)}}b.restore()}};h.prototype.adjustNodesSize=function(){for(var a=this.graph._nodes,b=0;b<a.length;++b)a[b].size=a[b].computeSize();this.setDirty(!0,!0)};h.prototype.resize=function(a,b){a||b||(b=this.canvas.parentNode,a=b.offsetWidth,b=b.offsetHeight);if(this.canvas.width!=a||this.canvas.height!=b)this.canvas.width=
|
||||
a,this.canvas.height=b,this.bgcanvas.width=this.canvas.width,this.bgcanvas.height=this.canvas.height,this.setDirty(!0,!0)};h.prototype.switchLiveMode=function(a){if(a){var b=this,c=this.live_mode?1.1:.9;this.live_mode&&(this.live_mode=!1,this.editor_alpha=.1);var e=setInterval(function(){b.editor_alpha*=c;b.dirty_canvas=!0;b.dirty_bgcanvas=!0;1>c&&.01>b.editor_alpha&&(clearInterval(e),1>c&&(b.live_mode=!0));1<c&&.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};h.prototype.onNodeSelectionChange=function(a){};h.onGroupAdd=function(a,b,c){a=h.active_canvas;a.getCanvasWindow();b=new f.LGraphGroup;b.pos=a.convertEventToCanvasOffset(c);a.graph.add(b)};h.onMenuAdd=function(a,b,c,e,d){function g(a,b){var e=[];f.getNodeTypesCategories(k.filter||p.filter).filter(function(b){return b.startsWith(a)}).map(function(b){if(b){b=b.replace(new RegExp("^("+a+")"),"").split("/")[0];var c=""===a?b+"/":a+b+"/";-1!=b.indexOf("::")&&(b=
|
||||
b.split("::")[1]);-1===e.findIndex(function(a){return a.value===c})&&e.push({value:c,content:b,has_submenu:!0,callback:function(a,b,c,d){g(a.value,d)}})}});f.getNodeTypesInCategory(a.slice(0,-1),k.filter||p.filter).map(function(a){a.skip_list||e.push({value:a.type,content:a.title,has_submenu:!1,callback:function(a,b,c,e){b=e.getFirstEvent();k.graph.beforeChange();if(a=f.createNode(a.value))a.pos=k.convertEventToCanvasOffset(b),k.graph.add(a);d&&d(a);k.graph.afterChange()}})});new f.ContextMenu(e,
|
||||
{event:c,parentMenu:b},n)}var k=h.active_canvas,n=k.getCanvasWindow(),p=k.graph;if(p)return g("",e),!1};h.onMenuCollapseAll=function(){};h.onMenuNodeEdit=function(){};h.showMenuNodeOptionalInputs=function(a,b,c,e,d){if(d){var g=this;a=h.active_canvas.getCanvasWindow();b=d.optional_inputs;d.onGetInputs&&(b=d.onGetInputs());var k=[];if(b)for(var n=0;n<b.length;n++){var p=b[n];if(p){var r=p[0];p[2]||(p[2]={});p[2].label&&(r=p[2].label);p[2].removable=!0;r={content:r,value:p};p[1]==f.ACTION&&(r.className=
|
||||
"event");k.push(r)}else k.push(null)}d.onMenuNodeInputs&&(b=d.onMenuNodeInputs(k))&&(k=b);if(k.length)return new f.ContextMenu(k,{event:c,callback:function(a,b,c){if(d&&(a.callback&&a.callback.call(g,d,a,b,c),a.value)){d.graph.beforeChange();d.addInput(a.value[0],a.value[1],a.value[2]);if(d.onNodeInputAdd)d.onNodeInputAdd(a.value);d.setDirtyCanvas(!0,!0);d.graph.afterChange()}},parentMenu:e,node:d},a),!1;console.log("no input entries")}};h.showMenuNodeOptionalOutputs=function(a,b,c,e,d){function g(a,
|
||||
b,c){if(d&&(a.callback&&a.callback.call(k,d,a,b,c),a.value))if(c=a.value[1],!c||c.constructor!==Object&&c.constructor!==Array){d.graph.beforeChange();d.addOutput(a.value[0],a.value[1],a.value[2]);if(d.onNodeOutputAdd)d.onNodeOutputAdd(a.value);d.setDirtyCanvas(!0,!0);d.graph.afterChange()}else{a=[];for(var r in c)a.push({content:r,value:c[r]});new f.ContextMenu(a,{event:b,callback:g,parentMenu:e,node:d});return!1}}if(d){var k=this;a=h.active_canvas.getCanvasWindow();b=d.optional_outputs;d.onGetOutputs&&
|
||||
(b=d.onGetOutputs());var n=[];if(b)for(var p=0;p<b.length;p++){var r=b[p];if(!r)n.push(null);else if(!d.flags||!d.flags.skip_repeated_outputs||-1==d.findOutputSlot(r[0])){var u=r[0];r[2]||(r[2]={});r[2].label&&(u=r[2].label);r[2].removable=!0;u={content:u,value:r};r[1]==f.EVENT&&(u.className="event");n.push(u)}}this.onMenuNodeOutputs&&(n=this.onMenuNodeOutputs(n));f.do_add_triggers_slots&&-1==d.findOutputSlot("onExecuted")&&n.push({content:"On Executed",value:["onExecuted",f.EVENT,{nameLocked:!0}],
|
||||
className:"event"});d.onMenuNodeOutputs&&(b=d.onMenuNodeOutputs(n))&&(n=b);if(n.length)return new f.ContextMenu(n,{event:c,callback:g,parentMenu:e,node:d},a),!1}};h.onShowMenuNodeProperties=function(a,b,c,e,d){if(d&&d.properties){var g=h.active_canvas;b=g.getCanvasWindow();var k=[],n;for(n in d.properties){a=void 0!==d.properties[n]?d.properties[n]:" ";"object"==typeof a&&(a=JSON.stringify(a));var p=d.getPropertyInfo(n);if("enum"==p.type||"combo"==p.type)a=h.getPropertyPrintableValue(a,p.values);
|
||||
a=h.decodeHTML(a);k.push({content:"<span class='property_name'>"+(p.label?p.label:n)+"</span><span class='property_value'>"+a+"</span>",value:n})}if(k.length)return new f.ContextMenu(k,{event:c,callback:function(a,b,c,e){d&&(b=this.getBoundingClientRect(),g.showEditPropertyValue(d,a.value,{position:[b.left,b.top]}))},parentMenu:e,allow_html:!0,node:d},b),!1}};h.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};h.onMenuResizeNode=function(a,b,c,e,d){if(d){a=
|
||||
function(a){a.size=a.computeSize();if(a.onResize)a.onResize(a.size)};b=h.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)a(d);else for(var g in b.selected_nodes)a(b.selected_nodes[g]);d.setDirtyCanvas(!0,!0)}};h.prototype.showLinkMenu=function(a,b){var c=this,e=c.graph.getNodeById(a.origin_id),d=c.graph.getNodeById(a.target_id),g=!1;e&&e.outputs&&e.outputs[a.origin_slot]&&(g=e.outputs[a.origin_slot].type);var k=!1;d&&d.outputs&&d.outputs[a.target_slot]&&(k=d.inputs[a.target_slot].type);
|
||||
var n=new f.ContextMenu(["Add Node",null,"Delete",null],{event:b,title:null!=a.data?a.data.constructor.name:null,callback:function(b,f,u){switch(b){case "Add Node":h.onMenuAdd(null,null,u,n,function(b){b.inputs&&b.inputs.length&&b.outputs&&b.outputs.length&&e.connectByType(a.origin_slot,b,g)&&(b.connectByType(a.target_slot,d,k),b.pos[0]-=.5*b.size[0])});break;case "Delete":c.graph.removeLink(a.id)}}});return!1};h.prototype.createDefaultNodeForSlot=function(a){a=a||{};a=Object.assign({nodeFrom:null,
|
||||
slotFrom:null,nodeTo:null,slotTo:null,position:[],nodeType:null,posAdd:[0,0],posSizeFix:[0,0]},a);var b=a.nodeFrom&&null!==a.slotFrom,c=!b&&a.nodeTo&&null!==a.slotTo;if(!b&&!c)return console.warn("No data passed to createDefaultNodeForSlot "+a.nodeFrom+" "+a.slotFrom+" "+a.nodeTo+" "+a.slotTo),!1;if(!a.nodeType)return console.warn("No type to createDefaultNodeForSlot"),!1;var e=b?a.nodeFrom:a.nodeTo,d=b?a.slotFrom:a.slotTo;switch(typeof d){case "string":c=b?e.findOutputSlot(d,!1):e.findInputSlot(d,
|
||||
!1);d=b?e.outputs[d]:e.inputs[d];break;case "object":c=b?e.findOutputSlot(d.name):e.findInputSlot(d.name);break;case "number":c=d;d=b?e.outputs[d]:e.inputs[d];break;default:return console.warn("Cant get slot information "+d),!1}!1!==d&&!1!==c||console.warn("createDefaultNodeForSlot bad slotX "+d+" "+c);e=d.type==f.EVENT?"_event_":d.type;if((d=b?f.slot_types_default_out:f.slot_types_default_in)&&d[e]){nodeNewType=!1;if("object"==typeof d[e]||"array"==typeof d[e])for(var g in d[e]){if(a.nodeType==d[e][g]||
|
||||
"AUTO"==a.nodeType){nodeNewType=d[e][g];break}}else if(a.nodeType==d[e]||"AUTO"==a.nodeType)nodeNewType=d[e];if(nodeNewType){g=!1;"object"==typeof nodeNewType&&nodeNewType.node&&(g=nodeNewType,nodeNewType=nodeNewType.node);if(d=f.createNode(nodeNewType)){if(g){if(g.properties)for(var k in g.properties)d.addProperty(k,g.properties[k]);if(g.inputs)for(k in d.inputs=[],g.inputs)d.addOutput(g.inputs[k][0],g.inputs[k][1]);if(g.outputs)for(k in d.outputs=[],g.outputs)d.addOutput(g.outputs[k][0],g.outputs[k][1]);
|
||||
g.title&&(d.title=g.title);g.json&&d.configure(g.json)}this.graph.add(d);d.pos=[a.position[0]+a.posAdd[0]+(a.posSizeFix[0]?a.posSizeFix[0]*d.size[0]:0),a.position[1]+a.posAdd[1]+(a.posSizeFix[1]?a.posSizeFix[1]*d.size[1]:0)];b?a.nodeFrom.connectByType(c,d,e):a.nodeTo.connectByTypeOutput(c,d,e);return!0}console.log("failed creating "+nodeNewType)}}return!1};h.prototype.showConnectionMenu=function(a){a=a||{};var b=Object.assign({nodeFrom:null,slotFrom:null,nodeTo:null,slotTo:null,e:null},a),c=this,
|
||||
e=b.nodeFrom&&b.slotFrom;a=!e&&b.nodeTo&&b.slotTo;if(!e&&!a)return console.warn("No data passed to showConnectionMenu"),!1;a=e?b.nodeFrom:b.nodeTo;var d=e?b.slotFrom:b.slotTo,g=!1;switch(typeof d){case "string":g=e?a.findOutputSlot(d,!1):a.findInputSlot(d,!1);d=e?a.outputs[d]:a.inputs[d];break;case "object":g=e?a.findOutputSlot(d.name):a.findInputSlot(d.name);break;case "number":g=d;d=e?a.outputs[d]:a.inputs[d];break;default:return console.warn("Cant get slot information "+d),!1}a=["Add Node",null];
|
||||
c.allow_searchbox&&(a.push("Search"),a.push(null));var k=d.type==f.EVENT?"_event_":d.type,n=e?f.slot_types_default_out:f.slot_types_default_in;if(n&&n[k])if("object"==typeof n[k]||"array"==typeof n[k])for(var p in n[k])a.push(n[k][p]);else a.push(n[k]);var r=new f.ContextMenu(a,{event:b.e,title:(d&&""!=d.name?d.name+(k?" | ":""):"")+(d&&k?k:""),callback:function(a,f,n){switch(a){case "Add Node":h.onMenuAdd(null,null,n,r,function(a){e?b.nodeFrom.connectByType(g,a,k):b.nodeTo.connectByTypeOutput(g,
|
||||
a,k)});break;case "Search":e?c.showSearchBox(n,{node_from:b.nodeFrom,slot_from:d,type_filter_in:k}):c.showSearchBox(n,{node_to:b.nodeTo,slot_from:d,type_filter_out:k});break;default:c.createDefaultNodeForSlot(Object.assign(b,{position:[b.e.canvasX,b.e.canvasY],nodeType:a}))}}});return!1};h.onShowPropertyEditor=function(a,b,c,e,d){function g(){if(p){var b=p.value;"Number"==a.type?b=Number(b):"Boolean"==a.type&&(b=!!b);d[k]=b;n.parentNode&&n.parentNode.removeChild(n);d.setDirtyCanvas(!0,!0)}}var k=
|
||||
a.property||"title";b=d[k];var n=document.createElement("div");n.is_modified=!1;n.className="graphdialog";n.innerHTML="<span class='name'></span><input autofocus type='text' class='value'/><button>OK</button>";n.close=function(){n.parentNode&&n.parentNode.removeChild(n)};n.querySelector(".name").innerText=k;var p=n.querySelector(".value");p&&(p.value=b,p.addEventListener("blur",function(a){this.focus()}),p.addEventListener("keydown",function(a){n.is_modified=!0;if(27==a.keyCode)n.close();else if(13==
|
||||
a.keyCode)g();else if(13!=a.keyCode&&"textarea"!=a.target.localName)return;a.preventDefault();a.stopPropagation()}));b=h.active_canvas.canvas;c=b.getBoundingClientRect();var r=e=-20;c&&(e-=c.left,r-=c.top);event?(n.style.left=event.clientX+e+"px",n.style.top=event.clientY+r+"px"):(n.style.left=.5*b.width+e+"px",n.style.top=.5*b.height+r+"px");n.querySelector("button").addEventListener("click",g);b.parentNode.appendChild(n);p&&p.focus();var u=null;n.addEventListener("mouseleave",function(a){f.dialog_close_on_mouse_leave&&
|
||||
!n.is_modified&&f.dialog_close_on_mouse_leave&&(u=setTimeout(n.close,f.dialog_close_on_mouse_leave_delay))});n.addEventListener("mouseenter",function(a){f.dialog_close_on_mouse_leave&&u&&clearTimeout(u)})};h.prototype.prompt=function(a,b,c,e,d){var g=this;a=a||"";var k=document.createElement("div");k.is_modified=!1;k.className="graphdialog rounded";k.innerHTML=d?"<span class='name'></span> <textarea autofocus class='value'></textarea><button class='rounded'>OK</button>":"<span class='name'></span> <input autofocus type='text' class='value'/><button class='rounded'>OK</button>";
|
||||
k.close=function(){g.prompt_box=null;k.parentNode&&k.parentNode.removeChild(k)};d=h.active_canvas.canvas;d.parentNode.appendChild(k);1<this.ds.scale&&(k.style.transform="scale("+this.ds.scale+")");var n=null,p=!1;f.pointerListenerAdd(k,"leave",function(a){p||f.dialog_close_on_mouse_leave&&!k.is_modified&&f.dialog_close_on_mouse_leave&&(n=setTimeout(k.close,f.dialog_close_on_mouse_leave_delay))});f.pointerListenerAdd(k,"enter",function(a){f.dialog_close_on_mouse_leave&&n&&clearTimeout(n)});var r=k.querySelectorAll("select");
|
||||
r&&r.forEach(function(a){a.addEventListener("click",function(a){p++});a.addEventListener("blur",function(a){p=0});a.addEventListener("change",function(a){p=-1})});g.prompt_box&&g.prompt_box.close();g.prompt_box=k;k.querySelector(".name").innerText=a;var u=k.querySelector(".value");u.value=b;u.addEventListener("keydown",function(a){k.is_modified=!0;if(27==a.keyCode)k.close();else if(13==a.keyCode&&"textarea"!=a.target.localName)c&&c(this.value),k.close();else return;a.preventDefault();a.stopPropagation()});
|
||||
k.querySelector("button").addEventListener("click",function(a){c&&c(u.value);g.setDirty(!0);k.close()});a=d.getBoundingClientRect();r=b=-20;a&&(b-=a.left,r-=a.top);e?(k.style.left=e.clientX+b+"px",k.style.top=e.clientY+r+"px"):(k.style.left=.5*d.width+b+"px",k.style.top=.5*d.height+r+"px");setTimeout(function(){u.focus()},10);return k};h.search_limit=-1;h.prototype.showSearchBox=function(a,b){function c(c){if(c)if(g.onSearchBoxSelection)g.onSearchBoxSelection(c,a,k);else{var d=f.searchbox_extras[c.toLowerCase()];
|
||||
d&&(c=d.type);k.graph.beforeChange();if(c=f.createNode(c))c.pos=k.convertEventToCanvasOffset(a),k.graph.add(c,!1);if(d&&d.data){if(d.data.properties)for(var e in d.data.properties)c.addProperty(e,d.data.properties[e]);if(d.data.inputs)for(e in c.inputs=[],d.data.inputs)c.addOutput(d.data.inputs[e][0],d.data.inputs[e][1]);if(d.data.outputs)for(e in c.outputs=[],d.data.outputs)c.addOutput(d.data.outputs[e][0],d.data.outputs[e][1]);d.data.title&&(c.title=d.data.title);d.data.json&&c.configure(d.data.json)}if(b.node_from){switch(typeof b.slot_from){case "string":d=
|
||||
b.node_from.findOutputSlot(b.slot_from);break;case "object":d=b.slot_from.name?b.node_from.findOutputSlot(b.slot_from.name):-1;-1==d&&"undefined"!==typeof b.slot_from.slot_index&&(d=b.slot_from.slot_index);break;case "number":d=b.slot_from;break;default:d=0}!1!==d&&-1<d&&b.node_from.connectByType(d,c,b.node_from.outputs[d].type)}if(b.node_to){switch(typeof b.slot_from){case "string":d=b.node_to.findInputSlot(b.slot_from);break;case "object":d=b.slot_from.name?b.node_to.findInputSlot(b.slot_from.name):
|
||||
-1;-1==d&&"undefined"!==typeof b.slot_from.slot_index&&(d=b.slot_from.slot_index);break;case "number":d=b.slot_from;break;default:d=0}!1!==d&&-1<d&&b.node_to.connectByTypeOutput(d,c,b.node_to.inputs[d].type)}k.graph.afterChange()}r.close()}function e(a){var b=t;t&&t.classList.remove("selected");t?(t=a?t.nextSibling:t.previousSibling)||(t=b):t=a?v.childNodes[0]:v.childNodes[v.childNodes.length];t&&(t.classList.add("selected"),t.scrollIntoView({block:"end",behavior:"smooth"}))}function d(){function a(a,
|
||||
b){var d=document.createElement("div");m||(m=a);d.innerText=a;d.dataset.type=escape(a);d.className="litegraph lite-search-item";b&&(d.className+=" "+b);d.addEventListener("click",function(a){c(unescape(this.dataset.type))});v.appendChild(d)}w=null;var d=z.value;m=null;v.innerHTML="";if(d||b.show_all_if_empty)if(g.onSearchBox){var e=g.onSearchBox(v,d,k);if(e)for(var r=0;r<e.length;++r)a(e[r])}else{e=function(a,c){c=c||{};c=Object.assign({skipFilter:!1,inTypeOverride:!1,outTypeOverride:!1},c);var e=
|
||||
f.registered_node_types[a];if(u&&e.filter!=u||(!b.show_all_if_empty||d)&&-1===a.toLowerCase().indexOf(d))return!1;if(b.do_type_filter&&!c.skipFilter){e=y.value;!1!==c.inTypeOverride&&(e=c.inTypeOverride);if(y&&e&&f.registered_slot_in_types[e]&&f.registered_slot_in_types[e].nodes&&(e=f.registered_slot_in_types[e].nodes.includes(a),!1===e))return!1;e=q.value;!1!==c.outTypeOverride&&(e=c.outTypeOverride);if(q&&e&&f.registered_slot_out_types[e]&&f.registered_slot_out_types[e].nodes&&(e=f.registered_slot_out_types[e].nodes.includes(a),
|
||||
!1===e))return!1}return!0};var n=0;d=d.toLowerCase();var u=k.filter||k.graph.filter;if(b.do_type_filter&&g.search_box)var y=g.search_box.querySelector(".slot_in_type_filter"),q=g.search_box.querySelector(".slot_out_type_filter");else q=y=!1;for(r in f.searchbox_extras){var p=f.searchbox_extras[r];if(b.show_all_if_empty&&!d||-1!==p.desc.toLowerCase().indexOf(d)){var l=f.registered_node_types[p.type];if((!l||l.filter==u)&&e(p.type)&&(a(p.desc,"searchbox_extra"),-1!==h.search_limit&&n++>h.search_limit))break}}p=
|
||||
null;if(Array.prototype.filter)p=Object.keys(f.registered_node_types).filter(e);else for(r in p=[],f.registered_node_types)e(r)&&p.push(r);for(r=0;r<p.length&&!(a(p[r]),-1!==h.search_limit&&n++>h.search_limit);r++);if(b.show_general_after_typefiltered&&(y.value||q.value)){filtered_extra=[];for(r in f.registered_node_types)e(r,{inTypeOverride:y&&y.value?"*":!1,outTypeOverride:q&&q.value?"*":!1})&&filtered_extra.push(r);for(r=0;r<filtered_extra.length&&!(a(filtered_extra[r],"generic_type"),-1!==h.search_limit&&
|
||||
n++>h.search_limit);r++);}if((y.value||q.value)&&0==v.childNodes.length&&b.show_general_if_none_on_typefilter){filtered_extra=[];for(r in f.registered_node_types)e(r,{skipFilter:!0})&&filtered_extra.push(r);for(r=0;r<filtered_extra.length&&!(a(filtered_extra[r],"not_in_filter"),-1!==h.search_limit&&n++>h.search_limit);r++);}}}def_options={slot_from:null,node_from:null,node_to:null,do_type_filter:f.search_filter_enabled,type_filter_in:!1,type_filter_out:!1,show_general_if_none_on_typefilter:!0,show_general_after_typefiltered:!0,
|
||||
hide_on_mouse_leave:f.search_hide_on_mouse_leave,show_all_if_empty:!0,show_all_on_open:f.search_show_all_on_open};b=Object.assign(def_options,b||{});var g=this,k=h.active_canvas,n=k.canvas,p=n.ownerDocument||document,r=document.createElement("div");r.className="litegraph litesearchbox graphdialog rounded";r.innerHTML="<span class='name'>Search</span> <input autofocus type='text' class='value rounded'/>";b.do_type_filter&&(r.innerHTML+="<select class='slot_in_type_filter'><option value=''></option></select>",
|
||||
r.innerHTML+="<select class='slot_out_type_filter'><option value=''></option></select>");r.innerHTML+="<div class='helper'></div>";p.fullscreenElement?p.fullscreenElement.appendChild(r):(p.body.appendChild(r),p.body.style.overflow="hidden");if(b.do_type_filter)var u=r.querySelector(".slot_in_type_filter"),q=r.querySelector(".slot_out_type_filter");r.close=function(){g.search_box=null;p.body.focus();p.body.style.overflow="";setTimeout(function(){g.canvas.focus()},20);r.parentNode&&r.parentNode.removeChild(r)};
|
||||
1<this.ds.scale&&(r.style.transform="scale("+this.ds.scale+")");if(b.hide_on_mouse_leave){var y=!1,l=null;f.pointerListenerAdd(r,"enter",function(a){l&&(clearTimeout(l),l=null)});f.pointerListenerAdd(r,"leave",function(a){y||(l=setTimeout(function(){r.close()},500))});b.do_type_filter&&(u.addEventListener("click",function(a){y++}),u.addEventListener("blur",function(a){y=0}),u.addEventListener("change",function(a){y=-1}),q.addEventListener("click",function(a){y++}),q.addEventListener("blur",function(a){y=
|
||||
0}),q.addEventListener("change",function(a){y=-1}))}g.search_box&&g.search_box.close();g.search_box=r;var v=r.querySelector(".helper"),m=null,w=null,t=null,z=r.querySelector("input");z&&(z.addEventListener("blur",function(a){this.focus()}),z.addEventListener("keydown",function(a){if(38==a.keyCode)e(!1);else if(40==a.keyCode)e(!0);else if(27==a.keyCode)r.close();else if(13==a.keyCode)t?c(t.innerHTML):m?c(m):r.close();else{w&&clearInterval(w);w=setTimeout(d,250);return}a.preventDefault();a.stopPropagation();
|
||||
a.stopImmediatePropagation();return!0}));if(b.do_type_filter){if(u){var x=f.slot_types_in,L=x.length;if(b.type_filter_in==f.EVENT||b.type_filter_in==f.ACTION)b.type_filter_in="_event_";for(var A=0;A<L;A++){var B=document.createElement("option");B.value=x[A];B.innerHTML=x[A];u.appendChild(B);!1!==b.type_filter_in&&(b.type_filter_in+"").toLowerCase()==(x[A]+"").toLowerCase()&&(B.selected=!0)}u.addEventListener("change",function(){d()})}if(q){x=f.slot_types_out;L=x.length;if(b.type_filter_out==f.EVENT||
|
||||
b.type_filter_out==f.ACTION)b.type_filter_out="_event_";for(A=0;A<L;A++)B=document.createElement("option"),B.value=x[A],B.innerHTML=x[A],q.appendChild(B),!1!==b.type_filter_out&&(b.type_filter_out+"").toLowerCase()==(x[A]+"").toLowerCase()&&(B.selected=!0);q.addEventListener("change",function(){d()})}}n=n.getBoundingClientRect();u=(a?a.clientY:n.top+.5*n.height)-20;r.style.left=(a?a.clientX:n.left+.5*n.width)-80+"px";r.style.top=u+"px";a.layerY>n.height-200&&(v.style.maxHeight=n.height-a.layerY-20+
|
||||
"px");z.focus();b.show_all_on_open&&d();return r};h.prototype.showEditPropertyValue=function(a,b,c){function e(){d(q.value)}function d(d){g&&g.values&&g.values.constructor===Object&&void 0!=g.values[d]&&(d=g.values[d]);"number"==typeof a.properties[b]&&(d=Number(d));if("array"==f||"object"==f)d=JSON.parse(d);a.properties[b]=d;a.graph&&a.graph._version++;if(a.onPropertyChanged)a.onPropertyChanged(b,d);if(c.onclose)c.onclose();u.close();a.setDirtyCanvas(!0,!0)}if(a&&void 0!==a.properties[b]){c=c||{};
|
||||
var g=a.getPropertyInfo(b),f=g.type,n="";if("string"==f||"number"==f||"array"==f||"object"==f)n="<input autofocus type='text' class='value'/>";else if("enum"!=f&&"combo"!=f||!g.values)if("boolean"==f||"toggle"==f)n="<input autofocus type='checkbox' class='value' "+(a.properties[b]?"checked":"")+"/>";else{console.warn("unknown type: "+f);return}else{n="<select autofocus type='text' class='value'>";for(var h in g.values){var r=h;g.values.constructor===Array&&(r=g.values[h]);n+="<option value='"+r+"' "+
|
||||
(r==a.properties[b]?"selected":"")+">"+g.values[h]+"</option>"}n+="</select>"}var u=this.createDialog("<span class='name'>"+(g.label?g.label:b)+"</span>"+n+"<button>OK</button>",c),q=!1;if("enum"!=f&&"combo"!=f||!g.values)if("boolean"==f||"toggle"==f)(q=u.querySelector("input"))&&q.addEventListener("click",function(a){u.modified();d(!!q.checked)});else{if(q=u.querySelector("input"))q.addEventListener("blur",function(a){this.focus()}),r=void 0!==a.properties[b]?a.properties[b]:"","string"!==f&&(r=
|
||||
JSON.stringify(r)),q.value=r,q.addEventListener("keydown",function(a){if(27==a.keyCode)u.close();else if(13==a.keyCode)e();else if(13!=a.keyCode){u.modified();return}a.preventDefault();a.stopPropagation()})}else q=u.querySelector("select"),q.addEventListener("change",function(a){u.modified();d(a.target.value)});q&&q.focus();u.querySelector("button").addEventListener("click",e);return u}};h.prototype.createDialog=function(a,b){def_options={checkForInput:!1,closeOnLeave:!0,closeOnLeave_checkModified:!0};
|
||||
b=Object.assign(def_options,b||{});var c=document.createElement("div");c.className="graphdialog";c.innerHTML=a;c.is_modified=!1;a=this.canvas.getBoundingClientRect();var e=-20,d=-20;a&&(e-=a.left,d-=a.top);b.position?(e+=b.position[0],d+=b.position[1]):b.event?(e+=b.event.clientX,d+=b.event.clientY):(e+=.5*this.canvas.width,d+=.5*this.canvas.height);c.style.left=e+"px";c.style.top=d+"px";this.canvas.parentNode.appendChild(c);b.checkForInput&&(a=[],(a=c.querySelectorAll("input"))&&a.forEach(function(a){a.addEventListener("keydown",
|
||||
function(a){c.modified();if(27==a.keyCode)c.close();else if(13!=a.keyCode)return;a.preventDefault();a.stopPropagation()});a.focus()}));c.modified=function(){c.is_modified=!0};c.close=function(){c.parentNode&&c.parentNode.removeChild(c)};var g=null,k=!1;c.addEventListener("mouseleave",function(a){k||(b.closeOnLeave||f.dialog_close_on_mouse_leave)&&!c.is_modified&&f.dialog_close_on_mouse_leave&&(g=setTimeout(c.close,f.dialog_close_on_mouse_leave_delay))});c.addEventListener("mouseenter",function(a){(b.closeOnLeave||
|
||||
f.dialog_close_on_mouse_leave)&&g&&clearTimeout(g)});(a=c.querySelectorAll("select"))&&a.forEach(function(a){a.addEventListener("click",function(a){k++});a.addEventListener("blur",function(a){k=0});a.addEventListener("change",function(a){k=-1})});return c};h.prototype.createPanel=function(a,b){b=b||{};var c=b.window||window,e=document.createElement("div");e.className="litegraph dialog";e.innerHTML="<div class='dialog-header'><span class='dialog-title'></span></div><div class='dialog-content'></div><div style='display:none;' class='dialog-alt-content'></div><div class='dialog-footer'></div>";
|
||||
e.header=e.querySelector(".dialog-header");b.width&&(e.style.width=b.width+(b.width.constructor===Number?"px":""));b.height&&(e.style.height=b.height+(b.height.constructor===Number?"px":""));b.closable&&(b=document.createElement("span"),b.innerHTML="✕",b.classList.add("close"),b.addEventListener("click",function(){e.close()}),e.header.appendChild(b));e.title_element=e.querySelector(".dialog-title");e.title_element.innerText=a;e.content=e.querySelector(".dialog-content");e.alt_content=e.querySelector(".dialog-alt-content");
|
||||
e.footer=e.querySelector(".dialog-footer");e.close=function(){if(e.onClose&&"function"==typeof e.onClose)e.onClose();e.parentNode.removeChild(e);this.parentNode&&this.parentNode.removeChild(this)};e.toggleAltContent=function(a){if("undefined"!=typeof a){var b=a?"block":"none";a=a?"none":"block"}else b="block"!=e.alt_content.style.display?"block":"none",a="block"!=e.alt_content.style.display?"none":"block";e.alt_content.style.display=b;e.content.style.display=a};e.toggleFooterVisibility=function(a){e.footer.style.display=
|
||||
"undefined"!=typeof a?a?"block":"none":"block"!=e.footer.style.display?"block":"none"};e.clear=function(){this.content.innerHTML=""};e.addHTML=function(a,b,c){var d=document.createElement("div");b&&(d.className=b);d.innerHTML=a;c?e.footer.appendChild(d):e.content.appendChild(d);return d};e.addButton=function(a,b,c){var d=document.createElement("button");d.innerText=a;d.options=c;d.classList.add("btn");d.addEventListener("click",b);e.footer.appendChild(d);return d};e.addSeparator=function(){var a=
|
||||
document.createElement("div");a.className="separator";e.content.appendChild(a)};e.addWidget=function(a,b,k,n,p){function d(a,b){n.callback&&n.callback(a,b,n);p&&p(a,b,n)}n=n||{};var g=String(k);a=a.toLowerCase();"number"==a&&(g=k.toFixed(3));var q=document.createElement("div");q.className="property";q.innerHTML="<span class='property_name'></span><span class='property_value'></span>";q.querySelector(".property_name").innerText=n.label||b;var y=q.querySelector(".property_value");y.innerText=g;q.dataset.property=
|
||||
b;q.dataset.type=n.type||a;q.options=n;q.value=k;if("code"==a)q.addEventListener("click",function(a){e.inner_showCodePad(this.dataset.property)});else if("boolean"==a)q.classList.add("boolean"),k&&q.classList.add("bool-on"),q.addEventListener("click",function(){var a=this.dataset.property;this.value=!this.value;this.classList.toggle("bool-on");this.querySelector(".property_value").innerText=this.value?"true":"false";d(a,this.value)});else if("string"==a||"number"==a)y.setAttribute("contenteditable",
|
||||
!0),y.addEventListener("keydown",function(b){"Enter"!=b.code||"string"==a&&b.shiftKey||(b.preventDefault(),this.blur())}),y.addEventListener("blur",function(){var a=this.innerText,b=this.parentNode.dataset.property;"number"==this.parentNode.dataset.type&&(a=Number(a));d(b,a)});else if("enum"==a||"combo"==a)g=h.getPropertyPrintableValue(k,n.values),y.innerText=g,y.addEventListener("click",function(a){var b=this.parentNode.dataset.property,e=this;new f.ContextMenu(n.values||[],{event:a,className:"dark",
|
||||
callback:function(a,c,g){e.innerText=a;d(b,a);return!1}},c)});e.content.appendChild(q);return q};if(e.onOpen&&"function"==typeof e.onOpen)e.onOpen();return e};h.getPropertyPrintableValue=function(a,b){if(!b||b.constructor===Array)return String(a);if(b.constructor===Object){var c="",e;for(e in b)if(b[e]==a){c=e;break}return String(a)+" ("+c+")"}};h.prototype.closePanels=function(){var a=document.querySelector("#node-panel");a&&a.close();(a=document.querySelector("#option-panel"))&&a.close()};h.prototype.showShowGraphOptionsPanel=
|
||||
function(a,b,c,e){if(this.constructor&&"HTMLDivElement"==this.constructor.name){if(!(b&&b.event&&b.event.target&&b.event.target.lgraphcanvas)){console.warn("Canvas not found");return}var d=b.event.target.lgraphcanvas}else d=this;d.closePanels();a=d.getCanvasWindow();panel=d.createPanel("Options",{closable:!0,window:a,onOpen:function(){d.OPTIONPANEL_IS_OPEN=!0},onClose:function(){d.OPTIONPANEL_IS_OPEN=!1;d.options_panel=null}});d.options_panel=panel;panel.id="option-panel";panel.classList.add("settings");
|
||||
(function(){panel.content.innerHTML="";var a=function(a,b,c){c&&c.key&&(a=c.key);c.values&&(b=Object.values(c.values).indexOf(b));d[a]=b},b=f.availableCanvasOptions;b.sort();for(pI in b){var c=b[pI];panel.addWidget("boolean",c,d[c],{key:c,on:"True",off:"False"},a)}panel.addWidget("combo","Render mode",f.LINK_RENDER_MODES[d.links_render_mode],{key:"links_render_mode",values:f.LINK_RENDER_MODES},a);panel.addSeparator();panel.footer.innerHTML=""})();d.canvas.parentNode.appendChild(panel)};h.prototype.showShowNodePanel=
|
||||
function(a){function b(){panel.content.innerHTML="";panel.addHTML("<span class='node_type'>"+a.type+"</span><span class='node_desc'>"+(a.constructor.desc||"")+"</span><span class='separator'></span>");panel.addHTML("<h3>Properties</h3>");var b=function(b,c){e.graph.beforeChange(a);switch(b){case "Title":a.title=c;break;case "Mode":b=Object.values(f.NODE_MODES).indexOf(c);0<=b&&f.NODE_MODES[b]?a.changeMode(b):console.warn("unexpected mode: "+c);break;case "Color":h.node_colors[c]?(a.color=h.node_colors[c].color,
|
||||
a.bgcolor=h.node_colors[c].bgcolor):console.warn("unexpected color: "+c);break;default:a.setProperty(b,c)}e.graph.afterChange();e.dirty_canvas=!0};panel.addWidget("string","Title",a.title,{},b);panel.addWidget("combo","Mode",f.NODE_MODES[a.mode],{values:f.NODE_MODES},b);var c="";void 0!==a.color&&(c=Object.keys(h.node_colors).filter(function(b){return h.node_colors[b].color==a.color}));panel.addWidget("combo","Color",c,{values:Object.keys(h.node_colors)},b);for(var k in a.properties){c=a.properties[k];
|
||||
var n=a.getPropertyInfo(k);a.onAddPropertyToPanel&&a.onAddPropertyToPanel(k,panel)||panel.addWidget(n.widget||n.type,k,c,n,b)}panel.addSeparator();if(a.onShowCustomPanelInfo)a.onShowCustomPanelInfo(panel);panel.footer.innerHTML="";panel.addButton("Delete",function(){a.block_delete||(a.graph.remove(a),panel.close())}).classList.add("delete")}this.SELECTED_NODE=a;this.closePanels();var c=this.getCanvasWindow(),e=this;panel=this.createPanel(a.title||"",{closable:!0,window:c,onOpen:function(){e.NODEPANEL_IS_OPEN=
|
||||
!0},onClose:function(){e.NODEPANEL_IS_OPEN=!1;e.node_panel=null}});e.node_panel=panel;panel.id="node-panel";panel.node=a;panel.classList.add("settings");panel.inner_showCodePad=function(c){panel.classList.remove("settings");panel.classList.add("centered");panel.alt_content.innerHTML="<textarea class='code'></textarea>";var d=panel.alt_content.querySelector("textarea"),e=function(){panel.toggleAltContent(!1);panel.toggleFooterVisibility(!0);d.parentNode.removeChild(d);panel.classList.add("settings");
|
||||
panel.classList.remove("centered");b()};d.value=a.properties[c];d.addEventListener("keydown",function(b){"Enter"==b.code&&b.ctrlKey&&(a.setProperty(c,d.value),e())});panel.toggleAltContent(!0);panel.toggleFooterVisibility(!1);d.style.height="calc(100% - 40px)";var f=panel.addButton("Assign",function(){a.setProperty(c,d.value);e()});panel.alt_content.appendChild(f);f=panel.addButton("Close",e);f.style.float="right";panel.alt_content.appendChild(f)};b();this.canvas.parentNode.appendChild(panel)};h.prototype.showSubgraphPropertiesDialog=
|
||||
function(a){function b(){e.clear();if(a.inputs)for(var c=0;c<a.inputs.length;++c){var g=a.inputs[c];if(!g.not_subgraph_input){var f=e.addHTML("<button>✕</button> <span class='bullet_icon'></span><span class='name'></span><span class='type'></span>","subgraph_property");f.dataset.name=g.name;f.dataset.slot=c;f.querySelector(".name").innerText=g.name;f.querySelector(".type").innerText=g.type;f.querySelector("button").addEventListener("click",function(c){a.removeInput(Number(this.parentNode.dataset.slot));
|
||||
b()})}}}console.log("showing subgraph properties dialog");var c=this.canvas.parentNode.querySelector(".subgraph_dialog");c&&c.close();var e=this.createPanel("Subgraph Inputs",{closable:!0,width:500});e.node=a;e.classList.add("subgraph_dialog");e.addHTML(" + <span class='label'>Name</span><input class='name'/><span class='label'>Type</span><input class='type'></input><button>+</button>","subgraph_property extra",!0).querySelector("button").addEventListener("click",function(c){c=this.parentNode;var d=
|
||||
c.querySelector(".name").value,e=c.querySelector(".type").value;d&&-1==a.findInputSlot(d)&&(a.addInput(d,e),c.querySelector(".name").value="",c.querySelector(".type").value="",b())});b();this.canvas.parentNode.appendChild(e);return e};h.prototype.showSubgraphPropertiesDialogRight=function(a){function b(){d.clear();if(a.outputs)for(var c=0;c<a.outputs.length;++c){var e=a.outputs[c];if(!e.not_subgraph_output){var f=d.addHTML("<button>✕</button> <span class='bullet_icon'></span><span class='name'></span><span class='type'></span>",
|
||||
"subgraph_property");f.dataset.name=e.name;f.dataset.slot=c;f.querySelector(".name").innerText=e.name;f.querySelector(".type").innerText=e.type;f.querySelector("button").addEventListener("click",function(c){a.removeOutput(Number(this.parentNode.dataset.slot));b()})}}}function c(){var c=this.parentNode,d=c.querySelector(".name").value,e=c.querySelector(".type").value;d&&-1==a.findOutputSlot(d)&&(a.addOutput(d,e),c.querySelector(".name").value="",c.querySelector(".type").value="",b())}var e=this.canvas.parentNode.querySelector(".subgraph_dialog");
|
||||
e&&e.close();var d=this.createPanel("Subgraph Outputs",{closable:!0,width:500});d.node=a;d.classList.add("subgraph_dialog");e=d.addHTML(" + <span class='label'>Name</span><input class='name'/><span class='label'>Type</span><input class='type'></input><button>+</button>","subgraph_property extra",!0);e.querySelector(".name").addEventListener("keydown",function(a){13==a.keyCode&&c.apply(this)});e.querySelector("button").addEventListener("click",function(a){c.apply(this)});b();this.canvas.parentNode.appendChild(d);
|
||||
return d};h.prototype.checkPanels=function(){if(this.canvas)for(var a=this.canvas.parentNode.querySelectorAll(".litegraph.dialog"),b=0;b<a.length;++b){var c=a[b];c.node&&(c.node.graph&&c.graph==this.graph||c.close())}};h.onMenuNodeCollapse=function(a,b,c,e,d){d.graph.beforeChange();a=h.active_canvas;if(!a.selected_nodes||1>=Object.keys(a.selected_nodes).length)d.collapse();else for(var f in a.selected_nodes)a.selected_nodes[f].collapse();d.graph.afterChange()};h.onMenuNodePin=function(a,b,c,e,d){d.pin()};
|
||||
h.onMenuNodeMode=function(a,b,c,e,d){new f.ContextMenu(f.NODE_MODES,{event:c,callback:function(a){if(d){var b=Object.values(f.NODE_MODES).indexOf(a),c=function(c){0<=b&&f.NODE_MODES[b]?c.changeMode(b):(console.warn("unexpected mode: "+a),c.changeMode(f.ALWAYS))},e=h.active_canvas;if(!e.selected_nodes||1>=Object.keys(e.selected_nodes).length)c(d);else for(var g in e.selected_nodes)c(e.selected_nodes[g])}},parentMenu:e,node:d});return!1};h.onMenuNodeColors=function(a,b,c,e,d){if(!d)throw"no node for color";
|
||||
b=[];b.push({value:null,content:"<span style='display: block; padding-left: 4px;'>No color</span>"});for(var g in h.node_colors)a=h.node_colors[g],a={value:g,content:"<span style='display: block; color: #999; padding-left: 4px; border-left: 8px solid "+a.color+"; background-color:"+a.bgcolor+"'>"+g+"</span>"},b.push(a);new f.ContextMenu(b,{event:c,callback:function(a){if(d){var b=a.value?h.node_colors[a.value]:null;a=function(a){b?a.constructor===f.LGraphGroup?a.color=b.groupcolor:(a.color=b.color,
|
||||
a.bgcolor=b.bgcolor):(delete a.color,delete a.bgcolor)};var c=h.active_canvas;if(!c.selected_nodes||1>=Object.keys(c.selected_nodes).length)a(d);else for(var e in c.selected_nodes)a(c.selected_nodes[e]);d.setDirtyCanvas(!0,!0)}},parentMenu:e,node:d});return!1};h.onMenuNodeShapes=function(a,b,c,e,d){if(!d)throw"no node passed";new f.ContextMenu(f.VALID_SHAPES,{event:c,callback:function(a){if(d){d.graph.beforeChange();var b=h.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)d.shape=
|
||||
a;else for(var c in b.selected_nodes)b.selected_nodes[c].shape=a;d.graph.afterChange();d.setDirtyCanvas(!0)}},parentMenu:e,node:d});return!1};h.onMenuNodeRemove=function(a,b,c,e,d){if(!d)throw"no node passed";a=d.graph;a.beforeChange();b=h.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)!1!==d.removable&&a.remove(d);else for(var f in b.selected_nodes)c=b.selected_nodes[f],!1!==c.removable&&a.remove(c);a.afterChange();d.setDirtyCanvas(!0,!0)};h.onMenuNodeToSubgraph=function(a,
|
||||
b,c,e,d){a=d.graph;if(b=h.active_canvas)c=Object.values(b.selected_nodes||{}),c.length||(c=[d]),e=f.createNode("graph/subgraph"),e.pos=d.pos.concat(),a.add(e),e.buildFromNodes(c),b.deselectAllNodes(),d.setDirtyCanvas(!0,!0)};h.onMenuNodeClone=function(a,b,c,e,d){d.graph.beforeChange();var f={};a=function(a){if(0!=a.clonable){var b=a.clone();b&&(b.pos=[a.pos[0]+5,a.pos[1]+5],a.graph.add(b),f[b.id]=b)}};b=h.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)a(d);else for(var k in b.selected_nodes)a(b.selected_nodes[k]);
|
||||
Object.keys(f).length&&b.selectNodes(f);d.graph.afterChange();d.setDirtyCanvas(!0,!0)};h.node_colors={red:{color:"#322",bgcolor:"#533",groupcolor:"#A88"},brown:{color:"#332922",bgcolor:"#593930",groupcolor:"#b06634"},green:{color:"#232",bgcolor:"#353",groupcolor:"#8A8"},blue:{color:"#223",bgcolor:"#335",groupcolor:"#88A"},pale_blue:{color:"#2a363b",bgcolor:"#3f5159",groupcolor:"#3f789e"},cyan:{color:"#233",bgcolor:"#355",groupcolor:"#8AA"},purple:{color:"#323",bgcolor:"#535",groupcolor:"#a1309b"},
|
||||
yellow:{color:"#432",bgcolor:"#653",groupcolor:"#b58b2a"},black:{color:"#222",bgcolor:"#000",groupcolor:"#444"}};h.prototype.getCanvasMenuOptions=function(){if(this.getMenuOptions)var a=this.getMenuOptions();else a=[{content:"Add Node",has_submenu:!0,callback:h.onMenuAdd},{content:"Add Group",callback:h.onGroupAdd}],this._graph_stack&&0<this._graph_stack.length&&a.push(null,{content:"Close subgraph",callback:this.closeSubgraph.bind(this)});if(this.getExtraMenuOptions){var b=this.getExtraMenuOptions(this,
|
||||
a);b&&(a=a.concat(b))}return a};h.prototype.getNodeMenuOptions=function(a){if(a.getMenuOptions)var b=a.getMenuOptions(this);else b=[{content:"Inputs",has_submenu:!0,disabled:!0,callback:h.showMenuNodeOptionalInputs},{content:"Outputs",has_submenu:!0,disabled:!0,callback:h.showMenuNodeOptionalOutputs},null,{content:"Properties",has_submenu:!0,callback:h.onShowMenuNodeProperties},null,{content:"Title",callback:h.onShowPropertyEditor},{content:"Mode",has_submenu:!0,callback:h.onMenuNodeMode}],!1!==a.resizable&&
|
||||
b.push({content:"Resize",callback:h.onMenuResizeNode}),b.push({content:"Collapse",callback:h.onMenuNodeCollapse},{content:"Pin",callback:h.onMenuNodePin},{content:"Colors",has_submenu:!0,callback:h.onMenuNodeColors},{content:"Shapes",has_submenu:!0,callback:h.onMenuNodeShapes},null);if(a.onGetInputs){var c=a.onGetInputs();c&&c.length&&(b[0].disabled=!1)}a.onGetOutputs&&(c=a.onGetOutputs())&&c.length&&(b[1].disabled=!1);a.getExtraMenuOptions&&(c=a.getExtraMenuOptions(this,b))&&(c.push(null),b=c.concat(b));
|
||||
!1!==a.clonable&&b.push({content:"Clone",callback:h.onMenuNodeClone});b.push(null,{content:"Remove",disabled:!(!1!==a.removable&&!a.block_delete),callback:h.onMenuNodeRemove});if(a.graph&&a.graph.onGetNodeMenuOptions)a.graph.onGetNodeMenuOptions(b,a);return b};h.prototype.getGroupMenuOptions=function(a){return[{content:"Title",callback:h.onShowPropertyEditor},{content:"Color",has_submenu:!0,callback:h.onMenuNodeColors},{content:"Font size",property:"font_size",type:"Number",callback:h.onShowPropertyEditor},
|
||||
null,{content:"Remove",callback:h.onMenuNodeRemove}]};h.prototype.processContextMenu=function(a,b){var c=this,e=h.active_canvas.getCanvasWindow(),d=null,g={event:b,callback:function(b,d,e){if(b)if("Remove Slot"==b.content)b=b.slot,a.graph.beforeChange(),b.input?a.removeInput(b.slot):b.output&&a.removeOutput(b.slot),a.graph.afterChange();else if("Disconnect Links"==b.content)b=b.slot,a.graph.beforeChange(),b.output?a.disconnectOutput(b.slot):b.input&&a.disconnectInput(b.slot),a.graph.afterChange();
|
||||
else if("Rename Slot"==b.content){b=b.slot;var f=b.input?a.getInputInfo(b.slot):a.getOutputInfo(b.slot),g=c.createDialog("<span class='name'>Name</span><input autofocus type='text'/><button>OK</button>",d),r=g.querySelector("input");r&&f&&(r.value=f.label||"");var k=function(){a.graph.beforeChange();r.value&&(f&&(f.label=r.value),c.setDirty(!0));g.close();a.graph.afterChange()};g.querySelector("button").addEventListener("click",k);r.addEventListener("keydown",function(a){g.is_modified=!0;if(27==a.keyCode)g.close();
|
||||
else if(13==a.keyCode)k();else if(13!=a.keyCode&&"textarea"!=a.target.localName)return;a.preventDefault();a.stopPropagation()});r.focus()}},extra:a};a&&(g.title=a.type);var k=null;a&&(k=a.getSlotInPosition(b.canvasX,b.canvasY),h.active_node=a);k?(d=[],a.getSlotMenuOptions?d=a.getSlotMenuOptions(k):(k&&k.output&&k.output.links&&k.output.links.length&&d.push({content:"Disconnect Links",slot:k}),b=k.input||k.output,b.removable&&d.push(b.locked?"Cannot remove":{content:"Remove Slot",slot:k}),b.nameLocked||
|
||||
d.push({content:"Rename Slot",slot:k})),g.title=(k.input?k.input.type:k.output.type)||"*",k.input&&k.input.type==f.ACTION&&(g.title="Action"),k.output&&k.output.type==f.EVENT&&(g.title="Event")):a?d=this.getNodeMenuOptions(a):(d=this.getCanvasMenuOptions(),(k=this.graph.getGroupOnPos(b.canvasX,b.canvasY))&&d.push(null,{content:"Edit Group",has_submenu:!0,submenu:{title:"Group",extra:k,options:this.getGroupMenuOptions(k)}}));d&&new f.ContextMenu(d,g,e)};"undefined"!=typeof window&&window.CanvasRenderingContext2D&&
|
||||
!window.CanvasRenderingContext2D.prototype.roundRect&&(window.CanvasRenderingContext2D.prototype.roundRect=function(a,b,c,e,d,f){var g,h;if(0===d)this.rect(a,b,c,e);else{void 0===f&&(f=d);if(null!=d&&d.constructor===Array)if(1==d.length)var l=g=h=f=d[0];else if(2==d.length)l=f=d[0],g=h=d[1];else if(4==d.length)l=d[0],g=d[1],h=d[2],f=d[3];else return;else l=d||0,g=d||0,h=f||0,f=f||0;this.moveTo(a+l,b);this.lineTo(a+c-g,b);this.quadraticCurveTo(a+c,b,a+c,b+g);this.lineTo(a+c,b+e-f);this.quadraticCurveTo(a+
|
||||
c,b+e,a+c-f,b+e);this.lineTo(a+f,b+e);this.quadraticCurveTo(a,b+e,a,b+e-h);this.lineTo(a,b+h);this.quadraticCurveTo(a,b,a+l,b)}});f.compareObjects=function(a,b){for(var c in a)if(a[c]!=b[c])return!1;return!0};f.distance=D;f.colorToString=function(a){return"rgba("+Math.round(255*a[0]).toFixed()+","+Math.round(255*a[1]).toFixed()+","+Math.round(255*a[2]).toFixed()+","+(4==a.length?a[3].toFixed(2):"1.0")+")"};f.isInsideRectangle=C;f.growBounding=function(a,b,c){b<a[0]?a[0]=b:b>a[2]&&(a[2]=b);c<a[1]?
|
||||
a[1]=c:c>a[3]&&(a[3]=c)};f.isInsideBounding=function(a,b){return a[0]<b[0][0]||a[1]<b[0][1]||a[0]>b[1][0]||a[1]>b[1][1]?!1:!0};f.overlapBounding=A;f.hex2num=function(a){"#"==a.charAt(0)&&(a=a.slice(1));a=a.toUpperCase();for(var b=Array(3),c=0,e,d,f=0;6>f;f+=2)e="0123456789ABCDEF".indexOf(a.charAt(f)),d="0123456789ABCDEF".indexOf(a.charAt(f+1)),b[c]=16*e+d,c++;return b};f.num2hex=function(a){for(var b="#",c,e,d=0;3>d;d++)c=a[d]/16,e=a[d]%16,b+="0123456789ABCDEF".charAt(c)+"0123456789ABCDEF".charAt(e);
|
||||
return b};E.prototype.addItem=function(a,b,c){function e(a){var b=this.value;b&&b.has_submenu&&d.call(this,a)}function d(a){var b=this.value,d=!0;g.current_submenu&&g.current_submenu.close(a);if(c.callback){var e=c.callback.call(this,b,c,a,g,c.node);!0===e&&(d=!1)}if(b&&(b.callback&&!c.ignore_item_callbacks&&!0!==b.disabled&&(e=b.callback.call(this,b,c,a,g,c.extra),!0===e&&(d=!1)),b.submenu)){if(!b.submenu.options)throw"ContextMenu submenu needs options";new g.constructor(b.submenu.options,{callback:b.submenu.callback,
|
||||
event:a,parentMenu:g,ignore_item_callbacks:b.submenu.ignore_item_callbacks,title:b.submenu.title,extra:b.submenu.extra,autoopen:c.autoopen});d=!1}d&&!g.lock&&g.close()}var g=this;c=c||{};var k=document.createElement("div");k.className="litemenu-entry submenu";var h=!1;if(null===b)k.classList.add("separator");else{k.innerHTML=b&&b.title?b.title:a;if(k.value=b)b.disabled&&(h=!0,k.classList.add("disabled")),(b.submenu||b.has_submenu)&&k.classList.add("has_submenu");"function"==typeof b?(k.dataset.value=
|
||||
a,k.onclick_callback=b):k.dataset.value=b;b.className&&(k.className+=" "+b.className)}this.root.appendChild(k);h||k.addEventListener("click",d);c.autoopen&&f.pointerListenerAdd(k,"enter",e);return k};E.prototype.close=function(a,b){this.root.parentNode&&this.root.parentNode.removeChild(this.root);this.parentMenu&&!b&&(this.parentMenu.lock=!1,this.parentMenu.current_submenu=null,void 0===a?this.parentMenu.close():a&&!E.isCursorOverElement(a,this.parentMenu.root)&&E.trigger(this.parentMenu.root,f.pointerevents_method+
|
||||
"leave",a));this.current_submenu&&this.current_submenu.close(a,!0);this.root.closing_timer&&clearTimeout(this.root.closing_timer)};E.trigger=function(a,b,c,e){var d=document.createEvent("CustomEvent");d.initCustomEvent(b,!0,!0,c);d.srcElement=e;a.dispatchEvent?a.dispatchEvent(d):a.__events&&a.__events.dispatchEvent(d);return d};E.prototype.getTopMenu=function(){return this.options.parentMenu?this.options.parentMenu.getTopMenu():this};E.prototype.getFirstEvent=function(){return this.options.parentMenu?
|
||||
this.options.parentMenu.getFirstEvent():this.options.event};E.isCursorOverElement=function(a,b){var c=a.clientX;a=a.clientY;return(b=b.getBoundingClientRect())?a>b.top&&a<b.top+b.height&&c>b.left&&c<b.left+b.width?!0:!1:!1};f.ContextMenu=E;f.closeAllContextMenus=function(a){a=a||window;a=a.document.querySelectorAll(".litecontextmenu");if(a.length){for(var b=[],c=0;c<a.length;c++)b.push(a[c]);for(c=0;c<b.length;c++)b[c].close?b[c].close():b[c].parentNode&&b[c].parentNode.removeChild(b[c])}};f.extendClass=
|
||||
function(a,b){for(var c in b)a.hasOwnProperty(c)||(a[c]=b[c]);if(b.prototype)for(c in b.prototype)b.prototype.hasOwnProperty(c)&&!a.prototype.hasOwnProperty(c)&&(b.prototype.__lookupGetter__(c)?a.prototype.__defineGetter__(c,b.prototype.__lookupGetter__(c)):a.prototype[c]=b.prototype[c],b.prototype.__lookupSetter__(c)&&a.prototype.__defineSetter__(c,b.prototype.__lookupSetter__(c)))};G.sampleCurve=function(a,b){if(b){for(var c=0;c<b.length-1;++c){var e=b[c],d=b[c+1];if(!(d[0]<a)){b=d[0]-e[0];if(1E-5>
|
||||
Math.abs(b))return e[1];a=(a-e[0])/b;return e[1]*(1-a)+d[1]*a}}return 0}};G.prototype.draw=function(a,b,c,e,d,f){if(c=this.points){this.size=b;var g=b[0]-2*this.margin;b=b[1]-2*this.margin;d=d||"#666";a.save();a.translate(this.margin,this.margin);e&&(a.fillStyle="#111",a.fillRect(0,0,g,b),a.fillStyle="#222",a.fillRect(.5*g,0,1,b),a.strokeStyle="#333",a.strokeRect(0,0,g,b));a.strokeStyle=d;f&&(a.globalAlpha=.5);a.beginPath();for(e=0;e<c.length;++e)d=c[e],a.lineTo(d[0]*g,(1-d[1])*b);a.stroke();a.globalAlpha=
|
||||
1;if(!f)for(e=0;e<c.length;++e)d=c[e],a.fillStyle=this.selected==e?"#FFF":this.nearest==e?"#DDD":"#AAA",a.beginPath(),a.arc(d[0]*g,(1-d[1])*b,2,0,2*Math.PI),a.fill();a.restore()}};G.prototype.onMouseDown=function(a,b){var c=this.points;if(c&&!(0>a[1])){var e=this.size[0]-2*this.margin,d=this.size[1]-2*this.margin,f=a[0]-this.margin;a=a[1]-this.margin;this.selected=this.getCloserPoint([f,a],30/b.ds.scale);-1==this.selected&&(b=[f/e,1-a/d],c.push(b),c.sort(function(a,b){return a[0]-b[0]}),this.selected=
|
||||
c.indexOf(b),this.must_update=!0);if(-1!=this.selected)return!0}};G.prototype.onMouseMove=function(a,b){var c=this.points;if(c){var e=this.selected;if(!(0>e)){var d=(a[0]-this.margin)/(this.size[0]-2*this.margin),f=(a[1]-this.margin)/(this.size[1]-2*this.margin);this._nearest=this.getCloserPoint([a[0]-this.margin,a[1]-this.margin],30/b.ds.scale);if(b=c[e]){var k=0==e||e==c.length-1;!k&&(-10>a[0]||a[0]>this.size[0]+10||-10>a[1]||a[1]>this.size[1]+10)?(c.splice(e,1),this.selected=-1):(b[0]=k?0==e?0:
|
||||
1:Math.clamp(d,0,1),b[1]=1-Math.clamp(f,0,1),c.sort(function(a,b){return a[0]-b[0]}),this.selected=c.indexOf(b),this.must_update=!0)}}}};G.prototype.onMouseUp=function(a,b){this.selected=-1;return!1};G.prototype.getCloserPoint=function(a,b){var c=this.points;if(!c)return-1;b=b||30;for(var e=this.size[0]-2*this.margin,d=this.size[1]-2*this.margin,f=c.length,k=[0,0],h=1E6,l=-1,r=0;r<f;++r){var u=c[r];k[0]=u[0]*e;k[1]=(1-u[1])*d;u=vec2.distance(a,k);u>h||u>b||(l=r,h=u)}return l};f.CurveEditor=G;f.getParameterNames=
|
||||
function(a){return(a+"").replace(/[/][/].*$/gm,"").replace(/\s+/g,"").replace(/[/][*][^/*]*[*][/]/g,"").split("){",1)[0].replace(/^[^(]*[(]/,"").replace(/=[^,]+/g,"").split(",").filter(Boolean)};f.pointerListenerAdd=function(a,b,c,e){e=void 0===e?!1:e;if(a&&a.addEventListener&&b&&"function"===typeof c){var d=f.pointerevents_method;if("pointer"==d&&!window.PointerEvent)switch(console.warn("sMethod=='pointer' && !window.PointerEvent"),console.log("Converting pointer["+b+"] : down move up cancel enter TO touchstart touchmove touchend, etc .."),
|
||||
b){case "down":d="touch";b="start";break;case "move":d="touch";break;case "up":d="touch";b="end";break;case "cancel":d="touch";break;case "enter":console.log("debug: Should I send a move event?");break;default:console.warn("PointerEvent not available in this browser ? The event "+b+" would not be called")}switch(b){case "down":case "up":case "move":case "over":case "out":case "enter":a.addEventListener(d+b,c,e);case "leave":case "cancel":case "gotpointercapture":case "lostpointercapture":if("mouse"!=
|
||||
d)return a.addEventListener(d+b,c,e);default:return a.addEventListener(b,c,e)}}};f.pointerListenerRemove=function(a,b,c,e){e=void 0===e?!1:e;if(a&&a.removeEventListener&&b&&"function"===typeof c)switch(b){case "down":case "up":case "move":case "over":case "out":case "enter":"pointer"!=f.pointerevents_method&&"mouse"!=f.pointerevents_method||a.removeEventListener(f.pointerevents_method+b,c,e);case "leave":case "cancel":case "gotpointercapture":case "lostpointercapture":if("pointer"==f.pointerevents_method)return a.removeEventListener(f.pointerevents_method+
|
||||
b,c,e);default:return a.removeEventListener(b,c,e)}};Math.clamp=function(a,b,c){return b>a?b:c<a?c:a};"undefined"==typeof window||window.requestAnimationFrame||(window.requestAnimationFrame=window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(a){window.setTimeout(a,1E3/60)})})(this);"undefined"!=typeof exports&&(exports.LiteGraph=this.LiteGraph);
|
||||
-a.pos[1]-.5*a.size[1]+.5*this.canvas.height/this.ds.scale;this.setDirty(!0,!0)};h.prototype.adjustMouseEvent=function(a){if(this.canvas){var b=this.canvas.getBoundingClientRect();var c=a.clientX-b.left;b=a.clientY-b.top}else c=a.clientX,b=a.clientY;a.deltaX=c-this.last_mouse_position[0];a.deltaY=b-this.last_mouse_position[1];this.last_mouse_position[0]=c;this.last_mouse_position[1]=b;a.canvasX=c/this.ds.scale-this.ds.offset[0];a.canvasY=b/this.ds.scale-this.ds.offset[1]};h.prototype.setZoom=function(a,
|
||||
b){this.ds.changeScale(a,b);this.dirty_bgcanvas=this.dirty_canvas=!0};h.prototype.convertOffsetToCanvas=function(a,b){return this.ds.convertOffsetToCanvas(a,b)};h.prototype.convertCanvasToOffset=function(a,b){return this.ds.convertCanvasToOffset(a,b)};h.prototype.convertEventToCanvasOffset=function(a){var b=this.canvas.getBoundingClientRect();return this.convertCanvasToOffset([a.clientX-b.left,a.clientY-b.top])};h.prototype.bringToFront=function(a){var b=this.graph._nodes.indexOf(a);-1!=b&&(this.graph._nodes.splice(b,
|
||||
1),this.graph._nodes.push(a))};h.prototype.sendToBack=function(a){var b=this.graph._nodes.indexOf(a);-1!=b&&(this.graph._nodes.splice(b,1),this.graph._nodes.unshift(a))};var L=new Float32Array(4);h.prototype.computeVisibleNodes=function(a,b){b=b||[];b.length=0;a=a||this.graph._nodes;for(var c=0,e=a.length;c<e;++c){var d=a[c];(!this.live_mode||d.onDrawBackground||d.onDrawForeground)&&A(this.visible_area,d.getBounding(L))&&b.push(d)}return b};h.prototype.draw=function(a,b){if(this.canvas&&0!=this.canvas.width&&
|
||||
0!=this.canvas.height){var c=f.getTime();this.render_time=.001*(c-this.last_draw_time);this.last_draw_time=c;this.graph&&this.ds.computeVisibleArea(this.viewport);(this.dirty_bgcanvas||b||this.always_render_background||this.graph&&this.graph._last_trigger_time&&1E3>c-this.graph._last_trigger_time)&&this.drawBackCanvas();(this.dirty_canvas||a)&&this.drawFrontCanvas();this.fps=this.render_time?1/this.render_time:0;this.frame+=1}};h.prototype.drawFrontCanvas=function(){this.dirty_canvas=!1;this.ctx||
|
||||
(this.ctx=this.bgcanvas.getContext("2d"));var a=this.ctx;if(a){var b=this.canvas;a.start2D&&!this.viewport&&(a.start2D(),a.restore(),a.setTransform(1,0,0,1,0,0));var c=this.viewport||this.dirty_area;c&&(a.save(),a.beginPath(),a.rect(c[0],c[1],c[2],c[3]),a.clip());this.clear_background&&(c?a.clearRect(c[0],c[1],c[2],c[3]):a.clearRect(0,0,b.width,b.height));this.bgcanvas==this.canvas?this.drawBackCanvas():a.drawImage(this.bgcanvas,0,0);if(this.onRender)this.onRender(b,a);this.show_info&&this.renderInfo(a,
|
||||
c?c[0]:0,c?c[1]:0);if(this.graph){a.save();this.ds.toCanvasContext(a);b=this.computeVisibleNodes(null,this.visible_nodes);for(var e=0;e<b.length;++e){var d=b[e];a.save();a.translate(d.pos[0],d.pos[1]);this.drawNode(d,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;d=this.connecting_output||this.connecting_input;b=d.type;e=d.dir;null==e&&(e=
|
||||
this.connecting_output?this.connecting_node.horizontal?f.DOWN:f.RIGHT:this.connecting_node.horizontal?f.UP:f.LEFT);var g=d.shape;switch(b){case f.EVENT:d=f.EVENT_LINK_COLOR;break;default:d=f.CONNECTING_LINK_COLOR}this.renderLink(a,this.connecting_pos,[this.graph_mouse[0],this.graph_mouse[1]],null,!1,null,d,e,f.CENTER);a.beginPath();b===f.EVENT||g===f.BOX_SHAPE?(a.rect(this.connecting_pos[0]-6+.5,this.connecting_pos[1]-5+.5,14,10),a.fill(),a.beginPath(),a.rect(this.graph_mouse[0]-6+.5,this.graph_mouse[1]-
|
||||
5+.5,14,10)):g===f.ARROW_SHAPE?(a.moveTo(this.connecting_pos[0]+8,this.connecting_pos[1]+.5),a.lineTo(this.connecting_pos[0]-4,this.connecting_pos[1]+6+.5),a.lineTo(this.connecting_pos[0]-4,this.connecting_pos[1]-6+.5),a.closePath()):(a.arc(this.connecting_pos[0],this.connecting_pos[1],4,0,2*Math.PI),a.fill(),a.beginPath(),a.arc(this.graph_mouse[0],this.graph_mouse[1],4,0,2*Math.PI));a.fill();a.fillStyle="#ffcc00";if(this._highlight_input){a.beginPath();var k=this._highlight_input_slot.shape;k===
|
||||
f.ARROW_SHAPE?(a.moveTo(this._highlight_input[0]+8,this._highlight_input[1]+.5),a.lineTo(this._highlight_input[0]-4,this._highlight_input[1]+6+.5),a.lineTo(this._highlight_input[0]-4,this._highlight_input[1]-6+.5),a.closePath()):a.arc(this._highlight_input[0],this._highlight_input[1],6,0,2*Math.PI);a.fill()}this._highlight_output&&(a.beginPath(),k===f.ARROW_SHAPE?(a.moveTo(this._highlight_output[0]+8,this._highlight_output[1]+.5),a.lineTo(this._highlight_output[0]-4,this._highlight_output[1]+6+.5),
|
||||
a.lineTo(this._highlight_output[0]-4,this._highlight_output[1]-6+.5),a.closePath()):a.arc(this._highlight_output[0],this._highlight_output[1],6,0,2*Math.PI),a.fill())}this.dragging_rectangle&&(a.strokeStyle="#FFF",a.strokeRect(this.dragging_rectangle[0],this.dragging_rectangle[1],this.dragging_rectangle[2],this.dragging_rectangle[3]));if(this.over_link_center&&this.render_link_tooltip)this.drawLinkTooltip(a,this.over_link_center);else if(this.onDrawLinkTooltip)this.onDrawLinkTooltip(a,null);if(this.onDrawForeground)this.onDrawForeground(a,
|
||||
this.visible_rect);a.restore()}this._graph_stack&&this._graph_stack.length&&this.drawSubgraphPanel(a);if(this.onDrawOverlay)this.onDrawOverlay(a);c&&a.restore();a.finish2D&&a.finish2D()}};h.prototype.drawSubgraphPanel=function(a){var b=this.graph,c=b._subgraph_node;c?(this.drawSubgraphPanelLeft(b,c,a),this.drawSubgraphPanelRight(b,c,a)):console.warn("subgraph without subnode")};h.prototype.drawSubgraphPanelLeft=function(a,b,c){var e=b.inputs?b.inputs.length:0,d=Math.floor(1.6*f.NODE_SLOT_HEIGHT);
|
||||
c.fillStyle="#111";c.globalAlpha=.8;c.beginPath();c.roundRect(10,10,200,(e+1)*d+50,[8]);c.fill();c.globalAlpha=1;c.fillStyle="#888";c.font="14px Arial";c.textAlign="left";c.fillText("Graph Inputs",20,34);if(this.drawButton(180,20,20,20,"X","#151515"))this.closeSubgraph();else{e=50;c.font="14px Arial";if(b.inputs)for(var g=0;g<b.inputs.length;++g){var k=b.inputs[g];if(!k.not_subgraph_input){if(this.drawButton(20,e+2,180,d-2)){var n=b.constructor.input_node_type||"graph/input";this.graph.beforeChange();
|
||||
var p=f.createNode(n);p?(a.add(p),this.block_click=!1,this.last_click_position=null,this.selectNodes([p]),this.node_dragged=p,this.dragging_canvas=!1,p.setProperty("name",k.name),p.setProperty("type",k.type),this.node_dragged.pos[0]=this.graph_mouse[0]-5,this.node_dragged.pos[1]=this.graph_mouse[1]-5,this.graph.afterChange()):console.error("graph input node not found:",n)}c.fillStyle="#9C9";c.beginPath();c.arc(184,e+.5*d,5,0,2*Math.PI);c.fill();c.fillStyle="#AAA";c.fillText(k.name,30,e+.75*d);c.fillStyle=
|
||||
"#777";c.fillText(k.type,130,e+.75*d);e+=d}}this.drawButton(20,e+2,180,d-2,"+","#151515","#222")&&this.showSubgraphPropertiesDialog(b)}};h.prototype.drawSubgraphPanelRight=function(a,b,c){var e=b.outputs?b.outputs.length:0,d=this.bgcanvas.width,g=Math.floor(1.6*f.NODE_SLOT_HEIGHT);c.fillStyle="#111";c.globalAlpha=.8;c.beginPath();c.roundRect(d-200-10,10,200,(e+1)*g+50,[8]);c.fill();c.globalAlpha=1;c.fillStyle="#888";c.font="14px Arial";c.textAlign="left";e=c.measureText("Graph Outputs").width;c.fillText("Graph Outputs",
|
||||
d-e-20,34);if(this.drawButton(d-200,20,20,20,"X","#151515"))this.closeSubgraph();else{e=50;c.font="14px Arial";if(b.outputs)for(var k=0;k<b.outputs.length;++k){var n=b.outputs[k];if(!n.not_subgraph_input){if(this.drawButton(d-200,e+2,180,g-2)){var p=b.constructor.output_node_type||"graph/output";this.graph.beforeChange();var r=f.createNode(p);r?(a.add(r),this.block_click=!1,this.last_click_position=null,this.selectNodes([r]),this.node_dragged=r,this.dragging_canvas=!1,r.setProperty("name",n.name),
|
||||
r.setProperty("type",n.type),this.node_dragged.pos[0]=this.graph_mouse[0]-5,this.node_dragged.pos[1]=this.graph_mouse[1]-5,this.graph.afterChange()):console.error("graph input node not found:",p)}c.fillStyle="#9C9";c.beginPath();c.arc(d-200+16,e+.5*g,5,0,2*Math.PI);c.fill();c.fillStyle="#AAA";c.fillText(n.name,d-200+30,e+.75*g);c.fillStyle="#777";c.fillText(n.type,d-200+130,e+.75*g);e+=g}}this.drawButton(d-200,e+2,180,g-2,"+","#151515","#222")&&this.showSubgraphPropertiesDialogRight(b)}};h.prototype.drawButton=
|
||||
function(a,b,c,e,d,g,k,n){var p=this.ctx;g=g||f.NODE_DEFAULT_COLOR;k=k||"#555";n=n||f.NODE_TEXT_COLOR;var r=b+f.NODE_TITLE_HEIGHT+2,u=this.mouse,q=f.isInsideRectangle(u[0],u[1],a,r,c,e);r=(u=this.last_click_position)&&f.isInsideRectangle(u[0],u[1],a,r,c,e);p.fillStyle=q?k:g;r&&(p.fillStyle="#AAA");p.beginPath();p.roundRect(a,b,c,e,[4]);p.fill();null!=d&&d.constructor==String&&(p.fillStyle=n,p.textAlign="center",p.font=(.65*e|0)+"px Arial",p.fillText(d,a+.5*c,b+.75*e),p.textAlign="left");a=r&&!this.block_click;
|
||||
r&&this.blockClick();return a};h.prototype.isAreaClicked=function(a,b,c,e,d){var g=this.mouse;f.isInsideRectangle(g[0],g[1],a,b,c,e);b=(a=(g=this.last_click_position)&&f.isInsideRectangle(g[0],g[1],a,b,c,e))&&!this.block_click;a&&d&&this.blockClick();return b};h.prototype.renderInfo=function(a,b,c){b=b||10;c=c||this.canvas.height-80;a.save();a.translate(b,c);a.font="10px Arial";a.fillStyle="#888";a.textAlign="left";this.graph?(a.fillText("T: "+this.graph.globaltime.toFixed(2)+"s",5,13),a.fillText("I: "+
|
||||
this.graph.iteration,5,26),a.fillText("N: "+this.graph._nodes.length+" ["+this.visible_nodes.length+"]",5,39),a.fillText("V: "+this.graph._version,5,52),a.fillText("FPS:"+this.fps.toFixed(2),5,65)):a.fillText("No graph selected",5,13);a.restore()};h.prototype.drawBackCanvas=function(){var a=this.bgcanvas;if(a.width!=this.canvas.width||a.height!=this.canvas.height)a.width=this.canvas.width,a.height=this.canvas.height;this.bgctx||(this.bgctx=this.bgcanvas.getContext("2d"));var b=this.bgctx;b.start&&
|
||||
b.start();var c=this.viewport||[0,0,b.canvas.width,b.canvas.height];this.clear_background&&b.clearRect(c[0],c[1],c[2],c[3]);if(this._graph_stack&&this._graph_stack.length){b.save();c=this.graph._subgraph_node;b.strokeStyle=c.bgcolor;b.lineWidth=10;b.strokeRect(1,1,a.width-2,a.height-2);b.lineWidth=1;b.font="40px Arial";b.textAlign="center";b.fillStyle=c.bgcolor||"#AAA";for(var e="",d=1;d<this._graph_stack.length;++d)e+=this._graph_stack[d]._subgraph_node.getTitle()+" >> ";b.fillText(e+c.getTitle(),
|
||||
.5*a.width,40);b.restore()}c=!1;this.onRenderBackground&&(c=this.onRenderBackground(a,b));this.viewport||(b.restore(),b.setTransform(1,0,0,1,0,0));this.visible_links.length=0;if(this.graph){b.save();this.ds.toCanvasContext(b);if(this.background_image&&.5<this.ds.scale&&!c){b.globalAlpha=this.zoom_modify_alpha?(1-.5/this.ds.scale)*this.editor_alpha:this.editor_alpha;b.imageSmoothingEnabled=b.imageSmoothingEnabled=!1;if(!this._bg_img||this._bg_img.name!=this.background_image){this._bg_img=new Image;
|
||||
this._bg_img.name=this.background_image;this._bg_img.src=this.background_image;var g=this;this._bg_img.onload=function(){g.draw(!0,!0)}}c=null;null==this._pattern&&0<this._bg_img.width?(c=b.createPattern(this._bg_img,"repeat"),this._pattern_img=this._bg_img,this._pattern=c):c=this._pattern;c&&(b.fillStyle=c,b.fillRect(this.visible_area[0],this.visible_area[1],this.visible_area[2],this.visible_area[3]),b.fillStyle="transparent");b.globalAlpha=1;b.imageSmoothingEnabled=b.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 I=new Float32Array(2);h.prototype.drawNode=function(a,b){this.current_node=a;var c=a.color||a.constructor.color||f.NODE_DEFAULT_COLOR,e=a.bgcolor||a.constructor.bgcolor||f.NODE_DEFAULT_BGCOLOR,d=.6>this.ds.scale;if(this.live_mode){if(!a.flags.collapsed&&(b.shadowColor="transparent",a.onDrawForeground))a.onDrawForeground(b,this,this.canvas)}else{var g=this.editor_alpha;b.globalAlpha=g;this.render_shadows&&
|
||||
!d?(b.shadowColor=f.DEFAULT_SHADOW_COLOR,b.shadowOffsetX=2*this.ds.scale,b.shadowOffsetY=2*this.ds.scale,b.shadowBlur=3*this.ds.scale):b.shadowColor="transparent";if(!a.flags.collapsed||!a.onDrawCollapsed||1!=a.onDrawCollapsed(b,this)){var k=a._shape||f.BOX_SHAPE;I.set(a.size);var n=a.horizontal;if(a.flags.collapsed){b.font=this.inner_text_font;var p=a.getTitle?a.getTitle():a.title;null!=p&&(a._collapsed_width=Math.min(a.size[0],b.measureText(p).width+2*f.NODE_TITLE_HEIGHT),I[0]=a._collapsed_width,
|
||||
I[1]=0)}a.clip_area&&(b.save(),b.beginPath(),k==f.BOX_SHAPE?b.rect(0,0,I[0],I[1]):k==f.ROUND_SHAPE?b.roundRect(0,0,I[0],I[1],[10]):k==f.CIRCLE_SHAPE&&b.arc(.5*I[0],.5*I[1],.5*I[0],0,2*Math.PI),b.clip());a.has_errors&&(e="red");this.drawNodeShape(a,b,I,c,e,a.is_selected,a.mouseOver);b.shadowColor="transparent";if(a.onDrawForeground)a.onDrawForeground(b,this,this.canvas);b.textAlign=n?"center":"left";b.font=this.inner_text_font;e=!d;var r=this.connecting_output;k=this.connecting_input;b.lineWidth=1;
|
||||
p=0;var u=new Float32Array(2);if(!a.flags.collapsed){if(a.inputs)for(c=0;c<a.inputs.length;c++){var q=a.inputs[c],y=q.type,h=q.shape;b.globalAlpha=g;this.connecting_output&&!f.isValidConnection(q.type,r.type)&&(b.globalAlpha=.4*g);b.fillStyle=null!=q.link?q.color_on||this.default_connection_color_byType[y]||this.default_connection_color.input_on:q.color_off||this.default_connection_color_byTypeOff[y]||this.default_connection_color_byType[y]||this.default_connection_color.input_off;var v=a.getConnectionPos(!0,
|
||||
c,u);v[0]-=a.pos[0];v[1]-=a.pos[1];p<v[1]+.5*f.NODE_SLOT_HEIGHT&&(p=v[1]+.5*f.NODE_SLOT_HEIGHT);b.beginPath();"array"==y&&(h=f.GRID_SHAPE);q.type===f.EVENT||q.shape===f.BOX_SHAPE?n?b.rect(v[0]-5+.5,v[1]-8+.5,10,14):b.rect(v[0]-6+.5,v[1]-5+.5,14,10):h===f.ARROW_SHAPE?(b.moveTo(v[0]+8,v[1]+.5),b.lineTo(v[0]-4,v[1]+6+.5),b.lineTo(v[0]-4,v[1]-6+.5),b.closePath()):h===f.GRID_SHAPE?(b.rect(v[0]-4,v[1]-4,2,2),b.rect(v[0]-1,v[1]-4,2,2),b.rect(v[0]+2,v[1]-4,2,2),b.rect(v[0]-4,v[1]-1,2,2),b.rect(v[0]-1,v[1]-
|
||||
1,2,2),b.rect(v[0]+2,v[1]-1,2,2),b.rect(v[0]-4,v[1]+2,2,2),b.rect(v[0]-1,v[1]+2,2,2),b.rect(v[0]+2,v[1]+2,2,2)):d?b.rect(v[0]-4,v[1]-4,8,8):b.arc(v[0],v[1],4,0,2*Math.PI);b.fill();e&&(y=null!=q.label?q.label:q.name)&&(b.fillStyle=f.NODE_TEXT_COLOR,n||q.dir==f.UP?b.fillText(y,v[0],v[1]-10):b.fillText(y,v[0]+10,v[1]+5))}b.textAlign=n?"center":"right";b.strokeStyle="black";if(a.outputs)for(c=0;c<a.outputs.length;c++)if(q=a.outputs[c],y=q.type,h=q.shape,this.connecting_input&&!f.isValidConnection(y,k.type)&&
|
||||
(b.globalAlpha=.4*g),v=a.getConnectionPos(!1,c,u),v[0]-=a.pos[0],v[1]-=a.pos[1],p<v[1]+.5*f.NODE_SLOT_HEIGHT&&(p=v[1]+.5*f.NODE_SLOT_HEIGHT),b.fillStyle=q.links&&q.links.length?q.color_on||this.default_connection_color_byType[y]||this.default_connection_color.output_on:q.color_off||this.default_connection_color_byTypeOff[y]||this.default_connection_color_byType[y]||this.default_connection_color.output_off,b.beginPath(),"array"==y&&(h=f.GRID_SHAPE),r=!0,y===f.EVENT||h===f.BOX_SHAPE?n?b.rect(v[0]-5+
|
||||
.5,v[1]-8+.5,10,14):b.rect(v[0]-6+.5,v[1]-5+.5,14,10):h===f.ARROW_SHAPE?(b.moveTo(v[0]+8,v[1]+.5),b.lineTo(v[0]-4,v[1]+6+.5),b.lineTo(v[0]-4,v[1]-6+.5),b.closePath()):h===f.GRID_SHAPE?(b.rect(v[0]-4,v[1]-4,2,2),b.rect(v[0]-1,v[1]-4,2,2),b.rect(v[0]+2,v[1]-4,2,2),b.rect(v[0]-4,v[1]-1,2,2),b.rect(v[0]-1,v[1]-1,2,2),b.rect(v[0]+2,v[1]-1,2,2),b.rect(v[0]-4,v[1]+2,2,2),b.rect(v[0]-1,v[1]+2,2,2),b.rect(v[0]+2,v[1]+2,2,2),r=!1):d?b.rect(v[0]-4,v[1]-4,8,8):b.arc(v[0],v[1],4,0,2*Math.PI),b.fill(),!d&&r&&b.stroke(),
|
||||
e&&(y=null!=q.label?q.label:q.name))b.fillStyle=f.NODE_TEXT_COLOR,n||q.dir==f.DOWN?b.fillText(y,v[0],v[1]-8):b.fillText(y,v[0]-10,v[1]+5);b.textAlign="left";b.globalAlpha=1;if(a.widgets){q=p;if(n||a.widgets_up)q=2;null!=a.widgets_start_y&&(q=a.widgets_start_y);this.drawNodeWidgets(a,q,b,this.node_widget&&this.node_widget[0]==a?this.node_widget[1]:null)}}else if(this.render_collapsed_slots){d=g=null;if(a.inputs)for(c=0;c<a.inputs.length;c++)if(q=a.inputs[c],null!=q.link){g=q;break}if(a.outputs)for(c=
|
||||
0;c<a.outputs.length;c++)q=a.outputs[c],q.links&&q.links.length&&(d=q);g&&(g=0,c=-.5*f.NODE_TITLE_HEIGHT,n&&(g=.5*a._collapsed_width,c=-f.NODE_TITLE_HEIGHT),b.fillStyle="#686",b.beginPath(),q.type===f.EVENT||q.shape===f.BOX_SHAPE?b.rect(g-7+.5,c-4,14,8):q.shape===f.ARROW_SHAPE?(b.moveTo(g+8,c),b.lineTo(g+-4,c-4),b.lineTo(g+-4,c+4),b.closePath()):b.arc(g,c,4,0,2*Math.PI),b.fill());d&&(g=a._collapsed_width,c=-.5*f.NODE_TITLE_HEIGHT,n&&(g=.5*a._collapsed_width,c=0),b.fillStyle="#686",b.strokeStyle="black",
|
||||
b.beginPath(),q.type===f.EVENT||q.shape===f.BOX_SHAPE?b.rect(g-7+.5,c-4,14,8):q.shape===f.ARROW_SHAPE?(b.moveTo(g+6,c),b.lineTo(g-6,c-4),b.lineTo(g-6,c+4),b.closePath()):b.arc(g,c,4,0,2*Math.PI),b.fill())}a.clip_area&&b.restore();b.globalAlpha=1}}};h.prototype.drawLinkTooltip=function(a,b){var c=b._pos;a.fillStyle="black";a.beginPath();a.arc(c[0],c[1],3,0,2*Math.PI);a.fill();if(null!=b.data&&(!this.onDrawLinkTooltip||1!=this.onDrawLinkTooltip(a,b,this))&&(b=b.data,b=b.constructor===Number?b.toFixed(2):
|
||||
b.constructor===String?'"'+b+'"':b.constructor===Boolean?String(b):b.toToolTip?b.toToolTip():"["+b.constructor.name+"]",null!=b)){b=b.substr(0,30);a.font="14px Courier New";var e=a.measureText(b).width+20;a.shadowColor="black";a.shadowOffsetX=2;a.shadowOffsetY=2;a.shadowBlur=3;a.fillStyle="#454";a.beginPath();a.roundRect(c[0]-.5*e,c[1]-15-24,e,24,[3]);a.moveTo(c[0]-10,c[1]-15);a.lineTo(c[0]+10,c[1]-15);a.lineTo(c[0],c[1]-5);a.fill();a.shadowColor="transparent";a.textAlign="center";a.fillStyle="#CEC";
|
||||
a.fillText(b,c[0],c[1]-15-24*.3)}};var B=new Float32Array(4);h.prototype.drawNodeShape=function(a,b,c,e,d,g,k){b.strokeStyle=e;b.fillStyle=d;d=f.NODE_TITLE_HEIGHT;var n=.5>this.ds.scale,p=a._shape||a.constructor.shape||f.ROUND_SHAPE,r=a.constructor.title_mode,u=!0;r==f.TRANSPARENT_TITLE||r==f.NO_TITLE?u=!1:r==f.AUTOHIDE_TITLE&&k&&(u=!0);B[0]=0;B[1]=u?-d:0;B[2]=c[0]+1;B[3]=u?c[1]+d:c[1];k=b.globalAlpha;b.beginPath();p==f.BOX_SHAPE||n?b.fillRect(B[0],B[1],B[2],B[3]):p==f.ROUND_SHAPE||p==f.CARD_SHAPE?
|
||||
b.roundRect(B[0],B[1],B[2],B[3],p==f.CARD_SHAPE?[this.round_radius,this.round_radius,0,0]:[this.round_radius]):p==f.CIRCLE_SHAPE&&b.arc(.5*c[0],.5*c[1],.5*c[0],0,2*Math.PI);b.fill();!a.flags.collapsed&&u&&(b.shadowColor="transparent",b.fillStyle="rgba(0,0,0,0.2)",b.fillRect(0,-1,B[2],2));b.shadowColor="transparent";if(a.onDrawBackground)a.onDrawBackground(b,this,this.canvas,this.graph_mouse);if(u||r==f.TRANSPARENT_TITLE){if(a.onDrawTitleBar)a.onDrawTitleBar(b,d,c,this.ds.scale,e);else if(r!=f.TRANSPARENT_TITLE&&
|
||||
(a.constructor.title_color||this.render_title_colored)){u=a.constructor.title_color||e;a.flags.collapsed&&(b.shadowColor=f.DEFAULT_SHADOW_COLOR);if(this.use_gradients){var q=h.gradients[u];q||(q=h.gradients[u]=b.createLinearGradient(0,0,400,0),q.addColorStop(0,u),q.addColorStop(1,"#000"));b.fillStyle=q}else b.fillStyle=u;b.beginPath();p==f.BOX_SHAPE||n?b.rect(0,-d,c[0]+1,d):(p==f.ROUND_SHAPE||p==f.CARD_SHAPE)&&b.roundRect(0,-d,c[0]+1,d,a.flags.collapsed?[this.round_radius]:[this.round_radius,this.round_radius,
|
||||
0,0]);b.fill();b.shadowColor="transparent"}u=!1;f.node_box_coloured_by_mode&&f.NODE_MODES_COLORS[a.mode]&&(u=f.NODE_MODES_COLORS[a.mode]);f.node_box_coloured_when_on&&(u=a.action_triggered?"#FFF":a.execute_triggered?"#AAA":u);if(a.onDrawTitleBox)a.onDrawTitleBox(b,d,c,this.ds.scale);else p==f.ROUND_SHAPE||p==f.CIRCLE_SHAPE||p==f.CARD_SHAPE?(n&&(b.fillStyle="black",b.beginPath(),b.arc(.5*d,-.5*d,6,0,2*Math.PI),b.fill()),b.fillStyle=a.boxcolor||u||f.NODE_DEFAULT_BOXCOLOR,n?b.fillRect(.5*d-5,-.5*d-5,
|
||||
10,10):(b.beginPath(),b.arc(.5*d,-.5*d,5,0,2*Math.PI),b.fill())):(n&&(b.fillStyle="black",b.fillRect(.5*(d-10)-1,-.5*(d+10)-1,12,12)),b.fillStyle=a.boxcolor||u||f.NODE_DEFAULT_BOXCOLOR,b.fillRect(.5*(d-10),-.5*(d+10),10,10));b.globalAlpha=k;if(a.onDrawTitleText)a.onDrawTitleText(b,d,c,this.ds.scale,this.title_text_font,g);!n&&(b.font=this.title_text_font,k=String(a.getTitle()))&&(b.fillStyle=g?f.NODE_SELECTED_TITLE_COLOR:a.constructor.title_text_color||this.node_title_color,a.flags.collapsed?(b.textAlign=
|
||||
"left",b.measureText(k),b.fillText(k.substr(0,20),d,f.NODE_TITLE_TEXT_Y-d),b.textAlign="left"):(b.textAlign="left",b.fillText(k,d,f.NODE_TITLE_TEXT_Y-d)));a.flags.collapsed||!a.subgraph||a.skip_subgraph_button||(k=f.NODE_TITLE_HEIGHT,u=a.size[0]-k,q=f.isInsideRectangle(this.graph_mouse[0]-a.pos[0],this.graph_mouse[1]-a.pos[1],u+2,-k+2,k-4,k-4),b.fillStyle=q?"#888":"#555",p==f.BOX_SHAPE||n?b.fillRect(u+2,-k+2,k-4,k-4):(b.beginPath(),b.roundRect(u+2,-k+2,k-4,k-4,[4]),b.fill()),b.fillStyle="#333",b.beginPath(),
|
||||
b.moveTo(u+.2*k,.6*-k),b.lineTo(u+.8*k,.6*-k),b.lineTo(u+.5*k,.3*-k),b.fill());if(a.onDrawTitle)a.onDrawTitle(b)}if(g){if(a.onBounding)a.onBounding(B);r==f.TRANSPARENT_TITLE&&(B[1]-=d,B[3]+=d);b.lineWidth=1;b.globalAlpha=.8;b.beginPath();p==f.BOX_SHAPE?b.rect(-6+B[0],-6+B[1],12+B[2],12+B[3]):p==f.ROUND_SHAPE||p==f.CARD_SHAPE&&a.flags.collapsed?b.roundRect(-6+B[0],-6+B[1],12+B[2],12+B[3],[2*this.round_radius]):p==f.CARD_SHAPE?b.roundRect(-6+B[0],-6+B[1],12+B[2],12+B[3],[2*this.round_radius,2,2*this.round_radius,
|
||||
2]):p==f.CIRCLE_SHAPE&&b.arc(.5*c[0],.5*c[1],.5*c[0]+6,0,2*Math.PI);b.strokeStyle=f.NODE_BOX_OUTLINE_COLOR;b.stroke();b.strokeStyle=e;b.globalAlpha=1}0<a.execute_triggered&&a.execute_triggered--;0<a.action_triggered&&a.action_triggered--};var K=new Float32Array(4),F=new Float32Array(4),J=new Float32Array(2),H=new Float32Array(2);h.prototype.drawConnections=function(a){var b=f.getTime(),c=this.visible_area;K[0]=c[0]-20;K[1]=c[1]-20;K[2]=c[2]+40;K[3]=c[3]+40;a.lineWidth=this.connections_width;a.fillStyle=
|
||||
"#AAA";a.strokeStyle="#AAA";a.globalAlpha=this.editor_alpha;c=this.graph._nodes;for(var e=0,d=c.length;e<d;++e){var g=c[e];if(g.inputs&&g.inputs.length)for(var k=0;k<g.inputs.length;++k){var n=g.inputs[k];if(n&&null!=n.link&&(n=this.graph.links[n.link])){var p=this.graph.getNodeById(n.origin_id);if(null!=p){var r=n.origin_slot;var u=-1==r?[p.pos[0]+10,p.pos[1]+10]:p.getConnectionPos(!1,r,J);var q=g.getConnectionPos(!0,k,H);F[0]=u[0];F[1]=u[1];F[2]=q[0]-u[0];F[3]=q[1]-u[1];0>F[2]&&(F[0]+=F[2],F[2]=
|
||||
Math.abs(F[2]));0>F[3]&&(F[1]+=F[3],F[3]=Math.abs(F[3]));if(A(F,K)){var y=p.outputs[r];r=g.inputs[k];if(y&&r&&(p=y.dir||(p.horizontal?f.DOWN:f.RIGHT),r=r.dir||(g.horizontal?f.UP:f.LEFT),this.renderLink(a,u,q,n,!1,0,null,p,r),n&&n._last_time&&1E3>b-n._last_time)){y=2-.002*(b-n._last_time);var h=a.globalAlpha;a.globalAlpha=h*y;this.renderLink(a,u,q,n,!0,y,"white",p,r);a.globalAlpha=h}}}}}}a.globalAlpha=1};h.prototype.renderLink=function(a,b,c,e,d,g,k,n,p,r){e&&this.visible_links.push(e);!k&&e&&(k=e.color||
|
||||
h.link_type_colors[e.type]);k||(k=this.default_link_color);null!=e&&this.highlighted_links[e.id]&&(k="#FFF");n=n||f.RIGHT;p=p||f.LEFT;var u=D(b,c);this.render_connections_border&&.6<this.ds.scale&&(a.lineWidth=this.connections_width+4);a.lineJoin="round";r=r||1;1<r&&(a.lineWidth=.5);a.beginPath();for(var q=0;q<r;q+=1){var y=5*(q-.5*(r-1));if(this.links_render_mode==f.SPLINE_LINK){a.moveTo(b[0],b[1]+y);var l=0,v=0,m=0,w=0;switch(n){case f.LEFT:l=-.25*u;break;case f.RIGHT:l=.25*u;break;case f.UP:v=
|
||||
-.25*u;break;case f.DOWN:v=.25*u}switch(p){case f.LEFT:m=-.25*u;break;case f.RIGHT:m=.25*u;break;case f.UP:w=-.25*u;break;case f.DOWN:w=.25*u}a.bezierCurveTo(b[0]+l,b[1]+v+y,c[0]+m,c[1]+w+y,c[0],c[1]+y)}else if(this.links_render_mode==f.LINEAR_LINK){a.moveTo(b[0],b[1]+y);w=m=v=l=0;switch(n){case f.LEFT:l=-1;break;case f.RIGHT:l=1;break;case f.UP:v=-1;break;case f.DOWN:v=1}switch(p){case f.LEFT:m=-1;break;case f.RIGHT:m=1;break;case f.UP:w=-1;break;case f.DOWN:w=1}a.lineTo(b[0]+15*l,b[1]+15*v+y);a.lineTo(c[0]+
|
||||
15*m,c[1]+15*w+y);a.lineTo(c[0],c[1]+y)}else if(this.links_render_mode==f.STRAIGHT_LINK)a.moveTo(b[0],b[1]),y=b[0],l=b[1],v=c[0],m=c[1],n==f.RIGHT?y+=10:l+=10,p==f.LEFT?v-=10:m-=10,a.lineTo(y,l),a.lineTo(.5*(y+v),l),a.lineTo(.5*(y+v),m),a.lineTo(v,m),a.lineTo(c[0],c[1]);else return}this.render_connections_border&&.6<this.ds.scale&&!d&&(a.strokeStyle="rgba(0,0,0,0.5)",a.stroke());a.lineWidth=this.connections_width;a.fillStyle=a.strokeStyle=k;a.stroke();d=this.computeConnectionPoint(b,c,.5,n,p);e&&
|
||||
e._pos&&(e._pos[0]=d[0],e._pos[1]=d[1]);.6<=this.ds.scale&&this.highquality_render&&p!=f.CENTER&&(this.render_connection_arrows&&(q=this.computeConnectionPoint(b,c,.25,n,p),u=this.computeConnectionPoint(b,c,.26,n,p),e=this.computeConnectionPoint(b,c,.75,n,p),r=this.computeConnectionPoint(b,c,.76,n,p),this.render_curved_connections?(u=-Math.atan2(u[0]-q[0],u[1]-q[1]),r=-Math.atan2(r[0]-e[0],r[1]-e[1])):r=u=c[1]>b[1]?0:Math.PI,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.save(),a.translate(e[0],e[1]),a.rotate(r),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore()),a.beginPath(),a.arc(d[0],d[1],5,0,2*Math.PI),a.fill());if(g)for(a.fillStyle=k,q=0;5>q;++q)g=(.001*f.getTime()+.2*q)%1,d=this.computeConnectionPoint(b,c,g,n,p),a.beginPath(),a.arc(d[0],d[1],5,0,2*Math.PI),a.fill()};h.prototype.computeConnectionPoint=function(a,b,c,e,d){e=e||f.RIGHT;d=d||f.LEFT;var g=D(a,b),k=[a[0],a[1]],n=[b[0],
|
||||
b[1]];switch(e){case f.LEFT:k[0]+=-.25*g;break;case f.RIGHT:k[0]+=.25*g;break;case f.UP:k[1]+=-.25*g;break;case f.DOWN:k[1]+=.25*g}switch(d){case f.LEFT:n[0]+=-.25*g;break;case f.RIGHT:n[0]+=.25*g;break;case f.UP:n[1]+=-.25*g;break;case f.DOWN:n[1]+=.25*g}e=(1-c)*(1-c)*(1-c);d=3*(1-c)*(1-c)*c;g=3*(1-c)*c*c;c*=c*c;return[e*a[0]+d*k[0]+g*n[0]+c*b[0],e*a[1]+d*k[1]+g*n[1]+c*b[1]]};h.prototype.drawExecutionOrder=function(a){a.shadowColor="transparent";a.globalAlpha=.25;a.textAlign="center";a.strokeStyle=
|
||||
"white";a.globalAlpha=.75;for(var b=this.visible_nodes,c=0;c<b.length;++c){var e=b[c];a.fillStyle="black";a.fillRect(e.pos[0]-f.NODE_TITLE_HEIGHT,e.pos[1]-f.NODE_TITLE_HEIGHT,f.NODE_TITLE_HEIGHT,f.NODE_TITLE_HEIGHT);0==e.order&&a.strokeRect(e.pos[0]-f.NODE_TITLE_HEIGHT+.5,e.pos[1]-f.NODE_TITLE_HEIGHT+.5,f.NODE_TITLE_HEIGHT,f.NODE_TITLE_HEIGHT);a.fillStyle="#FFF";a.fillText(e.order,e.pos[0]+-.5*f.NODE_TITLE_HEIGHT,e.pos[1]-6)}a.globalAlpha=1};h.prototype.drawNodeWidgets=function(a,b,c,e){if(!a.widgets||
|
||||
!a.widgets.length)return 0;var d=a.size[0],g=a.widgets;b+=2;var k=f.NODE_WIDGET_HEIGHT,n=.5<this.ds.scale;c.save();c.globalAlpha=this.editor_alpha;for(var p=f.WIDGET_OUTLINE_COLOR,r=f.WIDGET_BGCOLOR,u=f.WIDGET_TEXT_COLOR,q=f.WIDGET_SECONDARY_TEXT_COLOR,y=0;y<g.length;++y){var h=g[y],v=b;h.y&&(v=h.y);h.last_y=v;c.strokeStyle=p;c.fillStyle="#222";c.textAlign="left";h.disabled&&(c.globalAlpha*=.5);var l=h.width||d;switch(h.type){case "button":h.clicked&&(c.fillStyle="#AAA",h.clicked=!1,this.dirty_canvas=
|
||||
!0);c.fillRect(15,v,l-30,k);n&&!h.disabled&&c.strokeRect(15,v,l-30,k);n&&(c.textAlign="center",c.fillStyle=u,c.fillText(h.name,.5*l,v+.7*k));break;case "toggle":c.textAlign="left";c.strokeStyle=p;c.fillStyle=r;c.beginPath();n?c.roundRect(15,v,l-30,k,[.5*k]):c.rect(15,v,l-30,k);c.fill();n&&!h.disabled&&c.stroke();c.fillStyle=h.value?"#89A":"#333";c.beginPath();c.arc(l-30,v+.5*k,.36*k,0,2*Math.PI);c.fill();n&&(c.fillStyle=q,null!=h.name&&c.fillText(h.name,30,v+.7*k),c.fillStyle=h.value?u:q,c.textAlign=
|
||||
"right",c.fillText(h.value?h.options.on||"true":h.options.off||"false",l-40,v+.7*k));break;case "slider":c.fillStyle=r;c.fillRect(15,v,l-30,k);var m=h.options.max-h.options.min,w=(h.value-h.options.min)/m;c.fillStyle=e==h?"#89A":"#678";c.fillRect(15,v,w*(l-30),k);n&&!h.disabled&&c.strokeRect(15,v,l-30,k);h.marker&&(m=(h.marker-h.options.min)/m,c.fillStyle="#AA9",c.fillRect(15+m*(l-30),v,2,k));n&&(c.textAlign="center",c.fillStyle=u,c.fillText(h.name+" "+Number(h.value).toFixed(3),.5*l,v+.7*k));break;
|
||||
case "number":case "combo":c.textAlign="left";c.strokeStyle=p;c.fillStyle=r;c.beginPath();n?c.roundRect(15,v,l-30,k,[.5*k]):c.rect(15,v,l-30,k);c.fill();n&&(h.disabled||c.stroke(),c.fillStyle=u,h.disabled||(c.beginPath(),c.moveTo(31,v+5),c.lineTo(21,v+.5*k),c.lineTo(31,v+k-5),c.fill(),c.beginPath(),c.moveTo(l-15-16,v+5),c.lineTo(l-15-6,v+.5*k),c.lineTo(l-15-16,v+k-5),c.fill()),c.fillStyle=q,c.fillText(h.name,35,v+.7*k),c.fillStyle=u,c.textAlign="right","number"==h.type?c.fillText(Number(h.value).toFixed(void 0!==
|
||||
h.options.precision?h.options.precision:3),l-30-20,v+.7*k):(m=h.value,h.options.values&&(w=h.options.values,w.constructor===Function&&(w=w()),w&&w.constructor!==Array&&(m=w[h.value])),c.fillText(m,l-30-20,v+.7*k)));break;case "string":case "text":c.textAlign="left";c.strokeStyle=p;c.fillStyle=r;c.beginPath();n?c.roundRect(15,v,l-30,k,[.5*k]):c.rect(15,v,l-30,k);c.fill();n&&(h.disabled||c.stroke(),c.save(),c.beginPath(),c.rect(15,v,l-30,k),c.clip(),c.fillStyle=q,null!=h.name&&c.fillText(h.name,30,
|
||||
v+.7*k),c.fillStyle=u,c.textAlign="right",c.fillText(String(h.value).substr(0,30),l-30,v+.7*k),c.restore());break;default:h.draw&&h.draw(c,a,l,v,k)}b+=(h.computeSize?h.computeSize(l)[1]:k)+4;c.globalAlpha=this.editor_alpha}c.restore();c.textAlign="left"};h.prototype.processNodeWidgets=function(a,b,c,e){function d(d,e){d.value=e;d.options&&d.options.property&&void 0!==a.properties[d.options.property]&&a.setProperty(d.options.property,e);d.callback&&d.callback(d.value,h,a,b,c)}if(!a.widgets||!a.widgets.length)return null;
|
||||
for(var g=b[0]-a.pos[0],k=b[1]-a.pos[1],n=a.size[0],h=this,r=this.getCanvasWindow(),u=0;u<a.widgets.length;++u){var q=a.widgets[u];if(q&&!q.disabled){var y=q.computeSize?q.computeSize(n)[1]:f.NODE_WIDGET_HEIGHT,l=q.width||n;if(q==e||!(6>g||g>l-12||k<q.last_y||k>q.last_y+y||void 0===q.last_y)){e=q.value;switch(q.type){case "button":c.type===f.pointerevents_method+"down"&&(q.callback&&setTimeout(function(){q.callback(q,h,a,b,c)},20),this.dirty_canvas=q.clicked=!0);break;case "slider":r=Math.clamp((g-
|
||||
15)/(l-30),0,1);q.value=q.options.min+(q.options.max-q.options.min)*r;q.callback&&setTimeout(function(){d(q,q.value)},20);this.dirty_canvas=!0;break;case "number":case "combo":e=q.value;if(c.type==f.pointerevents_method+"move"&&"number"==q.type)q.value+=.1*c.deltaX*(q.options.step||1),null!=q.options.min&&q.value<q.options.min&&(q.value=q.options.min),null!=q.options.max&&q.value>q.options.max&&(q.value=q.options.max);else if(c.type==f.pointerevents_method+"down"){var v=q.options.values;v&&v.constructor===
|
||||
Function&&(v=q.options.values(q,a));var m=null;"number"!=q.type&&(m=v.constructor===Array?v:Object.keys(v));g=40>g?-1:g>l-40?1:0;if("number"==q.type)q.value+=.1*g*(q.options.step||1),null!=q.options.min&&q.value<q.options.min&&(q.value=q.options.min),null!=q.options.max&&q.value>q.options.max&&(q.value=q.options.max);else if(g)r=-1,this.last_mouseclick=0,r=v.constructor===Object?m.indexOf(String(q.value))+g:m.indexOf(q.value)+g,r>=m.length&&(r=m.length-1),0>r&&(r=0),q.value=v.constructor===Array?
|
||||
v[r]:r;else{var w=v!=m?Object.values(v):v;new f.ContextMenu(w,{scale:Math.max(1,this.ds.scale),event:c,className:"dark",callback:function(a,b,c){v!=m&&(a=w.indexOf(a));this.value=a;d(this,a);h.dirty_canvas=!0;return!1}.bind(q)},r)}}else c.type==f.pointerevents_method+"up"&&"number"==q.type&&(g=40>g?-1:g>l-40?1:0,200>c.click_time&&0==g&&this.prompt("Value",q.value,function(a){this.value=Number(a);d(this,this.value)}.bind(q),c));e!=q.value&&setTimeout(function(){d(this,this.value)}.bind(q),20);this.dirty_canvas=
|
||||
!0;break;case "toggle":c.type==f.pointerevents_method+"down"&&(q.value=!q.value,setTimeout(function(){d(q,q.value)},20));break;case "string":case "text":c.type==f.pointerevents_method+"down"&&this.prompt("Value",q.value,function(a){this.value=a;d(this,a)}.bind(q),c,q.options?q.options.multiline:!1);break;default:q.mouse&&(this.dirty_canvas=q.mouse(c,[g,k],a))}if(e!=q.value){if(a.onWidgetChanged)a.onWidgetChanged(q.name,q.value,e,q);a.graph._version++}return q}}}return null};h.prototype.drawGroups=
|
||||
function(a,b){if(this.graph){a=this.graph._groups;b.save();b.globalAlpha=.5*this.editor_alpha;for(var c=0;c<a.length;++c){var e=a[c];if(A(this.visible_area,e._bounding)){b.fillStyle=e.color||"#335";b.strokeStyle=e.color||"#335";var d=e._pos,g=e._size;b.globalAlpha=.25*this.editor_alpha;b.beginPath();b.rect(d[0]+.5,d[1]+.5,g[0],g[1]);b.fill();b.globalAlpha=this.editor_alpha;b.stroke();b.beginPath();b.moveTo(d[0]+g[0],d[1]+g[1]);b.lineTo(d[0]+g[0]-10,d[1]+g[1]);b.lineTo(d[0]+g[0],d[1]+g[1]-10);b.fill();
|
||||
g=e.font_size||f.DEFAULT_GROUP_FONT_SIZE;b.font=g+"px Arial";b.textAlign="left";b.fillText(e.title,d[0]+4,d[1]+g)}}b.restore()}};h.prototype.adjustNodesSize=function(){for(var a=this.graph._nodes,b=0;b<a.length;++b)a[b].size=a[b].computeSize();this.setDirty(!0,!0)};h.prototype.resize=function(a,b){a||b||(b=this.canvas.parentNode,a=b.offsetWidth,b=b.offsetHeight);if(this.canvas.width!=a||this.canvas.height!=b)this.canvas.width=a,this.canvas.height=b,this.bgcanvas.width=this.canvas.width,this.bgcanvas.height=
|
||||
this.canvas.height,this.setDirty(!0,!0)};h.prototype.switchLiveMode=function(a){if(a){var b=this,c=this.live_mode?1.1:.9;this.live_mode&&(this.live_mode=!1,this.editor_alpha=.1);var e=setInterval(function(){b.editor_alpha*=c;b.dirty_canvas=!0;b.dirty_bgcanvas=!0;1>c&&.01>b.editor_alpha&&(clearInterval(e),1>c&&(b.live_mode=!0));1<c&&.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};h.prototype.onNodeSelectionChange=
|
||||
function(a){};h.onGroupAdd=function(a,b,c){a=h.active_canvas;a.getCanvasWindow();b=new f.LGraphGroup;b.pos=a.convertEventToCanvasOffset(c);a.graph.add(b)};h.onMenuAdd=function(a,b,c,e,d){function g(a,b){var e=[];f.getNodeTypesCategories(k.filter||p.filter).filter(function(b){return b.startsWith(a)}).map(function(b){if(b){b=b.replace(new RegExp("^("+a+")"),"").split("/")[0];var c=""===a?b+"/":a+b+"/";-1!=b.indexOf("::")&&(b=b.split("::")[1]);-1===e.findIndex(function(a){return a.value===c})&&e.push({value:c,
|
||||
content:b,has_submenu:!0,callback:function(a,b,c,d){g(a.value,d)}})}});f.getNodeTypesInCategory(a.slice(0,-1),k.filter||p.filter).map(function(a){a.skip_list||e.push({value:a.type,content:a.title,has_submenu:!1,callback:function(a,b,c,e){b=e.getFirstEvent();k.graph.beforeChange();if(a=f.createNode(a.value))a.pos=k.convertEventToCanvasOffset(b),k.graph.add(a);d&&d(a);k.graph.afterChange()}})});new f.ContextMenu(e,{event:c,parentMenu:b},n)}var k=h.active_canvas,n=k.getCanvasWindow(),p=k.graph;if(p)return g("",
|
||||
e),!1};h.onMenuCollapseAll=function(){};h.onMenuNodeEdit=function(){};h.showMenuNodeOptionalInputs=function(a,b,c,e,d){if(d){var g=this;a=h.active_canvas.getCanvasWindow();b=d.optional_inputs;d.onGetInputs&&(b=d.onGetInputs());var k=[];if(b)for(var n=0;n<b.length;n++){var p=b[n];if(p){var r=p[0];p[2]||(p[2]={});p[2].label&&(r=p[2].label);p[2].removable=!0;r={content:r,value:p};p[1]==f.ACTION&&(r.className="event");k.push(r)}else k.push(null)}d.onMenuNodeInputs&&(b=d.onMenuNodeInputs(k))&&(k=b);if(k.length)return new f.ContextMenu(k,
|
||||
{event:c,callback:function(a,b,c){if(d&&(a.callback&&a.callback.call(g,d,a,b,c),a.value)){d.graph.beforeChange();d.addInput(a.value[0],a.value[1],a.value[2]);if(d.onNodeInputAdd)d.onNodeInputAdd(a.value);d.setDirtyCanvas(!0,!0);d.graph.afterChange()}},parentMenu:e,node:d},a),!1;console.log("no input entries")}};h.showMenuNodeOptionalOutputs=function(a,b,c,e,d){function g(a,b,c){if(d&&(a.callback&&a.callback.call(k,d,a,b,c),a.value))if(c=a.value[1],!c||c.constructor!==Object&&c.constructor!==Array){d.graph.beforeChange();
|
||||
d.addOutput(a.value[0],a.value[1],a.value[2]);if(d.onNodeOutputAdd)d.onNodeOutputAdd(a.value);d.setDirtyCanvas(!0,!0);d.graph.afterChange()}else{a=[];for(var r in c)a.push({content:r,value:c[r]});new f.ContextMenu(a,{event:b,callback:g,parentMenu:e,node:d});return!1}}if(d){var k=this;a=h.active_canvas.getCanvasWindow();b=d.optional_outputs;d.onGetOutputs&&(b=d.onGetOutputs());var n=[];if(b)for(var p=0;p<b.length;p++){var r=b[p];if(!r)n.push(null);else if(!d.flags||!d.flags.skip_repeated_outputs||
|
||||
-1==d.findOutputSlot(r[0])){var u=r[0];r[2]||(r[2]={});r[2].label&&(u=r[2].label);r[2].removable=!0;u={content:u,value:r};r[1]==f.EVENT&&(u.className="event");n.push(u)}}this.onMenuNodeOutputs&&(n=this.onMenuNodeOutputs(n));f.do_add_triggers_slots&&-1==d.findOutputSlot("onExecuted")&&n.push({content:"On Executed",value:["onExecuted",f.EVENT,{nameLocked:!0}],className:"event"});d.onMenuNodeOutputs&&(b=d.onMenuNodeOutputs(n))&&(n=b);if(n.length)return new f.ContextMenu(n,{event:c,callback:g,parentMenu:e,
|
||||
node:d},a),!1}};h.onShowMenuNodeProperties=function(a,b,c,e,d){if(d&&d.properties){var g=h.active_canvas;b=g.getCanvasWindow();var k=[],n;for(n in d.properties){a=void 0!==d.properties[n]?d.properties[n]:" ";"object"==typeof a&&(a=JSON.stringify(a));var p=d.getPropertyInfo(n);if("enum"==p.type||"combo"==p.type)a=h.getPropertyPrintableValue(a,p.values);a=h.decodeHTML(a);k.push({content:"<span class='property_name'>"+(p.label?p.label:n)+"</span><span class='property_value'>"+a+"</span>",value:n})}if(k.length)return new f.ContextMenu(k,
|
||||
{event:c,callback:function(a,b,c,e){d&&(b=this.getBoundingClientRect(),g.showEditPropertyValue(d,a.value,{position:[b.left,b.top]}))},parentMenu:e,allow_html:!0,node:d},b),!1}};h.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};h.onMenuResizeNode=function(a,b,c,e,d){if(d){a=function(a){a.size=a.computeSize();if(a.onResize)a.onResize(a.size)};b=h.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)a(d);else for(var g in b.selected_nodes)a(b.selected_nodes[g]);
|
||||
d.setDirtyCanvas(!0,!0)}};h.prototype.showLinkMenu=function(a,b){var c=this,e=c.graph.getNodeById(a.origin_id),d=c.graph.getNodeById(a.target_id),g=!1;e&&e.outputs&&e.outputs[a.origin_slot]&&(g=e.outputs[a.origin_slot].type);var k=!1;d&&d.outputs&&d.outputs[a.target_slot]&&(k=d.inputs[a.target_slot].type);var n=new f.ContextMenu(["Add Node",null,"Delete",null],{event:b,title:null!=a.data?a.data.constructor.name:null,callback:function(b,f,u){switch(b){case "Add Node":h.onMenuAdd(null,null,u,n,function(b){b.inputs&&
|
||||
b.inputs.length&&b.outputs&&b.outputs.length&&e.connectByType(a.origin_slot,b,g)&&(b.connectByType(a.target_slot,d,k),b.pos[0]-=.5*b.size[0])});break;case "Delete":c.graph.removeLink(a.id)}}});return!1};h.prototype.createDefaultNodeForSlot=function(a){a=a||{};a=Object.assign({nodeFrom:null,slotFrom:null,nodeTo:null,slotTo:null,position:[],nodeType:null,posAdd:[0,0],posSizeFix:[0,0]},a);var b=a.nodeFrom&&null!==a.slotFrom,c=!b&&a.nodeTo&&null!==a.slotTo;if(!b&&!c)return console.warn("No data passed to createDefaultNodeForSlot "+
|
||||
a.nodeFrom+" "+a.slotFrom+" "+a.nodeTo+" "+a.slotTo),!1;if(!a.nodeType)return console.warn("No type to createDefaultNodeForSlot"),!1;var e=b?a.nodeFrom:a.nodeTo,d=b?a.slotFrom:a.slotTo;switch(typeof d){case "string":c=b?e.findOutputSlot(d,!1):e.findInputSlot(d,!1);d=b?e.outputs[d]:e.inputs[d];break;case "object":c=b?e.findOutputSlot(d.name):e.findInputSlot(d.name);break;case "number":c=d;d=b?e.outputs[d]:e.inputs[d];break;default:return console.warn("Cant get slot information "+d),!1}!1!==d&&!1!==
|
||||
c||console.warn("createDefaultNodeForSlot bad slotX "+d+" "+c);e=d.type==f.EVENT?"_event_":d.type;if((d=b?f.slot_types_default_out:f.slot_types_default_in)&&d[e]){nodeNewType=!1;if("object"==typeof d[e]||"array"==typeof d[e])for(var g in d[e]){if(a.nodeType==d[e][g]||"AUTO"==a.nodeType){nodeNewType=d[e][g];break}}else if(a.nodeType==d[e]||"AUTO"==a.nodeType)nodeNewType=d[e];if(nodeNewType){g=!1;"object"==typeof nodeNewType&&nodeNewType.node&&(g=nodeNewType,nodeNewType=nodeNewType.node);if(d=f.createNode(nodeNewType)){if(g){if(g.properties)for(var k in g.properties)d.addProperty(k,
|
||||
g.properties[k]);if(g.inputs)for(k in d.inputs=[],g.inputs)d.addOutput(g.inputs[k][0],g.inputs[k][1]);if(g.outputs)for(k in d.outputs=[],g.outputs)d.addOutput(g.outputs[k][0],g.outputs[k][1]);g.title&&(d.title=g.title);g.json&&d.configure(g.json)}this.graph.add(d);d.pos=[a.position[0]+a.posAdd[0]+(a.posSizeFix[0]?a.posSizeFix[0]*d.size[0]:0),a.position[1]+a.posAdd[1]+(a.posSizeFix[1]?a.posSizeFix[1]*d.size[1]:0)];b?a.nodeFrom.connectByType(c,d,e):a.nodeTo.connectByTypeOutput(c,d,e);return!0}console.log("failed creating "+
|
||||
nodeNewType)}}return!1};h.prototype.showConnectionMenu=function(a){a=a||{};var b=Object.assign({nodeFrom:null,slotFrom:null,nodeTo:null,slotTo:null,e:null},a),c=this,e=b.nodeFrom&&b.slotFrom;a=!e&&b.nodeTo&&b.slotTo;if(!e&&!a)return console.warn("No data passed to showConnectionMenu"),!1;a=e?b.nodeFrom:b.nodeTo;var d=e?b.slotFrom:b.slotTo,g=!1;switch(typeof d){case "string":g=e?a.findOutputSlot(d,!1):a.findInputSlot(d,!1);d=e?a.outputs[d]:a.inputs[d];break;case "object":g=e?a.findOutputSlot(d.name):
|
||||
a.findInputSlot(d.name);break;case "number":g=d;d=e?a.outputs[d]:a.inputs[d];break;default:return console.warn("Cant get slot information "+d),!1}a=["Add Node",null];c.allow_searchbox&&(a.push("Search"),a.push(null));var k=d.type==f.EVENT?"_event_":d.type,n=e?f.slot_types_default_out:f.slot_types_default_in;if(n&&n[k])if("object"==typeof n[k]||"array"==typeof n[k])for(var p in n[k])a.push(n[k][p]);else a.push(n[k]);var r=new f.ContextMenu(a,{event:b.e,title:(d&&""!=d.name?d.name+(k?" | ":""):"")+
|
||||
(d&&k?k:""),callback:function(a,f,n){switch(a){case "Add Node":h.onMenuAdd(null,null,n,r,function(a){e?b.nodeFrom.connectByType(g,a,k):b.nodeTo.connectByTypeOutput(g,a,k)});break;case "Search":e?c.showSearchBox(n,{node_from:b.nodeFrom,slot_from:d,type_filter_in:k}):c.showSearchBox(n,{node_to:b.nodeTo,slot_from:d,type_filter_out:k});break;default:c.createDefaultNodeForSlot(Object.assign(b,{position:[b.e.canvasX,b.e.canvasY],nodeType:a}))}}});return!1};h.onShowPropertyEditor=function(a,b,c,e,d){function g(){if(p){var b=
|
||||
p.value;"Number"==a.type?b=Number(b):"Boolean"==a.type&&(b=!!b);d[k]=b;n.parentNode&&n.parentNode.removeChild(n);d.setDirtyCanvas(!0,!0)}}var k=a.property||"title";b=d[k];var n=document.createElement("div");n.is_modified=!1;n.className="graphdialog";n.innerHTML="<span class='name'></span><input autofocus type='text' class='value'/><button>OK</button>";n.close=function(){n.parentNode&&n.parentNode.removeChild(n)};n.querySelector(".name").innerText=k;var p=n.querySelector(".value");p&&(p.value=b,p.addEventListener("blur",
|
||||
function(a){this.focus()}),p.addEventListener("keydown",function(a){n.is_modified=!0;if(27==a.keyCode)n.close();else if(13==a.keyCode)g();else if(13!=a.keyCode&&"textarea"!=a.target.localName)return;a.preventDefault();a.stopPropagation()}));b=h.active_canvas.canvas;c=b.getBoundingClientRect();var r=e=-20;c&&(e-=c.left,r-=c.top);event?(n.style.left=event.clientX+e+"px",n.style.top=event.clientY+r+"px"):(n.style.left=.5*b.width+e+"px",n.style.top=.5*b.height+r+"px");n.querySelector("button").addEventListener("click",
|
||||
g);b.parentNode.appendChild(n);p&&p.focus();var u=null;n.addEventListener("mouseleave",function(a){f.dialog_close_on_mouse_leave&&!n.is_modified&&f.dialog_close_on_mouse_leave&&(u=setTimeout(n.close,f.dialog_close_on_mouse_leave_delay))});n.addEventListener("mouseenter",function(a){f.dialog_close_on_mouse_leave&&u&&clearTimeout(u)})};h.prototype.prompt=function(a,b,c,e,d){var g=this;a=a||"";var k=document.createElement("div");k.is_modified=!1;k.className="graphdialog rounded";k.innerHTML=d?"<span class='name'></span> <textarea autofocus class='value'></textarea><button class='rounded'>OK</button>":
|
||||
"<span class='name'></span> <input autofocus type='text' class='value'/><button class='rounded'>OK</button>";k.close=function(){g.prompt_box=null;k.parentNode&&k.parentNode.removeChild(k)};d=h.active_canvas.canvas;d.parentNode.appendChild(k);1<this.ds.scale&&(k.style.transform="scale("+this.ds.scale+")");var n=null,p=!1;f.pointerListenerAdd(k,"leave",function(a){p||f.dialog_close_on_mouse_leave&&!k.is_modified&&f.dialog_close_on_mouse_leave&&(n=setTimeout(k.close,f.dialog_close_on_mouse_leave_delay))});
|
||||
f.pointerListenerAdd(k,"enter",function(a){f.dialog_close_on_mouse_leave&&n&&clearTimeout(n)});var r=k.querySelectorAll("select");r&&r.forEach(function(a){a.addEventListener("click",function(a){p++});a.addEventListener("blur",function(a){p=0});a.addEventListener("change",function(a){p=-1})});g.prompt_box&&g.prompt_box.close();g.prompt_box=k;k.querySelector(".name").innerText=a;var u=k.querySelector(".value");u.value=b;u.addEventListener("keydown",function(a){k.is_modified=!0;if(27==a.keyCode)k.close();
|
||||
else if(13==a.keyCode&&"textarea"!=a.target.localName)c&&c(this.value),k.close();else return;a.preventDefault();a.stopPropagation()});k.querySelector("button").addEventListener("click",function(a){c&&c(u.value);g.setDirty(!0);k.close()});a=d.getBoundingClientRect();r=b=-20;a&&(b-=a.left,r-=a.top);e?(k.style.left=e.clientX+b+"px",k.style.top=e.clientY+r+"px"):(k.style.left=.5*d.width+b+"px",k.style.top=.5*d.height+r+"px");setTimeout(function(){u.focus()},10);return k};h.search_limit=-1;h.prototype.showSearchBox=
|
||||
function(a,b){function c(c){if(c)if(g.onSearchBoxSelection)g.onSearchBoxSelection(c,a,k);else{var d=f.searchbox_extras[c.toLowerCase()];d&&(c=d.type);k.graph.beforeChange();if(c=f.createNode(c))c.pos=k.convertEventToCanvasOffset(a),k.graph.add(c,!1);if(d&&d.data){if(d.data.properties)for(var e in d.data.properties)c.addProperty(e,d.data.properties[e]);if(d.data.inputs)for(e in c.inputs=[],d.data.inputs)c.addOutput(d.data.inputs[e][0],d.data.inputs[e][1]);if(d.data.outputs)for(e in c.outputs=[],d.data.outputs)c.addOutput(d.data.outputs[e][0],
|
||||
d.data.outputs[e][1]);d.data.title&&(c.title=d.data.title);d.data.json&&c.configure(d.data.json)}if(b.node_from){switch(typeof b.slot_from){case "string":d=b.node_from.findOutputSlot(b.slot_from);break;case "object":d=b.slot_from.name?b.node_from.findOutputSlot(b.slot_from.name):-1;-1==d&&"undefined"!==typeof b.slot_from.slot_index&&(d=b.slot_from.slot_index);break;case "number":d=b.slot_from;break;default:d=0}!1!==d&&-1<d&&b.node_from.connectByType(d,c,b.node_from.outputs[d].type)}if(b.node_to){switch(typeof b.slot_from){case "string":d=
|
||||
b.node_to.findInputSlot(b.slot_from);break;case "object":d=b.slot_from.name?b.node_to.findInputSlot(b.slot_from.name):-1;-1==d&&"undefined"!==typeof b.slot_from.slot_index&&(d=b.slot_from.slot_index);break;case "number":d=b.slot_from;break;default:d=0}!1!==d&&-1<d&&b.node_to.connectByTypeOutput(d,c,b.node_to.inputs[d].type)}k.graph.afterChange()}r.close()}function e(a){var b=t;t&&t.classList.remove("selected");t?(t=a?t.nextSibling:t.previousSibling)||(t=b):t=a?v.childNodes[0]:v.childNodes[v.childNodes.length];
|
||||
t&&(t.classList.add("selected"),t.scrollIntoView({block:"end",behavior:"smooth"}))}function d(){function a(a,b){var d=document.createElement("div");m||(m=a);d.innerText=a;d.dataset.type=escape(a);d.className="litegraph lite-search-item";b&&(d.className+=" "+b);d.addEventListener("click",function(a){c(unescape(this.dataset.type))});v.appendChild(d)}w=null;var d=z.value;m=null;v.innerHTML="";if(d||b.show_all_if_empty)if(g.onSearchBox){var e=g.onSearchBox(v,d,k);if(e)for(var r=0;r<e.length;++r)a(e[r])}else{e=
|
||||
function(a,c){c=c||{};c=Object.assign({skipFilter:!1,inTypeOverride:!1,outTypeOverride:!1},c);var e=f.registered_node_types[a];if(u&&e.filter!=u||(!b.show_all_if_empty||d)&&-1===a.toLowerCase().indexOf(d))return!1;if(b.do_type_filter&&!c.skipFilter){e=y.value;!1!==c.inTypeOverride&&(e=c.inTypeOverride);if(y&&e&&f.registered_slot_in_types[e]&&f.registered_slot_in_types[e].nodes&&(e=f.registered_slot_in_types[e].nodes.includes(a),!1===e))return!1;e=q.value;!1!==c.outTypeOverride&&(e=c.outTypeOverride);
|
||||
if(q&&e&&f.registered_slot_out_types[e]&&f.registered_slot_out_types[e].nodes&&(e=f.registered_slot_out_types[e].nodes.includes(a),!1===e))return!1}return!0};var n=0;d=d.toLowerCase();var u=k.filter||k.graph.filter;if(b.do_type_filter&&g.search_box)var y=g.search_box.querySelector(".slot_in_type_filter"),q=g.search_box.querySelector(".slot_out_type_filter");else q=y=!1;for(r in f.searchbox_extras){var p=f.searchbox_extras[r];if(b.show_all_if_empty&&!d||-1!==p.desc.toLowerCase().indexOf(d)){var l=
|
||||
f.registered_node_types[p.type];if((!l||l.filter==u)&&e(p.type)&&(a(p.desc,"searchbox_extra"),-1!==h.search_limit&&n++>h.search_limit))break}}p=null;if(Array.prototype.filter)p=Object.keys(f.registered_node_types).filter(e);else for(r in p=[],f.registered_node_types)e(r)&&p.push(r);for(r=0;r<p.length&&!(a(p[r]),-1!==h.search_limit&&n++>h.search_limit);r++);if(b.show_general_after_typefiltered&&(y.value||q.value)){filtered_extra=[];for(r in f.registered_node_types)e(r,{inTypeOverride:y&&y.value?"*":
|
||||
!1,outTypeOverride:q&&q.value?"*":!1})&&filtered_extra.push(r);for(r=0;r<filtered_extra.length&&!(a(filtered_extra[r],"generic_type"),-1!==h.search_limit&&n++>h.search_limit);r++);}if((y.value||q.value)&&0==v.childNodes.length&&b.show_general_if_none_on_typefilter){filtered_extra=[];for(r in f.registered_node_types)e(r,{skipFilter:!0})&&filtered_extra.push(r);for(r=0;r<filtered_extra.length&&!(a(filtered_extra[r],"not_in_filter"),-1!==h.search_limit&&n++>h.search_limit);r++);}}}def_options={slot_from:null,
|
||||
node_from:null,node_to:null,do_type_filter:f.search_filter_enabled,type_filter_in:!1,type_filter_out:!1,show_general_if_none_on_typefilter:!0,show_general_after_typefiltered:!0,hide_on_mouse_leave:f.search_hide_on_mouse_leave,show_all_if_empty:!0,show_all_on_open:f.search_show_all_on_open};b=Object.assign(def_options,b||{});var g=this,k=h.active_canvas,n=k.canvas,p=n.ownerDocument||document,r=document.createElement("div");r.className="litegraph litesearchbox graphdialog rounded";r.innerHTML="<span class='name'>Search</span> <input autofocus type='text' class='value rounded'/>";
|
||||
b.do_type_filter&&(r.innerHTML+="<select class='slot_in_type_filter'><option value=''></option></select>",r.innerHTML+="<select class='slot_out_type_filter'><option value=''></option></select>");r.innerHTML+="<div class='helper'></div>";p.fullscreenElement?p.fullscreenElement.appendChild(r):(p.body.appendChild(r),p.body.style.overflow="hidden");if(b.do_type_filter)var u=r.querySelector(".slot_in_type_filter"),q=r.querySelector(".slot_out_type_filter");r.close=function(){g.search_box=null;p.body.focus();
|
||||
p.body.style.overflow="";setTimeout(function(){g.canvas.focus()},20);r.parentNode&&r.parentNode.removeChild(r)};1<this.ds.scale&&(r.style.transform="scale("+this.ds.scale+")");if(b.hide_on_mouse_leave){var y=!1,l=null;f.pointerListenerAdd(r,"enter",function(a){l&&(clearTimeout(l),l=null)});f.pointerListenerAdd(r,"leave",function(a){y||(l=setTimeout(function(){r.close()},500))});b.do_type_filter&&(u.addEventListener("click",function(a){y++}),u.addEventListener("blur",function(a){y=0}),u.addEventListener("change",
|
||||
function(a){y=-1}),q.addEventListener("click",function(a){y++}),q.addEventListener("blur",function(a){y=0}),q.addEventListener("change",function(a){y=-1}))}g.search_box&&g.search_box.close();g.search_box=r;var v=r.querySelector(".helper"),m=null,w=null,t=null,z=r.querySelector("input");z&&(z.addEventListener("blur",function(a){this.focus()}),z.addEventListener("keydown",function(a){if(38==a.keyCode)e(!1);else if(40==a.keyCode)e(!0);else if(27==a.keyCode)r.close();else if(13==a.keyCode)t?c(t.innerHTML):
|
||||
m?c(m):r.close();else{w&&clearInterval(w);w=setTimeout(d,250);return}a.preventDefault();a.stopPropagation();a.stopImmediatePropagation();return!0}));if(b.do_type_filter){if(u){var x=f.slot_types_in,L=x.length;if(b.type_filter_in==f.EVENT||b.type_filter_in==f.ACTION)b.type_filter_in="_event_";for(var A=0;A<L;A++){var B=document.createElement("option");B.value=x[A];B.innerHTML=x[A];u.appendChild(B);!1!==b.type_filter_in&&(b.type_filter_in+"").toLowerCase()==(x[A]+"").toLowerCase()&&(B.selected=!0)}u.addEventListener("change",
|
||||
function(){d()})}if(q){x=f.slot_types_out;L=x.length;if(b.type_filter_out==f.EVENT||b.type_filter_out==f.ACTION)b.type_filter_out="_event_";for(A=0;A<L;A++)B=document.createElement("option"),B.value=x[A],B.innerHTML=x[A],q.appendChild(B),!1!==b.type_filter_out&&(b.type_filter_out+"").toLowerCase()==(x[A]+"").toLowerCase()&&(B.selected=!0);q.addEventListener("change",function(){d()})}}n=n.getBoundingClientRect();u=(a?a.clientY:n.top+.5*n.height)-20;r.style.left=(a?a.clientX:n.left+.5*n.width)-80+"px";
|
||||
r.style.top=u+"px";a.layerY>n.height-200&&(v.style.maxHeight=n.height-a.layerY-20+"px");z.focus();b.show_all_on_open&&d();return r};h.prototype.showEditPropertyValue=function(a,b,c){function e(){d(q.value)}function d(d){g&&g.values&&g.values.constructor===Object&&void 0!=g.values[d]&&(d=g.values[d]);"number"==typeof a.properties[b]&&(d=Number(d));if("array"==f||"object"==f)d=JSON.parse(d);a.properties[b]=d;a.graph&&a.graph._version++;if(a.onPropertyChanged)a.onPropertyChanged(b,d);if(c.onclose)c.onclose();
|
||||
u.close();a.setDirtyCanvas(!0,!0)}if(a&&void 0!==a.properties[b]){c=c||{};var g=a.getPropertyInfo(b),f=g.type,n="";if("string"==f||"number"==f||"array"==f||"object"==f)n="<input autofocus type='text' class='value'/>";else if("enum"!=f&&"combo"!=f||!g.values)if("boolean"==f||"toggle"==f)n="<input autofocus type='checkbox' class='value' "+(a.properties[b]?"checked":"")+"/>";else{console.warn("unknown type: "+f);return}else{n="<select autofocus type='text' class='value'>";for(var h in g.values){var r=
|
||||
h;g.values.constructor===Array&&(r=g.values[h]);n+="<option value='"+r+"' "+(r==a.properties[b]?"selected":"")+">"+g.values[h]+"</option>"}n+="</select>"}var u=this.createDialog("<span class='name'>"+(g.label?g.label:b)+"</span>"+n+"<button>OK</button>",c),q=!1;if("enum"!=f&&"combo"!=f||!g.values)if("boolean"==f||"toggle"==f)(q=u.querySelector("input"))&&q.addEventListener("click",function(a){u.modified();d(!!q.checked)});else{if(q=u.querySelector("input"))q.addEventListener("blur",function(a){this.focus()}),
|
||||
r=void 0!==a.properties[b]?a.properties[b]:"","string"!==f&&(r=JSON.stringify(r)),q.value=r,q.addEventListener("keydown",function(a){if(27==a.keyCode)u.close();else if(13==a.keyCode)e();else if(13!=a.keyCode){u.modified();return}a.preventDefault();a.stopPropagation()})}else q=u.querySelector("select"),q.addEventListener("change",function(a){u.modified();d(a.target.value)});q&&q.focus();u.querySelector("button").addEventListener("click",e);return u}};h.prototype.createDialog=function(a,b){def_options=
|
||||
{checkForInput:!1,closeOnLeave:!0,closeOnLeave_checkModified:!0};b=Object.assign(def_options,b||{});var c=document.createElement("div");c.className="graphdialog";c.innerHTML=a;c.is_modified=!1;a=this.canvas.getBoundingClientRect();var e=-20,d=-20;a&&(e-=a.left,d-=a.top);b.position?(e+=b.position[0],d+=b.position[1]):b.event?(e+=b.event.clientX,d+=b.event.clientY):(e+=.5*this.canvas.width,d+=.5*this.canvas.height);c.style.left=e+"px";c.style.top=d+"px";this.canvas.parentNode.appendChild(c);b.checkForInput&&
|
||||
(a=[],(a=c.querySelectorAll("input"))&&a.forEach(function(a){a.addEventListener("keydown",function(a){c.modified();if(27==a.keyCode)c.close();else if(13!=a.keyCode)return;a.preventDefault();a.stopPropagation()});a.focus()}));c.modified=function(){c.is_modified=!0};c.close=function(){c.parentNode&&c.parentNode.removeChild(c)};var g=null,k=!1;c.addEventListener("mouseleave",function(a){k||(b.closeOnLeave||f.dialog_close_on_mouse_leave)&&!c.is_modified&&f.dialog_close_on_mouse_leave&&(g=setTimeout(c.close,
|
||||
f.dialog_close_on_mouse_leave_delay))});c.addEventListener("mouseenter",function(a){(b.closeOnLeave||f.dialog_close_on_mouse_leave)&&g&&clearTimeout(g)});(a=c.querySelectorAll("select"))&&a.forEach(function(a){a.addEventListener("click",function(a){k++});a.addEventListener("blur",function(a){k=0});a.addEventListener("change",function(a){k=-1})});return c};h.prototype.createPanel=function(a,b){b=b||{};var c=b.window||window,e=document.createElement("div");e.className="litegraph dialog";e.innerHTML=
|
||||
"<div class='dialog-header'><span class='dialog-title'></span></div><div class='dialog-content'></div><div style='display:none;' class='dialog-alt-content'></div><div class='dialog-footer'></div>";e.header=e.querySelector(".dialog-header");b.width&&(e.style.width=b.width+(b.width.constructor===Number?"px":""));b.height&&(e.style.height=b.height+(b.height.constructor===Number?"px":""));b.closable&&(b=document.createElement("span"),b.innerHTML="✕",b.classList.add("close"),b.addEventListener("click",
|
||||
function(){e.close()}),e.header.appendChild(b));e.title_element=e.querySelector(".dialog-title");e.title_element.innerText=a;e.content=e.querySelector(".dialog-content");e.alt_content=e.querySelector(".dialog-alt-content");e.footer=e.querySelector(".dialog-footer");e.close=function(){if(e.onClose&&"function"==typeof e.onClose)e.onClose();e.parentNode.removeChild(e);this.parentNode&&this.parentNode.removeChild(this)};e.toggleAltContent=function(a){if("undefined"!=typeof a){var b=a?"block":"none";a=
|
||||
a?"none":"block"}else b="block"!=e.alt_content.style.display?"block":"none",a="block"!=e.alt_content.style.display?"none":"block";e.alt_content.style.display=b;e.content.style.display=a};e.toggleFooterVisibility=function(a){e.footer.style.display="undefined"!=typeof a?a?"block":"none":"block"!=e.footer.style.display?"block":"none"};e.clear=function(){this.content.innerHTML=""};e.addHTML=function(a,b,c){var d=document.createElement("div");b&&(d.className=b);d.innerHTML=a;c?e.footer.appendChild(d):
|
||||
e.content.appendChild(d);return d};e.addButton=function(a,b,c){var d=document.createElement("button");d.innerText=a;d.options=c;d.classList.add("btn");d.addEventListener("click",b);e.footer.appendChild(d);return d};e.addSeparator=function(){var a=document.createElement("div");a.className="separator";e.content.appendChild(a)};e.addWidget=function(a,b,k,n,p){function d(a,b){n.callback&&n.callback(a,b,n);p&&p(a,b,n)}n=n||{};var g=String(k);a=a.toLowerCase();"number"==a&&(g=k.toFixed(3));var q=document.createElement("div");
|
||||
q.className="property";q.innerHTML="<span class='property_name'></span><span class='property_value'></span>";q.querySelector(".property_name").innerText=n.label||b;var y=q.querySelector(".property_value");y.innerText=g;q.dataset.property=b;q.dataset.type=n.type||a;q.options=n;q.value=k;if("code"==a)q.addEventListener("click",function(a){e.inner_showCodePad(this.dataset.property)});else if("boolean"==a)q.classList.add("boolean"),k&&q.classList.add("bool-on"),q.addEventListener("click",function(){var a=
|
||||
this.dataset.property;this.value=!this.value;this.classList.toggle("bool-on");this.querySelector(".property_value").innerText=this.value?"true":"false";d(a,this.value)});else if("string"==a||"number"==a)y.setAttribute("contenteditable",!0),y.addEventListener("keydown",function(b){"Enter"!=b.code||"string"==a&&b.shiftKey||(b.preventDefault(),this.blur())}),y.addEventListener("blur",function(){var a=this.innerText,b=this.parentNode.dataset.property;"number"==this.parentNode.dataset.type&&(a=Number(a));
|
||||
d(b,a)});else if("enum"==a||"combo"==a)g=h.getPropertyPrintableValue(k,n.values),y.innerText=g,y.addEventListener("click",function(a){var b=this.parentNode.dataset.property,e=this;new f.ContextMenu(n.values||[],{event:a,className:"dark",callback:function(a,c,g){e.innerText=a;d(b,a);return!1}},c)});e.content.appendChild(q);return q};if(e.onOpen&&"function"==typeof e.onOpen)e.onOpen();return e};h.getPropertyPrintableValue=function(a,b){if(!b||b.constructor===Array)return String(a);if(b.constructor===
|
||||
Object){var c="",e;for(e in b)if(b[e]==a){c=e;break}return String(a)+" ("+c+")"}};h.prototype.closePanels=function(){var a=document.querySelector("#node-panel");a&&a.close();(a=document.querySelector("#option-panel"))&&a.close()};h.prototype.showShowGraphOptionsPanel=function(a,b,c,e){if(this.constructor&&"HTMLDivElement"==this.constructor.name){if(!(b&&b.event&&b.event.target&&b.event.target.lgraphcanvas)){console.warn("Canvas not found");return}var d=b.event.target.lgraphcanvas}else d=this;d.closePanels();
|
||||
a=d.getCanvasWindow();panel=d.createPanel("Options",{closable:!0,window:a,onOpen:function(){d.OPTIONPANEL_IS_OPEN=!0},onClose:function(){d.OPTIONPANEL_IS_OPEN=!1;d.options_panel=null}});d.options_panel=panel;panel.id="option-panel";panel.classList.add("settings");(function(){panel.content.innerHTML="";var a=function(a,b,c){c&&c.key&&(a=c.key);c.values&&(b=Object.values(c.values).indexOf(b));d[a]=b},b=f.availableCanvasOptions;b.sort();for(pI in b){var c=b[pI];panel.addWidget("boolean",c,d[c],{key:c,
|
||||
on:"True",off:"False"},a)}panel.addWidget("combo","Render mode",f.LINK_RENDER_MODES[d.links_render_mode],{key:"links_render_mode",values:f.LINK_RENDER_MODES},a);panel.addSeparator();panel.footer.innerHTML=""})();d.canvas.parentNode.appendChild(panel)};h.prototype.showShowNodePanel=function(a){function b(){panel.content.innerHTML="";panel.addHTML("<span class='node_type'>"+a.type+"</span><span class='node_desc'>"+(a.constructor.desc||"")+"</span><span class='separator'></span>");panel.addHTML("<h3>Properties</h3>");
|
||||
var b=function(b,c){e.graph.beforeChange(a);switch(b){case "Title":a.title=c;break;case "Mode":b=Object.values(f.NODE_MODES).indexOf(c);0<=b&&f.NODE_MODES[b]?a.changeMode(b):console.warn("unexpected mode: "+c);break;case "Color":h.node_colors[c]?(a.color=h.node_colors[c].color,a.bgcolor=h.node_colors[c].bgcolor):console.warn("unexpected color: "+c);break;default:a.setProperty(b,c)}e.graph.afterChange();e.dirty_canvas=!0};panel.addWidget("string","Title",a.title,{},b);panel.addWidget("combo","Mode",
|
||||
f.NODE_MODES[a.mode],{values:f.NODE_MODES},b);var c="";void 0!==a.color&&(c=Object.keys(h.node_colors).filter(function(b){return h.node_colors[b].color==a.color}));panel.addWidget("combo","Color",c,{values:Object.keys(h.node_colors)},b);for(var k in a.properties){c=a.properties[k];var n=a.getPropertyInfo(k);a.onAddPropertyToPanel&&a.onAddPropertyToPanel(k,panel)||panel.addWidget(n.widget||n.type,k,c,n,b)}panel.addSeparator();if(a.onShowCustomPanelInfo)a.onShowCustomPanelInfo(panel);panel.footer.innerHTML=
|
||||
"";panel.addButton("Delete",function(){a.block_delete||(a.graph.remove(a),panel.close())}).classList.add("delete")}this.SELECTED_NODE=a;this.closePanels();var c=this.getCanvasWindow(),e=this;panel=this.createPanel(a.title||"",{closable:!0,window:c,onOpen:function(){e.NODEPANEL_IS_OPEN=!0},onClose:function(){e.NODEPANEL_IS_OPEN=!1;e.node_panel=null}});e.node_panel=panel;panel.id="node-panel";panel.node=a;panel.classList.add("settings");panel.inner_showCodePad=function(c){panel.classList.remove("settings");
|
||||
panel.classList.add("centered");panel.alt_content.innerHTML="<textarea class='code'></textarea>";var d=panel.alt_content.querySelector("textarea"),e=function(){panel.toggleAltContent(!1);panel.toggleFooterVisibility(!0);d.parentNode.removeChild(d);panel.classList.add("settings");panel.classList.remove("centered");b()};d.value=a.properties[c];d.addEventListener("keydown",function(b){"Enter"==b.code&&b.ctrlKey&&(a.setProperty(c,d.value),e())});panel.toggleAltContent(!0);panel.toggleFooterVisibility(!1);
|
||||
d.style.height="calc(100% - 40px)";var f=panel.addButton("Assign",function(){a.setProperty(c,d.value);e()});panel.alt_content.appendChild(f);f=panel.addButton("Close",e);f.style.float="right";panel.alt_content.appendChild(f)};b();this.canvas.parentNode.appendChild(panel)};h.prototype.showSubgraphPropertiesDialog=function(a){function b(){e.clear();if(a.inputs)for(var c=0;c<a.inputs.length;++c){var g=a.inputs[c];if(!g.not_subgraph_input){var f=e.addHTML("<button>✕</button> <span class='bullet_icon'></span><span class='name'></span><span class='type'></span>",
|
||||
"subgraph_property");f.dataset.name=g.name;f.dataset.slot=c;f.querySelector(".name").innerText=g.name;f.querySelector(".type").innerText=g.type;f.querySelector("button").addEventListener("click",function(c){a.removeInput(Number(this.parentNode.dataset.slot));b()})}}}console.log("showing subgraph properties dialog");var c=this.canvas.parentNode.querySelector(".subgraph_dialog");c&&c.close();var e=this.createPanel("Subgraph Inputs",{closable:!0,width:500});e.node=a;e.classList.add("subgraph_dialog");
|
||||
e.addHTML(" + <span class='label'>Name</span><input class='name'/><span class='label'>Type</span><input class='type'></input><button>+</button>","subgraph_property extra",!0).querySelector("button").addEventListener("click",function(c){c=this.parentNode;var d=c.querySelector(".name").value,e=c.querySelector(".type").value;d&&-1==a.findInputSlot(d)&&(a.addInput(d,e),c.querySelector(".name").value="",c.querySelector(".type").value="",b())});b();this.canvas.parentNode.appendChild(e);return e};h.prototype.showSubgraphPropertiesDialogRight=
|
||||
function(a){function b(){d.clear();if(a.outputs)for(var c=0;c<a.outputs.length;++c){var e=a.outputs[c];if(!e.not_subgraph_output){var f=d.addHTML("<button>✕</button> <span class='bullet_icon'></span><span class='name'></span><span class='type'></span>","subgraph_property");f.dataset.name=e.name;f.dataset.slot=c;f.querySelector(".name").innerText=e.name;f.querySelector(".type").innerText=e.type;f.querySelector("button").addEventListener("click",function(c){a.removeOutput(Number(this.parentNode.dataset.slot));
|
||||
b()})}}}function c(){var c=this.parentNode,d=c.querySelector(".name").value,e=c.querySelector(".type").value;d&&-1==a.findOutputSlot(d)&&(a.addOutput(d,e),c.querySelector(".name").value="",c.querySelector(".type").value="",b())}var e=this.canvas.parentNode.querySelector(".subgraph_dialog");e&&e.close();var d=this.createPanel("Subgraph Outputs",{closable:!0,width:500});d.node=a;d.classList.add("subgraph_dialog");e=d.addHTML(" + <span class='label'>Name</span><input class='name'/><span class='label'>Type</span><input class='type'></input><button>+</button>",
|
||||
"subgraph_property extra",!0);e.querySelector(".name").addEventListener("keydown",function(a){13==a.keyCode&&c.apply(this)});e.querySelector("button").addEventListener("click",function(a){c.apply(this)});b();this.canvas.parentNode.appendChild(d);return d};h.prototype.checkPanels=function(){if(this.canvas)for(var a=this.canvas.parentNode.querySelectorAll(".litegraph.dialog"),b=0;b<a.length;++b){var c=a[b];c.node&&(c.node.graph&&c.graph==this.graph||c.close())}};h.onMenuNodeCollapse=function(a,b,c,
|
||||
e,d){d.graph.beforeChange();a=h.active_canvas;if(!a.selected_nodes||1>=Object.keys(a.selected_nodes).length)d.collapse();else for(var f in a.selected_nodes)a.selected_nodes[f].collapse();d.graph.afterChange()};h.onMenuNodePin=function(a,b,c,e,d){d.pin()};h.onMenuNodeMode=function(a,b,c,e,d){new f.ContextMenu(f.NODE_MODES,{event:c,callback:function(a){if(d){var b=Object.values(f.NODE_MODES).indexOf(a),c=function(c){0<=b&&f.NODE_MODES[b]?c.changeMode(b):(console.warn("unexpected mode: "+a),c.changeMode(f.ALWAYS))},
|
||||
e=h.active_canvas;if(!e.selected_nodes||1>=Object.keys(e.selected_nodes).length)c(d);else for(var g in e.selected_nodes)c(e.selected_nodes[g])}},parentMenu:e,node:d});return!1};h.onMenuNodeColors=function(a,b,c,e,d){if(!d)throw"no node for color";b=[];b.push({value:null,content:"<span style='display: block; padding-left: 4px;'>No color</span>"});for(var g in h.node_colors)a=h.node_colors[g],a={value:g,content:"<span style='display: block; color: #999; padding-left: 4px; border-left: 8px solid "+a.color+
|
||||
"; background-color:"+a.bgcolor+"'>"+g+"</span>"},b.push(a);new f.ContextMenu(b,{event:c,callback:function(a){if(d){var b=a.value?h.node_colors[a.value]:null;a=function(a){b?a.constructor===f.LGraphGroup?a.color=b.groupcolor:(a.color=b.color,a.bgcolor=b.bgcolor):(delete a.color,delete a.bgcolor)};var c=h.active_canvas;if(!c.selected_nodes||1>=Object.keys(c.selected_nodes).length)a(d);else for(var e in c.selected_nodes)a(c.selected_nodes[e]);d.setDirtyCanvas(!0,!0)}},parentMenu:e,node:d});return!1};
|
||||
h.onMenuNodeShapes=function(a,b,c,e,d){if(!d)throw"no node passed";new f.ContextMenu(f.VALID_SHAPES,{event:c,callback:function(a){if(d){d.graph.beforeChange();var b=h.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)d.shape=a;else for(var c in b.selected_nodes)b.selected_nodes[c].shape=a;d.graph.afterChange();d.setDirtyCanvas(!0)}},parentMenu:e,node:d});return!1};h.onMenuNodeRemove=function(a,b,c,e,d){if(!d)throw"no node passed";a=d.graph;a.beforeChange();b=h.active_canvas;
|
||||
if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)!1!==d.removable&&a.remove(d);else for(var f in b.selected_nodes)c=b.selected_nodes[f],!1!==c.removable&&a.remove(c);a.afterChange();d.setDirtyCanvas(!0,!0)};h.onMenuNodeToSubgraph=function(a,b,c,e,d){a=d.graph;if(b=h.active_canvas)c=Object.values(b.selected_nodes||{}),c.length||(c=[d]),e=f.createNode("graph/subgraph"),e.pos=d.pos.concat(),a.add(e),e.buildFromNodes(c),b.deselectAllNodes(),d.setDirtyCanvas(!0,!0)};h.onMenuNodeClone=function(a,
|
||||
b,c,e,d){d.graph.beforeChange();var f={};a=function(a){if(0!=a.clonable){var b=a.clone();b&&(b.pos=[a.pos[0]+5,a.pos[1]+5],a.graph.add(b),f[b.id]=b)}};b=h.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)a(d);else for(var k in b.selected_nodes)a(b.selected_nodes[k]);Object.keys(f).length&&b.selectNodes(f);d.graph.afterChange();d.setDirtyCanvas(!0,!0)};h.node_colors={red:{color:"#322",bgcolor:"#533",groupcolor:"#A88"},brown:{color:"#332922",bgcolor:"#593930",groupcolor:"#b06634"},
|
||||
green:{color:"#232",bgcolor:"#353",groupcolor:"#8A8"},blue:{color:"#223",bgcolor:"#335",groupcolor:"#88A"},pale_blue:{color:"#2a363b",bgcolor:"#3f5159",groupcolor:"#3f789e"},cyan:{color:"#233",bgcolor:"#355",groupcolor:"#8AA"},purple:{color:"#323",bgcolor:"#535",groupcolor:"#a1309b"},yellow:{color:"#432",bgcolor:"#653",groupcolor:"#b58b2a"},black:{color:"#222",bgcolor:"#000",groupcolor:"#444"}};h.prototype.getCanvasMenuOptions=function(){if(this.getMenuOptions)var a=this.getMenuOptions();else a=[{content:"Add Node",
|
||||
has_submenu:!0,callback:h.onMenuAdd},{content:"Add Group",callback:h.onGroupAdd}],this._graph_stack&&0<this._graph_stack.length&&a.push(null,{content:"Close subgraph",callback:this.closeSubgraph.bind(this)});if(this.getExtraMenuOptions){var b=this.getExtraMenuOptions(this,a);b&&(a=a.concat(b))}return a};h.prototype.getNodeMenuOptions=function(a){if(a.getMenuOptions)var b=a.getMenuOptions(this);else b=[{content:"Inputs",has_submenu:!0,disabled:!0,callback:h.showMenuNodeOptionalInputs},{content:"Outputs",
|
||||
has_submenu:!0,disabled:!0,callback:h.showMenuNodeOptionalOutputs},null,{content:"Properties",has_submenu:!0,callback:h.onShowMenuNodeProperties},null,{content:"Title",callback:h.onShowPropertyEditor},{content:"Mode",has_submenu:!0,callback:h.onMenuNodeMode}],!1!==a.resizable&&b.push({content:"Resize",callback:h.onMenuResizeNode}),b.push({content:"Collapse",callback:h.onMenuNodeCollapse},{content:"Pin",callback:h.onMenuNodePin},{content:"Colors",has_submenu:!0,callback:h.onMenuNodeColors},{content:"Shapes",
|
||||
has_submenu:!0,callback:h.onMenuNodeShapes},null);if(a.onGetInputs){var c=a.onGetInputs();c&&c.length&&(b[0].disabled=!1)}a.onGetOutputs&&(c=a.onGetOutputs())&&c.length&&(b[1].disabled=!1);a.getExtraMenuOptions&&(c=a.getExtraMenuOptions(this,b))&&(c.push(null),b=c.concat(b));!1!==a.clonable&&b.push({content:"Clone",callback:h.onMenuNodeClone});b.push(null,{content:"Remove",disabled:!(!1!==a.removable&&!a.block_delete),callback:h.onMenuNodeRemove});if(a.graph&&a.graph.onGetNodeMenuOptions)a.graph.onGetNodeMenuOptions(b,
|
||||
a);return b};h.prototype.getGroupMenuOptions=function(a){return[{content:"Title",callback:h.onShowPropertyEditor},{content:"Color",has_submenu:!0,callback:h.onMenuNodeColors},{content:"Font size",property:"font_size",type:"Number",callback:h.onShowPropertyEditor},null,{content:"Remove",callback:h.onMenuNodeRemove}]};h.prototype.processContextMenu=function(a,b){var c=this,e=h.active_canvas.getCanvasWindow(),d=null,g={event:b,callback:function(b,d,e){if(b)if("Remove Slot"==b.content)b=b.slot,a.graph.beforeChange(),
|
||||
b.input?a.removeInput(b.slot):b.output&&a.removeOutput(b.slot),a.graph.afterChange();else if("Disconnect Links"==b.content)b=b.slot,a.graph.beforeChange(),b.output?a.disconnectOutput(b.slot):b.input&&a.disconnectInput(b.slot),a.graph.afterChange();else if("Rename Slot"==b.content){b=b.slot;var f=b.input?a.getInputInfo(b.slot):a.getOutputInfo(b.slot),g=c.createDialog("<span class='name'>Name</span><input autofocus type='text'/><button>OK</button>",d),r=g.querySelector("input");r&&f&&(r.value=f.label||
|
||||
"");var k=function(){a.graph.beforeChange();r.value&&(f&&(f.label=r.value),c.setDirty(!0));g.close();a.graph.afterChange()};g.querySelector("button").addEventListener("click",k);r.addEventListener("keydown",function(a){g.is_modified=!0;if(27==a.keyCode)g.close();else if(13==a.keyCode)k();else if(13!=a.keyCode&&"textarea"!=a.target.localName)return;a.preventDefault();a.stopPropagation()});r.focus()}},extra:a};a&&(g.title=a.type);var k=null;a&&(k=a.getSlotInPosition(b.canvasX,b.canvasY),h.active_node=
|
||||
a);k?(d=[],a.getSlotMenuOptions?d=a.getSlotMenuOptions(k):(k&&k.output&&k.output.links&&k.output.links.length&&d.push({content:"Disconnect Links",slot:k}),b=k.input||k.output,b.removable&&d.push(b.locked?"Cannot remove":{content:"Remove Slot",slot:k}),b.nameLocked||d.push({content:"Rename Slot",slot:k})),g.title=(k.input?k.input.type:k.output.type)||"*",k.input&&k.input.type==f.ACTION&&(g.title="Action"),k.output&&k.output.type==f.EVENT&&(g.title="Event")):a?d=this.getNodeMenuOptions(a):(d=this.getCanvasMenuOptions(),
|
||||
(k=this.graph.getGroupOnPos(b.canvasX,b.canvasY))&&d.push(null,{content:"Edit Group",has_submenu:!0,submenu:{title:"Group",extra:k,options:this.getGroupMenuOptions(k)}}));d&&new f.ContextMenu(d,g,e)};"undefined"!=typeof window&&window.CanvasRenderingContext2D&&!window.CanvasRenderingContext2D.prototype.roundRect&&(window.CanvasRenderingContext2D.prototype.roundRect=function(a,b,c,e,d,f){var g,h;if(0===d)this.rect(a,b,c,e);else{void 0===f&&(f=d);if(null!=d&&d.constructor===Array)if(1==d.length)var l=
|
||||
g=h=f=d[0];else if(2==d.length)l=f=d[0],g=h=d[1];else if(4==d.length)l=d[0],g=d[1],h=d[2],f=d[3];else return;else l=d||0,g=d||0,h=f||0,f=f||0;this.moveTo(a+l,b);this.lineTo(a+c-g,b);this.quadraticCurveTo(a+c,b,a+c,b+g);this.lineTo(a+c,b+e-f);this.quadraticCurveTo(a+c,b+e,a+c-f,b+e);this.lineTo(a+f,b+e);this.quadraticCurveTo(a,b+e,a,b+e-h);this.lineTo(a,b+h);this.quadraticCurveTo(a,b,a+l,b)}});f.compareObjects=function(a,b){for(var c in a)if(a[c]!=b[c])return!1;return!0};f.distance=D;f.colorToString=
|
||||
function(a){return"rgba("+Math.round(255*a[0]).toFixed()+","+Math.round(255*a[1]).toFixed()+","+Math.round(255*a[2]).toFixed()+","+(4==a.length?a[3].toFixed(2):"1.0")+")"};f.isInsideRectangle=C;f.growBounding=function(a,b,c){b<a[0]?a[0]=b:b>a[2]&&(a[2]=b);c<a[1]?a[1]=c:c>a[3]&&(a[3]=c)};f.isInsideBounding=function(a,b){return a[0]<b[0][0]||a[1]<b[0][1]||a[0]>b[1][0]||a[1]>b[1][1]?!1:!0};f.overlapBounding=A;f.hex2num=function(a){"#"==a.charAt(0)&&(a=a.slice(1));a=a.toUpperCase();for(var b=Array(3),
|
||||
c=0,e,d,f=0;6>f;f+=2)e="0123456789ABCDEF".indexOf(a.charAt(f)),d="0123456789ABCDEF".indexOf(a.charAt(f+1)),b[c]=16*e+d,c++;return b};f.num2hex=function(a){for(var b="#",c,e,d=0;3>d;d++)c=a[d]/16,e=a[d]%16,b+="0123456789ABCDEF".charAt(c)+"0123456789ABCDEF".charAt(e);return b};E.prototype.addItem=function(a,b,c){function e(a){var b=this.value;b&&b.has_submenu&&d.call(this,a)}function d(a){var b=this.value,d=!0;g.current_submenu&&g.current_submenu.close(a);if(c.callback){var e=c.callback.call(this,b,
|
||||
c,a,g,c.node);!0===e&&(d=!1)}if(b&&(b.callback&&!c.ignore_item_callbacks&&!0!==b.disabled&&(e=b.callback.call(this,b,c,a,g,c.extra),!0===e&&(d=!1)),b.submenu)){if(!b.submenu.options)throw"ContextMenu submenu needs options";new g.constructor(b.submenu.options,{callback:b.submenu.callback,event:a,parentMenu:g,ignore_item_callbacks:b.submenu.ignore_item_callbacks,title:b.submenu.title,extra:b.submenu.extra,autoopen:c.autoopen});d=!1}d&&!g.lock&&g.close()}var g=this;c=c||{};var k=document.createElement("div");
|
||||
k.className="litemenu-entry submenu";var h=!1;if(null===b)k.classList.add("separator");else{k.innerHTML=b&&b.title?b.title:a;if(k.value=b)b.disabled&&(h=!0,k.classList.add("disabled")),(b.submenu||b.has_submenu)&&k.classList.add("has_submenu");"function"==typeof b?(k.dataset.value=a,k.onclick_callback=b):k.dataset.value=b;b.className&&(k.className+=" "+b.className)}this.root.appendChild(k);h||k.addEventListener("click",d);c.autoopen&&f.pointerListenerAdd(k,"enter",e);return k};E.prototype.close=function(a,
|
||||
b){this.root.parentNode&&this.root.parentNode.removeChild(this.root);this.parentMenu&&!b&&(this.parentMenu.lock=!1,this.parentMenu.current_submenu=null,void 0===a?this.parentMenu.close():a&&!E.isCursorOverElement(a,this.parentMenu.root)&&E.trigger(this.parentMenu.root,f.pointerevents_method+"leave",a));this.current_submenu&&this.current_submenu.close(a,!0);this.root.closing_timer&&clearTimeout(this.root.closing_timer)};E.trigger=function(a,b,c,e){var d=document.createEvent("CustomEvent");d.initCustomEvent(b,
|
||||
!0,!0,c);d.srcElement=e;a.dispatchEvent?a.dispatchEvent(d):a.__events&&a.__events.dispatchEvent(d);return d};E.prototype.getTopMenu=function(){return this.options.parentMenu?this.options.parentMenu.getTopMenu():this};E.prototype.getFirstEvent=function(){return this.options.parentMenu?this.options.parentMenu.getFirstEvent():this.options.event};E.isCursorOverElement=function(a,b){var c=a.clientX;a=a.clientY;return(b=b.getBoundingClientRect())?a>b.top&&a<b.top+b.height&&c>b.left&&c<b.left+b.width?!0:
|
||||
!1:!1};f.ContextMenu=E;f.closeAllContextMenus=function(a){a=a||window;a=a.document.querySelectorAll(".litecontextmenu");if(a.length){for(var b=[],c=0;c<a.length;c++)b.push(a[c]);for(c=0;c<b.length;c++)b[c].close?b[c].close():b[c].parentNode&&b[c].parentNode.removeChild(b[c])}};f.extendClass=function(a,b){for(var c in b)a.hasOwnProperty(c)||(a[c]=b[c]);if(b.prototype)for(c in b.prototype)b.prototype.hasOwnProperty(c)&&!a.prototype.hasOwnProperty(c)&&(b.prototype.__lookupGetter__(c)?a.prototype.__defineGetter__(c,
|
||||
b.prototype.__lookupGetter__(c)):a.prototype[c]=b.prototype[c],b.prototype.__lookupSetter__(c)&&a.prototype.__defineSetter__(c,b.prototype.__lookupSetter__(c)))};G.sampleCurve=function(a,b){if(b){for(var c=0;c<b.length-1;++c){var e=b[c],d=b[c+1];if(!(d[0]<a)){b=d[0]-e[0];if(1E-5>Math.abs(b))return e[1];a=(a-e[0])/b;return e[1]*(1-a)+d[1]*a}}return 0}};G.prototype.draw=function(a,b,c,e,d,f){if(c=this.points){this.size=b;var g=b[0]-2*this.margin;b=b[1]-2*this.margin;d=d||"#666";a.save();a.translate(this.margin,
|
||||
this.margin);e&&(a.fillStyle="#111",a.fillRect(0,0,g,b),a.fillStyle="#222",a.fillRect(.5*g,0,1,b),a.strokeStyle="#333",a.strokeRect(0,0,g,b));a.strokeStyle=d;f&&(a.globalAlpha=.5);a.beginPath();for(e=0;e<c.length;++e)d=c[e],a.lineTo(d[0]*g,(1-d[1])*b);a.stroke();a.globalAlpha=1;if(!f)for(e=0;e<c.length;++e)d=c[e],a.fillStyle=this.selected==e?"#FFF":this.nearest==e?"#DDD":"#AAA",a.beginPath(),a.arc(d[0]*g,(1-d[1])*b,2,0,2*Math.PI),a.fill();a.restore()}};G.prototype.onMouseDown=function(a,b){var c=
|
||||
this.points;if(c&&!(0>a[1])){var e=this.size[0]-2*this.margin,d=this.size[1]-2*this.margin,f=a[0]-this.margin;a=a[1]-this.margin;this.selected=this.getCloserPoint([f,a],30/b.ds.scale);-1==this.selected&&(b=[f/e,1-a/d],c.push(b),c.sort(function(a,b){return a[0]-b[0]}),this.selected=c.indexOf(b),this.must_update=!0);if(-1!=this.selected)return!0}};G.prototype.onMouseMove=function(a,b){var c=this.points;if(c){var e=this.selected;if(!(0>e)){var d=(a[0]-this.margin)/(this.size[0]-2*this.margin),f=(a[1]-
|
||||
this.margin)/(this.size[1]-2*this.margin);this._nearest=this.getCloserPoint([a[0]-this.margin,a[1]-this.margin],30/b.ds.scale);if(b=c[e]){var k=0==e||e==c.length-1;!k&&(-10>a[0]||a[0]>this.size[0]+10||-10>a[1]||a[1]>this.size[1]+10)?(c.splice(e,1),this.selected=-1):(b[0]=k?0==e?0:1:Math.clamp(d,0,1),b[1]=1-Math.clamp(f,0,1),c.sort(function(a,b){return a[0]-b[0]}),this.selected=c.indexOf(b),this.must_update=!0)}}}};G.prototype.onMouseUp=function(a,b){this.selected=-1;return!1};G.prototype.getCloserPoint=
|
||||
function(a,b){var c=this.points;if(!c)return-1;b=b||30;for(var e=this.size[0]-2*this.margin,d=this.size[1]-2*this.margin,f=c.length,k=[0,0],h=1E6,l=-1,r=0;r<f;++r){var u=c[r];k[0]=u[0]*e;k[1]=(1-u[1])*d;u=vec2.distance(a,k);u>h||u>b||(l=r,h=u)}return l};f.CurveEditor=G;f.getParameterNames=function(a){return(a+"").replace(/[/][/].*$/gm,"").replace(/\s+/g,"").replace(/[/][*][^/*]*[*][/]/g,"").split("){",1)[0].replace(/^[^(]*[(]/,"").replace(/=[^,]+/g,"").split(",").filter(Boolean)};f.pointerListenerAdd=
|
||||
function(a,b,c,e){e=void 0===e?!1:e;if(a&&a.addEventListener&&b&&"function"===typeof c){var d=f.pointerevents_method;if("pointer"==d&&!window.PointerEvent)switch(console.warn("sMethod=='pointer' && !window.PointerEvent"),console.log("Converting pointer["+b+"] : down move up cancel enter TO touchstart touchmove touchend, etc .."),b){case "down":d="touch";b="start";break;case "move":d="touch";break;case "up":d="touch";b="end";break;case "cancel":d="touch";break;case "enter":console.log("debug: Should I send a move event?");
|
||||
break;default:console.warn("PointerEvent not available in this browser ? The event "+b+" would not be called")}switch(b){case "down":case "up":case "move":case "over":case "out":case "enter":a.addEventListener(d+b,c,e);case "leave":case "cancel":case "gotpointercapture":case "lostpointercapture":if("mouse"!=d)return a.addEventListener(d+b,c,e);default:return a.addEventListener(b,c,e)}}};f.pointerListenerRemove=function(a,b,c,e){e=void 0===e?!1:e;if(a&&a.removeEventListener&&b&&"function"===typeof c)switch(b){case "down":case "up":case "move":case "over":case "out":case "enter":"pointer"!=
|
||||
f.pointerevents_method&&"mouse"!=f.pointerevents_method||a.removeEventListener(f.pointerevents_method+b,c,e);case "leave":case "cancel":case "gotpointercapture":case "lostpointercapture":if("pointer"==f.pointerevents_method)return a.removeEventListener(f.pointerevents_method+b,c,e);default:return a.removeEventListener(b,c,e)}};Math.clamp=function(a,b,c){return b>a?b:c<a?c:a};"undefined"==typeof window||window.requestAnimationFrame||(window.requestAnimationFrame=window.webkitRequestAnimationFrame||
|
||||
window.mozRequestAnimationFrame||function(a){window.setTimeout(a,1E3/60)})})(this);"undefined"!=typeof exports&&(exports.LiteGraph=this.LiteGraph);
|
||||
(function(x){function m(){this.addOutput("in ms","number");this.addOutput("in sec","number")}function t(){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 w(){this.addInput("","");this.name_in_graph="";this.properties={};this.name_widget=this.addWidget("text","Name",this.properties.name,"name");this.type_widget=this.addWidget("text",
|
||||
|
||||
Reference in New Issue
Block a user