mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-28 18:22:40 +00:00
merge
This commit is contained in:
232
build/litegraph.min.js
vendored
232
build/litegraph.min.js
vendored
@@ -76,44 +76,44 @@ this.inputs.length:1,this.outputs?this.outputs.length:1);a=a||new Float32Array([
|
||||
a[1]=(this.constructor.slot_start_y||0)+d*f.NODE_SLOT_HEIGHT;d=0;if(this.widgets&&this.widgets.length){q=0;for(C=this.widgets.length;q<C;++q)d=this.widgets[q].computeSize?d+(this.widgets[q].computeSize(a[0])[1]+4):d+(f.NODE_WIDGET_HEIGHT+4);d+=8}a[1]=this.widgets_up?Math.max(a[1],d):null!=this.widgets_start_y?Math.max(a[1],d+this.widgets_start_y):a[1]+d;this.constructor.min_height&&a[1]<this.constructor.min_height&&(a[1]=this.constructor.min_height);a[1]+=6;return a};v.prototype.getPropertyInfo=function(a){var b=
|
||||
null;if(this.properties_info)for(var d=0;d<this.properties_info.length;++d)if(this.properties_info[d].name==a){b=this.properties_info[d];break}this.constructor["@"+a]&&(b=this.constructor["@"+a]);this.constructor.widgets_info&&this.constructor.widgets_info[a]&&(b=this.constructor.widgets_info[a]);!b&&this.onGetPropertyInfo&&(b=this.onGetPropertyInfo(a));b||(b={});b.type||(b.type=typeof this.properties[a]);"combo"==b.widget&&(b.type="enum");return b};v.prototype.addWidget=function(a,b,d,g,e){this.widgets||
|
||||
(this.widgets=[]);!e&&g&&g.constructor===Object&&(e=g,g=null);e&&e.constructor===String&&(e={property:e});g&&g.constructor===String&&(e||(e={}),e.property=g,g=null);g&&g.constructor!==Function&&(console.warn("addWidget: callback must be a function"),g=null);b={type:a.toLowerCase(),name:b,value:d,callback:g,options:e||{}};void 0!==b.options.y&&(b.y=b.options.y);g||b.options.callback||b.options.property||console.warn("LiteGraph addWidget(...) without a callback or property assigned");if("combo"==a&&
|
||||
!b.options.values)throw"LiteGraph addWidget('combo',...) requires to pass values in options: { values:['red','blue'] }";this.widgets.push(b);this.setSize(this.computeSize());return b};v.prototype.addCustomWidget=function(a){this.widgets||(this.widgets=[]);this.widgets.push(a);return a};v.prototype.getBounding=function(a){a=a||new Float32Array(4);a[0]=this.pos[0]-4;a[1]=this.pos[1]-f.NODE_TITLE_HEIGHT;a[2]=this.size[0]+4;a[3]=this.size[1]+f.NODE_TITLE_HEIGHT;if(this.onBounding)this.onBounding(a);return a};
|
||||
v.prototype.isPointInside=function(a,b,d,g){d=d||0;var e=this.graph&&this.graph.isLive()?0:f.NODE_TITLE_HEIGHT;g&&(e=0);if(this.flags&&this.flags.collapsed){if(z(a,b,this.pos[0]-d,this.pos[1]-f.NODE_TITLE_HEIGHT-d,(this._collapsed_width||f.NODE_COLLAPSED_WIDTH)+2*d,f.NODE_TITLE_HEIGHT+2*d))return!0}else if(this.pos[0]-4-d<a&&this.pos[0]+this.size[0]+4+d>a&&this.pos[1]-e-d<b&&this.pos[1]+this.size[1]+d>b)return!0;return!1};v.prototype.getSlotInPosition=function(a,b){var d=new Float32Array(2);if(this.inputs)for(var g=
|
||||
0,e=this.inputs.length;g<e;++g){var f=this.inputs[g];this.getConnectionPos(!0,g,d);if(z(a,b,d[0]-10,d[1]-5,20,10))return{input:f,slot:g,link_pos:d}}if(this.outputs)for(g=0,e=this.outputs.length;g<e;++g)if(f=this.outputs[g],this.getConnectionPos(!1,g,d),z(a,b,d[0]-10,d[1]-5,20,10))return{output:f,slot:g,link_pos:d};return null};v.prototype.findInputSlot=function(a){if(!this.inputs)return-1;for(var b=0,d=this.inputs.length;b<d;++b)if(a==this.inputs[b].name)return b;return-1};v.prototype.findOutputSlot=
|
||||
function(a){if(!this.outputs)return-1;for(var b=0,d=this.outputs.length;b<d;++b)if(a==this.outputs[b].name)return b;return-1};v.prototype.connect=function(a,b,d){d=d||0;if(!this.graph)return console.log("Connect: Error, node doesn't belong to any graph. Nodes must be added first to a graph before connecting them."),null;if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return f.debug&&console.log("Connect: Error, no slot of name "+a),null}else if(!this.outputs||a>=this.outputs.length)return f.debug&&
|
||||
console.log("Connect: Error, slot number not found"),null;b&&b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"target node is null";if(b==this)return null;if(d.constructor===String){if(d=b.findInputSlot(d),-1==d)return f.debug&&console.log("Connect: Error, no slot of name "+d),null}else{if(d===f.EVENT)return null;if(!b.inputs||d>=b.inputs.length)return f.debug&&console.log("Connect: Error, slot number not found"),null}var g=!1;null!=b.inputs[d].link&&(this.graph.beforeChange(),b.disconnectInput(d),
|
||||
g=!0);var e=this.outputs[a];if(b.onConnectInput&&!1===b.onConnectInput(d,e.type,e,this,a))return null;var y=b.inputs[d],m=null;if(!f.isValidConnection(e.type,y.type))return this.setDirtyCanvas(!1,!0),g&&this.graph.connectionChange(this,m),null;g||this.graph.beforeChange();m=new k(++this.graph.last_link_id,y.type,this.id,a,b.id,d);this.graph.links[m.id]=m;null==e.links&&(e.links=[]);e.links.push(m.id);b.inputs[d].link=m.id;this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(f.OUTPUT,
|
||||
a,!0,m,e);if(b.onConnectionsChange)b.onConnectionsChange(f.INPUT,d,!0,m,y);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(f.INPUT,b,d,this,a),this.graph.onNodeConnectionChange(f.OUTPUT,this,a,b,d));this.setDirtyCanvas(!1,!0);this.graph.afterChange();this.graph.connectionChange(this,m);return m};v.prototype.disconnectOutput=function(a,b){if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return f.debug&&console.log("Connect: Error, no slot of name "+a),
|
||||
!1}else if(!this.outputs||a>=this.outputs.length)return f.debug&&console.log("Connect: Error, slot number not found"),!1;var d=this.outputs[a];if(!d||!d.links||0==d.links.length)return!1;if(b){b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"Target Node not found";for(var g=0,e=d.links.length;g<e;g++){var y=d.links[g],m=this.graph.links[y];if(m.target_id==b.id){d.links.splice(g,1);var q=b.inputs[m.target_slot];q.link=null;delete this.graph.links[y];this.graph&&this.graph._version++;
|
||||
if(b.onConnectionsChange)b.onConnectionsChange(f.INPUT,m.target_slot,!1,m,q);if(this.onConnectionsChange)this.onConnectionsChange(f.OUTPUT,a,!1,m,d);if(this.graph&&this.graph.onNodeConnectionChange)this.graph.onNodeConnectionChange(f.OUTPUT,this,a);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(f.OUTPUT,this,a),this.graph.onNodeConnectionChange(f.INPUT,b,m.target_slot));break}}}else{g=0;for(e=d.links.length;g<e;g++)if(y=d.links[g],m=this.graph.links[y]){b=this.graph.getNodeById(m.target_id);
|
||||
this.graph&&this.graph._version++;if(b){q=b.inputs[m.target_slot];q.link=null;if(b.onConnectionsChange)b.onConnectionsChange(f.INPUT,m.target_slot,!1,m,q);if(this.graph&&this.graph.onNodeConnectionChange)this.graph.onNodeConnectionChange(f.INPUT,b,m.target_slot)}delete this.graph.links[y];if(this.onConnectionsChange)this.onConnectionsChange(f.OUTPUT,a,!1,m,d);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(f.OUTPUT,this,a),this.graph.onNodeConnectionChange(f.INPUT,
|
||||
b,m.target_slot))}d.links=null}this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this);return!0};v.prototype.disconnectInput=function(a){if(a.constructor===String){if(a=this.findInputSlot(a),-1==a)return f.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.inputs||a>=this.inputs.length)return f.debug&&console.log("Connect: Error, slot number not found"),!1;var b=this.inputs[a];if(!b)return!1;var d=this.inputs[a].link;if(null!=d){this.inputs[a].link=null;var g=this.graph.links[d];
|
||||
if(g){var e=this.graph.getNodeById(g.origin_id);if(!e)return!1;var y=e.outputs[g.origin_slot];if(!y||!y.links||0==y.links.length)return!1;for(var m=0,q=y.links.length;m<q;m++)if(y.links[m]==d){y.links.splice(m,1);break}delete this.graph.links[d];this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(f.INPUT,a,!1,g,b);if(e.onConnectionsChange)e.onConnectionsChange(f.OUTPUT,m,!1,g,y);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(f.OUTPUT,
|
||||
e,m),this.graph.onNodeConnectionChange(f.INPUT,this,a))}}this.setDirtyCanvas(!1,!0);this.graph&&this.graph.connectionChange(this);return!0};v.prototype.getConnectionPos=function(a,b,d){d=d||new Float32Array(2);var g=0;a&&this.inputs&&(g=this.inputs.length);!a&&this.outputs&&(g=this.outputs.length);var e=0.5*f.NODE_SLOT_HEIGHT;if(this.flags.collapsed)return b=this._collapsed_width||f.NODE_COLLAPSED_WIDTH,this.horizontal?(d[0]=this.pos[0]+0.5*b,d[1]=a?this.pos[1]-f.NODE_TITLE_HEIGHT:this.pos[1]):(d[0]=
|
||||
a?this.pos[0]:this.pos[0]+b,d[1]=this.pos[1]-0.5*f.NODE_TITLE_HEIGHT),d;if(a&&-1==b)return d[0]=this.pos[0]+0.5*f.NODE_TITLE_HEIGHT,d[1]=this.pos[1]+0.5*f.NODE_TITLE_HEIGHT,d;if(a&&g>b&&this.inputs[b].pos)return d[0]=this.pos[0]+this.inputs[b].pos[0],d[1]=this.pos[1]+this.inputs[b].pos[1],d;if(!a&&g>b&&this.outputs[b].pos)return d[0]=this.pos[0]+this.outputs[b].pos[0],d[1]=this.pos[1]+this.outputs[b].pos[1],d;if(this.horizontal)return d[0]=this.pos[0]+this.size[0]/g*(b+0.5),d[1]=a?this.pos[1]-f.NODE_TITLE_HEIGHT:
|
||||
this.pos[1]+this.size[1],d;d[0]=a?this.pos[0]+e:this.pos[0]+this.size[0]+1-e;d[1]=this.pos[1]+(b+0.7)*f.NODE_SLOT_HEIGHT+(this.constructor.slot_start_y||0);return d};v.prototype.alignToGrid=function(){this.pos[0]=f.CANVAS_GRID_SIZE*Math.round(this.pos[0]/f.CANVAS_GRID_SIZE);this.pos[1]=f.CANVAS_GRID_SIZE*Math.round(this.pos[1]/f.CANVAS_GRID_SIZE)};v.prototype.trace=function(a){this.console||(this.console=[]);this.console.push(a);this.console.length>v.MAX_CONSOLE&&this.console.shift();if(this.graph.onNodeTrace)this.graph.onNodeTrace(this,
|
||||
a)};v.prototype.setDirtyCanvas=function(a,b){this.graph&&this.graph.sendActionToCanvas("setDirty",[a,b])};v.prototype.loadImage=function(a){var b=new Image;b.src=f.node_images_path+a;b.ready=!1;var d=this;b.onload=function(){this.ready=!0;d.setDirtyCanvas(!0)};return b};v.prototype.captureInput=function(a){if(this.graph&&this.graph.list_of_graphcanvas)for(var b=this.graph.list_of_graphcanvas,d=0;d<b.length;++d){var g=b[d];if(a||g.node_capturing_input==this)g.node_capturing_input=a?this:null}};v.prototype.collapse=
|
||||
function(a){this.graph._version++;if(!1!==this.constructor.collapsable||a)this.flags.collapsed=this.flags.collapsed?!1:!0,this.setDirtyCanvas(!0,!0)};v.prototype.pin=function(a){this.graph._version++;this.flags.pinned=void 0===a?!this.flags.pinned:a};v.prototype.localToScreen=function(a,b,d){return[(a+this.pos[0])*d.scale+d.offset[0],(b+this.pos[1])*d.scale+d.offset[1]]};B.LGraphGroup=f.LGraphGroup=r;r.prototype._ctor=function(a){this.title=a||"Group";this.font_size=24;this.color=h.node_colors.pale_blue?
|
||||
h.node_colors.pale_blue.groupcolor:"#AAA";this._bounding=new Float32Array([10,10,140,80]);this._pos=this._bounding.subarray(0,2);this._size=this._bounding.subarray(2,4);this._nodes=[];this.graph=null;Object.defineProperty(this,"pos",{set:function(a){!a||2>a.length||(this._pos[0]=a[0],this._pos[1]=a[1])},get:function(){return this._pos},enumerable:!0});Object.defineProperty(this,"size",{set:function(a){!a||2>a.length||(this._size[0]=Math.max(140,a[0]),this._size[1]=Math.max(80,a[1]))},get:function(){return this._size},
|
||||
enumerable:!0})};r.prototype.configure=function(a){this.title=a.title;this._bounding.set(a.bounding);this.color=a.color;this.font=a.font};r.prototype.serialize=function(){var a=this._bounding;return{title:this.title,bounding:[Math.round(a[0]),Math.round(a[1]),Math.round(a[2]),Math.round(a[3])],color:this.color,font:this.font}};r.prototype.move=function(a,b,d){this._pos[0]+=a;this._pos[1]+=b;if(!d)for(d=0;d<this._nodes.length;++d){var g=this._nodes[d];g.pos[0]+=a;g.pos[1]+=b}};r.prototype.recomputeInsideNodes=
|
||||
function(){this._nodes.length=0;for(var a=this.graph._nodes,b=new Float32Array(4),d=0;d<a.length;++d){var g=a[d];g.getBounding(b);G(this._bounding,b)&&this._nodes.push(g)}};r.prototype.isPointInside=v.prototype.isPointInside;r.prototype.setDirtyCanvas=v.prototype.setDirtyCanvas;f.DragAndScale=t;t.prototype.bindEvents=function(a){this.last_mouse=new Float32Array(2);this._binded_mouse_callback=this.onMouse.bind(this);a.addEventListener("mousedown",this._binded_mouse_callback);a.addEventListener("mousemove",
|
||||
this._binded_mouse_callback);a.addEventListener("mousewheel",this._binded_mouse_callback,!1);a.addEventListener("wheel",this._binded_mouse_callback,!1)};t.prototype.computeVisibleArea=function(a){if(this.element){var b=this.element.width,d=this.element.height,g=-this.offset[0],e=-this.offset[1];a&&(g+=a[0]/this.scale,e+=a[1]/this.scale,b=a[2],d=a[3]);a=g+b/this.scale;d=e+d/this.scale;this.visible_area[0]=g;this.visible_area[1]=e;this.visible_area[2]=a-g;this.visible_area[3]=d-e}else this.visible_area[0]=
|
||||
this.visible_area[1]=this.visible_area[2]=this.visible_area[3]=0};t.prototype.onMouse=function(a){if(this.enabled){var b=this.element,d=b.getBoundingClientRect(),g=a.clientX-d.left,d=a.clientY-d.top;a.canvasx=g;a.canvasy=d;a.dragging=this.dragging;var e=!this.viewport||this.viewport&&g>=this.viewport[0]&&g<this.viewport[0]+this.viewport[2]&&d>=this.viewport[1]&&d<this.viewport[1]+this.viewport[3],f=!1;this.onmouse&&(f=this.onmouse(a));"mousedown"==a.type&&e?(this.dragging=!0,b.removeEventListener("mousemove",
|
||||
this._binded_mouse_callback),document.body.addEventListener("mousemove",this._binded_mouse_callback),document.body.addEventListener("mouseup",this._binded_mouse_callback)):"mousemove"==a.type?f||(b=g-this.last_mouse[0],f=d-this.last_mouse[1],this.dragging&&this.mouseDrag(b,f)):"mouseup"==a.type?(this.dragging=!1,document.body.removeEventListener("mousemove",this._binded_mouse_callback),document.body.removeEventListener("mouseup",this._binded_mouse_callback),b.addEventListener("mousemove",this._binded_mouse_callback)):
|
||||
!e||"mousewheel"!=a.type&&"wheel"!=a.type&&"DOMMouseScroll"!=a.type||(a.eventType="mousewheel",a.wheel="wheel"==a.type?-a.deltaY:null!=a.wheelDeltaY?a.wheelDeltaY:-60*a.detail,a.delta=a.wheelDelta?a.wheelDelta/40:a.deltaY?-a.deltaY/3:0,this.changeDeltaScale(1+0.05*a.delta));this.last_mouse[0]=g;this.last_mouse[1]=d;if(e)return a.preventDefault(),a.stopPropagation(),!1}};t.prototype.toCanvasContext=function(a){a.scale(this.scale,this.scale);a.translate(this.offset[0],this.offset[1])};t.prototype.convertOffsetToCanvas=
|
||||
function(a){return[(a[0]+this.offset[0])*this.scale,(a[1]+this.offset[1])*this.scale]};t.prototype.convertCanvasToOffset=function(a,b){b=b||[0,0];b[0]=a[0]/this.scale-this.offset[0];b[1]=a[1]/this.scale-this.offset[1];return b};t.prototype.mouseDrag=function(a,b){this.offset[0]+=a/this.scale;this.offset[1]+=b/this.scale;if(this.onredraw)this.onredraw(this)};t.prototype.changeScale=function(a,b){a<this.min_scale?a=this.min_scale:a>this.max_scale&&(a=this.max_scale);if(a!=this.scale&&this.element){var d=
|
||||
this.element.getBoundingClientRect();if(d){b=b||[0.5*d.width,0.5*d.height];d=this.convertCanvasToOffset(b);this.scale=a;0.01>Math.abs(this.scale-1)&&(this.scale=1);var g=this.convertCanvasToOffset(b),d=[g[0]-d[0],g[1]-d[1]];this.offset[0]+=d[0];this.offset[1]+=d[1];if(this.onredraw)this.onredraw(this)}}};t.prototype.changeDeltaScale=function(a,b){this.changeScale(this.scale*a,b)};t.prototype.reset=function(){this.scale=1;this.offset[0]=0;this.offset[1]=0};B.LGraphCanvas=f.LGraphCanvas=h;h.DEFAULT_BACKGROUND_IMAGE=
|
||||
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQBJREFUeNrs1rEKwjAUhlETUkj3vP9rdmr1Ysammk2w5wdxuLgcMHyptfawuZX4pJSWZTnfnu/lnIe/jNNxHHGNn//HNbbv+4dr6V+11uF527arU7+u63qfa/bnmh8sWLBgwYJlqRf8MEptXPBXJXa37BSl3ixYsGDBMliwFLyCV/DeLIMFCxYsWLBMwSt4Be/NggXLYMGCBUvBK3iNruC9WbBgwYJlsGApeAWv4L1ZBgsWLFiwYJmCV/AK3psFC5bBggULloJX8BpdwXuzYMGCBctgwVLwCl7Be7MMFixYsGDBsu8FH1FaSmExVfAxBa/gvVmwYMGCZbBg/W4vAQYA5tRF9QYlv/QAAAAASUVORK5CYII=";h.link_type_colors=
|
||||
{"-1":f.EVENT_LINK_COLOR,number:"#AAA",node:"#DCA"};h.gradients={};h.prototype.clear=function(){this.fps=this.render_time=this.last_draw_time=this.frame=0;this.dragging_rectangle=null;this.selected_nodes={};this.selected_group=null;this.visible_nodes=[];this.connecting_node=this.node_capturing_input=this.node_over=this.node_dragged=null;this.highlighted_links={};this.dragging_canvas=!1;this.dirty_bgcanvas=this.dirty_canvas=!0;this.node_widget=this.node_in_panel=this.dirty_area=null;this.last_mouse=
|
||||
[0,0];this.last_mouseclick=0;this.visible_area.set([0,0,0,0]);if(this.onClear)this.onClear()};h.prototype.setGraph=function(a,b){this.graph!=a&&(b||this.clear(),!a&&this.graph?this.graph.detachCanvas(this):(a.attachCanvas(this),this._graph_stack&&(this._graph_stack=null),this.setDirty(!0,!0)))};h.prototype.getTopGraph=function(){return this._graph_stack.length?this._graph_stack[0]:this.graph};h.prototype.openSubgraph=function(a){if(!a)throw"graph cannot be null";if(this.graph==a)throw"graph cannot be the same";
|
||||
this.clear();this.graph&&(this._graph_stack||(this._graph_stack=[]),this._graph_stack.push(this.graph));a.attachCanvas(this);this.checkPanels();this.setDirty(!0,!0)};h.prototype.closeSubgraph=function(){if(this._graph_stack&&0!=this._graph_stack.length){var a=this.graph._subgraph_node,b=this._graph_stack.pop();this.selected_nodes={};this.highlighted_links={};b.attachCanvas(this);this.setDirty(!0,!0);a&&(this.centerOnNode(a),this.selectNodes([a]))}};h.prototype.getCurrentGraph=function(){return this.graph};
|
||||
h.prototype.setCanvas=function(a,b){if(a&&a.constructor===String&&(a=document.getElementById(a),!a))throw"Error creating LiteGraph canvas: Canvas not found";if(a!==this.canvas&&(!a&&this.canvas&&(b||this.unbindEvents()),this.canvas=a,this.ds.element=a)){a.className+=" lgraphcanvas";a.data=this;a.tabindex="1";this.bgcanvas=null;this.bgcanvas||(this.bgcanvas=document.createElement("canvas"),this.bgcanvas.width=this.canvas.width,this.bgcanvas.height=this.canvas.height);if(null==a.getContext){if("canvas"!=
|
||||
a.localName)throw"Element supplied for LGraphCanvas must be a <canvas> element, you passed a "+a.localName;throw"This browser doesn't support Canvas";}null==(this.ctx=a.getContext("2d"))&&(a.webgl_enabled||console.warn("This canvas seems to be WebGL, enabling WebGL renderer"),this.enableWebGL());this._mousemove_callback=this.processMouseMove.bind(this);this._mouseup_callback=this.processMouseUp.bind(this);b||this.bindEvents()}};h.prototype._doNothing=function(a){a.preventDefault();return!1};h.prototype._doReturnTrue=
|
||||
function(a){a.preventDefault();return!0};h.prototype.bindEvents=function(){if(this._events_binded)console.warn("LGraphCanvas: events already binded");else{var a=this.canvas,b=this.getCanvasWindow().document;this._mousedown_callback=this.processMouseDown.bind(this);this._mousewheel_callback=this.processMouseWheel.bind(this);a.addEventListener("mousedown",this._mousedown_callback,!0);a.addEventListener("mousemove",this._mousemove_callback);a.addEventListener("mousewheel",this._mousewheel_callback,!1);
|
||||
a.addEventListener("contextmenu",this._doNothing);a.addEventListener("DOMMouseScroll",this._mousewheel_callback,!1);a.addEventListener("touchstart",this.touchHandler,!0);a.addEventListener("touchmove",this.touchHandler,!0);a.addEventListener("touchend",this.touchHandler,!0);a.addEventListener("touchcancel",this.touchHandler,!0);this._key_callback=this.processKey.bind(this);a.addEventListener("keydown",this._key_callback,!0);b.addEventListener("keyup",this._key_callback,!0);this._ondrop_callback=this.processDrop.bind(this);
|
||||
a.addEventListener("dragover",this._doNothing,!1);a.addEventListener("dragend",this._doNothing,!1);a.addEventListener("drop",this._ondrop_callback,!1);a.addEventListener("dragenter",this._doReturnTrue,!1);this._events_binded=!0}};h.prototype.unbindEvents=function(){if(this._events_binded){var a=this.getCanvasWindow().document;this.canvas.removeEventListener("mousedown",this._mousedown_callback);this.canvas.removeEventListener("mousewheel",this._mousewheel_callback);this.canvas.removeEventListener("DOMMouseScroll",
|
||||
this._mousewheel_callback);this.canvas.removeEventListener("keydown",this._key_callback);a.removeEventListener("keyup",this._key_callback);this.canvas.removeEventListener("contextmenu",this._doNothing);this.canvas.removeEventListener("drop",this._ondrop_callback);this.canvas.removeEventListener("dragenter",this._doReturnTrue);this.canvas.removeEventListener("touchstart",this.touchHandler);this.canvas.removeEventListener("touchmove",this.touchHandler);this.canvas.removeEventListener("touchend",this.touchHandler);
|
||||
this.canvas.removeEventListener("touchcancel",this.touchHandler);this._ondrop_callback=this._key_callback=this._mousewheel_callback=this._mousedown_callback=null;this._events_binded=!1}else console.warn("LGraphCanvas: no events binded")};h.getFileExtension=function(a){var b=a.indexOf("?");-1!=b&&(a=a.substr(0,b));b=a.lastIndexOf(".");return-1==b?"":a.substr(b+1).toLowerCase()};h.prototype.enableWebGL=function(){if(void 0===typeof GL)throw"litegl.js must be included to use a WebGL canvas";if(void 0===
|
||||
typeof enableWebGLCanvas)throw"webglCanvas.js must be included to use this feature";this.gl=this.ctx=enableWebGLCanvas(this.canvas);this.ctx.webgl=!0;this.bgcanvas=this.canvas;this.bgctx=this.gl;this.canvas.webgl_enabled=!0};h.prototype.setDirty=function(a,b){a&&(this.dirty_canvas=!0);b&&(this.dirty_bgcanvas=!0)};h.prototype.getCanvasWindow=function(){if(!this.canvas)return window;var a=this.canvas.ownerDocument;return a.defaultView||a.parentWindow};h.prototype.startRendering=function(){function a(){this.pause_rendering||
|
||||
!b.options.values)throw"LiteGraph addWidget('combo',...) requires to pass values in options: { values:['red','blue'] }";this.widgets.push(b);this.setSize(this.computeSize());return b};v.prototype.addCustomWidget=function(a){this.widgets||(this.widgets=[]);this.widgets.push(a);return a};v.prototype.getBounding=function(a){a=a||new Float32Array(4);a[0]=this.pos[0]-4;a[1]=this.pos[1]-f.NODE_TITLE_HEIGHT;a[2]=this.size[0]+4;a[3]=this.flags.collapsed?f.NODE_TITLE_HEIGHT:this.size[1]+f.NODE_TITLE_HEIGHT;
|
||||
if(this.onBounding)this.onBounding(a);return a};v.prototype.isPointInside=function(a,b,d,g){d=d||0;var e=this.graph&&this.graph.isLive()?0:f.NODE_TITLE_HEIGHT;g&&(e=0);if(this.flags&&this.flags.collapsed){if(z(a,b,this.pos[0]-d,this.pos[1]-f.NODE_TITLE_HEIGHT-d,(this._collapsed_width||f.NODE_COLLAPSED_WIDTH)+2*d,f.NODE_TITLE_HEIGHT+2*d))return!0}else if(this.pos[0]-4-d<a&&this.pos[0]+this.size[0]+4+d>a&&this.pos[1]-e-d<b&&this.pos[1]+this.size[1]+d>b)return!0;return!1};v.prototype.getSlotInPosition=
|
||||
function(a,b){var d=new Float32Array(2);if(this.inputs)for(var g=0,e=this.inputs.length;g<e;++g){var f=this.inputs[g];this.getConnectionPos(!0,g,d);if(z(a,b,d[0]-10,d[1]-5,20,10))return{input:f,slot:g,link_pos:d}}if(this.outputs)for(g=0,e=this.outputs.length;g<e;++g)if(f=this.outputs[g],this.getConnectionPos(!1,g,d),z(a,b,d[0]-10,d[1]-5,20,10))return{output:f,slot:g,link_pos:d};return null};v.prototype.findInputSlot=function(a){if(!this.inputs)return-1;for(var b=0,d=this.inputs.length;b<d;++b)if(a==
|
||||
this.inputs[b].name)return b;return-1};v.prototype.findOutputSlot=function(a){if(!this.outputs)return-1;for(var b=0,d=this.outputs.length;b<d;++b)if(a==this.outputs[b].name)return b;return-1};v.prototype.connect=function(a,b,d){d=d||0;if(!this.graph)return console.log("Connect: Error, node doesn't belong to any graph. Nodes must be added first to a graph before connecting them."),null;if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return f.debug&&console.log("Connect: Error, no slot of name "+
|
||||
a),null}else if(!this.outputs||a>=this.outputs.length)return f.debug&&console.log("Connect: Error, slot number not found"),null;b&&b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"target node is null";if(b==this)return null;if(d.constructor===String){if(d=b.findInputSlot(d),-1==d)return f.debug&&console.log("Connect: Error, no slot of name "+d),null}else{if(d===f.EVENT)return null;if(!b.inputs||d>=b.inputs.length)return f.debug&&console.log("Connect: Error, slot number not found"),
|
||||
null}var g=!1;null!=b.inputs[d].link&&(this.graph.beforeChange(),b.disconnectInput(d),g=!0);var e=this.outputs[a];if(b.onConnectInput&&!1===b.onConnectInput(d,e.type,e,this,a))return null;var y=b.inputs[d],m=null;if(!f.isValidConnection(e.type,y.type))return this.setDirtyCanvas(!1,!0),g&&this.graph.connectionChange(this,m),null;g||this.graph.beforeChange();m=new k(++this.graph.last_link_id,y.type,this.id,a,b.id,d);this.graph.links[m.id]=m;null==e.links&&(e.links=[]);e.links.push(m.id);b.inputs[d].link=
|
||||
m.id;this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(f.OUTPUT,a,!0,m,e);if(b.onConnectionsChange)b.onConnectionsChange(f.INPUT,d,!0,m,y);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(f.INPUT,b,d,this,a),this.graph.onNodeConnectionChange(f.OUTPUT,this,a,b,d));this.setDirtyCanvas(!1,!0);this.graph.afterChange();this.graph.connectionChange(this,m);return m};v.prototype.disconnectOutput=function(a,b){if(a.constructor===String){if(a=
|
||||
this.findOutputSlot(a),-1==a)return f.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.outputs||a>=this.outputs.length)return f.debug&&console.log("Connect: Error, slot number not found"),!1;var d=this.outputs[a];if(!d||!d.links||0==d.links.length)return!1;if(b){b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"Target Node not found";for(var g=0,e=d.links.length;g<e;g++){var y=d.links[g],m=this.graph.links[y];if(m.target_id==b.id){d.links.splice(g,1);var q=
|
||||
b.inputs[m.target_slot];q.link=null;delete this.graph.links[y];this.graph&&this.graph._version++;if(b.onConnectionsChange)b.onConnectionsChange(f.INPUT,m.target_slot,!1,m,q);if(this.onConnectionsChange)this.onConnectionsChange(f.OUTPUT,a,!1,m,d);if(this.graph&&this.graph.onNodeConnectionChange)this.graph.onNodeConnectionChange(f.OUTPUT,this,a);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(f.OUTPUT,this,a),this.graph.onNodeConnectionChange(f.INPUT,b,m.target_slot));
|
||||
break}}}else{g=0;for(e=d.links.length;g<e;g++)if(y=d.links[g],m=this.graph.links[y]){b=this.graph.getNodeById(m.target_id);this.graph&&this.graph._version++;if(b){q=b.inputs[m.target_slot];q.link=null;if(b.onConnectionsChange)b.onConnectionsChange(f.INPUT,m.target_slot,!1,m,q);if(this.graph&&this.graph.onNodeConnectionChange)this.graph.onNodeConnectionChange(f.INPUT,b,m.target_slot)}delete this.graph.links[y];if(this.onConnectionsChange)this.onConnectionsChange(f.OUTPUT,a,!1,m,d);this.graph&&this.graph.onNodeConnectionChange&&
|
||||
(this.graph.onNodeConnectionChange(f.OUTPUT,this,a),this.graph.onNodeConnectionChange(f.INPUT,b,m.target_slot))}d.links=null}this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this);return!0};v.prototype.disconnectInput=function(a){if(a.constructor===String){if(a=this.findInputSlot(a),-1==a)return f.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.inputs||a>=this.inputs.length)return f.debug&&console.log("Connect: Error, slot number not found"),!1;var b=this.inputs[a];
|
||||
if(!b)return!1;var d=this.inputs[a].link;if(null!=d){this.inputs[a].link=null;var g=this.graph.links[d];if(g){var e=this.graph.getNodeById(g.origin_id);if(!e)return!1;var y=e.outputs[g.origin_slot];if(!y||!y.links||0==y.links.length)return!1;for(var m=0,q=y.links.length;m<q;m++)if(y.links[m]==d){y.links.splice(m,1);break}delete this.graph.links[d];this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(f.INPUT,a,!1,g,b);if(e.onConnectionsChange)e.onConnectionsChange(f.OUTPUT,
|
||||
m,!1,g,y);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(f.OUTPUT,e,m),this.graph.onNodeConnectionChange(f.INPUT,this,a))}}this.setDirtyCanvas(!1,!0);this.graph&&this.graph.connectionChange(this);return!0};v.prototype.getConnectionPos=function(a,b,d){d=d||new Float32Array(2);var g=0;a&&this.inputs&&(g=this.inputs.length);!a&&this.outputs&&(g=this.outputs.length);var e=0.5*f.NODE_SLOT_HEIGHT;if(this.flags.collapsed)return b=this._collapsed_width||f.NODE_COLLAPSED_WIDTH,
|
||||
this.horizontal?(d[0]=this.pos[0]+0.5*b,d[1]=a?this.pos[1]-f.NODE_TITLE_HEIGHT:this.pos[1]):(d[0]=a?this.pos[0]:this.pos[0]+b,d[1]=this.pos[1]-0.5*f.NODE_TITLE_HEIGHT),d;if(a&&-1==b)return d[0]=this.pos[0]+0.5*f.NODE_TITLE_HEIGHT,d[1]=this.pos[1]+0.5*f.NODE_TITLE_HEIGHT,d;if(a&&g>b&&this.inputs[b].pos)return d[0]=this.pos[0]+this.inputs[b].pos[0],d[1]=this.pos[1]+this.inputs[b].pos[1],d;if(!a&&g>b&&this.outputs[b].pos)return d[0]=this.pos[0]+this.outputs[b].pos[0],d[1]=this.pos[1]+this.outputs[b].pos[1],
|
||||
d;if(this.horizontal)return d[0]=this.pos[0]+this.size[0]/g*(b+0.5),d[1]=a?this.pos[1]-f.NODE_TITLE_HEIGHT:this.pos[1]+this.size[1],d;d[0]=a?this.pos[0]+e:this.pos[0]+this.size[0]+1-e;d[1]=this.pos[1]+(b+0.7)*f.NODE_SLOT_HEIGHT+(this.constructor.slot_start_y||0);return d};v.prototype.alignToGrid=function(){this.pos[0]=f.CANVAS_GRID_SIZE*Math.round(this.pos[0]/f.CANVAS_GRID_SIZE);this.pos[1]=f.CANVAS_GRID_SIZE*Math.round(this.pos[1]/f.CANVAS_GRID_SIZE)};v.prototype.trace=function(a){this.console||
|
||||
(this.console=[]);this.console.push(a);this.console.length>v.MAX_CONSOLE&&this.console.shift();if(this.graph.onNodeTrace)this.graph.onNodeTrace(this,a)};v.prototype.setDirtyCanvas=function(a,b){this.graph&&this.graph.sendActionToCanvas("setDirty",[a,b])};v.prototype.loadImage=function(a){var b=new Image;b.src=f.node_images_path+a;b.ready=!1;var d=this;b.onload=function(){this.ready=!0;d.setDirtyCanvas(!0)};return b};v.prototype.captureInput=function(a){if(this.graph&&this.graph.list_of_graphcanvas)for(var b=
|
||||
this.graph.list_of_graphcanvas,d=0;d<b.length;++d){var g=b[d];if(a||g.node_capturing_input==this)g.node_capturing_input=a?this:null}};v.prototype.collapse=function(a){this.graph._version++;if(!1!==this.constructor.collapsable||a)this.flags.collapsed=this.flags.collapsed?!1:!0,this.setDirtyCanvas(!0,!0)};v.prototype.pin=function(a){this.graph._version++;this.flags.pinned=void 0===a?!this.flags.pinned:a};v.prototype.localToScreen=function(a,b,d){return[(a+this.pos[0])*d.scale+d.offset[0],(b+this.pos[1])*
|
||||
d.scale+d.offset[1]]};B.LGraphGroup=f.LGraphGroup=r;r.prototype._ctor=function(a){this.title=a||"Group";this.font_size=24;this.color=h.node_colors.pale_blue?h.node_colors.pale_blue.groupcolor:"#AAA";this._bounding=new Float32Array([10,10,140,80]);this._pos=this._bounding.subarray(0,2);this._size=this._bounding.subarray(2,4);this._nodes=[];this.graph=null;Object.defineProperty(this,"pos",{set:function(a){!a||2>a.length||(this._pos[0]=a[0],this._pos[1]=a[1])},get:function(){return this._pos},enumerable:!0});
|
||||
Object.defineProperty(this,"size",{set:function(a){!a||2>a.length||(this._size[0]=Math.max(140,a[0]),this._size[1]=Math.max(80,a[1]))},get:function(){return this._size},enumerable:!0})};r.prototype.configure=function(a){this.title=a.title;this._bounding.set(a.bounding);this.color=a.color;this.font=a.font};r.prototype.serialize=function(){var a=this._bounding;return{title:this.title,bounding:[Math.round(a[0]),Math.round(a[1]),Math.round(a[2]),Math.round(a[3])],color:this.color,font:this.font}};r.prototype.move=
|
||||
function(a,b,d){this._pos[0]+=a;this._pos[1]+=b;if(!d)for(d=0;d<this._nodes.length;++d){var g=this._nodes[d];g.pos[0]+=a;g.pos[1]+=b}};r.prototype.recomputeInsideNodes=function(){this._nodes.length=0;for(var a=this.graph._nodes,b=new Float32Array(4),d=0;d<a.length;++d){var g=a[d];g.getBounding(b);G(this._bounding,b)&&this._nodes.push(g)}};r.prototype.isPointInside=v.prototype.isPointInside;r.prototype.setDirtyCanvas=v.prototype.setDirtyCanvas;f.DragAndScale=t;t.prototype.bindEvents=function(a){this.last_mouse=
|
||||
new Float32Array(2);this._binded_mouse_callback=this.onMouse.bind(this);a.addEventListener("mousedown",this._binded_mouse_callback);a.addEventListener("mousemove",this._binded_mouse_callback);a.addEventListener("mousewheel",this._binded_mouse_callback,!1);a.addEventListener("wheel",this._binded_mouse_callback,!1)};t.prototype.computeVisibleArea=function(a){if(this.element){var b=this.element.width,d=this.element.height,g=-this.offset[0],e=-this.offset[1];a&&(g+=a[0]/this.scale,e+=a[1]/this.scale,
|
||||
b=a[2],d=a[3]);a=g+b/this.scale;d=e+d/this.scale;this.visible_area[0]=g;this.visible_area[1]=e;this.visible_area[2]=a-g;this.visible_area[3]=d-e}else this.visible_area[0]=this.visible_area[1]=this.visible_area[2]=this.visible_area[3]=0};t.prototype.onMouse=function(a){if(this.enabled){var b=this.element,d=b.getBoundingClientRect(),g=a.clientX-d.left,d=a.clientY-d.top;a.canvasx=g;a.canvasy=d;a.dragging=this.dragging;var e=!this.viewport||this.viewport&&g>=this.viewport[0]&&g<this.viewport[0]+this.viewport[2]&&
|
||||
d>=this.viewport[1]&&d<this.viewport[1]+this.viewport[3],f=!1;this.onmouse&&(f=this.onmouse(a));"mousedown"==a.type&&e?(this.dragging=!0,b.removeEventListener("mousemove",this._binded_mouse_callback),document.body.addEventListener("mousemove",this._binded_mouse_callback),document.body.addEventListener("mouseup",this._binded_mouse_callback)):"mousemove"==a.type?f||(b=g-this.last_mouse[0],f=d-this.last_mouse[1],this.dragging&&this.mouseDrag(b,f)):"mouseup"==a.type?(this.dragging=!1,document.body.removeEventListener("mousemove",
|
||||
this._binded_mouse_callback),document.body.removeEventListener("mouseup",this._binded_mouse_callback),b.addEventListener("mousemove",this._binded_mouse_callback)):!e||"mousewheel"!=a.type&&"wheel"!=a.type&&"DOMMouseScroll"!=a.type||(a.eventType="mousewheel",a.wheel="wheel"==a.type?-a.deltaY:null!=a.wheelDeltaY?a.wheelDeltaY:-60*a.detail,a.delta=a.wheelDelta?a.wheelDelta/40:a.deltaY?-a.deltaY/3:0,this.changeDeltaScale(1+0.05*a.delta));this.last_mouse[0]=g;this.last_mouse[1]=d;if(e)return a.preventDefault(),
|
||||
a.stopPropagation(),!1}};t.prototype.toCanvasContext=function(a){a.scale(this.scale,this.scale);a.translate(this.offset[0],this.offset[1])};t.prototype.convertOffsetToCanvas=function(a){return[(a[0]+this.offset[0])*this.scale,(a[1]+this.offset[1])*this.scale]};t.prototype.convertCanvasToOffset=function(a,b){b=b||[0,0];b[0]=a[0]/this.scale-this.offset[0];b[1]=a[1]/this.scale-this.offset[1];return b};t.prototype.mouseDrag=function(a,b){this.offset[0]+=a/this.scale;this.offset[1]+=b/this.scale;if(this.onredraw)this.onredraw(this)};
|
||||
t.prototype.changeScale=function(a,b){a<this.min_scale?a=this.min_scale:a>this.max_scale&&(a=this.max_scale);if(a!=this.scale&&this.element){var d=this.element.getBoundingClientRect();if(d){b=b||[0.5*d.width,0.5*d.height];d=this.convertCanvasToOffset(b);this.scale=a;0.01>Math.abs(this.scale-1)&&(this.scale=1);var g=this.convertCanvasToOffset(b),d=[g[0]-d[0],g[1]-d[1]];this.offset[0]+=d[0];this.offset[1]+=d[1];if(this.onredraw)this.onredraw(this)}}};t.prototype.changeDeltaScale=function(a,b){this.changeScale(this.scale*
|
||||
a,b)};t.prototype.reset=function(){this.scale=1;this.offset[0]=0;this.offset[1]=0};B.LGraphCanvas=f.LGraphCanvas=h;h.DEFAULT_BACKGROUND_IMAGE="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQBJREFUeNrs1rEKwjAUhlETUkj3vP9rdmr1Ysammk2w5wdxuLgcMHyptfawuZX4pJSWZTnfnu/lnIe/jNNxHHGNn//HNbbv+4dr6V+11uF527arU7+u63qfa/bnmh8sWLBgwYJlqRf8MEptXPBXJXa37BSl3ixYsGDBMliwFLyCV/DeLIMFCxYsWLBMwSt4Be/NggXLYMGCBUvBK3iNruC9WbBgwYJlsGApeAWv4L1ZBgsWLFiwYJmCV/AK3psFC5bBggULloJX8BpdwXuzYMGCBctgwVLwCl7Be7MMFixYsGDBsu8FH1FaSmExVfAxBa/gvVmwYMGCZbBg/W4vAQYA5tRF9QYlv/QAAAAASUVORK5CYII=";
|
||||
h.link_type_colors={"-1":f.EVENT_LINK_COLOR,number:"#AAA",node:"#DCA"};h.gradients={};h.prototype.clear=function(){this.fps=this.render_time=this.last_draw_time=this.frame=0;this.dragging_rectangle=null;this.selected_nodes={};this.selected_group=null;this.visible_nodes=[];this.connecting_node=this.node_capturing_input=this.node_over=this.node_dragged=null;this.highlighted_links={};this.dragging_canvas=!1;this.dirty_bgcanvas=this.dirty_canvas=!0;this.node_widget=this.node_in_panel=this.dirty_area=
|
||||
null;this.last_mouse=[0,0];this.last_mouseclick=0;this.visible_area.set([0,0,0,0]);if(this.onClear)this.onClear()};h.prototype.setGraph=function(a,b){this.graph!=a&&(b||this.clear(),!a&&this.graph?this.graph.detachCanvas(this):(a.attachCanvas(this),this._graph_stack&&(this._graph_stack=null),this.setDirty(!0,!0)))};h.prototype.getTopGraph=function(){return this._graph_stack.length?this._graph_stack[0]:this.graph};h.prototype.openSubgraph=function(a){if(!a)throw"graph cannot be null";if(this.graph==
|
||||
a)throw"graph cannot be the same";this.clear();this.graph&&(this._graph_stack||(this._graph_stack=[]),this._graph_stack.push(this.graph));a.attachCanvas(this);this.checkPanels();this.setDirty(!0,!0)};h.prototype.closeSubgraph=function(){if(this._graph_stack&&0!=this._graph_stack.length){var a=this.graph._subgraph_node,b=this._graph_stack.pop();this.selected_nodes={};this.highlighted_links={};b.attachCanvas(this);this.setDirty(!0,!0);a&&(this.centerOnNode(a),this.selectNodes([a]))}};h.prototype.getCurrentGraph=
|
||||
function(){return this.graph};h.prototype.setCanvas=function(a,b){if(a&&a.constructor===String&&(a=document.getElementById(a),!a))throw"Error creating LiteGraph canvas: Canvas not found";if(a!==this.canvas&&(!a&&this.canvas&&(b||this.unbindEvents()),this.canvas=a,this.ds.element=a)){a.className+=" lgraphcanvas";a.data=this;a.tabindex="1";this.bgcanvas=null;this.bgcanvas||(this.bgcanvas=document.createElement("canvas"),this.bgcanvas.width=this.canvas.width,this.bgcanvas.height=this.canvas.height);
|
||||
if(null==a.getContext){if("canvas"!=a.localName)throw"Element supplied for LGraphCanvas must be a <canvas> element, you passed a "+a.localName;throw"This browser doesn't support Canvas";}null==(this.ctx=a.getContext("2d"))&&(a.webgl_enabled||console.warn("This canvas seems to be WebGL, enabling WebGL renderer"),this.enableWebGL());this._mousemove_callback=this.processMouseMove.bind(this);this._mouseup_callback=this.processMouseUp.bind(this);b||this.bindEvents()}};h.prototype._doNothing=function(a){a.preventDefault();
|
||||
return!1};h.prototype._doReturnTrue=function(a){a.preventDefault();return!0};h.prototype.bindEvents=function(){if(this._events_binded)console.warn("LGraphCanvas: events already binded");else{var a=this.canvas,b=this.getCanvasWindow().document;this._mousedown_callback=this.processMouseDown.bind(this);this._mousewheel_callback=this.processMouseWheel.bind(this);a.addEventListener("mousedown",this._mousedown_callback,!0);a.addEventListener("mousemove",this._mousemove_callback);a.addEventListener("mousewheel",
|
||||
this._mousewheel_callback,!1);a.addEventListener("contextmenu",this._doNothing);a.addEventListener("DOMMouseScroll",this._mousewheel_callback,!1);a.addEventListener("touchstart",this.touchHandler,!0);a.addEventListener("touchmove",this.touchHandler,!0);a.addEventListener("touchend",this.touchHandler,!0);a.addEventListener("touchcancel",this.touchHandler,!0);this._key_callback=this.processKey.bind(this);a.addEventListener("keydown",this._key_callback,!0);b.addEventListener("keyup",this._key_callback,
|
||||
!0);this._ondrop_callback=this.processDrop.bind(this);a.addEventListener("dragover",this._doNothing,!1);a.addEventListener("dragend",this._doNothing,!1);a.addEventListener("drop",this._ondrop_callback,!1);a.addEventListener("dragenter",this._doReturnTrue,!1);this._events_binded=!0}};h.prototype.unbindEvents=function(){if(this._events_binded){var a=this.getCanvasWindow().document;this.canvas.removeEventListener("mousedown",this._mousedown_callback);this.canvas.removeEventListener("mousewheel",this._mousewheel_callback);
|
||||
this.canvas.removeEventListener("DOMMouseScroll",this._mousewheel_callback);this.canvas.removeEventListener("keydown",this._key_callback);a.removeEventListener("keyup",this._key_callback);this.canvas.removeEventListener("contextmenu",this._doNothing);this.canvas.removeEventListener("drop",this._ondrop_callback);this.canvas.removeEventListener("dragenter",this._doReturnTrue);this.canvas.removeEventListener("touchstart",this.touchHandler);this.canvas.removeEventListener("touchmove",this.touchHandler);
|
||||
this.canvas.removeEventListener("touchend",this.touchHandler);this.canvas.removeEventListener("touchcancel",this.touchHandler);this._ondrop_callback=this._key_callback=this._mousewheel_callback=this._mousedown_callback=null;this._events_binded=!1}else console.warn("LGraphCanvas: no events binded")};h.getFileExtension=function(a){var b=a.indexOf("?");-1!=b&&(a=a.substr(0,b));b=a.lastIndexOf(".");return-1==b?"":a.substr(b+1).toLowerCase()};h.prototype.enableWebGL=function(){if(void 0===typeof GL)throw"litegl.js must be included to use a WebGL canvas";
|
||||
if(void 0===typeof enableWebGLCanvas)throw"webglCanvas.js must be included to use this feature";this.gl=this.ctx=enableWebGLCanvas(this.canvas);this.ctx.webgl=!0;this.bgcanvas=this.canvas;this.bgctx=this.gl;this.canvas.webgl_enabled=!0};h.prototype.setDirty=function(a,b){a&&(this.dirty_canvas=!0);b&&(this.dirty_bgcanvas=!0)};h.prototype.getCanvasWindow=function(){if(!this.canvas)return window;var a=this.canvas.ownerDocument;return a.defaultView||a.parentWindow};h.prototype.startRendering=function(){function a(){this.pause_rendering||
|
||||
this.draw();var b=this.getCanvasWindow();this.is_rendering&&b.requestAnimationFrame(a.bind(this))}this.is_rendering||(this.is_rendering=!0,a.call(this))};h.prototype.stopRendering=function(){this.is_rendering=!1};h.prototype.blockClick=function(){this.block_click=!0;this.last_mouseclick=0};h.prototype.processMouseDown=function(a){this.set_canvas_dirty_on_mouse_event&&(this.dirty_canvas=!0);if(this.graph){this.adjustMouseEvent(a);var b=this.getCanvasWindow();h.active_canvas=this;var d=this,g=a.localX,
|
||||
e=a.localY;this.ds.viewport=this.viewport;g=!this.viewport||this.viewport&&g>=this.viewport[0]&&g<this.viewport[0]+this.viewport[2]&&e>=this.viewport[1]&&e<this.viewport[1]+this.viewport[3];this.options.skip_events||(this.canvas.removeEventListener("mousemove",this._mousemove_callback),b.document.addEventListener("mousemove",this._mousemove_callback,!0),b.document.addEventListener("mouseup",this._mouseup_callback,!0));if(g){var y=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes,5),e=
|
||||
!1,g=300>f.getTime()-this.last_mouseclick;this.mouse[0]=a.localX;this.mouse[1]=a.localY;this.graph_mouse[0]=a.canvasX;this.graph_mouse[1]=a.canvasY;this.last_click_position=[this.mouse[0],this.mouse[1]];this.canvas.focus();f.closeAllContextMenus(b);if(!this.onMouse||!0!=this.onMouse(a)){if(1==a.which){a.ctrlKey&&(this.dragging_rectangle=new Float32Array(4),this.dragging_rectangle[0]=a.canvasX,this.dragging_rectangle[1]=a.canvasY,this.dragging_rectangle[2]=1,this.dragging_rectangle[3]=1,e=!0);var m=
|
||||
@@ -202,74 +202,74 @@ J,w*(H-30),m);q&&!s.disabled&&d.strokeRect(15,J,H-30,m);s.marker&&(h=(s.marker-s
|
||||
b+0.5*m),d.lineTo(31,b+m-5),d.fill(),d.beginPath(),d.moveTo(H-15-16,b+5),d.lineTo(H-15-6,b+0.5*m),d.lineTo(H-15-16,b+m-5),d.fill()),d.fillStyle=u,d.fillText(s.name,35,J+0.7*m),d.fillStyle=n,d.textAlign="right","number"==s.type?d.fillText(Number(s.value).toFixed(void 0!==s.options.precision?s.options.precision:3),H-30-20,J+0.7*m):(h=s.value,s.options.values&&(w=s.options.values,w.constructor===Function&&(w=w()),w&&w.constructor!==Array&&(h=w[s.value])),d.fillText(h,H-30-20,J+0.7*m)));break;case "string":case "text":d.textAlign=
|
||||
"left";d.strokeStyle=C;d.fillStyle=l;d.beginPath();q?d.roundRect(15,b,H-30,m,0.5*m):d.rect(15,b,H-30,m);d.fill();q&&(s.disabled||d.stroke(),d.save(),d.beginPath(),d.rect(15,b,H-30,m),d.clip(),d.fillStyle=u,null!=s.name&&d.fillText(s.name,30,J+0.7*m),d.fillStyle=n,d.textAlign="right",d.fillText(String(s.value).substr(0,30),H-30,J+0.7*m),d.restore());break;default:s.draw&&s.draw(d,a,H,J,m)}b+=(s.computeSize?s.computeSize(H)[1]:m)+4;d.globalAlpha=this.editor_alpha}d.restore();d.textAlign="left"};h.prototype.processNodeWidgets=
|
||||
function(a,b,d,g){function e(e,g){e.value=g;e.options&&e.options.property&&void 0!==a.properties[e.options.property]&&a.setProperty(e.options.property,g);e.callback&&e.callback(e.value,l,a,b,d)}if(!a.widgets||!a.widgets.length)return null;for(var c=b[0]-a.pos[0],m=b[1]-a.pos[1],q=a.size[0],l=this,n=this.getCanvasWindow(),s=0;s<a.widgets.length;++s){var u=a.widgets[s];if(u&&!u.disabled){var F=u.computeSize?u.computeSize(q)[1]:f.NODE_WIDGET_HEIGHT,h=u.width||q;if(u==g||!(6>c||c>h-12||m<u.last_y||m>
|
||||
u.last_y+F)){g=u.value;switch(u.type){case "button":if("mousemove"===d.type)break;u.callback&&setTimeout(function(){u.callback(u,l,a,b,d)},20);this.dirty_canvas=u.clicked=!0;break;case "slider":n=Math.clamp((c-15)/(h-30),0,1);u.value=u.options.min+(u.options.max-u.options.min)*n;u.callback&&setTimeout(function(){e(u,u.value)},20);this.dirty_canvas=!0;break;case "number":case "combo":g=u.value;if("mousemove"==d.type&&"number"==u.type)u.value+=0.1*d.deltaX*(u.options.step||1),null!=u.options.min&&u.value<
|
||||
u.options.min&&(u.value=u.options.min),null!=u.options.max&&u.value>u.options.max&&(u.value=u.options.max);else if("mousedown"==d.type){var J=u.options.values;J&&J.constructor===Function&&(J=u.options.values(u,a));var H=null;"number"!=u.type&&(H=J.constructor===Array?J:Object.keys(J));c=40>c?-1:c>h-40?1:0;if("number"==u.type)u.value+=0.1*c*(u.options.step||1),null!=u.options.min&&u.value<u.options.min&&(u.value=u.options.min),null!=u.options.max&&u.value>u.options.max&&(u.value=u.options.max);else if(c)n=
|
||||
-1,this.last_mouseclick=0,n=J.constructor===Object?H.indexOf(String(u.value))+c:H.indexOf(u.value)+c,n>=H.length&&(n=H.length-1),0>n&&(n=0),u.value=J.constructor===Array?J[n]:n;else{var w=J!=H?Object.values(J):J;new f.ContextMenu(w,{scale:Math.max(1,this.ds.scale),event:d,className:"dark",callback:r.bind(u)},n);var r=function(a,b,d){J!=H&&(a=w.indexOf(a));this.value=a;e(this,a);l.dirty_canvas=!0;return!1}}}else"mouseup"==d.type&&"number"==u.type&&(c=40>c?-1:c>h-40?1:0,200>d.click_time&&0==c&&this.prompt("Value",
|
||||
u.value,function(a){this.value=Number(a);e(this,this.value)}.bind(u),d));g!=u.value&&setTimeout(function(){e(this,this.value)}.bind(u),20);this.dirty_canvas=!0;break;case "toggle":"mousedown"==d.type&&(u.value=!u.value,setTimeout(function(){e(u,u.value)},20));break;case "string":case "text":"mousedown"==d.type&&this.prompt("Value",u.value,function(a){this.value=a;e(this,a)}.bind(u),d,u.options?u.options.multiline:!1);break;default:u.mouse&&(this.dirty_canvas=u.mouse(d,[c,m],a))}if(g!=u.value){if(a.onWidgetChanged)a.onWidgetChanged(u.name,
|
||||
u.value,g,u);a.graph._version++}return u}}}return null};h.prototype.drawGroups=function(a,b){if(this.graph){var d=this.graph._groups;b.save();b.globalAlpha=0.5*this.editor_alpha;for(var g=0;g<d.length;++g){var e=d[g];if(G(this.visible_area,e._bounding)){b.fillStyle=e.color||"#335";b.strokeStyle=e.color||"#335";var c=e._pos,m=e._size;b.globalAlpha=0.25*this.editor_alpha;b.beginPath();b.rect(c[0]+0.5,c[1]+0.5,m[0],m[1]);b.fill();b.globalAlpha=this.editor_alpha;b.stroke();b.beginPath();b.moveTo(c[0]+
|
||||
m[0],c[1]+m[1]);b.lineTo(c[0]+m[0]-10,c[1]+m[1]);b.lineTo(c[0]+m[0],c[1]+m[1]-10);b.fill();m=e.font_size||f.DEFAULT_GROUP_FONT_SIZE;b.font=m+"px Arial";b.fillText(e.title,c[0]+4,c[1]+m)}}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){if(!a&&!b){var d=this.canvas.parentNode;a=d.offsetWidth;b=d.offsetHeight}if(this.canvas.width!=a||this.canvas.height!=b)this.canvas.width=
|
||||
a,this.canvas.height=b,this.bgcanvas.width=this.canvas.width,this.bgcanvas.height=this.canvas.height,this.setDirty(!0,!0)};h.prototype.switchLiveMode=function(a){if(a){var b=this,d=this.live_mode?1.1:0.9;this.live_mode&&(this.live_mode=!1,this.editor_alpha=0.1);var g=setInterval(function(){b.editor_alpha*=d;b.dirty_canvas=!0;b.dirty_bgcanvas=!0;1>d&&0.01>b.editor_alpha&&(clearInterval(g),1>d&&(b.live_mode=!0));1<d&&0.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.prototype.touchHandler=function(a){var b=a.changedTouches[0],d="";switch(a.type){case "touchstart":d="mousedown";break;case "touchmove":d="mousemove";break;case "touchend":d="mouseup";break;default:return}var g=this.getCanvasWindow(),e=g.document.createEvent("MouseEvent");e.initMouseEvent(d,!0,!0,g,1,b.screenX,b.screenY,b.clientX,b.clientY,!1,!1,!1,!1,0,null);b.target.dispatchEvent(e);a.preventDefault()};h.onGroupAdd=
|
||||
function(a,b,d){a=h.active_canvas;a.getCanvasWindow();b=new f.LGraphGroup;b.pos=a.convertEventToCanvasOffset(d);a.graph.add(b)};h.onMenuAdd=function(a,b,d,g,e){function c(a,b){var g=[];f.getNodeTypesCategories(m.filter||l.filter).filter(function(b){return b.startsWith(a)}).map(function(b){if(b){b=b.replace(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,e){c(a.value,e)}})}});f.getNodeTypesInCategory(a.slice(0,-1),m.filter||l.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();m.graph.beforeChange();if(a=f.createNode(a.value))a.pos=m.convertEventToCanvasOffset(b),m.graph.add(a);e&&e(a);m.graph.afterChange()}})});new f.ContextMenu(g,{event:d,parentMenu:b},q)}var m=h.active_canvas,q=m.getCanvasWindow(),l=m.graph;if(l)return c("",g),!1};h.onMenuCollapseAll=
|
||||
function(){};h.onMenuNodeEdit=function(){};h.showMenuNodeOptionalInputs=function(a,b,d,g,e){function c(a,b,d){e&&(a.callback&&a.callback.call(m,e,a,b,d),a.value&&(e.graph.beforeChange(),e.addInput(a.value[0],a.value[1],a.value[2]),e.setDirtyCanvas(!0,!0),e.graph.afterChange()))}if(e){var m=this;a=h.active_canvas.getCanvasWindow();b=e.optional_inputs;e.onGetInputs&&(b=e.onGetInputs());var q=[];if(b)for(var l=0;l<b.length;l++){var n=b[l];if(n){var s=n[0];n[2]&&n[2].label&&(s=n[2].label);s={content:s,
|
||||
value:n};n[1]==f.ACTION&&(s.className="event");q.push(s)}else q.push(null)}this.onMenuNodeInputs&&(q=this.onMenuNodeInputs(q));if(q.length)return new f.ContextMenu(q,{event:d,callback:c,parentMenu:g,node:e},a),!1;console.log("no input entries")}};h.showMenuNodeOptionalOutputs=function(a,b,d,g,e){function c(a,b,d){if(e&&(a.callback&&a.callback.call(m,e,a,b,d),a.value))if(d=a.value[1],!d||d.constructor!==Object&&d.constructor!==Array)e.graph.beforeChange(),e.addOutput(a.value[0],a.value[1],a.value[2]),
|
||||
e.setDirtyCanvas(!0,!0),e.graph.afterChange();else{a=[];for(var q in d)a.push({content:q,value:d[q]});new f.ContextMenu(a,{event:b,callback:c,parentMenu:g,node:e});return!1}}if(e){var m=this;a=h.active_canvas.getCanvasWindow();b=e.optional_outputs;e.onGetOutputs&&(b=e.onGetOutputs());var q=[];if(b)for(var l=0;l<b.length;l++){var n=b[l];if(!n)q.push(null);else if(!e.flags||!e.flags.skip_repeated_outputs||-1==e.findOutputSlot(n[0])){var s=n[0];n[2]&&n[2].label&&(s=n[2].label);s={content:s,value:n};
|
||||
n[1]==f.EVENT&&(s.className="event");q.push(s)}}this.onMenuNodeOutputs&&(q=this.onMenuNodeOutputs(q));if(q.length)return new f.ContextMenu(q,{event:d,callback:c,parentMenu:g,node:e},a),!1}};h.onShowMenuNodeProperties=function(a,b,d,g,e){function c(a,b,d,g){e&&(b=this.getBoundingClientRect(),m.showEditPropertyValue(e,a.value,{position:[b.left,b.top]}))}if(e&&e.properties){var m=h.active_canvas;b=m.getCanvasWindow();var q=[],l;for(l in e.properties){a=void 0!==e.properties[l]?e.properties[l]:" ";"object"==
|
||||
typeof a&&(a=JSON.stringify(a));var n=e.getPropertyInfo(l);if("enum"==n.type||"combo"==n.type)a=h.getPropertyPrintableValue(a,n.values);a=h.decodeHTML(a);q.push({content:"<span class='property_name'>"+(n.label?n.label:l)+"</span><span class='property_value'>"+a+"</span>",value:l})}if(q.length)return new f.ContextMenu(q,{event:d,callback:c,parentMenu:g,allow_html:!0,node:e},b),!1}};h.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};h.onResizeNode=function(a,
|
||||
b,d,g,e){if(e){e.size=e.computeSize();if(e.onResize)e.onResize(e.size);e.setDirtyCanvas(!0,!0)}};h.prototype.showLinkMenu=function(a,b){var d=this;console.log(a);var g=new f.ContextMenu(["Add Node",null,"Delete"],{event:b,title:null!=a.data?a.data.constructor.name:null,callback:function(b,f,c){switch(b){case "Add Node":h.onMenuAdd(null,null,c,g,function(b){console.log("node autoconnect");var e=d.graph.getNodeById(a.origin_id),g=d.graph.getNodeById(a.target_id);b.inputs&&b.inputs.length&&b.outputs&&
|
||||
b.outputs.length&&e.outputs[a.origin_slot].type==b.inputs[0].type&&b.outputs[0].type==g.inputs[0].type&&(e.connect(a.origin_slot,b,0),b.connect(0,g,a.target_slot),b.pos[0]-=0.5*b.size[0])});break;case "Delete":d.graph.removeLink(a.id)}}});return!1};h.onShowPropertyEditor=function(a,b,d,g,e){function f(){var b=l.value;"Number"==a.type?b=Number(b):"Boolean"==a.type&&(b=Boolean(b));e[c]=b;q.parentNode&&q.parentNode.removeChild(q);e.setDirtyCanvas(!0,!0)}var c=a.property||"title";b=e[c];var q=document.createElement("div");
|
||||
q.className="graphdialog";q.innerHTML="<span class='name'></span><input autofocus type='text' class='value'/><button>OK</button>";q.querySelector(".name").innerText=c;var l=q.querySelector(".value");l&&(l.value=b,l.addEventListener("blur",function(a){this.focus()}),l.addEventListener("keydown",function(a){if(13==a.keyCode||"textarea"==a.target.localName)f(),a.preventDefault(),a.stopPropagation()}));b=h.active_canvas.canvas;d=b.getBoundingClientRect();var n=g=-20;d&&(g-=d.left,n-=d.top);event?(q.style.left=
|
||||
event.clientX+g+"px",q.style.top=event.clientY+n+"px"):(q.style.left=0.5*b.width+g+"px",q.style.top=0.5*b.height+n+"px");q.querySelector("button").addEventListener("click",f);b.parentNode.appendChild(q)};h.prototype.prompt=function(a,b,d,g,e){var f=this;a=a||"";var c=!1,q=document.createElement("div");q.className="graphdialog rounded";q.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>";
|
||||
q.close=function(){f.prompt_box=null;q.parentNode&&q.parentNode.removeChild(q)};1<this.ds.scale&&(q.style.transform="scale("+this.ds.scale+")");q.addEventListener("mouseleave",function(a){c||q.close()});f.prompt_box&&f.prompt_box.close();f.prompt_box=q;q.querySelector(".name").innerText=a;var l=q.querySelector(".value");l.value=b;l.addEventListener("keydown",function(a){c=!0;if(27==a.keyCode)q.close();else if(13==a.keyCode&&"textarea"!=a.target.localName)d&&d(this.value),q.close();else return;a.preventDefault();
|
||||
a.stopPropagation()});q.querySelector("button").addEventListener("click",function(a){d&&d(l.value);f.setDirty(!0);q.close()});a=h.active_canvas.canvas;b=a.getBoundingClientRect();var n=e=-20;b&&(e-=b.left,n-=b.top);g?(q.style.left=g.clientX+e+"px",q.style.top=g.clientY+n+"px"):(q.style.left=0.5*a.width+e+"px",q.style.top=0.5*a.height+n+"px");a.parentNode.appendChild(q);setTimeout(function(){l.focus()},10);return q};h.search_limit=-1;h.prototype.showSearchBox=function(a){function b(b){if(b)if(e.onSearchBoxSelection)e.onSearchBoxSelection(b,
|
||||
a,c);else{var d=f.searchbox_extras[b.toLowerCase()];d&&(b=d.type);c.graph.beforeChange();if(b=f.createNode(b))b.pos=c.convertEventToCanvasOffset(a),c.graph.add(b);if(d&&d.data){if(d.data.properties)for(var g in d.data.properties)b.addProperty(g,d.data.properties[g]);if(d.data.inputs)for(g in b.inputs=[],d.data.inputs)b.addOutput(d.data.inputs[g][0],d.data.inputs[g][1]);if(d.data.outputs)for(g in b.outputs=[],d.data.outputs)b.addOutput(d.data.outputs[g][0],d.data.outputs[g][1]);d.data.title&&(b.title=
|
||||
d.data.title);d.data.json&&b.configure(d.data.json);c.graph.afterChange()}}l.close()}function d(a){var b=r;r&&r.classList.remove("selected");r?(r=a?r.nextSibling:r.previousSibling)||(r=b):r=a?s.childNodes[0]:s.childNodes[s.childNodes.length];r&&(r.classList.add("selected"),r.scrollIntoView({block:"end",behavior:"smooth"}))}function g(){function a(d,e){var g=document.createElement("div");w||(w=d);g.innerText=d;g.dataset.type=escape(d);g.className="litegraph lite-search-item";e&&(g.className+=" "+e);
|
||||
g.addEventListener("click",function(a){b(unescape(this.dataset.type))});s.appendChild(g)}F=null;var d=J.value;w=null;s.innerHTML="";if(d)if(e.onSearchBox){var g=e.onSearchBox(s,d,c);if(g)for(var m=0;m<g.length;++m)a(g[m])}else{var g=0,d=d.toLowerCase(),q=c.filter||c.graph.filter;for(m in f.searchbox_extras){var l=f.searchbox_extras[m];if(-1!==l.desc.toLowerCase().indexOf(d)){var n=f.registered_node_types[l.type];if(!n||n.filter==q)if(a(l.desc,"searchbox_extra"),-1!==h.search_limit&&g++>h.search_limit)break}}l=
|
||||
null;if(Array.prototype.filter)l=Object.keys(f.registered_node_types).filter(H);else for(m in l=[],f.registered_node_types)H(m)&&l.push(m);for(m=0;m<l.length&&!(a(l[m]),-1!==h.search_limit&&g++>h.search_limit);m++);var H=function(a){var b=f.registered_node_types[a];return q&&b.filter!=q?!1:-1!==a.toLowerCase().indexOf(d)}}}var e=this,c=h.active_canvas,m=c.canvas,q=m.ownerDocument||document,l=document.createElement("div");l.className="litegraph litesearchbox graphdialog rounded";l.innerHTML="<span class='name'>Search</span> <input autofocus type='text' class='value rounded'/><div class='helper'></div>";
|
||||
l.close=function(){e.search_box=null;q.body.focus();q.body.style.overflow="";setTimeout(function(){e.canvas.focus()},20);l.parentNode&&l.parentNode.removeChild(l)};var n=null;1<this.ds.scale&&(l.style.transform="scale("+this.ds.scale+")");l.addEventListener("mouseenter",function(a){n&&(clearTimeout(n),n=null)});l.addEventListener("mouseleave",function(a){n=setTimeout(function(){l.close()},500)});e.search_box&&e.search_box.close();e.search_box=l;var s=l.querySelector(".helper"),w=null,F=null,r=null,
|
||||
J=l.querySelector("input");J&&(J.addEventListener("blur",function(a){this.focus()}),J.addEventListener("keydown",function(a){if(38==a.keyCode)d(!1);else if(40==a.keyCode)d(!0);else if(27==a.keyCode)l.close();else if(13==a.keyCode)r?b(r.innerHTML):w?b(w):l.close();else{F&&clearInterval(F);F=setTimeout(g,10);return}a.preventDefault();a.stopPropagation();a.stopImmediatePropagation();return!0}));q.fullscreenElement?q.fullscreenElement.appendChild(l):(q.body.appendChild(l),q.body.style.overflow="hidden");
|
||||
var m=m.getBoundingClientRect(),H=(a?a.clientY:m.top+0.5*m.height)-20;l.style.left=(a?a.clientX:m.left+0.5*m.width)-80+"px";l.style.top=H+"px";a.layerY>m.height-200&&(s.style.maxHeight=m.height-a.layerY-20+"px");J.focus();return l};h.prototype.showEditPropertyValue=function(a,b,d){function g(){e(h.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"==c||"object"==c)e=JSON.parse(e);a.properties[b]=
|
||||
e;a.graph&&a.graph._version++;if(a.onPropertyChanged)a.onPropertyChanged(b,e);if(d.onclose)d.onclose();s.close();a.setDirtyCanvas(!0,!0)}if(a&&void 0!==a.properties[b]){d=d||{};var f=a.getPropertyInfo(b),c=f.type,q="";if("string"==c||"number"==c||"array"==c||"object"==c)q="<input autofocus type='text' class='value'/>";else if("enum"!=c&&"combo"!=c||!f.values)if("boolean"==c)q="<input autofocus type='checkbox' class='value' "+(a.properties[b]?"checked":"")+"/>";else{console.warn("unknown type: "+c);
|
||||
return}else{var q="<select autofocus type='text' class='value'>",l;for(l in f.values){var n=l;f.values.constructor===Array&&(n=f.values[l]);q+="<option value='"+n+"' "+(n==a.properties[b]?"selected":"")+">"+f.values[l]+"</option>"}q+="</select>"}var s=this.createDialog("<span class='name'>"+(f.label?f.label:b)+"</span>"+q+"<button>OK</button>",d);if("enum"!=c&&"combo"!=c||!f.values)if("boolean"==c)(h=s.querySelector("input"))&&h.addEventListener("click",function(a){e(!!h.checked)});else{if(h=s.querySelector("input"))h.addEventListener("blur",
|
||||
function(a){this.focus()}),n=void 0!==a.properties[b]?a.properties[b]:"","string"!==c&&(n=JSON.stringify(n)),h.value=n,h.addEventListener("keydown",function(a){13==a.keyCode&&(g(),a.preventDefault(),a.stopPropagation())})}else{var h=s.querySelector("select");h.addEventListener("change",function(a){e(a.target.value)})}s.querySelector("button").addEventListener("click",g);return s}};h.prototype.createDialog=function(a,b){b=b||{};var d=document.createElement("div");d.className="graphdialog";d.innerHTML=
|
||||
a;var g=this.canvas.getBoundingClientRect(),e=-20,f=-20;g&&(e-=g.left,f-=g.top);b.position?(e+=b.position[0],f+=b.position[1]):b.event?(e+=b.event.clientX,f+=b.event.clientY):(e+=0.5*this.canvas.width,f+=0.5*this.canvas.height);d.style.left=e+"px";d.style.top=f+"px";this.canvas.parentNode.appendChild(d);d.close=function(){this.parentNode&&this.parentNode.removeChild(this)};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 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":""));if(b.closable){var e=document.createElement("span");e.innerHTML="✕";e.classList.add("close");e.addEventListener("click",function(){g.close()});g.header.appendChild(e)}g.title_element=
|
||||
g.querySelector(".dialog-title");g.title_element.innerText=a;g.content=g.querySelector(".dialog-content");g.footer=g.querySelector(".dialog-footer");g.close=function(){this.parentNode&&this.parentNode.removeChild(this)};g.clear=function(){this.content.innerHTML=""};g.addHTML=function(a,b,d){var e=document.createElement("div");b&&(e.className=b);e.innerHTML=a;d?g.footer.appendChild(e):g.content.appendChild(e);return e};g.addButton=function(a,b,d){var e=document.createElement("button");e.innerText=
|
||||
a;e.options=d;e.classList.add("btn");e.addEventListener("click",b);g.footer.appendChild(e);return e};g.addSeparator=function(){var a=document.createElement("div");a.className="separator";g.content.appendChild(a)};g.addWidget=function(a,b,e,c,l){function n(a,b){console.log("change",a,b);c.callback&&c.callback(a,b);l&&l(a,b)}c=c||{};var s=String(e);a=a.toLowerCase();"number"==a&&(s=e.toFixed(3));var F=document.createElement("div");F.className="property";F.innerHTML="<span class='property_name'></span><span class='property_value'></span>";
|
||||
F.querySelector(".property_name").innerText=b;var w=F.querySelector(".property_value");w.innerText=s;F.dataset.property=b;F.dataset.type=c.type||a;F.options=c;F.value=e;if("boolean"==a)F.classList.add("boolean"),e&&F.classList.add("bool-on"),F.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";n(a,this.value)});else if("string"==a||"number"==a)w.setAttribute("contenteditable",
|
||||
!0),w.addEventListener("keydown",function(a){"Enter"==a.code&&(a.preventDefault(),this.blur())}),w.addEventListener("blur",function(){var a=this.innerText,b=this.parentNode.dataset.property;"number"==this.parentNode.dataset.type&&(a=Number(a));n(b,a)});else if("enum"==a||"combo"==a)s=h.getPropertyPrintableValue(e,c.values);w.innerText=s;w.addEventListener("click",function(a){var b=this.parentNode.dataset.property,e=this;new f.ContextMenu(c.values||[],{event:a,className:"dark",callback:function(a,
|
||||
d,g){e.innerText=a;n(b,a);return!1}},d)});g.content.appendChild(F);return F};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.showShowNodePanel=function(a){window.SELECTED_NODE=a;var b=document.querySelector("#node-panel");b&&b.close();var d=this.getCanvasWindow(),b=this.createPanel(a.title||"",{closable:!0,window:d});b.id="node-panel";b.node=
|
||||
a;b.classList.add("settings");var g=this;(function(){b.content.innerHTML="";b.addHTML("<span class='node_type'>"+a.type+"</span><span class='node_desc'>"+(a.constructor.desc||"")+"</span><span class='separator'></span>");b.addHTML("<h3>Properties</h3>");for(var d in a.properties){var f=a.properties[d],c=a.getPropertyInfo(d);a.onAddPropertyToPanel&&a.onAddPropertyToPanel(d,b)||b.addWidget(c.widget||c.type,d,f,c,function(b,d){g.graph.beforeChange(a);a.setProperty(b,d);g.graph.afterChange();g.dirty_canvas=
|
||||
!0})}b.addSeparator();if(a.onShowCustomPanelInfo)a.onShowCustomPanelInfo(b);b.addButton("Delete",function(){a.block_delete||(a.graph.remove(a),b.close())}).classList.add("delete")})();this.canvas.parentNode.appendChild(b)};h.prototype.showSubgraphPropertiesDialog=function(a){function b(){g.clear();if(a.inputs)for(var d=0;d<a.inputs.length;++d){var f=a.inputs[d];if(!f.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=f.name;c.dataset.slot=d;c.querySelector(".name").innerText=f.name;c.querySelector(".type").innerText=f.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 g=d.querySelector(".name").value,f=d.querySelector(".type").value;g&&-1==a.findInputSlot(g)&&(a.addInput(g,f),d.querySelector(".name").value="",d.querySelector(".type").value="",b())});b();this.canvas.parentNode.appendChild(g);return g};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,e){e.graph.beforeChange(e);e.collapse();e.graph.afterChange(e)};h.onMenuNodePin=function(a,b,d,g,e){e.pin()};h.onMenuNodeMode=function(a,b,d,g,e){new f.ContextMenu(["Always","On Event","On Trigger","Never"],{event:d,callback:function(a){if(e)switch(a){case "On Event":e.mode=f.ON_EVENT;
|
||||
break;case "On Trigger":e.mode=f.ON_TRIGGER;break;case "Never":e.mode=f.NEVER;break;default:e.mode=f.ALWAYS}},parentMenu:g,node:e});return!1};h.onMenuNodeColors=function(a,b,d,g,e){if(!e)throw"no node for color";b=[];b.push({value:null,content:"<span style='display: block; padding-left: 4px;'>No color</span>"});for(var 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 f.ContextMenu(b,{event:d,callback:function(a){e&&((a=a.value?h.node_colors[a.value]:null)?e.constructor===f.LGraphGroup?e.color=a.groupcolor:(e.color=a.color,e.bgcolor=a.bgcolor):(delete e.color,delete e.bgcolor),e.setDirtyCanvas(!0,!0))},parentMenu:g,node:e});return!1};h.onMenuNodeShapes=function(a,b,d,g,e){if(!e)throw"no node passed";new f.ContextMenu(f.VALID_SHAPES,{event:d,callback:function(a){e&&(e.graph.beforeChange(e),e.shape=a,e.graph.afterChange(e),e.setDirtyCanvas(!0))},
|
||||
parentMenu:g,node:e});return!1};h.onMenuNodeRemove=function(a,b,d,g,e){if(!e)throw"no node passed";!1!==e.removable&&(a=e.graph,a.beforeChange(),a.remove(e),a.afterChange(),e.setDirtyCanvas(!0,!0))};h.onMenuNodeToSubgraph=function(a,b,d,g,e){a=e.graph;if(b=h.active_canvas)d=Object.values(b.selected_nodes||{}),d.length||(d=[e]),g=f.createNode("graph/subgraph"),g.pos=e.pos.concat(),a.add(g),g.buildFromNodes(d),b.deselectAllNodes(),e.setDirtyCanvas(!0,!0)};h.onMenuNodeClone=function(a,b,d,g,e){!1!=e.clonable&&
|
||||
(a=e.clone())&&(a.pos=[e.pos[0]+5,e.pos[1]+5],e.graph.beforeChange(),e.graph.add(a),e.graph.afterChange(),e.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(){var a=null;this.getMenuOptions?a=this.getMenuOptions():(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){var b=null,b=a.getMenuOptions?a.getMenuOptions(this):[{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},
|
||||
{content:"Resize",callback:function(){if(a.resizable)return h.onResizeNode}},{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(),e=null,c={event:b,callback:function(b,e,g){if(b)if("Remove Slot"==b.content)b=b.slot,b.input?a.removeInput(b.slot):b.output&&a.removeOutput(b.slot);else if("Disconnect Links"==b.content)b=b.slot,b.output?a.disconnectOutput(b.slot):b.input&&a.disconnectInput(b.slot);else if("Rename Slot"==b.content){b=b.slot;var f=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>",e),q=c.querySelector("input");q&&f&&(q.value=f.label||"");c.querySelector("button").addEventListener("click",function(a){q.value&&(f&&(f.label=q.value),d.setDirty(!0));c.close()})}},extra:a};a&&(c.title=a.type);var m=null;a&&(m=a.getSlotInPosition(b.canvasX,b.canvasY),h.active_node=a);if(m){e=[];if(a.getSlotMenuOptions)e=a.getSlotMenuOptions(m);else{m&&m.output&&m.output.links&&m.output.links.length&&
|
||||
e.push({content:"Disconnect Links",slot:m});var q=m.input||m.output;e.push(q.locked?"Cannot remove":{content:"Remove Slot",slot:m});e.push(q.nameLocked?"Cannot rename":{content:"Rename Slot",slot:m})}c.title=(m.input?m.input.type:m.output.type)||"*";m.input&&m.input.type==f.ACTION&&(c.title="Action");m.output&&m.output.type==f.EVENT&&(c.title="Event")}else a?e=this.getNodeMenuOptions(a):(e=this.getCanvasMenuOptions(),(m=this.graph.getGroupOnPos(b.canvasX,b.canvasY))&&e.push(null,{content:"Edit Group",
|
||||
has_submenu:!0,submenu:{title:"Group",extra:m,options:this.getGroupMenuOptions(m)}}));e&&new f.ContextMenu(e,c,g)};"undefined"!=typeof window&&window.CanvasRenderingContext2D&&(window.CanvasRenderingContext2D.prototype.roundRect=function(a,b,d,g,e,f){void 0===e&&(e=5);void 0===f&&(f=e);this.moveTo(a+e,b);this.lineTo(a+d-e,b);this.quadraticCurveTo(a+d,b,a+d,b+e);this.lineTo(a+d,b+g-f);this.quadraticCurveTo(a+d,b+g,a+d-f,b+g);this.lineTo(a+f,b+g);this.quadraticCurveTo(a,b+g,a,b+g-f);this.lineTo(a,b+
|
||||
e);this.quadraticCurveTo(a,b,a+e,b)});f.compareObjects=function(a,b){for(var d in a)if(a[d]!=b[d])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=z;f.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)};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=G;f.hex2num=function(a){"#"==a.charAt(0)&&(a=a.slice(1));a=a.toUpperCase();for(var b=Array(3),d=0,g,e,f=0;6>f;f+=2)g="0123456789ABCDEF".indexOf(a.charAt(f)),e="0123456789ABCDEF".indexOf(a.charAt(f+1)),b[d]=16*g+e,d++;return b};f.num2hex=function(a){for(var b="#",d,g,e=0;3>e;e++)d=a[e]/16,g=a[e]%16,b+="0123456789ABCDEF".charAt(d)+"0123456789ABCDEF".charAt(g);return b};A.prototype.addItem=function(a,b,d){function g(a){var b=this.value;b&&b.has_submenu&&
|
||||
e.call(this,a)}function e(a){var b=this.value,e=!0;f.current_submenu&&f.current_submenu.close(a);if(d.callback){var g=d.callback.call(this,b,d,a,f,d.node);!0===g&&(e=!1)}if(b&&(b.callback&&!d.ignore_item_callbacks&&!0!==b.disabled&&(g=b.callback.call(this,b,d,a,f,d.extra),!0===g&&(e=!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:d.autoopen});e=!1}e&&!f.lock&&f.close()}var f=this;d=d||{};var c=document.createElement("div");c.className="litemenu-entry submenu";var q=!1;if(null===b)c.classList.add("separator");else{c.innerHTML=b&&b.title?b.title:a;if(c.value=b)b.disabled&&(q=!0,c.classList.add("disabled")),(b.submenu||b.has_submenu)&&c.classList.add("has_submenu");"function"==typeof b?(c.dataset.value=a,c.onclick_callback=b):c.dataset.value=b;b.className&&(c.className+=" "+
|
||||
b.className)}this.root.appendChild(c);q||c.addEventListener("click",e);d.autoopen&&c.addEventListener("mouseenter",g);return c};A.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&&!A.isCursorOverElement(a,this.parentMenu.root)&&A.trigger(this.parentMenu.root,"mouseleave",a));this.current_submenu&&this.current_submenu.close(a,!0);this.root.closing_timer&&
|
||||
clearTimeout(this.root.closing_timer)};A.trigger=function(a,b,d,g){var e=document.createEvent("CustomEvent");e.initCustomEvent(b,!0,!0,d);e.srcElement=g;a.dispatchEvent?a.dispatchEvent(e):a.__events&&a.__events.dispatchEvent(e);return e};A.prototype.getTopMenu=function(){return this.options.parentMenu?this.options.parentMenu.getTopMenu():this};A.prototype.getFirstEvent=function(){return this.options.parentMenu?this.options.parentMenu.getFirstEvent():this.options.event};A.isCursorOverElement=function(a,
|
||||
b){var d=a.clientX,g=a.clientY,e=b.getBoundingClientRect();return e?g>e.top&&g<e.top+e.height&&d>e.left&&d<e.left+e.width?!0:!1:!1};f.ContextMenu=A;f.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])}};f.extendClass=function(a,b){for(var d in b)a.hasOwnProperty(d)||(a[d]=b[d]);if(b.prototype)for(d in b.prototype)b.prototype.hasOwnProperty(d)&&
|
||||
!a.prototype.hasOwnProperty(d)&&(b.prototype.__lookupGetter__(d)?a.prototype.__defineGetter__(d,b.prototype.__lookupGetter__(d)):a.prototype[d]=b.prototype[d],b.prototype.__lookupSetter__(d)&&a.prototype.__defineSetter__(d,b.prototype.__lookupSetter__(d)))};E.sampleCurve=function(a,b){if(b){for(var d=0;d<b.length-1;++d){var g=b[d],e=b[d+1];if(!(e[0]<a)){d=e[0]-g[0];if(1E-5>Math.abs(d))return g[1];d=(a-g[0])/d;return g[1]*(1-d)+e[1]*d}}return 0}};E.prototype.draw=function(a,b,d,g,e,f){if(d=this.points){this.size=
|
||||
b;var c=b[0]-2*this.margin;b=b[1]-2*this.margin;e=e||"#666";a.save();a.translate(this.margin,this.margin);g&&(a.fillStyle="#111",a.fillRect(0,0,c,b),a.fillStyle="#222",a.fillRect(0.5*c,0,1,b),a.strokeStyle="#333",a.strokeRect(0,0,c,b));a.strokeStyle=e;f&&(a.globalAlpha=0.5);a.beginPath();for(g=0;g<d.length;++g)e=d[g],a.lineTo(e[0]*c,(1-e[1])*b);a.stroke();a.globalAlpha=1;if(!f)for(g=0;g<d.length;++g)e=d[g],a.fillStyle=this.selected==g?"#FFF":this.nearest==g?"#DDD":"#AAA",a.beginPath(),a.arc(e[0]*
|
||||
c,(1-e[1])*b,2,0,2*Math.PI),a.fill();a.restore()}};E.prototype.onMouseDown=function(a,b){var d=this.points;if(d&&!(0>a[1])){var g=this.size[0]-2*this.margin,e=this.size[1]-2*this.margin,f=a[0]-this.margin,c=a[1]-this.margin;this.selected=this.getCloserPoint([f,c],30/b.ds.scale);-1==this.selected&&(g=[f/g,1-c/e],d.push(g),d.sort(function(a,b){return a[0]-b[0]}),this.selected=d.indexOf(g),this.must_update=!0);if(-1!=this.selected)return!0}};E.prototype.onMouseMove=function(a,b){var d=this.points;if(d){var g=
|
||||
this.selected;if(!(0>g)){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);var c=d[g];if(c){var q=0==g||g==d.length-1;!q&&(-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):(c[0]=q?0==g?0:1:Math.clamp(e,0,1),c[1]=1-Math.clamp(f,0,1),d.sort(function(a,b){return a[0]-b[0]}),this.selected=d.indexOf(c),this.must_update=
|
||||
!0)}}}};E.prototype.onMouseUp=function(a,b){this.selected=-1;return!1};E.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,e=this.size[1]-2*this.margin,f=d.length,c=[0,0],q=1E6,l=-1,n=0;n<f;++n){var s=d[n];c[0]=s[0]*g;c[1]=(1-s[1])*e;s=vec2.distance(a,c);s>q||s>b||(l=n,q=s)}return l};f.CurveEditor=E;f.getParameterNames=function(a){return(a+"").replace(/[/][/].*$/gm,"").replace(/\s+/g,"").replace(/[/][*][^/*]*[*][/]/g,"").split("){",
|
||||
1)[0].replace(/^[^(]*[(]/,"").replace(/=[^,]+/g,"").split(",").filter(Boolean)};Math.clamp=function(a,b,d){return b>a?b:d<a?d:a};"undefined"==typeof window||window.requestAnimationFrame||(window.requestAnimationFrame=window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(a){window.setTimeout(a,1E3/60)})})(this);"undefined"!=typeof exports&&(exports.LiteGraph=this.LiteGraph);
|
||||
u.last_y+F||void 0===u.last_y)){g=u.value;switch(u.type){case "button":if("mousemove"===d.type)break;u.callback&&setTimeout(function(){u.callback(u,l,a,b,d)},20);this.dirty_canvas=u.clicked=!0;break;case "slider":n=Math.clamp((c-15)/(h-30),0,1);u.value=u.options.min+(u.options.max-u.options.min)*n;u.callback&&setTimeout(function(){e(u,u.value)},20);this.dirty_canvas=!0;break;case "number":case "combo":g=u.value;if("mousemove"==d.type&&"number"==u.type)u.value+=0.1*d.deltaX*(u.options.step||1),null!=
|
||||
u.options.min&&u.value<u.options.min&&(u.value=u.options.min),null!=u.options.max&&u.value>u.options.max&&(u.value=u.options.max);else if("mousedown"==d.type){var J=u.options.values;J&&J.constructor===Function&&(J=u.options.values(u,a));var H=null;"number"!=u.type&&(H=J.constructor===Array?J:Object.keys(J));c=40>c?-1:c>h-40?1:0;if("number"==u.type)u.value+=0.1*c*(u.options.step||1),null!=u.options.min&&u.value<u.options.min&&(u.value=u.options.min),null!=u.options.max&&u.value>u.options.max&&(u.value=
|
||||
u.options.max);else if(c)n=-1,this.last_mouseclick=0,n=J.constructor===Object?H.indexOf(String(u.value))+c:H.indexOf(u.value)+c,n>=H.length&&(n=H.length-1),0>n&&(n=0),u.value=J.constructor===Array?J[n]:n;else{var w=J!=H?Object.values(J):J;new f.ContextMenu(w,{scale:Math.max(1,this.ds.scale),event:d,className:"dark",callback:r.bind(u)},n);var r=function(a,b,d){J!=H&&(a=w.indexOf(a));this.value=a;e(this,a);l.dirty_canvas=!0;return!1}}}else"mouseup"==d.type&&"number"==u.type&&(c=40>c?-1:c>h-40?1:0,200>
|
||||
d.click_time&&0==c&&this.prompt("Value",u.value,function(a){this.value=Number(a);e(this,this.value)}.bind(u),d));g!=u.value&&setTimeout(function(){e(this,this.value)}.bind(u),20);this.dirty_canvas=!0;break;case "toggle":"mousedown"==d.type&&(u.value=!u.value,setTimeout(function(){e(u,u.value)},20));break;case "string":case "text":"mousedown"==d.type&&this.prompt("Value",u.value,function(a){this.value=a;e(this,a)}.bind(u),d,u.options?u.options.multiline:!1);break;default:u.mouse&&(this.dirty_canvas=
|
||||
u.mouse(d,[c,m],a))}if(g!=u.value){if(a.onWidgetChanged)a.onWidgetChanged(u.name,u.value,g,u);a.graph._version++}return u}}}return null};h.prototype.drawGroups=function(a,b){if(this.graph){var d=this.graph._groups;b.save();b.globalAlpha=0.5*this.editor_alpha;for(var g=0;g<d.length;++g){var e=d[g];if(G(this.visible_area,e._bounding)){b.fillStyle=e.color||"#335";b.strokeStyle=e.color||"#335";var c=e._pos,m=e._size;b.globalAlpha=0.25*this.editor_alpha;b.beginPath();b.rect(c[0]+0.5,c[1]+0.5,m[0],m[1]);
|
||||
b.fill();b.globalAlpha=this.editor_alpha;b.stroke();b.beginPath();b.moveTo(c[0]+m[0],c[1]+m[1]);b.lineTo(c[0]+m[0]-10,c[1]+m[1]);b.lineTo(c[0]+m[0],c[1]+m[1]-10);b.fill();m=e.font_size||f.DEFAULT_GROUP_FONT_SIZE;b.font=m+"px Arial";b.fillText(e.title,c[0]+4,c[1]+m)}}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){if(!a&&!b){var d=this.canvas.parentNode;a=d.offsetWidth;
|
||||
b=d.offsetHeight}if(this.canvas.width!=a||this.canvas.height!=b)this.canvas.width=a,this.canvas.height=b,this.bgcanvas.width=this.canvas.width,this.bgcanvas.height=this.canvas.height,this.setDirty(!0,!0)};h.prototype.switchLiveMode=function(a){if(a){var b=this,d=this.live_mode?1.1:0.9;this.live_mode&&(this.live_mode=!1,this.editor_alpha=0.1);var g=setInterval(function(){b.editor_alpha*=d;b.dirty_canvas=!0;b.dirty_bgcanvas=!0;1>d&&0.01>b.editor_alpha&&(clearInterval(g),1>d&&(b.live_mode=!0));1<d&&
|
||||
0.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.prototype.touchHandler=function(a){var b=a.changedTouches[0],d="";switch(a.type){case "touchstart":d="mousedown";break;case "touchmove":d="mousemove";break;case "touchend":d="mouseup";break;default:return}var g=this.getCanvasWindow(),e=g.document.createEvent("MouseEvent");e.initMouseEvent(d,!0,!0,g,1,b.screenX,
|
||||
b.screenY,b.clientX,b.clientY,!1,!1,!1,!1,0,null);b.target.dispatchEvent(e);a.preventDefault()};h.onGroupAdd=function(a,b,d){a=h.active_canvas;a.getCanvasWindow();b=new f.LGraphGroup;b.pos=a.convertEventToCanvasOffset(d);a.graph.add(b)};h.onMenuAdd=function(a,b,d,g,e){function c(a,b){var g=[];f.getNodeTypesCategories(m.filter||l.filter).filter(function(b){return b.startsWith(a)}).map(function(b){if(b){b=b.replace(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,e){c(a.value,e)}})}});f.getNodeTypesInCategory(a.slice(0,-1),m.filter||l.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();m.graph.beforeChange();if(a=f.createNode(a.value))a.pos=m.convertEventToCanvasOffset(b),m.graph.add(a);e&&e(a);m.graph.afterChange()}})});new f.ContextMenu(g,
|
||||
{event:d,parentMenu:b},q)}var m=h.active_canvas,q=m.getCanvasWindow(),l=m.graph;if(l)return c("",g),!1};h.onMenuCollapseAll=function(){};h.onMenuNodeEdit=function(){};h.showMenuNodeOptionalInputs=function(a,b,d,g,e){function c(a,b,d){e&&(a.callback&&a.callback.call(m,e,a,b,d),a.value&&(e.graph.beforeChange(),e.addInput(a.value[0],a.value[1],a.value[2]),e.setDirtyCanvas(!0,!0),e.graph.afterChange()))}if(e){var m=this;a=h.active_canvas.getCanvasWindow();b=e.optional_inputs;e.onGetInputs&&(b=e.onGetInputs());
|
||||
var q=[];if(b)for(var l=0;l<b.length;l++){var n=b[l];if(n){var s=n[0];n[2]&&n[2].label&&(s=n[2].label);s={content:s,value:n};n[1]==f.ACTION&&(s.className="event");q.push(s)}else q.push(null)}this.onMenuNodeInputs&&(q=this.onMenuNodeInputs(q));if(q.length)return new f.ContextMenu(q,{event:d,callback:c,parentMenu:g,node:e},a),!1;console.log("no input entries")}};h.showMenuNodeOptionalOutputs=function(a,b,d,g,e){function c(a,b,d){if(e&&(a.callback&&a.callback.call(m,e,a,b,d),a.value))if(d=a.value[1],
|
||||
!d||d.constructor!==Object&&d.constructor!==Array)e.graph.beforeChange(),e.addOutput(a.value[0],a.value[1],a.value[2]),e.setDirtyCanvas(!0,!0),e.graph.afterChange();else{a=[];for(var q in d)a.push({content:q,value:d[q]});new f.ContextMenu(a,{event:b,callback:c,parentMenu:g,node:e});return!1}}if(e){var m=this;a=h.active_canvas.getCanvasWindow();b=e.optional_outputs;e.onGetOutputs&&(b=e.onGetOutputs());var q=[];if(b)for(var l=0;l<b.length;l++){var n=b[l];if(!n)q.push(null);else if(!e.flags||!e.flags.skip_repeated_outputs||
|
||||
-1==e.findOutputSlot(n[0])){var s=n[0];n[2]&&n[2].label&&(s=n[2].label);s={content:s,value:n};n[1]==f.EVENT&&(s.className="event");q.push(s)}}this.onMenuNodeOutputs&&(q=this.onMenuNodeOutputs(q));if(q.length)return new f.ContextMenu(q,{event:d,callback:c,parentMenu:g,node:e},a),!1}};h.onShowMenuNodeProperties=function(a,b,d,g,e){function c(a,b,d,g){e&&(b=this.getBoundingClientRect(),m.showEditPropertyValue(e,a.value,{position:[b.left,b.top]}))}if(e&&e.properties){var m=h.active_canvas;b=m.getCanvasWindow();
|
||||
var q=[],l;for(l in e.properties){a=void 0!==e.properties[l]?e.properties[l]:" ";"object"==typeof a&&(a=JSON.stringify(a));var n=e.getPropertyInfo(l);if("enum"==n.type||"combo"==n.type)a=h.getPropertyPrintableValue(a,n.values);a=h.decodeHTML(a);q.push({content:"<span class='property_name'>"+(n.label?n.label:l)+"</span><span class='property_value'>"+a+"</span>",value:l})}if(q.length)return new f.ContextMenu(q,{event:d,callback:c,parentMenu:g,allow_html:!0,node:e},b),!1}};h.decodeHTML=function(a){var b=
|
||||
document.createElement("div");b.innerText=a;return b.innerHTML};h.onResizeNode=function(a,b,d,g,e){if(e){e.size=e.computeSize();if(e.onResize)e.onResize(e.size);e.setDirtyCanvas(!0,!0)}};h.prototype.showLinkMenu=function(a,b){var d=this;console.log(a);var g=new f.ContextMenu(["Add Node",null,"Delete"],{event:b,title:null!=a.data?a.data.constructor.name:null,callback:function(b,f,c){switch(b){case "Add Node":h.onMenuAdd(null,null,c,g,function(b){console.log("node autoconnect");var e=d.graph.getNodeById(a.origin_id),
|
||||
g=d.graph.getNodeById(a.target_id);b.inputs&&b.inputs.length&&b.outputs&&b.outputs.length&&e.outputs[a.origin_slot].type==b.inputs[0].type&&b.outputs[0].type==g.inputs[0].type&&(e.connect(a.origin_slot,b,0),b.connect(0,g,a.target_slot),b.pos[0]-=0.5*b.size[0])});break;case "Delete":d.graph.removeLink(a.id)}}});return!1};h.onShowPropertyEditor=function(a,b,d,g,e){function f(){var b=l.value;"Number"==a.type?b=Number(b):"Boolean"==a.type&&(b=Boolean(b));e[c]=b;q.parentNode&&q.parentNode.removeChild(q);
|
||||
e.setDirtyCanvas(!0,!0)}var c=a.property||"title";b=e[c];var q=document.createElement("div");q.className="graphdialog";q.innerHTML="<span class='name'></span><input autofocus type='text' class='value'/><button>OK</button>";q.querySelector(".name").innerText=c;var l=q.querySelector(".value");l&&(l.value=b,l.addEventListener("blur",function(a){this.focus()}),l.addEventListener("keydown",function(a){if(13==a.keyCode||"textarea"==a.target.localName)f(),a.preventDefault(),a.stopPropagation()}));b=h.active_canvas.canvas;
|
||||
d=b.getBoundingClientRect();var n=g=-20;d&&(g-=d.left,n-=d.top);event?(q.style.left=event.clientX+g+"px",q.style.top=event.clientY+n+"px"):(q.style.left=0.5*b.width+g+"px",q.style.top=0.5*b.height+n+"px");q.querySelector("button").addEventListener("click",f);b.parentNode.appendChild(q)};h.prototype.prompt=function(a,b,d,g,e){var f=this;a=a||"";var c=!1,q=document.createElement("div");q.className="graphdialog rounded";q.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>";q.close=function(){f.prompt_box=null;q.parentNode&&q.parentNode.removeChild(q)};1<this.ds.scale&&(q.style.transform="scale("+this.ds.scale+")");q.addEventListener("mouseleave",function(a){c||q.close()});f.prompt_box&&f.prompt_box.close();f.prompt_box=q;q.querySelector(".name").innerText=a;var l=q.querySelector(".value");l.value=b;l.addEventListener("keydown",function(a){c=!0;if(27==a.keyCode)q.close();
|
||||
else if(13==a.keyCode&&"textarea"!=a.target.localName)d&&d(this.value),q.close();else return;a.preventDefault();a.stopPropagation()});q.querySelector("button").addEventListener("click",function(a){d&&d(l.value);f.setDirty(!0);q.close()});a=h.active_canvas.canvas;b=a.getBoundingClientRect();var n=e=-20;b&&(e-=b.left,n-=b.top);g?(q.style.left=g.clientX+e+"px",q.style.top=g.clientY+n+"px"):(q.style.left=0.5*a.width+e+"px",q.style.top=0.5*a.height+n+"px");a.parentNode.appendChild(q);setTimeout(function(){l.focus()},
|
||||
10);return q};h.search_limit=-1;h.prototype.showSearchBox=function(a){function b(b){if(b)if(e.onSearchBoxSelection)e.onSearchBoxSelection(b,a,c);else{var d=f.searchbox_extras[b.toLowerCase()];d&&(b=d.type);c.graph.beforeChange();if(b=f.createNode(b))b.pos=c.convertEventToCanvasOffset(a),c.graph.add(b);if(d&&d.data){if(d.data.properties)for(var g in d.data.properties)b.addProperty(g,d.data.properties[g]);if(d.data.inputs)for(g in b.inputs=[],d.data.inputs)b.addOutput(d.data.inputs[g][0],d.data.inputs[g][1]);
|
||||
if(d.data.outputs)for(g in b.outputs=[],d.data.outputs)b.addOutput(d.data.outputs[g][0],d.data.outputs[g][1]);d.data.title&&(b.title=d.data.title);d.data.json&&b.configure(d.data.json);c.graph.afterChange()}}l.close()}function d(a){var b=r;r&&r.classList.remove("selected");r?(r=a?r.nextSibling:r.previousSibling)||(r=b):r=a?s.childNodes[0]:s.childNodes[s.childNodes.length];r&&(r.classList.add("selected"),r.scrollIntoView({block:"end",behavior:"smooth"}))}function g(){function a(d,e){var g=document.createElement("div");
|
||||
w||(w=d);g.innerText=d;g.dataset.type=escape(d);g.className="litegraph lite-search-item";e&&(g.className+=" "+e);g.addEventListener("click",function(a){b(unescape(this.dataset.type))});s.appendChild(g)}F=null;var d=J.value;w=null;s.innerHTML="";if(d)if(e.onSearchBox){var g=e.onSearchBox(s,d,c);if(g)for(var m=0;m<g.length;++m)a(g[m])}else{var g=0,d=d.toLowerCase(),q=c.filter||c.graph.filter;for(m in f.searchbox_extras){var l=f.searchbox_extras[m];if(-1!==l.desc.toLowerCase().indexOf(d)){var n=f.registered_node_types[l.type];
|
||||
if(!n||n.filter==q)if(a(l.desc,"searchbox_extra"),-1!==h.search_limit&&g++>h.search_limit)break}}l=null;if(Array.prototype.filter)l=Object.keys(f.registered_node_types).filter(H);else for(m in l=[],f.registered_node_types)H(m)&&l.push(m);for(m=0;m<l.length&&!(a(l[m]),-1!==h.search_limit&&g++>h.search_limit);m++);var H=function(a){var b=f.registered_node_types[a];return q&&b.filter!=q?!1:-1!==a.toLowerCase().indexOf(d)}}}var e=this,c=h.active_canvas,m=c.canvas,q=m.ownerDocument||document,l=document.createElement("div");
|
||||
l.className="litegraph litesearchbox graphdialog rounded";l.innerHTML="<span class='name'>Search</span> <input autofocus type='text' class='value rounded'/><div class='helper'></div>";l.close=function(){e.search_box=null;q.body.focus();q.body.style.overflow="";setTimeout(function(){e.canvas.focus()},20);l.parentNode&&l.parentNode.removeChild(l)};var n=null;1<this.ds.scale&&(l.style.transform="scale("+this.ds.scale+")");l.addEventListener("mouseenter",function(a){n&&(clearTimeout(n),n=null)});l.addEventListener("mouseleave",
|
||||
function(a){n=setTimeout(function(){l.close()},500)});e.search_box&&e.search_box.close();e.search_box=l;var s=l.querySelector(".helper"),w=null,F=null,r=null,J=l.querySelector("input");J&&(J.addEventListener("blur",function(a){this.focus()}),J.addEventListener("keydown",function(a){if(38==a.keyCode)d(!1);else if(40==a.keyCode)d(!0);else if(27==a.keyCode)l.close();else if(13==a.keyCode)r?b(r.innerHTML):w?b(w):l.close();else{F&&clearInterval(F);F=setTimeout(g,10);return}a.preventDefault();a.stopPropagation();
|
||||
a.stopImmediatePropagation();return!0}));q.fullscreenElement?q.fullscreenElement.appendChild(l):(q.body.appendChild(l),q.body.style.overflow="hidden");var m=m.getBoundingClientRect(),H=(a?a.clientY:m.top+0.5*m.height)-20;l.style.left=(a?a.clientX:m.left+0.5*m.width)-80+"px";l.style.top=H+"px";a.layerY>m.height-200&&(s.style.maxHeight=m.height-a.layerY-20+"px");J.focus();return l};h.prototype.showEditPropertyValue=function(a,b,d){function g(){e(h.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"==c||"object"==c)e=JSON.parse(e);a.properties[b]=e;a.graph&&a.graph._version++;if(a.onPropertyChanged)a.onPropertyChanged(b,e);if(d.onclose)d.onclose();s.close();a.setDirtyCanvas(!0,!0)}if(a&&void 0!==a.properties[b]){d=d||{};var f=a.getPropertyInfo(b),c=f.type,q="";if("string"==c||"number"==c||"array"==c||"object"==c)q="<input autofocus type='text' class='value'/>";else if("enum"!=c&&"combo"!=c||
|
||||
!f.values)if("boolean"==c)q="<input autofocus type='checkbox' class='value' "+(a.properties[b]?"checked":"")+"/>";else{console.warn("unknown type: "+c);return}else{var q="<select autofocus type='text' class='value'>",l;for(l in f.values){var n=l;f.values.constructor===Array&&(n=f.values[l]);q+="<option value='"+n+"' "+(n==a.properties[b]?"selected":"")+">"+f.values[l]+"</option>"}q+="</select>"}var s=this.createDialog("<span class='name'>"+(f.label?f.label:b)+"</span>"+q+"<button>OK</button>",d);
|
||||
if("enum"!=c&&"combo"!=c||!f.values)if("boolean"==c)(h=s.querySelector("input"))&&h.addEventListener("click",function(a){e(!!h.checked)});else{if(h=s.querySelector("input"))h.addEventListener("blur",function(a){this.focus()}),n=void 0!==a.properties[b]?a.properties[b]:"","string"!==c&&(n=JSON.stringify(n)),h.value=n,h.addEventListener("keydown",function(a){13==a.keyCode&&(g(),a.preventDefault(),a.stopPropagation())})}else{var h=s.querySelector("select");h.addEventListener("change",function(a){e(a.target.value)})}s.querySelector("button").addEventListener("click",
|
||||
g);return s}};h.prototype.createDialog=function(a,b){b=b||{};var d=document.createElement("div");d.className="graphdialog";d.innerHTML=a;var g=this.canvas.getBoundingClientRect(),e=-20,f=-20;g&&(e-=g.left,f-=g.top);b.position?(e+=b.position[0],f+=b.position[1]):b.event?(e+=b.event.clientX,f+=b.event.clientY):(e+=0.5*this.canvas.width,f+=0.5*this.canvas.height);d.style.left=e+"px";d.style.top=f+"px";this.canvas.parentNode.appendChild(d);d.close=function(){this.parentNode&&this.parentNode.removeChild(this)};
|
||||
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 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":""));if(b.closable){var e=
|
||||
document.createElement("span");e.innerHTML="✕";e.classList.add("close");e.addEventListener("click",function(){g.close()});g.header.appendChild(e)}g.title_element=g.querySelector(".dialog-title");g.title_element.innerText=a;g.content=g.querySelector(".dialog-content");g.footer=g.querySelector(".dialog-footer");g.close=function(){this.parentNode&&this.parentNode.removeChild(this)};g.clear=function(){this.content.innerHTML=""};g.addHTML=function(a,b,d){var e=document.createElement("div");b&&(e.className=
|
||||
b);e.innerHTML=a;d?g.footer.appendChild(e):g.content.appendChild(e);return e};g.addButton=function(a,b,d){var e=document.createElement("button");e.innerText=a;e.options=d;e.classList.add("btn");e.addEventListener("click",b);g.footer.appendChild(e);return e};g.addSeparator=function(){var a=document.createElement("div");a.className="separator";g.content.appendChild(a)};g.addWidget=function(a,b,e,c,l){function n(a,b){console.log("change",a,b);c.callback&&c.callback(a,b);l&&l(a,b)}c=c||{};var s=String(e);
|
||||
a=a.toLowerCase();"number"==a&&(s=e.toFixed(3));var F=document.createElement("div");F.className="property";F.innerHTML="<span class='property_name'></span><span class='property_value'></span>";F.querySelector(".property_name").innerText=b;var w=F.querySelector(".property_value");w.innerText=s;F.dataset.property=b;F.dataset.type=c.type||a;F.options=c;F.value=e;if("boolean"==a)F.classList.add("boolean"),e&&F.classList.add("bool-on"),F.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";n(a,this.value)});else if("string"==a||"number"==a)w.setAttribute("contenteditable",!0),w.addEventListener("keydown",function(a){"Enter"==a.code&&(a.preventDefault(),this.blur())}),w.addEventListener("blur",function(){var a=this.innerText,b=this.parentNode.dataset.property;"number"==this.parentNode.dataset.type&&(a=Number(a));n(b,a)});else if("enum"==a||"combo"==a)s=h.getPropertyPrintableValue(e,
|
||||
c.values);w.innerText=s;w.addEventListener("click",function(a){var b=this.parentNode.dataset.property,e=this;new f.ContextMenu(c.values||[],{event:a,className:"dark",callback:function(a,d,g){e.innerText=a;n(b,a);return!1}},d)});g.content.appendChild(F);return F};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.showShowNodePanel=function(a){window.SELECTED_NODE=
|
||||
a;var b=document.querySelector("#node-panel");b&&b.close();var d=this.getCanvasWindow(),b=this.createPanel(a.title||"",{closable:!0,window:d});b.id="node-panel";b.node=a;b.classList.add("settings");var g=this;(function(){b.content.innerHTML="";b.addHTML("<span class='node_type'>"+a.type+"</span><span class='node_desc'>"+(a.constructor.desc||"")+"</span><span class='separator'></span>");b.addHTML("<h3>Properties</h3>");for(var d in a.properties){var f=a.properties[d],c=a.getPropertyInfo(d);a.onAddPropertyToPanel&&
|
||||
a.onAddPropertyToPanel(d,b)||b.addWidget(c.widget||c.type,d,f,c,function(b,d){g.graph.beforeChange(a);a.setProperty(b,d);g.graph.afterChange();g.dirty_canvas=!0})}b.addSeparator();if(a.onShowCustomPanelInfo)a.onShowCustomPanelInfo(b);b.addButton("Delete",function(){a.block_delete||(a.graph.remove(a),b.close())}).classList.add("delete")})();this.canvas.parentNode.appendChild(b)};h.prototype.showSubgraphPropertiesDialog=function(a){function b(){g.clear();if(a.inputs)for(var d=0;d<a.inputs.length;++d){var f=
|
||||
a.inputs[d];if(!f.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=f.name;c.dataset.slot=d;c.querySelector(".name").innerText=f.name;c.querySelector(".type").innerText=f.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 g=d.querySelector(".name").value,f=d.querySelector(".type").value;g&&-1==a.findInputSlot(g)&&(a.addInput(g,f),d.querySelector(".name").value=
|
||||
"",d.querySelector(".type").value="",b())});b();this.canvas.parentNode.appendChild(g);return g};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,e){e.graph.beforeChange(e);e.collapse();e.graph.afterChange(e)};h.onMenuNodePin=function(a,b,d,g,e){e.pin()};h.onMenuNodeMode=function(a,b,d,g,e){new f.ContextMenu(["Always",
|
||||
"On Event","On Trigger","Never"],{event:d,callback:function(a){if(e)switch(a){case "On Event":e.mode=f.ON_EVENT;break;case "On Trigger":e.mode=f.ON_TRIGGER;break;case "Never":e.mode=f.NEVER;break;default:e.mode=f.ALWAYS}},parentMenu:g,node:e});return!1};h.onMenuNodeColors=function(a,b,d,g,e){if(!e)throw"no node for color";b=[];b.push({value:null,content:"<span style='display: block; padding-left: 4px;'>No color</span>"});for(var 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 f.ContextMenu(b,{event:d,callback:function(a){e&&((a=a.value?h.node_colors[a.value]:null)?e.constructor===f.LGraphGroup?e.color=a.groupcolor:(e.color=a.color,e.bgcolor=a.bgcolor):(delete e.color,delete e.bgcolor),e.setDirtyCanvas(!0,!0))},parentMenu:g,node:e});return!1};h.onMenuNodeShapes=function(a,b,d,g,e){if(!e)throw"no node passed";new f.ContextMenu(f.VALID_SHAPES,{event:d,callback:function(a){e&&(e.graph.beforeChange(e),
|
||||
e.shape=a,e.graph.afterChange(e),e.setDirtyCanvas(!0))},parentMenu:g,node:e});return!1};h.onMenuNodeRemove=function(a,b,d,g,e){if(!e)throw"no node passed";!1!==e.removable&&(a=e.graph,a.beforeChange(),a.remove(e),a.afterChange(),e.setDirtyCanvas(!0,!0))};h.onMenuNodeToSubgraph=function(a,b,d,g,e){a=e.graph;if(b=h.active_canvas)d=Object.values(b.selected_nodes||{}),d.length||(d=[e]),g=f.createNode("graph/subgraph"),g.pos=e.pos.concat(),a.add(g),g.buildFromNodes(d),b.deselectAllNodes(),e.setDirtyCanvas(!0,
|
||||
!0)};h.onMenuNodeClone=function(a,b,d,g,e){!1!=e.clonable&&(a=e.clone())&&(a.pos=[e.pos[0]+5,e.pos[1]+5],e.graph.beforeChange(),e.graph.add(a),e.graph.afterChange(),e.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(){var a=null;this.getMenuOptions?a=this.getMenuOptions():(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){var b=null,b=a.getMenuOptions?a.getMenuOptions(this):[{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},{content:"Resize",callback:function(){if(a.resizable)return h.onResizeNode}},{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(),e=null,c={event:b,callback:function(b,e,g){if(b)if("Remove Slot"==b.content)b=b.slot,b.input?a.removeInput(b.slot):b.output&&a.removeOutput(b.slot);else if("Disconnect Links"==b.content)b=b.slot,b.output?a.disconnectOutput(b.slot):b.input&&a.disconnectInput(b.slot);else if("Rename Slot"==
|
||||
b.content){b=b.slot;var f=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>",e),q=c.querySelector("input");q&&f&&(q.value=f.label||"");c.querySelector("button").addEventListener("click",function(a){q.value&&(f&&(f.label=q.value),d.setDirty(!0));c.close()})}},extra:a};a&&(c.title=a.type);var m=null;a&&(m=a.getSlotInPosition(b.canvasX,b.canvasY),h.active_node=a);if(m){e=[];if(a.getSlotMenuOptions)e=
|
||||
a.getSlotMenuOptions(m);else{m&&m.output&&m.output.links&&m.output.links.length&&e.push({content:"Disconnect Links",slot:m});var q=m.input||m.output;e.push(q.locked?"Cannot remove":{content:"Remove Slot",slot:m});e.push(q.nameLocked?"Cannot rename":{content:"Rename Slot",slot:m})}c.title=(m.input?m.input.type:m.output.type)||"*";m.input&&m.input.type==f.ACTION&&(c.title="Action");m.output&&m.output.type==f.EVENT&&(c.title="Event")}else a?e=this.getNodeMenuOptions(a):(e=this.getCanvasMenuOptions(),
|
||||
(m=this.graph.getGroupOnPos(b.canvasX,b.canvasY))&&e.push(null,{content:"Edit Group",has_submenu:!0,submenu:{title:"Group",extra:m,options:this.getGroupMenuOptions(m)}}));e&&new f.ContextMenu(e,c,g)};"undefined"!=typeof window&&window.CanvasRenderingContext2D&&(window.CanvasRenderingContext2D.prototype.roundRect=function(a,b,d,g,e,f){void 0===e&&(e=5);void 0===f&&(f=e);this.moveTo(a+e,b);this.lineTo(a+d-e,b);this.quadraticCurveTo(a+d,b,a+d,b+e);this.lineTo(a+d,b+g-f);this.quadraticCurveTo(a+d,b+g,
|
||||
a+d-f,b+g);this.lineTo(a+f,b+g);this.quadraticCurveTo(a,b+g,a,b+g-f);this.lineTo(a,b+e);this.quadraticCurveTo(a,b,a+e,b)});f.compareObjects=function(a,b){for(var d in a)if(a[d]!=b[d])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=z;f.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)};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=G;f.hex2num=function(a){"#"==a.charAt(0)&&(a=a.slice(1));a=a.toUpperCase();for(var b=Array(3),d=0,g,e,f=0;6>f;f+=2)g="0123456789ABCDEF".indexOf(a.charAt(f)),e="0123456789ABCDEF".indexOf(a.charAt(f+1)),b[d]=16*g+e,d++;return b};f.num2hex=function(a){for(var b="#",d,g,e=0;3>e;e++)d=a[e]/16,g=a[e]%16,b+="0123456789ABCDEF".charAt(d)+"0123456789ABCDEF".charAt(g);return b};
|
||||
A.prototype.addItem=function(a,b,d){function g(a){var b=this.value;b&&b.has_submenu&&e.call(this,a)}function e(a){var b=this.value,e=!0;f.current_submenu&&f.current_submenu.close(a);if(d.callback){var g=d.callback.call(this,b,d,a,f,d.node);!0===g&&(e=!1)}if(b&&(b.callback&&!d.ignore_item_callbacks&&!0!==b.disabled&&(g=b.callback.call(this,b,d,a,f,d.extra),!0===g&&(e=!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:d.autoopen});e=!1}e&&!f.lock&&f.close()}var f=this;d=d||{};var c=document.createElement("div");c.className="litemenu-entry submenu";var q=!1;if(null===b)c.classList.add("separator");else{c.innerHTML=b&&b.title?b.title:a;if(c.value=b)b.disabled&&(q=!0,c.classList.add("disabled")),(b.submenu||b.has_submenu)&&c.classList.add("has_submenu");"function"==typeof b?(c.dataset.value=
|
||||
a,c.onclick_callback=b):c.dataset.value=b;b.className&&(c.className+=" "+b.className)}this.root.appendChild(c);q||c.addEventListener("click",e);d.autoopen&&c.addEventListener("mouseenter",g);return c};A.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&&!A.isCursorOverElement(a,this.parentMenu.root)&&A.trigger(this.parentMenu.root,"mouseleave",
|
||||
a));this.current_submenu&&this.current_submenu.close(a,!0);this.root.closing_timer&&clearTimeout(this.root.closing_timer)};A.trigger=function(a,b,d,g){var e=document.createEvent("CustomEvent");e.initCustomEvent(b,!0,!0,d);e.srcElement=g;a.dispatchEvent?a.dispatchEvent(e):a.__events&&a.__events.dispatchEvent(e);return e};A.prototype.getTopMenu=function(){return this.options.parentMenu?this.options.parentMenu.getTopMenu():this};A.prototype.getFirstEvent=function(){return this.options.parentMenu?this.options.parentMenu.getFirstEvent():
|
||||
this.options.event};A.isCursorOverElement=function(a,b){var d=a.clientX,g=a.clientY,e=b.getBoundingClientRect();return e?g>e.top&&g<e.top+e.height&&d>e.left&&d<e.left+e.width?!0:!1:!1};f.ContextMenu=A;f.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])}};f.extendClass=function(a,b){for(var d in b)a.hasOwnProperty(d)||
|
||||
(a[d]=b[d]);if(b.prototype)for(d in b.prototype)b.prototype.hasOwnProperty(d)&&!a.prototype.hasOwnProperty(d)&&(b.prototype.__lookupGetter__(d)?a.prototype.__defineGetter__(d,b.prototype.__lookupGetter__(d)):a.prototype[d]=b.prototype[d],b.prototype.__lookupSetter__(d)&&a.prototype.__defineSetter__(d,b.prototype.__lookupSetter__(d)))};E.sampleCurve=function(a,b){if(b){for(var d=0;d<b.length-1;++d){var g=b[d],e=b[d+1];if(!(e[0]<a)){d=e[0]-g[0];if(1E-5>Math.abs(d))return g[1];d=(a-g[0])/d;return g[1]*
|
||||
(1-d)+e[1]*d}}return 0}};E.prototype.draw=function(a,b,d,g,e,f){if(d=this.points){this.size=b;var c=b[0]-2*this.margin;b=b[1]-2*this.margin;e=e||"#666";a.save();a.translate(this.margin,this.margin);g&&(a.fillStyle="#111",a.fillRect(0,0,c,b),a.fillStyle="#222",a.fillRect(0.5*c,0,1,b),a.strokeStyle="#333",a.strokeRect(0,0,c,b));a.strokeStyle=e;f&&(a.globalAlpha=0.5);a.beginPath();for(g=0;g<d.length;++g)e=d[g],a.lineTo(e[0]*c,(1-e[1])*b);a.stroke();a.globalAlpha=1;if(!f)for(g=0;g<d.length;++g)e=d[g],
|
||||
a.fillStyle=this.selected==g?"#FFF":this.nearest==g?"#DDD":"#AAA",a.beginPath(),a.arc(e[0]*c,(1-e[1])*b,2,0,2*Math.PI),a.fill();a.restore()}};E.prototype.onMouseDown=function(a,b){var d=this.points;if(d&&!(0>a[1])){var g=this.size[0]-2*this.margin,e=this.size[1]-2*this.margin,f=a[0]-this.margin,c=a[1]-this.margin;this.selected=this.getCloserPoint([f,c],30/b.ds.scale);-1==this.selected&&(g=[f/g,1-c/e],d.push(g),d.sort(function(a,b){return a[0]-b[0]}),this.selected=d.indexOf(g),this.must_update=!0);
|
||||
if(-1!=this.selected)return!0}};E.prototype.onMouseMove=function(a,b){var d=this.points;if(d){var g=this.selected;if(!(0>g)){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);var c=d[g];if(c){var q=0==g||g==d.length-1;!q&&(-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):(c[0]=q?0==g?0:1:Math.clamp(e,0,1),c[1]=1-
|
||||
Math.clamp(f,0,1),d.sort(function(a,b){return a[0]-b[0]}),this.selected=d.indexOf(c),this.must_update=!0)}}}};E.prototype.onMouseUp=function(a,b){this.selected=-1;return!1};E.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,e=this.size[1]-2*this.margin,f=d.length,c=[0,0],q=1E6,l=-1,n=0;n<f;++n){var s=d[n];c[0]=s[0]*g;c[1]=(1-s[1])*e;s=vec2.distance(a,c);s>q||s>b||(l=n,q=s)}return l};f.CurveEditor=E;f.getParameterNames=function(a){return(a+
|
||||
"").replace(/[/][/].*$/gm,"").replace(/\s+/g,"").replace(/[/][*][^/*]*[*][/]/g,"").split("){",1)[0].replace(/^[^(]*[(]/,"").replace(/=[^,]+/g,"").split(",").filter(Boolean)};Math.clamp=function(a,b,d){return b>a?b:d<a?d:a};"undefined"==typeof window||window.requestAnimationFrame||(window.requestAnimationFrame=window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(a){window.setTimeout(a,1E3/60)})})(this);"undefined"!=typeof exports&&(exports.LiteGraph=this.LiteGraph);
|
||||
(function(B){function c(){this.addOutput("in ms","number");this.addOutput("in sec","number")}function k(){this.size=[140,80];this.properties={enabled:!0};this.enabled=!0;this.subgraph=new m.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 v(){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 r(){this.addInput("","");this.name_in_graph="";this.properties={};var a=this;Object.defineProperty(this.properties,"name",{get:function(){return a.name_in_graph},set:function(b){""!=
|
||||
@@ -361,16 +361,16 @@ break;case 13:k.buttons[t].pressed&&(r.hat+="down",r.hatmap|=c.DOWN);break;case
|
||||
c.strokeRect(0.5*(t[0]+1)*this.size[0]-4,0.5*(t[1]+1)*this.size[1]-4,8,8);k=this.size[1]/this._current_buttons.length;c.fillStyle="#AEB";for(t=0;t<this._current_buttons.length;++t)this._current_buttons[t]&&c.fillRect(0,k*t,6,k)}};c.prototype.onGetOutputs=function(){return[["left_axis","vec2"],["right_axis","vec2"],["left_x_axis","number"],["left_y_axis","number"],["right_x_axis","number"],["right_y_axis","number"],["trigger_left","number"],["trigger_right","number"],["a_button","number"],["b_button",
|
||||
"number"],["x_button","number"],["y_button","number"],["lb_button","number"],["rb_button","number"],["ls_button","number"],["rs_button","number"],["start_button","number"],["back_button","number"],["a_button_event",k.EVENT],["b_button_event",k.EVENT],["x_button_event",k.EVENT],["y_button_event",k.EVENT],["lb_button_event",k.EVENT],["rb_button_event",k.EVENT],["ls_button_event",k.EVENT],["rs_button_event",k.EVENT],["start_button_event",k.EVENT],["back_button_event",k.EVENT],["hat_left","number"],["hat_right",
|
||||
"number"],["hat_up","number"],["hat_down","number"],["hat","number"],["button_pressed",k.EVENT]]};k.registerNodeType("input/gamepad",c)})(this);
|
||||
(function(B){function c(){this.addInput("in","*");this.size=[80,30]}function k(){this.addInput("in");this.addOutput("out");this.size=[80,30]}function v(){this.addInput("in");this.addOutput("out")}function r(){this.addInput("in","number",{locked:!0});this.addOutput("out","number",{locked:!0});this.addOutput("clamped","number",{locked:!0});this.addProperty("in",0);this.addProperty("in_min",0);this.addProperty("in_max",1);this.addProperty("out_min",0);this.addProperty("out_max",1);this.size=[120,50]}
|
||||
function t(){this.addOutput("value","number");this.addProperty("min",0);this.addProperty("max",1);this.size=[80,30]}function h(){this.addInput("in","number");this.addOutput("out","number");this.addProperty("min",0);this.addProperty("max",1);this.addProperty("smooth",!0);this.addProperty("seed",0);this.addProperty("octaves",1);this.addProperty("persistence",0.8);this.addProperty("speed",1);this.size=[90,30]}function D(){this.addOutput("out","number");this.addProperty("min_time",1);this.addProperty("max_time",
|
||||
2);this.addProperty("duration",0.2);this.size=[90,30];this._blink_time=this._remaining_time=0}function z(){this.addInput("in","number");this.addOutput("out","number");this.size=[80,30];this.addProperty("min",0);this.addProperty("max",1)}function G(){this.properties={f:0.5};this.addInput("A","number");this.addInput("B","number");this.addOutput("out","number")}function A(){this.addInput("in","number");this.addOutput("out","number");this.size=[80,30]}function E(){this.addInput("in","number");this.addOutput("out",
|
||||
"number");this.size=[80,30]}function f(){this.addInput("in","number");this.addOutput("out","number");this.size=[80,30]}function n(){this.addInput("in","number");this.addOutput("out","number");this.size=[80,30];this.properties={A:0,B:1}}function I(){this.addInput("in","number",{label:""});this.addOutput("out","number",{label:""});this.size=[80,30];this.addProperty("factor",1)}function x(){this.addInput("v","boolean");this.addInput("A");this.addInput("B");this.addOutput("out")}function L(){this.addInput("in",
|
||||
"number");this.addOutput("out","number");this.size=[80,30];this.addProperty("samples",10);this._values=new Float32Array(10);this._current=0}function s(){this.addInput("in","number");this.addOutput("out","number");this.addProperty("factor",0.1);this.size=[80,30];this._value=null}function w(){this.addInput("A","number,array,object");this.addInput("B","number");this.addOutput("=","number");this.addProperty("A",1);this.addProperty("B",1);this.addProperty("OP","+","enum",{values:w.values});this._func=
|
||||
function(a,b){return a+b};this._result=[]}function l(){this.addInput("A","number");this.addInput("B","number");this.addOutput("A==B","boolean");this.addOutput("A!=B","boolean");this.addProperty("A",0);this.addProperty("B",0)}function a(){this.addInput("A","number");this.addInput("B","number");this.addOutput("true","boolean");this.addOutput("false","boolean");this.addProperty("A",1);this.addProperty("B",1);this.addProperty("OP",">","enum",{values:a.values});this.addWidget("combo","Cond.",this.properties.OP,
|
||||
{property:"OP",values:a.values});this.size=[80,60]}function b(){this.addInput("in","");this.addInput("cond","boolean");this.addOutput("true","");this.addOutput("false","");this.size=[80,60]}function d(){this.addInput("inc","number");this.addOutput("total","number");this.addProperty("increment",1);this.addProperty("value",0)}function g(){this.addInput("v","number");this.addOutput("sin","number");this.addProperty("amplitude",1);this.addProperty("offset",0);this.bgImageUrl="nodes/imgs/icon-sin.png"}
|
||||
function e(){this.addInput("x","number");this.addInput("y","number");this.addOutput("","number");this.properties={x:1,y:1,formula:"x+y"};this.code_widget=this.addWidget("text","F(x,y)",this.properties.formula,function(a,b,d){d.properties.formula=a});this.addWidget("toggle","allow",u.allow_scripts,function(a){u.allow_scripts=a});this._func=null}function y(){this.addInput("vec2","vec2");this.addOutput("x","number");this.addOutput("y","number")}function m(){this.addInputs([["x","number"],["y","number"]]);
|
||||
this.addOutput("vec2","vec2");this.properties={x:0,y:0};this._data=new Float32Array(2)}function q(){this.addInput("vec3","vec3");this.addOutput("x","number");this.addOutput("y","number");this.addOutput("z","number")}function C(){this.addInputs([["x","number"],["y","number"],["z","number"]]);this.addOutput("vec3","vec3");this.properties={x:0,y:0,z:0};this._data=new Float32Array(3)}function N(){this.addInput("vec4","vec4");this.addOutput("x","number");this.addOutput("y","number");this.addOutput("z",
|
||||
"number");this.addOutput("w","number")}function M(){this.addInputs([["x","number"],["y","number"],["z","number"],["w","number"]]);this.addOutput("vec4","vec4");this.properties={x:0,y:0,z:0,w:0};this._data=new Float32Array(4)}var u=B.LiteGraph;c.title="Converter";c.desc="type A to type B";c.prototype.onExecute=function(){var a=this.getInputData(0);if(null!=a&&this.outputs)for(var b=0;b<this.outputs.length;b++){var d=this.outputs[b];if(d.links&&d.links.length){var e=null;switch(d.name){case "number":e=
|
||||
(function(B){function c(){this.addInput("in","*");this.addOutput("out");this.size=[80,30]}function k(){this.addInput("in");this.addOutput("out");this.size=[80,30]}function v(){this.addInput("in");this.addOutput("out")}function r(){this.addInput("in","number",{locked:!0});this.addOutput("out","number",{locked:!0});this.addOutput("clamped","number",{locked:!0});this.addProperty("in",0);this.addProperty("in_min",0);this.addProperty("in_max",1);this.addProperty("out_min",0);this.addProperty("out_max",
|
||||
1);this.size=[120,50]}function t(){this.addOutput("value","number");this.addProperty("min",0);this.addProperty("max",1);this.size=[80,30]}function h(){this.addInput("in","number");this.addOutput("out","number");this.addProperty("min",0);this.addProperty("max",1);this.addProperty("smooth",!0);this.addProperty("seed",0);this.addProperty("octaves",1);this.addProperty("persistence",0.8);this.addProperty("speed",1);this.size=[90,30]}function D(){this.addOutput("out","number");this.addProperty("min_time",
|
||||
1);this.addProperty("max_time",2);this.addProperty("duration",0.2);this.size=[90,30];this._blink_time=this._remaining_time=0}function z(){this.addInput("in","number");this.addOutput("out","number");this.size=[80,30];this.addProperty("min",0);this.addProperty("max",1)}function G(){this.properties={f:0.5};this.addInput("A","number");this.addInput("B","number");this.addOutput("out","number")}function A(){this.addInput("in","number");this.addOutput("out","number");this.size=[80,30]}function E(){this.addInput("in",
|
||||
"number");this.addOutput("out","number");this.size=[80,30]}function f(){this.addInput("in","number");this.addOutput("out","number");this.size=[80,30]}function n(){this.addInput("in","number");this.addOutput("out","number");this.size=[80,30];this.properties={A:0,B:1}}function I(){this.addInput("in","number",{label:""});this.addOutput("out","number",{label:""});this.size=[80,30];this.addProperty("factor",1)}function x(){this.addInput("v","boolean");this.addInput("A");this.addInput("B");this.addOutput("out")}
|
||||
function L(){this.addInput("in","number");this.addOutput("out","number");this.size=[80,30];this.addProperty("samples",10);this._values=new Float32Array(10);this._current=0}function s(){this.addInput("in","number");this.addOutput("out","number");this.addProperty("factor",0.1);this.size=[80,30];this._value=null}function w(){this.addInput("A","number,array,object");this.addInput("B","number");this.addOutput("=","number");this.addProperty("A",1);this.addProperty("B",1);this.addProperty("OP","+","enum",
|
||||
{values:w.values});this._func=function(a,b){return a+b};this._result=[]}function l(){this.addInput("A","number");this.addInput("B","number");this.addOutput("A==B","boolean");this.addOutput("A!=B","boolean");this.addProperty("A",0);this.addProperty("B",0)}function a(){this.addInput("A","number");this.addInput("B","number");this.addOutput("true","boolean");this.addOutput("false","boolean");this.addProperty("A",1);this.addProperty("B",1);this.addProperty("OP",">","enum",{values:a.values});this.addWidget("combo",
|
||||
"Cond.",this.properties.OP,{property:"OP",values:a.values});this.size=[80,60]}function b(){this.addInput("in","");this.addInput("cond","boolean");this.addOutput("true","");this.addOutput("false","");this.size=[80,60]}function d(){this.addInput("inc","number");this.addOutput("total","number");this.addProperty("increment",1);this.addProperty("value",0)}function g(){this.addInput("v","number");this.addOutput("sin","number");this.addProperty("amplitude",1);this.addProperty("offset",0);this.bgImageUrl=
|
||||
"nodes/imgs/icon-sin.png"}function e(){this.addInput("x","number");this.addInput("y","number");this.addOutput("","number");this.properties={x:1,y:1,formula:"x+y"};this.code_widget=this.addWidget("text","F(x,y)",this.properties.formula,function(a,b,d){d.properties.formula=a});this.addWidget("toggle","allow",u.allow_scripts,function(a){u.allow_scripts=a});this._func=null}function y(){this.addInput("vec2","vec2");this.addOutput("x","number");this.addOutput("y","number")}function m(){this.addInputs([["x",
|
||||
"number"],["y","number"]]);this.addOutput("vec2","vec2");this.properties={x:0,y:0};this._data=new Float32Array(2)}function q(){this.addInput("vec3","vec3");this.addOutput("x","number");this.addOutput("y","number");this.addOutput("z","number")}function C(){this.addInputs([["x","number"],["y","number"],["z","number"]]);this.addOutput("vec3","vec3");this.properties={x:0,y:0,z:0};this._data=new Float32Array(3)}function N(){this.addInput("vec4","vec4");this.addOutput("x","number");this.addOutput("y","number");
|
||||
this.addOutput("z","number");this.addOutput("w","number")}function M(){this.addInputs([["x","number"],["y","number"],["z","number"],["w","number"]]);this.addOutput("vec4","vec4");this.properties={x:0,y:0,z:0,w:0};this._data=new Float32Array(4)}var u=B.LiteGraph;c.title="Converter";c.desc="type A to type B";c.prototype.onExecute=function(){var a=this.getInputData(0);if(null!=a&&this.outputs)for(var b=0;b<this.outputs.length;b++){var d=this.outputs[b];if(d.links&&d.links.length){var e=null;switch(d.name){case "number":e=
|
||||
a.length?a[0]:parseFloat(a);break;case "vec2":case "vec3":case "vec4":e=1;switch(d.name){case "vec2":e=2;break;case "vec3":e=3;break;case "vec4":e=4}e=new Float32Array(e);if(a.length)for(d=0;d<a.length&&d<e.length;d++)e[d]=a[d];else e[0]=parseFloat(a)}this.setOutputData(b,e)}}};c.prototype.onGetOutputs=function(){return[["number","number"],["vec2","vec2"],["vec3","vec3"],["vec4","vec4"]]};u.registerNodeType("math/converter",c);k.title="Bypass";k.desc="removes the type";k.prototype.onExecute=function(){var a=
|
||||
this.getInputData(0);this.setOutputData(0,a)};u.registerNodeType("math/bypass",k);v.title="to Number";v.desc="Cast to number";v.prototype.onExecute=function(){var a=this.getInputData(0);this.setOutputData(0,Number(a))};u.registerNodeType("math/to_number",v);r.title="Range";r.desc="Convert a number from one range to another";r.prototype.getTitle=function(){return this.flags.collapsed?(this._last_v||0).toFixed(2):this.title};r.prototype.onExecute=function(){if(this.inputs)for(var a=0;a<this.inputs.length;a++){var b=
|
||||
this.inputs[a],d=this.getInputData(a);void 0!==d&&(this.properties[b.name]=d)}d=this.properties["in"];if(void 0===d||null===d||d.constructor!==Number)d=0;var a=this.properties.in_min,b=this.properties.out_min,e=this.properties.out_max;this._last_v=(d-a)/(this.properties.in_max-a)*(e-b)+b;this.setOutputData(0,this._last_v);this.setOutputData(1,Math.clamp(this._last_v,b,e))};r.prototype.onDrawBackground=function(a){this.outputs[0].label=this._last_v?this._last_v.toFixed(3):"?"};r.prototype.onGetInputs=
|
||||
|
||||
Reference in New Issue
Block a user