mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-02 22:37:32 +00:00
fix in widget
This commit is contained in:
@@ -89,6 +89,7 @@
|
||||
NO_TITLE: 1,
|
||||
TRANSPARENT_TITLE: 2,
|
||||
AUTOHIDE_TITLE: 3,
|
||||
VERTICAL_LAYOUT: "vertical", // arrange nodes vertically
|
||||
|
||||
proxy: null, //used to redirect calls
|
||||
node_images_path: "",
|
||||
@@ -1260,7 +1261,7 @@
|
||||
* Positions every node in a more readable manner
|
||||
* @method arrange
|
||||
*/
|
||||
LGraph.prototype.arrange = function(margin) {
|
||||
LGraph.prototype.arrange = function (margin, layout) {
|
||||
margin = margin || 100;
|
||||
|
||||
var nodes = this.computeExecutionOrder(false, true);
|
||||
@@ -1285,12 +1286,14 @@
|
||||
var y = margin + LiteGraph.NODE_TITLE_HEIGHT;
|
||||
for (var j = 0; j < column.length; ++j) {
|
||||
var node = column[j];
|
||||
node.pos[0] = x;
|
||||
node.pos[1] = y;
|
||||
if (node.size[0] > max_size) {
|
||||
max_size = node.size[0];
|
||||
node.pos[0] = (layout == LiteGraph.VERTICAL_LAYOUT) ? y : x;
|
||||
node.pos[1] = (layout == LiteGraph.VERTICAL_LAYOUT) ? x : y;
|
||||
var max_size_index = (layout == LiteGraph.VERTICAL_LAYOUT) ? 1 : 0;
|
||||
if (node.size[max_size_index] > max_size) {
|
||||
max_size = node.size[max_size_index];
|
||||
}
|
||||
y += node.size[1] + margin + LiteGraph.NODE_TITLE_HEIGHT;
|
||||
var node_size_index = (layout == LiteGraph.VERTICAL_LAYOUT) ? 0 : 1;
|
||||
y += node.size[node_size_index] + margin + LiteGraph.NODE_TITLE_HEIGHT;
|
||||
}
|
||||
x += max_size + margin;
|
||||
}
|
||||
@@ -2468,43 +2471,34 @@
|
||||
this.title = this.constructor.title;
|
||||
}
|
||||
|
||||
if (this.onConnectionsChange) {
|
||||
if (this.inputs) {
|
||||
for (var i = 0; i < this.inputs.length; ++i) {
|
||||
var input = this.inputs[i];
|
||||
var link_info = this.graph
|
||||
? this.graph.links[input.link]
|
||||
: null;
|
||||
this.onConnectionsChange(
|
||||
LiteGraph.INPUT,
|
||||
i,
|
||||
true,
|
||||
link_info,
|
||||
input
|
||||
); //link_info has been created now, so its updated
|
||||
}
|
||||
}
|
||||
if (this.inputs) {
|
||||
for (var i = 0; i < this.inputs.length; ++i) {
|
||||
var input = this.inputs[i];
|
||||
var link_info = this.graph ? this.graph.links[input.link] : null;
|
||||
if (this.onConnectionsChange)
|
||||
this.onConnectionsChange( LiteGraph.INPUT, i, true, link_info, input ); //link_info has been created now, so its updated
|
||||
|
||||
if (this.outputs) {
|
||||
for (var i = 0; i < this.outputs.length; ++i) {
|
||||
var output = this.outputs[i];
|
||||
if (!output.links) {
|
||||
continue;
|
||||
}
|
||||
for (var j = 0; j < output.links.length; ++j) {
|
||||
var link_info = this.graph
|
||||
? this.graph.links[output.links[j]]
|
||||
: null;
|
||||
this.onConnectionsChange(
|
||||
LiteGraph.OUTPUT,
|
||||
i,
|
||||
true,
|
||||
link_info,
|
||||
output
|
||||
); //link_info has been created now, so its updated
|
||||
}
|
||||
}
|
||||
}
|
||||
if( this.onInputAdded )
|
||||
this.onInputAdded(input);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (this.outputs) {
|
||||
for (var i = 0; i < this.outputs.length; ++i) {
|
||||
var output = this.outputs[i];
|
||||
if (!output.links) {
|
||||
continue;
|
||||
}
|
||||
for (var j = 0; j < output.links.length; ++j) {
|
||||
var link_info = this.graph ? this.graph.links[output.links[j]] : null;
|
||||
if (this.onConnectionsChange)
|
||||
this.onConnectionsChange( LiteGraph.OUTPUT, i, true, link_info, output ); //link_info has been created now, so its updated
|
||||
}
|
||||
|
||||
if( this.onOutputAdded )
|
||||
this.onOutputAdded(output);
|
||||
}
|
||||
}
|
||||
|
||||
if( this.widgets )
|
||||
@@ -3200,6 +3194,15 @@
|
||||
return;
|
||||
}
|
||||
|
||||
if(slot == null)
|
||||
{
|
||||
console.error("slot must be a number");
|
||||
return;
|
||||
}
|
||||
|
||||
if(slot.constructor !== Number)
|
||||
console.warn("slot must be a number, use node.trigger('name') if you want to use a string");
|
||||
|
||||
var output = this.outputs[slot];
|
||||
if (!output) {
|
||||
return;
|
||||
@@ -3346,26 +3349,26 @@
|
||||
* @param {Object} extra_info this can be used to have special properties of an output (label, special color, position, etc)
|
||||
*/
|
||||
LGraphNode.prototype.addOutput = function(name, type, extra_info) {
|
||||
var o = { name: name, type: type, links: null };
|
||||
var output = { name: name, type: type, links: null };
|
||||
if (extra_info) {
|
||||
for (var i in extra_info) {
|
||||
o[i] = extra_info[i];
|
||||
output[i] = extra_info[i];
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.outputs) {
|
||||
this.outputs = [];
|
||||
}
|
||||
this.outputs.push(o);
|
||||
this.outputs.push(output);
|
||||
if (this.onOutputAdded) {
|
||||
this.onOutputAdded(o);
|
||||
this.onOutputAdded(output);
|
||||
}
|
||||
|
||||
if (LiteGraph.auto_load_slot_types) LiteGraph.registerNodeAndSlotType(this,type,true);
|
||||
|
||||
this.setSize( this.computeSize() );
|
||||
this.setDirtyCanvas(true, true);
|
||||
return o;
|
||||
return output;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -3437,10 +3440,10 @@
|
||||
*/
|
||||
LGraphNode.prototype.addInput = function(name, type, extra_info) {
|
||||
type = type || 0;
|
||||
var o = { name: name, type: type, link: null };
|
||||
var input = { name: name, type: type, link: null };
|
||||
if (extra_info) {
|
||||
for (var i in extra_info) {
|
||||
o[i] = extra_info[i];
|
||||
input[i] = extra_info[i];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3448,17 +3451,17 @@
|
||||
this.inputs = [];
|
||||
}
|
||||
|
||||
this.inputs.push(o);
|
||||
this.inputs.push(input);
|
||||
this.setSize( this.computeSize() );
|
||||
|
||||
if (this.onInputAdded) {
|
||||
this.onInputAdded(o);
|
||||
this.onInputAdded(input);
|
||||
}
|
||||
|
||||
LiteGraph.registerNodeAndSlotType(this,type);
|
||||
|
||||
this.setDirtyCanvas(true, true);
|
||||
return o;
|
||||
return input;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -7489,8 +7492,8 @@ LGraphNode.prototype.executeAction = function(action)
|
||||
clientY_rel = e.clientY;
|
||||
}
|
||||
|
||||
e.deltaX = clientX_rel - this.last_mouse_position[0];
|
||||
e.deltaY = clientY_rel- this.last_mouse_position[1];
|
||||
// e.deltaX = clientX_rel - this.last_mouse_position[0];
|
||||
// e.deltaY = clientY_rel- this.last_mouse_position[1];
|
||||
|
||||
this.last_mouse_position[0] = clientX_rel;
|
||||
this.last_mouse_position[1] = clientY_rel;
|
||||
@@ -9927,7 +9930,8 @@ LGraphNode.prototype.executeAction = function(action)
|
||||
case "combo":
|
||||
var old_value = w.value;
|
||||
if (event.type == LiteGraph.pointerevents_method+"move" && w.type == "number") {
|
||||
w.value += event.deltaX * 0.1 * (w.options.step || 1);
|
||||
if(event.deltaX)
|
||||
w.value += event.deltaX * 0.1 * (w.options.step || 1);
|
||||
if ( w.options.min != null && w.value < w.options.min ) {
|
||||
w.value = w.options.min;
|
||||
}
|
||||
@@ -11993,7 +11997,8 @@ LGraphNode.prototype.executeAction = function(action)
|
||||
if (root.onClose && typeof root.onClose == "function"){
|
||||
root.onClose();
|
||||
}
|
||||
root.parentNode.removeChild(root);
|
||||
if(root.parentNode)
|
||||
root.parentNode.removeChild(root);
|
||||
/* XXX CHECK THIS */
|
||||
if(this.parentNode){
|
||||
this.parentNode.removeChild(this);
|
||||
|
||||
414
build/litegraph.core.min.js
vendored
414
build/litegraph.core.min.js
vendored
@@ -1,15 +1,15 @@
|
||||
var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.ASSUME_ES5=!1;$jscomp.ASSUME_NO_NATIVE_MAP=!1;$jscomp.ASSUME_NO_NATIVE_SET=!1;$jscomp.defineProperty=$jscomp.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(p,v,w){p!=Array.prototype&&p!=Object.prototype&&(p[v]=w.value)};$jscomp.getGlobal=function(p){return"undefined"!=typeof window&&window===p?p:"undefined"!=typeof global&&null!=global?global:p};$jscomp.global=$jscomp.getGlobal(this);
|
||||
$jscomp.polyfill=function(p,v,w,l){if(v){w=$jscomp.global;p=p.split(".");for(l=0;l<p.length-1;l++){var z=p[l];z in w||(w[z]={});w=w[z]}p=p[p.length-1];l=w[p];v=v(l);v!=l&&null!=v&&$jscomp.defineProperty(w,p,{configurable:!0,writable:!0,value:v})}};$jscomp.polyfill("Object.is",function(p){return p?p:function(v,p){return v===p?0!==v||1/v===1/p:v!==v&&p!==p}},"es6","es3");
|
||||
$jscomp.polyfill("Array.prototype.includes",function(p){return p?p:function(v,p){var l=this;l instanceof String&&(l=String(l));var w=l.length;for(p=p||0;p<w;p++)if(l[p]==v||Object.is(l[p],v))return!0;return!1}},"es7","es3");
|
||||
$jscomp.checkStringArgs=function(p,v,w){if(null==p)throw new TypeError("The 'this' value for String.prototype."+w+" must not be null or undefined");if(v instanceof RegExp)throw new TypeError("First argument to String.prototype."+w+" must not be a regular expression");return p+""};$jscomp.polyfill("String.prototype.includes",function(p){return p?p:function(v,p){return-1!==$jscomp.checkStringArgs(this,v,"includes").indexOf(v,p||0)}},"es6","es3");
|
||||
$jscomp.owns=function(p,v){return Object.prototype.hasOwnProperty.call(p,v)};$jscomp.polyfill("Object.assign",function(p){return p?p:function(v,p){for(var l=1;l<arguments.length;l++){var w=arguments[l];if(w)for(var y in w)$jscomp.owns(w,y)&&(v[y]=w[y])}return v}},"es6","es3");$jscomp.SYMBOL_PREFIX="jscomp_symbol_";$jscomp.initSymbol=function(){$jscomp.initSymbol=function(){};$jscomp.global.Symbol||($jscomp.global.Symbol=$jscomp.Symbol)};
|
||||
$jscomp.Symbol=function(){var p=0;return function(v){return $jscomp.SYMBOL_PREFIX+(v||"")+p++}}();$jscomp.initSymbolIterator=function(){$jscomp.initSymbol();var p=$jscomp.global.Symbol.iterator;p||(p=$jscomp.global.Symbol.iterator=$jscomp.global.Symbol("iterator"));"function"!=typeof Array.prototype[p]&&$jscomp.defineProperty(Array.prototype,p,{configurable:!0,writable:!0,value:function(){return $jscomp.arrayIterator(this)}});$jscomp.initSymbolIterator=function(){}};
|
||||
$jscomp.arrayIterator=function(p){var v=0;return $jscomp.iteratorPrototype(function(){return v<p.length?{done:!1,value:p[v++]}:{done:!0}})};$jscomp.iteratorPrototype=function(p){$jscomp.initSymbolIterator();p={next:p};p[$jscomp.global.Symbol.iterator]=function(){return this};return p};
|
||||
$jscomp.iteratorFromArray=function(p,v){$jscomp.initSymbolIterator();p instanceof String&&(p+="");var w=0,l={next:function(){if(w<p.length){var z=w++;return{value:v(z,p[z]),done:!1}}l.next=function(){return{done:!0,value:void 0}};return l.next()}};l[Symbol.iterator]=function(){return l};return l};$jscomp.polyfill("Array.prototype.keys",function(p){return p?p:function(){return $jscomp.iteratorFromArray(this,function(v){return v})}},"es6","es3");
|
||||
$jscomp.polyfill("Array.prototype.fill",function(p){return p?p:function(v,p,l){var w=this.length||0;0>p&&(p=Math.max(0,w+p));if(null==l||l>w)l=w;l=Number(l);0>l&&(l=Math.max(0,w+l));for(p=Number(p||0);p<l;p++)this[p]=v;return this}},"es6","es3");$jscomp.polyfill("Array.prototype.values",function(p){return p?p:function(){return $jscomp.iteratorFromArray(this,function(v,p){return p})}},"es8","es3");
|
||||
$jscomp.polyfill("Object.values",function(p){return p?p:function(v){var p=[],l;for(l in v)$jscomp.owns(v,l)&&p.push(v[l]);return p}},"es8","es3");$jscomp.polyfill("String.prototype.startsWith",function(p){return p?p:function(v,p){var l=$jscomp.checkStringArgs(this,v,"startsWith");v+="";var w=l.length,y=v.length;p=Math.max(0,Math.min(p|0,l.length));for(var m=0;m<y&&p<w;)if(l[p++]!=v[m++])return!1;return m>=y}},"es6","es3");
|
||||
$jscomp.findInternal=function(p,v,w){p instanceof String&&(p=String(p));for(var l=p.length,z=0;z<l;z++){var y=p[z];if(v.call(w,y,z,p))return{i:z,v:y}}return{i:-1,v:void 0}};$jscomp.polyfill("Array.prototype.findIndex",function(p){return p?p:function(p,w){return $jscomp.findInternal(this,p,w).i}},"es6","es3");
|
||||
(function(p){function v(a){g.debug&&console.log("Graph created");this.list_of_graphcanvas=null;this.clear();a&&this.configure(a)}function w(a,b,c,d,e,f){this.id=a;this.type=b;this.origin_id=c;this.origin_slot=d;this.target_id=e;this.target_slot=f;this._data=null;this._pos=new Float32Array(2)}function l(a){this._ctor(a)}function z(a){this._ctor(a)}function y(a,b){this.offset=new Float32Array([0,0]);this.scale=1;this.max_scale=10;this.min_scale=.1;this.onredraw=null;this.enabled=!0;this.last_mouse=
|
||||
var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.ASSUME_ES5=!1;$jscomp.ASSUME_NO_NATIVE_MAP=!1;$jscomp.ASSUME_NO_NATIVE_SET=!1;$jscomp.defineProperty=$jscomp.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(r,v,w){r!=Array.prototype&&r!=Object.prototype&&(r[v]=w.value)};$jscomp.getGlobal=function(r){return"undefined"!=typeof window&&window===r?r:"undefined"!=typeof global&&null!=global?global:r};$jscomp.global=$jscomp.getGlobal(this);
|
||||
$jscomp.polyfill=function(r,v,w,l){if(v){w=$jscomp.global;r=r.split(".");for(l=0;l<r.length-1;l++){var z=r[l];z in w||(w[z]={});w=w[z]}r=r[r.length-1];l=w[r];v=v(l);v!=l&&null!=v&&$jscomp.defineProperty(w,r,{configurable:!0,writable:!0,value:v})}};$jscomp.polyfill("Object.is",function(r){return r?r:function(v,r){return v===r?0!==v||1/v===1/r:v!==v&&r!==r}},"es6","es3");
|
||||
$jscomp.polyfill("Array.prototype.includes",function(r){return r?r:function(v,r){var l=this;l instanceof String&&(l=String(l));var w=l.length;for(r=r||0;r<w;r++)if(l[r]==v||Object.is(l[r],v))return!0;return!1}},"es7","es3");
|
||||
$jscomp.checkStringArgs=function(r,v,w){if(null==r)throw new TypeError("The 'this' value for String.prototype."+w+" must not be null or undefined");if(v instanceof RegExp)throw new TypeError("First argument to String.prototype."+w+" must not be a regular expression");return r+""};$jscomp.polyfill("String.prototype.includes",function(r){return r?r:function(v,r){return-1!==$jscomp.checkStringArgs(this,v,"includes").indexOf(v,r||0)}},"es6","es3");
|
||||
$jscomp.owns=function(r,v){return Object.prototype.hasOwnProperty.call(r,v)};$jscomp.polyfill("Object.assign",function(r){return r?r:function(v,r){for(var l=1;l<arguments.length;l++){var w=arguments[l];if(w)for(var y in w)$jscomp.owns(w,y)&&(v[y]=w[y])}return v}},"es6","es3");$jscomp.SYMBOL_PREFIX="jscomp_symbol_";$jscomp.initSymbol=function(){$jscomp.initSymbol=function(){};$jscomp.global.Symbol||($jscomp.global.Symbol=$jscomp.Symbol)};
|
||||
$jscomp.Symbol=function(){var r=0;return function(v){return $jscomp.SYMBOL_PREFIX+(v||"")+r++}}();$jscomp.initSymbolIterator=function(){$jscomp.initSymbol();var r=$jscomp.global.Symbol.iterator;r||(r=$jscomp.global.Symbol.iterator=$jscomp.global.Symbol("iterator"));"function"!=typeof Array.prototype[r]&&$jscomp.defineProperty(Array.prototype,r,{configurable:!0,writable:!0,value:function(){return $jscomp.arrayIterator(this)}});$jscomp.initSymbolIterator=function(){}};
|
||||
$jscomp.arrayIterator=function(r){var v=0;return $jscomp.iteratorPrototype(function(){return v<r.length?{done:!1,value:r[v++]}:{done:!0}})};$jscomp.iteratorPrototype=function(r){$jscomp.initSymbolIterator();r={next:r};r[$jscomp.global.Symbol.iterator]=function(){return this};return r};
|
||||
$jscomp.iteratorFromArray=function(r,v){$jscomp.initSymbolIterator();r instanceof String&&(r+="");var w=0,l={next:function(){if(w<r.length){var z=w++;return{value:v(z,r[z]),done:!1}}l.next=function(){return{done:!0,value:void 0}};return l.next()}};l[Symbol.iterator]=function(){return l};return l};$jscomp.polyfill("Array.prototype.keys",function(r){return r?r:function(){return $jscomp.iteratorFromArray(this,function(v){return v})}},"es6","es3");
|
||||
$jscomp.polyfill("Array.prototype.fill",function(r){return r?r:function(v,r,l){var w=this.length||0;0>r&&(r=Math.max(0,w+r));if(null==l||l>w)l=w;l=Number(l);0>l&&(l=Math.max(0,w+l));for(r=Number(r||0);r<l;r++)this[r]=v;return this}},"es6","es3");$jscomp.polyfill("Array.prototype.values",function(r){return r?r:function(){return $jscomp.iteratorFromArray(this,function(v,r){return r})}},"es8","es3");
|
||||
$jscomp.polyfill("Object.values",function(r){return r?r:function(v){var r=[],l;for(l in v)$jscomp.owns(v,l)&&r.push(v[l]);return r}},"es8","es3");$jscomp.polyfill("String.prototype.startsWith",function(r){return r?r:function(v,r){var l=$jscomp.checkStringArgs(this,v,"startsWith");v+="";var w=l.length,y=v.length;r=Math.max(0,Math.min(r|0,l.length));for(var m=0;m<y&&r<w;)if(l[r++]!=v[m++])return!1;return m>=y}},"es6","es3");
|
||||
$jscomp.findInternal=function(r,v,w){r instanceof String&&(r=String(r));for(var l=r.length,z=0;z<l;z++){var y=r[z];if(v.call(w,y,z,r))return{i:z,v:y}}return{i:-1,v:void 0}};$jscomp.polyfill("Array.prototype.findIndex",function(r){return r?r:function(r,w){return $jscomp.findInternal(this,r,w).i}},"es6","es3");
|
||||
(function(r){function v(a){g.debug&&console.log("Graph created");this.list_of_graphcanvas=null;this.clear();a&&this.configure(a)}function w(a,b,c,d,e,f){this.id=a;this.type=b;this.origin_id=c;this.origin_slot=d;this.target_id=e;this.target_slot=f;this._data=null;this._pos=new Float32Array(2)}function l(a){this._ctor(a)}function z(a){this._ctor(a)}function y(a,b){this.offset=new Float32Array([0,0]);this.scale=1;this.max_scale=10;this.min_scale=.1;this.onredraw=null;this.enabled=!0;this.last_mouse=
|
||||
[0,0];this.element=null;this.visible_area=new Float32Array(4);a&&(this.element=a,b||this.bindEvents(a))}function m(a,b,c){this.options=c=c||{};this.background_image=m.DEFAULT_BACKGROUND_IMAGE;a&&a.constructor===String&&(a=document.querySelector(a));this.ds=new y;this.zoom_modify_alpha=!0;this.title_text_font=""+g.NODE_TEXT_SIZE+"px Arial";this.inner_text_font="normal "+g.NODE_SUBTEXT_SIZE+"px Arial";this.node_title_color=g.NODE_TITLE_COLOR;this.default_link_color=g.LINK_COLOR;this.default_connection_color=
|
||||
{input_off:"#778",input_on:"#7F7",output_off:"#778",output_on:"#7F7"};this.default_connection_color_byType={};this.default_connection_color_byTypeOff={};this.highquality_render=!0;this.use_gradients=!1;this.editor_alpha=1;this.pause_rendering=!1;this.clear_background=!0;this.read_only=!1;this.render_only_selected=!0;this.live_mode=!1;this.allow_reconnect_links=this.allow_searchbox=this.allow_interaction=this.allow_dragnodes=this.allow_dragcanvas=this.show_info=!0;this.drag_mode=this.align_to_grid=
|
||||
!1;this.filter=this.dragging_rectangle=null;this.set_canvas_dirty_on_mouse_event=!0;this.always_render_background=!1;this.render_canvas_border=this.render_shadows=!0;this.render_connections_shadows=!1;this.render_connections_border=!0;this.render_connection_arrows=this.render_curved_connections=!1;this.render_collapsed_slots=!0;this.render_execution_order=!1;this.render_link_tooltip=this.render_title_colored=!0;this.links_render_mode=g.SPLINE_LINK;this.mouse=[0,0];this.canvas_mouse=this.graph_mouse=
|
||||
@@ -19,17 +19,17 @@ this.options=b=b||{};var d=this;b.parentMenu&&(b.parentMenu.constructor!==this.c
|
||||
var f=document.createElement("div");f.className="litegraph litecontextmenu litemenubar-panel";b.className&&(f.className+=" "+b.className);f.style.minWidth=100;f.style.minHeight=100;f.style.pointerEvents="none";setTimeout(function(){f.style.pointerEvents="auto"},100);g.pointerListenerAdd(f,"up",function(a){a.preventDefault();return!0},!0);f.addEventListener("contextmenu",function(a){if(2!=a.button)return!1;a.preventDefault();return!1},!0);g.pointerListenerAdd(f,"down",function(a){if(2==a.button)return d.close(),
|
||||
a.preventDefault(),!0},!0);b.scroll_speed||(b.scroll_speed=.1);f.addEventListener("wheel",c,!0);f.addEventListener("mousewheel",c,!0);this.root=f;b.title&&(e=document.createElement("div"),e.className="litemenu-title",e.innerHTML=b.title,f.appendChild(e));for(var h=e=0;h<a.length;h++){var k=a.constructor==Array?a[h]:h;null!=k&&k.constructor!==String&&(k=void 0===k.content?String(k):k.content);this.addItem(k,a[h],b);e++}g.pointerListenerAdd(f,"enter",function(a){f.closing_timer&&clearTimeout(f.closing_timer)});
|
||||
a=document;b.event&&(a=b.event.target.ownerDocument);a||(a=document);a.fullscreenElement?a.fullscreenElement.appendChild(f):a.body.appendChild(f);e=b.left||0;a=b.top||0;b.event&&(e=b.event.clientX-10,a=b.event.clientY-10,b.title&&(a-=20),b.parentMenu&&(e=b.parentMenu.root.getBoundingClientRect(),e=e.left+e.width),h=document.body.getBoundingClientRect(),k=f.getBoundingClientRect(),0==h.height&&console.error("document.body height is 0. That is dangerous, set html,body { height: 100%; }"),h.width&&e>
|
||||
h.width-k.width-10&&(e=h.width-k.width-10),h.height&&a>h.height-k.height-10&&(a=h.height-k.height-10));f.style.left=e+"px";f.style.top=a+"px";b.scale&&(f.style.transform="scale("+b.scale+")")}function E(a){this.points=a;this.nearest=this.selected=-1;this.size=null;this.must_update=!0;this.margin=5}var g=p.LiteGraph={VERSION:.4,CANVAS_GRID_SIZE:10,NODE_TITLE_HEIGHT:30,NODE_TITLE_TEXT_Y:20,NODE_SLOT_HEIGHT:20,NODE_WIDGET_HEIGHT:20,NODE_WIDTH:140,NODE_MIN_WIDTH:50,NODE_COLLAPSED_RADIUS:10,NODE_COLLAPSED_WIDTH:80,
|
||||
h.width-k.width-10&&(e=h.width-k.width-10),h.height&&a>h.height-k.height-10&&(a=h.height-k.height-10));f.style.left=e+"px";f.style.top=a+"px";b.scale&&(f.style.transform="scale("+b.scale+")")}function E(a){this.points=a;this.nearest=this.selected=-1;this.size=null;this.must_update=!0;this.margin=5}var g=r.LiteGraph={VERSION:.4,CANVAS_GRID_SIZE:10,NODE_TITLE_HEIGHT:30,NODE_TITLE_TEXT_Y:20,NODE_SLOT_HEIGHT:20,NODE_WIDGET_HEIGHT:20,NODE_WIDTH:140,NODE_MIN_WIDTH:50,NODE_COLLAPSED_RADIUS:10,NODE_COLLAPSED_WIDTH:80,
|
||||
NODE_TITLE_COLOR:"#999",NODE_SELECTED_TITLE_COLOR:"#FFF",NODE_TEXT_SIZE:14,NODE_TEXT_COLOR:"#AAA",NODE_SUBTEXT_SIZE:12,NODE_DEFAULT_COLOR:"#333",NODE_DEFAULT_BGCOLOR:"#353535",NODE_DEFAULT_BOXCOLOR:"#666",NODE_DEFAULT_SHAPE:"box",NODE_BOX_OUTLINE_COLOR:"#FFF",DEFAULT_SHADOW_COLOR:"rgba(0,0,0,0.5)",DEFAULT_GROUP_FONT:24,WIDGET_BGCOLOR:"#222",WIDGET_OUTLINE_COLOR:"#666",WIDGET_TEXT_COLOR:"#DDD",WIDGET_SECONDARY_TEXT_COLOR:"#999",LINK_COLOR:"#9A9",EVENT_LINK_COLOR:"#A86",CONNECTING_LINK_COLOR:"#AFA",
|
||||
MAX_NUMBER_OF_NODES:1E3,DEFAULT_POSITION:[100,100],VALID_SHAPES:["default","box","round","card"],BOX_SHAPE:1,ROUND_SHAPE:2,CIRCLE_SHAPE:3,CARD_SHAPE:4,ARROW_SHAPE:5,GRID_SHAPE:6,INPUT:1,OUTPUT:2,EVENT:-1,ACTION:-1,NODE_MODES:["Always","On Event","Never","On Trigger"],NODE_MODES_COLORS:["#666","#422","#333","#224","#626"],ALWAYS:0,ON_EVENT:1,NEVER:2,ON_TRIGGER:3,UP:1,DOWN:2,LEFT:3,RIGHT:4,CENTER:5,LINK_RENDER_MODES:["Straight","Linear","Spline"],STRAIGHT_LINK:0,LINEAR_LINK:1,SPLINE_LINK:2,NORMAL_TITLE:0,
|
||||
NO_TITLE:1,TRANSPARENT_TITLE:2,AUTOHIDE_TITLE:3,proxy:null,node_images_path:"",debug:!1,catch_exceptions:!0,throw_errors:!0,allow_scripts:!1,registered_node_types:{},node_types_by_file_extension:{},Nodes:{},Globals:{},searchbox_extras:{},auto_sort_node_types:!1,node_box_coloured_when_on:!1,node_box_coloured_by_mode:!1,dialog_close_on_mouse_leave:!0,dialog_close_on_mouse_leave_delay:500,shift_click_do_break_link_from:!1,click_do_break_link_to:!1,search_hide_on_mouse_leave:!0,search_filter_enabled:!1,
|
||||
search_show_all_on_open:!0,auto_load_slot_types:!1,registered_slot_in_types:{},registered_slot_out_types:{},slot_types_in:[],slot_types_out:[],slot_types_default_in:[],slot_types_default_out:[],alt_drag_do_clone_nodes:!1,do_add_triggers_slots:!1,allow_multi_output_for_events:!0,middle_click_slot_add_default_node:!1,release_link_on_empty_shows_menu:!1,pointerevents_method:"mouse",registerNodeType:function(a,b){if(!b.prototype)throw"Cannot register a simple object, it must be a class with a prototype";
|
||||
NO_TITLE:1,TRANSPARENT_TITLE:2,AUTOHIDE_TITLE:3,VERTICAL_LAYOUT:"vertical",proxy:null,node_images_path:"",debug:!1,catch_exceptions:!0,throw_errors:!0,allow_scripts:!1,registered_node_types:{},node_types_by_file_extension:{},Nodes:{},Globals:{},searchbox_extras:{},auto_sort_node_types:!1,node_box_coloured_when_on:!1,node_box_coloured_by_mode:!1,dialog_close_on_mouse_leave:!0,dialog_close_on_mouse_leave_delay:500,shift_click_do_break_link_from:!1,click_do_break_link_to:!1,search_hide_on_mouse_leave:!0,
|
||||
search_filter_enabled:!1,search_show_all_on_open:!0,auto_load_slot_types:!1,registered_slot_in_types:{},registered_slot_out_types:{},slot_types_in:[],slot_types_out:[],slot_types_default_in:[],slot_types_default_out:[],alt_drag_do_clone_nodes:!1,do_add_triggers_slots:!1,allow_multi_output_for_events:!0,middle_click_slot_add_default_node:!1,release_link_on_empty_shows_menu:!1,pointerevents_method:"mouse",registerNodeType:function(a,b){if(!b.prototype)throw"Cannot register a simple object, it must be a class with a prototype";
|
||||
b.type=a;g.debug&&console.log("Node registered: "+a);a.split("/");var c=b.name,d=a.lastIndexOf("/");b.category=a.substr(0,d);b.title||(b.title=c);if(b.prototype)for(var e in l.prototype)b.prototype[e]||(b.prototype[e]=l.prototype[e]);if(d=this.registered_node_types[a])console.log("replacing node type: "+a);else if(Object.hasOwnProperty(b.prototype,"shape")||Object.defineProperty(b.prototype,"shape",{set:function(a){switch(a){case "default":delete this._shape;break;case "box":this._shape=g.BOX_SHAPE;
|
||||
break;case "round":this._shape=g.ROUND_SHAPE;break;case "circle":this._shape=g.CIRCLE_SHAPE;break;case "card":this._shape=g.CARD_SHAPE;break;default:this._shape=a}},get:function(a){return this._shape},enumerable:!0,configurable:!0}),b.prototype.onPropertyChange&&console.warn("LiteGraph node class "+a+" has onPropertyChange method, it must be called onPropertyChanged with d at the end"),b.supported_extensions)for(e in b.supported_extensions){var f=b.supported_extensions[e];f&&f.constructor===String&&
|
||||
(this.node_types_by_file_extension[f.toLowerCase()]=b)}this.registered_node_types[a]=b;b.constructor.name&&(this.Nodes[c]=b);if(g.onNodeTypeRegistered)g.onNodeTypeRegistered(a,b);if(d&&g.onNodeTypeReplaced)g.onNodeTypeReplaced(a,b,d);b.prototype.onPropertyChange&&console.warn("LiteGraph node class "+a+" has onPropertyChange method, it must be called onPropertyChanged with d at the end");if(b.supported_extensions)for(e=0;e<b.supported_extensions.length;e++)(f=b.supported_extensions[e])&&f.constructor===
|
||||
String&&(this.node_types_by_file_extension[f.toLowerCase()]=b);this.auto_load_slot_types&&(nodeTmp=new b(b.title||"tmpnode"))},unregisterNodeType:function(a){var b=a.constructor===String?this.registered_node_types[a]:a;if(!b)throw"node type not found: "+a;delete this.registered_node_types[b.type];b.constructor.name&&delete this.Nodes[b.constructor.name]},registerNodeAndSlotType:function(a,b,c){c=c||!1;a=(a.constructor===String&&"anonymous"!==this.registered_node_types[a]?this.registered_node_types[a]:
|
||||
a).constructor.type;b="string"==typeof b?b.split(","):b==this.EVENT||b==this.ACTION?["_event_"]:["*"];for(var d=0;d<b.length;++d){var e=b[d];""===e&&(e="*");var f=c?"registered_slot_out_types":"registered_slot_in_types";"undefined"==typeof this[f][e]&&(this[f][e]={nodes:[]});this[f][e].nodes.push(a);c?this.slot_types_out.includes(e.toLowerCase())||(this.slot_types_out.push(e.toLowerCase()),this.slot_types_out.sort()):this.slot_types_in.includes(e.toLowerCase())||(this.slot_types_in.push(e.toLowerCase()),
|
||||
this.slot_types_in.sort())}},wrapFunctionAsNode:function(a,b,c,d,e){for(var f=Array(b.length),h="",k=g.getParameterNames(b),n=0;n<k.length;++n)h+="this.addInput('"+k[n]+"',"+(c&&c[n]?"'"+c[n]+"'":"0")+");\n";h+="this.addOutput('out',"+(d?"'"+d+"'":0)+");\n";e&&(h+="this.properties = "+JSON.stringify(e)+";\n");c=Function(h);c.title=a.split("/").pop();c.desc="Generated from "+b.name;c.prototype.onExecute=function(){for(var a=0;a<f.length;++a)f[a]=this.getInputData(a);a=b.apply(this,f);this.setOutputData(0,
|
||||
this.slot_types_in.sort())}},wrapFunctionAsNode:function(a,b,c,d,e){for(var f=Array(b.length),h="",k=g.getParameterNames(b),q=0;q<k.length;++q)h+="this.addInput('"+k[q]+"',"+(c&&c[q]?"'"+c[q]+"'":"0")+");\n";h+="this.addOutput('out',"+(d?"'"+d+"'":0)+");\n";e&&(h+="this.properties = "+JSON.stringify(e)+";\n");c=Function(h);c.title=a.split("/").pop();c.desc="Generated from "+b.name;c.prototype.onExecute=function(){for(var a=0;a<f.length;++a)f[a]=this.getInputData(a);a=b.apply(this,f);this.setOutputData(0,
|
||||
a)};this.registerNodeType(a,c)},clearRegisteredTypes:function(){this.registered_node_types={};this.node_types_by_file_extension={};this.Nodes={};this.searchbox_extras={}},addNodeMethod:function(a,b){l.prototype[a]=b;for(var c in this.registered_node_types){var d=this.registered_node_types[c];d.prototype[a]&&(d.prototype["_"+a]=d.prototype[a]);d.prototype[a]=b}},createNode:function(a,b,c){var d=this.registered_node_types[a];if(!d)return g.debug&&console.log('GraphNode type "'+a+'" not registered.'),
|
||||
null;b=b||d.title||a;var e=null;if(g.catch_exceptions)try{e=new d(b)}catch(h){return console.error(h),null}else e=new d(b);e.type=a;!e.title&&b&&(e.title=b);e.properties||(e.properties={});e.properties_info||(e.properties_info=[]);e.flags||(e.flags={});e.size||(e.size=e.computeSize());e.pos||(e.pos=g.DEFAULT_POSITION.concat());e.mode||(e.mode=g.ALWAYS);if(c)for(var f in c)e[f]=c[f];if(e.onNodeCreated)e.onNodeCreated();return e},getNodeType:function(a){return this.registered_node_types[a]},getNodeTypesInCategory:function(a,
|
||||
b){var c=[],d;for(d in this.registered_node_types){var e=this.registered_node_types[d];e.filter==b&&(""==a?null==e.category&&c.push(e):e.category==a&&c.push(e))}this.auto_sort_node_types&&c.sort(function(a,b){return a.title.localeCompare(b.title)});return c},getNodeTypesCategories:function(a){var b={"":1},c;for(c in this.registered_node_types){var d=this.registered_node_types[c];d.category&&!d.skip_list&&d.filter==a&&(b[d.category]=1)}a=[];for(c in b)a.push(c);return this.auto_sort_node_types?a.sort():
|
||||
@@ -37,26 +37,26 @@ a},reloadNodes:function(a){for(var b=document.getElementsByTagName("script"),c=[
|
||||
cloneObject:function(a,b){if(null==a)return null;a=JSON.parse(JSON.stringify(a));if(!b)return a;for(var c in a)b[c]=a[c];return b},isValidConnection:function(a,b){if(""==a||"*"===a)a=0;if(""==b||"*"===b)b=0;if(!a||!b||a==b||a==g.EVENT&&b==g.ACTION)return!0;a=String(a);b=String(b);a=a.toLowerCase();b=b.toLowerCase();if(-1==a.indexOf(",")&&-1==b.indexOf(","))return a==b;a=a.split(",");b=b.split(",");for(var c=0;c<a.length;++c)for(var d=0;d<b.length;++d)if(this.isValidConnection(a[c],b[d]))return!0;
|
||||
return!1},registerSearchboxExtra:function(a,b,c){this.searchbox_extras[b.toLowerCase()]={type:a,desc:b,data:c}},fetchFile:function(a,b,c,d){if(!a)return null;b=b||"text";if(a.constructor===String)return"http"==a.substr(0,4)&&g.proxy&&(a=g.proxy+a.substr(a.indexOf(":")+3)),fetch(a).then(function(a){if(!a.ok)throw Error("File not found");if("arraybuffer"==b)return a.arrayBuffer();if("text"==b||"string"==b)return a.text();if("json"==b)return a.json();if("blob"==b)return a.blob()}).then(function(a){c&&
|
||||
c(a)}).catch(function(b){console.error("error fetching file:",a);d&&d(b)});if(a.constructor===File||a.constructor===Blob){var e=new FileReader;e.onload=function(a){a=a.target.result;"json"==b&&(a=JSON.parse(a));c&&c(a)};if("arraybuffer"==b)return e.readAsArrayBuffer(a);if("text"==b||"json"==b)return e.readAsText(a);if("blob"==b)return e.readAsBinaryString(a)}return null}};g.getTime="undefined"!=typeof performance?performance.now.bind(performance):"undefined"!=typeof Date&&Date.now?Date.now.bind(Date):
|
||||
"undefined"!=typeof process?function(){var a=process.hrtime();return.001*a[0]+1E-6*a[1]}:function(){return(new Date).getTime()};p.LGraph=g.LGraph=v;v.supported_types=["number","string","boolean"];v.prototype.getSupportedTypes=function(){return this.supported_types||v.supported_types};v.STATUS_STOPPED=1;v.STATUS_RUNNING=2;v.prototype.clear=function(){this.stop();this.status=v.STATUS_STOPPED;this.last_link_id=this.last_node_id=0;this._version=-1;if(this._nodes)for(var a=0;a<this._nodes.length;++a){var b=
|
||||
"undefined"!=typeof process?function(){var a=process.hrtime();return.001*a[0]+1E-6*a[1]}:function(){return(new Date).getTime()};r.LGraph=g.LGraph=v;v.supported_types=["number","string","boolean"];v.prototype.getSupportedTypes=function(){return this.supported_types||v.supported_types};v.STATUS_STOPPED=1;v.STATUS_RUNNING=2;v.prototype.clear=function(){this.stop();this.status=v.STATUS_STOPPED;this.last_link_id=this.last_node_id=0;this._version=-1;if(this._nodes)for(var a=0;a<this._nodes.length;++a){var b=
|
||||
this._nodes[a];if(b.onRemoved)b.onRemoved()}this._nodes=[];this._nodes_by_id={};this._nodes_in_order=[];this._nodes_executable=null;this._groups=[];this.links={};this.iteration=0;this.config={};this.vars={};this.extra={};this.fixedtime=this.runningtime=this.globaltime=0;this.elapsed_time=this.fixedtime_lapse=.01;this.starttime=this.last_update_time=0;this.catch_errors=!0;this.nodes_executing=[];this.nodes_actioning=[];this.nodes_executedAction=[];this.inputs={};this.outputs={};this.change();this.sendActionToCanvas("clear")};
|
||||
v.prototype.attachCanvas=function(a){if(a.constructor!=m)throw"attachCanvas expects a LGraphCanvas instance";a.graph&&a.graph!=this&&a.graph.detachCanvas(a);a.graph=this;this.list_of_graphcanvas||(this.list_of_graphcanvas=[]);this.list_of_graphcanvas.push(a)};v.prototype.detachCanvas=function(a){if(this.list_of_graphcanvas){var b=this.list_of_graphcanvas.indexOf(a);-1!=b&&(a.graph=null,this.list_of_graphcanvas.splice(b,1))}};v.prototype.start=function(a){if(this.status!=v.STATUS_RUNNING){this.status=
|
||||
v.STATUS_RUNNING;if(this.onPlayEvent)this.onPlayEvent();this.sendEventToAllNodes("onStart");this.last_update_time=this.starttime=g.getTime();a=a||0;var b=this;if(0==a&&"undefined"!=typeof window&&window.requestAnimationFrame){var c=function(){if(-1==b.execution_timer_id){window.requestAnimationFrame(c);if(b.onBeforeStep)b.onBeforeStep();b.runStep(1,!b.catch_errors);if(b.onAfterStep)b.onAfterStep()}};this.execution_timer_id=-1;c()}else this.execution_timer_id=setInterval(function(){if(b.onBeforeStep)b.onBeforeStep();
|
||||
b.runStep(1,!b.catch_errors);if(b.onAfterStep)b.onAfterStep()},a)}};v.prototype.stop=function(){if(this.status!=v.STATUS_STOPPED){this.status=v.STATUS_STOPPED;if(this.onStopEvent)this.onStopEvent();null!=this.execution_timer_id&&(-1!=this.execution_timer_id&&clearInterval(this.execution_timer_id),this.execution_timer_id=null);this.sendEventToAllNodes("onStop")}};v.prototype.runStep=function(a,b,c){a=a||1;var d=g.getTime();this.globaltime=.001*(d-this.starttime);var e=this._nodes_executable?this._nodes_executable:
|
||||
this._nodes;if(e){c=c||e.length;if(b){for(var f=0;f<a;f++){for(var h=0;h<c;++h){var k=e[h];k.mode==g.ALWAYS&&k.onExecute&&k.doExecute()}this.fixedtime+=this.fixedtime_lapse;if(this.onExecuteStep)this.onExecuteStep()}if(this.onAfterExecute)this.onAfterExecute()}else try{for(f=0;f<a;f++){for(h=0;h<c;++h)if(k=e[h],k.mode==g.ALWAYS&&k.onExecute)k.onExecute();this.fixedtime+=this.fixedtime_lapse;if(this.onExecuteStep)this.onExecuteStep()}if(this.onAfterExecute)this.onAfterExecute();this.errors_in_execution=
|
||||
!1}catch(n){this.errors_in_execution=!0;if(g.throw_errors)throw n;g.debug&&console.log("Error during execution: "+n);this.stop()}a=g.getTime();d=a-d;0==d&&(d=1);this.execution_time=.001*d;this.globaltime+=.001*d;this.iteration+=1;this.elapsed_time=.001*(a-this.last_update_time);this.last_update_time=a;this.nodes_executing=[];this.nodes_actioning=[];this.nodes_executedAction=[]}};v.prototype.updateExecutionOrder=function(){this._nodes_in_order=this.computeExecutionOrder(!1);this._nodes_executable=
|
||||
[];for(var a=0;a<this._nodes_in_order.length;++a)this._nodes_in_order[a].onExecute&&this._nodes_executable.push(this._nodes_in_order[a])};v.prototype.computeExecutionOrder=function(a,b){for(var c=[],d=[],e={},f={},h={},k=0,n=this._nodes.length;k<n;++k){var q=this._nodes[k];if(!a||q.onExecute){e[q.id]=q;var t=0;if(q.inputs)for(var r=0,m=q.inputs.length;r<m;r++)q.inputs[r]&&null!=q.inputs[r].link&&(t+=1);0==t?(d.push(q),b&&(q._level=1)):(b&&(q._level=0),h[q.id]=t)}}for(;0!=d.length;)if(q=d.shift(),
|
||||
c.push(q),delete e[q.id],q.outputs)for(k=0;k<q.outputs.length;k++)if(a=q.outputs[k],null!=a&&null!=a.links&&0!=a.links.length)for(r=0;r<a.links.length;r++)(n=this.links[a.links[r]])&&!f[n.id]&&(t=this.getNodeById(n.target_id),null==t?f[n.id]=!0:(b&&(!t._level||t._level<=q._level)&&(t._level=q._level+1),f[n.id]=!0,--h[t.id],0==h[t.id]&&d.push(t)));for(k in e)c.push(e[k]);c.length!=this._nodes.length&&g.debug&&console.warn("something went wrong, nodes missing");n=c.length;for(k=0;k<n;++k)c[k].order=
|
||||
k;c=c.sort(function(a,b){var c=a.constructor.priority||a.priority||0,d=b.constructor.priority||b.priority||0;return c==d?a.order-b.order:c-d});for(k=0;k<n;++k)c[k].order=k;return c};v.prototype.getAncestors=function(a){for(var b=[],c=[a],d={};c.length;){var e=c.shift();if(e.inputs){d[e.id]||e==a||(d[e.id]=!0,b.push(e));for(var f=0;f<e.inputs.length;++f){var h=e.getInputNode(f);h&&-1==b.indexOf(h)&&c.push(h)}}}b.sort(function(a,b){return a.order-b.order});return b};v.prototype.arrange=function(a){a=
|
||||
a||100;for(var b=this.computeExecutionOrder(!1,!0),c=[],d=0;d<b.length;++d){var e=b[d],f=e._level||1;c[f]||(c[f]=[]);c[f].push(e)}b=a;for(d=0;d<c.length;++d)if(f=c[d]){for(var h=100,k=a+g.NODE_TITLE_HEIGHT,n=0;n<f.length;++n)e=f[n],e.pos[0]=b,e.pos[1]=k,e.size[0]>h&&(h=e.size[0]),k+=e.size[1]+a+g.NODE_TITLE_HEIGHT;b+=h+a}this.setDirtyCanvas(!0,!0)};v.prototype.getTime=function(){return this.globaltime};v.prototype.getFixedTime=function(){return this.fixedtime};v.prototype.getElapsedTime=function(){return this.elapsed_time};
|
||||
v.prototype.sendEventToAllNodes=function(a,b,c){c=c||g.ALWAYS;var d=this._nodes_in_order?this._nodes_in_order:this._nodes;if(d)for(var e=0,f=d.length;e<f;++e){var h=d[e];if(h.constructor===g.Subgraph&&"onExecute"!=a)h.mode==c&&h.sendEventToAllNodes(a,b,c);else if(h[a]&&h.mode==c)if(void 0===b)h[a]();else if(b&&b.constructor===Array)h[a].apply(h,b);else h[a](b)}};v.prototype.sendActionToCanvas=function(a,b){if(this.list_of_graphcanvas)for(var c=0;c<this.list_of_graphcanvas.length;++c){var d=this.list_of_graphcanvas[c];
|
||||
d[a]&&d[a].apply(d,b)}};v.prototype.add=function(a,b){if(a)if(a.constructor===z)this._groups.push(a),this.setDirtyCanvas(!0),this.change(),a.graph=this,this._version++;else{-1!=a.id&&null!=this._nodes_by_id[a.id]&&(console.warn("LiteGraph: there is already a node with this ID, changing it"),a.id=++this.last_node_id);if(this._nodes.length>=g.MAX_NUMBER_OF_NODES)throw"LiteGraph: max number of nodes in a graph reached";null==a.id||-1==a.id?a.id=++this.last_node_id:this.last_node_id<a.id&&(this.last_node_id=
|
||||
a.id);a.graph=this;this._version++;this._nodes.push(a);this._nodes_by_id[a.id]=a;if(a.onAdded)a.onAdded(this);this.config.align_to_grid&&a.alignToGrid();b||this.updateExecutionOrder();if(this.onNodeAdded)this.onNodeAdded(a);this.setDirtyCanvas(!0);this.change();return a}};v.prototype.remove=function(a){if(a.constructor===g.LGraphGroup){var b=this._groups.indexOf(a);-1!=b&&this._groups.splice(b,1);a.graph=null;this._version++;this.setDirtyCanvas(!0,!0);this.change()}else if(null!=this._nodes_by_id[a.id]&&
|
||||
!a.ignore_remove){this.beforeChange();if(a.inputs)for(b=0;b<a.inputs.length;b++){var c=a.inputs[b];null!=c.link&&a.disconnectInput(b)}if(a.outputs)for(b=0;b<a.outputs.length;b++)c=a.outputs[b],null!=c.links&&c.links.length&&a.disconnectOutput(b);if(a.onRemoved)a.onRemoved();a.graph=null;this._version++;if(this.list_of_graphcanvas)for(b=0;b<this.list_of_graphcanvas.length;++b)c=this.list_of_graphcanvas[b],c.selected_nodes[a.id]&&delete c.selected_nodes[a.id],c.node_dragged==a&&(c.node_dragged=null);
|
||||
b=this._nodes.indexOf(a);-1!=b&&this._nodes.splice(b,1);delete this._nodes_by_id[a.id];if(this.onNodeRemoved)this.onNodeRemoved(a);this.sendActionToCanvas("checkPanels");this.setDirtyCanvas(!0,!0);this.afterChange();this.change();this.updateExecutionOrder()}};v.prototype.getNodeById=function(a){return null==a?null:this._nodes_by_id[a]};v.prototype.findNodesByClass=function(a,b){b=b||[];for(var c=b.length=0,d=this._nodes.length;c<d;++c)this._nodes[c].constructor===a&&b.push(this._nodes[c]);return b};
|
||||
v.prototype.findNodesByType=function(a,b){a=a.toLowerCase();b=b||[];for(var c=b.length=0,d=this._nodes.length;c<d;++c)this._nodes[c].type.toLowerCase()==a&&b.push(this._nodes[c]);return b};v.prototype.findNodeByTitle=function(a){for(var b=0,c=this._nodes.length;b<c;++b)if(this._nodes[b].title==a)return this._nodes[b];return null};v.prototype.findNodesByTitle=function(a){for(var b=[],c=0,d=this._nodes.length;c<d;++c)this._nodes[c].title==a&&b.push(this._nodes[c]);return b};v.prototype.getNodeOnPos=
|
||||
function(a,b,c,d){c=c||this._nodes;for(var e=c.length-1;0<=e;e--){var f=c[e];if(f.isPointInside(a,b,d))return f}return null};v.prototype.getGroupOnPos=function(a,b){for(var c=this._groups.length-1;0<=c;c--){var d=this._groups[c];if(d.isPointInside(a,b,2,!0))return d}return null};v.prototype.checkNodeTypes=function(){for(var a=0;a<this._nodes.length;a++){var b=this._nodes[a];if(b.constructor!=g.registered_node_types[b.type]){console.log("node being replaced by newer version: "+b.type);var c=g.createNode(b.type);
|
||||
this._nodes[a]=c;c.configure(b.serialize());c.graph=this;this._nodes_by_id[c.id]=c;b.inputs&&(c.inputs=b.inputs.concat());b.outputs&&(c.outputs=b.outputs.concat())}}this.updateExecutionOrder()};v.prototype.onAction=function(a,b,c){this._input_nodes=this.findNodesByClass(g.GraphInput,this._input_nodes);for(var d=0;d<this._input_nodes.length;++d){var e=this._input_nodes[d];if(e.properties.name==a){e.actionDo(a,b,c);break}}};v.prototype.trigger=function(a,b){if(this.onTrigger)this.onTrigger(a,b)};v.prototype.addInput=
|
||||
function(a,b,c){if(!this.inputs[a]){this.beforeChange();this.inputs[a]={name:a,type:b,value:c};this._version++;this.afterChange();if(this.onInputAdded)this.onInputAdded(a,b);if(this.onInputsOutputsChange)this.onInputsOutputsChange()}};v.prototype.setInputData=function(a,b){if(a=this.inputs[a])a.value=b};v.prototype.getInputData=function(a){return(a=this.inputs[a])?a.value:null};v.prototype.renameInput=function(a,b){if(b!=a){if(!this.inputs[a])return!1;if(this.inputs[b])return console.error("there is already one input with that name"),
|
||||
!1}catch(q){this.errors_in_execution=!0;if(g.throw_errors)throw q;g.debug&&console.log("Error during execution: "+q);this.stop()}a=g.getTime();d=a-d;0==d&&(d=1);this.execution_time=.001*d;this.globaltime+=.001*d;this.iteration+=1;this.elapsed_time=.001*(a-this.last_update_time);this.last_update_time=a;this.nodes_executing=[];this.nodes_actioning=[];this.nodes_executedAction=[]}};v.prototype.updateExecutionOrder=function(){this._nodes_in_order=this.computeExecutionOrder(!1);this._nodes_executable=
|
||||
[];for(var a=0;a<this._nodes_in_order.length;++a)this._nodes_in_order[a].onExecute&&this._nodes_executable.push(this._nodes_in_order[a])};v.prototype.computeExecutionOrder=function(a,b){for(var c=[],d=[],e={},f={},h={},k=0,q=this._nodes.length;k<q;++k){var p=this._nodes[k];if(!a||p.onExecute){e[p.id]=p;var t=0;if(p.inputs)for(var n=0,m=p.inputs.length;n<m;n++)p.inputs[n]&&null!=p.inputs[n].link&&(t+=1);0==t?(d.push(p),b&&(p._level=1)):(b&&(p._level=0),h[p.id]=t)}}for(;0!=d.length;)if(p=d.shift(),
|
||||
c.push(p),delete e[p.id],p.outputs)for(k=0;k<p.outputs.length;k++)if(a=p.outputs[k],null!=a&&null!=a.links&&0!=a.links.length)for(n=0;n<a.links.length;n++)(q=this.links[a.links[n]])&&!f[q.id]&&(t=this.getNodeById(q.target_id),null==t?f[q.id]=!0:(b&&(!t._level||t._level<=p._level)&&(t._level=p._level+1),f[q.id]=!0,--h[t.id],0==h[t.id]&&d.push(t)));for(k in e)c.push(e[k]);c.length!=this._nodes.length&&g.debug&&console.warn("something went wrong, nodes missing");q=c.length;for(k=0;k<q;++k)c[k].order=
|
||||
k;c=c.sort(function(a,b){var c=a.constructor.priority||a.priority||0,d=b.constructor.priority||b.priority||0;return c==d?a.order-b.order:c-d});for(k=0;k<q;++k)c[k].order=k;return c};v.prototype.getAncestors=function(a){for(var b=[],c=[a],d={};c.length;){var e=c.shift();if(e.inputs){d[e.id]||e==a||(d[e.id]=!0,b.push(e));for(var f=0;f<e.inputs.length;++f){var h=e.getInputNode(f);h&&-1==b.indexOf(h)&&c.push(h)}}}b.sort(function(a,b){return a.order-b.order});return b};v.prototype.arrange=function(a,b){a=
|
||||
a||100;for(var c=this.computeExecutionOrder(!1,!0),d=[],e=0;e<c.length;++e){var f=c[e],h=f._level||1;d[h]||(d[h]=[]);d[h].push(f)}c=a;for(e=0;e<d.length;++e)if(h=d[e]){for(var k=100,q=a+g.NODE_TITLE_HEIGHT,p=0;p<h.length;++p){f=h[p];f.pos[0]=b==g.VERTICAL_LAYOUT?q:c;f.pos[1]=b==g.VERTICAL_LAYOUT?c:q;var t=b==g.VERTICAL_LAYOUT?1:0;f.size[t]>k&&(k=f.size[t]);q+=f.size[b==g.VERTICAL_LAYOUT?0:1]+a+g.NODE_TITLE_HEIGHT}c+=k+a}this.setDirtyCanvas(!0,!0)};v.prototype.getTime=function(){return this.globaltime};
|
||||
v.prototype.getFixedTime=function(){return this.fixedtime};v.prototype.getElapsedTime=function(){return this.elapsed_time};v.prototype.sendEventToAllNodes=function(a,b,c){c=c||g.ALWAYS;var d=this._nodes_in_order?this._nodes_in_order:this._nodes;if(d)for(var e=0,f=d.length;e<f;++e){var h=d[e];if(h.constructor===g.Subgraph&&"onExecute"!=a)h.mode==c&&h.sendEventToAllNodes(a,b,c);else if(h[a]&&h.mode==c)if(void 0===b)h[a]();else if(b&&b.constructor===Array)h[a].apply(h,b);else h[a](b)}};v.prototype.sendActionToCanvas=
|
||||
function(a,b){if(this.list_of_graphcanvas)for(var c=0;c<this.list_of_graphcanvas.length;++c){var d=this.list_of_graphcanvas[c];d[a]&&d[a].apply(d,b)}};v.prototype.add=function(a,b){if(a)if(a.constructor===z)this._groups.push(a),this.setDirtyCanvas(!0),this.change(),a.graph=this,this._version++;else{-1!=a.id&&null!=this._nodes_by_id[a.id]&&(console.warn("LiteGraph: there is already a node with this ID, changing it"),a.id=++this.last_node_id);if(this._nodes.length>=g.MAX_NUMBER_OF_NODES)throw"LiteGraph: max number of nodes in a graph reached";
|
||||
null==a.id||-1==a.id?a.id=++this.last_node_id:this.last_node_id<a.id&&(this.last_node_id=a.id);a.graph=this;this._version++;this._nodes.push(a);this._nodes_by_id[a.id]=a;if(a.onAdded)a.onAdded(this);this.config.align_to_grid&&a.alignToGrid();b||this.updateExecutionOrder();if(this.onNodeAdded)this.onNodeAdded(a);this.setDirtyCanvas(!0);this.change();return a}};v.prototype.remove=function(a){if(a.constructor===g.LGraphGroup){var b=this._groups.indexOf(a);-1!=b&&this._groups.splice(b,1);a.graph=null;
|
||||
this._version++;this.setDirtyCanvas(!0,!0);this.change()}else if(null!=this._nodes_by_id[a.id]&&!a.ignore_remove){this.beforeChange();if(a.inputs)for(b=0;b<a.inputs.length;b++){var c=a.inputs[b];null!=c.link&&a.disconnectInput(b)}if(a.outputs)for(b=0;b<a.outputs.length;b++)c=a.outputs[b],null!=c.links&&c.links.length&&a.disconnectOutput(b);if(a.onRemoved)a.onRemoved();a.graph=null;this._version++;if(this.list_of_graphcanvas)for(b=0;b<this.list_of_graphcanvas.length;++b)c=this.list_of_graphcanvas[b],
|
||||
c.selected_nodes[a.id]&&delete c.selected_nodes[a.id],c.node_dragged==a&&(c.node_dragged=null);b=this._nodes.indexOf(a);-1!=b&&this._nodes.splice(b,1);delete this._nodes_by_id[a.id];if(this.onNodeRemoved)this.onNodeRemoved(a);this.sendActionToCanvas("checkPanels");this.setDirtyCanvas(!0,!0);this.afterChange();this.change();this.updateExecutionOrder()}};v.prototype.getNodeById=function(a){return null==a?null:this._nodes_by_id[a]};v.prototype.findNodesByClass=function(a,b){b=b||[];for(var c=b.length=
|
||||
0,d=this._nodes.length;c<d;++c)this._nodes[c].constructor===a&&b.push(this._nodes[c]);return b};v.prototype.findNodesByType=function(a,b){a=a.toLowerCase();b=b||[];for(var c=b.length=0,d=this._nodes.length;c<d;++c)this._nodes[c].type.toLowerCase()==a&&b.push(this._nodes[c]);return b};v.prototype.findNodeByTitle=function(a){for(var b=0,c=this._nodes.length;b<c;++b)if(this._nodes[b].title==a)return this._nodes[b];return null};v.prototype.findNodesByTitle=function(a){for(var b=[],c=0,d=this._nodes.length;c<
|
||||
d;++c)this._nodes[c].title==a&&b.push(this._nodes[c]);return b};v.prototype.getNodeOnPos=function(a,b,c,d){c=c||this._nodes;for(var e=c.length-1;0<=e;e--){var f=c[e];if(f.isPointInside(a,b,d))return f}return null};v.prototype.getGroupOnPos=function(a,b){for(var c=this._groups.length-1;0<=c;c--){var d=this._groups[c];if(d.isPointInside(a,b,2,!0))return d}return null};v.prototype.checkNodeTypes=function(){for(var a=0;a<this._nodes.length;a++){var b=this._nodes[a];if(b.constructor!=g.registered_node_types[b.type]){console.log("node being replaced by newer version: "+
|
||||
b.type);var c=g.createNode(b.type);this._nodes[a]=c;c.configure(b.serialize());c.graph=this;this._nodes_by_id[c.id]=c;b.inputs&&(c.inputs=b.inputs.concat());b.outputs&&(c.outputs=b.outputs.concat())}}this.updateExecutionOrder()};v.prototype.onAction=function(a,b,c){this._input_nodes=this.findNodesByClass(g.GraphInput,this._input_nodes);for(var d=0;d<this._input_nodes.length;++d){var e=this._input_nodes[d];if(e.properties.name==a){e.actionDo(a,b,c);break}}};v.prototype.trigger=function(a,b){if(this.onTrigger)this.onTrigger(a,
|
||||
b)};v.prototype.addInput=function(a,b,c){if(!this.inputs[a]){this.beforeChange();this.inputs[a]={name:a,type:b,value:c};this._version++;this.afterChange();if(this.onInputAdded)this.onInputAdded(a,b);if(this.onInputsOutputsChange)this.onInputsOutputsChange()}};v.prototype.setInputData=function(a,b){if(a=this.inputs[a])a.value=b};v.prototype.getInputData=function(a){return(a=this.inputs[a])?a.value:null};v.prototype.renameInput=function(a,b){if(b!=a){if(!this.inputs[a])return!1;if(this.inputs[b])return console.error("there is already one input with that name"),
|
||||
!1;this.inputs[b]=this.inputs[a];delete this.inputs[a];this._version++;if(this.onInputRenamed)this.onInputRenamed(a,b);if(this.onInputsOutputsChange)this.onInputsOutputsChange()}};v.prototype.changeInputType=function(a,b){if(!this.inputs[a])return!1;if(!this.inputs[a].type||String(this.inputs[a].type).toLowerCase()!=String(b).toLowerCase())if(this.inputs[a].type=b,this._version++,this.onInputTypeChanged)this.onInputTypeChanged(a,b)};v.prototype.removeInput=function(a){if(!this.inputs[a])return!1;
|
||||
delete this.inputs[a];this._version++;if(this.onInputRemoved)this.onInputRemoved(a);if(this.onInputsOutputsChange)this.onInputsOutputsChange();return!0};v.prototype.addOutput=function(a,b,c){this.outputs[a]={name:a,type:b,value:c};this._version++;if(this.onOutputAdded)this.onOutputAdded(a,b);if(this.onInputsOutputsChange)this.onInputsOutputsChange()};v.prototype.setOutputData=function(a,b){if(a=this.outputs[a])a.value=b};v.prototype.getOutputData=function(a){return(a=this.outputs[a])?a.value:null};
|
||||
v.prototype.renameOutput=function(a,b){if(!this.outputs[a])return!1;if(this.outputs[b])return console.error("there is already one output with that name"),!1;this.outputs[b]=this.outputs[a];delete this.outputs[a];this._version++;if(this.onOutputRenamed)this.onOutputRenamed(a,b);if(this.onInputsOutputsChange)this.onInputsOutputsChange()};v.prototype.changeOutputType=function(a,b){if(!this.outputs[a])return!1;if(!this.outputs[a].type||String(this.outputs[a].type).toLowerCase()!=String(b).toLowerCase())if(this.outputs[a].type=
|
||||
@@ -68,67 +68,67 @@ last_link_id:this.last_link_id,nodes:a,links:c,groups:f,config:this.config,extra
|
||||
c=!1;this._nodes=[];if(b){d=0;for(e=b.length;d<e;++d){f=b[d];var h=g.createNode(f.type,f.title);h||(g.debug&&console.log("Node not found or has errors: "+f.type),h=new l,h.last_serialization=f,c=h.has_errors=!0);h.id=f.id;this.add(h,!0)}d=0;for(e=b.length;d<e;++d)f=b[d],(h=this.getNodeById(f.id))&&h.configure(f)}this._groups.length=0;if(a.groups)for(d=0;d<a.groups.length;++d)b=new g.LGraphGroup,b.configure(a.groups[d]),this.add(b);this.updateExecutionOrder();this.extra=a.extra||{};if(this.onConfigure)this.onConfigure(a);
|
||||
this._version++;this.setDirtyCanvas(!0,!0);return c}};v.prototype.load=function(a,b){var c=this;if(a.constructor===File||a.constructor===Blob){var d=new FileReader;d.addEventListener("load",function(a){a=JSON.parse(a.target.result);c.configure(a);b&&b()});d.readAsText(a)}else{var e=new XMLHttpRequest;e.open("GET",a,!0);e.send(null);e.onload=function(a){200!==e.status?console.error("Error loading graph:",e.status,e.response):(a=JSON.parse(e.response),c.configure(a),b&&b())};e.onerror=function(a){console.error("Error loading graph:",
|
||||
a)}}};v.prototype.onNodeTrace=function(a,b,c){};w.prototype.configure=function(a){a.constructor===Array?(this.id=a[0],this.origin_id=a[1],this.origin_slot=a[2],this.target_id=a[3],this.target_slot=a[4],this.type=a[5]):(this.id=a.id,this.type=a.type,this.origin_id=a.origin_id,this.origin_slot=a.origin_slot,this.target_id=a.target_id,this.target_slot=a.target_slot)};w.prototype.serialize=function(){return[this.id,this.origin_id,this.origin_slot,this.target_id,this.target_slot,this.type]};g.LLink=w;
|
||||
p.LGraphNode=g.LGraphNode=l;l.prototype._ctor=function(a){this.title=a||"Unnamed";this.size=[g.NODE_WIDTH,60];this.graph=null;this._pos=new Float32Array(10,10);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});this.id=-1;this.type=null;this.inputs=[];this.outputs=[];this.connections=[];this.properties={};this.properties_info=[];this.flags={}};l.prototype.configure=function(a){this.graph&&this.graph._version++;
|
||||
for(var b in a)if("properties"==b)for(var c in a.properties){if(this.properties[c]=a.properties[c],this.onPropertyChanged)this.onPropertyChanged(c,a.properties[c])}else null!=a[b]&&("object"==typeof a[b]?this[b]&&this[b].configure?this[b].configure(a[b]):this[b]=g.cloneObject(a[b],this[b]):this[b]=a[b]);a.title||(this.title=this.constructor.title);if(this.onConnectionsChange){if(this.inputs)for(c=0;c<this.inputs.length;++c){b=this.inputs[c];var d=this.graph?this.graph.links[b.link]:null;this.onConnectionsChange(g.INPUT,
|
||||
c,!0,d,b)}if(this.outputs)for(c=0;c<this.outputs.length;++c){var e=this.outputs[c];if(e.links)for(b=0;b<e.links.length;++b)d=this.graph?this.graph.links[e.links[b]]:null,this.onConnectionsChange(g.OUTPUT,c,!0,d,e)}}if(this.widgets){for(c=0;c<this.widgets.length;++c)(b=this.widgets[c])&&b.options&&b.options.property&&this.properties[b.options.property]&&(b.value=JSON.parse(JSON.stringify(this.properties[b.options.property])));if(a.widgets_values)for(c=0;c<a.widgets_values.length;++c)this.widgets[c]&&
|
||||
(this.widgets[c].value=a.widgets_values[c])}if(this.onConfigure)this.onConfigure(a)};l.prototype.serialize=function(){var a={id:this.id,type:this.type,pos:this.pos,size:this.size,flags:g.cloneObject(this.flags),order:this.order,mode:this.mode};if(this.constructor===l&&this.last_serialization)return this.last_serialization;this.inputs&&(a.inputs=this.inputs);if(this.outputs){for(var b=0;b<this.outputs.length;b++)delete this.outputs[b]._data;a.outputs=this.outputs}this.title&&this.title!=this.constructor.title&&
|
||||
(a.title=this.title);this.properties&&(a.properties=g.cloneObject(this.properties));if(this.widgets&&this.serialize_widgets)for(a.widgets_values=[],b=0;b<this.widgets.length;++b)a.widgets_values[b]=this.widgets[b]?this.widgets[b].value:null;a.type||(a.type=this.constructor.type);this.color&&(a.color=this.color);this.bgcolor&&(a.bgcolor=this.bgcolor);this.boxcolor&&(a.boxcolor=this.boxcolor);this.shape&&(a.shape=this.shape);this.onSerialize&&this.onSerialize(a)&&console.warn("node onSerialize shouldnt return anything, data should be stored in the object pass in the first parameter");
|
||||
return a};l.prototype.clone=function(){var a=g.createNode(this.type);if(!a)return null;var b=g.cloneObject(this.serialize());if(b.inputs)for(var c=0;c<b.inputs.length;++c)b.inputs[c].link=null;if(b.outputs)for(c=0;c<b.outputs.length;++c)b.outputs[c].links&&(b.outputs[c].links.length=0);delete b.id;a.configure(b);return a};l.prototype.toString=function(){return JSON.stringify(this.serialize())};l.prototype.getTitle=function(){return this.title||this.constructor.title};l.prototype.setProperty=function(a,
|
||||
b){this.properties||(this.properties={});if(b!==this.properties[a]){var c=this.properties[a];this.properties[a]=b;this.onPropertyChanged&&!1===this.onPropertyChanged(a,b,c)&&(this.properties[a]=c);if(this.widgets)for(c=0;c<this.widgets.length;++c){var d=this.widgets[c];if(d&&d.options.property==a){d.value=b;break}}}};l.prototype.setOutputData=function(a,b){if(this.outputs&&!(-1==a||a>=this.outputs.length)){var c=this.outputs[a];if(c&&(c._data=b,this.outputs[a].links))for(c=0;c<this.outputs[a].links.length;c++){var d=
|
||||
this.graph.links[this.outputs[a].links[c]];d&&(d.data=b)}}};l.prototype.setOutputDataType=function(a,b){if(this.outputs&&!(-1==a||a>=this.outputs.length)){var c=this.outputs[a];if(c&&(c.type=b,this.outputs[a].links))for(c=0;c<this.outputs[a].links.length;c++)this.graph.links[this.outputs[a].links[c]].type=b}};l.prototype.getInputData=function(a,b){if(this.inputs&&!(a>=this.inputs.length||null==this.inputs[a].link)){a=this.graph.links[this.inputs[a].link];if(!a)return null;if(!b)return a.data;b=this.graph.getNodeById(a.origin_id);
|
||||
if(!b)return a.data;if(b.updateOutputData)b.updateOutputData(a.origin_slot);else if(b.onExecute)b.onExecute();return a.data}};l.prototype.getInputDataType=function(a){if(!this.inputs||a>=this.inputs.length||null==this.inputs[a].link)return null;a=this.graph.links[this.inputs[a].link];if(!a)return null;var b=this.graph.getNodeById(a.origin_id);return b?(a=b.outputs[a.origin_slot])?a.type:null:a.type};l.prototype.getInputDataByName=function(a,b){a=this.findInputSlot(a);return-1==a?null:this.getInputData(a,
|
||||
b)};l.prototype.isInputConnected=function(a){return this.inputs?a<this.inputs.length&&null!=this.inputs[a].link:!1};l.prototype.getInputInfo=function(a){return this.inputs?a<this.inputs.length?this.inputs[a]:null:null};l.prototype.getInputLink=function(a){return this.inputs?a<this.inputs.length?this.graph.links[this.inputs[a].link]:null:null};l.prototype.getInputNode=function(a){if(!this.inputs||a>=this.inputs.length)return null;a=this.inputs[a];return a&&null!==a.link?(a=this.graph.links[a.link])?
|
||||
this.graph.getNodeById(a.origin_id):null:null};l.prototype.getInputOrProperty=function(a){if(!this.inputs||!this.inputs.length)return this.properties?this.properties[a]:null;for(var b=0,c=this.inputs.length;b<c;++b){var d=this.inputs[b];if(a==d.name&&null!=d.link&&(d=this.graph.links[d.link]))return d.data}return this.properties[a]};l.prototype.getOutputData=function(a){return!this.outputs||a>=this.outputs.length?null:this.outputs[a]._data};l.prototype.getOutputInfo=function(a){return this.outputs?
|
||||
a<this.outputs.length?this.outputs[a]:null:null};l.prototype.isOutputConnected=function(a){return this.outputs?a<this.outputs.length&&this.outputs[a].links&&this.outputs[a].links.length:!1};l.prototype.isAnyOutputConnected=function(){if(!this.outputs)return!1;for(var a=0;a<this.outputs.length;++a)if(this.outputs[a].links&&this.outputs[a].links.length)return!0;return!1};l.prototype.getOutputNodes=function(a){if(!this.outputs||0==this.outputs.length||a>=this.outputs.length)return null;a=this.outputs[a];
|
||||
if(!a.links||0==a.links.length)return null;for(var b=[],c=0;c<a.links.length;c++){var d=this.graph.links[a.links[c]];d&&(d=this.graph.getNodeById(d.target_id))&&b.push(d)}return b};l.prototype.addOnTriggerInput=function(){var a=this.findInputSlot("onTrigger");return-1==a?(this.addInput("onTrigger",g.EVENT,{optional:!0,nameLocked:!0}),this.findInputSlot("onTrigger")):a};l.prototype.addOnExecutedOutput=function(){var a=this.findOutputSlot("onExecuted");return-1==a?(this.addOutput("onExecuted",g.ACTION,
|
||||
{optional:!0,nameLocked:!0}),this.findOutputSlot("onExecuted")):a};l.prototype.onAfterExecuteNode=function(a,b){var c=this.findOutputSlot("onExecuted");-1!=c&&this.triggerSlot(c,a,null,b)};l.prototype.changeMode=function(a){switch(a){case g.ON_EVENT:break;case g.ON_TRIGGER:this.addOnTriggerInput();this.addOnExecutedOutput();break;case g.NEVER:break;case g.ALWAYS:break;case g.ON_REQUEST:break;default:return!1}this.mode=a;return!0};l.prototype.doExecute=function(a,b){b=b||{};this.onExecute&&(b.action_call||
|
||||
(b.action_call=this.id+"_exec_"+Math.floor(9999*Math.random())),this.graph.nodes_executing[this.id]=!0,this.onExecute(a,b),this.graph.nodes_executing[this.id]=!1,this.exec_version=this.graph.iteration,b&&b.action_call&&(this.action_call=b.action_call,this.graph.nodes_executedAction[this.id]=b.action_call));this.execute_triggered=2;if(this.onAfterExecuteNode)this.onAfterExecuteNode(a,b)};l.prototype.actionDo=function(a,b,c){c=c||{};this.onAction&&(c.action_call||(c.action_call=this.id+"_"+(a?a:"action")+
|
||||
"_"+Math.floor(9999*Math.random())),this.graph.nodes_actioning[this.id]=a?a:"actioning",this.onAction(a,b,c),this.graph.nodes_actioning[this.id]=!1,c&&c.action_call&&(this.action_call=c.action_call,this.graph.nodes_executedAction[this.id]=c.action_call));this.action_triggered=2;if(this.onAfterExecuteNode)this.onAfterExecuteNode(b,c)};l.prototype.trigger=function(a,b,c){if(this.outputs&&this.outputs.length){this.graph&&(this.graph._last_trigger_time=g.getTime());for(var d=0;d<this.outputs.length;++d){var e=
|
||||
this.outputs[d];!e||e.type!==g.EVENT||a&&e.name!=a||this.triggerSlot(d,b,null,c)}}};l.prototype.triggerSlot=function(a,b,c,d){d=d||{};if(this.outputs&&(a=this.outputs[a])&&(a=a.links)&&a.length){this.graph&&(this.graph._last_trigger_time=g.getTime());for(var e=0;e<a.length;++e){var f=a[e];if(null==c||c==f){var h=this.graph.links[a[e]];h&&(h._last_time=g.getTime(),f=this.graph.getNodeById(h.target_id))&&(f.mode===g.ON_TRIGGER?(d.action_call||(d.action_call=this.id+"_trigg_"+Math.floor(9999*Math.random())),
|
||||
f.onExecute&&f.doExecute(b,d)):f.onAction&&(d.action_call||(d.action_call=this.id+"_act_"+Math.floor(9999*Math.random())),h=f.inputs[h.target_slot],f.actionDo(h.name,b,d)))}}}};l.prototype.clearTriggeredSlot=function(a,b){if(this.outputs&&(a=this.outputs[a])&&(a=a.links)&&a.length)for(var c=0;c<a.length;++c){var d=a[c];if(null==b||b==d)if(d=this.graph.links[a[c]])d._last_time=0}};l.prototype.setSize=function(a){this.size=a;if(this.onResize)this.onResize(this.size)};l.prototype.addProperty=function(a,
|
||||
b,c,d){c={name:a,type:c,default_value:b};if(d)for(var e in d)c[e]=d[e];this.properties_info||(this.properties_info=[]);this.properties_info.push(c);this.properties||(this.properties={});this.properties[a]=b;return c};l.prototype.addOutput=function(a,b,c){a={name:a,type:b,links:null};if(c)for(var d in c)a[d]=c[d];this.outputs||(this.outputs=[]);this.outputs.push(a);if(this.onOutputAdded)this.onOutputAdded(a);g.auto_load_slot_types&&g.registerNodeAndSlotType(this,b,!0);this.setSize(this.computeSize());
|
||||
this.setDirtyCanvas(!0,!0);return a};l.prototype.addOutputs=function(a){for(var b=0;b<a.length;++b){var c=a[b],d={name:c[0],type:c[1],link:null};if(a[2])for(var e in c[2])d[e]=c[2][e];this.outputs||(this.outputs=[]);this.outputs.push(d);if(this.onOutputAdded)this.onOutputAdded(d);g.auto_load_slot_types&&g.registerNodeAndSlotType(this,c[1],!0)}this.setSize(this.computeSize());this.setDirtyCanvas(!0,!0)};l.prototype.removeOutput=function(a){this.disconnectOutput(a);this.outputs.splice(a,1);for(var b=
|
||||
a;b<this.outputs.length;++b)if(this.outputs[b]&&this.outputs[b].links)for(var c=this.outputs[b].links,d=0;d<c.length;++d){var e=this.graph.links[c[d]];e&&--e.origin_slot}this.setSize(this.computeSize());if(this.onOutputRemoved)this.onOutputRemoved(a);this.setDirtyCanvas(!0,!0)};l.prototype.addInput=function(a,b,c){b=b||0;a={name:a,type:b,link:null};if(c)for(var d in c)a[d]=c[d];this.inputs||(this.inputs=[]);this.inputs.push(a);this.setSize(this.computeSize());if(this.onInputAdded)this.onInputAdded(a);
|
||||
g.registerNodeAndSlotType(this,b);this.setDirtyCanvas(!0,!0);return a};l.prototype.addInputs=function(a){for(var b=0;b<a.length;++b){var c=a[b],d={name:c[0],type:c[1],link:null};if(a[2])for(var e in c[2])d[e]=c[2][e];this.inputs||(this.inputs=[]);this.inputs.push(d);if(this.onInputAdded)this.onInputAdded(d);g.registerNodeAndSlotType(this,c[1])}this.setSize(this.computeSize());this.setDirtyCanvas(!0,!0)};l.prototype.removeInput=function(a){this.disconnectInput(a);for(var b=this.inputs.splice(a,1),
|
||||
c=a;c<this.inputs.length;++c)if(this.inputs[c]){var d=this.graph.links[this.inputs[c].link];d&&--d.target_slot}this.setSize(this.computeSize());if(this.onInputRemoved)this.onInputRemoved(a,b[0]);this.setDirtyCanvas(!0,!0)};l.prototype.addConnection=function(a,b,c,d){a={name:a,type:b,pos:c,direction:d,links:null};this.connections.push(a);return a};l.prototype.computeSize=function(a){function b(a){return a?d*a.length*.6:0}if(this.constructor.size)return this.constructor.size.concat();var c=Math.max(this.inputs?
|
||||
this.inputs.length:1,this.outputs?this.outputs.length:1);a=a||new Float32Array([0,0]);c=Math.max(c,1);var d=g.NODE_TEXT_SIZE,e=b(this.title),f=0,h=0;if(this.inputs)for(var k=0,n=this.inputs.length;k<n;++k){var q=this.inputs[k];q=q.label||q.name||"";q=b(q);f<q&&(f=q)}if(this.outputs)for(k=0,n=this.outputs.length;k<n;++k)q=this.outputs[k],q=q.label||q.name||"",q=b(q),h<q&&(h=q);a[0]=Math.max(f+h+10,e);a[0]=Math.max(a[0],g.NODE_WIDTH);this.widgets&&this.widgets.length&&(a[0]=Math.max(a[0],1.5*g.NODE_WIDTH));
|
||||
a[1]=(this.constructor.slot_start_y||0)+c*g.NODE_SLOT_HEIGHT;c=0;if(this.widgets&&this.widgets.length){k=0;for(n=this.widgets.length;k<n;++k)c=this.widgets[k].computeSize?c+(this.widgets[k].computeSize(a[0])[1]+4):c+(g.NODE_WIDGET_HEIGHT+4);c+=8}a[1]=this.widgets_up?Math.max(a[1],c):null!=this.widgets_start_y?Math.max(a[1],c+this.widgets_start_y):a[1]+c;this.constructor.min_height&&a[1]<this.constructor.min_height&&(a[1]=this.constructor.min_height);a[1]+=6;return a};l.prototype.getPropertyInfo=function(a){var b=
|
||||
null;if(this.properties_info)for(var c=0;c<this.properties_info.length;++c)if(this.properties_info[c].name==a){b=this.properties_info[c];break}this.constructor["@"+a]&&(b=this.constructor["@"+a]);this.constructor.widgets_info&&this.constructor.widgets_info[a]&&(b=this.constructor.widgets_info[a]);!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};l.prototype.addWidget=function(a,b,c,d,e){this.widgets||
|
||||
(this.widgets=[]);!e&&d&&d.constructor===Object&&(e=d,d=null);e&&e.constructor===String&&(e={property:e});d&&d.constructor===String&&(e||(e={}),e.property=d,d=null);d&&d.constructor!==Function&&(console.warn("addWidget: callback must be a function"),d=null);b={type:a.toLowerCase(),name:b,value:c,callback:d,options:e||{}};void 0!==b.options.y&&(b.y=b.options.y);d||b.options.callback||b.options.property||console.warn("LiteGraph addWidget(...) without a callback or property assigned");if("combo"==a&&
|
||||
!b.options.values)throw"LiteGraph addWidget('combo',...) requires to pass values in options: { values:['red','blue'] }";this.widgets.push(b);this.setSize(this.computeSize());return b};l.prototype.addCustomWidget=function(a){this.widgets||(this.widgets=[]);this.widgets.push(a);return a};l.prototype.getBounding=function(a){a=a||new Float32Array(4);a[0]=this.pos[0]-4;a[1]=this.pos[1]-g.NODE_TITLE_HEIGHT;a[2]=this.size[0]+4;a[3]=this.flags.collapsed?g.NODE_TITLE_HEIGHT:this.size[1]+g.NODE_TITLE_HEIGHT;
|
||||
if(this.onBounding)this.onBounding(a);return a};l.prototype.isPointInside=function(a,b,c,d){c=c||0;var e=this.graph&&this.graph.isLive()?0:g.NODE_TITLE_HEIGHT;d&&(e=0);if(this.flags&&this.flags.collapsed){if(A(a,b,this.pos[0]-c,this.pos[1]-g.NODE_TITLE_HEIGHT-c,(this._collapsed_width||g.NODE_COLLAPSED_WIDTH)+2*c,g.NODE_TITLE_HEIGHT+2*c))return!0}else if(this.pos[0]-4-c<a&&this.pos[0]+this.size[0]+4+c>a&&this.pos[1]-e-c<b&&this.pos[1]+this.size[1]+c>b)return!0;return!1};l.prototype.getSlotInPosition=
|
||||
function(a,b){var c=new Float32Array(2);if(this.inputs)for(var d=0,e=this.inputs.length;d<e;++d){var f=this.inputs[d];this.getConnectionPos(!0,d,c);if(A(a,b,c[0]-10,c[1]-5,20,10))return{input:f,slot:d,link_pos:c}}if(this.outputs)for(d=0,e=this.outputs.length;d<e;++d)if(f=this.outputs[d],this.getConnectionPos(!1,d,c),A(a,b,c[0]-10,c[1]-5,20,10))return{output:f,slot:d,link_pos:c};return null};l.prototype.findInputSlot=function(a,b){if(!this.inputs)return-1;for(var c=0,d=this.inputs.length;c<d;++c)if(a==
|
||||
this.inputs[c].name)return b?this.inputs[c]:c;return-1};l.prototype.findOutputSlot=function(a,b){b=b||!1;if(!this.outputs)return-1;for(var c=0,d=this.outputs.length;c<d;++c)if(a==this.outputs[c].name)return b?this.outputs[c]:c;return-1};l.prototype.findInputSlotFree=function(a){a=a||{};a=Object.assign({returnObj:!1,typesNotAccepted:[]},a);if(!this.inputs)return-1;for(var b=0,c=this.inputs.length;b<c;++b)if(!(this.inputs[b].link&&null!=this.inputs[b].link||a.typesNotAccepted&&a.typesNotAccepted.includes&&
|
||||
a.typesNotAccepted.includes(this.inputs[b].type)))return a.returnObj?this.inputs[b]:b;return-1};l.prototype.findOutputSlotFree=function(a){a=a||{};a=Object.assign({returnObj:!1,typesNotAccepted:[]},a);if(!this.outputs)return-1;for(var b=0,c=this.outputs.length;b<c;++b)if(!(this.outputs[b].links&&null!=this.outputs[b].links||a.typesNotAccepted&&a.typesNotAccepted.includes&&a.typesNotAccepted.includes(this.outputs[b].type)))return a.returnObj?this.outputs[b]:b;return-1};l.prototype.findInputSlotByType=
|
||||
function(a,b,c,d){return this.findSlotByType(!0,a,b,c,d)};l.prototype.findOutputSlotByType=function(a,b,c,d){return this.findSlotByType(!1,a,b,c,d)};l.prototype.findSlotByType=function(a,b,c,d,e){c=c||!1;d=d||!1;e=e||!1;a=a?this.inputs:this.outputs;if(!a)return-1;if(""==b||"*"==b)b=0;for(var f=0,h=a.length;f<h;++f){var k=(b+"").toLowerCase().split(","),n="0"==a[f].type||"*"==a[f].type?"0":a[f].type;n=(n+"").toLowerCase().split(",");for(sI=0;sI<k.length;sI++)for(dI=0;dI<n.length;dI++)if("_event_"==
|
||||
k[sI]&&(k[sI]=g.EVENT),"_event_"==n[sI]&&(n[sI]=g.EVENT),"*"==k[sI]&&(k[sI]=0),"*"==n[sI]&&(n[sI]=0),!(k[sI]!=n[dI]||d&&a[f].links&&null!==a[f].links))return c?a[f]:f}if(d&&!e)for(f=0,h=a.length;f<h;++f)for(k=(b+"").toLowerCase().split(","),n="0"==a[f].type||"*"==a[f].type?"0":a[f].type,n=(n+"").toLowerCase().split(","),sI=0;sI<k.length;sI++)for(dI=0;dI<n.length;dI++)if("*"==k[sI]&&(k[sI]=0),"*"==n[sI]&&(n[sI]=0),k[sI]==n[dI])return c?a[f]:f;return-1};l.prototype.connectByType=function(a,b,c,d){d=
|
||||
d||{};d=Object.assign({createEventInCase:!0,firstFreeIfOutputGeneralInCase:!0,generalTypeInCase:!0},d);b&&b.constructor===Number&&(b=this.graph.getNodeById(b));e=b.findInputSlotByType(c,!1,!0);if(0<=e&&null!==e)return this.connect(a,b,e);if(d.createEventInCase&&c==g.EVENT)return this.connect(a,b,-1);if(d.generalTypeInCase){var e=b.findInputSlotByType(0,!1,!0,!0);if(0<=e)return this.connect(a,b,e)}if(d.firstFreeIfOutputGeneralInCase&&(0==c||"*"==c||""==c)&&(e=b.findInputSlotFree({typesNotAccepted:[g.EVENT]}),
|
||||
0<=e))return this.connect(a,b,e);console.debug("no way to connect type: ",c," to targetNODE ",b);return null};l.prototype.connectByTypeOutput=function(a,b,c,d){d=d||{};d=Object.assign({createEventInCase:!0,firstFreeIfInputGeneralInCase:!0,generalTypeInCase:!0},d);b&&b.constructor===Number&&(b=this.graph.getNodeById(b));e=b.findOutputSlotByType(c,!1,!0);if(0<=e&&null!==e)return b.connect(e,this,a);if(d.generalTypeInCase){var e=b.findOutputSlotByType(0,!1,!0,!0);if(0<=e)return b.connect(e,this,a)}if(d.createEventInCase&&
|
||||
c==g.EVENT&&g.do_add_triggers_slots)return e=b.addOnExecutedOutput(),b.connect(e,this,a);if(d.firstFreeIfInputGeneralInCase&&(0==c||"*"==c||""==c)&&(e=b.findOutputSlotFree({typesNotAccepted:[g.EVENT]}),0<=e))return b.connect(e,this,a);console.debug("no way to connect byOUT type: ",c," to sourceNODE ",b);return null};l.prototype.connect=function(a,b,c){c=c||0;if(!this.graph)return console.log("Connect: Error, node doesn't belong to any graph. Nodes must be added first to a graph before connecting them."),
|
||||
null;if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return g.debug&&console.log("Connect: Error, no slot of name "+a),null}else if(!this.outputs||a>=this.outputs.length)return g.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(c.constructor===String){if(c=b.findInputSlot(c),-1==c)return g.debug&&console.log("Connect: Error, no slot of name "+c),null}else if(c===
|
||||
g.EVENT)if(g.do_add_triggers_slots)b.changeMode(g.ON_TRIGGER),c=b.findInputSlot("onTrigger");else return null;else if(!b.inputs||c>=b.inputs.length)return g.debug&&console.log("Connect: Error, slot number not found"),null;var d=b.inputs[c],e=this.outputs[a];if(!this.outputs[a])return null;b.onBeforeConnectInput&&(c=b.onBeforeConnectInput(c));if(!1===c||null===c||!g.isValidConnection(e.type,d.type))return this.setDirtyCanvas(!1,!0),null;if(b.onConnectInput&&!1===b.onConnectInput(c,e.type,e,this,a)||
|
||||
this.onConnectOutput&&!1===this.onConnectOutput(a,d.type,d,b,c))return null;b.inputs[c]&&null!=b.inputs[c].link&&(this.graph.beforeChange(),b.disconnectInput(c,{doProcessChange:!1}));if(null!==e.links&&e.links.length)switch(e.type){case g.EVENT:g.allow_multi_output_for_events||(this.graph.beforeChange(),this.disconnectOutput(a,!1,{doProcessChange:!1}))}var f=new w(++this.graph.last_link_id,d.type||e.type,this.id,a,b.id,c);this.graph.links[f.id]=f;null==e.links&&(e.links=[]);e.links.push(f.id);b.inputs[c].link=
|
||||
f.id;this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(g.OUTPUT,a,!0,f,e);if(b.onConnectionsChange)b.onConnectionsChange(g.INPUT,c,!0,f,d);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(g.INPUT,b,c,this,a),this.graph.onNodeConnectionChange(g.OUTPUT,this,a,b,c));this.setDirtyCanvas(!1,!0);this.graph.afterChange();this.graph.connectionChange(this,f);return f};l.prototype.disconnectOutput=function(a,b){if(a.constructor===String){if(a=
|
||||
this.findOutputSlot(a),-1==a)return g.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.outputs||a>=this.outputs.length)return g.debug&&console.log("Connect: Error, slot number not found"),!1;var c=this.outputs[a];if(!c||!c.links||0==c.links.length)return!1;if(b){b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"Target Node not found";for(var d=0,e=c.links.length;d<e;d++){var f=c.links[d],h=this.graph.links[f];if(h.target_id==b.id){c.links.splice(d,1);var k=
|
||||
b.inputs[h.target_slot];k.link=null;delete this.graph.links[f];this.graph&&this.graph._version++;if(b.onConnectionsChange)b.onConnectionsChange(g.INPUT,h.target_slot,!1,h,k);if(this.onConnectionsChange)this.onConnectionsChange(g.OUTPUT,a,!1,h,c);if(this.graph&&this.graph.onNodeConnectionChange)this.graph.onNodeConnectionChange(g.OUTPUT,this,a);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(g.OUTPUT,this,a),this.graph.onNodeConnectionChange(g.INPUT,b,h.target_slot));
|
||||
break}}}else{d=0;for(e=c.links.length;d<e;d++)if(f=c.links[d],h=this.graph.links[f]){b=this.graph.getNodeById(h.target_id);this.graph&&this.graph._version++;if(b){k=b.inputs[h.target_slot];k.link=null;if(b.onConnectionsChange)b.onConnectionsChange(g.INPUT,h.target_slot,!1,h,k);if(this.graph&&this.graph.onNodeConnectionChange)this.graph.onNodeConnectionChange(g.INPUT,b,h.target_slot)}delete this.graph.links[f];if(this.onConnectionsChange)this.onConnectionsChange(g.OUTPUT,a,!1,h,c);this.graph&&this.graph.onNodeConnectionChange&&
|
||||
(this.graph.onNodeConnectionChange(g.OUTPUT,this,a),this.graph.onNodeConnectionChange(g.INPUT,b,h.target_slot))}c.links=null}this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this);return!0};l.prototype.disconnectInput=function(a){if(a.constructor===String){if(a=this.findInputSlot(a),-1==a)return g.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.inputs||a>=this.inputs.length)return g.debug&&console.log("Connect: Error, slot number not found"),!1;var b=this.inputs[a];
|
||||
if(!b)return!1;var c=this.inputs[a].link;if(null!=c){this.inputs[a].link=null;var d=this.graph.links[c];if(d){var e=this.graph.getNodeById(d.origin_id);if(!e)return!1;var f=e.outputs[d.origin_slot];if(!f||!f.links||0==f.links.length)return!1;for(var h=0,k=f.links.length;h<k;h++)if(f.links[h]==c){f.links.splice(h,1);break}delete this.graph.links[c];this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(g.INPUT,a,!1,d,b);if(e.onConnectionsChange)e.onConnectionsChange(g.OUTPUT,
|
||||
h,!1,d,f);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(g.OUTPUT,e,h),this.graph.onNodeConnectionChange(g.INPUT,this,a))}}this.setDirtyCanvas(!1,!0);this.graph&&this.graph.connectionChange(this);return!0};l.prototype.getConnectionPos=function(a,b,c){c=c||new Float32Array(2);var d=0;a&&this.inputs&&(d=this.inputs.length);!a&&this.outputs&&(d=this.outputs.length);var e=.5*g.NODE_SLOT_HEIGHT;if(this.flags.collapsed)return b=this._collapsed_width||g.NODE_COLLAPSED_WIDTH,
|
||||
this.horizontal?(c[0]=this.pos[0]+.5*b,c[1]=a?this.pos[1]-g.NODE_TITLE_HEIGHT:this.pos[1]):(c[0]=a?this.pos[0]:this.pos[0]+b,c[1]=this.pos[1]-.5*g.NODE_TITLE_HEIGHT),c;if(a&&-1==b)return c[0]=this.pos[0]+.5*g.NODE_TITLE_HEIGHT,c[1]=this.pos[1]+.5*g.NODE_TITLE_HEIGHT,c;if(a&&d>b&&this.inputs[b].pos)return c[0]=this.pos[0]+this.inputs[b].pos[0],c[1]=this.pos[1]+this.inputs[b].pos[1],c;if(!a&&d>b&&this.outputs[b].pos)return c[0]=this.pos[0]+this.outputs[b].pos[0],c[1]=this.pos[1]+this.outputs[b].pos[1],
|
||||
c;if(this.horizontal)return c[0]=this.pos[0]+this.size[0]/d*(b+.5),c[1]=a?this.pos[1]-g.NODE_TITLE_HEIGHT:this.pos[1]+this.size[1],c;c[0]=a?this.pos[0]+e:this.pos[0]+this.size[0]+1-e;c[1]=this.pos[1]+(b+.7)*g.NODE_SLOT_HEIGHT+(this.constructor.slot_start_y||0);return c};l.prototype.alignToGrid=function(){this.pos[0]=g.CANVAS_GRID_SIZE*Math.round(this.pos[0]/g.CANVAS_GRID_SIZE);this.pos[1]=g.CANVAS_GRID_SIZE*Math.round(this.pos[1]/g.CANVAS_GRID_SIZE)};l.prototype.trace=function(a){this.console||(this.console=
|
||||
[]);this.console.push(a);this.console.length>l.MAX_CONSOLE&&this.console.shift();if(this.graph.onNodeTrace)this.graph.onNodeTrace(this,a)};l.prototype.setDirtyCanvas=function(a,b){this.graph&&this.graph.sendActionToCanvas("setDirty",[a,b])};l.prototype.loadImage=function(a){var b=new Image;b.src=g.node_images_path+a;b.ready=!1;var c=this;b.onload=function(){this.ready=!0;c.setDirtyCanvas(!0)};return b};l.prototype.captureInput=function(a){if(this.graph&&this.graph.list_of_graphcanvas)for(var b=this.graph.list_of_graphcanvas,
|
||||
c=0;c<b.length;++c){var d=b[c];if(a||d.node_capturing_input==this)d.node_capturing_input=a?this:null}};l.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)};l.prototype.pin=function(a){this.graph._version++;this.flags.pinned=void 0===a?!this.flags.pinned:a};l.prototype.localToScreen=function(a,b,c){return[(a+this.pos[0])*c.scale+c.offset[0],(b+this.pos[1])*c.scale+c.offset[1]]};p.LGraphGroup=
|
||||
g.LGraphGroup=z;z.prototype._ctor=function(a){this.title=a||"Group";this.font_size=24;this.color=m.node_colors.pale_blue?m.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})};z.prototype.configure=function(a){this.title=a.title;this._bounding.set(a.bounding);this.color=a.color;this.font=a.font};z.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}};z.prototype.move=function(a,b,
|
||||
c){this._pos[0]+=a;this._pos[1]+=b;if(!c)for(c=0;c<this._nodes.length;++c){var d=this._nodes[c];d.pos[0]+=a;d.pos[1]+=b}};z.prototype.recomputeInsideNodes=function(){this._nodes.length=0;for(var a=this.graph._nodes,b=new Float32Array(4),c=0;c<a.length;++c){var d=a[c];d.getBounding(b);F(this._bounding,b)&&this._nodes.push(d)}};z.prototype.isPointInside=l.prototype.isPointInside;z.prototype.setDirtyCanvas=l.prototype.setDirtyCanvas;g.DragAndScale=y;y.prototype.bindEvents=function(a){this.last_mouse=
|
||||
new Float32Array(2);this._binded_mouse_callback=this.onMouse.bind(this);g.pointerListenerAdd(a,"down",this._binded_mouse_callback);g.pointerListenerAdd(a,"move",this._binded_mouse_callback);g.pointerListenerAdd(a,"up",this._binded_mouse_callback);a.addEventListener("mousewheel",this._binded_mouse_callback,!1);a.addEventListener("wheel",this._binded_mouse_callback,!1)};y.prototype.computeVisibleArea=function(a){if(this.element){var b=this.element.width,c=this.element.height,d=-this.offset[0],e=-this.offset[1];
|
||||
a&&(d+=a[0]/this.scale,e+=a[1]/this.scale,b=a[2],c=a[3]);a=d+b/this.scale;c=e+c/this.scale;this.visible_area[0]=d;this.visible_area[1]=e;this.visible_area[2]=a-d;this.visible_area[3]=c-e}else this.visible_area[0]=this.visible_area[1]=this.visible_area[2]=this.visible_area[3]=0};y.prototype.onMouse=function(a){if(this.enabled){var b=this.element,c=b.getBoundingClientRect(),d=a.clientX-c.left;c=a.clientY-c.top;a.canvasx=d;a.canvasy=c;a.dragging=this.dragging;var e=!this.viewport||this.viewport&&d>=
|
||||
this.viewport[0]&&d<this.viewport[0]+this.viewport[2]&&c>=this.viewport[1]&&c<this.viewport[1]+this.viewport[3],f=!1;this.onmouse&&(f=this.onmouse(a));a.type==g.pointerevents_method+"down"&&e?(this.dragging=!0,g.pointerListenerRemove(b,"move",this._binded_mouse_callback),g.pointerListenerAdd(document,"move",this._binded_mouse_callback),g.pointerListenerAdd(document,"up",this._binded_mouse_callback)):a.type==g.pointerevents_method+"move"?f||(b=d-this.last_mouse[0],f=c-this.last_mouse[1],this.dragging&&
|
||||
this.mouseDrag(b,f)):a.type==g.pointerevents_method+"up"?(this.dragging=!1,g.pointerListenerRemove(document,"move",this._binded_mouse_callback),g.pointerListenerRemove(document,"up",this._binded_mouse_callback),g.pointerListenerAdd(b,"move",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+.05*a.delta));this.last_mouse[0]=d;this.last_mouse[1]=c;if(e)return a.preventDefault(),a.stopPropagation(),!1}};y.prototype.toCanvasContext=function(a){a.scale(this.scale,this.scale);a.translate(this.offset[0],this.offset[1])};y.prototype.convertOffsetToCanvas=function(a){return[(a[0]+this.offset[0])*this.scale,(a[1]+this.offset[1])*this.scale]};y.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};y.prototype.mouseDrag=function(a,b){this.offset[0]+=a/this.scale;this.offset[1]+=b/this.scale;if(this.onredraw)this.onredraw(this)};y.prototype.changeScale=function(a,b){a<this.min_scale?a=this.min_scale:a>this.max_scale&&(a=this.max_scale);if(a!=this.scale&&this.element){var c=this.element.getBoundingClientRect();if(c&&(b=b||[.5*c.width,.5*c.height],c=this.convertCanvasToOffset(b),this.scale=a,.01>Math.abs(this.scale-1)&&(this.scale=1),a=this.convertCanvasToOffset(b),a=[a[0]-c[0],a[1]-
|
||||
c[1]],this.offset[0]+=a[0],this.offset[1]+=a[1],this.onredraw))this.onredraw(this)}};y.prototype.changeDeltaScale=function(a,b){this.changeScale(this.scale*a,b)};y.prototype.reset=function(){this.scale=1;this.offset[0]=0;this.offset[1]=0};p.LGraphCanvas=g.LGraphCanvas=m;m.DEFAULT_BACKGROUND_IMAGE="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQBJREFUeNrs1rEKwjAUhlETUkj3vP9rdmr1Ysammk2w5wdxuLgcMHyptfawuZX4pJSWZTnfnu/lnIe/jNNxHHGNn//HNbbv+4dr6V+11uF527arU7+u63qfa/bnmh8sWLBgwYJlqRf8MEptXPBXJXa37BSl3ixYsGDBMliwFLyCV/DeLIMFCxYsWLBMwSt4Be/NggXLYMGCBUvBK3iNruC9WbBgwYJlsGApeAWv4L1ZBgsWLFiwYJmCV/AK3psFC5bBggULloJX8BpdwXuzYMGCBctgwVLwCl7Be7MMFixYsGDBsu8FH1FaSmExVfAxBa/gvVmwYMGCZbBg/W4vAQYA5tRF9QYlv/QAAAAASUVORK5CYII=";
|
||||
r.LGraphNode=g.LGraphNode=l;l.prototype._ctor=function(a){this.title=a||"Unnamed";this.size=[g.NODE_WIDTH,60];this.graph=null;this._pos=new Float32Array(10,10);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});this.id=-1;this.type=null;this.inputs=[];this.outputs=[];this.connections=[];this.properties={};this.properties_info=[];this.flags={}};l.prototype.configure=function(a){this.graph&&this.graph._version++;
|
||||
for(var b in a)if("properties"==b)for(var c in a.properties){if(this.properties[c]=a.properties[c],this.onPropertyChanged)this.onPropertyChanged(c,a.properties[c])}else null!=a[b]&&("object"==typeof a[b]?this[b]&&this[b].configure?this[b].configure(a[b]):this[b]=g.cloneObject(a[b],this[b]):this[b]=a[b]);a.title||(this.title=this.constructor.title);if(this.inputs)for(c=0;c<this.inputs.length;++c){b=this.inputs[c];var d=this.graph?this.graph.links[b.link]:null;if(this.onConnectionsChange)this.onConnectionsChange(g.INPUT,
|
||||
c,!0,d,b);if(this.onInputAdded)this.onInputAdded(b)}if(this.outputs)for(c=0;c<this.outputs.length;++c){var e=this.outputs[c];if(e.links){for(b=0;b<e.links.length;++b)if(d=this.graph?this.graph.links[e.links[b]]:null,this.onConnectionsChange)this.onConnectionsChange(g.OUTPUT,c,!0,d,e);if(this.onOutputAdded)this.onOutputAdded(e)}}if(this.widgets){for(c=0;c<this.widgets.length;++c)(b=this.widgets[c])&&b.options&&b.options.property&&this.properties[b.options.property]&&(b.value=JSON.parse(JSON.stringify(this.properties[b.options.property])));
|
||||
if(a.widgets_values)for(c=0;c<a.widgets_values.length;++c)this.widgets[c]&&(this.widgets[c].value=a.widgets_values[c])}if(this.onConfigure)this.onConfigure(a)};l.prototype.serialize=function(){var a={id:this.id,type:this.type,pos:this.pos,size:this.size,flags:g.cloneObject(this.flags),order:this.order,mode:this.mode};if(this.constructor===l&&this.last_serialization)return this.last_serialization;this.inputs&&(a.inputs=this.inputs);if(this.outputs){for(var b=0;b<this.outputs.length;b++)delete this.outputs[b]._data;
|
||||
a.outputs=this.outputs}this.title&&this.title!=this.constructor.title&&(a.title=this.title);this.properties&&(a.properties=g.cloneObject(this.properties));if(this.widgets&&this.serialize_widgets)for(a.widgets_values=[],b=0;b<this.widgets.length;++b)a.widgets_values[b]=this.widgets[b]?this.widgets[b].value:null;a.type||(a.type=this.constructor.type);this.color&&(a.color=this.color);this.bgcolor&&(a.bgcolor=this.bgcolor);this.boxcolor&&(a.boxcolor=this.boxcolor);this.shape&&(a.shape=this.shape);this.onSerialize&&
|
||||
this.onSerialize(a)&&console.warn("node onSerialize shouldnt return anything, data should be stored in the object pass in the first parameter");return a};l.prototype.clone=function(){var a=g.createNode(this.type);if(!a)return null;var b=g.cloneObject(this.serialize());if(b.inputs)for(var c=0;c<b.inputs.length;++c)b.inputs[c].link=null;if(b.outputs)for(c=0;c<b.outputs.length;++c)b.outputs[c].links&&(b.outputs[c].links.length=0);delete b.id;a.configure(b);return a};l.prototype.toString=function(){return JSON.stringify(this.serialize())};
|
||||
l.prototype.getTitle=function(){return this.title||this.constructor.title};l.prototype.setProperty=function(a,b){this.properties||(this.properties={});if(b!==this.properties[a]){var c=this.properties[a];this.properties[a]=b;this.onPropertyChanged&&!1===this.onPropertyChanged(a,b,c)&&(this.properties[a]=c);if(this.widgets)for(c=0;c<this.widgets.length;++c){var d=this.widgets[c];if(d&&d.options.property==a){d.value=b;break}}}};l.prototype.setOutputData=function(a,b){if(this.outputs&&!(-1==a||a>=this.outputs.length)){var c=
|
||||
this.outputs[a];if(c&&(c._data=b,this.outputs[a].links))for(c=0;c<this.outputs[a].links.length;c++){var d=this.graph.links[this.outputs[a].links[c]];d&&(d.data=b)}}};l.prototype.setOutputDataType=function(a,b){if(this.outputs&&!(-1==a||a>=this.outputs.length)){var c=this.outputs[a];if(c&&(c.type=b,this.outputs[a].links))for(c=0;c<this.outputs[a].links.length;c++)this.graph.links[this.outputs[a].links[c]].type=b}};l.prototype.getInputData=function(a,b){if(this.inputs&&!(a>=this.inputs.length||null==
|
||||
this.inputs[a].link)){a=this.graph.links[this.inputs[a].link];if(!a)return null;if(!b)return a.data;b=this.graph.getNodeById(a.origin_id);if(!b)return a.data;if(b.updateOutputData)b.updateOutputData(a.origin_slot);else if(b.onExecute)b.onExecute();return a.data}};l.prototype.getInputDataType=function(a){if(!this.inputs||a>=this.inputs.length||null==this.inputs[a].link)return null;a=this.graph.links[this.inputs[a].link];if(!a)return null;var b=this.graph.getNodeById(a.origin_id);return b?(a=b.outputs[a.origin_slot])?
|
||||
a.type:null:a.type};l.prototype.getInputDataByName=function(a,b){a=this.findInputSlot(a);return-1==a?null:this.getInputData(a,b)};l.prototype.isInputConnected=function(a){return this.inputs?a<this.inputs.length&&null!=this.inputs[a].link:!1};l.prototype.getInputInfo=function(a){return this.inputs?a<this.inputs.length?this.inputs[a]:null:null};l.prototype.getInputLink=function(a){return this.inputs?a<this.inputs.length?this.graph.links[this.inputs[a].link]:null:null};l.prototype.getInputNode=function(a){if(!this.inputs||
|
||||
a>=this.inputs.length)return null;a=this.inputs[a];return a&&null!==a.link?(a=this.graph.links[a.link])?this.graph.getNodeById(a.origin_id):null:null};l.prototype.getInputOrProperty=function(a){if(!this.inputs||!this.inputs.length)return this.properties?this.properties[a]:null;for(var b=0,c=this.inputs.length;b<c;++b){var d=this.inputs[b];if(a==d.name&&null!=d.link&&(d=this.graph.links[d.link]))return d.data}return this.properties[a]};l.prototype.getOutputData=function(a){return!this.outputs||a>=
|
||||
this.outputs.length?null:this.outputs[a]._data};l.prototype.getOutputInfo=function(a){return this.outputs?a<this.outputs.length?this.outputs[a]:null:null};l.prototype.isOutputConnected=function(a){return this.outputs?a<this.outputs.length&&this.outputs[a].links&&this.outputs[a].links.length:!1};l.prototype.isAnyOutputConnected=function(){if(!this.outputs)return!1;for(var a=0;a<this.outputs.length;++a)if(this.outputs[a].links&&this.outputs[a].links.length)return!0;return!1};l.prototype.getOutputNodes=
|
||||
function(a){if(!this.outputs||0==this.outputs.length||a>=this.outputs.length)return null;a=this.outputs[a];if(!a.links||0==a.links.length)return null;for(var b=[],c=0;c<a.links.length;c++){var d=this.graph.links[a.links[c]];d&&(d=this.graph.getNodeById(d.target_id))&&b.push(d)}return b};l.prototype.addOnTriggerInput=function(){var a=this.findInputSlot("onTrigger");return-1==a?(this.addInput("onTrigger",g.EVENT,{optional:!0,nameLocked:!0}),this.findInputSlot("onTrigger")):a};l.prototype.addOnExecutedOutput=
|
||||
function(){var a=this.findOutputSlot("onExecuted");return-1==a?(this.addOutput("onExecuted",g.ACTION,{optional:!0,nameLocked:!0}),this.findOutputSlot("onExecuted")):a};l.prototype.onAfterExecuteNode=function(a,b){var c=this.findOutputSlot("onExecuted");-1!=c&&this.triggerSlot(c,a,null,b)};l.prototype.changeMode=function(a){switch(a){case g.ON_EVENT:break;case g.ON_TRIGGER:this.addOnTriggerInput();this.addOnExecutedOutput();break;case g.NEVER:break;case g.ALWAYS:break;case g.ON_REQUEST:break;default:return!1}this.mode=
|
||||
a;return!0};l.prototype.doExecute=function(a,b){b=b||{};this.onExecute&&(b.action_call||(b.action_call=this.id+"_exec_"+Math.floor(9999*Math.random())),this.graph.nodes_executing[this.id]=!0,this.onExecute(a,b),this.graph.nodes_executing[this.id]=!1,this.exec_version=this.graph.iteration,b&&b.action_call&&(this.action_call=b.action_call,this.graph.nodes_executedAction[this.id]=b.action_call));this.execute_triggered=2;if(this.onAfterExecuteNode)this.onAfterExecuteNode(a,b)};l.prototype.actionDo=function(a,
|
||||
b,c){c=c||{};this.onAction&&(c.action_call||(c.action_call=this.id+"_"+(a?a:"action")+"_"+Math.floor(9999*Math.random())),this.graph.nodes_actioning[this.id]=a?a:"actioning",this.onAction(a,b,c),this.graph.nodes_actioning[this.id]=!1,c&&c.action_call&&(this.action_call=c.action_call,this.graph.nodes_executedAction[this.id]=c.action_call));this.action_triggered=2;if(this.onAfterExecuteNode)this.onAfterExecuteNode(b,c)};l.prototype.trigger=function(a,b,c){if(this.outputs&&this.outputs.length){this.graph&&
|
||||
(this.graph._last_trigger_time=g.getTime());for(var d=0;d<this.outputs.length;++d){var e=this.outputs[d];!e||e.type!==g.EVENT||a&&e.name!=a||this.triggerSlot(d,b,null,c)}}};l.prototype.triggerSlot=function(a,b,c,d){d=d||{};if(this.outputs)if(null==a)console.error("slot must be a number");else if(a.constructor!==Number&&console.warn("slot must be a number, use node.trigger('name') if you want to use a string"),(a=this.outputs[a])&&(a=a.links)&&a.length){this.graph&&(this.graph._last_trigger_time=g.getTime());
|
||||
for(var e=0;e<a.length;++e){var f=a[e];if(null==c||c==f){var h=this.graph.links[a[e]];h&&(h._last_time=g.getTime(),f=this.graph.getNodeById(h.target_id))&&(f.mode===g.ON_TRIGGER?(d.action_call||(d.action_call=this.id+"_trigg_"+Math.floor(9999*Math.random())),f.onExecute&&f.doExecute(b,d)):f.onAction&&(d.action_call||(d.action_call=this.id+"_act_"+Math.floor(9999*Math.random())),h=f.inputs[h.target_slot],f.actionDo(h.name,b,d)))}}}};l.prototype.clearTriggeredSlot=function(a,b){if(this.outputs&&(a=
|
||||
this.outputs[a])&&(a=a.links)&&a.length)for(var c=0;c<a.length;++c){var d=a[c];if(null==b||b==d)if(d=this.graph.links[a[c]])d._last_time=0}};l.prototype.setSize=function(a){this.size=a;if(this.onResize)this.onResize(this.size)};l.prototype.addProperty=function(a,b,c,d){c={name:a,type:c,default_value:b};if(d)for(var e in d)c[e]=d[e];this.properties_info||(this.properties_info=[]);this.properties_info.push(c);this.properties||(this.properties={});this.properties[a]=b;return c};l.prototype.addOutput=
|
||||
function(a,b,c){a={name:a,type:b,links:null};if(c)for(var d in c)a[d]=c[d];this.outputs||(this.outputs=[]);this.outputs.push(a);if(this.onOutputAdded)this.onOutputAdded(a);g.auto_load_slot_types&&g.registerNodeAndSlotType(this,b,!0);this.setSize(this.computeSize());this.setDirtyCanvas(!0,!0);return a};l.prototype.addOutputs=function(a){for(var b=0;b<a.length;++b){var c=a[b],d={name:c[0],type:c[1],link:null};if(a[2])for(var e in c[2])d[e]=c[2][e];this.outputs||(this.outputs=[]);this.outputs.push(d);
|
||||
if(this.onOutputAdded)this.onOutputAdded(d);g.auto_load_slot_types&&g.registerNodeAndSlotType(this,c[1],!0)}this.setSize(this.computeSize());this.setDirtyCanvas(!0,!0)};l.prototype.removeOutput=function(a){this.disconnectOutput(a);this.outputs.splice(a,1);for(var b=a;b<this.outputs.length;++b)if(this.outputs[b]&&this.outputs[b].links)for(var c=this.outputs[b].links,d=0;d<c.length;++d){var e=this.graph.links[c[d]];e&&--e.origin_slot}this.setSize(this.computeSize());if(this.onOutputRemoved)this.onOutputRemoved(a);
|
||||
this.setDirtyCanvas(!0,!0)};l.prototype.addInput=function(a,b,c){b=b||0;a={name:a,type:b,link:null};if(c)for(var d in c)a[d]=c[d];this.inputs||(this.inputs=[]);this.inputs.push(a);this.setSize(this.computeSize());if(this.onInputAdded)this.onInputAdded(a);g.registerNodeAndSlotType(this,b);this.setDirtyCanvas(!0,!0);return a};l.prototype.addInputs=function(a){for(var b=0;b<a.length;++b){var c=a[b],d={name:c[0],type:c[1],link:null};if(a[2])for(var e in c[2])d[e]=c[2][e];this.inputs||(this.inputs=[]);
|
||||
this.inputs.push(d);if(this.onInputAdded)this.onInputAdded(d);g.registerNodeAndSlotType(this,c[1])}this.setSize(this.computeSize());this.setDirtyCanvas(!0,!0)};l.prototype.removeInput=function(a){this.disconnectInput(a);for(var b=this.inputs.splice(a,1),c=a;c<this.inputs.length;++c)if(this.inputs[c]){var d=this.graph.links[this.inputs[c].link];d&&--d.target_slot}this.setSize(this.computeSize());if(this.onInputRemoved)this.onInputRemoved(a,b[0]);this.setDirtyCanvas(!0,!0)};l.prototype.addConnection=
|
||||
function(a,b,c,d){a={name:a,type:b,pos:c,direction:d,links:null};this.connections.push(a);return a};l.prototype.computeSize=function(a){function b(a){return a?d*a.length*.6:0}if(this.constructor.size)return this.constructor.size.concat();var c=Math.max(this.inputs?this.inputs.length:1,this.outputs?this.outputs.length:1);a=a||new Float32Array([0,0]);c=Math.max(c,1);var d=g.NODE_TEXT_SIZE,e=b(this.title),f=0,h=0;if(this.inputs)for(var k=0,q=this.inputs.length;k<q;++k){var p=this.inputs[k];p=p.label||
|
||||
p.name||"";p=b(p);f<p&&(f=p)}if(this.outputs)for(k=0,q=this.outputs.length;k<q;++k)p=this.outputs[k],p=p.label||p.name||"",p=b(p),h<p&&(h=p);a[0]=Math.max(f+h+10,e);a[0]=Math.max(a[0],g.NODE_WIDTH);this.widgets&&this.widgets.length&&(a[0]=Math.max(a[0],1.5*g.NODE_WIDTH));a[1]=(this.constructor.slot_start_y||0)+c*g.NODE_SLOT_HEIGHT;c=0;if(this.widgets&&this.widgets.length){k=0;for(q=this.widgets.length;k<q;++k)c=this.widgets[k].computeSize?c+(this.widgets[k].computeSize(a[0])[1]+4):c+(g.NODE_WIDGET_HEIGHT+
|
||||
4);c+=8}a[1]=this.widgets_up?Math.max(a[1],c):null!=this.widgets_start_y?Math.max(a[1],c+this.widgets_start_y):a[1]+c;this.constructor.min_height&&a[1]<this.constructor.min_height&&(a[1]=this.constructor.min_height);a[1]+=6;return a};l.prototype.getPropertyInfo=function(a){var b=null;if(this.properties_info)for(var c=0;c<this.properties_info.length;++c)if(this.properties_info[c].name==a){b=this.properties_info[c];break}this.constructor["@"+a]&&(b=this.constructor["@"+a]);this.constructor.widgets_info&&
|
||||
this.constructor.widgets_info[a]&&(b=this.constructor.widgets_info[a]);!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};l.prototype.addWidget=function(a,b,c,d,e){this.widgets||(this.widgets=[]);!e&&d&&d.constructor===Object&&(e=d,d=null);e&&e.constructor===String&&(e={property:e});d&&d.constructor===String&&(e||(e={}),e.property=d,d=null);d&&d.constructor!==Function&&(console.warn("addWidget: callback must be a function"),
|
||||
d=null);b={type:a.toLowerCase(),name:b,value:c,callback:d,options:e||{}};void 0!==b.options.y&&(b.y=b.options.y);d||b.options.callback||b.options.property||console.warn("LiteGraph addWidget(...) without a callback or property assigned");if("combo"==a&&!b.options.values)throw"LiteGraph addWidget('combo',...) requires to pass values in options: { values:['red','blue'] }";this.widgets.push(b);this.setSize(this.computeSize());return b};l.prototype.addCustomWidget=function(a){this.widgets||(this.widgets=
|
||||
[]);this.widgets.push(a);return a};l.prototype.getBounding=function(a){a=a||new Float32Array(4);a[0]=this.pos[0]-4;a[1]=this.pos[1]-g.NODE_TITLE_HEIGHT;a[2]=this.size[0]+4;a[3]=this.flags.collapsed?g.NODE_TITLE_HEIGHT:this.size[1]+g.NODE_TITLE_HEIGHT;if(this.onBounding)this.onBounding(a);return a};l.prototype.isPointInside=function(a,b,c,d){c=c||0;var e=this.graph&&this.graph.isLive()?0:g.NODE_TITLE_HEIGHT;d&&(e=0);if(this.flags&&this.flags.collapsed){if(A(a,b,this.pos[0]-c,this.pos[1]-g.NODE_TITLE_HEIGHT-
|
||||
c,(this._collapsed_width||g.NODE_COLLAPSED_WIDTH)+2*c,g.NODE_TITLE_HEIGHT+2*c))return!0}else if(this.pos[0]-4-c<a&&this.pos[0]+this.size[0]+4+c>a&&this.pos[1]-e-c<b&&this.pos[1]+this.size[1]+c>b)return!0;return!1};l.prototype.getSlotInPosition=function(a,b){var c=new Float32Array(2);if(this.inputs)for(var d=0,e=this.inputs.length;d<e;++d){var f=this.inputs[d];this.getConnectionPos(!0,d,c);if(A(a,b,c[0]-10,c[1]-5,20,10))return{input:f,slot:d,link_pos:c}}if(this.outputs)for(d=0,e=this.outputs.length;d<
|
||||
e;++d)if(f=this.outputs[d],this.getConnectionPos(!1,d,c),A(a,b,c[0]-10,c[1]-5,20,10))return{output:f,slot:d,link_pos:c};return null};l.prototype.findInputSlot=function(a,b){if(!this.inputs)return-1;for(var c=0,d=this.inputs.length;c<d;++c)if(a==this.inputs[c].name)return b?this.inputs[c]:c;return-1};l.prototype.findOutputSlot=function(a,b){b=b||!1;if(!this.outputs)return-1;for(var c=0,d=this.outputs.length;c<d;++c)if(a==this.outputs[c].name)return b?this.outputs[c]:c;return-1};l.prototype.findInputSlotFree=
|
||||
function(a){a=a||{};a=Object.assign({returnObj:!1,typesNotAccepted:[]},a);if(!this.inputs)return-1;for(var b=0,c=this.inputs.length;b<c;++b)if(!(this.inputs[b].link&&null!=this.inputs[b].link||a.typesNotAccepted&&a.typesNotAccepted.includes&&a.typesNotAccepted.includes(this.inputs[b].type)))return a.returnObj?this.inputs[b]:b;return-1};l.prototype.findOutputSlotFree=function(a){a=a||{};a=Object.assign({returnObj:!1,typesNotAccepted:[]},a);if(!this.outputs)return-1;for(var b=0,c=this.outputs.length;b<
|
||||
c;++b)if(!(this.outputs[b].links&&null!=this.outputs[b].links||a.typesNotAccepted&&a.typesNotAccepted.includes&&a.typesNotAccepted.includes(this.outputs[b].type)))return a.returnObj?this.outputs[b]:b;return-1};l.prototype.findInputSlotByType=function(a,b,c,d){return this.findSlotByType(!0,a,b,c,d)};l.prototype.findOutputSlotByType=function(a,b,c,d){return this.findSlotByType(!1,a,b,c,d)};l.prototype.findSlotByType=function(a,b,c,d,e){c=c||!1;d=d||!1;e=e||!1;a=a?this.inputs:this.outputs;if(!a)return-1;
|
||||
if(""==b||"*"==b)b=0;for(var f=0,h=a.length;f<h;++f){var k=(b+"").toLowerCase().split(","),q="0"==a[f].type||"*"==a[f].type?"0":a[f].type;q=(q+"").toLowerCase().split(",");for(sI=0;sI<k.length;sI++)for(dI=0;dI<q.length;dI++)if("_event_"==k[sI]&&(k[sI]=g.EVENT),"_event_"==q[sI]&&(q[sI]=g.EVENT),"*"==k[sI]&&(k[sI]=0),"*"==q[sI]&&(q[sI]=0),!(k[sI]!=q[dI]||d&&a[f].links&&null!==a[f].links))return c?a[f]:f}if(d&&!e)for(f=0,h=a.length;f<h;++f)for(k=(b+"").toLowerCase().split(","),q="0"==a[f].type||"*"==
|
||||
a[f].type?"0":a[f].type,q=(q+"").toLowerCase().split(","),sI=0;sI<k.length;sI++)for(dI=0;dI<q.length;dI++)if("*"==k[sI]&&(k[sI]=0),"*"==q[sI]&&(q[sI]=0),k[sI]==q[dI])return c?a[f]:f;return-1};l.prototype.connectByType=function(a,b,c,d){d=d||{};d=Object.assign({createEventInCase:!0,firstFreeIfOutputGeneralInCase:!0,generalTypeInCase:!0},d);b&&b.constructor===Number&&(b=this.graph.getNodeById(b));e=b.findInputSlotByType(c,!1,!0);if(0<=e&&null!==e)return this.connect(a,b,e);if(d.createEventInCase&&c==
|
||||
g.EVENT)return this.connect(a,b,-1);if(d.generalTypeInCase){var e=b.findInputSlotByType(0,!1,!0,!0);if(0<=e)return this.connect(a,b,e)}if(d.firstFreeIfOutputGeneralInCase&&(0==c||"*"==c||""==c)&&(e=b.findInputSlotFree({typesNotAccepted:[g.EVENT]}),0<=e))return this.connect(a,b,e);console.debug("no way to connect type: ",c," to targetNODE ",b);return null};l.prototype.connectByTypeOutput=function(a,b,c,d){d=d||{};d=Object.assign({createEventInCase:!0,firstFreeIfInputGeneralInCase:!0,generalTypeInCase:!0},
|
||||
d);b&&b.constructor===Number&&(b=this.graph.getNodeById(b));e=b.findOutputSlotByType(c,!1,!0);if(0<=e&&null!==e)return b.connect(e,this,a);if(d.generalTypeInCase){var e=b.findOutputSlotByType(0,!1,!0,!0);if(0<=e)return b.connect(e,this,a)}if(d.createEventInCase&&c==g.EVENT&&g.do_add_triggers_slots)return e=b.addOnExecutedOutput(),b.connect(e,this,a);if(d.firstFreeIfInputGeneralInCase&&(0==c||"*"==c||""==c)&&(e=b.findOutputSlotFree({typesNotAccepted:[g.EVENT]}),0<=e))return b.connect(e,this,a);console.debug("no way to connect byOUT type: ",
|
||||
c," to sourceNODE ",b);return null};l.prototype.connect=function(a,b,c){c=c||0;if(!this.graph)return console.log("Connect: Error, node doesn't belong to any graph. Nodes must be added first to a graph before connecting them."),null;if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return g.debug&&console.log("Connect: Error, no slot of name "+a),null}else if(!this.outputs||a>=this.outputs.length)return g.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(c.constructor===String){if(c=b.findInputSlot(c),-1==c)return g.debug&&console.log("Connect: Error, no slot of name "+c),null}else if(c===g.EVENT)if(g.do_add_triggers_slots)b.changeMode(g.ON_TRIGGER),c=b.findInputSlot("onTrigger");else return null;else if(!b.inputs||c>=b.inputs.length)return g.debug&&console.log("Connect: Error, slot number not found"),null;var d=b.inputs[c],e=this.outputs[a];if(!this.outputs[a])return null;
|
||||
b.onBeforeConnectInput&&(c=b.onBeforeConnectInput(c));if(!1===c||null===c||!g.isValidConnection(e.type,d.type))return this.setDirtyCanvas(!1,!0),null;if(b.onConnectInput&&!1===b.onConnectInput(c,e.type,e,this,a)||this.onConnectOutput&&!1===this.onConnectOutput(a,d.type,d,b,c))return null;b.inputs[c]&&null!=b.inputs[c].link&&(this.graph.beforeChange(),b.disconnectInput(c,{doProcessChange:!1}));if(null!==e.links&&e.links.length)switch(e.type){case g.EVENT:g.allow_multi_output_for_events||(this.graph.beforeChange(),
|
||||
this.disconnectOutput(a,!1,{doProcessChange:!1}))}var f=new w(++this.graph.last_link_id,d.type||e.type,this.id,a,b.id,c);this.graph.links[f.id]=f;null==e.links&&(e.links=[]);e.links.push(f.id);b.inputs[c].link=f.id;this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(g.OUTPUT,a,!0,f,e);if(b.onConnectionsChange)b.onConnectionsChange(g.INPUT,c,!0,f,d);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(g.INPUT,b,c,this,a),this.graph.onNodeConnectionChange(g.OUTPUT,
|
||||
this,a,b,c));this.setDirtyCanvas(!1,!0);this.graph.afterChange();this.graph.connectionChange(this,f);return f};l.prototype.disconnectOutput=function(a,b){if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return g.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.outputs||a>=this.outputs.length)return g.debug&&console.log("Connect: Error, slot number not found"),!1;var c=this.outputs[a];if(!c||!c.links||0==c.links.length)return!1;if(b){b.constructor===Number&&(b=
|
||||
this.graph.getNodeById(b));if(!b)throw"Target Node not found";for(var d=0,e=c.links.length;d<e;d++){var f=c.links[d],h=this.graph.links[f];if(h.target_id==b.id){c.links.splice(d,1);var k=b.inputs[h.target_slot];k.link=null;delete this.graph.links[f];this.graph&&this.graph._version++;if(b.onConnectionsChange)b.onConnectionsChange(g.INPUT,h.target_slot,!1,h,k);if(this.onConnectionsChange)this.onConnectionsChange(g.OUTPUT,a,!1,h,c);if(this.graph&&this.graph.onNodeConnectionChange)this.graph.onNodeConnectionChange(g.OUTPUT,
|
||||
this,a);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(g.OUTPUT,this,a),this.graph.onNodeConnectionChange(g.INPUT,b,h.target_slot));break}}}else{d=0;for(e=c.links.length;d<e;d++)if(f=c.links[d],h=this.graph.links[f]){b=this.graph.getNodeById(h.target_id);this.graph&&this.graph._version++;if(b){k=b.inputs[h.target_slot];k.link=null;if(b.onConnectionsChange)b.onConnectionsChange(g.INPUT,h.target_slot,!1,h,k);if(this.graph&&this.graph.onNodeConnectionChange)this.graph.onNodeConnectionChange(g.INPUT,
|
||||
b,h.target_slot)}delete this.graph.links[f];if(this.onConnectionsChange)this.onConnectionsChange(g.OUTPUT,a,!1,h,c);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(g.OUTPUT,this,a),this.graph.onNodeConnectionChange(g.INPUT,b,h.target_slot))}c.links=null}this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this);return!0};l.prototype.disconnectInput=function(a){if(a.constructor===String){if(a=this.findInputSlot(a),-1==a)return g.debug&&console.log("Connect: Error, no slot of name "+
|
||||
a),!1}else if(!this.inputs||a>=this.inputs.length)return g.debug&&console.log("Connect: Error, slot number not found"),!1;var b=this.inputs[a];if(!b)return!1;var c=this.inputs[a].link;if(null!=c){this.inputs[a].link=null;var d=this.graph.links[c];if(d){var e=this.graph.getNodeById(d.origin_id);if(!e)return!1;var f=e.outputs[d.origin_slot];if(!f||!f.links||0==f.links.length)return!1;for(var h=0,k=f.links.length;h<k;h++)if(f.links[h]==c){f.links.splice(h,1);break}delete this.graph.links[c];this.graph&&
|
||||
this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(g.INPUT,a,!1,d,b);if(e.onConnectionsChange)e.onConnectionsChange(g.OUTPUT,h,!1,d,f);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(g.OUTPUT,e,h),this.graph.onNodeConnectionChange(g.INPUT,this,a))}}this.setDirtyCanvas(!1,!0);this.graph&&this.graph.connectionChange(this);return!0};l.prototype.getConnectionPos=function(a,b,c){c=c||new Float32Array(2);var d=0;a&&this.inputs&&(d=this.inputs.length);
|
||||
!a&&this.outputs&&(d=this.outputs.length);var e=.5*g.NODE_SLOT_HEIGHT;if(this.flags.collapsed)return b=this._collapsed_width||g.NODE_COLLAPSED_WIDTH,this.horizontal?(c[0]=this.pos[0]+.5*b,c[1]=a?this.pos[1]-g.NODE_TITLE_HEIGHT:this.pos[1]):(c[0]=a?this.pos[0]:this.pos[0]+b,c[1]=this.pos[1]-.5*g.NODE_TITLE_HEIGHT),c;if(a&&-1==b)return c[0]=this.pos[0]+.5*g.NODE_TITLE_HEIGHT,c[1]=this.pos[1]+.5*g.NODE_TITLE_HEIGHT,c;if(a&&d>b&&this.inputs[b].pos)return c[0]=this.pos[0]+this.inputs[b].pos[0],c[1]=this.pos[1]+
|
||||
this.inputs[b].pos[1],c;if(!a&&d>b&&this.outputs[b].pos)return c[0]=this.pos[0]+this.outputs[b].pos[0],c[1]=this.pos[1]+this.outputs[b].pos[1],c;if(this.horizontal)return c[0]=this.pos[0]+this.size[0]/d*(b+.5),c[1]=a?this.pos[1]-g.NODE_TITLE_HEIGHT:this.pos[1]+this.size[1],c;c[0]=a?this.pos[0]+e:this.pos[0]+this.size[0]+1-e;c[1]=this.pos[1]+(b+.7)*g.NODE_SLOT_HEIGHT+(this.constructor.slot_start_y||0);return c};l.prototype.alignToGrid=function(){this.pos[0]=g.CANVAS_GRID_SIZE*Math.round(this.pos[0]/
|
||||
g.CANVAS_GRID_SIZE);this.pos[1]=g.CANVAS_GRID_SIZE*Math.round(this.pos[1]/g.CANVAS_GRID_SIZE)};l.prototype.trace=function(a){this.console||(this.console=[]);this.console.push(a);this.console.length>l.MAX_CONSOLE&&this.console.shift();if(this.graph.onNodeTrace)this.graph.onNodeTrace(this,a)};l.prototype.setDirtyCanvas=function(a,b){this.graph&&this.graph.sendActionToCanvas("setDirty",[a,b])};l.prototype.loadImage=function(a){var b=new Image;b.src=g.node_images_path+a;b.ready=!1;var c=this;b.onload=
|
||||
function(){this.ready=!0;c.setDirtyCanvas(!0)};return b};l.prototype.captureInput=function(a){if(this.graph&&this.graph.list_of_graphcanvas)for(var b=this.graph.list_of_graphcanvas,c=0;c<b.length;++c){var d=b[c];if(a||d.node_capturing_input==this)d.node_capturing_input=a?this:null}};l.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)};l.prototype.pin=function(a){this.graph._version++;
|
||||
this.flags.pinned=void 0===a?!this.flags.pinned:a};l.prototype.localToScreen=function(a,b,c){return[(a+this.pos[0])*c.scale+c.offset[0],(b+this.pos[1])*c.scale+c.offset[1]]};r.LGraphGroup=g.LGraphGroup=z;z.prototype._ctor=function(a){this.title=a||"Group";this.font_size=24;this.color=m.node_colors.pale_blue?m.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})};z.prototype.configure=function(a){this.title=a.title;this._bounding.set(a.bounding);this.color=a.color;this.font=a.font};z.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}};z.prototype.move=function(a,b,c){this._pos[0]+=a;this._pos[1]+=b;if(!c)for(c=0;c<this._nodes.length;++c){var d=this._nodes[c];d.pos[0]+=a;d.pos[1]+=b}};z.prototype.recomputeInsideNodes=function(){this._nodes.length=0;for(var a=this.graph._nodes,b=new Float32Array(4),c=0;c<a.length;++c){var d=a[c];d.getBounding(b);F(this._bounding,b)&&this._nodes.push(d)}};
|
||||
z.prototype.isPointInside=l.prototype.isPointInside;z.prototype.setDirtyCanvas=l.prototype.setDirtyCanvas;g.DragAndScale=y;y.prototype.bindEvents=function(a){this.last_mouse=new Float32Array(2);this._binded_mouse_callback=this.onMouse.bind(this);g.pointerListenerAdd(a,"down",this._binded_mouse_callback);g.pointerListenerAdd(a,"move",this._binded_mouse_callback);g.pointerListenerAdd(a,"up",this._binded_mouse_callback);a.addEventListener("mousewheel",this._binded_mouse_callback,!1);a.addEventListener("wheel",
|
||||
this._binded_mouse_callback,!1)};y.prototype.computeVisibleArea=function(a){if(this.element){var b=this.element.width,c=this.element.height,d=-this.offset[0],e=-this.offset[1];a&&(d+=a[0]/this.scale,e+=a[1]/this.scale,b=a[2],c=a[3]);a=d+b/this.scale;c=e+c/this.scale;this.visible_area[0]=d;this.visible_area[1]=e;this.visible_area[2]=a-d;this.visible_area[3]=c-e}else this.visible_area[0]=this.visible_area[1]=this.visible_area[2]=this.visible_area[3]=0};y.prototype.onMouse=function(a){if(this.enabled){var b=
|
||||
this.element,c=b.getBoundingClientRect(),d=a.clientX-c.left;c=a.clientY-c.top;a.canvasx=d;a.canvasy=c;a.dragging=this.dragging;var e=!this.viewport||this.viewport&&d>=this.viewport[0]&&d<this.viewport[0]+this.viewport[2]&&c>=this.viewport[1]&&c<this.viewport[1]+this.viewport[3],f=!1;this.onmouse&&(f=this.onmouse(a));a.type==g.pointerevents_method+"down"&&e?(this.dragging=!0,g.pointerListenerRemove(b,"move",this._binded_mouse_callback),g.pointerListenerAdd(document,"move",this._binded_mouse_callback),
|
||||
g.pointerListenerAdd(document,"up",this._binded_mouse_callback)):a.type==g.pointerevents_method+"move"?f||(b=d-this.last_mouse[0],f=c-this.last_mouse[1],this.dragging&&this.mouseDrag(b,f)):a.type==g.pointerevents_method+"up"?(this.dragging=!1,g.pointerListenerRemove(document,"move",this._binded_mouse_callback),g.pointerListenerRemove(document,"up",this._binded_mouse_callback),g.pointerListenerAdd(b,"move",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+.05*a.delta));this.last_mouse[0]=d;this.last_mouse[1]=c;if(e)return a.preventDefault(),a.stopPropagation(),!1}};y.prototype.toCanvasContext=function(a){a.scale(this.scale,this.scale);a.translate(this.offset[0],this.offset[1])};y.prototype.convertOffsetToCanvas=function(a){return[(a[0]+this.offset[0])*this.scale,
|
||||
(a[1]+this.offset[1])*this.scale]};y.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};y.prototype.mouseDrag=function(a,b){this.offset[0]+=a/this.scale;this.offset[1]+=b/this.scale;if(this.onredraw)this.onredraw(this)};y.prototype.changeScale=function(a,b){a<this.min_scale?a=this.min_scale:a>this.max_scale&&(a=this.max_scale);if(a!=this.scale&&this.element){var c=this.element.getBoundingClientRect();if(c&&(b=
|
||||
b||[.5*c.width,.5*c.height],c=this.convertCanvasToOffset(b),this.scale=a,.01>Math.abs(this.scale-1)&&(this.scale=1),a=this.convertCanvasToOffset(b),a=[a[0]-c[0],a[1]-c[1]],this.offset[0]+=a[0],this.offset[1]+=a[1],this.onredraw))this.onredraw(this)}};y.prototype.changeDeltaScale=function(a,b){this.changeScale(this.scale*a,b)};y.prototype.reset=function(){this.scale=1;this.offset[0]=0;this.offset[1]=0};r.LGraphCanvas=g.LGraphCanvas=m;m.DEFAULT_BACKGROUND_IMAGE="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQBJREFUeNrs1rEKwjAUhlETUkj3vP9rdmr1Ysammk2w5wdxuLgcMHyptfawuZX4pJSWZTnfnu/lnIe/jNNxHHGNn//HNbbv+4dr6V+11uF527arU7+u63qfa/bnmh8sWLBgwYJlqRf8MEptXPBXJXa37BSl3ixYsGDBMliwFLyCV/DeLIMFCxYsWLBMwSt4Be/NggXLYMGCBUvBK3iNruC9WbBgwYJlsGApeAWv4L1ZBgsWLFiwYJmCV/AK3psFC5bBggULloJX8BpdwXuzYMGCBctgwVLwCl7Be7MMFixYsGDBsu8FH1FaSmExVfAxBa/gvVmwYMGCZbBg/W4vAQYA5tRF9QYlv/QAAAAASUVORK5CYII=";
|
||||
m.link_type_colors={"-1":g.EVENT_LINK_COLOR,number:"#AAA",node:"#DCA"};m.gradients={};m.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.pointer_is_double=this.pointer_is_down=!1;this.visible_area.set([0,0,0,0]);if(this.onClear)this.onClear()};m.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)))};m.prototype.getTopGraph=function(){return this._graph_stack.length?this._graph_stack[0]:this.graph};m.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)};m.prototype.closeSubgraph=function(){if(this._graph_stack&&0!=this._graph_stack.length){var a=this.graph._subgraph_node,b=this._graph_stack.pop();this.selected_nodes={};this.highlighted_links={};b.attachCanvas(this);this.setDirty(!0,!0);a&&(this.centerOnNode(a),this.selectNodes([a]));this.ds.offset=
|
||||
@@ -142,13 +142,13 @@ m.getFileExtension=function(a){var b=a.indexOf("?");-1!=b&&(a=a.substr(0,b));b=a
|
||||
return a.defaultView||a.parentWindow};m.prototype.startRendering=function(){function a(){this.pause_rendering||this.draw();var b=this.getCanvasWindow();this.is_rendering&&b.requestAnimationFrame(a.bind(this))}this.is_rendering||(this.is_rendering=!0,a.call(this))};m.prototype.stopRendering=function(){this.is_rendering=!1};m.prototype.blockClick=function(){this.block_click=!0;this.last_mouseclick=0};m.prototype.processMouseDown=function(a){this.set_canvas_dirty_on_mouse_event&&(this.dirty_canvas=!0);
|
||||
if(this.graph){this.adjustMouseEvent(a);var b=this.getCanvasWindow();m.active_canvas=this;var c=this,d=a.clientX,e=a.clientY;this.ds.viewport=this.viewport;d=!this.viewport||this.viewport&&d>=this.viewport[0]&&d<this.viewport[0]+this.viewport[2]&&e>=this.viewport[1]&&e<this.viewport[1]+this.viewport[3];this.options.skip_events||(g.pointerListenerRemove(this.canvas,"move",this._mousemove_callback),g.pointerListenerAdd(b.document,"move",this._mousemove_callback,!0),g.pointerListenerAdd(b.document,"up",
|
||||
this._mouseup_callback,!0));if(d){var f=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes,5);d=!1;e=g.getTime();var h=void 0===a.isPrimary||!a.isPrimary;e=300>e-this.last_mouseclick&&h;this.mouse[0]=a.clientX;this.mouse[1]=a.clientY;this.graph_mouse[0]=a.canvasX;this.graph_mouse[1]=a.canvasY;this.last_click_position=[this.mouse[0],this.mouse[1]];this.pointer_is_double=this.pointer_is_down&&h?!0:!1;this.pointer_is_down=!0;this.canvas.focus();g.closeAllContextMenus(b);if(!this.onMouse||
|
||||
1!=this.onMouse(a)){if(1!=a.which||this.pointer_is_double)if(2==a.which){if(g.middle_click_slot_add_default_node&&f&&this.allow_interaction&&!d&&!this.read_only&&!this.connecting_node&&!f.flags.collapsed&&!this.live_mode){e=d=h=!1;if(f.outputs)for(t=0,k=f.outputs.length;t<k;++t)if(n=f.outputs[t],q=f.getConnectionPos(!1,t),A(a.canvasX,a.canvasY,q[0]-15,q[1]-10,30,20)){h=n;d=t;e=!0;break}if(f.inputs)for(t=0,k=f.inputs.length;t<k;++t)if(n=f.inputs[t],q=f.getConnectionPos(!0,t),A(a.canvasX,a.canvasY,
|
||||
q[0]-15,q[1]-10,30,20)){h=n;d=t;e=!1;break}h&&!1!==d&&(t=.5-(d+1)/(e?f.outputs.length:f.inputs.length),h=f.getBounding(),this.createDefaultNodeForSlot({nodeFrom:e?f:null,slotFrom:e?d:null,nodeTo:e?null:f,slotTo:e?null:d,position:[e?h[0]+h[2]:h[0],a.canvasY-80],nodeType:"AUTO",posAdd:[e?30:-30,130*-t],posSizeFix:[e?0:-1,0]}))}}else 3!=a.which&&!this.pointer_is_double||!this.allow_interaction||d||this.read_only||(f&&(Object.keys(this.selected_nodes).length&&(this.selected_nodes[f.id]||a.shiftKey||a.ctrlKey||
|
||||
1!=this.onMouse(a)){if(1!=a.which||this.pointer_is_double)if(2==a.which){if(g.middle_click_slot_add_default_node&&f&&this.allow_interaction&&!d&&!this.read_only&&!this.connecting_node&&!f.flags.collapsed&&!this.live_mode){e=d=h=!1;if(f.outputs)for(t=0,k=f.outputs.length;t<k;++t)if(q=f.outputs[t],p=f.getConnectionPos(!1,t),A(a.canvasX,a.canvasY,p[0]-15,p[1]-10,30,20)){h=q;d=t;e=!0;break}if(f.inputs)for(t=0,k=f.inputs.length;t<k;++t)if(q=f.inputs[t],p=f.getConnectionPos(!0,t),A(a.canvasX,a.canvasY,
|
||||
p[0]-15,p[1]-10,30,20)){h=q;d=t;e=!1;break}h&&!1!==d&&(t=.5-(d+1)/(e?f.outputs.length:f.inputs.length),h=f.getBounding(),this.createDefaultNodeForSlot({nodeFrom:e?f:null,slotFrom:e?d:null,nodeTo:e?null:f,slotTo:e?null:d,position:[e?h[0]+h[2]:h[0],a.canvasY-80],nodeType:"AUTO",posAdd:[e?30:-30,130*-t],posSizeFix:[e?0:-1,0]}))}}else 3!=a.which&&!this.pointer_is_double||!this.allow_interaction||d||this.read_only||(f&&(Object.keys(this.selected_nodes).length&&(this.selected_nodes[f.id]||a.shiftKey||a.ctrlKey||
|
||||
a.metaKey)?this.selected_nodes[f.id]||this.selectNodes([f],!0):this.selectNodes([f])),this.processContextMenu(f,a));else{a.ctrlKey&&(this.dragging_rectangle=new Float32Array(4),this.dragging_rectangle[0]=a.canvasX,this.dragging_rectangle[1]=a.canvasY,this.dragging_rectangle[2]=1,this.dragging_rectangle[3]=1,d=!0);g.alt_drag_do_clone_nodes&&a.altKey&&f&&this.allow_interaction&&!d&&!this.read_only&&(cloned=f.clone())&&(cloned.pos[0]+=5,cloned.pos[1]+=5,this.graph.add(cloned,!1,{doCalcSize:!1}),f=cloned,
|
||||
d=!0,t||(this.allow_dragnodes&&(this.graph.beforeChange(),this.node_dragged=f),this.selected_nodes[f.id]||this.processNodeSelected(f,a)));h=!1;if(f&&this.allow_interaction&&!d&&!this.read_only){this.live_mode||f.flags.pinned||this.bringToFront(f);if(!this.connecting_node&&!f.flags.collapsed&&!this.live_mode)if(!d&&!1!==f.resizable&&A(a.canvasX,a.canvasY,f.pos[0]+f.size[0]-5,f.pos[1]+f.size[1]-5,10,10))this.graph.beforeChange(),this.resizing_node=f,this.canvas.style.cursor="se-resize",d=!0;else{if(f.outputs){t=
|
||||
0;for(var k=f.outputs.length;t<k;++t){var n=f.outputs[t],q=f.getConnectionPos(!1,t);if(A(a.canvasX,a.canvasY,q[0]-15,q[1]-10,30,20)){this.connecting_node=f;this.connecting_output=n;this.connecting_output.slot_index=t;this.connecting_pos=f.getConnectionPos(!1,t);this.connecting_slot=t;g.shift_click_do_break_link_from&&a.shiftKey&&f.disconnectOutput(t);if(e){if(f.onOutputDblClick)f.onOutputDblClick(t,a)}else if(f.onOutputClick)f.onOutputClick(t,a);d=!0;break}}}if(f.inputs)for(t=0,k=f.inputs.length;t<
|
||||
k;++t)if(n=f.inputs[t],q=f.getConnectionPos(!0,t),A(a.canvasX,a.canvasY,q[0]-15,q[1]-10,30,20)){if(e){if(f.onInputDblClick)f.onInputDblClick(t,a)}else if(f.onInputClick)f.onInputClick(t,a);null!==n.link&&(q=this.graph.links[n.link],g.click_do_break_link_to&&(f.disconnectInput(t),d=this.dirty_bgcanvas=!0),this.allow_reconnect_links||a.shiftKey)&&(g.click_do_break_link_to||f.disconnectInput(t),this.connecting_node=this.graph._nodes_by_id[q.origin_id],this.connecting_slot=q.origin_slot,this.connecting_output=
|
||||
this.connecting_node.outputs[this.connecting_slot],this.connecting_pos=this.connecting_node.getConnectionPos(!1,this.connecting_slot),d=this.dirty_bgcanvas=!0);d||(this.connecting_node=f,this.connecting_input=n,this.connecting_input.slot_index=t,this.connecting_pos=f.getConnectionPos(!0,t),this.connecting_slot=t,d=this.dirty_bgcanvas=!0)}}if(!d){var t=!1;k=[a.canvasX-f.pos[0],a.canvasY-f.pos[1]];if(q=this.processNodeWidgets(f,this.graph_mouse,a))t=!0,this.node_widget=[f,q];if(e&&this.selected_nodes[f.id]){if(f.onDblClick)f.onDblClick(a,
|
||||
0;for(var k=f.outputs.length;t<k;++t){var q=f.outputs[t],p=f.getConnectionPos(!1,t);if(A(a.canvasX,a.canvasY,p[0]-15,p[1]-10,30,20)){this.connecting_node=f;this.connecting_output=q;this.connecting_output.slot_index=t;this.connecting_pos=f.getConnectionPos(!1,t);this.connecting_slot=t;g.shift_click_do_break_link_from&&a.shiftKey&&f.disconnectOutput(t);if(e){if(f.onOutputDblClick)f.onOutputDblClick(t,a)}else if(f.onOutputClick)f.onOutputClick(t,a);d=!0;break}}}if(f.inputs)for(t=0,k=f.inputs.length;t<
|
||||
k;++t)if(q=f.inputs[t],p=f.getConnectionPos(!0,t),A(a.canvasX,a.canvasY,p[0]-15,p[1]-10,30,20)){if(e){if(f.onInputDblClick)f.onInputDblClick(t,a)}else if(f.onInputClick)f.onInputClick(t,a);null!==q.link&&(p=this.graph.links[q.link],g.click_do_break_link_to&&(f.disconnectInput(t),d=this.dirty_bgcanvas=!0),this.allow_reconnect_links||a.shiftKey)&&(g.click_do_break_link_to||f.disconnectInput(t),this.connecting_node=this.graph._nodes_by_id[p.origin_id],this.connecting_slot=p.origin_slot,this.connecting_output=
|
||||
this.connecting_node.outputs[this.connecting_slot],this.connecting_pos=this.connecting_node.getConnectionPos(!1,this.connecting_slot),d=this.dirty_bgcanvas=!0);d||(this.connecting_node=f,this.connecting_input=q,this.connecting_input.slot_index=t,this.connecting_pos=f.getConnectionPos(!0,t),this.connecting_slot=t,d=this.dirty_bgcanvas=!0)}}if(!d){var t=!1;k=[a.canvasX-f.pos[0],a.canvasY-f.pos[1]];if(p=this.processNodeWidgets(f,this.graph_mouse,a))t=!0,this.node_widget=[f,p];if(e&&this.selected_nodes[f.id]){if(f.onDblClick)f.onDblClick(a,
|
||||
k,this);this.processNodeDblClicked(f);t=!0}f.onMouseDown&&f.onMouseDown(a,k,this)?t=!0:(f.subgraph&&!f.skip_subgraph_button&&!f.flags.collapsed&&k[0]>f.size[0]-g.NODE_TITLE_HEIGHT&&0>k[1]&&(c=this,setTimeout(function(){c.openSubgraph(f.subgraph)},10)),this.live_mode&&(t=h=!0));t||(this.allow_dragnodes&&(this.graph.beforeChange(),this.node_dragged=f),this.selected_nodes[f.id]||this.processNodeSelected(f,a));this.dirty_canvas=!0}}else if(!d){if(!this.read_only)for(t=0;t<this.visible_links.length;++t)if(h=
|
||||
this.visible_links[t],k=h._pos,!(!k||a.canvasX<k[0]-4||a.canvasX>k[0]+4||a.canvasY<k[1]-4||a.canvasY>k[1]+4)){this.showLinkMenu(h,a);this.over_link_center=null;break}this.selected_group=this.graph.getGroupOnPos(a.canvasX,a.canvasY);this.selected_group_resizing=!1;this.selected_group&&!this.read_only&&(a.ctrlKey&&(this.dragging_rectangle=null),10>H([a.canvasX,a.canvasY],[this.selected_group.pos[0]+this.selected_group.size[0],this.selected_group.pos[1]+this.selected_group.size[1]])*this.ds.scale?this.selected_group_resizing=
|
||||
!0:this.selected_group.recomputeInsideNodes());e&&!this.read_only&&this.allow_searchbox&&(this.showSearchBox(a),a.preventDefault(),a.stopPropagation());h=!0}!d&&h&&this.allow_dragcanvas&&(this.dragging_canvas=!0)}this.last_mouse[0]=a.clientX;this.last_mouse[1]=a.clientY;this.last_mouseclick=g.getTime();this.last_mouse_dragging=!0;this.graph.change();(!b.document.activeElement||"input"!=b.document.activeElement.nodeName.toLowerCase()&&"textarea"!=b.document.activeElement.nodeName.toLowerCase())&&a.preventDefault();
|
||||
@@ -183,122 +183,122 @@ if(b.inputs)for(var d=0;d<b.inputs.length;++d)this.highlighted_links[b.inputs[d]
|
||||
0;b<a.inputs.length;++b)delete this.highlighted_links[a.inputs[b].link];if(a.outputs)for(b=0;b<a.outputs.length;++b){var c=a.outputs[b];if(c.links)for(var d=0;d<c.links.length;++d)delete this.highlighted_links[c.links[d]]}}};m.prototype.deselectAllNodes=function(){if(this.graph){for(var a=this.graph._nodes,b=0,c=a.length;b<c;++b){var d=a[b];if(d.is_selected){if(d.onDeselected)d.onDeselected();d.is_selected=!1;if(this.onNodeDeselected)this.onNodeDeselected(d)}}this.selected_nodes={};this.current_node=
|
||||
null;this.highlighted_links={};if(this.onSelectionChange)this.onSelectionChange(this.selected_nodes);this.setDirty(!0)}};m.prototype.deleteSelectedNodes=function(){this.graph.beforeChange();for(var a in this.selected_nodes){var b=this.selected_nodes[a];if(!b.block_delete){if(b.inputs&&b.inputs.length&&b.outputs&&b.outputs.length&&g.isValidConnection(b.inputs[0].type,b.outputs[0].type)&&b.inputs[0].link&&b.outputs[0].links&&b.outputs[0].links.length){var c=b.graph.links[b.inputs[0].link],d=b.graph.links[b.outputs[0].links[0]],
|
||||
e=b.getInputNode(0),f=b.getOutputNodes(0)[0];e&&f&&e.connect(c.origin_slot,f,d.target_slot)}this.graph.remove(b);if(this.onNodeDeselected)this.onNodeDeselected(b)}}this.selected_nodes={};this.current_node=null;this.highlighted_links={};this.setDirty(!0);this.graph.afterChange()};m.prototype.centerOnNode=function(a){this.ds.offset[0]=-a.pos[0]-.5*a.size[0]+.5*this.canvas.width/this.ds.scale;this.ds.offset[1]=-a.pos[1]-.5*a.size[1]+.5*this.canvas.height/this.ds.scale;this.setDirty(!0,!0)};m.prototype.adjustMouseEvent=
|
||||
function(a){if(this.canvas){var b=this.canvas.getBoundingClientRect();var c=a.clientX-b.left;b=a.clientY-b.top}else c=a.clientX,b=a.clientY;a.deltaX=c-this.last_mouse_position[0];a.deltaY=b-this.last_mouse_position[1];this.last_mouse_position[0]=c;this.last_mouse_position[1]=b;a.canvasX=c/this.ds.scale-this.ds.offset[0];a.canvasY=b/this.ds.scale-this.ds.offset[1]};m.prototype.setZoom=function(a,b){this.ds.changeScale(a,b);this.dirty_bgcanvas=this.dirty_canvas=!0};m.prototype.convertOffsetToCanvas=
|
||||
function(a,b){return this.ds.convertOffsetToCanvas(a,b)};m.prototype.convertCanvasToOffset=function(a,b){return this.ds.convertCanvasToOffset(a,b)};m.prototype.convertEventToCanvasOffset=function(a){var b=this.canvas.getBoundingClientRect();return this.convertCanvasToOffset([a.clientX-b.left,a.clientY-b.top])};m.prototype.bringToFront=function(a){var b=this.graph._nodes.indexOf(a);-1!=b&&(this.graph._nodes.splice(b,1),this.graph._nodes.push(a))};m.prototype.sendToBack=function(a){var b=this.graph._nodes.indexOf(a);
|
||||
-1!=b&&(this.graph._nodes.splice(b,1),this.graph._nodes.unshift(a))};var I=new Float32Array(4);m.prototype.computeVisibleNodes=function(a,b){b=b||[];b.length=0;a=a||this.graph._nodes;for(var c=0,d=a.length;c<d;++c){var e=a[c];(!this.live_mode||e.onDrawBackground||e.onDrawForeground)&&F(this.visible_area,e.getBounding(I))&&b.push(e)}return b};m.prototype.draw=function(a,b){if(this.canvas&&0!=this.canvas.width&&0!=this.canvas.height){var c=g.getTime();this.render_time=.001*(c-this.last_draw_time);this.last_draw_time=
|
||||
c;this.graph&&this.ds.computeVisibleArea(this.viewport);(this.dirty_bgcanvas||b||this.always_render_background||this.graph&&this.graph._last_trigger_time&&1E3>c-this.graph._last_trigger_time)&&this.drawBackCanvas();(this.dirty_canvas||a)&&this.drawFrontCanvas();this.fps=this.render_time?1/this.render_time:0;this.frame+=1}};m.prototype.drawFrontCanvas=function(){this.dirty_canvas=!1;this.ctx||(this.ctx=this.bgcanvas.getContext("2d"));var a=this.ctx;if(a){var b=this.canvas;a.start2D&&!this.viewport&&
|
||||
(a.start2D(),a.restore(),a.setTransform(1,0,0,1,0,0));var c=this.viewport||this.dirty_area;c&&(a.save(),a.beginPath(),a.rect(c[0],c[1],c[2],c[3]),a.clip());this.clear_background&&(c?a.clearRect(c[0],c[1],c[2],c[3]):a.clearRect(0,0,b.width,b.height));this.bgcanvas==this.canvas?this.drawBackCanvas():a.drawImage(this.bgcanvas,0,0);if(this.onRender)this.onRender(b,a);this.show_info&&this.renderInfo(a,c?c[0]:0,c?c[1]:0);if(this.graph){a.save();this.ds.toCanvasContext(a);b=this.computeVisibleNodes(null,
|
||||
this.visible_nodes);for(var d=0;d<b.length;++d){var e=b[d];a.save();a.translate(e.pos[0],e.pos[1]);this.drawNode(e,a);a.restore()}this.render_execution_order&&this.drawExecutionOrder(a);this.graph.config.links_ontop&&(this.live_mode||this.drawConnections(a));if(null!=this.connecting_pos){a.lineWidth=this.connections_width;e=this.connecting_output||this.connecting_input;b=e.type;d=e.dir;null==d&&(d=this.connecting_output?this.connecting_node.horizontal?g.DOWN:g.RIGHT:this.connecting_node.horizontal?
|
||||
g.UP:g.LEFT);var f=e.shape;switch(b){case g.EVENT:e=g.EVENT_LINK_COLOR;break;default:e=g.CONNECTING_LINK_COLOR}this.renderLink(a,this.connecting_pos,[this.graph_mouse[0],this.graph_mouse[1]],null,!1,null,e,d,g.CENTER);a.beginPath();b===g.EVENT||f===g.BOX_SHAPE?(a.rect(this.connecting_pos[0]-6+.5,this.connecting_pos[1]-5+.5,14,10),a.fill(),a.beginPath(),a.rect(this.graph_mouse[0]-6+.5,this.graph_mouse[1]-5+.5,14,10)):f===g.ARROW_SHAPE?(a.moveTo(this.connecting_pos[0]+8,this.connecting_pos[1]+.5),a.lineTo(this.connecting_pos[0]-
|
||||
4,this.connecting_pos[1]+6+.5),a.lineTo(this.connecting_pos[0]-4,this.connecting_pos[1]-6+.5),a.closePath()):(a.arc(this.connecting_pos[0],this.connecting_pos[1],4,0,2*Math.PI),a.fill(),a.beginPath(),a.arc(this.graph_mouse[0],this.graph_mouse[1],4,0,2*Math.PI));a.fill();a.fillStyle="#ffcc00";if(this._highlight_input){a.beginPath();var h=this._highlight_input_slot.shape;h===g.ARROW_SHAPE?(a.moveTo(this._highlight_input[0]+8,this._highlight_input[1]+.5),a.lineTo(this._highlight_input[0]-4,this._highlight_input[1]+
|
||||
6+.5),a.lineTo(this._highlight_input[0]-4,this._highlight_input[1]-6+.5),a.closePath()):a.arc(this._highlight_input[0],this._highlight_input[1],6,0,2*Math.PI);a.fill()}this._highlight_output&&(a.beginPath(),h===g.ARROW_SHAPE?(a.moveTo(this._highlight_output[0]+8,this._highlight_output[1]+.5),a.lineTo(this._highlight_output[0]-4,this._highlight_output[1]+6+.5),a.lineTo(this._highlight_output[0]-4,this._highlight_output[1]-6+.5),a.closePath()):a.arc(this._highlight_output[0],this._highlight_output[1],
|
||||
6,0,2*Math.PI),a.fill())}this.dragging_rectangle&&(a.strokeStyle="#FFF",a.strokeRect(this.dragging_rectangle[0],this.dragging_rectangle[1],this.dragging_rectangle[2],this.dragging_rectangle[3]));if(this.over_link_center&&this.render_link_tooltip)this.drawLinkTooltip(a,this.over_link_center);else if(this.onDrawLinkTooltip)this.onDrawLinkTooltip(a,null);if(this.onDrawForeground)this.onDrawForeground(a,this.visible_rect);a.restore()}this._graph_stack&&this._graph_stack.length&&this.drawSubgraphPanel(a);
|
||||
if(this.onDrawOverlay)this.onDrawOverlay(a);c&&a.restore();a.finish2D&&a.finish2D()}};m.prototype.drawSubgraphPanel=function(a){var b=this.graph,c=b._subgraph_node;c?(this.drawSubgraphPanelLeft(b,c,a),this.drawSubgraphPanelRight(b,c,a)):console.warn("subgraph without subnode")};m.prototype.drawSubgraphPanelLeft=function(a,b,c){var d=b.inputs?b.inputs.length:0,e=Math.floor(1.6*g.NODE_SLOT_HEIGHT);c.fillStyle="#111";c.globalAlpha=.8;c.beginPath();c.roundRect(10,10,200,(d+1)*e+50,[8]);c.fill();c.globalAlpha=
|
||||
1;c.fillStyle="#888";c.font="14px Arial";c.textAlign="left";c.fillText("Graph Inputs",20,34);if(this.drawButton(180,20,20,20,"X","#151515"))this.closeSubgraph();else{d=50;c.font="14px Arial";if(b.inputs)for(var f=0;f<b.inputs.length;++f){var h=b.inputs[f];if(!h.not_subgraph_input){if(this.drawButton(20,d+2,180,e-2)){var k=b.constructor.input_node_type||"graph/input";this.graph.beforeChange();var n=g.createNode(k);n?(a.add(n),this.block_click=!1,this.last_click_position=null,this.selectNodes([n]),
|
||||
this.node_dragged=n,this.dragging_canvas=!1,n.setProperty("name",h.name),n.setProperty("type",h.type),this.node_dragged.pos[0]=this.graph_mouse[0]-5,this.node_dragged.pos[1]=this.graph_mouse[1]-5,this.graph.afterChange()):console.error("graph input node not found:",k)}c.fillStyle="#9C9";c.beginPath();c.arc(184,d+.5*e,5,0,2*Math.PI);c.fill();c.fillStyle="#AAA";c.fillText(h.name,30,d+.75*e);c.fillStyle="#777";c.fillText(h.type,130,d+.75*e);d+=e}}this.drawButton(20,d+2,180,e-2,"+","#151515","#222")&&
|
||||
this.showSubgraphPropertiesDialog(b)}};m.prototype.drawSubgraphPanelRight=function(a,b,c){var d=b.outputs?b.outputs.length:0,e=this.bgcanvas.width,f=Math.floor(1.6*g.NODE_SLOT_HEIGHT);c.fillStyle="#111";c.globalAlpha=.8;c.beginPath();c.roundRect(e-200-10,10,200,(d+1)*f+50,[8]);c.fill();c.globalAlpha=1;c.fillStyle="#888";c.font="14px Arial";c.textAlign="left";d=c.measureText("Graph Outputs").width;c.fillText("Graph Outputs",e-d-20,34);if(this.drawButton(e-200,20,20,20,"X","#151515"))this.closeSubgraph();
|
||||
else{d=50;c.font="14px Arial";if(b.outputs)for(var h=0;h<b.outputs.length;++h){var k=b.outputs[h];if(!k.not_subgraph_input){if(this.drawButton(e-200,d+2,180,f-2)){var n=b.constructor.output_node_type||"graph/output";this.graph.beforeChange();var q=g.createNode(n);q?(a.add(q),this.block_click=!1,this.last_click_position=null,this.selectNodes([q]),this.node_dragged=q,this.dragging_canvas=!1,q.setProperty("name",k.name),q.setProperty("type",k.type),this.node_dragged.pos[0]=this.graph_mouse[0]-5,this.node_dragged.pos[1]=
|
||||
this.graph_mouse[1]-5,this.graph.afterChange()):console.error("graph input node not found:",n)}c.fillStyle="#9C9";c.beginPath();c.arc(e-200+16,d+.5*f,5,0,2*Math.PI);c.fill();c.fillStyle="#AAA";c.fillText(k.name,e-200+30,d+.75*f);c.fillStyle="#777";c.fillText(k.type,e-200+130,d+.75*f);d+=f}}this.drawButton(e-200,d+2,180,f-2,"+","#151515","#222")&&this.showSubgraphPropertiesDialogRight(b)}};m.prototype.drawButton=function(a,b,c,d,e,f,h,k){var n=this.ctx;f=f||g.NODE_DEFAULT_COLOR;h=h||"#555";k=k||g.NODE_TEXT_COLOR;
|
||||
var q=b+g.NODE_TITLE_HEIGHT+2,t=this.mouse,r=g.isInsideRectangle(t[0],t[1],a,q,c,d);q=(t=this.last_click_position)&&g.isInsideRectangle(t[0],t[1],a,q,c,d);n.fillStyle=r?h:f;q&&(n.fillStyle="#AAA");n.beginPath();n.roundRect(a,b,c,d,[4]);n.fill();null!=e&&e.constructor==String&&(n.fillStyle=k,n.textAlign="center",n.font=(.65*d|0)+"px Arial",n.fillText(e,a+.5*c,b+.75*d),n.textAlign="left");a=q&&!this.block_click;q&&this.blockClick();return a};m.prototype.isAreaClicked=function(a,b,c,d,e){var f=this.mouse;
|
||||
g.isInsideRectangle(f[0],f[1],a,b,c,d);b=(a=(f=this.last_click_position)&&g.isInsideRectangle(f[0],f[1],a,b,c,d))&&!this.block_click;a&&e&&this.blockClick();return b};m.prototype.renderInfo=function(a,b,c){b=b||10;c=c||this.canvas.height-80;a.save();a.translate(b,c);a.font="10px Arial";a.fillStyle="#888";a.textAlign="left";this.graph?(a.fillText("T: "+this.graph.globaltime.toFixed(2)+"s",5,13),a.fillText("I: "+this.graph.iteration,5,26),a.fillText("N: "+this.graph._nodes.length+" ["+this.visible_nodes.length+
|
||||
"]",5,39),a.fillText("V: "+this.graph._version,5,52),a.fillText("FPS:"+this.fps.toFixed(2),5,65)):a.fillText("No graph selected",5,13);a.restore()};m.prototype.drawBackCanvas=function(){var a=this.bgcanvas;if(a.width!=this.canvas.width||a.height!=this.canvas.height)a.width=this.canvas.width,a.height=this.canvas.height;this.bgctx||(this.bgctx=this.bgcanvas.getContext("2d"));var b=this.bgctx;b.start&&b.start();var c=this.viewport||[0,0,b.canvas.width,b.canvas.height];this.clear_background&&b.clearRect(c[0],
|
||||
c[1],c[2],c[3]);if(this._graph_stack&&this._graph_stack.length){b.save();c=this.graph._subgraph_node;b.strokeStyle=c.bgcolor;b.lineWidth=10;b.strokeRect(1,1,a.width-2,a.height-2);b.lineWidth=1;b.font="40px Arial";b.textAlign="center";b.fillStyle=c.bgcolor||"#AAA";for(var d="",e=1;e<this._graph_stack.length;++e)d+=this._graph_stack[e]._subgraph_node.getTitle()+" >> ";b.fillText(d+c.getTitle(),.5*a.width,40);b.restore()}c=!1;this.onRenderBackground&&(c=this.onRenderBackground(a,b));this.viewport||(b.restore(),
|
||||
b.setTransform(1,0,0,1,0,0));this.visible_links.length=0;if(this.graph){b.save();this.ds.toCanvasContext(b);if(this.background_image&&.5<this.ds.scale&&!c){b.globalAlpha=this.zoom_modify_alpha?(1-.5/this.ds.scale)*this.editor_alpha:this.editor_alpha;b.imageSmoothingEnabled=b.imageSmoothingEnabled=!1;if(!this._bg_img||this._bg_img.name!=this.background_image){this._bg_img=new Image;this._bg_img.name=this.background_image;this._bg_img.src=this.background_image;var f=this;this._bg_img.onload=function(){f.draw(!0,
|
||||
!0)}}c=null;null==this._pattern&&0<this._bg_img.width?(c=b.createPattern(this._bg_img,"repeat"),this._pattern_img=this._bg_img,this._pattern=c):c=this._pattern;c&&(b.fillStyle=c,b.fillRect(this.visible_area[0],this.visible_area[1],this.visible_area[2],this.visible_area[3]),b.fillStyle="transparent");b.globalAlpha=1;b.imageSmoothingEnabled=b.imageSmoothingEnabled=!0}this.graph._groups.length&&!this.live_mode&&this.drawGroups(a,b);if(this.onDrawBackground)this.onDrawBackground(b,this.visible_area);
|
||||
this.onBackgroundRender&&(console.error("WARNING! onBackgroundRender deprecated, now is named onDrawBackground "),this.onBackgroundRender=null);this.render_canvas_border&&(b.strokeStyle="#235",b.strokeRect(0,0,a.width,a.height));this.render_connections_shadows?(b.shadowColor="#000",b.shadowOffsetX=0,b.shadowOffsetY=0,b.shadowBlur=6):b.shadowColor="rgba(0,0,0,0)";this.live_mode||this.drawConnections(b);b.shadowColor="rgba(0,0,0,0)";b.restore()}b.finish&&b.finish();this.dirty_bgcanvas=!1;this.dirty_canvas=
|
||||
!0};var B=new Float32Array(2);m.prototype.drawNode=function(a,b){this.current_node=a;var c=a.color||a.constructor.color||g.NODE_DEFAULT_COLOR,d=a.bgcolor||a.constructor.bgcolor||g.NODE_DEFAULT_BGCOLOR,e=.6>this.ds.scale;if(this.live_mode){if(!a.flags.collapsed&&(b.shadowColor="transparent",a.onDrawForeground))a.onDrawForeground(b,this,this.canvas)}else{var f=this.editor_alpha;b.globalAlpha=f;this.render_shadows&&!e?(b.shadowColor=g.DEFAULT_SHADOW_COLOR,b.shadowOffsetX=2*this.ds.scale,b.shadowOffsetY=
|
||||
2*this.ds.scale,b.shadowBlur=3*this.ds.scale):b.shadowColor="transparent";if(!a.flags.collapsed||!a.onDrawCollapsed||1!=a.onDrawCollapsed(b,this)){var h=a._shape||g.BOX_SHAPE;B.set(a.size);var k=a.horizontal;if(a.flags.collapsed){b.font=this.inner_text_font;var n=a.getTitle?a.getTitle():a.title;null!=n&&(a._collapsed_width=Math.min(a.size[0],b.measureText(n).width+2*g.NODE_TITLE_HEIGHT),B[0]=a._collapsed_width,B[1]=0)}a.clip_area&&(b.save(),b.beginPath(),h==g.BOX_SHAPE?b.rect(0,0,B[0],B[1]):h==g.ROUND_SHAPE?
|
||||
b.roundRect(0,0,B[0],B[1],[10]):h==g.CIRCLE_SHAPE&&b.arc(.5*B[0],.5*B[1],.5*B[0],0,2*Math.PI),b.clip());a.has_errors&&(d="red");this.drawNodeShape(a,b,B,c,d,a.is_selected,a.mouseOver);b.shadowColor="transparent";if(a.onDrawForeground)a.onDrawForeground(b,this,this.canvas);b.textAlign=k?"center":"left";b.font=this.inner_text_font;d=!e;var q=this.connecting_output;h=this.connecting_input;b.lineWidth=1;n=0;var t=new Float32Array(2);if(!a.flags.collapsed){if(a.inputs)for(c=0;c<a.inputs.length;c++){var r=
|
||||
a.inputs[c],m=r.type,l=r.shape;b.globalAlpha=f;this.connecting_output&&!g.isValidConnection(r.type,q.type)&&(b.globalAlpha=.4*f);b.fillStyle=null!=r.link?r.color_on||this.default_connection_color_byType[m]||this.default_connection_color.input_on:r.color_off||this.default_connection_color_byTypeOff[m]||this.default_connection_color_byType[m]||this.default_connection_color.input_off;var u=a.getConnectionPos(!0,c,t);u[0]-=a.pos[0];u[1]-=a.pos[1];n<u[1]+.5*g.NODE_SLOT_HEIGHT&&(n=u[1]+.5*g.NODE_SLOT_HEIGHT);
|
||||
b.beginPath();"array"==m&&(l=g.GRID_SHAPE);r.type===g.EVENT||r.shape===g.BOX_SHAPE?k?b.rect(u[0]-5+.5,u[1]-8+.5,10,14):b.rect(u[0]-6+.5,u[1]-5+.5,14,10):l===g.ARROW_SHAPE?(b.moveTo(u[0]+8,u[1]+.5),b.lineTo(u[0]-4,u[1]+6+.5),b.lineTo(u[0]-4,u[1]-6+.5),b.closePath()):l===g.GRID_SHAPE?(b.rect(u[0]-4,u[1]-4,2,2),b.rect(u[0]-1,u[1]-4,2,2),b.rect(u[0]+2,u[1]-4,2,2),b.rect(u[0]-4,u[1]-1,2,2),b.rect(u[0]-1,u[1]-1,2,2),b.rect(u[0]+2,u[1]-1,2,2),b.rect(u[0]-4,u[1]+2,2,2),b.rect(u[0]-1,u[1]+2,2,2),b.rect(u[0]+
|
||||
2,u[1]+2,2,2)):e?b.rect(u[0]-4,u[1]-4,8,8):b.arc(u[0],u[1],4,0,2*Math.PI);b.fill();d&&(m=null!=r.label?r.label:r.name)&&(b.fillStyle=g.NODE_TEXT_COLOR,k||r.dir==g.UP?b.fillText(m,u[0],u[1]-10):b.fillText(m,u[0]+10,u[1]+5))}b.textAlign=k?"center":"right";b.strokeStyle="black";if(a.outputs)for(c=0;c<a.outputs.length;c++)if(r=a.outputs[c],m=r.type,l=r.shape,this.connecting_input&&!g.isValidConnection(m,h.type)&&(b.globalAlpha=.4*f),u=a.getConnectionPos(!1,c,t),u[0]-=a.pos[0],u[1]-=a.pos[1],n<u[1]+.5*
|
||||
g.NODE_SLOT_HEIGHT&&(n=u[1]+.5*g.NODE_SLOT_HEIGHT),b.fillStyle=r.links&&r.links.length?r.color_on||this.default_connection_color_byType[m]||this.default_connection_color.output_on:r.color_off||this.default_connection_color_byTypeOff[m]||this.default_connection_color_byType[m]||this.default_connection_color.output_off,b.beginPath(),"array"==m&&(l=g.GRID_SHAPE),q=!0,m===g.EVENT||l===g.BOX_SHAPE?k?b.rect(u[0]-5+.5,u[1]-8+.5,10,14):b.rect(u[0]-6+.5,u[1]-5+.5,14,10):l===g.ARROW_SHAPE?(b.moveTo(u[0]+8,
|
||||
u[1]+.5),b.lineTo(u[0]-4,u[1]+6+.5),b.lineTo(u[0]-4,u[1]-6+.5),b.closePath()):l===g.GRID_SHAPE?(b.rect(u[0]-4,u[1]-4,2,2),b.rect(u[0]-1,u[1]-4,2,2),b.rect(u[0]+2,u[1]-4,2,2),b.rect(u[0]-4,u[1]-1,2,2),b.rect(u[0]-1,u[1]-1,2,2),b.rect(u[0]+2,u[1]-1,2,2),b.rect(u[0]-4,u[1]+2,2,2),b.rect(u[0]-1,u[1]+2,2,2),b.rect(u[0]+2,u[1]+2,2,2),q=!1):e?b.rect(u[0]-4,u[1]-4,8,8):b.arc(u[0],u[1],4,0,2*Math.PI),b.fill(),!e&&q&&b.stroke(),d&&(m=null!=r.label?r.label:r.name))b.fillStyle=g.NODE_TEXT_COLOR,k||r.dir==g.DOWN?
|
||||
b.fillText(m,u[0],u[1]-8):b.fillText(m,u[0]-10,u[1]+5);b.textAlign="left";b.globalAlpha=1;if(a.widgets){r=n;if(k||a.widgets_up)r=2;null!=a.widgets_start_y&&(r=a.widgets_start_y);this.drawNodeWidgets(a,r,b,this.node_widget&&this.node_widget[0]==a?this.node_widget[1]:null)}}else if(this.render_collapsed_slots){e=f=null;if(a.inputs)for(c=0;c<a.inputs.length;c++)if(r=a.inputs[c],null!=r.link){f=r;break}if(a.outputs)for(c=0;c<a.outputs.length;c++)r=a.outputs[c],r.links&&r.links.length&&(e=r);f&&(f=0,c=
|
||||
-.5*g.NODE_TITLE_HEIGHT,k&&(f=.5*a._collapsed_width,c=-g.NODE_TITLE_HEIGHT),b.fillStyle="#686",b.beginPath(),r.type===g.EVENT||r.shape===g.BOX_SHAPE?b.rect(f-7+.5,c-4,14,8):r.shape===g.ARROW_SHAPE?(b.moveTo(f+8,c),b.lineTo(f+-4,c-4),b.lineTo(f+-4,c+4),b.closePath()):b.arc(f,c,4,0,2*Math.PI),b.fill());e&&(f=a._collapsed_width,c=-.5*g.NODE_TITLE_HEIGHT,k&&(f=.5*a._collapsed_width,c=0),b.fillStyle="#686",b.strokeStyle="black",b.beginPath(),r.type===g.EVENT||r.shape===g.BOX_SHAPE?b.rect(f-7+.5,c-4,14,
|
||||
8):r.shape===g.ARROW_SHAPE?(b.moveTo(f+6,c),b.lineTo(f-6,c-4),b.lineTo(f-6,c+4),b.closePath()):b.arc(f,c,4,0,2*Math.PI),b.fill())}a.clip_area&&b.restore();b.globalAlpha=1}}};m.prototype.drawLinkTooltip=function(a,b){var c=b._pos;a.fillStyle="black";a.beginPath();a.arc(c[0],c[1],3,0,2*Math.PI);a.fill();if(null!=b.data&&(!this.onDrawLinkTooltip||1!=this.onDrawLinkTooltip(a,b,this))&&(b=b.data,b=b.constructor===Number?b.toFixed(2):b.constructor===String?'"'+b+'"':b.constructor===Boolean?String(b):b.toToolTip?
|
||||
b.toToolTip():"["+b.constructor.name+"]",null!=b)){b=b.substr(0,30);a.font="14px Courier New";var d=a.measureText(b).width+20;a.shadowColor="black";a.shadowOffsetX=2;a.shadowOffsetY=2;a.shadowBlur=3;a.fillStyle="#454";a.beginPath();a.roundRect(c[0]-.5*d,c[1]-15-24,d,24,[3]);a.moveTo(c[0]-10,c[1]-15);a.lineTo(c[0]+10,c[1]-15);a.lineTo(c[0],c[1]-5);a.fill();a.shadowColor="transparent";a.textAlign="center";a.fillStyle="#CEC";a.fillText(b,c[0],c[1]-15-24*.3)}};var x=new Float32Array(4);m.prototype.drawNodeShape=
|
||||
function(a,b,c,d,e,f,h){b.strokeStyle=d;b.fillStyle=e;e=g.NODE_TITLE_HEIGHT;var k=.5>this.ds.scale,n=a._shape||a.constructor.shape||g.ROUND_SHAPE,q=a.constructor.title_mode,t=!0;q==g.TRANSPARENT_TITLE||q==g.NO_TITLE?t=!1:q==g.AUTOHIDE_TITLE&&h&&(t=!0);x[0]=0;x[1]=t?-e:0;x[2]=c[0]+1;x[3]=t?c[1]+e:c[1];h=b.globalAlpha;b.beginPath();n==g.BOX_SHAPE||k?b.fillRect(x[0],x[1],x[2],x[3]):n==g.ROUND_SHAPE||n==g.CARD_SHAPE?b.roundRect(x[0],x[1],x[2],x[3],n==g.CARD_SHAPE?[this.round_radius,this.round_radius,
|
||||
0,0]:[this.round_radius]):n==g.CIRCLE_SHAPE&&b.arc(.5*c[0],.5*c[1],.5*c[0],0,2*Math.PI);b.fill();!a.flags.collapsed&&t&&(b.shadowColor="transparent",b.fillStyle="rgba(0,0,0,0.2)",b.fillRect(0,-1,x[2],2));b.shadowColor="transparent";if(a.onDrawBackground)a.onDrawBackground(b,this,this.canvas,this.graph_mouse);if(t||q==g.TRANSPARENT_TITLE){if(a.onDrawTitleBar)a.onDrawTitleBar(b,e,c,this.ds.scale,d);else if(q!=g.TRANSPARENT_TITLE&&(a.constructor.title_color||this.render_title_colored)){t=a.constructor.title_color||
|
||||
d;a.flags.collapsed&&(b.shadowColor=g.DEFAULT_SHADOW_COLOR);if(this.use_gradients){var r=m.gradients[t];r||(r=m.gradients[t]=b.createLinearGradient(0,0,400,0),r.addColorStop(0,t),r.addColorStop(1,"#000"));b.fillStyle=r}else b.fillStyle=t;b.beginPath();n==g.BOX_SHAPE||k?b.rect(0,-e,c[0]+1,e):(n==g.ROUND_SHAPE||n==g.CARD_SHAPE)&&b.roundRect(0,-e,c[0]+1,e,a.flags.collapsed?[this.round_radius]:[this.round_radius,this.round_radius,0,0]);b.fill();b.shadowColor="transparent"}t=!1;g.node_box_coloured_by_mode&&
|
||||
g.NODE_MODES_COLORS[a.mode]&&(t=g.NODE_MODES_COLORS[a.mode]);g.node_box_coloured_when_on&&(t=a.action_triggered?"#FFF":a.execute_triggered?"#AAA":t);if(a.onDrawTitleBox)a.onDrawTitleBox(b,e,c,this.ds.scale);else n==g.ROUND_SHAPE||n==g.CIRCLE_SHAPE||n==g.CARD_SHAPE?(k&&(b.fillStyle="black",b.beginPath(),b.arc(.5*e,-.5*e,6,0,2*Math.PI),b.fill()),b.fillStyle=a.boxcolor||t||g.NODE_DEFAULT_BOXCOLOR,k?b.fillRect(.5*e-5,-.5*e-5,10,10):(b.beginPath(),b.arc(.5*e,-.5*e,5,0,2*Math.PI),b.fill())):(k&&(b.fillStyle=
|
||||
"black",b.fillRect(.5*(e-10)-1,-.5*(e+10)-1,12,12)),b.fillStyle=a.boxcolor||t||g.NODE_DEFAULT_BOXCOLOR,b.fillRect(.5*(e-10),-.5*(e+10),10,10));b.globalAlpha=h;if(a.onDrawTitleText)a.onDrawTitleText(b,e,c,this.ds.scale,this.title_text_font,f);!k&&(b.font=this.title_text_font,h=String(a.getTitle()))&&(b.fillStyle=f?g.NODE_SELECTED_TITLE_COLOR:a.constructor.title_text_color||this.node_title_color,a.flags.collapsed?(b.textAlign="left",b.measureText(h),b.fillText(h.substr(0,20),e,g.NODE_TITLE_TEXT_Y-e),
|
||||
b.textAlign="left"):(b.textAlign="left",b.fillText(h,e,g.NODE_TITLE_TEXT_Y-e)));a.flags.collapsed||!a.subgraph||a.skip_subgraph_button||(h=g.NODE_TITLE_HEIGHT,t=a.size[0]-h,r=g.isInsideRectangle(this.graph_mouse[0]-a.pos[0],this.graph_mouse[1]-a.pos[1],t+2,-h+2,h-4,h-4),b.fillStyle=r?"#888":"#555",n==g.BOX_SHAPE||k?b.fillRect(t+2,-h+2,h-4,h-4):(b.beginPath(),b.roundRect(t+2,-h+2,h-4,h-4,[4]),b.fill()),b.fillStyle="#333",b.beginPath(),b.moveTo(t+.2*h,.6*-h),b.lineTo(t+.8*h,.6*-h),b.lineTo(t+.5*h,.3*
|
||||
-h),b.fill());if(a.onDrawTitle)a.onDrawTitle(b)}if(f){if(a.onBounding)a.onBounding(x);q==g.TRANSPARENT_TITLE&&(x[1]-=e,x[3]+=e);b.lineWidth=1;b.globalAlpha=.8;b.beginPath();n==g.BOX_SHAPE?b.rect(-6+x[0],-6+x[1],12+x[2],12+x[3]):n==g.ROUND_SHAPE||n==g.CARD_SHAPE&&a.flags.collapsed?b.roundRect(-6+x[0],-6+x[1],12+x[2],12+x[3],[2*this.round_radius]):n==g.CARD_SHAPE?b.roundRect(-6+x[0],-6+x[1],12+x[2],12+x[3],[2*this.round_radius,2,2*this.round_radius,2]):n==g.CIRCLE_SHAPE&&b.arc(.5*c[0],.5*c[1],.5*c[0]+
|
||||
6,0,2*Math.PI);b.strokeStyle=g.NODE_BOX_OUTLINE_COLOR;b.stroke();b.strokeStyle=d;b.globalAlpha=1}0<a.execute_triggered&&a.execute_triggered--;0<a.action_triggered&&a.action_triggered--};var G=new Float32Array(4),C=new Float32Array(4),J=new Float32Array(2),K=new Float32Array(2);m.prototype.drawConnections=function(a){var b=g.getTime(),c=this.visible_area;G[0]=c[0]-20;G[1]=c[1]-20;G[2]=c[2]+40;G[3]=c[3]+40;a.lineWidth=this.connections_width;a.fillStyle="#AAA";a.strokeStyle="#AAA";a.globalAlpha=this.editor_alpha;
|
||||
c=this.graph._nodes;for(var d=0,e=c.length;d<e;++d){var f=c[d];if(f.inputs&&f.inputs.length)for(var h=0;h<f.inputs.length;++h){var k=f.inputs[h];if(k&&null!=k.link&&(k=this.graph.links[k.link])){var n=this.graph.getNodeById(k.origin_id);if(null!=n){var q=k.origin_slot;var t=-1==q?[n.pos[0]+10,n.pos[1]+10]:n.getConnectionPos(!1,q,J);var r=f.getConnectionPos(!0,h,K);C[0]=t[0];C[1]=t[1];C[2]=r[0]-t[0];C[3]=r[1]-t[1];0>C[2]&&(C[0]+=C[2],C[2]=Math.abs(C[2]));0>C[3]&&(C[1]+=C[3],C[3]=Math.abs(C[3]));if(F(C,
|
||||
G)){var m=n.outputs[q];q=f.inputs[h];if(m&&q&&(n=m.dir||(n.horizontal?g.DOWN:g.RIGHT),q=q.dir||(f.horizontal?g.UP:g.LEFT),this.renderLink(a,t,r,k,!1,0,null,n,q),k&&k._last_time&&1E3>b-k._last_time)){m=2-.002*(b-k._last_time);var l=a.globalAlpha;a.globalAlpha=l*m;this.renderLink(a,t,r,k,!0,m,"white",n,q);a.globalAlpha=l}}}}}}a.globalAlpha=1};m.prototype.renderLink=function(a,b,c,d,e,f,h,k,n,q){d&&this.visible_links.push(d);!h&&d&&(h=d.color||m.link_type_colors[d.type]);h||(h=this.default_link_color);
|
||||
null!=d&&this.highlighted_links[d.id]&&(h="#FFF");k=k||g.RIGHT;n=n||g.LEFT;var t=H(b,c);this.render_connections_border&&.6<this.ds.scale&&(a.lineWidth=this.connections_width+4);a.lineJoin="round";q=q||1;1<q&&(a.lineWidth=.5);a.beginPath();for(var r=0;r<q;r+=1){var l=5*(r-.5*(q-1));if(this.links_render_mode==g.SPLINE_LINK){a.moveTo(b[0],b[1]+l);var p=0,u=0,v=0,w=0;switch(k){case g.LEFT:p=-.25*t;break;case g.RIGHT:p=.25*t;break;case g.UP:u=-.25*t;break;case g.DOWN:u=.25*t}switch(n){case g.LEFT:v=-.25*
|
||||
t;break;case g.RIGHT:v=.25*t;break;case g.UP:w=-.25*t;break;case g.DOWN:w=.25*t}a.bezierCurveTo(b[0]+p,b[1]+u+l,c[0]+v,c[1]+w+l,c[0],c[1]+l)}else if(this.links_render_mode==g.LINEAR_LINK){a.moveTo(b[0],b[1]+l);w=v=u=p=0;switch(k){case g.LEFT:p=-1;break;case g.RIGHT:p=1;break;case g.UP:u=-1;break;case g.DOWN:u=1}switch(n){case g.LEFT:v=-1;break;case g.RIGHT:v=1;break;case g.UP:w=-1;break;case g.DOWN:w=1}a.lineTo(b[0]+15*p,b[1]+15*u+l);a.lineTo(c[0]+15*v,c[1]+15*w+l);a.lineTo(c[0],c[1]+l)}else if(this.links_render_mode==
|
||||
g.STRAIGHT_LINK)a.moveTo(b[0],b[1]),l=b[0],p=b[1],u=c[0],v=c[1],k==g.RIGHT?l+=10:p+=10,n==g.LEFT?u-=10:v-=10,a.lineTo(l,p),a.lineTo(.5*(l+u),p),a.lineTo(.5*(l+u),v),a.lineTo(u,v),a.lineTo(c[0],c[1]);else return}this.render_connections_border&&.6<this.ds.scale&&!e&&(a.strokeStyle="rgba(0,0,0,0.5)",a.stroke());a.lineWidth=this.connections_width;a.fillStyle=a.strokeStyle=h;a.stroke();e=this.computeConnectionPoint(b,c,.5,k,n);d&&d._pos&&(d._pos[0]=e[0],d._pos[1]=e[1]);.6<=this.ds.scale&&this.highquality_render&&
|
||||
n!=g.CENTER&&(this.render_connection_arrows&&(r=this.computeConnectionPoint(b,c,.25,k,n),t=this.computeConnectionPoint(b,c,.26,k,n),d=this.computeConnectionPoint(b,c,.75,k,n),q=this.computeConnectionPoint(b,c,.76,k,n),this.render_curved_connections?(t=-Math.atan2(t[0]-r[0],t[1]-r[1]),q=-Math.atan2(q[0]-d[0],q[1]-d[1])):q=t=c[1]>b[1]?0:Math.PI,a.save(),a.translate(r[0],r[1]),a.rotate(t),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore(),a.save(),a.translate(d[0],d[1]),
|
||||
a.rotate(q),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore()),a.beginPath(),a.arc(e[0],e[1],5,0,2*Math.PI),a.fill());if(f)for(a.fillStyle=h,r=0;5>r;++r)f=(.001*g.getTime()+.2*r)%1,e=this.computeConnectionPoint(b,c,f,k,n),a.beginPath(),a.arc(e[0],e[1],5,0,2*Math.PI),a.fill()};m.prototype.computeConnectionPoint=function(a,b,c,d,e){d=d||g.RIGHT;e=e||g.LEFT;var f=H(a,b),h=[a[0],a[1]],k=[b[0],b[1]];switch(d){case g.LEFT:h[0]+=-.25*f;break;case g.RIGHT:h[0]+=.25*f;break;case g.UP:h[1]+=
|
||||
-.25*f;break;case g.DOWN:h[1]+=.25*f}switch(e){case g.LEFT:k[0]+=-.25*f;break;case g.RIGHT:k[0]+=.25*f;break;case g.UP:k[1]+=-.25*f;break;case g.DOWN:k[1]+=.25*f}d=(1-c)*(1-c)*(1-c);e=3*(1-c)*(1-c)*c;f=3*(1-c)*c*c;c*=c*c;return[d*a[0]+e*h[0]+f*k[0]+c*b[0],d*a[1]+e*h[1]+f*k[1]+c*b[1]]};m.prototype.drawExecutionOrder=function(a){a.shadowColor="transparent";a.globalAlpha=.25;a.textAlign="center";a.strokeStyle="white";a.globalAlpha=.75;for(var b=this.visible_nodes,c=0;c<b.length;++c){var d=b[c];a.fillStyle=
|
||||
"black";a.fillRect(d.pos[0]-g.NODE_TITLE_HEIGHT,d.pos[1]-g.NODE_TITLE_HEIGHT,g.NODE_TITLE_HEIGHT,g.NODE_TITLE_HEIGHT);0==d.order&&a.strokeRect(d.pos[0]-g.NODE_TITLE_HEIGHT+.5,d.pos[1]-g.NODE_TITLE_HEIGHT+.5,g.NODE_TITLE_HEIGHT,g.NODE_TITLE_HEIGHT);a.fillStyle="#FFF";a.fillText(d.order,d.pos[0]+-.5*g.NODE_TITLE_HEIGHT,d.pos[1]-6)}a.globalAlpha=1};m.prototype.drawNodeWidgets=function(a,b,c,d){if(!a.widgets||!a.widgets.length)return 0;var e=a.size[0],f=a.widgets;b+=2;var h=g.NODE_WIDGET_HEIGHT,k=.5<
|
||||
this.ds.scale;c.save();c.globalAlpha=this.editor_alpha;for(var n=g.WIDGET_OUTLINE_COLOR,q=g.WIDGET_BGCOLOR,t=g.WIDGET_TEXT_COLOR,r=g.WIDGET_SECONDARY_TEXT_COLOR,m=0;m<f.length;++m){var l=f[m],u=b;l.y&&(u=l.y);l.last_y=u;c.strokeStyle=n;c.fillStyle="#222";c.textAlign="left";l.disabled&&(c.globalAlpha*=.5);var p=l.width||e;switch(l.type){case "button":l.clicked&&(c.fillStyle="#AAA",l.clicked=!1,this.dirty_canvas=!0);c.fillRect(15,u,p-30,h);k&&!l.disabled&&c.strokeRect(15,u,p-30,h);k&&(c.textAlign="center",
|
||||
c.fillStyle=t,c.fillText(l.name,.5*p,u+.7*h));break;case "toggle":c.textAlign="left";c.strokeStyle=n;c.fillStyle=q;c.beginPath();k?c.roundRect(15,u,p-30,h,[.5*h]):c.rect(15,u,p-30,h);c.fill();k&&!l.disabled&&c.stroke();c.fillStyle=l.value?"#89A":"#333";c.beginPath();c.arc(p-30,u+.5*h,.36*h,0,2*Math.PI);c.fill();k&&(c.fillStyle=r,null!=l.name&&c.fillText(l.name,30,u+.7*h),c.fillStyle=l.value?t:r,c.textAlign="right",c.fillText(l.value?l.options.on||"true":l.options.off||"false",p-40,u+.7*h));break;
|
||||
case "slider":c.fillStyle=q;c.fillRect(15,u,p-30,h);var v=l.options.max-l.options.min,w=(l.value-l.options.min)/v;c.fillStyle=d==l?"#89A":"#678";c.fillRect(15,u,w*(p-30),h);k&&!l.disabled&&c.strokeRect(15,u,p-30,h);l.marker&&(v=(l.marker-l.options.min)/v,c.fillStyle="#AA9",c.fillRect(15+v*(p-30),u,2,h));k&&(c.textAlign="center",c.fillStyle=t,c.fillText(l.name+" "+Number(l.value).toFixed(3),.5*p,u+.7*h));break;case "number":case "combo":c.textAlign="left";c.strokeStyle=n;c.fillStyle=q;c.beginPath();
|
||||
k?c.roundRect(15,u,p-30,h,[.5*h]):c.rect(15,u,p-30,h);c.fill();k&&(l.disabled||c.stroke(),c.fillStyle=t,l.disabled||(c.beginPath(),c.moveTo(31,u+5),c.lineTo(21,u+.5*h),c.lineTo(31,u+h-5),c.fill(),c.beginPath(),c.moveTo(p-15-16,u+5),c.lineTo(p-15-6,u+.5*h),c.lineTo(p-15-16,u+h-5),c.fill()),c.fillStyle=r,c.fillText(l.name,35,u+.7*h),c.fillStyle=t,c.textAlign="right","number"==l.type?c.fillText(Number(l.value).toFixed(void 0!==l.options.precision?l.options.precision:3),p-30-20,u+.7*h):(v=l.value,l.options.values&&
|
||||
(w=l.options.values,w.constructor===Function&&(w=w()),w&&w.constructor!==Array&&(v=w[l.value])),c.fillText(v,p-30-20,u+.7*h)));break;case "string":case "text":c.textAlign="left";c.strokeStyle=n;c.fillStyle=q;c.beginPath();k?c.roundRect(15,u,p-30,h,[.5*h]):c.rect(15,u,p-30,h);c.fill();k&&(l.disabled||c.stroke(),c.save(),c.beginPath(),c.rect(15,u,p-30,h),c.clip(),c.fillStyle=r,null!=l.name&&c.fillText(l.name,30,u+.7*h),c.fillStyle=t,c.textAlign="right",c.fillText(String(l.value).substr(0,30),p-30,u+
|
||||
.7*h),c.restore());break;default:l.draw&&l.draw(c,a,p,u,h)}b+=(l.computeSize?l.computeSize(p)[1]:h)+4;c.globalAlpha=this.editor_alpha}c.restore();c.textAlign="left"};m.prototype.processNodeWidgets=function(a,b,c,d){function e(d,e){d.value=e;d.options&&d.options.property&&void 0!==a.properties[d.options.property]&&a.setProperty(d.options.property,e);d.callback&&d.callback(d.value,n,a,b,c)}if(!a.widgets||!a.widgets.length)return null;for(var f=b[0]-a.pos[0],h=b[1]-a.pos[1],k=a.size[0],n=this,q=this.getCanvasWindow(),
|
||||
t=0;t<a.widgets.length;++t){var r=a.widgets[t];if(r&&!r.disabled){var m=r.computeSize?r.computeSize(k)[1]:g.NODE_WIDGET_HEIGHT,l=r.width||k;if(r==d||!(6>f||f>l-12||h<r.last_y||h>r.last_y+m||void 0===r.last_y)){d=r.value;switch(r.type){case "button":c.type===g.pointerevents_method+"down"&&(r.callback&&setTimeout(function(){r.callback(r,n,a,b,c)},20),this.dirty_canvas=r.clicked=!0);break;case "slider":q=Math.clamp((f-15)/(l-30),0,1);r.value=r.options.min+(r.options.max-r.options.min)*q;r.callback&&
|
||||
setTimeout(function(){e(r,r.value)},20);this.dirty_canvas=!0;break;case "number":case "combo":d=r.value;if(c.type==g.pointerevents_method+"move"&&"number"==r.type)r.value+=.1*c.deltaX*(r.options.step||1),null!=r.options.min&&r.value<r.options.min&&(r.value=r.options.min),null!=r.options.max&&r.value>r.options.max&&(r.value=r.options.max);else if(c.type==g.pointerevents_method+"down"){var u=r.options.values;u&&u.constructor===Function&&(u=r.options.values(r,a));var p=null;"number"!=r.type&&(p=u.constructor===
|
||||
Array?u:Object.keys(u));f=40>f?-1:f>l-40?1:0;if("number"==r.type)r.value+=.1*f*(r.options.step||1),null!=r.options.min&&r.value<r.options.min&&(r.value=r.options.min),null!=r.options.max&&r.value>r.options.max&&(r.value=r.options.max);else if(f)q=-1,this.last_mouseclick=0,q=u.constructor===Object?p.indexOf(String(r.value))+f:p.indexOf(r.value)+f,q>=p.length&&(q=p.length-1),0>q&&(q=0),r.value=u.constructor===Array?u[q]:q;else{var v=u!=p?Object.values(u):u;new g.ContextMenu(v,{scale:Math.max(1,this.ds.scale),
|
||||
event:c,className:"dark",callback:function(a,b,c){u!=p&&(a=v.indexOf(a));this.value=a;e(this,a);n.dirty_canvas=!0;return!1}.bind(r)},q)}}else c.type==g.pointerevents_method+"up"&&"number"==r.type&&(f=40>f?-1:f>l-40?1:0,200>c.click_time&&0==f&&this.prompt("Value",r.value,function(a){this.value=Number(a);e(this,this.value)}.bind(r),c));d!=r.value&&setTimeout(function(){e(this,this.value)}.bind(r),20);this.dirty_canvas=!0;break;case "toggle":c.type==g.pointerevents_method+"down"&&(r.value=!r.value,setTimeout(function(){e(r,
|
||||
r.value)},20));break;case "string":case "text":c.type==g.pointerevents_method+"down"&&this.prompt("Value",r.value,function(a){this.value=a;e(this,a)}.bind(r),c,r.options?r.options.multiline:!1);break;default:r.mouse&&(this.dirty_canvas=r.mouse(c,[f,h],a))}if(d!=r.value){if(a.onWidgetChanged)a.onWidgetChanged(r.name,r.value,d,r);a.graph._version++}return r}}}return null};m.prototype.drawGroups=function(a,b){if(this.graph){a=this.graph._groups;b.save();b.globalAlpha=.5*this.editor_alpha;for(var c=0;c<
|
||||
a.length;++c){var d=a[c];if(F(this.visible_area,d._bounding)){b.fillStyle=d.color||"#335";b.strokeStyle=d.color||"#335";var e=d._pos,f=d._size;b.globalAlpha=.25*this.editor_alpha;b.beginPath();b.rect(e[0]+.5,e[1]+.5,f[0],f[1]);b.fill();b.globalAlpha=this.editor_alpha;b.stroke();b.beginPath();b.moveTo(e[0]+f[0],e[1]+f[1]);b.lineTo(e[0]+f[0]-10,e[1]+f[1]);b.lineTo(e[0]+f[0],e[1]+f[1]-10);b.fill();f=d.font_size||g.DEFAULT_GROUP_FONT_SIZE;b.font=f+"px Arial";b.textAlign="left";b.fillText(d.title,e[0]+
|
||||
4,e[1]+f)}}b.restore()}};m.prototype.adjustNodesSize=function(){for(var a=this.graph._nodes,b=0;b<a.length;++b)a[b].size=a[b].computeSize();this.setDirty(!0,!0)};m.prototype.resize=function(a,b){a||b||(b=this.canvas.parentNode,a=b.offsetWidth,b=b.offsetHeight);if(this.canvas.width!=a||this.canvas.height!=b)this.canvas.width=a,this.canvas.height=b,this.bgcanvas.width=this.canvas.width,this.bgcanvas.height=this.canvas.height,this.setDirty(!0,!0)};m.prototype.switchLiveMode=function(a){if(a){var b=this,
|
||||
c=this.live_mode?1.1:.9;this.live_mode&&(this.live_mode=!1,this.editor_alpha=.1);var d=setInterval(function(){b.editor_alpha*=c;b.dirty_canvas=!0;b.dirty_bgcanvas=!0;1>c&&.01>b.editor_alpha&&(clearInterval(d),1>c&&(b.live_mode=!0));1<c&&.99<b.editor_alpha&&(clearInterval(d),b.editor_alpha=1)},1)}else this.live_mode=!this.live_mode,this.dirty_bgcanvas=this.dirty_canvas=!0};m.prototype.onNodeSelectionChange=function(a){};m.onGroupAdd=function(a,b,c){a=m.active_canvas;a.getCanvasWindow();b=new g.LGraphGroup;
|
||||
b.pos=a.convertEventToCanvasOffset(c);a.graph.add(b)};m.onMenuAdd=function(a,b,c,d,e){function f(a,b){var d=[];g.getNodeTypesCategories(h.filter||n.filter).filter(function(b){return b.startsWith(a)}).map(function(b){if(b){b=b.replace(new RegExp("^("+a+")"),"").split("/")[0];var c=""===a?b+"/":a+b+"/";-1!=b.indexOf("::")&&(b=b.split("::")[1]);-1===d.findIndex(function(a){return a.value===c})&&d.push({value:c,content:b,has_submenu:!0,callback:function(a,b,c,d){f(a.value,d)}})}});g.getNodeTypesInCategory(a.slice(0,
|
||||
-1),h.filter||n.filter).map(function(a){a.skip_list||d.push({value:a.type,content:a.title,has_submenu:!1,callback:function(a,b,c,d){b=d.getFirstEvent();h.graph.beforeChange();if(a=g.createNode(a.value))a.pos=h.convertEventToCanvasOffset(b),h.graph.add(a);e&&e(a);h.graph.afterChange()}})});new g.ContextMenu(d,{event:c,parentMenu:b},k)}var h=m.active_canvas,k=h.getCanvasWindow(),n=h.graph;if(n)return f("",d),!1};m.onMenuCollapseAll=function(){};m.onMenuNodeEdit=function(){};m.showMenuNodeOptionalInputs=
|
||||
function(a,b,c,d,e){if(e){var f=this;a=m.active_canvas.getCanvasWindow();b=e.optional_inputs;e.onGetInputs&&(b=e.onGetInputs());var h=[];if(b)for(var k=0;k<b.length;k++){var n=b[k];if(n){var q=n[0];n[2]||(n[2]={});n[2].label&&(q=n[2].label);n[2].removable=!0;q={content:q,value:n};n[1]==g.ACTION&&(q.className="event");h.push(q)}else h.push(null)}e.onMenuNodeInputs&&(b=e.onMenuNodeInputs(h))&&(h=b);if(h.length)return new g.ContextMenu(h,{event:c,callback:function(a,b,c){if(e&&(a.callback&&a.callback.call(f,
|
||||
e,a,b,c),a.value)){e.graph.beforeChange();e.addInput(a.value[0],a.value[1],a.value[2]);if(e.onNodeInputAdd)e.onNodeInputAdd(a.value);e.setDirtyCanvas(!0,!0);e.graph.afterChange()}},parentMenu:d,node:e},a),!1;console.log("no input entries")}};m.showMenuNodeOptionalOutputs=function(a,b,c,d,e){function f(a,b,c){if(e&&(a.callback&&a.callback.call(h,e,a,b,c),a.value))if(c=a.value[1],!c||c.constructor!==Object&&c.constructor!==Array){e.graph.beforeChange();e.addOutput(a.value[0],a.value[1],a.value[2]);
|
||||
if(e.onNodeOutputAdd)e.onNodeOutputAdd(a.value);e.setDirtyCanvas(!0,!0);e.graph.afterChange()}else{a=[];for(var k in c)a.push({content:k,value:c[k]});new g.ContextMenu(a,{event:b,callback:f,parentMenu:d,node:e});return!1}}if(e){var h=this;a=m.active_canvas.getCanvasWindow();b=e.optional_outputs;e.onGetOutputs&&(b=e.onGetOutputs());var k=[];if(b)for(var n=0;n<b.length;n++){var q=b[n];if(!q)k.push(null);else if(!e.flags||!e.flags.skip_repeated_outputs||-1==e.findOutputSlot(q[0])){var t=q[0];q[2]||(q[2]=
|
||||
{});q[2].label&&(t=q[2].label);q[2].removable=!0;t={content:t,value:q};q[1]==g.EVENT&&(t.className="event");k.push(t)}}this.onMenuNodeOutputs&&(k=this.onMenuNodeOutputs(k));g.do_add_triggers_slots&&-1==e.findOutputSlot("onExecuted")&&k.push({content:"On Executed",value:["onExecuted",g.EVENT,{nameLocked:!0}],className:"event"});e.onMenuNodeOutputs&&(b=e.onMenuNodeOutputs(k))&&(k=b);if(k.length)return new g.ContextMenu(k,{event:c,callback:f,parentMenu:d,node:e},a),!1}};m.onShowMenuNodeProperties=function(a,
|
||||
b,c,d,e){if(e&&e.properties){var f=m.active_canvas;b=f.getCanvasWindow();var h=[],k;for(k in e.properties){a=void 0!==e.properties[k]?e.properties[k]:" ";"object"==typeof a&&(a=JSON.stringify(a));var n=e.getPropertyInfo(k);if("enum"==n.type||"combo"==n.type)a=m.getPropertyPrintableValue(a,n.values);a=m.decodeHTML(a);h.push({content:"<span class='property_name'>"+(n.label?n.label:k)+"</span><span class='property_value'>"+a+"</span>",value:k})}if(h.length)return new g.ContextMenu(h,{event:c,callback:function(a,
|
||||
b,c,d){e&&(b=this.getBoundingClientRect(),f.showEditPropertyValue(e,a.value,{position:[b.left,b.top]}))},parentMenu:d,allow_html:!0,node:e},b),!1}};m.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};m.onMenuResizeNode=function(a,b,c,d,e){if(e){a=function(a){a.size=a.computeSize();if(a.onResize)a.onResize(a.size)};b=m.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)a(e);else for(var f in b.selected_nodes)a(b.selected_nodes[f]);
|
||||
e.setDirtyCanvas(!0,!0)}};m.prototype.showLinkMenu=function(a,b){var c=this,d=c.graph.getNodeById(a.origin_id),e=c.graph.getNodeById(a.target_id),f=!1;d&&d.outputs&&d.outputs[a.origin_slot]&&(f=d.outputs[a.origin_slot].type);var h=!1;e&&e.outputs&&e.outputs[a.target_slot]&&(h=e.inputs[a.target_slot].type);var k=new g.ContextMenu(["Add Node",null,"Delete",null],{event:b,title:null!=a.data?a.data.constructor.name:null,callback:function(b,g,t){switch(b){case "Add Node":m.onMenuAdd(null,null,t,k,function(b){b.inputs&&
|
||||
b.inputs.length&&b.outputs&&b.outputs.length&&d.connectByType(a.origin_slot,b,f)&&(b.connectByType(a.target_slot,e,h),b.pos[0]-=.5*b.size[0])});break;case "Delete":c.graph.removeLink(a.id)}}});return!1};m.prototype.createDefaultNodeForSlot=function(a){a=a||{};a=Object.assign({nodeFrom:null,slotFrom:null,nodeTo:null,slotTo:null,position:[],nodeType:null,posAdd:[0,0],posSizeFix:[0,0]},a);var b=a.nodeFrom&&null!==a.slotFrom,c=!b&&a.nodeTo&&null!==a.slotTo;if(!b&&!c)return console.warn("No data passed to createDefaultNodeForSlot "+
|
||||
a.nodeFrom+" "+a.slotFrom+" "+a.nodeTo+" "+a.slotTo),!1;if(!a.nodeType)return console.warn("No type to createDefaultNodeForSlot"),!1;var d=b?a.nodeFrom:a.nodeTo,e=b?a.slotFrom:a.slotTo;switch(typeof e){case "string":c=b?d.findOutputSlot(e,!1):d.findInputSlot(e,!1);e=b?d.outputs[e]:d.inputs[e];break;case "object":c=b?d.findOutputSlot(e.name):d.findInputSlot(e.name);break;case "number":c=e;e=b?d.outputs[e]:d.inputs[e];break;default:return console.warn("Cant get slot information "+e),!1}!1!==e&&!1!==
|
||||
c||console.warn("createDefaultNodeForSlot bad slotX "+e+" "+c);d=e.type==g.EVENT?"_event_":e.type;if((e=b?g.slot_types_default_out:g.slot_types_default_in)&&e[d]){nodeNewType=!1;if("object"==typeof e[d]||"array"==typeof e[d])for(var f in e[d]){if(a.nodeType==e[d][f]||"AUTO"==a.nodeType){nodeNewType=e[d][f];break}}else if(a.nodeType==e[d]||"AUTO"==a.nodeType)nodeNewType=e[d];if(nodeNewType){f=!1;"object"==typeof nodeNewType&&nodeNewType.node&&(f=nodeNewType,nodeNewType=nodeNewType.node);if(e=g.createNode(nodeNewType)){if(f){if(f.properties)for(var h in f.properties)e.addProperty(h,
|
||||
f.properties[h]);if(f.inputs)for(h in e.inputs=[],f.inputs)e.addOutput(f.inputs[h][0],f.inputs[h][1]);if(f.outputs)for(h in e.outputs=[],f.outputs)e.addOutput(f.outputs[h][0],f.outputs[h][1]);f.title&&(e.title=f.title);f.json&&e.configure(f.json)}this.graph.add(e);e.pos=[a.position[0]+a.posAdd[0]+(a.posSizeFix[0]?a.posSizeFix[0]*e.size[0]:0),a.position[1]+a.posAdd[1]+(a.posSizeFix[1]?a.posSizeFix[1]*e.size[1]:0)];b?a.nodeFrom.connectByType(c,e,d):a.nodeTo.connectByTypeOutput(c,e,d);return!0}console.log("failed creating "+
|
||||
nodeNewType)}}return!1};m.prototype.showConnectionMenu=function(a){a=a||{};var b=Object.assign({nodeFrom:null,slotFrom:null,nodeTo:null,slotTo:null,e:null},a),c=this,d=b.nodeFrom&&b.slotFrom;a=!d&&b.nodeTo&&b.slotTo;if(!d&&!a)return console.warn("No data passed to showConnectionMenu"),!1;a=d?b.nodeFrom:b.nodeTo;var e=d?b.slotFrom:b.slotTo,f=!1;switch(typeof e){case "string":f=d?a.findOutputSlot(e,!1):a.findInputSlot(e,!1);e=d?a.outputs[e]:a.inputs[e];break;case "object":f=d?a.findOutputSlot(e.name):
|
||||
a.findInputSlot(e.name);break;case "number":f=e;e=d?a.outputs[e]:a.inputs[e];break;default:return console.warn("Cant get slot information "+e),!1}a=["Add Node",null];c.allow_searchbox&&(a.push("Search"),a.push(null));var h=e.type==g.EVENT?"_event_":e.type,k=d?g.slot_types_default_out:g.slot_types_default_in;if(k&&k[h])if("object"==typeof k[h]||"array"==typeof k[h])for(var n in k[h])a.push(k[h][n]);else a.push(k[h]);var q=new g.ContextMenu(a,{event:b.e,title:(e&&""!=e.name?e.name+(h?" | ":""):"")+
|
||||
(e&&h?h:""),callback:function(a,g,k){switch(a){case "Add Node":m.onMenuAdd(null,null,k,q,function(a){d?b.nodeFrom.connectByType(f,a,h):b.nodeTo.connectByTypeOutput(f,a,h)});break;case "Search":d?c.showSearchBox(k,{node_from:b.nodeFrom,slot_from:e,type_filter_in:h}):c.showSearchBox(k,{node_to:b.nodeTo,slot_from:e,type_filter_out:h});break;default:c.createDefaultNodeForSlot(Object.assign(b,{position:[b.e.canvasX,b.e.canvasY],nodeType:a}))}}});return!1};m.onShowPropertyEditor=function(a,b,c,d,e){function f(){if(n){var b=
|
||||
n.value;"Number"==a.type?b=Number(b):"Boolean"==a.type&&(b=!!b);e[h]=b;k.parentNode&&k.parentNode.removeChild(k);e.setDirtyCanvas(!0,!0)}}var h=a.property||"title";b=e[h];var k=document.createElement("div");k.is_modified=!1;k.className="graphdialog";k.innerHTML="<span class='name'></span><input autofocus type='text' class='value'/><button>OK</button>";k.close=function(){k.parentNode&&k.parentNode.removeChild(k)};k.querySelector(".name").innerText=h;var n=k.querySelector(".value");n&&(n.value=b,n.addEventListener("blur",
|
||||
function(a){this.focus()}),n.addEventListener("keydown",function(a){k.is_modified=!0;if(27==a.keyCode)k.close();else if(13==a.keyCode)f();else if(13!=a.keyCode&&"textarea"!=a.target.localName)return;a.preventDefault();a.stopPropagation()}));b=m.active_canvas.canvas;c=b.getBoundingClientRect();var q=d=-20;c&&(d-=c.left,q-=c.top);event?(k.style.left=event.clientX+d+"px",k.style.top=event.clientY+q+"px"):(k.style.left=.5*b.width+d+"px",k.style.top=.5*b.height+q+"px");k.querySelector("button").addEventListener("click",
|
||||
f);b.parentNode.appendChild(k);n&&n.focus();var t=null;k.addEventListener("mouseleave",function(a){g.dialog_close_on_mouse_leave&&!k.is_modified&&g.dialog_close_on_mouse_leave&&(t=setTimeout(k.close,g.dialog_close_on_mouse_leave_delay))});k.addEventListener("mouseenter",function(a){g.dialog_close_on_mouse_leave&&t&&clearTimeout(t)})};m.prototype.prompt=function(a,b,c,d,e){var f=this;a=a||"";var h=document.createElement("div");h.is_modified=!1;h.className="graphdialog rounded";h.innerHTML=e?"<span class='name'></span> <textarea autofocus class='value'></textarea><button class='rounded'>OK</button>":
|
||||
"<span class='name'></span> <input autofocus type='text' class='value'/><button class='rounded'>OK</button>";h.close=function(){f.prompt_box=null;h.parentNode&&h.parentNode.removeChild(h)};e=m.active_canvas.canvas;e.parentNode.appendChild(h);1<this.ds.scale&&(h.style.transform="scale("+this.ds.scale+")");var k=null,n=!1;g.pointerListenerAdd(h,"leave",function(a){n||g.dialog_close_on_mouse_leave&&!h.is_modified&&g.dialog_close_on_mouse_leave&&(k=setTimeout(h.close,g.dialog_close_on_mouse_leave_delay))});
|
||||
g.pointerListenerAdd(h,"enter",function(a){g.dialog_close_on_mouse_leave&&k&&clearTimeout(k)});var q=h.querySelectorAll("select");q&&q.forEach(function(a){a.addEventListener("click",function(a){n++});a.addEventListener("blur",function(a){n=0});a.addEventListener("change",function(a){n=-1})});f.prompt_box&&f.prompt_box.close();f.prompt_box=h;h.querySelector(".name").innerText=a;var t=h.querySelector(".value");t.value=b;t.addEventListener("keydown",function(a){h.is_modified=!0;if(27==a.keyCode)h.close();
|
||||
else if(13==a.keyCode&&"textarea"!=a.target.localName)c&&c(this.value),h.close();else return;a.preventDefault();a.stopPropagation()});h.querySelector("button").addEventListener("click",function(a){c&&c(t.value);f.setDirty(!0);h.close()});a=e.getBoundingClientRect();q=b=-20;a&&(b-=a.left,q-=a.top);d?(h.style.left=d.clientX+b+"px",h.style.top=d.clientY+q+"px"):(h.style.left=.5*e.width+b+"px",h.style.top=.5*e.height+q+"px");setTimeout(function(){t.focus()},10);return h};m.search_limit=-1;m.prototype.showSearchBox=
|
||||
function(a){if(this.canvas){var b=this.canvas.getBoundingClientRect();var c=a.clientX-b.left;b=a.clientY-b.top}else c=a.clientX,b=a.clientY;this.last_mouse_position[0]=c;this.last_mouse_position[1]=b;a.canvasX=c/this.ds.scale-this.ds.offset[0];a.canvasY=b/this.ds.scale-this.ds.offset[1]};m.prototype.setZoom=function(a,b){this.ds.changeScale(a,b);this.dirty_bgcanvas=this.dirty_canvas=!0};m.prototype.convertOffsetToCanvas=function(a,b){return this.ds.convertOffsetToCanvas(a,b)};m.prototype.convertCanvasToOffset=
|
||||
function(a,b){return this.ds.convertCanvasToOffset(a,b)};m.prototype.convertEventToCanvasOffset=function(a){var b=this.canvas.getBoundingClientRect();return this.convertCanvasToOffset([a.clientX-b.left,a.clientY-b.top])};m.prototype.bringToFront=function(a){var b=this.graph._nodes.indexOf(a);-1!=b&&(this.graph._nodes.splice(b,1),this.graph._nodes.push(a))};m.prototype.sendToBack=function(a){var b=this.graph._nodes.indexOf(a);-1!=b&&(this.graph._nodes.splice(b,1),this.graph._nodes.unshift(a))};var I=
|
||||
new Float32Array(4);m.prototype.computeVisibleNodes=function(a,b){b=b||[];b.length=0;a=a||this.graph._nodes;for(var c=0,d=a.length;c<d;++c){var e=a[c];(!this.live_mode||e.onDrawBackground||e.onDrawForeground)&&F(this.visible_area,e.getBounding(I))&&b.push(e)}return b};m.prototype.draw=function(a,b){if(this.canvas&&0!=this.canvas.width&&0!=this.canvas.height){var c=g.getTime();this.render_time=.001*(c-this.last_draw_time);this.last_draw_time=c;this.graph&&this.ds.computeVisibleArea(this.viewport);
|
||||
(this.dirty_bgcanvas||b||this.always_render_background||this.graph&&this.graph._last_trigger_time&&1E3>c-this.graph._last_trigger_time)&&this.drawBackCanvas();(this.dirty_canvas||a)&&this.drawFrontCanvas();this.fps=this.render_time?1/this.render_time:0;this.frame+=1}};m.prototype.drawFrontCanvas=function(){this.dirty_canvas=!1;this.ctx||(this.ctx=this.bgcanvas.getContext("2d"));var a=this.ctx;if(a){var b=this.canvas;a.start2D&&!this.viewport&&(a.start2D(),a.restore(),a.setTransform(1,0,0,1,0,0));
|
||||
var c=this.viewport||this.dirty_area;c&&(a.save(),a.beginPath(),a.rect(c[0],c[1],c[2],c[3]),a.clip());this.clear_background&&(c?a.clearRect(c[0],c[1],c[2],c[3]):a.clearRect(0,0,b.width,b.height));this.bgcanvas==this.canvas?this.drawBackCanvas():a.drawImage(this.bgcanvas,0,0);if(this.onRender)this.onRender(b,a);this.show_info&&this.renderInfo(a,c?c[0]:0,c?c[1]:0);if(this.graph){a.save();this.ds.toCanvasContext(a);b=this.computeVisibleNodes(null,this.visible_nodes);for(var d=0;d<b.length;++d){var e=
|
||||
b[d];a.save();a.translate(e.pos[0],e.pos[1]);this.drawNode(e,a);a.restore()}this.render_execution_order&&this.drawExecutionOrder(a);this.graph.config.links_ontop&&(this.live_mode||this.drawConnections(a));if(null!=this.connecting_pos){a.lineWidth=this.connections_width;e=this.connecting_output||this.connecting_input;b=e.type;d=e.dir;null==d&&(d=this.connecting_output?this.connecting_node.horizontal?g.DOWN:g.RIGHT:this.connecting_node.horizontal?g.UP:g.LEFT);var f=e.shape;switch(b){case g.EVENT:e=
|
||||
g.EVENT_LINK_COLOR;break;default:e=g.CONNECTING_LINK_COLOR}this.renderLink(a,this.connecting_pos,[this.graph_mouse[0],this.graph_mouse[1]],null,!1,null,e,d,g.CENTER);a.beginPath();b===g.EVENT||f===g.BOX_SHAPE?(a.rect(this.connecting_pos[0]-6+.5,this.connecting_pos[1]-5+.5,14,10),a.fill(),a.beginPath(),a.rect(this.graph_mouse[0]-6+.5,this.graph_mouse[1]-5+.5,14,10)):f===g.ARROW_SHAPE?(a.moveTo(this.connecting_pos[0]+8,this.connecting_pos[1]+.5),a.lineTo(this.connecting_pos[0]-4,this.connecting_pos[1]+
|
||||
6+.5),a.lineTo(this.connecting_pos[0]-4,this.connecting_pos[1]-6+.5),a.closePath()):(a.arc(this.connecting_pos[0],this.connecting_pos[1],4,0,2*Math.PI),a.fill(),a.beginPath(),a.arc(this.graph_mouse[0],this.graph_mouse[1],4,0,2*Math.PI));a.fill();a.fillStyle="#ffcc00";if(this._highlight_input){a.beginPath();var h=this._highlight_input_slot.shape;h===g.ARROW_SHAPE?(a.moveTo(this._highlight_input[0]+8,this._highlight_input[1]+.5),a.lineTo(this._highlight_input[0]-4,this._highlight_input[1]+6+.5),a.lineTo(this._highlight_input[0]-
|
||||
4,this._highlight_input[1]-6+.5),a.closePath()):a.arc(this._highlight_input[0],this._highlight_input[1],6,0,2*Math.PI);a.fill()}this._highlight_output&&(a.beginPath(),h===g.ARROW_SHAPE?(a.moveTo(this._highlight_output[0]+8,this._highlight_output[1]+.5),a.lineTo(this._highlight_output[0]-4,this._highlight_output[1]+6+.5),a.lineTo(this._highlight_output[0]-4,this._highlight_output[1]-6+.5),a.closePath()):a.arc(this._highlight_output[0],this._highlight_output[1],6,0,2*Math.PI),a.fill())}this.dragging_rectangle&&
|
||||
(a.strokeStyle="#FFF",a.strokeRect(this.dragging_rectangle[0],this.dragging_rectangle[1],this.dragging_rectangle[2],this.dragging_rectangle[3]));if(this.over_link_center&&this.render_link_tooltip)this.drawLinkTooltip(a,this.over_link_center);else if(this.onDrawLinkTooltip)this.onDrawLinkTooltip(a,null);if(this.onDrawForeground)this.onDrawForeground(a,this.visible_rect);a.restore()}this._graph_stack&&this._graph_stack.length&&this.drawSubgraphPanel(a);if(this.onDrawOverlay)this.onDrawOverlay(a);c&&
|
||||
a.restore();a.finish2D&&a.finish2D()}};m.prototype.drawSubgraphPanel=function(a){var b=this.graph,c=b._subgraph_node;c?(this.drawSubgraphPanelLeft(b,c,a),this.drawSubgraphPanelRight(b,c,a)):console.warn("subgraph without subnode")};m.prototype.drawSubgraphPanelLeft=function(a,b,c){var d=b.inputs?b.inputs.length:0,e=Math.floor(1.6*g.NODE_SLOT_HEIGHT);c.fillStyle="#111";c.globalAlpha=.8;c.beginPath();c.roundRect(10,10,200,(d+1)*e+50,[8]);c.fill();c.globalAlpha=1;c.fillStyle="#888";c.font="14px Arial";
|
||||
c.textAlign="left";c.fillText("Graph Inputs",20,34);if(this.drawButton(180,20,20,20,"X","#151515"))this.closeSubgraph();else{d=50;c.font="14px Arial";if(b.inputs)for(var f=0;f<b.inputs.length;++f){var h=b.inputs[f];if(!h.not_subgraph_input){if(this.drawButton(20,d+2,180,e-2)){var k=b.constructor.input_node_type||"graph/input";this.graph.beforeChange();var q=g.createNode(k);q?(a.add(q),this.block_click=!1,this.last_click_position=null,this.selectNodes([q]),this.node_dragged=q,this.dragging_canvas=
|
||||
!1,q.setProperty("name",h.name),q.setProperty("type",h.type),this.node_dragged.pos[0]=this.graph_mouse[0]-5,this.node_dragged.pos[1]=this.graph_mouse[1]-5,this.graph.afterChange()):console.error("graph input node not found:",k)}c.fillStyle="#9C9";c.beginPath();c.arc(184,d+.5*e,5,0,2*Math.PI);c.fill();c.fillStyle="#AAA";c.fillText(h.name,30,d+.75*e);c.fillStyle="#777";c.fillText(h.type,130,d+.75*e);d+=e}}this.drawButton(20,d+2,180,e-2,"+","#151515","#222")&&this.showSubgraphPropertiesDialog(b)}};m.prototype.drawSubgraphPanelRight=
|
||||
function(a,b,c){var d=b.outputs?b.outputs.length:0,e=this.bgcanvas.width,f=Math.floor(1.6*g.NODE_SLOT_HEIGHT);c.fillStyle="#111";c.globalAlpha=.8;c.beginPath();c.roundRect(e-200-10,10,200,(d+1)*f+50,[8]);c.fill();c.globalAlpha=1;c.fillStyle="#888";c.font="14px Arial";c.textAlign="left";d=c.measureText("Graph Outputs").width;c.fillText("Graph Outputs",e-d-20,34);if(this.drawButton(e-200,20,20,20,"X","#151515"))this.closeSubgraph();else{d=50;c.font="14px Arial";if(b.outputs)for(var h=0;h<b.outputs.length;++h){var k=
|
||||
b.outputs[h];if(!k.not_subgraph_input){if(this.drawButton(e-200,d+2,180,f-2)){var q=b.constructor.output_node_type||"graph/output";this.graph.beforeChange();var p=g.createNode(q);p?(a.add(p),this.block_click=!1,this.last_click_position=null,this.selectNodes([p]),this.node_dragged=p,this.dragging_canvas=!1,p.setProperty("name",k.name),p.setProperty("type",k.type),this.node_dragged.pos[0]=this.graph_mouse[0]-5,this.node_dragged.pos[1]=this.graph_mouse[1]-5,this.graph.afterChange()):console.error("graph input node not found:",
|
||||
q)}c.fillStyle="#9C9";c.beginPath();c.arc(e-200+16,d+.5*f,5,0,2*Math.PI);c.fill();c.fillStyle="#AAA";c.fillText(k.name,e-200+30,d+.75*f);c.fillStyle="#777";c.fillText(k.type,e-200+130,d+.75*f);d+=f}}this.drawButton(e-200,d+2,180,f-2,"+","#151515","#222")&&this.showSubgraphPropertiesDialogRight(b)}};m.prototype.drawButton=function(a,b,c,d,e,f,h,k){var q=this.ctx;f=f||g.NODE_DEFAULT_COLOR;h=h||"#555";k=k||g.NODE_TEXT_COLOR;var p=b+g.NODE_TITLE_HEIGHT+2,t=this.mouse,n=g.isInsideRectangle(t[0],t[1],a,
|
||||
p,c,d);p=(t=this.last_click_position)&&g.isInsideRectangle(t[0],t[1],a,p,c,d);q.fillStyle=n?h:f;p&&(q.fillStyle="#AAA");q.beginPath();q.roundRect(a,b,c,d,[4]);q.fill();null!=e&&e.constructor==String&&(q.fillStyle=k,q.textAlign="center",q.font=(.65*d|0)+"px Arial",q.fillText(e,a+.5*c,b+.75*d),q.textAlign="left");a=p&&!this.block_click;p&&this.blockClick();return a};m.prototype.isAreaClicked=function(a,b,c,d,e){var f=this.mouse;g.isInsideRectangle(f[0],f[1],a,b,c,d);b=(a=(f=this.last_click_position)&&
|
||||
g.isInsideRectangle(f[0],f[1],a,b,c,d))&&!this.block_click;a&&e&&this.blockClick();return b};m.prototype.renderInfo=function(a,b,c){b=b||10;c=c||this.canvas.height-80;a.save();a.translate(b,c);a.font="10px Arial";a.fillStyle="#888";a.textAlign="left";this.graph?(a.fillText("T: "+this.graph.globaltime.toFixed(2)+"s",5,13),a.fillText("I: "+this.graph.iteration,5,26),a.fillText("N: "+this.graph._nodes.length+" ["+this.visible_nodes.length+"]",5,39),a.fillText("V: "+this.graph._version,5,52),a.fillText("FPS:"+
|
||||
this.fps.toFixed(2),5,65)):a.fillText("No graph selected",5,13);a.restore()};m.prototype.drawBackCanvas=function(){var a=this.bgcanvas;if(a.width!=this.canvas.width||a.height!=this.canvas.height)a.width=this.canvas.width,a.height=this.canvas.height;this.bgctx||(this.bgctx=this.bgcanvas.getContext("2d"));var b=this.bgctx;b.start&&b.start();var c=this.viewport||[0,0,b.canvas.width,b.canvas.height];this.clear_background&&b.clearRect(c[0],c[1],c[2],c[3]);if(this._graph_stack&&this._graph_stack.length){b.save();
|
||||
c=this.graph._subgraph_node;b.strokeStyle=c.bgcolor;b.lineWidth=10;b.strokeRect(1,1,a.width-2,a.height-2);b.lineWidth=1;b.font="40px Arial";b.textAlign="center";b.fillStyle=c.bgcolor||"#AAA";for(var d="",e=1;e<this._graph_stack.length;++e)d+=this._graph_stack[e]._subgraph_node.getTitle()+" >> ";b.fillText(d+c.getTitle(),.5*a.width,40);b.restore()}c=!1;this.onRenderBackground&&(c=this.onRenderBackground(a,b));this.viewport||(b.restore(),b.setTransform(1,0,0,1,0,0));this.visible_links.length=0;if(this.graph){b.save();
|
||||
this.ds.toCanvasContext(b);if(this.background_image&&.5<this.ds.scale&&!c){b.globalAlpha=this.zoom_modify_alpha?(1-.5/this.ds.scale)*this.editor_alpha:this.editor_alpha;b.imageSmoothingEnabled=b.imageSmoothingEnabled=!1;if(!this._bg_img||this._bg_img.name!=this.background_image){this._bg_img=new Image;this._bg_img.name=this.background_image;this._bg_img.src=this.background_image;var f=this;this._bg_img.onload=function(){f.draw(!0,!0)}}c=null;null==this._pattern&&0<this._bg_img.width?(c=b.createPattern(this._bg_img,
|
||||
"repeat"),this._pattern_img=this._bg_img,this._pattern=c):c=this._pattern;c&&(b.fillStyle=c,b.fillRect(this.visible_area[0],this.visible_area[1],this.visible_area[2],this.visible_area[3]),b.fillStyle="transparent");b.globalAlpha=1;b.imageSmoothingEnabled=b.imageSmoothingEnabled=!0}this.graph._groups.length&&!this.live_mode&&this.drawGroups(a,b);if(this.onDrawBackground)this.onDrawBackground(b,this.visible_area);this.onBackgroundRender&&(console.error("WARNING! onBackgroundRender deprecated, now is named onDrawBackground "),
|
||||
this.onBackgroundRender=null);this.render_canvas_border&&(b.strokeStyle="#235",b.strokeRect(0,0,a.width,a.height));this.render_connections_shadows?(b.shadowColor="#000",b.shadowOffsetX=0,b.shadowOffsetY=0,b.shadowBlur=6):b.shadowColor="rgba(0,0,0,0)";this.live_mode||this.drawConnections(b);b.shadowColor="rgba(0,0,0,0)";b.restore()}b.finish&&b.finish();this.dirty_bgcanvas=!1;this.dirty_canvas=!0};var B=new Float32Array(2);m.prototype.drawNode=function(a,b){this.current_node=a;var c=a.color||a.constructor.color||
|
||||
g.NODE_DEFAULT_COLOR,d=a.bgcolor||a.constructor.bgcolor||g.NODE_DEFAULT_BGCOLOR,e=.6>this.ds.scale;if(this.live_mode){if(!a.flags.collapsed&&(b.shadowColor="transparent",a.onDrawForeground))a.onDrawForeground(b,this,this.canvas)}else{var f=this.editor_alpha;b.globalAlpha=f;this.render_shadows&&!e?(b.shadowColor=g.DEFAULT_SHADOW_COLOR,b.shadowOffsetX=2*this.ds.scale,b.shadowOffsetY=2*this.ds.scale,b.shadowBlur=3*this.ds.scale):b.shadowColor="transparent";if(!a.flags.collapsed||!a.onDrawCollapsed||
|
||||
1!=a.onDrawCollapsed(b,this)){var h=a._shape||g.BOX_SHAPE;B.set(a.size);var k=a.horizontal;if(a.flags.collapsed){b.font=this.inner_text_font;var q=a.getTitle?a.getTitle():a.title;null!=q&&(a._collapsed_width=Math.min(a.size[0],b.measureText(q).width+2*g.NODE_TITLE_HEIGHT),B[0]=a._collapsed_width,B[1]=0)}a.clip_area&&(b.save(),b.beginPath(),h==g.BOX_SHAPE?b.rect(0,0,B[0],B[1]):h==g.ROUND_SHAPE?b.roundRect(0,0,B[0],B[1],[10]):h==g.CIRCLE_SHAPE&&b.arc(.5*B[0],.5*B[1],.5*B[0],0,2*Math.PI),b.clip());a.has_errors&&
|
||||
(d="red");this.drawNodeShape(a,b,B,c,d,a.is_selected,a.mouseOver);b.shadowColor="transparent";if(a.onDrawForeground)a.onDrawForeground(b,this,this.canvas);b.textAlign=k?"center":"left";b.font=this.inner_text_font;d=!e;var p=this.connecting_output;h=this.connecting_input;b.lineWidth=1;q=0;var t=new Float32Array(2);if(!a.flags.collapsed){if(a.inputs)for(c=0;c<a.inputs.length;c++){var n=a.inputs[c],m=n.type,l=n.shape;b.globalAlpha=f;this.connecting_output&&!g.isValidConnection(n.type,p.type)&&(b.globalAlpha=
|
||||
.4*f);b.fillStyle=null!=n.link?n.color_on||this.default_connection_color_byType[m]||this.default_connection_color.input_on:n.color_off||this.default_connection_color_byTypeOff[m]||this.default_connection_color_byType[m]||this.default_connection_color.input_off;var u=a.getConnectionPos(!0,c,t);u[0]-=a.pos[0];u[1]-=a.pos[1];q<u[1]+.5*g.NODE_SLOT_HEIGHT&&(q=u[1]+.5*g.NODE_SLOT_HEIGHT);b.beginPath();"array"==m&&(l=g.GRID_SHAPE);n.type===g.EVENT||n.shape===g.BOX_SHAPE?k?b.rect(u[0]-5+.5,u[1]-8+.5,10,14):
|
||||
b.rect(u[0]-6+.5,u[1]-5+.5,14,10):l===g.ARROW_SHAPE?(b.moveTo(u[0]+8,u[1]+.5),b.lineTo(u[0]-4,u[1]+6+.5),b.lineTo(u[0]-4,u[1]-6+.5),b.closePath()):l===g.GRID_SHAPE?(b.rect(u[0]-4,u[1]-4,2,2),b.rect(u[0]-1,u[1]-4,2,2),b.rect(u[0]+2,u[1]-4,2,2),b.rect(u[0]-4,u[1]-1,2,2),b.rect(u[0]-1,u[1]-1,2,2),b.rect(u[0]+2,u[1]-1,2,2),b.rect(u[0]-4,u[1]+2,2,2),b.rect(u[0]-1,u[1]+2,2,2),b.rect(u[0]+2,u[1]+2,2,2)):e?b.rect(u[0]-4,u[1]-4,8,8):b.arc(u[0],u[1],4,0,2*Math.PI);b.fill();d&&(m=null!=n.label?n.label:n.name)&&
|
||||
(b.fillStyle=g.NODE_TEXT_COLOR,k||n.dir==g.UP?b.fillText(m,u[0],u[1]-10):b.fillText(m,u[0]+10,u[1]+5))}b.textAlign=k?"center":"right";b.strokeStyle="black";if(a.outputs)for(c=0;c<a.outputs.length;c++)if(n=a.outputs[c],m=n.type,l=n.shape,this.connecting_input&&!g.isValidConnection(m,h.type)&&(b.globalAlpha=.4*f),u=a.getConnectionPos(!1,c,t),u[0]-=a.pos[0],u[1]-=a.pos[1],q<u[1]+.5*g.NODE_SLOT_HEIGHT&&(q=u[1]+.5*g.NODE_SLOT_HEIGHT),b.fillStyle=n.links&&n.links.length?n.color_on||this.default_connection_color_byType[m]||
|
||||
this.default_connection_color.output_on:n.color_off||this.default_connection_color_byTypeOff[m]||this.default_connection_color_byType[m]||this.default_connection_color.output_off,b.beginPath(),"array"==m&&(l=g.GRID_SHAPE),p=!0,m===g.EVENT||l===g.BOX_SHAPE?k?b.rect(u[0]-5+.5,u[1]-8+.5,10,14):b.rect(u[0]-6+.5,u[1]-5+.5,14,10):l===g.ARROW_SHAPE?(b.moveTo(u[0]+8,u[1]+.5),b.lineTo(u[0]-4,u[1]+6+.5),b.lineTo(u[0]-4,u[1]-6+.5),b.closePath()):l===g.GRID_SHAPE?(b.rect(u[0]-4,u[1]-4,2,2),b.rect(u[0]-1,u[1]-
|
||||
4,2,2),b.rect(u[0]+2,u[1]-4,2,2),b.rect(u[0]-4,u[1]-1,2,2),b.rect(u[0]-1,u[1]-1,2,2),b.rect(u[0]+2,u[1]-1,2,2),b.rect(u[0]-4,u[1]+2,2,2),b.rect(u[0]-1,u[1]+2,2,2),b.rect(u[0]+2,u[1]+2,2,2),p=!1):e?b.rect(u[0]-4,u[1]-4,8,8):b.arc(u[0],u[1],4,0,2*Math.PI),b.fill(),!e&&p&&b.stroke(),d&&(m=null!=n.label?n.label:n.name))b.fillStyle=g.NODE_TEXT_COLOR,k||n.dir==g.DOWN?b.fillText(m,u[0],u[1]-8):b.fillText(m,u[0]-10,u[1]+5);b.textAlign="left";b.globalAlpha=1;if(a.widgets){n=q;if(k||a.widgets_up)n=2;null!=
|
||||
a.widgets_start_y&&(n=a.widgets_start_y);this.drawNodeWidgets(a,n,b,this.node_widget&&this.node_widget[0]==a?this.node_widget[1]:null)}}else if(this.render_collapsed_slots){e=f=null;if(a.inputs)for(c=0;c<a.inputs.length;c++)if(n=a.inputs[c],null!=n.link){f=n;break}if(a.outputs)for(c=0;c<a.outputs.length;c++)n=a.outputs[c],n.links&&n.links.length&&(e=n);f&&(f=0,c=-.5*g.NODE_TITLE_HEIGHT,k&&(f=.5*a._collapsed_width,c=-g.NODE_TITLE_HEIGHT),b.fillStyle="#686",b.beginPath(),n.type===g.EVENT||n.shape===
|
||||
g.BOX_SHAPE?b.rect(f-7+.5,c-4,14,8):n.shape===g.ARROW_SHAPE?(b.moveTo(f+8,c),b.lineTo(f+-4,c-4),b.lineTo(f+-4,c+4),b.closePath()):b.arc(f,c,4,0,2*Math.PI),b.fill());e&&(f=a._collapsed_width,c=-.5*g.NODE_TITLE_HEIGHT,k&&(f=.5*a._collapsed_width,c=0),b.fillStyle="#686",b.strokeStyle="black",b.beginPath(),n.type===g.EVENT||n.shape===g.BOX_SHAPE?b.rect(f-7+.5,c-4,14,8):n.shape===g.ARROW_SHAPE?(b.moveTo(f+6,c),b.lineTo(f-6,c-4),b.lineTo(f-6,c+4),b.closePath()):b.arc(f,c,4,0,2*Math.PI),b.fill())}a.clip_area&&
|
||||
b.restore();b.globalAlpha=1}}};m.prototype.drawLinkTooltip=function(a,b){var c=b._pos;a.fillStyle="black";a.beginPath();a.arc(c[0],c[1],3,0,2*Math.PI);a.fill();if(null!=b.data&&(!this.onDrawLinkTooltip||1!=this.onDrawLinkTooltip(a,b,this))&&(b=b.data,b=b.constructor===Number?b.toFixed(2):b.constructor===String?'"'+b+'"':b.constructor===Boolean?String(b):b.toToolTip?b.toToolTip():"["+b.constructor.name+"]",null!=b)){b=b.substr(0,30);a.font="14px Courier New";var d=a.measureText(b).width+20;a.shadowColor=
|
||||
"black";a.shadowOffsetX=2;a.shadowOffsetY=2;a.shadowBlur=3;a.fillStyle="#454";a.beginPath();a.roundRect(c[0]-.5*d,c[1]-15-24,d,24,[3]);a.moveTo(c[0]-10,c[1]-15);a.lineTo(c[0]+10,c[1]-15);a.lineTo(c[0],c[1]-5);a.fill();a.shadowColor="transparent";a.textAlign="center";a.fillStyle="#CEC";a.fillText(b,c[0],c[1]-15-24*.3)}};var x=new Float32Array(4);m.prototype.drawNodeShape=function(a,b,c,d,e,f,h){b.strokeStyle=d;b.fillStyle=e;e=g.NODE_TITLE_HEIGHT;var k=.5>this.ds.scale,q=a._shape||a.constructor.shape||
|
||||
g.ROUND_SHAPE,p=a.constructor.title_mode,t=!0;p==g.TRANSPARENT_TITLE||p==g.NO_TITLE?t=!1:p==g.AUTOHIDE_TITLE&&h&&(t=!0);x[0]=0;x[1]=t?-e:0;x[2]=c[0]+1;x[3]=t?c[1]+e:c[1];h=b.globalAlpha;b.beginPath();q==g.BOX_SHAPE||k?b.fillRect(x[0],x[1],x[2],x[3]):q==g.ROUND_SHAPE||q==g.CARD_SHAPE?b.roundRect(x[0],x[1],x[2],x[3],q==g.CARD_SHAPE?[this.round_radius,this.round_radius,0,0]:[this.round_radius]):q==g.CIRCLE_SHAPE&&b.arc(.5*c[0],.5*c[1],.5*c[0],0,2*Math.PI);b.fill();!a.flags.collapsed&&t&&(b.shadowColor=
|
||||
"transparent",b.fillStyle="rgba(0,0,0,0.2)",b.fillRect(0,-1,x[2],2));b.shadowColor="transparent";if(a.onDrawBackground)a.onDrawBackground(b,this,this.canvas,this.graph_mouse);if(t||p==g.TRANSPARENT_TITLE){if(a.onDrawTitleBar)a.onDrawTitleBar(b,e,c,this.ds.scale,d);else if(p!=g.TRANSPARENT_TITLE&&(a.constructor.title_color||this.render_title_colored)){t=a.constructor.title_color||d;a.flags.collapsed&&(b.shadowColor=g.DEFAULT_SHADOW_COLOR);if(this.use_gradients){var n=m.gradients[t];n||(n=m.gradients[t]=
|
||||
b.createLinearGradient(0,0,400,0),n.addColorStop(0,t),n.addColorStop(1,"#000"));b.fillStyle=n}else b.fillStyle=t;b.beginPath();q==g.BOX_SHAPE||k?b.rect(0,-e,c[0]+1,e):(q==g.ROUND_SHAPE||q==g.CARD_SHAPE)&&b.roundRect(0,-e,c[0]+1,e,a.flags.collapsed?[this.round_radius]:[this.round_radius,this.round_radius,0,0]);b.fill();b.shadowColor="transparent"}t=!1;g.node_box_coloured_by_mode&&g.NODE_MODES_COLORS[a.mode]&&(t=g.NODE_MODES_COLORS[a.mode]);g.node_box_coloured_when_on&&(t=a.action_triggered?"#FFF":
|
||||
a.execute_triggered?"#AAA":t);if(a.onDrawTitleBox)a.onDrawTitleBox(b,e,c,this.ds.scale);else q==g.ROUND_SHAPE||q==g.CIRCLE_SHAPE||q==g.CARD_SHAPE?(k&&(b.fillStyle="black",b.beginPath(),b.arc(.5*e,-.5*e,6,0,2*Math.PI),b.fill()),b.fillStyle=a.boxcolor||t||g.NODE_DEFAULT_BOXCOLOR,k?b.fillRect(.5*e-5,-.5*e-5,10,10):(b.beginPath(),b.arc(.5*e,-.5*e,5,0,2*Math.PI),b.fill())):(k&&(b.fillStyle="black",b.fillRect(.5*(e-10)-1,-.5*(e+10)-1,12,12)),b.fillStyle=a.boxcolor||t||g.NODE_DEFAULT_BOXCOLOR,b.fillRect(.5*
|
||||
(e-10),-.5*(e+10),10,10));b.globalAlpha=h;if(a.onDrawTitleText)a.onDrawTitleText(b,e,c,this.ds.scale,this.title_text_font,f);!k&&(b.font=this.title_text_font,h=String(a.getTitle()))&&(b.fillStyle=f?g.NODE_SELECTED_TITLE_COLOR:a.constructor.title_text_color||this.node_title_color,a.flags.collapsed?(b.textAlign="left",b.measureText(h),b.fillText(h.substr(0,20),e,g.NODE_TITLE_TEXT_Y-e),b.textAlign="left"):(b.textAlign="left",b.fillText(h,e,g.NODE_TITLE_TEXT_Y-e)));a.flags.collapsed||!a.subgraph||a.skip_subgraph_button||
|
||||
(h=g.NODE_TITLE_HEIGHT,t=a.size[0]-h,n=g.isInsideRectangle(this.graph_mouse[0]-a.pos[0],this.graph_mouse[1]-a.pos[1],t+2,-h+2,h-4,h-4),b.fillStyle=n?"#888":"#555",q==g.BOX_SHAPE||k?b.fillRect(t+2,-h+2,h-4,h-4):(b.beginPath(),b.roundRect(t+2,-h+2,h-4,h-4,[4]),b.fill()),b.fillStyle="#333",b.beginPath(),b.moveTo(t+.2*h,.6*-h),b.lineTo(t+.8*h,.6*-h),b.lineTo(t+.5*h,.3*-h),b.fill());if(a.onDrawTitle)a.onDrawTitle(b)}if(f){if(a.onBounding)a.onBounding(x);p==g.TRANSPARENT_TITLE&&(x[1]-=e,x[3]+=e);b.lineWidth=
|
||||
1;b.globalAlpha=.8;b.beginPath();q==g.BOX_SHAPE?b.rect(-6+x[0],-6+x[1],12+x[2],12+x[3]):q==g.ROUND_SHAPE||q==g.CARD_SHAPE&&a.flags.collapsed?b.roundRect(-6+x[0],-6+x[1],12+x[2],12+x[3],[2*this.round_radius]):q==g.CARD_SHAPE?b.roundRect(-6+x[0],-6+x[1],12+x[2],12+x[3],[2*this.round_radius,2,2*this.round_radius,2]):q==g.CIRCLE_SHAPE&&b.arc(.5*c[0],.5*c[1],.5*c[0]+6,0,2*Math.PI);b.strokeStyle=g.NODE_BOX_OUTLINE_COLOR;b.stroke();b.strokeStyle=d;b.globalAlpha=1}0<a.execute_triggered&&a.execute_triggered--;
|
||||
0<a.action_triggered&&a.action_triggered--};var G=new Float32Array(4),C=new Float32Array(4),J=new Float32Array(2),K=new Float32Array(2);m.prototype.drawConnections=function(a){var b=g.getTime(),c=this.visible_area;G[0]=c[0]-20;G[1]=c[1]-20;G[2]=c[2]+40;G[3]=c[3]+40;a.lineWidth=this.connections_width;a.fillStyle="#AAA";a.strokeStyle="#AAA";a.globalAlpha=this.editor_alpha;c=this.graph._nodes;for(var d=0,e=c.length;d<e;++d){var f=c[d];if(f.inputs&&f.inputs.length)for(var h=0;h<f.inputs.length;++h){var k=
|
||||
f.inputs[h];if(k&&null!=k.link&&(k=this.graph.links[k.link])){var q=this.graph.getNodeById(k.origin_id);if(null!=q){var p=k.origin_slot;var t=-1==p?[q.pos[0]+10,q.pos[1]+10]:q.getConnectionPos(!1,p,J);var n=f.getConnectionPos(!0,h,K);C[0]=t[0];C[1]=t[1];C[2]=n[0]-t[0];C[3]=n[1]-t[1];0>C[2]&&(C[0]+=C[2],C[2]=Math.abs(C[2]));0>C[3]&&(C[1]+=C[3],C[3]=Math.abs(C[3]));if(F(C,G)){var m=q.outputs[p];p=f.inputs[h];if(m&&p&&(q=m.dir||(q.horizontal?g.DOWN:g.RIGHT),p=p.dir||(f.horizontal?g.UP:g.LEFT),this.renderLink(a,
|
||||
t,n,k,!1,0,null,q,p),k&&k._last_time&&1E3>b-k._last_time)){m=2-.002*(b-k._last_time);var l=a.globalAlpha;a.globalAlpha=l*m;this.renderLink(a,t,n,k,!0,m,"white",q,p);a.globalAlpha=l}}}}}}a.globalAlpha=1};m.prototype.renderLink=function(a,b,c,d,e,f,h,k,q,p){d&&this.visible_links.push(d);!h&&d&&(h=d.color||m.link_type_colors[d.type]);h||(h=this.default_link_color);null!=d&&this.highlighted_links[d.id]&&(h="#FFF");k=k||g.RIGHT;q=q||g.LEFT;var t=H(b,c);this.render_connections_border&&.6<this.ds.scale&&
|
||||
(a.lineWidth=this.connections_width+4);a.lineJoin="round";p=p||1;1<p&&(a.lineWidth=.5);a.beginPath();for(var n=0;n<p;n+=1){var l=5*(n-.5*(p-1));if(this.links_render_mode==g.SPLINE_LINK){a.moveTo(b[0],b[1]+l);var r=0,u=0,v=0,w=0;switch(k){case g.LEFT:r=-.25*t;break;case g.RIGHT:r=.25*t;break;case g.UP:u=-.25*t;break;case g.DOWN:u=.25*t}switch(q){case g.LEFT:v=-.25*t;break;case g.RIGHT:v=.25*t;break;case g.UP:w=-.25*t;break;case g.DOWN:w=.25*t}a.bezierCurveTo(b[0]+r,b[1]+u+l,c[0]+v,c[1]+w+l,c[0],c[1]+
|
||||
l)}else if(this.links_render_mode==g.LINEAR_LINK){a.moveTo(b[0],b[1]+l);w=v=u=r=0;switch(k){case g.LEFT:r=-1;break;case g.RIGHT:r=1;break;case g.UP:u=-1;break;case g.DOWN:u=1}switch(q){case g.LEFT:v=-1;break;case g.RIGHT:v=1;break;case g.UP:w=-1;break;case g.DOWN:w=1}a.lineTo(b[0]+15*r,b[1]+15*u+l);a.lineTo(c[0]+15*v,c[1]+15*w+l);a.lineTo(c[0],c[1]+l)}else if(this.links_render_mode==g.STRAIGHT_LINK)a.moveTo(b[0],b[1]),l=b[0],r=b[1],u=c[0],v=c[1],k==g.RIGHT?l+=10:r+=10,q==g.LEFT?u-=10:v-=10,a.lineTo(l,
|
||||
r),a.lineTo(.5*(l+u),r),a.lineTo(.5*(l+u),v),a.lineTo(u,v),a.lineTo(c[0],c[1]);else return}this.render_connections_border&&.6<this.ds.scale&&!e&&(a.strokeStyle="rgba(0,0,0,0.5)",a.stroke());a.lineWidth=this.connections_width;a.fillStyle=a.strokeStyle=h;a.stroke();e=this.computeConnectionPoint(b,c,.5,k,q);d&&d._pos&&(d._pos[0]=e[0],d._pos[1]=e[1]);.6<=this.ds.scale&&this.highquality_render&&q!=g.CENTER&&(this.render_connection_arrows&&(n=this.computeConnectionPoint(b,c,.25,k,q),t=this.computeConnectionPoint(b,
|
||||
c,.26,k,q),d=this.computeConnectionPoint(b,c,.75,k,q),p=this.computeConnectionPoint(b,c,.76,k,q),this.render_curved_connections?(t=-Math.atan2(t[0]-n[0],t[1]-n[1]),p=-Math.atan2(p[0]-d[0],p[1]-d[1])):p=t=c[1]>b[1]?0:Math.PI,a.save(),a.translate(n[0],n[1]),a.rotate(t),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore(),a.save(),a.translate(d[0],d[1]),a.rotate(p),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore()),a.beginPath(),a.arc(e[0],e[1],
|
||||
5,0,2*Math.PI),a.fill());if(f)for(a.fillStyle=h,n=0;5>n;++n)f=(.001*g.getTime()+.2*n)%1,e=this.computeConnectionPoint(b,c,f,k,q),a.beginPath(),a.arc(e[0],e[1],5,0,2*Math.PI),a.fill()};m.prototype.computeConnectionPoint=function(a,b,c,d,e){d=d||g.RIGHT;e=e||g.LEFT;var f=H(a,b),h=[a[0],a[1]],k=[b[0],b[1]];switch(d){case g.LEFT:h[0]+=-.25*f;break;case g.RIGHT:h[0]+=.25*f;break;case g.UP:h[1]+=-.25*f;break;case g.DOWN:h[1]+=.25*f}switch(e){case g.LEFT:k[0]+=-.25*f;break;case g.RIGHT:k[0]+=.25*f;break;
|
||||
case g.UP:k[1]+=-.25*f;break;case g.DOWN:k[1]+=.25*f}d=(1-c)*(1-c)*(1-c);e=3*(1-c)*(1-c)*c;f=3*(1-c)*c*c;c*=c*c;return[d*a[0]+e*h[0]+f*k[0]+c*b[0],d*a[1]+e*h[1]+f*k[1]+c*b[1]]};m.prototype.drawExecutionOrder=function(a){a.shadowColor="transparent";a.globalAlpha=.25;a.textAlign="center";a.strokeStyle="white";a.globalAlpha=.75;for(var b=this.visible_nodes,c=0;c<b.length;++c){var d=b[c];a.fillStyle="black";a.fillRect(d.pos[0]-g.NODE_TITLE_HEIGHT,d.pos[1]-g.NODE_TITLE_HEIGHT,g.NODE_TITLE_HEIGHT,g.NODE_TITLE_HEIGHT);
|
||||
0==d.order&&a.strokeRect(d.pos[0]-g.NODE_TITLE_HEIGHT+.5,d.pos[1]-g.NODE_TITLE_HEIGHT+.5,g.NODE_TITLE_HEIGHT,g.NODE_TITLE_HEIGHT);a.fillStyle="#FFF";a.fillText(d.order,d.pos[0]+-.5*g.NODE_TITLE_HEIGHT,d.pos[1]-6)}a.globalAlpha=1};m.prototype.drawNodeWidgets=function(a,b,c,d){if(!a.widgets||!a.widgets.length)return 0;var e=a.size[0],f=a.widgets;b+=2;var h=g.NODE_WIDGET_HEIGHT,k=.5<this.ds.scale;c.save();c.globalAlpha=this.editor_alpha;for(var q=g.WIDGET_OUTLINE_COLOR,p=g.WIDGET_BGCOLOR,t=g.WIDGET_TEXT_COLOR,
|
||||
n=g.WIDGET_SECONDARY_TEXT_COLOR,m=0;m<f.length;++m){var l=f[m],u=b;l.y&&(u=l.y);l.last_y=u;c.strokeStyle=q;c.fillStyle="#222";c.textAlign="left";l.disabled&&(c.globalAlpha*=.5);var r=l.width||e;switch(l.type){case "button":l.clicked&&(c.fillStyle="#AAA",l.clicked=!1,this.dirty_canvas=!0);c.fillRect(15,u,r-30,h);k&&!l.disabled&&c.strokeRect(15,u,r-30,h);k&&(c.textAlign="center",c.fillStyle=t,c.fillText(l.name,.5*r,u+.7*h));break;case "toggle":c.textAlign="left";c.strokeStyle=q;c.fillStyle=p;c.beginPath();
|
||||
k?c.roundRect(15,u,r-30,h,[.5*h]):c.rect(15,u,r-30,h);c.fill();k&&!l.disabled&&c.stroke();c.fillStyle=l.value?"#89A":"#333";c.beginPath();c.arc(r-30,u+.5*h,.36*h,0,2*Math.PI);c.fill();k&&(c.fillStyle=n,null!=l.name&&c.fillText(l.name,30,u+.7*h),c.fillStyle=l.value?t:n,c.textAlign="right",c.fillText(l.value?l.options.on||"true":l.options.off||"false",r-40,u+.7*h));break;case "slider":c.fillStyle=p;c.fillRect(15,u,r-30,h);var v=l.options.max-l.options.min,w=(l.value-l.options.min)/v;c.fillStyle=d==
|
||||
l?"#89A":"#678";c.fillRect(15,u,w*(r-30),h);k&&!l.disabled&&c.strokeRect(15,u,r-30,h);l.marker&&(v=(l.marker-l.options.min)/v,c.fillStyle="#AA9",c.fillRect(15+v*(r-30),u,2,h));k&&(c.textAlign="center",c.fillStyle=t,c.fillText(l.name+" "+Number(l.value).toFixed(3),.5*r,u+.7*h));break;case "number":case "combo":c.textAlign="left";c.strokeStyle=q;c.fillStyle=p;c.beginPath();k?c.roundRect(15,u,r-30,h,[.5*h]):c.rect(15,u,r-30,h);c.fill();k&&(l.disabled||c.stroke(),c.fillStyle=t,l.disabled||(c.beginPath(),
|
||||
c.moveTo(31,u+5),c.lineTo(21,u+.5*h),c.lineTo(31,u+h-5),c.fill(),c.beginPath(),c.moveTo(r-15-16,u+5),c.lineTo(r-15-6,u+.5*h),c.lineTo(r-15-16,u+h-5),c.fill()),c.fillStyle=n,c.fillText(l.name,35,u+.7*h),c.fillStyle=t,c.textAlign="right","number"==l.type?c.fillText(Number(l.value).toFixed(void 0!==l.options.precision?l.options.precision:3),r-30-20,u+.7*h):(v=l.value,l.options.values&&(w=l.options.values,w.constructor===Function&&(w=w()),w&&w.constructor!==Array&&(v=w[l.value])),c.fillText(v,r-30-20,
|
||||
u+.7*h)));break;case "string":case "text":c.textAlign="left";c.strokeStyle=q;c.fillStyle=p;c.beginPath();k?c.roundRect(15,u,r-30,h,[.5*h]):c.rect(15,u,r-30,h);c.fill();k&&(l.disabled||c.stroke(),c.save(),c.beginPath(),c.rect(15,u,r-30,h),c.clip(),c.fillStyle=n,null!=l.name&&c.fillText(l.name,30,u+.7*h),c.fillStyle=t,c.textAlign="right",c.fillText(String(l.value).substr(0,30),r-30,u+.7*h),c.restore());break;default:l.draw&&l.draw(c,a,r,u,h)}b+=(l.computeSize?l.computeSize(r)[1]:h)+4;c.globalAlpha=
|
||||
this.editor_alpha}c.restore();c.textAlign="left"};m.prototype.processNodeWidgets=function(a,b,c,d){function e(d,e){d.value=e;d.options&&d.options.property&&void 0!==a.properties[d.options.property]&&a.setProperty(d.options.property,e);d.callback&&d.callback(d.value,q,a,b,c)}if(!a.widgets||!a.widgets.length)return null;for(var f=b[0]-a.pos[0],h=b[1]-a.pos[1],k=a.size[0],q=this,p=this.getCanvasWindow(),t=0;t<a.widgets.length;++t){var n=a.widgets[t];if(n&&!n.disabled){var m=n.computeSize?n.computeSize(k)[1]:
|
||||
g.NODE_WIDGET_HEIGHT,l=n.width||k;if(n==d||!(6>f||f>l-12||h<n.last_y||h>n.last_y+m||void 0===n.last_y)){d=n.value;switch(n.type){case "button":c.type===g.pointerevents_method+"down"&&(n.callback&&setTimeout(function(){n.callback(n,q,a,b,c)},20),this.dirty_canvas=n.clicked=!0);break;case "slider":p=Math.clamp((f-15)/(l-30),0,1);n.value=n.options.min+(n.options.max-n.options.min)*p;n.callback&&setTimeout(function(){e(n,n.value)},20);this.dirty_canvas=!0;break;case "number":case "combo":d=n.value;if(c.type==
|
||||
g.pointerevents_method+"move"&&"number"==n.type)c.deltaX&&(n.value+=.1*c.deltaX*(n.options.step||1)),null!=n.options.min&&n.value<n.options.min&&(n.value=n.options.min),null!=n.options.max&&n.value>n.options.max&&(n.value=n.options.max);else if(c.type==g.pointerevents_method+"down"){var u=n.options.values;u&&u.constructor===Function&&(u=n.options.values(n,a));var r=null;"number"!=n.type&&(r=u.constructor===Array?u:Object.keys(u));f=40>f?-1:f>l-40?1:0;if("number"==n.type)n.value+=.1*f*(n.options.step||
|
||||
1),null!=n.options.min&&n.value<n.options.min&&(n.value=n.options.min),null!=n.options.max&&n.value>n.options.max&&(n.value=n.options.max);else if(f)p=-1,this.last_mouseclick=0,p=u.constructor===Object?r.indexOf(String(n.value))+f:r.indexOf(n.value)+f,p>=r.length&&(p=r.length-1),0>p&&(p=0),n.value=u.constructor===Array?u[p]:p;else{var v=u!=r?Object.values(u):u;new g.ContextMenu(v,{scale:Math.max(1,this.ds.scale),event:c,className:"dark",callback:function(a,b,c){u!=r&&(a=v.indexOf(a));this.value=a;
|
||||
e(this,a);q.dirty_canvas=!0;return!1}.bind(n)},p)}}else c.type==g.pointerevents_method+"up"&&"number"==n.type&&(f=40>f?-1:f>l-40?1:0,200>c.click_time&&0==f&&this.prompt("Value",n.value,function(a){this.value=Number(a);e(this,this.value)}.bind(n),c));d!=n.value&&setTimeout(function(){e(this,this.value)}.bind(n),20);this.dirty_canvas=!0;break;case "toggle":c.type==g.pointerevents_method+"down"&&(n.value=!n.value,setTimeout(function(){e(n,n.value)},20));break;case "string":case "text":c.type==g.pointerevents_method+
|
||||
"down"&&this.prompt("Value",n.value,function(a){this.value=a;e(this,a)}.bind(n),c,n.options?n.options.multiline:!1);break;default:n.mouse&&(this.dirty_canvas=n.mouse(c,[f,h],a))}if(d!=n.value){if(a.onWidgetChanged)a.onWidgetChanged(n.name,n.value,d,n);a.graph._version++}return n}}}return null};m.prototype.drawGroups=function(a,b){if(this.graph){a=this.graph._groups;b.save();b.globalAlpha=.5*this.editor_alpha;for(var c=0;c<a.length;++c){var d=a[c];if(F(this.visible_area,d._bounding)){b.fillStyle=d.color||
|
||||
"#335";b.strokeStyle=d.color||"#335";var e=d._pos,f=d._size;b.globalAlpha=.25*this.editor_alpha;b.beginPath();b.rect(e[0]+.5,e[1]+.5,f[0],f[1]);b.fill();b.globalAlpha=this.editor_alpha;b.stroke();b.beginPath();b.moveTo(e[0]+f[0],e[1]+f[1]);b.lineTo(e[0]+f[0]-10,e[1]+f[1]);b.lineTo(e[0]+f[0],e[1]+f[1]-10);b.fill();f=d.font_size||g.DEFAULT_GROUP_FONT_SIZE;b.font=f+"px Arial";b.textAlign="left";b.fillText(d.title,e[0]+4,e[1]+f)}}b.restore()}};m.prototype.adjustNodesSize=function(){for(var a=this.graph._nodes,
|
||||
b=0;b<a.length;++b)a[b].size=a[b].computeSize();this.setDirty(!0,!0)};m.prototype.resize=function(a,b){a||b||(b=this.canvas.parentNode,a=b.offsetWidth,b=b.offsetHeight);if(this.canvas.width!=a||this.canvas.height!=b)this.canvas.width=a,this.canvas.height=b,this.bgcanvas.width=this.canvas.width,this.bgcanvas.height=this.canvas.height,this.setDirty(!0,!0)};m.prototype.switchLiveMode=function(a){if(a){var b=this,c=this.live_mode?1.1:.9;this.live_mode&&(this.live_mode=!1,this.editor_alpha=.1);var d=setInterval(function(){b.editor_alpha*=
|
||||
c;b.dirty_canvas=!0;b.dirty_bgcanvas=!0;1>c&&.01>b.editor_alpha&&(clearInterval(d),1>c&&(b.live_mode=!0));1<c&&.99<b.editor_alpha&&(clearInterval(d),b.editor_alpha=1)},1)}else this.live_mode=!this.live_mode,this.dirty_bgcanvas=this.dirty_canvas=!0};m.prototype.onNodeSelectionChange=function(a){};m.onGroupAdd=function(a,b,c){a=m.active_canvas;a.getCanvasWindow();b=new g.LGraphGroup;b.pos=a.convertEventToCanvasOffset(c);a.graph.add(b)};m.onMenuAdd=function(a,b,c,d,e){function f(a,b){var d=[];g.getNodeTypesCategories(h.filter||
|
||||
q.filter).filter(function(b){return b.startsWith(a)}).map(function(b){if(b){b=b.replace(new RegExp("^("+a+")"),"").split("/")[0];var c=""===a?b+"/":a+b+"/";-1!=b.indexOf("::")&&(b=b.split("::")[1]);-1===d.findIndex(function(a){return a.value===c})&&d.push({value:c,content:b,has_submenu:!0,callback:function(a,b,c,d){f(a.value,d)}})}});g.getNodeTypesInCategory(a.slice(0,-1),h.filter||q.filter).map(function(a){a.skip_list||d.push({value:a.type,content:a.title,has_submenu:!1,callback:function(a,b,c,d){b=
|
||||
d.getFirstEvent();h.graph.beforeChange();if(a=g.createNode(a.value))a.pos=h.convertEventToCanvasOffset(b),h.graph.add(a);e&&e(a);h.graph.afterChange()}})});new g.ContextMenu(d,{event:c,parentMenu:b},k)}var h=m.active_canvas,k=h.getCanvasWindow(),q=h.graph;if(q)return f("",d),!1};m.onMenuCollapseAll=function(){};m.onMenuNodeEdit=function(){};m.showMenuNodeOptionalInputs=function(a,b,c,d,e){if(e){var f=this;a=m.active_canvas.getCanvasWindow();b=e.optional_inputs;e.onGetInputs&&(b=e.onGetInputs());var h=
|
||||
[];if(b)for(var k=0;k<b.length;k++){var q=b[k];if(q){var p=q[0];q[2]||(q[2]={});q[2].label&&(p=q[2].label);q[2].removable=!0;p={content:p,value:q};q[1]==g.ACTION&&(p.className="event");h.push(p)}else h.push(null)}e.onMenuNodeInputs&&(b=e.onMenuNodeInputs(h))&&(h=b);if(h.length)return new g.ContextMenu(h,{event:c,callback:function(a,b,c){if(e&&(a.callback&&a.callback.call(f,e,a,b,c),a.value)){e.graph.beforeChange();e.addInput(a.value[0],a.value[1],a.value[2]);if(e.onNodeInputAdd)e.onNodeInputAdd(a.value);
|
||||
e.setDirtyCanvas(!0,!0);e.graph.afterChange()}},parentMenu:d,node:e},a),!1;console.log("no input entries")}};m.showMenuNodeOptionalOutputs=function(a,b,c,d,e){function f(a,b,c){if(e&&(a.callback&&a.callback.call(h,e,a,b,c),a.value))if(c=a.value[1],!c||c.constructor!==Object&&c.constructor!==Array){e.graph.beforeChange();e.addOutput(a.value[0],a.value[1],a.value[2]);if(e.onNodeOutputAdd)e.onNodeOutputAdd(a.value);e.setDirtyCanvas(!0,!0);e.graph.afterChange()}else{a=[];for(var k in c)a.push({content:k,
|
||||
value:c[k]});new g.ContextMenu(a,{event:b,callback:f,parentMenu:d,node:e});return!1}}if(e){var h=this;a=m.active_canvas.getCanvasWindow();b=e.optional_outputs;e.onGetOutputs&&(b=e.onGetOutputs());var k=[];if(b)for(var q=0;q<b.length;q++){var p=b[q];if(!p)k.push(null);else if(!e.flags||!e.flags.skip_repeated_outputs||-1==e.findOutputSlot(p[0])){var t=p[0];p[2]||(p[2]={});p[2].label&&(t=p[2].label);p[2].removable=!0;t={content:t,value:p};p[1]==g.EVENT&&(t.className="event");k.push(t)}}this.onMenuNodeOutputs&&
|
||||
(k=this.onMenuNodeOutputs(k));g.do_add_triggers_slots&&-1==e.findOutputSlot("onExecuted")&&k.push({content:"On Executed",value:["onExecuted",g.EVENT,{nameLocked:!0}],className:"event"});e.onMenuNodeOutputs&&(b=e.onMenuNodeOutputs(k))&&(k=b);if(k.length)return new g.ContextMenu(k,{event:c,callback:f,parentMenu:d,node:e},a),!1}};m.onShowMenuNodeProperties=function(a,b,c,d,e){if(e&&e.properties){var f=m.active_canvas;b=f.getCanvasWindow();var h=[],k;for(k in e.properties){a=void 0!==e.properties[k]?
|
||||
e.properties[k]:" ";"object"==typeof a&&(a=JSON.stringify(a));var q=e.getPropertyInfo(k);if("enum"==q.type||"combo"==q.type)a=m.getPropertyPrintableValue(a,q.values);a=m.decodeHTML(a);h.push({content:"<span class='property_name'>"+(q.label?q.label:k)+"</span><span class='property_value'>"+a+"</span>",value:k})}if(h.length)return new g.ContextMenu(h,{event:c,callback:function(a,b,c,d){e&&(b=this.getBoundingClientRect(),f.showEditPropertyValue(e,a.value,{position:[b.left,b.top]}))},parentMenu:d,allow_html:!0,
|
||||
node:e},b),!1}};m.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};m.onMenuResizeNode=function(a,b,c,d,e){if(e){a=function(a){a.size=a.computeSize();if(a.onResize)a.onResize(a.size)};b=m.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)a(e);else for(var f in b.selected_nodes)a(b.selected_nodes[f]);e.setDirtyCanvas(!0,!0)}};m.prototype.showLinkMenu=function(a,b){var c=this,d=c.graph.getNodeById(a.origin_id),e=c.graph.getNodeById(a.target_id),
|
||||
f=!1;d&&d.outputs&&d.outputs[a.origin_slot]&&(f=d.outputs[a.origin_slot].type);var h=!1;e&&e.outputs&&e.outputs[a.target_slot]&&(h=e.inputs[a.target_slot].type);var k=new g.ContextMenu(["Add Node",null,"Delete",null],{event:b,title:null!=a.data?a.data.constructor.name:null,callback:function(b,g,t){switch(b){case "Add Node":m.onMenuAdd(null,null,t,k,function(b){b.inputs&&b.inputs.length&&b.outputs&&b.outputs.length&&d.connectByType(a.origin_slot,b,f)&&(b.connectByType(a.target_slot,e,h),b.pos[0]-=
|
||||
.5*b.size[0])});break;case "Delete":c.graph.removeLink(a.id)}}});return!1};m.prototype.createDefaultNodeForSlot=function(a){a=a||{};a=Object.assign({nodeFrom:null,slotFrom:null,nodeTo:null,slotTo:null,position:[],nodeType:null,posAdd:[0,0],posSizeFix:[0,0]},a);var b=a.nodeFrom&&null!==a.slotFrom,c=!b&&a.nodeTo&&null!==a.slotTo;if(!b&&!c)return console.warn("No data passed to createDefaultNodeForSlot "+a.nodeFrom+" "+a.slotFrom+" "+a.nodeTo+" "+a.slotTo),!1;if(!a.nodeType)return console.warn("No type to createDefaultNodeForSlot"),
|
||||
!1;var d=b?a.nodeFrom:a.nodeTo,e=b?a.slotFrom:a.slotTo;switch(typeof e){case "string":c=b?d.findOutputSlot(e,!1):d.findInputSlot(e,!1);e=b?d.outputs[e]:d.inputs[e];break;case "object":c=b?d.findOutputSlot(e.name):d.findInputSlot(e.name);break;case "number":c=e;e=b?d.outputs[e]:d.inputs[e];break;default:return console.warn("Cant get slot information "+e),!1}!1!==e&&!1!==c||console.warn("createDefaultNodeForSlot bad slotX "+e+" "+c);d=e.type==g.EVENT?"_event_":e.type;if((e=b?g.slot_types_default_out:
|
||||
g.slot_types_default_in)&&e[d]){nodeNewType=!1;if("object"==typeof e[d]||"array"==typeof e[d])for(var f in e[d]){if(a.nodeType==e[d][f]||"AUTO"==a.nodeType){nodeNewType=e[d][f];break}}else if(a.nodeType==e[d]||"AUTO"==a.nodeType)nodeNewType=e[d];if(nodeNewType){f=!1;"object"==typeof nodeNewType&&nodeNewType.node&&(f=nodeNewType,nodeNewType=nodeNewType.node);if(e=g.createNode(nodeNewType)){if(f){if(f.properties)for(var h in f.properties)e.addProperty(h,f.properties[h]);if(f.inputs)for(h in e.inputs=
|
||||
[],f.inputs)e.addOutput(f.inputs[h][0],f.inputs[h][1]);if(f.outputs)for(h in e.outputs=[],f.outputs)e.addOutput(f.outputs[h][0],f.outputs[h][1]);f.title&&(e.title=f.title);f.json&&e.configure(f.json)}this.graph.add(e);e.pos=[a.position[0]+a.posAdd[0]+(a.posSizeFix[0]?a.posSizeFix[0]*e.size[0]:0),a.position[1]+a.posAdd[1]+(a.posSizeFix[1]?a.posSizeFix[1]*e.size[1]:0)];b?a.nodeFrom.connectByType(c,e,d):a.nodeTo.connectByTypeOutput(c,e,d);return!0}console.log("failed creating "+nodeNewType)}}return!1};
|
||||
m.prototype.showConnectionMenu=function(a){a=a||{};var b=Object.assign({nodeFrom:null,slotFrom:null,nodeTo:null,slotTo:null,e:null},a),c=this,d=b.nodeFrom&&b.slotFrom;a=!d&&b.nodeTo&&b.slotTo;if(!d&&!a)return console.warn("No data passed to showConnectionMenu"),!1;a=d?b.nodeFrom:b.nodeTo;var e=d?b.slotFrom:b.slotTo,f=!1;switch(typeof e){case "string":f=d?a.findOutputSlot(e,!1):a.findInputSlot(e,!1);e=d?a.outputs[e]:a.inputs[e];break;case "object":f=d?a.findOutputSlot(e.name):a.findInputSlot(e.name);
|
||||
break;case "number":f=e;e=d?a.outputs[e]:a.inputs[e];break;default:return console.warn("Cant get slot information "+e),!1}a=["Add Node",null];c.allow_searchbox&&(a.push("Search"),a.push(null));var h=e.type==g.EVENT?"_event_":e.type,k=d?g.slot_types_default_out:g.slot_types_default_in;if(k&&k[h])if("object"==typeof k[h]||"array"==typeof k[h])for(var q in k[h])a.push(k[h][q]);else a.push(k[h]);var p=new g.ContextMenu(a,{event:b.e,title:(e&&""!=e.name?e.name+(h?" | ":""):"")+(e&&h?h:""),callback:function(a,
|
||||
g,k){switch(a){case "Add Node":m.onMenuAdd(null,null,k,p,function(a){d?b.nodeFrom.connectByType(f,a,h):b.nodeTo.connectByTypeOutput(f,a,h)});break;case "Search":d?c.showSearchBox(k,{node_from:b.nodeFrom,slot_from:e,type_filter_in:h}):c.showSearchBox(k,{node_to:b.nodeTo,slot_from:e,type_filter_out:h});break;default:c.createDefaultNodeForSlot(Object.assign(b,{position:[b.e.canvasX,b.e.canvasY],nodeType:a}))}}});return!1};m.onShowPropertyEditor=function(a,b,c,d,e){function f(){if(q){var b=q.value;"Number"==
|
||||
a.type?b=Number(b):"Boolean"==a.type&&(b=!!b);e[h]=b;k.parentNode&&k.parentNode.removeChild(k);e.setDirtyCanvas(!0,!0)}}var h=a.property||"title";b=e[h];var k=document.createElement("div");k.is_modified=!1;k.className="graphdialog";k.innerHTML="<span class='name'></span><input autofocus type='text' class='value'/><button>OK</button>";k.close=function(){k.parentNode&&k.parentNode.removeChild(k)};k.querySelector(".name").innerText=h;var q=k.querySelector(".value");q&&(q.value=b,q.addEventListener("blur",
|
||||
function(a){this.focus()}),q.addEventListener("keydown",function(a){k.is_modified=!0;if(27==a.keyCode)k.close();else if(13==a.keyCode)f();else if(13!=a.keyCode&&"textarea"!=a.target.localName)return;a.preventDefault();a.stopPropagation()}));b=m.active_canvas.canvas;c=b.getBoundingClientRect();var p=d=-20;c&&(d-=c.left,p-=c.top);event?(k.style.left=event.clientX+d+"px",k.style.top=event.clientY+p+"px"):(k.style.left=.5*b.width+d+"px",k.style.top=.5*b.height+p+"px");k.querySelector("button").addEventListener("click",
|
||||
f);b.parentNode.appendChild(k);q&&q.focus();var t=null;k.addEventListener("mouseleave",function(a){g.dialog_close_on_mouse_leave&&!k.is_modified&&g.dialog_close_on_mouse_leave&&(t=setTimeout(k.close,g.dialog_close_on_mouse_leave_delay))});k.addEventListener("mouseenter",function(a){g.dialog_close_on_mouse_leave&&t&&clearTimeout(t)})};m.prototype.prompt=function(a,b,c,d,e){var f=this;a=a||"";var h=document.createElement("div");h.is_modified=!1;h.className="graphdialog rounded";h.innerHTML=e?"<span class='name'></span> <textarea autofocus class='value'></textarea><button class='rounded'>OK</button>":
|
||||
"<span class='name'></span> <input autofocus type='text' class='value'/><button class='rounded'>OK</button>";h.close=function(){f.prompt_box=null;h.parentNode&&h.parentNode.removeChild(h)};e=m.active_canvas.canvas;e.parentNode.appendChild(h);1<this.ds.scale&&(h.style.transform="scale("+this.ds.scale+")");var k=null,q=!1;g.pointerListenerAdd(h,"leave",function(a){q||g.dialog_close_on_mouse_leave&&!h.is_modified&&g.dialog_close_on_mouse_leave&&(k=setTimeout(h.close,g.dialog_close_on_mouse_leave_delay))});
|
||||
g.pointerListenerAdd(h,"enter",function(a){g.dialog_close_on_mouse_leave&&k&&clearTimeout(k)});var p=h.querySelectorAll("select");p&&p.forEach(function(a){a.addEventListener("click",function(a){q++});a.addEventListener("blur",function(a){q=0});a.addEventListener("change",function(a){q=-1})});f.prompt_box&&f.prompt_box.close();f.prompt_box=h;h.querySelector(".name").innerText=a;var t=h.querySelector(".value");t.value=b;t.addEventListener("keydown",function(a){h.is_modified=!0;if(27==a.keyCode)h.close();
|
||||
else if(13==a.keyCode&&"textarea"!=a.target.localName)c&&c(this.value),h.close();else return;a.preventDefault();a.stopPropagation()});h.querySelector("button").addEventListener("click",function(a){c&&c(t.value);f.setDirty(!0);h.close()});a=e.getBoundingClientRect();p=b=-20;a&&(b-=a.left,p-=a.top);d?(h.style.left=d.clientX+b+"px",h.style.top=d.clientY+p+"px"):(h.style.left=.5*e.width+b+"px",h.style.top=.5*e.height+p+"px");setTimeout(function(){t.focus()},10);return h};m.search_limit=-1;m.prototype.showSearchBox=
|
||||
function(a,b){function c(c){if(c)if(f.onSearchBoxSelection)f.onSearchBoxSelection(c,a,h);else{var d=g.searchbox_extras[c.toLowerCase()];d&&(c=d.type);h.graph.beforeChange();if(c=g.createNode(c))c.pos=h.convertEventToCanvasOffset(a),h.graph.add(c,!1);if(d&&d.data){if(d.data.properties)for(var e in d.data.properties)c.addProperty(e,d.data.properties[e]);if(d.data.inputs)for(e in c.inputs=[],d.data.inputs)c.addOutput(d.data.inputs[e][0],d.data.inputs[e][1]);if(d.data.outputs)for(e in c.outputs=[],d.data.outputs)c.addOutput(d.data.outputs[e][0],
|
||||
d.data.outputs[e][1]);d.data.title&&(c.title=d.data.title);d.data.json&&c.configure(d.data.json)}if(b.node_from){switch(typeof b.slot_from){case "string":d=b.node_from.findOutputSlot(b.slot_from);break;case "object":d=b.slot_from.name?b.node_from.findOutputSlot(b.slot_from.name):-1;-1==d&&"undefined"!==typeof b.slot_from.slot_index&&(d=b.slot_from.slot_index);break;case "number":d=b.slot_from;break;default:d=0}!1!==d&&-1<d&&b.node_from.connectByType(d,c,b.node_from.outputs[d].type)}if(b.node_to){switch(typeof b.slot_from){case "string":d=
|
||||
b.node_to.findInputSlot(b.slot_from);break;case "object":d=b.slot_from.name?b.node_to.findInputSlot(b.slot_from.name):-1;-1==d&&"undefined"!==typeof b.slot_from.slot_index&&(d=b.slot_from.slot_index);break;case "number":d=b.slot_from;break;default:d=0}!1!==d&&-1<d&&b.node_to.connectByTypeOutput(d,c,b.node_to.inputs[d].type)}h.graph.afterChange()}q.close()}function d(a){var b=x;x&&x.classList.remove("selected");x?(x=a?x.nextSibling:x.previousSibling)||(x=b):x=a?u.childNodes[0]:u.childNodes[u.childNodes.length];
|
||||
b.node_to.findInputSlot(b.slot_from);break;case "object":d=b.slot_from.name?b.node_to.findInputSlot(b.slot_from.name):-1;-1==d&&"undefined"!==typeof b.slot_from.slot_index&&(d=b.slot_from.slot_index);break;case "number":d=b.slot_from;break;default:d=0}!1!==d&&-1<d&&b.node_to.connectByTypeOutput(d,c,b.node_to.inputs[d].type)}h.graph.afterChange()}p.close()}function d(a){var b=x;x&&x.classList.remove("selected");x?(x=a?x.nextSibling:x.previousSibling)||(x=b):x=a?u.childNodes[0]:u.childNodes[u.childNodes.length];
|
||||
x&&(x.classList.add("selected"),x.scrollIntoView({block:"end",behavior:"smooth"}))}function e(){function a(a,b){var d=document.createElement("div");v||(v=a);d.innerText=a;d.dataset.type=escape(a);d.className="litegraph lite-search-item";b&&(d.className+=" "+b);d.addEventListener("click",function(a){c(unescape(this.dataset.type))});u.appendChild(d)}w=null;var d=z.value;v=null;u.innerHTML="";if(d||b.show_all_if_empty)if(f.onSearchBox){var e=f.onSearchBox(u,d,h);if(e)for(var k=0;k<e.length;++k)a(e[k])}else{e=
|
||||
function(a,c){c=c||{};c=Object.assign({skipFilter:!1,inTypeOverride:!1,outTypeOverride:!1},c);var e=g.registered_node_types[a];if(q&&e.filter!=q||(!b.show_all_if_empty||d)&&-1===a.toLowerCase().indexOf(d))return!1;if(b.do_type_filter&&!c.skipFilter){e=l.value;!1!==c.inTypeOverride&&(e=c.inTypeOverride);if(l&&e&&g.registered_slot_in_types[e]&&g.registered_slot_in_types[e].nodes&&(e=g.registered_slot_in_types[e].nodes.includes(a),!1===e))return!1;e=r.value;!1!==c.outTypeOverride&&(e=c.outTypeOverride);
|
||||
if(r&&e&&g.registered_slot_out_types[e]&&g.registered_slot_out_types[e].nodes&&(e=g.registered_slot_out_types[e].nodes.includes(a),!1===e))return!1}return!0};var n=0;d=d.toLowerCase();var q=h.filter||h.graph.filter;if(b.do_type_filter&&f.search_box)var l=f.search_box.querySelector(".slot_in_type_filter"),r=f.search_box.querySelector(".slot_out_type_filter");else r=l=!1;for(k in g.searchbox_extras){var t=g.searchbox_extras[k];if(b.show_all_if_empty&&!d||-1!==t.desc.toLowerCase().indexOf(d)){var p=
|
||||
g.registered_node_types[t.type];if((!p||p.filter==q)&&e(t.type)&&(a(t.desc,"searchbox_extra"),-1!==m.search_limit&&n++>m.search_limit))break}}t=null;if(Array.prototype.filter)t=Object.keys(g.registered_node_types).filter(e);else for(k in t=[],g.registered_node_types)e(k)&&t.push(k);for(k=0;k<t.length&&!(a(t[k]),-1!==m.search_limit&&n++>m.search_limit);k++);if(b.show_general_after_typefiltered&&(l.value||r.value)){filtered_extra=[];for(k in g.registered_node_types)e(k,{inTypeOverride:l&&l.value?"*":
|
||||
!1,outTypeOverride:r&&r.value?"*":!1})&&filtered_extra.push(k);for(k=0;k<filtered_extra.length&&!(a(filtered_extra[k],"generic_type"),-1!==m.search_limit&&n++>m.search_limit);k++);}if((l.value||r.value)&&0==u.childNodes.length&&b.show_general_if_none_on_typefilter){filtered_extra=[];for(k in g.registered_node_types)e(k,{skipFilter:!0})&&filtered_extra.push(k);for(k=0;k<filtered_extra.length&&!(a(filtered_extra[k],"not_in_filter"),-1!==m.search_limit&&n++>m.search_limit);k++);}}}def_options={slot_from:null,
|
||||
node_from:null,node_to:null,do_type_filter:g.search_filter_enabled,type_filter_in:!1,type_filter_out:!1,show_general_if_none_on_typefilter:!0,show_general_after_typefiltered:!0,hide_on_mouse_leave:g.search_hide_on_mouse_leave,show_all_if_empty:!0,show_all_on_open:g.search_show_all_on_open};b=Object.assign(def_options,b||{});var f=this,h=m.active_canvas,k=h.canvas,n=k.ownerDocument||document,q=document.createElement("div");q.className="litegraph litesearchbox graphdialog rounded";q.innerHTML="<span class='name'>Search</span> <input autofocus type='text' class='value rounded'/>";
|
||||
b.do_type_filter&&(q.innerHTML+="<select class='slot_in_type_filter'><option value=''></option></select>",q.innerHTML+="<select class='slot_out_type_filter'><option value=''></option></select>");q.innerHTML+="<div class='helper'></div>";n.fullscreenElement?n.fullscreenElement.appendChild(q):(n.body.appendChild(q),n.body.style.overflow="hidden");if(b.do_type_filter)var t=q.querySelector(".slot_in_type_filter"),r=q.querySelector(".slot_out_type_filter");q.close=function(){f.search_box=null;this.blur();
|
||||
k.focus();n.body.style.overflow="";setTimeout(function(){f.canvas.focus()},20);q.parentNode&&q.parentNode.removeChild(q)};1<this.ds.scale&&(q.style.transform="scale("+this.ds.scale+")");if(b.hide_on_mouse_leave){var l=!1,p=null;g.pointerListenerAdd(q,"enter",function(a){p&&(clearTimeout(p),p=null)});g.pointerListenerAdd(q,"leave",function(a){l||(p=setTimeout(function(){q.close()},500))});b.do_type_filter&&(t.addEventListener("click",function(a){l++}),t.addEventListener("blur",function(a){l=0}),t.addEventListener("change",
|
||||
function(a){l=-1}),r.addEventListener("click",function(a){l++}),r.addEventListener("blur",function(a){l=0}),r.addEventListener("change",function(a){l=-1}))}f.search_box&&f.search_box.close();f.search_box=q;var u=q.querySelector(".helper"),v=null,w=null,x=null,z=q.querySelector("input");z&&(z.addEventListener("blur",function(a){this.focus()}),z.addEventListener("keydown",function(a){if(38==a.keyCode)d(!1);else if(40==a.keyCode)d(!0);else if(27==a.keyCode)q.close();else if(13==a.keyCode)x?c(x.innerHTML):
|
||||
v?c(v):q.close();else{w&&clearInterval(w);w=setTimeout(e,250);return}a.preventDefault();a.stopPropagation();a.stopImmediatePropagation();return!0}));if(b.do_type_filter){if(t){var y=g.slot_types_in,C=y.length;if(b.type_filter_in==g.EVENT||b.type_filter_in==g.ACTION)b.type_filter_in="_event_";for(var A=0;A<C;A++){var B=document.createElement("option");B.value=y[A];B.innerHTML=y[A];t.appendChild(B);!1!==b.type_filter_in&&(b.type_filter_in+"").toLowerCase()==(y[A]+"").toLowerCase()&&(B.selected=!0)}t.addEventListener("change",
|
||||
function(){e()})}if(r){y=g.slot_types_out;C=y.length;if(b.type_filter_out==g.EVENT||b.type_filter_out==g.ACTION)b.type_filter_out="_event_";for(A=0;A<C;A++)B=document.createElement("option"),B.value=y[A],B.innerHTML=y[A],r.appendChild(B),!1!==b.type_filter_out&&(b.type_filter_out+"").toLowerCase()==(y[A]+"").toLowerCase()&&(B.selected=!0);r.addEventListener("change",function(){e()})}}t=k.getBoundingClientRect();r=(a?a.clientY:t.top+.5*t.height)-20;q.style.left=(a?a.clientX:t.left+.5*t.width)-80+"px";
|
||||
q.style.top=r+"px";a.layerY>t.height-200&&(u.style.maxHeight=t.height-a.layerY-20+"px");z.focus();b.show_all_on_open&&e();return q};m.prototype.showEditPropertyValue=function(a,b,c){function d(){e(m.value)}function e(d){f&&f.values&&f.values.constructor===Object&&void 0!=f.values[d]&&(d=f.values[d]);"number"==typeof a.properties[b]&&(d=Number(d));if("array"==h||"object"==h)d=JSON.parse(d);a.properties[b]=d;a.graph&&a.graph._version++;if(a.onPropertyChanged)a.onPropertyChanged(b,d);if(c.onclose)c.onclose();
|
||||
l.close();a.setDirtyCanvas(!0,!0)}if(a&&void 0!==a.properties[b]){c=c||{};var f=a.getPropertyInfo(b),h=f.type,g="";if("string"==h||"number"==h||"array"==h||"object"==h)g="<input autofocus type='text' class='value'/>";else if("enum"!=h&&"combo"!=h||!f.values)if("boolean"==h||"toggle"==h)g="<input autofocus type='checkbox' class='value' "+(a.properties[b]?"checked":"")+"/>";else{console.warn("unknown type: "+h);return}else{g="<select autofocus type='text' class='value'>";for(var n in f.values){var q=
|
||||
n;f.values.constructor===Array&&(q=f.values[n]);g+="<option value='"+q+"' "+(q==a.properties[b]?"selected":"")+">"+f.values[n]+"</option>"}g+="</select>"}var l=this.createDialog("<span class='name'>"+(f.label?f.label:b)+"</span>"+g+"<button>OK</button>",c),m=!1;if("enum"!=h&&"combo"!=h||!f.values)if("boolean"==h||"toggle"==h)(m=l.querySelector("input"))&&m.addEventListener("click",function(a){l.modified();e(!!m.checked)});else{if(m=l.querySelector("input"))m.addEventListener("blur",function(a){this.focus()}),
|
||||
q=void 0!==a.properties[b]?a.properties[b]:"","string"!==h&&(q=JSON.stringify(q)),m.value=q,m.addEventListener("keydown",function(a){if(27==a.keyCode)l.close();else if(13==a.keyCode)d();else if(13!=a.keyCode){l.modified();return}a.preventDefault();a.stopPropagation()})}else m=l.querySelector("select"),m.addEventListener("change",function(a){l.modified();e(a.target.value)});m&&m.focus();l.querySelector("button").addEventListener("click",d);return l}};m.prototype.createDialog=function(a,b){def_options=
|
||||
function(a,c){c=c||{};c=Object.assign({skipFilter:!1,inTypeOverride:!1,outTypeOverride:!1},c);var e=g.registered_node_types[a];if(p&&e.filter!=p||(!b.show_all_if_empty||d)&&-1===a.toLowerCase().indexOf(d))return!1;if(b.do_type_filter&&!c.skipFilter){e=l.value;!1!==c.inTypeOverride&&(e=c.inTypeOverride);if(l&&e&&g.registered_slot_in_types[e]&&g.registered_slot_in_types[e].nodes&&(e=g.registered_slot_in_types[e].nodes.includes(a),!1===e))return!1;e=t.value;!1!==c.outTypeOverride&&(e=c.outTypeOverride);
|
||||
if(t&&e&&g.registered_slot_out_types[e]&&g.registered_slot_out_types[e].nodes&&(e=g.registered_slot_out_types[e].nodes.includes(a),!1===e))return!1}return!0};var q=0;d=d.toLowerCase();var p=h.filter||h.graph.filter;if(b.do_type_filter&&f.search_box)var l=f.search_box.querySelector(".slot_in_type_filter"),t=f.search_box.querySelector(".slot_out_type_filter");else t=l=!1;for(k in g.searchbox_extras){var n=g.searchbox_extras[k];if(b.show_all_if_empty&&!d||-1!==n.desc.toLowerCase().indexOf(d)){var r=
|
||||
g.registered_node_types[n.type];if((!r||r.filter==p)&&e(n.type)&&(a(n.desc,"searchbox_extra"),-1!==m.search_limit&&q++>m.search_limit))break}}n=null;if(Array.prototype.filter)n=Object.keys(g.registered_node_types).filter(e);else for(k in n=[],g.registered_node_types)e(k)&&n.push(k);for(k=0;k<n.length&&!(a(n[k]),-1!==m.search_limit&&q++>m.search_limit);k++);if(b.show_general_after_typefiltered&&(l.value||t.value)){filtered_extra=[];for(k in g.registered_node_types)e(k,{inTypeOverride:l&&l.value?"*":
|
||||
!1,outTypeOverride:t&&t.value?"*":!1})&&filtered_extra.push(k);for(k=0;k<filtered_extra.length&&!(a(filtered_extra[k],"generic_type"),-1!==m.search_limit&&q++>m.search_limit);k++);}if((l.value||t.value)&&0==u.childNodes.length&&b.show_general_if_none_on_typefilter){filtered_extra=[];for(k in g.registered_node_types)e(k,{skipFilter:!0})&&filtered_extra.push(k);for(k=0;k<filtered_extra.length&&!(a(filtered_extra[k],"not_in_filter"),-1!==m.search_limit&&q++>m.search_limit);k++);}}}def_options={slot_from:null,
|
||||
node_from:null,node_to:null,do_type_filter:g.search_filter_enabled,type_filter_in:!1,type_filter_out:!1,show_general_if_none_on_typefilter:!0,show_general_after_typefiltered:!0,hide_on_mouse_leave:g.search_hide_on_mouse_leave,show_all_if_empty:!0,show_all_on_open:g.search_show_all_on_open};b=Object.assign(def_options,b||{});var f=this,h=m.active_canvas,k=h.canvas,q=k.ownerDocument||document,p=document.createElement("div");p.className="litegraph litesearchbox graphdialog rounded";p.innerHTML="<span class='name'>Search</span> <input autofocus type='text' class='value rounded'/>";
|
||||
b.do_type_filter&&(p.innerHTML+="<select class='slot_in_type_filter'><option value=''></option></select>",p.innerHTML+="<select class='slot_out_type_filter'><option value=''></option></select>");p.innerHTML+="<div class='helper'></div>";q.fullscreenElement?q.fullscreenElement.appendChild(p):(q.body.appendChild(p),q.body.style.overflow="hidden");if(b.do_type_filter)var t=p.querySelector(".slot_in_type_filter"),n=p.querySelector(".slot_out_type_filter");p.close=function(){f.search_box=null;this.blur();
|
||||
k.focus();q.body.style.overflow="";setTimeout(function(){f.canvas.focus()},20);p.parentNode&&p.parentNode.removeChild(p)};1<this.ds.scale&&(p.style.transform="scale("+this.ds.scale+")");if(b.hide_on_mouse_leave){var l=!1,r=null;g.pointerListenerAdd(p,"enter",function(a){r&&(clearTimeout(r),r=null)});g.pointerListenerAdd(p,"leave",function(a){l||(r=setTimeout(function(){p.close()},500))});b.do_type_filter&&(t.addEventListener("click",function(a){l++}),t.addEventListener("blur",function(a){l=0}),t.addEventListener("change",
|
||||
function(a){l=-1}),n.addEventListener("click",function(a){l++}),n.addEventListener("blur",function(a){l=0}),n.addEventListener("change",function(a){l=-1}))}f.search_box&&f.search_box.close();f.search_box=p;var u=p.querySelector(".helper"),v=null,w=null,x=null,z=p.querySelector("input");z&&(z.addEventListener("blur",function(a){this.focus()}),z.addEventListener("keydown",function(a){if(38==a.keyCode)d(!1);else if(40==a.keyCode)d(!0);else if(27==a.keyCode)p.close();else if(13==a.keyCode)x?c(x.innerHTML):
|
||||
v?c(v):p.close();else{w&&clearInterval(w);w=setTimeout(e,250);return}a.preventDefault();a.stopPropagation();a.stopImmediatePropagation();return!0}));if(b.do_type_filter){if(t){var y=g.slot_types_in,C=y.length;if(b.type_filter_in==g.EVENT||b.type_filter_in==g.ACTION)b.type_filter_in="_event_";for(var A=0;A<C;A++){var B=document.createElement("option");B.value=y[A];B.innerHTML=y[A];t.appendChild(B);!1!==b.type_filter_in&&(b.type_filter_in+"").toLowerCase()==(y[A]+"").toLowerCase()&&(B.selected=!0)}t.addEventListener("change",
|
||||
function(){e()})}if(n){y=g.slot_types_out;C=y.length;if(b.type_filter_out==g.EVENT||b.type_filter_out==g.ACTION)b.type_filter_out="_event_";for(A=0;A<C;A++)B=document.createElement("option"),B.value=y[A],B.innerHTML=y[A],n.appendChild(B),!1!==b.type_filter_out&&(b.type_filter_out+"").toLowerCase()==(y[A]+"").toLowerCase()&&(B.selected=!0);n.addEventListener("change",function(){e()})}}t=k.getBoundingClientRect();n=(a?a.clientY:t.top+.5*t.height)-20;p.style.left=(a?a.clientX:t.left+.5*t.width)-80+"px";
|
||||
p.style.top=n+"px";a.layerY>t.height-200&&(u.style.maxHeight=t.height-a.layerY-20+"px");z.focus();b.show_all_on_open&&e();return p};m.prototype.showEditPropertyValue=function(a,b,c){function d(){e(n.value)}function e(d){f&&f.values&&f.values.constructor===Object&&void 0!=f.values[d]&&(d=f.values[d]);"number"==typeof a.properties[b]&&(d=Number(d));if("array"==h||"object"==h)d=JSON.parse(d);a.properties[b]=d;a.graph&&a.graph._version++;if(a.onPropertyChanged)a.onPropertyChanged(b,d);if(c.onclose)c.onclose();
|
||||
l.close();a.setDirtyCanvas(!0,!0)}if(a&&void 0!==a.properties[b]){c=c||{};var f=a.getPropertyInfo(b),h=f.type,g="";if("string"==h||"number"==h||"array"==h||"object"==h)g="<input autofocus type='text' class='value'/>";else if("enum"!=h&&"combo"!=h||!f.values)if("boolean"==h||"toggle"==h)g="<input autofocus type='checkbox' class='value' "+(a.properties[b]?"checked":"")+"/>";else{console.warn("unknown type: "+h);return}else{g="<select autofocus type='text' class='value'>";for(var q in f.values){var p=
|
||||
q;f.values.constructor===Array&&(p=f.values[q]);g+="<option value='"+p+"' "+(p==a.properties[b]?"selected":"")+">"+f.values[q]+"</option>"}g+="</select>"}var l=this.createDialog("<span class='name'>"+(f.label?f.label:b)+"</span>"+g+"<button>OK</button>",c),n=!1;if("enum"!=h&&"combo"!=h||!f.values)if("boolean"==h||"toggle"==h)(n=l.querySelector("input"))&&n.addEventListener("click",function(a){l.modified();e(!!n.checked)});else{if(n=l.querySelector("input"))n.addEventListener("blur",function(a){this.focus()}),
|
||||
p=void 0!==a.properties[b]?a.properties[b]:"","string"!==h&&(p=JSON.stringify(p)),n.value=p,n.addEventListener("keydown",function(a){if(27==a.keyCode)l.close();else if(13==a.keyCode)d();else if(13!=a.keyCode){l.modified();return}a.preventDefault();a.stopPropagation()})}else n=l.querySelector("select"),n.addEventListener("change",function(a){l.modified();e(a.target.value)});n&&n.focus();l.querySelector("button").addEventListener("click",d);return l}};m.prototype.createDialog=function(a,b){def_options=
|
||||
{checkForInput:!1,closeOnLeave:!0,closeOnLeave_checkModified:!0};b=Object.assign(def_options,b||{});var c=document.createElement("div");c.className="graphdialog";c.innerHTML=a;c.is_modified=!1;a=this.canvas.getBoundingClientRect();var d=-20,e=-20;a&&(d-=a.left,e-=a.top);b.position?(d+=b.position[0],e+=b.position[1]):b.event?(d+=b.event.clientX,e+=b.event.clientY):(d+=.5*this.canvas.width,e+=.5*this.canvas.height);c.style.left=d+"px";c.style.top=e+"px";this.canvas.parentNode.appendChild(c);b.checkForInput&&
|
||||
(a=[],(a=c.querySelectorAll("input"))&&a.forEach(function(a){a.addEventListener("keydown",function(a){c.modified();if(27==a.keyCode)c.close();else if(13!=a.keyCode)return;a.preventDefault();a.stopPropagation()});a.focus()}));c.modified=function(){c.is_modified=!0};c.close=function(){c.parentNode&&c.parentNode.removeChild(c)};var f=null,h=!1;c.addEventListener("mouseleave",function(a){h||(b.closeOnLeave||g.dialog_close_on_mouse_leave)&&!c.is_modified&&g.dialog_close_on_mouse_leave&&(f=setTimeout(c.close,
|
||||
g.dialog_close_on_mouse_leave_delay))});c.addEventListener("mouseenter",function(a){(b.closeOnLeave||g.dialog_close_on_mouse_leave)&&f&&clearTimeout(f)});(a=c.querySelectorAll("select"))&&a.forEach(function(a){a.addEventListener("click",function(a){h++});a.addEventListener("blur",function(a){h=0});a.addEventListener("change",function(a){h=-1})});return c};m.prototype.createPanel=function(a,b){b=b||{};var c=b.window||window,d=document.createElement("div");d.className="litegraph dialog";d.innerHTML=
|
||||
"<div class='dialog-header'><span class='dialog-title'></span></div><div class='dialog-content'></div><div style='display:none;' class='dialog-alt-content'></div><div class='dialog-footer'></div>";d.header=d.querySelector(".dialog-header");b.width&&(d.style.width=b.width+(b.width.constructor===Number?"px":""));b.height&&(d.style.height=b.height+(b.height.constructor===Number?"px":""));b.closable&&(b=document.createElement("span"),b.innerHTML="✕",b.classList.add("close"),b.addEventListener("click",
|
||||
function(){d.close()}),d.header.appendChild(b));d.title_element=d.querySelector(".dialog-title");d.title_element.innerText=a;d.content=d.querySelector(".dialog-content");d.alt_content=d.querySelector(".dialog-alt-content");d.footer=d.querySelector(".dialog-footer");d.close=function(){if(d.onClose&&"function"==typeof d.onClose)d.onClose();d.parentNode.removeChild(d);this.parentNode&&this.parentNode.removeChild(this)};d.toggleAltContent=function(a){if("undefined"!=typeof a){var b=a?"block":"none";a=
|
||||
a?"none":"block"}else b="block"!=d.alt_content.style.display?"block":"none",a="block"!=d.alt_content.style.display?"none":"block";d.alt_content.style.display=b;d.content.style.display=a};d.toggleFooterVisibility=function(a){d.footer.style.display="undefined"!=typeof a?a?"block":"none":"block"!=d.footer.style.display?"block":"none"};d.clear=function(){this.content.innerHTML=""};d.addHTML=function(a,b,c){var e=document.createElement("div");b&&(e.className=b);e.innerHTML=a;c?d.footer.appendChild(e):
|
||||
d.content.appendChild(e);return e};d.addButton=function(a,b,c){var e=document.createElement("button");e.innerText=a;e.options=c;e.classList.add("btn");e.addEventListener("click",b);d.footer.appendChild(e);return e};d.addSeparator=function(){var a=document.createElement("div");a.className="separator";d.content.appendChild(a)};d.addWidget=function(a,b,h,k,n){function e(a,b){k.callback&&k.callback(a,b,k);n&&n(a,b,k)}k=k||{};var f=String(h);a=a.toLowerCase();"number"==a&&(f=h.toFixed(3));var l=document.createElement("div");
|
||||
l.className="property";l.innerHTML="<span class='property_name'></span><span class='property_value'></span>";l.querySelector(".property_name").innerText=k.label||b;var p=l.querySelector(".property_value");p.innerText=f;l.dataset.property=b;l.dataset.type=k.type||a;l.options=k;l.value=h;if("code"==a)l.addEventListener("click",function(a){d.inner_showCodePad(this.dataset.property)});else if("boolean"==a)l.classList.add("boolean"),h&&l.classList.add("bool-on"),l.addEventListener("click",function(){var a=
|
||||
this.dataset.property;this.value=!this.value;this.classList.toggle("bool-on");this.querySelector(".property_value").innerText=this.value?"true":"false";e(a,this.value)});else if("string"==a||"number"==a)p.setAttribute("contenteditable",!0),p.addEventListener("keydown",function(b){"Enter"!=b.code||"string"==a&&b.shiftKey||(b.preventDefault(),this.blur())}),p.addEventListener("blur",function(){var a=this.innerText,b=this.parentNode.dataset.property;"number"==this.parentNode.dataset.type&&(a=Number(a));
|
||||
e(b,a)});else if("enum"==a||"combo"==a)f=m.getPropertyPrintableValue(h,k.values),p.innerText=f,p.addEventListener("click",function(a){var b=this.parentNode.dataset.property,d=this;new g.ContextMenu(k.values||[],{event:a,className:"dark",callback:function(a,c,f){d.innerText=a;e(b,a);return!1}},c)});d.content.appendChild(l);return l};if(d.onOpen&&"function"==typeof d.onOpen)d.onOpen();return d};m.getPropertyPrintableValue=function(a,b){if(!b||b.constructor===Array)return String(a);if(b.constructor===
|
||||
function(){d.close()}),d.header.appendChild(b));d.title_element=d.querySelector(".dialog-title");d.title_element.innerText=a;d.content=d.querySelector(".dialog-content");d.alt_content=d.querySelector(".dialog-alt-content");d.footer=d.querySelector(".dialog-footer");d.close=function(){if(d.onClose&&"function"==typeof d.onClose)d.onClose();d.parentNode&&d.parentNode.removeChild(d);this.parentNode&&this.parentNode.removeChild(this)};d.toggleAltContent=function(a){if("undefined"!=typeof a){var b=a?"block":
|
||||
"none";a=a?"none":"block"}else b="block"!=d.alt_content.style.display?"block":"none",a="block"!=d.alt_content.style.display?"none":"block";d.alt_content.style.display=b;d.content.style.display=a};d.toggleFooterVisibility=function(a){d.footer.style.display="undefined"!=typeof a?a?"block":"none":"block"!=d.footer.style.display?"block":"none"};d.clear=function(){this.content.innerHTML=""};d.addHTML=function(a,b,c){var e=document.createElement("div");b&&(e.className=b);e.innerHTML=a;c?d.footer.appendChild(e):
|
||||
d.content.appendChild(e);return e};d.addButton=function(a,b,c){var e=document.createElement("button");e.innerText=a;e.options=c;e.classList.add("btn");e.addEventListener("click",b);d.footer.appendChild(e);return e};d.addSeparator=function(){var a=document.createElement("div");a.className="separator";d.content.appendChild(a)};d.addWidget=function(a,b,h,k,q){function e(a,b){k.callback&&k.callback(a,b,k);q&&q(a,b,k)}k=k||{};var f=String(h);a=a.toLowerCase();"number"==a&&(f=h.toFixed(3));var l=document.createElement("div");
|
||||
l.className="property";l.innerHTML="<span class='property_name'></span><span class='property_value'></span>";l.querySelector(".property_name").innerText=k.label||b;var r=l.querySelector(".property_value");r.innerText=f;l.dataset.property=b;l.dataset.type=k.type||a;l.options=k;l.value=h;if("code"==a)l.addEventListener("click",function(a){d.inner_showCodePad(this.dataset.property)});else if("boolean"==a)l.classList.add("boolean"),h&&l.classList.add("bool-on"),l.addEventListener("click",function(){var a=
|
||||
this.dataset.property;this.value=!this.value;this.classList.toggle("bool-on");this.querySelector(".property_value").innerText=this.value?"true":"false";e(a,this.value)});else if("string"==a||"number"==a)r.setAttribute("contenteditable",!0),r.addEventListener("keydown",function(b){"Enter"!=b.code||"string"==a&&b.shiftKey||(b.preventDefault(),this.blur())}),r.addEventListener("blur",function(){var a=this.innerText,b=this.parentNode.dataset.property;"number"==this.parentNode.dataset.type&&(a=Number(a));
|
||||
e(b,a)});else if("enum"==a||"combo"==a)f=m.getPropertyPrintableValue(h,k.values),r.innerText=f,r.addEventListener("click",function(a){var b=this.parentNode.dataset.property,d=this;new g.ContextMenu(k.values||[],{event:a,className:"dark",callback:function(a,c,f){d.innerText=a;e(b,a);return!1}},c)});d.content.appendChild(l);return l};if(d.onOpen&&"function"==typeof d.onOpen)d.onOpen();return d};m.getPropertyPrintableValue=function(a,b){if(!b||b.constructor===Array)return String(a);if(b.constructor===
|
||||
Object){var c="",d;for(d in b)if(b[d]==a){c=d;break}return String(a)+" ("+c+")"}};m.prototype.closePanels=function(){var a=document.querySelector("#node-panel");a&&a.close();(a=document.querySelector("#option-panel"))&&a.close()};m.prototype.showShowGraphOptionsPanel=function(a,b,c,d){if(this.constructor&&"HTMLDivElement"==this.constructor.name){if(!(b&&b.event&&b.event.target&&b.event.target.lgraphcanvas)){console.warn("Canvas not found");return}var e=b.event.target.lgraphcanvas}else e=this;e.closePanels();
|
||||
a=e.getCanvasWindow();panel=e.createPanel("Options",{closable:!0,window:a,onOpen:function(){e.OPTIONPANEL_IS_OPEN=!0},onClose:function(){e.OPTIONPANEL_IS_OPEN=!1;e.options_panel=null}});e.options_panel=panel;panel.id="option-panel";panel.classList.add("settings");(function(){panel.content.innerHTML="";var a=function(a,b,c){c&&c.key&&(a=c.key);c.values&&(b=Object.values(c.values).indexOf(b));e[a]=b},b=g.availableCanvasOptions;b.sort();for(pI in b){var c=b[pI];panel.addWidget("boolean",c,e[c],{key:c,
|
||||
on:"True",off:"False"},a)}panel.addWidget("combo","Render mode",g.LINK_RENDER_MODES[e.links_render_mode],{key:"links_render_mode",values:g.LINK_RENDER_MODES},a);panel.addSeparator();panel.footer.innerHTML=""})();e.canvas.parentNode.appendChild(panel)};m.prototype.showShowNodePanel=function(a){function b(){panel.content.innerHTML="";panel.addHTML("<span class='node_type'>"+a.type+"</span><span class='node_desc'>"+(a.constructor.desc||"")+"</span><span class='separator'></span>");panel.addHTML("<h3>Properties</h3>");
|
||||
@@ -339,7 +339,7 @@ b.prototype.__lookupGetter__(c)):a.prototype[c]=b.prototype[c],b.prototype.__loo
|
||||
this.margin);d&&(a.fillStyle="#111",a.fillRect(0,0,g,b),a.fillStyle="#222",a.fillRect(.5*g,0,1,b),a.strokeStyle="#333",a.strokeRect(0,0,g,b));a.strokeStyle=e;f&&(a.globalAlpha=.5);a.beginPath();for(d=0;d<c.length;++d)e=c[d],a.lineTo(e[0]*g,(1-e[1])*b);a.stroke();a.globalAlpha=1;if(!f)for(d=0;d<c.length;++d)e=c[d],a.fillStyle=this.selected==d?"#FFF":this.nearest==d?"#DDD":"#AAA",a.beginPath(),a.arc(e[0]*g,(1-e[1])*b,2,0,2*Math.PI),a.fill();a.restore()}};E.prototype.onMouseDown=function(a,b){var c=
|
||||
this.points;if(c&&!(0>a[1])){var d=this.size[0]-2*this.margin,e=this.size[1]-2*this.margin,f=a[0]-this.margin;a=a[1]-this.margin;this.selected=this.getCloserPoint([f,a],30/b.ds.scale);-1==this.selected&&(b=[f/d,1-a/e],c.push(b),c.sort(function(a,b){return a[0]-b[0]}),this.selected=c.indexOf(b),this.must_update=!0);if(-1!=this.selected)return!0}};E.prototype.onMouseMove=function(a,b){var c=this.points;if(c){var d=this.selected;if(!(0>d)){var e=(a[0]-this.margin)/(this.size[0]-2*this.margin),f=(a[1]-
|
||||
this.margin)/(this.size[1]-2*this.margin);this._nearest=this.getCloserPoint([a[0]-this.margin,a[1]-this.margin],30/b.ds.scale);if(b=c[d]){var g=0==d||d==c.length-1;!g&&(-10>a[0]||a[0]>this.size[0]+10||-10>a[1]||a[1]>this.size[1]+10)?(c.splice(d,1),this.selected=-1):(b[0]=g?0==d?0:1:Math.clamp(e,0,1),b[1]=1-Math.clamp(f,0,1),c.sort(function(a,b){return a[0]-b[0]}),this.selected=c.indexOf(b),this.must_update=!0)}}}};E.prototype.onMouseUp=function(a,b){this.selected=-1;return!1};E.prototype.getCloserPoint=
|
||||
function(a,b){var c=this.points;if(!c)return-1;b=b||30;for(var d=this.size[0]-2*this.margin,e=this.size[1]-2*this.margin,f=c.length,g=[0,0],k=1E6,l=-1,m=0;m<f;++m){var p=c[m];g[0]=p[0]*d;g[1]=(1-p[1])*e;p=vec2.distance(a,g);p>k||p>b||(l=m,k=p)}return l};g.CurveEditor=E;g.getParameterNames=function(a){return(a+"").replace(/[/][/].*$/gm,"").replace(/\s+/g,"").replace(/[/][*][^/*]*[*][/]/g,"").split("){",1)[0].replace(/^[^(]*[(]/,"").replace(/=[^,]+/g,"").split(",").filter(Boolean)};g.pointerListenerAdd=
|
||||
function(a,b){var c=this.points;if(!c)return-1;b=b||30;for(var d=this.size[0]-2*this.margin,e=this.size[1]-2*this.margin,f=c.length,g=[0,0],k=1E6,l=-1,m=0;m<f;++m){var r=c[m];g[0]=r[0]*d;g[1]=(1-r[1])*e;r=vec2.distance(a,g);r>k||r>b||(l=m,k=r)}return l};g.CurveEditor=E;g.getParameterNames=function(a){return(a+"").replace(/[/][/].*$/gm,"").replace(/\s+/g,"").replace(/[/][*][^/*]*[*][/]/g,"").split("){",1)[0].replace(/^[^(]*[(]/,"").replace(/=[^,]+/g,"").split(",").filter(Boolean)};g.pointerListenerAdd=
|
||||
function(a,b,c,d){d=void 0===d?!1:d;if(a&&a.addEventListener&&b&&"function"===typeof c){var e=g.pointerevents_method;if("pointer"==e&&!window.PointerEvent)switch(console.warn("sMethod=='pointer' && !window.PointerEvent"),console.log("Converting pointer["+b+"] : down move up cancel enter TO touchstart touchmove touchend, etc .."),b){case "down":e="touch";b="start";break;case "move":e="touch";break;case "up":e="touch";b="end";break;case "cancel":e="touch";break;case "enter":console.log("debug: Should I send a move event?");
|
||||
break;default:console.warn("PointerEvent not available in this browser ? The event "+b+" would not be called")}switch(b){case "down":case "up":case "move":case "over":case "out":case "enter":a.addEventListener(e+b,c,d);case "leave":case "cancel":case "gotpointercapture":case "lostpointercapture":if("mouse"!=e)return a.addEventListener(e+b,c,d);default:return a.addEventListener(b,c,d)}}};g.pointerListenerRemove=function(a,b,c,d){d=void 0===d?!1:d;if(a&&a.removeEventListener&&b&&"function"===typeof c)switch(b){case "down":case "up":case "move":case "over":case "out":case "enter":"pointer"!=
|
||||
g.pointerevents_method&&"mouse"!=g.pointerevents_method||a.removeEventListener(g.pointerevents_method+b,c,d);case "leave":case "cancel":case "gotpointercapture":case "lostpointercapture":if("pointer"==g.pointerevents_method)return a.removeEventListener(g.pointerevents_method+b,c,d);default:return a.removeEventListener(b,c,d)}};Math.clamp=function(a,b,c){return b>a?b:c<a?c:a};"undefined"==typeof window||window.requestAnimationFrame||(window.requestAnimationFrame=window.webkitRequestAnimationFrame||
|
||||
|
||||
@@ -1288,11 +1288,11 @@
|
||||
var node = column[j];
|
||||
node.pos[0] = (layout == LiteGraph.VERTICAL_LAYOUT) ? y : x;
|
||||
node.pos[1] = (layout == LiteGraph.VERTICAL_LAYOUT) ? x : y;
|
||||
max_size_index = (layout == LiteGraph.VERTICAL_LAYOUT) ? 1 : 0;
|
||||
var max_size_index = (layout == LiteGraph.VERTICAL_LAYOUT) ? 1 : 0;
|
||||
if (node.size[max_size_index] > max_size) {
|
||||
max_size = node.size[max_size_index];
|
||||
}
|
||||
node_size_index = (layout == LiteGraph.VERTICAL_LAYOUT) ? 0 : 1;
|
||||
var node_size_index = (layout == LiteGraph.VERTICAL_LAYOUT) ? 0 : 1;
|
||||
y += node.size[node_size_index] + margin + LiteGraph.NODE_TITLE_HEIGHT;
|
||||
}
|
||||
x += max_size + margin;
|
||||
@@ -3194,6 +3194,15 @@
|
||||
return;
|
||||
}
|
||||
|
||||
if(slot == null)
|
||||
{
|
||||
console.error("slot must be a number");
|
||||
return;
|
||||
}
|
||||
|
||||
if(slot.constructor !== Number)
|
||||
console.warn("slot must be a number, use node.trigger('name') if you want to use a string");
|
||||
|
||||
var output = this.outputs[slot];
|
||||
if (!output) {
|
||||
return;
|
||||
@@ -7483,8 +7492,8 @@ LGraphNode.prototype.executeAction = function(action)
|
||||
clientY_rel = e.clientY;
|
||||
}
|
||||
|
||||
e.deltaX = clientX_rel - this.last_mouse_position[0];
|
||||
e.deltaY = clientY_rel- this.last_mouse_position[1];
|
||||
// e.deltaX = clientX_rel - this.last_mouse_position[0];
|
||||
// e.deltaY = clientY_rel- this.last_mouse_position[1];
|
||||
|
||||
this.last_mouse_position[0] = clientX_rel;
|
||||
this.last_mouse_position[1] = clientY_rel;
|
||||
@@ -9921,7 +9930,8 @@ LGraphNode.prototype.executeAction = function(action)
|
||||
case "combo":
|
||||
var old_value = w.value;
|
||||
if (event.type == LiteGraph.pointerevents_method+"move" && w.type == "number") {
|
||||
w.value += event.deltaX * 0.1 * (w.options.step || 1);
|
||||
if(event.deltaX)
|
||||
w.value += event.deltaX * 0.1 * (w.options.step || 1);
|
||||
if ( w.options.min != null && w.value < w.options.min ) {
|
||||
w.value = w.options.min;
|
||||
}
|
||||
@@ -11987,7 +11997,8 @@ LGraphNode.prototype.executeAction = function(action)
|
||||
if (root.onClose && typeof root.onClose == "function"){
|
||||
root.onClose();
|
||||
}
|
||||
root.parentNode.removeChild(root);
|
||||
if(root.parentNode)
|
||||
root.parentNode.removeChild(root);
|
||||
/* XXX CHECK THIS */
|
||||
if(this.parentNode){
|
||||
this.parentNode.removeChild(this);
|
||||
@@ -15606,7 +15617,7 @@ if (typeof exports != "undefined") {
|
||||
};
|
||||
|
||||
NodeScript.title = "Script";
|
||||
NodeScript.desc = "executes a code (max 100 characters)";
|
||||
NodeScript.desc = "executes a code (max 256 characters)";
|
||||
|
||||
NodeScript.widgets_info = {
|
||||
onExecute: { type: "code" }
|
||||
@@ -16208,7 +16219,32 @@ if (typeof exports != "undefined") {
|
||||
|
||||
LiteGraph.registerNodeType("events/semaphore", SemaphoreEvent);
|
||||
|
||||
function OnceEvent() {
|
||||
this.addInput("in", LiteGraph.ACTION );
|
||||
this.addInput("reset", LiteGraph.ACTION );
|
||||
this.addOutput("out", LiteGraph.EVENT );
|
||||
this._once = false;
|
||||
this.properties = {};
|
||||
var that = this;
|
||||
this.addWidget("button","reset","",function(){
|
||||
that._once = false;
|
||||
});
|
||||
}
|
||||
|
||||
OnceEvent.title = "Once";
|
||||
OnceEvent.desc = "Only passes an event once, then gets locked";
|
||||
|
||||
OnceEvent.prototype.onAction = function(action, param) {
|
||||
if( action == "in" && !this._once )
|
||||
{
|
||||
this._once = true;
|
||||
this.triggerSlot( 0, param );
|
||||
}
|
||||
else if( action == "reset" )
|
||||
this._once = false;
|
||||
};
|
||||
|
||||
LiteGraph.registerNodeType("events/once", OnceEvent);
|
||||
|
||||
function DataStore() {
|
||||
this.addInput("data", 0);
|
||||
|
||||
899
build/litegraph.min.js
vendored
899
build/litegraph.min.js
vendored
File diff suppressed because it is too large
Load Diff
@@ -1288,11 +1288,11 @@
|
||||
var node = column[j];
|
||||
node.pos[0] = (layout == LiteGraph.VERTICAL_LAYOUT) ? y : x;
|
||||
node.pos[1] = (layout == LiteGraph.VERTICAL_LAYOUT) ? x : y;
|
||||
max_size_index = (layout == LiteGraph.VERTICAL_LAYOUT) ? 1 : 0;
|
||||
var max_size_index = (layout == LiteGraph.VERTICAL_LAYOUT) ? 1 : 0;
|
||||
if (node.size[max_size_index] > max_size) {
|
||||
max_size = node.size[max_size_index];
|
||||
}
|
||||
node_size_index = (layout == LiteGraph.VERTICAL_LAYOUT) ? 0 : 1;
|
||||
var node_size_index = (layout == LiteGraph.VERTICAL_LAYOUT) ? 0 : 1;
|
||||
y += node.size[node_size_index] + margin + LiteGraph.NODE_TITLE_HEIGHT;
|
||||
}
|
||||
x += max_size + margin;
|
||||
@@ -3194,6 +3194,15 @@
|
||||
return;
|
||||
}
|
||||
|
||||
if(slot == null)
|
||||
{
|
||||
console.error("slot must be a number");
|
||||
return;
|
||||
}
|
||||
|
||||
if(slot.constructor !== Number)
|
||||
console.warn("slot must be a number, use node.trigger('name') if you want to use a string");
|
||||
|
||||
var output = this.outputs[slot];
|
||||
if (!output) {
|
||||
return;
|
||||
@@ -7483,8 +7492,8 @@ LGraphNode.prototype.executeAction = function(action)
|
||||
clientY_rel = e.clientY;
|
||||
}
|
||||
|
||||
e.deltaX = clientX_rel - this.last_mouse_position[0];
|
||||
e.deltaY = clientY_rel- this.last_mouse_position[1];
|
||||
// e.deltaX = clientX_rel - this.last_mouse_position[0];
|
||||
// e.deltaY = clientY_rel- this.last_mouse_position[1];
|
||||
|
||||
this.last_mouse_position[0] = clientX_rel;
|
||||
this.last_mouse_position[1] = clientY_rel;
|
||||
@@ -9921,7 +9930,8 @@ LGraphNode.prototype.executeAction = function(action)
|
||||
case "combo":
|
||||
var old_value = w.value;
|
||||
if (event.type == LiteGraph.pointerevents_method+"move" && w.type == "number") {
|
||||
w.value += event.deltaX * 0.1 * (w.options.step || 1);
|
||||
if(event.deltaX)
|
||||
w.value += event.deltaX * 0.1 * (w.options.step || 1);
|
||||
if ( w.options.min != null && w.value < w.options.min ) {
|
||||
w.value = w.options.min;
|
||||
}
|
||||
@@ -11987,7 +11997,8 @@ LGraphNode.prototype.executeAction = function(action)
|
||||
if (root.onClose && typeof root.onClose == "function"){
|
||||
root.onClose();
|
||||
}
|
||||
root.parentNode.removeChild(root);
|
||||
if(root.parentNode)
|
||||
root.parentNode.removeChild(root);
|
||||
/* XXX CHECK THIS */
|
||||
if(this.parentNode){
|
||||
this.parentNode.removeChild(this);
|
||||
@@ -15606,7 +15617,7 @@ if (typeof exports != "undefined") {
|
||||
};
|
||||
|
||||
NodeScript.title = "Script";
|
||||
NodeScript.desc = "executes a code (max 100 characters)";
|
||||
NodeScript.desc = "executes a code (max 256 characters)";
|
||||
|
||||
NodeScript.widgets_info = {
|
||||
onExecute: { type: "code" }
|
||||
@@ -16208,7 +16219,32 @@ if (typeof exports != "undefined") {
|
||||
|
||||
LiteGraph.registerNodeType("events/semaphore", SemaphoreEvent);
|
||||
|
||||
function OnceEvent() {
|
||||
this.addInput("in", LiteGraph.ACTION );
|
||||
this.addInput("reset", LiteGraph.ACTION );
|
||||
this.addOutput("out", LiteGraph.EVENT );
|
||||
this._once = false;
|
||||
this.properties = {};
|
||||
var that = this;
|
||||
this.addWidget("button","reset","",function(){
|
||||
that._once = false;
|
||||
});
|
||||
}
|
||||
|
||||
OnceEvent.title = "Once";
|
||||
OnceEvent.desc = "Only passes an event once, then gets locked";
|
||||
|
||||
OnceEvent.prototype.onAction = function(action, param) {
|
||||
if( action == "in" && !this._once )
|
||||
{
|
||||
this._once = true;
|
||||
this.triggerSlot( 0, param );
|
||||
}
|
||||
else if( action == "reset" )
|
||||
this._once = false;
|
||||
};
|
||||
|
||||
LiteGraph.registerNodeType("events/once", OnceEvent);
|
||||
|
||||
function DataStore() {
|
||||
this.addInput("data", 0);
|
||||
|
||||
727
build/litegraph_mini.min.js
vendored
727
build/litegraph_mini.min.js
vendored
@@ -2,61 +2,61 @@ var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.ASSUME_ES5=!1;$jscomp.ASSUME_NO
|
||||
$jscomp.polyfill=function(x,m,t,l){if(m){t=$jscomp.global;x=x.split(".");for(l=0;l<x.length-1;l++){var w=x[l];w in t||(t[w]={});t=t[w]}x=x[x.length-1];l=t[x];m=m(l);m!=l&&null!=m&&$jscomp.defineProperty(t,x,{configurable:!0,writable:!0,value:m})}};$jscomp.polyfill("Object.is",function(x){return x?x:function(m,t){return m===t?0!==m||1/m===1/t:m!==m&&t!==t}},"es6","es3");
|
||||
$jscomp.polyfill("Array.prototype.includes",function(x){return x?x:function(m,t){var l=this;l instanceof String&&(l=String(l));var w=l.length;for(t=t||0;t<w;t++)if(l[t]==m||Object.is(l[t],m))return!0;return!1}},"es7","es3");
|
||||
$jscomp.checkStringArgs=function(x,m,t){if(null==x)throw new TypeError("The 'this' value for String.prototype."+t+" must not be null or undefined");if(m instanceof RegExp)throw new TypeError("First argument to String.prototype."+t+" must not be a regular expression");return x+""};$jscomp.polyfill("String.prototype.includes",function(x){return x?x:function(m,t){return-1!==$jscomp.checkStringArgs(this,m,"includes").indexOf(m,t||0)}},"es6","es3");
|
||||
$jscomp.owns=function(x,m){return Object.prototype.hasOwnProperty.call(x,m)};$jscomp.polyfill("Object.assign",function(x){return x?x:function(m,t){for(var l=1;l<arguments.length;l++){var w=arguments[l];if(w)for(var z in w)$jscomp.owns(w,z)&&(m[z]=w[z])}return m}},"es6","es3");$jscomp.SYMBOL_PREFIX="jscomp_symbol_";$jscomp.initSymbol=function(){$jscomp.initSymbol=function(){};$jscomp.global.Symbol||($jscomp.global.Symbol=$jscomp.Symbol)};
|
||||
$jscomp.owns=function(x,m){return Object.prototype.hasOwnProperty.call(x,m)};$jscomp.polyfill("Object.assign",function(x){return x?x:function(m,t){for(var l=1;l<arguments.length;l++){var w=arguments[l];if(w)for(var A in w)$jscomp.owns(w,A)&&(m[A]=w[A])}return m}},"es6","es3");$jscomp.SYMBOL_PREFIX="jscomp_symbol_";$jscomp.initSymbol=function(){$jscomp.initSymbol=function(){};$jscomp.global.Symbol||($jscomp.global.Symbol=$jscomp.Symbol)};
|
||||
$jscomp.Symbol=function(){var x=0;return function(m){return $jscomp.SYMBOL_PREFIX+(m||"")+x++}}();$jscomp.initSymbolIterator=function(){$jscomp.initSymbol();var x=$jscomp.global.Symbol.iterator;x||(x=$jscomp.global.Symbol.iterator=$jscomp.global.Symbol("iterator"));"function"!=typeof Array.prototype[x]&&$jscomp.defineProperty(Array.prototype,x,{configurable:!0,writable:!0,value:function(){return $jscomp.arrayIterator(this)}});$jscomp.initSymbolIterator=function(){}};
|
||||
$jscomp.arrayIterator=function(x){var m=0;return $jscomp.iteratorPrototype(function(){return m<x.length?{done:!1,value:x[m++]}:{done:!0}})};$jscomp.iteratorPrototype=function(x){$jscomp.initSymbolIterator();x={next:x};x[$jscomp.global.Symbol.iterator]=function(){return this};return x};
|
||||
$jscomp.iteratorFromArray=function(x,m){$jscomp.initSymbolIterator();x instanceof String&&(x+="");var t=0,l={next:function(){if(t<x.length){var w=t++;return{value:m(w,x[w]),done:!1}}l.next=function(){return{done:!0,value:void 0}};return l.next()}};l[Symbol.iterator]=function(){return l};return l};$jscomp.polyfill("Array.prototype.keys",function(x){return x?x:function(){return $jscomp.iteratorFromArray(this,function(m){return m})}},"es6","es3");
|
||||
$jscomp.polyfill("Array.prototype.fill",function(x){return x?x:function(m,t,l){var w=this.length||0;0>t&&(t=Math.max(0,w+t));if(null==l||l>w)l=w;l=Number(l);0>l&&(l=Math.max(0,w+l));for(t=Number(t||0);t<l;t++)this[t]=m;return this}},"es6","es3");$jscomp.polyfill("Array.prototype.values",function(x){return x?x:function(){return $jscomp.iteratorFromArray(this,function(m,t){return t})}},"es8","es3");
|
||||
$jscomp.polyfill("Object.values",function(x){return x?x:function(m){var t=[],l;for(l in m)$jscomp.owns(m,l)&&t.push(m[l]);return t}},"es8","es3");$jscomp.polyfill("String.prototype.startsWith",function(x){return x?x:function(m,t){var l=$jscomp.checkStringArgs(this,m,"startsWith");m+="";var w=l.length,z=m.length;t=Math.max(0,Math.min(t|0,l.length));for(var h=0;h<z&&t<w;)if(l[t++]!=m[h++])return!1;return h>=z}},"es6","es3");
|
||||
$jscomp.findInternal=function(x,m,t){x instanceof String&&(x=String(x));for(var l=x.length,w=0;w<l;w++){var z=x[w];if(m.call(t,z,w,x))return{i:w,v:z}}return{i:-1,v:void 0}};$jscomp.polyfill("Array.prototype.findIndex",function(x){return x?x:function(m,t){return $jscomp.findInternal(this,m,t).i}},"es6","es3");
|
||||
(function(x){function m(a){f.debug&&console.log("Graph created");this.list_of_graphcanvas=null;this.clear();a&&this.configure(a)}function t(a,b,c,d,e,g){this.id=a;this.type=b;this.origin_id=c;this.origin_slot=d;this.target_id=e;this.target_slot=g;this._data=null;this._pos=new Float32Array(2)}function l(a){this._ctor(a)}function w(a){this._ctor(a)}function z(a,b){this.offset=new Float32Array([0,0]);this.scale=1;this.max_scale=10;this.min_scale=.1;this.onredraw=null;this.enabled=!0;this.last_mouse=
|
||||
[0,0];this.element=null;this.visible_area=new Float32Array(4);a&&(this.element=a,b||this.bindEvents(a))}function h(a,b,c){this.options=c=c||{};this.background_image=h.DEFAULT_BACKGROUND_IMAGE;a&&a.constructor===String&&(a=document.querySelector(a));this.ds=new z;this.zoom_modify_alpha=!0;this.title_text_font=""+f.NODE_TEXT_SIZE+"px Arial";this.inner_text_font="normal "+f.NODE_SUBTEXT_SIZE+"px Arial";this.node_title_color=f.NODE_TITLE_COLOR;this.default_link_color=f.LINK_COLOR;this.default_connection_color=
|
||||
$jscomp.polyfill("Object.values",function(x){return x?x:function(m){var t=[],l;for(l in m)$jscomp.owns(m,l)&&t.push(m[l]);return t}},"es8","es3");$jscomp.polyfill("String.prototype.startsWith",function(x){return x?x:function(m,t){var l=$jscomp.checkStringArgs(this,m,"startsWith");m+="";var w=l.length,A=m.length;t=Math.max(0,Math.min(t|0,l.length));for(var k=0;k<A&&t<w;)if(l[t++]!=m[k++])return!1;return k>=A}},"es6","es3");
|
||||
$jscomp.findInternal=function(x,m,t){x instanceof String&&(x=String(x));for(var l=x.length,w=0;w<l;w++){var A=x[w];if(m.call(t,A,w,x))return{i:w,v:A}}return{i:-1,v:void 0}};$jscomp.polyfill("Array.prototype.findIndex",function(x){return x?x:function(m,t){return $jscomp.findInternal(this,m,t).i}},"es6","es3");
|
||||
(function(x){function m(a){f.debug&&console.log("Graph created");this.list_of_graphcanvas=null;this.clear();a&&this.configure(a)}function t(a,b,c,d,e,g){this.id=a;this.type=b;this.origin_id=c;this.origin_slot=d;this.target_id=e;this.target_slot=g;this._data=null;this._pos=new Float32Array(2)}function l(a){this._ctor(a)}function w(a){this._ctor(a)}function A(a,b){this.offset=new Float32Array([0,0]);this.scale=1;this.max_scale=10;this.min_scale=.1;this.onredraw=null;this.enabled=!0;this.last_mouse=
|
||||
[0,0];this.element=null;this.visible_area=new Float32Array(4);a&&(this.element=a,b||this.bindEvents(a))}function k(a,b,c){this.options=c=c||{};this.background_image=k.DEFAULT_BACKGROUND_IMAGE;a&&a.constructor===String&&(a=document.querySelector(a));this.ds=new A;this.zoom_modify_alpha=!0;this.title_text_font=""+f.NODE_TEXT_SIZE+"px Arial";this.inner_text_font="normal "+f.NODE_SUBTEXT_SIZE+"px Arial";this.node_title_color=f.NODE_TITLE_COLOR;this.default_link_color=f.LINK_COLOR;this.default_connection_color=
|
||||
{input_off:"#778",input_on:"#7F7",output_off:"#778",output_on:"#7F7"};this.default_connection_color_byType={};this.default_connection_color_byTypeOff={};this.highquality_render=!0;this.use_gradients=!1;this.editor_alpha=1;this.pause_rendering=!1;this.clear_background=!0;this.read_only=!1;this.render_only_selected=!0;this.live_mode=!1;this.allow_reconnect_links=this.allow_searchbox=this.allow_interaction=this.allow_dragnodes=this.allow_dragcanvas=this.show_info=!0;this.drag_mode=this.align_to_grid=
|
||||
!1;this.filter=this.dragging_rectangle=null;this.set_canvas_dirty_on_mouse_event=!0;this.always_render_background=!1;this.render_canvas_border=this.render_shadows=!0;this.render_connections_shadows=!1;this.render_connections_border=!0;this.render_connection_arrows=this.render_curved_connections=!1;this.render_collapsed_slots=!0;this.render_execution_order=!1;this.render_link_tooltip=this.render_title_colored=!0;this.links_render_mode=f.SPLINE_LINK;this.mouse=[0,0];this.canvas_mouse=this.graph_mouse=
|
||||
[0,0];this.onAfterChange=this.onBeforeChange=this.onConnectingChange=this.onSelectionChange=this.onNodeMoved=this.onDrawLinkTooltip=this.onDrawOverlay=this.onDrawForeground=this.onDrawBackground=this.onMouse=this.onSearchBoxSelection=this.onSearchBox=null;this.connections_width=3;this.round_radius=8;this.over_link_center=this.node_widget=this.current_node=null;this.last_mouse_position=[0,0];this.visible_area=this.ds.visible_area;this.visible_links=[];this.viewport=c.viewport||null;b&&b.attachCanvas(this);
|
||||
this.setCanvas(a,c.skip_events);this.clear();c.skip_render||this.startRendering();this.autoresize=c.autoresize}function D(a,b){return Math.sqrt((b[0]-a[0])*(b[0]-a[0])+(b[1]-a[1])*(b[1]-a[1]))}function C(a,b,c,d,e,g){return c<a&&c+e>a&&d<b&&d+g>b?!0:!1}function A(a,b){var c=a[0]+a[2],d=a[1]+a[3],e=b[1]+b[3];return a[0]>b[0]+b[2]||a[1]>e||c<b[0]||d<b[1]?!1:!0}function E(a,b){function c(a){var c=parseInt(g.style.top);g.style.top=(c+a.deltaY*b.scroll_speed).toFixed()+"px";a.preventDefault();return!0}
|
||||
this.setCanvas(a,c.skip_events);this.clear();c.skip_render||this.startRendering();this.autoresize=c.autoresize}function E(a,b){return Math.sqrt((b[0]-a[0])*(b[0]-a[0])+(b[1]-a[1])*(b[1]-a[1]))}function D(a,b,c,d,e,g){return c<a&&c+e>a&&d<b&&d+g>b?!0:!1}function B(a,b){var c=a[0]+a[2],d=a[1]+a[3],e=b[1]+b[3];return a[0]>b[0]+b[2]||a[1]>e||c<b[0]||d<b[1]?!1:!0}function F(a,b){function c(a){var c=parseInt(g.style.top);g.style.top=(c+a.deltaY*b.scroll_speed).toFixed()+"px";a.preventDefault();return!0}
|
||||
this.options=b=b||{};var d=this;b.parentMenu&&(b.parentMenu.constructor!==this.constructor?(console.error("parentMenu must be of class ContextMenu, ignoring it"),b.parentMenu=null):(this.parentMenu=b.parentMenu,this.parentMenu.lock=!0,this.parentMenu.current_submenu=this));var e=null;b.event&&(e=b.event.constructor.name);"MouseEvent"!==e&&"CustomEvent"!==e&&"PointerEvent"!==e&&(console.error("Event passed to ContextMenu is not of type MouseEvent or CustomEvent. Ignoring it. ("+e+")"),b.event=null);
|
||||
var g=document.createElement("div");g.className="litegraph litecontextmenu litemenubar-panel";b.className&&(g.className+=" "+b.className);g.style.minWidth=100;g.style.minHeight=100;g.style.pointerEvents="none";setTimeout(function(){g.style.pointerEvents="auto"},100);f.pointerListenerAdd(g,"up",function(a){a.preventDefault();return!0},!0);g.addEventListener("contextmenu",function(a){if(2!=a.button)return!1;a.preventDefault();return!1},!0);f.pointerListenerAdd(g,"down",function(a){if(2==a.button)return d.close(),
|
||||
a.preventDefault(),!0},!0);b.scroll_speed||(b.scroll_speed=.1);g.addEventListener("wheel",c,!0);g.addEventListener("mousewheel",c,!0);this.root=g;b.title&&(e=document.createElement("div"),e.className="litemenu-title",e.innerHTML=b.title,g.appendChild(e));for(var k=e=0;k<a.length;k++){var n=a.constructor==Array?a[k]:k;null!=n&&n.constructor!==String&&(n=void 0===n.content?String(n):n.content);this.addItem(n,a[k],b);e++}f.pointerListenerAdd(g,"enter",function(a){g.closing_timer&&clearTimeout(g.closing_timer)});
|
||||
a=document;b.event&&(a=b.event.target.ownerDocument);a||(a=document);a.fullscreenElement?a.fullscreenElement.appendChild(g):a.body.appendChild(g);e=b.left||0;a=b.top||0;b.event&&(e=b.event.clientX-10,a=b.event.clientY-10,b.title&&(a-=20),b.parentMenu&&(e=b.parentMenu.root.getBoundingClientRect(),e=e.left+e.width),k=document.body.getBoundingClientRect(),n=g.getBoundingClientRect(),0==k.height&&console.error("document.body height is 0. That is dangerous, set html,body { height: 100%; }"),k.width&&e>
|
||||
k.width-n.width-10&&(e=k.width-n.width-10),k.height&&a>k.height-n.height-10&&(a=k.height-n.height-10));g.style.left=e+"px";g.style.top=a+"px";b.scale&&(g.style.transform="scale("+b.scale+")")}function G(a){this.points=a;this.nearest=this.selected=-1;this.size=null;this.must_update=!0;this.margin=5}var f=x.LiteGraph={VERSION:.4,CANVAS_GRID_SIZE:10,NODE_TITLE_HEIGHT:30,NODE_TITLE_TEXT_Y:20,NODE_SLOT_HEIGHT:20,NODE_WIDGET_HEIGHT:20,NODE_WIDTH:140,NODE_MIN_WIDTH:50,NODE_COLLAPSED_RADIUS:10,NODE_COLLAPSED_WIDTH:80,
|
||||
a.preventDefault(),!0},!0);b.scroll_speed||(b.scroll_speed=.1);g.addEventListener("wheel",c,!0);g.addEventListener("mousewheel",c,!0);this.root=g;b.title&&(e=document.createElement("div"),e.className="litemenu-title",e.innerHTML=b.title,g.appendChild(e));for(var h=e=0;h<a.length;h++){var n=a.constructor==Array?a[h]:h;null!=n&&n.constructor!==String&&(n=void 0===n.content?String(n):n.content);this.addItem(n,a[h],b);e++}f.pointerListenerAdd(g,"enter",function(a){g.closing_timer&&clearTimeout(g.closing_timer)});
|
||||
a=document;b.event&&(a=b.event.target.ownerDocument);a||(a=document);a.fullscreenElement?a.fullscreenElement.appendChild(g):a.body.appendChild(g);e=b.left||0;a=b.top||0;b.event&&(e=b.event.clientX-10,a=b.event.clientY-10,b.title&&(a-=20),b.parentMenu&&(e=b.parentMenu.root.getBoundingClientRect(),e=e.left+e.width),h=document.body.getBoundingClientRect(),n=g.getBoundingClientRect(),0==h.height&&console.error("document.body height is 0. That is dangerous, set html,body { height: 100%; }"),h.width&&e>
|
||||
h.width-n.width-10&&(e=h.width-n.width-10),h.height&&a>h.height-n.height-10&&(a=h.height-n.height-10));g.style.left=e+"px";g.style.top=a+"px";b.scale&&(g.style.transform="scale("+b.scale+")")}function I(a){this.points=a;this.nearest=this.selected=-1;this.size=null;this.must_update=!0;this.margin=5}var f=x.LiteGraph={VERSION:.4,CANVAS_GRID_SIZE:10,NODE_TITLE_HEIGHT:30,NODE_TITLE_TEXT_Y:20,NODE_SLOT_HEIGHT:20,NODE_WIDGET_HEIGHT:20,NODE_WIDTH:140,NODE_MIN_WIDTH:50,NODE_COLLAPSED_RADIUS:10,NODE_COLLAPSED_WIDTH:80,
|
||||
NODE_TITLE_COLOR:"#999",NODE_SELECTED_TITLE_COLOR:"#FFF",NODE_TEXT_SIZE:14,NODE_TEXT_COLOR:"#AAA",NODE_SUBTEXT_SIZE:12,NODE_DEFAULT_COLOR:"#333",NODE_DEFAULT_BGCOLOR:"#353535",NODE_DEFAULT_BOXCOLOR:"#666",NODE_DEFAULT_SHAPE:"box",NODE_BOX_OUTLINE_COLOR:"#FFF",DEFAULT_SHADOW_COLOR:"rgba(0,0,0,0.5)",DEFAULT_GROUP_FONT:24,WIDGET_BGCOLOR:"#222",WIDGET_OUTLINE_COLOR:"#666",WIDGET_TEXT_COLOR:"#DDD",WIDGET_SECONDARY_TEXT_COLOR:"#999",LINK_COLOR:"#9A9",EVENT_LINK_COLOR:"#A86",CONNECTING_LINK_COLOR:"#AFA",
|
||||
MAX_NUMBER_OF_NODES:1E3,DEFAULT_POSITION:[100,100],VALID_SHAPES:["default","box","round","card"],BOX_SHAPE:1,ROUND_SHAPE:2,CIRCLE_SHAPE:3,CARD_SHAPE:4,ARROW_SHAPE:5,GRID_SHAPE:6,INPUT:1,OUTPUT:2,EVENT:-1,ACTION:-1,NODE_MODES:["Always","On Event","Never","On Trigger"],NODE_MODES_COLORS:["#666","#422","#333","#224","#626"],ALWAYS:0,ON_EVENT:1,NEVER:2,ON_TRIGGER:3,UP:1,DOWN:2,LEFT:3,RIGHT:4,CENTER:5,LINK_RENDER_MODES:["Straight","Linear","Spline"],STRAIGHT_LINK:0,LINEAR_LINK:1,SPLINE_LINK:2,NORMAL_TITLE:0,
|
||||
NO_TITLE:1,TRANSPARENT_TITLE:2,AUTOHIDE_TITLE:3,proxy:null,node_images_path:"",debug:!1,catch_exceptions:!0,throw_errors:!0,allow_scripts:!1,registered_node_types:{},node_types_by_file_extension:{},Nodes:{},Globals:{},searchbox_extras:{},auto_sort_node_types:!1,node_box_coloured_when_on:!1,node_box_coloured_by_mode:!1,dialog_close_on_mouse_leave:!0,dialog_close_on_mouse_leave_delay:500,shift_click_do_break_link_from:!1,click_do_break_link_to:!1,search_hide_on_mouse_leave:!0,search_filter_enabled:!1,
|
||||
search_show_all_on_open:!0,auto_load_slot_types:!1,registered_slot_in_types:{},registered_slot_out_types:{},slot_types_in:[],slot_types_out:[],slot_types_default_in:[],slot_types_default_out:[],alt_drag_do_clone_nodes:!1,do_add_triggers_slots:!1,allow_multi_output_for_events:!0,middle_click_slot_add_default_node:!1,release_link_on_empty_shows_menu:!1,pointerevents_method:"mouse",registerNodeType:function(a,b){if(!b.prototype)throw"Cannot register a simple object, it must be a class with a prototype";
|
||||
NO_TITLE:1,TRANSPARENT_TITLE:2,AUTOHIDE_TITLE:3,VERTICAL_LAYOUT:"vertical",proxy:null,node_images_path:"",debug:!1,catch_exceptions:!0,throw_errors:!0,allow_scripts:!1,registered_node_types:{},node_types_by_file_extension:{},Nodes:{},Globals:{},searchbox_extras:{},auto_sort_node_types:!1,node_box_coloured_when_on:!1,node_box_coloured_by_mode:!1,dialog_close_on_mouse_leave:!0,dialog_close_on_mouse_leave_delay:500,shift_click_do_break_link_from:!1,click_do_break_link_to:!1,search_hide_on_mouse_leave:!0,
|
||||
search_filter_enabled:!1,search_show_all_on_open:!0,auto_load_slot_types:!1,registered_slot_in_types:{},registered_slot_out_types:{},slot_types_in:[],slot_types_out:[],slot_types_default_in:[],slot_types_default_out:[],alt_drag_do_clone_nodes:!1,do_add_triggers_slots:!1,allow_multi_output_for_events:!0,middle_click_slot_add_default_node:!1,release_link_on_empty_shows_menu:!1,pointerevents_method:"mouse",registerNodeType:function(a,b){if(!b.prototype)throw"Cannot register a simple object, it must be a class with a prototype";
|
||||
b.type=a;f.debug&&console.log("Node registered: "+a);a.split("/");var c=b.name,d=a.lastIndexOf("/");b.category=a.substr(0,d);b.title||(b.title=c);if(b.prototype)for(var e in l.prototype)b.prototype[e]||(b.prototype[e]=l.prototype[e]);if(d=this.registered_node_types[a])console.log("replacing node type: "+a);else if(Object.hasOwnProperty(b.prototype,"shape")||Object.defineProperty(b.prototype,"shape",{set:function(a){switch(a){case "default":delete this._shape;break;case "box":this._shape=f.BOX_SHAPE;
|
||||
break;case "round":this._shape=f.ROUND_SHAPE;break;case "circle":this._shape=f.CIRCLE_SHAPE;break;case "card":this._shape=f.CARD_SHAPE;break;default:this._shape=a}},get:function(a){return this._shape},enumerable:!0,configurable:!0}),b.prototype.onPropertyChange&&console.warn("LiteGraph node class "+a+" has onPropertyChange method, it must be called onPropertyChanged with d at the end"),b.supported_extensions)for(e in b.supported_extensions){var g=b.supported_extensions[e];g&&g.constructor===String&&
|
||||
(this.node_types_by_file_extension[g.toLowerCase()]=b)}this.registered_node_types[a]=b;b.constructor.name&&(this.Nodes[c]=b);if(f.onNodeTypeRegistered)f.onNodeTypeRegistered(a,b);if(d&&f.onNodeTypeReplaced)f.onNodeTypeReplaced(a,b,d);b.prototype.onPropertyChange&&console.warn("LiteGraph node class "+a+" has onPropertyChange method, it must be called onPropertyChanged with d at the end");if(b.supported_extensions)for(e=0;e<b.supported_extensions.length;e++)(g=b.supported_extensions[e])&&g.constructor===
|
||||
String&&(this.node_types_by_file_extension[g.toLowerCase()]=b);this.auto_load_slot_types&&(nodeTmp=new b(b.title||"tmpnode"))},unregisterNodeType:function(a){var b=a.constructor===String?this.registered_node_types[a]:a;if(!b)throw"node type not found: "+a;delete this.registered_node_types[b.type];b.constructor.name&&delete this.Nodes[b.constructor.name]},registerNodeAndSlotType:function(a,b,c){c=c||!1;a=(a.constructor===String&&"anonymous"!==this.registered_node_types[a]?this.registered_node_types[a]:
|
||||
a).constructor.type;b="string"==typeof b?b.split(","):b==this.EVENT||b==this.ACTION?["_event_"]:["*"];for(var d=0;d<b.length;++d){var e=b[d];""===e&&(e="*");var g=c?"registered_slot_out_types":"registered_slot_in_types";"undefined"==typeof this[g][e]&&(this[g][e]={nodes:[]});this[g][e].nodes.push(a);c?this.slot_types_out.includes(e.toLowerCase())||(this.slot_types_out.push(e.toLowerCase()),this.slot_types_out.sort()):this.slot_types_in.includes(e.toLowerCase())||(this.slot_types_in.push(e.toLowerCase()),
|
||||
this.slot_types_in.sort())}},wrapFunctionAsNode:function(a,b,c,d,e){for(var g=Array(b.length),k="",n=f.getParameterNames(b),p=0;p<n.length;++p)k+="this.addInput('"+n[p]+"',"+(c&&c[p]?"'"+c[p]+"'":"0")+");\n";k+="this.addOutput('out',"+(d?"'"+d+"'":0)+");\n";e&&(k+="this.properties = "+JSON.stringify(e)+";\n");c=Function(k);c.title=a.split("/").pop();c.desc="Generated from "+b.name;c.prototype.onExecute=function(){for(var a=0;a<g.length;++a)g[a]=this.getInputData(a);a=b.apply(this,g);this.setOutputData(0,
|
||||
this.slot_types_in.sort())}},wrapFunctionAsNode:function(a,b,c,d,e){for(var g=Array(b.length),h="",n=f.getParameterNames(b),p=0;p<n.length;++p)h+="this.addInput('"+n[p]+"',"+(c&&c[p]?"'"+c[p]+"'":"0")+");\n";h+="this.addOutput('out',"+(d?"'"+d+"'":0)+");\n";e&&(h+="this.properties = "+JSON.stringify(e)+";\n");c=Function(h);c.title=a.split("/").pop();c.desc="Generated from "+b.name;c.prototype.onExecute=function(){for(var a=0;a<g.length;++a)g[a]=this.getInputData(a);a=b.apply(this,g);this.setOutputData(0,
|
||||
a)};this.registerNodeType(a,c)},clearRegisteredTypes:function(){this.registered_node_types={};this.node_types_by_file_extension={};this.Nodes={};this.searchbox_extras={}},addNodeMethod:function(a,b){l.prototype[a]=b;for(var c in this.registered_node_types){var d=this.registered_node_types[c];d.prototype[a]&&(d.prototype["_"+a]=d.prototype[a]);d.prototype[a]=b}},createNode:function(a,b,c){var d=this.registered_node_types[a];if(!d)return f.debug&&console.log('GraphNode type "'+a+'" not registered.'),
|
||||
null;b=b||d.title||a;var e=null;if(f.catch_exceptions)try{e=new d(b)}catch(k){return console.error(k),null}else e=new d(b);e.type=a;!e.title&&b&&(e.title=b);e.properties||(e.properties={});e.properties_info||(e.properties_info=[]);e.flags||(e.flags={});e.size||(e.size=e.computeSize());e.pos||(e.pos=f.DEFAULT_POSITION.concat());e.mode||(e.mode=f.ALWAYS);if(c)for(var g in c)e[g]=c[g];if(e.onNodeCreated)e.onNodeCreated();return e},getNodeType:function(a){return this.registered_node_types[a]},getNodeTypesInCategory:function(a,
|
||||
null;b=b||d.title||a;var e=null;if(f.catch_exceptions)try{e=new d(b)}catch(h){return console.error(h),null}else e=new d(b);e.type=a;!e.title&&b&&(e.title=b);e.properties||(e.properties={});e.properties_info||(e.properties_info=[]);e.flags||(e.flags={});e.size||(e.size=e.computeSize());e.pos||(e.pos=f.DEFAULT_POSITION.concat());e.mode||(e.mode=f.ALWAYS);if(c)for(var g in c)e[g]=c[g];if(e.onNodeCreated)e.onNodeCreated();return e},getNodeType:function(a){return this.registered_node_types[a]},getNodeTypesInCategory:function(a,
|
||||
b){var c=[],d;for(d in this.registered_node_types){var e=this.registered_node_types[d];e.filter==b&&(""==a?null==e.category&&c.push(e):e.category==a&&c.push(e))}this.auto_sort_node_types&&c.sort(function(a,b){return a.title.localeCompare(b.title)});return c},getNodeTypesCategories:function(a){var b={"":1},c;for(c in this.registered_node_types){var d=this.registered_node_types[c];d.category&&!d.skip_list&&d.filter==a&&(b[d.category]=1)}a=[];for(c in b)a.push(c);return this.auto_sort_node_types?a.sort():
|
||||
a},reloadNodes:function(a){for(var b=document.getElementsByTagName("script"),c=[],d=0;d<b.length;d++)c.push(b[d]);b=document.getElementsByTagName("head")[0];a=document.location.href+a;for(d=0;d<c.length;d++){var e=c[d].src;if(e&&e.substr(0,a.length)==a)try{f.debug&&console.log("Reloading: "+e);var g=document.createElement("script");g.type="text/javascript";g.src=e;b.appendChild(g);b.removeChild(c[d])}catch(k){if(f.throw_errors)throw k;f.debug&&console.log("Error while reloading "+e)}}f.debug&&console.log("Nodes reloaded")},
|
||||
a},reloadNodes:function(a){for(var b=document.getElementsByTagName("script"),c=[],d=0;d<b.length;d++)c.push(b[d]);b=document.getElementsByTagName("head")[0];a=document.location.href+a;for(d=0;d<c.length;d++){var e=c[d].src;if(e&&e.substr(0,a.length)==a)try{f.debug&&console.log("Reloading: "+e);var g=document.createElement("script");g.type="text/javascript";g.src=e;b.appendChild(g);b.removeChild(c[d])}catch(h){if(f.throw_errors)throw h;f.debug&&console.log("Error while reloading "+e)}}f.debug&&console.log("Nodes reloaded")},
|
||||
cloneObject:function(a,b){if(null==a)return null;a=JSON.parse(JSON.stringify(a));if(!b)return a;for(var c in a)b[c]=a[c];return b},isValidConnection:function(a,b){if(""==a||"*"===a)a=0;if(""==b||"*"===b)b=0;if(!a||!b||a==b||a==f.EVENT&&b==f.ACTION)return!0;a=String(a);b=String(b);a=a.toLowerCase();b=b.toLowerCase();if(-1==a.indexOf(",")&&-1==b.indexOf(","))return a==b;a=a.split(",");b=b.split(",");for(var c=0;c<a.length;++c)for(var d=0;d<b.length;++d)if(this.isValidConnection(a[c],b[d]))return!0;
|
||||
return!1},registerSearchboxExtra:function(a,b,c){this.searchbox_extras[b.toLowerCase()]={type:a,desc:b,data:c}},fetchFile:function(a,b,c,d){if(!a)return null;b=b||"text";if(a.constructor===String)return"http"==a.substr(0,4)&&f.proxy&&(a=f.proxy+a.substr(a.indexOf(":")+3)),fetch(a).then(function(a){if(!a.ok)throw Error("File not found");if("arraybuffer"==b)return a.arrayBuffer();if("text"==b||"string"==b)return a.text();if("json"==b)return a.json();if("blob"==b)return a.blob()}).then(function(a){c&&
|
||||
c(a)}).catch(function(b){console.error("error fetching file:",a);d&&d(b)});if(a.constructor===File||a.constructor===Blob){var e=new FileReader;e.onload=function(a){a=a.target.result;"json"==b&&(a=JSON.parse(a));c&&c(a)};if("arraybuffer"==b)return e.readAsArrayBuffer(a);if("text"==b||"json"==b)return e.readAsText(a);if("blob"==b)return e.readAsBinaryString(a)}return null}};f.getTime="undefined"!=typeof performance?performance.now.bind(performance):"undefined"!=typeof Date&&Date.now?Date.now.bind(Date):
|
||||
"undefined"!=typeof process?function(){var a=process.hrtime();return.001*a[0]+1E-6*a[1]}:function(){return(new Date).getTime()};x.LGraph=f.LGraph=m;m.supported_types=["number","string","boolean"];m.prototype.getSupportedTypes=function(){return this.supported_types||m.supported_types};m.STATUS_STOPPED=1;m.STATUS_RUNNING=2;m.prototype.clear=function(){this.stop();this.status=m.STATUS_STOPPED;this.last_link_id=this.last_node_id=0;this._version=-1;if(this._nodes)for(var a=0;a<this._nodes.length;++a){var b=
|
||||
this._nodes[a];if(b.onRemoved)b.onRemoved()}this._nodes=[];this._nodes_by_id={};this._nodes_in_order=[];this._nodes_executable=null;this._groups=[];this.links={};this.iteration=0;this.config={};this.vars={};this.extra={};this.fixedtime=this.runningtime=this.globaltime=0;this.elapsed_time=this.fixedtime_lapse=.01;this.starttime=this.last_update_time=0;this.catch_errors=!0;this.nodes_executing=[];this.nodes_actioning=[];this.nodes_executedAction=[];this.inputs={};this.outputs={};this.change();this.sendActionToCanvas("clear")};
|
||||
m.prototype.attachCanvas=function(a){if(a.constructor!=h)throw"attachCanvas expects a LGraphCanvas instance";a.graph&&a.graph!=this&&a.graph.detachCanvas(a);a.graph=this;this.list_of_graphcanvas||(this.list_of_graphcanvas=[]);this.list_of_graphcanvas.push(a)};m.prototype.detachCanvas=function(a){if(this.list_of_graphcanvas){var b=this.list_of_graphcanvas.indexOf(a);-1!=b&&(a.graph=null,this.list_of_graphcanvas.splice(b,1))}};m.prototype.start=function(a){if(this.status!=m.STATUS_RUNNING){this.status=
|
||||
m.prototype.attachCanvas=function(a){if(a.constructor!=k)throw"attachCanvas expects a LGraphCanvas instance";a.graph&&a.graph!=this&&a.graph.detachCanvas(a);a.graph=this;this.list_of_graphcanvas||(this.list_of_graphcanvas=[]);this.list_of_graphcanvas.push(a)};m.prototype.detachCanvas=function(a){if(this.list_of_graphcanvas){var b=this.list_of_graphcanvas.indexOf(a);-1!=b&&(a.graph=null,this.list_of_graphcanvas.splice(b,1))}};m.prototype.start=function(a){if(this.status!=m.STATUS_RUNNING){this.status=
|
||||
m.STATUS_RUNNING;if(this.onPlayEvent)this.onPlayEvent();this.sendEventToAllNodes("onStart");this.last_update_time=this.starttime=f.getTime();a=a||0;var b=this;if(0==a&&"undefined"!=typeof window&&window.requestAnimationFrame){var c=function(){if(-1==b.execution_timer_id){window.requestAnimationFrame(c);if(b.onBeforeStep)b.onBeforeStep();b.runStep(1,!b.catch_errors);if(b.onAfterStep)b.onAfterStep()}};this.execution_timer_id=-1;c()}else this.execution_timer_id=setInterval(function(){if(b.onBeforeStep)b.onBeforeStep();
|
||||
b.runStep(1,!b.catch_errors);if(b.onAfterStep)b.onAfterStep()},a)}};m.prototype.stop=function(){if(this.status!=m.STATUS_STOPPED){this.status=m.STATUS_STOPPED;if(this.onStopEvent)this.onStopEvent();null!=this.execution_timer_id&&(-1!=this.execution_timer_id&&clearInterval(this.execution_timer_id),this.execution_timer_id=null);this.sendEventToAllNodes("onStop")}};m.prototype.runStep=function(a,b,c){a=a||1;var d=f.getTime();this.globaltime=.001*(d-this.starttime);var e=this._nodes_executable?this._nodes_executable:
|
||||
this._nodes;if(e){c=c||e.length;if(b){for(var g=0;g<a;g++){for(var k=0;k<c;++k){var n=e[k];n.mode==f.ALWAYS&&n.onExecute&&n.doExecute()}this.fixedtime+=this.fixedtime_lapse;if(this.onExecuteStep)this.onExecuteStep()}if(this.onAfterExecute)this.onAfterExecute()}else try{for(g=0;g<a;g++){for(k=0;k<c;++k)if(n=e[k],n.mode==f.ALWAYS&&n.onExecute)n.onExecute();this.fixedtime+=this.fixedtime_lapse;if(this.onExecuteStep)this.onExecuteStep()}if(this.onAfterExecute)this.onAfterExecute();this.errors_in_execution=
|
||||
this._nodes;if(e){c=c||e.length;if(b){for(var g=0;g<a;g++){for(var h=0;h<c;++h){var n=e[h];n.mode==f.ALWAYS&&n.onExecute&&n.doExecute()}this.fixedtime+=this.fixedtime_lapse;if(this.onExecuteStep)this.onExecuteStep()}if(this.onAfterExecute)this.onAfterExecute()}else try{for(g=0;g<a;g++){for(h=0;h<c;++h)if(n=e[h],n.mode==f.ALWAYS&&n.onExecute)n.onExecute();this.fixedtime+=this.fixedtime_lapse;if(this.onExecuteStep)this.onExecuteStep()}if(this.onAfterExecute)this.onAfterExecute();this.errors_in_execution=
|
||||
!1}catch(p){this.errors_in_execution=!0;if(f.throw_errors)throw p;f.debug&&console.log("Error during execution: "+p);this.stop()}a=f.getTime();d=a-d;0==d&&(d=1);this.execution_time=.001*d;this.globaltime+=.001*d;this.iteration+=1;this.elapsed_time=.001*(a-this.last_update_time);this.last_update_time=a;this.nodes_executing=[];this.nodes_actioning=[];this.nodes_executedAction=[]}};m.prototype.updateExecutionOrder=function(){this._nodes_in_order=this.computeExecutionOrder(!1);this._nodes_executable=
|
||||
[];for(var a=0;a<this._nodes_in_order.length;++a)this._nodes_in_order[a].onExecute&&this._nodes_executable.push(this._nodes_in_order[a])};m.prototype.computeExecutionOrder=function(a,b){for(var c=[],d=[],e={},g={},k={},n=0,p=this._nodes.length;n<p;++n){var r=this._nodes[n];if(!a||r.onExecute){e[r.id]=r;var u=0;if(r.inputs)for(var q=0,y=r.inputs.length;q<y;q++)r.inputs[q]&&null!=r.inputs[q].link&&(u+=1);0==u?(d.push(r),b&&(r._level=1)):(b&&(r._level=0),k[r.id]=u)}}for(;0!=d.length;)if(r=d.shift(),
|
||||
c.push(r),delete e[r.id],r.outputs)for(n=0;n<r.outputs.length;n++)if(a=r.outputs[n],null!=a&&null!=a.links&&0!=a.links.length)for(q=0;q<a.links.length;q++)(p=this.links[a.links[q]])&&!g[p.id]&&(u=this.getNodeById(p.target_id),null==u?g[p.id]=!0:(b&&(!u._level||u._level<=r._level)&&(u._level=r._level+1),g[p.id]=!0,--k[u.id],0==k[u.id]&&d.push(u)));for(n in e)c.push(e[n]);c.length!=this._nodes.length&&f.debug&&console.warn("something went wrong, nodes missing");p=c.length;for(n=0;n<p;++n)c[n].order=
|
||||
n;c=c.sort(function(a,b){var c=a.constructor.priority||a.priority||0,d=b.constructor.priority||b.priority||0;return c==d?a.order-b.order:c-d});for(n=0;n<p;++n)c[n].order=n;return c};m.prototype.getAncestors=function(a){for(var b=[],c=[a],d={};c.length;){var e=c.shift();if(e.inputs){d[e.id]||e==a||(d[e.id]=!0,b.push(e));for(var g=0;g<e.inputs.length;++g){var f=e.getInputNode(g);f&&-1==b.indexOf(f)&&c.push(f)}}}b.sort(function(a,b){return a.order-b.order});return b};m.prototype.arrange=function(a){a=
|
||||
a||100;for(var b=this.computeExecutionOrder(!1,!0),c=[],d=0;d<b.length;++d){var e=b[d],g=e._level||1;c[g]||(c[g]=[]);c[g].push(e)}b=a;for(d=0;d<c.length;++d)if(g=c[d]){for(var k=100,n=a+f.NODE_TITLE_HEIGHT,p=0;p<g.length;++p)e=g[p],e.pos[0]=b,e.pos[1]=n,e.size[0]>k&&(k=e.size[0]),n+=e.size[1]+a+f.NODE_TITLE_HEIGHT;b+=k+a}this.setDirtyCanvas(!0,!0)};m.prototype.getTime=function(){return this.globaltime};m.prototype.getFixedTime=function(){return this.fixedtime};m.prototype.getElapsedTime=function(){return this.elapsed_time};
|
||||
m.prototype.sendEventToAllNodes=function(a,b,c){c=c||f.ALWAYS;var d=this._nodes_in_order?this._nodes_in_order:this._nodes;if(d)for(var e=0,g=d.length;e<g;++e){var k=d[e];if(k.constructor===f.Subgraph&&"onExecute"!=a)k.mode==c&&k.sendEventToAllNodes(a,b,c);else if(k[a]&&k.mode==c)if(void 0===b)k[a]();else if(b&&b.constructor===Array)k[a].apply(k,b);else k[a](b)}};m.prototype.sendActionToCanvas=function(a,b){if(this.list_of_graphcanvas)for(var c=0;c<this.list_of_graphcanvas.length;++c){var d=this.list_of_graphcanvas[c];
|
||||
d[a]&&d[a].apply(d,b)}};m.prototype.add=function(a,b){if(a)if(a.constructor===w)this._groups.push(a),this.setDirtyCanvas(!0),this.change(),a.graph=this,this._version++;else{-1!=a.id&&null!=this._nodes_by_id[a.id]&&(console.warn("LiteGraph: there is already a node with this ID, changing it"),a.id=++this.last_node_id);if(this._nodes.length>=f.MAX_NUMBER_OF_NODES)throw"LiteGraph: max number of nodes in a graph reached";null==a.id||-1==a.id?a.id=++this.last_node_id:this.last_node_id<a.id&&(this.last_node_id=
|
||||
a.id);a.graph=this;this._version++;this._nodes.push(a);this._nodes_by_id[a.id]=a;if(a.onAdded)a.onAdded(this);this.config.align_to_grid&&a.alignToGrid();b||this.updateExecutionOrder();if(this.onNodeAdded)this.onNodeAdded(a);this.setDirtyCanvas(!0);this.change();return a}};m.prototype.remove=function(a){if(a.constructor===f.LGraphGroup){var b=this._groups.indexOf(a);-1!=b&&this._groups.splice(b,1);a.graph=null;this._version++;this.setDirtyCanvas(!0,!0);this.change()}else if(null!=this._nodes_by_id[a.id]&&
|
||||
!a.ignore_remove){this.beforeChange();if(a.inputs)for(b=0;b<a.inputs.length;b++){var c=a.inputs[b];null!=c.link&&a.disconnectInput(b)}if(a.outputs)for(b=0;b<a.outputs.length;b++)c=a.outputs[b],null!=c.links&&c.links.length&&a.disconnectOutput(b);if(a.onRemoved)a.onRemoved();a.graph=null;this._version++;if(this.list_of_graphcanvas)for(b=0;b<this.list_of_graphcanvas.length;++b)c=this.list_of_graphcanvas[b],c.selected_nodes[a.id]&&delete c.selected_nodes[a.id],c.node_dragged==a&&(c.node_dragged=null);
|
||||
b=this._nodes.indexOf(a);-1!=b&&this._nodes.splice(b,1);delete this._nodes_by_id[a.id];if(this.onNodeRemoved)this.onNodeRemoved(a);this.sendActionToCanvas("checkPanels");this.setDirtyCanvas(!0,!0);this.afterChange();this.change();this.updateExecutionOrder()}};m.prototype.getNodeById=function(a){return null==a?null:this._nodes_by_id[a]};m.prototype.findNodesByClass=function(a,b){b=b||[];for(var c=b.length=0,d=this._nodes.length;c<d;++c)this._nodes[c].constructor===a&&b.push(this._nodes[c]);return b};
|
||||
m.prototype.findNodesByType=function(a,b){a=a.toLowerCase();b=b||[];for(var c=b.length=0,d=this._nodes.length;c<d;++c)this._nodes[c].type.toLowerCase()==a&&b.push(this._nodes[c]);return b};m.prototype.findNodeByTitle=function(a){for(var b=0,c=this._nodes.length;b<c;++b)if(this._nodes[b].title==a)return this._nodes[b];return null};m.prototype.findNodesByTitle=function(a){for(var b=[],c=0,d=this._nodes.length;c<d;++c)this._nodes[c].title==a&&b.push(this._nodes[c]);return b};m.prototype.getNodeOnPos=
|
||||
function(a,b,c,d){c=c||this._nodes;for(var e=c.length-1;0<=e;e--){var g=c[e];if(g.isPointInside(a,b,d))return g}return null};m.prototype.getGroupOnPos=function(a,b){for(var c=this._groups.length-1;0<=c;c--){var d=this._groups[c];if(d.isPointInside(a,b,2,!0))return d}return null};m.prototype.checkNodeTypes=function(){for(var a=0;a<this._nodes.length;a++){var b=this._nodes[a];if(b.constructor!=f.registered_node_types[b.type]){console.log("node being replaced by newer version: "+b.type);var c=f.createNode(b.type);
|
||||
this._nodes[a]=c;c.configure(b.serialize());c.graph=this;this._nodes_by_id[c.id]=c;b.inputs&&(c.inputs=b.inputs.concat());b.outputs&&(c.outputs=b.outputs.concat())}}this.updateExecutionOrder()};m.prototype.onAction=function(a,b,c){this._input_nodes=this.findNodesByClass(f.GraphInput,this._input_nodes);for(var d=0;d<this._input_nodes.length;++d){var e=this._input_nodes[d];if(e.properties.name==a){e.actionDo(a,b,c);break}}};m.prototype.trigger=function(a,b){if(this.onTrigger)this.onTrigger(a,b)};m.prototype.addInput=
|
||||
function(a,b,c){if(!this.inputs[a]){this.beforeChange();this.inputs[a]={name:a,type:b,value:c};this._version++;this.afterChange();if(this.onInputAdded)this.onInputAdded(a,b);if(this.onInputsOutputsChange)this.onInputsOutputsChange()}};m.prototype.setInputData=function(a,b){if(a=this.inputs[a])a.value=b};m.prototype.getInputData=function(a){return(a=this.inputs[a])?a.value:null};m.prototype.renameInput=function(a,b){if(b!=a){if(!this.inputs[a])return!1;if(this.inputs[b])return console.error("there is already one input with that name"),
|
||||
[];for(var a=0;a<this._nodes_in_order.length;++a)this._nodes_in_order[a].onExecute&&this._nodes_executable.push(this._nodes_in_order[a])};m.prototype.computeExecutionOrder=function(a,b){for(var c=[],d=[],e={},g={},h={},n=0,p=this._nodes.length;n<p;++n){var r=this._nodes[n];if(!a||r.onExecute){e[r.id]=r;var u=0;if(r.inputs)for(var q=0,y=r.inputs.length;q<y;q++)r.inputs[q]&&null!=r.inputs[q].link&&(u+=1);0==u?(d.push(r),b&&(r._level=1)):(b&&(r._level=0),h[r.id]=u)}}for(;0!=d.length;)if(r=d.shift(),
|
||||
c.push(r),delete e[r.id],r.outputs)for(n=0;n<r.outputs.length;n++)if(a=r.outputs[n],null!=a&&null!=a.links&&0!=a.links.length)for(q=0;q<a.links.length;q++)(p=this.links[a.links[q]])&&!g[p.id]&&(u=this.getNodeById(p.target_id),null==u?g[p.id]=!0:(b&&(!u._level||u._level<=r._level)&&(u._level=r._level+1),g[p.id]=!0,--h[u.id],0==h[u.id]&&d.push(u)));for(n in e)c.push(e[n]);c.length!=this._nodes.length&&f.debug&&console.warn("something went wrong, nodes missing");p=c.length;for(n=0;n<p;++n)c[n].order=
|
||||
n;c=c.sort(function(a,b){var c=a.constructor.priority||a.priority||0,d=b.constructor.priority||b.priority||0;return c==d?a.order-b.order:c-d});for(n=0;n<p;++n)c[n].order=n;return c};m.prototype.getAncestors=function(a){for(var b=[],c=[a],d={};c.length;){var e=c.shift();if(e.inputs){d[e.id]||e==a||(d[e.id]=!0,b.push(e));for(var g=0;g<e.inputs.length;++g){var h=e.getInputNode(g);h&&-1==b.indexOf(h)&&c.push(h)}}}b.sort(function(a,b){return a.order-b.order});return b};m.prototype.arrange=function(a,b){a=
|
||||
a||100;for(var c=this.computeExecutionOrder(!1,!0),d=[],e=0;e<c.length;++e){var g=c[e],h=g._level||1;d[h]||(d[h]=[]);d[h].push(g)}c=a;for(e=0;e<d.length;++e)if(h=d[e]){for(var n=100,p=a+f.NODE_TITLE_HEIGHT,r=0;r<h.length;++r){g=h[r];g.pos[0]=b==f.VERTICAL_LAYOUT?p:c;g.pos[1]=b==f.VERTICAL_LAYOUT?c:p;var u=b==f.VERTICAL_LAYOUT?1:0;g.size[u]>n&&(n=g.size[u]);p+=g.size[b==f.VERTICAL_LAYOUT?0:1]+a+f.NODE_TITLE_HEIGHT}c+=n+a}this.setDirtyCanvas(!0,!0)};m.prototype.getTime=function(){return this.globaltime};
|
||||
m.prototype.getFixedTime=function(){return this.fixedtime};m.prototype.getElapsedTime=function(){return this.elapsed_time};m.prototype.sendEventToAllNodes=function(a,b,c){c=c||f.ALWAYS;var d=this._nodes_in_order?this._nodes_in_order:this._nodes;if(d)for(var e=0,g=d.length;e<g;++e){var h=d[e];if(h.constructor===f.Subgraph&&"onExecute"!=a)h.mode==c&&h.sendEventToAllNodes(a,b,c);else if(h[a]&&h.mode==c)if(void 0===b)h[a]();else if(b&&b.constructor===Array)h[a].apply(h,b);else h[a](b)}};m.prototype.sendActionToCanvas=
|
||||
function(a,b){if(this.list_of_graphcanvas)for(var c=0;c<this.list_of_graphcanvas.length;++c){var d=this.list_of_graphcanvas[c];d[a]&&d[a].apply(d,b)}};m.prototype.add=function(a,b){if(a)if(a.constructor===w)this._groups.push(a),this.setDirtyCanvas(!0),this.change(),a.graph=this,this._version++;else{-1!=a.id&&null!=this._nodes_by_id[a.id]&&(console.warn("LiteGraph: there is already a node with this ID, changing it"),a.id=++this.last_node_id);if(this._nodes.length>=f.MAX_NUMBER_OF_NODES)throw"LiteGraph: max number of nodes in a graph reached";
|
||||
null==a.id||-1==a.id?a.id=++this.last_node_id:this.last_node_id<a.id&&(this.last_node_id=a.id);a.graph=this;this._version++;this._nodes.push(a);this._nodes_by_id[a.id]=a;if(a.onAdded)a.onAdded(this);this.config.align_to_grid&&a.alignToGrid();b||this.updateExecutionOrder();if(this.onNodeAdded)this.onNodeAdded(a);this.setDirtyCanvas(!0);this.change();return a}};m.prototype.remove=function(a){if(a.constructor===f.LGraphGroup){var b=this._groups.indexOf(a);-1!=b&&this._groups.splice(b,1);a.graph=null;
|
||||
this._version++;this.setDirtyCanvas(!0,!0);this.change()}else if(null!=this._nodes_by_id[a.id]&&!a.ignore_remove){this.beforeChange();if(a.inputs)for(b=0;b<a.inputs.length;b++){var c=a.inputs[b];null!=c.link&&a.disconnectInput(b)}if(a.outputs)for(b=0;b<a.outputs.length;b++)c=a.outputs[b],null!=c.links&&c.links.length&&a.disconnectOutput(b);if(a.onRemoved)a.onRemoved();a.graph=null;this._version++;if(this.list_of_graphcanvas)for(b=0;b<this.list_of_graphcanvas.length;++b)c=this.list_of_graphcanvas[b],
|
||||
c.selected_nodes[a.id]&&delete c.selected_nodes[a.id],c.node_dragged==a&&(c.node_dragged=null);b=this._nodes.indexOf(a);-1!=b&&this._nodes.splice(b,1);delete this._nodes_by_id[a.id];if(this.onNodeRemoved)this.onNodeRemoved(a);this.sendActionToCanvas("checkPanels");this.setDirtyCanvas(!0,!0);this.afterChange();this.change();this.updateExecutionOrder()}};m.prototype.getNodeById=function(a){return null==a?null:this._nodes_by_id[a]};m.prototype.findNodesByClass=function(a,b){b=b||[];for(var c=b.length=
|
||||
0,d=this._nodes.length;c<d;++c)this._nodes[c].constructor===a&&b.push(this._nodes[c]);return b};m.prototype.findNodesByType=function(a,b){a=a.toLowerCase();b=b||[];for(var c=b.length=0,d=this._nodes.length;c<d;++c)this._nodes[c].type.toLowerCase()==a&&b.push(this._nodes[c]);return b};m.prototype.findNodeByTitle=function(a){for(var b=0,c=this._nodes.length;b<c;++b)if(this._nodes[b].title==a)return this._nodes[b];return null};m.prototype.findNodesByTitle=function(a){for(var b=[],c=0,d=this._nodes.length;c<
|
||||
d;++c)this._nodes[c].title==a&&b.push(this._nodes[c]);return b};m.prototype.getNodeOnPos=function(a,b,c,d){c=c||this._nodes;for(var e=c.length-1;0<=e;e--){var g=c[e];if(g.isPointInside(a,b,d))return g}return null};m.prototype.getGroupOnPos=function(a,b){for(var c=this._groups.length-1;0<=c;c--){var d=this._groups[c];if(d.isPointInside(a,b,2,!0))return d}return null};m.prototype.checkNodeTypes=function(){for(var a=0;a<this._nodes.length;a++){var b=this._nodes[a];if(b.constructor!=f.registered_node_types[b.type]){console.log("node being replaced by newer version: "+
|
||||
b.type);var c=f.createNode(b.type);this._nodes[a]=c;c.configure(b.serialize());c.graph=this;this._nodes_by_id[c.id]=c;b.inputs&&(c.inputs=b.inputs.concat());b.outputs&&(c.outputs=b.outputs.concat())}}this.updateExecutionOrder()};m.prototype.onAction=function(a,b,c){this._input_nodes=this.findNodesByClass(f.GraphInput,this._input_nodes);for(var d=0;d<this._input_nodes.length;++d){var e=this._input_nodes[d];if(e.properties.name==a){e.actionDo(a,b,c);break}}};m.prototype.trigger=function(a,b){if(this.onTrigger)this.onTrigger(a,
|
||||
b)};m.prototype.addInput=function(a,b,c){if(!this.inputs[a]){this.beforeChange();this.inputs[a]={name:a,type:b,value:c};this._version++;this.afterChange();if(this.onInputAdded)this.onInputAdded(a,b);if(this.onInputsOutputsChange)this.onInputsOutputsChange()}};m.prototype.setInputData=function(a,b){if(a=this.inputs[a])a.value=b};m.prototype.getInputData=function(a){return(a=this.inputs[a])?a.value:null};m.prototype.renameInput=function(a,b){if(b!=a){if(!this.inputs[a])return!1;if(this.inputs[b])return console.error("there is already one input with that name"),
|
||||
!1;this.inputs[b]=this.inputs[a];delete this.inputs[a];this._version++;if(this.onInputRenamed)this.onInputRenamed(a,b);if(this.onInputsOutputsChange)this.onInputsOutputsChange()}};m.prototype.changeInputType=function(a,b){if(!this.inputs[a])return!1;if(!this.inputs[a].type||String(this.inputs[a].type).toLowerCase()!=String(b).toLowerCase())if(this.inputs[a].type=b,this._version++,this.onInputTypeChanged)this.onInputTypeChanged(a,b)};m.prototype.removeInput=function(a){if(!this.inputs[a])return!1;
|
||||
delete this.inputs[a];this._version++;if(this.onInputRemoved)this.onInputRemoved(a);if(this.onInputsOutputsChange)this.onInputsOutputsChange();return!0};m.prototype.addOutput=function(a,b,c){this.outputs[a]={name:a,type:b,value:c};this._version++;if(this.onOutputAdded)this.onOutputAdded(a,b);if(this.onInputsOutputsChange)this.onInputsOutputsChange()};m.prototype.setOutputData=function(a,b){if(a=this.outputs[a])a.value=b};m.prototype.getOutputData=function(a){return(a=this.outputs[a])?a.value:null};
|
||||
m.prototype.renameOutput=function(a,b){if(!this.outputs[a])return!1;if(this.outputs[b])return console.error("there is already one output with that name"),!1;this.outputs[b]=this.outputs[a];delete this.outputs[a];this._version++;if(this.onOutputRenamed)this.onOutputRenamed(a,b);if(this.onInputsOutputsChange)this.onInputsOutputsChange()};m.prototype.changeOutputType=function(a,b){if(!this.outputs[a])return!1;if(!this.outputs[a].type||String(this.outputs[a].type).toLowerCase()!=String(b).toLowerCase())if(this.outputs[a].type=
|
||||
@@ -65,296 +65,296 @@ m.prototype.beforeChange=function(a){if(this.onBeforeChange)this.onBeforeChange(
|
||||
for(var a=0;a<this.list_of_graphcanvas.length;++a)if(this.list_of_graphcanvas[a].live_mode)return!0;return!1};m.prototype.clearTriggeredSlots=function(){for(var a in this.links){var b=this.links[a];b&&b._last_time&&(b._last_time=0)}};m.prototype.change=function(){f.debug&&console.log("Graph changed");this.sendActionToCanvas("setDirty",[!0,!0]);if(this.on_change)this.on_change(this)};m.prototype.setDirtyCanvas=function(a,b){this.sendActionToCanvas("setDirty",[a,b])};m.prototype.removeLink=function(a){if(a=
|
||||
this.links[a]){var b=this.getNodeById(a.target_id);b&&b.disconnectInput(a.target_slot)}};m.prototype.serialize=function(){for(var a=[],b=0,c=this._nodes.length;b<c;++b)a.push(this._nodes[b].serialize());c=[];for(b in this.links){var d=this.links[b];if(!d.serialize){console.warn("weird LLink bug, link info is not a LLink but a regular object");var e=new t;for(g in d)e[g]=d[g];d=this.links[b]=e}c.push(d.serialize())}var g=[];for(b=0;b<this._groups.length;++b)g.push(this._groups[b].serialize());a={last_node_id:this.last_node_id,
|
||||
last_link_id:this.last_link_id,nodes:a,links:c,groups:g,config:this.config,extra:this.extra,version:f.VERSION};if(this.onSerialize)this.onSerialize(a);return a};m.prototype.configure=function(a,b){if(a){b||this.clear();b=a.nodes;if(a.links&&a.links.constructor===Array){for(var c=[],d=0;d<a.links.length;++d){var e=a.links[d];if(e){var g=new t;g.configure(e);c[g.id]=g}else console.warn("serialized graph link data contains errors, skipping.")}a.links=c}for(d in a)"nodes"!=d&&"groups"!=d&&(this[d]=a[d]);
|
||||
c=!1;this._nodes=[];if(b){d=0;for(e=b.length;d<e;++d){g=b[d];var k=f.createNode(g.type,g.title);k||(f.debug&&console.log("Node not found or has errors: "+g.type),k=new l,k.last_serialization=g,c=k.has_errors=!0);k.id=g.id;this.add(k,!0)}d=0;for(e=b.length;d<e;++d)g=b[d],(k=this.getNodeById(g.id))&&k.configure(g)}this._groups.length=0;if(a.groups)for(d=0;d<a.groups.length;++d)b=new f.LGraphGroup,b.configure(a.groups[d]),this.add(b);this.updateExecutionOrder();this.extra=a.extra||{};if(this.onConfigure)this.onConfigure(a);
|
||||
c=!1;this._nodes=[];if(b){d=0;for(e=b.length;d<e;++d){g=b[d];var h=f.createNode(g.type,g.title);h||(f.debug&&console.log("Node not found or has errors: "+g.type),h=new l,h.last_serialization=g,c=h.has_errors=!0);h.id=g.id;this.add(h,!0)}d=0;for(e=b.length;d<e;++d)g=b[d],(h=this.getNodeById(g.id))&&h.configure(g)}this._groups.length=0;if(a.groups)for(d=0;d<a.groups.length;++d)b=new f.LGraphGroup,b.configure(a.groups[d]),this.add(b);this.updateExecutionOrder();this.extra=a.extra||{};if(this.onConfigure)this.onConfigure(a);
|
||||
this._version++;this.setDirtyCanvas(!0,!0);return c}};m.prototype.load=function(a,b){var c=this;if(a.constructor===File||a.constructor===Blob){var d=new FileReader;d.addEventListener("load",function(a){a=JSON.parse(a.target.result);c.configure(a);b&&b()});d.readAsText(a)}else{var e=new XMLHttpRequest;e.open("GET",a,!0);e.send(null);e.onload=function(a){200!==e.status?console.error("Error loading graph:",e.status,e.response):(a=JSON.parse(e.response),c.configure(a),b&&b())};e.onerror=function(a){console.error("Error loading graph:",
|
||||
a)}}};m.prototype.onNodeTrace=function(a,b,c){};t.prototype.configure=function(a){a.constructor===Array?(this.id=a[0],this.origin_id=a[1],this.origin_slot=a[2],this.target_id=a[3],this.target_slot=a[4],this.type=a[5]):(this.id=a.id,this.type=a.type,this.origin_id=a.origin_id,this.origin_slot=a.origin_slot,this.target_id=a.target_id,this.target_slot=a.target_slot)};t.prototype.serialize=function(){return[this.id,this.origin_id,this.origin_slot,this.target_id,this.target_slot,this.type]};f.LLink=t;
|
||||
x.LGraphNode=f.LGraphNode=l;l.prototype._ctor=function(a){this.title=a||"Unnamed";this.size=[f.NODE_WIDTH,60];this.graph=null;this._pos=new Float32Array(10,10);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});this.id=-1;this.type=null;this.inputs=[];this.outputs=[];this.connections=[];this.properties={};this.properties_info=[];this.flags={}};l.prototype.configure=function(a){this.graph&&this.graph._version++;
|
||||
for(var b in a)if("properties"==b)for(var c in a.properties){if(this.properties[c]=a.properties[c],this.onPropertyChanged)this.onPropertyChanged(c,a.properties[c])}else null!=a[b]&&("object"==typeof a[b]?this[b]&&this[b].configure?this[b].configure(a[b]):this[b]=f.cloneObject(a[b],this[b]):this[b]=a[b]);a.title||(this.title=this.constructor.title);if(this.onConnectionsChange){if(this.inputs)for(c=0;c<this.inputs.length;++c){b=this.inputs[c];var d=this.graph?this.graph.links[b.link]:null;this.onConnectionsChange(f.INPUT,
|
||||
c,!0,d,b)}if(this.outputs)for(c=0;c<this.outputs.length;++c){var e=this.outputs[c];if(e.links)for(b=0;b<e.links.length;++b)d=this.graph?this.graph.links[e.links[b]]:null,this.onConnectionsChange(f.OUTPUT,c,!0,d,e)}}if(this.widgets){for(c=0;c<this.widgets.length;++c)(b=this.widgets[c])&&b.options&&b.options.property&&this.properties[b.options.property]&&(b.value=JSON.parse(JSON.stringify(this.properties[b.options.property])));if(a.widgets_values)for(c=0;c<a.widgets_values.length;++c)this.widgets[c]&&
|
||||
(this.widgets[c].value=a.widgets_values[c])}if(this.onConfigure)this.onConfigure(a)};l.prototype.serialize=function(){var a={id:this.id,type:this.type,pos:this.pos,size:this.size,flags:f.cloneObject(this.flags),order:this.order,mode:this.mode};if(this.constructor===l&&this.last_serialization)return this.last_serialization;this.inputs&&(a.inputs=this.inputs);if(this.outputs){for(var b=0;b<this.outputs.length;b++)delete this.outputs[b]._data;a.outputs=this.outputs}this.title&&this.title!=this.constructor.title&&
|
||||
(a.title=this.title);this.properties&&(a.properties=f.cloneObject(this.properties));if(this.widgets&&this.serialize_widgets)for(a.widgets_values=[],b=0;b<this.widgets.length;++b)a.widgets_values[b]=this.widgets[b]?this.widgets[b].value:null;a.type||(a.type=this.constructor.type);this.color&&(a.color=this.color);this.bgcolor&&(a.bgcolor=this.bgcolor);this.boxcolor&&(a.boxcolor=this.boxcolor);this.shape&&(a.shape=this.shape);this.onSerialize&&this.onSerialize(a)&&console.warn("node onSerialize shouldnt return anything, data should be stored in the object pass in the first parameter");
|
||||
return a};l.prototype.clone=function(){var a=f.createNode(this.type);if(!a)return null;var b=f.cloneObject(this.serialize());if(b.inputs)for(var c=0;c<b.inputs.length;++c)b.inputs[c].link=null;if(b.outputs)for(c=0;c<b.outputs.length;++c)b.outputs[c].links&&(b.outputs[c].links.length=0);delete b.id;a.configure(b);return a};l.prototype.toString=function(){return JSON.stringify(this.serialize())};l.prototype.getTitle=function(){return this.title||this.constructor.title};l.prototype.setProperty=function(a,
|
||||
b){this.properties||(this.properties={});if(b!==this.properties[a]){var c=this.properties[a];this.properties[a]=b;this.onPropertyChanged&&!1===this.onPropertyChanged(a,b,c)&&(this.properties[a]=c);if(this.widgets)for(c=0;c<this.widgets.length;++c){var d=this.widgets[c];if(d&&d.options.property==a){d.value=b;break}}}};l.prototype.setOutputData=function(a,b){if(this.outputs&&!(-1==a||a>=this.outputs.length)){var c=this.outputs[a];if(c&&(c._data=b,this.outputs[a].links))for(c=0;c<this.outputs[a].links.length;c++){var d=
|
||||
this.graph.links[this.outputs[a].links[c]];d&&(d.data=b)}}};l.prototype.setOutputDataType=function(a,b){if(this.outputs&&!(-1==a||a>=this.outputs.length)){var c=this.outputs[a];if(c&&(c.type=b,this.outputs[a].links))for(c=0;c<this.outputs[a].links.length;c++)this.graph.links[this.outputs[a].links[c]].type=b}};l.prototype.getInputData=function(a,b){if(this.inputs&&!(a>=this.inputs.length||null==this.inputs[a].link)){a=this.graph.links[this.inputs[a].link];if(!a)return null;if(!b)return a.data;b=this.graph.getNodeById(a.origin_id);
|
||||
if(!b)return a.data;if(b.updateOutputData)b.updateOutputData(a.origin_slot);else if(b.onExecute)b.onExecute();return a.data}};l.prototype.getInputDataType=function(a){if(!this.inputs||a>=this.inputs.length||null==this.inputs[a].link)return null;a=this.graph.links[this.inputs[a].link];if(!a)return null;var b=this.graph.getNodeById(a.origin_id);return b?(a=b.outputs[a.origin_slot])?a.type:null:a.type};l.prototype.getInputDataByName=function(a,b){a=this.findInputSlot(a);return-1==a?null:this.getInputData(a,
|
||||
b)};l.prototype.isInputConnected=function(a){return this.inputs?a<this.inputs.length&&null!=this.inputs[a].link:!1};l.prototype.getInputInfo=function(a){return this.inputs?a<this.inputs.length?this.inputs[a]:null:null};l.prototype.getInputLink=function(a){return this.inputs?a<this.inputs.length?this.graph.links[this.inputs[a].link]:null:null};l.prototype.getInputNode=function(a){if(!this.inputs||a>=this.inputs.length)return null;a=this.inputs[a];return a&&null!==a.link?(a=this.graph.links[a.link])?
|
||||
this.graph.getNodeById(a.origin_id):null:null};l.prototype.getInputOrProperty=function(a){if(!this.inputs||!this.inputs.length)return this.properties?this.properties[a]:null;for(var b=0,c=this.inputs.length;b<c;++b){var d=this.inputs[b];if(a==d.name&&null!=d.link&&(d=this.graph.links[d.link]))return d.data}return this.properties[a]};l.prototype.getOutputData=function(a){return!this.outputs||a>=this.outputs.length?null:this.outputs[a]._data};l.prototype.getOutputInfo=function(a){return this.outputs?
|
||||
a<this.outputs.length?this.outputs[a]:null:null};l.prototype.isOutputConnected=function(a){return this.outputs?a<this.outputs.length&&this.outputs[a].links&&this.outputs[a].links.length:!1};l.prototype.isAnyOutputConnected=function(){if(!this.outputs)return!1;for(var a=0;a<this.outputs.length;++a)if(this.outputs[a].links&&this.outputs[a].links.length)return!0;return!1};l.prototype.getOutputNodes=function(a){if(!this.outputs||0==this.outputs.length||a>=this.outputs.length)return null;a=this.outputs[a];
|
||||
if(!a.links||0==a.links.length)return null;for(var b=[],c=0;c<a.links.length;c++){var d=this.graph.links[a.links[c]];d&&(d=this.graph.getNodeById(d.target_id))&&b.push(d)}return b};l.prototype.addOnTriggerInput=function(){var a=this.findInputSlot("onTrigger");return-1==a?(this.addInput("onTrigger",f.EVENT,{optional:!0,nameLocked:!0}),this.findInputSlot("onTrigger")):a};l.prototype.addOnExecutedOutput=function(){var a=this.findOutputSlot("onExecuted");return-1==a?(this.addOutput("onExecuted",f.ACTION,
|
||||
{optional:!0,nameLocked:!0}),this.findOutputSlot("onExecuted")):a};l.prototype.onAfterExecuteNode=function(a,b){var c=this.findOutputSlot("onExecuted");-1!=c&&this.triggerSlot(c,a,null,b)};l.prototype.changeMode=function(a){switch(a){case f.ON_EVENT:break;case f.ON_TRIGGER:this.addOnTriggerInput();this.addOnExecutedOutput();break;case f.NEVER:break;case f.ALWAYS:break;case f.ON_REQUEST:break;default:return!1}this.mode=a;return!0};l.prototype.doExecute=function(a,b){b=b||{};this.onExecute&&(b.action_call||
|
||||
(b.action_call=this.id+"_exec_"+Math.floor(9999*Math.random())),this.graph.nodes_executing[this.id]=!0,this.onExecute(a,b),this.graph.nodes_executing[this.id]=!1,this.exec_version=this.graph.iteration,b&&b.action_call&&(this.action_call=b.action_call,this.graph.nodes_executedAction[this.id]=b.action_call));this.execute_triggered=2;if(this.onAfterExecuteNode)this.onAfterExecuteNode(a,b)};l.prototype.actionDo=function(a,b,c){c=c||{};this.onAction&&(c.action_call||(c.action_call=this.id+"_"+(a?a:"action")+
|
||||
"_"+Math.floor(9999*Math.random())),this.graph.nodes_actioning[this.id]=a?a:"actioning",this.onAction(a,b,c),this.graph.nodes_actioning[this.id]=!1,c&&c.action_call&&(this.action_call=c.action_call,this.graph.nodes_executedAction[this.id]=c.action_call));this.action_triggered=2;if(this.onAfterExecuteNode)this.onAfterExecuteNode(b,c)};l.prototype.trigger=function(a,b,c){if(this.outputs&&this.outputs.length){this.graph&&(this.graph._last_trigger_time=f.getTime());for(var d=0;d<this.outputs.length;++d){var e=
|
||||
this.outputs[d];!e||e.type!==f.EVENT||a&&e.name!=a||this.triggerSlot(d,b,null,c)}}};l.prototype.triggerSlot=function(a,b,c,d){d=d||{};if(this.outputs&&(a=this.outputs[a])&&(a=a.links)&&a.length){this.graph&&(this.graph._last_trigger_time=f.getTime());for(var e=0;e<a.length;++e){var g=a[e];if(null==c||c==g){var k=this.graph.links[a[e]];k&&(k._last_time=f.getTime(),g=this.graph.getNodeById(k.target_id))&&(g.mode===f.ON_TRIGGER?(d.action_call||(d.action_call=this.id+"_trigg_"+Math.floor(9999*Math.random())),
|
||||
g.onExecute&&g.doExecute(b,d)):g.onAction&&(d.action_call||(d.action_call=this.id+"_act_"+Math.floor(9999*Math.random())),k=g.inputs[k.target_slot],g.actionDo(k.name,b,d)))}}}};l.prototype.clearTriggeredSlot=function(a,b){if(this.outputs&&(a=this.outputs[a])&&(a=a.links)&&a.length)for(var c=0;c<a.length;++c){var d=a[c];if(null==b||b==d)if(d=this.graph.links[a[c]])d._last_time=0}};l.prototype.setSize=function(a){this.size=a;if(this.onResize)this.onResize(this.size)};l.prototype.addProperty=function(a,
|
||||
b,c,d){c={name:a,type:c,default_value:b};if(d)for(var e in d)c[e]=d[e];this.properties_info||(this.properties_info=[]);this.properties_info.push(c);this.properties||(this.properties={});this.properties[a]=b;return c};l.prototype.addOutput=function(a,b,c){a={name:a,type:b,links:null};if(c)for(var d in c)a[d]=c[d];this.outputs||(this.outputs=[]);this.outputs.push(a);if(this.onOutputAdded)this.onOutputAdded(a);f.auto_load_slot_types&&f.registerNodeAndSlotType(this,b,!0);this.setSize(this.computeSize());
|
||||
this.setDirtyCanvas(!0,!0);return a};l.prototype.addOutputs=function(a){for(var b=0;b<a.length;++b){var c=a[b],d={name:c[0],type:c[1],link:null};if(a[2])for(var e in c[2])d[e]=c[2][e];this.outputs||(this.outputs=[]);this.outputs.push(d);if(this.onOutputAdded)this.onOutputAdded(d);f.auto_load_slot_types&&f.registerNodeAndSlotType(this,c[1],!0)}this.setSize(this.computeSize());this.setDirtyCanvas(!0,!0)};l.prototype.removeOutput=function(a){this.disconnectOutput(a);this.outputs.splice(a,1);for(var b=
|
||||
a;b<this.outputs.length;++b)if(this.outputs[b]&&this.outputs[b].links)for(var c=this.outputs[b].links,d=0;d<c.length;++d){var e=this.graph.links[c[d]];e&&--e.origin_slot}this.setSize(this.computeSize());if(this.onOutputRemoved)this.onOutputRemoved(a);this.setDirtyCanvas(!0,!0)};l.prototype.addInput=function(a,b,c){b=b||0;a={name:a,type:b,link:null};if(c)for(var d in c)a[d]=c[d];this.inputs||(this.inputs=[]);this.inputs.push(a);this.setSize(this.computeSize());if(this.onInputAdded)this.onInputAdded(a);
|
||||
f.registerNodeAndSlotType(this,b);this.setDirtyCanvas(!0,!0);return a};l.prototype.addInputs=function(a){for(var b=0;b<a.length;++b){var c=a[b],d={name:c[0],type:c[1],link:null};if(a[2])for(var e in c[2])d[e]=c[2][e];this.inputs||(this.inputs=[]);this.inputs.push(d);if(this.onInputAdded)this.onInputAdded(d);f.registerNodeAndSlotType(this,c[1])}this.setSize(this.computeSize());this.setDirtyCanvas(!0,!0)};l.prototype.removeInput=function(a){this.disconnectInput(a);for(var b=this.inputs.splice(a,1),
|
||||
c=a;c<this.inputs.length;++c)if(this.inputs[c]){var d=this.graph.links[this.inputs[c].link];d&&--d.target_slot}this.setSize(this.computeSize());if(this.onInputRemoved)this.onInputRemoved(a,b[0]);this.setDirtyCanvas(!0,!0)};l.prototype.addConnection=function(a,b,c,d){a={name:a,type:b,pos:c,direction:d,links:null};this.connections.push(a);return a};l.prototype.computeSize=function(a){function b(a){return a?d*a.length*.6:0}if(this.constructor.size)return this.constructor.size.concat();var c=Math.max(this.inputs?
|
||||
this.inputs.length:1,this.outputs?this.outputs.length:1);a=a||new Float32Array([0,0]);c=Math.max(c,1);var d=f.NODE_TEXT_SIZE,e=b(this.title),g=0,k=0;if(this.inputs)for(var n=0,p=this.inputs.length;n<p;++n){var r=this.inputs[n];r=r.label||r.name||"";r=b(r);g<r&&(g=r)}if(this.outputs)for(n=0,p=this.outputs.length;n<p;++n)r=this.outputs[n],r=r.label||r.name||"",r=b(r),k<r&&(k=r);a[0]=Math.max(g+k+10,e);a[0]=Math.max(a[0],f.NODE_WIDTH);this.widgets&&this.widgets.length&&(a[0]=Math.max(a[0],1.5*f.NODE_WIDTH));
|
||||
a[1]=(this.constructor.slot_start_y||0)+c*f.NODE_SLOT_HEIGHT;c=0;if(this.widgets&&this.widgets.length){n=0;for(p=this.widgets.length;n<p;++n)c=this.widgets[n].computeSize?c+(this.widgets[n].computeSize(a[0])[1]+4):c+(f.NODE_WIDGET_HEIGHT+4);c+=8}a[1]=this.widgets_up?Math.max(a[1],c):null!=this.widgets_start_y?Math.max(a[1],c+this.widgets_start_y):a[1]+c;this.constructor.min_height&&a[1]<this.constructor.min_height&&(a[1]=this.constructor.min_height);a[1]+=6;return a};l.prototype.getPropertyInfo=function(a){var b=
|
||||
null;if(this.properties_info)for(var c=0;c<this.properties_info.length;++c)if(this.properties_info[c].name==a){b=this.properties_info[c];break}this.constructor["@"+a]&&(b=this.constructor["@"+a]);this.constructor.widgets_info&&this.constructor.widgets_info[a]&&(b=this.constructor.widgets_info[a]);!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};l.prototype.addWidget=function(a,b,c,d,e){this.widgets||
|
||||
(this.widgets=[]);!e&&d&&d.constructor===Object&&(e=d,d=null);e&&e.constructor===String&&(e={property:e});d&&d.constructor===String&&(e||(e={}),e.property=d,d=null);d&&d.constructor!==Function&&(console.warn("addWidget: callback must be a function"),d=null);b={type:a.toLowerCase(),name:b,value:c,callback:d,options:e||{}};void 0!==b.options.y&&(b.y=b.options.y);d||b.options.callback||b.options.property||console.warn("LiteGraph addWidget(...) without a callback or property assigned");if("combo"==a&&
|
||||
!b.options.values)throw"LiteGraph addWidget('combo',...) requires to pass values in options: { values:['red','blue'] }";this.widgets.push(b);this.setSize(this.computeSize());return b};l.prototype.addCustomWidget=function(a){this.widgets||(this.widgets=[]);this.widgets.push(a);return a};l.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};l.prototype.isPointInside=function(a,b,c,d){c=c||0;var e=this.graph&&this.graph.isLive()?0:f.NODE_TITLE_HEIGHT;d&&(e=0);if(this.flags&&this.flags.collapsed){if(C(a,b,this.pos[0]-c,this.pos[1]-f.NODE_TITLE_HEIGHT-c,(this._collapsed_width||f.NODE_COLLAPSED_WIDTH)+2*c,f.NODE_TITLE_HEIGHT+2*c))return!0}else if(this.pos[0]-4-c<a&&this.pos[0]+this.size[0]+4+c>a&&this.pos[1]-e-c<b&&this.pos[1]+this.size[1]+c>b)return!0;return!1};l.prototype.getSlotInPosition=
|
||||
function(a,b){var c=new Float32Array(2);if(this.inputs)for(var d=0,e=this.inputs.length;d<e;++d){var g=this.inputs[d];this.getConnectionPos(!0,d,c);if(C(a,b,c[0]-10,c[1]-5,20,10))return{input:g,slot:d,link_pos:c}}if(this.outputs)for(d=0,e=this.outputs.length;d<e;++d)if(g=this.outputs[d],this.getConnectionPos(!1,d,c),C(a,b,c[0]-10,c[1]-5,20,10))return{output:g,slot:d,link_pos:c};return null};l.prototype.findInputSlot=function(a,b){if(!this.inputs)return-1;for(var c=0,d=this.inputs.length;c<d;++c)if(a==
|
||||
this.inputs[c].name)return b?this.inputs[c]:c;return-1};l.prototype.findOutputSlot=function(a,b){b=b||!1;if(!this.outputs)return-1;for(var c=0,d=this.outputs.length;c<d;++c)if(a==this.outputs[c].name)return b?this.outputs[c]:c;return-1};l.prototype.findInputSlotFree=function(a){a=a||{};a=Object.assign({returnObj:!1,typesNotAccepted:[]},a);if(!this.inputs)return-1;for(var b=0,c=this.inputs.length;b<c;++b)if(!(this.inputs[b].link&&null!=this.inputs[b].link||a.typesNotAccepted&&a.typesNotAccepted.includes&&
|
||||
a.typesNotAccepted.includes(this.inputs[b].type)))return a.returnObj?this.inputs[b]:b;return-1};l.prototype.findOutputSlotFree=function(a){a=a||{};a=Object.assign({returnObj:!1,typesNotAccepted:[]},a);if(!this.outputs)return-1;for(var b=0,c=this.outputs.length;b<c;++b)if(!(this.outputs[b].links&&null!=this.outputs[b].links||a.typesNotAccepted&&a.typesNotAccepted.includes&&a.typesNotAccepted.includes(this.outputs[b].type)))return a.returnObj?this.outputs[b]:b;return-1};l.prototype.findInputSlotByType=
|
||||
function(a,b,c,d){return this.findSlotByType(!0,a,b,c,d)};l.prototype.findOutputSlotByType=function(a,b,c,d){return this.findSlotByType(!1,a,b,c,d)};l.prototype.findSlotByType=function(a,b,c,d,e){c=c||!1;d=d||!1;e=e||!1;a=a?this.inputs:this.outputs;if(!a)return-1;if(""==b||"*"==b)b=0;for(var g=0,k=a.length;g<k;++g){var n=(b+"").toLowerCase().split(","),p="0"==a[g].type||"*"==a[g].type?"0":a[g].type;p=(p+"").toLowerCase().split(",");for(sI=0;sI<n.length;sI++)for(dI=0;dI<p.length;dI++)if("_event_"==
|
||||
n[sI]&&(n[sI]=f.EVENT),"_event_"==p[sI]&&(p[sI]=f.EVENT),"*"==n[sI]&&(n[sI]=0),"*"==p[sI]&&(p[sI]=0),!(n[sI]!=p[dI]||d&&a[g].links&&null!==a[g].links))return c?a[g]:g}if(d&&!e)for(g=0,k=a.length;g<k;++g)for(n=(b+"").toLowerCase().split(","),p="0"==a[g].type||"*"==a[g].type?"0":a[g].type,p=(p+"").toLowerCase().split(","),sI=0;sI<n.length;sI++)for(dI=0;dI<p.length;dI++)if("*"==n[sI]&&(n[sI]=0),"*"==p[sI]&&(p[sI]=0),n[sI]==p[dI])return c?a[g]:g;return-1};l.prototype.connectByType=function(a,b,c,d){d=
|
||||
d||{};d=Object.assign({createEventInCase:!0,firstFreeIfOutputGeneralInCase:!0,generalTypeInCase:!0},d);b&&b.constructor===Number&&(b=this.graph.getNodeById(b));e=b.findInputSlotByType(c,!1,!0);if(0<=e&&null!==e)return this.connect(a,b,e);if(d.createEventInCase&&c==f.EVENT)return this.connect(a,b,-1);if(d.generalTypeInCase){var e=b.findInputSlotByType(0,!1,!0,!0);if(0<=e)return this.connect(a,b,e)}if(d.firstFreeIfOutputGeneralInCase&&(0==c||"*"==c||""==c)&&(e=b.findInputSlotFree({typesNotAccepted:[f.EVENT]}),
|
||||
0<=e))return this.connect(a,b,e);console.debug("no way to connect type: ",c," to targetNODE ",b);return null};l.prototype.connectByTypeOutput=function(a,b,c,d){d=d||{};d=Object.assign({createEventInCase:!0,firstFreeIfInputGeneralInCase:!0,generalTypeInCase:!0},d);b&&b.constructor===Number&&(b=this.graph.getNodeById(b));e=b.findOutputSlotByType(c,!1,!0);if(0<=e&&null!==e)return b.connect(e,this,a);if(d.generalTypeInCase){var e=b.findOutputSlotByType(0,!1,!0,!0);if(0<=e)return b.connect(e,this,a)}if(d.createEventInCase&&
|
||||
c==f.EVENT&&f.do_add_triggers_slots)return e=b.addOnExecutedOutput(),b.connect(e,this,a);if(d.firstFreeIfInputGeneralInCase&&(0==c||"*"==c||""==c)&&(e=b.findOutputSlotFree({typesNotAccepted:[f.EVENT]}),0<=e))return b.connect(e,this,a);console.debug("no way to connect byOUT type: ",c," to sourceNODE ",b);return null};l.prototype.connect=function(a,b,c){c=c||0;if(!this.graph)return console.log("Connect: Error, node doesn't belong to any graph. Nodes must be added first to a graph before connecting them."),
|
||||
null;if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return 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(c.constructor===String){if(c=b.findInputSlot(c),-1==c)return f.debug&&console.log("Connect: Error, no slot of name "+c),null}else if(c===
|
||||
f.EVENT)if(f.do_add_triggers_slots)b.changeMode(f.ON_TRIGGER),c=b.findInputSlot("onTrigger");else return null;else if(!b.inputs||c>=b.inputs.length)return f.debug&&console.log("Connect: Error, slot number not found"),null;var d=b.inputs[c],e=this.outputs[a];if(!this.outputs[a])return null;b.onBeforeConnectInput&&(c=b.onBeforeConnectInput(c));if(!1===c||null===c||!f.isValidConnection(e.type,d.type))return this.setDirtyCanvas(!1,!0),null;if(b.onConnectInput&&!1===b.onConnectInput(c,e.type,e,this,a)||
|
||||
this.onConnectOutput&&!1===this.onConnectOutput(a,d.type,d,b,c))return null;b.inputs[c]&&null!=b.inputs[c].link&&(this.graph.beforeChange(),b.disconnectInput(c,{doProcessChange:!1}));if(null!==e.links&&e.links.length)switch(e.type){case f.EVENT:f.allow_multi_output_for_events||(this.graph.beforeChange(),this.disconnectOutput(a,!1,{doProcessChange:!1}))}var g=new t(++this.graph.last_link_id,d.type||e.type,this.id,a,b.id,c);this.graph.links[g.id]=g;null==e.links&&(e.links=[]);e.links.push(g.id);b.inputs[c].link=
|
||||
g.id;this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(f.OUTPUT,a,!0,g,e);if(b.onConnectionsChange)b.onConnectionsChange(f.INPUT,c,!0,g,d);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(f.INPUT,b,c,this,a),this.graph.onNodeConnectionChange(f.OUTPUT,this,a,b,c));this.setDirtyCanvas(!1,!0);this.graph.afterChange();this.graph.connectionChange(this,g);return g};l.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 c=this.outputs[a];if(!c||!c.links||0==c.links.length)return!1;if(b){b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"Target Node not found";for(var d=0,e=c.links.length;d<e;d++){var g=c.links[d],k=this.graph.links[g];if(k.target_id==b.id){c.links.splice(d,1);var n=
|
||||
b.inputs[k.target_slot];n.link=null;delete this.graph.links[g];this.graph&&this.graph._version++;if(b.onConnectionsChange)b.onConnectionsChange(f.INPUT,k.target_slot,!1,k,n);if(this.onConnectionsChange)this.onConnectionsChange(f.OUTPUT,a,!1,k,c);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,k.target_slot));
|
||||
break}}}else{d=0;for(e=c.links.length;d<e;d++)if(g=c.links[d],k=this.graph.links[g]){b=this.graph.getNodeById(k.target_id);this.graph&&this.graph._version++;if(b){n=b.inputs[k.target_slot];n.link=null;if(b.onConnectionsChange)b.onConnectionsChange(f.INPUT,k.target_slot,!1,k,n);if(this.graph&&this.graph.onNodeConnectionChange)this.graph.onNodeConnectionChange(f.INPUT,b,k.target_slot)}delete this.graph.links[g];if(this.onConnectionsChange)this.onConnectionsChange(f.OUTPUT,a,!1,k,c);this.graph&&this.graph.onNodeConnectionChange&&
|
||||
(this.graph.onNodeConnectionChange(f.OUTPUT,this,a),this.graph.onNodeConnectionChange(f.INPUT,b,k.target_slot))}c.links=null}this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this);return!0};l.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 c=this.inputs[a].link;if(null!=c){this.inputs[a].link=null;var d=this.graph.links[c];if(d){var e=this.graph.getNodeById(d.origin_id);if(!e)return!1;var g=e.outputs[d.origin_slot];if(!g||!g.links||0==g.links.length)return!1;for(var k=0,n=g.links.length;k<n;k++)if(g.links[k]==c){g.links.splice(k,1);break}delete this.graph.links[c];this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(f.INPUT,a,!1,d,b);if(e.onConnectionsChange)e.onConnectionsChange(f.OUTPUT,
|
||||
k,!1,d,g);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(f.OUTPUT,e,k),this.graph.onNodeConnectionChange(f.INPUT,this,a))}}this.setDirtyCanvas(!1,!0);this.graph&&this.graph.connectionChange(this);return!0};l.prototype.getConnectionPos=function(a,b,c){c=c||new Float32Array(2);var d=0;a&&this.inputs&&(d=this.inputs.length);!a&&this.outputs&&(d=this.outputs.length);var e=.5*f.NODE_SLOT_HEIGHT;if(this.flags.collapsed)return b=this._collapsed_width||f.NODE_COLLAPSED_WIDTH,
|
||||
this.horizontal?(c[0]=this.pos[0]+.5*b,c[1]=a?this.pos[1]-f.NODE_TITLE_HEIGHT:this.pos[1]):(c[0]=a?this.pos[0]:this.pos[0]+b,c[1]=this.pos[1]-.5*f.NODE_TITLE_HEIGHT),c;if(a&&-1==b)return c[0]=this.pos[0]+.5*f.NODE_TITLE_HEIGHT,c[1]=this.pos[1]+.5*f.NODE_TITLE_HEIGHT,c;if(a&&d>b&&this.inputs[b].pos)return c[0]=this.pos[0]+this.inputs[b].pos[0],c[1]=this.pos[1]+this.inputs[b].pos[1],c;if(!a&&d>b&&this.outputs[b].pos)return c[0]=this.pos[0]+this.outputs[b].pos[0],c[1]=this.pos[1]+this.outputs[b].pos[1],
|
||||
c;if(this.horizontal)return c[0]=this.pos[0]+this.size[0]/d*(b+.5),c[1]=a?this.pos[1]-f.NODE_TITLE_HEIGHT:this.pos[1]+this.size[1],c;c[0]=a?this.pos[0]+e:this.pos[0]+this.size[0]+1-e;c[1]=this.pos[1]+(b+.7)*f.NODE_SLOT_HEIGHT+(this.constructor.slot_start_y||0);return c};l.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)};l.prototype.trace=function(a){this.console||(this.console=
|
||||
[]);this.console.push(a);this.console.length>l.MAX_CONSOLE&&this.console.shift();if(this.graph.onNodeTrace)this.graph.onNodeTrace(this,a)};l.prototype.setDirtyCanvas=function(a,b){this.graph&&this.graph.sendActionToCanvas("setDirty",[a,b])};l.prototype.loadImage=function(a){var b=new Image;b.src=f.node_images_path+a;b.ready=!1;var c=this;b.onload=function(){this.ready=!0;c.setDirtyCanvas(!0)};return b};l.prototype.captureInput=function(a){if(this.graph&&this.graph.list_of_graphcanvas)for(var b=this.graph.list_of_graphcanvas,
|
||||
c=0;c<b.length;++c){var d=b[c];if(a||d.node_capturing_input==this)d.node_capturing_input=a?this:null}};l.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)};l.prototype.pin=function(a){this.graph._version++;this.flags.pinned=void 0===a?!this.flags.pinned:a};l.prototype.localToScreen=function(a,b,c){return[(a+this.pos[0])*c.scale+c.offset[0],(b+this.pos[1])*c.scale+c.offset[1]]};x.LGraphGroup=
|
||||
f.LGraphGroup=w;w.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})};w.prototype.configure=function(a){this.title=a.title;this._bounding.set(a.bounding);this.color=a.color;this.font=a.font};w.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}};w.prototype.move=function(a,b,
|
||||
c){this._pos[0]+=a;this._pos[1]+=b;if(!c)for(c=0;c<this._nodes.length;++c){var d=this._nodes[c];d.pos[0]+=a;d.pos[1]+=b}};w.prototype.recomputeInsideNodes=function(){this._nodes.length=0;for(var a=this.graph._nodes,b=new Float32Array(4),c=0;c<a.length;++c){var d=a[c];d.getBounding(b);A(this._bounding,b)&&this._nodes.push(d)}};w.prototype.isPointInside=l.prototype.isPointInside;w.prototype.setDirtyCanvas=l.prototype.setDirtyCanvas;f.DragAndScale=z;z.prototype.bindEvents=function(a){this.last_mouse=
|
||||
new Float32Array(2);this._binded_mouse_callback=this.onMouse.bind(this);f.pointerListenerAdd(a,"down",this._binded_mouse_callback);f.pointerListenerAdd(a,"move",this._binded_mouse_callback);f.pointerListenerAdd(a,"up",this._binded_mouse_callback);a.addEventListener("mousewheel",this._binded_mouse_callback,!1);a.addEventListener("wheel",this._binded_mouse_callback,!1)};z.prototype.computeVisibleArea=function(a){if(this.element){var b=this.element.width,c=this.element.height,d=-this.offset[0],e=-this.offset[1];
|
||||
a&&(d+=a[0]/this.scale,e+=a[1]/this.scale,b=a[2],c=a[3]);a=d+b/this.scale;c=e+c/this.scale;this.visible_area[0]=d;this.visible_area[1]=e;this.visible_area[2]=a-d;this.visible_area[3]=c-e}else this.visible_area[0]=this.visible_area[1]=this.visible_area[2]=this.visible_area[3]=0};z.prototype.onMouse=function(a){if(this.enabled){var b=this.element,c=b.getBoundingClientRect(),d=a.clientX-c.left;c=a.clientY-c.top;a.canvasx=d;a.canvasy=c;a.dragging=this.dragging;var e=!this.viewport||this.viewport&&d>=
|
||||
this.viewport[0]&&d<this.viewport[0]+this.viewport[2]&&c>=this.viewport[1]&&c<this.viewport[1]+this.viewport[3],g=!1;this.onmouse&&(g=this.onmouse(a));a.type==f.pointerevents_method+"down"&&e?(this.dragging=!0,f.pointerListenerRemove(b,"move",this._binded_mouse_callback),f.pointerListenerAdd(document,"move",this._binded_mouse_callback),f.pointerListenerAdd(document,"up",this._binded_mouse_callback)):a.type==f.pointerevents_method+"move"?g||(b=d-this.last_mouse[0],g=c-this.last_mouse[1],this.dragging&&
|
||||
this.mouseDrag(b,g)):a.type==f.pointerevents_method+"up"?(this.dragging=!1,f.pointerListenerRemove(document,"move",this._binded_mouse_callback),f.pointerListenerRemove(document,"up",this._binded_mouse_callback),f.pointerListenerAdd(b,"move",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+.05*a.delta));this.last_mouse[0]=d;this.last_mouse[1]=c;if(e)return a.preventDefault(),a.stopPropagation(),!1}};z.prototype.toCanvasContext=function(a){a.scale(this.scale,this.scale);a.translate(this.offset[0],this.offset[1])};z.prototype.convertOffsetToCanvas=function(a){return[(a[0]+this.offset[0])*this.scale,(a[1]+this.offset[1])*this.scale]};z.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};z.prototype.mouseDrag=function(a,b){this.offset[0]+=a/this.scale;this.offset[1]+=b/this.scale;if(this.onredraw)this.onredraw(this)};z.prototype.changeScale=function(a,b){a<this.min_scale?a=this.min_scale:a>this.max_scale&&(a=this.max_scale);if(a!=this.scale&&this.element){var c=this.element.getBoundingClientRect();if(c&&(b=b||[.5*c.width,.5*c.height],c=this.convertCanvasToOffset(b),this.scale=a,.01>Math.abs(this.scale-1)&&(this.scale=1),a=this.convertCanvasToOffset(b),a=[a[0]-c[0],a[1]-
|
||||
c[1]],this.offset[0]+=a[0],this.offset[1]+=a[1],this.onredraw))this.onredraw(this)}};z.prototype.changeDeltaScale=function(a,b){this.changeScale(this.scale*a,b)};z.prototype.reset=function(){this.scale=1;this.offset[0]=0;this.offset[1]=0};x.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.pointer_is_double=this.pointer_is_down=!1;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]));this.ds.offset=
|
||||
[0,0];this.ds.scale=1}};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());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);this._mousemove_callback=this.processMouseMove.bind(this);this._mouseup_callback=this.processMouseUp.bind(this);f.pointerListenerAdd(a,"down",this._mousedown_callback,!0);a.addEventListener("mousewheel",this._mousewheel_callback,
|
||||
for(var b in a)if("properties"==b)for(var c in a.properties){if(this.properties[c]=a.properties[c],this.onPropertyChanged)this.onPropertyChanged(c,a.properties[c])}else null!=a[b]&&("object"==typeof a[b]?this[b]&&this[b].configure?this[b].configure(a[b]):this[b]=f.cloneObject(a[b],this[b]):this[b]=a[b]);a.title||(this.title=this.constructor.title);if(this.inputs)for(c=0;c<this.inputs.length;++c){b=this.inputs[c];var d=this.graph?this.graph.links[b.link]:null;if(this.onConnectionsChange)this.onConnectionsChange(f.INPUT,
|
||||
c,!0,d,b);if(this.onInputAdded)this.onInputAdded(b)}if(this.outputs)for(c=0;c<this.outputs.length;++c){var e=this.outputs[c];if(e.links){for(b=0;b<e.links.length;++b)if(d=this.graph?this.graph.links[e.links[b]]:null,this.onConnectionsChange)this.onConnectionsChange(f.OUTPUT,c,!0,d,e);if(this.onOutputAdded)this.onOutputAdded(e)}}if(this.widgets){for(c=0;c<this.widgets.length;++c)(b=this.widgets[c])&&b.options&&b.options.property&&this.properties[b.options.property]&&(b.value=JSON.parse(JSON.stringify(this.properties[b.options.property])));
|
||||
if(a.widgets_values)for(c=0;c<a.widgets_values.length;++c)this.widgets[c]&&(this.widgets[c].value=a.widgets_values[c])}if(this.onConfigure)this.onConfigure(a)};l.prototype.serialize=function(){var a={id:this.id,type:this.type,pos:this.pos,size:this.size,flags:f.cloneObject(this.flags),order:this.order,mode:this.mode};if(this.constructor===l&&this.last_serialization)return this.last_serialization;this.inputs&&(a.inputs=this.inputs);if(this.outputs){for(var b=0;b<this.outputs.length;b++)delete this.outputs[b]._data;
|
||||
a.outputs=this.outputs}this.title&&this.title!=this.constructor.title&&(a.title=this.title);this.properties&&(a.properties=f.cloneObject(this.properties));if(this.widgets&&this.serialize_widgets)for(a.widgets_values=[],b=0;b<this.widgets.length;++b)a.widgets_values[b]=this.widgets[b]?this.widgets[b].value:null;a.type||(a.type=this.constructor.type);this.color&&(a.color=this.color);this.bgcolor&&(a.bgcolor=this.bgcolor);this.boxcolor&&(a.boxcolor=this.boxcolor);this.shape&&(a.shape=this.shape);this.onSerialize&&
|
||||
this.onSerialize(a)&&console.warn("node onSerialize shouldnt return anything, data should be stored in the object pass in the first parameter");return a};l.prototype.clone=function(){var a=f.createNode(this.type);if(!a)return null;var b=f.cloneObject(this.serialize());if(b.inputs)for(var c=0;c<b.inputs.length;++c)b.inputs[c].link=null;if(b.outputs)for(c=0;c<b.outputs.length;++c)b.outputs[c].links&&(b.outputs[c].links.length=0);delete b.id;a.configure(b);return a};l.prototype.toString=function(){return JSON.stringify(this.serialize())};
|
||||
l.prototype.getTitle=function(){return this.title||this.constructor.title};l.prototype.setProperty=function(a,b){this.properties||(this.properties={});if(b!==this.properties[a]){var c=this.properties[a];this.properties[a]=b;this.onPropertyChanged&&!1===this.onPropertyChanged(a,b,c)&&(this.properties[a]=c);if(this.widgets)for(c=0;c<this.widgets.length;++c){var d=this.widgets[c];if(d&&d.options.property==a){d.value=b;break}}}};l.prototype.setOutputData=function(a,b){if(this.outputs&&!(-1==a||a>=this.outputs.length)){var c=
|
||||
this.outputs[a];if(c&&(c._data=b,this.outputs[a].links))for(c=0;c<this.outputs[a].links.length;c++){var d=this.graph.links[this.outputs[a].links[c]];d&&(d.data=b)}}};l.prototype.setOutputDataType=function(a,b){if(this.outputs&&!(-1==a||a>=this.outputs.length)){var c=this.outputs[a];if(c&&(c.type=b,this.outputs[a].links))for(c=0;c<this.outputs[a].links.length;c++)this.graph.links[this.outputs[a].links[c]].type=b}};l.prototype.getInputData=function(a,b){if(this.inputs&&!(a>=this.inputs.length||null==
|
||||
this.inputs[a].link)){a=this.graph.links[this.inputs[a].link];if(!a)return null;if(!b)return a.data;b=this.graph.getNodeById(a.origin_id);if(!b)return a.data;if(b.updateOutputData)b.updateOutputData(a.origin_slot);else if(b.onExecute)b.onExecute();return a.data}};l.prototype.getInputDataType=function(a){if(!this.inputs||a>=this.inputs.length||null==this.inputs[a].link)return null;a=this.graph.links[this.inputs[a].link];if(!a)return null;var b=this.graph.getNodeById(a.origin_id);return b?(a=b.outputs[a.origin_slot])?
|
||||
a.type:null:a.type};l.prototype.getInputDataByName=function(a,b){a=this.findInputSlot(a);return-1==a?null:this.getInputData(a,b)};l.prototype.isInputConnected=function(a){return this.inputs?a<this.inputs.length&&null!=this.inputs[a].link:!1};l.prototype.getInputInfo=function(a){return this.inputs?a<this.inputs.length?this.inputs[a]:null:null};l.prototype.getInputLink=function(a){return this.inputs?a<this.inputs.length?this.graph.links[this.inputs[a].link]:null:null};l.prototype.getInputNode=function(a){if(!this.inputs||
|
||||
a>=this.inputs.length)return null;a=this.inputs[a];return a&&null!==a.link?(a=this.graph.links[a.link])?this.graph.getNodeById(a.origin_id):null:null};l.prototype.getInputOrProperty=function(a){if(!this.inputs||!this.inputs.length)return this.properties?this.properties[a]:null;for(var b=0,c=this.inputs.length;b<c;++b){var d=this.inputs[b];if(a==d.name&&null!=d.link&&(d=this.graph.links[d.link]))return d.data}return this.properties[a]};l.prototype.getOutputData=function(a){return!this.outputs||a>=
|
||||
this.outputs.length?null:this.outputs[a]._data};l.prototype.getOutputInfo=function(a){return this.outputs?a<this.outputs.length?this.outputs[a]:null:null};l.prototype.isOutputConnected=function(a){return this.outputs?a<this.outputs.length&&this.outputs[a].links&&this.outputs[a].links.length:!1};l.prototype.isAnyOutputConnected=function(){if(!this.outputs)return!1;for(var a=0;a<this.outputs.length;++a)if(this.outputs[a].links&&this.outputs[a].links.length)return!0;return!1};l.prototype.getOutputNodes=
|
||||
function(a){if(!this.outputs||0==this.outputs.length||a>=this.outputs.length)return null;a=this.outputs[a];if(!a.links||0==a.links.length)return null;for(var b=[],c=0;c<a.links.length;c++){var d=this.graph.links[a.links[c]];d&&(d=this.graph.getNodeById(d.target_id))&&b.push(d)}return b};l.prototype.addOnTriggerInput=function(){var a=this.findInputSlot("onTrigger");return-1==a?(this.addInput("onTrigger",f.EVENT,{optional:!0,nameLocked:!0}),this.findInputSlot("onTrigger")):a};l.prototype.addOnExecutedOutput=
|
||||
function(){var a=this.findOutputSlot("onExecuted");return-1==a?(this.addOutput("onExecuted",f.ACTION,{optional:!0,nameLocked:!0}),this.findOutputSlot("onExecuted")):a};l.prototype.onAfterExecuteNode=function(a,b){var c=this.findOutputSlot("onExecuted");-1!=c&&this.triggerSlot(c,a,null,b)};l.prototype.changeMode=function(a){switch(a){case f.ON_EVENT:break;case f.ON_TRIGGER:this.addOnTriggerInput();this.addOnExecutedOutput();break;case f.NEVER:break;case f.ALWAYS:break;case f.ON_REQUEST:break;default:return!1}this.mode=
|
||||
a;return!0};l.prototype.doExecute=function(a,b){b=b||{};this.onExecute&&(b.action_call||(b.action_call=this.id+"_exec_"+Math.floor(9999*Math.random())),this.graph.nodes_executing[this.id]=!0,this.onExecute(a,b),this.graph.nodes_executing[this.id]=!1,this.exec_version=this.graph.iteration,b&&b.action_call&&(this.action_call=b.action_call,this.graph.nodes_executedAction[this.id]=b.action_call));this.execute_triggered=2;if(this.onAfterExecuteNode)this.onAfterExecuteNode(a,b)};l.prototype.actionDo=function(a,
|
||||
b,c){c=c||{};this.onAction&&(c.action_call||(c.action_call=this.id+"_"+(a?a:"action")+"_"+Math.floor(9999*Math.random())),this.graph.nodes_actioning[this.id]=a?a:"actioning",this.onAction(a,b,c),this.graph.nodes_actioning[this.id]=!1,c&&c.action_call&&(this.action_call=c.action_call,this.graph.nodes_executedAction[this.id]=c.action_call));this.action_triggered=2;if(this.onAfterExecuteNode)this.onAfterExecuteNode(b,c)};l.prototype.trigger=function(a,b,c){if(this.outputs&&this.outputs.length){this.graph&&
|
||||
(this.graph._last_trigger_time=f.getTime());for(var d=0;d<this.outputs.length;++d){var e=this.outputs[d];!e||e.type!==f.EVENT||a&&e.name!=a||this.triggerSlot(d,b,null,c)}}};l.prototype.triggerSlot=function(a,b,c,d){d=d||{};if(this.outputs)if(null==a)console.error("slot must be a number");else if(a.constructor!==Number&&console.warn("slot must be a number, use node.trigger('name') if you want to use a string"),(a=this.outputs[a])&&(a=a.links)&&a.length){this.graph&&(this.graph._last_trigger_time=f.getTime());
|
||||
for(var e=0;e<a.length;++e){var g=a[e];if(null==c||c==g){var h=this.graph.links[a[e]];h&&(h._last_time=f.getTime(),g=this.graph.getNodeById(h.target_id))&&(g.mode===f.ON_TRIGGER?(d.action_call||(d.action_call=this.id+"_trigg_"+Math.floor(9999*Math.random())),g.onExecute&&g.doExecute(b,d)):g.onAction&&(d.action_call||(d.action_call=this.id+"_act_"+Math.floor(9999*Math.random())),h=g.inputs[h.target_slot],g.actionDo(h.name,b,d)))}}}};l.prototype.clearTriggeredSlot=function(a,b){if(this.outputs&&(a=
|
||||
this.outputs[a])&&(a=a.links)&&a.length)for(var c=0;c<a.length;++c){var d=a[c];if(null==b||b==d)if(d=this.graph.links[a[c]])d._last_time=0}};l.prototype.setSize=function(a){this.size=a;if(this.onResize)this.onResize(this.size)};l.prototype.addProperty=function(a,b,c,d){c={name:a,type:c,default_value:b};if(d)for(var e in d)c[e]=d[e];this.properties_info||(this.properties_info=[]);this.properties_info.push(c);this.properties||(this.properties={});this.properties[a]=b;return c};l.prototype.addOutput=
|
||||
function(a,b,c){a={name:a,type:b,links:null};if(c)for(var d in c)a[d]=c[d];this.outputs||(this.outputs=[]);this.outputs.push(a);if(this.onOutputAdded)this.onOutputAdded(a);f.auto_load_slot_types&&f.registerNodeAndSlotType(this,b,!0);this.setSize(this.computeSize());this.setDirtyCanvas(!0,!0);return a};l.prototype.addOutputs=function(a){for(var b=0;b<a.length;++b){var c=a[b],d={name:c[0],type:c[1],link:null};if(a[2])for(var e in c[2])d[e]=c[2][e];this.outputs||(this.outputs=[]);this.outputs.push(d);
|
||||
if(this.onOutputAdded)this.onOutputAdded(d);f.auto_load_slot_types&&f.registerNodeAndSlotType(this,c[1],!0)}this.setSize(this.computeSize());this.setDirtyCanvas(!0,!0)};l.prototype.removeOutput=function(a){this.disconnectOutput(a);this.outputs.splice(a,1);for(var b=a;b<this.outputs.length;++b)if(this.outputs[b]&&this.outputs[b].links)for(var c=this.outputs[b].links,d=0;d<c.length;++d){var e=this.graph.links[c[d]];e&&--e.origin_slot}this.setSize(this.computeSize());if(this.onOutputRemoved)this.onOutputRemoved(a);
|
||||
this.setDirtyCanvas(!0,!0)};l.prototype.addInput=function(a,b,c){b=b||0;a={name:a,type:b,link:null};if(c)for(var d in c)a[d]=c[d];this.inputs||(this.inputs=[]);this.inputs.push(a);this.setSize(this.computeSize());if(this.onInputAdded)this.onInputAdded(a);f.registerNodeAndSlotType(this,b);this.setDirtyCanvas(!0,!0);return a};l.prototype.addInputs=function(a){for(var b=0;b<a.length;++b){var c=a[b],d={name:c[0],type:c[1],link:null};if(a[2])for(var e in c[2])d[e]=c[2][e];this.inputs||(this.inputs=[]);
|
||||
this.inputs.push(d);if(this.onInputAdded)this.onInputAdded(d);f.registerNodeAndSlotType(this,c[1])}this.setSize(this.computeSize());this.setDirtyCanvas(!0,!0)};l.prototype.removeInput=function(a){this.disconnectInput(a);for(var b=this.inputs.splice(a,1),c=a;c<this.inputs.length;++c)if(this.inputs[c]){var d=this.graph.links[this.inputs[c].link];d&&--d.target_slot}this.setSize(this.computeSize());if(this.onInputRemoved)this.onInputRemoved(a,b[0]);this.setDirtyCanvas(!0,!0)};l.prototype.addConnection=
|
||||
function(a,b,c,d){a={name:a,type:b,pos:c,direction:d,links:null};this.connections.push(a);return a};l.prototype.computeSize=function(a){function b(a){return a?d*a.length*.6:0}if(this.constructor.size)return this.constructor.size.concat();var c=Math.max(this.inputs?this.inputs.length:1,this.outputs?this.outputs.length:1);a=a||new Float32Array([0,0]);c=Math.max(c,1);var d=f.NODE_TEXT_SIZE,e=b(this.title),g=0,h=0;if(this.inputs)for(var n=0,p=this.inputs.length;n<p;++n){var r=this.inputs[n];r=r.label||
|
||||
r.name||"";r=b(r);g<r&&(g=r)}if(this.outputs)for(n=0,p=this.outputs.length;n<p;++n)r=this.outputs[n],r=r.label||r.name||"",r=b(r),h<r&&(h=r);a[0]=Math.max(g+h+10,e);a[0]=Math.max(a[0],f.NODE_WIDTH);this.widgets&&this.widgets.length&&(a[0]=Math.max(a[0],1.5*f.NODE_WIDTH));a[1]=(this.constructor.slot_start_y||0)+c*f.NODE_SLOT_HEIGHT;c=0;if(this.widgets&&this.widgets.length){n=0;for(p=this.widgets.length;n<p;++n)c=this.widgets[n].computeSize?c+(this.widgets[n].computeSize(a[0])[1]+4):c+(f.NODE_WIDGET_HEIGHT+
|
||||
4);c+=8}a[1]=this.widgets_up?Math.max(a[1],c):null!=this.widgets_start_y?Math.max(a[1],c+this.widgets_start_y):a[1]+c;this.constructor.min_height&&a[1]<this.constructor.min_height&&(a[1]=this.constructor.min_height);a[1]+=6;return a};l.prototype.getPropertyInfo=function(a){var b=null;if(this.properties_info)for(var c=0;c<this.properties_info.length;++c)if(this.properties_info[c].name==a){b=this.properties_info[c];break}this.constructor["@"+a]&&(b=this.constructor["@"+a]);this.constructor.widgets_info&&
|
||||
this.constructor.widgets_info[a]&&(b=this.constructor.widgets_info[a]);!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};l.prototype.addWidget=function(a,b,c,d,e){this.widgets||(this.widgets=[]);!e&&d&&d.constructor===Object&&(e=d,d=null);e&&e.constructor===String&&(e={property:e});d&&d.constructor===String&&(e||(e={}),e.property=d,d=null);d&&d.constructor!==Function&&(console.warn("addWidget: callback must be a function"),
|
||||
d=null);b={type:a.toLowerCase(),name:b,value:c,callback:d,options:e||{}};void 0!==b.options.y&&(b.y=b.options.y);d||b.options.callback||b.options.property||console.warn("LiteGraph addWidget(...) without a callback or property assigned");if("combo"==a&&!b.options.values)throw"LiteGraph addWidget('combo',...) requires to pass values in options: { values:['red','blue'] }";this.widgets.push(b);this.setSize(this.computeSize());return b};l.prototype.addCustomWidget=function(a){this.widgets||(this.widgets=
|
||||
[]);this.widgets.push(a);return a};l.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};l.prototype.isPointInside=function(a,b,c,d){c=c||0;var e=this.graph&&this.graph.isLive()?0:f.NODE_TITLE_HEIGHT;d&&(e=0);if(this.flags&&this.flags.collapsed){if(D(a,b,this.pos[0]-c,this.pos[1]-f.NODE_TITLE_HEIGHT-
|
||||
c,(this._collapsed_width||f.NODE_COLLAPSED_WIDTH)+2*c,f.NODE_TITLE_HEIGHT+2*c))return!0}else if(this.pos[0]-4-c<a&&this.pos[0]+this.size[0]+4+c>a&&this.pos[1]-e-c<b&&this.pos[1]+this.size[1]+c>b)return!0;return!1};l.prototype.getSlotInPosition=function(a,b){var c=new Float32Array(2);if(this.inputs)for(var d=0,e=this.inputs.length;d<e;++d){var g=this.inputs[d];this.getConnectionPos(!0,d,c);if(D(a,b,c[0]-10,c[1]-5,20,10))return{input:g,slot:d,link_pos:c}}if(this.outputs)for(d=0,e=this.outputs.length;d<
|
||||
e;++d)if(g=this.outputs[d],this.getConnectionPos(!1,d,c),D(a,b,c[0]-10,c[1]-5,20,10))return{output:g,slot:d,link_pos:c};return null};l.prototype.findInputSlot=function(a,b){if(!this.inputs)return-1;for(var c=0,d=this.inputs.length;c<d;++c)if(a==this.inputs[c].name)return b?this.inputs[c]:c;return-1};l.prototype.findOutputSlot=function(a,b){b=b||!1;if(!this.outputs)return-1;for(var c=0,d=this.outputs.length;c<d;++c)if(a==this.outputs[c].name)return b?this.outputs[c]:c;return-1};l.prototype.findInputSlotFree=
|
||||
function(a){a=a||{};a=Object.assign({returnObj:!1,typesNotAccepted:[]},a);if(!this.inputs)return-1;for(var b=0,c=this.inputs.length;b<c;++b)if(!(this.inputs[b].link&&null!=this.inputs[b].link||a.typesNotAccepted&&a.typesNotAccepted.includes&&a.typesNotAccepted.includes(this.inputs[b].type)))return a.returnObj?this.inputs[b]:b;return-1};l.prototype.findOutputSlotFree=function(a){a=a||{};a=Object.assign({returnObj:!1,typesNotAccepted:[]},a);if(!this.outputs)return-1;for(var b=0,c=this.outputs.length;b<
|
||||
c;++b)if(!(this.outputs[b].links&&null!=this.outputs[b].links||a.typesNotAccepted&&a.typesNotAccepted.includes&&a.typesNotAccepted.includes(this.outputs[b].type)))return a.returnObj?this.outputs[b]:b;return-1};l.prototype.findInputSlotByType=function(a,b,c,d){return this.findSlotByType(!0,a,b,c,d)};l.prototype.findOutputSlotByType=function(a,b,c,d){return this.findSlotByType(!1,a,b,c,d)};l.prototype.findSlotByType=function(a,b,c,d,e){c=c||!1;d=d||!1;e=e||!1;a=a?this.inputs:this.outputs;if(!a)return-1;
|
||||
if(""==b||"*"==b)b=0;for(var g=0,h=a.length;g<h;++g){var n=(b+"").toLowerCase().split(","),p="0"==a[g].type||"*"==a[g].type?"0":a[g].type;p=(p+"").toLowerCase().split(",");for(sI=0;sI<n.length;sI++)for(dI=0;dI<p.length;dI++)if("_event_"==n[sI]&&(n[sI]=f.EVENT),"_event_"==p[sI]&&(p[sI]=f.EVENT),"*"==n[sI]&&(n[sI]=0),"*"==p[sI]&&(p[sI]=0),!(n[sI]!=p[dI]||d&&a[g].links&&null!==a[g].links))return c?a[g]:g}if(d&&!e)for(g=0,h=a.length;g<h;++g)for(n=(b+"").toLowerCase().split(","),p="0"==a[g].type||"*"==
|
||||
a[g].type?"0":a[g].type,p=(p+"").toLowerCase().split(","),sI=0;sI<n.length;sI++)for(dI=0;dI<p.length;dI++)if("*"==n[sI]&&(n[sI]=0),"*"==p[sI]&&(p[sI]=0),n[sI]==p[dI])return c?a[g]:g;return-1};l.prototype.connectByType=function(a,b,c,d){d=d||{};d=Object.assign({createEventInCase:!0,firstFreeIfOutputGeneralInCase:!0,generalTypeInCase:!0},d);b&&b.constructor===Number&&(b=this.graph.getNodeById(b));e=b.findInputSlotByType(c,!1,!0);if(0<=e&&null!==e)return this.connect(a,b,e);if(d.createEventInCase&&c==
|
||||
f.EVENT)return this.connect(a,b,-1);if(d.generalTypeInCase){var e=b.findInputSlotByType(0,!1,!0,!0);if(0<=e)return this.connect(a,b,e)}if(d.firstFreeIfOutputGeneralInCase&&(0==c||"*"==c||""==c)&&(e=b.findInputSlotFree({typesNotAccepted:[f.EVENT]}),0<=e))return this.connect(a,b,e);console.debug("no way to connect type: ",c," to targetNODE ",b);return null};l.prototype.connectByTypeOutput=function(a,b,c,d){d=d||{};d=Object.assign({createEventInCase:!0,firstFreeIfInputGeneralInCase:!0,generalTypeInCase:!0},
|
||||
d);b&&b.constructor===Number&&(b=this.graph.getNodeById(b));e=b.findOutputSlotByType(c,!1,!0);if(0<=e&&null!==e)return b.connect(e,this,a);if(d.generalTypeInCase){var e=b.findOutputSlotByType(0,!1,!0,!0);if(0<=e)return b.connect(e,this,a)}if(d.createEventInCase&&c==f.EVENT&&f.do_add_triggers_slots)return e=b.addOnExecutedOutput(),b.connect(e,this,a);if(d.firstFreeIfInputGeneralInCase&&(0==c||"*"==c||""==c)&&(e=b.findOutputSlotFree({typesNotAccepted:[f.EVENT]}),0<=e))return b.connect(e,this,a);console.debug("no way to connect byOUT type: ",
|
||||
c," to sourceNODE ",b);return null};l.prototype.connect=function(a,b,c){c=c||0;if(!this.graph)return console.log("Connect: Error, node doesn't belong to any graph. Nodes must be added first to a graph before connecting them."),null;if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return 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(c.constructor===String){if(c=b.findInputSlot(c),-1==c)return f.debug&&console.log("Connect: Error, no slot of name "+c),null}else if(c===f.EVENT)if(f.do_add_triggers_slots)b.changeMode(f.ON_TRIGGER),c=b.findInputSlot("onTrigger");else return null;else if(!b.inputs||c>=b.inputs.length)return f.debug&&console.log("Connect: Error, slot number not found"),null;var d=b.inputs[c],e=this.outputs[a];if(!this.outputs[a])return null;
|
||||
b.onBeforeConnectInput&&(c=b.onBeforeConnectInput(c));if(!1===c||null===c||!f.isValidConnection(e.type,d.type))return this.setDirtyCanvas(!1,!0),null;if(b.onConnectInput&&!1===b.onConnectInput(c,e.type,e,this,a)||this.onConnectOutput&&!1===this.onConnectOutput(a,d.type,d,b,c))return null;b.inputs[c]&&null!=b.inputs[c].link&&(this.graph.beforeChange(),b.disconnectInput(c,{doProcessChange:!1}));if(null!==e.links&&e.links.length)switch(e.type){case f.EVENT:f.allow_multi_output_for_events||(this.graph.beforeChange(),
|
||||
this.disconnectOutput(a,!1,{doProcessChange:!1}))}var g=new t(++this.graph.last_link_id,d.type||e.type,this.id,a,b.id,c);this.graph.links[g.id]=g;null==e.links&&(e.links=[]);e.links.push(g.id);b.inputs[c].link=g.id;this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(f.OUTPUT,a,!0,g,e);if(b.onConnectionsChange)b.onConnectionsChange(f.INPUT,c,!0,g,d);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(f.INPUT,b,c,this,a),this.graph.onNodeConnectionChange(f.OUTPUT,
|
||||
this,a,b,c));this.setDirtyCanvas(!1,!0);this.graph.afterChange();this.graph.connectionChange(this,g);return g};l.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 c=this.outputs[a];if(!c||!c.links||0==c.links.length)return!1;if(b){b.constructor===Number&&(b=
|
||||
this.graph.getNodeById(b));if(!b)throw"Target Node not found";for(var d=0,e=c.links.length;d<e;d++){var g=c.links[d],h=this.graph.links[g];if(h.target_id==b.id){c.links.splice(d,1);var n=b.inputs[h.target_slot];n.link=null;delete this.graph.links[g];this.graph&&this.graph._version++;if(b.onConnectionsChange)b.onConnectionsChange(f.INPUT,h.target_slot,!1,h,n);if(this.onConnectionsChange)this.onConnectionsChange(f.OUTPUT,a,!1,h,c);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,h.target_slot));break}}}else{d=0;for(e=c.links.length;d<e;d++)if(g=c.links[d],h=this.graph.links[g]){b=this.graph.getNodeById(h.target_id);this.graph&&this.graph._version++;if(b){n=b.inputs[h.target_slot];n.link=null;if(b.onConnectionsChange)b.onConnectionsChange(f.INPUT,h.target_slot,!1,h,n);if(this.graph&&this.graph.onNodeConnectionChange)this.graph.onNodeConnectionChange(f.INPUT,
|
||||
b,h.target_slot)}delete this.graph.links[g];if(this.onConnectionsChange)this.onConnectionsChange(f.OUTPUT,a,!1,h,c);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(f.OUTPUT,this,a),this.graph.onNodeConnectionChange(f.INPUT,b,h.target_slot))}c.links=null}this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this);return!0};l.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 c=this.inputs[a].link;if(null!=c){this.inputs[a].link=null;var d=this.graph.links[c];if(d){var e=this.graph.getNodeById(d.origin_id);if(!e)return!1;var g=e.outputs[d.origin_slot];if(!g||!g.links||0==g.links.length)return!1;for(var h=0,n=g.links.length;h<n;h++)if(g.links[h]==c){g.links.splice(h,1);break}delete this.graph.links[c];this.graph&&
|
||||
this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(f.INPUT,a,!1,d,b);if(e.onConnectionsChange)e.onConnectionsChange(f.OUTPUT,h,!1,d,g);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(f.OUTPUT,e,h),this.graph.onNodeConnectionChange(f.INPUT,this,a))}}this.setDirtyCanvas(!1,!0);this.graph&&this.graph.connectionChange(this);return!0};l.prototype.getConnectionPos=function(a,b,c){c=c||new Float32Array(2);var d=0;a&&this.inputs&&(d=this.inputs.length);
|
||||
!a&&this.outputs&&(d=this.outputs.length);var e=.5*f.NODE_SLOT_HEIGHT;if(this.flags.collapsed)return b=this._collapsed_width||f.NODE_COLLAPSED_WIDTH,this.horizontal?(c[0]=this.pos[0]+.5*b,c[1]=a?this.pos[1]-f.NODE_TITLE_HEIGHT:this.pos[1]):(c[0]=a?this.pos[0]:this.pos[0]+b,c[1]=this.pos[1]-.5*f.NODE_TITLE_HEIGHT),c;if(a&&-1==b)return c[0]=this.pos[0]+.5*f.NODE_TITLE_HEIGHT,c[1]=this.pos[1]+.5*f.NODE_TITLE_HEIGHT,c;if(a&&d>b&&this.inputs[b].pos)return c[0]=this.pos[0]+this.inputs[b].pos[0],c[1]=this.pos[1]+
|
||||
this.inputs[b].pos[1],c;if(!a&&d>b&&this.outputs[b].pos)return c[0]=this.pos[0]+this.outputs[b].pos[0],c[1]=this.pos[1]+this.outputs[b].pos[1],c;if(this.horizontal)return c[0]=this.pos[0]+this.size[0]/d*(b+.5),c[1]=a?this.pos[1]-f.NODE_TITLE_HEIGHT:this.pos[1]+this.size[1],c;c[0]=a?this.pos[0]+e:this.pos[0]+this.size[0]+1-e;c[1]=this.pos[1]+(b+.7)*f.NODE_SLOT_HEIGHT+(this.constructor.slot_start_y||0);return c};l.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)};l.prototype.trace=function(a){this.console||(this.console=[]);this.console.push(a);this.console.length>l.MAX_CONSOLE&&this.console.shift();if(this.graph.onNodeTrace)this.graph.onNodeTrace(this,a)};l.prototype.setDirtyCanvas=function(a,b){this.graph&&this.graph.sendActionToCanvas("setDirty",[a,b])};l.prototype.loadImage=function(a){var b=new Image;b.src=f.node_images_path+a;b.ready=!1;var c=this;b.onload=
|
||||
function(){this.ready=!0;c.setDirtyCanvas(!0)};return b};l.prototype.captureInput=function(a){if(this.graph&&this.graph.list_of_graphcanvas)for(var b=this.graph.list_of_graphcanvas,c=0;c<b.length;++c){var d=b[c];if(a||d.node_capturing_input==this)d.node_capturing_input=a?this:null}};l.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)};l.prototype.pin=function(a){this.graph._version++;
|
||||
this.flags.pinned=void 0===a?!this.flags.pinned:a};l.prototype.localToScreen=function(a,b,c){return[(a+this.pos[0])*c.scale+c.offset[0],(b+this.pos[1])*c.scale+c.offset[1]]};x.LGraphGroup=f.LGraphGroup=w;w.prototype._ctor=function(a){this.title=a||"Group";this.font_size=24;this.color=k.node_colors.pale_blue?k.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})};w.prototype.configure=function(a){this.title=a.title;this._bounding.set(a.bounding);this.color=a.color;this.font=a.font};w.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}};w.prototype.move=function(a,b,c){this._pos[0]+=a;this._pos[1]+=b;if(!c)for(c=0;c<this._nodes.length;++c){var d=this._nodes[c];d.pos[0]+=a;d.pos[1]+=b}};w.prototype.recomputeInsideNodes=function(){this._nodes.length=0;for(var a=this.graph._nodes,b=new Float32Array(4),c=0;c<a.length;++c){var d=a[c];d.getBounding(b);B(this._bounding,b)&&this._nodes.push(d)}};
|
||||
w.prototype.isPointInside=l.prototype.isPointInside;w.prototype.setDirtyCanvas=l.prototype.setDirtyCanvas;f.DragAndScale=A;A.prototype.bindEvents=function(a){this.last_mouse=new Float32Array(2);this._binded_mouse_callback=this.onMouse.bind(this);f.pointerListenerAdd(a,"down",this._binded_mouse_callback);f.pointerListenerAdd(a,"move",this._binded_mouse_callback);f.pointerListenerAdd(a,"up",this._binded_mouse_callback);a.addEventListener("mousewheel",this._binded_mouse_callback,!1);a.addEventListener("wheel",
|
||||
this._binded_mouse_callback,!1)};A.prototype.computeVisibleArea=function(a){if(this.element){var b=this.element.width,c=this.element.height,d=-this.offset[0],e=-this.offset[1];a&&(d+=a[0]/this.scale,e+=a[1]/this.scale,b=a[2],c=a[3]);a=d+b/this.scale;c=e+c/this.scale;this.visible_area[0]=d;this.visible_area[1]=e;this.visible_area[2]=a-d;this.visible_area[3]=c-e}else this.visible_area[0]=this.visible_area[1]=this.visible_area[2]=this.visible_area[3]=0};A.prototype.onMouse=function(a){if(this.enabled){var b=
|
||||
this.element,c=b.getBoundingClientRect(),d=a.clientX-c.left;c=a.clientY-c.top;a.canvasx=d;a.canvasy=c;a.dragging=this.dragging;var e=!this.viewport||this.viewport&&d>=this.viewport[0]&&d<this.viewport[0]+this.viewport[2]&&c>=this.viewport[1]&&c<this.viewport[1]+this.viewport[3],g=!1;this.onmouse&&(g=this.onmouse(a));a.type==f.pointerevents_method+"down"&&e?(this.dragging=!0,f.pointerListenerRemove(b,"move",this._binded_mouse_callback),f.pointerListenerAdd(document,"move",this._binded_mouse_callback),
|
||||
f.pointerListenerAdd(document,"up",this._binded_mouse_callback)):a.type==f.pointerevents_method+"move"?g||(b=d-this.last_mouse[0],g=c-this.last_mouse[1],this.dragging&&this.mouseDrag(b,g)):a.type==f.pointerevents_method+"up"?(this.dragging=!1,f.pointerListenerRemove(document,"move",this._binded_mouse_callback),f.pointerListenerRemove(document,"up",this._binded_mouse_callback),f.pointerListenerAdd(b,"move",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+.05*a.delta));this.last_mouse[0]=d;this.last_mouse[1]=c;if(e)return a.preventDefault(),a.stopPropagation(),!1}};A.prototype.toCanvasContext=function(a){a.scale(this.scale,this.scale);a.translate(this.offset[0],this.offset[1])};A.prototype.convertOffsetToCanvas=function(a){return[(a[0]+this.offset[0])*this.scale,
|
||||
(a[1]+this.offset[1])*this.scale]};A.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};A.prototype.mouseDrag=function(a,b){this.offset[0]+=a/this.scale;this.offset[1]+=b/this.scale;if(this.onredraw)this.onredraw(this)};A.prototype.changeScale=function(a,b){a<this.min_scale?a=this.min_scale:a>this.max_scale&&(a=this.max_scale);if(a!=this.scale&&this.element){var c=this.element.getBoundingClientRect();if(c&&(b=
|
||||
b||[.5*c.width,.5*c.height],c=this.convertCanvasToOffset(b),this.scale=a,.01>Math.abs(this.scale-1)&&(this.scale=1),a=this.convertCanvasToOffset(b),a=[a[0]-c[0],a[1]-c[1]],this.offset[0]+=a[0],this.offset[1]+=a[1],this.onredraw))this.onredraw(this)}};A.prototype.changeDeltaScale=function(a,b){this.changeScale(this.scale*a,b)};A.prototype.reset=function(){this.scale=1;this.offset[0]=0;this.offset[1]=0};x.LGraphCanvas=f.LGraphCanvas=k;k.DEFAULT_BACKGROUND_IMAGE="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQBJREFUeNrs1rEKwjAUhlETUkj3vP9rdmr1Ysammk2w5wdxuLgcMHyptfawuZX4pJSWZTnfnu/lnIe/jNNxHHGNn//HNbbv+4dr6V+11uF527arU7+u63qfa/bnmh8sWLBgwYJlqRf8MEptXPBXJXa37BSl3ixYsGDBMliwFLyCV/DeLIMFCxYsWLBMwSt4Be/NggXLYMGCBUvBK3iNruC9WbBgwYJlsGApeAWv4L1ZBgsWLFiwYJmCV/AK3psFC5bBggULloJX8BpdwXuzYMGCBctgwVLwCl7Be7MMFixYsGDBsu8FH1FaSmExVfAxBa/gvVmwYMGCZbBg/W4vAQYA5tRF9QYlv/QAAAAASUVORK5CYII=";
|
||||
k.link_type_colors={"-1":f.EVENT_LINK_COLOR,number:"#AAA",node:"#DCA"};k.gradients={};k.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.pointer_is_double=this.pointer_is_down=!1;this.visible_area.set([0,0,0,0]);if(this.onClear)this.onClear()};k.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)))};k.prototype.getTopGraph=function(){return this._graph_stack.length?this._graph_stack[0]:this.graph};k.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)};k.prototype.closeSubgraph=function(){if(this._graph_stack&&0!=this._graph_stack.length){var a=this.graph._subgraph_node,b=this._graph_stack.pop();this.selected_nodes={};this.highlighted_links={};b.attachCanvas(this);this.setDirty(!0,!0);a&&(this.centerOnNode(a),this.selectNodes([a]));this.ds.offset=
|
||||
[0,0];this.ds.scale=1}};k.prototype.getCurrentGraph=function(){return this.graph};k.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());b||this.bindEvents()}};k.prototype._doNothing=function(a){a.preventDefault();return!1};k.prototype._doReturnTrue=function(a){a.preventDefault();
|
||||
return!0};k.prototype.bindEvents=function(){if(this._events_binded)console.warn("LGraphCanvas: events already binded");else{var a=this.canvas,b=this.getCanvasWindow().document;this._mousedown_callback=this.processMouseDown.bind(this);this._mousewheel_callback=this.processMouseWheel.bind(this);this._mousemove_callback=this.processMouseMove.bind(this);this._mouseup_callback=this.processMouseUp.bind(this);f.pointerListenerAdd(a,"down",this._mousedown_callback,!0);a.addEventListener("mousewheel",this._mousewheel_callback,
|
||||
!1);f.pointerListenerAdd(a,"up",this._mouseup_callback,!0);f.pointerListenerAdd(a,"move",this._mousemove_callback);a.addEventListener("contextmenu",this._doNothing);a.addEventListener("DOMMouseScroll",this._mousewheel_callback,!1);this._key_callback=this.processKey.bind(this);a.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;f.pointerListenerRemove(this.canvas,"move",this._mousedown_callback);f.pointerListenerRemove(this.canvas,"up",this._mousedown_callback);f.pointerListenerRemove(this.canvas,"down",this._mousedown_callback);this.canvas.removeEventListener("mousewheel",this._mousewheel_callback);
|
||||
this._doNothing,!1);a.addEventListener("drop",this._ondrop_callback,!1);a.addEventListener("dragenter",this._doReturnTrue,!1);this._events_binded=!0}};k.prototype.unbindEvents=function(){if(this._events_binded){var a=this.getCanvasWindow().document;f.pointerListenerRemove(this.canvas,"move",this._mousedown_callback);f.pointerListenerRemove(this.canvas,"up",this._mousedown_callback);f.pointerListenerRemove(this.canvas,"down",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._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(){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 c=this,d=a.clientX,e=a.clientY;this.ds.viewport=this.viewport;d=!this.viewport||this.viewport&&d>=this.viewport[0]&&d<this.viewport[0]+this.viewport[2]&&e>=this.viewport[1]&&e<this.viewport[1]+this.viewport[3];this.options.skip_events||(f.pointerListenerRemove(this.canvas,"move",this._mousemove_callback),f.pointerListenerAdd(b.document,"move",this._mousemove_callback,!0),f.pointerListenerAdd(b.document,"up",
|
||||
this._mouseup_callback,!0));if(d){var g=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes,5);d=!1;e=f.getTime();var k=void 0===a.isPrimary||!a.isPrimary;e=300>e-this.last_mouseclick&&k;this.mouse[0]=a.clientX;this.mouse[1]=a.clientY;this.graph_mouse[0]=a.canvasX;this.graph_mouse[1]=a.canvasY;this.last_click_position=[this.mouse[0],this.mouse[1]];this.pointer_is_double=this.pointer_is_down&&k?!0:!1;this.pointer_is_down=!0;this.canvas.focus();f.closeAllContextMenus(b);if(!this.onMouse||
|
||||
1!=this.onMouse(a)){if(1!=a.which||this.pointer_is_double)if(2==a.which){if(f.middle_click_slot_add_default_node&&g&&this.allow_interaction&&!d&&!this.read_only&&!this.connecting_node&&!g.flags.collapsed&&!this.live_mode){e=d=k=!1;if(g.outputs)for(u=0,n=g.outputs.length;u<n;++u)if(p=g.outputs[u],r=g.getConnectionPos(!1,u),C(a.canvasX,a.canvasY,r[0]-15,r[1]-10,30,20)){k=p;d=u;e=!0;break}if(g.inputs)for(u=0,n=g.inputs.length;u<n;++u)if(p=g.inputs[u],r=g.getConnectionPos(!0,u),C(a.canvasX,a.canvasY,
|
||||
r[0]-15,r[1]-10,30,20)){k=p;d=u;e=!1;break}k&&!1!==d&&(u=.5-(d+1)/(e?g.outputs.length:g.inputs.length),k=g.getBounding(),this.createDefaultNodeForSlot({nodeFrom:e?g:null,slotFrom:e?d:null,nodeTo:e?null:g,slotTo:e?null:d,position:[e?k[0]+k[2]:k[0],a.canvasY-80],nodeType:"AUTO",posAdd:[e?30:-30,130*-u],posSizeFix:[e?0:-1,0]}))}}else 3!=a.which&&!this.pointer_is_double||!this.allow_interaction||d||this.read_only||(g&&(Object.keys(this.selected_nodes).length&&(this.selected_nodes[g.id]||a.shiftKey||a.ctrlKey||
|
||||
k.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()};k.prototype.enableWebGL=function(){this.gl=this.ctx=enableWebGLCanvas(this.canvas);this.ctx.webgl=!0;this.bgcanvas=this.canvas;this.bgctx=this.gl;this.canvas.webgl_enabled=!0};k.prototype.setDirty=function(a,b){a&&(this.dirty_canvas=!0);b&&(this.dirty_bgcanvas=!0)};k.prototype.getCanvasWindow=function(){if(!this.canvas)return window;var a=this.canvas.ownerDocument;
|
||||
return a.defaultView||a.parentWindow};k.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))};k.prototype.stopRendering=function(){this.is_rendering=!1};k.prototype.blockClick=function(){this.block_click=!0;this.last_mouseclick=0};k.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();k.active_canvas=this;var c=this,d=a.clientX,e=a.clientY;this.ds.viewport=this.viewport;d=!this.viewport||this.viewport&&d>=this.viewport[0]&&d<this.viewport[0]+this.viewport[2]&&e>=this.viewport[1]&&e<this.viewport[1]+this.viewport[3];this.options.skip_events||(f.pointerListenerRemove(this.canvas,"move",this._mousemove_callback),f.pointerListenerAdd(b.document,"move",this._mousemove_callback,!0),f.pointerListenerAdd(b.document,"up",
|
||||
this._mouseup_callback,!0));if(d){var g=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes,5);d=!1;e=f.getTime();var h=void 0===a.isPrimary||!a.isPrimary;e=300>e-this.last_mouseclick&&h;this.mouse[0]=a.clientX;this.mouse[1]=a.clientY;this.graph_mouse[0]=a.canvasX;this.graph_mouse[1]=a.canvasY;this.last_click_position=[this.mouse[0],this.mouse[1]];this.pointer_is_double=this.pointer_is_down&&h?!0:!1;this.pointer_is_down=!0;this.canvas.focus();f.closeAllContextMenus(b);if(!this.onMouse||
|
||||
1!=this.onMouse(a)){if(1!=a.which||this.pointer_is_double)if(2==a.which){if(f.middle_click_slot_add_default_node&&g&&this.allow_interaction&&!d&&!this.read_only&&!this.connecting_node&&!g.flags.collapsed&&!this.live_mode){e=d=h=!1;if(g.outputs)for(u=0,n=g.outputs.length;u<n;++u)if(p=g.outputs[u],r=g.getConnectionPos(!1,u),D(a.canvasX,a.canvasY,r[0]-15,r[1]-10,30,20)){h=p;d=u;e=!0;break}if(g.inputs)for(u=0,n=g.inputs.length;u<n;++u)if(p=g.inputs[u],r=g.getConnectionPos(!0,u),D(a.canvasX,a.canvasY,
|
||||
r[0]-15,r[1]-10,30,20)){h=p;d=u;e=!1;break}h&&!1!==d&&(u=.5-(d+1)/(e?g.outputs.length:g.inputs.length),h=g.getBounding(),this.createDefaultNodeForSlot({nodeFrom:e?g:null,slotFrom:e?d:null,nodeTo:e?null:g,slotTo:e?null:d,position:[e?h[0]+h[2]:h[0],a.canvasY-80],nodeType:"AUTO",posAdd:[e?30:-30,130*-u],posSizeFix:[e?0:-1,0]}))}}else 3!=a.which&&!this.pointer_is_double||!this.allow_interaction||d||this.read_only||(g&&(Object.keys(this.selected_nodes).length&&(this.selected_nodes[g.id]||a.shiftKey||a.ctrlKey||
|
||||
a.metaKey)?this.selected_nodes[g.id]||this.selectNodes([g],!0):this.selectNodes([g])),this.processContextMenu(g,a));else{a.ctrlKey&&(this.dragging_rectangle=new Float32Array(4),this.dragging_rectangle[0]=a.canvasX,this.dragging_rectangle[1]=a.canvasY,this.dragging_rectangle[2]=1,this.dragging_rectangle[3]=1,d=!0);f.alt_drag_do_clone_nodes&&a.altKey&&g&&this.allow_interaction&&!d&&!this.read_only&&(cloned=g.clone())&&(cloned.pos[0]+=5,cloned.pos[1]+=5,this.graph.add(cloned,!1,{doCalcSize:!1}),g=cloned,
|
||||
d=!0,u||(this.allow_dragnodes&&(this.graph.beforeChange(),this.node_dragged=g),this.selected_nodes[g.id]||this.processNodeSelected(g,a)));k=!1;if(g&&this.allow_interaction&&!d&&!this.read_only){this.live_mode||g.flags.pinned||this.bringToFront(g);if(!this.connecting_node&&!g.flags.collapsed&&!this.live_mode)if(!d&&!1!==g.resizable&&C(a.canvasX,a.canvasY,g.pos[0]+g.size[0]-5,g.pos[1]+g.size[1]-5,10,10))this.graph.beforeChange(),this.resizing_node=g,this.canvas.style.cursor="se-resize",d=!0;else{if(g.outputs){u=
|
||||
0;for(var n=g.outputs.length;u<n;++u){var p=g.outputs[u],r=g.getConnectionPos(!1,u);if(C(a.canvasX,a.canvasY,r[0]-15,r[1]-10,30,20)){this.connecting_node=g;this.connecting_output=p;this.connecting_output.slot_index=u;this.connecting_pos=g.getConnectionPos(!1,u);this.connecting_slot=u;f.shift_click_do_break_link_from&&a.shiftKey&&g.disconnectOutput(u);if(e){if(g.onOutputDblClick)g.onOutputDblClick(u,a)}else if(g.onOutputClick)g.onOutputClick(u,a);d=!0;break}}}if(g.inputs)for(u=0,n=g.inputs.length;u<
|
||||
n;++u)if(p=g.inputs[u],r=g.getConnectionPos(!0,u),C(a.canvasX,a.canvasY,r[0]-15,r[1]-10,30,20)){if(e){if(g.onInputDblClick)g.onInputDblClick(u,a)}else if(g.onInputClick)g.onInputClick(u,a);null!==p.link&&(r=this.graph.links[p.link],f.click_do_break_link_to&&(g.disconnectInput(u),d=this.dirty_bgcanvas=!0),this.allow_reconnect_links||a.shiftKey)&&(f.click_do_break_link_to||g.disconnectInput(u),this.connecting_node=this.graph._nodes_by_id[r.origin_id],this.connecting_slot=r.origin_slot,this.connecting_output=
|
||||
d=!0,u||(this.allow_dragnodes&&(this.graph.beforeChange(),this.node_dragged=g),this.selected_nodes[g.id]||this.processNodeSelected(g,a)));h=!1;if(g&&this.allow_interaction&&!d&&!this.read_only){this.live_mode||g.flags.pinned||this.bringToFront(g);if(!this.connecting_node&&!g.flags.collapsed&&!this.live_mode)if(!d&&!1!==g.resizable&&D(a.canvasX,a.canvasY,g.pos[0]+g.size[0]-5,g.pos[1]+g.size[1]-5,10,10))this.graph.beforeChange(),this.resizing_node=g,this.canvas.style.cursor="se-resize",d=!0;else{if(g.outputs){u=
|
||||
0;for(var n=g.outputs.length;u<n;++u){var p=g.outputs[u],r=g.getConnectionPos(!1,u);if(D(a.canvasX,a.canvasY,r[0]-15,r[1]-10,30,20)){this.connecting_node=g;this.connecting_output=p;this.connecting_output.slot_index=u;this.connecting_pos=g.getConnectionPos(!1,u);this.connecting_slot=u;f.shift_click_do_break_link_from&&a.shiftKey&&g.disconnectOutput(u);if(e){if(g.onOutputDblClick)g.onOutputDblClick(u,a)}else if(g.onOutputClick)g.onOutputClick(u,a);d=!0;break}}}if(g.inputs)for(u=0,n=g.inputs.length;u<
|
||||
n;++u)if(p=g.inputs[u],r=g.getConnectionPos(!0,u),D(a.canvasX,a.canvasY,r[0]-15,r[1]-10,30,20)){if(e){if(g.onInputDblClick)g.onInputDblClick(u,a)}else if(g.onInputClick)g.onInputClick(u,a);null!==p.link&&(r=this.graph.links[p.link],f.click_do_break_link_to&&(g.disconnectInput(u),d=this.dirty_bgcanvas=!0),this.allow_reconnect_links||a.shiftKey)&&(f.click_do_break_link_to||g.disconnectInput(u),this.connecting_node=this.graph._nodes_by_id[r.origin_id],this.connecting_slot=r.origin_slot,this.connecting_output=
|
||||
this.connecting_node.outputs[this.connecting_slot],this.connecting_pos=this.connecting_node.getConnectionPos(!1,this.connecting_slot),d=this.dirty_bgcanvas=!0);d||(this.connecting_node=g,this.connecting_input=p,this.connecting_input.slot_index=u,this.connecting_pos=g.getConnectionPos(!0,u),this.connecting_slot=u,d=this.dirty_bgcanvas=!0)}}if(!d){var u=!1;n=[a.canvasX-g.pos[0],a.canvasY-g.pos[1]];if(r=this.processNodeWidgets(g,this.graph_mouse,a))u=!0,this.node_widget=[g,r];if(e&&this.selected_nodes[g.id]){if(g.onDblClick)g.onDblClick(a,
|
||||
n,this);this.processNodeDblClicked(g);u=!0}g.onMouseDown&&g.onMouseDown(a,n,this)?u=!0:(g.subgraph&&!g.skip_subgraph_button&&!g.flags.collapsed&&n[0]>g.size[0]-f.NODE_TITLE_HEIGHT&&0>n[1]&&(c=this,setTimeout(function(){c.openSubgraph(g.subgraph)},10)),this.live_mode&&(u=k=!0));u||(this.allow_dragnodes&&(this.graph.beforeChange(),this.node_dragged=g),this.selected_nodes[g.id]||this.processNodeSelected(g,a));this.dirty_canvas=!0}}else if(!d){if(!this.read_only)for(u=0;u<this.visible_links.length;++u)if(k=
|
||||
this.visible_links[u],n=k._pos,!(!n||a.canvasX<n[0]-4||a.canvasX>n[0]+4||a.canvasY<n[1]-4||a.canvasY>n[1]+4)){this.showLinkMenu(k,a);this.over_link_center=null;break}this.selected_group=this.graph.getGroupOnPos(a.canvasX,a.canvasY);this.selected_group_resizing=!1;this.selected_group&&!this.read_only&&(a.ctrlKey&&(this.dragging_rectangle=null),10>D([a.canvasX,a.canvasY],[this.selected_group.pos[0]+this.selected_group.size[0],this.selected_group.pos[1]+this.selected_group.size[1]])*this.ds.scale?this.selected_group_resizing=
|
||||
!0:this.selected_group.recomputeInsideNodes());e&&!this.read_only&&this.allow_searchbox&&(this.showSearchBox(a),a.preventDefault(),a.stopPropagation());k=!0}!d&&k&&this.allow_dragcanvas&&(this.dragging_canvas=!0)}this.last_mouse[0]=a.clientX;this.last_mouse[1]=a.clientY;this.last_mouseclick=f.getTime();this.last_mouse_dragging=!0;this.graph.change();(!b.document.activeElement||"input"!=b.document.activeElement.nodeName.toLowerCase()&&"textarea"!=b.document.activeElement.nodeName.toLowerCase())&&a.preventDefault();
|
||||
a.stopPropagation();if(this.onMouseDown)this.onMouseDown(a);return!1}}}};h.prototype.processMouseMove=function(a){this.autoresize&&this.resize();this.set_canvas_dirty_on_mouse_event&&(this.dirty_canvas=!0);if(this.graph){h.active_canvas=this;this.adjustMouseEvent(a);var b=[a.clientX,a.clientY];this.mouse[0]=b[0];this.mouse[1]=b[1];var c=[b[0]-this.last_mouse[0],b[1]-this.last_mouse[1]];this.last_mouse=b;this.graph_mouse[0]=a.canvasX;this.graph_mouse[1]=a.canvasY;if(this.block_click)return a.preventDefault(),
|
||||
n,this);this.processNodeDblClicked(g);u=!0}g.onMouseDown&&g.onMouseDown(a,n,this)?u=!0:(g.subgraph&&!g.skip_subgraph_button&&!g.flags.collapsed&&n[0]>g.size[0]-f.NODE_TITLE_HEIGHT&&0>n[1]&&(c=this,setTimeout(function(){c.openSubgraph(g.subgraph)},10)),this.live_mode&&(u=h=!0));u||(this.allow_dragnodes&&(this.graph.beforeChange(),this.node_dragged=g),this.selected_nodes[g.id]||this.processNodeSelected(g,a));this.dirty_canvas=!0}}else if(!d){if(!this.read_only)for(u=0;u<this.visible_links.length;++u)if(h=
|
||||
this.visible_links[u],n=h._pos,!(!n||a.canvasX<n[0]-4||a.canvasX>n[0]+4||a.canvasY<n[1]-4||a.canvasY>n[1]+4)){this.showLinkMenu(h,a);this.over_link_center=null;break}this.selected_group=this.graph.getGroupOnPos(a.canvasX,a.canvasY);this.selected_group_resizing=!1;this.selected_group&&!this.read_only&&(a.ctrlKey&&(this.dragging_rectangle=null),10>E([a.canvasX,a.canvasY],[this.selected_group.pos[0]+this.selected_group.size[0],this.selected_group.pos[1]+this.selected_group.size[1]])*this.ds.scale?this.selected_group_resizing=
|
||||
!0:this.selected_group.recomputeInsideNodes());e&&!this.read_only&&this.allow_searchbox&&(this.showSearchBox(a),a.preventDefault(),a.stopPropagation());h=!0}!d&&h&&this.allow_dragcanvas&&(this.dragging_canvas=!0)}this.last_mouse[0]=a.clientX;this.last_mouse[1]=a.clientY;this.last_mouseclick=f.getTime();this.last_mouse_dragging=!0;this.graph.change();(!b.document.activeElement||"input"!=b.document.activeElement.nodeName.toLowerCase()&&"textarea"!=b.document.activeElement.nodeName.toLowerCase())&&a.preventDefault();
|
||||
a.stopPropagation();if(this.onMouseDown)this.onMouseDown(a);return!1}}}};k.prototype.processMouseMove=function(a){this.autoresize&&this.resize();this.set_canvas_dirty_on_mouse_event&&(this.dirty_canvas=!0);if(this.graph){k.active_canvas=this;this.adjustMouseEvent(a);var b=[a.clientX,a.clientY];this.mouse[0]=b[0];this.mouse[1]=b[1];var c=[b[0]-this.last_mouse[0],b[1]-this.last_mouse[1]];this.last_mouse=b;this.graph_mouse[0]=a.canvasX;this.graph_mouse[1]=a.canvasY;if(this.block_click)return a.preventDefault(),
|
||||
!1;a.dragging=this.last_mouse_dragging;this.node_widget&&(this.processNodeWidgets(this.node_widget[0],this.graph_mouse,a,this.node_widget[1]),this.dirty_canvas=!0);if(this.dragging_rectangle)this.dragging_rectangle[2]=a.canvasX-this.dragging_rectangle[0],this.dragging_rectangle[3]=a.canvasY-this.dragging_rectangle[1],this.dirty_canvas=!0;else if(this.selected_group&&!this.read_only)this.selected_group_resizing?this.selected_group.size=[a.canvasX-this.selected_group.pos[0],a.canvasY-this.selected_group.pos[1]]:
|
||||
(this.selected_group.move(c[0]/this.ds.scale,c[1]/this.ds.scale,a.ctrlKey),this.selected_group._nodes.length&&(this.dirty_canvas=!0)),this.dirty_bgcanvas=!0;else if(this.dragging_canvas)this.ds.offset[0]+=c[0]/this.ds.scale,this.ds.offset[1]+=c[1]/this.ds.scale,this.dirty_bgcanvas=this.dirty_canvas=!0;else if(this.allow_interaction&&!this.read_only){this.connecting_node&&(this.dirty_canvas=!0);var d=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes);b=0;for(var e=this.graph._nodes.length;b<
|
||||
e;++b)if(this.graph._nodes[b].mouseOver&&d!=this.graph._nodes[b]){this.graph._nodes[b].mouseOver=!1;if(this.node_over&&this.node_over.onMouseLeave)this.node_over.onMouseLeave(a);this.node_over=null;this.dirty_canvas=!0}if(d){d.redraw_on_mouse&&(this.dirty_canvas=!0);if(!d.mouseOver&&(d.mouseOver=!0,this.node_over=d,this.dirty_canvas=!0,d.onMouseEnter))d.onMouseEnter(a);if(d.onMouseMove)d.onMouseMove(a,[a.canvasX-d.pos[0],a.canvasY-d.pos[1]],this);if(this.connecting_node)if(this.connecting_output){if(e=
|
||||
this._highlight_input||[0,0],!this.isOverNodeBox(d,a.canvasX,a.canvasY)){var g=this.isOverNodeInput(d,a.canvasX,a.canvasY,e);if(-1!=g&&d.inputs[g]){var k=d.inputs[g].type;f.isValidConnection(this.connecting_output.type,k)&&(this._highlight_input=e,this._highlight_input_slot=d.inputs[g])}else this._highlight_input_slot=this._highlight_input=null}}else this.connecting_input&&(e=this._highlight_output||[0,0],this.isOverNodeBox(d,a.canvasX,a.canvasY)||(g=this.isOverNodeOutput(d,a.canvasX,a.canvasY,e),
|
||||
-1!=g&&d.outputs[g]?(k=d.outputs[g].type,f.isValidConnection(this.connecting_input.type,k)&&(this._highlight_output=e)):this._highlight_output=null));this.canvas&&(C(a.canvasX,a.canvasY,d.pos[0]+d.size[0]-5,d.pos[1]+d.size[1]-5,5,5)?this.canvas.style.cursor="se-resize":this.canvas.style.cursor="crosshair")}else{e=null;for(b=0;b<this.visible_links.length;++b)if(g=this.visible_links[b],k=g._pos,!(!k||a.canvasX<k[0]-4||a.canvasX>k[0]+4||a.canvasY<k[1]-4||a.canvasY>k[1]+4)){e=g;break}e!=this.over_link_center&&
|
||||
this._highlight_input||[0,0],!this.isOverNodeBox(d,a.canvasX,a.canvasY)){var g=this.isOverNodeInput(d,a.canvasX,a.canvasY,e);if(-1!=g&&d.inputs[g]){var h=d.inputs[g].type;f.isValidConnection(this.connecting_output.type,h)&&(this._highlight_input=e,this._highlight_input_slot=d.inputs[g])}else this._highlight_input_slot=this._highlight_input=null}}else this.connecting_input&&(e=this._highlight_output||[0,0],this.isOverNodeBox(d,a.canvasX,a.canvasY)||(g=this.isOverNodeOutput(d,a.canvasX,a.canvasY,e),
|
||||
-1!=g&&d.outputs[g]?(h=d.outputs[g].type,f.isValidConnection(this.connecting_input.type,h)&&(this._highlight_output=e)):this._highlight_output=null));this.canvas&&(D(a.canvasX,a.canvasY,d.pos[0]+d.size[0]-5,d.pos[1]+d.size[1]-5,5,5)?this.canvas.style.cursor="se-resize":this.canvas.style.cursor="crosshair")}else{e=null;for(b=0;b<this.visible_links.length;++b)if(g=this.visible_links[b],h=g._pos,!(!h||a.canvasX<h[0]-4||a.canvasX>h[0]+4||a.canvasY<h[1]-4||a.canvasY>h[1]+4)){e=g;break}e!=this.over_link_center&&
|
||||
(this.over_link_center=e,this.dirty_canvas=!0);this.canvas&&(this.canvas.style.cursor="")}if(this.node_capturing_input&&this.node_capturing_input!=d&&this.node_capturing_input.onMouseMove)this.node_capturing_input.onMouseMove(a,[a.canvasX-this.node_capturing_input.pos[0],a.canvasY-this.node_capturing_input.pos[1]],this);if(this.node_dragged&&!this.live_mode){for(b in this.selected_nodes)d=this.selected_nodes[b],d.pos[0]+=c[0]/this.ds.scale,d.pos[1]+=c[1]/this.ds.scale;this.dirty_bgcanvas=this.dirty_canvas=
|
||||
!0}this.resizing_node&&!this.live_mode&&(c=[a.canvasX-this.resizing_node.pos[0],a.canvasY-this.resizing_node.pos[1]],b=this.resizing_node.computeSize(),c[0]=Math.max(b[0],c[0]),c[1]=Math.max(b[1],c[1]),this.resizing_node.setSize(c),this.canvas.style.cursor="se-resize",this.dirty_bgcanvas=this.dirty_canvas=!0)}a.preventDefault();return!1}};h.prototype.processMouseUp=function(a){var b=void 0===a.isPrimary||a.isPrimary;if(!b)return!1;this.set_canvas_dirty_on_mouse_event&&(this.dirty_canvas=!0);if(this.graph){var c=
|
||||
this.getCanvasWindow().document;h.active_canvas=this;this.options.skip_events||(f.pointerListenerRemove(c,"move",this._mousemove_callback,!0),f.pointerListenerAdd(this.canvas,"move",this._mousemove_callback,!0),f.pointerListenerRemove(c,"up",this._mouseup_callback,!0));this.adjustMouseEvent(a);c=f.getTime();a.click_time=c-this.last_mouseclick;this.last_mouse_dragging=!1;this.last_click_position=null;this.block_click&&(this.block_click=!1);if(1==a.which){this.node_widget&&this.processNodeWidgets(this.node_widget[0],
|
||||
!0}this.resizing_node&&!this.live_mode&&(c=[a.canvasX-this.resizing_node.pos[0],a.canvasY-this.resizing_node.pos[1]],b=this.resizing_node.computeSize(),c[0]=Math.max(b[0],c[0]),c[1]=Math.max(b[1],c[1]),this.resizing_node.setSize(c),this.canvas.style.cursor="se-resize",this.dirty_bgcanvas=this.dirty_canvas=!0)}a.preventDefault();return!1}};k.prototype.processMouseUp=function(a){var b=void 0===a.isPrimary||a.isPrimary;if(!b)return!1;this.set_canvas_dirty_on_mouse_event&&(this.dirty_canvas=!0);if(this.graph){var c=
|
||||
this.getCanvasWindow().document;k.active_canvas=this;this.options.skip_events||(f.pointerListenerRemove(c,"move",this._mousemove_callback,!0),f.pointerListenerAdd(this.canvas,"move",this._mousemove_callback,!0),f.pointerListenerRemove(c,"up",this._mouseup_callback,!0));this.adjustMouseEvent(a);c=f.getTime();a.click_time=c-this.last_mouseclick;this.last_mouse_dragging=!1;this.last_click_position=null;this.block_click&&(this.block_click=!1);if(1==a.which){this.node_widget&&this.processNodeWidgets(this.node_widget[0],
|
||||
this.graph_mouse,a);this.node_widget=null;this.selected_group&&(this.selected_group.move(this.selected_group.pos[0]-Math.round(this.selected_group.pos[0]),this.selected_group.pos[1]-Math.round(this.selected_group.pos[1]),a.ctrlKey),this.selected_group.pos[0]=Math.round(this.selected_group.pos[0]),this.selected_group.pos[1]=Math.round(this.selected_group.pos[1]),this.selected_group._nodes.length&&(this.dirty_canvas=!0),this.selected_group=null);this.selected_group_resizing=!1;var d=this.graph.getNodeOnPos(a.canvasX,
|
||||
a.canvasY,this.visible_nodes);if(this.dragging_rectangle){if(this.graph){c=this.graph._nodes;var e=new Float32Array(4),g=Math.abs(this.dragging_rectangle[2]),k=Math.abs(this.dragging_rectangle[3]),n=0>this.dragging_rectangle[3]?this.dragging_rectangle[1]-k:this.dragging_rectangle[1];this.dragging_rectangle[0]=0>this.dragging_rectangle[2]?this.dragging_rectangle[0]-g:this.dragging_rectangle[0];this.dragging_rectangle[1]=n;this.dragging_rectangle[2]=g;this.dragging_rectangle[3]=k;if(!d||10<g&&10<k){d=
|
||||
[];for(g=0;g<c.length;++g)k=c[g],k.getBounding(e),A(this.dragging_rectangle,e)&&d.push(k);d.length&&this.selectNodes(d,a.shiftKey)}else this.selectNodes([d],a.shiftKey||a.ctrlKey)}this.dragging_rectangle=null}else if(this.connecting_node)this.dirty_bgcanvas=this.dirty_canvas=!0,c=(this.connecting_output||this.connecting_input).type,d?this.connecting_output?(e=this.isOverNodeInput(d,a.canvasX,a.canvasY),-1!=e?this.connecting_node.connect(this.connecting_slot,d,e):this.connecting_node.connectByType(this.connecting_slot,
|
||||
a.canvasY,this.visible_nodes);if(this.dragging_rectangle){if(this.graph){c=this.graph._nodes;var e=new Float32Array(4),g=Math.abs(this.dragging_rectangle[2]),h=Math.abs(this.dragging_rectangle[3]),n=0>this.dragging_rectangle[3]?this.dragging_rectangle[1]-h:this.dragging_rectangle[1];this.dragging_rectangle[0]=0>this.dragging_rectangle[2]?this.dragging_rectangle[0]-g:this.dragging_rectangle[0];this.dragging_rectangle[1]=n;this.dragging_rectangle[2]=g;this.dragging_rectangle[3]=h;if(!d||10<g&&10<h){d=
|
||||
[];for(g=0;g<c.length;++g)h=c[g],h.getBounding(e),B(this.dragging_rectangle,e)&&d.push(h);d.length&&this.selectNodes(d,a.shiftKey)}else this.selectNodes([d],a.shiftKey||a.ctrlKey)}this.dragging_rectangle=null}else if(this.connecting_node)this.dirty_bgcanvas=this.dirty_canvas=!0,c=(this.connecting_output||this.connecting_input).type,d?this.connecting_output?(e=this.isOverNodeInput(d,a.canvasX,a.canvasY),-1!=e?this.connecting_node.connect(this.connecting_slot,d,e):this.connecting_node.connectByType(this.connecting_slot,
|
||||
d,c)):this.connecting_input&&(e=this.isOverNodeOutput(d,a.canvasX,a.canvasY),-1!=e?d.connect(e,this.connecting_node,this.connecting_slot):this.connecting_node.connectByTypeOutput(this.connecting_slot,d,c)):f.release_link_on_empty_shows_menu&&(a.shiftKey&&this.allow_searchbox?this.connecting_output?this.showSearchBox(a,{node_from:this.connecting_node,slot_from:this.connecting_output,type_filter_in:this.connecting_output.type}):this.connecting_input&&this.showSearchBox(a,{node_to:this.connecting_node,
|
||||
slot_from:this.connecting_input,type_filter_out:this.connecting_input.type}):this.connecting_output?this.showConnectionMenu({nodeFrom:this.connecting_node,slotFrom:this.connecting_output,e:a}):this.connecting_input&&this.showConnectionMenu({nodeTo:this.connecting_node,slotTo:this.connecting_input,e:a})),this.connecting_node=this.connecting_pos=this.connecting_input=this.connecting_output=null,this.connecting_slot=-1;else if(this.resizing_node)this.dirty_bgcanvas=this.dirty_canvas=!0,this.graph.afterChange(this.resizing_node),
|
||||
this.resizing_node=null;else if(this.node_dragged){(d=this.node_dragged)&&300>a.click_time&&C(a.canvasX,a.canvasY,d.pos[0],d.pos[1]-f.NODE_TITLE_HEIGHT,f.NODE_TITLE_HEIGHT,f.NODE_TITLE_HEIGHT)&&d.collapse();this.dirty_bgcanvas=this.dirty_canvas=!0;this.node_dragged.pos[0]=Math.round(this.node_dragged.pos[0]);this.node_dragged.pos[1]=Math.round(this.node_dragged.pos[1]);(this.graph.config.align_to_grid||this.align_to_grid)&&this.node_dragged.alignToGrid();if(this.onNodeMoved)this.onNodeMoved(this.node_dragged);
|
||||
this.resizing_node=null;else if(this.node_dragged){(d=this.node_dragged)&&300>a.click_time&&D(a.canvasX,a.canvasY,d.pos[0],d.pos[1]-f.NODE_TITLE_HEIGHT,f.NODE_TITLE_HEIGHT,f.NODE_TITLE_HEIGHT)&&d.collapse();this.dirty_bgcanvas=this.dirty_canvas=!0;this.node_dragged.pos[0]=Math.round(this.node_dragged.pos[0]);this.node_dragged.pos[1]=Math.round(this.node_dragged.pos[1]);(this.graph.config.align_to_grid||this.align_to_grid)&&this.node_dragged.alignToGrid();if(this.onNodeMoved)this.onNodeMoved(this.node_dragged);
|
||||
this.graph.afterChange(this.node_dragged);this.node_dragged=null}else{d=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes);!d&&300>a.click_time&&this.deselectAllNodes();this.dirty_canvas=!0;this.dragging_canvas=!1;if(this.node_over&&this.node_over.onMouseUp)this.node_over.onMouseUp(a,[a.canvasX-this.node_over.pos[0],a.canvasY-this.node_over.pos[1]],this);if(this.node_capturing_input&&this.node_capturing_input.onMouseUp)this.node_capturing_input.onMouseUp(a,[a.canvasX-this.node_capturing_input.pos[0],
|
||||
a.canvasY-this.node_capturing_input.pos[1]])}}else 2==a.which?(this.dirty_canvas=!0,this.dragging_canvas=!1):3==a.which&&(this.dirty_canvas=!0,this.dragging_canvas=!1);b&&(this.pointer_is_double=this.pointer_is_down=!1);this.graph.change();a.stopPropagation();a.preventDefault();return!1}};h.prototype.processMouseWheel=function(a){if(this.graph&&this.allow_dragcanvas){var b=null!=a.wheelDeltaY?a.wheelDeltaY:-60*a.detail;this.adjustMouseEvent(a);var c=a.clientX,d=a.clientY;if(!this.viewport||this.viewport&&
|
||||
c>=this.viewport[0]&&c<this.viewport[0]+this.viewport[2]&&d>=this.viewport[1]&&d<this.viewport[1]+this.viewport[3])return c=this.ds.scale,0<b?c*=1.1:0>b&&(c*=1/1.1),this.ds.changeScale(c,[a.clientX,a.clientY]),this.graph.change(),a.preventDefault(),!1}};h.prototype.isOverNodeBox=function(a,b,c){var d=f.NODE_TITLE_HEIGHT;return C(b,c,a.pos[0]+2,a.pos[1]+2-d,d-4,d-4)?!0:!1};h.prototype.isOverNodeInput=function(a,b,c,d){if(a.inputs)for(var e=0,g=a.inputs.length;e<g;++e){var f=a.getConnectionPos(!0,e);
|
||||
if(a.horizontal?C(b,c,f[0]-5,f[1]-10,10,20):C(b,c,f[0]-10,f[1]-5,40,10))return d&&(d[0]=f[0],d[1]=f[1]),e}return-1};h.prototype.isOverNodeOutput=function(a,b,c,d){if(a.outputs)for(var e=0,g=a.outputs.length;e<g;++e){var f=a.getConnectionPos(!1,e);if(a.horizontal?C(b,c,f[0]-5,f[1]-10,10,20):C(b,c,f[0]-10,f[1]-5,40,10))return d&&(d[0]=f[0],d[1]=f[1]),e}return-1};h.prototype.processKey=function(a){if(this.graph){var b=!1;if("input"!=a.target.localName){if("keydown"==a.type){if(32==a.keyCode&&(b=this.dragging_canvas=
|
||||
a.canvasY-this.node_capturing_input.pos[1]])}}else 2==a.which?(this.dirty_canvas=!0,this.dragging_canvas=!1):3==a.which&&(this.dirty_canvas=!0,this.dragging_canvas=!1);b&&(this.pointer_is_double=this.pointer_is_down=!1);this.graph.change();a.stopPropagation();a.preventDefault();return!1}};k.prototype.processMouseWheel=function(a){if(this.graph&&this.allow_dragcanvas){var b=null!=a.wheelDeltaY?a.wheelDeltaY:-60*a.detail;this.adjustMouseEvent(a);var c=a.clientX,d=a.clientY;if(!this.viewport||this.viewport&&
|
||||
c>=this.viewport[0]&&c<this.viewport[0]+this.viewport[2]&&d>=this.viewport[1]&&d<this.viewport[1]+this.viewport[3])return c=this.ds.scale,0<b?c*=1.1:0>b&&(c*=1/1.1),this.ds.changeScale(c,[a.clientX,a.clientY]),this.graph.change(),a.preventDefault(),!1}};k.prototype.isOverNodeBox=function(a,b,c){var d=f.NODE_TITLE_HEIGHT;return D(b,c,a.pos[0]+2,a.pos[1]+2-d,d-4,d-4)?!0:!1};k.prototype.isOverNodeInput=function(a,b,c,d){if(a.inputs)for(var e=0,g=a.inputs.length;e<g;++e){var h=a.getConnectionPos(!0,e);
|
||||
if(a.horizontal?D(b,c,h[0]-5,h[1]-10,10,20):D(b,c,h[0]-10,h[1]-5,40,10))return d&&(d[0]=h[0],d[1]=h[1]),e}return-1};k.prototype.isOverNodeOutput=function(a,b,c,d){if(a.outputs)for(var e=0,g=a.outputs.length;e<g;++e){var h=a.getConnectionPos(!1,e);if(a.horizontal?D(b,c,h[0]-5,h[1]-10,10,20):D(b,c,h[0]-10,h[1]-5,40,10))return d&&(d[0]=h[0],d[1]=h[1]),e}return-1};k.prototype.processKey=function(a){if(this.graph){var b=!1;if("input"!=a.target.localName){if("keydown"==a.type){if(32==a.keyCode&&(b=this.dragging_canvas=
|
||||
!0),27==a.keyCode&&(this.node_panel&&this.node_panel.close(),this.options_panel&&this.options_panel.close(),b=!0),65==a.keyCode&&a.ctrlKey&&(this.selectNodes(),b=!0),"KeyC"==a.code&&(a.metaKey||a.ctrlKey)&&!a.shiftKey&&this.selected_nodes&&(this.copyToClipboard(),b=!0),"KeyV"!=a.code||!a.metaKey&&!a.ctrlKey||a.shiftKey||this.pasteFromClipboard(),46!=a.keyCode&&8!=a.keyCode||"input"==a.target.localName||"textarea"==a.target.localName||(this.deleteSelectedNodes(),b=!0),this.selected_nodes)for(var c in this.selected_nodes)if(this.selected_nodes[c].onKeyDown)this.selected_nodes[c].onKeyDown(a)}else if("keyup"==
|
||||
a.type&&(32==a.keyCode&&(this.dragging_canvas=!1),this.selected_nodes))for(c in this.selected_nodes)if(this.selected_nodes[c].onKeyUp)this.selected_nodes[c].onKeyUp(a);this.graph.change();if(b)return a.preventDefault(),a.stopImmediatePropagation(),!1}}};h.prototype.copyToClipboard=function(){var a={nodes:[],links:[]},b=0,c=[],d;for(d in this.selected_nodes){var e=this.selected_nodes[d];e._relative_id=b;c.push(e);b+=1}for(d=0;d<c.length;++d)if(e=c[d],b=e.clone()){if(a.nodes.push(b.serialize()),e.inputs&&
|
||||
e.inputs.length)for(b=0;b<e.inputs.length;++b){var g=e.inputs[b];if(g&&null!=g.link&&(g=this.graph.links[g.link])){var f=this.graph.getNodeById(g.origin_id);f&&this.selected_nodes[f.id]&&a.links.push([f._relative_id,g.origin_slot,e._relative_id,g.target_slot])}}}else console.warn("node type not found: "+e.type);localStorage.setItem("litegrapheditor_clipboard",JSON.stringify(a))};h.prototype.pasteFromClipboard=function(){var a=localStorage.getItem("litegrapheditor_clipboard");if(a){this.graph.beforeChange();
|
||||
a.type&&(32==a.keyCode&&(this.dragging_canvas=!1),this.selected_nodes))for(c in this.selected_nodes)if(this.selected_nodes[c].onKeyUp)this.selected_nodes[c].onKeyUp(a);this.graph.change();if(b)return a.preventDefault(),a.stopImmediatePropagation(),!1}}};k.prototype.copyToClipboard=function(){var a={nodes:[],links:[]},b=0,c=[],d;for(d in this.selected_nodes){var e=this.selected_nodes[d];e._relative_id=b;c.push(e);b+=1}for(d=0;d<c.length;++d)if(e=c[d],b=e.clone()){if(a.nodes.push(b.serialize()),e.inputs&&
|
||||
e.inputs.length)for(b=0;b<e.inputs.length;++b){var g=e.inputs[b];if(g&&null!=g.link&&(g=this.graph.links[g.link])){var h=this.graph.getNodeById(g.origin_id);h&&this.selected_nodes[h.id]&&a.links.push([h._relative_id,g.origin_slot,e._relative_id,g.target_slot])}}}else console.warn("node type not found: "+e.type);localStorage.setItem("litegrapheditor_clipboard",JSON.stringify(a))};k.prototype.pasteFromClipboard=function(){var a=localStorage.getItem("litegrapheditor_clipboard");if(a){this.graph.beforeChange();
|
||||
a=JSON.parse(a);for(var b=!1,c=!1,d=0;d<a.nodes.length;++d)b?(b[0]>a.nodes[d].pos[0]&&(b[0]=a.nodes[d].pos[0],c[0]=d),b[1]>a.nodes[d].pos[1]&&(b[1]=a.nodes[d].pos[1],c[1]=d)):(b=[a.nodes[d].pos[0],a.nodes[d].pos[1]],c=[d,d]);c=[];for(d=0;d<a.nodes.length;++d){var e=a.nodes[d],g=f.createNode(e.type);g&&(g.configure(e),g.pos[0]+=this.graph_mouse[0]-b[0],g.pos[1]+=this.graph_mouse[1]-b[1],this.graph.add(g,{doProcessChange:!1}),c.push(g))}for(d=0;d<a.links.length;++d)b=a.links[d],e=c[b[0]],g=c[b[2]],
|
||||
e&&g?e.connect(b[1],g,b[3]):console.warn("Warning, nodes missing on pasting");this.selectNodes(c);this.graph.afterChange()}};h.prototype.processDrop=function(a){a.preventDefault();this.adjustMouseEvent(a);var b=a.clientX,c=a.clientY;if(!this.viewport||this.viewport&&b>=this.viewport[0]&&b<this.viewport[0]+this.viewport[2]&&c>=this.viewport[1]&&c<this.viewport[1]+this.viewport[3]){b=[a.canvasX,a.canvasY];var d=this.graph?this.graph.getNodeOnPos(b[0],b[1]):null;if(d){if((d.onDropFile||d.onDropData)&&
|
||||
(b=a.dataTransfer.files)&&b.length)for(c=0;c<b.length;c++){var e=a.dataTransfer.files[0],g=e.name;h.getFileExtension(g);if(d.onDropFile)d.onDropFile(e);if(d.onDropData){var f=new FileReader;f.onload=function(a){d.onDropData(a.target.result,g,e)};var n=e.type.split("/")[0];"text"==n||""==n?f.readAsText(e):"image"==n?f.readAsDataURL(e):f.readAsArrayBuffer(e)}}return d.onDropItem&&d.onDropItem(event)?!0:this.onDropItem?this.onDropItem(event):!1}b=null;this.onDropItem&&(b=this.onDropItem(event));b||this.checkDropItem(a)}};
|
||||
h.prototype.checkDropItem=function(a){if(a.dataTransfer.files.length){var b=a.dataTransfer.files[0],c=h.getFileExtension(b.name).toLowerCase();if(c=f.node_types_by_file_extension[c]){this.graph.beforeChange();c=f.createNode(c.type);c.pos=[a.canvasX,a.canvasY];this.graph.add(c);if(c.onDropFile)c.onDropFile(b);this.graph.afterChange()}}};h.prototype.processNodeDblClicked=function(a){if(this.onShowNodePanel)this.onShowNodePanel(a);else this.showShowNodePanel(a);if(this.onNodeDblClicked)this.onNodeDblClicked(a);
|
||||
this.setDirty(!0)};h.prototype.processNodeSelected=function(a,b){this.selectNode(a,b&&(b.shiftKey||b.ctrlKey));if(this.onNodeSelected)this.onNodeSelected(a)};h.prototype.selectNode=function(a,b){null==a?this.deselectAllNodes():this.selectNodes([a],b)};h.prototype.selectNodes=function(a,b){b||this.deselectAllNodes();a=a||this.graph._nodes;"string"==typeof a&&(a=[a]);for(var c in a)if(b=a[c],!b.is_selected){if(!b.is_selected&&b.onSelected)b.onSelected();b.is_selected=!0;this.selected_nodes[b.id]=b;
|
||||
if(b.inputs)for(var d=0;d<b.inputs.length;++d)this.highlighted_links[b.inputs[d].link]=!0;if(b.outputs)for(d=0;d<b.outputs.length;++d){var e=b.outputs[d];if(e.links)for(var g=0;g<e.links.length;++g)this.highlighted_links[e.links[g]]=!0}}if(this.onSelectionChange)this.onSelectionChange(this.selected_nodes);this.setDirty(!0)};h.prototype.deselectNode=function(a){if(a.is_selected){if(a.onDeselected)a.onDeselected();a.is_selected=!1;if(this.onNodeDeselected)this.onNodeDeselected(a);if(a.inputs)for(var b=
|
||||
0;b<a.inputs.length;++b)delete this.highlighted_links[a.inputs[b].link];if(a.outputs)for(b=0;b<a.outputs.length;++b){var c=a.outputs[b];if(c.links)for(var d=0;d<c.links.length;++d)delete this.highlighted_links[c.links[d]]}}};h.prototype.deselectAllNodes=function(){if(this.graph){for(var a=this.graph._nodes,b=0,c=a.length;b<c;++b){var d=a[b];if(d.is_selected){if(d.onDeselected)d.onDeselected();d.is_selected=!1;if(this.onNodeDeselected)this.onNodeDeselected(d)}}this.selected_nodes={};this.current_node=
|
||||
null;this.highlighted_links={};if(this.onSelectionChange)this.onSelectionChange(this.selected_nodes);this.setDirty(!0)}};h.prototype.deleteSelectedNodes=function(){this.graph.beforeChange();for(var a in this.selected_nodes){var b=this.selected_nodes[a];if(!b.block_delete){if(b.inputs&&b.inputs.length&&b.outputs&&b.outputs.length&&f.isValidConnection(b.inputs[0].type,b.outputs[0].type)&&b.inputs[0].link&&b.outputs[0].links&&b.outputs[0].links.length){var c=b.graph.links[b.inputs[0].link],d=b.graph.links[b.outputs[0].links[0]],
|
||||
e=b.getInputNode(0),g=b.getOutputNodes(0)[0];e&&g&&e.connect(c.origin_slot,g,d.target_slot)}this.graph.remove(b);if(this.onNodeDeselected)this.onNodeDeselected(b)}}this.selected_nodes={};this.current_node=null;this.highlighted_links={};this.setDirty(!0);this.graph.afterChange()};h.prototype.centerOnNode=function(a){this.ds.offset[0]=-a.pos[0]-.5*a.size[0]+.5*this.canvas.width/this.ds.scale;this.ds.offset[1]=-a.pos[1]-.5*a.size[1]+.5*this.canvas.height/this.ds.scale;this.setDirty(!0,!0)};h.prototype.adjustMouseEvent=
|
||||
function(a){if(this.canvas){var b=this.canvas.getBoundingClientRect();var c=a.clientX-b.left;b=a.clientY-b.top}else c=a.clientX,b=a.clientY;a.deltaX=c-this.last_mouse_position[0];a.deltaY=b-this.last_mouse_position[1];this.last_mouse_position[0]=c;this.last_mouse_position[1]=b;a.canvasX=c/this.ds.scale-this.ds.offset[0];a.canvasY=b/this.ds.scale-this.ds.offset[1]};h.prototype.setZoom=function(a,b){this.ds.changeScale(a,b);this.dirty_bgcanvas=this.dirty_canvas=!0};h.prototype.convertOffsetToCanvas=
|
||||
function(a,b){return this.ds.convertOffsetToCanvas(a,b)};h.prototype.convertCanvasToOffset=function(a,b){return this.ds.convertCanvasToOffset(a,b)};h.prototype.convertEventToCanvasOffset=function(a){var b=this.canvas.getBoundingClientRect();return this.convertCanvasToOffset([a.clientX-b.left,a.clientY-b.top])};h.prototype.bringToFront=function(a){var b=this.graph._nodes.indexOf(a);-1!=b&&(this.graph._nodes.splice(b,1),this.graph._nodes.push(a))};h.prototype.sendToBack=function(a){var b=this.graph._nodes.indexOf(a);
|
||||
-1!=b&&(this.graph._nodes.splice(b,1),this.graph._nodes.unshift(a))};var L=new Float32Array(4);h.prototype.computeVisibleNodes=function(a,b){b=b||[];b.length=0;a=a||this.graph._nodes;for(var c=0,d=a.length;c<d;++c){var e=a[c];(!this.live_mode||e.onDrawBackground||e.onDrawForeground)&&A(this.visible_area,e.getBounding(L))&&b.push(e)}return b};h.prototype.draw=function(a,b){if(this.canvas&&0!=this.canvas.width&&0!=this.canvas.height){var c=f.getTime();this.render_time=.001*(c-this.last_draw_time);this.last_draw_time=
|
||||
c;this.graph&&this.ds.computeVisibleArea(this.viewport);(this.dirty_bgcanvas||b||this.always_render_background||this.graph&&this.graph._last_trigger_time&&1E3>c-this.graph._last_trigger_time)&&this.drawBackCanvas();(this.dirty_canvas||a)&&this.drawFrontCanvas();this.fps=this.render_time?1/this.render_time:0;this.frame+=1}};h.prototype.drawFrontCanvas=function(){this.dirty_canvas=!1;this.ctx||(this.ctx=this.bgcanvas.getContext("2d"));var a=this.ctx;if(a){var b=this.canvas;a.start2D&&!this.viewport&&
|
||||
(a.start2D(),a.restore(),a.setTransform(1,0,0,1,0,0));var c=this.viewport||this.dirty_area;c&&(a.save(),a.beginPath(),a.rect(c[0],c[1],c[2],c[3]),a.clip());this.clear_background&&(c?a.clearRect(c[0],c[1],c[2],c[3]):a.clearRect(0,0,b.width,b.height));this.bgcanvas==this.canvas?this.drawBackCanvas():a.drawImage(this.bgcanvas,0,0);if(this.onRender)this.onRender(b,a);this.show_info&&this.renderInfo(a,c?c[0]:0,c?c[1]:0);if(this.graph){a.save();this.ds.toCanvasContext(a);b=this.computeVisibleNodes(null,
|
||||
this.visible_nodes);for(var d=0;d<b.length;++d){var e=b[d];a.save();a.translate(e.pos[0],e.pos[1]);this.drawNode(e,a);a.restore()}this.render_execution_order&&this.drawExecutionOrder(a);this.graph.config.links_ontop&&(this.live_mode||this.drawConnections(a));if(null!=this.connecting_pos){a.lineWidth=this.connections_width;e=this.connecting_output||this.connecting_input;b=e.type;d=e.dir;null==d&&(d=this.connecting_output?this.connecting_node.horizontal?f.DOWN:f.RIGHT:this.connecting_node.horizontal?
|
||||
f.UP:f.LEFT);var g=e.shape;switch(b){case f.EVENT:e=f.EVENT_LINK_COLOR;break;default:e=f.CONNECTING_LINK_COLOR}this.renderLink(a,this.connecting_pos,[this.graph_mouse[0],this.graph_mouse[1]],null,!1,null,e,d,f.CENTER);a.beginPath();b===f.EVENT||g===f.BOX_SHAPE?(a.rect(this.connecting_pos[0]-6+.5,this.connecting_pos[1]-5+.5,14,10),a.fill(),a.beginPath(),a.rect(this.graph_mouse[0]-6+.5,this.graph_mouse[1]-5+.5,14,10)):g===f.ARROW_SHAPE?(a.moveTo(this.connecting_pos[0]+8,this.connecting_pos[1]+.5),a.lineTo(this.connecting_pos[0]-
|
||||
4,this.connecting_pos[1]+6+.5),a.lineTo(this.connecting_pos[0]-4,this.connecting_pos[1]-6+.5),a.closePath()):(a.arc(this.connecting_pos[0],this.connecting_pos[1],4,0,2*Math.PI),a.fill(),a.beginPath(),a.arc(this.graph_mouse[0],this.graph_mouse[1],4,0,2*Math.PI));a.fill();a.fillStyle="#ffcc00";if(this._highlight_input){a.beginPath();var k=this._highlight_input_slot.shape;k===f.ARROW_SHAPE?(a.moveTo(this._highlight_input[0]+8,this._highlight_input[1]+.5),a.lineTo(this._highlight_input[0]-4,this._highlight_input[1]+
|
||||
6+.5),a.lineTo(this._highlight_input[0]-4,this._highlight_input[1]-6+.5),a.closePath()):a.arc(this._highlight_input[0],this._highlight_input[1],6,0,2*Math.PI);a.fill()}this._highlight_output&&(a.beginPath(),k===f.ARROW_SHAPE?(a.moveTo(this._highlight_output[0]+8,this._highlight_output[1]+.5),a.lineTo(this._highlight_output[0]-4,this._highlight_output[1]+6+.5),a.lineTo(this._highlight_output[0]-4,this._highlight_output[1]-6+.5),a.closePath()):a.arc(this._highlight_output[0],this._highlight_output[1],
|
||||
6,0,2*Math.PI),a.fill())}this.dragging_rectangle&&(a.strokeStyle="#FFF",a.strokeRect(this.dragging_rectangle[0],this.dragging_rectangle[1],this.dragging_rectangle[2],this.dragging_rectangle[3]));if(this.over_link_center&&this.render_link_tooltip)this.drawLinkTooltip(a,this.over_link_center);else if(this.onDrawLinkTooltip)this.onDrawLinkTooltip(a,null);if(this.onDrawForeground)this.onDrawForeground(a,this.visible_rect);a.restore()}this._graph_stack&&this._graph_stack.length&&this.drawSubgraphPanel(a);
|
||||
if(this.onDrawOverlay)this.onDrawOverlay(a);c&&a.restore();a.finish2D&&a.finish2D()}};h.prototype.drawSubgraphPanel=function(a){var b=this.graph,c=b._subgraph_node;c?(this.drawSubgraphPanelLeft(b,c,a),this.drawSubgraphPanelRight(b,c,a)):console.warn("subgraph without subnode")};h.prototype.drawSubgraphPanelLeft=function(a,b,c){var d=b.inputs?b.inputs.length:0,e=Math.floor(1.6*f.NODE_SLOT_HEIGHT);c.fillStyle="#111";c.globalAlpha=.8;c.beginPath();c.roundRect(10,10,200,(d+1)*e+50,[8]);c.fill();c.globalAlpha=
|
||||
1;c.fillStyle="#888";c.font="14px Arial";c.textAlign="left";c.fillText("Graph Inputs",20,34);if(this.drawButton(180,20,20,20,"X","#151515"))this.closeSubgraph();else{d=50;c.font="14px Arial";if(b.inputs)for(var g=0;g<b.inputs.length;++g){var k=b.inputs[g];if(!k.not_subgraph_input){if(this.drawButton(20,d+2,180,e-2)){var n=b.constructor.input_node_type||"graph/input";this.graph.beforeChange();var p=f.createNode(n);p?(a.add(p),this.block_click=!1,this.last_click_position=null,this.selectNodes([p]),
|
||||
this.node_dragged=p,this.dragging_canvas=!1,p.setProperty("name",k.name),p.setProperty("type",k.type),this.node_dragged.pos[0]=this.graph_mouse[0]-5,this.node_dragged.pos[1]=this.graph_mouse[1]-5,this.graph.afterChange()):console.error("graph input node not found:",n)}c.fillStyle="#9C9";c.beginPath();c.arc(184,d+.5*e,5,0,2*Math.PI);c.fill();c.fillStyle="#AAA";c.fillText(k.name,30,d+.75*e);c.fillStyle="#777";c.fillText(k.type,130,d+.75*e);d+=e}}this.drawButton(20,d+2,180,e-2,"+","#151515","#222")&&
|
||||
this.showSubgraphPropertiesDialog(b)}};h.prototype.drawSubgraphPanelRight=function(a,b,c){var d=b.outputs?b.outputs.length:0,e=this.bgcanvas.width,g=Math.floor(1.6*f.NODE_SLOT_HEIGHT);c.fillStyle="#111";c.globalAlpha=.8;c.beginPath();c.roundRect(e-200-10,10,200,(d+1)*g+50,[8]);c.fill();c.globalAlpha=1;c.fillStyle="#888";c.font="14px Arial";c.textAlign="left";d=c.measureText("Graph Outputs").width;c.fillText("Graph Outputs",e-d-20,34);if(this.drawButton(e-200,20,20,20,"X","#151515"))this.closeSubgraph();
|
||||
else{d=50;c.font="14px Arial";if(b.outputs)for(var k=0;k<b.outputs.length;++k){var n=b.outputs[k];if(!n.not_subgraph_input){if(this.drawButton(e-200,d+2,180,g-2)){var p=b.constructor.output_node_type||"graph/output";this.graph.beforeChange();var r=f.createNode(p);r?(a.add(r),this.block_click=!1,this.last_click_position=null,this.selectNodes([r]),this.node_dragged=r,this.dragging_canvas=!1,r.setProperty("name",n.name),r.setProperty("type",n.type),this.node_dragged.pos[0]=this.graph_mouse[0]-5,this.node_dragged.pos[1]=
|
||||
this.graph_mouse[1]-5,this.graph.afterChange()):console.error("graph input node not found:",p)}c.fillStyle="#9C9";c.beginPath();c.arc(e-200+16,d+.5*g,5,0,2*Math.PI);c.fill();c.fillStyle="#AAA";c.fillText(n.name,e-200+30,d+.75*g);c.fillStyle="#777";c.fillText(n.type,e-200+130,d+.75*g);d+=g}}this.drawButton(e-200,d+2,180,g-2,"+","#151515","#222")&&this.showSubgraphPropertiesDialogRight(b)}};h.prototype.drawButton=function(a,b,c,d,e,g,k,n){var p=this.ctx;g=g||f.NODE_DEFAULT_COLOR;k=k||"#555";n=n||f.NODE_TEXT_COLOR;
|
||||
var r=b+f.NODE_TITLE_HEIGHT+2,u=this.mouse,q=f.isInsideRectangle(u[0],u[1],a,r,c,d);r=(u=this.last_click_position)&&f.isInsideRectangle(u[0],u[1],a,r,c,d);p.fillStyle=q?k:g;r&&(p.fillStyle="#AAA");p.beginPath();p.roundRect(a,b,c,d,[4]);p.fill();null!=e&&e.constructor==String&&(p.fillStyle=n,p.textAlign="center",p.font=(.65*d|0)+"px Arial",p.fillText(e,a+.5*c,b+.75*d),p.textAlign="left");a=r&&!this.block_click;r&&this.blockClick();return a};h.prototype.isAreaClicked=function(a,b,c,d,e){var g=this.mouse;
|
||||
f.isInsideRectangle(g[0],g[1],a,b,c,d);b=(a=(g=this.last_click_position)&&f.isInsideRectangle(g[0],g[1],a,b,c,d))&&!this.block_click;a&&e&&this.blockClick();return b};h.prototype.renderInfo=function(a,b,c){b=b||10;c=c||this.canvas.height-80;a.save();a.translate(b,c);a.font="10px Arial";a.fillStyle="#888";a.textAlign="left";this.graph?(a.fillText("T: "+this.graph.globaltime.toFixed(2)+"s",5,13),a.fillText("I: "+this.graph.iteration,5,26),a.fillText("N: "+this.graph._nodes.length+" ["+this.visible_nodes.length+
|
||||
"]",5,39),a.fillText("V: "+this.graph._version,5,52),a.fillText("FPS:"+this.fps.toFixed(2),5,65)):a.fillText("No graph selected",5,13);a.restore()};h.prototype.drawBackCanvas=function(){var a=this.bgcanvas;if(a.width!=this.canvas.width||a.height!=this.canvas.height)a.width=this.canvas.width,a.height=this.canvas.height;this.bgctx||(this.bgctx=this.bgcanvas.getContext("2d"));var b=this.bgctx;b.start&&b.start();var c=this.viewport||[0,0,b.canvas.width,b.canvas.height];this.clear_background&&b.clearRect(c[0],
|
||||
c[1],c[2],c[3]);if(this._graph_stack&&this._graph_stack.length){b.save();c=this.graph._subgraph_node;b.strokeStyle=c.bgcolor;b.lineWidth=10;b.strokeRect(1,1,a.width-2,a.height-2);b.lineWidth=1;b.font="40px Arial";b.textAlign="center";b.fillStyle=c.bgcolor||"#AAA";for(var d="",e=1;e<this._graph_stack.length;++e)d+=this._graph_stack[e]._subgraph_node.getTitle()+" >> ";b.fillText(d+c.getTitle(),.5*a.width,40);b.restore()}c=!1;this.onRenderBackground&&(c=this.onRenderBackground(a,b));this.viewport||(b.restore(),
|
||||
b.setTransform(1,0,0,1,0,0));this.visible_links.length=0;if(this.graph){b.save();this.ds.toCanvasContext(b);if(this.background_image&&.5<this.ds.scale&&!c){b.globalAlpha=this.zoom_modify_alpha?(1-.5/this.ds.scale)*this.editor_alpha:this.editor_alpha;b.imageSmoothingEnabled=b.imageSmoothingEnabled=!1;if(!this._bg_img||this._bg_img.name!=this.background_image){this._bg_img=new Image;this._bg_img.name=this.background_image;this._bg_img.src=this.background_image;var g=this;this._bg_img.onload=function(){g.draw(!0,
|
||||
!0)}}c=null;null==this._pattern&&0<this._bg_img.width?(c=b.createPattern(this._bg_img,"repeat"),this._pattern_img=this._bg_img,this._pattern=c):c=this._pattern;c&&(b.fillStyle=c,b.fillRect(this.visible_area[0],this.visible_area[1],this.visible_area[2],this.visible_area[3]),b.fillStyle="transparent");b.globalAlpha=1;b.imageSmoothingEnabled=b.imageSmoothingEnabled=!0}this.graph._groups.length&&!this.live_mode&&this.drawGroups(a,b);if(this.onDrawBackground)this.onDrawBackground(b,this.visible_area);
|
||||
this.onBackgroundRender&&(console.error("WARNING! onBackgroundRender deprecated, now is named onDrawBackground "),this.onBackgroundRender=null);this.render_canvas_border&&(b.strokeStyle="#235",b.strokeRect(0,0,a.width,a.height));this.render_connections_shadows?(b.shadowColor="#000",b.shadowOffsetX=0,b.shadowOffsetY=0,b.shadowBlur=6):b.shadowColor="rgba(0,0,0,0)";this.live_mode||this.drawConnections(b);b.shadowColor="rgba(0,0,0,0)";b.restore()}b.finish&&b.finish();this.dirty_bgcanvas=!1;this.dirty_canvas=
|
||||
!0};var I=new Float32Array(2);h.prototype.drawNode=function(a,b){this.current_node=a;var c=a.color||a.constructor.color||f.NODE_DEFAULT_COLOR,d=a.bgcolor||a.constructor.bgcolor||f.NODE_DEFAULT_BGCOLOR,e=.6>this.ds.scale;if(this.live_mode){if(!a.flags.collapsed&&(b.shadowColor="transparent",a.onDrawForeground))a.onDrawForeground(b,this,this.canvas)}else{var g=this.editor_alpha;b.globalAlpha=g;this.render_shadows&&!e?(b.shadowColor=f.DEFAULT_SHADOW_COLOR,b.shadowOffsetX=2*this.ds.scale,b.shadowOffsetY=
|
||||
2*this.ds.scale,b.shadowBlur=3*this.ds.scale):b.shadowColor="transparent";if(!a.flags.collapsed||!a.onDrawCollapsed||1!=a.onDrawCollapsed(b,this)){var k=a._shape||f.BOX_SHAPE;I.set(a.size);var n=a.horizontal;if(a.flags.collapsed){b.font=this.inner_text_font;var p=a.getTitle?a.getTitle():a.title;null!=p&&(a._collapsed_width=Math.min(a.size[0],b.measureText(p).width+2*f.NODE_TITLE_HEIGHT),I[0]=a._collapsed_width,I[1]=0)}a.clip_area&&(b.save(),b.beginPath(),k==f.BOX_SHAPE?b.rect(0,0,I[0],I[1]):k==f.ROUND_SHAPE?
|
||||
b.roundRect(0,0,I[0],I[1],[10]):k==f.CIRCLE_SHAPE&&b.arc(.5*I[0],.5*I[1],.5*I[0],0,2*Math.PI),b.clip());a.has_errors&&(d="red");this.drawNodeShape(a,b,I,c,d,a.is_selected,a.mouseOver);b.shadowColor="transparent";if(a.onDrawForeground)a.onDrawForeground(b,this,this.canvas);b.textAlign=n?"center":"left";b.font=this.inner_text_font;d=!e;var r=this.connecting_output;k=this.connecting_input;b.lineWidth=1;p=0;var u=new Float32Array(2);if(!a.flags.collapsed){if(a.inputs)for(c=0;c<a.inputs.length;c++){var q=
|
||||
a.inputs[c],y=q.type,h=q.shape;b.globalAlpha=g;this.connecting_output&&!f.isValidConnection(q.type,r.type)&&(b.globalAlpha=.4*g);b.fillStyle=null!=q.link?q.color_on||this.default_connection_color_byType[y]||this.default_connection_color.input_on:q.color_off||this.default_connection_color_byTypeOff[y]||this.default_connection_color_byType[y]||this.default_connection_color.input_off;var v=a.getConnectionPos(!0,c,u);v[0]-=a.pos[0];v[1]-=a.pos[1];p<v[1]+.5*f.NODE_SLOT_HEIGHT&&(p=v[1]+.5*f.NODE_SLOT_HEIGHT);
|
||||
b.beginPath();"array"==y&&(h=f.GRID_SHAPE);q.type===f.EVENT||q.shape===f.BOX_SHAPE?n?b.rect(v[0]-5+.5,v[1]-8+.5,10,14):b.rect(v[0]-6+.5,v[1]-5+.5,14,10):h===f.ARROW_SHAPE?(b.moveTo(v[0]+8,v[1]+.5),b.lineTo(v[0]-4,v[1]+6+.5),b.lineTo(v[0]-4,v[1]-6+.5),b.closePath()):h===f.GRID_SHAPE?(b.rect(v[0]-4,v[1]-4,2,2),b.rect(v[0]-1,v[1]-4,2,2),b.rect(v[0]+2,v[1]-4,2,2),b.rect(v[0]-4,v[1]-1,2,2),b.rect(v[0]-1,v[1]-1,2,2),b.rect(v[0]+2,v[1]-1,2,2),b.rect(v[0]-4,v[1]+2,2,2),b.rect(v[0]-1,v[1]+2,2,2),b.rect(v[0]+
|
||||
2,v[1]+2,2,2)):e?b.rect(v[0]-4,v[1]-4,8,8):b.arc(v[0],v[1],4,0,2*Math.PI);b.fill();d&&(y=null!=q.label?q.label:q.name)&&(b.fillStyle=f.NODE_TEXT_COLOR,n||q.dir==f.UP?b.fillText(y,v[0],v[1]-10):b.fillText(y,v[0]+10,v[1]+5))}b.textAlign=n?"center":"right";b.strokeStyle="black";if(a.outputs)for(c=0;c<a.outputs.length;c++)if(q=a.outputs[c],y=q.type,h=q.shape,this.connecting_input&&!f.isValidConnection(y,k.type)&&(b.globalAlpha=.4*g),v=a.getConnectionPos(!1,c,u),v[0]-=a.pos[0],v[1]-=a.pos[1],p<v[1]+.5*
|
||||
f.NODE_SLOT_HEIGHT&&(p=v[1]+.5*f.NODE_SLOT_HEIGHT),b.fillStyle=q.links&&q.links.length?q.color_on||this.default_connection_color_byType[y]||this.default_connection_color.output_on:q.color_off||this.default_connection_color_byTypeOff[y]||this.default_connection_color_byType[y]||this.default_connection_color.output_off,b.beginPath(),"array"==y&&(h=f.GRID_SHAPE),r=!0,y===f.EVENT||h===f.BOX_SHAPE?n?b.rect(v[0]-5+.5,v[1]-8+.5,10,14):b.rect(v[0]-6+.5,v[1]-5+.5,14,10):h===f.ARROW_SHAPE?(b.moveTo(v[0]+8,
|
||||
v[1]+.5),b.lineTo(v[0]-4,v[1]+6+.5),b.lineTo(v[0]-4,v[1]-6+.5),b.closePath()):h===f.GRID_SHAPE?(b.rect(v[0]-4,v[1]-4,2,2),b.rect(v[0]-1,v[1]-4,2,2),b.rect(v[0]+2,v[1]-4,2,2),b.rect(v[0]-4,v[1]-1,2,2),b.rect(v[0]-1,v[1]-1,2,2),b.rect(v[0]+2,v[1]-1,2,2),b.rect(v[0]-4,v[1]+2,2,2),b.rect(v[0]-1,v[1]+2,2,2),b.rect(v[0]+2,v[1]+2,2,2),r=!1):e?b.rect(v[0]-4,v[1]-4,8,8):b.arc(v[0],v[1],4,0,2*Math.PI),b.fill(),!e&&r&&b.stroke(),d&&(y=null!=q.label?q.label:q.name))b.fillStyle=f.NODE_TEXT_COLOR,n||q.dir==f.DOWN?
|
||||
b.fillText(y,v[0],v[1]-8):b.fillText(y,v[0]-10,v[1]+5);b.textAlign="left";b.globalAlpha=1;if(a.widgets){q=p;if(n||a.widgets_up)q=2;null!=a.widgets_start_y&&(q=a.widgets_start_y);this.drawNodeWidgets(a,q,b,this.node_widget&&this.node_widget[0]==a?this.node_widget[1]:null)}}else if(this.render_collapsed_slots){e=g=null;if(a.inputs)for(c=0;c<a.inputs.length;c++)if(q=a.inputs[c],null!=q.link){g=q;break}if(a.outputs)for(c=0;c<a.outputs.length;c++)q=a.outputs[c],q.links&&q.links.length&&(e=q);g&&(g=0,c=
|
||||
-.5*f.NODE_TITLE_HEIGHT,n&&(g=.5*a._collapsed_width,c=-f.NODE_TITLE_HEIGHT),b.fillStyle="#686",b.beginPath(),q.type===f.EVENT||q.shape===f.BOX_SHAPE?b.rect(g-7+.5,c-4,14,8):q.shape===f.ARROW_SHAPE?(b.moveTo(g+8,c),b.lineTo(g+-4,c-4),b.lineTo(g+-4,c+4),b.closePath()):b.arc(g,c,4,0,2*Math.PI),b.fill());e&&(g=a._collapsed_width,c=-.5*f.NODE_TITLE_HEIGHT,n&&(g=.5*a._collapsed_width,c=0),b.fillStyle="#686",b.strokeStyle="black",b.beginPath(),q.type===f.EVENT||q.shape===f.BOX_SHAPE?b.rect(g-7+.5,c-4,14,
|
||||
8):q.shape===f.ARROW_SHAPE?(b.moveTo(g+6,c),b.lineTo(g-6,c-4),b.lineTo(g-6,c+4),b.closePath()):b.arc(g,c,4,0,2*Math.PI),b.fill())}a.clip_area&&b.restore();b.globalAlpha=1}}};h.prototype.drawLinkTooltip=function(a,b){var c=b._pos;a.fillStyle="black";a.beginPath();a.arc(c[0],c[1],3,0,2*Math.PI);a.fill();if(null!=b.data&&(!this.onDrawLinkTooltip||1!=this.onDrawLinkTooltip(a,b,this))&&(b=b.data,b=b.constructor===Number?b.toFixed(2):b.constructor===String?'"'+b+'"':b.constructor===Boolean?String(b):b.toToolTip?
|
||||
b.toToolTip():"["+b.constructor.name+"]",null!=b)){b=b.substr(0,30);a.font="14px Courier New";var d=a.measureText(b).width+20;a.shadowColor="black";a.shadowOffsetX=2;a.shadowOffsetY=2;a.shadowBlur=3;a.fillStyle="#454";a.beginPath();a.roundRect(c[0]-.5*d,c[1]-15-24,d,24,[3]);a.moveTo(c[0]-10,c[1]-15);a.lineTo(c[0]+10,c[1]-15);a.lineTo(c[0],c[1]-5);a.fill();a.shadowColor="transparent";a.textAlign="center";a.fillStyle="#CEC";a.fillText(b,c[0],c[1]-15-24*.3)}};var B=new Float32Array(4);h.prototype.drawNodeShape=
|
||||
function(a,b,c,d,e,g,k){b.strokeStyle=d;b.fillStyle=e;e=f.NODE_TITLE_HEIGHT;var n=.5>this.ds.scale,p=a._shape||a.constructor.shape||f.ROUND_SHAPE,r=a.constructor.title_mode,u=!0;r==f.TRANSPARENT_TITLE||r==f.NO_TITLE?u=!1:r==f.AUTOHIDE_TITLE&&k&&(u=!0);B[0]=0;B[1]=u?-e:0;B[2]=c[0]+1;B[3]=u?c[1]+e:c[1];k=b.globalAlpha;b.beginPath();p==f.BOX_SHAPE||n?b.fillRect(B[0],B[1],B[2],B[3]):p==f.ROUND_SHAPE||p==f.CARD_SHAPE?b.roundRect(B[0],B[1],B[2],B[3],p==f.CARD_SHAPE?[this.round_radius,this.round_radius,
|
||||
0,0]:[this.round_radius]):p==f.CIRCLE_SHAPE&&b.arc(.5*c[0],.5*c[1],.5*c[0],0,2*Math.PI);b.fill();!a.flags.collapsed&&u&&(b.shadowColor="transparent",b.fillStyle="rgba(0,0,0,0.2)",b.fillRect(0,-1,B[2],2));b.shadowColor="transparent";if(a.onDrawBackground)a.onDrawBackground(b,this,this.canvas,this.graph_mouse);if(u||r==f.TRANSPARENT_TITLE){if(a.onDrawTitleBar)a.onDrawTitleBar(b,e,c,this.ds.scale,d);else if(r!=f.TRANSPARENT_TITLE&&(a.constructor.title_color||this.render_title_colored)){u=a.constructor.title_color||
|
||||
d;a.flags.collapsed&&(b.shadowColor=f.DEFAULT_SHADOW_COLOR);if(this.use_gradients){var q=h.gradients[u];q||(q=h.gradients[u]=b.createLinearGradient(0,0,400,0),q.addColorStop(0,u),q.addColorStop(1,"#000"));b.fillStyle=q}else b.fillStyle=u;b.beginPath();p==f.BOX_SHAPE||n?b.rect(0,-e,c[0]+1,e):(p==f.ROUND_SHAPE||p==f.CARD_SHAPE)&&b.roundRect(0,-e,c[0]+1,e,a.flags.collapsed?[this.round_radius]:[this.round_radius,this.round_radius,0,0]);b.fill();b.shadowColor="transparent"}u=!1;f.node_box_coloured_by_mode&&
|
||||
f.NODE_MODES_COLORS[a.mode]&&(u=f.NODE_MODES_COLORS[a.mode]);f.node_box_coloured_when_on&&(u=a.action_triggered?"#FFF":a.execute_triggered?"#AAA":u);if(a.onDrawTitleBox)a.onDrawTitleBox(b,e,c,this.ds.scale);else p==f.ROUND_SHAPE||p==f.CIRCLE_SHAPE||p==f.CARD_SHAPE?(n&&(b.fillStyle="black",b.beginPath(),b.arc(.5*e,-.5*e,6,0,2*Math.PI),b.fill()),b.fillStyle=a.boxcolor||u||f.NODE_DEFAULT_BOXCOLOR,n?b.fillRect(.5*e-5,-.5*e-5,10,10):(b.beginPath(),b.arc(.5*e,-.5*e,5,0,2*Math.PI),b.fill())):(n&&(b.fillStyle=
|
||||
"black",b.fillRect(.5*(e-10)-1,-.5*(e+10)-1,12,12)),b.fillStyle=a.boxcolor||u||f.NODE_DEFAULT_BOXCOLOR,b.fillRect(.5*(e-10),-.5*(e+10),10,10));b.globalAlpha=k;if(a.onDrawTitleText)a.onDrawTitleText(b,e,c,this.ds.scale,this.title_text_font,g);!n&&(b.font=this.title_text_font,k=String(a.getTitle()))&&(b.fillStyle=g?f.NODE_SELECTED_TITLE_COLOR:a.constructor.title_text_color||this.node_title_color,a.flags.collapsed?(b.textAlign="left",b.measureText(k),b.fillText(k.substr(0,20),e,f.NODE_TITLE_TEXT_Y-e),
|
||||
b.textAlign="left"):(b.textAlign="left",b.fillText(k,e,f.NODE_TITLE_TEXT_Y-e)));a.flags.collapsed||!a.subgraph||a.skip_subgraph_button||(k=f.NODE_TITLE_HEIGHT,u=a.size[0]-k,q=f.isInsideRectangle(this.graph_mouse[0]-a.pos[0],this.graph_mouse[1]-a.pos[1],u+2,-k+2,k-4,k-4),b.fillStyle=q?"#888":"#555",p==f.BOX_SHAPE||n?b.fillRect(u+2,-k+2,k-4,k-4):(b.beginPath(),b.roundRect(u+2,-k+2,k-4,k-4,[4]),b.fill()),b.fillStyle="#333",b.beginPath(),b.moveTo(u+.2*k,.6*-k),b.lineTo(u+.8*k,.6*-k),b.lineTo(u+.5*k,.3*
|
||||
-k),b.fill());if(a.onDrawTitle)a.onDrawTitle(b)}if(g){if(a.onBounding)a.onBounding(B);r==f.TRANSPARENT_TITLE&&(B[1]-=e,B[3]+=e);b.lineWidth=1;b.globalAlpha=.8;b.beginPath();p==f.BOX_SHAPE?b.rect(-6+B[0],-6+B[1],12+B[2],12+B[3]):p==f.ROUND_SHAPE||p==f.CARD_SHAPE&&a.flags.collapsed?b.roundRect(-6+B[0],-6+B[1],12+B[2],12+B[3],[2*this.round_radius]):p==f.CARD_SHAPE?b.roundRect(-6+B[0],-6+B[1],12+B[2],12+B[3],[2*this.round_radius,2,2*this.round_radius,2]):p==f.CIRCLE_SHAPE&&b.arc(.5*c[0],.5*c[1],.5*c[0]+
|
||||
6,0,2*Math.PI);b.strokeStyle=f.NODE_BOX_OUTLINE_COLOR;b.stroke();b.strokeStyle=d;b.globalAlpha=1}0<a.execute_triggered&&a.execute_triggered--;0<a.action_triggered&&a.action_triggered--};var K=new Float32Array(4),F=new Float32Array(4),J=new Float32Array(2),H=new Float32Array(2);h.prototype.drawConnections=function(a){var b=f.getTime(),c=this.visible_area;K[0]=c[0]-20;K[1]=c[1]-20;K[2]=c[2]+40;K[3]=c[3]+40;a.lineWidth=this.connections_width;a.fillStyle="#AAA";a.strokeStyle="#AAA";a.globalAlpha=this.editor_alpha;
|
||||
c=this.graph._nodes;for(var d=0,e=c.length;d<e;++d){var g=c[d];if(g.inputs&&g.inputs.length)for(var k=0;k<g.inputs.length;++k){var n=g.inputs[k];if(n&&null!=n.link&&(n=this.graph.links[n.link])){var p=this.graph.getNodeById(n.origin_id);if(null!=p){var r=n.origin_slot;var u=-1==r?[p.pos[0]+10,p.pos[1]+10]:p.getConnectionPos(!1,r,J);var q=g.getConnectionPos(!0,k,H);F[0]=u[0];F[1]=u[1];F[2]=q[0]-u[0];F[3]=q[1]-u[1];0>F[2]&&(F[0]+=F[2],F[2]=Math.abs(F[2]));0>F[3]&&(F[1]+=F[3],F[3]=Math.abs(F[3]));if(A(F,
|
||||
K)){var y=p.outputs[r];r=g.inputs[k];if(y&&r&&(p=y.dir||(p.horizontal?f.DOWN:f.RIGHT),r=r.dir||(g.horizontal?f.UP:f.LEFT),this.renderLink(a,u,q,n,!1,0,null,p,r),n&&n._last_time&&1E3>b-n._last_time)){y=2-.002*(b-n._last_time);var h=a.globalAlpha;a.globalAlpha=h*y;this.renderLink(a,u,q,n,!0,y,"white",p,r);a.globalAlpha=h}}}}}}a.globalAlpha=1};h.prototype.renderLink=function(a,b,c,d,e,g,k,n,p,r){d&&this.visible_links.push(d);!k&&d&&(k=d.color||h.link_type_colors[d.type]);k||(k=this.default_link_color);
|
||||
null!=d&&this.highlighted_links[d.id]&&(k="#FFF");n=n||f.RIGHT;p=p||f.LEFT;var u=D(b,c);this.render_connections_border&&.6<this.ds.scale&&(a.lineWidth=this.connections_width+4);a.lineJoin="round";r=r||1;1<r&&(a.lineWidth=.5);a.beginPath();for(var q=0;q<r;q+=1){var y=5*(q-.5*(r-1));if(this.links_render_mode==f.SPLINE_LINK){a.moveTo(b[0],b[1]+y);var l=0,v=0,m=0,w=0;switch(n){case f.LEFT:l=-.25*u;break;case f.RIGHT:l=.25*u;break;case f.UP:v=-.25*u;break;case f.DOWN:v=.25*u}switch(p){case f.LEFT:m=-.25*
|
||||
u;break;case f.RIGHT:m=.25*u;break;case f.UP:w=-.25*u;break;case f.DOWN:w=.25*u}a.bezierCurveTo(b[0]+l,b[1]+v+y,c[0]+m,c[1]+w+y,c[0],c[1]+y)}else if(this.links_render_mode==f.LINEAR_LINK){a.moveTo(b[0],b[1]+y);w=m=v=l=0;switch(n){case f.LEFT:l=-1;break;case f.RIGHT:l=1;break;case f.UP:v=-1;break;case f.DOWN:v=1}switch(p){case f.LEFT:m=-1;break;case f.RIGHT:m=1;break;case f.UP:w=-1;break;case f.DOWN:w=1}a.lineTo(b[0]+15*l,b[1]+15*v+y);a.lineTo(c[0]+15*m,c[1]+15*w+y);a.lineTo(c[0],c[1]+y)}else if(this.links_render_mode==
|
||||
f.STRAIGHT_LINK)a.moveTo(b[0],b[1]),y=b[0],l=b[1],v=c[0],m=c[1],n==f.RIGHT?y+=10:l+=10,p==f.LEFT?v-=10:m-=10,a.lineTo(y,l),a.lineTo(.5*(y+v),l),a.lineTo(.5*(y+v),m),a.lineTo(v,m),a.lineTo(c[0],c[1]);else return}this.render_connections_border&&.6<this.ds.scale&&!e&&(a.strokeStyle="rgba(0,0,0,0.5)",a.stroke());a.lineWidth=this.connections_width;a.fillStyle=a.strokeStyle=k;a.stroke();e=this.computeConnectionPoint(b,c,.5,n,p);d&&d._pos&&(d._pos[0]=e[0],d._pos[1]=e[1]);.6<=this.ds.scale&&this.highquality_render&&
|
||||
p!=f.CENTER&&(this.render_connection_arrows&&(q=this.computeConnectionPoint(b,c,.25,n,p),u=this.computeConnectionPoint(b,c,.26,n,p),d=this.computeConnectionPoint(b,c,.75,n,p),r=this.computeConnectionPoint(b,c,.76,n,p),this.render_curved_connections?(u=-Math.atan2(u[0]-q[0],u[1]-q[1]),r=-Math.atan2(r[0]-d[0],r[1]-d[1])):r=u=c[1]>b[1]?0:Math.PI,a.save(),a.translate(q[0],q[1]),a.rotate(u),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore(),a.save(),a.translate(d[0],d[1]),
|
||||
a.rotate(r),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore()),a.beginPath(),a.arc(e[0],e[1],5,0,2*Math.PI),a.fill());if(g)for(a.fillStyle=k,q=0;5>q;++q)g=(.001*f.getTime()+.2*q)%1,e=this.computeConnectionPoint(b,c,g,n,p),a.beginPath(),a.arc(e[0],e[1],5,0,2*Math.PI),a.fill()};h.prototype.computeConnectionPoint=function(a,b,c,d,e){d=d||f.RIGHT;e=e||f.LEFT;var g=D(a,b),k=[a[0],a[1]],n=[b[0],b[1]];switch(d){case f.LEFT:k[0]+=-.25*g;break;case f.RIGHT:k[0]+=.25*g;break;case f.UP:k[1]+=
|
||||
-.25*g;break;case f.DOWN:k[1]+=.25*g}switch(e){case f.LEFT:n[0]+=-.25*g;break;case f.RIGHT:n[0]+=.25*g;break;case f.UP:n[1]+=-.25*g;break;case f.DOWN:n[1]+=.25*g}d=(1-c)*(1-c)*(1-c);e=3*(1-c)*(1-c)*c;g=3*(1-c)*c*c;c*=c*c;return[d*a[0]+e*k[0]+g*n[0]+c*b[0],d*a[1]+e*k[1]+g*n[1]+c*b[1]]};h.prototype.drawExecutionOrder=function(a){a.shadowColor="transparent";a.globalAlpha=.25;a.textAlign="center";a.strokeStyle="white";a.globalAlpha=.75;for(var b=this.visible_nodes,c=0;c<b.length;++c){var d=b[c];a.fillStyle=
|
||||
"black";a.fillRect(d.pos[0]-f.NODE_TITLE_HEIGHT,d.pos[1]-f.NODE_TITLE_HEIGHT,f.NODE_TITLE_HEIGHT,f.NODE_TITLE_HEIGHT);0==d.order&&a.strokeRect(d.pos[0]-f.NODE_TITLE_HEIGHT+.5,d.pos[1]-f.NODE_TITLE_HEIGHT+.5,f.NODE_TITLE_HEIGHT,f.NODE_TITLE_HEIGHT);a.fillStyle="#FFF";a.fillText(d.order,d.pos[0]+-.5*f.NODE_TITLE_HEIGHT,d.pos[1]-6)}a.globalAlpha=1};h.prototype.drawNodeWidgets=function(a,b,c,d){if(!a.widgets||!a.widgets.length)return 0;var e=a.size[0],g=a.widgets;b+=2;var k=f.NODE_WIDGET_HEIGHT,n=.5<
|
||||
this.ds.scale;c.save();c.globalAlpha=this.editor_alpha;for(var p=f.WIDGET_OUTLINE_COLOR,r=f.WIDGET_BGCOLOR,u=f.WIDGET_TEXT_COLOR,q=f.WIDGET_SECONDARY_TEXT_COLOR,y=0;y<g.length;++y){var h=g[y],v=b;h.y&&(v=h.y);h.last_y=v;c.strokeStyle=p;c.fillStyle="#222";c.textAlign="left";h.disabled&&(c.globalAlpha*=.5);var l=h.width||e;switch(h.type){case "button":h.clicked&&(c.fillStyle="#AAA",h.clicked=!1,this.dirty_canvas=!0);c.fillRect(15,v,l-30,k);n&&!h.disabled&&c.strokeRect(15,v,l-30,k);n&&(c.textAlign="center",
|
||||
c.fillStyle=u,c.fillText(h.name,.5*l,v+.7*k));break;case "toggle":c.textAlign="left";c.strokeStyle=p;c.fillStyle=r;c.beginPath();n?c.roundRect(15,v,l-30,k,[.5*k]):c.rect(15,v,l-30,k);c.fill();n&&!h.disabled&&c.stroke();c.fillStyle=h.value?"#89A":"#333";c.beginPath();c.arc(l-30,v+.5*k,.36*k,0,2*Math.PI);c.fill();n&&(c.fillStyle=q,null!=h.name&&c.fillText(h.name,30,v+.7*k),c.fillStyle=h.value?u:q,c.textAlign="right",c.fillText(h.value?h.options.on||"true":h.options.off||"false",l-40,v+.7*k));break;
|
||||
case "slider":c.fillStyle=r;c.fillRect(15,v,l-30,k);var m=h.options.max-h.options.min,w=(h.value-h.options.min)/m;c.fillStyle=d==h?"#89A":"#678";c.fillRect(15,v,w*(l-30),k);n&&!h.disabled&&c.strokeRect(15,v,l-30,k);h.marker&&(m=(h.marker-h.options.min)/m,c.fillStyle="#AA9",c.fillRect(15+m*(l-30),v,2,k));n&&(c.textAlign="center",c.fillStyle=u,c.fillText(h.name+" "+Number(h.value).toFixed(3),.5*l,v+.7*k));break;case "number":case "combo":c.textAlign="left";c.strokeStyle=p;c.fillStyle=r;c.beginPath();
|
||||
n?c.roundRect(15,v,l-30,k,[.5*k]):c.rect(15,v,l-30,k);c.fill();n&&(h.disabled||c.stroke(),c.fillStyle=u,h.disabled||(c.beginPath(),c.moveTo(31,v+5),c.lineTo(21,v+.5*k),c.lineTo(31,v+k-5),c.fill(),c.beginPath(),c.moveTo(l-15-16,v+5),c.lineTo(l-15-6,v+.5*k),c.lineTo(l-15-16,v+k-5),c.fill()),c.fillStyle=q,c.fillText(h.name,35,v+.7*k),c.fillStyle=u,c.textAlign="right","number"==h.type?c.fillText(Number(h.value).toFixed(void 0!==h.options.precision?h.options.precision:3),l-30-20,v+.7*k):(m=h.value,h.options.values&&
|
||||
(w=h.options.values,w.constructor===Function&&(w=w()),w&&w.constructor!==Array&&(m=w[h.value])),c.fillText(m,l-30-20,v+.7*k)));break;case "string":case "text":c.textAlign="left";c.strokeStyle=p;c.fillStyle=r;c.beginPath();n?c.roundRect(15,v,l-30,k,[.5*k]):c.rect(15,v,l-30,k);c.fill();n&&(h.disabled||c.stroke(),c.save(),c.beginPath(),c.rect(15,v,l-30,k),c.clip(),c.fillStyle=q,null!=h.name&&c.fillText(h.name,30,v+.7*k),c.fillStyle=u,c.textAlign="right",c.fillText(String(h.value).substr(0,30),l-30,v+
|
||||
.7*k),c.restore());break;default:h.draw&&h.draw(c,a,l,v,k)}b+=(h.computeSize?h.computeSize(l)[1]:k)+4;c.globalAlpha=this.editor_alpha}c.restore();c.textAlign="left"};h.prototype.processNodeWidgets=function(a,b,c,d){function e(d,e){d.value=e;d.options&&d.options.property&&void 0!==a.properties[d.options.property]&&a.setProperty(d.options.property,e);d.callback&&d.callback(d.value,h,a,b,c)}if(!a.widgets||!a.widgets.length)return null;for(var g=b[0]-a.pos[0],k=b[1]-a.pos[1],n=a.size[0],h=this,r=this.getCanvasWindow(),
|
||||
u=0;u<a.widgets.length;++u){var q=a.widgets[u];if(q&&!q.disabled){var y=q.computeSize?q.computeSize(n)[1]:f.NODE_WIDGET_HEIGHT,l=q.width||n;if(q==d||!(6>g||g>l-12||k<q.last_y||k>q.last_y+y||void 0===q.last_y)){d=q.value;switch(q.type){case "button":c.type===f.pointerevents_method+"down"&&(q.callback&&setTimeout(function(){q.callback(q,h,a,b,c)},20),this.dirty_canvas=q.clicked=!0);break;case "slider":r=Math.clamp((g-15)/(l-30),0,1);q.value=q.options.min+(q.options.max-q.options.min)*r;q.callback&&
|
||||
setTimeout(function(){e(q,q.value)},20);this.dirty_canvas=!0;break;case "number":case "combo":d=q.value;if(c.type==f.pointerevents_method+"move"&&"number"==q.type)q.value+=.1*c.deltaX*(q.options.step||1),null!=q.options.min&&q.value<q.options.min&&(q.value=q.options.min),null!=q.options.max&&q.value>q.options.max&&(q.value=q.options.max);else if(c.type==f.pointerevents_method+"down"){var v=q.options.values;v&&v.constructor===Function&&(v=q.options.values(q,a));var m=null;"number"!=q.type&&(m=v.constructor===
|
||||
Array?v:Object.keys(v));g=40>g?-1:g>l-40?1:0;if("number"==q.type)q.value+=.1*g*(q.options.step||1),null!=q.options.min&&q.value<q.options.min&&(q.value=q.options.min),null!=q.options.max&&q.value>q.options.max&&(q.value=q.options.max);else if(g)r=-1,this.last_mouseclick=0,r=v.constructor===Object?m.indexOf(String(q.value))+g:m.indexOf(q.value)+g,r>=m.length&&(r=m.length-1),0>r&&(r=0),q.value=v.constructor===Array?v[r]:r;else{var w=v!=m?Object.values(v):v;new f.ContextMenu(w,{scale:Math.max(1,this.ds.scale),
|
||||
event:c,className:"dark",callback:function(a,b,c){v!=m&&(a=w.indexOf(a));this.value=a;e(this,a);h.dirty_canvas=!0;return!1}.bind(q)},r)}}else c.type==f.pointerevents_method+"up"&&"number"==q.type&&(g=40>g?-1:g>l-40?1:0,200>c.click_time&&0==g&&this.prompt("Value",q.value,function(a){this.value=Number(a);e(this,this.value)}.bind(q),c));d!=q.value&&setTimeout(function(){e(this,this.value)}.bind(q),20);this.dirty_canvas=!0;break;case "toggle":c.type==f.pointerevents_method+"down"&&(q.value=!q.value,setTimeout(function(){e(q,
|
||||
q.value)},20));break;case "string":case "text":c.type==f.pointerevents_method+"down"&&this.prompt("Value",q.value,function(a){this.value=a;e(this,a)}.bind(q),c,q.options?q.options.multiline:!1);break;default:q.mouse&&(this.dirty_canvas=q.mouse(c,[g,k],a))}if(d!=q.value){if(a.onWidgetChanged)a.onWidgetChanged(q.name,q.value,d,q);a.graph._version++}return q}}}return null};h.prototype.drawGroups=function(a,b){if(this.graph){a=this.graph._groups;b.save();b.globalAlpha=.5*this.editor_alpha;for(var c=0;c<
|
||||
a.length;++c){var d=a[c];if(A(this.visible_area,d._bounding)){b.fillStyle=d.color||"#335";b.strokeStyle=d.color||"#335";var e=d._pos,g=d._size;b.globalAlpha=.25*this.editor_alpha;b.beginPath();b.rect(e[0]+.5,e[1]+.5,g[0],g[1]);b.fill();b.globalAlpha=this.editor_alpha;b.stroke();b.beginPath();b.moveTo(e[0]+g[0],e[1]+g[1]);b.lineTo(e[0]+g[0]-10,e[1]+g[1]);b.lineTo(e[0]+g[0],e[1]+g[1]-10);b.fill();g=d.font_size||f.DEFAULT_GROUP_FONT_SIZE;b.font=g+"px Arial";b.textAlign="left";b.fillText(d.title,e[0]+
|
||||
4,e[1]+g)}}b.restore()}};h.prototype.adjustNodesSize=function(){for(var a=this.graph._nodes,b=0;b<a.length;++b)a[b].size=a[b].computeSize();this.setDirty(!0,!0)};h.prototype.resize=function(a,b){a||b||(b=this.canvas.parentNode,a=b.offsetWidth,b=b.offsetHeight);if(this.canvas.width!=a||this.canvas.height!=b)this.canvas.width=a,this.canvas.height=b,this.bgcanvas.width=this.canvas.width,this.bgcanvas.height=this.canvas.height,this.setDirty(!0,!0)};h.prototype.switchLiveMode=function(a){if(a){var b=this,
|
||||
c=this.live_mode?1.1:.9;this.live_mode&&(this.live_mode=!1,this.editor_alpha=.1);var d=setInterval(function(){b.editor_alpha*=c;b.dirty_canvas=!0;b.dirty_bgcanvas=!0;1>c&&.01>b.editor_alpha&&(clearInterval(d),1>c&&(b.live_mode=!0));1<c&&.99<b.editor_alpha&&(clearInterval(d),b.editor_alpha=1)},1)}else this.live_mode=!this.live_mode,this.dirty_bgcanvas=this.dirty_canvas=!0};h.prototype.onNodeSelectionChange=function(a){};h.onGroupAdd=function(a,b,c){a=h.active_canvas;a.getCanvasWindow();b=new f.LGraphGroup;
|
||||
b.pos=a.convertEventToCanvasOffset(c);a.graph.add(b)};h.onMenuAdd=function(a,b,c,d,e){function g(a,b){var d=[];f.getNodeTypesCategories(k.filter||p.filter).filter(function(b){return b.startsWith(a)}).map(function(b){if(b){b=b.replace(new RegExp("^("+a+")"),"").split("/")[0];var c=""===a?b+"/":a+b+"/";-1!=b.indexOf("::")&&(b=b.split("::")[1]);-1===d.findIndex(function(a){return a.value===c})&&d.push({value:c,content:b,has_submenu:!0,callback:function(a,b,c,d){g(a.value,d)}})}});f.getNodeTypesInCategory(a.slice(0,
|
||||
-1),k.filter||p.filter).map(function(a){a.skip_list||d.push({value:a.type,content:a.title,has_submenu:!1,callback:function(a,b,c,d){b=d.getFirstEvent();k.graph.beforeChange();if(a=f.createNode(a.value))a.pos=k.convertEventToCanvasOffset(b),k.graph.add(a);e&&e(a);k.graph.afterChange()}})});new f.ContextMenu(d,{event:c,parentMenu:b},n)}var k=h.active_canvas,n=k.getCanvasWindow(),p=k.graph;if(p)return g("",d),!1};h.onMenuCollapseAll=function(){};h.onMenuNodeEdit=function(){};h.showMenuNodeOptionalInputs=
|
||||
function(a,b,c,d,e){if(e){var g=this;a=h.active_canvas.getCanvasWindow();b=e.optional_inputs;e.onGetInputs&&(b=e.onGetInputs());var k=[];if(b)for(var n=0;n<b.length;n++){var p=b[n];if(p){var r=p[0];p[2]||(p[2]={});p[2].label&&(r=p[2].label);p[2].removable=!0;r={content:r,value:p};p[1]==f.ACTION&&(r.className="event");k.push(r)}else k.push(null)}e.onMenuNodeInputs&&(b=e.onMenuNodeInputs(k))&&(k=b);if(k.length)return new f.ContextMenu(k,{event:c,callback:function(a,b,c){if(e&&(a.callback&&a.callback.call(g,
|
||||
e,a,b,c),a.value)){e.graph.beforeChange();e.addInput(a.value[0],a.value[1],a.value[2]);if(e.onNodeInputAdd)e.onNodeInputAdd(a.value);e.setDirtyCanvas(!0,!0);e.graph.afterChange()}},parentMenu:d,node:e},a),!1;console.log("no input entries")}};h.showMenuNodeOptionalOutputs=function(a,b,c,d,e){function g(a,b,c){if(e&&(a.callback&&a.callback.call(k,e,a,b,c),a.value))if(c=a.value[1],!c||c.constructor!==Object&&c.constructor!==Array){e.graph.beforeChange();e.addOutput(a.value[0],a.value[1],a.value[2]);
|
||||
if(e.onNodeOutputAdd)e.onNodeOutputAdd(a.value);e.setDirtyCanvas(!0,!0);e.graph.afterChange()}else{a=[];for(var r in c)a.push({content:r,value:c[r]});new f.ContextMenu(a,{event:b,callback:g,parentMenu:d,node:e});return!1}}if(e){var k=this;a=h.active_canvas.getCanvasWindow();b=e.optional_outputs;e.onGetOutputs&&(b=e.onGetOutputs());var n=[];if(b)for(var p=0;p<b.length;p++){var r=b[p];if(!r)n.push(null);else if(!e.flags||!e.flags.skip_repeated_outputs||-1==e.findOutputSlot(r[0])){var u=r[0];r[2]||(r[2]=
|
||||
{});r[2].label&&(u=r[2].label);r[2].removable=!0;u={content:u,value:r};r[1]==f.EVENT&&(u.className="event");n.push(u)}}this.onMenuNodeOutputs&&(n=this.onMenuNodeOutputs(n));f.do_add_triggers_slots&&-1==e.findOutputSlot("onExecuted")&&n.push({content:"On Executed",value:["onExecuted",f.EVENT,{nameLocked:!0}],className:"event"});e.onMenuNodeOutputs&&(b=e.onMenuNodeOutputs(n))&&(n=b);if(n.length)return new f.ContextMenu(n,{event:c,callback:g,parentMenu:d,node:e},a),!1}};h.onShowMenuNodeProperties=function(a,
|
||||
b,c,d,e){if(e&&e.properties){var g=h.active_canvas;b=g.getCanvasWindow();var k=[],n;for(n in e.properties){a=void 0!==e.properties[n]?e.properties[n]:" ";"object"==typeof a&&(a=JSON.stringify(a));var p=e.getPropertyInfo(n);if("enum"==p.type||"combo"==p.type)a=h.getPropertyPrintableValue(a,p.values);a=h.decodeHTML(a);k.push({content:"<span class='property_name'>"+(p.label?p.label:n)+"</span><span class='property_value'>"+a+"</span>",value:n})}if(k.length)return new f.ContextMenu(k,{event:c,callback:function(a,
|
||||
b,c,d){e&&(b=this.getBoundingClientRect(),g.showEditPropertyValue(e,a.value,{position:[b.left,b.top]}))},parentMenu:d,allow_html:!0,node:e},b),!1}};h.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};h.onMenuResizeNode=function(a,b,c,d,e){if(e){a=function(a){a.size=a.computeSize();if(a.onResize)a.onResize(a.size)};b=h.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)a(e);else for(var g in b.selected_nodes)a(b.selected_nodes[g]);
|
||||
e.setDirtyCanvas(!0,!0)}};h.prototype.showLinkMenu=function(a,b){var c=this,d=c.graph.getNodeById(a.origin_id),e=c.graph.getNodeById(a.target_id),g=!1;d&&d.outputs&&d.outputs[a.origin_slot]&&(g=d.outputs[a.origin_slot].type);var k=!1;e&&e.outputs&&e.outputs[a.target_slot]&&(k=e.inputs[a.target_slot].type);var n=new f.ContextMenu(["Add Node",null,"Delete",null],{event:b,title:null!=a.data?a.data.constructor.name:null,callback:function(b,f,u){switch(b){case "Add Node":h.onMenuAdd(null,null,u,n,function(b){b.inputs&&
|
||||
b.inputs.length&&b.outputs&&b.outputs.length&&d.connectByType(a.origin_slot,b,g)&&(b.connectByType(a.target_slot,e,k),b.pos[0]-=.5*b.size[0])});break;case "Delete":c.graph.removeLink(a.id)}}});return!1};h.prototype.createDefaultNodeForSlot=function(a){a=a||{};a=Object.assign({nodeFrom:null,slotFrom:null,nodeTo:null,slotTo:null,position:[],nodeType:null,posAdd:[0,0],posSizeFix:[0,0]},a);var b=a.nodeFrom&&null!==a.slotFrom,c=!b&&a.nodeTo&&null!==a.slotTo;if(!b&&!c)return console.warn("No data passed to createDefaultNodeForSlot "+
|
||||
a.nodeFrom+" "+a.slotFrom+" "+a.nodeTo+" "+a.slotTo),!1;if(!a.nodeType)return console.warn("No type to createDefaultNodeForSlot"),!1;var d=b?a.nodeFrom:a.nodeTo,e=b?a.slotFrom:a.slotTo;switch(typeof e){case "string":c=b?d.findOutputSlot(e,!1):d.findInputSlot(e,!1);e=b?d.outputs[e]:d.inputs[e];break;case "object":c=b?d.findOutputSlot(e.name):d.findInputSlot(e.name);break;case "number":c=e;e=b?d.outputs[e]:d.inputs[e];break;default:return console.warn("Cant get slot information "+e),!1}!1!==e&&!1!==
|
||||
c||console.warn("createDefaultNodeForSlot bad slotX "+e+" "+c);d=e.type==f.EVENT?"_event_":e.type;if((e=b?f.slot_types_default_out:f.slot_types_default_in)&&e[d]){nodeNewType=!1;if("object"==typeof e[d]||"array"==typeof e[d])for(var g in e[d]){if(a.nodeType==e[d][g]||"AUTO"==a.nodeType){nodeNewType=e[d][g];break}}else if(a.nodeType==e[d]||"AUTO"==a.nodeType)nodeNewType=e[d];if(nodeNewType){g=!1;"object"==typeof nodeNewType&&nodeNewType.node&&(g=nodeNewType,nodeNewType=nodeNewType.node);if(e=f.createNode(nodeNewType)){if(g){if(g.properties)for(var k in g.properties)e.addProperty(k,
|
||||
g.properties[k]);if(g.inputs)for(k in e.inputs=[],g.inputs)e.addOutput(g.inputs[k][0],g.inputs[k][1]);if(g.outputs)for(k in e.outputs=[],g.outputs)e.addOutput(g.outputs[k][0],g.outputs[k][1]);g.title&&(e.title=g.title);g.json&&e.configure(g.json)}this.graph.add(e);e.pos=[a.position[0]+a.posAdd[0]+(a.posSizeFix[0]?a.posSizeFix[0]*e.size[0]:0),a.position[1]+a.posAdd[1]+(a.posSizeFix[1]?a.posSizeFix[1]*e.size[1]:0)];b?a.nodeFrom.connectByType(c,e,d):a.nodeTo.connectByTypeOutput(c,e,d);return!0}console.log("failed creating "+
|
||||
nodeNewType)}}return!1};h.prototype.showConnectionMenu=function(a){a=a||{};var b=Object.assign({nodeFrom:null,slotFrom:null,nodeTo:null,slotTo:null,e:null},a),c=this,d=b.nodeFrom&&b.slotFrom;a=!d&&b.nodeTo&&b.slotTo;if(!d&&!a)return console.warn("No data passed to showConnectionMenu"),!1;a=d?b.nodeFrom:b.nodeTo;var e=d?b.slotFrom:b.slotTo,g=!1;switch(typeof e){case "string":g=d?a.findOutputSlot(e,!1):a.findInputSlot(e,!1);e=d?a.outputs[e]:a.inputs[e];break;case "object":g=d?a.findOutputSlot(e.name):
|
||||
a.findInputSlot(e.name);break;case "number":g=e;e=d?a.outputs[e]:a.inputs[e];break;default:return console.warn("Cant get slot information "+e),!1}a=["Add Node",null];c.allow_searchbox&&(a.push("Search"),a.push(null));var k=e.type==f.EVENT?"_event_":e.type,n=d?f.slot_types_default_out:f.slot_types_default_in;if(n&&n[k])if("object"==typeof n[k]||"array"==typeof n[k])for(var p in n[k])a.push(n[k][p]);else a.push(n[k]);var r=new f.ContextMenu(a,{event:b.e,title:(e&&""!=e.name?e.name+(k?" | ":""):"")+
|
||||
(e&&k?k:""),callback:function(a,f,n){switch(a){case "Add Node":h.onMenuAdd(null,null,n,r,function(a){d?b.nodeFrom.connectByType(g,a,k):b.nodeTo.connectByTypeOutput(g,a,k)});break;case "Search":d?c.showSearchBox(n,{node_from:b.nodeFrom,slot_from:e,type_filter_in:k}):c.showSearchBox(n,{node_to:b.nodeTo,slot_from:e,type_filter_out:k});break;default:c.createDefaultNodeForSlot(Object.assign(b,{position:[b.e.canvasX,b.e.canvasY],nodeType:a}))}}});return!1};h.onShowPropertyEditor=function(a,b,c,d,e){function g(){if(p){var b=
|
||||
p.value;"Number"==a.type?b=Number(b):"Boolean"==a.type&&(b=!!b);e[k]=b;n.parentNode&&n.parentNode.removeChild(n);e.setDirtyCanvas(!0,!0)}}var k=a.property||"title";b=e[k];var n=document.createElement("div");n.is_modified=!1;n.className="graphdialog";n.innerHTML="<span class='name'></span><input autofocus type='text' class='value'/><button>OK</button>";n.close=function(){n.parentNode&&n.parentNode.removeChild(n)};n.querySelector(".name").innerText=k;var p=n.querySelector(".value");p&&(p.value=b,p.addEventListener("blur",
|
||||
function(a){this.focus()}),p.addEventListener("keydown",function(a){n.is_modified=!0;if(27==a.keyCode)n.close();else if(13==a.keyCode)g();else if(13!=a.keyCode&&"textarea"!=a.target.localName)return;a.preventDefault();a.stopPropagation()}));b=h.active_canvas.canvas;c=b.getBoundingClientRect();var r=d=-20;c&&(d-=c.left,r-=c.top);event?(n.style.left=event.clientX+d+"px",n.style.top=event.clientY+r+"px"):(n.style.left=.5*b.width+d+"px",n.style.top=.5*b.height+r+"px");n.querySelector("button").addEventListener("click",
|
||||
g);b.parentNode.appendChild(n);p&&p.focus();var u=null;n.addEventListener("mouseleave",function(a){f.dialog_close_on_mouse_leave&&!n.is_modified&&f.dialog_close_on_mouse_leave&&(u=setTimeout(n.close,f.dialog_close_on_mouse_leave_delay))});n.addEventListener("mouseenter",function(a){f.dialog_close_on_mouse_leave&&u&&clearTimeout(u)})};h.prototype.prompt=function(a,b,c,d,e){var g=this;a=a||"";var k=document.createElement("div");k.is_modified=!1;k.className="graphdialog rounded";k.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>";k.close=function(){g.prompt_box=null;k.parentNode&&k.parentNode.removeChild(k)};e=h.active_canvas.canvas;e.parentNode.appendChild(k);1<this.ds.scale&&(k.style.transform="scale("+this.ds.scale+")");var n=null,p=!1;f.pointerListenerAdd(k,"leave",function(a){p||f.dialog_close_on_mouse_leave&&!k.is_modified&&f.dialog_close_on_mouse_leave&&(n=setTimeout(k.close,f.dialog_close_on_mouse_leave_delay))});
|
||||
f.pointerListenerAdd(k,"enter",function(a){f.dialog_close_on_mouse_leave&&n&&clearTimeout(n)});var r=k.querySelectorAll("select");r&&r.forEach(function(a){a.addEventListener("click",function(a){p++});a.addEventListener("blur",function(a){p=0});a.addEventListener("change",function(a){p=-1})});g.prompt_box&&g.prompt_box.close();g.prompt_box=k;k.querySelector(".name").innerText=a;var u=k.querySelector(".value");u.value=b;u.addEventListener("keydown",function(a){k.is_modified=!0;if(27==a.keyCode)k.close();
|
||||
else if(13==a.keyCode&&"textarea"!=a.target.localName)c&&c(this.value),k.close();else return;a.preventDefault();a.stopPropagation()});k.querySelector("button").addEventListener("click",function(a){c&&c(u.value);g.setDirty(!0);k.close()});a=e.getBoundingClientRect();r=b=-20;a&&(b-=a.left,r-=a.top);d?(k.style.left=d.clientX+b+"px",k.style.top=d.clientY+r+"px"):(k.style.left=.5*e.width+b+"px",k.style.top=.5*e.height+r+"px");setTimeout(function(){u.focus()},10);return k};h.search_limit=-1;h.prototype.showSearchBox=
|
||||
function(a,b){function c(c){if(c)if(g.onSearchBoxSelection)g.onSearchBoxSelection(c,a,k);else{var d=f.searchbox_extras[c.toLowerCase()];d&&(c=d.type);k.graph.beforeChange();if(c=f.createNode(c))c.pos=k.convertEventToCanvasOffset(a),k.graph.add(c,!1);if(d&&d.data){if(d.data.properties)for(var e in d.data.properties)c.addProperty(e,d.data.properties[e]);if(d.data.inputs)for(e in c.inputs=[],d.data.inputs)c.addOutput(d.data.inputs[e][0],d.data.inputs[e][1]);if(d.data.outputs)for(e in c.outputs=[],d.data.outputs)c.addOutput(d.data.outputs[e][0],
|
||||
e&&g?e.connect(b[1],g,b[3]):console.warn("Warning, nodes missing on pasting");this.selectNodes(c);this.graph.afterChange()}};k.prototype.processDrop=function(a){a.preventDefault();this.adjustMouseEvent(a);var b=a.clientX,c=a.clientY;if(!this.viewport||this.viewport&&b>=this.viewport[0]&&b<this.viewport[0]+this.viewport[2]&&c>=this.viewport[1]&&c<this.viewport[1]+this.viewport[3]){b=[a.canvasX,a.canvasY];var d=this.graph?this.graph.getNodeOnPos(b[0],b[1]):null;if(d){if((d.onDropFile||d.onDropData)&&
|
||||
(b=a.dataTransfer.files)&&b.length)for(c=0;c<b.length;c++){var e=a.dataTransfer.files[0],g=e.name;k.getFileExtension(g);if(d.onDropFile)d.onDropFile(e);if(d.onDropData){var h=new FileReader;h.onload=function(a){d.onDropData(a.target.result,g,e)};var f=e.type.split("/")[0];"text"==f||""==f?h.readAsText(e):"image"==f?h.readAsDataURL(e):h.readAsArrayBuffer(e)}}return d.onDropItem&&d.onDropItem(event)?!0:this.onDropItem?this.onDropItem(event):!1}b=null;this.onDropItem&&(b=this.onDropItem(event));b||this.checkDropItem(a)}};
|
||||
k.prototype.checkDropItem=function(a){if(a.dataTransfer.files.length){var b=a.dataTransfer.files[0],c=k.getFileExtension(b.name).toLowerCase();if(c=f.node_types_by_file_extension[c]){this.graph.beforeChange();c=f.createNode(c.type);c.pos=[a.canvasX,a.canvasY];this.graph.add(c);if(c.onDropFile)c.onDropFile(b);this.graph.afterChange()}}};k.prototype.processNodeDblClicked=function(a){if(this.onShowNodePanel)this.onShowNodePanel(a);else this.showShowNodePanel(a);if(this.onNodeDblClicked)this.onNodeDblClicked(a);
|
||||
this.setDirty(!0)};k.prototype.processNodeSelected=function(a,b){this.selectNode(a,b&&(b.shiftKey||b.ctrlKey));if(this.onNodeSelected)this.onNodeSelected(a)};k.prototype.selectNode=function(a,b){null==a?this.deselectAllNodes():this.selectNodes([a],b)};k.prototype.selectNodes=function(a,b){b||this.deselectAllNodes();a=a||this.graph._nodes;"string"==typeof a&&(a=[a]);for(var c in a)if(b=a[c],!b.is_selected){if(!b.is_selected&&b.onSelected)b.onSelected();b.is_selected=!0;this.selected_nodes[b.id]=b;
|
||||
if(b.inputs)for(var d=0;d<b.inputs.length;++d)this.highlighted_links[b.inputs[d].link]=!0;if(b.outputs)for(d=0;d<b.outputs.length;++d){var e=b.outputs[d];if(e.links)for(var g=0;g<e.links.length;++g)this.highlighted_links[e.links[g]]=!0}}if(this.onSelectionChange)this.onSelectionChange(this.selected_nodes);this.setDirty(!0)};k.prototype.deselectNode=function(a){if(a.is_selected){if(a.onDeselected)a.onDeselected();a.is_selected=!1;if(this.onNodeDeselected)this.onNodeDeselected(a);if(a.inputs)for(var b=
|
||||
0;b<a.inputs.length;++b)delete this.highlighted_links[a.inputs[b].link];if(a.outputs)for(b=0;b<a.outputs.length;++b){var c=a.outputs[b];if(c.links)for(var d=0;d<c.links.length;++d)delete this.highlighted_links[c.links[d]]}}};k.prototype.deselectAllNodes=function(){if(this.graph){for(var a=this.graph._nodes,b=0,c=a.length;b<c;++b){var d=a[b];if(d.is_selected){if(d.onDeselected)d.onDeselected();d.is_selected=!1;if(this.onNodeDeselected)this.onNodeDeselected(d)}}this.selected_nodes={};this.current_node=
|
||||
null;this.highlighted_links={};if(this.onSelectionChange)this.onSelectionChange(this.selected_nodes);this.setDirty(!0)}};k.prototype.deleteSelectedNodes=function(){this.graph.beforeChange();for(var a in this.selected_nodes){var b=this.selected_nodes[a];if(!b.block_delete){if(b.inputs&&b.inputs.length&&b.outputs&&b.outputs.length&&f.isValidConnection(b.inputs[0].type,b.outputs[0].type)&&b.inputs[0].link&&b.outputs[0].links&&b.outputs[0].links.length){var c=b.graph.links[b.inputs[0].link],d=b.graph.links[b.outputs[0].links[0]],
|
||||
e=b.getInputNode(0),g=b.getOutputNodes(0)[0];e&&g&&e.connect(c.origin_slot,g,d.target_slot)}this.graph.remove(b);if(this.onNodeDeselected)this.onNodeDeselected(b)}}this.selected_nodes={};this.current_node=null;this.highlighted_links={};this.setDirty(!0);this.graph.afterChange()};k.prototype.centerOnNode=function(a){this.ds.offset[0]=-a.pos[0]-.5*a.size[0]+.5*this.canvas.width/this.ds.scale;this.ds.offset[1]=-a.pos[1]-.5*a.size[1]+.5*this.canvas.height/this.ds.scale;this.setDirty(!0,!0)};k.prototype.adjustMouseEvent=
|
||||
function(a){if(this.canvas){var b=this.canvas.getBoundingClientRect();var c=a.clientX-b.left;b=a.clientY-b.top}else c=a.clientX,b=a.clientY;this.last_mouse_position[0]=c;this.last_mouse_position[1]=b;a.canvasX=c/this.ds.scale-this.ds.offset[0];a.canvasY=b/this.ds.scale-this.ds.offset[1]};k.prototype.setZoom=function(a,b){this.ds.changeScale(a,b);this.dirty_bgcanvas=this.dirty_canvas=!0};k.prototype.convertOffsetToCanvas=function(a,b){return this.ds.convertOffsetToCanvas(a,b)};k.prototype.convertCanvasToOffset=
|
||||
function(a,b){return this.ds.convertCanvasToOffset(a,b)};k.prototype.convertEventToCanvasOffset=function(a){var b=this.canvas.getBoundingClientRect();return this.convertCanvasToOffset([a.clientX-b.left,a.clientY-b.top])};k.prototype.bringToFront=function(a){var b=this.graph._nodes.indexOf(a);-1!=b&&(this.graph._nodes.splice(b,1),this.graph._nodes.push(a))};k.prototype.sendToBack=function(a){var b=this.graph._nodes.indexOf(a);-1!=b&&(this.graph._nodes.splice(b,1),this.graph._nodes.unshift(a))};var z=
|
||||
new Float32Array(4);k.prototype.computeVisibleNodes=function(a,b){b=b||[];b.length=0;a=a||this.graph._nodes;for(var c=0,d=a.length;c<d;++c){var e=a[c];(!this.live_mode||e.onDrawBackground||e.onDrawForeground)&&B(this.visible_area,e.getBounding(z))&&b.push(e)}return b};k.prototype.draw=function(a,b){if(this.canvas&&0!=this.canvas.width&&0!=this.canvas.height){var c=f.getTime();this.render_time=.001*(c-this.last_draw_time);this.last_draw_time=c;this.graph&&this.ds.computeVisibleArea(this.viewport);
|
||||
(this.dirty_bgcanvas||b||this.always_render_background||this.graph&&this.graph._last_trigger_time&&1E3>c-this.graph._last_trigger_time)&&this.drawBackCanvas();(this.dirty_canvas||a)&&this.drawFrontCanvas();this.fps=this.render_time?1/this.render_time:0;this.frame+=1}};k.prototype.drawFrontCanvas=function(){this.dirty_canvas=!1;this.ctx||(this.ctx=this.bgcanvas.getContext("2d"));var a=this.ctx;if(a){var b=this.canvas;a.start2D&&!this.viewport&&(a.start2D(),a.restore(),a.setTransform(1,0,0,1,0,0));
|
||||
var c=this.viewport||this.dirty_area;c&&(a.save(),a.beginPath(),a.rect(c[0],c[1],c[2],c[3]),a.clip());this.clear_background&&(c?a.clearRect(c[0],c[1],c[2],c[3]):a.clearRect(0,0,b.width,b.height));this.bgcanvas==this.canvas?this.drawBackCanvas():a.drawImage(this.bgcanvas,0,0);if(this.onRender)this.onRender(b,a);this.show_info&&this.renderInfo(a,c?c[0]:0,c?c[1]:0);if(this.graph){a.save();this.ds.toCanvasContext(a);b=this.computeVisibleNodes(null,this.visible_nodes);for(var d=0;d<b.length;++d){var e=
|
||||
b[d];a.save();a.translate(e.pos[0],e.pos[1]);this.drawNode(e,a);a.restore()}this.render_execution_order&&this.drawExecutionOrder(a);this.graph.config.links_ontop&&(this.live_mode||this.drawConnections(a));if(null!=this.connecting_pos){a.lineWidth=this.connections_width;e=this.connecting_output||this.connecting_input;b=e.type;d=e.dir;null==d&&(d=this.connecting_output?this.connecting_node.horizontal?f.DOWN:f.RIGHT:this.connecting_node.horizontal?f.UP:f.LEFT);var g=e.shape;switch(b){case f.EVENT:e=
|
||||
f.EVENT_LINK_COLOR;break;default:e=f.CONNECTING_LINK_COLOR}this.renderLink(a,this.connecting_pos,[this.graph_mouse[0],this.graph_mouse[1]],null,!1,null,e,d,f.CENTER);a.beginPath();b===f.EVENT||g===f.BOX_SHAPE?(a.rect(this.connecting_pos[0]-6+.5,this.connecting_pos[1]-5+.5,14,10),a.fill(),a.beginPath(),a.rect(this.graph_mouse[0]-6+.5,this.graph_mouse[1]-5+.5,14,10)):g===f.ARROW_SHAPE?(a.moveTo(this.connecting_pos[0]+8,this.connecting_pos[1]+.5),a.lineTo(this.connecting_pos[0]-4,this.connecting_pos[1]+
|
||||
6+.5),a.lineTo(this.connecting_pos[0]-4,this.connecting_pos[1]-6+.5),a.closePath()):(a.arc(this.connecting_pos[0],this.connecting_pos[1],4,0,2*Math.PI),a.fill(),a.beginPath(),a.arc(this.graph_mouse[0],this.graph_mouse[1],4,0,2*Math.PI));a.fill();a.fillStyle="#ffcc00";if(this._highlight_input){a.beginPath();var h=this._highlight_input_slot.shape;h===f.ARROW_SHAPE?(a.moveTo(this._highlight_input[0]+8,this._highlight_input[1]+.5),a.lineTo(this._highlight_input[0]-4,this._highlight_input[1]+6+.5),a.lineTo(this._highlight_input[0]-
|
||||
4,this._highlight_input[1]-6+.5),a.closePath()):a.arc(this._highlight_input[0],this._highlight_input[1],6,0,2*Math.PI);a.fill()}this._highlight_output&&(a.beginPath(),h===f.ARROW_SHAPE?(a.moveTo(this._highlight_output[0]+8,this._highlight_output[1]+.5),a.lineTo(this._highlight_output[0]-4,this._highlight_output[1]+6+.5),a.lineTo(this._highlight_output[0]-4,this._highlight_output[1]-6+.5),a.closePath()):a.arc(this._highlight_output[0],this._highlight_output[1],6,0,2*Math.PI),a.fill())}this.dragging_rectangle&&
|
||||
(a.strokeStyle="#FFF",a.strokeRect(this.dragging_rectangle[0],this.dragging_rectangle[1],this.dragging_rectangle[2],this.dragging_rectangle[3]));if(this.over_link_center&&this.render_link_tooltip)this.drawLinkTooltip(a,this.over_link_center);else if(this.onDrawLinkTooltip)this.onDrawLinkTooltip(a,null);if(this.onDrawForeground)this.onDrawForeground(a,this.visible_rect);a.restore()}this._graph_stack&&this._graph_stack.length&&this.drawSubgraphPanel(a);if(this.onDrawOverlay)this.onDrawOverlay(a);c&&
|
||||
a.restore();a.finish2D&&a.finish2D()}};k.prototype.drawSubgraphPanel=function(a){var b=this.graph,c=b._subgraph_node;c?(this.drawSubgraphPanelLeft(b,c,a),this.drawSubgraphPanelRight(b,c,a)):console.warn("subgraph without subnode")};k.prototype.drawSubgraphPanelLeft=function(a,b,c){var d=b.inputs?b.inputs.length:0,e=Math.floor(1.6*f.NODE_SLOT_HEIGHT);c.fillStyle="#111";c.globalAlpha=.8;c.beginPath();c.roundRect(10,10,200,(d+1)*e+50,[8]);c.fill();c.globalAlpha=1;c.fillStyle="#888";c.font="14px Arial";
|
||||
c.textAlign="left";c.fillText("Graph Inputs",20,34);if(this.drawButton(180,20,20,20,"X","#151515"))this.closeSubgraph();else{d=50;c.font="14px Arial";if(b.inputs)for(var g=0;g<b.inputs.length;++g){var h=b.inputs[g];if(!h.not_subgraph_input){if(this.drawButton(20,d+2,180,e-2)){var n=b.constructor.input_node_type||"graph/input";this.graph.beforeChange();var p=f.createNode(n);p?(a.add(p),this.block_click=!1,this.last_click_position=null,this.selectNodes([p]),this.node_dragged=p,this.dragging_canvas=
|
||||
!1,p.setProperty("name",h.name),p.setProperty("type",h.type),this.node_dragged.pos[0]=this.graph_mouse[0]-5,this.node_dragged.pos[1]=this.graph_mouse[1]-5,this.graph.afterChange()):console.error("graph input node not found:",n)}c.fillStyle="#9C9";c.beginPath();c.arc(184,d+.5*e,5,0,2*Math.PI);c.fill();c.fillStyle="#AAA";c.fillText(h.name,30,d+.75*e);c.fillStyle="#777";c.fillText(h.type,130,d+.75*e);d+=e}}this.drawButton(20,d+2,180,e-2,"+","#151515","#222")&&this.showSubgraphPropertiesDialog(b)}};k.prototype.drawSubgraphPanelRight=
|
||||
function(a,b,c){var d=b.outputs?b.outputs.length:0,e=this.bgcanvas.width,g=Math.floor(1.6*f.NODE_SLOT_HEIGHT);c.fillStyle="#111";c.globalAlpha=.8;c.beginPath();c.roundRect(e-200-10,10,200,(d+1)*g+50,[8]);c.fill();c.globalAlpha=1;c.fillStyle="#888";c.font="14px Arial";c.textAlign="left";d=c.measureText("Graph Outputs").width;c.fillText("Graph Outputs",e-d-20,34);if(this.drawButton(e-200,20,20,20,"X","#151515"))this.closeSubgraph();else{d=50;c.font="14px Arial";if(b.outputs)for(var h=0;h<b.outputs.length;++h){var n=
|
||||
b.outputs[h];if(!n.not_subgraph_input){if(this.drawButton(e-200,d+2,180,g-2)){var p=b.constructor.output_node_type||"graph/output";this.graph.beforeChange();var r=f.createNode(p);r?(a.add(r),this.block_click=!1,this.last_click_position=null,this.selectNodes([r]),this.node_dragged=r,this.dragging_canvas=!1,r.setProperty("name",n.name),r.setProperty("type",n.type),this.node_dragged.pos[0]=this.graph_mouse[0]-5,this.node_dragged.pos[1]=this.graph_mouse[1]-5,this.graph.afterChange()):console.error("graph input node not found:",
|
||||
p)}c.fillStyle="#9C9";c.beginPath();c.arc(e-200+16,d+.5*g,5,0,2*Math.PI);c.fill();c.fillStyle="#AAA";c.fillText(n.name,e-200+30,d+.75*g);c.fillStyle="#777";c.fillText(n.type,e-200+130,d+.75*g);d+=g}}this.drawButton(e-200,d+2,180,g-2,"+","#151515","#222")&&this.showSubgraphPropertiesDialogRight(b)}};k.prototype.drawButton=function(a,b,c,d,e,g,h,n){var p=this.ctx;g=g||f.NODE_DEFAULT_COLOR;h=h||"#555";n=n||f.NODE_TEXT_COLOR;var r=b+f.NODE_TITLE_HEIGHT+2,u=this.mouse,q=f.isInsideRectangle(u[0],u[1],a,
|
||||
r,c,d);r=(u=this.last_click_position)&&f.isInsideRectangle(u[0],u[1],a,r,c,d);p.fillStyle=q?h:g;r&&(p.fillStyle="#AAA");p.beginPath();p.roundRect(a,b,c,d,[4]);p.fill();null!=e&&e.constructor==String&&(p.fillStyle=n,p.textAlign="center",p.font=(.65*d|0)+"px Arial",p.fillText(e,a+.5*c,b+.75*d),p.textAlign="left");a=r&&!this.block_click;r&&this.blockClick();return a};k.prototype.isAreaClicked=function(a,b,c,d,e){var g=this.mouse;f.isInsideRectangle(g[0],g[1],a,b,c,d);b=(a=(g=this.last_click_position)&&
|
||||
f.isInsideRectangle(g[0],g[1],a,b,c,d))&&!this.block_click;a&&e&&this.blockClick();return b};k.prototype.renderInfo=function(a,b,c){b=b||10;c=c||this.canvas.height-80;a.save();a.translate(b,c);a.font="10px Arial";a.fillStyle="#888";a.textAlign="left";this.graph?(a.fillText("T: "+this.graph.globaltime.toFixed(2)+"s",5,13),a.fillText("I: "+this.graph.iteration,5,26),a.fillText("N: "+this.graph._nodes.length+" ["+this.visible_nodes.length+"]",5,39),a.fillText("V: "+this.graph._version,5,52),a.fillText("FPS:"+
|
||||
this.fps.toFixed(2),5,65)):a.fillText("No graph selected",5,13);a.restore()};k.prototype.drawBackCanvas=function(){var a=this.bgcanvas;if(a.width!=this.canvas.width||a.height!=this.canvas.height)a.width=this.canvas.width,a.height=this.canvas.height;this.bgctx||(this.bgctx=this.bgcanvas.getContext("2d"));var b=this.bgctx;b.start&&b.start();var c=this.viewport||[0,0,b.canvas.width,b.canvas.height];this.clear_background&&b.clearRect(c[0],c[1],c[2],c[3]);if(this._graph_stack&&this._graph_stack.length){b.save();
|
||||
c=this.graph._subgraph_node;b.strokeStyle=c.bgcolor;b.lineWidth=10;b.strokeRect(1,1,a.width-2,a.height-2);b.lineWidth=1;b.font="40px Arial";b.textAlign="center";b.fillStyle=c.bgcolor||"#AAA";for(var d="",e=1;e<this._graph_stack.length;++e)d+=this._graph_stack[e]._subgraph_node.getTitle()+" >> ";b.fillText(d+c.getTitle(),.5*a.width,40);b.restore()}c=!1;this.onRenderBackground&&(c=this.onRenderBackground(a,b));this.viewport||(b.restore(),b.setTransform(1,0,0,1,0,0));this.visible_links.length=0;if(this.graph){b.save();
|
||||
this.ds.toCanvasContext(b);if(this.background_image&&.5<this.ds.scale&&!c){b.globalAlpha=this.zoom_modify_alpha?(1-.5/this.ds.scale)*this.editor_alpha:this.editor_alpha;b.imageSmoothingEnabled=b.imageSmoothingEnabled=!1;if(!this._bg_img||this._bg_img.name!=this.background_image){this._bg_img=new Image;this._bg_img.name=this.background_image;this._bg_img.src=this.background_image;var g=this;this._bg_img.onload=function(){g.draw(!0,!0)}}c=null;null==this._pattern&&0<this._bg_img.width?(c=b.createPattern(this._bg_img,
|
||||
"repeat"),this._pattern_img=this._bg_img,this._pattern=c):c=this._pattern;c&&(b.fillStyle=c,b.fillRect(this.visible_area[0],this.visible_area[1],this.visible_area[2],this.visible_area[3]),b.fillStyle="transparent");b.globalAlpha=1;b.imageSmoothingEnabled=b.imageSmoothingEnabled=!0}this.graph._groups.length&&!this.live_mode&&this.drawGroups(a,b);if(this.onDrawBackground)this.onDrawBackground(b,this.visible_area);this.onBackgroundRender&&(console.error("WARNING! onBackgroundRender deprecated, now is named onDrawBackground "),
|
||||
this.onBackgroundRender=null);this.render_canvas_border&&(b.strokeStyle="#235",b.strokeRect(0,0,a.width,a.height));this.render_connections_shadows?(b.shadowColor="#000",b.shadowOffsetX=0,b.shadowOffsetY=0,b.shadowBlur=6):b.shadowColor="rgba(0,0,0,0)";this.live_mode||this.drawConnections(b);b.shadowColor="rgba(0,0,0,0)";b.restore()}b.finish&&b.finish();this.dirty_bgcanvas=!1;this.dirty_canvas=!0};var H=new Float32Array(2);k.prototype.drawNode=function(a,b){this.current_node=a;var c=a.color||a.constructor.color||
|
||||
f.NODE_DEFAULT_COLOR,d=a.bgcolor||a.constructor.bgcolor||f.NODE_DEFAULT_BGCOLOR,e=.6>this.ds.scale;if(this.live_mode){if(!a.flags.collapsed&&(b.shadowColor="transparent",a.onDrawForeground))a.onDrawForeground(b,this,this.canvas)}else{var g=this.editor_alpha;b.globalAlpha=g;this.render_shadows&&!e?(b.shadowColor=f.DEFAULT_SHADOW_COLOR,b.shadowOffsetX=2*this.ds.scale,b.shadowOffsetY=2*this.ds.scale,b.shadowBlur=3*this.ds.scale):b.shadowColor="transparent";if(!a.flags.collapsed||!a.onDrawCollapsed||
|
||||
1!=a.onDrawCollapsed(b,this)){var h=a._shape||f.BOX_SHAPE;H.set(a.size);var n=a.horizontal;if(a.flags.collapsed){b.font=this.inner_text_font;var p=a.getTitle?a.getTitle():a.title;null!=p&&(a._collapsed_width=Math.min(a.size[0],b.measureText(p).width+2*f.NODE_TITLE_HEIGHT),H[0]=a._collapsed_width,H[1]=0)}a.clip_area&&(b.save(),b.beginPath(),h==f.BOX_SHAPE?b.rect(0,0,H[0],H[1]):h==f.ROUND_SHAPE?b.roundRect(0,0,H[0],H[1],[10]):h==f.CIRCLE_SHAPE&&b.arc(.5*H[0],.5*H[1],.5*H[0],0,2*Math.PI),b.clip());a.has_errors&&
|
||||
(d="red");this.drawNodeShape(a,b,H,c,d,a.is_selected,a.mouseOver);b.shadowColor="transparent";if(a.onDrawForeground)a.onDrawForeground(b,this,this.canvas);b.textAlign=n?"center":"left";b.font=this.inner_text_font;d=!e;var r=this.connecting_output;h=this.connecting_input;b.lineWidth=1;p=0;var u=new Float32Array(2);if(!a.flags.collapsed){if(a.inputs)for(c=0;c<a.inputs.length;c++){var q=a.inputs[c],y=q.type,k=q.shape;b.globalAlpha=g;this.connecting_output&&!f.isValidConnection(q.type,r.type)&&(b.globalAlpha=
|
||||
.4*g);b.fillStyle=null!=q.link?q.color_on||this.default_connection_color_byType[y]||this.default_connection_color.input_on:q.color_off||this.default_connection_color_byTypeOff[y]||this.default_connection_color_byType[y]||this.default_connection_color.input_off;var v=a.getConnectionPos(!0,c,u);v[0]-=a.pos[0];v[1]-=a.pos[1];p<v[1]+.5*f.NODE_SLOT_HEIGHT&&(p=v[1]+.5*f.NODE_SLOT_HEIGHT);b.beginPath();"array"==y&&(k=f.GRID_SHAPE);q.type===f.EVENT||q.shape===f.BOX_SHAPE?n?b.rect(v[0]-5+.5,v[1]-8+.5,10,14):
|
||||
b.rect(v[0]-6+.5,v[1]-5+.5,14,10):k===f.ARROW_SHAPE?(b.moveTo(v[0]+8,v[1]+.5),b.lineTo(v[0]-4,v[1]+6+.5),b.lineTo(v[0]-4,v[1]-6+.5),b.closePath()):k===f.GRID_SHAPE?(b.rect(v[0]-4,v[1]-4,2,2),b.rect(v[0]-1,v[1]-4,2,2),b.rect(v[0]+2,v[1]-4,2,2),b.rect(v[0]-4,v[1]-1,2,2),b.rect(v[0]-1,v[1]-1,2,2),b.rect(v[0]+2,v[1]-1,2,2),b.rect(v[0]-4,v[1]+2,2,2),b.rect(v[0]-1,v[1]+2,2,2),b.rect(v[0]+2,v[1]+2,2,2)):e?b.rect(v[0]-4,v[1]-4,8,8):b.arc(v[0],v[1],4,0,2*Math.PI);b.fill();d&&(y=null!=q.label?q.label:q.name)&&
|
||||
(b.fillStyle=f.NODE_TEXT_COLOR,n||q.dir==f.UP?b.fillText(y,v[0],v[1]-10):b.fillText(y,v[0]+10,v[1]+5))}b.textAlign=n?"center":"right";b.strokeStyle="black";if(a.outputs)for(c=0;c<a.outputs.length;c++)if(q=a.outputs[c],y=q.type,k=q.shape,this.connecting_input&&!f.isValidConnection(y,h.type)&&(b.globalAlpha=.4*g),v=a.getConnectionPos(!1,c,u),v[0]-=a.pos[0],v[1]-=a.pos[1],p<v[1]+.5*f.NODE_SLOT_HEIGHT&&(p=v[1]+.5*f.NODE_SLOT_HEIGHT),b.fillStyle=q.links&&q.links.length?q.color_on||this.default_connection_color_byType[y]||
|
||||
this.default_connection_color.output_on:q.color_off||this.default_connection_color_byTypeOff[y]||this.default_connection_color_byType[y]||this.default_connection_color.output_off,b.beginPath(),"array"==y&&(k=f.GRID_SHAPE),r=!0,y===f.EVENT||k===f.BOX_SHAPE?n?b.rect(v[0]-5+.5,v[1]-8+.5,10,14):b.rect(v[0]-6+.5,v[1]-5+.5,14,10):k===f.ARROW_SHAPE?(b.moveTo(v[0]+8,v[1]+.5),b.lineTo(v[0]-4,v[1]+6+.5),b.lineTo(v[0]-4,v[1]-6+.5),b.closePath()):k===f.GRID_SHAPE?(b.rect(v[0]-4,v[1]-4,2,2),b.rect(v[0]-1,v[1]-
|
||||
4,2,2),b.rect(v[0]+2,v[1]-4,2,2),b.rect(v[0]-4,v[1]-1,2,2),b.rect(v[0]-1,v[1]-1,2,2),b.rect(v[0]+2,v[1]-1,2,2),b.rect(v[0]-4,v[1]+2,2,2),b.rect(v[0]-1,v[1]+2,2,2),b.rect(v[0]+2,v[1]+2,2,2),r=!1):e?b.rect(v[0]-4,v[1]-4,8,8):b.arc(v[0],v[1],4,0,2*Math.PI),b.fill(),!e&&r&&b.stroke(),d&&(y=null!=q.label?q.label:q.name))b.fillStyle=f.NODE_TEXT_COLOR,n||q.dir==f.DOWN?b.fillText(y,v[0],v[1]-8):b.fillText(y,v[0]-10,v[1]+5);b.textAlign="left";b.globalAlpha=1;if(a.widgets){q=p;if(n||a.widgets_up)q=2;null!=
|
||||
a.widgets_start_y&&(q=a.widgets_start_y);this.drawNodeWidgets(a,q,b,this.node_widget&&this.node_widget[0]==a?this.node_widget[1]:null)}}else if(this.render_collapsed_slots){e=g=null;if(a.inputs)for(c=0;c<a.inputs.length;c++)if(q=a.inputs[c],null!=q.link){g=q;break}if(a.outputs)for(c=0;c<a.outputs.length;c++)q=a.outputs[c],q.links&&q.links.length&&(e=q);g&&(g=0,c=-.5*f.NODE_TITLE_HEIGHT,n&&(g=.5*a._collapsed_width,c=-f.NODE_TITLE_HEIGHT),b.fillStyle="#686",b.beginPath(),q.type===f.EVENT||q.shape===
|
||||
f.BOX_SHAPE?b.rect(g-7+.5,c-4,14,8):q.shape===f.ARROW_SHAPE?(b.moveTo(g+8,c),b.lineTo(g+-4,c-4),b.lineTo(g+-4,c+4),b.closePath()):b.arc(g,c,4,0,2*Math.PI),b.fill());e&&(g=a._collapsed_width,c=-.5*f.NODE_TITLE_HEIGHT,n&&(g=.5*a._collapsed_width,c=0),b.fillStyle="#686",b.strokeStyle="black",b.beginPath(),q.type===f.EVENT||q.shape===f.BOX_SHAPE?b.rect(g-7+.5,c-4,14,8):q.shape===f.ARROW_SHAPE?(b.moveTo(g+6,c),b.lineTo(g-6,c-4),b.lineTo(g-6,c+4),b.closePath()):b.arc(g,c,4,0,2*Math.PI),b.fill())}a.clip_area&&
|
||||
b.restore();b.globalAlpha=1}}};k.prototype.drawLinkTooltip=function(a,b){var c=b._pos;a.fillStyle="black";a.beginPath();a.arc(c[0],c[1],3,0,2*Math.PI);a.fill();if(null!=b.data&&(!this.onDrawLinkTooltip||1!=this.onDrawLinkTooltip(a,b,this))&&(b=b.data,b=b.constructor===Number?b.toFixed(2):b.constructor===String?'"'+b+'"':b.constructor===Boolean?String(b):b.toToolTip?b.toToolTip():"["+b.constructor.name+"]",null!=b)){b=b.substr(0,30);a.font="14px Courier New";var d=a.measureText(b).width+20;a.shadowColor=
|
||||
"black";a.shadowOffsetX=2;a.shadowOffsetY=2;a.shadowBlur=3;a.fillStyle="#454";a.beginPath();a.roundRect(c[0]-.5*d,c[1]-15-24,d,24,[3]);a.moveTo(c[0]-10,c[1]-15);a.lineTo(c[0]+10,c[1]-15);a.lineTo(c[0],c[1]-5);a.fill();a.shadowColor="transparent";a.textAlign="center";a.fillStyle="#CEC";a.fillText(b,c[0],c[1]-15-24*.3)}};var C=new Float32Array(4);k.prototype.drawNodeShape=function(a,b,c,d,e,g,h){b.strokeStyle=d;b.fillStyle=e;e=f.NODE_TITLE_HEIGHT;var n=.5>this.ds.scale,p=a._shape||a.constructor.shape||
|
||||
f.ROUND_SHAPE,r=a.constructor.title_mode,u=!0;r==f.TRANSPARENT_TITLE||r==f.NO_TITLE?u=!1:r==f.AUTOHIDE_TITLE&&h&&(u=!0);C[0]=0;C[1]=u?-e:0;C[2]=c[0]+1;C[3]=u?c[1]+e:c[1];h=b.globalAlpha;b.beginPath();p==f.BOX_SHAPE||n?b.fillRect(C[0],C[1],C[2],C[3]):p==f.ROUND_SHAPE||p==f.CARD_SHAPE?b.roundRect(C[0],C[1],C[2],C[3],p==f.CARD_SHAPE?[this.round_radius,this.round_radius,0,0]:[this.round_radius]):p==f.CIRCLE_SHAPE&&b.arc(.5*c[0],.5*c[1],.5*c[0],0,2*Math.PI);b.fill();!a.flags.collapsed&&u&&(b.shadowColor=
|
||||
"transparent",b.fillStyle="rgba(0,0,0,0.2)",b.fillRect(0,-1,C[2],2));b.shadowColor="transparent";if(a.onDrawBackground)a.onDrawBackground(b,this,this.canvas,this.graph_mouse);if(u||r==f.TRANSPARENT_TITLE){if(a.onDrawTitleBar)a.onDrawTitleBar(b,e,c,this.ds.scale,d);else if(r!=f.TRANSPARENT_TITLE&&(a.constructor.title_color||this.render_title_colored)){u=a.constructor.title_color||d;a.flags.collapsed&&(b.shadowColor=f.DEFAULT_SHADOW_COLOR);if(this.use_gradients){var q=k.gradients[u];q||(q=k.gradients[u]=
|
||||
b.createLinearGradient(0,0,400,0),q.addColorStop(0,u),q.addColorStop(1,"#000"));b.fillStyle=q}else b.fillStyle=u;b.beginPath();p==f.BOX_SHAPE||n?b.rect(0,-e,c[0]+1,e):(p==f.ROUND_SHAPE||p==f.CARD_SHAPE)&&b.roundRect(0,-e,c[0]+1,e,a.flags.collapsed?[this.round_radius]:[this.round_radius,this.round_radius,0,0]);b.fill();b.shadowColor="transparent"}u=!1;f.node_box_coloured_by_mode&&f.NODE_MODES_COLORS[a.mode]&&(u=f.NODE_MODES_COLORS[a.mode]);f.node_box_coloured_when_on&&(u=a.action_triggered?"#FFF":
|
||||
a.execute_triggered?"#AAA":u);if(a.onDrawTitleBox)a.onDrawTitleBox(b,e,c,this.ds.scale);else p==f.ROUND_SHAPE||p==f.CIRCLE_SHAPE||p==f.CARD_SHAPE?(n&&(b.fillStyle="black",b.beginPath(),b.arc(.5*e,-.5*e,6,0,2*Math.PI),b.fill()),b.fillStyle=a.boxcolor||u||f.NODE_DEFAULT_BOXCOLOR,n?b.fillRect(.5*e-5,-.5*e-5,10,10):(b.beginPath(),b.arc(.5*e,-.5*e,5,0,2*Math.PI),b.fill())):(n&&(b.fillStyle="black",b.fillRect(.5*(e-10)-1,-.5*(e+10)-1,12,12)),b.fillStyle=a.boxcolor||u||f.NODE_DEFAULT_BOXCOLOR,b.fillRect(.5*
|
||||
(e-10),-.5*(e+10),10,10));b.globalAlpha=h;if(a.onDrawTitleText)a.onDrawTitleText(b,e,c,this.ds.scale,this.title_text_font,g);!n&&(b.font=this.title_text_font,h=String(a.getTitle()))&&(b.fillStyle=g?f.NODE_SELECTED_TITLE_COLOR:a.constructor.title_text_color||this.node_title_color,a.flags.collapsed?(b.textAlign="left",b.measureText(h),b.fillText(h.substr(0,20),e,f.NODE_TITLE_TEXT_Y-e),b.textAlign="left"):(b.textAlign="left",b.fillText(h,e,f.NODE_TITLE_TEXT_Y-e)));a.flags.collapsed||!a.subgraph||a.skip_subgraph_button||
|
||||
(h=f.NODE_TITLE_HEIGHT,u=a.size[0]-h,q=f.isInsideRectangle(this.graph_mouse[0]-a.pos[0],this.graph_mouse[1]-a.pos[1],u+2,-h+2,h-4,h-4),b.fillStyle=q?"#888":"#555",p==f.BOX_SHAPE||n?b.fillRect(u+2,-h+2,h-4,h-4):(b.beginPath(),b.roundRect(u+2,-h+2,h-4,h-4,[4]),b.fill()),b.fillStyle="#333",b.beginPath(),b.moveTo(u+.2*h,.6*-h),b.lineTo(u+.8*h,.6*-h),b.lineTo(u+.5*h,.3*-h),b.fill());if(a.onDrawTitle)a.onDrawTitle(b)}if(g){if(a.onBounding)a.onBounding(C);r==f.TRANSPARENT_TITLE&&(C[1]-=e,C[3]+=e);b.lineWidth=
|
||||
1;b.globalAlpha=.8;b.beginPath();p==f.BOX_SHAPE?b.rect(-6+C[0],-6+C[1],12+C[2],12+C[3]):p==f.ROUND_SHAPE||p==f.CARD_SHAPE&&a.flags.collapsed?b.roundRect(-6+C[0],-6+C[1],12+C[2],12+C[3],[2*this.round_radius]):p==f.CARD_SHAPE?b.roundRect(-6+C[0],-6+C[1],12+C[2],12+C[3],[2*this.round_radius,2,2*this.round_radius,2]):p==f.CIRCLE_SHAPE&&b.arc(.5*c[0],.5*c[1],.5*c[0]+6,0,2*Math.PI);b.strokeStyle=f.NODE_BOX_OUTLINE_COLOR;b.stroke();b.strokeStyle=d;b.globalAlpha=1}0<a.execute_triggered&&a.execute_triggered--;
|
||||
0<a.action_triggered&&a.action_triggered--};var L=new Float32Array(4),G=new Float32Array(4),K=new Float32Array(2),J=new Float32Array(2);k.prototype.drawConnections=function(a){var b=f.getTime(),c=this.visible_area;L[0]=c[0]-20;L[1]=c[1]-20;L[2]=c[2]+40;L[3]=c[3]+40;a.lineWidth=this.connections_width;a.fillStyle="#AAA";a.strokeStyle="#AAA";a.globalAlpha=this.editor_alpha;c=this.graph._nodes;for(var d=0,e=c.length;d<e;++d){var g=c[d];if(g.inputs&&g.inputs.length)for(var h=0;h<g.inputs.length;++h){var n=
|
||||
g.inputs[h];if(n&&null!=n.link&&(n=this.graph.links[n.link])){var p=this.graph.getNodeById(n.origin_id);if(null!=p){var r=n.origin_slot;var u=-1==r?[p.pos[0]+10,p.pos[1]+10]:p.getConnectionPos(!1,r,K);var q=g.getConnectionPos(!0,h,J);G[0]=u[0];G[1]=u[1];G[2]=q[0]-u[0];G[3]=q[1]-u[1];0>G[2]&&(G[0]+=G[2],G[2]=Math.abs(G[2]));0>G[3]&&(G[1]+=G[3],G[3]=Math.abs(G[3]));if(B(G,L)){var y=p.outputs[r];r=g.inputs[h];if(y&&r&&(p=y.dir||(p.horizontal?f.DOWN:f.RIGHT),r=r.dir||(g.horizontal?f.UP:f.LEFT),this.renderLink(a,
|
||||
u,q,n,!1,0,null,p,r),n&&n._last_time&&1E3>b-n._last_time)){y=2-.002*(b-n._last_time);var k=a.globalAlpha;a.globalAlpha=k*y;this.renderLink(a,u,q,n,!0,y,"white",p,r);a.globalAlpha=k}}}}}}a.globalAlpha=1};k.prototype.renderLink=function(a,b,c,d,e,g,h,n,p,r){d&&this.visible_links.push(d);!h&&d&&(h=d.color||k.link_type_colors[d.type]);h||(h=this.default_link_color);null!=d&&this.highlighted_links[d.id]&&(h="#FFF");n=n||f.RIGHT;p=p||f.LEFT;var u=E(b,c);this.render_connections_border&&.6<this.ds.scale&&
|
||||
(a.lineWidth=this.connections_width+4);a.lineJoin="round";r=r||1;1<r&&(a.lineWidth=.5);a.beginPath();for(var q=0;q<r;q+=1){var y=5*(q-.5*(r-1));if(this.links_render_mode==f.SPLINE_LINK){a.moveTo(b[0],b[1]+y);var l=0,v=0,m=0,w=0;switch(n){case f.LEFT:l=-.25*u;break;case f.RIGHT:l=.25*u;break;case f.UP:v=-.25*u;break;case f.DOWN:v=.25*u}switch(p){case f.LEFT:m=-.25*u;break;case f.RIGHT:m=.25*u;break;case f.UP:w=-.25*u;break;case f.DOWN:w=.25*u}a.bezierCurveTo(b[0]+l,b[1]+v+y,c[0]+m,c[1]+w+y,c[0],c[1]+
|
||||
y)}else if(this.links_render_mode==f.LINEAR_LINK){a.moveTo(b[0],b[1]+y);w=m=v=l=0;switch(n){case f.LEFT:l=-1;break;case f.RIGHT:l=1;break;case f.UP:v=-1;break;case f.DOWN:v=1}switch(p){case f.LEFT:m=-1;break;case f.RIGHT:m=1;break;case f.UP:w=-1;break;case f.DOWN:w=1}a.lineTo(b[0]+15*l,b[1]+15*v+y);a.lineTo(c[0]+15*m,c[1]+15*w+y);a.lineTo(c[0],c[1]+y)}else if(this.links_render_mode==f.STRAIGHT_LINK)a.moveTo(b[0],b[1]),y=b[0],l=b[1],v=c[0],m=c[1],n==f.RIGHT?y+=10:l+=10,p==f.LEFT?v-=10:m-=10,a.lineTo(y,
|
||||
l),a.lineTo(.5*(y+v),l),a.lineTo(.5*(y+v),m),a.lineTo(v,m),a.lineTo(c[0],c[1]);else return}this.render_connections_border&&.6<this.ds.scale&&!e&&(a.strokeStyle="rgba(0,0,0,0.5)",a.stroke());a.lineWidth=this.connections_width;a.fillStyle=a.strokeStyle=h;a.stroke();e=this.computeConnectionPoint(b,c,.5,n,p);d&&d._pos&&(d._pos[0]=e[0],d._pos[1]=e[1]);.6<=this.ds.scale&&this.highquality_render&&p!=f.CENTER&&(this.render_connection_arrows&&(q=this.computeConnectionPoint(b,c,.25,n,p),u=this.computeConnectionPoint(b,
|
||||
c,.26,n,p),d=this.computeConnectionPoint(b,c,.75,n,p),r=this.computeConnectionPoint(b,c,.76,n,p),this.render_curved_connections?(u=-Math.atan2(u[0]-q[0],u[1]-q[1]),r=-Math.atan2(r[0]-d[0],r[1]-d[1])):r=u=c[1]>b[1]?0:Math.PI,a.save(),a.translate(q[0],q[1]),a.rotate(u),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore(),a.save(),a.translate(d[0],d[1]),a.rotate(r),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore()),a.beginPath(),a.arc(e[0],e[1],
|
||||
5,0,2*Math.PI),a.fill());if(g)for(a.fillStyle=h,q=0;5>q;++q)g=(.001*f.getTime()+.2*q)%1,e=this.computeConnectionPoint(b,c,g,n,p),a.beginPath(),a.arc(e[0],e[1],5,0,2*Math.PI),a.fill()};k.prototype.computeConnectionPoint=function(a,b,c,d,e){d=d||f.RIGHT;e=e||f.LEFT;var g=E(a,b),h=[a[0],a[1]],n=[b[0],b[1]];switch(d){case f.LEFT:h[0]+=-.25*g;break;case f.RIGHT:h[0]+=.25*g;break;case f.UP:h[1]+=-.25*g;break;case f.DOWN:h[1]+=.25*g}switch(e){case f.LEFT:n[0]+=-.25*g;break;case f.RIGHT:n[0]+=.25*g;break;
|
||||
case f.UP:n[1]+=-.25*g;break;case f.DOWN:n[1]+=.25*g}d=(1-c)*(1-c)*(1-c);e=3*(1-c)*(1-c)*c;g=3*(1-c)*c*c;c*=c*c;return[d*a[0]+e*h[0]+g*n[0]+c*b[0],d*a[1]+e*h[1]+g*n[1]+c*b[1]]};k.prototype.drawExecutionOrder=function(a){a.shadowColor="transparent";a.globalAlpha=.25;a.textAlign="center";a.strokeStyle="white";a.globalAlpha=.75;for(var b=this.visible_nodes,c=0;c<b.length;++c){var d=b[c];a.fillStyle="black";a.fillRect(d.pos[0]-f.NODE_TITLE_HEIGHT,d.pos[1]-f.NODE_TITLE_HEIGHT,f.NODE_TITLE_HEIGHT,f.NODE_TITLE_HEIGHT);
|
||||
0==d.order&&a.strokeRect(d.pos[0]-f.NODE_TITLE_HEIGHT+.5,d.pos[1]-f.NODE_TITLE_HEIGHT+.5,f.NODE_TITLE_HEIGHT,f.NODE_TITLE_HEIGHT);a.fillStyle="#FFF";a.fillText(d.order,d.pos[0]+-.5*f.NODE_TITLE_HEIGHT,d.pos[1]-6)}a.globalAlpha=1};k.prototype.drawNodeWidgets=function(a,b,c,d){if(!a.widgets||!a.widgets.length)return 0;var e=a.size[0],g=a.widgets;b+=2;var h=f.NODE_WIDGET_HEIGHT,n=.5<this.ds.scale;c.save();c.globalAlpha=this.editor_alpha;for(var p=f.WIDGET_OUTLINE_COLOR,r=f.WIDGET_BGCOLOR,u=f.WIDGET_TEXT_COLOR,
|
||||
q=f.WIDGET_SECONDARY_TEXT_COLOR,y=0;y<g.length;++y){var k=g[y],v=b;k.y&&(v=k.y);k.last_y=v;c.strokeStyle=p;c.fillStyle="#222";c.textAlign="left";k.disabled&&(c.globalAlpha*=.5);var l=k.width||e;switch(k.type){case "button":k.clicked&&(c.fillStyle="#AAA",k.clicked=!1,this.dirty_canvas=!0);c.fillRect(15,v,l-30,h);n&&!k.disabled&&c.strokeRect(15,v,l-30,h);n&&(c.textAlign="center",c.fillStyle=u,c.fillText(k.name,.5*l,v+.7*h));break;case "toggle":c.textAlign="left";c.strokeStyle=p;c.fillStyle=r;c.beginPath();
|
||||
n?c.roundRect(15,v,l-30,h,[.5*h]):c.rect(15,v,l-30,h);c.fill();n&&!k.disabled&&c.stroke();c.fillStyle=k.value?"#89A":"#333";c.beginPath();c.arc(l-30,v+.5*h,.36*h,0,2*Math.PI);c.fill();n&&(c.fillStyle=q,null!=k.name&&c.fillText(k.name,30,v+.7*h),c.fillStyle=k.value?u:q,c.textAlign="right",c.fillText(k.value?k.options.on||"true":k.options.off||"false",l-40,v+.7*h));break;case "slider":c.fillStyle=r;c.fillRect(15,v,l-30,h);var m=k.options.max-k.options.min,w=(k.value-k.options.min)/m;c.fillStyle=d==
|
||||
k?"#89A":"#678";c.fillRect(15,v,w*(l-30),h);n&&!k.disabled&&c.strokeRect(15,v,l-30,h);k.marker&&(m=(k.marker-k.options.min)/m,c.fillStyle="#AA9",c.fillRect(15+m*(l-30),v,2,h));n&&(c.textAlign="center",c.fillStyle=u,c.fillText(k.name+" "+Number(k.value).toFixed(3),.5*l,v+.7*h));break;case "number":case "combo":c.textAlign="left";c.strokeStyle=p;c.fillStyle=r;c.beginPath();n?c.roundRect(15,v,l-30,h,[.5*h]):c.rect(15,v,l-30,h);c.fill();n&&(k.disabled||c.stroke(),c.fillStyle=u,k.disabled||(c.beginPath(),
|
||||
c.moveTo(31,v+5),c.lineTo(21,v+.5*h),c.lineTo(31,v+h-5),c.fill(),c.beginPath(),c.moveTo(l-15-16,v+5),c.lineTo(l-15-6,v+.5*h),c.lineTo(l-15-16,v+h-5),c.fill()),c.fillStyle=q,c.fillText(k.name,35,v+.7*h),c.fillStyle=u,c.textAlign="right","number"==k.type?c.fillText(Number(k.value).toFixed(void 0!==k.options.precision?k.options.precision:3),l-30-20,v+.7*h):(m=k.value,k.options.values&&(w=k.options.values,w.constructor===Function&&(w=w()),w&&w.constructor!==Array&&(m=w[k.value])),c.fillText(m,l-30-20,
|
||||
v+.7*h)));break;case "string":case "text":c.textAlign="left";c.strokeStyle=p;c.fillStyle=r;c.beginPath();n?c.roundRect(15,v,l-30,h,[.5*h]):c.rect(15,v,l-30,h);c.fill();n&&(k.disabled||c.stroke(),c.save(),c.beginPath(),c.rect(15,v,l-30,h),c.clip(),c.fillStyle=q,null!=k.name&&c.fillText(k.name,30,v+.7*h),c.fillStyle=u,c.textAlign="right",c.fillText(String(k.value).substr(0,30),l-30,v+.7*h),c.restore());break;default:k.draw&&k.draw(c,a,l,v,h)}b+=(k.computeSize?k.computeSize(l)[1]:h)+4;c.globalAlpha=
|
||||
this.editor_alpha}c.restore();c.textAlign="left"};k.prototype.processNodeWidgets=function(a,b,c,d){function e(d,e){d.value=e;d.options&&d.options.property&&void 0!==a.properties[d.options.property]&&a.setProperty(d.options.property,e);d.callback&&d.callback(d.value,k,a,b,c)}if(!a.widgets||!a.widgets.length)return null;for(var g=b[0]-a.pos[0],h=b[1]-a.pos[1],n=a.size[0],k=this,r=this.getCanvasWindow(),u=0;u<a.widgets.length;++u){var q=a.widgets[u];if(q&&!q.disabled){var y=q.computeSize?q.computeSize(n)[1]:
|
||||
f.NODE_WIDGET_HEIGHT,l=q.width||n;if(q==d||!(6>g||g>l-12||h<q.last_y||h>q.last_y+y||void 0===q.last_y)){d=q.value;switch(q.type){case "button":c.type===f.pointerevents_method+"down"&&(q.callback&&setTimeout(function(){q.callback(q,k,a,b,c)},20),this.dirty_canvas=q.clicked=!0);break;case "slider":r=Math.clamp((g-15)/(l-30),0,1);q.value=q.options.min+(q.options.max-q.options.min)*r;q.callback&&setTimeout(function(){e(q,q.value)},20);this.dirty_canvas=!0;break;case "number":case "combo":d=q.value;if(c.type==
|
||||
f.pointerevents_method+"move"&&"number"==q.type)c.deltaX&&(q.value+=.1*c.deltaX*(q.options.step||1)),null!=q.options.min&&q.value<q.options.min&&(q.value=q.options.min),null!=q.options.max&&q.value>q.options.max&&(q.value=q.options.max);else if(c.type==f.pointerevents_method+"down"){var v=q.options.values;v&&v.constructor===Function&&(v=q.options.values(q,a));var m=null;"number"!=q.type&&(m=v.constructor===Array?v:Object.keys(v));g=40>g?-1:g>l-40?1:0;if("number"==q.type)q.value+=.1*g*(q.options.step||
|
||||
1),null!=q.options.min&&q.value<q.options.min&&(q.value=q.options.min),null!=q.options.max&&q.value>q.options.max&&(q.value=q.options.max);else if(g)r=-1,this.last_mouseclick=0,r=v.constructor===Object?m.indexOf(String(q.value))+g:m.indexOf(q.value)+g,r>=m.length&&(r=m.length-1),0>r&&(r=0),q.value=v.constructor===Array?v[r]:r;else{var w=v!=m?Object.values(v):v;new f.ContextMenu(w,{scale:Math.max(1,this.ds.scale),event:c,className:"dark",callback:function(a,b,c){v!=m&&(a=w.indexOf(a));this.value=a;
|
||||
e(this,a);k.dirty_canvas=!0;return!1}.bind(q)},r)}}else c.type==f.pointerevents_method+"up"&&"number"==q.type&&(g=40>g?-1:g>l-40?1:0,200>c.click_time&&0==g&&this.prompt("Value",q.value,function(a){this.value=Number(a);e(this,this.value)}.bind(q),c));d!=q.value&&setTimeout(function(){e(this,this.value)}.bind(q),20);this.dirty_canvas=!0;break;case "toggle":c.type==f.pointerevents_method+"down"&&(q.value=!q.value,setTimeout(function(){e(q,q.value)},20));break;case "string":case "text":c.type==f.pointerevents_method+
|
||||
"down"&&this.prompt("Value",q.value,function(a){this.value=a;e(this,a)}.bind(q),c,q.options?q.options.multiline:!1);break;default:q.mouse&&(this.dirty_canvas=q.mouse(c,[g,h],a))}if(d!=q.value){if(a.onWidgetChanged)a.onWidgetChanged(q.name,q.value,d,q);a.graph._version++}return q}}}return null};k.prototype.drawGroups=function(a,b){if(this.graph){a=this.graph._groups;b.save();b.globalAlpha=.5*this.editor_alpha;for(var c=0;c<a.length;++c){var d=a[c];if(B(this.visible_area,d._bounding)){b.fillStyle=d.color||
|
||||
"#335";b.strokeStyle=d.color||"#335";var e=d._pos,g=d._size;b.globalAlpha=.25*this.editor_alpha;b.beginPath();b.rect(e[0]+.5,e[1]+.5,g[0],g[1]);b.fill();b.globalAlpha=this.editor_alpha;b.stroke();b.beginPath();b.moveTo(e[0]+g[0],e[1]+g[1]);b.lineTo(e[0]+g[0]-10,e[1]+g[1]);b.lineTo(e[0]+g[0],e[1]+g[1]-10);b.fill();g=d.font_size||f.DEFAULT_GROUP_FONT_SIZE;b.font=g+"px Arial";b.textAlign="left";b.fillText(d.title,e[0]+4,e[1]+g)}}b.restore()}};k.prototype.adjustNodesSize=function(){for(var a=this.graph._nodes,
|
||||
b=0;b<a.length;++b)a[b].size=a[b].computeSize();this.setDirty(!0,!0)};k.prototype.resize=function(a,b){a||b||(b=this.canvas.parentNode,a=b.offsetWidth,b=b.offsetHeight);if(this.canvas.width!=a||this.canvas.height!=b)this.canvas.width=a,this.canvas.height=b,this.bgcanvas.width=this.canvas.width,this.bgcanvas.height=this.canvas.height,this.setDirty(!0,!0)};k.prototype.switchLiveMode=function(a){if(a){var b=this,c=this.live_mode?1.1:.9;this.live_mode&&(this.live_mode=!1,this.editor_alpha=.1);var d=setInterval(function(){b.editor_alpha*=
|
||||
c;b.dirty_canvas=!0;b.dirty_bgcanvas=!0;1>c&&.01>b.editor_alpha&&(clearInterval(d),1>c&&(b.live_mode=!0));1<c&&.99<b.editor_alpha&&(clearInterval(d),b.editor_alpha=1)},1)}else this.live_mode=!this.live_mode,this.dirty_bgcanvas=this.dirty_canvas=!0};k.prototype.onNodeSelectionChange=function(a){};k.onGroupAdd=function(a,b,c){a=k.active_canvas;a.getCanvasWindow();b=new f.LGraphGroup;b.pos=a.convertEventToCanvasOffset(c);a.graph.add(b)};k.onMenuAdd=function(a,b,c,d,e){function g(a,b){var d=[];f.getNodeTypesCategories(h.filter||
|
||||
p.filter).filter(function(b){return b.startsWith(a)}).map(function(b){if(b){b=b.replace(new RegExp("^("+a+")"),"").split("/")[0];var c=""===a?b+"/":a+b+"/";-1!=b.indexOf("::")&&(b=b.split("::")[1]);-1===d.findIndex(function(a){return a.value===c})&&d.push({value:c,content:b,has_submenu:!0,callback:function(a,b,c,d){g(a.value,d)}})}});f.getNodeTypesInCategory(a.slice(0,-1),h.filter||p.filter).map(function(a){a.skip_list||d.push({value:a.type,content:a.title,has_submenu:!1,callback:function(a,b,c,d){b=
|
||||
d.getFirstEvent();h.graph.beforeChange();if(a=f.createNode(a.value))a.pos=h.convertEventToCanvasOffset(b),h.graph.add(a);e&&e(a);h.graph.afterChange()}})});new f.ContextMenu(d,{event:c,parentMenu:b},n)}var h=k.active_canvas,n=h.getCanvasWindow(),p=h.graph;if(p)return g("",d),!1};k.onMenuCollapseAll=function(){};k.onMenuNodeEdit=function(){};k.showMenuNodeOptionalInputs=function(a,b,c,d,e){if(e){var g=this;a=k.active_canvas.getCanvasWindow();b=e.optional_inputs;e.onGetInputs&&(b=e.onGetInputs());var h=
|
||||
[];if(b)for(var n=0;n<b.length;n++){var p=b[n];if(p){var r=p[0];p[2]||(p[2]={});p[2].label&&(r=p[2].label);p[2].removable=!0;r={content:r,value:p};p[1]==f.ACTION&&(r.className="event");h.push(r)}else h.push(null)}e.onMenuNodeInputs&&(b=e.onMenuNodeInputs(h))&&(h=b);if(h.length)return new f.ContextMenu(h,{event:c,callback:function(a,b,c){if(e&&(a.callback&&a.callback.call(g,e,a,b,c),a.value)){e.graph.beforeChange();e.addInput(a.value[0],a.value[1],a.value[2]);if(e.onNodeInputAdd)e.onNodeInputAdd(a.value);
|
||||
e.setDirtyCanvas(!0,!0);e.graph.afterChange()}},parentMenu:d,node:e},a),!1;console.log("no input entries")}};k.showMenuNodeOptionalOutputs=function(a,b,c,d,e){function g(a,b,c){if(e&&(a.callback&&a.callback.call(h,e,a,b,c),a.value))if(c=a.value[1],!c||c.constructor!==Object&&c.constructor!==Array){e.graph.beforeChange();e.addOutput(a.value[0],a.value[1],a.value[2]);if(e.onNodeOutputAdd)e.onNodeOutputAdd(a.value);e.setDirtyCanvas(!0,!0);e.graph.afterChange()}else{a=[];for(var r in c)a.push({content:r,
|
||||
value:c[r]});new f.ContextMenu(a,{event:b,callback:g,parentMenu:d,node:e});return!1}}if(e){var h=this;a=k.active_canvas.getCanvasWindow();b=e.optional_outputs;e.onGetOutputs&&(b=e.onGetOutputs());var n=[];if(b)for(var p=0;p<b.length;p++){var r=b[p];if(!r)n.push(null);else if(!e.flags||!e.flags.skip_repeated_outputs||-1==e.findOutputSlot(r[0])){var u=r[0];r[2]||(r[2]={});r[2].label&&(u=r[2].label);r[2].removable=!0;u={content:u,value:r};r[1]==f.EVENT&&(u.className="event");n.push(u)}}this.onMenuNodeOutputs&&
|
||||
(n=this.onMenuNodeOutputs(n));f.do_add_triggers_slots&&-1==e.findOutputSlot("onExecuted")&&n.push({content:"On Executed",value:["onExecuted",f.EVENT,{nameLocked:!0}],className:"event"});e.onMenuNodeOutputs&&(b=e.onMenuNodeOutputs(n))&&(n=b);if(n.length)return new f.ContextMenu(n,{event:c,callback:g,parentMenu:d,node:e},a),!1}};k.onShowMenuNodeProperties=function(a,b,c,d,e){if(e&&e.properties){var g=k.active_canvas;b=g.getCanvasWindow();var h=[],n;for(n in e.properties){a=void 0!==e.properties[n]?
|
||||
e.properties[n]:" ";"object"==typeof a&&(a=JSON.stringify(a));var p=e.getPropertyInfo(n);if("enum"==p.type||"combo"==p.type)a=k.getPropertyPrintableValue(a,p.values);a=k.decodeHTML(a);h.push({content:"<span class='property_name'>"+(p.label?p.label:n)+"</span><span class='property_value'>"+a+"</span>",value:n})}if(h.length)return new f.ContextMenu(h,{event:c,callback:function(a,b,c,d){e&&(b=this.getBoundingClientRect(),g.showEditPropertyValue(e,a.value,{position:[b.left,b.top]}))},parentMenu:d,allow_html:!0,
|
||||
node:e},b),!1}};k.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};k.onMenuResizeNode=function(a,b,c,d,e){if(e){a=function(a){a.size=a.computeSize();if(a.onResize)a.onResize(a.size)};b=k.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)a(e);else for(var g in b.selected_nodes)a(b.selected_nodes[g]);e.setDirtyCanvas(!0,!0)}};k.prototype.showLinkMenu=function(a,b){var c=this,d=c.graph.getNodeById(a.origin_id),e=c.graph.getNodeById(a.target_id),
|
||||
g=!1;d&&d.outputs&&d.outputs[a.origin_slot]&&(g=d.outputs[a.origin_slot].type);var h=!1;e&&e.outputs&&e.outputs[a.target_slot]&&(h=e.inputs[a.target_slot].type);var n=new f.ContextMenu(["Add Node",null,"Delete",null],{event:b,title:null!=a.data?a.data.constructor.name:null,callback:function(b,r,f){switch(b){case "Add Node":k.onMenuAdd(null,null,f,n,function(b){b.inputs&&b.inputs.length&&b.outputs&&b.outputs.length&&d.connectByType(a.origin_slot,b,g)&&(b.connectByType(a.target_slot,e,h),b.pos[0]-=
|
||||
.5*b.size[0])});break;case "Delete":c.graph.removeLink(a.id)}}});return!1};k.prototype.createDefaultNodeForSlot=function(a){a=a||{};a=Object.assign({nodeFrom:null,slotFrom:null,nodeTo:null,slotTo:null,position:[],nodeType:null,posAdd:[0,0],posSizeFix:[0,0]},a);var b=a.nodeFrom&&null!==a.slotFrom,c=!b&&a.nodeTo&&null!==a.slotTo;if(!b&&!c)return console.warn("No data passed to createDefaultNodeForSlot "+a.nodeFrom+" "+a.slotFrom+" "+a.nodeTo+" "+a.slotTo),!1;if(!a.nodeType)return console.warn("No type to createDefaultNodeForSlot"),
|
||||
!1;var d=b?a.nodeFrom:a.nodeTo,e=b?a.slotFrom:a.slotTo;switch(typeof e){case "string":c=b?d.findOutputSlot(e,!1):d.findInputSlot(e,!1);e=b?d.outputs[e]:d.inputs[e];break;case "object":c=b?d.findOutputSlot(e.name):d.findInputSlot(e.name);break;case "number":c=e;e=b?d.outputs[e]:d.inputs[e];break;default:return console.warn("Cant get slot information "+e),!1}!1!==e&&!1!==c||console.warn("createDefaultNodeForSlot bad slotX "+e+" "+c);d=e.type==f.EVENT?"_event_":e.type;if((e=b?f.slot_types_default_out:
|
||||
f.slot_types_default_in)&&e[d]){nodeNewType=!1;if("object"==typeof e[d]||"array"==typeof e[d])for(var g in e[d]){if(a.nodeType==e[d][g]||"AUTO"==a.nodeType){nodeNewType=e[d][g];break}}else if(a.nodeType==e[d]||"AUTO"==a.nodeType)nodeNewType=e[d];if(nodeNewType){g=!1;"object"==typeof nodeNewType&&nodeNewType.node&&(g=nodeNewType,nodeNewType=nodeNewType.node);if(e=f.createNode(nodeNewType)){if(g){if(g.properties)for(var h in g.properties)e.addProperty(h,g.properties[h]);if(g.inputs)for(h in e.inputs=
|
||||
[],g.inputs)e.addOutput(g.inputs[h][0],g.inputs[h][1]);if(g.outputs)for(h in e.outputs=[],g.outputs)e.addOutput(g.outputs[h][0],g.outputs[h][1]);g.title&&(e.title=g.title);g.json&&e.configure(g.json)}this.graph.add(e);e.pos=[a.position[0]+a.posAdd[0]+(a.posSizeFix[0]?a.posSizeFix[0]*e.size[0]:0),a.position[1]+a.posAdd[1]+(a.posSizeFix[1]?a.posSizeFix[1]*e.size[1]:0)];b?a.nodeFrom.connectByType(c,e,d):a.nodeTo.connectByTypeOutput(c,e,d);return!0}console.log("failed creating "+nodeNewType)}}return!1};
|
||||
k.prototype.showConnectionMenu=function(a){a=a||{};var b=Object.assign({nodeFrom:null,slotFrom:null,nodeTo:null,slotTo:null,e:null},a),c=this,d=b.nodeFrom&&b.slotFrom;a=!d&&b.nodeTo&&b.slotTo;if(!d&&!a)return console.warn("No data passed to showConnectionMenu"),!1;a=d?b.nodeFrom:b.nodeTo;var e=d?b.slotFrom:b.slotTo,g=!1;switch(typeof e){case "string":g=d?a.findOutputSlot(e,!1):a.findInputSlot(e,!1);e=d?a.outputs[e]:a.inputs[e];break;case "object":g=d?a.findOutputSlot(e.name):a.findInputSlot(e.name);
|
||||
break;case "number":g=e;e=d?a.outputs[e]:a.inputs[e];break;default:return console.warn("Cant get slot information "+e),!1}a=["Add Node",null];c.allow_searchbox&&(a.push("Search"),a.push(null));var h=e.type==f.EVENT?"_event_":e.type,n=d?f.slot_types_default_out:f.slot_types_default_in;if(n&&n[h])if("object"==typeof n[h]||"array"==typeof n[h])for(var p in n[h])a.push(n[h][p]);else a.push(n[h]);var r=new f.ContextMenu(a,{event:b.e,title:(e&&""!=e.name?e.name+(h?" | ":""):"")+(e&&h?h:""),callback:function(a,
|
||||
f,n){switch(a){case "Add Node":k.onMenuAdd(null,null,n,r,function(a){d?b.nodeFrom.connectByType(g,a,h):b.nodeTo.connectByTypeOutput(g,a,h)});break;case "Search":d?c.showSearchBox(n,{node_from:b.nodeFrom,slot_from:e,type_filter_in:h}):c.showSearchBox(n,{node_to:b.nodeTo,slot_from:e,type_filter_out:h});break;default:c.createDefaultNodeForSlot(Object.assign(b,{position:[b.e.canvasX,b.e.canvasY],nodeType:a}))}}});return!1};k.onShowPropertyEditor=function(a,b,c,d,e){function g(){if(p){var b=p.value;"Number"==
|
||||
a.type?b=Number(b):"Boolean"==a.type&&(b=!!b);e[h]=b;n.parentNode&&n.parentNode.removeChild(n);e.setDirtyCanvas(!0,!0)}}var h=a.property||"title";b=e[h];var n=document.createElement("div");n.is_modified=!1;n.className="graphdialog";n.innerHTML="<span class='name'></span><input autofocus type='text' class='value'/><button>OK</button>";n.close=function(){n.parentNode&&n.parentNode.removeChild(n)};n.querySelector(".name").innerText=h;var p=n.querySelector(".value");p&&(p.value=b,p.addEventListener("blur",
|
||||
function(a){this.focus()}),p.addEventListener("keydown",function(a){n.is_modified=!0;if(27==a.keyCode)n.close();else if(13==a.keyCode)g();else if(13!=a.keyCode&&"textarea"!=a.target.localName)return;a.preventDefault();a.stopPropagation()}));b=k.active_canvas.canvas;c=b.getBoundingClientRect();var r=d=-20;c&&(d-=c.left,r-=c.top);event?(n.style.left=event.clientX+d+"px",n.style.top=event.clientY+r+"px"):(n.style.left=.5*b.width+d+"px",n.style.top=.5*b.height+r+"px");n.querySelector("button").addEventListener("click",
|
||||
g);b.parentNode.appendChild(n);p&&p.focus();var u=null;n.addEventListener("mouseleave",function(a){f.dialog_close_on_mouse_leave&&!n.is_modified&&f.dialog_close_on_mouse_leave&&(u=setTimeout(n.close,f.dialog_close_on_mouse_leave_delay))});n.addEventListener("mouseenter",function(a){f.dialog_close_on_mouse_leave&&u&&clearTimeout(u)})};k.prototype.prompt=function(a,b,c,d,e){var g=this;a=a||"";var h=document.createElement("div");h.is_modified=!1;h.className="graphdialog rounded";h.innerHTML=e?"<span class='name'></span> <textarea autofocus class='value'></textarea><button class='rounded'>OK</button>":
|
||||
"<span class='name'></span> <input autofocus type='text' class='value'/><button class='rounded'>OK</button>";h.close=function(){g.prompt_box=null;h.parentNode&&h.parentNode.removeChild(h)};e=k.active_canvas.canvas;e.parentNode.appendChild(h);1<this.ds.scale&&(h.style.transform="scale("+this.ds.scale+")");var n=null,p=!1;f.pointerListenerAdd(h,"leave",function(a){p||f.dialog_close_on_mouse_leave&&!h.is_modified&&f.dialog_close_on_mouse_leave&&(n=setTimeout(h.close,f.dialog_close_on_mouse_leave_delay))});
|
||||
f.pointerListenerAdd(h,"enter",function(a){f.dialog_close_on_mouse_leave&&n&&clearTimeout(n)});var r=h.querySelectorAll("select");r&&r.forEach(function(a){a.addEventListener("click",function(a){p++});a.addEventListener("blur",function(a){p=0});a.addEventListener("change",function(a){p=-1})});g.prompt_box&&g.prompt_box.close();g.prompt_box=h;h.querySelector(".name").innerText=a;var u=h.querySelector(".value");u.value=b;u.addEventListener("keydown",function(a){h.is_modified=!0;if(27==a.keyCode)h.close();
|
||||
else if(13==a.keyCode&&"textarea"!=a.target.localName)c&&c(this.value),h.close();else return;a.preventDefault();a.stopPropagation()});h.querySelector("button").addEventListener("click",function(a){c&&c(u.value);g.setDirty(!0);h.close()});a=e.getBoundingClientRect();r=b=-20;a&&(b-=a.left,r-=a.top);d?(h.style.left=d.clientX+b+"px",h.style.top=d.clientY+r+"px"):(h.style.left=.5*e.width+b+"px",h.style.top=.5*e.height+r+"px");setTimeout(function(){u.focus()},10);return h};k.search_limit=-1;k.prototype.showSearchBox=
|
||||
function(a,b){function c(c){if(c)if(g.onSearchBoxSelection)g.onSearchBoxSelection(c,a,h);else{var d=f.searchbox_extras[c.toLowerCase()];d&&(c=d.type);h.graph.beforeChange();if(c=f.createNode(c))c.pos=h.convertEventToCanvasOffset(a),h.graph.add(c,!1);if(d&&d.data){if(d.data.properties)for(var e in d.data.properties)c.addProperty(e,d.data.properties[e]);if(d.data.inputs)for(e in c.inputs=[],d.data.inputs)c.addOutput(d.data.inputs[e][0],d.data.inputs[e][1]);if(d.data.outputs)for(e in c.outputs=[],d.data.outputs)c.addOutput(d.data.outputs[e][0],
|
||||
d.data.outputs[e][1]);d.data.title&&(c.title=d.data.title);d.data.json&&c.configure(d.data.json)}if(b.node_from){switch(typeof b.slot_from){case "string":d=b.node_from.findOutputSlot(b.slot_from);break;case "object":d=b.slot_from.name?b.node_from.findOutputSlot(b.slot_from.name):-1;-1==d&&"undefined"!==typeof b.slot_from.slot_index&&(d=b.slot_from.slot_index);break;case "number":d=b.slot_from;break;default:d=0}!1!==d&&-1<d&&b.node_from.connectByType(d,c,b.node_from.outputs[d].type)}if(b.node_to){switch(typeof b.slot_from){case "string":d=
|
||||
b.node_to.findInputSlot(b.slot_from);break;case "object":d=b.slot_from.name?b.node_to.findInputSlot(b.slot_from.name):-1;-1==d&&"undefined"!==typeof b.slot_from.slot_index&&(d=b.slot_from.slot_index);break;case "number":d=b.slot_from;break;default:d=0}!1!==d&&-1<d&&b.node_to.connectByTypeOutput(d,c,b.node_to.inputs[d].type)}k.graph.afterChange()}r.close()}function d(a){var b=t;t&&t.classList.remove("selected");t?(t=a?t.nextSibling:t.previousSibling)||(t=b):t=a?v.childNodes[0]:v.childNodes[v.childNodes.length];
|
||||
t&&(t.classList.add("selected"),t.scrollIntoView({block:"end",behavior:"smooth"}))}function e(){function a(a,b){var d=document.createElement("div");m||(m=a);d.innerText=a;d.dataset.type=escape(a);d.className="litegraph lite-search-item";b&&(d.className+=" "+b);d.addEventListener("click",function(a){c(unescape(this.dataset.type))});v.appendChild(d)}w=null;var d=z.value;m=null;v.innerHTML="";if(d||b.show_all_if_empty)if(g.onSearchBox){var e=g.onSearchBox(v,d,k);if(e)for(var r=0;r<e.length;++r)a(e[r])}else{e=
|
||||
b.node_to.findInputSlot(b.slot_from);break;case "object":d=b.slot_from.name?b.node_to.findInputSlot(b.slot_from.name):-1;-1==d&&"undefined"!==typeof b.slot_from.slot_index&&(d=b.slot_from.slot_index);break;case "number":d=b.slot_from;break;default:d=0}!1!==d&&-1<d&&b.node_to.connectByTypeOutput(d,c,b.node_to.inputs[d].type)}h.graph.afterChange()}r.close()}function d(a){var b=t;t&&t.classList.remove("selected");t?(t=a?t.nextSibling:t.previousSibling)||(t=b):t=a?v.childNodes[0]:v.childNodes[v.childNodes.length];
|
||||
t&&(t.classList.add("selected"),t.scrollIntoView({block:"end",behavior:"smooth"}))}function e(){function a(a,b){var d=document.createElement("div");m||(m=a);d.innerText=a;d.dataset.type=escape(a);d.className="litegraph lite-search-item";b&&(d.className+=" "+b);d.addEventListener("click",function(a){c(unescape(this.dataset.type))});v.appendChild(d)}w=null;var d=A.value;m=null;v.innerHTML="";if(d||b.show_all_if_empty)if(g.onSearchBox){var e=g.onSearchBox(v,d,h);if(e)for(var r=0;r<e.length;++r)a(e[r])}else{e=
|
||||
function(a,c){c=c||{};c=Object.assign({skipFilter:!1,inTypeOverride:!1,outTypeOverride:!1},c);var e=f.registered_node_types[a];if(u&&e.filter!=u||(!b.show_all_if_empty||d)&&-1===a.toLowerCase().indexOf(d))return!1;if(b.do_type_filter&&!c.skipFilter){e=y.value;!1!==c.inTypeOverride&&(e=c.inTypeOverride);if(y&&e&&f.registered_slot_in_types[e]&&f.registered_slot_in_types[e].nodes&&(e=f.registered_slot_in_types[e].nodes.includes(a),!1===e))return!1;e=q.value;!1!==c.outTypeOverride&&(e=c.outTypeOverride);
|
||||
if(q&&e&&f.registered_slot_out_types[e]&&f.registered_slot_out_types[e].nodes&&(e=f.registered_slot_out_types[e].nodes.includes(a),!1===e))return!1}return!0};var n=0;d=d.toLowerCase();var u=k.filter||k.graph.filter;if(b.do_type_filter&&g.search_box)var y=g.search_box.querySelector(".slot_in_type_filter"),q=g.search_box.querySelector(".slot_out_type_filter");else q=y=!1;for(r in f.searchbox_extras){var p=f.searchbox_extras[r];if(b.show_all_if_empty&&!d||-1!==p.desc.toLowerCase().indexOf(d)){var l=
|
||||
f.registered_node_types[p.type];if((!l||l.filter==u)&&e(p.type)&&(a(p.desc,"searchbox_extra"),-1!==h.search_limit&&n++>h.search_limit))break}}p=null;if(Array.prototype.filter)p=Object.keys(f.registered_node_types).filter(e);else for(r in p=[],f.registered_node_types)e(r)&&p.push(r);for(r=0;r<p.length&&!(a(p[r]),-1!==h.search_limit&&n++>h.search_limit);r++);if(b.show_general_after_typefiltered&&(y.value||q.value)){filtered_extra=[];for(r in f.registered_node_types)e(r,{inTypeOverride:y&&y.value?"*":
|
||||
!1,outTypeOverride:q&&q.value?"*":!1})&&filtered_extra.push(r);for(r=0;r<filtered_extra.length&&!(a(filtered_extra[r],"generic_type"),-1!==h.search_limit&&n++>h.search_limit);r++);}if((y.value||q.value)&&0==v.childNodes.length&&b.show_general_if_none_on_typefilter){filtered_extra=[];for(r in f.registered_node_types)e(r,{skipFilter:!0})&&filtered_extra.push(r);for(r=0;r<filtered_extra.length&&!(a(filtered_extra[r],"not_in_filter"),-1!==h.search_limit&&n++>h.search_limit);r++);}}}def_options={slot_from:null,
|
||||
node_from:null,node_to:null,do_type_filter:f.search_filter_enabled,type_filter_in:!1,type_filter_out:!1,show_general_if_none_on_typefilter:!0,show_general_after_typefiltered:!0,hide_on_mouse_leave:f.search_hide_on_mouse_leave,show_all_if_empty:!0,show_all_on_open:f.search_show_all_on_open};b=Object.assign(def_options,b||{});var g=this,k=h.active_canvas,n=k.canvas,p=n.ownerDocument||document,r=document.createElement("div");r.className="litegraph litesearchbox graphdialog rounded";r.innerHTML="<span class='name'>Search</span> <input autofocus type='text' class='value rounded'/>";
|
||||
if(q&&e&&f.registered_slot_out_types[e]&&f.registered_slot_out_types[e].nodes&&(e=f.registered_slot_out_types[e].nodes.includes(a),!1===e))return!1}return!0};var n=0;d=d.toLowerCase();var u=h.filter||h.graph.filter;if(b.do_type_filter&&g.search_box)var y=g.search_box.querySelector(".slot_in_type_filter"),q=g.search_box.querySelector(".slot_out_type_filter");else q=y=!1;for(r in f.searchbox_extras){var p=f.searchbox_extras[r];if(b.show_all_if_empty&&!d||-1!==p.desc.toLowerCase().indexOf(d)){var l=
|
||||
f.registered_node_types[p.type];if((!l||l.filter==u)&&e(p.type)&&(a(p.desc,"searchbox_extra"),-1!==k.search_limit&&n++>k.search_limit))break}}p=null;if(Array.prototype.filter)p=Object.keys(f.registered_node_types).filter(e);else for(r in p=[],f.registered_node_types)e(r)&&p.push(r);for(r=0;r<p.length&&!(a(p[r]),-1!==k.search_limit&&n++>k.search_limit);r++);if(b.show_general_after_typefiltered&&(y.value||q.value)){filtered_extra=[];for(r in f.registered_node_types)e(r,{inTypeOverride:y&&y.value?"*":
|
||||
!1,outTypeOverride:q&&q.value?"*":!1})&&filtered_extra.push(r);for(r=0;r<filtered_extra.length&&!(a(filtered_extra[r],"generic_type"),-1!==k.search_limit&&n++>k.search_limit);r++);}if((y.value||q.value)&&0==v.childNodes.length&&b.show_general_if_none_on_typefilter){filtered_extra=[];for(r in f.registered_node_types)e(r,{skipFilter:!0})&&filtered_extra.push(r);for(r=0;r<filtered_extra.length&&!(a(filtered_extra[r],"not_in_filter"),-1!==k.search_limit&&n++>k.search_limit);r++);}}}def_options={slot_from:null,
|
||||
node_from:null,node_to:null,do_type_filter:f.search_filter_enabled,type_filter_in:!1,type_filter_out:!1,show_general_if_none_on_typefilter:!0,show_general_after_typefiltered:!0,hide_on_mouse_leave:f.search_hide_on_mouse_leave,show_all_if_empty:!0,show_all_on_open:f.search_show_all_on_open};b=Object.assign(def_options,b||{});var g=this,h=k.active_canvas,n=h.canvas,p=n.ownerDocument||document,r=document.createElement("div");r.className="litegraph litesearchbox graphdialog rounded";r.innerHTML="<span class='name'>Search</span> <input autofocus type='text' class='value rounded'/>";
|
||||
b.do_type_filter&&(r.innerHTML+="<select class='slot_in_type_filter'><option value=''></option></select>",r.innerHTML+="<select class='slot_out_type_filter'><option value=''></option></select>");r.innerHTML+="<div class='helper'></div>";p.fullscreenElement?p.fullscreenElement.appendChild(r):(p.body.appendChild(r),p.body.style.overflow="hidden");if(b.do_type_filter)var u=r.querySelector(".slot_in_type_filter"),q=r.querySelector(".slot_out_type_filter");r.close=function(){g.search_box=null;this.blur();
|
||||
n.focus();p.body.style.overflow="";setTimeout(function(){g.canvas.focus()},20);r.parentNode&&r.parentNode.removeChild(r)};1<this.ds.scale&&(r.style.transform="scale("+this.ds.scale+")");if(b.hide_on_mouse_leave){var y=!1,l=null;f.pointerListenerAdd(r,"enter",function(a){l&&(clearTimeout(l),l=null)});f.pointerListenerAdd(r,"leave",function(a){y||(l=setTimeout(function(){r.close()},500))});b.do_type_filter&&(u.addEventListener("click",function(a){y++}),u.addEventListener("blur",function(a){y=0}),u.addEventListener("change",
|
||||
function(a){y=-1}),q.addEventListener("click",function(a){y++}),q.addEventListener("blur",function(a){y=0}),q.addEventListener("change",function(a){y=-1}))}g.search_box&&g.search_box.close();g.search_box=r;var v=r.querySelector(".helper"),m=null,w=null,t=null,z=r.querySelector("input");z&&(z.addEventListener("blur",function(a){this.focus()}),z.addEventListener("keydown",function(a){if(38==a.keyCode)d(!1);else if(40==a.keyCode)d(!0);else if(27==a.keyCode)r.close();else if(13==a.keyCode)t?c(t.innerHTML):
|
||||
m?c(m):r.close();else{w&&clearInterval(w);w=setTimeout(e,250);return}a.preventDefault();a.stopPropagation();a.stopImmediatePropagation();return!0}));if(b.do_type_filter){if(u){var x=f.slot_types_in,L=x.length;if(b.type_filter_in==f.EVENT||b.type_filter_in==f.ACTION)b.type_filter_in="_event_";for(var A=0;A<L;A++){var B=document.createElement("option");B.value=x[A];B.innerHTML=x[A];u.appendChild(B);!1!==b.type_filter_in&&(b.type_filter_in+"").toLowerCase()==(x[A]+"").toLowerCase()&&(B.selected=!0)}u.addEventListener("change",
|
||||
function(){e()})}if(q){x=f.slot_types_out;L=x.length;if(b.type_filter_out==f.EVENT||b.type_filter_out==f.ACTION)b.type_filter_out="_event_";for(A=0;A<L;A++)B=document.createElement("option"),B.value=x[A],B.innerHTML=x[A],q.appendChild(B),!1!==b.type_filter_out&&(b.type_filter_out+"").toLowerCase()==(x[A]+"").toLowerCase()&&(B.selected=!0);q.addEventListener("change",function(){e()})}}u=n.getBoundingClientRect();q=(a?a.clientY:u.top+.5*u.height)-20;r.style.left=(a?a.clientX:u.left+.5*u.width)-80+"px";
|
||||
r.style.top=q+"px";a.layerY>u.height-200&&(v.style.maxHeight=u.height-a.layerY-20+"px");z.focus();b.show_all_on_open&&e();return r};h.prototype.showEditPropertyValue=function(a,b,c){function d(){e(q.value)}function e(d){g&&g.values&&g.values.constructor===Object&&void 0!=g.values[d]&&(d=g.values[d]);"number"==typeof a.properties[b]&&(d=Number(d));if("array"==f||"object"==f)d=JSON.parse(d);a.properties[b]=d;a.graph&&a.graph._version++;if(a.onPropertyChanged)a.onPropertyChanged(b,d);if(c.onclose)c.onclose();
|
||||
u.close();a.setDirtyCanvas(!0,!0)}if(a&&void 0!==a.properties[b]){c=c||{};var g=a.getPropertyInfo(b),f=g.type,n="";if("string"==f||"number"==f||"array"==f||"object"==f)n="<input autofocus type='text' class='value'/>";else if("enum"!=f&&"combo"!=f||!g.values)if("boolean"==f||"toggle"==f)n="<input autofocus type='checkbox' class='value' "+(a.properties[b]?"checked":"")+"/>";else{console.warn("unknown type: "+f);return}else{n="<select autofocus type='text' class='value'>";for(var h in g.values){var r=
|
||||
h;g.values.constructor===Array&&(r=g.values[h]);n+="<option value='"+r+"' "+(r==a.properties[b]?"selected":"")+">"+g.values[h]+"</option>"}n+="</select>"}var u=this.createDialog("<span class='name'>"+(g.label?g.label:b)+"</span>"+n+"<button>OK</button>",c),q=!1;if("enum"!=f&&"combo"!=f||!g.values)if("boolean"==f||"toggle"==f)(q=u.querySelector("input"))&&q.addEventListener("click",function(a){u.modified();e(!!q.checked)});else{if(q=u.querySelector("input"))q.addEventListener("blur",function(a){this.focus()}),
|
||||
r=void 0!==a.properties[b]?a.properties[b]:"","string"!==f&&(r=JSON.stringify(r)),q.value=r,q.addEventListener("keydown",function(a){if(27==a.keyCode)u.close();else if(13==a.keyCode)d();else if(13!=a.keyCode){u.modified();return}a.preventDefault();a.stopPropagation()})}else q=u.querySelector("select"),q.addEventListener("change",function(a){u.modified();e(a.target.value)});q&&q.focus();u.querySelector("button").addEventListener("click",d);return u}};h.prototype.createDialog=function(a,b){def_options=
|
||||
function(a){y=-1}),q.addEventListener("click",function(a){y++}),q.addEventListener("blur",function(a){y=0}),q.addEventListener("change",function(a){y=-1}))}g.search_box&&g.search_box.close();g.search_box=r;var v=r.querySelector(".helper"),m=null,w=null,t=null,A=r.querySelector("input");A&&(A.addEventListener("blur",function(a){this.focus()}),A.addEventListener("keydown",function(a){if(38==a.keyCode)d(!1);else if(40==a.keyCode)d(!0);else if(27==a.keyCode)r.close();else if(13==a.keyCode)t?c(t.innerHTML):
|
||||
m?c(m):r.close();else{w&&clearInterval(w);w=setTimeout(e,250);return}a.preventDefault();a.stopPropagation();a.stopImmediatePropagation();return!0}));if(b.do_type_filter){if(u){var x=f.slot_types_in,H=x.length;if(b.type_filter_in==f.EVENT||b.type_filter_in==f.ACTION)b.type_filter_in="_event_";for(var B=0;B<H;B++){var C=document.createElement("option");C.value=x[B];C.innerHTML=x[B];u.appendChild(C);!1!==b.type_filter_in&&(b.type_filter_in+"").toLowerCase()==(x[B]+"").toLowerCase()&&(C.selected=!0)}u.addEventListener("change",
|
||||
function(){e()})}if(q){x=f.slot_types_out;H=x.length;if(b.type_filter_out==f.EVENT||b.type_filter_out==f.ACTION)b.type_filter_out="_event_";for(B=0;B<H;B++)C=document.createElement("option"),C.value=x[B],C.innerHTML=x[B],q.appendChild(C),!1!==b.type_filter_out&&(b.type_filter_out+"").toLowerCase()==(x[B]+"").toLowerCase()&&(C.selected=!0);q.addEventListener("change",function(){e()})}}u=n.getBoundingClientRect();q=(a?a.clientY:u.top+.5*u.height)-20;r.style.left=(a?a.clientX:u.left+.5*u.width)-80+"px";
|
||||
r.style.top=q+"px";a.layerY>u.height-200&&(v.style.maxHeight=u.height-a.layerY-20+"px");A.focus();b.show_all_on_open&&e();return r};k.prototype.showEditPropertyValue=function(a,b,c){function d(){e(q.value)}function e(d){g&&g.values&&g.values.constructor===Object&&void 0!=g.values[d]&&(d=g.values[d]);"number"==typeof a.properties[b]&&(d=Number(d));if("array"==h||"object"==h)d=JSON.parse(d);a.properties[b]=d;a.graph&&a.graph._version++;if(a.onPropertyChanged)a.onPropertyChanged(b,d);if(c.onclose)c.onclose();
|
||||
u.close();a.setDirtyCanvas(!0,!0)}if(a&&void 0!==a.properties[b]){c=c||{};var g=a.getPropertyInfo(b),h=g.type,f="";if("string"==h||"number"==h||"array"==h||"object"==h)f="<input autofocus type='text' class='value'/>";else if("enum"!=h&&"combo"!=h||!g.values)if("boolean"==h||"toggle"==h)f="<input autofocus type='checkbox' class='value' "+(a.properties[b]?"checked":"")+"/>";else{console.warn("unknown type: "+h);return}else{f="<select autofocus type='text' class='value'>";for(var k in g.values){var r=
|
||||
k;g.values.constructor===Array&&(r=g.values[k]);f+="<option value='"+r+"' "+(r==a.properties[b]?"selected":"")+">"+g.values[k]+"</option>"}f+="</select>"}var u=this.createDialog("<span class='name'>"+(g.label?g.label:b)+"</span>"+f+"<button>OK</button>",c),q=!1;if("enum"!=h&&"combo"!=h||!g.values)if("boolean"==h||"toggle"==h)(q=u.querySelector("input"))&&q.addEventListener("click",function(a){u.modified();e(!!q.checked)});else{if(q=u.querySelector("input"))q.addEventListener("blur",function(a){this.focus()}),
|
||||
r=void 0!==a.properties[b]?a.properties[b]:"","string"!==h&&(r=JSON.stringify(r)),q.value=r,q.addEventListener("keydown",function(a){if(27==a.keyCode)u.close();else if(13==a.keyCode)d();else if(13!=a.keyCode){u.modified();return}a.preventDefault();a.stopPropagation()})}else q=u.querySelector("select"),q.addEventListener("change",function(a){u.modified();e(a.target.value)});q&&q.focus();u.querySelector("button").addEventListener("click",d);return u}};k.prototype.createDialog=function(a,b){def_options=
|
||||
{checkForInput:!1,closeOnLeave:!0,closeOnLeave_checkModified:!0};b=Object.assign(def_options,b||{});var c=document.createElement("div");c.className="graphdialog";c.innerHTML=a;c.is_modified=!1;a=this.canvas.getBoundingClientRect();var d=-20,e=-20;a&&(d-=a.left,e-=a.top);b.position?(d+=b.position[0],e+=b.position[1]):b.event?(d+=b.event.clientX,e+=b.event.clientY):(d+=.5*this.canvas.width,e+=.5*this.canvas.height);c.style.left=d+"px";c.style.top=e+"px";this.canvas.parentNode.appendChild(c);b.checkForInput&&
|
||||
(a=[],(a=c.querySelectorAll("input"))&&a.forEach(function(a){a.addEventListener("keydown",function(a){c.modified();if(27==a.keyCode)c.close();else if(13!=a.keyCode)return;a.preventDefault();a.stopPropagation()});a.focus()}));c.modified=function(){c.is_modified=!0};c.close=function(){c.parentNode&&c.parentNode.removeChild(c)};var g=null,k=!1;c.addEventListener("mouseleave",function(a){k||(b.closeOnLeave||f.dialog_close_on_mouse_leave)&&!c.is_modified&&f.dialog_close_on_mouse_leave&&(g=setTimeout(c.close,
|
||||
f.dialog_close_on_mouse_leave_delay))});c.addEventListener("mouseenter",function(a){(b.closeOnLeave||f.dialog_close_on_mouse_leave)&&g&&clearTimeout(g)});(a=c.querySelectorAll("select"))&&a.forEach(function(a){a.addEventListener("click",function(a){k++});a.addEventListener("blur",function(a){k=0});a.addEventListener("change",function(a){k=-1})});return c};h.prototype.createPanel=function(a,b){b=b||{};var c=b.window||window,d=document.createElement("div");d.className="litegraph dialog";d.innerHTML=
|
||||
(a=[],(a=c.querySelectorAll("input"))&&a.forEach(function(a){a.addEventListener("keydown",function(a){c.modified();if(27==a.keyCode)c.close();else if(13!=a.keyCode)return;a.preventDefault();a.stopPropagation()});a.focus()}));c.modified=function(){c.is_modified=!0};c.close=function(){c.parentNode&&c.parentNode.removeChild(c)};var g=null,h=!1;c.addEventListener("mouseleave",function(a){h||(b.closeOnLeave||f.dialog_close_on_mouse_leave)&&!c.is_modified&&f.dialog_close_on_mouse_leave&&(g=setTimeout(c.close,
|
||||
f.dialog_close_on_mouse_leave_delay))});c.addEventListener("mouseenter",function(a){(b.closeOnLeave||f.dialog_close_on_mouse_leave)&&g&&clearTimeout(g)});(a=c.querySelectorAll("select"))&&a.forEach(function(a){a.addEventListener("click",function(a){h++});a.addEventListener("blur",function(a){h=0});a.addEventListener("change",function(a){h=-1})});return c};k.prototype.createPanel=function(a,b){b=b||{};var c=b.window||window,d=document.createElement("div");d.className="litegraph dialog";d.innerHTML=
|
||||
"<div class='dialog-header'><span class='dialog-title'></span></div><div class='dialog-content'></div><div style='display:none;' class='dialog-alt-content'></div><div class='dialog-footer'></div>";d.header=d.querySelector(".dialog-header");b.width&&(d.style.width=b.width+(b.width.constructor===Number?"px":""));b.height&&(d.style.height=b.height+(b.height.constructor===Number?"px":""));b.closable&&(b=document.createElement("span"),b.innerHTML="✕",b.classList.add("close"),b.addEventListener("click",
|
||||
function(){d.close()}),d.header.appendChild(b));d.title_element=d.querySelector(".dialog-title");d.title_element.innerText=a;d.content=d.querySelector(".dialog-content");d.alt_content=d.querySelector(".dialog-alt-content");d.footer=d.querySelector(".dialog-footer");d.close=function(){if(d.onClose&&"function"==typeof d.onClose)d.onClose();d.parentNode.removeChild(d);this.parentNode&&this.parentNode.removeChild(this)};d.toggleAltContent=function(a){if("undefined"!=typeof a){var b=a?"block":"none";a=
|
||||
a?"none":"block"}else b="block"!=d.alt_content.style.display?"block":"none",a="block"!=d.alt_content.style.display?"none":"block";d.alt_content.style.display=b;d.content.style.display=a};d.toggleFooterVisibility=function(a){d.footer.style.display="undefined"!=typeof a?a?"block":"none":"block"!=d.footer.style.display?"block":"none"};d.clear=function(){this.content.innerHTML=""};d.addHTML=function(a,b,c){var e=document.createElement("div");b&&(e.className=b);e.innerHTML=a;c?d.footer.appendChild(e):
|
||||
d.content.appendChild(e);return e};d.addButton=function(a,b,c){var e=document.createElement("button");e.innerText=a;e.options=c;e.classList.add("btn");e.addEventListener("click",b);d.footer.appendChild(e);return e};d.addSeparator=function(){var a=document.createElement("div");a.className="separator";d.content.appendChild(a)};d.addWidget=function(a,b,k,n,p){function e(a,b){n.callback&&n.callback(a,b,n);p&&p(a,b,n)}n=n||{};var g=String(k);a=a.toLowerCase();"number"==a&&(g=k.toFixed(3));var q=document.createElement("div");
|
||||
q.className="property";q.innerHTML="<span class='property_name'></span><span class='property_value'></span>";q.querySelector(".property_name").innerText=n.label||b;var y=q.querySelector(".property_value");y.innerText=g;q.dataset.property=b;q.dataset.type=n.type||a;q.options=n;q.value=k;if("code"==a)q.addEventListener("click",function(a){d.inner_showCodePad(this.dataset.property)});else if("boolean"==a)q.classList.add("boolean"),k&&q.classList.add("bool-on"),q.addEventListener("click",function(){var a=
|
||||
function(){d.close()}),d.header.appendChild(b));d.title_element=d.querySelector(".dialog-title");d.title_element.innerText=a;d.content=d.querySelector(".dialog-content");d.alt_content=d.querySelector(".dialog-alt-content");d.footer=d.querySelector(".dialog-footer");d.close=function(){if(d.onClose&&"function"==typeof d.onClose)d.onClose();d.parentNode&&d.parentNode.removeChild(d);this.parentNode&&this.parentNode.removeChild(this)};d.toggleAltContent=function(a){if("undefined"!=typeof a){var b=a?"block":
|
||||
"none";a=a?"none":"block"}else b="block"!=d.alt_content.style.display?"block":"none",a="block"!=d.alt_content.style.display?"none":"block";d.alt_content.style.display=b;d.content.style.display=a};d.toggleFooterVisibility=function(a){d.footer.style.display="undefined"!=typeof a?a?"block":"none":"block"!=d.footer.style.display?"block":"none"};d.clear=function(){this.content.innerHTML=""};d.addHTML=function(a,b,c){var e=document.createElement("div");b&&(e.className=b);e.innerHTML=a;c?d.footer.appendChild(e):
|
||||
d.content.appendChild(e);return e};d.addButton=function(a,b,c){var e=document.createElement("button");e.innerText=a;e.options=c;e.classList.add("btn");e.addEventListener("click",b);d.footer.appendChild(e);return e};d.addSeparator=function(){var a=document.createElement("div");a.className="separator";d.content.appendChild(a)};d.addWidget=function(a,b,h,n,p){function e(a,b){n.callback&&n.callback(a,b,n);p&&p(a,b,n)}n=n||{};var g=String(h);a=a.toLowerCase();"number"==a&&(g=h.toFixed(3));var q=document.createElement("div");
|
||||
q.className="property";q.innerHTML="<span class='property_name'></span><span class='property_value'></span>";q.querySelector(".property_name").innerText=n.label||b;var y=q.querySelector(".property_value");y.innerText=g;q.dataset.property=b;q.dataset.type=n.type||a;q.options=n;q.value=h;if("code"==a)q.addEventListener("click",function(a){d.inner_showCodePad(this.dataset.property)});else if("boolean"==a)q.classList.add("boolean"),h&&q.classList.add("bool-on"),q.addEventListener("click",function(){var a=
|
||||
this.dataset.property;this.value=!this.value;this.classList.toggle("bool-on");this.querySelector(".property_value").innerText=this.value?"true":"false";e(a,this.value)});else if("string"==a||"number"==a)y.setAttribute("contenteditable",!0),y.addEventListener("keydown",function(b){"Enter"!=b.code||"string"==a&&b.shiftKey||(b.preventDefault(),this.blur())}),y.addEventListener("blur",function(){var a=this.innerText,b=this.parentNode.dataset.property;"number"==this.parentNode.dataset.type&&(a=Number(a));
|
||||
e(b,a)});else if("enum"==a||"combo"==a)g=h.getPropertyPrintableValue(k,n.values),y.innerText=g,y.addEventListener("click",function(a){var b=this.parentNode.dataset.property,d=this;new f.ContextMenu(n.values||[],{event:a,className:"dark",callback:function(a,c,g){d.innerText=a;e(b,a);return!1}},c)});d.content.appendChild(q);return q};if(d.onOpen&&"function"==typeof d.onOpen)d.onOpen();return d};h.getPropertyPrintableValue=function(a,b){if(!b||b.constructor===Array)return String(a);if(b.constructor===
|
||||
Object){var c="",d;for(d in b)if(b[d]==a){c=d;break}return String(a)+" ("+c+")"}};h.prototype.closePanels=function(){var a=document.querySelector("#node-panel");a&&a.close();(a=document.querySelector("#option-panel"))&&a.close()};h.prototype.showShowGraphOptionsPanel=function(a,b,c,d){if(this.constructor&&"HTMLDivElement"==this.constructor.name){if(!(b&&b.event&&b.event.target&&b.event.target.lgraphcanvas)){console.warn("Canvas not found");return}var e=b.event.target.lgraphcanvas}else e=this;e.closePanels();
|
||||
e(b,a)});else if("enum"==a||"combo"==a)g=k.getPropertyPrintableValue(h,n.values),y.innerText=g,y.addEventListener("click",function(a){var b=this.parentNode.dataset.property,d=this;new f.ContextMenu(n.values||[],{event:a,className:"dark",callback:function(a,c,g){d.innerText=a;e(b,a);return!1}},c)});d.content.appendChild(q);return q};if(d.onOpen&&"function"==typeof d.onOpen)d.onOpen();return d};k.getPropertyPrintableValue=function(a,b){if(!b||b.constructor===Array)return String(a);if(b.constructor===
|
||||
Object){var c="",d;for(d in b)if(b[d]==a){c=d;break}return String(a)+" ("+c+")"}};k.prototype.closePanels=function(){var a=document.querySelector("#node-panel");a&&a.close();(a=document.querySelector("#option-panel"))&&a.close()};k.prototype.showShowGraphOptionsPanel=function(a,b,c,d){if(this.constructor&&"HTMLDivElement"==this.constructor.name){if(!(b&&b.event&&b.event.target&&b.event.target.lgraphcanvas)){console.warn("Canvas not found");return}var e=b.event.target.lgraphcanvas}else e=this;e.closePanels();
|
||||
a=e.getCanvasWindow();panel=e.createPanel("Options",{closable:!0,window:a,onOpen:function(){e.OPTIONPANEL_IS_OPEN=!0},onClose:function(){e.OPTIONPANEL_IS_OPEN=!1;e.options_panel=null}});e.options_panel=panel;panel.id="option-panel";panel.classList.add("settings");(function(){panel.content.innerHTML="";var a=function(a,b,c){c&&c.key&&(a=c.key);c.values&&(b=Object.values(c.values).indexOf(b));e[a]=b},b=f.availableCanvasOptions;b.sort();for(pI in b){var c=b[pI];panel.addWidget("boolean",c,e[c],{key:c,
|
||||
on:"True",off:"False"},a)}panel.addWidget("combo","Render mode",f.LINK_RENDER_MODES[e.links_render_mode],{key:"links_render_mode",values:f.LINK_RENDER_MODES},a);panel.addSeparator();panel.footer.innerHTML=""})();e.canvas.parentNode.appendChild(panel)};h.prototype.showShowNodePanel=function(a){function b(){panel.content.innerHTML="";panel.addHTML("<span class='node_type'>"+a.type+"</span><span class='node_desc'>"+(a.constructor.desc||"")+"</span><span class='separator'></span>");panel.addHTML("<h3>Properties</h3>");
|
||||
var b=function(b,c){d.graph.beforeChange(a);switch(b){case "Title":a.title=c;break;case "Mode":b=Object.values(f.NODE_MODES).indexOf(c);0<=b&&f.NODE_MODES[b]?a.changeMode(b):console.warn("unexpected mode: "+c);break;case "Color":h.node_colors[c]?(a.color=h.node_colors[c].color,a.bgcolor=h.node_colors[c].bgcolor):console.warn("unexpected color: "+c);break;default:a.setProperty(b,c)}d.graph.afterChange();d.dirty_canvas=!0};panel.addWidget("string","Title",a.title,{},b);panel.addWidget("combo","Mode",
|
||||
f.NODE_MODES[a.mode],{values:f.NODE_MODES},b);var c="";void 0!==a.color&&(c=Object.keys(h.node_colors).filter(function(b){return h.node_colors[b].color==a.color}));panel.addWidget("combo","Color",c,{values:Object.keys(h.node_colors)},b);for(var k in a.properties){c=a.properties[k];var n=a.getPropertyInfo(k);a.onAddPropertyToPanel&&a.onAddPropertyToPanel(k,panel)||panel.addWidget(n.widget||n.type,k,c,n,b)}panel.addSeparator();if(a.onShowCustomPanelInfo)a.onShowCustomPanelInfo(panel);panel.footer.innerHTML=
|
||||
on:"True",off:"False"},a)}panel.addWidget("combo","Render mode",f.LINK_RENDER_MODES[e.links_render_mode],{key:"links_render_mode",values:f.LINK_RENDER_MODES},a);panel.addSeparator();panel.footer.innerHTML=""})();e.canvas.parentNode.appendChild(panel)};k.prototype.showShowNodePanel=function(a){function b(){panel.content.innerHTML="";panel.addHTML("<span class='node_type'>"+a.type+"</span><span class='node_desc'>"+(a.constructor.desc||"")+"</span><span class='separator'></span>");panel.addHTML("<h3>Properties</h3>");
|
||||
var b=function(b,c){d.graph.beforeChange(a);switch(b){case "Title":a.title=c;break;case "Mode":b=Object.values(f.NODE_MODES).indexOf(c);0<=b&&f.NODE_MODES[b]?a.changeMode(b):console.warn("unexpected mode: "+c);break;case "Color":k.node_colors[c]?(a.color=k.node_colors[c].color,a.bgcolor=k.node_colors[c].bgcolor):console.warn("unexpected color: "+c);break;default:a.setProperty(b,c)}d.graph.afterChange();d.dirty_canvas=!0};panel.addWidget("string","Title",a.title,{},b);panel.addWidget("combo","Mode",
|
||||
f.NODE_MODES[a.mode],{values:f.NODE_MODES},b);var c="";void 0!==a.color&&(c=Object.keys(k.node_colors).filter(function(b){return k.node_colors[b].color==a.color}));panel.addWidget("combo","Color",c,{values:Object.keys(k.node_colors)},b);for(var h in a.properties){c=a.properties[h];var n=a.getPropertyInfo(h);a.onAddPropertyToPanel&&a.onAddPropertyToPanel(h,panel)||panel.addWidget(n.widget||n.type,h,c,n,b)}panel.addSeparator();if(a.onShowCustomPanelInfo)a.onShowCustomPanelInfo(panel);panel.footer.innerHTML=
|
||||
"";panel.addButton("Delete",function(){a.block_delete||(a.graph.remove(a),panel.close())}).classList.add("delete")}this.SELECTED_NODE=a;this.closePanels();var c=this.getCanvasWindow(),d=this;panel=this.createPanel(a.title||"",{closable:!0,window:c,onOpen:function(){d.NODEPANEL_IS_OPEN=!0},onClose:function(){d.NODEPANEL_IS_OPEN=!1;d.node_panel=null}});d.node_panel=panel;panel.id="node-panel";panel.node=a;panel.classList.add("settings");panel.inner_showCodePad=function(c){panel.classList.remove("settings");
|
||||
panel.classList.add("centered");panel.alt_content.innerHTML="<textarea class='code'></textarea>";var d=panel.alt_content.querySelector("textarea"),e=function(){panel.toggleAltContent(!1);panel.toggleFooterVisibility(!0);d.parentNode.removeChild(d);panel.classList.add("settings");panel.classList.remove("centered");b()};d.value=a.properties[c];d.addEventListener("keydown",function(b){"Enter"==b.code&&b.ctrlKey&&(a.setProperty(c,d.value),e())});panel.toggleAltContent(!0);panel.toggleFooterVisibility(!1);
|
||||
d.style.height="calc(100% - 40px)";var f=panel.addButton("Assign",function(){a.setProperty(c,d.value);e()});panel.alt_content.appendChild(f);f=panel.addButton("Close",e);f.style.float="right";panel.alt_content.appendChild(f)};b();this.canvas.parentNode.appendChild(panel)};h.prototype.showSubgraphPropertiesDialog=function(a){function b(){d.clear();if(a.inputs)for(var c=0;c<a.inputs.length;++c){var g=a.inputs[c];if(!g.not_subgraph_input){var f=d.addHTML("<button>✕</button> <span class='bullet_icon'></span><span class='name'></span><span class='type'></span>",
|
||||
d.style.height="calc(100% - 40px)";var f=panel.addButton("Assign",function(){a.setProperty(c,d.value);e()});panel.alt_content.appendChild(f);f=panel.addButton("Close",e);f.style.float="right";panel.alt_content.appendChild(f)};b();this.canvas.parentNode.appendChild(panel)};k.prototype.showSubgraphPropertiesDialog=function(a){function b(){d.clear();if(a.inputs)for(var c=0;c<a.inputs.length;++c){var g=a.inputs[c];if(!g.not_subgraph_input){var f=d.addHTML("<button>✕</button> <span class='bullet_icon'></span><span class='name'></span><span class='type'></span>",
|
||||
"subgraph_property");f.dataset.name=g.name;f.dataset.slot=c;f.querySelector(".name").innerText=g.name;f.querySelector(".type").innerText=g.type;f.querySelector("button").addEventListener("click",function(c){a.removeInput(Number(this.parentNode.dataset.slot));b()})}}}console.log("showing subgraph properties dialog");var c=this.canvas.parentNode.querySelector(".subgraph_dialog");c&&c.close();var d=this.createPanel("Subgraph Inputs",{closable:!0,width:500});d.node=a;d.classList.add("subgraph_dialog");
|
||||
d.addHTML(" + <span class='label'>Name</span><input class='name'/><span class='label'>Type</span><input class='type'></input><button>+</button>","subgraph_property extra",!0).querySelector("button").addEventListener("click",function(c){c=this.parentNode;var d=c.querySelector(".name").value,e=c.querySelector(".type").value;d&&-1==a.findInputSlot(d)&&(a.addInput(d,e),c.querySelector(".name").value="",c.querySelector(".type").value="",b())});b();this.canvas.parentNode.appendChild(d);return d};h.prototype.showSubgraphPropertiesDialogRight=
|
||||
d.addHTML(" + <span class='label'>Name</span><input class='name'/><span class='label'>Type</span><input class='type'></input><button>+</button>","subgraph_property extra",!0).querySelector("button").addEventListener("click",function(c){c=this.parentNode;var d=c.querySelector(".name").value,e=c.querySelector(".type").value;d&&-1==a.findInputSlot(d)&&(a.addInput(d,e),c.querySelector(".name").value="",c.querySelector(".type").value="",b())});b();this.canvas.parentNode.appendChild(d);return d};k.prototype.showSubgraphPropertiesDialogRight=
|
||||
function(a){function b(){e.clear();if(a.outputs)for(var c=0;c<a.outputs.length;++c){var d=a.outputs[c];if(!d.not_subgraph_output){var f=e.addHTML("<button>✕</button> <span class='bullet_icon'></span><span class='name'></span><span class='type'></span>","subgraph_property");f.dataset.name=d.name;f.dataset.slot=c;f.querySelector(".name").innerText=d.name;f.querySelector(".type").innerText=d.type;f.querySelector("button").addEventListener("click",function(c){a.removeOutput(Number(this.parentNode.dataset.slot));
|
||||
b()})}}}function c(){var c=this.parentNode,d=c.querySelector(".name").value,e=c.querySelector(".type").value;d&&-1==a.findOutputSlot(d)&&(a.addOutput(d,e),c.querySelector(".name").value="",c.querySelector(".type").value="",b())}var d=this.canvas.parentNode.querySelector(".subgraph_dialog");d&&d.close();var e=this.createPanel("Subgraph Outputs",{closable:!0,width:500});e.node=a;e.classList.add("subgraph_dialog");d=e.addHTML(" + <span class='label'>Name</span><input class='name'/><span class='label'>Type</span><input class='type'></input><button>+</button>",
|
||||
"subgraph_property extra",!0);d.querySelector(".name").addEventListener("keydown",function(a){13==a.keyCode&&c.apply(this)});d.querySelector("button").addEventListener("click",function(a){c.apply(this)});b();this.canvas.parentNode.appendChild(e);return e};h.prototype.checkPanels=function(){if(this.canvas)for(var a=this.canvas.parentNode.querySelectorAll(".litegraph.dialog"),b=0;b<a.length;++b){var c=a[b];c.node&&(c.node.graph&&c.graph==this.graph||c.close())}};h.onMenuNodeCollapse=function(a,b,c,
|
||||
d,e){e.graph.beforeChange();a=h.active_canvas;if(!a.selected_nodes||1>=Object.keys(a.selected_nodes).length)e.collapse();else for(var f in a.selected_nodes)a.selected_nodes[f].collapse();e.graph.afterChange()};h.onMenuNodePin=function(a,b,c,d,e){e.pin()};h.onMenuNodeMode=function(a,b,c,d,e){new f.ContextMenu(f.NODE_MODES,{event:c,callback:function(a){if(e){var b=Object.values(f.NODE_MODES).indexOf(a),c=function(c){0<=b&&f.NODE_MODES[b]?c.changeMode(b):(console.warn("unexpected mode: "+a),c.changeMode(f.ALWAYS))},
|
||||
d=h.active_canvas;if(!d.selected_nodes||1>=Object.keys(d.selected_nodes).length)c(e);else for(var g in d.selected_nodes)c(d.selected_nodes[g])}},parentMenu:d,node:e});return!1};h.onMenuNodeColors=function(a,b,c,d,e){if(!e)throw"no node for color";b=[];b.push({value:null,content:"<span style='display: block; padding-left: 4px;'>No color</span>"});for(var g in h.node_colors)a=h.node_colors[g],a={value:g,content:"<span style='display: block; color: #999; padding-left: 4px; border-left: 8px solid "+a.color+
|
||||
"; background-color:"+a.bgcolor+"'>"+g+"</span>"},b.push(a);new f.ContextMenu(b,{event:c,callback:function(a){if(e){var b=a.value?h.node_colors[a.value]:null;a=function(a){b?a.constructor===f.LGraphGroup?a.color=b.groupcolor:(a.color=b.color,a.bgcolor=b.bgcolor):(delete a.color,delete a.bgcolor)};var c=h.active_canvas;if(!c.selected_nodes||1>=Object.keys(c.selected_nodes).length)a(e);else for(var d in c.selected_nodes)a(c.selected_nodes[d]);e.setDirtyCanvas(!0,!0)}},parentMenu:d,node:e});return!1};
|
||||
h.onMenuNodeShapes=function(a,b,c,d,e){if(!e)throw"no node passed";new f.ContextMenu(f.VALID_SHAPES,{event:c,callback:function(a){if(e){e.graph.beforeChange();var b=h.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)e.shape=a;else for(var c in b.selected_nodes)b.selected_nodes[c].shape=a;e.graph.afterChange();e.setDirtyCanvas(!0)}},parentMenu:d,node:e});return!1};h.onMenuNodeRemove=function(a,b,c,d,e){if(!e)throw"no node passed";a=e.graph;a.beforeChange();b=h.active_canvas;
|
||||
if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)!1!==e.removable&&a.remove(e);else for(var f in b.selected_nodes)c=b.selected_nodes[f],!1!==c.removable&&a.remove(c);a.afterChange();e.setDirtyCanvas(!0,!0)};h.onMenuNodeToSubgraph=function(a,b,c,d,e){a=e.graph;if(b=h.active_canvas)c=Object.values(b.selected_nodes||{}),c.length||(c=[e]),d=f.createNode("graph/subgraph"),d.pos=e.pos.concat(),a.add(d),d.buildFromNodes(c),b.deselectAllNodes(),e.setDirtyCanvas(!0,!0)};h.onMenuNodeClone=function(a,
|
||||
b,c,d,e){e.graph.beforeChange();var f={};a=function(a){if(0!=a.clonable){var b=a.clone();b&&(b.pos=[a.pos[0]+5,a.pos[1]+5],a.graph.add(b),f[b.id]=b)}};b=h.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)a(e);else for(var k in b.selected_nodes)a(b.selected_nodes[k]);Object.keys(f).length&&b.selectNodes(f);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(){if(this.getMenuOptions)var a=this.getMenuOptions();else a=[{content:"Add Node",
|
||||
has_submenu:!0,callback:h.onMenuAdd},{content:"Add Group",callback:h.onGroupAdd}],this._graph_stack&&0<this._graph_stack.length&&a.push(null,{content:"Close subgraph",callback:this.closeSubgraph.bind(this)});if(this.getExtraMenuOptions){var b=this.getExtraMenuOptions(this,a);b&&(a=a.concat(b))}return a};h.prototype.getNodeMenuOptions=function(a){if(a.getMenuOptions)var b=a.getMenuOptions(this);else b=[{content:"Inputs",has_submenu:!0,disabled:!0,callback:h.showMenuNodeOptionalInputs},{content:"Outputs",
|
||||
has_submenu:!0,disabled:!0,callback:h.showMenuNodeOptionalOutputs},null,{content:"Properties",has_submenu:!0,callback:h.onShowMenuNodeProperties},null,{content:"Title",callback:h.onShowPropertyEditor},{content:"Mode",has_submenu:!0,callback:h.onMenuNodeMode}],!1!==a.resizable&&b.push({content:"Resize",callback:h.onMenuResizeNode}),b.push({content:"Collapse",callback:h.onMenuNodeCollapse},{content:"Pin",callback:h.onMenuNodePin},{content:"Colors",has_submenu:!0,callback:h.onMenuNodeColors},{content:"Shapes",
|
||||
has_submenu:!0,callback:h.onMenuNodeShapes},null);if(a.onGetInputs){var c=a.onGetInputs();c&&c.length&&(b[0].disabled=!1)}a.onGetOutputs&&(c=a.onGetOutputs())&&c.length&&(b[1].disabled=!1);a.getExtraMenuOptions&&(c=a.getExtraMenuOptions(this,b))&&(c.push(null),b=c.concat(b));!1!==a.clonable&&b.push({content:"Clone",callback:h.onMenuNodeClone});b.push(null,{content:"Remove",disabled:!(!1!==a.removable&&!a.block_delete),callback:h.onMenuNodeRemove});if(a.graph&&a.graph.onGetNodeMenuOptions)a.graph.onGetNodeMenuOptions(b,
|
||||
a);return b};h.prototype.getGroupMenuOptions=function(a){return[{content:"Title",callback:h.onShowPropertyEditor},{content:"Color",has_submenu:!0,callback:h.onMenuNodeColors},{content:"Font size",property:"font_size",type:"Number",callback:h.onShowPropertyEditor},null,{content:"Remove",callback:h.onMenuNodeRemove}]};h.prototype.processContextMenu=function(a,b){var c=this,d=h.active_canvas.getCanvasWindow(),e=null,g={event:b,callback:function(b,d,e){if(b)if("Remove Slot"==b.content)b=b.slot,a.graph.beforeChange(),
|
||||
b.input?a.removeInput(b.slot):b.output&&a.removeOutput(b.slot),a.graph.afterChange();else if("Disconnect Links"==b.content)b=b.slot,a.graph.beforeChange(),b.output?a.disconnectOutput(b.slot):b.input&&a.disconnectInput(b.slot),a.graph.afterChange();else if("Rename Slot"==b.content){b=b.slot;var f=b.input?a.getInputInfo(b.slot):a.getOutputInfo(b.slot),g=c.createDialog("<span class='name'>Name</span><input autofocus type='text'/><button>OK</button>",d),r=g.querySelector("input");r&&f&&(r.value=f.label||
|
||||
"");var k=function(){a.graph.beforeChange();r.value&&(f&&(f.label=r.value),c.setDirty(!0));g.close();a.graph.afterChange()};g.querySelector("button").addEventListener("click",k);r.addEventListener("keydown",function(a){g.is_modified=!0;if(27==a.keyCode)g.close();else if(13==a.keyCode)k();else if(13!=a.keyCode&&"textarea"!=a.target.localName)return;a.preventDefault();a.stopPropagation()});r.focus()}},extra:a};a&&(g.title=a.type);var k=null;a&&(k=a.getSlotInPosition(b.canvasX,b.canvasY),h.active_node=
|
||||
a);k?(e=[],a.getSlotMenuOptions?e=a.getSlotMenuOptions(k):(k&&k.output&&k.output.links&&k.output.links.length&&e.push({content:"Disconnect Links",slot:k}),b=k.input||k.output,b.removable&&e.push(b.locked?"Cannot remove":{content:"Remove Slot",slot:k}),b.nameLocked||e.push({content:"Rename Slot",slot:k})),g.title=(k.input?k.input.type:k.output.type)||"*",k.input&&k.input.type==f.ACTION&&(g.title="Action"),k.output&&k.output.type==f.EVENT&&(g.title="Event")):a?e=this.getNodeMenuOptions(a):(e=this.getCanvasMenuOptions(),
|
||||
(k=this.graph.getGroupOnPos(b.canvasX,b.canvasY))&&e.push(null,{content:"Edit Group",has_submenu:!0,submenu:{title:"Group",extra:k,options:this.getGroupMenuOptions(k)}}));e&&new f.ContextMenu(e,g,d)};"undefined"!=typeof window&&window.CanvasRenderingContext2D&&!window.CanvasRenderingContext2D.prototype.roundRect&&(window.CanvasRenderingContext2D.prototype.roundRect=function(a,b,c,d,e,f){var g,h;if(0===e)this.rect(a,b,c,d);else{void 0===f&&(f=e);if(null!=e&&e.constructor===Array)if(1==e.length)var l=
|
||||
g=h=f=e[0];else if(2==e.length)l=f=e[0],g=h=e[1];else if(4==e.length)l=e[0],g=e[1],h=e[2],f=e[3];else return;else l=e||0,g=e||0,h=f||0,f=f||0;this.moveTo(a+l,b);this.lineTo(a+c-g,b);this.quadraticCurveTo(a+c,b,a+c,b+g);this.lineTo(a+c,b+d-f);this.quadraticCurveTo(a+c,b+d,a+c-f,b+d);this.lineTo(a+f,b+d);this.quadraticCurveTo(a,b+d,a,b+d-h);this.lineTo(a,b+h);this.quadraticCurveTo(a,b,a+l,b)}});f.compareObjects=function(a,b){for(var c in a)if(a[c]!=b[c])return!1;return!0};f.distance=D;f.colorToString=
|
||||
function(a){return"rgba("+Math.round(255*a[0]).toFixed()+","+Math.round(255*a[1]).toFixed()+","+Math.round(255*a[2]).toFixed()+","+(4==a.length?a[3].toFixed(2):"1.0")+")"};f.isInsideRectangle=C;f.growBounding=function(a,b,c){b<a[0]?a[0]=b:b>a[2]&&(a[2]=b);c<a[1]?a[1]=c:c>a[3]&&(a[3]=c)};f.isInsideBounding=function(a,b){return a[0]<b[0][0]||a[1]<b[0][1]||a[0]>b[1][0]||a[1]>b[1][1]?!1:!0};f.overlapBounding=A;f.hex2num=function(a){"#"==a.charAt(0)&&(a=a.slice(1));a=a.toUpperCase();for(var b=Array(3),
|
||||
c=0,d,e,f=0;6>f;f+=2)d="0123456789ABCDEF".indexOf(a.charAt(f)),e="0123456789ABCDEF".indexOf(a.charAt(f+1)),b[c]=16*d+e,c++;return b};f.num2hex=function(a){for(var b="#",c,d,e=0;3>e;e++)c=a[e]/16,d=a[e]%16,b+="0123456789ABCDEF".charAt(c)+"0123456789ABCDEF".charAt(d);return b};E.prototype.addItem=function(a,b,c){function d(a){var b=this.value;b&&b.has_submenu&&e.call(this,a)}function e(a){var b=this.value,d=!0;g.current_submenu&&g.current_submenu.close(a);if(c.callback){var e=c.callback.call(this,b,
|
||||
c,a,g,c.node);!0===e&&(d=!1)}if(b&&(b.callback&&!c.ignore_item_callbacks&&!0!==b.disabled&&(e=b.callback.call(this,b,c,a,g,c.extra),!0===e&&(d=!1)),b.submenu)){if(!b.submenu.options)throw"ContextMenu submenu needs options";new g.constructor(b.submenu.options,{callback:b.submenu.callback,event:a,parentMenu:g,ignore_item_callbacks:b.submenu.ignore_item_callbacks,title:b.submenu.title,extra:b.submenu.extra,autoopen:c.autoopen});d=!1}d&&!g.lock&&g.close()}var g=this;c=c||{};var k=document.createElement("div");
|
||||
k.className="litemenu-entry submenu";var h=!1;if(null===b)k.classList.add("separator");else{k.innerHTML=b&&b.title?b.title:a;if(k.value=b)b.disabled&&(h=!0,k.classList.add("disabled")),(b.submenu||b.has_submenu)&&k.classList.add("has_submenu");"function"==typeof b?(k.dataset.value=a,k.onclick_callback=b):k.dataset.value=b;b.className&&(k.className+=" "+b.className)}this.root.appendChild(k);h||k.addEventListener("click",e);c.autoopen&&f.pointerListenerAdd(k,"enter",d);return k};E.prototype.close=function(a,
|
||||
b){this.root.parentNode&&this.root.parentNode.removeChild(this.root);this.parentMenu&&!b&&(this.parentMenu.lock=!1,this.parentMenu.current_submenu=null,void 0===a?this.parentMenu.close():a&&!E.isCursorOverElement(a,this.parentMenu.root)&&E.trigger(this.parentMenu.root,f.pointerevents_method+"leave",a));this.current_submenu&&this.current_submenu.close(a,!0);this.root.closing_timer&&clearTimeout(this.root.closing_timer)};E.trigger=function(a,b,c,d){var e=document.createEvent("CustomEvent");e.initCustomEvent(b,
|
||||
!0,!0,c);e.srcElement=d;a.dispatchEvent?a.dispatchEvent(e):a.__events&&a.__events.dispatchEvent(e);return e};E.prototype.getTopMenu=function(){return this.options.parentMenu?this.options.parentMenu.getTopMenu():this};E.prototype.getFirstEvent=function(){return this.options.parentMenu?this.options.parentMenu.getFirstEvent():this.options.event};E.isCursorOverElement=function(a,b){var c=a.clientX;a=a.clientY;return(b=b.getBoundingClientRect())?a>b.top&&a<b.top+b.height&&c>b.left&&c<b.left+b.width?!0:
|
||||
!1:!1};f.ContextMenu=E;f.closeAllContextMenus=function(a){a=a||window;a=a.document.querySelectorAll(".litecontextmenu");if(a.length){for(var b=[],c=0;c<a.length;c++)b.push(a[c]);for(c=0;c<b.length;c++)b[c].close?b[c].close():b[c].parentNode&&b[c].parentNode.removeChild(b[c])}};f.extendClass=function(a,b){for(var c in b)a.hasOwnProperty(c)||(a[c]=b[c]);if(b.prototype)for(c in b.prototype)b.prototype.hasOwnProperty(c)&&!a.prototype.hasOwnProperty(c)&&(b.prototype.__lookupGetter__(c)?a.prototype.__defineGetter__(c,
|
||||
b.prototype.__lookupGetter__(c)):a.prototype[c]=b.prototype[c],b.prototype.__lookupSetter__(c)&&a.prototype.__defineSetter__(c,b.prototype.__lookupSetter__(c)))};G.sampleCurve=function(a,b){if(b){for(var c=0;c<b.length-1;++c){var d=b[c],e=b[c+1];if(!(e[0]<a)){b=e[0]-d[0];if(1E-5>Math.abs(b))return d[1];a=(a-d[0])/b;return d[1]*(1-a)+e[1]*a}}return 0}};G.prototype.draw=function(a,b,c,d,e,f){if(c=this.points){this.size=b;var g=b[0]-2*this.margin;b=b[1]-2*this.margin;e=e||"#666";a.save();a.translate(this.margin,
|
||||
this.margin);d&&(a.fillStyle="#111",a.fillRect(0,0,g,b),a.fillStyle="#222",a.fillRect(.5*g,0,1,b),a.strokeStyle="#333",a.strokeRect(0,0,g,b));a.strokeStyle=e;f&&(a.globalAlpha=.5);a.beginPath();for(d=0;d<c.length;++d)e=c[d],a.lineTo(e[0]*g,(1-e[1])*b);a.stroke();a.globalAlpha=1;if(!f)for(d=0;d<c.length;++d)e=c[d],a.fillStyle=this.selected==d?"#FFF":this.nearest==d?"#DDD":"#AAA",a.beginPath(),a.arc(e[0]*g,(1-e[1])*b,2,0,2*Math.PI),a.fill();a.restore()}};G.prototype.onMouseDown=function(a,b){var c=
|
||||
this.points;if(c&&!(0>a[1])){var d=this.size[0]-2*this.margin,e=this.size[1]-2*this.margin,f=a[0]-this.margin;a=a[1]-this.margin;this.selected=this.getCloserPoint([f,a],30/b.ds.scale);-1==this.selected&&(b=[f/d,1-a/e],c.push(b),c.sort(function(a,b){return a[0]-b[0]}),this.selected=c.indexOf(b),this.must_update=!0);if(-1!=this.selected)return!0}};G.prototype.onMouseMove=function(a,b){var c=this.points;if(c){var d=this.selected;if(!(0>d)){var e=(a[0]-this.margin)/(this.size[0]-2*this.margin),f=(a[1]-
|
||||
this.margin)/(this.size[1]-2*this.margin);this._nearest=this.getCloserPoint([a[0]-this.margin,a[1]-this.margin],30/b.ds.scale);if(b=c[d]){var k=0==d||d==c.length-1;!k&&(-10>a[0]||a[0]>this.size[0]+10||-10>a[1]||a[1]>this.size[1]+10)?(c.splice(d,1),this.selected=-1):(b[0]=k?0==d?0:1:Math.clamp(e,0,1),b[1]=1-Math.clamp(f,0,1),c.sort(function(a,b){return a[0]-b[0]}),this.selected=c.indexOf(b),this.must_update=!0)}}}};G.prototype.onMouseUp=function(a,b){this.selected=-1;return!1};G.prototype.getCloserPoint=
|
||||
function(a,b){var c=this.points;if(!c)return-1;b=b||30;for(var d=this.size[0]-2*this.margin,e=this.size[1]-2*this.margin,f=c.length,k=[0,0],h=1E6,l=-1,r=0;r<f;++r){var u=c[r];k[0]=u[0]*d;k[1]=(1-u[1])*e;u=vec2.distance(a,k);u>h||u>b||(l=r,h=u)}return l};f.CurveEditor=G;f.getParameterNames=function(a){return(a+"").replace(/[/][/].*$/gm,"").replace(/\s+/g,"").replace(/[/][*][^/*]*[*][/]/g,"").split("){",1)[0].replace(/^[^(]*[(]/,"").replace(/=[^,]+/g,"").split(",").filter(Boolean)};f.pointerListenerAdd=
|
||||
"subgraph_property extra",!0);d.querySelector(".name").addEventListener("keydown",function(a){13==a.keyCode&&c.apply(this)});d.querySelector("button").addEventListener("click",function(a){c.apply(this)});b();this.canvas.parentNode.appendChild(e);return e};k.prototype.checkPanels=function(){if(this.canvas)for(var a=this.canvas.parentNode.querySelectorAll(".litegraph.dialog"),b=0;b<a.length;++b){var c=a[b];c.node&&(c.node.graph&&c.graph==this.graph||c.close())}};k.onMenuNodeCollapse=function(a,b,c,
|
||||
d,e){e.graph.beforeChange();a=k.active_canvas;if(!a.selected_nodes||1>=Object.keys(a.selected_nodes).length)e.collapse();else for(var g in a.selected_nodes)a.selected_nodes[g].collapse();e.graph.afterChange()};k.onMenuNodePin=function(a,b,c,d,e){e.pin()};k.onMenuNodeMode=function(a,b,c,d,e){new f.ContextMenu(f.NODE_MODES,{event:c,callback:function(a){if(e){var b=Object.values(f.NODE_MODES).indexOf(a),c=function(c){0<=b&&f.NODE_MODES[b]?c.changeMode(b):(console.warn("unexpected mode: "+a),c.changeMode(f.ALWAYS))},
|
||||
d=k.active_canvas;if(!d.selected_nodes||1>=Object.keys(d.selected_nodes).length)c(e);else for(var g in d.selected_nodes)c(d.selected_nodes[g])}},parentMenu:d,node:e});return!1};k.onMenuNodeColors=function(a,b,c,d,e){if(!e)throw"no node for color";b=[];b.push({value:null,content:"<span style='display: block; padding-left: 4px;'>No color</span>"});for(var g in k.node_colors)a=k.node_colors[g],a={value:g,content:"<span style='display: block; color: #999; padding-left: 4px; border-left: 8px solid "+a.color+
|
||||
"; background-color:"+a.bgcolor+"'>"+g+"</span>"},b.push(a);new f.ContextMenu(b,{event:c,callback:function(a){if(e){var b=a.value?k.node_colors[a.value]:null;a=function(a){b?a.constructor===f.LGraphGroup?a.color=b.groupcolor:(a.color=b.color,a.bgcolor=b.bgcolor):(delete a.color,delete a.bgcolor)};var c=k.active_canvas;if(!c.selected_nodes||1>=Object.keys(c.selected_nodes).length)a(e);else for(var d in c.selected_nodes)a(c.selected_nodes[d]);e.setDirtyCanvas(!0,!0)}},parentMenu:d,node:e});return!1};
|
||||
k.onMenuNodeShapes=function(a,b,c,d,e){if(!e)throw"no node passed";new f.ContextMenu(f.VALID_SHAPES,{event:c,callback:function(a){if(e){e.graph.beforeChange();var b=k.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)e.shape=a;else for(var c in b.selected_nodes)b.selected_nodes[c].shape=a;e.graph.afterChange();e.setDirtyCanvas(!0)}},parentMenu:d,node:e});return!1};k.onMenuNodeRemove=function(a,b,c,d,e){if(!e)throw"no node passed";a=e.graph;a.beforeChange();b=k.active_canvas;
|
||||
if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)!1!==e.removable&&a.remove(e);else for(var g in b.selected_nodes)c=b.selected_nodes[g],!1!==c.removable&&a.remove(c);a.afterChange();e.setDirtyCanvas(!0,!0)};k.onMenuNodeToSubgraph=function(a,b,c,d,e){a=e.graph;if(b=k.active_canvas)c=Object.values(b.selected_nodes||{}),c.length||(c=[e]),d=f.createNode("graph/subgraph"),d.pos=e.pos.concat(),a.add(d),d.buildFromNodes(c),b.deselectAllNodes(),e.setDirtyCanvas(!0,!0)};k.onMenuNodeClone=function(a,
|
||||
b,c,d,e){e.graph.beforeChange();var g={};a=function(a){if(0!=a.clonable){var b=a.clone();b&&(b.pos=[a.pos[0]+5,a.pos[1]+5],a.graph.add(b),g[b.id]=b)}};b=k.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)a(e);else for(var f in b.selected_nodes)a(b.selected_nodes[f]);Object.keys(g).length&&b.selectNodes(g);e.graph.afterChange();e.setDirtyCanvas(!0,!0)};k.node_colors={red:{color:"#322",bgcolor:"#533",groupcolor:"#A88"},brown:{color:"#332922",bgcolor:"#593930",groupcolor:"#b06634"},
|
||||
green:{color:"#232",bgcolor:"#353",groupcolor:"#8A8"},blue:{color:"#223",bgcolor:"#335",groupcolor:"#88A"},pale_blue:{color:"#2a363b",bgcolor:"#3f5159",groupcolor:"#3f789e"},cyan:{color:"#233",bgcolor:"#355",groupcolor:"#8AA"},purple:{color:"#323",bgcolor:"#535",groupcolor:"#a1309b"},yellow:{color:"#432",bgcolor:"#653",groupcolor:"#b58b2a"},black:{color:"#222",bgcolor:"#000",groupcolor:"#444"}};k.prototype.getCanvasMenuOptions=function(){if(this.getMenuOptions)var a=this.getMenuOptions();else a=[{content:"Add Node",
|
||||
has_submenu:!0,callback:k.onMenuAdd},{content:"Add Group",callback:k.onGroupAdd}],this._graph_stack&&0<this._graph_stack.length&&a.push(null,{content:"Close subgraph",callback:this.closeSubgraph.bind(this)});if(this.getExtraMenuOptions){var b=this.getExtraMenuOptions(this,a);b&&(a=a.concat(b))}return a};k.prototype.getNodeMenuOptions=function(a){if(a.getMenuOptions)var b=a.getMenuOptions(this);else b=[{content:"Inputs",has_submenu:!0,disabled:!0,callback:k.showMenuNodeOptionalInputs},{content:"Outputs",
|
||||
has_submenu:!0,disabled:!0,callback:k.showMenuNodeOptionalOutputs},null,{content:"Properties",has_submenu:!0,callback:k.onShowMenuNodeProperties},null,{content:"Title",callback:k.onShowPropertyEditor},{content:"Mode",has_submenu:!0,callback:k.onMenuNodeMode}],!1!==a.resizable&&b.push({content:"Resize",callback:k.onMenuResizeNode}),b.push({content:"Collapse",callback:k.onMenuNodeCollapse},{content:"Pin",callback:k.onMenuNodePin},{content:"Colors",has_submenu:!0,callback:k.onMenuNodeColors},{content:"Shapes",
|
||||
has_submenu:!0,callback:k.onMenuNodeShapes},null);if(a.onGetInputs){var c=a.onGetInputs();c&&c.length&&(b[0].disabled=!1)}a.onGetOutputs&&(c=a.onGetOutputs())&&c.length&&(b[1].disabled=!1);a.getExtraMenuOptions&&(c=a.getExtraMenuOptions(this,b))&&(c.push(null),b=c.concat(b));!1!==a.clonable&&b.push({content:"Clone",callback:k.onMenuNodeClone});b.push(null,{content:"Remove",disabled:!(!1!==a.removable&&!a.block_delete),callback:k.onMenuNodeRemove});if(a.graph&&a.graph.onGetNodeMenuOptions)a.graph.onGetNodeMenuOptions(b,
|
||||
a);return b};k.prototype.getGroupMenuOptions=function(a){return[{content:"Title",callback:k.onShowPropertyEditor},{content:"Color",has_submenu:!0,callback:k.onMenuNodeColors},{content:"Font size",property:"font_size",type:"Number",callback:k.onShowPropertyEditor},null,{content:"Remove",callback:k.onMenuNodeRemove}]};k.prototype.processContextMenu=function(a,b){var c=this,d=k.active_canvas.getCanvasWindow(),e=null,g={event:b,callback:function(b,d,e){if(b)if("Remove Slot"==b.content)b=b.slot,a.graph.beforeChange(),
|
||||
b.input?a.removeInput(b.slot):b.output&&a.removeOutput(b.slot),a.graph.afterChange();else if("Disconnect Links"==b.content)b=b.slot,a.graph.beforeChange(),b.output?a.disconnectOutput(b.slot):b.input&&a.disconnectInput(b.slot),a.graph.afterChange();else if("Rename Slot"==b.content){b=b.slot;var g=b.input?a.getInputInfo(b.slot):a.getOutputInfo(b.slot),f=c.createDialog("<span class='name'>Name</span><input autofocus type='text'/><button>OK</button>",d),r=f.querySelector("input");r&&g&&(r.value=g.label||
|
||||
"");var h=function(){a.graph.beforeChange();r.value&&(g&&(g.label=r.value),c.setDirty(!0));f.close();a.graph.afterChange()};f.querySelector("button").addEventListener("click",h);r.addEventListener("keydown",function(a){f.is_modified=!0;if(27==a.keyCode)f.close();else if(13==a.keyCode)h();else if(13!=a.keyCode&&"textarea"!=a.target.localName)return;a.preventDefault();a.stopPropagation()});r.focus()}},extra:a};a&&(g.title=a.type);var h=null;a&&(h=a.getSlotInPosition(b.canvasX,b.canvasY),k.active_node=
|
||||
a);h?(e=[],a.getSlotMenuOptions?e=a.getSlotMenuOptions(h):(h&&h.output&&h.output.links&&h.output.links.length&&e.push({content:"Disconnect Links",slot:h}),b=h.input||h.output,b.removable&&e.push(b.locked?"Cannot remove":{content:"Remove Slot",slot:h}),b.nameLocked||e.push({content:"Rename Slot",slot:h})),g.title=(h.input?h.input.type:h.output.type)||"*",h.input&&h.input.type==f.ACTION&&(g.title="Action"),h.output&&h.output.type==f.EVENT&&(g.title="Event")):a?e=this.getNodeMenuOptions(a):(e=this.getCanvasMenuOptions(),
|
||||
(h=this.graph.getGroupOnPos(b.canvasX,b.canvasY))&&e.push(null,{content:"Edit Group",has_submenu:!0,submenu:{title:"Group",extra:h,options:this.getGroupMenuOptions(h)}}));e&&new f.ContextMenu(e,g,d)};"undefined"!=typeof window&&window.CanvasRenderingContext2D&&!window.CanvasRenderingContext2D.prototype.roundRect&&(window.CanvasRenderingContext2D.prototype.roundRect=function(a,b,c,d,e,g){var f,k;if(0===e)this.rect(a,b,c,d);else{void 0===g&&(g=e);if(null!=e&&e.constructor===Array)if(1==e.length)var l=
|
||||
f=k=g=e[0];else if(2==e.length)l=g=e[0],f=k=e[1];else if(4==e.length)l=e[0],f=e[1],k=e[2],g=e[3];else return;else l=e||0,f=e||0,k=g||0,g=g||0;this.moveTo(a+l,b);this.lineTo(a+c-f,b);this.quadraticCurveTo(a+c,b,a+c,b+f);this.lineTo(a+c,b+d-g);this.quadraticCurveTo(a+c,b+d,a+c-g,b+d);this.lineTo(a+g,b+d);this.quadraticCurveTo(a,b+d,a,b+d-k);this.lineTo(a,b+k);this.quadraticCurveTo(a,b,a+l,b)}});f.compareObjects=function(a,b){for(var c in a)if(a[c]!=b[c])return!1;return!0};f.distance=E;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=D;f.growBounding=function(a,b,c){b<a[0]?a[0]=b:b>a[2]&&(a[2]=b);c<a[1]?a[1]=c:c>a[3]&&(a[3]=c)};f.isInsideBounding=function(a,b){return a[0]<b[0][0]||a[1]<b[0][1]||a[0]>b[1][0]||a[1]>b[1][1]?!1:!0};f.overlapBounding=B;f.hex2num=function(a){"#"==a.charAt(0)&&(a=a.slice(1));a=a.toUpperCase();for(var b=Array(3),
|
||||
c=0,d,e,g=0;6>g;g+=2)d="0123456789ABCDEF".indexOf(a.charAt(g)),e="0123456789ABCDEF".indexOf(a.charAt(g+1)),b[c]=16*d+e,c++;return b};f.num2hex=function(a){for(var b="#",c,d,e=0;3>e;e++)c=a[e]/16,d=a[e]%16,b+="0123456789ABCDEF".charAt(c)+"0123456789ABCDEF".charAt(d);return b};F.prototype.addItem=function(a,b,c){function d(a){var b=this.value;b&&b.has_submenu&&e.call(this,a)}function e(a){var b=this.value,d=!0;g.current_submenu&&g.current_submenu.close(a);if(c.callback){var e=c.callback.call(this,b,
|
||||
c,a,g,c.node);!0===e&&(d=!1)}if(b&&(b.callback&&!c.ignore_item_callbacks&&!0!==b.disabled&&(e=b.callback.call(this,b,c,a,g,c.extra),!0===e&&(d=!1)),b.submenu)){if(!b.submenu.options)throw"ContextMenu submenu needs options";new g.constructor(b.submenu.options,{callback:b.submenu.callback,event:a,parentMenu:g,ignore_item_callbacks:b.submenu.ignore_item_callbacks,title:b.submenu.title,extra:b.submenu.extra,autoopen:c.autoopen});d=!1}d&&!g.lock&&g.close()}var g=this;c=c||{};var h=document.createElement("div");
|
||||
h.className="litemenu-entry submenu";var k=!1;if(null===b)h.classList.add("separator");else{h.innerHTML=b&&b.title?b.title:a;if(h.value=b)b.disabled&&(k=!0,h.classList.add("disabled")),(b.submenu||b.has_submenu)&&h.classList.add("has_submenu");"function"==typeof b?(h.dataset.value=a,h.onclick_callback=b):h.dataset.value=b;b.className&&(h.className+=" "+b.className)}this.root.appendChild(h);k||h.addEventListener("click",e);c.autoopen&&f.pointerListenerAdd(h,"enter",d);return h};F.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&&!F.isCursorOverElement(a,this.parentMenu.root)&&F.trigger(this.parentMenu.root,f.pointerevents_method+"leave",a));this.current_submenu&&this.current_submenu.close(a,!0);this.root.closing_timer&&clearTimeout(this.root.closing_timer)};F.trigger=function(a,b,c,d){var e=document.createEvent("CustomEvent");e.initCustomEvent(b,
|
||||
!0,!0,c);e.srcElement=d;a.dispatchEvent?a.dispatchEvent(e):a.__events&&a.__events.dispatchEvent(e);return e};F.prototype.getTopMenu=function(){return this.options.parentMenu?this.options.parentMenu.getTopMenu():this};F.prototype.getFirstEvent=function(){return this.options.parentMenu?this.options.parentMenu.getFirstEvent():this.options.event};F.isCursorOverElement=function(a,b){var c=a.clientX;a=a.clientY;return(b=b.getBoundingClientRect())?a>b.top&&a<b.top+b.height&&c>b.left&&c<b.left+b.width?!0:
|
||||
!1:!1};f.ContextMenu=F;f.closeAllContextMenus=function(a){a=a||window;a=a.document.querySelectorAll(".litecontextmenu");if(a.length){for(var b=[],c=0;c<a.length;c++)b.push(a[c]);for(c=0;c<b.length;c++)b[c].close?b[c].close():b[c].parentNode&&b[c].parentNode.removeChild(b[c])}};f.extendClass=function(a,b){for(var c in b)a.hasOwnProperty(c)||(a[c]=b[c]);if(b.prototype)for(c in b.prototype)b.prototype.hasOwnProperty(c)&&!a.prototype.hasOwnProperty(c)&&(b.prototype.__lookupGetter__(c)?a.prototype.__defineGetter__(c,
|
||||
b.prototype.__lookupGetter__(c)):a.prototype[c]=b.prototype[c],b.prototype.__lookupSetter__(c)&&a.prototype.__defineSetter__(c,b.prototype.__lookupSetter__(c)))};I.sampleCurve=function(a,b){if(b){for(var c=0;c<b.length-1;++c){var d=b[c],e=b[c+1];if(!(e[0]<a)){b=e[0]-d[0];if(1E-5>Math.abs(b))return d[1];a=(a-d[0])/b;return d[1]*(1-a)+e[1]*a}}return 0}};I.prototype.draw=function(a,b,c,d,e,g){if(c=this.points){this.size=b;var f=b[0]-2*this.margin;b=b[1]-2*this.margin;e=e||"#666";a.save();a.translate(this.margin,
|
||||
this.margin);d&&(a.fillStyle="#111",a.fillRect(0,0,f,b),a.fillStyle="#222",a.fillRect(.5*f,0,1,b),a.strokeStyle="#333",a.strokeRect(0,0,f,b));a.strokeStyle=e;g&&(a.globalAlpha=.5);a.beginPath();for(d=0;d<c.length;++d)e=c[d],a.lineTo(e[0]*f,(1-e[1])*b);a.stroke();a.globalAlpha=1;if(!g)for(d=0;d<c.length;++d)e=c[d],a.fillStyle=this.selected==d?"#FFF":this.nearest==d?"#DDD":"#AAA",a.beginPath(),a.arc(e[0]*f,(1-e[1])*b,2,0,2*Math.PI),a.fill();a.restore()}};I.prototype.onMouseDown=function(a,b){var c=
|
||||
this.points;if(c&&!(0>a[1])){var d=this.size[0]-2*this.margin,e=this.size[1]-2*this.margin,g=a[0]-this.margin;a=a[1]-this.margin;this.selected=this.getCloserPoint([g,a],30/b.ds.scale);-1==this.selected&&(b=[g/d,1-a/e],c.push(b),c.sort(function(a,b){return a[0]-b[0]}),this.selected=c.indexOf(b),this.must_update=!0);if(-1!=this.selected)return!0}};I.prototype.onMouseMove=function(a,b){var c=this.points;if(c){var d=this.selected;if(!(0>d)){var e=(a[0]-this.margin)/(this.size[0]-2*this.margin),g=(a[1]-
|
||||
this.margin)/(this.size[1]-2*this.margin);this._nearest=this.getCloserPoint([a[0]-this.margin,a[1]-this.margin],30/b.ds.scale);if(b=c[d]){var f=0==d||d==c.length-1;!f&&(-10>a[0]||a[0]>this.size[0]+10||-10>a[1]||a[1]>this.size[1]+10)?(c.splice(d,1),this.selected=-1):(b[0]=f?0==d?0:1:Math.clamp(e,0,1),b[1]=1-Math.clamp(g,0,1),c.sort(function(a,b){return a[0]-b[0]}),this.selected=c.indexOf(b),this.must_update=!0)}}}};I.prototype.onMouseUp=function(a,b){this.selected=-1;return!1};I.prototype.getCloserPoint=
|
||||
function(a,b){var c=this.points;if(!c)return-1;b=b||30;for(var d=this.size[0]-2*this.margin,e=this.size[1]-2*this.margin,g=c.length,f=[0,0],k=1E6,l=-1,r=0;r<g;++r){var u=c[r];f[0]=u[0]*d;f[1]=(1-u[1])*e;u=vec2.distance(a,f);u>k||u>b||(l=r,k=u)}return l};f.CurveEditor=I;f.getParameterNames=function(a){return(a+"").replace(/[/][/].*$/gm,"").replace(/\s+/g,"").replace(/[/][*][^/*]*[*][/]/g,"").split("){",1)[0].replace(/^[^(]*[(]/,"").replace(/=[^,]+/g,"").split(",").filter(Boolean)};f.pointerListenerAdd=
|
||||
function(a,b,c,d){d=void 0===d?!1:d;if(a&&a.addEventListener&&b&&"function"===typeof c){var e=f.pointerevents_method;if("pointer"==e&&!window.PointerEvent)switch(console.warn("sMethod=='pointer' && !window.PointerEvent"),console.log("Converting pointer["+b+"] : down move up cancel enter TO touchstart touchmove touchend, etc .."),b){case "down":e="touch";b="start";break;case "move":e="touch";break;case "up":e="touch";b="end";break;case "cancel":e="touch";break;case "enter":console.log("debug: Should I send a move event?");
|
||||
break;default:console.warn("PointerEvent not available in this browser ? The event "+b+" would not be called")}switch(b){case "down":case "up":case "move":case "over":case "out":case "enter":a.addEventListener(e+b,c,d);case "leave":case "cancel":case "gotpointercapture":case "lostpointercapture":if("mouse"!=e)return a.addEventListener(e+b,c,d);default:return a.addEventListener(b,c,d)}}};f.pointerListenerRemove=function(a,b,c,d){d=void 0===d?!1:d;if(a&&a.removeEventListener&&b&&"function"===typeof c)switch(b){case "down":case "up":case "move":case "over":case "out":case "enter":"pointer"!=
|
||||
f.pointerevents_method&&"mouse"!=f.pointerevents_method||a.removeEventListener(f.pointerevents_method+b,c,d);case "leave":case "cancel":case "gotpointercapture":case "lostpointercapture":if("pointer"==f.pointerevents_method)return a.removeEventListener(f.pointerevents_method+b,c,d);default:return a.removeEventListener(b,c,d)}};Math.clamp=function(a,b,c){return b>a?b:c<a?c:a};"undefined"==typeof window||window.requestAnimationFrame||(window.requestAnimationFrame=window.webkitRequestAnimationFrame||
|
||||
window.mozRequestAnimationFrame||function(a){window.setTimeout(a,1E3/60)})})(this);"undefined"!=typeof exports&&(exports.LiteGraph=this.LiteGraph);
|
||||
(function(x){function m(){this.addOutput("in ms","number");this.addOutput("in sec","number")}function t(){this.size=[140,80];this.properties={enabled:!0};this.enabled=!0;this.subgraph=new p.LGraph;this.subgraph._subgraph_node=this;this.subgraph._is_subgraph=!0;this.subgraph.onTrigger=this.onSubgraphTrigger.bind(this);this.subgraph.onInputAdded=this.onSubgraphNewInput.bind(this);this.subgraph.onInputRenamed=this.onSubgraphRenamedInput.bind(this);this.subgraph.onInputTypeChanged=this.onSubgraphTypeChangeInput.bind(this);
|
||||
this.subgraph.onInputRemoved=this.onSubgraphRemovedInput.bind(this);this.subgraph.onOutputAdded=this.onSubgraphNewOutput.bind(this);this.subgraph.onOutputRenamed=this.onSubgraphRenamedOutput.bind(this);this.subgraph.onOutputTypeChanged=this.onSubgraphTypeChangeOutput.bind(this);this.subgraph.onOutputRemoved=this.onSubgraphRemovedOutput.bind(this)}function l(){this.addOutput("","number");this.name_in_graph="";this.properties={name:"",type:"number",value:0};var a=this;this.name_widget=this.addWidget("text",
|
||||
"Name",this.properties.name,function(b){b&&a.setProperty("name",b)});this.type_widget=this.addWidget("text","Type",this.properties.type,function(b){a.setProperty("type",b)});this.value_widget=this.addWidget("number","Value",this.properties.value,function(b){a.setProperty("value",b)});this.widgets_up=!0;this.size=[180,90]}function w(){this.addInput("","");this.name_in_graph="";this.properties={};this.name_widget=this.addWidget("text","Name",this.properties.name,"name");this.type_widget=this.addWidget("text",
|
||||
"Type",this.properties.type,"type");this.widgets_up=!0;this.size=[180,60]}function z(){this.addOutput("value","number");this.addProperty("value",1);this.widget=this.addWidget("number","value",1,"value");this.widgets_up=!0;this.size=[180,30]}function h(){this.addOutput("bool","boolean");this.addProperty("value",!0);this.widget=this.addWidget("toggle","value",!0,"value");this.widgets_up=this.serialize_widgets=!0;this.size=[140,30]}function D(){this.addOutput("string","string");this.addProperty("value",
|
||||
"");this.widget=this.addWidget("text","value","","value");this.widgets_up=!0;this.size=[180,30]}function C(){this.addOutput("obj","object");this.size=[120,30];this._object={}}function A(){this.addInput("url","string");this.addOutput("file","string");this.addProperty("url","");this.addProperty("type","text");this.widget=this.addWidget("text","url","","url");this._data=null}function E(){this.addOutput("data","object");this.addProperty("value","");this.widget=this.addWidget("text","json","","value");
|
||||
this.widgets_up=!0;this.size=[140,30];this._value=null}function G(){this._value=[];this.addInput("json","");this.addOutput("arrayOut","array");this.addOutput("length","number");this.addProperty("value","[]");this.widget=this.addWidget("text","array",this.properties.value,"value");this.widgets_up=!0;this.size=[140,50]}function f(){this.addInput("arr","array");this.addInput("value","");this.addOutput("arr","array");this.properties={index:0};this.widget=this.addWidget("number","i",this.properties.index,
|
||||
"index",{precision:0,step:10,min:0})}function L(){this.addInput("array","array,table,string");this.addInput("index","number");this.addOutput("value","");this.addProperty("index",0)}function I(){this.addInput("table","table");this.addInput("row","number");this.addInput("col","number");this.addOutput("value","");this.addProperty("row",0);this.addProperty("column",0)}function B(){this.addInput("obj","object");this.addOutput("property",0);this.addProperty("value",0);this.widget=this.addWidget("text",
|
||||
"prop.","",this.setValue.bind(this));this.widgets_up=!0;this.size=[140,30];this._value=null}function K(){this.addInput("obj","");this.addOutput("keys","array");this.size=[140,30]}function F(){this.addInput("obj","");this.addInput("value","");this.addOutput("obj","");this.properties={property:""};this.name_widget=this.addWidget("text","prop.",this.properties.property,"property")}function J(){this.addInput("A","object");this.addInput("B","object");this.addOutput("out","object");this._result={};var a=
|
||||
this;this.addWidget("button","clear","",function(){a._result={}});this.size=this.computeSize()}function H(){this.size=[60,30];this.addInput("in");this.addOutput("out");this.properties={varname:"myname",container:H.LITEGRAPH};this.value=null}function a(a){return a&&null!=a.length?Number(a.length):0}function a(a){return a&&null!=a.length?Number(a.length):0}function b(){this.size=[60,30];this.addInput("data",0);this.addInput("download",p.ACTION);this.properties={filename:"data.json"};this.value=null;
|
||||
var a=this;this.addWidget("button","Download","",function(b){a.value&&a.downloadAsFile()})}function c(){this.size=[60,30];this.addInput("value",0,{label:""});this.value=0}function d(){this.addInput("in",0);this.addOutput("out",0);this.size=[40,30]}function e(){this.mode=p.ON_EVENT;this.size=[80,30];this.addProperty("msg","");this.addInput("log",p.EVENT);this.addInput("msg",0)}function g(){this.mode=p.ON_EVENT;this.addProperty("msg","");this.addInput("",p.EVENT);this.widget=this.addWidget("text","Text",
|
||||
"","msg");this.widgets_up=!0;this.size=[200,30]}function k(){this.size=[60,30];this.addProperty("onExecute","return A;");this.addInput("A",0);this.addInput("B",0);this.addOutput("out",0);this._func=null;this.data={}}function n(){this.addInput("A",0);this.addInput("B",0);this.addOutput("true","boolean");this.addOutput("false","boolean");this.addProperty("A",1);this.addProperty("B",1);this.addProperty("OP","==","enum",{values:n.values});this.addWidget("combo","Op.",this.properties.OP,{property:"OP",
|
||||
"Name",this.properties.name,function(b){b&&a.setProperty("name",b)});this.type_widget=this.addWidget("text","Type",this.properties.type,function(b){a.setProperty("type",b)});this.value_widget=this.addWidget("number","Value",this.properties.value,function(b){a.setProperty("value",b)});this.widgets_up=!0;this.size=[180,90]}function w(){this.addInput("","");this.name_in_graph="";this.properties={name:"",type:""};this.name_widget=this.addWidget("text","Name",this.properties.name,"name");this.type_widget=
|
||||
this.addWidget("text","Type",this.properties.type,"type");this.widgets_up=!0;this.size=[180,60]}function A(){this.addOutput("value","number");this.addProperty("value",1);this.widget=this.addWidget("number","value",1,"value");this.widgets_up=!0;this.size=[180,30]}function k(){this.addOutput("bool","boolean");this.addProperty("value",!0);this.widget=this.addWidget("toggle","value",!0,"value");this.widgets_up=this.serialize_widgets=!0;this.size=[140,30]}function E(){this.addOutput("string","string");
|
||||
this.addProperty("value","");this.widget=this.addWidget("text","value","","value");this.widgets_up=!0;this.size=[180,30]}function D(){this.addOutput("obj","object");this.size=[120,30];this._object={}}function B(){this.addInput("url","string");this.addOutput("file","string");this.addProperty("url","");this.addProperty("type","text");this.widget=this.addWidget("text","url","","url");this._data=null}function F(){this.addOutput("data","object");this.addProperty("value","");this.widget=this.addWidget("text",
|
||||
"json","","value");this.widgets_up=!0;this.size=[140,30];this._value=null}function I(){this._value=[];this.addInput("json","");this.addOutput("arrayOut","array");this.addOutput("length","number");this.addProperty("value","[]");this.widget=this.addWidget("text","array",this.properties.value,"value");this.widgets_up=!0;this.size=[140,50]}function f(){this.addInput("arr","array");this.addInput("value","");this.addOutput("arr","array");this.properties={index:0};this.widget=this.addWidget("number","i",
|
||||
this.properties.index,"index",{precision:0,step:10,min:0})}function z(){this.addInput("array","array,table,string");this.addInput("index","number");this.addOutput("value","");this.addProperty("index",0)}function H(){this.addInput("table","table");this.addInput("row","number");this.addInput("col","number");this.addOutput("value","");this.addProperty("row",0);this.addProperty("column",0)}function C(){this.addInput("obj","object");this.addOutput("property",0);this.addProperty("value",0);this.widget=
|
||||
this.addWidget("text","prop.","",this.setValue.bind(this));this.widgets_up=!0;this.size=[140,30];this._value=null}function L(){this.addInput("obj","");this.addOutput("keys","array");this.size=[140,30]}function G(){this.addInput("obj","");this.addInput("value","");this.addOutput("obj","");this.properties={property:""};this.name_widget=this.addWidget("text","prop.",this.properties.property,"property")}function K(){this.addInput("A","object");this.addInput("B","object");this.addOutput("out","object");
|
||||
this._result={};var a=this;this.addWidget("button","clear","",function(){a._result={}});this.size=this.computeSize()}function J(){this.size=[60,30];this.addInput("in");this.addOutput("out");this.properties={varname:"myname",container:J.LITEGRAPH};this.value=null}function a(a){return a&&null!=a.length?Number(a.length):0}function a(a){return a&&null!=a.length?Number(a.length):0}function b(){this.size=[60,30];this.addInput("data",0);this.addInput("download",p.ACTION);this.properties={filename:"data.json"};
|
||||
this.value=null;var a=this;this.addWidget("button","Download","",function(b){a.value&&a.downloadAsFile()})}function c(){this.size=[60,30];this.addInput("value",0,{label:""});this.value=0}function d(){this.addInput("in",0);this.addOutput("out",0);this.size=[40,30]}function e(){this.mode=p.ON_EVENT;this.size=[80,30];this.addProperty("msg","");this.addInput("log",p.EVENT);this.addInput("msg",0)}function g(){this.mode=p.ON_EVENT;this.addProperty("msg","");this.addInput("",p.EVENT);this.widget=this.addWidget("text",
|
||||
"Text","","msg");this.widgets_up=!0;this.size=[200,30]}function h(){this.size=[60,30];this.addProperty("onExecute","return A;");this.addInput("A",0);this.addInput("B",0);this.addOutput("out",0);this._func=null;this.data={}}function n(){this.addInput("A",0);this.addInput("B",0);this.addOutput("true","boolean");this.addOutput("false","boolean");this.addProperty("A",1);this.addProperty("B",1);this.addProperty("OP","==","enum",{values:n.values});this.addWidget("combo","Op.",this.properties.OP,{property:"OP",
|
||||
values:n.values});this.size=[80,60]}var p=x.LiteGraph;m.title="Time";m.desc="Time";m.prototype.onExecute=function(){this.setOutputData(0,1E3*this.graph.globaltime);this.setOutputData(1,this.graph.globaltime)};p.registerNodeType("basic/time",m);t.title="Subgraph";t.desc="Graph inside a node";t.title_color="#334";t.prototype.onGetInputs=function(){return[["enabled","boolean"]]};t.prototype.onDblClick=function(a,b,c){var d=this;setTimeout(function(){c.openSubgraph(d.subgraph)},10)};t.prototype.onAction=
|
||||
function(a,b){this.subgraph.onAction(a,b)};t.prototype.onExecute=function(){if(this.enabled=this.getInputOrProperty("enabled")){if(this.inputs)for(var a=0;a<this.inputs.length;a++){var b=this.inputs[a],c=this.getInputData(a);this.subgraph.setInputData(b.name,c)}this.subgraph.runStep();if(this.outputs)for(a=0;a<this.outputs.length;a++)c=this.subgraph.getOutputData(this.outputs[a].name),this.setOutputData(a,c)}};t.prototype.sendEventToAllNodes=function(a,b,c){this.enabled&&this.subgraph.sendEventToAllNodes(a,
|
||||
b,c)};t.prototype.onDrawBackground=function(a,b,c,d){this.flags.collapsed||(b=this.size[1]-p.NODE_TITLE_HEIGHT+.5,c=p.isInsideRectangle(d[0],d[1],this.pos[0],this.pos[1]+b,this.size[0],p.NODE_TITLE_HEIGHT),d=p.isInsideRectangle(d[0],d[1],this.pos[0],this.pos[1]+b,this.size[0]/2,p.NODE_TITLE_HEIGHT),a.fillStyle=c?"#555":"#222",a.beginPath(),this._shape==p.BOX_SHAPE?d?a.rect(0,b,this.size[0]/2+1,p.NODE_TITLE_HEIGHT):a.rect(this.size[0]/2,b,this.size[0]/2+1,p.NODE_TITLE_HEIGHT):d?a.roundRect(0,b,this.size[0]/
|
||||
@@ -362,99 +362,100 @@ b,c)};t.prototype.onDrawBackground=function(a,b,c,d){this.flags.collapsed||(b=th
|
||||
c.showSubgraphPropertiesDialogRight(this)))};t.prototype.computeSize=function(){return[200,Math.max(this.inputs?this.inputs.length:0,this.outputs?this.outputs.length:0)*p.NODE_SLOT_HEIGHT+p.NODE_TITLE_HEIGHT]};t.prototype.onSubgraphTrigger=function(a,b){a=this.findOutputSlot(a);-1!=a&&this.triggerSlot(a)};t.prototype.onSubgraphNewInput=function(a,b){-1==this.findInputSlot(a)&&this.addInput(a,b)};t.prototype.onSubgraphRenamedInput=function(a,b){a=this.findInputSlot(a);-1!=a&&(this.getInputInfo(a).name=
|
||||
b)};t.prototype.onSubgraphTypeChangeInput=function(a,b){a=this.findInputSlot(a);-1!=a&&(this.getInputInfo(a).type=b)};t.prototype.onSubgraphRemovedInput=function(a){a=this.findInputSlot(a);-1!=a&&this.removeInput(a)};t.prototype.onSubgraphNewOutput=function(a,b){-1==this.findOutputSlot(a)&&this.addOutput(a,b)};t.prototype.onSubgraphRenamedOutput=function(a,b){a=this.findOutputSlot(a);-1!=a&&(this.getOutputInfo(a).name=b)};t.prototype.onSubgraphTypeChangeOutput=function(a,b){a=this.findOutputSlot(a);
|
||||
-1!=a&&(this.getOutputInfo(a).type=b)};t.prototype.onSubgraphRemovedOutput=function(a){a=this.findInputSlot(a);-1!=a&&this.removeOutput(a)};t.prototype.getExtraMenuOptions=function(a){var b=this;return[{content:"Open",callback:function(){a.openSubgraph(b.subgraph)}}]};t.prototype.onResize=function(a){a[1]+=20};t.prototype.serialize=function(){var a=p.LGraphNode.prototype.serialize.call(this);a.subgraph=this.subgraph.serialize();return a};t.prototype.clone=function(){var a=p.createNode(this.type),
|
||||
b=this.serialize();delete b.id;delete b.inputs;delete b.outputs;a.configure(b);return a};t.prototype.buildFromNodes=function(a){for(var b={},c=0;c<a.length;++c){var d=a[c];b[d.id]=d}for(c=0;c<a.length;++c){d=a[c];if(d.inputs)for(var e=0;e<d.inputs.length;++e){var f=d.inputs[e];if(f&&f.link){var g=d.graph.links[f.link];g&&(b[g.origin_id]||this.subgraph.addInput(f.name,g.type))}}if(d.outputs)for(e=0;e<d.outputs.length;++e)if((f=d.outputs[e])&&f.links&&f.links.length)for(var k=0;k<f.links.length&&(!(g=
|
||||
d.graph.links[f.links[k]])||b[g.target_id]);++k);}};p.Subgraph=t;p.registerNodeType("graph/subgraph",t);l.title="Input";l.desc="Input of the graph";l.prototype.onConfigure=function(){this.updateType()};l.prototype.updateType=function(){var a=this.properties.type;this.type_widget.value=a;this.outputs[0].type!=a&&(p.isValidConnection(this.outputs[0].type,a)||this.disconnectOutput(0),this.outputs[0].type=a);"number"==a?(this.value_widget.type="number",this.value_widget.value=0):"boolean"==a?(this.value_widget.type=
|
||||
b=this.serialize();delete b.id;delete b.inputs;delete b.outputs;a.configure(b);return a};t.prototype.buildFromNodes=function(a){for(var b={},c=0;c<a.length;++c){var d=a[c];b[d.id]=d}for(c=0;c<a.length;++c){d=a[c];if(d.inputs)for(var e=0;e<d.inputs.length;++e){var g=d.inputs[e];if(g&&g.link){var f=d.graph.links[g.link];f&&(b[f.origin_id]||this.subgraph.addInput(g.name,f.type))}}if(d.outputs)for(e=0;e<d.outputs.length;++e)if((g=d.outputs[e])&&g.links&&g.links.length)for(var h=0;h<g.links.length&&(!(f=
|
||||
d.graph.links[g.links[h]])||b[f.target_id]);++h);}};p.Subgraph=t;p.registerNodeType("graph/subgraph",t);l.title="Input";l.desc="Input of the graph";l.prototype.onConfigure=function(){this.updateType()};l.prototype.updateType=function(){var a=this.properties.type;this.type_widget.value=a;this.outputs[0].type!=a&&(p.isValidConnection(this.outputs[0].type,a)||this.disconnectOutput(0),this.outputs[0].type=a);"number"==a?(this.value_widget.type="number",this.value_widget.value=0):"boolean"==a?(this.value_widget.type=
|
||||
"toggle",this.value_widget.value=!0):"string"==a?(this.value_widget.type="text",this.value_widget.value=""):(this.value_widget.type=null,this.value_widget.value=null);this.properties.value=this.value_widget.value;this.graph&&this.name_in_graph&&this.graph.changeInputType(this.name_in_graph,a)};l.prototype.onPropertyChanged=function(a,b){if("name"==a){if(""==b||b==this.name_in_graph||"enabled"==b)return!1;this.graph&&(this.name_in_graph?this.graph.renameInput(this.name_in_graph,b):this.graph.addInput(b,
|
||||
this.properties.type));this.name_in_graph=this.name_widget.value=b}else"type"==a&&this.updateType()};l.prototype.getTitle=function(){return this.flags.collapsed?this.properties.name:this.title};l.prototype.onAction=function(a,b){this.properties.type==p.EVENT&&this.triggerSlot(0,b)};l.prototype.onExecute=function(){var a=this.graph.inputs[this.properties.name];a?this.setOutputData(0,void 0!==a.value?a.value:this.properties.value):this.setOutputData(0,this.properties.value)};l.prototype.onRemoved=function(){this.name_in_graph&&
|
||||
this.graph.removeInput(this.name_in_graph)};p.GraphInput=l;p.registerNodeType("graph/input",l);w.title="Output";w.desc="Output of the graph";w.prototype.onPropertyChanged=function(a,b){if("name"==a){if(""==b||b==this.name_in_graph||"enabled"==b)return!1;this.graph&&(this.name_in_graph?this.graph.renameOutput(this.name_in_graph,b):this.graph.addOutput(b,this.properties.type));this.name_in_graph=this.name_widget.value=b}else"type"==a&&this.updateType()};w.prototype.updateType=function(){var a=this.properties.type;
|
||||
this.type_widget&&(this.type_widget.value=a);this.inputs[0].type!=a&&(p.isValidConnection(this.inputs[0].type,a)||this.disconnectInput(0),this.inputs[0].type=a);this.graph&&this.name_in_graph&&this.graph.changeOutputType(this.name_in_graph,a)};w.prototype.onExecute=function(){this._value=this.getInputData(0);this.graph.setOutputData(this.properties.name,this._value)};w.prototype.onAction=function(a,b){this.properties.type==p.ACTION&&this.graph.trigger(this.properties.name,b)};w.prototype.onRemoved=
|
||||
function(){this.name_in_graph&&this.graph.removeOutput(this.name_in_graph)};w.prototype.getTitle=function(){return this.flags.collapsed?this.properties.name:this.title};p.GraphOutput=w;p.registerNodeType("graph/output",w);z.title="Const Number";z.desc="Constant number";z.prototype.onExecute=function(){this.setOutputData(0,parseFloat(this.properties.value))};z.prototype.getTitle=function(){return this.flags.collapsed?this.properties.value:this.title};z.prototype.setValue=function(a){this.setProperty("value",
|
||||
a)};z.prototype.onDrawBackground=function(a){this.outputs[0].label=this.properties.value.toFixed(3)};p.registerNodeType("basic/const",z);h.title="Const Boolean";h.desc="Constant boolean";h.prototype.getTitle=z.prototype.getTitle;h.prototype.onExecute=function(){this.setOutputData(0,this.properties.value)};h.prototype.setValue=z.prototype.setValue;h.prototype.onGetInputs=function(){return[["toggle",p.ACTION]]};h.prototype.onAction=function(a){this.setValue(!this.properties.value)};p.registerNodeType("basic/boolean",
|
||||
h);D.title="Const String";D.desc="Constant string";D.prototype.getTitle=z.prototype.getTitle;D.prototype.onExecute=function(){this.setOutputData(0,this.properties.value)};D.prototype.setValue=z.prototype.setValue;D.prototype.onDropFile=function(a){var b=this,c=new FileReader;c.onload=function(a){b.setProperty("value",a.target.result)};c.readAsText(a)};p.registerNodeType("basic/string",D);C.title="Const Object";C.desc="Constant Object";C.prototype.onExecute=function(){this.setOutputData(0,this._object)};
|
||||
p.registerNodeType("basic/object",C);A.title="Const File";A.desc="Fetches a file from an url";A["@type"]={type:"enum",values:["text","arraybuffer","blob","json"]};A.prototype.onPropertyChanged=function(a,b){"url"==a&&(null==b||""==b?this._data=null:this.fetchFile(b))};A.prototype.onExecute=function(){var a=this.getInputData(0)||this.properties.url;!a||a==this._url&&this._type==this.properties.type||this.fetchFile(a);this.setOutputData(0,this._data)};A.prototype.setValue=z.prototype.setValue;A.prototype.fetchFile=
|
||||
function(a){var b=this;a&&a.constructor===String?(this._url=a,this._type=this.properties.type,"http"==a.substr(0,4)&&p.proxy&&(a=p.proxy+a.substr(a.indexOf(":")+3)),fetch(a).then(function(a){if(!a.ok)throw Error("File not found");if("arraybuffer"==b.properties.type)return a.arrayBuffer();if("text"==b.properties.type)return a.text();if("json"==b.properties.type)return a.json();if("blob"==b.properties.type)return a.blob()}).then(function(a){b._data=a;b.boxcolor="#AEA"}).catch(function(c){b._data=null;
|
||||
b.boxcolor="red";console.error("error fetching file:",a)})):(b._data=null,b.boxcolor=null)};A.prototype.onDropFile=function(a){var b=this;this._url=a.name;this._type=this.properties.type;this.properties.url=a.name;var c=new FileReader;c.onload=function(a){b.boxcolor="#AEA";a=a.target.result;"json"==b.properties.type&&(a=JSON.parse(a));b._data=a};if("arraybuffer"==b.properties.type)c.readAsArrayBuffer(a);else if("text"==b.properties.type||"json"==b.properties.type)c.readAsText(a);else if("blob"==b.properties.type)return c.readAsBinaryString(a)};
|
||||
p.registerNodeType("basic/file",A);E.title="Const Data";E.desc="Constant Data";E.prototype.onPropertyChanged=function(a,b){this.widget.value=b;if(null!=b&&""!=b)try{this._value=JSON.parse(b),this.boxcolor="#AEA"}catch(q){this.boxcolor="red"}};E.prototype.onExecute=function(){this.setOutputData(0,this._value)};E.prototype.setValue=z.prototype.setValue;p.registerNodeType("basic/data",E);G.title="Const Array";G.desc="Constant Array";G.prototype.onPropertyChanged=function(a,b){this.widget.value=b;if(null!=
|
||||
b&&""!=b)try{this._value="["!=b[0]?JSON.parse("["+b+"]"):JSON.parse(b),this.boxcolor="#AEA"}catch(q){this.boxcolor="red"}};G.prototype.onExecute=function(){var a=this.getInputData(0);if(a&&a.length){this._value||(this._value=[]);this._value.length=a.length;for(var b=0;b<a.length;++b)this._value[b]=a[b]}this.setOutputData(0,this._value);this.setOutputData(1,this._value?this._value.length||0:0)};G.prototype.setValue=z.prototype.setValue;p.registerNodeType("basic/array",G);f.title="Set Array";f.desc=
|
||||
"Sets index of array";f.prototype.onExecute=function(){var a=this.getInputData(0);if(a){var b=this.getInputData(1);void 0!==b&&(this.properties.index&&(a[Math.floor(this.properties.index)]=b),this.setOutputData(0,a))}};p.registerNodeType("basic/set_array",f);L.title="Array[i]";L.desc="Returns an element from an array";L.prototype.onExecute=function(){var a=this.getInputData(0),b=this.getInputData(1);null==b&&(b=this.properties.index);null!=a&&null!=b&&this.setOutputData(0,a[Math.floor(Number(b))])};
|
||||
p.registerNodeType("basic/array[]",L);I.title="Table[row][col]";I.desc="Returns an element from a table";I.prototype.onExecute=function(){var a=this.getInputData(0),b=this.getInputData(1),c=this.getInputData(2);null==b&&(b=this.properties.row);null==c&&(c=this.properties.column);null!=a&&null!=b&&null!=c&&((b=a[Math.floor(Number(b))])?this.setOutputData(0,b[Math.floor(Number(c))]):this.setOutputData(0,null))};p.registerNodeType("basic/table[][]",I);B.title="Object property";B.desc="Outputs the property of an object";
|
||||
B.prototype.setValue=function(a){this.properties.value=a;this.widget.value=a};B.prototype.getTitle=function(){return this.flags.collapsed?"in."+this.properties.value:this.title};B.prototype.onPropertyChanged=function(a,b){this.widget.value=b};B.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,a[this.properties.value])};p.registerNodeType("basic/object_property",B);K.title="Object keys";K.desc="Outputs an array with the keys of an object";K.prototype.onExecute=
|
||||
function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,Object.keys(a))};p.registerNodeType("basic/object_keys",K);F.title="Set Object";F.desc="Adds propertiesrty to object";F.prototype.onExecute=function(){var a=this.getInputData(0);if(a){var b=this.getInputData(1);void 0!==b&&(this.properties.property&&(a[this.properties.property]=b),this.setOutputData(0,a))}};p.registerNodeType("basic/set_object",F);J.title="Merge Objects";J.desc="Creates an object copying properties from others";J.prototype.onExecute=
|
||||
function(){var a=this.getInputData(0),b=this.getInputData(1),c=this._result;if(a)for(var d in a)c[d]=a[d];if(b)for(d in b)c[d]=b[d];this.setOutputData(0,c)};p.registerNodeType("basic/merge_objects",J);H.title="Variable";H.desc="store/read variable value";H.LITEGRAPH=0;H.GRAPH=1;H.GLOBALSCOPE=2;H["@container"]={type:"enum",values:{litegraph:H.LITEGRAPH,graph:H.GRAPH,global:H.GLOBALSCOPE}};H.prototype.onExecute=function(){var a=this.getContainer();this.isInputConnected(0)?(this.value=this.getInputData(0),
|
||||
a[this.properties.varname]=this.value,this.setOutputData(0,this.value)):this.setOutputData(0,a[this.properties.varname])};H.prototype.getContainer=function(){switch(this.properties.container){case H.GRAPH:return this.graph?this.graph.vars:{};case H.GLOBALSCOPE:return x;default:return p.Globals}};H.prototype.getTitle=function(){return this.properties.varname};p.registerNodeType("basic/variable",H);p.wrapFunctionAsNode("basic/length",a,[""],"number");p.wrapFunctionAsNode("basic/not",function(a){return!a},
|
||||
[""],"boolean");b.title="Download";b.desc="Download some data";b.prototype.downloadAsFile=function(){if(null!=this.value){var a=null;a=this.value.constructor===String?this.value:JSON.stringify(this.value);a=new Blob([a]);var b=URL.createObjectURL(a);a=document.createElement("a");a.setAttribute("href",b);a.setAttribute("download",this.properties.filename);a.style.display="none";document.body.appendChild(a);a.click();document.body.removeChild(a);setTimeout(function(){URL.revokeObjectURL(b)},6E4)}};
|
||||
b.prototype.onAction=function(a,b){var c=this;setTimeout(function(){c.downloadAsFile()},100)};b.prototype.onExecute=function(){this.inputs[0]&&(this.value=this.getInputData(0))};b.prototype.getTitle=function(){return this.flags.collapsed?this.properties.filename:this.title};p.registerNodeType("basic/download",b);c.title="Watch";c.desc="Show value of input";c.prototype.onExecute=function(){this.inputs[0]&&(this.value=this.getInputData(0))};c.prototype.getTitle=function(){return this.flags.collapsed?
|
||||
this.type_widget&&(this.type_widget.value=a);if(this.inputs[0].type!=a){if("action"==a||"event"==a)a=p.EVENT;p.isValidConnection(this.inputs[0].type,a)||this.disconnectInput(0);this.inputs[0].type=a}this.graph&&this.name_in_graph&&this.graph.changeOutputType(this.name_in_graph,a)};w.prototype.onExecute=function(){this._value=this.getInputData(0);this.graph.setOutputData(this.properties.name,this._value)};w.prototype.onAction=function(a,b){this.properties.type==p.ACTION&&this.graph.trigger(this.properties.name,
|
||||
b)};w.prototype.onRemoved=function(){this.name_in_graph&&this.graph.removeOutput(this.name_in_graph)};w.prototype.getTitle=function(){return this.flags.collapsed?this.properties.name:this.title};p.GraphOutput=w;p.registerNodeType("graph/output",w);A.title="Const Number";A.desc="Constant number";A.prototype.onExecute=function(){this.setOutputData(0,parseFloat(this.properties.value))};A.prototype.getTitle=function(){return this.flags.collapsed?this.properties.value:this.title};A.prototype.setValue=
|
||||
function(a){this.setProperty("value",a)};A.prototype.onDrawBackground=function(a){this.outputs[0].label=this.properties.value.toFixed(3)};p.registerNodeType("basic/const",A);k.title="Const Boolean";k.desc="Constant boolean";k.prototype.getTitle=A.prototype.getTitle;k.prototype.onExecute=function(){this.setOutputData(0,this.properties.value)};k.prototype.setValue=A.prototype.setValue;k.prototype.onGetInputs=function(){return[["toggle",p.ACTION]]};k.prototype.onAction=function(a){this.setValue(!this.properties.value)};
|
||||
p.registerNodeType("basic/boolean",k);E.title="Const String";E.desc="Constant string";E.prototype.getTitle=A.prototype.getTitle;E.prototype.onExecute=function(){this.setOutputData(0,this.properties.value)};E.prototype.setValue=A.prototype.setValue;E.prototype.onDropFile=function(a){var b=this,c=new FileReader;c.onload=function(a){b.setProperty("value",a.target.result)};c.readAsText(a)};p.registerNodeType("basic/string",E);D.title="Const Object";D.desc="Constant Object";D.prototype.onExecute=function(){this.setOutputData(0,
|
||||
this._object)};p.registerNodeType("basic/object",D);B.title="Const File";B.desc="Fetches a file from an url";B["@type"]={type:"enum",values:["text","arraybuffer","blob","json"]};B.prototype.onPropertyChanged=function(a,b){"url"==a&&(null==b||""==b?this._data=null:this.fetchFile(b))};B.prototype.onExecute=function(){var a=this.getInputData(0)||this.properties.url;!a||a==this._url&&this._type==this.properties.type||this.fetchFile(a);this.setOutputData(0,this._data)};B.prototype.setValue=A.prototype.setValue;
|
||||
B.prototype.fetchFile=function(a){var b=this;a&&a.constructor===String?(this._url=a,this._type=this.properties.type,"http"==a.substr(0,4)&&p.proxy&&(a=p.proxy+a.substr(a.indexOf(":")+3)),fetch(a).then(function(a){if(!a.ok)throw Error("File not found");if("arraybuffer"==b.properties.type)return a.arrayBuffer();if("text"==b.properties.type)return a.text();if("json"==b.properties.type)return a.json();if("blob"==b.properties.type)return a.blob()}).then(function(a){b._data=a;b.boxcolor="#AEA"}).catch(function(c){b._data=
|
||||
null;b.boxcolor="red";console.error("error fetching file:",a)})):(b._data=null,b.boxcolor=null)};B.prototype.onDropFile=function(a){var b=this;this._url=a.name;this._type=this.properties.type;this.properties.url=a.name;var c=new FileReader;c.onload=function(a){b.boxcolor="#AEA";a=a.target.result;"json"==b.properties.type&&(a=JSON.parse(a));b._data=a};if("arraybuffer"==b.properties.type)c.readAsArrayBuffer(a);else if("text"==b.properties.type||"json"==b.properties.type)c.readAsText(a);else if("blob"==
|
||||
b.properties.type)return c.readAsBinaryString(a)};p.registerNodeType("basic/file",B);F.title="Const Data";F.desc="Constant Data";F.prototype.onPropertyChanged=function(a,b){this.widget.value=b;if(null!=b&&""!=b)try{this._value=JSON.parse(b),this.boxcolor="#AEA"}catch(q){this.boxcolor="red"}};F.prototype.onExecute=function(){this.setOutputData(0,this._value)};F.prototype.setValue=A.prototype.setValue;p.registerNodeType("basic/data",F);I.title="Const Array";I.desc="Constant Array";I.prototype.onPropertyChanged=
|
||||
function(a,b){this.widget.value=b;if(null!=b&&""!=b)try{this._value="["!=b[0]?JSON.parse("["+b+"]"):JSON.parse(b),this.boxcolor="#AEA"}catch(q){this.boxcolor="red"}};I.prototype.onExecute=function(){var a=this.getInputData(0);if(a&&a.length){this._value||(this._value=[]);this._value.length=a.length;for(var b=0;b<a.length;++b)this._value[b]=a[b]}this.setOutputData(0,this._value);this.setOutputData(1,this._value?this._value.length||0:0)};I.prototype.setValue=A.prototype.setValue;p.registerNodeType("basic/array",
|
||||
I);f.title="Set Array";f.desc="Sets index of array";f.prototype.onExecute=function(){var a=this.getInputData(0);if(a){var b=this.getInputData(1);void 0!==b&&(this.properties.index&&(a[Math.floor(this.properties.index)]=b),this.setOutputData(0,a))}};p.registerNodeType("basic/set_array",f);z.title="Array[i]";z.desc="Returns an element from an array";z.prototype.onExecute=function(){var a=this.getInputData(0),b=this.getInputData(1);null==b&&(b=this.properties.index);null!=a&&null!=b&&this.setOutputData(0,
|
||||
a[Math.floor(Number(b))])};p.registerNodeType("basic/array[]",z);H.title="Table[row][col]";H.desc="Returns an element from a table";H.prototype.onExecute=function(){var a=this.getInputData(0),b=this.getInputData(1),c=this.getInputData(2);null==b&&(b=this.properties.row);null==c&&(c=this.properties.column);null!=a&&null!=b&&null!=c&&((b=a[Math.floor(Number(b))])?this.setOutputData(0,b[Math.floor(Number(c))]):this.setOutputData(0,null))};p.registerNodeType("basic/table[][]",H);C.title="Object property";
|
||||
C.desc="Outputs the property of an object";C.prototype.setValue=function(a){this.properties.value=a;this.widget.value=a};C.prototype.getTitle=function(){return this.flags.collapsed?"in."+this.properties.value:this.title};C.prototype.onPropertyChanged=function(a,b){this.widget.value=b};C.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,a[this.properties.value])};p.registerNodeType("basic/object_property",C);L.title="Object keys";L.desc="Outputs an array with the keys of an object";
|
||||
L.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,Object.keys(a))};p.registerNodeType("basic/object_keys",L);G.title="Set Object";G.desc="Adds propertiesrty to object";G.prototype.onExecute=function(){var a=this.getInputData(0);if(a){var b=this.getInputData(1);void 0!==b&&(this.properties.property&&(a[this.properties.property]=b),this.setOutputData(0,a))}};p.registerNodeType("basic/set_object",G);K.title="Merge Objects";K.desc="Creates an object copying properties from others";
|
||||
K.prototype.onExecute=function(){var a=this.getInputData(0),b=this.getInputData(1),c=this._result;if(a)for(var d in a)c[d]=a[d];if(b)for(d in b)c[d]=b[d];this.setOutputData(0,c)};p.registerNodeType("basic/merge_objects",K);J.title="Variable";J.desc="store/read variable value";J.LITEGRAPH=0;J.GRAPH=1;J.GLOBALSCOPE=2;J["@container"]={type:"enum",values:{litegraph:J.LITEGRAPH,graph:J.GRAPH,global:J.GLOBALSCOPE}};J.prototype.onExecute=function(){var a=this.getContainer();this.isInputConnected(0)?(this.value=
|
||||
this.getInputData(0),a[this.properties.varname]=this.value,this.setOutputData(0,this.value)):this.setOutputData(0,a[this.properties.varname])};J.prototype.getContainer=function(){switch(this.properties.container){case J.GRAPH:return this.graph?this.graph.vars:{};case J.GLOBALSCOPE:return x;default:return p.Globals}};J.prototype.getTitle=function(){return this.properties.varname};p.registerNodeType("basic/variable",J);p.wrapFunctionAsNode("basic/length",a,[""],"number");p.wrapFunctionAsNode("basic/not",
|
||||
function(a){return!a},[""],"boolean");b.title="Download";b.desc="Download some data";b.prototype.downloadAsFile=function(){if(null!=this.value){var a=null;a=this.value.constructor===String?this.value:JSON.stringify(this.value);a=new Blob([a]);var b=URL.createObjectURL(a);a=document.createElement("a");a.setAttribute("href",b);a.setAttribute("download",this.properties.filename);a.style.display="none";document.body.appendChild(a);a.click();document.body.removeChild(a);setTimeout(function(){URL.revokeObjectURL(b)},
|
||||
6E4)}};b.prototype.onAction=function(a,b){var c=this;setTimeout(function(){c.downloadAsFile()},100)};b.prototype.onExecute=function(){this.inputs[0]&&(this.value=this.getInputData(0))};b.prototype.getTitle=function(){return this.flags.collapsed?this.properties.filename:this.title};p.registerNodeType("basic/download",b);c.title="Watch";c.desc="Show value of input";c.prototype.onExecute=function(){this.inputs[0]&&(this.value=this.getInputData(0))};c.prototype.getTitle=function(){return this.flags.collapsed?
|
||||
this.inputs[0].label:this.title};c.toString=function(a){if(null==a)return"null";if(a.constructor===Number)return a.toFixed(3);if(a.constructor===Array){for(var b="[",d=0;d<a.length;++d)b+=c.toString(a[d])+(d+1!=a.length?",":"");return b+"]"}return String(a)};c.prototype.onDrawBackground=function(a){this.inputs[0].label=c.toString(this.value)};p.registerNodeType("basic/watch",c);d.title="Cast";d.desc="Allows to connect different types";d.prototype.onExecute=function(){this.setOutputData(0,this.getInputData(0))};
|
||||
p.registerNodeType("basic/cast",d);e.title="Console";e.desc="Show value inside the console";e.prototype.onAction=function(a,b){var c=this.getInputData(1);c||(c=this.properties.msg);c||(c="Event: "+b);"log"==a?console.log(c):"warn"==a?console.warn(c):"error"==a&&console.error(c)};e.prototype.onExecute=function(){var a=this.getInputData(1);a||(a=this.properties.msg);null!=a&&"undefined"!=typeof a&&(this.properties.msg=a,console.log(a))};e.prototype.onGetInputs=function(){return[["log",p.ACTION],["warn",
|
||||
p.ACTION],["error",p.ACTION]]};p.registerNodeType("basic/console",e);g.title="Alert";g.desc="Show an alert window";g.color="#510";g.prototype.onConfigure=function(a){this.widget.value=a.properties.msg};g.prototype.onAction=function(a,b){var c=this.properties.msg;setTimeout(function(){alert(c)},10)};p.registerNodeType("basic/alert",g);k.prototype.onConfigure=function(a){a.properties.onExecute&&p.allow_scripts?this.compileCode(a.properties.onExecute):console.warn("Script not compiled, LiteGraph.allow_scripts is false")};
|
||||
k.title="Script";k.desc="executes a code (max 100 characters)";k.widgets_info={onExecute:{type:"code"}};k.prototype.onPropertyChanged=function(a,b){"onExecute"==a&&p.allow_scripts?this.compileCode(b):console.warn("Script not compiled, LiteGraph.allow_scripts is false")};k.prototype.compileCode=function(a){this._func=null;if(256<a.length)console.warn("Script too long, max 256 chars");else{for(var b=a.toLowerCase(),c="script body document eval nodescript function".split(" "),d=0;d<c.length;++d)if(-1!=
|
||||
b.indexOf(c[d])){console.warn("invalid script");return}try{this._func=new Function("A","B","C","DATA","node",a)}catch(M){console.error("Error parsing script"),console.error(M)}}};k.prototype.onExecute=function(){if(this._func)try{var a=this.getInputData(0),b=this.getInputData(1),c=this.getInputData(2);this.setOutputData(0,this._func(a,b,c,this.data,this))}catch(y){console.error("Error in script"),console.error(y)}};k.prototype.onGetOutputs=function(){return[["C",""]]};p.registerNodeType("basic/script",
|
||||
k);n.values=["==","!="];n["@OP"]={type:"enum",title:"operation",values:n.values};n.title="Compare *";n.desc="evaluates condition between A and B";n.prototype.getTitle=function(){return"*A "+this.properties.OP+" *B"};n.prototype.onExecute=function(){var a=this.getInputData(0);void 0===a?a=this.properties.A:this.properties.A=a;var b=this.getInputData(1);void 0===b?b=this.properties.B:this.properties.B=b;var c=!1;if(typeof a==typeof b)switch(this.properties.OP){case "==":case "!=":c=!0;switch(typeof a){case "object":var d=
|
||||
Object.getOwnPropertyNames(a),e=Object.getOwnPropertyNames(b);if(d.length!=e.length){c=!1;break}for(e=0;e<d.length;e++){var f=d[e];if(a[f]!==b[f]){c=!1;break}}break;default:c=a==b}"!="==this.properties.OP&&(c=!c)}this.setOutputData(0,c);this.setOutputData(1,!c)};p.registerNodeType("basic/CompareValues",n)})(this);
|
||||
(function(x){function m(){this.size=[60,30];this.addInput("event",f.ACTION)}function t(){this.size=[60,30];this.addInput("if","");this.addOutput("true",f.EVENT);this.addOutput("change",f.EVENT);this.addOutput("false",f.EVENT);this.properties={only_on_change:!0};this.prev=0}function l(){var h=this;this.addInput("",f.ACTION);this.addInput("",f.ACTION);this.addInput("",f.ACTION);this.addOutput("",f.EVENT);this.addOutput("",f.EVENT);this.addOutput("",f.EVENT);this.addWidget("button","+",null,function(){h.addInput("",
|
||||
f.ACTION);h.addOutput("",f.EVENT)});this.size=[90,70];this.flags={horizontal:!0,render_box:!1}}function w(){var h=this;this.properties={index:0};this.addInput("index","number");this.addInput("step",f.ACTION);this.addInput("reset",f.ACTION);this.addOutput("index","number");this.addOutput("",f.EVENT);this.addOutput("",f.EVENT);this.addOutput("",f.EVENT,{removable:!0});this.addWidget("button","+",null,function(){h.addOutput("",f.EVENT,{removable:!0})});this.size=[120,120];this.flags={render_box:!1}}
|
||||
function z(){this.size=[60,30];this.addInput("event",f.ACTION);this.addOutput("event",f.EVENT);this.properties={equal_to:"",has_property:"",property_equal_to:""}}function h(){this.addInput("in",f.ACTION);this.addInput("cond","boolean");this.addOutput("true",f.EVENT);this.addOutput("false",f.EVENT);this.size=[120,60];this._value=!1}function D(){this.addInput("inc",f.ACTION);this.addInput("dec",f.ACTION);this.addInput("reset",f.ACTION);this.addOutput("change",f.EVENT);this.addOutput("num","number");
|
||||
this.addProperty("doCountExecution",!1,"boolean",{name:"Count Executions"});this.addWidget("toggle","Count Exec.",this.properties.doCountExecution,"doCountExecution");this.num=0}function C(){this.size=[60,30];this.addProperty("time_in_ms",1E3);this.addInput("event",f.ACTION);this.addOutput("on_time",f.EVENT);this._pending=[]}function A(){this.addProperty("interval",1E3);this.addProperty("event","tick");this.addOutput("on_tick",f.EVENT);this.time=0;this.last_interval=1E3;this.triggered=!1}function E(){this.addInput("go",
|
||||
f.ACTION);this.addInput("green",f.ACTION);this.addInput("red",f.ACTION);this.addOutput("continue",f.EVENT);this.addOutput("blocked",f.EVENT);this.addOutput("is_green","boolean");this._ready=!1;this.properties={};var h=this;this.addWidget("button","reset","",function(){h._ready=!1})}function G(){this.addInput("data",0);this.addInput("assign",f.ACTION);this.addOutput("data",0);this._last_value=null;this.properties={data:null,serialize:!0};var h=this;this.addWidget("button","store","",function(){h.properties.data=
|
||||
h._last_value})}var f=x.LiteGraph;m.title="Log Event";m.desc="Log event in console";m.prototype.onAction=function(f,h,l){console.log(f,h)};f.registerNodeType("events/log",m);t.title="TriggerEvent";t.desc="Triggers event if input evaluates to true";t.prototype.onExecute=function(f,h){var l=this.getInputData(0),m=l!=this.prev;0===this.prev&&(m=!1);var w=m&&this.properties.only_on_change||!m&&!this.properties.only_on_change;l&&w&&this.triggerSlot(0,f,null,h);!l&&w&&this.triggerSlot(2,f,null,h);m&&this.triggerSlot(1,
|
||||
f,null,h);this.prev=l};f.registerNodeType("events/trigger",t);l.title="Sequence";l.desc="Triggers a sequence of events when an event arrives";l.prototype.getTitle=function(){return""};l.prototype.onAction=function(f,h,l){if(this.outputs){l=l||{};for(var m=0;m<this.outputs.length;++m)l.action_call=l.action_call?l.action_call+"_seq_"+m:this.id+"_"+(f?f:"action")+"_seq_"+m+"_"+Math.floor(9999*Math.random()),this.triggerSlot(m,h,null,l)}};f.registerNodeType("events/sequence",l);w.title="Stepper";w.desc=
|
||||
"Trigger events sequentially when an tick arrives";w.prototype.onDrawBackground=function(h){if(!this.flags.collapsed){var l=this.properties.index||0;h.fillStyle="#AFB";var m=this.size[0];l=(l+1)*f.NODE_SLOT_HEIGHT+4;h.beginPath();h.moveTo(m-30,l);h.lineTo(m-30,l+f.NODE_SLOT_HEIGHT);h.lineTo(m-15,l+.5*f.NODE_SLOT_HEIGHT);h.fill()}};w.prototype.onExecute=function(){var f=this.getInputData(0);null!=f&&(f=Math.floor(f),f=Math.clamp(f,0,this.outputs?this.outputs.length-2:0),f!=this.properties.index&&(this.properties.index=
|
||||
f,this.triggerSlot(f+1)));this.setOutputData(0,this.properties.index)};w.prototype.onAction=function(f,h){"reset"==f?this.properties.index=0:"step"==f&&(this.triggerSlot(this.properties.index+1,h),this.properties.index=(this.properties.index+1)%(this.outputs?this.outputs.length-1:0))};f.registerNodeType("events/stepper",w);z.title="Filter Event";z.desc="Blocks events that do not match the filter";z.prototype.onAction=function(f,h,l){if(null!=h&&(!this.properties.equal_to||this.properties.equal_to==
|
||||
h)){if(this.properties.has_property&&(f=h[this.properties.has_property],null==f||this.properties.property_equal_to&&this.properties.property_equal_to!=f))return;this.triggerSlot(0,h,null,l)}};f.registerNodeType("events/filter",z);h.title="Branch";h.desc="If condition is true, outputs triggers true, otherwise false";h.prototype.onExecute=function(){this._value=this.getInputData(1)};h.prototype.onAction=function(f,h,l){this._value=this.getInputData(1);this.triggerSlot(this._value?0:1,h,null,l)};f.registerNodeType("events/branch",
|
||||
h);D.title="Counter";D.desc="Counts events";D.prototype.getTitle=function(){return this.flags.collapsed?String(this.num):this.title};D.prototype.onAction=function(f,h,l){h=this.num;"inc"==f?this.num+=1:"dec"==f?--this.num:"reset"==f&&(this.num=0);this.num!=h&&this.trigger("change",this.num)};D.prototype.onDrawBackground=function(f){this.flags.collapsed||(f.fillStyle="#AAA",f.font="20px Arial",f.textAlign="center",f.fillText(this.num,.5*this.size[0],.5*this.size[1]))};D.prototype.onExecute=function(){this.properties.doCountExecution&&
|
||||
(this.num+=1);this.setOutputData(1,this.num)};f.registerNodeType("events/counter",D);C.title="Delay";C.desc="Delays one event";C.prototype.onAction=function(f,h,l){f=this.properties.time_in_ms;0>=f?this.trigger(null,h,l):this._pending.push([f,h])};C.prototype.onExecute=function(f,h){f=1E3*this.graph.elapsed_time;this.isInputConnected(1)&&(this.properties.time_in_ms=this.getInputData(1));for(var l=0;l<this._pending.length;++l){var m=this._pending[l];m[0]-=f;0<m[0]||(this._pending.splice(l,1),--l,this.trigger(null,
|
||||
m[1],h))}};C.prototype.onGetInputs=function(){return[["event",f.ACTION],["time_in_ms","number"]]};f.registerNodeType("events/delay",C);A.title="Timer";A.desc="Sends an event every N milliseconds";A.prototype.onStart=function(){this.time=0};A.prototype.getTitle=function(){return"Timer: "+this.last_interval.toString()+"ms"};A.on_color="#AAA";A.off_color="#222";A.prototype.onDrawBackground=function(){this.boxcolor=this.triggered?A.on_color:A.off_color;this.triggered=!1};A.prototype.onExecute=function(){var f=
|
||||
0==this.time;this.time+=1E3*this.graph.elapsed_time;this.last_interval=Math.max(1,this.getInputOrProperty("interval")|0);!f&&(this.time<this.last_interval||isNaN(this.last_interval))?this.inputs&&1<this.inputs.length&&this.inputs[1]&&this.setOutputData(1,!1):(this.triggered=!0,this.time%=this.last_interval,this.trigger("on_tick",this.properties.event),this.inputs&&1<this.inputs.length&&this.inputs[1]&&this.setOutputData(1,!0))};A.prototype.onGetInputs=function(){return[["interval","number"]]};A.prototype.onGetOutputs=
|
||||
function(){return[["tick","boolean"]]};f.registerNodeType("events/timer",A);E.title="Semaphore Event";E.desc="Until both events are not triggered, it doesnt continue.";E.prototype.onExecute=function(){this.setOutputData(1,this._ready);this.boxcolor=this._ready?"#9F9":"#FA5"};E.prototype.onAction=function(f,h){"go"==f?this.triggerSlot(this._ready?0:1):"green"==f?this._ready=!0:"red"==f&&(this._ready=!1)};f.registerNodeType("events/semaphore",E);G.title="Data Store";G.desc="Stores data and only changes when event is received";
|
||||
G.prototype.onExecute=function(){this._last_value=this.getInputData(0);this.setOutputData(0,this.properties.data)};G.prototype.onAction=function(f,h,l){this.properties.data=this._last_value};G.prototype.onSerialize=function(f){null!=f.data&&(0==this.properties.serialize||f.data.constructor!==String&&f.data.constructor!==Number&&f.data.constructor!==Boolean&&f.data.constructor!==Array&&f.data.constructor!==Object)&&(f.data=null)};f.registerNodeType("basic/data_store",G)})(this);
|
||||
p.ACTION],["error",p.ACTION]]};p.registerNodeType("basic/console",e);g.title="Alert";g.desc="Show an alert window";g.color="#510";g.prototype.onConfigure=function(a){this.widget.value=a.properties.msg};g.prototype.onAction=function(a,b){var c=this.properties.msg;setTimeout(function(){alert(c)},10)};p.registerNodeType("basic/alert",g);h.prototype.onConfigure=function(a){a.properties.onExecute&&p.allow_scripts?this.compileCode(a.properties.onExecute):console.warn("Script not compiled, LiteGraph.allow_scripts is false")};
|
||||
h.title="Script";h.desc="executes a code (max 256 characters)";h.widgets_info={onExecute:{type:"code"}};h.prototype.onPropertyChanged=function(a,b){"onExecute"==a&&p.allow_scripts?this.compileCode(b):console.warn("Script not compiled, LiteGraph.allow_scripts is false")};h.prototype.compileCode=function(a){this._func=null;if(256<a.length)console.warn("Script too long, max 256 chars");else{for(var b=a.toLowerCase(),c="script body document eval nodescript function".split(" "),d=0;d<c.length;++d)if(-1!=
|
||||
b.indexOf(c[d])){console.warn("invalid script");return}try{this._func=new Function("A","B","C","DATA","node",a)}catch(M){console.error("Error parsing script"),console.error(M)}}};h.prototype.onExecute=function(){if(this._func)try{var a=this.getInputData(0),b=this.getInputData(1),c=this.getInputData(2);this.setOutputData(0,this._func(a,b,c,this.data,this))}catch(y){console.error("Error in script"),console.error(y)}};h.prototype.onGetOutputs=function(){return[["C",""]]};p.registerNodeType("basic/script",
|
||||
h);n.values=["==","!="];n["@OP"]={type:"enum",title:"operation",values:n.values};n.title="Compare *";n.desc="evaluates condition between A and B";n.prototype.getTitle=function(){return"*A "+this.properties.OP+" *B"};n.prototype.onExecute=function(){var a=this.getInputData(0);void 0===a?a=this.properties.A:this.properties.A=a;var b=this.getInputData(1);void 0===b?b=this.properties.B:this.properties.B=b;var c=!1;if(typeof a==typeof b)switch(this.properties.OP){case "==":case "!=":c=!0;switch(typeof a){case "object":var d=
|
||||
Object.getOwnPropertyNames(a),e=Object.getOwnPropertyNames(b);if(d.length!=e.length){c=!1;break}for(e=0;e<d.length;e++){var g=d[e];if(a[g]!==b[g]){c=!1;break}}break;default:c=a==b}"!="==this.properties.OP&&(c=!c)}this.setOutputData(0,c);this.setOutputData(1,!c)};p.registerNodeType("basic/CompareValues",n)})(this);
|
||||
(function(x){function m(){this.size=[60,30];this.addInput("event",z.ACTION)}function t(){this.size=[60,30];this.addInput("if","");this.addOutput("true",z.EVENT);this.addOutput("change",z.EVENT);this.addOutput("false",z.EVENT);this.properties={only_on_change:!0};this.prev=0}function l(){var f=this;this.addInput("",z.ACTION);this.addInput("",z.ACTION);this.addInput("",z.ACTION);this.addOutput("",z.EVENT);this.addOutput("",z.EVENT);this.addOutput("",z.EVENT);this.addWidget("button","+",null,function(){f.addInput("",
|
||||
z.ACTION);f.addOutput("",z.EVENT)});this.size=[90,70];this.flags={horizontal:!0,render_box:!1}}function w(){var f=this;this.properties={index:0};this.addInput("index","number");this.addInput("step",z.ACTION);this.addInput("reset",z.ACTION);this.addOutput("index","number");this.addOutput("",z.EVENT);this.addOutput("",z.EVENT);this.addOutput("",z.EVENT,{removable:!0});this.addWidget("button","+",null,function(){f.addOutput("",z.EVENT,{removable:!0})});this.size=[120,120];this.flags={render_box:!1}}
|
||||
function A(){this.size=[60,30];this.addInput("event",z.ACTION);this.addOutput("event",z.EVENT);this.properties={equal_to:"",has_property:"",property_equal_to:""}}function k(){this.addInput("in",z.ACTION);this.addInput("cond","boolean");this.addOutput("true",z.EVENT);this.addOutput("false",z.EVENT);this.size=[120,60];this._value=!1}function E(){this.addInput("inc",z.ACTION);this.addInput("dec",z.ACTION);this.addInput("reset",z.ACTION);this.addOutput("change",z.EVENT);this.addOutput("num","number");
|
||||
this.addProperty("doCountExecution",!1,"boolean",{name:"Count Executions"});this.addWidget("toggle","Count Exec.",this.properties.doCountExecution,"doCountExecution");this.num=0}function D(){this.size=[60,30];this.addProperty("time_in_ms",1E3);this.addInput("event",z.ACTION);this.addOutput("on_time",z.EVENT);this._pending=[]}function B(){this.addProperty("interval",1E3);this.addProperty("event","tick");this.addOutput("on_tick",z.EVENT);this.time=0;this.last_interval=1E3;this.triggered=!1}function F(){this.addInput("go",
|
||||
z.ACTION);this.addInput("green",z.ACTION);this.addInput("red",z.ACTION);this.addOutput("continue",z.EVENT);this.addOutput("blocked",z.EVENT);this.addOutput("is_green","boolean");this._ready=!1;this.properties={};var f=this;this.addWidget("button","reset","",function(){f._ready=!1})}function I(){this.addInput("in",z.ACTION);this.addInput("reset",z.ACTION);this.addOutput("out",z.EVENT);this._once=!1;this.properties={};var f=this;this.addWidget("button","reset","",function(){f._once=!1})}function f(){this.addInput("data",
|
||||
0);this.addInput("assign",z.ACTION);this.addOutput("data",0);this._last_value=null;this.properties={data:null,serialize:!0};var f=this;this.addWidget("button","store","",function(){f.properties.data=f._last_value})}var z=x.LiteGraph;m.title="Log Event";m.desc="Log event in console";m.prototype.onAction=function(f,k,l){console.log(f,k)};z.registerNodeType("events/log",m);t.title="TriggerEvent";t.desc="Triggers event if input evaluates to true";t.prototype.onExecute=function(f,k){var l=this.getInputData(0),
|
||||
m=l!=this.prev;0===this.prev&&(m=!1);var w=m&&this.properties.only_on_change||!m&&!this.properties.only_on_change;l&&w&&this.triggerSlot(0,f,null,k);!l&&w&&this.triggerSlot(2,f,null,k);m&&this.triggerSlot(1,f,null,k);this.prev=l};z.registerNodeType("events/trigger",t);l.title="Sequence";l.desc="Triggers a sequence of events when an event arrives";l.prototype.getTitle=function(){return""};l.prototype.onAction=function(f,k,l){if(this.outputs){l=l||{};for(var m=0;m<this.outputs.length;++m)l.action_call=
|
||||
l.action_call?l.action_call+"_seq_"+m:this.id+"_"+(f?f:"action")+"_seq_"+m+"_"+Math.floor(9999*Math.random()),this.triggerSlot(m,k,null,l)}};z.registerNodeType("events/sequence",l);w.title="Stepper";w.desc="Trigger events sequentially when an tick arrives";w.prototype.onDrawBackground=function(f){if(!this.flags.collapsed){var k=this.properties.index||0;f.fillStyle="#AFB";var l=this.size[0];k=(k+1)*z.NODE_SLOT_HEIGHT+4;f.beginPath();f.moveTo(l-30,k);f.lineTo(l-30,k+z.NODE_SLOT_HEIGHT);f.lineTo(l-15,
|
||||
k+.5*z.NODE_SLOT_HEIGHT);f.fill()}};w.prototype.onExecute=function(){var f=this.getInputData(0);null!=f&&(f=Math.floor(f),f=Math.clamp(f,0,this.outputs?this.outputs.length-2:0),f!=this.properties.index&&(this.properties.index=f,this.triggerSlot(f+1)));this.setOutputData(0,this.properties.index)};w.prototype.onAction=function(f,k){"reset"==f?this.properties.index=0:"step"==f&&(this.triggerSlot(this.properties.index+1,k),this.properties.index=(this.properties.index+1)%(this.outputs?this.outputs.length-
|
||||
1:0))};z.registerNodeType("events/stepper",w);A.title="Filter Event";A.desc="Blocks events that do not match the filter";A.prototype.onAction=function(f,k,l){if(null!=k&&(!this.properties.equal_to||this.properties.equal_to==k)){if(this.properties.has_property&&(f=k[this.properties.has_property],null==f||this.properties.property_equal_to&&this.properties.property_equal_to!=f))return;this.triggerSlot(0,k,null,l)}};z.registerNodeType("events/filter",A);k.title="Branch";k.desc="If condition is true, outputs triggers true, otherwise false";
|
||||
k.prototype.onExecute=function(){this._value=this.getInputData(1)};k.prototype.onAction=function(f,k,l){this._value=this.getInputData(1);this.triggerSlot(this._value?0:1,k,null,l)};z.registerNodeType("events/branch",k);E.title="Counter";E.desc="Counts events";E.prototype.getTitle=function(){return this.flags.collapsed?String(this.num):this.title};E.prototype.onAction=function(f,k,l){k=this.num;"inc"==f?this.num+=1:"dec"==f?--this.num:"reset"==f&&(this.num=0);this.num!=k&&this.trigger("change",this.num)};
|
||||
E.prototype.onDrawBackground=function(f){this.flags.collapsed||(f.fillStyle="#AAA",f.font="20px Arial",f.textAlign="center",f.fillText(this.num,.5*this.size[0],.5*this.size[1]))};E.prototype.onExecute=function(){this.properties.doCountExecution&&(this.num+=1);this.setOutputData(1,this.num)};z.registerNodeType("events/counter",E);D.title="Delay";D.desc="Delays one event";D.prototype.onAction=function(f,k,l){f=this.properties.time_in_ms;0>=f?this.trigger(null,k,l):this._pending.push([f,k])};D.prototype.onExecute=
|
||||
function(f,k){f=1E3*this.graph.elapsed_time;this.isInputConnected(1)&&(this.properties.time_in_ms=this.getInputData(1));for(var l=0;l<this._pending.length;++l){var m=this._pending[l];m[0]-=f;0<m[0]||(this._pending.splice(l,1),--l,this.trigger(null,m[1],k))}};D.prototype.onGetInputs=function(){return[["event",z.ACTION],["time_in_ms","number"]]};z.registerNodeType("events/delay",D);B.title="Timer";B.desc="Sends an event every N milliseconds";B.prototype.onStart=function(){this.time=0};B.prototype.getTitle=
|
||||
function(){return"Timer: "+this.last_interval.toString()+"ms"};B.on_color="#AAA";B.off_color="#222";B.prototype.onDrawBackground=function(){this.boxcolor=this.triggered?B.on_color:B.off_color;this.triggered=!1};B.prototype.onExecute=function(){var f=0==this.time;this.time+=1E3*this.graph.elapsed_time;this.last_interval=Math.max(1,this.getInputOrProperty("interval")|0);!f&&(this.time<this.last_interval||isNaN(this.last_interval))?this.inputs&&1<this.inputs.length&&this.inputs[1]&&this.setOutputData(1,
|
||||
!1):(this.triggered=!0,this.time%=this.last_interval,this.trigger("on_tick",this.properties.event),this.inputs&&1<this.inputs.length&&this.inputs[1]&&this.setOutputData(1,!0))};B.prototype.onGetInputs=function(){return[["interval","number"]]};B.prototype.onGetOutputs=function(){return[["tick","boolean"]]};z.registerNodeType("events/timer",B);F.title="Semaphore Event";F.desc="Until both events are not triggered, it doesnt continue.";F.prototype.onExecute=function(){this.setOutputData(1,this._ready);
|
||||
this.boxcolor=this._ready?"#9F9":"#FA5"};F.prototype.onAction=function(f,k){"go"==f?this.triggerSlot(this._ready?0:1):"green"==f?this._ready=!0:"red"==f&&(this._ready=!1)};z.registerNodeType("events/semaphore",F);I.title="Once";I.desc="Only passes an event once, then gets locked";I.prototype.onAction=function(f,k){"in"!=f||this._once?"reset"==f&&(this._once=!1):(this._once=!0,this.triggerSlot(0,k))};z.registerNodeType("events/once",I);f.title="Data Store";f.desc="Stores data and only changes when event is received";
|
||||
f.prototype.onExecute=function(){this._last_value=this.getInputData(0);this.setOutputData(0,this.properties.data)};f.prototype.onAction=function(f,k,l){this.properties.data=this._last_value};f.prototype.onSerialize=function(f){null!=f.data&&(0==this.properties.serialize||f.data.constructor!==String&&f.data.constructor!==Number&&f.data.constructor!==Boolean&&f.data.constructor!==Array&&f.data.constructor!==Object)&&(f.data=null)};z.registerNodeType("basic/data_store",f)})(this);
|
||||
(function(x){function m(){this.addOutput("left_x_axis","number");this.addOutput("left_y_axis","number");this.addOutput("button_pressed",t.EVENT);this.properties={gamepad_index:0,threshold:.1};this._left_axis=new Float32Array(2);this._right_axis=new Float32Array(2);this._triggers=new Float32Array(2);this._previous_buttons=new Uint8Array(17);this._current_buttons=new Uint8Array(17)}var t=x.LiteGraph;m.title="Gamepad";m.desc="gets the input of the gamepad";m.CENTER=0;m.LEFT=1;m.RIGHT=2;m.UP=4;m.DOWN=
|
||||
8;m.zero=new Float32Array(2);m.buttons="a b x y lb rb lt rt back start ls rs home".split(" ");m.prototype.onExecute=function(){var l=this.getGamepad(),w=this.properties.threshold||0;l&&(this._left_axis[0]=Math.abs(l.xbox.axes.lx)>w?l.xbox.axes.lx:0,this._left_axis[1]=Math.abs(l.xbox.axes.ly)>w?l.xbox.axes.ly:0,this._right_axis[0]=Math.abs(l.xbox.axes.rx)>w?l.xbox.axes.rx:0,this._right_axis[1]=Math.abs(l.xbox.axes.ry)>w?l.xbox.axes.ry:0,this._triggers[0]=Math.abs(l.xbox.axes.ltrigger)>w?l.xbox.axes.ltrigger:
|
||||
0,this._triggers[1]=Math.abs(l.xbox.axes.rtrigger)>w?l.xbox.axes.rtrigger:0);if(this.outputs)for(w=0;w<this.outputs.length;w++){var t=this.outputs[w];if(t.links&&t.links.length){var h=null;if(l)switch(t.name){case "left_axis":h=this._left_axis;break;case "right_axis":h=this._right_axis;break;case "left_x_axis":h=this._left_axis[0];break;case "left_y_axis":h=this._left_axis[1];break;case "right_x_axis":h=this._right_axis[0];break;case "right_y_axis":h=this._right_axis[1];break;case "trigger_left":h=
|
||||
this._triggers[0];break;case "trigger_right":h=this._triggers[1];break;case "a_button":h=l.xbox.buttons.a?1:0;break;case "b_button":h=l.xbox.buttons.b?1:0;break;case "x_button":h=l.xbox.buttons.x?1:0;break;case "y_button":h=l.xbox.buttons.y?1:0;break;case "lb_button":h=l.xbox.buttons.lb?1:0;break;case "rb_button":h=l.xbox.buttons.rb?1:0;break;case "ls_button":h=l.xbox.buttons.ls?1:0;break;case "rs_button":h=l.xbox.buttons.rs?1:0;break;case "hat_left":h=l.xbox.hatmap&m.LEFT;break;case "hat_right":h=
|
||||
l.xbox.hatmap&m.RIGHT;break;case "hat_up":h=l.xbox.hatmap&m.UP;break;case "hat_down":h=l.xbox.hatmap&m.DOWN;break;case "hat":h=l.xbox.hatmap;break;case "start_button":h=l.xbox.buttons.start?1:0;break;case "back_button":h=l.xbox.buttons.back?1:0;break;case "button_pressed":for(t=0;t<this._current_buttons.length;++t)this._current_buttons[t]&&!this._previous_buttons[t]&&this.triggerSlot(w,m.buttons[t])}else switch(t.name){case "button_pressed":break;case "left_axis":case "right_axis":h=m.zero;break;
|
||||
default:h=0}this.setOutputData(w,h)}}};m.mapping={a:0,b:1,x:2,y:3,lb:4,rb:5,lt:6,rt:7,back:8,start:9,ls:10,rs:11};m.mapping_array="a b x y lb rb lt rt back start ls rs".split(" ");m.prototype.getGamepad=function(){var l=navigator.getGamepads||navigator.webkitGetGamepads||navigator.mozGetGamepads;if(!l)return null;l=l.call(navigator);this._previous_buttons.set(this._current_buttons);for(var w=this.properties.gamepad_index;4>w;w++)if(l[w]){l=l[w];w=this.xbox_mapping;w||(w=this.xbox_mapping={axes:[],
|
||||
0,this._triggers[1]=Math.abs(l.xbox.axes.rtrigger)>w?l.xbox.axes.rtrigger:0);if(this.outputs)for(w=0;w<this.outputs.length;w++){var t=this.outputs[w];if(t.links&&t.links.length){var k=null;if(l)switch(t.name){case "left_axis":k=this._left_axis;break;case "right_axis":k=this._right_axis;break;case "left_x_axis":k=this._left_axis[0];break;case "left_y_axis":k=this._left_axis[1];break;case "right_x_axis":k=this._right_axis[0];break;case "right_y_axis":k=this._right_axis[1];break;case "trigger_left":k=
|
||||
this._triggers[0];break;case "trigger_right":k=this._triggers[1];break;case "a_button":k=l.xbox.buttons.a?1:0;break;case "b_button":k=l.xbox.buttons.b?1:0;break;case "x_button":k=l.xbox.buttons.x?1:0;break;case "y_button":k=l.xbox.buttons.y?1:0;break;case "lb_button":k=l.xbox.buttons.lb?1:0;break;case "rb_button":k=l.xbox.buttons.rb?1:0;break;case "ls_button":k=l.xbox.buttons.ls?1:0;break;case "rs_button":k=l.xbox.buttons.rs?1:0;break;case "hat_left":k=l.xbox.hatmap&m.LEFT;break;case "hat_right":k=
|
||||
l.xbox.hatmap&m.RIGHT;break;case "hat_up":k=l.xbox.hatmap&m.UP;break;case "hat_down":k=l.xbox.hatmap&m.DOWN;break;case "hat":k=l.xbox.hatmap;break;case "start_button":k=l.xbox.buttons.start?1:0;break;case "back_button":k=l.xbox.buttons.back?1:0;break;case "button_pressed":for(t=0;t<this._current_buttons.length;++t)this._current_buttons[t]&&!this._previous_buttons[t]&&this.triggerSlot(w,m.buttons[t])}else switch(t.name){case "button_pressed":break;case "left_axis":case "right_axis":k=m.zero;break;
|
||||
default:k=0}this.setOutputData(w,k)}}};m.mapping={a:0,b:1,x:2,y:3,lb:4,rb:5,lt:6,rt:7,back:8,start:9,ls:10,rs:11};m.mapping_array="a b x y lb rb lt rt back start ls rs".split(" ");m.prototype.getGamepad=function(){var l=navigator.getGamepads||navigator.webkitGetGamepads||navigator.mozGetGamepads;if(!l)return null;l=l.call(navigator);this._previous_buttons.set(this._current_buttons);for(var w=this.properties.gamepad_index;4>w;w++)if(l[w]){l=l[w];w=this.xbox_mapping;w||(w=this.xbox_mapping={axes:[],
|
||||
buttons:{},hat:"",hatmap:m.CENTER});w.axes.lx=l.axes[0];w.axes.ly=l.axes[1];w.axes.rx=l.axes[2];w.axes.ry=l.axes[3];w.axes.ltrigger=l.buttons[6].value;w.axes.rtrigger=l.buttons[7].value;w.hat="";w.hatmap=m.CENTER;for(var t=0;t<l.buttons.length;t++)if(this._current_buttons[t]=l.buttons[t].pressed,12>t)w.buttons[m.mapping_array[t]]=l.buttons[t].pressed,l.buttons[t].was_pressed&&this.trigger(m.mapping_array[t]+"_button_event");else switch(t){case 12:l.buttons[t].pressed&&(w.hat+="up",w.hatmap|=m.UP);
|
||||
break;case 13:l.buttons[t].pressed&&(w.hat+="down",w.hatmap|=m.DOWN);break;case 14:l.buttons[t].pressed&&(w.hat+="left",w.hatmap|=m.LEFT);break;case 15:l.buttons[t].pressed&&(w.hat+="right",w.hatmap|=m.RIGHT);break;case 16:w.buttons.home=l.buttons[t].pressed}l.xbox=w;return l}};m.prototype.onDrawBackground=function(l){if(!this.flags.collapsed){var m=this._left_axis,t=this._right_axis;l.strokeStyle="#88A";l.strokeRect(.5*(m[0]+1)*this.size[0]-4,.5*(m[1]+1)*this.size[1]-4,8,8);l.strokeStyle="#8A8";
|
||||
l.strokeRect(.5*(t[0]+1)*this.size[0]-4,.5*(t[1]+1)*this.size[1]-4,8,8);m=this.size[1]/this._current_buttons.length;l.fillStyle="#AEB";for(t=0;t<this._current_buttons.length;++t)this._current_buttons[t]&&l.fillRect(0,m*t,6,m)}};m.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",t.EVENT],["b_button_event",t.EVENT],["x_button_event",t.EVENT],["y_button_event",t.EVENT],["lb_button_event",t.EVENT],["rb_button_event",t.EVENT],["ls_button_event",t.EVENT],["rs_button_event",t.EVENT],["start_button_event",t.EVENT],["back_button_event",t.EVENT],["hat_left","number"],["hat_right",
|
||||
"number"],["hat_up","number"],["hat_down","number"],["hat","number"],["button_pressed",t.EVENT]]};t.registerNodeType("input/gamepad",m)})(this);
|
||||
(function(x){function m(){this.addInput("in",0);this.addOutput("out",0);this.size=[80,30]}function t(){this.addInput("in");this.addOutput("out");this.size=[80,30]}function l(){this.addInput("in");this.addOutput("out")}function w(){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 z(){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",.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",.2);this.size=[90,30];this._blink_time=this._remaining_time=0}function C(){this.addInput("in","number");this.addOutput("out","number");this.size=[80,30];this.addProperty("min",0);this.addProperty("max",1)}function A(){this.properties={f:.5};this.addInput("A","number");this.addInput("B","number");this.addOutput("out","number")}function E(){this.addInput("in","number");this.addOutput("out","number");this.size=[80,30]}function G(){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 L(){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 B(){this.addInput("v","boolean");this.addInput("A");this.addInput("B");this.addOutput("out")}
|
||||
function K(){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 F(){this.addInput("in","number");this.addOutput("out","number");this.addProperty("factor",.1);this.size=[80,30];this._value=null}function J(){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:J.values});this._func=function(a,b){return a+b};this._result=[]}function H(){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",
|
||||
1);this.size=[120,50]}function A(){this.addOutput("value","number");this.addProperty("min",0);this.addProperty("max",1);this.size=[80,30]}function k(){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",.8);this.addProperty("speed",1);this.size=[90,30]}function E(){this.addOutput("out","number");this.addProperty("min_time",
|
||||
1);this.addProperty("max_time",2);this.addProperty("duration",.2);this.size=[90,30];this._blink_time=this._remaining_time=0}function D(){this.addInput("in","number");this.addOutput("out","number");this.size=[80,30];this.addProperty("min",0);this.addProperty("max",1)}function B(){this.properties={f:.5};this.addInput("A","number");this.addInput("B","number");this.addOutput("out","number")}function F(){this.addInput("in","number");this.addOutput("out","number");this.size=[80,30]}function I(){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 z(){this.addInput("in","number");this.addOutput("out","number");this.size=[80,30];this.properties={A:0,B:1}}function H(){this.addInput("in","number",{label:""});this.addOutput("out","number",{label:""});this.size=[80,30];this.addProperty("factor",1)}function C(){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 G(){this.addInput("in","number");this.addOutput("out","number");this.addProperty("factor",.1);this.size=[80,30];this._value=null}function K(){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:K.values});this._func=function(a,b){return a+b};this._result=[]}function J(){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",0);this.addInput("cond","boolean");this.addOutput("true",0);this.addOutput("false",0);this.size=[80,60]}function c(){this.addInput("inc","number");this.addOutput("total","number");this.addProperty("increment",1);this.addProperty("value",0)}function d(){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,c){c.properties.formula=a});this.addWidget("toggle","allow",q.allow_scripts,function(a){q.allow_scripts=a});this._func=null}function g(){this.addInput("vec2","vec2");this.addOutput("x","number");this.addOutput("y","number")}function k(){this.addInputs([["x","number"],["y","number"]]);
|
||||
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,c){c.properties.formula=a});this.addWidget("toggle","allow",q.allow_scripts,function(a){q.allow_scripts=a});this._func=null}function g(){this.addInput("vec2","vec2");this.addOutput("x","number");this.addOutput("y","number")}function h(){this.addInputs([["x","number"],["y","number"]]);
|
||||
this.addOutput("vec2","vec2");this.properties={x:0,y:0};this._data=new Float32Array(2)}function n(){this.addInput("vec3","vec3");this.addOutput("x","number");this.addOutput("y","number");this.addOutput("z","number")}function p(){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 r(){this.addInput("vec4","vec4");this.addOutput("x","number");this.addOutput("y","number");this.addOutput("z",
|
||||
"number");this.addOutput("w","number")}function u(){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 q=x.LiteGraph;m.title="Converter";m.desc="type A to type B";m.prototype.onExecute=function(){var a=this.getInputData(0);if(null!=a&&this.outputs)for(var b=0;b<this.outputs.length;b++){var c=this.outputs[b];if(c.links&&c.links.length){var d=null;switch(c.name){case "number":d=
|
||||
a.length?a[0]:parseFloat(a);break;case "vec2":case "vec3":case "vec4":d=1;switch(c.name){case "vec2":d=2;break;case "vec3":d=3;break;case "vec4":d=4}d=new Float32Array(d);if(a.length)for(c=0;c<a.length&&c<d.length;c++)d[c]=a[c];else d[0]=parseFloat(a)}this.setOutputData(b,d)}}};m.prototype.onGetOutputs=function(){return[["number","number"],["vec2","vec2"],["vec3","vec3"],["vec4","vec4"]]};q.registerNodeType("math/converter",m);t.title="Bypass";t.desc="removes the type";t.prototype.onExecute=function(){var a=
|
||||
this.getInputData(0);this.setOutputData(0,a)};q.registerNodeType("math/bypass",t);l.title="to Number";l.desc="Cast to number";l.prototype.onExecute=function(){var a=this.getInputData(0);this.setOutputData(0,Number(a))};q.registerNodeType("math/to_number",l);w.title="Range";w.desc="Convert a number from one range to another";w.prototype.getTitle=function(){return this.flags.collapsed?(this._last_v||0).toFixed(2):this.title};w.prototype.onExecute=function(){if(this.inputs)for(var a=0;a<this.inputs.length;a++){var b=
|
||||
this.inputs[a],c=this.getInputData(a);void 0!==c&&(this.properties[b.name]=c)}c=this.properties["in"];if(void 0===c||null===c||c.constructor!==Number)c=0;a=this.properties.in_min;b=this.properties.out_min;var d=this.properties.out_max;this._last_v=(c-a)/(this.properties.in_max-a)*(d-b)+b;this.setOutputData(0,this._last_v);this.setOutputData(1,Math.clamp(this._last_v,b,d))};w.prototype.onDrawBackground=function(a){this.outputs[0].label=this._last_v?this._last_v.toFixed(3):"?"};w.prototype.onGetInputs=
|
||||
function(){return[["in_min","number"],["in_max","number"],["out_min","number"],["out_max","number"]]};q.registerNodeType("math/range",w);z.title="Rand";z.desc="Random number";z.prototype.onExecute=function(){if(this.inputs)for(var a=0;a<this.inputs.length;a++){var b=this.inputs[a],c=this.getInputData(a);void 0!==c&&(this.properties[b.name]=c)}a=this.properties.min;this._last_v=Math.random()*(this.properties.max-a)+a;this.setOutputData(0,this._last_v)};z.prototype.onDrawBackground=function(a){this.outputs[0].label=
|
||||
(this._last_v||0).toFixed(3)};z.prototype.onGetInputs=function(){return[["min","number"],["max","number"]]};q.registerNodeType("math/rand",z);h.title="Noise";h.desc="Random number with temporal continuity";h.data=null;h.getValue=function(a,b){if(!h.data){h.data=new Float32Array(1024);for(var c=0;c<h.data.length;++c)h.data[c]=Math.random()}a%=1024;0>a&&(a+=1024);var d=Math.floor(a);a-=d;c=h.data[d];d=h.data[1023==d?0:d+1];b&&(a=a*a*a*(a*(6*a-15)+10));return c*(1-a)+d*a};h.prototype.onExecute=function(){var a=
|
||||
this.getInputData(0)||0,b=this.properties.octaves||1,c=0,d=1;a+=this.properties.seed||0;for(var e=this.properties.speed||1,f=0,g=0;g<b&&!(c+=h.getValue(a*(1+g)*e,this.properties.smooth)*d,f+=d,d*=this.properties.persistence,.001>d);++g);a=this.properties.min;this._last_v=c/f*(this.properties.max-a)+a;this.setOutputData(0,this._last_v)};h.prototype.onDrawBackground=function(a){this.outputs[0].label=(this._last_v||0).toFixed(3)};q.registerNodeType("math/noise",h);D.title="Spikes";D.desc="spike every random time";
|
||||
D.prototype.onExecute=function(){var a=this.graph.elapsed_time;this._remaining_time-=a;this._blink_time-=a;a=0;0<this._blink_time&&(a=1/(Math.pow(this._blink_time/this.properties.duration*8-4,4)+1));0>this._remaining_time?(this._remaining_time=Math.random()*(this.properties.max_time-this.properties.min_time)+this.properties.min_time,this._blink_time=this.properties.duration,this.boxcolor="#FFF"):this.boxcolor="#000";this.setOutputData(0,a)};q.registerNodeType("math/spikes",D);C.title="Clamp";C.desc=
|
||||
"Clamp number between min and max";C.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&(a=Math.max(this.properties.min,a),a=Math.min(this.properties.max,a),this.setOutputData(0,a))};C.prototype.getCode=function(a){a="";this.isInputConnected(0)&&(a+="clamp({{0}},"+this.properties.min+","+this.properties.max+")");return a};q.registerNodeType("math/clamp",C);A.title="Lerp";A.desc="Linear Interpolation";A.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=0);var b=
|
||||
this.getInputData(1);null==b&&(b=0);var c=this.properties.f,d=this.getInputData(2);void 0!==d&&(c=d);this.setOutputData(0,a*(1-c)+b*c)};A.prototype.onGetInputs=function(){return[["f","number"]]};q.registerNodeType("math/lerp",A);E.title="Abs";E.desc="Absolute";E.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,Math.abs(a))};q.registerNodeType("math/abs",E);G.title="Floor";G.desc="Floor number to remove fractional part";G.prototype.onExecute=function(){var a=
|
||||
this.getInputData(0);null!=a&&this.setOutputData(0,Math.floor(a))};q.registerNodeType("math/floor",G);f.title="Frac";f.desc="Returns fractional part";f.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,a%1)};q.registerNodeType("math/frac",f);L.title="Smoothstep";L.desc="Smoothstep";L.prototype.onExecute=function(){var a=this.getInputData(0);if(void 0!==a){var b=this.properties.A;a=Math.clamp((a-b)/(this.properties.B-b),0,1);this.setOutputData(0,a*a*(3-2*a))}};
|
||||
q.registerNodeType("math/smoothstep",L);I.title="Scale";I.desc="v * factor";I.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,a*this.properties.factor)};q.registerNodeType("math/scale",I);B.title="Gate";B.desc="if v is true, then outputs A, otherwise B";B.prototype.onExecute=function(){var a=this.getInputData(0);this.setOutputData(0,this.getInputData(a?1:2))};q.registerNodeType("math/gate",B);K.title="Average";K.desc="Average Filter";K.prototype.onExecute=function(){var a=
|
||||
this.getInputData(0);null==a&&(a=0);var b=this._values.length;this._values[this._current%b]=a;this._current+=1;this._current>b&&(this._current=0);for(var c=a=0;c<b;++c)a+=this._values[c];this.setOutputData(0,a/b)};K.prototype.onPropertyChanged=function(a,b){1>b&&(b=1);this.properties.samples=Math.round(b);a=this._values;this._values=new Float32Array(this.properties.samples);a.length<=this._values.length?this._values.set(a):this._values.set(a.subarray(0,this._values.length))};q.registerNodeType("math/average",
|
||||
K);F.title="TendTo";F.desc="moves the output value always closer to the input";F.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=0);var b=this.properties.factor;this._value=null==this._value?a:this._value*(1-b)+a*b;this.setOutputData(0,this._value)};q.registerNodeType("math/tendTo",F);J.values="+ - * / % ^ max min".split(" ");J.title="Operation";J.desc="Easy math operators";J["@OP"]={type:"enum",title:"operation",values:J.values};J.size=[100,60];J.prototype.getTitle=function(){return"max"==
|
||||
this.properties.OP||"min"==this.properties.OP?this.properties.OP+"(A,B)":"A "+this.properties.OP+" B"};J.prototype.setValue=function(a){"string"==typeof a&&(a=parseFloat(a));this.properties.value=a};J.prototype.onPropertyChanged=function(a,b){if("OP"==a)switch(this.properties.OP){case "+":this._func=function(a,b){return a+b};break;case "-":this._func=function(a,b){return a-b};break;case "x":case "X":case "*":this._func=function(a,b){return a*b};break;case "/":this._func=function(a,b){return a/b};
|
||||
break;case "%":this._func=function(a,b){return a%b};break;case "^":this._func=function(a,b){return Math.pow(a,b)};break;case "max":this._func=function(a,b){return Math.max(a,b)};break;case "min":this._func=function(a,b){return Math.min(a,b)};break;default:console.warn("Unknown operation: "+this.properties.OP),this._func=function(a){return a}}};J.prototype.onExecute=function(){var a=this.getInputData(0),b=this.getInputData(1);null!=a?a.constructor===Number&&(this.properties.A=a):a=this.properties.A;
|
||||
null!=b?this.properties.B=b:b=this.properties.B;if(a.constructor===Number)var c=this._func(a,b);else if(a.constructor===Array){c=this._result;c.length=a.length;for(var d=0;d<a.length;++d)c[d]=this._func(a[d],b)}else for(d in c={},a)c[d]=this._func(a[d],b);this.setOutputData(0,c)};J.prototype.onDrawBackground=function(a){this.flags.collapsed||(a.font="40px Arial",a.fillStyle="#666",a.textAlign="center",a.fillText(this.properties.OP,.5*this.size[0],.5*(this.size[1]+q.NODE_TITLE_HEIGHT)),a.textAlign=
|
||||
"left")};q.registerNodeType("math/operation",J);q.registerSearchboxExtra("math/operation","MAX",{properties:{OP:"max"},title:"MAX()"});q.registerSearchboxExtra("math/operation","MIN",{properties:{OP:"min"},title:"MIN()"});H.title="Compare";H.desc="compares between two values";H.prototype.onExecute=function(){var a=this.getInputData(0),b=this.getInputData(1);void 0!==a?this.properties.A=a:a=this.properties.A;void 0!==b?this.properties.B=b:b=this.properties.B;for(var c=0,d=this.outputs.length;c<d;++c){var e=
|
||||
this.outputs[c];if(e.links&&e.links.length){switch(e.name){case "A==B":var f=a==b;break;case "A!=B":f=a!=b;break;case "A>B":f=a>b;break;case "A<B":f=a<b;break;case "A<=B":f=a<=b;break;case "A>=B":f=a>=b}this.setOutputData(c,f)}}};H.prototype.onGetOutputs=function(){return[["A==B","boolean"],["A!=B","boolean"],["A>B","boolean"],["A<B","boolean"],["A>=B","boolean"],["A<=B","boolean"]]};q.registerNodeType("math/compare",H);q.registerSearchboxExtra("math/compare","==",{outputs:[["A==B","boolean"]],title:"A==B"});
|
||||
function(){return[["in_min","number"],["in_max","number"],["out_min","number"],["out_max","number"]]};q.registerNodeType("math/range",w);A.title="Rand";A.desc="Random number";A.prototype.onExecute=function(){if(this.inputs)for(var a=0;a<this.inputs.length;a++){var b=this.inputs[a],c=this.getInputData(a);void 0!==c&&(this.properties[b.name]=c)}a=this.properties.min;this._last_v=Math.random()*(this.properties.max-a)+a;this.setOutputData(0,this._last_v)};A.prototype.onDrawBackground=function(a){this.outputs[0].label=
|
||||
(this._last_v||0).toFixed(3)};A.prototype.onGetInputs=function(){return[["min","number"],["max","number"]]};q.registerNodeType("math/rand",A);k.title="Noise";k.desc="Random number with temporal continuity";k.data=null;k.getValue=function(a,b){if(!k.data){k.data=new Float32Array(1024);for(var c=0;c<k.data.length;++c)k.data[c]=Math.random()}a%=1024;0>a&&(a+=1024);var d=Math.floor(a);a-=d;c=k.data[d];d=k.data[1023==d?0:d+1];b&&(a=a*a*a*(a*(6*a-15)+10));return c*(1-a)+d*a};k.prototype.onExecute=function(){var a=
|
||||
this.getInputData(0)||0,b=this.properties.octaves||1,c=0,d=1;a+=this.properties.seed||0;for(var e=this.properties.speed||1,f=0,g=0;g<b&&!(c+=k.getValue(a*(1+g)*e,this.properties.smooth)*d,f+=d,d*=this.properties.persistence,.001>d);++g);a=this.properties.min;this._last_v=c/f*(this.properties.max-a)+a;this.setOutputData(0,this._last_v)};k.prototype.onDrawBackground=function(a){this.outputs[0].label=(this._last_v||0).toFixed(3)};q.registerNodeType("math/noise",k);E.title="Spikes";E.desc="spike every random time";
|
||||
E.prototype.onExecute=function(){var a=this.graph.elapsed_time;this._remaining_time-=a;this._blink_time-=a;a=0;0<this._blink_time&&(a=1/(Math.pow(this._blink_time/this.properties.duration*8-4,4)+1));0>this._remaining_time?(this._remaining_time=Math.random()*(this.properties.max_time-this.properties.min_time)+this.properties.min_time,this._blink_time=this.properties.duration,this.boxcolor="#FFF"):this.boxcolor="#000";this.setOutputData(0,a)};q.registerNodeType("math/spikes",E);D.title="Clamp";D.desc=
|
||||
"Clamp number between min and max";D.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&(a=Math.max(this.properties.min,a),a=Math.min(this.properties.max,a),this.setOutputData(0,a))};D.prototype.getCode=function(a){a="";this.isInputConnected(0)&&(a+="clamp({{0}},"+this.properties.min+","+this.properties.max+")");return a};q.registerNodeType("math/clamp",D);B.title="Lerp";B.desc="Linear Interpolation";B.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=0);var b=
|
||||
this.getInputData(1);null==b&&(b=0);var c=this.properties.f,d=this.getInputData(2);void 0!==d&&(c=d);this.setOutputData(0,a*(1-c)+b*c)};B.prototype.onGetInputs=function(){return[["f","number"]]};q.registerNodeType("math/lerp",B);F.title="Abs";F.desc="Absolute";F.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,Math.abs(a))};q.registerNodeType("math/abs",F);I.title="Floor";I.desc="Floor number to remove fractional part";I.prototype.onExecute=function(){var a=
|
||||
this.getInputData(0);null!=a&&this.setOutputData(0,Math.floor(a))};q.registerNodeType("math/floor",I);f.title="Frac";f.desc="Returns fractional part";f.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,a%1)};q.registerNodeType("math/frac",f);z.title="Smoothstep";z.desc="Smoothstep";z.prototype.onExecute=function(){var a=this.getInputData(0);if(void 0!==a){var b=this.properties.A;a=Math.clamp((a-b)/(this.properties.B-b),0,1);this.setOutputData(0,a*a*(3-2*a))}};
|
||||
q.registerNodeType("math/smoothstep",z);H.title="Scale";H.desc="v * factor";H.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,a*this.properties.factor)};q.registerNodeType("math/scale",H);C.title="Gate";C.desc="if v is true, then outputs A, otherwise B";C.prototype.onExecute=function(){var a=this.getInputData(0);this.setOutputData(0,this.getInputData(a?1:2))};q.registerNodeType("math/gate",C);L.title="Average";L.desc="Average Filter";L.prototype.onExecute=function(){var a=
|
||||
this.getInputData(0);null==a&&(a=0);var b=this._values.length;this._values[this._current%b]=a;this._current+=1;this._current>b&&(this._current=0);for(var c=a=0;c<b;++c)a+=this._values[c];this.setOutputData(0,a/b)};L.prototype.onPropertyChanged=function(a,b){1>b&&(b=1);this.properties.samples=Math.round(b);a=this._values;this._values=new Float32Array(this.properties.samples);a.length<=this._values.length?this._values.set(a):this._values.set(a.subarray(0,this._values.length))};q.registerNodeType("math/average",
|
||||
L);G.title="TendTo";G.desc="moves the output value always closer to the input";G.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=0);var b=this.properties.factor;this._value=null==this._value?a:this._value*(1-b)+a*b;this.setOutputData(0,this._value)};q.registerNodeType("math/tendTo",G);K.values="+ - * / % ^ max min".split(" ");K.title="Operation";K.desc="Easy math operators";K["@OP"]={type:"enum",title:"operation",values:K.values};K.size=[100,60];K.prototype.getTitle=function(){return"max"==
|
||||
this.properties.OP||"min"==this.properties.OP?this.properties.OP+"(A,B)":"A "+this.properties.OP+" B"};K.prototype.setValue=function(a){"string"==typeof a&&(a=parseFloat(a));this.properties.value=a};K.prototype.onPropertyChanged=function(a,b){if("OP"==a)switch(this.properties.OP){case "+":this._func=function(a,b){return a+b};break;case "-":this._func=function(a,b){return a-b};break;case "x":case "X":case "*":this._func=function(a,b){return a*b};break;case "/":this._func=function(a,b){return a/b};
|
||||
break;case "%":this._func=function(a,b){return a%b};break;case "^":this._func=function(a,b){return Math.pow(a,b)};break;case "max":this._func=function(a,b){return Math.max(a,b)};break;case "min":this._func=function(a,b){return Math.min(a,b)};break;default:console.warn("Unknown operation: "+this.properties.OP),this._func=function(a){return a}}};K.prototype.onExecute=function(){var a=this.getInputData(0),b=this.getInputData(1);null!=a?a.constructor===Number&&(this.properties.A=a):a=this.properties.A;
|
||||
null!=b?this.properties.B=b:b=this.properties.B;if(a.constructor===Number)var c=this._func(a,b);else if(a.constructor===Array){c=this._result;c.length=a.length;for(var d=0;d<a.length;++d)c[d]=this._func(a[d],b)}else for(d in c={},a)c[d]=this._func(a[d],b);this.setOutputData(0,c)};K.prototype.onDrawBackground=function(a){this.flags.collapsed||(a.font="40px Arial",a.fillStyle="#666",a.textAlign="center",a.fillText(this.properties.OP,.5*this.size[0],.5*(this.size[1]+q.NODE_TITLE_HEIGHT)),a.textAlign=
|
||||
"left")};q.registerNodeType("math/operation",K);q.registerSearchboxExtra("math/operation","MAX",{properties:{OP:"max"},title:"MAX()"});q.registerSearchboxExtra("math/operation","MIN",{properties:{OP:"min"},title:"MIN()"});J.title="Compare";J.desc="compares between two values";J.prototype.onExecute=function(){var a=this.getInputData(0),b=this.getInputData(1);void 0!==a?this.properties.A=a:a=this.properties.A;void 0!==b?this.properties.B=b:b=this.properties.B;for(var c=0,d=this.outputs.length;c<d;++c){var e=
|
||||
this.outputs[c];if(e.links&&e.links.length){switch(e.name){case "A==B":var f=a==b;break;case "A!=B":f=a!=b;break;case "A>B":f=a>b;break;case "A<B":f=a<b;break;case "A<=B":f=a<=b;break;case "A>=B":f=a>=b}this.setOutputData(c,f)}}};J.prototype.onGetOutputs=function(){return[["A==B","boolean"],["A!=B","boolean"],["A>B","boolean"],["A<B","boolean"],["A>=B","boolean"],["A<=B","boolean"]]};q.registerNodeType("math/compare",J);q.registerSearchboxExtra("math/compare","==",{outputs:[["A==B","boolean"]],title:"A==B"});
|
||||
q.registerSearchboxExtra("math/compare","!=",{outputs:[["A!=B","boolean"]],title:"A!=B"});q.registerSearchboxExtra("math/compare",">",{outputs:[["A>B","boolean"]],title:"A>B"});q.registerSearchboxExtra("math/compare","<",{outputs:[["A<B","boolean"]],title:"A<B"});q.registerSearchboxExtra("math/compare",">=",{outputs:[["A>=B","boolean"]],title:"A>=B"});q.registerSearchboxExtra("math/compare","<=",{outputs:[["A<=B","boolean"]],title:"A<=B"});a.values="> < == != <= >= || &&".split(" ");a["@OP"]={type:"enum",
|
||||
title:"operation",values:a.values};a.title="Condition";a.desc="evaluates condition between A and B";a.prototype.getTitle=function(){return"A "+this.properties.OP+" B"};a.prototype.onExecute=function(){var a=this.getInputData(0);void 0===a?a=this.properties.A:this.properties.A=a;var b=this.getInputData(1);void 0===b?b=this.properties.B:this.properties.B=b;var c=!0;switch(this.properties.OP){case ">":c=a>b;break;case "<":c=a<b;break;case "==":c=a==b;break;case "!=":c=a!=b;break;case "<=":c=a<=b;break;
|
||||
case ">=":c=a>=b;break;case "||":c=a||b;break;case "&&":c=a&&b}this.setOutputData(0,c);this.setOutputData(1,!c)};q.registerNodeType("math/condition",a);b.title="Branch";b.desc="If condition is true, outputs IN in true, otherwise in false";b.prototype.onExecute=function(){var a=this.getInputData(0);this.getInputData(1)?(this.setOutputData(0,a),this.setOutputData(1,null)):(this.setOutputData(0,null),this.setOutputData(1,a))};q.registerNodeType("math/branch",b);c.title="Accumulate";c.desc="Increments a value every time";
|
||||
c.prototype.onExecute=function(){null===this.properties.value&&(this.properties.value=0);var a=this.getInputData(0);this.properties.value=null!==a?this.properties.value+a:this.properties.value+this.properties.increment;this.setOutputData(0,this.properties.value)};q.registerNodeType("math/accumulate",c);d.title="Trigonometry";d.desc="Sin Cos Tan";d.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=0);var b=this.properties.amplitude,c=this.findInputSlot("amplitude");-1!=c&&(b=this.getInputData(c));
|
||||
var d=this.properties.offset;c=this.findInputSlot("offset");-1!=c&&(d=this.getInputData(c));c=0;for(var e=this.outputs.length;c<e;++c){switch(this.outputs[c].name){case "sin":var f=Math.sin(a);break;case "cos":f=Math.cos(a);break;case "tan":f=Math.tan(a);break;case "asin":f=Math.asin(a);break;case "acos":f=Math.acos(a);break;case "atan":f=Math.atan(a)}this.setOutputData(c,b*f+d)}};d.prototype.onGetInputs=function(){return[["v","number"],["amplitude","number"],["offset","number"]]};d.prototype.onGetOutputs=
|
||||
function(){return[["sin","number"],["cos","number"],["tan","number"],["asin","number"],["acos","number"],["atan","number"]]};q.registerNodeType("math/trigonometry",d);q.registerSearchboxExtra("math/trigonometry","SIN()",{outputs:[["sin","number"]],title:"SIN()"});q.registerSearchboxExtra("math/trigonometry","COS()",{outputs:[["cos","number"]],title:"COS()"});q.registerSearchboxExtra("math/trigonometry","TAN()",{outputs:[["tan","number"]],title:"TAN()"});e.title="Formula";e.desc="Compute formula";
|
||||
e.size=[160,100];K.prototype.onPropertyChanged=function(a,b){"formula"==a&&(this.code_widget.value=b)};e.prototype.onExecute=function(){if(q.allow_scripts){var a=this.getInputData(0),b=this.getInputData(1);null!=a?this.properties.x=a:a=this.properties.x;null!=b?this.properties.y=b:b=this.properties.y;try{this._func&&this._func_code==this.properties.formula||(this._func=new Function("x","y","TIME","return "+this.properties.formula),this._func_code=this.properties.formula);var c=this._func(a,b,this.graph.globaltime);
|
||||
e.size=[160,100];L.prototype.onPropertyChanged=function(a,b){"formula"==a&&(this.code_widget.value=b)};e.prototype.onExecute=function(){if(q.allow_scripts){var a=this.getInputData(0),b=this.getInputData(1);null!=a?this.properties.x=a:a=this.properties.x;null!=b?this.properties.y=b:b=this.properties.y;try{this._func&&this._func_code==this.properties.formula||(this._func=new Function("x","y","TIME","return "+this.properties.formula),this._func_code=this.properties.formula);var c=this._func(a,b,this.graph.globaltime);
|
||||
this.boxcolor=null}catch(N){this.boxcolor="red"}this.setOutputData(0,c)}};e.prototype.getTitle=function(){return this._func_code||"Formula"};e.prototype.onDrawBackground=function(){var a=this.properties.formula;this.outputs&&this.outputs.length&&(this.outputs[0].label=a)};q.registerNodeType("math/formula",e);g.title="Vec2->XY";g.desc="vector 2 to components";g.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&(this.setOutputData(0,a[0]),this.setOutputData(1,a[1]))};q.registerNodeType("math3d/vec2-to-xy",
|
||||
g);k.title="XY->Vec2";k.desc="components to vector2";k.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=this.properties.x);var b=this.getInputData(1);null==b&&(b=this.properties.y);var c=this._data;c[0]=a;c[1]=b;this.setOutputData(0,c)};q.registerNodeType("math3d/xy-to-vec2",k);n.title="Vec3->XYZ";n.desc="vector 3 to components";n.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&(this.setOutputData(0,a[0]),this.setOutputData(1,a[1]),this.setOutputData(2,a[2]))};
|
||||
g);h.title="XY->Vec2";h.desc="components to vector2";h.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=this.properties.x);var b=this.getInputData(1);null==b&&(b=this.properties.y);var c=this._data;c[0]=a;c[1]=b;this.setOutputData(0,c)};q.registerNodeType("math3d/xy-to-vec2",h);n.title="Vec3->XYZ";n.desc="vector 3 to components";n.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&(this.setOutputData(0,a[0]),this.setOutputData(1,a[1]),this.setOutputData(2,a[2]))};
|
||||
q.registerNodeType("math3d/vec3-to-xyz",n);p.title="XYZ->Vec3";p.desc="components to vector3";p.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=this.properties.x);var b=this.getInputData(1);null==b&&(b=this.properties.y);var c=this.getInputData(2);null==c&&(c=this.properties.z);var d=this._data;d[0]=a;d[1]=b;d[2]=c;this.setOutputData(0,d)};q.registerNodeType("math3d/xyz-to-vec3",p);r.title="Vec4->XYZW";r.desc="vector 4 to components";r.prototype.onExecute=function(){var a=this.getInputData(0);
|
||||
null!=a&&(this.setOutputData(0,a[0]),this.setOutputData(1,a[1]),this.setOutputData(2,a[2]),this.setOutputData(3,a[3]))};q.registerNodeType("math3d/vec4-to-xyzw",r);u.title="XYZW->Vec4";u.desc="components to vector4";u.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=this.properties.x);var b=this.getInputData(1);null==b&&(b=this.properties.y);var c=this.getInputData(2);null==c&&(c=this.properties.z);var d=this.getInputData(3);null==d&&(d=this.properties.w);var e=this._data;e[0]=
|
||||
a;e[1]=b;e[2]=c;e[3]=d;this.setOutputData(0,e)};q.registerNodeType("math3d/xyzw-to-vec4",u)})(this);
|
||||
@@ -463,20 +464,20 @@ function(m,l){return void 0===m?l:void 0===l?m:m+l},["string","string"],"string"
|
||||
" ");if(m.constructor===Array){for(var w=[],t=0;t<m.length;++t)"string"==typeof m[t]&&(w[t]=m[t].split(l||" "));return w}return null},["string,array","string"],"array",{separator:","});x.wrapFunctionAsNode("string/toFixed",function(m){return null!=m&&m.constructor===Number?m.toFixed(this.properties.precision):m},["number"],"string",{precision:0});m.title="toTable";m.desc="Splits a string to table";m.prototype.onExecute=function(){var m=this.getInputData(0);if(m){var l=this.properties.separator||",";
|
||||
if(m!=this._str||l!=this._last_separator)this._last_separator=l,this._str=m,this._table=m.split("\n").map(function(m){return m.trim().split(l)});this.setOutputData(0,this._table);this.setOutputData(1,this._table?this._table.length:0)}};x.registerNodeType("string/toTable",m)})(this);
|
||||
(function(x){function m(){this.addInput("sel","number");this.addInput("A");this.addInput("B");this.addInput("C");this.addInput("D");this.addOutput("out");this.selected=0}function t(){this.properties={sequence:"A,B,C"};this.addInput("index","number");this.addInput("seq");this.addOutput("out");this.index=0;this.values=this.properties.sequence.split(",")}function l(){this.properties={};this.addInput("a","boolean");this.addInput("b","boolean");this.addOutput("out","boolean")}function w(){this.properties=
|
||||
{};this.addInput("a","boolean");this.addInput("b","boolean");this.addOutput("out","boolean")}function z(){this.properties={};this.addInput("in","boolean");this.addOutput("out","boolean")}function h(){this.properties={};this.addInput("a","boolean");this.addInput("b","boolean");this.addOutput("out","boolean")}function D(){this.properties={};this.addInput("onTrigger",C.ACTION);this.addInput("condition","boolean");this.addOutput("true",C.EVENT);this.addOutput("false",C.EVENT);this.mode=C.ON_TRIGGER}var C=
|
||||
x.LiteGraph;m.title="Selector";m.desc="selects an output";m.prototype.onDrawBackground=function(h){if(!this.flags.collapsed){h.fillStyle="#AFB";var l=(this.selected+1)*C.NODE_SLOT_HEIGHT+6;h.beginPath();h.moveTo(50,l);h.lineTo(50,l+C.NODE_SLOT_HEIGHT);h.lineTo(34,l+.5*C.NODE_SLOT_HEIGHT);h.fill()}};m.prototype.onExecute=function(){var h=this.getInputData(0);if(null==h||h.constructor!==Number)h=0;this.selected=h=Math.round(h)%(this.inputs.length-1);h=this.getInputData(h+1);void 0!==h&&this.setOutputData(0,
|
||||
h)};m.prototype.onGetInputs=function(){return[["E",0],["F",0],["G",0],["H",0]]};C.registerNodeType("logic/selector",m);t.title="Sequence";t.desc="select one element from a sequence from a string";t.prototype.onPropertyChanged=function(h,l){"sequence"==h&&(this.values=l.split(","))};t.prototype.onExecute=function(){var h=this.getInputData(1);h&&h!=this.current_sequence&&(this.values=h.split(","),this.current_sequence=h);h=this.getInputData(0);null==h&&(h=0);this.index=h=Math.round(h)%this.values.length;
|
||||
this.setOutputData(0,this.values[h])};C.registerNodeType("logic/sequence",t);l.title="AND";l.desc="Return true if all inputs are true";l.prototype.onExecute=function(){ret=!0;for(inX in this.inputs)if(!this.getInputData(inX)){ret=!1;break}this.setOutputData(0,ret)};l.prototype.onGetInputs=function(){return[["and","boolean"]]};C.registerNodeType("logic/AND",l);w.title="OR";w.desc="Return true if at least one input is true";w.prototype.onExecute=function(){ret=!1;for(inX in this.inputs)if(this.getInputData(inX)){ret=
|
||||
!0;break}this.setOutputData(0,ret)};w.prototype.onGetInputs=function(){return[["or","boolean"]]};C.registerNodeType("logic/OR",w);z.title="NOT";z.desc="Return the logical negation";z.prototype.onExecute=function(){var h=!this.getInputData(0);this.setOutputData(0,h)};C.registerNodeType("logic/NOT",z);h.title="bool == bool";h.desc="Compare for logical equality";h.prototype.onExecute=function(){last=null;ret=!0;for(inX in this.inputs)if(null===last)last=this.getInputData(inX);else if(last!=this.getInputData(inX)){ret=
|
||||
!1;break}this.setOutputData(0,ret)};h.prototype.onGetInputs=function(){return[["bool","boolean"]]};C.registerNodeType("logic/CompareBool",h);D.title="Branch";D.desc="Branch execution on condition";D.prototype.onExecute=function(h,l){this.getInputData(1)?this.triggerSlot(0):this.triggerSlot(1)};C.registerNodeType("logic/IF",D)})(this);
|
||||
{};this.addInput("a","boolean");this.addInput("b","boolean");this.addOutput("out","boolean")}function A(){this.properties={};this.addInput("in","boolean");this.addOutput("out","boolean")}function k(){this.properties={};this.addInput("a","boolean");this.addInput("b","boolean");this.addOutput("out","boolean")}function E(){this.properties={};this.addInput("onTrigger",D.ACTION);this.addInput("condition","boolean");this.addOutput("true",D.EVENT);this.addOutput("false",D.EVENT);this.mode=D.ON_TRIGGER}var D=
|
||||
x.LiteGraph;m.title="Selector";m.desc="selects an output";m.prototype.onDrawBackground=function(k){if(!this.flags.collapsed){k.fillStyle="#AFB";var l=(this.selected+1)*D.NODE_SLOT_HEIGHT+6;k.beginPath();k.moveTo(50,l);k.lineTo(50,l+D.NODE_SLOT_HEIGHT);k.lineTo(34,l+.5*D.NODE_SLOT_HEIGHT);k.fill()}};m.prototype.onExecute=function(){var k=this.getInputData(0);if(null==k||k.constructor!==Number)k=0;this.selected=k=Math.round(k)%(this.inputs.length-1);k=this.getInputData(k+1);void 0!==k&&this.setOutputData(0,
|
||||
k)};m.prototype.onGetInputs=function(){return[["E",0],["F",0],["G",0],["H",0]]};D.registerNodeType("logic/selector",m);t.title="Sequence";t.desc="select one element from a sequence from a string";t.prototype.onPropertyChanged=function(k,l){"sequence"==k&&(this.values=l.split(","))};t.prototype.onExecute=function(){var k=this.getInputData(1);k&&k!=this.current_sequence&&(this.values=k.split(","),this.current_sequence=k);k=this.getInputData(0);null==k&&(k=0);this.index=k=Math.round(k)%this.values.length;
|
||||
this.setOutputData(0,this.values[k])};D.registerNodeType("logic/sequence",t);l.title="AND";l.desc="Return true if all inputs are true";l.prototype.onExecute=function(){ret=!0;for(inX in this.inputs)if(!this.getInputData(inX)){ret=!1;break}this.setOutputData(0,ret)};l.prototype.onGetInputs=function(){return[["and","boolean"]]};D.registerNodeType("logic/AND",l);w.title="OR";w.desc="Return true if at least one input is true";w.prototype.onExecute=function(){ret=!1;for(inX in this.inputs)if(this.getInputData(inX)){ret=
|
||||
!0;break}this.setOutputData(0,ret)};w.prototype.onGetInputs=function(){return[["or","boolean"]]};D.registerNodeType("logic/OR",w);A.title="NOT";A.desc="Return the logical negation";A.prototype.onExecute=function(){var k=!this.getInputData(0);this.setOutputData(0,k)};D.registerNodeType("logic/NOT",A);k.title="bool == bool";k.desc="Compare for logical equality";k.prototype.onExecute=function(){last=null;ret=!0;for(inX in this.inputs)if(null===last)last=this.getInputData(inX);else if(last!=this.getInputData(inX)){ret=
|
||||
!1;break}this.setOutputData(0,ret)};k.prototype.onGetInputs=function(){return[["bool","boolean"]]};D.registerNodeType("logic/CompareBool",k);E.title="Branch";E.desc="Branch execution on condition";E.prototype.onExecute=function(k,l){this.getInputData(1)?this.triggerSlot(0):this.triggerSlot(1)};D.registerNodeType("logic/IF",E)})(this);
|
||||
(function(x){function m(){this.size=[60,20];this.addInput("send",l.ACTION);this.addOutput("received",l.EVENT);this.addInput("in",0);this.addOutput("out",0);this.properties={url:"",room:"lgraph",only_send_changes:!0};this._ws=null;this._last_sent_data=[];this._last_received_data=[]}function t(){this.room_widget=this.addWidget("text","Room","lgraph",this.setRoom.bind(this));this.addWidget("button","Reconnect",null,this.connectSocket.bind(this));this.addInput("send",l.ACTION);this.addOutput("received",
|
||||
l.EVENT);this.addInput("in",0);this.addOutput("out",0);this.properties={url:"tamats.com:55000",room:"lgraph",only_send_changes:!0};this._server=null;this.connectSocket();this._last_sent_data=[];this._last_received_data=[];"undefined"==typeof SillyClient&&console.warn("remember to add SillyClient.js to your project: https://tamats.com/projects/sillyserver/src/sillyclient.js")}var l=x.LiteGraph;m.title="WebSocket";m.desc="Send data through a websocket";m.prototype.onPropertyChanged=function(l,m){"url"==
|
||||
l&&this.connectSocket()};m.prototype.onExecute=function(){!this._ws&&this.properties.url&&this.connectSocket();if(this._ws&&this._ws.readyState==WebSocket.OPEN){for(var l=this.properties.room,m=this.properties.only_send_changes,h=1;h<this.inputs.length;++h){var t=this.getInputData(h);if(null!=t){try{var x=JSON.stringify({type:0,room:l,channel:h,data:t})}catch(A){continue}m&&this._last_sent_data[h]==x||(this._last_sent_data[h]=x,this._ws.send(x))}}for(h=1;h<this.outputs.length;++h)this.setOutputData(h,
|
||||
this._last_received_data[h]);"#AFA"==this.boxcolor&&(this.boxcolor="#6C6")}};m.prototype.connectSocket=function(){var m=this,t=this.properties.url;"ws"!=t.substr(0,2)&&(t="ws://"+t);this._ws=new WebSocket(t);this._ws.onopen=function(){console.log("ready");m.boxcolor="#6C6"};this._ws.onmessage=function(h){m.boxcolor="#AFA";h=JSON.parse(h.data);if(!h.room||h.room==m.properties.room)if(1==h.type)if(h.data.object_class&&l[h.data.object_class]){var t=null;try{t=new l[h.data.object_class](h.data),m.triggerSlot(0,
|
||||
t)}catch(C){}}else m.triggerSlot(0,h.data);else m._last_received_data[h.channel||0]=h.data};this._ws.onerror=function(h){console.log("couldnt connect to websocket");m.boxcolor="#E88"};this._ws.onclose=function(h){console.log("connection closed");m.boxcolor="#000"}};m.prototype.send=function(l){this._ws&&this._ws.readyState==WebSocket.OPEN&&this._ws.send(JSON.stringify({type:1,msg:l}))};m.prototype.onAction=function(l,m){this._ws&&this._ws.readyState==WebSocket.OPEN&&this._ws.send({type:1,room:this.properties.room,
|
||||
l&&this.connectSocket()};m.prototype.onExecute=function(){!this._ws&&this.properties.url&&this.connectSocket();if(this._ws&&this._ws.readyState==WebSocket.OPEN){for(var l=this.properties.room,m=this.properties.only_send_changes,k=1;k<this.inputs.length;++k){var t=this.getInputData(k);if(null!=t){try{var x=JSON.stringify({type:0,room:l,channel:k,data:t})}catch(B){continue}m&&this._last_sent_data[k]==x||(this._last_sent_data[k]=x,this._ws.send(x))}}for(k=1;k<this.outputs.length;++k)this.setOutputData(k,
|
||||
this._last_received_data[k]);"#AFA"==this.boxcolor&&(this.boxcolor="#6C6")}};m.prototype.connectSocket=function(){var m=this,t=this.properties.url;"ws"!=t.substr(0,2)&&(t="ws://"+t);this._ws=new WebSocket(t);this._ws.onopen=function(){console.log("ready");m.boxcolor="#6C6"};this._ws.onmessage=function(k){m.boxcolor="#AFA";k=JSON.parse(k.data);if(!k.room||k.room==m.properties.room)if(1==k.type)if(k.data.object_class&&l[k.data.object_class]){var t=null;try{t=new l[k.data.object_class](k.data),m.triggerSlot(0,
|
||||
t)}catch(D){}}else m.triggerSlot(0,k.data);else m._last_received_data[k.channel||0]=k.data};this._ws.onerror=function(k){console.log("couldnt connect to websocket");m.boxcolor="#E88"};this._ws.onclose=function(k){console.log("connection closed");m.boxcolor="#000"}};m.prototype.send=function(l){this._ws&&this._ws.readyState==WebSocket.OPEN&&this._ws.send(JSON.stringify({type:1,msg:l}))};m.prototype.onAction=function(l,m){this._ws&&this._ws.readyState==WebSocket.OPEN&&this._ws.send({type:1,room:this.properties.room,
|
||||
action:l,data:m})};m.prototype.onGetInputs=function(){return[["in",0]]};m.prototype.onGetOutputs=function(){return[["out",0]]};l.registerNodeType("network/websocket",m);t.title="SillyClient";t.desc="Connects to SillyServer to broadcast messages";t.prototype.onPropertyChanged=function(l,m){"room"==l&&(this.room_widget.value=m);this.connectSocket()};t.prototype.setRoom=function(l){this.properties.room=l;this.room_widget.value=l;this.connectSocket()};t.prototype.onDrawForeground=function(){for(var l=
|
||||
1;l<this.inputs.length;++l){var m=this.inputs[l];m.label="in_"+l}for(l=1;l<this.outputs.length;++l)m=this.outputs[l],m.label="out_"+l};t.prototype.onExecute=function(){if(this._server&&this._server.is_connected){for(var l=this.properties.only_send_changes,m=1;m<this.inputs.length;++m){var h=this.getInputData(m),t=this._last_sent_data[m];if(null!=h){if(l){var x=!0;if(h&&h.length&&t&&t.length==h.length&&h.constructor!==String)for(var A=0;A<h.length;++A){if(t[A]!=h[A]){x=!1;break}}else this._last_sent_data[m]!=
|
||||
h&&(x=!1);if(x)continue}this._server.sendMessage({type:0,channel:m,data:h});if(h.length&&h.constructor!==String)if(this._last_sent_data[m])for(this._last_sent_data[m].length=h.length,A=0;A<h.length;++A)this._last_sent_data[m][A]=h[A];else this._last_sent_data[m]=h.constructor===Array?h.concat():new h.constructor(h);else this._last_sent_data[m]=h}}for(m=1;m<this.outputs.length;++m)this.setOutputData(m,this._last_received_data[m]);"#AFA"==this.boxcolor&&(this.boxcolor="#6C6")}};t.prototype.connectSocket=
|
||||
function(){var m=this;if("undefined"==typeof SillyClient)this._error||console.error("SillyClient node cannot be used, you must include SillyServer.js"),this._error=!0;else if(this._server=new SillyClient,this._server.on_ready=function(){console.log("ready");m.boxcolor="#6C6"},this._server.on_message=function(t,h){t=null;try{t=JSON.parse(h)}catch(D){return}if(1==t.type)if(t.data.object_class&&l[t.data.object_class]){h=null;try{h=new l[t.data.object_class](t.data),m.triggerSlot(0,h)}catch(D){return}}else m.triggerSlot(0,
|
||||
t.data);else m._last_received_data[t.channel||0]=t.data;m.boxcolor="#AFA"},this._server.on_error=function(l){console.log("couldnt connect to websocket");m.boxcolor="#E88"},this._server.on_close=function(l){console.log("connection closed");m.boxcolor="#000"},this.properties.url&&this.properties.room){try{this._server.connect(this.properties.url,this.properties.room)}catch(z){console.error("SillyServer error: "+z);this._server=null;return}this._final_url=this.properties.url+"/"+this.properties.room}};
|
||||
1;l<this.inputs.length;++l){var m=this.inputs[l];m.label="in_"+l}for(l=1;l<this.outputs.length;++l)m=this.outputs[l],m.label="out_"+l};t.prototype.onExecute=function(){if(this._server&&this._server.is_connected){for(var l=this.properties.only_send_changes,m=1;m<this.inputs.length;++m){var k=this.getInputData(m),t=this._last_sent_data[m];if(null!=k){if(l){var x=!0;if(k&&k.length&&t&&t.length==k.length&&k.constructor!==String)for(var B=0;B<k.length;++B){if(t[B]!=k[B]){x=!1;break}}else this._last_sent_data[m]!=
|
||||
k&&(x=!1);if(x)continue}this._server.sendMessage({type:0,channel:m,data:k});if(k.length&&k.constructor!==String)if(this._last_sent_data[m])for(this._last_sent_data[m].length=k.length,B=0;B<k.length;++B)this._last_sent_data[m][B]=k[B];else this._last_sent_data[m]=k.constructor===Array?k.concat():new k.constructor(k);else this._last_sent_data[m]=k}}for(m=1;m<this.outputs.length;++m)this.setOutputData(m,this._last_received_data[m]);"#AFA"==this.boxcolor&&(this.boxcolor="#6C6")}};t.prototype.connectSocket=
|
||||
function(){var m=this;if("undefined"==typeof SillyClient)this._error||console.error("SillyClient node cannot be used, you must include SillyServer.js"),this._error=!0;else if(this._server=new SillyClient,this._server.on_ready=function(){console.log("ready");m.boxcolor="#6C6"},this._server.on_message=function(t,k){t=null;try{t=JSON.parse(k)}catch(E){return}if(1==t.type)if(t.data.object_class&&l[t.data.object_class]){k=null;try{k=new l[t.data.object_class](t.data),m.triggerSlot(0,k)}catch(E){return}}else m.triggerSlot(0,
|
||||
t.data);else m._last_received_data[t.channel||0]=t.data;m.boxcolor="#AFA"},this._server.on_error=function(l){console.log("couldnt connect to websocket");m.boxcolor="#E88"},this._server.on_close=function(l){console.log("connection closed");m.boxcolor="#000"},this.properties.url&&this.properties.room){try{this._server.connect(this.properties.url,this.properties.room)}catch(A){console.error("SillyServer error: "+A);this._server=null;return}this._final_url=this.properties.url+"/"+this.properties.room}};
|
||||
t.prototype.send=function(l){this._server&&this._server.is_connected&&this._server.sendMessage({type:1,data:l})};t.prototype.onAction=function(l,m){this._server&&this._server.is_connected&&this._server.sendMessage({type:1,action:l,data:m})};t.prototype.onGetInputs=function(){return[["in",0]]};t.prototype.onGetOutputs=function(){return[["out",0]]};l.registerNodeType("network/sillyclient",t)})(this);
|
||||
|
||||
@@ -9928,7 +9928,8 @@ LGraphNode.prototype.executeAction = function(action)
|
||||
case "combo":
|
||||
var old_value = w.value;
|
||||
if (event.type == LiteGraph.pointerevents_method+"move" && w.type == "number") {
|
||||
w.value += event.deltaX * 0.1 * (w.options.step || 1);
|
||||
if(event.deltaX)
|
||||
w.value += event.deltaX * 0.1 * (w.options.step || 1);
|
||||
if ( w.options.min != null && w.value < w.options.min ) {
|
||||
w.value = w.options.min;
|
||||
}
|
||||
@@ -11994,7 +11995,8 @@ LGraphNode.prototype.executeAction = function(action)
|
||||
if (root.onClose && typeof root.onClose == "function"){
|
||||
root.onClose();
|
||||
}
|
||||
root.parentNode.removeChild(root);
|
||||
if(root.parentNode)
|
||||
root.parentNode.removeChild(root);
|
||||
/* XXX CHECK THIS */
|
||||
if(this.parentNode){
|
||||
this.parentNode.removeChild(this);
|
||||
|
||||
Reference in New Issue
Block a user