diff --git a/build/litegraph.core.js b/build/litegraph.core.js index 0d9d0176a..2118409c9 100644 --- a/build/litegraph.core.js +++ b/build/litegraph.core.js @@ -58,6 +58,7 @@ CIRCLE_SHAPE: 3, CARD_SHAPE: 4, ARROW_SHAPE: 5, + GRID_SHAPE: 6, // intended for slot arrays //enums INPUT: 1, @@ -66,6 +67,8 @@ EVENT: -1, //for outputs ACTION: -1, //for inputs + NODE_MODES: ["Always", "On Event", "Never", "On Trigger"], // helper, will add "On Request" and more in the future + NODE_MODES_COLORS:["#666","#422","#333","#224","#626"], // use with node_box_coloured_by_mode ALWAYS: 0, ON_EVENT: 1, NEVER: 2, @@ -77,6 +80,7 @@ RIGHT: 4, CENTER: 5, + LINK_RENDER_MODES: ["Straight", "Linear", "Spline"], // helper STRAIGHT_LINK: 0, LINEAR_LINK: 1, SPLINE_LINK: 2, @@ -99,11 +103,44 @@ Globals: {}, //used to store vars between graphs searchbox_extras: {}, //used to add extra features to the search box - auto_sort_node_types: false, // If set to true, will automatically sort node types / categories in the context menus + auto_sort_node_types: false, // [true!] If set to true, will automatically sort node types / categories in the context menus + + node_box_coloured_when_on: false, // [true!] this make the nodes box (top left circle) coloured when triggered (execute/action), visual feedback + node_box_coloured_by_mode: false, // [true!] nodebox based on node mode, visual feedback - pointerevents_method: "pointer", // "mouse"|"pointer" use mouse for retrocompatibility issues + dialog_close_on_mouse_leave: true, // [false on mobile] better true if not touch device, TODO add an helper/listener to close if false + dialog_close_on_mouse_leave_delay: 500, + + shift_click_do_break_link_from: false, // [false!] prefer false if results too easy to break links - implement with ALT or TODO custom keys + click_do_break_link_to: false, // [false!]prefer false, way too easy to break links + + search_hide_on_mouse_leave: true, // [false on mobile] better true if not touch device, TODO add an helper/listener to close if false + search_filter_enabled: false, // [true!] enable filtering slots type in the search widget, !requires auto_load_slot_types or manual set registered_slot_[in/out]_types and slot_types_[in/out] + search_show_all_on_open: true, // [true!] opens the results list when opening the search widget + + auto_load_slot_types: false, // [if want false, use true, run, get vars values to be statically set, than disable] nodes types and nodeclass association with node types need to be calculated, if dont want this, calculate once and set registered_slot_[in/out]_types and slot_types_[in/out] + + // set these values if not using auto_load_slot_types + registered_slot_in_types: {}, // slot types for nodeclass + registered_slot_out_types: {}, // slot types for nodeclass + slot_types_in: [], // slot types IN + slot_types_out: [], // slot types OUT + slot_types_default_in: [], // specify for each IN slot type a(/many) deafult node(s), use single string, array, or object (with node, title, parameters, ..) like for search + slot_types_default_out: [], // specify for each OUT slot type a(/many) deafult node(s), use single string, array, or object (with node, title, parameters, ..) like for search + + alt_drag_do_clone_nodes: false, // [true!] very handy, ALT click to clone and drag the new node + + do_add_triggers_slots: false, // [true!] will create and connect event slots when using action/events connections, !WILL CHANGE node mode when using onTrigger (enable mode colors), onExecuted does not need this + + allow_multi_output_for_events: true, // [false!] being events, it is strongly reccomended to use them sequentually, one by one + + middle_click_slot_add_default_node: false, //[true!] allows to create and connect a ndoe clicking with the third button (wheel) + + release_link_on_empty_shows_menu: false, //[true!] dragging a link to empty space will open a menu, add from list, search or defaults + + pointerevents_method: "mouse", // "mouse"|"pointer" use mouse for retrocompatibility issues? (none found @ now) // TODO implement pointercancel, gotpointercapture, lostpointercapture, (pointerover, pointerout if necessary) - + /** * Register a node class so it can be listed when the user wants to create a new one * @method registerNodeType @@ -224,6 +261,10 @@ this.node_types_by_file_extension[ ext.toLowerCase() ] = base_class; } } + + // TODO one would want to know input and ouput :: this would allow trought registerNodeAndSlotType to get all the slots types + //console.debug("Registering "+type); + if (this.auto_load_slot_types) nodeTmp = new base_class(base_class.title || "tmpnode"); }, /** @@ -240,6 +281,50 @@ delete this.Nodes[base_class.constructor.name]; }, + /** + * Save a slot type and his node + * @method registerSlotType + * @param {String|Object} type name of the node or the node constructor itself + * @param {String} slot_type name of the slot type (variable type), eg. string, number, array, boolean, .. + */ + registerNodeAndSlotType: function(type,slot_type,out){ + out = out || false; + var base_class = type.constructor === String && this.registered_node_types[type] !== "anonymous" ? this.registered_node_types[type] : type; + + var sCN = base_class.constructor.type; + + if (typeof slot_type == "string"){ + var aTypes = slot_type.split(","); + }else if (slot_type == this.EVENT || slot_type == this.ACTION){ + var aTypes = ["_event_"]; + }else{ + var aTypes = ["*"]; + } + + for (var i = 0; i < aTypes.length; ++i) { + var sT = aTypes[i]; //.toLowerCase(); + if (sT === ""){ + sT = "*"; + } + var registerTo = out ? "registered_slot_out_types" : "registered_slot_in_types"; + if (typeof this[registerTo][sT] == "undefined") this[registerTo][sT] = {nodes: []}; + this[registerTo][sT].nodes.push(sCN); + + // check if is a new type + if (!out){ + if (!this.slot_types_in.includes(sT.toLowerCase())){ + this.slot_types_in.push(sT.toLowerCase()); + this.slot_types_in.sort(); + } + }else{ + if (!this.slot_types_out.includes(sT.toLowerCase())){ + this.slot_types_out.push(sT.toLowerCase()); + this.slot_types_out.sort(); + } + } + } + }, + /** * Create a new nodetype by passing a function, it wraps it with a proper class and generates inputs according to the parameters of the function. * Useful to wrap simple methods that do not require properties, and that only process some input to generate an output. @@ -386,6 +471,11 @@ } } + // callback + if ( node.onNodeCreated ) { + node.onNodeCreated(); + } + return node; }, @@ -523,11 +613,13 @@ * @return {Boolean} true if they can be connected */ isValidConnection: function(type_a, type_b) { + if (type_a=="" || type_a==="*") type_a = 0; + if (type_b=="" || type_b==="*") type_b = 0; if ( - !type_a || //generic output - !type_b || //generic input - type_a == type_b || //same type (is valid for triggers) - (type_a == LiteGraph.EVENT && type_b == LiteGraph.ACTION) + !type_a //generic output + || !type_b // generic input + || type_a == type_b //same type (is valid for triggers) + || (type_a == LiteGraph.EVENT && type_b == LiteGraph.ACTION) ) { return true; } @@ -548,7 +640,8 @@ var supported_types_b = type_b.split(","); for (var i = 0; i < supported_types_a.length; ++i) { for (var j = 0; j < supported_types_b.length; ++j) { - if (supported_types_a[i] == supported_types_b[j]) { + if(this.isValidConnection(supported_types_a[i],supported_types_b[j])){ + //if (supported_types_a[i] == supported_types_b[j]) { return true; } } @@ -750,6 +843,10 @@ this.catch_errors = true; + this.nodes_executing = []; + this.nodes_actioning = []; + this.nodes_executedAction = []; + //subgraph_data this.inputs = {}; this.outputs = {}; @@ -906,7 +1003,8 @@ for (var j = 0; j < limit; ++j) { var node = nodes[j]; if (node.mode == LiteGraph.ALWAYS && node.onExecute) { - node.onExecute(); //hard to send elapsed time + //wrap node.onExecute(); + node.doExecute(); } } @@ -962,6 +1060,9 @@ this.iteration += 1; this.elapsed_time = (now - this.last_update_time) * 0.001; this.last_update_time = now; + this.nodes_executing = []; + this.nodes_actioning = []; + this.nodes_executedAction = []; }; /** @@ -1375,7 +1476,7 @@ return; } //cannot be removed - this.beforeChange(); //sure? + this.beforeChange(); //sure? - almost sure is wrong //disconnect inputs if (node.inputs) { @@ -1435,7 +1536,7 @@ this.sendActionToCanvas("checkPanels"); this.setDirtyCanvas(true, true); - this.afterChange(); //sure? + this.afterChange(); //sure? - almost sure is wrong this.change(); this.updateExecutionOrder(); @@ -1530,13 +1631,19 @@ */ LGraph.prototype.getNodeOnPos = function(x, y, nodes_list, margin) { nodes_list = nodes_list || this._nodes; + var nRet = null; for (var i = nodes_list.length - 1; i >= 0; i--) { var n = nodes_list[i]; if (n.isPointInside(x, y, margin)) { - return n; + // check for lesser interest nodes (TODO check for overlapping, use the top) + /*if (typeof n == "LGraphGroup"){ + nRet = n; + }else{*/ + return n; + /*}*/ } } - return null; + return nRet; }; /** @@ -1588,7 +1695,7 @@ // ********** GLOBALS ***************** - LGraph.prototype.onAction = function(action, param) { + LGraph.prototype.onAction = function(action, param, options) { this._input_nodes = this.findNodesByClass( LiteGraph.GraphInput, this._input_nodes @@ -1598,7 +1705,8 @@ if (node.properties.name != action) { continue; } - node.onAction(action, param); + //wrap node.onAction(action, param); + node.actionDo(action, param, options); break; } }; @@ -2940,13 +3048,130 @@ return r; }; + LGraphNode.prototype.addOnTriggerInput = function(){ + var trigS = this.findInputSlot("onTrigger"); + if (trigS == -1){ //!trigS || + var input = this.addInput("onTrigger", LiteGraph.EVENT, {optional: true, nameLocked: true}); + return this.findInputSlot("onTrigger"); + } + return trigS; + } + + LGraphNode.prototype.addOnExecutedOutput = function(){ + var trigS = this.findOutputSlot("onExecuted"); + if (trigS == -1){ //!trigS || + var output = this.addOutput("onExecuted", LiteGraph.ACTION, {optional: true, nameLocked: true}); + return this.findOutputSlot("onExecuted"); + } + return trigS; + } + + LGraphNode.prototype.onAfterExecuteNode = function(param, options){ + var trigS = this.findOutputSlot("onExecuted"); + if (trigS != -1){ + + //console.debug(this.id+":"+this.order+" triggering slot onAfterExecute"); + //console.debug(param); + //console.debug(options); + this.triggerSlot(trigS, param, null, options); + + } + } + + LGraphNode.prototype.changeMode = function(modeTo){ + switch(modeTo){ + case LiteGraph.ON_EVENT: + // this.addOnExecutedOutput(); + break; + + case LiteGraph.ON_TRIGGER: + this.addOnTriggerInput(); + this.addOnExecutedOutput(); + break; + + case LiteGraph.NEVER: + break; + + case LiteGraph.ALWAYS: + break; + + case LiteGraph.ON_REQUEST: + break; + + default: + return false; + break; + } + this.mode = modeTo; + return true; + }; + + /** + * Triggers the node code execution, place a boolean/counter to mark the node as being executed + * @method execute + * @param {*} param + * @param {*} options + */ + LGraphNode.prototype.doExecute = function(param, options) { + options = options || {}; + if (this.onExecute){ + + // enable this to give the event an ID + if (!options.action_call) options.action_call = this.id+"_exec_"+Math.floor(Math.random()*9999); + + this.graph.nodes_executing[this.id] = true; //.push(this.id); + + this.onExecute(param, options); + + this.graph.nodes_executing[this.id] = false; //.pop(); + + // save execution/action ref + this.exec_version = this.graph.iteration; + if(options && options.action_call){ + this.action_call = options.action_call; // if (param) + this.graph.nodes_executedAction[this.id] = options.action_call; + } + } + this.execute_triggered = 2; // the nFrames it will be used (-- each step), means "how old" is the event + if(this.onAfterExecuteNode) this.onAfterExecuteNode(param, options); // callback + }; + + /** + * Triggers an action, wrapped by logics to control execution flow + * @method actionDo + * @param {String} action name + * @param {*} param + */ + LGraphNode.prototype.actionDo = function(action, param, options) { + options = options || {}; + if (this.onAction){ + + // enable this to give the event an ID + if (!options.action_call) options.action_call = this.id+"_"+(action?action:"action")+"_"+Math.floor(Math.random()*9999); + + this.graph.nodes_actioning[this.id] = (action?action:"actioning"); //.push(this.id); + + this.onAction(action, param, options); + + this.graph.nodes_actioning[this.id] = false; //.pop(); + + // save execution/action ref + if(options && options.action_call){ + this.action_call = options.action_call; // if (param) + this.graph.nodes_executedAction[this.id] = options.action_call; + } + } + this.action_triggered = 2; // the nFrames it will be used (-- each step), means "how old" is the event + if(this.onAfterExecuteNode) this.onAfterExecuteNode(param, options); + }; + /** * Triggers an event in this node, this will trigger any output with the same name * @method trigger * @param {String} event name ( "on_play", ... ) if action is equivalent to false then the event is send to all * @param {*} param */ - LGraphNode.prototype.trigger = function(action, param) { + LGraphNode.prototype.trigger = function(action, param, options) { if (!this.outputs || !this.outputs.length) { return; } @@ -2958,18 +3183,19 @@ var output = this.outputs[i]; if ( !output || output.type !== LiteGraph.EVENT || (action && output.name != action) ) continue; - this.triggerSlot(i, param); + this.triggerSlot(i, param, null, options); } }; /** - * Triggers an slot event in this node + * Triggers a slot event in this node: cycle output slots and launch execute/action on connected nodes * @method triggerSlot * @param {Number} slot the index of the output slot * @param {*} param * @param {Number} link_id [optional] in case you want to trigger and specific output link in a slot */ - LGraphNode.prototype.triggerSlot = function(slot, param, link_id) { + LGraphNode.prototype.triggerSlot = function(slot, param, link_id, options) { + options = options || {}; if (!this.outputs) { return; } @@ -3012,12 +3238,20 @@ if (node.mode === LiteGraph.ON_TRIGGER) { + // generate unique trigger ID if not present + if (!options.action_call) options.action_call = this.id+"_trigg_"+Math.floor(Math.random()*9999); if (node.onExecute) { - node.onExecute(param); + // -- wrapping node.onExecute(param); -- + node.doExecute(param, options); } } else if (node.onAction) { - node.onAction(target_connection.name, param); + // generate unique action ID if not present + if (!options.action_call) options.action_call = this.id+"_act_"+Math.floor(Math.random()*9999); + //pass the action name + var target_connection = node.inputs[link_info.target_slot]; + // wrap node.onAction(target_connection.name, param); + node.actionDo(target_connection.name, param, options); } } }; @@ -3126,6 +3360,9 @@ if (this.onOutputAdded) { this.onOutputAdded(o); } + + if (LiteGraph.auto_load_slot_types) LiteGraph.registerNodeAndSlotType(this,type,true); + this.setSize( this.computeSize() ); this.setDirtyCanvas(true, true); return o; @@ -3153,6 +3390,9 @@ if (this.onOutputAdded) { this.onOutputAdded(o); } + + if (LiteGraph.auto_load_slot_types) LiteGraph.registerNodeAndSlotType(this,info[1],true); + } this.setSize( this.computeSize() ); @@ -3213,7 +3453,9 @@ if (this.onInputAdded) { this.onInputAdded(o); - } + } + + LiteGraph.registerNodeAndSlotType(this,type); this.setDirtyCanvas(true, true); return o; @@ -3241,6 +3483,8 @@ if (this.onInputAdded) { this.onInputAdded(o); } + + LiteGraph.registerNodeAndSlotType(this,info[1]); } this.setSize( this.computeSize() ); @@ -3311,7 +3555,6 @@ rows = Math.max(rows, 1); var font_size = LiteGraph.NODE_TEXT_SIZE; //although it should be graphcanvas.inner_text_font size - var font_size = font_size; var title_width = compute_text_size(this.title); var input_width = 0; var output_width = 0; @@ -3612,15 +3855,16 @@ * returns the input slot with a given name (used for dynamic slots), -1 if not found * @method findInputSlot * @param {string} name the name of the slot - * @return {number} the slot (-1 if not found) + * @param {boolean} returnObj if the obj itself wanted + * @return {number_or_object} the slot (-1 if not found) */ - LGraphNode.prototype.findInputSlot = function(name) { + LGraphNode.prototype.findInputSlot = function(name, returnObj) { if (!this.inputs) { return -1; } for (var i = 0, l = this.inputs.length; i < l; ++i) { if (name == this.inputs[i].name) { - return i; + return !returnObj ? i : this.inputs[i]; } } return -1; @@ -3630,20 +3874,259 @@ * returns the output slot with a given name (used for dynamic slots), -1 if not found * @method findOutputSlot * @param {string} name the name of the slot - * @return {number} the slot (-1 if not found) + * @param {boolean} returnObj if the obj itself wanted + * @return {number_or_object} the slot (-1 if not found) */ - LGraphNode.prototype.findOutputSlot = function(name) { + LGraphNode.prototype.findOutputSlot = function(name, returnObj) { + returnObj = returnObj || false; if (!this.outputs) { return -1; } for (var i = 0, l = this.outputs.length; i < l; ++i) { if (name == this.outputs[i].name) { - return i; + return !returnObj ? i : this.outputs[i]; + } + } + return -1; + }; + + // TODO refactor: USE SINGLE findInput/findOutput functions! :: merge options + + /** + * returns the first free input slot + * @method findInputSlotFree + * @param {object} options + * @return {number_or_object} the slot (-1 if not found) + */ + LGraphNode.prototype.findInputSlotFree = function(optsIn) { + var optsIn = optsIn || {}; + var optsDef = {returnObj: false + ,typesNotAccepted: [] + }; + var opts = Object.assign(optsDef,optsIn); + if (!this.inputs) { + return -1; + } + for (var i = 0, l = this.inputs.length; i < l; ++i) { + if (this.inputs[i].link && this.inputs[i].link != null) { + continue; + } + if (opts.typesNotAccepted && opts.typesNotAccepted.includes && opts.typesNotAccepted.includes(this.inputs[i].type)){ + continue; + } + return !opts.returnObj ? i : this.inputs[i]; + } + return -1; + }; + + /** + * returns the first output slot free + * @method findOutputSlotFree + * @param {object} options + * @return {number_or_object} the slot (-1 if not found) + */ + LGraphNode.prototype.findOutputSlotFree = function(optsIn) { + var optsIn = optsIn || {}; + var optsDef = { returnObj: false + ,typesNotAccepted: [] + }; + var opts = Object.assign(optsDef,optsIn); + if (!this.outputs) { + return -1; + } + for (var i = 0, l = this.outputs.length; i < l; ++i) { + if (this.outputs[i].links && this.outputs[i].links != null) { + continue; + } + if (opts.typesNotAccepted && opts.typesNotAccepted.includes && opts.typesNotAccepted.includes(this.outputs[i].type)){ + continue; + } + return !opts.returnObj ? i : this.outputs[i]; + } + return -1; + }; + + /** + * findSlotByType for INPUTS + */ + LGraphNode.prototype.findInputSlotByType = function(type, returnObj, preferFreeSlot, doNotUseOccupied) { + return this.findSlotByType(true, type, returnObj, preferFreeSlot, doNotUseOccupied); + }; + + /** + * findSlotByType for OUTPUTS + */ + LGraphNode.prototype.findOutputSlotByType = function(type, returnObj, preferFreeSlot, doNotUseOccupied) { + return this.findSlotByType(false, type, returnObj, preferFreeSlot, doNotUseOccupied); + }; + + /** + * returns the output (or input) slot with a given type, -1 if not found + * @method findSlotByType + * @param {boolean} input uise inputs instead of outputs + * @param {string} type the type of the slot + * @param {boolean} returnObj if the obj itself wanted + * @param {boolean} preferFreeSlot if we want a free slot (if not found, will return the first of the type anyway) + * @return {number_or_object} the slot (-1 if not found) + */ + LGraphNode.prototype.findSlotByType = function(input, type, returnObj, preferFreeSlot, doNotUseOccupied) { + input = input || false; + returnObj = returnObj || false; + preferFreeSlot = preferFreeSlot || false; + doNotUseOccupied = doNotUseOccupied || false; + var aSlots = input ? this.inputs : this.outputs; + if (!aSlots) { + return -1; + } + // !! empty string type is considered 0, * !! + if (type == "" || type == "*") type = 0; + for (var i = 0, l = aSlots.length; i < l; ++i) { + var tFound = false; + var aSource = (type+"").toLowerCase().split(","); + var aDest = aSlots[i].type=="0"||aSlots[i].type=="*"?"0":aSlots[i].type; + aDest = (aDest+"").toLowerCase().split(","); + for(sI=0;sI= 0 && target_slot !== null){ + //console.debug("CONNbyTYPE type "+target_slotType+" for "+target_slot) + return this.connect(slot, target_node, target_slot); + }else{ + //console.log("type "+target_slotType+" not found or not free?") + if (opts.createEventInCase && target_slotType == LiteGraph.EVENT){ + // WILL CREATE THE onTrigger IN SLOT + //console.debug("connect WILL CREATE THE onTrigger "+target_slotType+" to "+target_node); + return this.connect(slot, target_node, -1); + } + // connect to the first general output slot if not found a specific type and + if (opts.generalTypeInCase){ + var target_slot = target_node.findInputSlotByType(0, false, true, true); + //console.debug("connect TO a general type (*, 0), if not found the specific type ",target_slotType," to ",target_node,"RES_SLOT:",target_slot); + if (target_slot >= 0){ + return this.connect(slot, target_node, target_slot); + } + } + // connect to the first free input slot if not found a specific type and this output is general + if (opts.firstFreeIfOutputGeneralInCase && (target_slotType == 0 || target_slotType == "*" || target_slotType == "")){ + var target_slot = target_node.findInputSlotFree({typesNotAccepted: [LiteGraph.EVENT] }); + //console.debug("connect TO TheFirstFREE ",target_slotType," to ",target_node,"RES_SLOT:",target_slot); + if (target_slot >= 0){ + return this.connect(slot, target_node, target_slot); + } + } + + console.debug("no way to connect type: ",target_slotType," to targetNODE ",target_node); + //TODO filter + + return null; + } + } + + /** + * connect this node input to the output of another node BY TYPE + * @method connectByType + * @param {number_or_string} slot (could be the number of the slot or the string with the name of the slot) + * @param {LGraphNode} node the target node + * @param {string} target_type the output slot type of the target node + * @return {Object} the link_info is created, otherwise null + */ + LGraphNode.prototype.connectByTypeOutput = function(slot, source_node, source_slotType, optsIn) { + var optsIn = optsIn || {}; + var optsDef = { createEventInCase: true + ,firstFreeIfInputGeneralInCase: true + ,generalTypeInCase: true + }; + var opts = Object.assign(optsDef,optsIn); + if (source_node && source_node.constructor === Number) { + source_node = this.graph.getNodeById(source_node); + } + source_slot = source_node.findOutputSlotByType(source_slotType, false, true); + if (source_slot >= 0 && source_slot !== null){ + //console.debug("CONNbyTYPE OUT! type "+source_slotType+" for "+source_slot) + return source_node.connect(source_slot, this, slot); + }else{ + + // connect to the first general output slot if not found a specific type and + if (opts.generalTypeInCase){ + var source_slot = source_node.findOutputSlotByType(0, false, true, true); + if (source_slot >= 0){ + return source_node.connect(source_slot, this, slot); + } + } + + if (opts.createEventInCase && source_slotType == LiteGraph.EVENT){ + // WILL CREATE THE onExecuted OUT SLOT + if (LiteGraph.do_add_triggers_slots){ + var source_slot = source_node.addOnExecutedOutput(); + return source_node.connect(source_slot, this, slot); + } + } + // connect to the first free output slot if not found a specific type and this input is general + if (opts.firstFreeIfInputGeneralInCase && (source_slotType == 0 || source_slotType == "*" || source_slotType == "")){ + var source_slot = source_node.findOutputSlotFree({typesNotAccepted: [LiteGraph.EVENT] }); + if (source_slot >= 0){ + return source_node.connect(source_slot, this, slot); + } + } + + console.debug("no way to connect byOUT type: ",source_slotType," to sourceNODE ",source_node); + //TODO filter + + //console.log("type OUT! "+source_slotType+" not found or not free?") + return null; + } + } + /** * connect this node output to the input of another node * @method connect @@ -3703,14 +4186,16 @@ return null; } } else if (target_slot === LiteGraph.EVENT) { - //search for first slot with event? - /* - //create input for trigger - var input = target_node.addInput("onTrigger", LiteGraph.EVENT ); - target_slot = target_node.inputs.length - 1; //last one is the one created - target_node.mode = LiteGraph.ON_TRIGGER; - */ - return null; + + if (LiteGraph.do_add_triggers_slots){ + //search for first slot with event? :: NO this is done outside + //console.log("Connect: Creating triggerEvent"); + // force mode + target_node.changeMode(LiteGraph.ON_TRIGGER); + target_slot = target_node.findInputSlot("onTrigger"); + }else{ + return null; // -- break -- + } } else if ( !target_node.inputs || target_slot >= target_node.inputs.length @@ -3723,45 +4208,69 @@ var changed = false; - //if there is something already plugged there, disconnect - if (target_node.inputs[target_slot].link != null) { - this.graph.beforeChange(); - target_node.disconnectInput(target_slot); - changed = true; - } - - //why here?? - //this.setDirtyCanvas(false,true); - //this.graph.connectionChange( this ); - - var output = this.outputs[slot]; - - //allows nodes to block connection - if (target_node.onConnectInput) { - if ( target_node.onConnectInput(target_slot, output.type, output, this, slot) === false ) { - return null; - } - } - var input = target_node.inputs[target_slot]; var link_info = null; + var output = this.outputs[slot]; + + if (!this.outputs[slot]){ + /*console.debug("Invalid slot passed: "+slot); + console.debug(this.outputs);*/ + return null; + } - //this slots cannot be connected (different types) - if (!LiteGraph.isValidConnection(output.type, input.type)) + // allow target node to change slot + if (target_node.onBeforeConnectInput) { + // This way node can choose another slot (or make a new one?) + target_slot = target_node.onBeforeConnectInput(target_slot); //callback + } + + //check target_slot and check connection types + if (target_slot===false || target_slot===null || !LiteGraph.isValidConnection(output.type, input.type)) { this.setDirtyCanvas(false, true); if(changed) this.graph.connectionChange(this, link_info); return null; + }else{ + //console.debug("valid connection",output.type, input.type); } - if(!changed) - this.graph.beforeChange(); + //allows nodes to block connection, callback + if (target_node.onConnectInput) { + if ( target_node.onConnectInput(target_slot, output.type, output, this, slot) === false ) { + return null; + } + } + if (this.onConnectOutput) { // callback + if ( this.onConnectOutput(slot, input.type, input, target_node, target_slot) === false ) { + return null; + } + } + //if there is something already plugged there, disconnect + if (target_node.inputs[target_slot] && target_node.inputs[target_slot].link != null) { + this.graph.beforeChange(); + target_node.disconnectInput(target_slot, {doProcessChange: false}); + changed = true; + } + if (output.links !== null && output.links.length){ + switch(output.type){ + case LiteGraph.EVENT: + if (!LiteGraph.allow_multi_output_for_events){ + this.graph.beforeChange(); + this.disconnectOutput(slot, false, {doProcessChange: false}); // Input(target_slot, {doProcessChange: false}); + changed = true; + } + break; + default: + break; + } + } + //create link class link_info = new LLink( ++this.graph.last_link_id, - input.type, + input.type || output.type, this.id, slot, target_node.id, @@ -4673,9 +5182,19 @@ LGraphNode.prototype.executeAction = function(action) this.default_link_color = LiteGraph.LINK_COLOR; this.default_connection_color = { input_off: "#778", - input_on: "#7F7", + input_on: "#7F7", //"#BBD" output_off: "#778", - output_on: "#7F7" + output_on: "#7F7" //"#BBD" + }; + this.default_connection_color_byType = { + /*number: "#7F7", + string: "#77F", + boolean: "#F77",*/ + } + this.default_connection_color_byTypeOff = { + /*number: "#474", + string: "#447", + boolean: "#744",*/ }; this.highquality_render = true; @@ -4692,7 +5211,7 @@ LGraphNode.prototype.executeAction = function(action) this.allow_dragnodes = true; this.allow_interaction = true; //allow to control widgets, buttons, collapse, etc this.allow_searchbox = true; - this.allow_reconnect_links = false; //allows to change a connection with having to redo it again + this.allow_reconnect_links = true; //allows to change a connection with having to redo it again this.align_to_grid = false; //snap to grid this.drag_mode = false; @@ -5034,7 +5553,7 @@ LGraphNode.prototype.executeAction = function(action) this._mousemove_callback = this.processMouseMove.bind(this); this._mouseup_callback = this.processMouseUp.bind(this); - //touch events -- THIS WAY DOES NOT WORK, finish implementing pointerevents, than clean the touchevents + //touch events -- TODO IMPLEMENT //this._touch_callback = this.touchHandler.bind(this); LiteGraph.pointerListenerAdd(canvas,"down", this._mousedown_callback, true); //down do not need to store the binded @@ -5273,8 +5792,9 @@ LGraphNode.prototype.executeAction = function(action) LiteGraph.pointerListenerAdd(ref_window.document,"up", this._mouseup_callback,true); } - if(!is_inside) + if(!is_inside){ return; + } var node = this.graph.getNodeOnPos( e.canvasX, e.canvasY, this.visible_nodes, 5 ); var skip_dragging = false; @@ -5319,6 +5839,27 @@ LGraphNode.prototype.executeAction = function(action) skip_action = true; } + // clone node ALT dragging + if (LiteGraph.alt_drag_do_clone_nodes && e.altKey && node && this.allow_interaction && !skip_action && !this.read_only) + { + if (cloned = node.clone()){ + cloned.pos[0] += 5; + cloned.pos[1] += 5; + this.graph.add(cloned,false,{doCalcSize: false}); + node = cloned; + skip_action = true; + if (!block_drag_node) { + if (this.allow_dragnodes) { + this.graph.beforeChange(); + this.node_dragged = node; + } + if (!this.selected_nodes[node.id]) { + this.processNodeSelected(node, e); + } + } + } + } + var clicking_canvas_bg = false; //when clicked on top of a node @@ -5331,11 +5872,9 @@ LGraphNode.prototype.executeAction = function(action) //not dragging mouse to connect two slots if ( !this.connecting_node && !node.flags.collapsed && !this.live_mode ) { //Search for corner for resize - if ( - !skip_action && + if ( !skip_action && node.resizable !== false && - isInsideRectangle( - e.canvasX, + isInsideRectangle( e.canvasX, e.canvasY, node.pos[0] + node.size[0] - 5, node.pos[1] + node.size[1] - 5, @@ -5343,7 +5882,7 @@ LGraphNode.prototype.executeAction = function(action) 10 ) ) { - this.graph.beforeChange(); + this.graph.beforeChange(); this.resizing_node = node; this.canvas.style.cursor = "se-resize"; skip_action = true; @@ -5365,11 +5904,14 @@ LGraphNode.prototype.executeAction = function(action) ) { this.connecting_node = node; this.connecting_output = output; + this.connecting_output.slot_index = i; this.connecting_pos = node.getConnectionPos( false, i ); this.connecting_slot = i; - if (e.shiftKey) { - node.disconnectOutput(i); + if (LiteGraph.shift_click_do_break_link_from){ + if (e.shiftKey) { + node.disconnectOutput(i); + } } if (is_double_click) { @@ -5417,12 +5959,22 @@ LGraphNode.prototype.executeAction = function(action) var link_info = this.graph.links[ input.link ]; //before disconnecting - node.disconnectInput(i); + if (LiteGraph.click_do_break_link_to){ + node.disconnectInput(i); + this.dirty_bgcanvas = true; + skip_action = true; + }else{ + // do same action as has not node ? + } if ( this.allow_reconnect_links || + //this.move_destination_link_without_shift || e.shiftKey ) { + if (!LiteGraph.click_do_break_link_to){ + node.disconnectInput(i); + } this.connecting_node = this.graph._nodes_by_id[ link_info.origin_id ]; @@ -5432,8 +5984,24 @@ LGraphNode.prototype.executeAction = function(action) this.connecting_slot ]; this.connecting_pos = this.connecting_node.getConnectionPos( false, this.connecting_slot ); + + this.dirty_bgcanvas = true; + skip_action = true; } + + }else{ + // has not node + } + + if (!skip_action){ + // connect from in to out, from to to from + this.connecting_node = node; + this.connecting_input = input; + this.connecting_input.slot_index = i; + this.connecting_pos = node.getConnectionPos( true, i ); + this.connecting_slot = i; + this.dirty_bgcanvas = true; skip_action = true; } @@ -5500,46 +6068,51 @@ LGraphNode.prototype.executeAction = function(action) } } //clicked outside of nodes else { - //search for link connector - if(!this.read_only) - for (var i = 0; i < this.visible_links.length; ++i) { - var link = this.visible_links[i]; - var center = link._pos; - if ( - !center || - e.canvasX < center[0] - 4 || - e.canvasX > center[0] + 4 || - e.canvasY < center[1] - 4 || - e.canvasY > center[1] + 4 - ) { - continue; + if (!skip_action){ + //search for link connector + if(!this.read_only) { + for (var i = 0; i < this.visible_links.length; ++i) { + var link = this.visible_links[i]; + var center = link._pos; + if ( + !center || + e.canvasX < center[0] - 4 || + e.canvasX > center[0] + 4 || + e.canvasY < center[1] - 4 || + e.canvasY > center[1] + 4 + ) { + continue; + } + //link clicked + this.showLinkMenu(link, e); + this.over_link_center = null; //clear tooltip + break; } - //link clicked - this.showLinkMenu(link, e); - this.over_link_center = null; //clear tooltip - break; } - this.selected_group = this.graph.getGroupOnPos( e.canvasX, e.canvasY ); - this.selected_group_resizing = false; - if (this.selected_group && !this.read_only ) { - if (e.ctrlKey) { - this.dragging_rectangle = null; - } + this.selected_group = this.graph.getGroupOnPos( e.canvasX, e.canvasY ); + this.selected_group_resizing = false; + if (this.selected_group && !this.read_only ) { + if (e.ctrlKey) { + this.dragging_rectangle = null; + } - var dist = distance( [e.canvasX, e.canvasY], [ this.selected_group.pos[0] + this.selected_group.size[0], this.selected_group.pos[1] + this.selected_group.size[1] ] ); - if (dist * this.ds.scale < 10) { - this.selected_group_resizing = true; - } else { - this.selected_group.recomputeInsideNodes(); - } - } + var dist = distance( [e.canvasX, e.canvasY], [ this.selected_group.pos[0] + this.selected_group.size[0], this.selected_group.pos[1] + this.selected_group.size[1] ] ); + if (dist * this.ds.scale < 10) { + this.selected_group_resizing = true; + } else { + this.selected_group.recomputeInsideNodes(); + } + } - if (is_double_click && !this.read_only && this.allow_searchbox) { - this.showSearchBox(e); - } + if (is_double_click && !this.read_only && this.allow_searchbox) { + this.showSearchBox(e); + e.preventDefault(); + e.stopPropagation(); + } - clicking_canvas_bg = true; + clicking_canvas_bg = true; + } } if (!skip_action && clicking_canvas_bg && this.allow_dragcanvas) { @@ -5549,10 +6122,91 @@ LGraphNode.prototype.executeAction = function(action) } else if (e.which == 2) { //middle button + + if (LiteGraph.middle_click_slot_add_default_node){ + if (node && this.allow_interaction && !skip_action && !this.read_only){ + //not dragging mouse to connect two slots + if ( + !this.connecting_node && + !node.flags.collapsed && + !this.live_mode + ) { + var mClikSlot = false; + var mClikSlot_index = false; + var mClikSlot_isOut = false; + //search for outputs + if (node.outputs) { + for ( var i = 0, l = node.outputs.length; i < l; ++i ) { + var output = node.outputs[i]; + var link_pos = node.getConnectionPos(false, i); + if (isInsideRectangle(e.canvasX,e.canvasY,link_pos[0] - 15,link_pos[1] - 10,30,20)) { + mClikSlot = output; + mClikSlot_index = i; + mClikSlot_isOut = true; + break; + } + } + } + + //search for inputs + if (node.inputs) { + for ( var i = 0, l = node.inputs.length; i < l; ++i ) { + var input = node.inputs[i]; + var link_pos = node.getConnectionPos(true, i); + if (isInsideRectangle(e.canvasX,e.canvasY,link_pos[0] - 15,link_pos[1] - 10,30,20)) { + mClikSlot = input; + mClikSlot_index = i; + mClikSlot_isOut = false; + break; + } + } + } + //console.log("middleClickSlots? "+mClikSlot+" & "+(mClikSlot_index!==false)); + if (mClikSlot && mClikSlot_index!==false){ + + var alphaPosY = 0.5-((mClikSlot_index+1)/((mClikSlot_isOut?node.outputs.length:node.inputs.length))); + var node_bounding = node.getBounding(); + // estimate a position: this is a bad semi-bad-working mess .. REFACTOR with a correct autoplacement that knows about the others slots and nodes + var posRef = [ (!mClikSlot_isOut?node_bounding[0]:node_bounding[0]+node_bounding[2])// + node_bounding[0]/this.canvas.width*150 + ,e.canvasY-80// + node_bounding[0]/this.canvas.width*66 // vertical "derive" + ]; + var nodeCreated = this.createDefaultNodeForSlot({ nodeFrom: !mClikSlot_isOut?null:node + ,slotFrom: !mClikSlot_isOut?null:mClikSlot_index + ,nodeTo: !mClikSlot_isOut?node:null + ,slotTo: !mClikSlot_isOut?mClikSlot_index:null + ,position: posRef //,e: e + ,nodeType: "AUTO" //nodeNewType + ,posAdd:[!mClikSlot_isOut?-30:30, -alphaPosY*130] //-alphaPosY*30] + ,posSizeFix:[!mClikSlot_isOut?-1:0, 0] //-alphaPosY*2*/ + }); + + } + } + } + } + } else if (e.which == 3 || this.pointer_is_double) { + //right button - if(!this.read_only) - this.processContextMenu(node, e); + if (this.allow_interaction && !skip_action && !this.read_only){ + + // is it hover a node ? + if (node){ + if(Object.keys(this.selected_nodes).length + && (this.selected_nodes[node.id] || e.shiftKey || e.ctrlKey || e.metaKey) + ){ + // is multiselected or using shift to include the now node + if (!this.selected_nodes[node.id]) this.selectNodes([node],true); // add this if not present + }else{ + // update selection + this.selectNodes([node]); + } + } + + // show menu on this node + this.processContextMenu(node, e); + } + } //TODO @@ -5715,23 +6369,47 @@ LGraphNode.prototype.executeAction = function(action) //if dragging a link if (this.connecting_node) { - var pos = this._highlight_input || [0, 0]; //to store the output of isOverNodeInput + + if (this.connecting_output){ + + var pos = this._highlight_input || [0, 0]; //to store the output of isOverNodeInput - //on top of input - if (this.isOverNodeBox(node, e.canvasX, e.canvasY)) { - //mouse on top of the corner box, don't know what to do - } else { - //check if I have a slot below de mouse - var slot = this.isOverNodeInput( node, e.canvasX, e.canvasY, pos ); - if (slot != -1 && node.inputs[slot]) { - var slot_type = node.inputs[slot].type; - if ( LiteGraph.isValidConnection( this.connecting_output.type, slot_type ) ) { - this._highlight_input = pos; - this._highlight_input_slot = node.inputs[slot]; - } + //on top of input + if (this.isOverNodeBox(node, e.canvasX, e.canvasY)) { + //mouse on top of the corner box, don't know what to do } else { - this._highlight_input = null; - this._highlight_input_slot = null; + //check if I have a slot below de mouse + var slot = this.isOverNodeInput( node, e.canvasX, e.canvasY, pos ); + if (slot != -1 && node.inputs[slot]) { + var slot_type = node.inputs[slot].type; + if ( LiteGraph.isValidConnection( this.connecting_output.type, slot_type ) ) { + this._highlight_input = pos; + this._highlight_input_slot = node.inputs[slot]; // XXX CHECK THIS + } + } else { + this._highlight_input = null; + this._highlight_input_slot = null; // XXX CHECK THIS + } + } + + }else if(this.connecting_input){ + + var pos = this._highlight_output || [0, 0]; //to store the output of isOverNodeOutput + + //on top of output + if (this.isOverNodeBox(node, e.canvasX, e.canvasY)) { + //mouse on top of the corner box, don't know what to do + } else { + //check if I have a slot below de mouse + var slot = this.isOverNodeOutput( node, e.canvasX, e.canvasY, pos ); + if (slot != -1 && node.outputs[slot]) { + var slot_type = node.outputs[slot].type; + if ( LiteGraph.isValidConnection( this.connecting_input.type, slot_type ) ) { + this._highlight_output = pos; + } + } else { + this._highlight_output = null; + } } } } @@ -5899,11 +6577,17 @@ LGraphNode.prototype.executeAction = function(action) } this.selected_group_resizing = false; + var node = this.graph.getNodeOnPos( + e.canvasX, + e.canvasY, + this.visible_nodes + ); + if (this.dragging_rectangle) { if (this.graph) { var nodes = this.graph._nodes; var node_bounding = new Float32Array(4); - this.deselectAllNodes(); + //compute bounding and flip if left to right var w = Math.abs(this.dragging_rectangle[2]); var h = Math.abs(this.dragging_rectangle[3]); @@ -5920,24 +6604,31 @@ LGraphNode.prototype.executeAction = function(action) this.dragging_rectangle[2] = w; this.dragging_rectangle[3] = h; - //test against all nodes (not visible because the rectangle maybe start outside - var to_select = []; - for (var i = 0; i < nodes.length; ++i) { - var node = nodes[i]; - node.getBounding(node_bounding); - if ( - !overlapBounding( - this.dragging_rectangle, - node_bounding - ) - ) { - continue; - } //out of the visible area - to_select.push(node); - } - if (to_select.length) { - this.selectNodes(to_select); - } + // test dragging rect size, if minimun simulate a click + if (!node || (w > 10 && h > 10 )){ + //test against all nodes (not visible because the rectangle maybe start outside + var to_select = []; + for (var i = 0; i < nodes.length; ++i) { + var nodeX = nodes[i]; + nodeX.getBounding(node_bounding); + if ( + !overlapBounding( + this.dragging_rectangle, + node_bounding + ) + ) { + continue; + } //out of the visible area + to_select.push(nodeX); + } + if (to_select.length) { + this.selectNodes(to_select,e.shiftKey); // add to selection with shift + } + }else{ + // will select of update selection + this.selectNodes([node],e.shiftKey||e.ctrlKey); // add to selection add to selection with ctrlKey or shiftKey + } + } this.dragging_rectangle = null; } else if (this.connecting_node) { @@ -5945,66 +6636,86 @@ LGraphNode.prototype.executeAction = function(action) this.dirty_canvas = true; this.dirty_bgcanvas = true; - var node = this.graph.getNodeOnPos( - e.canvasX, - e.canvasY, - this.visible_nodes - ); - + var connInOrOut = this.connecting_output || this.connecting_input; + var connType = connInOrOut.type; + //node below mouse if (node) { + + /* no need to condition on event type.. just another type if ( - this.connecting_output.type == LiteGraph.EVENT && + connType == LiteGraph.EVENT && this.isOverNodeBox(node, e.canvasX, e.canvasY) ) { + this.connecting_node.connect( this.connecting_slot, node, LiteGraph.EVENT ); - } else { + + } else {*/ + //slot below mouse? connect - var slot = this.isOverNodeInput( - node, - e.canvasX, - e.canvasY - ); - if (slot != -1) { - this.connecting_node.connect( - this.connecting_slot, + + if (this.connecting_output){ + + var slot = this.isOverNodeInput( node, - slot + e.canvasX, + e.canvasY ); - } else { - //not on top of an input - var input = node.getInputInfo(0); - //auto connect - if ( - this.connecting_output.type == LiteGraph.EVENT - ) { - this.connecting_node.connect( - this.connecting_slot, - node, - LiteGraph.EVENT - ); - } else if ( - input && - !input.link && - LiteGraph.isValidConnection( - input.type && this.connecting_output.type - ) - ) { - this.connecting_node.connect( - this.connecting_slot, - node, - 0 - ); + if (slot != -1) { + this.connecting_node.connect(this.connecting_slot, node, slot); + } else { + //not on top of an input + // look for a good slot + this.connecting_node.connectByType(this.connecting_slot,node,connType); } + + }else if (this.connecting_input){ + + var slot = this.isOverNodeOutput( + node, + e.canvasX, + e.canvasY + ); + + if (slot != -1) { + node.connect(slot, this.connecting_node, this.connecting_slot); // this is inverted has output-input nature like + } else { + //not on top of an input + // look for a good slot + this.connecting_node.connectByTypeOutput(this.connecting_slot,node,connType); + } + } - } + + + //} + + }else{ + + // add menu when releasing link in empty space + if (LiteGraph.release_link_on_empty_shows_menu){ + if (e.shiftKey && this.allow_searchbox){ + if(this.connecting_output){ + this.showSearchBox(e,{node_from: this.connecting_node, slot_from: this.connecting_output, type_filter_in: this.connecting_output.type}); + }else if(this.connecting_input){ + this.showSearchBox(e,{node_to: this.connecting_node, slot_from: this.connecting_input, type_filter_out: this.connecting_input.type}); + } + }else{ + if(this.connecting_output){ + this.showConnectionMenu({nodeFrom: this.connecting_node, slotFrom: this.connecting_output, e: e}); + }else if(this.connecting_input){ + this.showConnectionMenu({nodeTo: this.connecting_node, slotTo: this.connecting_input, e: e}); + } + } + } } this.connecting_output = null; + this.connecting_input = null; this.connecting_pos = null; this.connecting_node = null; this.connecting_slot = -1; @@ -6153,7 +6864,7 @@ LGraphNode.prototype.executeAction = function(action) }; /** - * returns true if a position (in graph space) is on top of a node input slot + * returns the INDEX if a position (in graph space) is on top of a node input slot * @method isOverNodeInput **/ LGraphCanvas.prototype.isOverNodeInput = function( @@ -6197,6 +6908,52 @@ LGraphNode.prototype.executeAction = function(action) } return -1; }; + + /** + * returns the INDEX if a position (in graph space) is on top of a node output slot + * @method isOverNodeOuput + **/ + LGraphCanvas.prototype.isOverNodeOutput = function( + node, + canvasx, + canvasy, + slot_pos + ) { + if (node.outputs) { + for (var i = 0, l = node.outputs.length; i < l; ++i) { + var output = node.outputs[i]; + var link_pos = node.getConnectionPos(false, i); + var is_inside = false; + if (node.horizontal) { + is_inside = isInsideRectangle( + canvasx, + canvasy, + link_pos[0] - 5, + link_pos[1] - 10, + 10, + 20 + ); + } else { + is_inside = isInsideRectangle( + canvasx, + canvasy, + link_pos[0] - 10, + link_pos[1] - 5, + 40, + 10 + ); + } + if (is_inside) { + if (slot_pos) { + slot_pos[0] = link_pos[0]; + slot_pos[1] = link_pos[1]; + } + return i; + } + } + } + return -1; + }; /** * process a key event @@ -6216,10 +6973,17 @@ LGraphNode.prototype.executeAction = function(action) if (e.type == "keydown") { if (e.keyCode == 32) { - //esc + //space this.dragging_canvas = true; block_default = true; } + + if (e.keyCode == 27) { + //esc + if(this.node_panel) this.node_panel.close(); + if(this.options_panel) this.options_panel.close(); + block_default = true; + } //select all Control A if (e.keyCode == 65 && e.ctrlKey) { @@ -6264,6 +7028,7 @@ LGraphNode.prototype.executeAction = function(action) } } else if (e.type == "keyup") { if (e.keyCode == 32) { + // space this.dragging_canvas = false; } @@ -6350,15 +7115,38 @@ LGraphNode.prototype.executeAction = function(action) //create nodes var clipboard_info = JSON.parse(data); + // calculate top-left node, could work without this processing but using diff with last node pos :: clipboard_info.nodes[clipboard_info.nodes.length-1].pos + var posMin = false; + var posMinIndexes = false; + for (var i = 0; i < clipboard_info.nodes.length; ++i) { + if (posMin){ + if(posMin[0]>clipboard_info.nodes[i].pos[0]){ + posMin[0] = clipboard_info.nodes[i].pos[0]; + posMinIndexes[0] = i; + } + if(posMin[1]>clipboard_info.nodes[i].pos[1]){ + posMin[1] = clipboard_info.nodes[i].pos[1]; + posMinIndexes[1] = i; + } + } + else{ + posMin = [clipboard_info.nodes[i].pos[0], clipboard_info.nodes[i].pos[1]]; + posMinIndexes = [i, i]; + } + } var nodes = []; for (var i = 0; i < clipboard_info.nodes.length; ++i) { var node_data = clipboard_info.nodes[i]; var node = LiteGraph.createNode(node_data.type); if (node) { node.configure(node_data); - node.pos[0] += 5; - node.pos[1] += 5; - this.graph.add(node); + + //paste in last known mouse position + node.pos[0] += this.graph_mouse[0] - posMin[0]; //+= 5; + node.pos[1] += this.graph_mouse[1] - posMin[1]; //+= 5; + + this.graph.add(node,{doProcessChange:false}); + nodes.push(node); } } @@ -6389,8 +7177,10 @@ LGraphNode.prototype.executeAction = function(action) var x = e.clientX; var y = e.clientY; var is_inside = !this.viewport || ( this.viewport && x >= this.viewport[0] && x < (this.viewport[0] + this.viewport[2]) && y >= this.viewport[1] && y < (this.viewport[1] + this.viewport[3]) ); - if(!is_inside) + if(!is_inside){ return; + // --- BREAK --- + } var pos = [e.canvasX, e.canvasY]; @@ -6493,7 +7283,7 @@ LGraphNode.prototype.executeAction = function(action) }; LGraphCanvas.prototype.processNodeSelected = function(node, e) { - this.selectNode(node, e && e.shiftKey); + this.selectNode(node, e && (e.shiftKey||e.ctrlKey)); if (this.onNodeSelected) { this.onNodeSelected(node); } @@ -6520,12 +7310,13 @@ LGraphNode.prototype.executeAction = function(action) **/ LGraphCanvas.prototype.selectNodes = function( nodes, add_to_current_selection ) { - if (!add_to_current_selection) { + if (!add_to_current_selection) { this.deselectAllNodes(); } nodes = nodes || this.graph._nodes; - for (var i = 0; i < nodes.length; ++i) { + if (typeof nodes == "string") nodes = [nodes]; + for (var i in nodes) { var node = nodes[i]; if (node.is_selected) { continue; @@ -6660,7 +7451,7 @@ LGraphNode.prototype.executeAction = function(action) this.setDirty(true); this.graph.afterChange(); }; - + /** * centers the camera on a given node * @method centerOnNode @@ -6955,8 +7746,21 @@ LGraphNode.prototype.executeAction = function(action) if (this.connecting_pos != null) { ctx.lineWidth = this.connections_width; var link_color = null; + + var connInOrOut = this.connecting_output || this.connecting_input; - switch (this.connecting_output.type) { + var connType = connInOrOut.type; + var connDir = connInOrOut.dir; + if(connDir == null) + { + if (this.connecting_output) + connDir = this.connecting_node.horizontal ? LiteGraph.DOWN : LiteGraph.RIGHT; + else + connDir = this.connecting_node.horizontal ? LiteGraph.UP : LiteGraph.LEFT; + } + var connShape = connInOrOut.shape; + + switch (connType) { case LiteGraph.EVENT: link_color = LiteGraph.EVENT_LINK_COLOR; break; @@ -6973,17 +7777,14 @@ LGraphNode.prototype.executeAction = function(action) false, null, link_color, - this.connecting_output.dir || - (this.connecting_node.horizontal - ? LiteGraph.DOWN - : LiteGraph.RIGHT), + connDir, LiteGraph.CENTER ); ctx.beginPath(); if ( - this.connecting_output.type === LiteGraph.EVENT || - this.connecting_output.shape === LiteGraph.BOX_SHAPE + connType === LiteGraph.EVENT || + connShape === LiteGraph.BOX_SHAPE ) { ctx.rect( this.connecting_pos[0] - 6 + 0.5, @@ -6999,7 +7800,7 @@ LGraphNode.prototype.executeAction = function(action) 14, 10 ); - } else if (this.connecting_output.shape === LiteGraph.ARROW_SHAPE) { + } else if (connShape === LiteGraph.ARROW_SHAPE) { ctx.moveTo(this.connecting_pos[0] + 8, this.connecting_pos[1] + 0.5); ctx.lineTo(this.connecting_pos[0] - 4, this.connecting_pos[1] + 6 + 0.5); ctx.lineTo(this.connecting_pos[0] - 4, this.connecting_pos[1] - 6 + 0.5); @@ -7045,6 +7846,24 @@ LGraphNode.prototype.executeAction = function(action) } ctx.fill(); } + if (this._highlight_output) { + ctx.beginPath(); + if (shape === LiteGraph.ARROW_SHAPE) { + ctx.moveTo(this._highlight_output[0] + 8, this._highlight_output[1] + 0.5); + ctx.lineTo(this._highlight_output[0] - 4, this._highlight_output[1] + 6 + 0.5); + ctx.lineTo(this._highlight_output[0] - 4, this._highlight_output[1] - 6 + 0.5); + ctx.closePath(); + } else { + ctx.arc( + this._highlight_output[0], + this._highlight_output[1], + 6, + 0, + Math.PI * 2 + ); + } + ctx.fill(); + } } //the selection rectangle @@ -7083,7 +7902,7 @@ LGraphNode.prototype.executeAction = function(action) this.onDrawOverlay(ctx); } - if (area) { + if (area){ ctx.restore(); } @@ -7253,11 +8072,11 @@ LGraphNode.prototype.executeAction = function(action) bgcolor = bgcolor || LiteGraph.NODE_DEFAULT_COLOR; hovercolor = hovercolor || "#555"; textcolor = textcolor || LiteGraph.NODE_TEXT_COLOR; - + var yFix = y + LiteGraph.NODE_TITLE_HEIGHT + 2; // fix the height with the title var pos = this.mouse; - var hover = LiteGraph.isInsideRectangle( pos[0], pos[1], x,y,w,h ); + var hover = LiteGraph.isInsideRectangle( pos[0], pos[1], x,yFix,w,h ); pos = this.last_click_position; - var clicked = pos && LiteGraph.isInsideRectangle( pos[0], pos[1], x,y,w,h ); + var clicked = pos && LiteGraph.isInsideRectangle( pos[0], pos[1], x,yFix,w,h ); ctx.fillStyle = hover ? hovercolor : bgcolor; if(clicked) @@ -7406,7 +8225,7 @@ LGraphNode.prototype.executeAction = function(action) } else { ctx.globalAlpha = this.editor_alpha; } - ctx.imageSmoothingEnabled = ctx.mozImageSmoothingEnabled = ctx.imageSmoothingEnabled = false; + ctx.imageSmoothingEnabled = ctx.imageSmoothingEnabled = false; // ctx.mozImageSmoothingEnabled = if ( !this._bg_img || this._bg_img.name != this.background_image @@ -7440,7 +8259,7 @@ LGraphNode.prototype.executeAction = function(action) } ctx.globalAlpha = 1.0; - ctx.imageSmoothingEnabled = ctx.mozImageSmoothingEnabled = ctx.imageSmoothingEnabled = true; + ctx.imageSmoothingEnabled = ctx.imageSmoothingEnabled = true; //= ctx.mozImageSmoothingEnabled } //groups @@ -7616,6 +8435,7 @@ LGraphNode.prototype.executeAction = function(action) var render_text = !low_quality; var out_slot = this.connecting_output; + var in_slot = this.connecting_input; ctx.lineWidth = 1; var max_y = 0; @@ -7627,18 +8447,24 @@ LGraphNode.prototype.executeAction = function(action) if (node.inputs) { for (var i = 0; i < node.inputs.length; i++) { var slot = node.inputs[i]; - + + var slot_type = slot.type; + var slot_shape = slot.shape; + ctx.globalAlpha = editor_alpha; //change opacity of incompatible slots when dragging a connection - if ( this.connecting_node && !LiteGraph.isValidConnection( slot.type , out_slot.type) ) { + if ( this.connecting_output && !LiteGraph.isValidConnection( slot.type , out_slot.type) ) { ctx.globalAlpha = 0.4 * editor_alpha; } ctx.fillStyle = slot.link != null ? slot.color_on || + this.default_connection_color_byType[slot_type] || this.default_connection_color.input_on : slot.color_off || + this.default_connection_color_byTypeOff[slot_type] || + this.default_connection_color_byType[slot_type] || this.default_connection_color.input_off; var pos = node.getConnectionPos(true, i, slot_pos); @@ -7650,6 +8476,12 @@ LGraphNode.prototype.executeAction = function(action) ctx.beginPath(); + if (slot_type == "array"){ + slot_shape = LiteGraph.GRID_SHAPE; // place in addInput? addOutput instead? + } + + var doStroke = true; + if ( slot.type === LiteGraph.EVENT || slot.shape === LiteGraph.BOX_SHAPE @@ -7669,11 +8501,22 @@ LGraphNode.prototype.executeAction = function(action) 10 ); } - } else if (slot.shape === LiteGraph.ARROW_SHAPE) { + } else if (slot_shape === LiteGraph.ARROW_SHAPE) { ctx.moveTo(pos[0] + 8, pos[1] + 0.5); ctx.lineTo(pos[0] - 4, pos[1] + 6 + 0.5); ctx.lineTo(pos[0] - 4, pos[1] - 6 + 0.5); ctx.closePath(); + } else if (slot_shape === LiteGraph.GRID_SHAPE) { + ctx.rect(pos[0] - 4, pos[1] - 4, 2, 2); + ctx.rect(pos[0] - 1, pos[1] - 4, 2, 2); + ctx.rect(pos[0] + 2, pos[1] - 4, 2, 2); + ctx.rect(pos[0] - 4, pos[1] - 1, 2, 2); + ctx.rect(pos[0] - 1, pos[1] - 1, 2, 2); + ctx.rect(pos[0] + 2, pos[1] - 1, 2, 2); + ctx.rect(pos[0] - 4, pos[1] + 2, 2, 2); + ctx.rect(pos[0] - 1, pos[1] + 2, 2, 2); + ctx.rect(pos[0] + 2, pos[1] + 2, 2, 2); + doStroke = false; } else { if(low_quality) ctx.rect(pos[0] - 4, pos[1] - 4, 8, 8 ); //faster @@ -7698,16 +8541,21 @@ LGraphNode.prototype.executeAction = function(action) } //output connection slots - if (this.connecting_node) { - ctx.globalAlpha = 0.4 * editor_alpha; - } ctx.textAlign = horizontal ? "center" : "right"; ctx.strokeStyle = "black"; if (node.outputs) { for (var i = 0; i < node.outputs.length; i++) { var slot = node.outputs[i]; - + + var slot_type = slot.type; + var slot_shape = slot.shape; + + //change opacity of incompatible slots when dragging a connection + if (this.connecting_input && !LiteGraph.isValidConnection( slot_type , in_slot.type) ) { + ctx.globalAlpha = 0.4 * editor_alpha; + } + var pos = node.getConnectionPos(false, i, slot_pos); pos[0] -= node.pos[0]; pos[1] -= node.pos[1]; @@ -7718,15 +8566,24 @@ LGraphNode.prototype.executeAction = function(action) ctx.fillStyle = slot.links && slot.links.length ? slot.color_on || + this.default_connection_color_byType[slot_type] || this.default_connection_color.output_on : slot.color_off || + this.default_connection_color_byTypeOff[slot_type] || + this.default_connection_color_byType[slot_type] || this.default_connection_color.output_off; ctx.beginPath(); //ctx.rect( node.size[0] - 14,i*14,10,10); + if (slot_type == "array"){ + slot_shape = LiteGraph.GRID_SHAPE; + } + + var doStroke = true; + if ( - slot.type === LiteGraph.EVENT || - slot.shape === LiteGraph.BOX_SHAPE + slot_type === LiteGraph.EVENT || + slot_shape === LiteGraph.BOX_SHAPE ) { if (horizontal) { ctx.rect( @@ -7743,11 +8600,22 @@ LGraphNode.prototype.executeAction = function(action) 10 ); } - } else if (slot.shape === LiteGraph.ARROW_SHAPE) { + } else if (slot_shape === LiteGraph.ARROW_SHAPE) { ctx.moveTo(pos[0] + 8, pos[1] + 0.5); ctx.lineTo(pos[0] - 4, pos[1] + 6 + 0.5); ctx.lineTo(pos[0] - 4, pos[1] - 6 + 0.5); ctx.closePath(); + } else if (slot_shape === LiteGraph.GRID_SHAPE) { + ctx.rect(pos[0] - 4, pos[1] - 4, 2, 2); + ctx.rect(pos[0] - 1, pos[1] - 4, 2, 2); + ctx.rect(pos[0] + 2, pos[1] - 4, 2, 2); + ctx.rect(pos[0] - 4, pos[1] - 1, 2, 2); + ctx.rect(pos[0] - 1, pos[1] - 1, 2, 2); + ctx.rect(pos[0] + 2, pos[1] - 1, 2, 2); + ctx.rect(pos[0] - 4, pos[1] + 2, 2, 2); + ctx.rect(pos[0] - 1, pos[1] + 2, 2, 2); + ctx.rect(pos[0] + 2, pos[1] + 2, 2, 2); + doStroke = false; } else { if(low_quality) ctx.rect(pos[0] - 4, pos[1] - 4, 8, 8 ); @@ -7761,7 +8629,7 @@ LGraphNode.prototype.executeAction = function(action) //if(slot.links != null && slot.links.length) ctx.fill(); - if(!low_quality) + if(!low_quality && doStroke) ctx.stroke(); //render output name @@ -8044,7 +8912,7 @@ LGraphNode.prototype.executeAction = function(action) var grad = LGraphCanvas.gradients[title_color]; if (!grad) { grad = LGraphCanvas.gradients[ title_color ] = ctx.createLinearGradient(0, 0, 400, 0); - grad.addColorStop(0, title_color); + grad.addColorStop(0, title_color); // TODO refactor: validate color !! prevent DOMException grad.addColorStop(1, "#000"); } ctx.fillStyle = grad; @@ -8069,6 +8937,16 @@ LGraphNode.prototype.executeAction = function(action) ctx.shadowColor = "transparent"; } + var colState = false; + if (LiteGraph.node_box_coloured_by_mode){ + if(LiteGraph.NODE_MODES_COLORS[node.mode]){ + colState = LiteGraph.NODE_MODES_COLORS[node.mode]; + } + } + if (LiteGraph.node_box_coloured_when_on){ + colState = node.action_triggered ? "#FFF" : (node.execute_triggered ? "#AAA" : colState); + } + //title box var box_size = 10; if (node.onDrawTitleBox) { @@ -8090,8 +8968,8 @@ LGraphNode.prototype.executeAction = function(action) ); ctx.fill(); } - - ctx.fillStyle = node.boxcolor || LiteGraph.NODE_DEFAULT_BOXCOLOR; + + ctx.fillStyle = node.boxcolor || colState || LiteGraph.NODE_DEFAULT_BOXCOLOR; if(low_quality) ctx.fillRect( title_height * 0.5 - box_size *0.5, title_height * -0.5 - box_size *0.5, box_size , box_size ); else @@ -8116,7 +8994,7 @@ LGraphNode.prototype.executeAction = function(action) box_size + 2 ); } - ctx.fillStyle = node.boxcolor || LiteGraph.NODE_DEFAULT_BOXCOLOR; + ctx.fillStyle = node.boxcolor || colState || LiteGraph.NODE_DEFAULT_BOXCOLOR; ctx.fillRect( (title_height - box_size) * 0.5, (title_height + box_size) * -0.5, @@ -8249,6 +9127,10 @@ LGraphNode.prototype.executeAction = function(action) ctx.strokeStyle = fgcolor; ctx.globalAlpha = 1; } + + // these counter helps in conditioning drawing based on if the node has been executed or an action occurred + if (node.execute_triggered>0) node.execute_triggered--; + if (node.action_triggered>0) node.action_triggered--; }; var margin_area = new Float32Array(4); @@ -8823,9 +9705,9 @@ LGraphNode.prototype.executeAction = function(action) ctx.fillStyle = background_color; ctx.beginPath(); if (show_text) - ctx.roundRect(margin, posY, widget_width - margin * 2, H, [H * 0.5]); + ctx.roundRect(margin, y, widget_width - margin * 2, H, [H * 0.5]); else - ctx.rect(margin, posY, widget_width - margin * 2, H ); + ctx.rect(margin, y, widget_width - margin * 2, H ); ctx.fill(); if(show_text && !w.disabled) ctx.stroke(); @@ -8880,9 +9762,9 @@ LGraphNode.prototype.executeAction = function(action) ctx.fillStyle = background_color; ctx.beginPath(); if(show_text) - ctx.roundRect(margin, posY, widget_width - margin * 2, H, [H * 0.5] ); + ctx.roundRect(margin, y, widget_width - margin * 2, H, [H * 0.5] ); else - ctx.rect(margin, posY, widget_width - margin * 2, H ); + ctx.rect(margin, y, widget_width - margin * 2, H ); ctx.fill(); if (show_text) { if(!w.disabled) @@ -8891,14 +9773,14 @@ LGraphNode.prototype.executeAction = function(action) if(!w.disabled) { ctx.beginPath(); - ctx.moveTo(margin + 16, posY + 5); - ctx.lineTo(margin + 6, posY + H * 0.5); - ctx.lineTo(margin + 16, posY + H - 5); + ctx.moveTo(margin + 16, y + 5); + ctx.lineTo(margin + 6, y + H * 0.5); + ctx.lineTo(margin + 16, y + H - 5); ctx.fill(); ctx.beginPath(); - ctx.moveTo(widget_width - margin - 16, posY + 5); - ctx.lineTo(widget_width - margin - 6, posY + H * 0.5); - ctx.lineTo(widget_width - margin - 16, posY + H - 5); + ctx.moveTo(widget_width - margin - 16, y + 5); + ctx.lineTo(widget_width - margin - 6, y + H * 0.5); + ctx.lineTo(widget_width - margin - 16, y + H - 5); ctx.fill(); } ctx.fillStyle = secondary_text_color; @@ -8940,16 +9822,16 @@ LGraphNode.prototype.executeAction = function(action) ctx.fillStyle = background_color; ctx.beginPath(); if (show_text) - ctx.roundRect(margin, posY, widget_width - margin * 2, H, [H * 0.5]); + ctx.roundRect(margin, y, widget_width - margin * 2, H, [H * 0.5]); else - ctx.rect( margin, posY, widget_width - margin * 2, H ); + ctx.rect( margin, y, widget_width - margin * 2, H ); ctx.fill(); if (show_text) { if(!w.disabled) ctx.stroke(); ctx.save(); ctx.beginPath(); - ctx.rect(margin, posY, widget_width - margin * 2, H); + ctx.rect(margin, y, widget_width - margin * 2, H); ctx.clip(); //ctx.stroke(); @@ -9292,8 +10174,6 @@ LGraphNode.prototype.executeAction = function(action) }; /* this is an implementation for touch not in production and not ready - * the idea is maybe good: simulate a similar event - * so let's try with pointerevents (working with both mouse and touch), and simulate the old mouseevents IF NECESSARY for retrocompatibility: existing old good nodes */ /*LGraphCanvas.prototype.touchHandler = function(event) { //alert("foo"); @@ -9319,7 +10199,13 @@ LGraphNode.prototype.executeAction = function(action) // screenX, screenY, clientX, clientY, ctrlKey, // altKey, shiftKey, metaKey, button, relatedTarget); - var window = this.getCanvasWindow(); + // this is eventually a Dom object, get the LGraphCanvas back + if(typeof this.getCanvasWindow == "undefined"){ + var window = this.lgraphcanvas.getCanvasWindow(); + }else{ + var window = this.getCanvasWindow(); + } + var document = window.document; var simulatedEvent = document.createEvent("MouseEvent"); @@ -9474,8 +10360,9 @@ LGraphNode.prototype.executeAction = function(action) } } - if (this.onMenuNodeInputs) { - entries = this.onMenuNodeInputs(entries); + if (node.onMenuNodeInputs) { + var retEntries = node.onMenuNodeInputs(entries); + if(retEntries) entries = retEntries; } if (!entries.length) { @@ -9506,6 +10393,10 @@ LGraphNode.prototype.executeAction = function(action) if (v.value) { node.graph.beforeChange(); node.addInput(v.value[0], v.value[1], v.value[2]); + + if (node.onNodeInputAdd) { // callback to the node when adding a slot + node.onNodeInputAdd(v.value); + } node.setDirtyCanvas(true, true); node.graph.afterChange(); } @@ -9569,6 +10460,16 @@ LGraphNode.prototype.executeAction = function(action) if (this.onMenuNodeOutputs) { entries = this.onMenuNodeOutputs(entries); } + if (LiteGraph.do_add_triggers_slots){ //canvas.allow_addOutSlot_onExecuted + if (node.findOutputSlot("onExecuted") == -1){ + entries.push({content: "On Executed", value: ["onExecuted", LiteGraph.EVENT, {nameLocked: true}], className: "event"}); //, opts: {} + } + } + // add callback for modifing the menu elements onMenuNodeOutputs + if (node.onMenuNodeOutputs) { + var retEntries = node.onMenuNodeOutputs(entries); + if(retEntries) entries = retEntries; + } if (!entries.length) { return; @@ -9619,6 +10520,10 @@ LGraphNode.prototype.executeAction = function(action) } else { node.graph.beforeChange(); node.addOutput(v.value[0], v.value[1], v.value[2]); + + if (node.onNodeOutputAdd) { // a callback to the node when adding a slot + node.onNodeOutputAdd(v.value); + } node.setDirtyCanvas(true, true); node.graph.afterChange(); } @@ -9699,20 +10604,42 @@ LGraphNode.prototype.executeAction = function(action) return e.innerHTML; }; - LGraphCanvas.onResizeNode = function(value, options, e, menu, node) { + LGraphCanvas.onMenuResizeNode = function(value, options, e, menu, node) { if (!node) { return; } - node.size = node.computeSize(); - if (node.onResize) - node.onResize(node.size); + + var fApplyMultiNode = function(node){ + node.size = node.computeSize(); + if (node.onResize) + node.onResize(node.size); + } + + var graphcanvas = LGraphCanvas.active_canvas; + if (!graphcanvas.selected_nodes || Object.keys(graphcanvas.selected_nodes).length <= 1){ + fApplyMultiNode(node); + }else{ + for (var i in graphcanvas.selected_nodes) { + fApplyMultiNode(graphcanvas.selected_nodes[i]); + } + } + node.setDirtyCanvas(true, true); }; LGraphCanvas.prototype.showLinkMenu = function(link, e) { var that = this; - console.log(link); - var options = ["Add Node",null,"Delete"]; + // console.log(link); + var node_left = that.graph.getNodeById( link.origin_id ); + var node_right = that.graph.getNodeById( link.target_id ); + var fromType = false; + if (node_left && node_left.outputs && node_left.outputs[link.origin_slot]) fromType = node_left.outputs[link.origin_slot].type; + var destType = false; + if (node_right && node_right.outputs && node_right.outputs[link.target_slot]) destType = node_right.inputs[link.target_slot].type; + + var options = ["Add Node",null,"Delete",null]; + + var menu = new LiteGraph.ContextMenu(options, { event: e, title: link.data != null ? link.data.constructor.name : null, @@ -9723,38 +10650,314 @@ LGraphNode.prototype.executeAction = function(action) switch (v) { case "Add Node": LGraphCanvas.onMenuAdd(null, null, e, menu, function(node){ - console.log("node autoconnect"); - var node_left = that.graph.getNodeById( link.origin_id ); - var node_right = that.graph.getNodeById( link.target_id ); - if(!node.inputs || !node.inputs.length || !node.outputs || !node.outputs.length) + // console.debug("node autoconnect"); + if(!node.inputs || !node.inputs.length || !node.outputs || !node.outputs.length){ return; - if( node_left.outputs[ link.origin_slot ].type == node.inputs[0].type && node.outputs[0].type == node_right.inputs[0].type ) - { - node_left.connect( link.origin_slot, node, 0 ); - node.connect( 0, node_right, link.target_slot ); - node.pos[0] -= node.size[0] * 0.5; } + // leave the connection type checking inside connectByType + if (node_left.connectByType( link.origin_slot, node, fromType )){ + node.connectByType( link.target_slot, node_right, destType ); + node.pos[0] -= node.size[0] * 0.5; + } }); break; + case "Delete": that.graph.removeLink(link.id); break; default: + /*var nodeCreated = createDefaultNodeForSlot({ nodeFrom: node_left + ,slotFrom: link.origin_slot + ,nodeTo: node + ,slotTo: link.target_slot + ,e: e + ,nodeType: "AUTO" + }); + if(nodeCreated) console.log("new node in beetween "+v+" created");*/ } } return false; }; + + LGraphCanvas.prototype.createDefaultNodeForSlot = function(optPass) { // addNodeMenu for connection + var optPass = optPass || {}; + var opts = Object.assign({ nodeFrom: null // input + ,slotFrom: null // input + ,nodeTo: null // output + ,slotTo: null // output + ,position: [] // pass the event coords + ,nodeType: null // choose a nodetype to add, AUTO to set at first good + ,posAdd:[0,0] // adjust x,y + ,posSizeFix:[0,0] // alpha, adjust the position x,y based on the new node size w,h + } + ,optPass + ); + var that = this; + + var isFrom = opts.nodeFrom && opts.slotFrom!==null; + var isTo = !isFrom && opts.nodeTo && opts.slotTo!==null; + + if (!isFrom && !isTo){ + console.warn("No data passed to createDefaultNodeForSlot "+opts.nodeFrom+" "+opts.slotFrom+" "+opts.nodeTo+" "+opts.slotTo); + return false; + } + if (!opts.nodeType){ + console.warn("No type to createDefaultNodeForSlot"); + return false; + } + + var nodeX = isFrom ? opts.nodeFrom : opts.nodeTo; + var slotX = isFrom ? opts.slotFrom : opts.slotTo; + + var iSlotConn = false; + switch (typeof slotX){ + case "string": + iSlotConn = isFrom ? nodeX.findOutputSlot(slotX,false) : nodeX.findInputSlot(slotX,false); + slotX = isFrom ? nodeX.outputs[slotX] : nodeX.inputs[slotX]; + break; + case "object": + // ok slotX + iSlotConn = isFrom ? nodeX.findOutputSlot(slotX.name) : nodeX.findInputSlot(slotX.name); + break; + case "number": + iSlotConn = slotX; + slotX = isFrom ? nodeX.outputs[slotX] : nodeX.inputs[slotX]; + break; + case "undefined": + default: + // bad ? + //iSlotConn = 0; + console.warn("Cant get slot information "+slotX); + return false; + } + + if (slotX===false || iSlotConn===false){ + console.warn("createDefaultNodeForSlot bad slotX "+slotX+" "+iSlotConn); + } + + // check for defaults nodes for this slottype + var fromSlotType = slotX.type==LiteGraph.EVENT?"_event_":slotX.type; + var slotTypesDefault = isFrom ? LiteGraph.slot_types_default_out : LiteGraph.slot_types_default_in; + if(slotTypesDefault && slotTypesDefault[fromSlotType]){ + if (slotX.link !== null) { + // is connected + }else{ + // is not not connected + } + nodeNewType = false; + if(typeof slotTypesDefault[fromSlotType] == "object" || typeof slotTypesDefault[fromSlotType] == "array"){ + for(var typeX in slotTypesDefault[fromSlotType]){ + if (opts.nodeType == slotTypesDefault[fromSlotType][typeX] || opts.nodeType == "AUTO"){ + nodeNewType = slotTypesDefault[fromSlotType][typeX]; + // console.log("opts.nodeType == slotTypesDefault[fromSlotType][typeX] :: "+opts.nodeType); + break; // -------- + } + } + }else{ + if (opts.nodeType == slotTypesDefault[fromSlotType] || opts.nodeType == "AUTO") nodeNewType = slotTypesDefault[fromSlotType]; + } + if (nodeNewType) { + var nodeNewOpts = false; + if (typeof nodeNewType == "object" && nodeNewType.node){ + nodeNewOpts = nodeNewType; + nodeNewType = nodeNewType.node; + } + + //that.graph.beforeChange(); + + var newNode = LiteGraph.createNode(nodeNewType); + if(newNode){ + // if is object pass options + if (nodeNewOpts){ + if (nodeNewOpts.properties) { + for (var i in nodeNewOpts.properties) { + newNode.addProperty( i, nodeNewOpts.properties[i] ); + } + } + if (nodeNewOpts.inputs) { + newNode.inputs = []; + for (var i in nodeNewOpts.inputs) { + newNode.addOutput( + nodeNewOpts.inputs[i][0], + nodeNewOpts.inputs[i][1] + ); + } + } + if (nodeNewOpts.outputs) { + newNode.outputs = []; + for (var i in nodeNewOpts.outputs) { + newNode.addOutput( + nodeNewOpts.outputs[i][0], + nodeNewOpts.outputs[i][1] + ); + } + } + if (nodeNewOpts.title) { + newNode.title = nodeNewOpts.title; + } + if (nodeNewOpts.json) { + newNode.configure(nodeNewOpts.json); + } + } + + // add the node + that.graph.add(newNode); + newNode.pos = [ opts.position[0]+opts.posAdd[0]+(opts.posSizeFix[0]?opts.posSizeFix[0]*newNode.size[0]:0) + ,opts.position[1]+opts.posAdd[1]+(opts.posSizeFix[1]?opts.posSizeFix[1]*newNode.size[1]:0)]; //that.last_click_position; //[e.canvasX+30, e.canvasX+5];*/ + + //that.graph.afterChange(); + + // connect the two! + if (isFrom){ + opts.nodeFrom.connectByType( iSlotConn, newNode, fromSlotType ); + }else{ + opts.nodeTo.connectByTypeOutput( iSlotConn, newNode, fromSlotType ); + } + + // if connecting in between + if (isFrom && isTo){ + // TODO + } + + return true; + + }else{ + console.log("failed creating "+nodeNewType); + } + } + } + return false; + } + + LGraphCanvas.prototype.showConnectionMenu = function(optPass) { // addNodeMenu for connection + var optPass = optPass || {}; + var opts = Object.assign({ nodeFrom: null // input + ,slotFrom: null // input + ,nodeTo: null // output + ,slotTo: null // output + ,e: null + } + ,optPass + ); + var that = this; + + var isFrom = opts.nodeFrom && opts.slotFrom; + var isTo = !isFrom && opts.nodeTo && opts.slotTo; + + if (!isFrom && !isTo){ + console.warn("No data passed to showConnectionMenu"); + return false; + } + + var nodeX = isFrom ? opts.nodeFrom : opts.nodeTo; + var slotX = isFrom ? opts.slotFrom : opts.slotTo; + + var iSlotConn = false; + switch (typeof slotX){ + case "string": + iSlotConn = isFrom ? nodeX.findOutputSlot(slotX,false) : nodeX.findInputSlot(slotX,false); + slotX = isFrom ? nodeX.outputs[slotX] : nodeX.inputs[slotX]; + break; + case "object": + // ok slotX + iSlotConn = isFrom ? nodeX.findOutputSlot(slotX.name) : nodeX.findInputSlot(slotX.name); + break; + case "number": + iSlotConn = slotX; + slotX = isFrom ? nodeX.outputs[slotX] : nodeX.inputs[slotX]; + break; + default: + // bad ? + //iSlotConn = 0; + console.warn("Cant get slot information "+slotX); + return false; + } + + var options = ["Add Node",null]; + + if (that.allow_searchbox){ + options.push("Search"); + options.push(null); + } + + // get defaults nodes for this slottype + var fromSlotType = slotX.type==LiteGraph.EVENT?"_event_":slotX.type; + var slotTypesDefault = isFrom ? LiteGraph.slot_types_default_out : LiteGraph.slot_types_default_in; + if(slotTypesDefault && slotTypesDefault[fromSlotType]){ + if(typeof slotTypesDefault[fromSlotType] == "object" || typeof slotTypesDefault[fromSlotType] == "array"){ + for(var typeX in slotTypesDefault[fromSlotType]){ + options.push(slotTypesDefault[fromSlotType][typeX]); + } + }else{ + options.push(slotTypesDefault[fromSlotType]); + } + } + + // build menu + var menu = new LiteGraph.ContextMenu(options, { + event: opts.e, + title: (slotX && slotX.name!="" ? (slotX.name + (fromSlotType?" | ":"")) : "")+(slotX && fromSlotType ? fromSlotType : ""), + callback: inner_clicked + }); + + // callback + function inner_clicked(v,options,e) { + //console.log("Process showConnectionMenu selection"); + switch (v) { + case "Add Node": + LGraphCanvas.onMenuAdd(null, null, e, menu, function(node){ + if (isFrom){ + opts.nodeFrom.connectByType( iSlotConn, node, fromSlotType ); + }else{ + opts.nodeTo.connectByTypeOutput( iSlotConn, node, fromSlotType ); + } + }); + break; + case "Search": + if(isFrom){ + that.showSearchBox(e,{node_from: opts.nodeFrom, slot_from: slotX, type_filter_in: fromSlotType}); + }else{ + that.showSearchBox(e,{node_to: opts.nodeTo, slot_from: slotX, type_filter_out: fromSlotType}); + } + break; + default: + // check for defaults nodes for this slottype + var nodeCreated = that.createDefaultNodeForSlot(Object.assign(opts,{ position: [opts.e.canvasX, opts.e.canvasY] + ,nodeType: v + })); + if (nodeCreated){ + // new node created + //console.log("node "+v+" created") + }else{ + // failed or v is not in defaults + } + break; + } + } + + return false; + }; + + // TODO refactor :: this is used fot title but not for properties! LGraphCanvas.onShowPropertyEditor = function(item, options, e, menu, node) { var input_html = ""; var property = item.property || "title"; var value = node[property]; + // TODO refactor :: use createDialog ? + var dialog = document.createElement("div"); + dialog.is_modified = false; dialog.className = "graphdialog"; - dialog.innerHTML = ""; - //dialog.innerHTML = ""; + dialog.innerHTML = + ""; + dialog.close = function() { + if (dialog.parentNode) { + dialog.parentNode.removeChild(dialog); + } + }; var title = dialog.querySelector(".name"); title.innerText = property; var input = dialog.querySelector(".value"); @@ -9764,10 +10967,15 @@ LGraphNode.prototype.executeAction = function(action) this.focus(); }); input.addEventListener("keydown", function(e) { - if (e.keyCode != 13 && e.target.localName != "textarea") { + dialog.is_modified = true; + if (e.keyCode == 27) { + //ESC + dialog.close(); + } else if (e.keyCode == 13) { + inner(); // save + } else if (e.keyCode != 13 && e.target.localName != "textarea") { return; } - inner(); e.preventDefault(); e.stopPropagation(); }); @@ -9796,8 +11004,21 @@ LGraphNode.prototype.executeAction = function(action) button.addEventListener("click", inner); canvas.parentNode.appendChild(dialog); + if(input) input.focus(); + + var dialogCloseTimer = null; + dialog.addEventListener("mouseleave", function(e) { + if(LiteGraph.dialog_close_on_mouse_leave) + if (!dialog.is_modified && LiteGraph.dialog_close_on_mouse_leave) + dialogCloseTimer = setTimeout(dialog.close, LiteGraph.dialog_close_on_mouse_leave_delay); //dialog.close(); + }); + dialog.addEventListener("mouseenter", function(e) { + if(LiteGraph.dialog_close_on_mouse_leave) + if(dialogCloseTimer) clearTimeout(dialogCloseTimer); + }); + function inner() { - setValue(input.value); + if(input) setValue(input.value); } function setValue(value) { @@ -9814,19 +11035,19 @@ LGraphNode.prototype.executeAction = function(action) } }; + // refactor: there are different dialogs, some uses createDialog some dont LGraphCanvas.prototype.prompt = function(title, value, callback, event, multiline) { var that = this; var input_html = ""; title = title || ""; - var modified = false; - var dialog = document.createElement("div"); + dialog.is_modified = false; dialog.className = "graphdialog rounded"; - if(multiline) + if(multiline) dialog.innerHTML = " "; else - dialog.innerHTML = " "; + dialog.innerHTML = " "; dialog.close = function() { that.prompt_box = null; if (dialog.parentNode) { @@ -9834,15 +11055,42 @@ LGraphNode.prototype.executeAction = function(action) } }; + var graphcanvas = LGraphCanvas.active_canvas; + var canvas = graphcanvas.canvas; + canvas.parentNode.appendChild(dialog); + if (this.ds.scale > 1) { dialog.style.transform = "scale(" + this.ds.scale + ")"; } - LiteGraph.pointerListenerAdd(dialog,"leave", function(e) { - if (!modified) { - dialog.close(); - } + var dialogCloseTimer = null; + var prevent_timeout = false; + LiteGraph.pointerListenerAdd(dialog,"leave", function(e) { + if (prevent_timeout) + return; + if(LiteGraph.dialog_close_on_mouse_leave) + if (!dialog.is_modified && LiteGraph.dialog_close_on_mouse_leave) + dialogCloseTimer = setTimeout(dialog.close, LiteGraph.dialog_close_on_mouse_leave_delay); //dialog.close(); }); + LiteGraph.pointerListenerAdd(dialog,"enter", function(e) { + if(LiteGraph.dialog_close_on_mouse_leave) + if(dialogCloseTimer) clearTimeout(dialogCloseTimer); + }); + var selInDia = dialog.querySelectorAll("select"); + if (selInDia){ + // if filtering, check focus changed to comboboxes and prevent closing + selInDia.forEach(function(selIn) { + selIn.addEventListener("click", function(e) { + prevent_timeout++; + }); + selIn.addEventListener("blur", function(e) { + prevent_timeout = 0; + }); + selIn.addEventListener("change", function(e) { + prevent_timeout = -1; + }); + }); + } if (that.prompt_box) { that.prompt_box.close(); @@ -9860,7 +11108,7 @@ LGraphNode.prototype.executeAction = function(action) var input = value_element; input.addEventListener("keydown", function(e) { - modified = true; + dialog.is_modified = true; if (e.keyCode == 27) { //ESC dialog.close(); @@ -9885,9 +11133,6 @@ LGraphNode.prototype.executeAction = function(action) dialog.close(); }); - var graphcanvas = LGraphCanvas.active_canvas; - var canvas = graphcanvas.canvas; - var rect = canvas.getBoundingClientRect(); var offsetx = -20; var offsety = -20; @@ -9904,7 +11149,6 @@ LGraphNode.prototype.executeAction = function(action) dialog.style.top = canvas.height * 0.5 + offsety + "px"; } - canvas.parentNode.appendChild(dialog); setTimeout(function() { input.focus(); }, 10); @@ -9913,7 +11157,24 @@ LGraphNode.prototype.executeAction = function(action) }; LGraphCanvas.search_limit = -1; - LGraphCanvas.prototype.showSearchBox = function(event) { + LGraphCanvas.prototype.showSearchBox = function(event, options) { + // proposed defaults + def_options = { slot_from: null + ,node_from: null + ,node_to: null + ,do_type_filter: LiteGraph.search_filter_enabled // TODO check for registered_slot_[in/out]_types not empty // this will be checked for functionality enabled : filter on slot type, in and out + ,type_filter_in: false // these are default: pass to set initially set values + ,type_filter_out: false + ,show_general_if_none_on_typefilter: true + ,show_general_after_typefiltered: true + ,hide_on_mouse_leave: LiteGraph.search_hide_on_mouse_leave + ,show_all_if_empty: true + ,show_all_on_open: LiteGraph.search_show_all_on_open + }; + options = Object.assign(def_options, options || {}); + + //console.log(options); + var that = this; var input_html = ""; var graphcanvas = LGraphCanvas.active_canvas; @@ -9922,8 +11183,27 @@ LGraphNode.prototype.executeAction = function(action) var dialog = document.createElement("div"); dialog.className = "litegraph litesearchbox graphdialog rounded"; - dialog.innerHTML = - "Search
"; + dialog.innerHTML = "Search "; + if (options.do_type_filter){ + dialog.innerHTML += ""; + dialog.innerHTML += ""; + } + dialog.innerHTML += "
"; + + if( root_document.fullscreenElement ) + root_document.fullscreenElement.appendChild(dialog); + else + { + root_document.body.appendChild(dialog); + root_document.body.style.overflow = "hidden"; + } + // dialog element has been appended + + if (options.do_type_filter){ + var selIn = dialog.querySelector(".slot_in_type_filter"); + var selOut = dialog.querySelector(".slot_out_type_filter"); + } + dialog.close = function() { that.search_box = null; root_document.body.focus(); @@ -9937,25 +11217,50 @@ LGraphNode.prototype.executeAction = function(action) } }; - var timeout_close = null; - if (this.ds.scale > 1) { dialog.style.transform = "scale(" + this.ds.scale + ")"; } - LiteGraph.pointerListenerAdd(dialog,"enter", function(e) { - if (timeout_close) { - clearTimeout(timeout_close); - timeout_close = null; + // hide on mouse leave + if(options.hide_on_mouse_leave){ + var prevent_timeout = false; + var timeout_close = null; + LiteGraph.pointerListenerAdd(dialog,"enter", function(e) { + if (timeout_close) { + clearTimeout(timeout_close); + timeout_close = null; + } + }); + LiteGraph.pointerListenerAdd(dialog,"leave", function(e) { + if (prevent_timeout){ + return; + } + timeout_close = setTimeout(function() { + dialog.close(); + }, 500); + }); + // if filtering, check focus changed to comboboxes and prevent closing + if (options.do_type_filter){ + selIn.addEventListener("click", function(e) { + prevent_timeout++; + }); + selIn.addEventListener("blur", function(e) { + prevent_timeout = 0; + }); + selIn.addEventListener("change", function(e) { + prevent_timeout = -1; + }); + selOut.addEventListener("click", function(e) { + prevent_timeout++; + }); + selOut.addEventListener("blur", function(e) { + prevent_timeout = 0; + }); + selOut.addEventListener("change", function(e) { + prevent_timeout = -1; + }); } - }); - - LiteGraph.pointerListenerAdd(dialog,"leave", function(e) { - //dialog.close(); - timeout_close = setTimeout(function() { - dialog.close(); - }, 500); - }); + } if (that.search_box) { that.search_box.close(); @@ -9995,7 +11300,7 @@ LGraphNode.prototype.executeAction = function(action) if (timeout) { clearInterval(timeout); } - timeout = setTimeout(refreshHelper, 10); + timeout = setTimeout(refreshHelper, 250); return; } e.preventDefault(); @@ -10004,15 +11309,62 @@ LGraphNode.prototype.executeAction = function(action) return true; }); } - - if( root_document.fullscreenElement ) - root_document.fullscreenElement.appendChild(dialog); - else - { - root_document.body.appendChild(dialog); - root_document.body.style.overflow = "hidden"; - } - + + // if should filter on type, load and fill selected and choose elements if passed + if (options.do_type_filter){ + if (selIn){ + var aSlots = LiteGraph.slot_types_in; + var nSlots = aSlots.length; // this for object :: Object.keys(aSlots).length; + + if (options.type_filter_in == LiteGraph.EVENT || options.type_filter_in == LiteGraph.ACTION) + options.type_filter_in = "_event_"; + /* this will filter on * .. but better do it manually in case + else if(options.type_filter_in === "" || options.type_filter_in === 0) + options.type_filter_in = "*";*/ + + for (var iK=0; iK-1){ + options.node_from.connectByType( iS, node, options.node_from.outputs[iS].type ); + } + }else{ + // console.warn("cant find slot " + options.slot_from); + } + } + if (options.node_to){ + var iS = false; + switch (typeof options.slot_from){ + case "string": + iS = options.node_to.findInputSlot(options.slot_from); + break; + case "object": + if (options.slot_from.name){ + iS = options.node_to.findInputSlot(options.slot_from.name); + }else{ + iS = -1; + } + if (iS==-1 && typeof options.slot_from.slot_index !== "undefined") iS = options.slot_from.slot_index; + break; + case "number": + iS = options.slot_from; + break; + default: + iS = 0; // try with first if no name set + } + if (typeof options.node_to.inputs[iS] !== undefined){ + if (iS!==false && iS>-1){ + // try connection + options.node_to.connectByTypeOutput(iS,node,options.node_to.inputs[iS].type); + } + }else{ + // console.warn("cant find slot_nodeTO " + options.slot_from); + } + } + + graphcanvas.graph.afterChange(); } } @@ -10132,7 +11545,7 @@ LGraphNode.prototype.executeAction = function(action) var str = input.value; first = null; helper.innerHTML = ""; - if (!str) { + if (!str && !options.show_all_if_empty) { return; } @@ -10148,15 +11561,26 @@ LGraphNode.prototype.executeAction = function(action) str = str.toLowerCase(); var filter = graphcanvas.filter || graphcanvas.graph.filter; + // filter by type preprocess + if(options.do_type_filter && that.search_box){ + var sIn = that.search_box.querySelector(".slot_in_type_filter"); + var sOut = that.search_box.querySelector(".slot_out_type_filter"); + }else{ + var sIn = false; + var sOut = false; + } + //extras for (var i in LiteGraph.searchbox_extras) { var extra = LiteGraph.searchbox_extras[i]; - if (extra.desc.toLowerCase().indexOf(str) === -1) { + if ((!options.show_all_if_empty || str) && extra.desc.toLowerCase().indexOf(str) === -1) { continue; } var ctor = LiteGraph.registered_node_types[ extra.type ]; if( ctor && ctor.filter != filter ) continue; + if( ! inner_test_filter(extra.type) ) + continue; addResult( extra.desc, "searchbox_extra" ); if ( LGraphCanvas.search_limit !== -1 && c++ > LGraphCanvas.search_limit ) { break; @@ -10181,13 +11605,98 @@ LGraphNode.prototype.executeAction = function(action) break; } } - - function inner_test_filter( type ) + + // add general type if filtering + if (options.show_general_after_typefiltered + && (sIn.value || sOut.value) + ){ + filtered_extra = []; + for (var i in LiteGraph.registered_node_types) { + if( inner_test_filter(i, {inTypeOverride: sIn&&sIn.value?"*":false, outTypeOverride: sOut&&sOut.value?"*":false}) ) + filtered_extra.push(i); + } + for (var i = 0; i < filtered_extra.length; i++) { + addResult(filtered_extra[i], "generic_type"); + if ( LGraphCanvas.search_limit !== -1 && c++ > LGraphCanvas.search_limit ) { + break; + } + } + } + + // check il filtering gave no results + if ((sIn.value || sOut.value) && + ( (helper.childNodes.length == 0 && options.show_general_if_none_on_typefilter) ) + ){ + filtered_extra = []; + for (var i in LiteGraph.registered_node_types) { + if( inner_test_filter(i, {skipFilter: true}) ) + filtered_extra.push(i); + } + for (var i = 0; i < filtered_extra.length; i++) { + addResult(filtered_extra[i], "not_in_filter"); + if ( LGraphCanvas.search_limit !== -1 && c++ > LGraphCanvas.search_limit ) { + break; + } + } + } + + function inner_test_filter( type, optsIn ) { + var optsIn = optsIn || {}; + var optsDef = { skipFilter: false + ,inTypeOverride: false + ,outTypeOverride: false + }; + var opts = Object.assign(optsDef,optsIn); var ctor = LiteGraph.registered_node_types[ type ]; if(filter && ctor.filter != filter ) return false; - return type.toLowerCase().indexOf(str) !== -1; + if ((!options.show_all_if_empty || str) && type.toLowerCase().indexOf(str) === -1) + return false; + + // filter by slot IN, OUT types + if(options.do_type_filter && !opts.skipFilter){ + var sType = type; + + var sV = sIn.value; + if (opts.inTypeOverride!==false) sV = opts.inTypeOverride; + //if (sV.toLowerCase() == "_event_") sV = LiteGraph.EVENT; // -1 + + if(sIn && sV){ + //console.log("will check filter against "+sV); + if (LiteGraph.registered_slot_in_types[sV] && LiteGraph.registered_slot_in_types[sV].nodes){ // type is stored + //console.debug("check "+sType+" in "+LiteGraph.registered_slot_in_types[sV].nodes); + var doesInc = LiteGraph.registered_slot_in_types[sV].nodes.includes(sType); + if (doesInc!==false){ + //console.log(sType+" HAS "+sV); + }else{ + /*console.debug(LiteGraph.registered_slot_in_types[sV]); + console.log(+" DONT includes "+type);*/ + return false; + } + } + } + + var sV = sOut.value; + if (opts.outTypeOverride!==false) sV = opts.outTypeOverride; + //if (sV.toLowerCase() == "_event_") sV = LiteGraph.EVENT; // -1 + + if(sOut && sV){ + //console.log("search will check filter against "+sV); + if (LiteGraph.registered_slot_out_types[sV] && LiteGraph.registered_slot_out_types[sV].nodes){ // type is stored + //console.debug("check "+sType+" in "+LiteGraph.registered_slot_out_types[sV].nodes); + var doesInc = LiteGraph.registered_slot_out_types[sV].nodes.includes(sType); + if (doesInc!==false){ + //console.log(sType+" HAS "+sV); + }else{ + /*console.debug(LiteGraph.registered_slot_out_types[sV]); + console.log(+" DONT includes "+type);*/ + return false; + } + } + } + } + return true; } } @@ -10244,7 +11753,7 @@ LGraphNode.prototype.executeAction = function(action) ""; } input_html += ""; - } else if (type == "boolean") { + } else if (type == "boolean" || type == "toggle") { input_html = "=0 && options.values[kV]){ + console.debug("update graph options: "+options.key+": "+kV); + graphcanvas[options.key] = kV; + //console.debug(graphcanvas); + break; + } + } + console.warn("unexpected options"); + console.debug(options); + break;*/ + default: + //console.debug("want to update graph options: "+name+": "+value); + if (options && options.key){ + name = options.key; + } + if (options.values){ + value = Object.values(options.values).indexOf(value); + } + //console.debug("update graph option: "+name+": "+value); + graphcanvas[name] = value; + break; + } + }; + + // panel.addWidget( "string", "Graph name", "", {}, fUpdate); // implement + + var aProps = LiteGraph.availableCanvasOptions; + aProps.sort(); + for(pI in aProps){ + var pX = aProps[pI]; + panel.addWidget( "boolean", pX, graphcanvas[pX], {key: pX, on: "True", off: "False"}, fUpdate); + } + + var aLinks = [ graphcanvas.links_render_mode ]; + panel.addWidget( "combo", "Render mode", LiteGraph.LINK_RENDER_MODES[graphcanvas.links_render_mode], {key: "links_render_mode", values: LiteGraph.LINK_RENDER_MODES}, fUpdate); + + panel.addSeparator(); + + panel.footer.innerHTML = ""; // clear + + } + inner_refresh(); + + graphcanvas.canvas.parentNode.appendChild( panel ); + } + + LGraphCanvas.prototype.showShowNodePanel = function( node ) + { + this.SELECTED_NODE = node; + this.closePanels(); var ref_window = this.getCanvasWindow(); - panel = this.createPanel(node.title || "",{closable: true, window: ref_window }); + var that = this; + var graphcanvas = this; + panel = this.createPanel(node.title || "",{ + closable: true + ,window: ref_window + ,onOpen: function(){ + graphcanvas.NODEPANEL_IS_OPEN = true; + } + ,onClose: function(){ + graphcanvas.NODEPANEL_IS_OPEN = false; + graphcanvas.node_panel = null; + } + }); + graphcanvas.node_panel = panel; panel.id = "node-panel"; panel.node = node; panel.classList.add("settings"); - var that = this; - var graphcanvas = this; function inner_refresh() { @@ -10588,22 +12301,58 @@ LGraphNode.prototype.executeAction = function(action) panel.addHTML("

Properties

"); - for(var i in node.properties) + var fUpdate = function(name,value){ + graphcanvas.graph.beforeChange(node); + switch(name){ + case "Title": + node.title = value; + break; + case "Mode": + var kV = Object.values(LiteGraph.NODE_MODES).indexOf(value); + if (kV>=0 && LiteGraph.NODE_MODES[kV]){ + node.changeMode(kV); + }else{ + console.warn("unexpected mode: "+value); + } + break; + case "Color": + if (LGraphCanvas.node_colors[value]){ + node.color = LGraphCanvas.node_colors[value].color; + node.bgcolor = LGraphCanvas.node_colors[value].bgcolor; + }else{ + console.warn("unexpected color: "+value); + } + break; + default: + node.setProperty(name,value); + break; + } + graphcanvas.graph.afterChange(); + graphcanvas.dirty_canvas = true; + }; + + panel.addWidget( "string", "Title", node.title, {}, fUpdate); + + panel.addWidget( "combo", "Mode", LiteGraph.NODE_MODES[node.mode], {values: LiteGraph.NODE_MODES}, fUpdate); + + var nodeCol = ""; + if (node.color !== undefined){ + nodeCol = Object.keys(LGraphCanvas.node_colors).filter(function(nK){ return LGraphCanvas.node_colors[nK].color == node.color; }); + } + + panel.addWidget( "combo", "Color", nodeCol, {values: Object.keys(LGraphCanvas.node_colors)}, fUpdate); + + for(var pName in node.properties) { - var value = node.properties[i]; - var info = node.getPropertyInfo(i); + var value = node.properties[pName]; + var info = node.getPropertyInfo(pName); var type = info.type || "string"; //in case the user wants control over the side panel widget - if( node.onAddPropertyToPanel && node.onAddPropertyToPanel(i,panel) ) + if( node.onAddPropertyToPanel && node.onAddPropertyToPanel(pName,panel) ) continue; - panel.addWidget( info.widget || info.type, i, value, info, function(name,value){ - graphcanvas.graph.beforeChange(node); - node.setProperty(name,value); - graphcanvas.graph.afterChange(); - graphcanvas.dirty_canvas = true; - }); + panel.addWidget( info.widget || info.type, pName, value, info, fUpdate); } panel.addSeparator(); @@ -10611,13 +12360,7 @@ LGraphNode.prototype.executeAction = function(action) if(node.onShowCustomPanelInfo) node.onShowCustomPanelInfo(panel); - /* - panel.addHTML("

Connections

"); - var connection_containers = panel.addHTML("
","connections"); - var inputs = connection_containers.querySelector(".inputs"); - var outputs = connection_containers.querySelector(".outputs"); - */ - + panel.footer.innerHTML = ""; // clear panel.addButton("Delete",function(){ if(node.block_delete) return; @@ -10626,14 +12369,13 @@ LGraphNode.prototype.executeAction = function(action) }).classList.add("delete"); } - function inner_showCodePad( node, propname ) + panel.inner_showCodePad = function( propname ) { - panel.style.top = "calc( 50% - 250px)"; - panel.style.left = "calc( 50% - 400px)"; - panel.style.width = "800px"; - panel.style.height = "500px"; + panel.classList.remove("settings"); + panel.classList.add("centered"); - if(window.CodeFlask) //disabled for now + + /*if(window.CodeFlask) //disabled for now { panel.content.innerHTML = "
"; var flask = new CodeFlask( "div.code", { language: 'js' }); @@ -10643,30 +12385,37 @@ LGraphNode.prototype.executeAction = function(action) }); } else - { - panel.content.innerHTML = ""; - var textarea = panel.content.querySelector("textarea"); + {*/ + panel.alt_content.innerHTML = ""; + var textarea = panel.alt_content.querySelector("textarea"); + var fDoneWith = function(){ + panel.toggleAltContent(false); //if(node_prop_div) node_prop_div.style.display = "block"; // panel.close(); + panel.toggleFooterVisibility(true); + textarea.parentNode.removeChild(textarea); + panel.classList.add("settings"); + panel.classList.remove("centered"); + inner_refresh(); + } textarea.value = node.properties[propname]; textarea.addEventListener("keydown", function(e){ - //console.log(e); if(e.code == "Enter" && e.ctrlKey ) { - console.log("Assigned"); node.setProperty(propname, textarea.value); + fDoneWith(); } }); + panel.toggleAltContent(true); + panel.toggleFooterVisibility(false); textarea.style.height = "calc(100% - 40px)"; - } - var assign = that.createButton( "Assign", null, function(){ + /*}*/ + var assign = panel.addButton( "Assign", function(){ node.setProperty(propname, textarea.value); + fDoneWith(); }); - panel.content.appendChild(assign); - var button = that.createButton( "Close", null, function(){ - panel.style.height = ""; - inner_refresh(); - }); + panel.alt_content.appendChild(assign); //panel.content.appendChild(assign); + var button = panel.addButton( "Close", fDoneWith); button.style.float = "right"; - panel.content.appendChild(button); + panel.alt_content.appendChild(button); // panel.content.appendChild(button); } inner_refresh(); @@ -10806,9 +12555,22 @@ LGraphNode.prototype.executeAction = function(action) } LGraphCanvas.onMenuNodeCollapse = function(value, options, e, menu, node) { - node.graph.beforeChange(node); - node.collapse(); - node.graph.afterChange(node); + node.graph.beforeChange(/*?*/); + + var fApplyMultiNode = function(node){ + node.collapse(); + } + + var graphcanvas = LGraphCanvas.active_canvas; + if (!graphcanvas.selected_nodes || Object.keys(graphcanvas.selected_nodes).length <= 1){ + fApplyMultiNode(node); + }else{ + for (var i in graphcanvas.selected_nodes) { + fApplyMultiNode(graphcanvas.selected_nodes[i]); + } + } + + node.graph.afterChange(/*?*/); }; LGraphCanvas.onMenuNodePin = function(value, options, e, menu, node) { @@ -10817,7 +12579,7 @@ LGraphNode.prototype.executeAction = function(action) LGraphCanvas.onMenuNodeMode = function(value, options, e, menu, node) { new LiteGraph.ContextMenu( - ["Always", "On Event", "On Trigger", "Never"], + LiteGraph.NODE_MODES, { event: e, callback: inner_clicked, parentMenu: menu, node: node } ); @@ -10825,21 +12587,24 @@ LGraphNode.prototype.executeAction = function(action) if (!node) { return; } - switch (v) { - case "On Event": - node.mode = LiteGraph.ON_EVENT; - break; - case "On Trigger": - node.mode = LiteGraph.ON_TRIGGER; - break; - case "Never": - node.mode = LiteGraph.NEVER; - break; - case "Always": - default: - node.mode = LiteGraph.ALWAYS; - break; - } + var kV = Object.values(LiteGraph.NODE_MODES).indexOf(v); + var fApplyMultiNode = function(node){ + if (kV>=0 && LiteGraph.NODE_MODES[kV]) + node.changeMode(kV); + else{ + console.warn("unexpected mode: "+v); + node.changeMode(LiteGraph.ALWAYS); + } + } + + var graphcanvas = LGraphCanvas.active_canvas; + if (!graphcanvas.selected_nodes || Object.keys(graphcanvas.selected_nodes).length <= 1){ + fApplyMultiNode(node); + }else{ + for (var i in graphcanvas.selected_nodes) { + fApplyMultiNode(graphcanvas.selected_nodes[i]); + } + } } return false; @@ -10885,17 +12650,29 @@ LGraphNode.prototype.executeAction = function(action) } var color = v.value ? LGraphCanvas.node_colors[v.value] : null; - if (color) { - if (node.constructor === LiteGraph.LGraphGroup) { - node.color = color.groupcolor; - } else { - node.color = color.color; - node.bgcolor = color.bgcolor; - } - } else { - delete node.color; - delete node.bgcolor; - } + + var fApplyColor = function(node){ + if (color) { + if (node.constructor === LiteGraph.LGraphGroup) { + node.color = color.groupcolor; + } else { + node.color = color.color; + node.bgcolor = color.bgcolor; + } + } else { + delete node.color; + delete node.bgcolor; + } + } + + var graphcanvas = LGraphCanvas.active_canvas; + if (!graphcanvas.selected_nodes || Object.keys(graphcanvas.selected_nodes).length <= 1){ + fApplyColor(node); + }else{ + for (var i in graphcanvas.selected_nodes) { + fApplyColor(graphcanvas.selected_nodes[i]); + } + } node.setDirtyCanvas(true, true); } @@ -10918,9 +12695,22 @@ LGraphNode.prototype.executeAction = function(action) if (!node) { return; } - node.graph.beforeChange(node); - node.shape = v; - node.graph.afterChange(node); + node.graph.beforeChange(/*?*/); //node + + var fApplyMultiNode = function(node){ + node.shape = v; + } + + var graphcanvas = LGraphCanvas.active_canvas; + if (!graphcanvas.selected_nodes || Object.keys(graphcanvas.selected_nodes).length <= 1){ + fApplyMultiNode(node); + }else{ + for (var i in graphcanvas.selected_nodes) { + fApplyMultiNode(graphcanvas.selected_nodes[i]); + } + } + + node.graph.afterChange(/*?*/); //node node.setDirtyCanvas(true); } @@ -10932,13 +12722,26 @@ LGraphNode.prototype.executeAction = function(action) throw "no node passed"; } - if (node.removable === false) { - return; - } - var graph = node.graph; graph.beforeChange(); - graph.remove(node); + + + var fApplyMultiNode = function(node){ + if (node.removable === false) { + return; + } + graph.remove(node); + } + + var graphcanvas = LGraphCanvas.active_canvas; + if (!graphcanvas.selected_nodes || Object.keys(graphcanvas.selected_nodes).length <= 1){ + fApplyMultiNode(node); + }else{ + for (var i in graphcanvas.selected_nodes) { + fApplyMultiNode(graphcanvas.selected_nodes[i]); + } + } + graph.afterChange(); node.setDirtyCanvas(true, true); }; @@ -10964,17 +12767,37 @@ LGraphNode.prototype.executeAction = function(action) }; LGraphCanvas.onMenuNodeClone = function(value, options, e, menu, node) { - if (node.clonable == false) { - return; - } - var newnode = node.clone(); - if (!newnode) { - return; - } - newnode.pos = [node.pos[0] + 5, node.pos[1] + 5]; - + node.graph.beforeChange(); - node.graph.add(newnode); + + var newSelected = {}; + + var fApplyMultiNode = function(node){ + if (node.clonable == false) { + return; + } + var newnode = node.clone(); + if (!newnode) { + return; + } + newnode.pos = [node.pos[0] + 5, node.pos[1] + 5]; + node.graph.add(newnode); + newSelected[newnode.id] = newnode; + } + + var graphcanvas = LGraphCanvas.active_canvas; + if (!graphcanvas.selected_nodes || Object.keys(graphcanvas.selected_nodes).length <= 1){ + fApplyMultiNode(node); + }else{ + for (var i in graphcanvas.selected_nodes) { + fApplyMultiNode(graphcanvas.selected_nodes[i]); + } + } + + if(Object.keys(newSelected).length){ + graphcanvas.selectNodes(newSelected); + } + node.graph.afterChange(); node.setDirtyCanvas(true, true); @@ -10998,6 +12821,7 @@ LGraphNode.prototype.executeAction = function(action) LGraphCanvas.prototype.getCanvasMenuOptions = function() { var options = null; + var that = this; if (this.getMenuOptions) { options = this.getMenuOptions(); } else { @@ -11007,9 +12831,13 @@ LGraphNode.prototype.executeAction = function(action) has_submenu: true, callback: LGraphCanvas.onMenuAdd }, - { content: "Add Group", callback: LGraphCanvas.onGroupAdd } + { content: "Add Group", callback: LGraphCanvas.onGroupAdd }, + //{ content: "Arrange", callback: that.graph.arrange }, //{content:"Collapse All", callback: LGraphCanvas.onMenuCollapseAll } ]; + /*if (LiteGraph.showCanvasOptions){ + options.push({ content: "Options", callback: that.showShowGraphOptionsPanel }); + }*/ if (this._graph_stack && this._graph_stack.length > 0) { options.push(null, { @@ -11064,13 +12892,13 @@ LGraphNode.prototype.executeAction = function(action) content: "Mode", has_submenu: true, callback: LGraphCanvas.onMenuNodeMode - }, - { - content: "Resize", callback: function() { - if(node.resizable) - return LGraphCanvas.onResizeNode; - } - }, + }]; + if(node.resizable !== false){ + options.push({ + content: "Resize", callback: LGraphCanvas.onMenuResizeNode + }); + } + options.push( { content: "Collapse", callback: LGraphCanvas.onMenuNodeCollapse @@ -11087,7 +12915,7 @@ LGraphNode.prototype.executeAction = function(action) callback: LGraphCanvas.onMenuNodeShapes }, null - ]; + ); } if (node.onGetInputs) { @@ -11196,16 +13024,16 @@ LGraphNode.prototype.executeAction = function(action) menu_info.push({ content: "Disconnect Links", slot: slot }); } var _slot = slot.input || slot.output; - menu_info.push( - _slot.locked || !_slot.removable - ? "Cannot remove" - : { content: "Remove Slot", slot: slot } - ); - menu_info.push( - _slot.nameLocked - ? "Cannot rename" - : { content: "Rename Slot", slot: slot } - ); + if (_slot.removable){ + menu_info.push( + _slot.locked + ? "Cannot remove" + : { content: "Remove Slot", slot: slot } + ); + } + if (!_slot.nameLocked){ + menu_info.push({ content: "Rename Slot", slot: slot }); + } } options.title = @@ -11255,19 +13083,23 @@ LGraphNode.prototype.executeAction = function(action) if (v.content == "Remove Slot") { var info = v.slot; + node.graph.beforeChange(); if (info.input) { node.removeInput(info.slot); } else if (info.output) { node.removeOutput(info.slot); } + node.graph.afterChange(); return; } else if (v.content == "Disconnect Links") { var info = v.slot; + node.graph.beforeChange(); if (info.output) { node.disconnectOutput(info.slot); } else if (info.input) { node.disconnectInput(info.slot); } + node.graph.afterChange(); return; } else if (v.content == "Rename Slot") { var info = v.slot; @@ -11282,17 +13114,32 @@ LGraphNode.prototype.executeAction = function(action) if (input && slot_info) { input.value = slot_info.label || ""; } - dialog - .querySelector("button") - .addEventListener("click", function(e) { - if (input.value) { - if (slot_info) { - slot_info.label = input.value; - } - that.setDirty(true); + var inner = function(){ + node.graph.beforeChange(); + if (input.value) { + if (slot_info) { + slot_info.label = input.value; } + that.setDirty(true); + } + dialog.close(); + node.graph.afterChange(); + } + dialog.querySelector("button").addEventListener("click", inner); + input.addEventListener("keydown", function(e) { + dialog.is_modified = true; + if (e.keyCode == 27) { + //ESC dialog.close(); - }); + } else if (e.keyCode == 13) { + inner(); // save + } else if (e.keyCode != 13 && e.target.localName != "textarea") { + return; + } + e.preventDefault(); + e.stopPropagation(); + }); + input.focus(); } //if(v.callback) @@ -11855,6 +13702,9 @@ LGraphNode.prototype.executeAction = function(action) if (this.root.closing_timer) { clearTimeout(this.root.closing_timer); } + + // TODO implement : LiteGraph.contextMenuClosed(); :: keep track of opened / closed / current ContextMenu + // on key press, allow filtering/selecting the context menu elements }; //this code is used to trigger events easily (used in the context menu mouseleave @@ -12162,23 +14012,65 @@ LGraphNode.prototype.executeAction = function(action) .filter(Boolean); // split & filter [""] }; - // helper pointerListener vs mouseListener, used by LGraphCanvas DragAndScale ContextMenu - LiteGraph.pointerListenerAdd = function(oDOM, sEvent, fCall, capture=false) { - if (!oDOM || !oDOM.addEventListener || !sEvent || typeof fCall!=="function"){ - console.log("cant pointerListenerAdd "+oDOM+", "+sEvent+", "+fCall); + /* helper for interaction: pointer, touch, mouse Listeners + used by LGraphCanvas DragAndScale ContextMenu*/ + LiteGraph.pointerListenerAdd = function(oDOM, sEvIn, fCall, capture=false) { + if (!oDOM || !oDOM.addEventListener || !sEvIn || typeof fCall!=="function"){ + //console.log("cant pointerListenerAdd "+oDOM+", "+sEvent+", "+fCall); return; // -- break -- } + + var sMethod = LiteGraph.pointerevents_method; + var sEvent = sEvIn; + + // UNDER CONSTRUCTION + // convert pointerevents to touch event when not available + if (sMethod=="pointer" && !window.PointerEvent){ + console.warn("sMethod=='pointer' && !window.PointerEvent"); + console.log("Converting pointer["+sEvent+"] : down move up cancel enter TO touchstart touchmove touchend, etc .."); + switch(sEvent){ + case "down":{ + sMethod = "touch"; + sEvent = "start"; + break; + } + case "move":{ + sMethod = "touch"; + //sEvent = "move"; + break; + } + case "up":{ + sMethod = "touch"; + sEvent = "end"; + break; + } + case "cancel":{ + sMethod = "touch"; + //sEvent = "cancel"; + break; + } + case "enter":{ + console.log("debug: Should I send a move event?"); // ??? + break; + } + // case "over": case "out": not used at now + default:{ + console.warn("PointerEvent not available in this browser ? The event "+sEvent+" would not be called"); + } + } + } + switch(sEvent){ //both pointer and move events case "down": case "up": case "move": case "over": case "out": case "enter": { - oDOM.addEventListener(LiteGraph.pointerevents_method+sEvent, fCall, capture); + oDOM.addEventListener(sMethod+sEvent, fCall, capture); } // only pointerevents case "leave": case "cancel": case "gotpointercapture": case "lostpointercapture": { - if (LiteGraph.pointerevents_method!="mouse"){ - return oDOM.addEventListener(LiteGraph.pointerevents_method+sEvent, fCall, capture); + if (sMethod!="mouse"){ + return oDOM.addEventListener(sMethod+sEvent, fCall, capture); } } // not "pointer" || "mouse" @@ -12188,19 +14080,21 @@ LGraphNode.prototype.executeAction = function(action) } LiteGraph.pointerListenerRemove = function(oDOM, sEvent, fCall, capture=false) { if (!oDOM || !oDOM.removeEventListener || !sEvent || typeof fCall!=="function"){ - console.log("cant pointerListenerRemove "+oDOM+", "+sEvent+", "+fCall); + //console.log("cant pointerListenerRemove "+oDOM+", "+sEvent+", "+fCall); return; // -- break -- } switch(sEvent){ //both pointer and move events case "down": case "up": case "move": case "over": case "out": case "enter": { - oDOM.removeEventListener(LiteGraph.pointerevents_method+sEvent, fCall, capture); + if (LiteGraph.pointerevents_method=="pointer" || LiteGraph.pointerevents_method=="mouse"){ + oDOM.removeEventListener(LiteGraph.pointerevents_method+sEvent, fCall, capture); + } } // only pointerevents case "leave": case "cancel": case "gotpointercapture": case "lostpointercapture": { - if (LiteGraph.pointerevents_method!="mouse"){ + if (LiteGraph.pointerevents_method=="pointer"){ return oDOM.removeEventListener(LiteGraph.pointerevents_method+sEvent, fCall, capture); } } diff --git a/build/litegraph.core.min.js b/build/litegraph.core.min.js index 043ab2aec..ed4b392de 100644 --- a/build/litegraph.core.min.js +++ b/build/litegraph.core.min.js @@ -1,290 +1,346 @@ -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(q,l,v){q!=Array.prototype&&q!=Object.prototype&&(q[l]=v.value)};$jscomp.getGlobal=function(q){return"undefined"!=typeof window&&window===q?q:"undefined"!=typeof global&&null!=global?global:q};$jscomp.global=$jscomp.getGlobal(this); -$jscomp.polyfill=function(q,l,v,r){if(l){v=$jscomp.global;q=q.split(".");for(r=0;rq&&(q=Math.max(0,v+q));if(null==r||r>v)r=v;r=Number(r);0>r&&(r=Math.max(0,v+r));for(q=Number(q||0);q=y}},"es6","es3");$jscomp.findInternal=function(q,l,v){q instanceof String&&(q=String(q));for(var r=q.length,x=0;xa&&db?!0:!1}function H(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||ch.width-k.width-10&&(e=h.width-k.width-10),h.height&&a>h.height-k.height-10&&(a=h.height-k.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=q.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,INPUT:1,OUTPUT:2, -EVENT:-1,ACTION:-1,ALWAYS:0,ON_EVENT:1,NEVER:2,ON_TRIGGER:3,UP:1,DOWN:2,LEFT:3,RIGHT:4,CENTER:5,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,pointerevents_method:"pointer",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 r.prototype)b.prototype[e]||(b.prototype[e]=r.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;eh&&(h=e.size[0]),k+=e.size[1]+a+f.NODE_TITLE_HEIGHT;b+=h+a}this.setDirtyCanvas(!0,!0)};l.prototype.getTime=function(){return this.globaltime};l.prototype.getFixedTime=function(){return this.fixedtime};l.prototype.getElapsedTime=function(){return this.elapsed_time}; -l.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=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_idp&&(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=z}},"es6","es3"); +$jscomp.findInternal=function(p,v,w){p instanceof String&&(p=String(p));for(var l=p.length,x=0;xa&&db?!0:!1}function F(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 +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, +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"; +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;eh&&(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=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_ida.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={}};r.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.outputs.length)){var c=this.outputs[a];if(c&&(c._data=b,this.outputs[a].links))for(c=0;c=this.outputs.length)){var c=this.outputs[a];if(c&&(c.type=b,this.outputs[a].links))for(c=0;c=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}};r.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};r.prototype.getInputDataByName=function(a,b){a=this.findInputSlot(a);return-1==a?null:this.getInputData(a, -b)};r.prototype.isInputConnected=function(a){return 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};r.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=this.outputs.length?null:this.outputs[a]._data};r.prototype.getOutputInfo=function(a){return this.outputs? -a=this.outputs.length)return null;a=this.outputs[a]; -if(!a.links||0==a.links.length)return null;for(var b=[],c=0;ca&&this.pos[1]-e-cb)return!0;return!1};r.prototype.getSlotInPosition=function(a,b){var c=new Float32Array(2);if(this.inputs)for(var d=0,e=this.inputs.length;d=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)return null;if(!b.inputs||c>=b.inputs.length)return f.debug&&console.log("Connect: Error, slot number not found"),null}var d=!1;null!=b.inputs[c].link&&(this.graph.beforeChange(),b.disconnectInput(c),d=!0);var e=this.outputs[a];if(b.onConnectInput&& -!1===b.onConnectInput(c,e.type,e,this,a))return null;var g=b.inputs[c],h=null;if(!f.isValidConnection(e.type,g.type))return this.setDirtyCanvas(!1,!0),d&&this.graph.connectionChange(this,h),null;d||this.graph.beforeChange();h=new v(++this.graph.last_link_id,g.type,this.id,a,b.id,c);this.graph.links[h.id]=h;null==e.links&&(e.links=[]);e.links.push(h.id);b.inputs[c].link=h.id;this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(f.OUTPUT,a,!0,h,e);if(b.onConnectionsChange)b.onConnectionsChange(f.INPUT, -c,!0,h,g);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,h);return h};r.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=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,k=g.links.length;hb&&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};r.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)};r.prototype.trace=function(a){this.console||(this.console=[]);this.console.push(a);this.console.length>r.MAX_CONSOLE&&this.console.shift();if(this.graph.onNodeTrace)this.graph.onNodeTrace(this, -a)};r.prototype.setDirtyCanvas=function(a,b){this.graph&&this.graph.sendActionToCanvas("setDirty",[a,b])};r.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};r.prototype.captureInput=function(a){if(this.graph&&this.graph.list_of_graphcanvas)for(var b=this.graph.list_of_graphcanvas,c=0;ca.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})};x.prototype.configure=function(a){this.title=a.title;this._bounding.set(a.bounding);this.color=a.color;this.font=a.font};x.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}};x.prototype.move=function(a,b,c){this._pos[0]+=a;this._pos[1]+=b;if(!c)for(c=0;c=this.viewport[0]&&d=this.viewport[1]&&cthis.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};q.LGraphCanvas=f.LGraphCanvas=n;n.DEFAULT_BACKGROUND_IMAGE="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQBJREFUeNrs1rEKwjAUhlETUkj3vP9rdmr1Ysammk2w5wdxuLgcMHyptfawuZX4pJSWZTnfnu/lnIe/jNNxHHGNn//HNbbv+4dr6V+11uF527arU7+u63qfa/bnmh8sWLBgwYJlqRf8MEptXPBXJXa37BSl3ixYsGDBMliwFLyCV/DeLIMFCxYsWLBMwSt4Be/NggXLYMGCBUvBK3iNruC9WbBgwYJlsGApeAWv4L1ZBgsWLFiwYJmCV/AK3psFC5bBggULloJX8BpdwXuzYMGCBctgwVLwCl7Be7MMFixYsGDBsu8FH1FaSmExVfAxBa/gvVmwYMGCZbBg/W4vAQYA5tRF9QYlv/QAAAAASUVORK5CYII="; -n.link_type_colors={"-1":f.EVENT_LINK_COLOR,number:"#AAA",node:"#DCA"};n.gradients={};n.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()};n.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)))};n.prototype.getTopGraph=function(){return this._graph_stack.length?this._graph_stack[0]:this.graph};n.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)};n.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}};n.prototype.getCurrentGraph=function(){return this.graph};n.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 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()}};n.prototype._doNothing=function(a){a.preventDefault();return!1};n.prototype._doReturnTrue=function(a){a.preventDefault(); -return!0};n.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}};n.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); +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;ca.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.outputs.length)){var c=this.outputs[a];if(c&&(c._data=b,this.outputs[a].links))for(c=0;c=this.outputs.length)){var c=this.outputs[a];if(c&&(c.type=b,this.outputs[a].links))for(c=0;c=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)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=this.outputs.length?null:this.outputs[a]._data};l.prototype.getOutputInfo=function(a){return this.outputs? +a=this.outputs.length)return null;a=this.outputs[a]; +if(!a.links||0==a.links.length)return null;for(var b=[],c=0;ca&&this.pos[1]-e-cb)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=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=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;hb&&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;ca.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})};x.prototype.configure=function(a){this.title=a.title;this._bounding.set(a.bounding);this.color=a.color;this.font=a.font};x.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}};x.prototype.move=function(a,b, +c){this._pos[0]+=a;this._pos[1]+=b;if(!c)for(c=0;c= +this.viewport[0]&&d=this.viewport[1]&&cthis.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};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="; +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= +[0,0];this.ds.scale=1}};m.prototype.getCurrentGraph=function(){return this.graph};m.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 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()}};m.prototype._doNothing=function(a){a.preventDefault();return!1};m.prototype._doReturnTrue=function(a){a.preventDefault(); +return!0};m.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);g.pointerListenerAdd(a,"down",this._mousedown_callback,!0);a.addEventListener("mousewheel",this._mousewheel_callback, +!1);g.pointerListenerAdd(a,"up",this._mouseup_callback,!0);g.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}};m.prototype.unbindEvents=function(){if(this._events_binded){var a=this.getCanvasWindow().document;g.pointerListenerRemove(this.canvas,"move",this._mousedown_callback);g.pointerListenerRemove(this.canvas,"up",this._mousedown_callback);g.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")}; -n.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()};n.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};n.prototype.setDirty=function(a,b){a&&(this.dirty_canvas=!0);b&&(this.dirty_bgcanvas=!0)};n.prototype.getCanvasWindow=function(){if(!this.canvas)return window;var a=this.canvas.ownerDocument; -return a.defaultView||a.parentWindow};n.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))};n.prototype.stopRendering=function(){this.is_rendering=!1};n.prototype.blockClick=function(){this.block_click=!0;this.last_mouseclick=0};n.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();n.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[1]&&ef.getTime()-this.last_mouseclick&&void 0!==a.isPrimary&&a.isPrimary;this.mouse[0]=a.clientX;this.mouse[1]=a.clientY;this.graph_mouse[0]=a.canvasX;this.graph_mouse[1]=a.canvasY;this.last_click_position=[this.mouse[0],this.mouse[1]];this.pointer_is_double=this.pointer_is_down&&void 0!==a.isPrimary&&!a.isPrimary?!0:!1;this.pointer_is_down=!0;this.canvas.focus();f.closeAllContextMenus(b); -if(!this.onMouse||1!=this.onMouse(a)){if(1!=a.which||this.pointer_is_double)2==a.which||3!=a.which&&!this.pointer_is_double||this.read_only||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,e=!0);var h=!1;if(g&&this.allow_interaction&&!e&&!this.read_only){this.live_mode||g.flags.pinned||this.bringToFront(g);if(!this.connecting_node&& -!g.flags.collapsed&&!this.live_mode)if(!e&&!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",e=!0;else{if(g.outputs)for(var k=0,m=g.outputs.length;kg.size[0]-f.NODE_TITLE_HEIGHT&&0>m[1]&&(c=this,setTimeout(function(){c.openSubgraph(g.subgraph)},10)),this.live_mode&&(k=h=!0));k||(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(!this.read_only)for(k=0;km[0]+4||a.canvasYm[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>J([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());d&&!this.read_only&& -this.allow_searchbox&&this.showSearchBox(a);h=!0}!e&&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}}}};n.prototype.processMouseMove= -function(a){this.autoresize&&this.resize();this.set_canvas_dirty_on_mouse_event&&(this.dirty_canvas=!0);if(this.graph){n.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;bh[0]+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}};n.prototype.processMouseUp=function(a){if(void 0!==a.isPrimary&&!a.isPrimary)return!1;this.set_canvas_dirty_on_mouse_event&& -(this.dirty_canvas=!0);if(this.graph){var b=this.getCanvasWindow().document;n.active_canvas=this;this.options.skip_events||(f.pointerListenerRemove(b,"move",this._mousemove_callback,!0),f.pointerListenerAdd(this.canvas,"move",this._mousemove_callback,!0),f.pointerListenerRemove(b,"up",this._mouseup_callback,!0));this.adjustMouseEvent(a);b=f.getTime();a.click_time=b-this.last_mouseclick;this.last_mouse_dragging=!1;this.last_click_position=null;this.block_click&&(this.block_click=!1);if(1==a.which)if(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,this.dragging_rectangle){if(this.graph){b=this.graph._nodes;var c=new Float32Array(4);this.deselectAllNodes();var d=Math.abs(this.dragging_rectangle[2]),e=Math.abs(this.dragging_rectangle[3]),g=0>this.dragging_rectangle[3]?this.dragging_rectangle[1]-e:this.dragging_rectangle[1];this.dragging_rectangle[0]=0>this.dragging_rectangle[2]?this.dragging_rectangle[0]-d:this.dragging_rectangle[0];this.dragging_rectangle[1]=g;this.dragging_rectangle[2]=d;this.dragging_rectangle[3]=e;e=[];for(g=0;ga.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.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);void 0!==a.isPrimary&&a.isPrimary&&(this.pointer_is_double=this.pointer_is_down=!1);this.graph.change();a.stopPropagation();a.preventDefault();return!1}};n.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[1]&&db&&(c*=1/1.1),this.ds.changeScale(c,[a.clientX,a.clientY]),this.graph.change(),a.preventDefault(),!1}};n.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};n.prototype.isOverNodeInput=function(a,b,c,d){if(a.inputs)for(var e=0,g=a.inputs.length;e=this.viewport[0]&&b=this.viewport[1]&&cc-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}};n.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.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&&.5this.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;D.set(a.size);var k=a.horizontal;if(a.flags.collapsed){b.font=this.inner_text_font;var m=a.getTitle?a.getTitle():a.title;null!=m&&(a._collapsed_width=Math.min(a.size[0],b.measureText(m).width+ -2*f.NODE_TITLE_HEIGHT),D[0]=a._collapsed_width,D[1]=0)}a.clip_area&&(b.save(),b.beginPath(),h==f.BOX_SHAPE?b.rect(0,0,D[0],D[1]):h==f.ROUND_SHAPE?b.roundRect(0,0,D[0],D[1],[10]):h==f.CIRCLE_SHAPE&&b.arc(.5*D[0],.5*D[1],.5*D[0],0,2*Math.PI),b.clip());a.has_errors&&(d="red");this.drawNodeShape(a,b,D,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;h=this.connecting_output; -b.lineWidth=1;m=0;var u=new Float32Array(2);if(!a.flags.collapsed){if(a.inputs)for(c=0;cthis.ds.scale,m=a._shape||a.constructor.shape||f.ROUND_SHAPE,u=a.constructor.title_mode,t=!0;u==f.TRANSPARENT_TITLE||u==f.NO_TITLE?t=!1:u==f.AUTOHIDE_TITLE&&h&&(t=!0);w[0]= -0;w[1]=t?-e:0;w[2]=c[0]+1;w[3]=t?c[1]+e:c[1];h=b.globalAlpha;b.beginPath();m==f.BOX_SHAPE||k?b.fillRect(w[0],w[1],w[2],w[3]):m==f.ROUND_SHAPE||m==f.CARD_SHAPE?b.roundRect(w[0],w[1],w[2],w[3],m==f.CARD_SHAPE?[this.round_radius,this.round_radius,0,0]:[this.round_radius]):m==f.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,w[2],2));b.shadowColor="transparent";if(a.onDrawBackground)a.onDrawBackground(b, -this,this.canvas,this.graph_mouse);if(t||u==f.TRANSPARENT_TITLE){if(a.onDrawTitleBar)a.onDrawTitleBar(b,e,c,this.ds.scale,d);else if(u!=f.TRANSPARENT_TITLE&&(a.constructor.title_color||this.render_title_colored)){t=a.constructor.title_color||d;a.flags.collapsed&&(b.shadowColor=f.DEFAULT_SHADOW_COLOR);if(this.use_gradients){var p=n.gradients[t];p||(p=n.gradients[t]=b.createLinearGradient(0,0,400,0),p.addColorStop(0,t),p.addColorStop(1,"#000"));b.fillStyle=p}else b.fillStyle=t;b.beginPath();m==f.BOX_SHAPE|| -k?b.rect(0,-e,c[0]+1,e):(m==f.ROUND_SHAPE||m==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"}if(a.onDrawTitleBox)a.onDrawTitleBox(b,e,c,this.ds.scale);else m==f.ROUND_SHAPE||m==f.CIRCLE_SHAPE||m==f.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||f.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||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);!k&&(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,t=a.size[0]-h,p=f.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=p?"#888":"#555",m==f.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(g){if(a.onBounding)a.onBounding(w);u==f.TRANSPARENT_TITLE&&(w[1]-=e,w[3]+=e);b.lineWidth=1;b.globalAlpha=.8;b.beginPath();m==f.BOX_SHAPE?b.rect(-6+w[0],-6+w[1],12+w[2],12+w[3]):m==f.ROUND_SHAPE||m==f.CARD_SHAPE&&a.flags.collapsed?b.roundRect(-6+w[0],-6+w[1],12+w[2],12+w[3],[2*this.round_radius]):m==f.CARD_SHAPE?b.roundRect(-6+w[0],-6+w[1],12+w[2],12+w[3],[2*this.round_radius,2,2*this.round_radius,2]):m==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}};var I=new Float32Array(4),A=new Float32Array(4),L=new Float32Array(2),M=new Float32Array(2);n.prototype.drawConnections=function(a){var b=f.getTime(),c=this.visible_area;I[0]=c[0]-20;I[1]=c[1]-20;I[2]=c[2]+40;I[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;hA[2]&&(A[0]+=A[2],A[2]=Math.abs(A[2]));0>A[3]&&(A[1]+=A[3],A[3]=Math.abs(A[3]));if(H(A,I)){var n=m.outputs[u];u=g.inputs[h];if(n&& -u&&(m=n.dir||(m.horizontal?f.DOWN:f.RIGHT),u=u.dir||(g.horizontal?f.UP:f.LEFT),this.renderLink(a,t,p,k,!1,0,null,m,u),k&&k._last_time&&1E3>b-k._last_time)){n=2-.002*(b-k._last_time);var B=a.globalAlpha;a.globalAlpha=B*n;this.renderLink(a,t,p,k,!0,n,"white",m,u);a.globalAlpha=B}}}}}}a.globalAlpha=1};n.prototype.renderLink=function(a,b,c,d,e,g,h,k,m,u){d&&this.visible_links.push(d);!h&&d&&(h=d.color||n.link_type_colors[d.type]);h||(h=this.default_link_color);null!=d&&this.highlighted_links[d.id]&&(h= -"#FFF");k=k||f.RIGHT;m=m||f.LEFT;var t=J(b,c);this.render_connections_border&&.6b[1]?0:Math.PI,a.save(),a.translate(p[0],p[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(u),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,p=0;5>p;++p)g=(.001*f.getTime()+.2*p)%1,e=this.computeConnectionPoint(b,c,g,k,m),a.beginPath(),a.arc(e[0],e[1],5,0,2*Math.PI),a.fill()};n.prototype.computeConnectionPoint=function(a,b,c,d,e){d=d||f.RIGHT;e=e||f.LEFT;var g=J(a,b),h=[a[0],a[1]],k=[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: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}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*k[0]+c*b[0],d*a[1]+e*h[1]+g*k[1]+c*b[1]]};n.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;cg||g>q-12||hp.last_y+l||void 0===p.last_y)){d=p.value;switch(p.type){case "button":c.type===f.pointerevents_method+"down"&&(p.callback&&setTimeout(function(){p.callback(p,m,a,b,c)},20),this.dirty_canvas=p.clicked=!0);break;case "slider":n=Math.clamp((g-15)/(q-30),0,1);p.value=p.options.min+(p.options.max-p.options.min)*n;p.callback&&setTimeout(function(){e(p,p.value)},20);this.dirty_canvas=!0;break;case "number":case "combo":d= -p.value;if(c.type==f.pointerevents_method+"move"&&"number"==p.type)p.value+=.1*c.deltaX*(p.options.step||1),null!=p.options.min&&p.valuep.options.max&&(p.value=p.options.max);else if(c.type==f.pointerevents_method+"down"){var r=p.options.values;r&&r.constructor===Function&&(r=p.options.values(p,a));var v=null;"number"!=p.type&&(v=r.constructor===Array?r:Object.keys(r));g=40>g?-1:g>q-40?1:0;if("number"==p.type)p.value+=.1*g*(p.options.step|| -1),null!=p.options.min&&p.valuep.options.max&&(p.value=p.options.max);else if(g)n=-1,this.last_mouseclick=0,n=r.constructor===Object?v.indexOf(String(p.value))+g:v.indexOf(p.value)+g,n>=v.length&&(n=v.length-1),0>n&&(n=0),p.value=r.constructor===Array?r[n]:n;else{var z=r!=v?Object.values(r):r;new f.ContextMenu(z,{scale:Math.max(1,this.ds.scale),event:c,className:"dark",callback:function(a,b,c){r!=v&&(a=z.indexOf(a));this.value=a; -e(this,a);m.dirty_canvas=!0;return!1}.bind(p)},n)}}else c.type==f.pointerevents_method+"up"&&"number"==p.type&&(g=40>g?-1:g>q-40?1:0,200>c.click_time&&0==g&&this.prompt("Value",p.value,function(a){this.value=Number(a);e(this,this.value)}.bind(p),c));d!=p.value&&setTimeout(function(){e(this,this.value)}.bind(p),20);this.dirty_canvas=!0;break;case "toggle":c.type==f.pointerevents_method+"down"&&(p.value=!p.value,setTimeout(function(){e(p,p.value)},20));break;case "string":case "text":c.type==f.pointerevents_method+ -"down"&&this.prompt("Value",p.value,function(a){this.value=a;e(this,a)}.bind(p),c,p.options?p.options.multiline:!1);break;default:p.mouse&&(this.dirty_canvas=p.mouse(c,[g,h],a))}if(d!=p.value){if(a.onWidgetChanged)a.onWidgetChanged(p.name,p.value,d,p);a.graph._version++}return p}}}return null};n.prototype.drawGroups=function(a,b){if(this.graph){a=this.graph._groups;b.save();b.globalAlpha=.5*this.editor_alpha;for(var c=0;cc&&.01>b.editor_alpha&&(clearInterval(d),1>c&&(b.live_mode=!0));1"+(m.label?m.label:k)+""+a+"", -value:k})}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}};n.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};n.onResizeNode=function(a,b,c,d,e){if(e){e.size=e.computeSize();if(e.onResize)e.onResize(e.size);e.setDirtyCanvas(!0,!0)}};n.prototype.showLinkMenu=function(a,b){var c=this;console.log(a); -var d=new f.ContextMenu(["Add Node",null,"Delete"],{event:b,title:null!=a.data?a.data.constructor.name:null,callback:function(b,g,h){switch(b){case "Add Node":n.onMenuAdd(null,null,h,d,function(b){console.log("node autoconnect");var d=c.graph.getNodeById(a.origin_id),e=c.graph.getNodeById(a.target_id);b.inputs&&b.inputs.length&&b.outputs&&b.outputs.length&&d.outputs[a.origin_slot].type==b.inputs[0].type&&b.outputs[0].type==e.inputs[0].type&&(d.connect(a.origin_slot,b,0),b.connect(0,e,a.target_slot), -b.pos[0]-=.5*b.size[0])});break;case "Delete":c.graph.removeLink(a.id)}}});return!1};n.onShowPropertyEditor=function(a,b,c,d,e){function g(){var b=m.value;"Number"==a.type?b=Number(b):"Boolean"==a.type&&(b=!!b);e[h]=b;f.parentNode&&f.parentNode.removeChild(f);e.setDirtyCanvas(!0,!0)}var h=a.property||"title";b=e[h];var f=document.createElement("div");f.className="graphdialog";f.innerHTML="";f.querySelector(".name").innerText= -h;var m=f.querySelector(".value");m&&(m.value=b,m.addEventListener("blur",function(a){this.focus()}),m.addEventListener("keydown",function(a){if(13==a.keyCode||"textarea"==a.target.localName)g(),a.preventDefault(),a.stopPropagation()}));b=n.active_canvas.canvas;c=b.getBoundingClientRect();var l=d=-20;c&&(d-=c.left,l-=c.top);event?(f.style.left=event.clientX+d+"px",f.style.top=event.clientY+l+"px"):(f.style.left=.5*b.width+d+"px",f.style.top=.5*b.height+l+"px");f.querySelector("button").addEventListener("click", -g);b.parentNode.appendChild(f)};n.prototype.prompt=function(a,b,c,d,e){var g=this;a=a||"";var h=!1,k=document.createElement("div");k.className="graphdialog rounded";k.innerHTML=e?" ":" ";k.close=function(){g.prompt_box=null;k.parentNode&&k.parentNode.removeChild(k)};1n.search_limit)break}}l=null;if(Array.prototype.filter)l=Object.keys(f.registered_node_types).filter(d);else for(h in l=[],f.registered_node_types)d(h)&&l.push(h);for(h=0;hn.search_limit);h++);}}var e=this,g=n.active_canvas,h=g.canvas,k=h.ownerDocument||document,m=document.createElement("div");m.className="litegraph litesearchbox graphdialog rounded";m.innerHTML="Search
"; -m.close=function(){e.search_box=null;k.body.focus();k.body.style.overflow="";setTimeout(function(){e.canvas.focus()},20);m.parentNode&&m.parentNode.removeChild(m)};var l=null;1h.height-200&&(t.style.maxHeight=h.height-a.layerY-20+"px");v.focus();return m};n.prototype.showEditPropertyValue=function(a,b,c){function d(){e(p.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();n.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="";else if("enum"!=h&&"combo"!=h||!g.values)if("boolean"==h)f="";else{console.warn("unknown type: "+h); -return}else{f=""}var n=this.createDialog(""+(g.label?g.label:b)+""+f+"",c);if("enum"!=h&&"combo"!=h||!g.values)if("boolean"==h)(p=n.querySelector("input"))&&p.addEventListener("click",function(a){e(!!p.checked)});else{if(p=n.querySelector("input"))p.addEventListener("blur", -function(a){this.focus()}),l=void 0!==a.properties[b]?a.properties[b]:"","string"!==h&&(l=JSON.stringify(l)),p.value=l,p.addEventListener("keydown",function(a){13==a.keyCode&&(d(),a.preventDefault(),a.stopPropagation())})}else{var p=n.querySelector("select");p.addEventListener("change",function(a){e(a.target.value)})}n.querySelector("button").addEventListener("click",d);return n}};n.prototype.createDialog=function(a,b){b=b||{};var c=document.createElement("div");c.className="graphdialog";c.innerHTML= -a;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);c.close=function(){this.parentNode&&this.parentNode.removeChild(this)};return c};n.prototype.createPanel=function(a,b){b=b||{};var c=b.window||window,d=document.createElement("div");d.className="litegraph dialog"; -d.innerHTML="
";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.footer=d.querySelector(".dialog-footer");d.close=function(){this.parentNode&&this.parentNode.removeChild(this)};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,l){function e(a,b){console.log("change",a,b);k.callback&&k.callback(a,b);l&&l(a,b)}k=k||{};var g=String(h);a=a.toLowerCase();"number"==a&&(g=h.toFixed(3));var m=document.createElement("div");m.className="property";m.innerHTML=""; -m.querySelector(".property_name").innerText=k.label||b;var q=m.querySelector(".property_value");q.innerText=g;m.dataset.property=b;m.dataset.type=k.type||a;m.options=k;m.value=h;if("boolean"==a)m.classList.add("boolean"),h&&m.classList.add("bool-on"),m.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)q.setAttribute("contenteditable", -!0),q.addEventListener("keydown",function(a){"Enter"==a.code&&(a.preventDefault(),this.blur())}),q.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=n.getPropertyPrintableValue(h,k.values),q.innerText=g,q.addEventListener("click",function(a){var b=this.parentNode.dataset.property,d=this;new f.ContextMenu(k.values||[],{event:a,className:"dark",callback:function(a, -c,g){d.innerText=a;e(b,a);return!1}},c)});d.content.appendChild(m);return m};return d};n.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+")"}};n.prototype.showShowNodePanel=function(a){window.SELECTED_NODE=a;var b=document.querySelector("#node-panel");b&&b.close();var c=this.getCanvasWindow();b=this.createPanel(a.title||"",{closable:!0,window:c});b.id="node-panel";b.node= -a;b.classList.add("settings");var d=this;(function(){b.content.innerHTML="";b.addHTML(""+a.type+""+(a.constructor.desc||"")+"");b.addHTML("

Properties

");for(var c in a.properties){var g=a.properties[c],f=a.getPropertyInfo(c);a.onAddPropertyToPanel&&a.onAddPropertyToPanel(c,b)||b.addWidget(f.widget||f.type,c,g,f,function(b,c){d.graph.beforeChange(a);a.setProperty(b,c);d.graph.afterChange();d.dirty_canvas= -!0})}b.addSeparator();if(a.onShowCustomPanelInfo)a.onShowCustomPanelInfo(b);b.addButton("Delete",function(){a.block_delete||(a.graph.remove(a),b.close())}).classList.add("delete")})();this.canvas.parentNode.appendChild(b)};n.prototype.showSubgraphPropertiesDialog=function(a){function b(){d.clear();if(a.inputs)for(var c=0;c", -"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(" + NameType","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};n.prototype.showSubgraphPropertiesDialogRight= -function(a){function b(){e.clear();if(a.outputs)for(var c=0;c","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(" + NameType", -"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};n.prototype.checkPanels=function(){if(this.canvas)for(var a=this.canvas.parentNode.querySelectorAll(".litegraph.dialog"),b=0;bNo color"});for(var g in n.node_colors)a=n.node_colors[g],a={value:g,content:""+g+""},b.push(a);new f.ContextMenu(b,{event:c,callback:function(a){e&&((a=a.value?n.node_colors[a.value]:null)?e.constructor===f.LGraphGroup?e.color=a.groupcolor:(e.color=a.color,e.bgcolor=a.bgcolor): -(delete e.color,delete e.bgcolor),e.setDirtyCanvas(!0,!0))},parentMenu:d,node:e});return!1};n.onMenuNodeShapes=function(a,b,c,d,e){if(!e)throw"no node passed";new f.ContextMenu(f.VALID_SHAPES,{event:c,callback:function(a){e&&(e.graph.beforeChange(e),e.shape=a,e.graph.afterChange(e),e.setDirtyCanvas(!0))},parentMenu:d,node:e});return!1};n.onMenuNodeRemove=function(a,b,c,d,e){if(!e)throw"no node passed";!1!==e.removable&&(a=e.graph,a.beforeChange(),a.remove(e),a.afterChange(),e.setDirtyCanvas(!0,!0))}; -n.onMenuNodeToSubgraph=function(a,b,c,d,e){a=e.graph;if(b=n.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)};n.onMenuNodeClone=function(a,b,c,d,e){0!=e.clonable&&(a=e.clone())&&(a.pos=[e.pos[0]+5,e.pos[1]+5],e.graph.beforeChange(),e.graph.add(a),e.graph.afterChange(),e.setDirtyCanvas(!0,!0))};n.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"}};n.prototype.getCanvasMenuOptions=function(){if(this.getMenuOptions)var a= -this.getMenuOptions();else a=[{content:"Add Node",has_submenu:!0,callback:n.onMenuAdd},{content:"Add Group",callback:n.onGroupAdd}],this._graph_stack&&0Name",d),h=f.querySelector("input");h&&g&&(h.value=g.label||"");f.querySelector("button").addEventListener("click",function(a){h.value&& -(g&&(g.label=h.value),c.setDirty(!0));f.close()})}},extra:a};a&&(g.title=a.type);var h=null;a&&(h=a.getSlotInPosition(b.canvasX,b.canvasY),n.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,e.push(b.locked||!b.removable?"Cannot remove":{content:"Remove Slot",slot:h}),e.push(b.nameLocked?"Cannot rename":{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 m=f=k=g=e[0];else if(2==e.length)m=g=e[0],f=k=e[1];else if(4==e.length)m=e[0],f=e[1],k=e[2],g=e[3];else return;else m=e||0,f=e||0,k=g||0,g=g||0;this.moveTo(a+m,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+m,b)}});f.compareObjects=function(a,b){for(var c in a)if(a[c]!=b[c])return!1;return!0};f.distance=J;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){ba[2]&&(a[2]=b);ca[3]&&(a[3]=c)};f.isInsideBounding=function(a,b){return a[0]< -b[0][0]||a[1]b[1][0]||a[1]>b[1][1]?!1:!0};f.overlapBounding=H;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 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};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&&ab.left&&cMath.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;da[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 h=0==d||d==c.length-1;!h&&(-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]=h?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,h=[0,0],k=1E6,l=-1,n=0;nk||q>b||(l=n,k=q)}return l};f.CurveEditor=G;f.getParameterNames=function(a){return(a+"").replace(/[/][/].*$/gm,"").replace(/\s+/g, -"").replace(/[/][*][^/*]*[*][/]/g,"").split("){",1)[0].replace(/^[^(]*[(]/,"").replace(/=[^,]+/g,"").split(",").filter(Boolean)};f.pointerListenerAdd=function(a,b,c,d){d=void 0===d?!1:d;if(a&&a.addEventListener&&b&&"function"===typeof c)switch(b){case "down":case "up":case "move":case "over":case "out":case "enter":a.addEventListener(f.pointerevents_method+b,c,d);case "leave":case "cancel":case "gotpointercapture":case "lostpointercapture":if("mouse"!=f.pointerevents_method)return a.addEventListener(f.pointerevents_method+ -b,c,d);default:return a.addEventListener(b,c,d)}else console.log("cant pointerListenerAdd "+a+", "+b+", "+c)};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":a.removeEventListener(f.pointerevents_method+b,c,d);case "leave":case "cancel":case "gotpointercapture":case "lostpointercapture":if("mouse"!=f.pointerevents_method)return a.removeEventListener(f.pointerevents_method+ -b,c,d);default:return a.removeEventListener(b,c,d)}else console.log("cant pointerListenerRemove "+a+", "+b+", "+c)};Math.clamp=function(a,b,c){return b>a?b:c=this.viewport[0]&&d=this.viewport[1]&&eg.getTime()-this.last_mouseclick&&void 0!==a.isPrimary&&a.isPrimary;this.mouse[0]=a.clientX;this.mouse[1]=a.clientY;this.graph_mouse[0]=a.canvasX;this.graph_mouse[1]=a.canvasY;this.last_click_position=[this.mouse[0],this.mouse[1]];this.pointer_is_double=this.pointer_is_down&&void 0!==a.isPrimary&&!a.isPrimary?!0:!1;this.pointer_is_down=!0;this.canvas.focus();g.closeAllContextMenus(b); +if(!this.onMouse||1!=this.onMouse(a)){if(1!=a.which||this.pointer_is_double)if(2==a.which){if(g.middle_click_slot_add_default_node&&f&&this.allow_interaction&&!d&&!this.read_only&&!this.connecting_node&&!f.flags.collapsed&&!this.live_mode){e=d=h=!1;if(f.outputs)for(u=0,k=f.outputs.length;uf.size[0]-g.NODE_TITLE_HEIGHT&&0>k[1]&&(c=this,setTimeout(function(){c.openSubgraph(f.subgraph)},10)),this.live_mode&&(u=h=!0));u||(this.allow_dragnodes&&(this.graph.beforeChange(),this.node_dragged=f),this.selected_nodes[f.id]||this.processNodeSelected(f,a));this.dirty_canvas=!0}}else if(!d){if(!this.read_only)for(u= +0;uk[0]+4||a.canvasYk[1]+4)){this.showLinkMenu(h,a);this.over_link_center=null;break}this.selected_group=this.graph.getGroupOnPos(a.canvasX,a.canvasY);this.selected_group_resizing=!1;this.selected_group&&!this.read_only&&(a.ctrlKey&&(this.dragging_rectangle=null),10>H([a.canvasX,a.canvasY],[this.selected_group.pos[0]+this.selected_group.size[0],this.selected_group.pos[1]+this.selected_group.size[1]])* +this.ds.scale?this.selected_group_resizing=!0:this.selected_group.recomputeInsideNodes());e&&!this.read_only&&this.allow_searchbox&&(this.showSearchBox(a),a.preventDefault(),a.stopPropagation());h=!0}!d&&h&&this.allow_dragcanvas&&(this.dragging_canvas=!0)}this.last_mouse[0]=a.clientX;this.last_mouse[1]=a.clientY;this.last_mouseclick=g.getTime();this.last_mouse_dragging=!0;this.graph.change();(!b.document.activeElement||"input"!=b.document.activeElement.nodeName.toLowerCase()&&"textarea"!=b.document.activeElement.nodeName.toLowerCase())&& +a.preventDefault();a.stopPropagation();if(this.onMouseDown)this.onMouseDown(a);return!1}}}};m.prototype.processMouseMove=function(a){this.autoresize&&this.resize();this.set_canvas_dirty_on_mouse_event&&(this.dirty_canvas=!0);if(this.graph){m.active_canvas=this;this.adjustMouseEvent(a);var b=[a.clientX,a.clientY];this.mouse[0]=b[0];this.mouse[1]=b[1];var c=[b[0]-this.last_mouse[0],b[1]-this.last_mouse[1]];this.last_mouse=b;this.graph_mouse[0]=a.canvasX;this.graph_mouse[1]=a.canvasY;if(this.block_click)return a.preventDefault(), +!1;a.dragging=this.last_mouse_dragging;this.node_widget&&(this.processNodeWidgets(this.node_widget[0],this.graph_mouse,a,this.node_widget[1]),this.dirty_canvas=!0);if(this.dragging_rectangle)this.dragging_rectangle[2]=a.canvasX-this.dragging_rectangle[0],this.dragging_rectangle[3]=a.canvasY-this.dragging_rectangle[1],this.dirty_canvas=!0;else if(this.selected_group&&!this.read_only)this.selected_group_resizing?this.selected_group.size=[a.canvasX-this.selected_group.pos[0],a.canvasY-this.selected_group.pos[1]]: +(this.selected_group.move(c[0]/this.ds.scale,c[1]/this.ds.scale,a.ctrlKey),this.selected_group._nodes.length&&(this.dirty_canvas=!0)),this.dirty_bgcanvas=!0;else if(this.dragging_canvas)this.ds.offset[0]+=c[0]/this.ds.scale,this.ds.offset[1]+=c[1]/this.ds.scale,this.dirty_bgcanvas=this.dirty_canvas=!0;else if(this.allow_interaction&&!this.read_only){this.connecting_node&&(this.dirty_canvas=!0);var d=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes);b=0;for(var e=this.graph._nodes.length;b< +e;++b)if(this.graph._nodes[b].mouseOver&&d!=this.graph._nodes[b]){this.graph._nodes[b].mouseOver=!1;if(this.node_over&&this.node_over.onMouseLeave)this.node_over.onMouseLeave(a);this.node_over=null;this.dirty_canvas=!0}if(d){d.redraw_on_mouse&&(this.dirty_canvas=!0);if(!d.mouseOver&&(d.mouseOver=!0,this.node_over=d,this.dirty_canvas=!0,d.onMouseEnter))d.onMouseEnter(a);if(d.onMouseMove)d.onMouseMove(a,[a.canvasX-d.pos[0],a.canvasY-d.pos[1]],this);if(this.connecting_node)if(this.connecting_output){if(e= +this._highlight_input||[0,0],!this.isOverNodeBox(d,a.canvasX,a.canvasY)){var f=this.isOverNodeInput(d,a.canvasX,a.canvasY,e);if(-1!=f&&d.inputs[f]){var h=d.inputs[f].type;g.isValidConnection(this.connecting_output.type,h)&&(this._highlight_input=e,this._highlight_input_slot=d.inputs[f])}else this._highlight_input_slot=this._highlight_input=null}}else this.connecting_input&&(e=this._highlight_output||[0,0],this.isOverNodeBox(d,a.canvasX,a.canvasY)||(f=this.isOverNodeOutput(d,a.canvasX,a.canvasY,e), +-1!=f&&d.outputs[f]?(h=d.outputs[f].type,g.isValidConnection(this.connecting_input.type,h)&&(this._highlight_output=e)):this._highlight_output=null));this.canvas&&(C(a.canvasX,a.canvasY,d.pos[0]+d.size[0]-5,d.pos[1]+d.size[1]-5,5,5)?this.canvas.style.cursor="se-resize":this.canvas.style.cursor="crosshair")}else{e=null;for(b=0;bh[0]+4||a.canvasYh[1]+4)){e=f;break}e!=this.over_link_center&& +(this.over_link_center=e,this.dirty_canvas=!0);this.canvas&&(this.canvas.style.cursor="")}if(this.node_capturing_input&&this.node_capturing_input!=d&&this.node_capturing_input.onMouseMove)this.node_capturing_input.onMouseMove(a,[a.canvasX-this.node_capturing_input.pos[0],a.canvasY-this.node_capturing_input.pos[1]],this);if(this.node_dragged&&!this.live_mode){for(b in this.selected_nodes)d=this.selected_nodes[b],d.pos[0]+=c[0]/this.ds.scale,d.pos[1]+=c[1]/this.ds.scale;this.dirty_bgcanvas=this.dirty_canvas= +!0}this.resizing_node&&!this.live_mode&&(c=[a.canvasX-this.resizing_node.pos[0],a.canvasY-this.resizing_node.pos[1]],b=this.resizing_node.computeSize(),c[0]=Math.max(b[0],c[0]),c[1]=Math.max(b[1],c[1]),this.resizing_node.setSize(c),this.canvas.style.cursor="se-resize",this.dirty_bgcanvas=this.dirty_canvas=!0)}a.preventDefault();return!1}};m.prototype.processMouseUp=function(a){if(void 0!==a.isPrimary&&!a.isPrimary)return!1;this.set_canvas_dirty_on_mouse_event&&(this.dirty_canvas=!0);if(this.graph){var b= +this.getCanvasWindow().document;m.active_canvas=this;this.options.skip_events||(g.pointerListenerRemove(b,"move",this._mousemove_callback,!0),g.pointerListenerAdd(this.canvas,"move",this._mousemove_callback,!0),g.pointerListenerRemove(b,"up",this._mouseup_callback,!0));this.adjustMouseEvent(a);b=g.getTime();a.click_time=b-this.last_mouseclick;this.last_mouse_dragging=!1;this.last_click_position=null;this.block_click&&(this.block_click=!1);if(1==a.which){this.node_widget&&this.processNodeWidgets(this.node_widget[0], +this.graph_mouse,a);this.node_widget=null;this.selected_group&&(this.selected_group.move(this.selected_group.pos[0]-Math.round(this.selected_group.pos[0]),this.selected_group.pos[1]-Math.round(this.selected_group.pos[1]),a.ctrlKey),this.selected_group.pos[0]=Math.round(this.selected_group.pos[0]),this.selected_group.pos[1]=Math.round(this.selected_group.pos[1]),this.selected_group._nodes.length&&(this.dirty_canvas=!0),this.selected_group=null);this.selected_group_resizing=!1;var c=this.graph.getNodeOnPos(a.canvasX, +a.canvasY,this.visible_nodes);if(this.dragging_rectangle){if(this.graph){b=this.graph._nodes;var d=new Float32Array(4),e=Math.abs(this.dragging_rectangle[2]),f=Math.abs(this.dragging_rectangle[3]),h=0>this.dragging_rectangle[3]?this.dragging_rectangle[1]-f:this.dragging_rectangle[1];this.dragging_rectangle[0]=0>this.dragging_rectangle[2]?this.dragging_rectangle[0]-e:this.dragging_rectangle[0];this.dragging_rectangle[1]=h;this.dragging_rectangle[2]=e;this.dragging_rectangle[3]=f;if(!c||10a.click_time&&C(a.canvasX,a.canvasY,c.pos[0],c.pos[1]-g.NODE_TITLE_HEIGHT,g.NODE_TITLE_HEIGHT,g.NODE_TITLE_HEIGHT)&&c.collapse();this.dirty_bgcanvas=this.dirty_canvas=!0;this.node_dragged.pos[0]=Math.round(this.node_dragged.pos[0]);this.node_dragged.pos[1]=Math.round(this.node_dragged.pos[1]);(this.graph.config.align_to_grid||this.align_to_grid)&&this.node_dragged.alignToGrid();if(this.onNodeMoved)this.onNodeMoved(this.node_dragged); +this.graph.afterChange(this.node_dragged);this.node_dragged=null}else{c=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes);!c&&300>a.click_time&&this.deselectAllNodes();this.dirty_canvas=!0;this.dragging_canvas=!1;if(this.node_over&&this.node_over.onMouseUp)this.node_over.onMouseUp(a,[a.canvasX-this.node_over.pos[0],a.canvasY-this.node_over.pos[1]],this);if(this.node_capturing_input&&this.node_capturing_input.onMouseUp)this.node_capturing_input.onMouseUp(a,[a.canvasX-this.node_capturing_input.pos[0], +a.canvasY-this.node_capturing_input.pos[1]])}}else 2==a.which?(this.dirty_canvas=!0,this.dragging_canvas=!1):3==a.which&&(this.dirty_canvas=!0,this.dragging_canvas=!1);void 0!==a.isPrimary&&a.isPrimary&&(this.pointer_is_double=this.pointer_is_down=!1);this.graph.change();a.stopPropagation();a.preventDefault();return!1}};m.prototype.processMouseWheel=function(a){if(this.graph&&this.allow_dragcanvas){var b=null!=a.wheelDeltaY?a.wheelDeltaY:-60*a.detail;this.adjustMouseEvent(a);var c=a.clientX,d=a.clientY; +if(!this.viewport||this.viewport&&c>=this.viewport[0]&&c=this.viewport[1]&&db&&(c*=1/1.1),this.ds.changeScale(c,[a.clientX,a.clientY]),this.graph.change(),a.preventDefault(),!1}};m.prototype.isOverNodeBox=function(a,b,c){var d=g.NODE_TITLE_HEIGHT;return C(b,c,a.pos[0]+2,a.pos[1]+2-d,d-4,d-4)?!0:!1};m.prototype.isOverNodeInput=function(a,b,c,d){if(a.inputs)for(var e=0,f=a.inputs.length;ea.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=this.viewport[0]&&b=this.viewport[1]&&cc-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.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&&.5this.ds.scale;if(this.live_mode){if(!a.flags.collapsed&&(b.shadowColor= +"transparent",a.onDrawForeground))a.onDrawForeground(b,this,this.canvas)}else{var f=this.editor_alpha;b.globalAlpha=f;this.render_shadows&&!e?(b.shadowColor=g.DEFAULT_SHADOW_COLOR,b.shadowOffsetX=2*this.ds.scale,b.shadowOffsetY=2*this.ds.scale,b.shadowBlur=3*this.ds.scale):b.shadowColor="transparent";if(!a.flags.collapsed||!a.onDrawCollapsed||1!=a.onDrawCollapsed(b,this)){var h=a._shape||g.BOX_SHAPE;B.set(a.size);var k=a.horizontal;if(a.flags.collapsed){b.font=this.inner_text_font;var n=a.getTitle? +a.getTitle():a.title;null!=n&&(a._collapsed_width=Math.min(a.size[0],b.measureText(n).width+2*g.NODE_TITLE_HEIGHT),B[0]=a._collapsed_width,B[1]=0)}a.clip_area&&(b.save(),b.beginPath(),h==g.BOX_SHAPE?b.rect(0,0,B[0],B[1]):h==g.ROUND_SHAPE?b.roundRect(0,0,B[0],B[1],[10]):h==g.CIRCLE_SHAPE&&b.arc(.5*B[0],.5*B[1],.5*B[0],0,2*Math.PI),b.clip());a.has_errors&&(d="red");this.drawNodeShape(a,b,B,c,d,a.is_selected,a.mouseOver);b.shadowColor="transparent";if(a.onDrawForeground)a.onDrawForeground(b,this,this.canvas); +b.textAlign=k?"center":"left";b.font=this.inner_text_font;d=!e;var q=this.connecting_output;h=this.connecting_input;b.lineWidth=1;n=0;var u=new Float32Array(2);if(!a.flags.collapsed){if(a.inputs)for(c=0;cthis.ds.scale,n=a._shape||a.constructor.shape||g.ROUND_SHAPE,q=a.constructor.title_mode,u=!0;q==g.TRANSPARENT_TITLE||q==g.NO_TITLE?u=!1:q==g.AUTOHIDE_TITLE&&h&&(u=!0);y[0]=0;y[1]=u?-e:0;y[2]=c[0]+1;y[3]=u?c[1]+e:c[1];h=b.globalAlpha;b.beginPath(); +n==g.BOX_SHAPE||k?b.fillRect(y[0],y[1],y[2],y[3]):n==g.ROUND_SHAPE||n==g.CARD_SHAPE?b.roundRect(y[0],y[1],y[2],y[3],n==g.CARD_SHAPE?[this.round_radius,this.round_radius,0,0]:[this.round_radius]):n==g.CIRCLE_SHAPE&&b.arc(.5*c[0],.5*c[1],.5*c[0],0,2*Math.PI);b.fill();!a.flags.collapsed&&u&&(b.shadowColor="transparent",b.fillStyle="rgba(0,0,0,0.2)",b.fillRect(0,-1,y[2],2));b.shadowColor="transparent";if(a.onDrawBackground)a.onDrawBackground(b,this,this.canvas,this.graph_mouse);if(u||q==g.TRANSPARENT_TITLE){if(a.onDrawTitleBar)a.onDrawTitleBar(b, +e,c,this.ds.scale,d);else if(q!=g.TRANSPARENT_TITLE&&(a.constructor.title_color||this.render_title_colored)){u=a.constructor.title_color||d;a.flags.collapsed&&(b.shadowColor=g.DEFAULT_SHADOW_COLOR);if(this.use_gradients){var r=m.gradients[u];r||(r=m.gradients[u]=b.createLinearGradient(0,0,400,0),r.addColorStop(0,u),r.addColorStop(1,"#000"));b.fillStyle=r}else b.fillStyle=u;b.beginPath();n==g.BOX_SHAPE||k?b.rect(0,-e,c[0]+1,e):(n==g.ROUND_SHAPE||n==g.CARD_SHAPE)&&b.roundRect(0,-e,c[0]+1,e,a.flags.collapsed? +[this.round_radius]:[this.round_radius,this.round_radius,0,0]);b.fill();b.shadowColor="transparent"}u=!1;g.node_box_coloured_by_mode&&g.NODE_MODES_COLORS[a.mode]&&(u=g.NODE_MODES_COLORS[a.mode]);g.node_box_coloured_when_on&&(u=a.action_triggered?"#FFF":a.execute_triggered?"#AAA":u);if(a.onDrawTitleBox)a.onDrawTitleBox(b,e,c,this.ds.scale);else n==g.ROUND_SHAPE||n==g.CIRCLE_SHAPE||n==g.CARD_SHAPE?(k&&(b.fillStyle="black",b.beginPath(),b.arc(.5*e,-.5*e,6,0,2*Math.PI),b.fill()),b.fillStyle=a.boxcolor|| +u||g.NODE_DEFAULT_BOXCOLOR,k?b.fillRect(.5*e-5,-.5*e-5,10,10):(b.beginPath(),b.arc(.5*e,-.5*e,5,0,2*Math.PI),b.fill())):(k&&(b.fillStyle="black",b.fillRect(.5*(e-10)-1,-.5*(e+10)-1,12,12)),b.fillStyle=a.boxcolor||u||g.NODE_DEFAULT_BOXCOLOR,b.fillRect(.5*(e-10),-.5*(e+10),10,10));b.globalAlpha=h;if(a.onDrawTitleText)a.onDrawTitleText(b,e,c,this.ds.scale,this.title_text_font,f);!k&&(b.font=this.title_text_font,h=String(a.getTitle()))&&(b.fillStyle=f?g.NODE_SELECTED_TITLE_COLOR:a.constructor.title_text_color|| +this.node_title_color,a.flags.collapsed?(b.textAlign="left",b.measureText(h),b.fillText(h.substr(0,20),e,g.NODE_TITLE_TEXT_Y-e),b.textAlign="left"):(b.textAlign="left",b.fillText(h,e,g.NODE_TITLE_TEXT_Y-e)));a.flags.collapsed||!a.subgraph||a.skip_subgraph_button||(h=g.NODE_TITLE_HEIGHT,u=a.size[0]-h,r=g.isInsideRectangle(this.graph_mouse[0]-a.pos[0],this.graph_mouse[1]-a.pos[1],u+2,-h+2,h-4,h-4),b.fillStyle=r?"#888":"#555",n==g.BOX_SHAPE||k?b.fillRect(u+2,-h+2,h-4,h-4):(b.beginPath(),b.roundRect(u+ +2,-h+2,h-4,h-4,[4]),b.fill()),b.fillStyle="#333",b.beginPath(),b.moveTo(u+.2*h,.6*-h),b.lineTo(u+.8*h,.6*-h),b.lineTo(u+.5*h,.3*-h),b.fill());if(a.onDrawTitle)a.onDrawTitle(b)}if(f){if(a.onBounding)a.onBounding(y);q==g.TRANSPARENT_TITLE&&(y[1]-=e,y[3]+=e);b.lineWidth=1;b.globalAlpha=.8;b.beginPath();n==g.BOX_SHAPE?b.rect(-6+y[0],-6+y[1],12+y[2],12+y[3]):n==g.ROUND_SHAPE||n==g.CARD_SHAPE&&a.flags.collapsed?b.roundRect(-6+y[0],-6+y[1],12+y[2],12+y[3],[2*this.round_radius]):n==g.CARD_SHAPE?b.roundRect(-6+ +y[0],-6+y[1],12+y[2],12+y[3],[2*this.round_radius,2,2*this.round_radius,2]):n==g.CIRCLE_SHAPE&&b.arc(.5*c[0],.5*c[1],.5*c[0]+6,0,2*Math.PI);b.strokeStyle=g.NODE_BOX_OUTLINE_COLOR;b.stroke();b.strokeStyle=d;b.globalAlpha=1}0A[2]&&(A[0]+=A[2],A[2]=Math.abs(A[2]));0>A[3]&&(A[1]+=A[3],A[3]=Math.abs(A[3]));if(F(A,G)){var m=n.outputs[q];q=f.inputs[h];if(m&&q&&(n=m.dir||(n.horizontal?g.DOWN:g.RIGHT),q=q.dir||(f.horizontal?g.UP:g.LEFT),this.renderLink(a,u,r,k,!1,0,null,n,q),k&&k._last_time&&1E3>b-k._last_time)){m=2-.002*(b-k._last_time);var l=a.globalAlpha;a.globalAlpha=l*m;this.renderLink(a,u,r,k,!0,m,"white",n,q);a.globalAlpha=l}}}}}}a.globalAlpha=1};m.prototype.renderLink= +function(a,b,c,d,e,f,h,k,n,q){d&&this.visible_links.push(d);!h&&d&&(h=d.color||m.link_type_colors[d.type]);h||(h=this.default_link_color);null!=d&&this.highlighted_links[d.id]&&(h="#FFF");k=k||g.RIGHT;n=n||g.LEFT;var u=H(b,c);this.render_connections_border&&.6b[1]? +0:Math.PI,a.save(),a.translate(r[0],r[1]),a.rotate(u),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore(),a.save(),a.translate(d[0],d[1]),a.rotate(q),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore()),a.beginPath(),a.arc(e[0],e[1],5,0,2*Math.PI),a.fill());if(f)for(a.fillStyle=h,r=0;5>r;++r)f=(.001*g.getTime()+.2*r)%1,e=this.computeConnectionPoint(b,c,f,k,n),a.beginPath(),a.arc(e[0],e[1],5,0,2*Math.PI),a.fill()};m.prototype.computeConnectionPoint= +function(a,b,c,d,e){d=d||g.RIGHT;e=e||g.LEFT;var f=H(a,b),h=[a[0],a[1]],k=[b[0],b[1]];switch(d){case g.LEFT:h[0]+=-.25*f;break;case g.RIGHT:h[0]+=.25*f;break;case g.UP:h[1]+=-.25*f;break;case g.DOWN:h[1]+=.25*f}switch(e){case g.LEFT:k[0]+=-.25*f;break;case g.RIGHT:k[0]+=.25*f;break;case g.UP:k[1]+=-.25*f;break;case g.DOWN:k[1]+=.25*f}d=(1-c)*(1-c)*(1-c);e=3*(1-c)*(1-c)*c;f=3*(1-c)*c*c;c*=c*c;return[d*a[0]+e*h[0]+f*k[0]+c*b[0],d*a[1]+e*h[1]+f*k[1]+c*b[1]]};m.prototype.drawExecutionOrder=function(a){a.shadowColor= +"transparent";a.globalAlpha=.25;a.textAlign="center";a.strokeStyle="white";a.globalAlpha=.75;for(var b=this.visible_nodes,c=0;cf||f>l-12||hr.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.valuer.options.max&&(r.value=r.options.max); +else if(c.type==g.pointerevents_method+"down"){var t=r.options.values;t&&t.constructor===Function&&(t=r.options.values(r,a));var p=null;"number"!=r.type&&(p=t.constructor===Array?t:Object.keys(t));f=40>f?-1:f>l-40?1:0;if("number"==r.type)r.value+=.1*f*(r.options.step||1),null!=r.options.min&&r.valuer.options.max&&(r.value=r.options.max);else if(f)q=-1,this.last_mouseclick=0,q=t.constructor===Object?p.indexOf(String(r.value))+f:p.indexOf(r.value)+ +f,q>=p.length&&(q=p.length-1),0>q&&(q=0),r.value=t.constructor===Array?t[q]:q;else{var v=t!=p?Object.values(t):t;new g.ContextMenu(v,{scale:Math.max(1,this.ds.scale),event:c,className:"dark",callback:function(a,b,c){t!=p&&(a=v.indexOf(a));this.value=a;e(this,a);n.dirty_canvas=!0;return!1}.bind(r)},q)}}else c.type==g.pointerevents_method+"up"&&"number"==r.type&&(f=40>f?-1:f>l-40?1:0,200>c.click_time&&0==f&&this.prompt("Value",r.value,function(a){this.value=Number(a);e(this,this.value)}.bind(r),c)); +d!=r.value&&setTimeout(function(){e(this,this.value)}.bind(r),20);this.dirty_canvas=!0;break;case "toggle":c.type==g.pointerevents_method+"down"&&(r.value=!r.value,setTimeout(function(){e(r,r.value)},20));break;case "string":case "text":c.type==g.pointerevents_method+"down"&&this.prompt("Value",r.value,function(a){this.value=a;e(this,a)}.bind(r),c,r.options?r.options.multiline:!1);break;default:r.mouse&&(this.dirty_canvas=r.mouse(c,[f,h],a))}if(d!=r.value){if(a.onWidgetChanged)a.onWidgetChanged(r.name, +r.value,d,r);a.graph._version++}return r}}}return null};m.prototype.drawGroups=function(a,b){if(this.graph){a=this.graph._groups;b.save();b.globalAlpha=.5*this.editor_alpha;for(var c=0;cc&&.01>b.editor_alpha&&(clearInterval(d),1>c&&(b.live_mode=!0));1"+(n.label?n.label:k)+""+a+"",value:k})}if(h.length)return new g.ContextMenu(h,{event:c,callback:function(a,b,c,d){e&&(b=this.getBoundingClientRect(),f.showEditPropertyValue(e,a.value,{position:[b.left,b.top]}))},parentMenu:d,allow_html:!0,node:e},b),!1}};m.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};m.onMenuResizeNode=function(a,b,c,d,e){if(e){a= +function(a){a.size=a.computeSize();if(a.onResize)a.onResize(a.size)};b=m.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)a(e);else for(var f in b.selected_nodes)a(b.selected_nodes[f]);e.setDirtyCanvas(!0,!0)}};m.prototype.showLinkMenu=function(a,b){var c=this,d=c.graph.getNodeById(a.origin_id),e=c.graph.getNodeById(a.target_id),f=!1;d&&d.outputs&&d.outputs[a.origin_slot]&&(f=d.outputs[a.origin_slot].type);var h=!1;e&&e.outputs&&e.outputs[a.target_slot]&&(h=e.inputs[a.target_slot].type); +var k=new g.ContextMenu(["Add Node",null,"Delete",null],{event:b,title:null!=a.data?a.data.constructor.name:null,callback:function(b,g,u){switch(b){case "Add Node":m.onMenuAdd(null,null,u,k,function(b){b.inputs&&b.inputs.length&&b.outputs&&b.outputs.length&&d.connectByType(a.origin_slot,b,f)&&(b.connectByType(a.target_slot,e,h),b.pos[0]-=.5*b.size[0])});break;case "Delete":c.graph.removeLink(a.id)}}});return!1};m.prototype.createDefaultNodeForSlot=function(a){a=a||{};a=Object.assign({nodeFrom:null, +slotFrom:null,nodeTo:null,slotTo:null,position:[],nodeType:null,posAdd:[0,0],posSizeFix:[0,0]},a);var b=a.nodeFrom&&null!==a.slotFrom,c=!b&&a.nodeTo&&null!==a.slotTo;if(!b&&!c)return console.warn("No data passed to createDefaultNodeForSlot "+a.nodeFrom+" "+a.slotFrom+" "+a.nodeTo+" "+a.slotTo),!1;if(!a.nodeType)return console.warn("No type to createDefaultNodeForSlot"),!1;var d=b?a.nodeFrom:a.nodeTo,e=b?a.slotFrom:a.slotTo;switch(typeof e){case "string":c=b?d.findOutputSlot(e,!1):d.findInputSlot(e, +!1);e=b?d.outputs[e]:d.inputs[e];break;case "object":c=b?d.findOutputSlot(e.name):d.findInputSlot(e.name);break;case "number":c=e;e=b?d.outputs[e]:d.inputs[e];break;default:return console.warn("Cant get slot information "+e),!1}!1!==e&&!1!==c||console.warn("createDefaultNodeForSlot bad slotX "+e+" "+c);d=e.type==g.EVENT?"_event_":e.type;if((e=b?g.slot_types_default_out:g.slot_types_default_in)&&e[d]){nodeNewType=!1;if("object"==typeof e[d]||"array"==typeof e[d])for(var f in e[d]){if(a.nodeType==e[d][f]|| +"AUTO"==a.nodeType){nodeNewType=e[d][f];break}}else if(a.nodeType==e[d]||"AUTO"==a.nodeType)nodeNewType=e[d];if(nodeNewType){f=!1;"object"==typeof nodeNewType&&nodeNewType.node&&(f=nodeNewType,nodeNewType=nodeNewType.node);if(e=g.createNode(nodeNewType)){if(f){if(f.properties)for(var h in f.properties)e.addProperty(h,f.properties[h]);if(f.inputs)for(h in e.inputs=[],f.inputs)e.addOutput(f.inputs[h][0],f.inputs[h][1]);if(f.outputs)for(h in e.outputs=[],f.outputs)e.addOutput(f.outputs[h][0],f.outputs[h][1]); +f.title&&(e.title=f.title);f.json&&e.configure(f.json)}this.graph.add(e);e.pos=[a.position[0]+a.posAdd[0]+(a.posSizeFix[0]?a.posSizeFix[0]*e.size[0]:0),a.position[1]+a.posAdd[1]+(a.posSizeFix[1]?a.posSizeFix[1]*e.size[1]:0)];b?a.nodeFrom.connectByType(c,e,d):a.nodeTo.connectByTypeOutput(c,e,d);return!0}console.log("failed creating "+nodeNewType)}}return!1};m.prototype.showConnectionMenu=function(a){a=a||{};var b=Object.assign({nodeFrom:null,slotFrom:null,nodeTo:null,slotTo:null,e:null},a),c=this, +d=b.nodeFrom&&b.slotFrom;a=!d&&b.nodeTo&&b.slotTo;if(!d&&!a)return console.warn("No data passed to showConnectionMenu"),!1;a=d?b.nodeFrom:b.nodeTo;var e=d?b.slotFrom:b.slotTo,f=!1;switch(typeof e){case "string":f=d?a.findOutputSlot(e,!1):a.findInputSlot(e,!1);e=d?a.outputs[e]:a.inputs[e];break;case "object":f=d?a.findOutputSlot(e.name):a.findInputSlot(e.name);break;case "number":f=e;e=d?a.outputs[e]:a.inputs[e];break;default:return console.warn("Cant get slot information "+e),!1}a=["Add Node",null]; +c.allow_searchbox&&(a.push("Search"),a.push(null));var h=e.type==g.EVENT?"_event_":e.type,k=d?g.slot_types_default_out:g.slot_types_default_in;if(k&&k[h])if("object"==typeof k[h]||"array"==typeof k[h])for(var n in k[h])a.push(k[h][n]);else a.push(k[h]);var q=new g.ContextMenu(a,{event:b.e,title:(e&&""!=e.name?e.name+(h?" | ":""):"")+(e&&h?h:""),callback:function(a,g,k){switch(a){case "Add Node":m.onMenuAdd(null,null,k,q,function(a){d?b.nodeFrom.connectByType(f,a,h):b.nodeTo.connectByTypeOutput(f, +a,h)});break;case "Search":d?c.showSearchBox(k,{node_from:b.nodeFrom,slot_from:e,type_filter_in:h}):c.showSearchBox(k,{node_to:b.nodeTo,slot_from:e,type_filter_out:h});break;default:c.createDefaultNodeForSlot(Object.assign(b,{position:[b.e.canvasX,b.e.canvasY],nodeType:a}))}}});return!1};m.onShowPropertyEditor=function(a,b,c,d,e){function f(){if(n){var b=n.value;"Number"==a.type?b=Number(b):"Boolean"==a.type&&(b=!!b);e[h]=b;k.parentNode&&k.parentNode.removeChild(k);e.setDirtyCanvas(!0,!0)}}var h= +a.property||"title";b=e[h];var k=document.createElement("div");k.is_modified=!1;k.className="graphdialog";k.innerHTML="";k.close=function(){k.parentNode&&k.parentNode.removeChild(k)};k.querySelector(".name").innerText=h;var n=k.querySelector(".value");n&&(n.value=b,n.addEventListener("blur",function(a){this.focus()}),n.addEventListener("keydown",function(a){k.is_modified=!0;if(27==a.keyCode)k.close();else if(13== +a.keyCode)f();else if(13!=a.keyCode&&"textarea"!=a.target.localName)return;a.preventDefault();a.stopPropagation()}));b=m.active_canvas.canvas;c=b.getBoundingClientRect();var q=d=-20;c&&(d-=c.left,q-=c.top);event?(k.style.left=event.clientX+d+"px",k.style.top=event.clientY+q+"px"):(k.style.left=.5*b.width+d+"px",k.style.top=.5*b.height+q+"px");k.querySelector("button").addEventListener("click",f);b.parentNode.appendChild(k);n&&n.focus();var l=null;k.addEventListener("mouseleave",function(a){g.dialog_close_on_mouse_leave&& +!k.is_modified&&g.dialog_close_on_mouse_leave&&(l=setTimeout(k.close,g.dialog_close_on_mouse_leave_delay))});k.addEventListener("mouseenter",function(a){g.dialog_close_on_mouse_leave&&l&&clearTimeout(l)})};m.prototype.prompt=function(a,b,c,d,e){var f=this;a=a||"";var h=document.createElement("div");h.is_modified=!1;h.className="graphdialog rounded";h.innerHTML=e?" ":" "; +h.close=function(){f.prompt_box=null;h.parentNode&&h.parentNode.removeChild(h)};e=m.active_canvas.canvas;e.parentNode.appendChild(h);1m.search_limit))break}}u= +null;if(Array.prototype.filter)u=Object.keys(g.registered_node_types).filter(d);else for(k in u=[],g.registered_node_types)d(k)&&u.push(k);for(k=0;km.search_limit);k++);if(b.show_general_after_typefiltered&&(l.value||r.value)){filtered_extra=[];for(k in g.registered_node_types)d(k,{inTypeOverride:l&&l.value?"*":!1,outTypeOverride:r&&r.value?"*":!1})&&filtered_extra.push(k);for(k=0;km.search_limit);k++);}if((l.value||r.value)&&0==t.childNodes.length&&b.show_general_if_none_on_typefilter){filtered_extra=[];for(k in g.registered_node_types)d(k,{skipFilter:!0})&&filtered_extra.push(k);for(k=0;km.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="Search ";b.do_type_filter&&(q.innerHTML+="", +q.innerHTML+="");q.innerHTML+="
";n.fullscreenElement?n.fullscreenElement.appendChild(q):(n.body.appendChild(q),n.body.style.overflow="hidden");if(b.do_type_filter)var l=q.querySelector(".slot_in_type_filter"),r=q.querySelector(".slot_out_type_filter");q.close=function(){f.search_box=null;n.body.focus();n.body.style.overflow="";setTimeout(function(){f.canvas.focus()},20);q.parentNode&&q.parentNode.removeChild(q)}; +1k.height-200&&(t.style.maxHeight=k.height-a.layerY-20+ +"px");z.focus();b.show_all_on_open&&e();return q};m.prototype.showEditPropertyValue=function(a,b,c){function d(){e(m.value)}function e(e){f&&f.values&&f.values.constructor===Object&&void 0!=f.values[e]&&(e=f.values[e]);"number"==typeof a.properties[b]&&(e=Number(e));if("array"==h||"object"==h)e=JSON.parse(e);a.properties[b]=e;a.graph&&a.graph._version++;if(a.onPropertyChanged)a.onPropertyChanged(b,e);if(c.onclose)c.onclose();l.close();a.setDirtyCanvas(!0,!0)}if(a&&void 0!==a.properties[b]){c=c||{}; +var f=a.getPropertyInfo(b),h=f.type,g="";if("string"==h||"number"==h||"array"==h||"object"==h)g="";else if("enum"!=h&&"combo"!=h||!f.values)if("boolean"==h||"toggle"==h)g="";else{console.warn("unknown type: "+h);return}else{g=""}var l=this.createDialog(""+(f.label?f.label:b)+""+g+"",c),m=!1;if("enum"!=h&&"combo"!=h||!f.values)if("boolean"==h||"toggle"==h)(m=l.querySelector("input"))&&m.addEventListener("click",function(a){l.modified();e(!!m.checked)});else{if(m=l.querySelector("input"))m.addEventListener("blur",function(a){this.focus()}),q=void 0!==a.properties[b]?a.properties[b]:"","string"!==h&&(q= +JSON.stringify(q)),m.value=q,m.addEventListener("keydown",function(a){if(27==a.keyCode)l.close();else if(13==a.keyCode)d();else if(13!=a.keyCode){l.modified();return}a.preventDefault();a.stopPropagation()})}else m=l.querySelector("select"),m.addEventListener("change",function(a){l.modified();e(a.target.value)});m&&m.focus();l.querySelector("button").addEventListener("click",d);return l}};m.prototype.createDialog=function(a,b){def_options={checkForInput:!1,closeOnLeave:!0,closeOnLeave_checkModified:!0}; +b=Object.assign(def_options,b||{});var c=document.createElement("div");c.className="graphdialog";c.innerHTML=a;c.is_modified=!1;a=this.canvas.getBoundingClientRect();var d=-20,e=-20;a&&(d-=a.left,e-=a.top);b.position?(d+=b.position[0],e+=b.position[1]):b.event?(d+=b.event.clientX,e+=b.event.clientY):(d+=.5*this.canvas.width,e+=.5*this.canvas.height);c.style.left=d+"px";c.style.top=e+"px";this.canvas.parentNode.appendChild(c);b.checkForInput&&(a=[],(a=c.querySelectorAll("input"))&&a.forEach(function(a){a.addEventListener("keydown", +function(a){c.modified();if(27==a.keyCode)c.close();else if(13!=a.keyCode)return;a.preventDefault();a.stopPropagation()});a.focus()}));c.modified=function(){c.is_modified=!0};c.close=function(){c.parentNode&&c.parentNode.removeChild(c)};var f=null,h=!1;c.addEventListener("mouseleave",function(a){h||(b.closeOnLeave||g.dialog_close_on_mouse_leave)&&!c.is_modified&&g.dialog_close_on_mouse_leave&&(f=setTimeout(c.close,g.dialog_close_on_mouse_leave_delay))});c.addEventListener("mouseenter",function(a){(b.closeOnLeave|| +g.dialog_close_on_mouse_leave)&&f&&clearTimeout(f)});(a=c.querySelectorAll("select"))&&a.forEach(function(a){a.addEventListener("click",function(a){h++});a.addEventListener("blur",function(a){h=0});a.addEventListener("change",function(a){h=-1})});return c};m.prototype.createPanel=function(a,b){b=b||{};var c=b.window||window,d=document.createElement("div");d.className="litegraph dialog";d.innerHTML="
"; +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="";l.querySelector(".property_name").innerText=k.label||b;var p=l.querySelector(".property_value");p.innerText=f;l.dataset.property= +b;l.dataset.type=k.type||a;l.options=k;l.value=h;if("code"==a)l.addEventListener("click",function(a){d.inner_showCodePad(this.dataset.property)});else if("boolean"==a)l.classList.add("boolean"),h&&l.classList.add("bool-on"),l.addEventListener("click",function(){var a=this.dataset.property;this.value=!this.value;this.classList.toggle("bool-on");this.querySelector(".property_value").innerText=this.value?"true":"false";e(a,this.value)});else if("string"==a||"number"==a)p.setAttribute("contenteditable", +!0),p.addEventListener("keydown",function(b){"Enter"!=b.code||"string"==a&&b.shiftKey||(b.preventDefault(),this.blur())}),p.addEventListener("blur",function(){var a=this.innerText,b=this.parentNode.dataset.property;"number"==this.parentNode.dataset.type&&(a=Number(a));e(b,a)});else if("enum"==a||"combo"==a)f=m.getPropertyPrintableValue(h,k.values),p.innerText=f,p.addEventListener("click",function(a){var b=this.parentNode.dataset.property,d=this;new g.ContextMenu(k.values||[],{event:a,className:"dark", +callback:function(a,c,f){d.innerText=a;e(b,a);return!1}},c)});d.content.appendChild(l);return l};if(d.onOpen&&"function"==typeof d.onOpen)d.onOpen();return d};m.getPropertyPrintableValue=function(a,b){if(!b||b.constructor===Array)return String(a);if(b.constructor===Object){var c="",d;for(d in b)if(b[d]==a){c=d;break}return String(a)+" ("+c+")"}};m.prototype.closePanels=function(){var a=document.querySelector("#node-panel");a&&a.close();(a=document.querySelector("#option-panel"))&&a.close()};m.prototype.showShowGraphOptionsPanel= +function(a,b,c,d){if(this.constructor&&"HTMLDivElement"==this.constructor.name){if(!(b&&b.event&&b.event.target&&b.event.target.lgraphcanvas)){console.warn("Canvas not found");return}var e=b.event.target.lgraphcanvas}else e=this;e.closePanels();a=e.getCanvasWindow();panel=e.createPanel("Options",{closable:!0,window:a,onOpen:function(){e.OPTIONPANEL_IS_OPEN=!0},onClose:function(){e.OPTIONPANEL_IS_OPEN=!1;e.options_panel=null}});e.options_panel=panel;panel.id="option-panel";panel.classList.add("settings"); +(function(){panel.content.innerHTML="";var a=function(a,b,c){c&&c.key&&(a=c.key);c.values&&(b=Object.values(c.values).indexOf(b));e[a]=b},b=g.availableCanvasOptions;b.sort();for(pI in b){var c=b[pI];panel.addWidget("boolean",c,e[c],{key:c,on:"True",off:"False"},a)}panel.addWidget("combo","Render mode",g.LINK_RENDER_MODES[e.links_render_mode],{key:"links_render_mode",values:g.LINK_RENDER_MODES},a);panel.addSeparator();panel.footer.innerHTML=""})();e.canvas.parentNode.appendChild(panel)};m.prototype.showShowNodePanel= +function(a){function b(){panel.content.innerHTML="";panel.addHTML(""+a.type+""+(a.constructor.desc||"")+"");panel.addHTML("

Properties

");var b=function(b,c){d.graph.beforeChange(a);switch(b){case "Title":a.title=c;break;case "Mode":b=Object.values(g.NODE_MODES).indexOf(c);0<=b&&g.NODE_MODES[b]?a.changeMode(b):console.warn("unexpected mode: "+c);break;case "Color":m.node_colors[c]?(a.color=m.node_colors[c].color, +a.bgcolor=m.node_colors[c].bgcolor):console.warn("unexpected color: "+c);break;default:a.setProperty(b,c)}d.graph.afterChange();d.dirty_canvas=!0};panel.addWidget("string","Title",a.title,{},b);panel.addWidget("combo","Mode",g.NODE_MODES[a.mode],{values:g.NODE_MODES},b);var c="";void 0!==a.color&&(c=Object.keys(m.node_colors).filter(function(b){return m.node_colors[b].color==a.color}));panel.addWidget("combo","Color",c,{values:Object.keys(m.node_colors)},b);for(var h in a.properties){c=a.properties[h]; +var k=a.getPropertyInfo(h);a.onAddPropertyToPanel&&a.onAddPropertyToPanel(h,panel)||panel.addWidget(k.widget||k.type,h,c,k,b)}panel.addSeparator();if(a.onShowCustomPanelInfo)a.onShowCustomPanelInfo(panel);panel.footer.innerHTML="";panel.addButton("Delete",function(){a.block_delete||(a.graph.remove(a),panel.close())}).classList.add("delete")}this.SELECTED_NODE=a;this.closePanels();var c=this.getCanvasWindow(),d=this;panel=this.createPanel(a.title||"",{closable:!0,window:c,onOpen:function(){d.NODEPANEL_IS_OPEN= +!0},onClose:function(){d.NODEPANEL_IS_OPEN=!1;d.node_panel=null}});d.node_panel=panel;panel.id="node-panel";panel.node=a;panel.classList.add("settings");panel.inner_showCodePad=function(c){panel.classList.remove("settings");panel.classList.add("centered");panel.alt_content.innerHTML="";var e=panel.alt_content.querySelector("textarea"),d=function(){panel.toggleAltContent(!1);panel.toggleFooterVisibility(!0);e.parentNode.removeChild(e);panel.classList.add("settings"); +panel.classList.remove("centered");b()};e.value=a.properties[c];e.addEventListener("keydown",function(b){"Enter"==b.code&&b.ctrlKey&&(a.setProperty(c,e.value),d())});panel.toggleAltContent(!0);panel.toggleFooterVisibility(!1);e.style.height="calc(100% - 40px)";var g=panel.addButton("Assign",function(){a.setProperty(c,e.value);d()});panel.alt_content.appendChild(g);g=panel.addButton("Close",d);g.style.float="right";panel.alt_content.appendChild(g)};b();this.canvas.parentNode.appendChild(panel)};m.prototype.showSubgraphPropertiesDialog= +function(a){function b(){d.clear();if(a.inputs)for(var c=0;c","subgraph_property");g.dataset.name=f.name;g.dataset.slot=c;g.querySelector(".name").innerText=f.name;g.querySelector(".type").innerText=f.type;g.querySelector("button").addEventListener("click",function(c){a.removeInput(Number(this.parentNode.dataset.slot)); +b()})}}}console.log("showing subgraph properties dialog");var c=this.canvas.parentNode.querySelector(".subgraph_dialog");c&&c.close();var d=this.createPanel("Subgraph Inputs",{closable:!0,width:500});d.node=a;d.classList.add("subgraph_dialog");d.addHTML(" + NameType","subgraph_property extra",!0).querySelector("button").addEventListener("click",function(c){c=this.parentNode;var e= +c.querySelector(".name").value,d=c.querySelector(".type").value;e&&-1==a.findInputSlot(e)&&(a.addInput(e,d),c.querySelector(".name").value="",c.querySelector(".type").value="",b())});b();this.canvas.parentNode.appendChild(d);return d};m.prototype.showSubgraphPropertiesDialogRight=function(a){function b(){e.clear();if(a.outputs)for(var c=0;c", +"subgraph_property");g.dataset.name=d.name;g.dataset.slot=c;g.querySelector(".name").innerText=d.name;g.querySelector(".type").innerText=d.type;g.querySelector("button").addEventListener("click",function(c){a.removeOutput(Number(this.parentNode.dataset.slot));b()})}}}function c(){var c=this.parentNode,e=c.querySelector(".name").value,d=c.querySelector(".type").value;e&&-1==a.findOutputSlot(e)&&(a.addOutput(e,d),c.querySelector(".name").value="",c.querySelector(".type").value="",b())}var d=this.canvas.parentNode.querySelector(".subgraph_dialog"); +d&&d.close();var e=this.createPanel("Subgraph Outputs",{closable:!0,width:500});e.node=a;e.classList.add("subgraph_dialog");d=e.addHTML(" + NameType","subgraph_property extra",!0);d.querySelector(".name").addEventListener("keydown",function(a){13==a.keyCode&&c.apply(this)});d.querySelector("button").addEventListener("click",function(a){c.apply(this)});b();this.canvas.parentNode.appendChild(e); +return e};m.prototype.checkPanels=function(){if(this.canvas)for(var a=this.canvas.parentNode.querySelectorAll(".litegraph.dialog"),b=0;b=Object.keys(a.selected_nodes).length)e.collapse();else for(var f in a.selected_nodes)a.selected_nodes[f].collapse();e.graph.afterChange()};m.onMenuNodePin=function(a,b,c,d,e){e.pin()}; +m.onMenuNodeMode=function(a,b,c,d,e){new g.ContextMenu(g.NODE_MODES,{event:c,callback:function(a){if(e){var b=Object.values(g.NODE_MODES).indexOf(a),c=function(c){0<=b&&g.NODE_MODES[b]?c.changeMode(b):(console.warn("unexpected mode: "+a),c.changeMode(g.ALWAYS))},d=m.active_canvas;if(!d.selected_nodes||1>=Object.keys(d.selected_nodes).length)c(e);else for(var f in d.selected_nodes)c(d.selected_nodes[f])}},parentMenu:d,node:e});return!1};m.onMenuNodeColors=function(a,b,c,d,e){if(!e)throw"no node for color"; +b=[];b.push({value:null,content:"No color"});for(var f in m.node_colors)a=m.node_colors[f],a={value:f,content:""+f+""},b.push(a);new g.ContextMenu(b,{event:c,callback:function(a){if(e){var b=a.value?m.node_colors[a.value]:null;a=function(a){b?a.constructor===g.LGraphGroup?a.color=b.groupcolor:(a.color=b.color, +a.bgcolor=b.bgcolor):(delete a.color,delete a.bgcolor)};var c=m.active_canvas;if(!c.selected_nodes||1>=Object.keys(c.selected_nodes).length)a(e);else for(var d in c.selected_nodes)a(c.selected_nodes[d]);e.setDirtyCanvas(!0,!0)}},parentMenu:d,node:e});return!1};m.onMenuNodeShapes=function(a,b,c,d,e){if(!e)throw"no node passed";new g.ContextMenu(g.VALID_SHAPES,{event:c,callback:function(a){if(e){e.graph.beforeChange();var b=m.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)e.shape= +a;else for(var c in b.selected_nodes)b.selected_nodes[c].shape=a;e.graph.afterChange();e.setDirtyCanvas(!0)}},parentMenu:d,node:e});return!1};m.onMenuNodeRemove=function(a,b,c,d,e){if(!e)throw"no node passed";a=e.graph;a.beforeChange();b=m.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)!1!==e.removable&&a.remove(e);else for(var f in b.selected_nodes)c=b.selected_nodes[f],!1!==c.removable&&a.remove(c);a.afterChange();e.setDirtyCanvas(!0,!0)};m.onMenuNodeToSubgraph=function(a, +b,c,d,e){a=e.graph;if(b=m.active_canvas)c=Object.values(b.selected_nodes||{}),c.length||(c=[e]),d=g.createNode("graph/subgraph"),d.pos=e.pos.concat(),a.add(d),d.buildFromNodes(c),b.deselectAllNodes(),e.setDirtyCanvas(!0,!0)};m.onMenuNodeClone=function(a,b,c,d,e){e.graph.beforeChange();var f={};a=function(a){if(0!=a.clonable){var b=a.clone();b&&(b.pos=[a.pos[0]+5,a.pos[1]+5],a.graph.add(b),f[b.id]=b)}};b=m.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)a(e);else for(var g in b.selected_nodes)a(b.selected_nodes[g]); +Object.keys(f).length&&b.selectNodes(f);e.graph.afterChange();e.setDirtyCanvas(!0,!0)};m.node_colors={red:{color:"#322",bgcolor:"#533",groupcolor:"#A88"},brown:{color:"#332922",bgcolor:"#593930",groupcolor:"#b06634"},green:{color:"#232",bgcolor:"#353",groupcolor:"#8A8"},blue:{color:"#223",bgcolor:"#335",groupcolor:"#88A"},pale_blue:{color:"#2a363b",bgcolor:"#3f5159",groupcolor:"#3f789e"},cyan:{color:"#233",bgcolor:"#355",groupcolor:"#8AA"},purple:{color:"#323",bgcolor:"#535",groupcolor:"#a1309b"}, +yellow:{color:"#432",bgcolor:"#653",groupcolor:"#b58b2a"},black:{color:"#222",bgcolor:"#000",groupcolor:"#444"}};m.prototype.getCanvasMenuOptions=function(){if(this.getMenuOptions)var a=this.getMenuOptions();else a=[{content:"Add Node",has_submenu:!0,callback:m.onMenuAdd},{content:"Add Group",callback:m.onGroupAdd}],this._graph_stack&&0Name",d),h=g.querySelector("input");h&&f&&(h.value=f.label||"");var k=function(){a.graph.beforeChange();h.value&&(f&&(f.label=h.value),c.setDirty(!0));g.close();a.graph.afterChange()};g.querySelector("button").addEventListener("click",k);h.addEventListener("keydown",function(a){g.is_modified=!0;if(27==a.keyCode)g.close(); +else if(13==a.keyCode)k();else if(13!=a.keyCode&&"textarea"!=a.target.localName)return;a.preventDefault();a.stopPropagation()});h.focus()}},extra:a};a&&(f.title=a.type);var h=null;a&&(h=a.getSlotInPosition(b.canvasX,b.canvasY),m.active_node=a);h?(e=[],a.getSlotMenuOptions?e=a.getSlotMenuOptions(h):(h&&h.output&&h.output.links&&h.output.links.length&&e.push({content:"Disconnect Links",slot:h}),b=h.input||h.output,b.removable&&e.push(b.locked?"Cannot remove":{content:"Remove Slot",slot:h}),b.nameLocked|| +e.push({content:"Rename Slot",slot:h})),f.title=(h.input?h.input.type:h.output.type)||"*",h.input&&h.input.type==g.ACTION&&(f.title="Action"),h.output&&h.output.type==g.EVENT&&(f.title="Event")):a?e=this.getNodeMenuOptions(a):(e=this.getCanvasMenuOptions(),(h=this.graph.getGroupOnPos(b.canvasX,b.canvasY))&&e.push(null,{content:"Edit Group",has_submenu:!0,submenu:{title:"Group",extra:h,options:this.getGroupMenuOptions(h)}}));e&&new g.ContextMenu(e,f,d)};"undefined"!=typeof window&&window.CanvasRenderingContext2D&& +!window.CanvasRenderingContext2D.prototype.roundRect&&(window.CanvasRenderingContext2D.prototype.roundRect=function(a,b,c,d,e,f){var g,k;if(0===e)this.rect(a,b,c,d);else{void 0===f&&(f=e);if(null!=e&&e.constructor===Array)if(1==e.length)var l=g=k=f=e[0];else if(2==e.length)l=f=e[0],g=k=e[1];else if(4==e.length)l=e[0],g=e[1],k=e[2],f=e[3];else return;else l=e||0,g=e||0,k=f||0,f=f||0;this.moveTo(a+l,b);this.lineTo(a+c-g,b);this.quadraticCurveTo(a+c,b,a+c,b+g);this.lineTo(a+c,b+d-f);this.quadraticCurveTo(a+ +c,b+d,a+c-f,b+d);this.lineTo(a+f,b+d);this.quadraticCurveTo(a,b+d,a,b+d-k);this.lineTo(a,b+k);this.quadraticCurveTo(a,b,a+l,b)}});g.compareObjects=function(a,b){for(var c in a)if(a[c]!=b[c])return!1;return!0};g.distance=H;g.colorToString=function(a){return"rgba("+Math.round(255*a[0]).toFixed()+","+Math.round(255*a[1]).toFixed()+","+Math.round(255*a[2]).toFixed()+","+(4==a.length?a[3].toFixed(2):"1.0")+")"};g.isInsideRectangle=C;g.growBounding=function(a,b,c){ba[2]&&(a[2]=b);ca[3]&&(a[3]=c)};g.isInsideBounding=function(a,b){return a[0]b[1][0]||a[1]>b[1][1]?!1:!0};g.overlapBounding=F;g.hex2num=function(a){"#"==a.charAt(0)&&(a=a.slice(1));a=a.toUpperCase();for(var b=Array(3),c=0,d,e,f=0;6>f;f+=2)d="0123456789ABCDEF".indexOf(a.charAt(f)),e="0123456789ABCDEF".indexOf(a.charAt(f+1)),b[c]=16*d+e,c++;return b};g.num2hex=function(a){for(var b="#",c,d,e=0;3>e;e++)c=a[e]/16,d=a[e]%16,b+="0123456789ABCDEF".charAt(c)+"0123456789ABCDEF".charAt(d); +return b};D.prototype.addItem=function(a,b,c){function d(a){var b=this.value;b&&b.has_submenu&&e.call(this,a)}function e(a){var b=this.value,d=!0;f.current_submenu&&f.current_submenu.close(a);if(c.callback){var e=c.callback.call(this,b,c,a,f,c.node);!0===e&&(d=!1)}if(b&&(b.callback&&!c.ignore_item_callbacks&&!0!==b.disabled&&(e=b.callback.call(this,b,c,a,f,c.extra),!0===e&&(d=!1)),b.submenu)){if(!b.submenu.options)throw"ContextMenu submenu needs options";new f.constructor(b.submenu.options,{callback:b.submenu.callback, +event:a,parentMenu:f,ignore_item_callbacks:b.submenu.ignore_item_callbacks,title:b.submenu.title,extra:b.submenu.extra,autoopen:c.autoopen});d=!1}d&&!f.lock&&f.close()}var f=this;c=c||{};var h=document.createElement("div");h.className="litemenu-entry submenu";var k=!1;if(null===b)h.classList.add("separator");else{h.innerHTML=b&&b.title?b.title:a;if(h.value=b)b.disabled&&(k=!0,h.classList.add("disabled")),(b.submenu||b.has_submenu)&&h.classList.add("has_submenu");"function"==typeof b?(h.dataset.value= +a,h.onclick_callback=b):h.dataset.value=b;b.className&&(h.className+=" "+b.className)}this.root.appendChild(h);k||h.addEventListener("click",e);c.autoopen&&g.pointerListenerAdd(h,"enter",d);return h};D.prototype.close=function(a,b){this.root.parentNode&&this.root.parentNode.removeChild(this.root);this.parentMenu&&!b&&(this.parentMenu.lock=!1,this.parentMenu.current_submenu=null,void 0===a?this.parentMenu.close():a&&!D.isCursorOverElement(a,this.parentMenu.root)&&D.trigger(this.parentMenu.root,g.pointerevents_method+ +"leave",a));this.current_submenu&&this.current_submenu.close(a,!0);this.root.closing_timer&&clearTimeout(this.root.closing_timer)};D.trigger=function(a,b,c,d){var e=document.createEvent("CustomEvent");e.initCustomEvent(b,!0,!0,c);e.srcElement=d;a.dispatchEvent?a.dispatchEvent(e):a.__events&&a.__events.dispatchEvent(e);return e};D.prototype.getTopMenu=function(){return this.options.parentMenu?this.options.parentMenu.getTopMenu():this};D.prototype.getFirstEvent=function(){return this.options.parentMenu? +this.options.parentMenu.getFirstEvent():this.options.event};D.isCursorOverElement=function(a,b){var c=a.clientX;a=a.clientY;return(b=b.getBoundingClientRect())?a>b.top&&ab.left&&c +Math.abs(b))return d[1];a=(a-d[0])/b;return d[1]*(1-a)+e[1]*a}}return 0}};E.prototype.draw=function(a,b,c,d,e,f){if(c=this.points){this.size=b;var g=b[0]-2*this.margin;b=b[1]-2*this.margin;e=e||"#666";a.save();a.translate(this.margin,this.margin);d&&(a.fillStyle="#111",a.fillRect(0,0,g,b),a.fillStyle="#222",a.fillRect(.5*g,0,1,b),a.strokeStyle="#333",a.strokeRect(0,0,g,b));a.strokeStyle=e;f&&(a.globalAlpha=.5);a.beginPath();for(d=0;da[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;mk||p>b||(l=m,k=p)}return l};g.CurveEditor=E;g.getParameterNames= +function(a){return(a+"").replace(/[/][/].*$/gm,"").replace(/\s+/g,"").replace(/[/][*][^/*]*[*][/]/g,"").split("){",1)[0].replace(/^[^(]*[(]/,"").replace(/=[^,]+/g,"").split(",").filter(Boolean)};g.pointerListenerAdd=function(a,b,c,d){d=void 0===d?!1:d;if(a&&a.addEventListener&&b&&"function"===typeof c){var e=g.pointerevents_method;if("pointer"==e&&!window.PointerEvent)switch(console.warn("sMethod=='pointer' && !window.PointerEvent"),console.log("Converting pointer["+b+"] : down move up cancel enter TO touchstart touchmove touchend, etc .."), +b){case "down":e="touch";b="start";break;case "move":e="touch";break;case "up":e="touch";b="end";break;case "cancel":e="touch";break;case "enter":console.log("debug: Should I send a move event?");break;default:console.warn("PointerEvent not available in this browser ? The event "+b+" would not be called")}switch(b){case "down":case "up":case "move":case "over":case "out":case "enter":a.addEventListener(e+b,c,d);case "leave":case "cancel":case "gotpointercapture":case "lostpointercapture":if("mouse"!= +e)return a.addEventListener(e+b,c,d);default:return a.addEventListener(b,c,d)}}};g.pointerListenerRemove=function(a,b,c,d){d=void 0===d?!1:d;if(a&&a.removeEventListener&&b&&"function"===typeof c)switch(b){case "down":case "up":case "move":case "over":case "out":case "enter":"pointer"!=g.pointerevents_method&&"mouse"!=g.pointerevents_method||a.removeEventListener(g.pointerevents_method+b,c,d);case "leave":case "cancel":case "gotpointercapture":case "lostpointercapture":if("pointer"==g.pointerevents_method)return a.removeEventListener(g.pointerevents_method+ +b,c,d);default:return a.removeEventListener(b,c,d)}};Math.clamp=function(a,b,c){return b>a?b:cg&&(g=Math.max(0,n+g));if(null==q||q>n)q=n;q=Number(q);0>q&&(q=Math.max(0,n+q));for(g=Number(g||0);g=w}},"es6","es3");$jscomp.findInternal=function(z,c,g){z instanceof String&&(z=String(z));for(var q=z.length,n=0;nc?-g:g}},"es6","es3"); -(function(z){function c(a){e.debug&&console.log("Graph created");this.list_of_graphcanvas=null;this.clear();a&&this.configure(a)}function g(a,b,d,h,f,e){this.id=a;this.type=b;this.origin_id=d;this.origin_slot=h;this.target_id=f;this.target_slot=e;this._data=null;this._pos=new Float32Array(2)}function q(a){this._ctor(a)}function n(a){this._ctor(a)}function w(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 l(a,b,d){this.options=d=d||{};this.background_image=l.DEFAULT_BACKGROUND_IMAGE;a&&a.constructor===String&&(a=document.querySelector(a));this.ds=new w;this.zoom_modify_alpha=!0;this.title_text_font=""+e.NODE_TEXT_SIZE+"px Arial";this.inner_text_font="normal "+e.NODE_SUBTEXT_SIZE+"px Arial";this.node_title_color=e.NODE_TITLE_COLOR;this.default_link_color=e.LINK_COLOR;this.default_connection_color= -{input_off:"#778",input_on:"#7F7",output_off:"#778",output_on:"#7F7"};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_searchbox=this.allow_interaction=this.allow_dragnodes=this.allow_dragcanvas=this.show_info=!0;this.drag_mode=this.align_to_grid=this.allow_reconnect_links=!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=e.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=d.viewport||null;b&&b.attachCanvas(this);this.setCanvas(a,d.skip_events);this.clear();d.skip_render||this.startRendering();this.autoresize= -d.autoresize}function A(a,b){return Math.sqrt((b[0]-a[0])*(b[0]-a[0])+(b[1]-a[1])*(b[1]-a[1]))}function B(a,b,d,h,f,e){return da&&hb?!0:!1}function C(a,b){var d=a[0]+a[2],h=a[1]+a[3],f=b[1]+b[3];return a[0]>b[0]+b[2]||a[1]>f||dJ.width-c.width-10&&(f=J.width-c.width-10),J.height&&a>J.height-c.height-10&&(a=J.height-c.height-10));x.style.left=f+"px";x.style.top=a+"px";b.scale&&(x.style.transform="scale("+ -b.scale+")")}function D(a){this.points=a;this.nearest=this.selected=-1;this.size=null;this.must_update=!0;this.margin=5}var e=z.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,INPUT:1,OUTPUT:2, -EVENT:-1,ACTION:-1,ALWAYS:0,ON_EVENT:1,NEVER:2,ON_TRIGGER:3,UP:1,DOWN:2,LEFT:3,RIGHT:4,CENTER:5,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,pointerevents_method:"pointer",registerNodeType:function(a,b){if(!b.prototype)throw"Cannot register a simple object, it must be a class with a prototype"; -b.type=a;e.debug&&console.log("Node registered: "+a);a.split("/");var d=b.name,h=a.lastIndexOf("/");b.category=a.substr(0,h);b.title||(b.title=d);if(b.prototype)for(var f in q.prototype)b.prototype[f]||(b.prototype[f]=q.prototype[f]);if(h=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=e.BOX_SHAPE; -break;case "round":this._shape=e.ROUND_SHAPE;break;case "circle":this._shape=e.CIRCLE_SHAPE;break;case "card":this._shape=e.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(f in b.supported_extensions){var x=b.supported_extensions[f];x&&x.constructor===String&& -(this.node_types_by_file_extension[x.toLowerCase()]=b)}this.registered_node_types[a]=b;b.constructor.name&&(this.Nodes[d]=b);if(e.onNodeTypeRegistered)e.onNodeTypeRegistered(a,b);if(h&&e.onNodeTypeReplaced)e.onNodeTypeReplaced(a,b,h);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(f=0;fc&&(c=f.size[0]),u+=f.size[1]+a+e.NODE_TITLE_HEIGHT;b+=c+a}this.setDirtyCanvas(!0,!0)};c.prototype.getTime=function(){return this.globaltime};c.prototype.getFixedTime=function(){return this.fixedtime};c.prototype.getElapsedTime=function(){return this.elapsed_time}; -c.prototype.sendEventToAllNodes=function(a,b,d){d=d||e.ALWAYS;var h=this._nodes_in_order?this._nodes_in_order:this._nodes;if(h)for(var f=0,x=h.length;f=e.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_idl&&(l=Math.max(0,t+l));if(null==r||r>t)r=t;r=Number(r);0>r&&(r=Math.max(0,t+r));for(l=Number(l||0);l=v}},"es6","es3"); +$jscomp.findInternal=function(B,c,l){B instanceof String&&(B=String(B));for(var r=B.length,t=0;tc?-l:l}},"es6","es3"); +(function(B){function c(a){e.debug&&console.log("Graph created");this.list_of_graphcanvas=null;this.clear();a&&this.configure(a)}function l(a,b,d,g,f,e){this.id=a;this.type=b;this.origin_id=d;this.origin_slot=g;this.target_id=f;this.target_slot=e;this._data=null;this._pos=new Float32Array(2)}function r(a){this._ctor(a)}function t(a){this._ctor(a)}function v(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,d){this.options=d=d||{};this.background_image=h.DEFAULT_BACKGROUND_IMAGE;a&&a.constructor===String&&(a=document.querySelector(a));this.ds=new v;this.zoom_modify_alpha=!0;this.title_text_font=""+e.NODE_TEXT_SIZE+"px Arial";this.inner_text_font="normal "+e.NODE_SUBTEXT_SIZE+"px Arial";this.node_title_color=e.NODE_TITLE_COLOR;this.default_link_color=e.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=e.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=d.viewport||null;b&&b.attachCanvas(this); +this.setCanvas(a,d.skip_events);this.clear();d.skip_render||this.startRendering();this.autoresize=d.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 A(a,b,d,g,f,e){return da&&gb?!0:!1}function I(a,b){var d=a[0]+a[2],g=a[1]+a[3],f=b[1]+b[3];return a[0]>b[0]+b[2]||a[1]>f||d +u.width-c.width-10&&(f=u.width-c.width-10),u.height&&a>u.height-c.height-10&&(a=u.height-c.height-10));m.style.left=f+"px";m.style.top=a+"px";b.scale&&(m.style.transform="scale("+b.scale+")")}function F(a){this.points=a;this.nearest=this.selected=-1;this.size=null;this.must_update=!0;this.margin=5}var e=B.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"; +b.type=a;e.debug&&console.log("Node registered: "+a);a.split("/");var d=b.name,g=a.lastIndexOf("/");b.category=a.substr(0,g);b.title||(b.title=d);if(b.prototype)for(var f in r.prototype)b.prototype[f]||(b.prototype[f]=r.prototype[f]);if(g=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=e.BOX_SHAPE; +break;case "round":this._shape=e.ROUND_SHAPE;break;case "circle":this._shape=e.CIRCLE_SHAPE;break;case "card":this._shape=e.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(f in b.supported_extensions){var m=b.supported_extensions[f];m&&m.constructor===String&& +(this.node_types_by_file_extension[m.toLowerCase()]=b)}this.registered_node_types[a]=b;b.constructor.name&&(this.Nodes[d]=b);if(e.onNodeTypeRegistered)e.onNodeTypeRegistered(a,b);if(g&&e.onNodeTypeReplaced)e.onNodeTypeReplaced(a,b,g);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(f=0;fu&&(u=f.size[0]),c+=f.size[1]+a+e.NODE_TITLE_HEIGHT;b+=u+a}this.setDirtyCanvas(!0,!0)};c.prototype.getTime=function(){return this.globaltime};c.prototype.getFixedTime=function(){return this.fixedtime};c.prototype.getElapsedTime=function(){return this.elapsed_time}; +c.prototype.sendEventToAllNodes=function(a,b,d){d=d||e.ALWAYS;var g=this._nodes_in_order?this._nodes_in_order:this._nodes;if(g)for(var f=0,m=g.length;f=e.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_ida.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={}};q.prototype.configure=function(a){this.graph&&this.graph._version++; -for(var b in a)if("properties"==b)for(var d in a.properties){if(this.properties[d]=a.properties[d],this.onPropertyChanged)this.onPropertyChanged(d,a.properties[d])}else null!=a[b]&&("object"==typeof a[b]?this[b]&&this[b].configure?this[b].configure(a[b]):this[b]=e.cloneObject(a[b],this[b]):this[b]=a[b]);a.title||(this.title=this.constructor.title);if(this.onConnectionsChange){if(this.inputs)for(d=0;da.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={}};r.prototype.configure=function(a){this.graph&&this.graph._version++; +for(var b in a)if("properties"==b)for(var d in a.properties){if(this.properties[d]=a.properties[d],this.onPropertyChanged)this.onPropertyChanged(d,a.properties[d])}else null!=a[b]&&("object"==typeof a[b]?this[b]&&this[b].configure?this[b].configure(a[b]):this[b]=e.cloneObject(a[b],this[b]):this[b]=a[b]);a.title||(this.title=this.constructor.title);if(this.onConnectionsChange){if(this.inputs)for(d=0;d=this.outputs.length)){var d=this.outputs[a];if(d&&(d._data=b,this.outputs[a].links))for(d=0;d=this.outputs.length)){var d=this.outputs[a];if(d&&(d.type=b,this.outputs[a].links))for(d=0;d=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}};q.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};q.prototype.getInputDataByName=function(a,b){a=this.findInputSlot(a);return-1==a?null:this.getInputData(a, -b)};q.prototype.isInputConnected=function(a){return 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};q.prototype.getInputOrProperty=function(a){if(!this.inputs||!this.inputs.length)return this.properties?this.properties[a]:null;for(var b=0,d=this.inputs.length;b=this.outputs.length?null:this.outputs[a]._data};q.prototype.getOutputInfo=function(a){return this.outputs? -a=this.outputs.length)return null;a=this.outputs[a]; -if(!a.links||0==a.links.length)return null;for(var b=[],d=0;da&&this.pos[1]-f-db)return!0;return!1};q.prototype.getSlotInPosition=function(a,b){var d=new Float32Array(2);if(this.inputs)for(var h=0,f=this.inputs.length;h=this.outputs.length)return e.debug&&console.log("Connect: Error, slot number not found"),null;b&& -b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"target node is null";if(b==this)return null;if(d.constructor===String){if(d=b.findInputSlot(d),-1==d)return e.debug&&console.log("Connect: Error, no slot of name "+d),null}else{if(d===e.EVENT)return null;if(!b.inputs||d>=b.inputs.length)return e.debug&&console.log("Connect: Error, slot number not found"),null}var h=!1;null!=b.inputs[d].link&&(this.graph.beforeChange(),b.disconnectInput(d),h=!0);var f=this.outputs[a];if(b.onConnectInput&& -!1===b.onConnectInput(d,f.type,f,this,a))return null;var x=b.inputs[d],c=null;if(!e.isValidConnection(f.type,x.type))return this.setDirtyCanvas(!1,!0),h&&this.graph.connectionChange(this,c),null;h||this.graph.beforeChange();c=new g(++this.graph.last_link_id,x.type,this.id,a,b.id,d);this.graph.links[c.id]=c;null==f.links&&(f.links=[]);f.links.push(c.id);b.inputs[d].link=c.id;this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(e.OUTPUT,a,!0,c,f);if(b.onConnectionsChange)b.onConnectionsChange(e.INPUT, -d,!0,c,x);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(e.INPUT,b,d,this,a),this.graph.onNodeConnectionChange(e.OUTPUT,this,a,b,d));this.setDirtyCanvas(!1,!0);this.graph.afterChange();this.graph.connectionChange(this,c);return c};q.prototype.disconnectOutput=function(a,b){if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return e.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.outputs||a>=this.outputs.length)return e.debug&& -console.log("Connect: Error, slot number not found"),!1;var d=this.outputs[a];if(!d||!d.links||0==d.links.length)return!1;if(b){b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"Target Node not found";for(var h=0,f=d.links.length;h=this.inputs.length)return e.debug&&console.log("Connect: Error, slot number not found"),!1;var b=this.inputs[a];if(!b)return!1;var d=this.inputs[a].link;if(null!=d){this.inputs[a].link=null;var h=this.graph.links[d];if(h){var f=this.graph.getNodeById(h.origin_id); -if(!f)return!1;var c=f.outputs[h.origin_slot];if(!c||!c.links||0==c.links.length)return!1;for(var k=0,u=c.links.length;kb&&this.inputs[b].pos)return d[0]=this.pos[0]+this.inputs[b].pos[0],d[1]=this.pos[1]+this.inputs[b].pos[1],d;if(!a&&h>b&&this.outputs[b].pos)return d[0]=this.pos[0]+this.outputs[b].pos[0],d[1]=this.pos[1]+this.outputs[b].pos[1],d;if(this.horizontal)return d[0]=this.pos[0]+this.size[0]/h*(b+.5),d[1]=a?this.pos[1]-e.NODE_TITLE_HEIGHT:this.pos[1]+this.size[1],d;d[0]= -a?this.pos[0]+f:this.pos[0]+this.size[0]+1-f;d[1]=this.pos[1]+(b+.7)*e.NODE_SLOT_HEIGHT+(this.constructor.slot_start_y||0);return d};q.prototype.alignToGrid=function(){this.pos[0]=e.CANVAS_GRID_SIZE*Math.round(this.pos[0]/e.CANVAS_GRID_SIZE);this.pos[1]=e.CANVAS_GRID_SIZE*Math.round(this.pos[1]/e.CANVAS_GRID_SIZE)};q.prototype.trace=function(a){this.console||(this.console=[]);this.console.push(a);this.console.length>q.MAX_CONSOLE&&this.console.shift();if(this.graph.onNodeTrace)this.graph.onNodeTrace(this, -a)};q.prototype.setDirtyCanvas=function(a,b){this.graph&&this.graph.sendActionToCanvas("setDirty",[a,b])};q.prototype.loadImage=function(a){var b=new Image;b.src=e.node_images_path+a;b.ready=!1;var d=this;b.onload=function(){this.ready=!0;d.setDirtyCanvas(!0)};return b};q.prototype.captureInput=function(a){if(this.graph&&this.graph.list_of_graphcanvas)for(var b=this.graph.list_of_graphcanvas,d=0;da.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})};n.prototype.configure=function(a){this.title=a.title;this._bounding.set(a.bounding);this.color=a.color;this.font=a.font};n.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}};n.prototype.move=function(a,b,d){this._pos[0]+=a;this._pos[1]+=b;if(!d)for(d=0;d=this.viewport[0]&&h=this.viewport[1]&&dthis.max_scale&&(a=this.max_scale);if(a!=this.scale&&this.element){var d=this.element.getBoundingClientRect();if(d&&(b=b||[.5*d.width,.5*d.height],d=this.convertCanvasToOffset(b),this.scale=a,.01>Math.abs(this.scale-1)&&(this.scale=1),a=this.convertCanvasToOffset(b),a=[a[0]-d[0],a[1]-d[1]],this.offset[0]+=a[0],this.offset[1]+=a[1],this.onredraw))this.onredraw(this)}};w.prototype.changeDeltaScale=function(a,b){this.changeScale(this.scale*a,b)};w.prototype.reset=function(){this.scale= -1;this.offset[0]=0;this.offset[1]=0};z.LGraphCanvas=e.LGraphCanvas=l;l.DEFAULT_BACKGROUND_IMAGE="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQBJREFUeNrs1rEKwjAUhlETUkj3vP9rdmr1Ysammk2w5wdxuLgcMHyptfawuZX4pJSWZTnfnu/lnIe/jNNxHHGNn//HNbbv+4dr6V+11uF527arU7+u63qfa/bnmh8sWLBgwYJlqRf8MEptXPBXJXa37BSl3ixYsGDBMliwFLyCV/DeLIMFCxYsWLBMwSt4Be/NggXLYMGCBUvBK3iNruC9WbBgwYJlsGApeAWv4L1ZBgsWLFiwYJmCV/AK3psFC5bBggULloJX8BpdwXuzYMGCBctgwVLwCl7Be7MMFixYsGDBsu8FH1FaSmExVfAxBa/gvVmwYMGCZbBg/W4vAQYA5tRF9QYlv/QAAAAASUVORK5CYII="; -l.link_type_colors={"-1":e.EVENT_LINK_COLOR,number:"#AAA",node:"#DCA"};l.gradients={};l.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()};l.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)))};l.prototype.getTopGraph=function(){return this._graph_stack.length?this._graph_stack[0]:this.graph};l.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)};l.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}};l.prototype.getCurrentGraph=function(){return this.graph};l.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 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()}};l.prototype._doNothing=function(a){a.preventDefault();return!1};l.prototype._doReturnTrue=function(a){a.preventDefault(); -return!0};l.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);e.pointerListenerAdd(a,"down",this._mousedown_callback,!0);a.addEventListener("mousewheel",this._mousewheel_callback, +return a};r.prototype.clone=function(){var a=e.createNode(this.type);if(!a)return null;var b=e.cloneObject(this.serialize());if(b.inputs)for(var d=0;d=this.outputs.length)){var d=this.outputs[a];if(d&&(d._data=b,this.outputs[a].links))for(d=0;d=this.outputs.length)){var d=this.outputs[a];if(d&&(d.type=b,this.outputs[a].links))for(d=0;d=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}};r.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};r.prototype.getInputDataByName=function(a,b){a=this.findInputSlot(a);return-1==a?null:this.getInputData(a, +b)};r.prototype.isInputConnected=function(a){return 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};r.prototype.getInputOrProperty=function(a){if(!this.inputs||!this.inputs.length)return this.properties?this.properties[a]:null;for(var b=0,d=this.inputs.length;b=this.outputs.length?null:this.outputs[a]._data};r.prototype.getOutputInfo=function(a){return this.outputs? +a=this.outputs.length)return null;a=this.outputs[a]; +if(!a.links||0==a.links.length)return null;for(var b=[],d=0;da&&this.pos[1]-f-db)return!0;return!1};r.prototype.getSlotInPosition= +function(a,b){var d=new Float32Array(2);if(this.inputs)for(var g=0,f=this.inputs.length;g=this.outputs.length)return e.debug&&console.log("Connect: Error, slot number not found"),null;b&&b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"target node is null";if(b==this)return null;if(d.constructor===String){if(d=b.findInputSlot(d),-1==d)return e.debug&&console.log("Connect: Error, no slot of name "+d),null}else if(d=== +e.EVENT)if(e.do_add_triggers_slots)b.changeMode(e.ON_TRIGGER),d=b.findInputSlot("onTrigger");else return null;else if(!b.inputs||d>=b.inputs.length)return e.debug&&console.log("Connect: Error, slot number not found"),null;var g=b.inputs[d],f=this.outputs[a];if(!this.outputs[a])return null;b.onBeforeConnectInput&&(d=b.onBeforeConnectInput(d));if(!1===d||null===d||!e.isValidConnection(f.type,g.type))return this.setDirtyCanvas(!1,!0),null;if(b.onConnectInput&&!1===b.onConnectInput(d,f.type,f,this,a)|| +this.onConnectOutput&&!1===this.onConnectOutput(a,g.type,g,b,d))return null;b.inputs[d]&&null!=b.inputs[d].link&&(this.graph.beforeChange(),b.disconnectInput(d,{doProcessChange:!1}));if(null!==f.links&&f.links.length)switch(f.type){case e.EVENT:e.allow_multi_output_for_events||(this.graph.beforeChange(),this.disconnectOutput(a,!1,{doProcessChange:!1}))}var m=new l(++this.graph.last_link_id,g.type||f.type,this.id,a,b.id,d);this.graph.links[m.id]=m;null==f.links&&(f.links=[]);f.links.push(m.id);b.inputs[d].link= +m.id;this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(e.OUTPUT,a,!0,m,f);if(b.onConnectionsChange)b.onConnectionsChange(e.INPUT,d,!0,m,g);this.graph&&this.graph.onNodeConnectionChange&&(this.graph.onNodeConnectionChange(e.INPUT,b,d,this,a),this.graph.onNodeConnectionChange(e.OUTPUT,this,a,b,d));this.setDirtyCanvas(!1,!0);this.graph.afterChange();this.graph.connectionChange(this,m);return m};r.prototype.disconnectOutput=function(a,b){if(a.constructor===String){if(a= +this.findOutputSlot(a),-1==a)return e.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.outputs||a>=this.outputs.length)return e.debug&&console.log("Connect: Error, slot number not found"),!1;var d=this.outputs[a];if(!d||!d.links||0==d.links.length)return!1;if(b){b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"Target Node not found";for(var g=0,f=d.links.length;g=this.inputs.length)return e.debug&&console.log("Connect: Error, slot number not found"),!1;var b=this.inputs[a]; +if(!b)return!1;var d=this.inputs[a].link;if(null!=d){this.inputs[a].link=null;var g=this.graph.links[d];if(g){var f=this.graph.getNodeById(g.origin_id);if(!f)return!1;var m=f.outputs[g.origin_slot];if(!m||!m.links||0==m.links.length)return!1;for(var u=0,c=m.links.length;ub&&this.inputs[b].pos)return d[0]=this.pos[0]+this.inputs[b].pos[0],d[1]=this.pos[1]+this.inputs[b].pos[1],d;if(!a&&g>b&&this.outputs[b].pos)return d[0]=this.pos[0]+this.outputs[b].pos[0],d[1]=this.pos[1]+this.outputs[b].pos[1], +d;if(this.horizontal)return d[0]=this.pos[0]+this.size[0]/g*(b+.5),d[1]=a?this.pos[1]-e.NODE_TITLE_HEIGHT:this.pos[1]+this.size[1],d;d[0]=a?this.pos[0]+f:this.pos[0]+this.size[0]+1-f;d[1]=this.pos[1]+(b+.7)*e.NODE_SLOT_HEIGHT+(this.constructor.slot_start_y||0);return d};r.prototype.alignToGrid=function(){this.pos[0]=e.CANVAS_GRID_SIZE*Math.round(this.pos[0]/e.CANVAS_GRID_SIZE);this.pos[1]=e.CANVAS_GRID_SIZE*Math.round(this.pos[1]/e.CANVAS_GRID_SIZE)};r.prototype.trace=function(a){this.console||(this.console= +[]);this.console.push(a);this.console.length>r.MAX_CONSOLE&&this.console.shift();if(this.graph.onNodeTrace)this.graph.onNodeTrace(this,a)};r.prototype.setDirtyCanvas=function(a,b){this.graph&&this.graph.sendActionToCanvas("setDirty",[a,b])};r.prototype.loadImage=function(a){var b=new Image;b.src=e.node_images_path+a;b.ready=!1;var d=this;b.onload=function(){this.ready=!0;d.setDirtyCanvas(!0)};return b};r.prototype.captureInput=function(a){if(this.graph&&this.graph.list_of_graphcanvas)for(var b=this.graph.list_of_graphcanvas, +d=0;da.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})};t.prototype.configure=function(a){this.title=a.title;this._bounding.set(a.bounding);this.color=a.color;this.font=a.font};t.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}};t.prototype.move=function(a,b, +d){this._pos[0]+=a;this._pos[1]+=b;if(!d)for(d=0;d= +this.viewport[0]&&g=this.viewport[1]&&dthis.max_scale&&(a=this.max_scale);if(a!=this.scale&&this.element){var d=this.element.getBoundingClientRect();if(d&&(b=b||[.5*d.width,.5*d.height],d=this.convertCanvasToOffset(b),this.scale=a,.01>Math.abs(this.scale-1)&&(this.scale=1),a=this.convertCanvasToOffset(b),a=[a[0]-d[0],a[1]- +d[1]],this.offset[0]+=a[0],this.offset[1]+=a[1],this.onredraw))this.onredraw(this)}};v.prototype.changeDeltaScale=function(a,b){this.changeScale(this.scale*a,b)};v.prototype.reset=function(){this.scale=1;this.offset[0]=0;this.offset[1]=0};B.LGraphCanvas=e.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":e.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 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);e.pointerListenerAdd(a,"down",this._mousedown_callback,!0);a.addEventListener("mousewheel",this._mousewheel_callback, !1);e.pointerListenerAdd(a,"up",this._mouseup_callback,!0);e.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}};l.prototype.unbindEvents=function(){if(this._events_binded){var a=this.getCanvasWindow().document;e.pointerListenerRemove(this.canvas,"move",this._mousedown_callback);e.pointerListenerRemove(this.canvas,"up",this._mousedown_callback);e.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}};h.prototype.unbindEvents=function(){if(this._events_binded){var a=this.getCanvasWindow().document;e.pointerListenerRemove(this.canvas,"move",this._mousedown_callback);e.pointerListenerRemove(this.canvas,"up",this._mousedown_callback);e.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")}; -l.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()};l.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};l.prototype.setDirty=function(a,b){a&&(this.dirty_canvas=!0);b&&(this.dirty_bgcanvas=!0)};l.prototype.getCanvasWindow=function(){if(!this.canvas)return window;var a=this.canvas.ownerDocument; -return a.defaultView||a.parentWindow};l.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))};l.prototype.stopRendering=function(){this.is_rendering=!1};l.prototype.blockClick=function(){this.block_click=!0;this.last_mouseclick=0};l.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();l.active_canvas=this;var d=this,h=a.clientX,f=a.clientY;this.ds.viewport=this.viewport;h=!this.viewport||this.viewport&&h>=this.viewport[0]&&h=this.viewport[1]&&fe.getTime()-this.last_mouseclick&&void 0!==a.isPrimary&&a.isPrimary;this.mouse[0]=a.clientX;this.mouse[1]=a.clientY;this.graph_mouse[0]=a.canvasX;this.graph_mouse[1]=a.canvasY;this.last_click_position=[this.mouse[0],this.mouse[1]];this.pointer_is_double=this.pointer_is_down&&void 0!==a.isPrimary&&!a.isPrimary?!0:!1;this.pointer_is_down=!0;this.canvas.focus();e.closeAllContextMenus(b); -if(!this.onMouse||1!=this.onMouse(a)){if(1!=a.which||this.pointer_is_double)2==a.which||3!=a.which&&!this.pointer_is_double||this.read_only||this.processContextMenu(c,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,f=!0);var k=!1;if(c&&this.allow_interaction&&!f&&!this.read_only){this.live_mode||c.flags.pinned||this.bringToFront(c);if(!this.connecting_node&& -!c.flags.collapsed&&!this.live_mode)if(!f&&!1!==c.resizable&&B(a.canvasX,a.canvasY,c.pos[0]+c.size[0]-5,c.pos[1]+c.size[1]-5,10,10))this.graph.beforeChange(),this.resizing_node=c,this.canvas.style.cursor="se-resize",f=!0;else{if(c.outputs)for(var u=0,v=c.outputs.length;uc.size[0]-e.NODE_TITLE_HEIGHT&&0>v[1]&&(d=this,setTimeout(function(){d.openSubgraph(c.subgraph)},10)),this.live_mode&&(u=k=!0));u||(this.allow_dragnodes&&(this.graph.beforeChange(),this.node_dragged=c),this.selected_nodes[c.id]||this.processNodeSelected(c,a));this.dirty_canvas=!0}}else{if(!this.read_only)for(u=0;uv[0]+4||a.canvasYv[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>A([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());h&&!this.read_only&& -this.allow_searchbox&&this.showSearchBox(a);k=!0}!f&&k&&this.allow_dragcanvas&&(this.dragging_canvas=!0)}this.last_mouse[0]=a.clientX;this.last_mouse[1]=a.clientY;this.last_mouseclick=e.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}}}};l.prototype.processMouseMove= -function(a){this.autoresize&&this.resize();this.set_canvas_dirty_on_mouse_event&&(this.dirty_canvas=!0);if(this.graph){l.active_canvas=this;this.adjustMouseEvent(a);var b=[a.clientX,a.clientY];this.mouse[0]=b[0];this.mouse[1]=b[1];var d=[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(d[0]/this.ds.scale,d[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]+=d[0]/this.ds.scale,this.ds.offset[1]+=d[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 h=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes);b=0;for(var f=this.graph._nodes.length;bk[0]+4||a.canvasY -k[1]+4)){f=c;break}}f!=this.over_link_center&&(this.over_link_center=f,this.dirty_canvas=!0);this.canvas&&(this.canvas.style.cursor="")}if(this.node_capturing_input&&this.node_capturing_input!=h&&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)h=this.selected_nodes[b],h.pos[0]+=d[0]/this.ds.scale,h.pos[1]+=d[1]/ -this.ds.scale;this.dirty_bgcanvas=this.dirty_canvas=!0}this.resizing_node&&!this.live_mode&&(d=[a.canvasX-this.resizing_node.pos[0],a.canvasY-this.resizing_node.pos[1]],b=this.resizing_node.computeSize(),d[0]=Math.max(b[0],d[0]),d[1]=Math.max(b[1],d[1]),this.resizing_node.setSize(d),this.canvas.style.cursor="se-resize",this.dirty_bgcanvas=this.dirty_canvas=!0)}a.preventDefault();return!1}};l.prototype.processMouseUp=function(a){if(void 0!==a.isPrimary&&!a.isPrimary)return!1;this.set_canvas_dirty_on_mouse_event&& -(this.dirty_canvas=!0);if(this.graph){var b=this.getCanvasWindow().document;l.active_canvas=this;this.options.skip_events||(e.pointerListenerRemove(b,"move",this._mousemove_callback,!0),e.pointerListenerAdd(this.canvas,"move",this._mousemove_callback,!0),e.pointerListenerRemove(b,"up",this._mouseup_callback,!0));this.adjustMouseEvent(a);b=e.getTime();a.click_time=b-this.last_mouseclick;this.last_mouse_dragging=!1;this.last_click_position=null;this.block_click&&(this.block_click=!1);if(1==a.which)if(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,this.dragging_rectangle){if(this.graph){b=this.graph._nodes;var d=new Float32Array(4);this.deselectAllNodes();var h=Math.abs(this.dragging_rectangle[2]),f=Math.abs(this.dragging_rectangle[3]),c=0>this.dragging_rectangle[3]?this.dragging_rectangle[1]-f:this.dragging_rectangle[1];this.dragging_rectangle[0]=0>this.dragging_rectangle[2]?this.dragging_rectangle[0]-h:this.dragging_rectangle[0];this.dragging_rectangle[1]=c;this.dragging_rectangle[2]=h;this.dragging_rectangle[3]=f;f=[];for(c=0;ca.click_time&&B(a.canvasX,a.canvasY,h.pos[0],h.pos[1]-e.NODE_TITLE_HEIGHT,e.NODE_TITLE_HEIGHT,e.NODE_TITLE_HEIGHT)&&h.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{h=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes);!h&&300>a.click_time&&this.deselectAllNodes();this.dirty_canvas=!0;this.dragging_canvas=!1;if(this.node_over&&this.node_over.onMouseUp)this.node_over.onMouseUp(a,[a.canvasX-this.node_over.pos[0],a.canvasY-this.node_over.pos[1]],this);if(this.node_capturing_input&&this.node_capturing_input.onMouseUp)this.node_capturing_input.onMouseUp(a,[a.canvasX-this.node_capturing_input.pos[0],a.canvasY-this.node_capturing_input.pos[1]])}else 2== -a.which?(this.dirty_canvas=!0,this.dragging_canvas=!1):3==a.which&&(this.dirty_canvas=!0,this.dragging_canvas=!1);void 0!==a.isPrimary&&a.isPrimary&&(this.pointer_is_double=this.pointer_is_down=!1);this.graph.change();a.stopPropagation();a.preventDefault();return!1}};l.prototype.processMouseWheel=function(a){if(this.graph&&this.allow_dragcanvas){var b=null!=a.wheelDeltaY?a.wheelDeltaY:-60*a.detail;this.adjustMouseEvent(a);var d=a.clientX,h=a.clientY;if(!this.viewport||this.viewport&&d>=this.viewport[0]&& -d=this.viewport[1]&&hb&&(d*=1/1.1),this.ds.changeScale(d,[a.clientX,a.clientY]),this.graph.change(),a.preventDefault(),!1}};l.prototype.isOverNodeBox=function(a,b,d){var h=e.NODE_TITLE_HEIGHT;return B(b,d,a.pos[0]+2,a.pos[1]+2-h,h-4,h-4)?!0:!1};l.prototype.isOverNodeInput=function(a,b,d,h){if(a.inputs)for(var f=0,e=a.inputs.length;f=this.viewport[0]&&b=this.viewport[1]&&dd-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}};l.prototype.drawFrontCanvas=function(){this.dirty_canvas=!1;this.ctx||(this.ctx=this.bgcanvas.getContext("2d"));var a=this.ctx;if(a){var b=this.canvas;a.start2D&&!this.viewport&& -(a.start2D(),a.restore(),a.setTransform(1,0,0,1,0,0));var d=this.viewport||this.dirty_area;d&&(a.save(),a.beginPath(),a.rect(d[0],d[1],d[2],d[3]),a.clip());this.clear_background&&(d?a.clearRect(d[0],d[1],d[2],d[3]):a.clearRect(0,0,b.width,b.height));this.bgcanvas==this.canvas?this.drawBackCanvas():a.drawImage(this.bgcanvas,0,0);if(this.onRender)this.onRender(b,a);this.show_info&&this.renderInfo(a,d?d[0]:0,d?d[1]:0);if(this.graph){a.save();this.ds.toCanvasContext(a);b=this.computeVisibleNodes(null, -this.visible_nodes);for(var h=0;h> ";b.fillText(h+d.getTitle(),.5*a.width,40);b.restore()}d= -!1;this.onRenderBackground&&(d=this.onRenderBackground(a,b));this.viewport||(b.restore(),b.setTransform(1,0,0,1,0,0));this.visible_links.length=0;if(this.graph){b.save();this.ds.toCanvasContext(b);if(this.background_image&&.5this.ds.scale;if(this.live_mode){if(!a.flags.collapsed&&(b.shadowColor="transparent",a.onDrawForeground))a.onDrawForeground(b,this,this.canvas)}else{var c= -this.editor_alpha;b.globalAlpha=c;this.render_shadows&&!f?(b.shadowColor=e.DEFAULT_SHADOW_COLOR,b.shadowOffsetX=2*this.ds.scale,b.shadowOffsetY=2*this.ds.scale,b.shadowBlur=3*this.ds.scale):b.shadowColor="transparent";if(!a.flags.collapsed||!a.onDrawCollapsed||1!=a.onDrawCollapsed(b,this)){var k=a._shape||e.BOX_SHAPE;F.set(a.size);var u=a.horizontal;if(a.flags.collapsed){b.font=this.inner_text_font;var v=a.getTitle?a.getTitle():a.title;null!=v&&(a._collapsed_width=Math.min(a.size[0],b.measureText(v).width+ -2*e.NODE_TITLE_HEIGHT),F[0]=a._collapsed_width,F[1]=0)}a.clip_area&&(b.save(),b.beginPath(),k==e.BOX_SHAPE?b.rect(0,0,F[0],F[1]):k==e.ROUND_SHAPE?b.roundRect(0,0,F[0],F[1],[10]):k==e.CIRCLE_SHAPE&&b.arc(.5*F[0],.5*F[1],.5*F[0],0,2*Math.PI),b.clip());a.has_errors&&(h="red");this.drawNodeShape(a,b,F,d,h,a.is_selected,a.mouseOver);b.shadowColor="transparent";if(a.onDrawForeground)a.onDrawForeground(b,this,this.canvas);b.textAlign=u?"center":"left";b.font=this.inner_text_font;h=!f;k=this.connecting_output; -b.lineWidth=1;v=0;var t=new Float32Array(2);if(!a.flags.collapsed){if(a.inputs)for(d=0;dthis.ds.scale,v=a._shape||a.constructor.shape||e.ROUND_SHAPE,m=a.constructor.title_mode,r=!0;m==e.TRANSPARENT_TITLE||m==e.NO_TITLE?r=!1:m==e.AUTOHIDE_TITLE&&k&&(r=!0);y[0]= -0;y[1]=r?-f:0;y[2]=d[0]+1;y[3]=r?d[1]+f:d[1];k=b.globalAlpha;b.beginPath();v==e.BOX_SHAPE||x?b.fillRect(y[0],y[1],y[2],y[3]):v==e.ROUND_SHAPE||v==e.CARD_SHAPE?b.roundRect(y[0],y[1],y[2],y[3],v==e.CARD_SHAPE?[this.round_radius,this.round_radius,0,0]:[this.round_radius]):v==e.CIRCLE_SHAPE&&b.arc(.5*d[0],.5*d[1],.5*d[0],0,2*Math.PI);b.fill();!a.flags.collapsed&&r&&(b.shadowColor="transparent",b.fillStyle="rgba(0,0,0,0.2)",b.fillRect(0,-1,y[2],2));b.shadowColor="transparent";if(a.onDrawBackground)a.onDrawBackground(b, -this,this.canvas,this.graph_mouse);if(r||m==e.TRANSPARENT_TITLE){if(a.onDrawTitleBar)a.onDrawTitleBar(b,f,d,this.ds.scale,h);else if(m!=e.TRANSPARENT_TITLE&&(a.constructor.title_color||this.render_title_colored)){r=a.constructor.title_color||h;a.flags.collapsed&&(b.shadowColor=e.DEFAULT_SHADOW_COLOR);if(this.use_gradients){var t=l.gradients[r];t||(t=l.gradients[r]=b.createLinearGradient(0,0,400,0),t.addColorStop(0,r),t.addColorStop(1,"#000"));b.fillStyle=t}else b.fillStyle=r;b.beginPath();v==e.BOX_SHAPE|| -x?b.rect(0,-f,d[0]+1,f):(v==e.ROUND_SHAPE||v==e.CARD_SHAPE)&&b.roundRect(0,-f,d[0]+1,f,a.flags.collapsed?[this.round_radius]:[this.round_radius,this.round_radius,0,0]);b.fill();b.shadowColor="transparent"}if(a.onDrawTitleBox)a.onDrawTitleBox(b,f,d,this.ds.scale);else v==e.ROUND_SHAPE||v==e.CIRCLE_SHAPE||v==e.CARD_SHAPE?(x&&(b.fillStyle="black",b.beginPath(),b.arc(.5*f,-.5*f,6,0,2*Math.PI),b.fill()),b.fillStyle=a.boxcolor||e.NODE_DEFAULT_BOXCOLOR,x?b.fillRect(.5*f-5,-.5*f-5,10,10):(b.beginPath(),b.arc(.5* -f,-.5*f,5,0,2*Math.PI),b.fill())):(x&&(b.fillStyle="black",b.fillRect(.5*(f-10)-1,-.5*(f+10)-1,12,12)),b.fillStyle=a.boxcolor||e.NODE_DEFAULT_BOXCOLOR,b.fillRect(.5*(f-10),-.5*(f+10),10,10));b.globalAlpha=k;if(a.onDrawTitleText)a.onDrawTitleText(b,f,d,this.ds.scale,this.title_text_font,c);!x&&(b.font=this.title_text_font,k=String(a.getTitle()))&&(b.fillStyle=c?e.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),f,e.NODE_TITLE_TEXT_Y-f),b.textAlign="left"):(b.textAlign="left",b.fillText(k,f,e.NODE_TITLE_TEXT_Y-f)));a.flags.collapsed||!a.subgraph||a.skip_subgraph_button||(k=e.NODE_TITLE_HEIGHT,r=a.size[0]-k,t=e.isInsideRectangle(this.graph_mouse[0]-a.pos[0],this.graph_mouse[1]-a.pos[1],r+2,-k+2,k-4,k-4),b.fillStyle=t?"#888":"#555",v==e.BOX_SHAPE||x?b.fillRect(r+2,-k+2,k-4,k-4):(b.beginPath(),b.roundRect(r+2,-k+2,k-4,k-4,[4]),b.fill()),b.fillStyle="#333",b.beginPath(),b.moveTo(r+.2*k,.6*-k),b.lineTo(r+ -.8*k,.6*-k),b.lineTo(r+.5*k,.3*-k),b.fill());if(a.onDrawTitle)a.onDrawTitle(b)}if(c){if(a.onBounding)a.onBounding(y);m==e.TRANSPARENT_TITLE&&(y[1]-=f,y[3]+=f);b.lineWidth=1;b.globalAlpha=.8;b.beginPath();v==e.BOX_SHAPE?b.rect(-6+y[0],-6+y[1],12+y[2],12+y[3]):v==e.ROUND_SHAPE||v==e.CARD_SHAPE&&a.flags.collapsed?b.roundRect(-6+y[0],-6+y[1],12+y[2],12+y[3],[2*this.round_radius]):v==e.CARD_SHAPE?b.roundRect(-6+y[0],-6+y[1],12+y[2],12+y[3],[2*this.round_radius,2,2*this.round_radius,2]):v==e.CIRCLE_SHAPE&& -b.arc(.5*d[0],.5*d[1],.5*d[0]+6,0,2*Math.PI);b.strokeStyle=e.NODE_BOX_OUTLINE_COLOR;b.stroke();b.strokeStyle=h;b.globalAlpha=1}};var K=new Float32Array(4),k=new Float32Array(4),m=new Float32Array(2),t=new Float32Array(2);l.prototype.drawConnections=function(a){var b=e.getTime(),d=this.visible_area;K[0]=d[0]-20;K[1]=d[1]-20;K[2]=d[2]+40;K[3]=d[3]+40;a.lineWidth=this.connections_width;a.fillStyle="#AAA";a.strokeStyle="#AAA";a.globalAlpha=this.editor_alpha;d=this.graph._nodes;for(var h=0,f=d.length;h< -f;++h){var c=d[h];if(c.inputs&&c.inputs.length)for(var r=0;rk[2]&&(k[0]+=k[2],k[2]=Math.abs(k[2]));0>k[3]&&(k[1]+=k[3],k[3]=Math.abs(k[3]));if(C(k,K)){var M=v.outputs[l];l=c.inputs[r];if(M&& -l&&(v=M.dir||(v.horizontal?e.DOWN:e.RIGHT),l=l.dir||(c.horizontal?e.UP:e.LEFT),this.renderLink(a,g,n,u,!1,0,null,v,l),u&&u._last_time&&1E3>b-u._last_time)){M=2-.002*(b-u._last_time);var E=a.globalAlpha;a.globalAlpha=E*M;this.renderLink(a,g,n,u,!0,M,"white",v,l);a.globalAlpha=E}}}}}}a.globalAlpha=1};l.prototype.renderLink=function(a,b,d,h,f,c,k,m,v,r){h&&this.visible_links.push(h);!k&&h&&(k=h.color||l.link_type_colors[h.type]);k||(k=this.default_link_color);null!=h&&this.highlighted_links[h.id]&&(k= -"#FFF");m=m||e.RIGHT;v=v||e.LEFT;var x=A(b,d);this.render_connections_border&&.6b[1]?0:Math.PI,a.save(),a.translate(t[0],t[1]),a.rotate(x),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore(),a.save(),a.translate(h[0],h[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(f[0],f[1],5,0,2*Math.PI),a.fill());if(c)for(a.fillStyle=k,t=0;5>t;++t)c=(.001*e.getTime()+.2*t)%1,f=this.computeConnectionPoint(b,d,c,m,v),a.beginPath(),a.arc(f[0],f[1],5,0,2*Math.PI),a.fill()};l.prototype.computeConnectionPoint=function(a,b,d,h,f){h=h||e.RIGHT;f=f||e.LEFT;var c=A(a,b),k=[a[0],a[1]],m=[b[0],b[1]];switch(h){case e.LEFT:k[0]+=-.25*c;break;case e.RIGHT:k[0]+=.25*c;break;case e.UP:k[1]+=-.25*c;break;case e.DOWN:k[1]+=.25*c}switch(f){case e.LEFT:m[0]+= --.25*c;break;case e.RIGHT:m[0]+=.25*c;break;case e.UP:m[1]+=-.25*c;break;case e.DOWN:m[1]+=.25*c}h=(1-d)*(1-d)*(1-d);f=3*(1-d)*(1-d)*d;c=3*(1-d)*d*d;d*=d*d;return[h*a[0]+f*k[0]+c*m[0]+d*b[0],h*a[1]+f*k[1]+c*m[1]+d*b[1]]};l.prototype.drawExecutionOrder=function(a){a.shadowColor="transparent";a.globalAlpha=.25;a.textAlign="center";a.strokeStyle="white";a.globalAlpha=.75;for(var b=this.visible_nodes,d=0;dc||c>E-12||kg.last_y+l||void 0===g.last_y)){h=g.value;switch(g.type){case "button":d.type===e.pointerevents_method+"down"&&(g.callback&&setTimeout(function(){g.callback(g,v,a,b,d)},20),this.dirty_canvas=g.clicked=!0);break;case "slider":r=Math.clamp((c-15)/(E-30),0,1);g.value=g.options.min+(g.options.max-g.options.min)*r;g.callback&&setTimeout(function(){f(g,g.value)},20);this.dirty_canvas=!0;break;case "number":case "combo":h= -g.value;if(d.type==e.pointerevents_method+"move"&&"number"==g.type)g.value+=.1*d.deltaX*(g.options.step||1),null!=g.options.min&&g.valueg.options.max&&(g.value=g.options.max);else if(d.type==e.pointerevents_method+"down"){var H=g.options.values;H&&H.constructor===Function&&(H=g.options.values(g,a));var n=null;"number"!=g.type&&(n=H.constructor===Array?H:Object.keys(H));c=40>c?-1:c>E-40?1:0;if("number"==g.type)g.value+=.1*c*(g.options.step|| -1),null!=g.options.min&&g.valueg.options.max&&(g.value=g.options.max);else if(c)r=-1,this.last_mouseclick=0,r=H.constructor===Object?n.indexOf(String(g.value))+c:n.indexOf(g.value)+c,r>=n.length&&(r=n.length-1),0>r&&(r=0),g.value=H.constructor===Array?H[r]:r;else{var q=H!=n?Object.values(H):H;new e.ContextMenu(q,{scale:Math.max(1,this.ds.scale),event:d,className:"dark",callback:function(a,b,d){H!=n&&(a=q.indexOf(a));this.value=a; -f(this,a);v.dirty_canvas=!0;return!1}.bind(g)},r)}}else d.type==e.pointerevents_method+"up"&&"number"==g.type&&(c=40>c?-1:c>E-40?1:0,200>d.click_time&&0==c&&this.prompt("Value",g.value,function(a){this.value=Number(a);f(this,this.value)}.bind(g),d));h!=g.value&&setTimeout(function(){f(this,this.value)}.bind(g),20);this.dirty_canvas=!0;break;case "toggle":d.type==e.pointerevents_method+"down"&&(g.value=!g.value,setTimeout(function(){f(g,g.value)},20));break;case "string":case "text":d.type==e.pointerevents_method+ -"down"&&this.prompt("Value",g.value,function(a){this.value=a;f(this,a)}.bind(g),d,g.options?g.options.multiline:!1);break;default:g.mouse&&(this.dirty_canvas=g.mouse(d,[c,k],a))}if(h!=g.value){if(a.onWidgetChanged)a.onWidgetChanged(g.name,g.value,h,g);a.graph._version++}return g}}}return null};l.prototype.drawGroups=function(a,b){if(this.graph){a=this.graph._groups;b.save();b.globalAlpha=.5*this.editor_alpha;for(var d=0;dd&&.01>b.editor_alpha&&(clearInterval(h),1>d&&(b.live_mode=!0));1"+(v.label?v.label:m)+""+a+"", -value:m})}if(k.length)return new e.ContextMenu(k,{event:d,callback:function(a,b,d,h){f&&(b=this.getBoundingClientRect(),c.showEditPropertyValue(f,a.value,{position:[b.left,b.top]}))},parentMenu:h,allow_html:!0,node:f},b),!1}};l.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};l.onResizeNode=function(a,b,d,h,f){if(f){f.size=f.computeSize();if(f.onResize)f.onResize(f.size);f.setDirtyCanvas(!0,!0)}};l.prototype.showLinkMenu=function(a,b){var d=this;console.log(a); -var h=new e.ContextMenu(["Add Node",null,"Delete"],{event:b,title:null!=a.data?a.data.constructor.name:null,callback:function(b,c,e){switch(b){case "Add Node":l.onMenuAdd(null,null,e,h,function(b){console.log("node autoconnect");var f=d.graph.getNodeById(a.origin_id),h=d.graph.getNodeById(a.target_id);b.inputs&&b.inputs.length&&b.outputs&&b.outputs.length&&f.outputs[a.origin_slot].type==b.inputs[0].type&&b.outputs[0].type==h.inputs[0].type&&(f.connect(a.origin_slot,b,0),b.connect(0,h,a.target_slot), -b.pos[0]-=.5*b.size[0])});break;case "Delete":d.graph.removeLink(a.id)}}});return!1};l.onShowPropertyEditor=function(a,b,d,h,f){function c(){var b=v.value;"Number"==a.type?b=Number(b):"Boolean"==a.type&&(b=!!b);f[e]=b;k.parentNode&&k.parentNode.removeChild(k);f.setDirtyCanvas(!0,!0)}var e=a.property||"title";b=f[e];var k=document.createElement("div");k.className="graphdialog";k.innerHTML="";k.querySelector(".name").innerText= -e;var v=k.querySelector(".value");v&&(v.value=b,v.addEventListener("blur",function(a){this.focus()}),v.addEventListener("keydown",function(a){if(13==a.keyCode||"textarea"==a.target.localName)c(),a.preventDefault(),a.stopPropagation()}));b=l.active_canvas.canvas;d=b.getBoundingClientRect();var m=h=-20;d&&(h-=d.left,m-=d.top);event?(k.style.left=event.clientX+h+"px",k.style.top=event.clientY+m+"px"):(k.style.left=.5*b.width+h+"px",k.style.top=.5*b.height+m+"px");k.querySelector("button").addEventListener("click", -c);b.parentNode.appendChild(k)};l.prototype.prompt=function(a,b,d,h,f){var c=this;a=a||"";var k=!1,m=document.createElement("div");m.className="graphdialog rounded";m.innerHTML=f?" ":" ";m.close=function(){c.prompt_box=null;m.parentNode&&m.parentNode.removeChild(m)};1l.search_limit)break}}r=null;if(Array.prototype.filter)r=Object.keys(e.registered_node_types).filter(h);else for(k in r=[],e.registered_node_types)h(k)&&r.push(k);for(k=0;kl.search_limit);k++);}}var f=this,c=l.active_canvas,k=c.canvas,m=k.ownerDocument||document,v=document.createElement("div");v.className="litegraph litesearchbox graphdialog rounded";v.innerHTML="Search
"; -v.close=function(){f.search_box=null;m.body.focus();m.body.style.overflow="";setTimeout(function(){f.canvas.focus()},20);v.parentNode&&v.parentNode.removeChild(v)};var r=null;1k.height-200&&(t.style.maxHeight=k.height-a.layerY-20+"px");H.focus();return v};l.prototype.showEditPropertyValue=function(a,b,d){function h(){f(g.value)}function f(f){c&&c.values&&c.values.constructor===Object&&void 0!=c.values[f]&&(f=c.values[f]);"number"==typeof a.properties[b]&&(f=Number(f));if("array"==e||"object"==e)f=JSON.parse(f);a.properties[b]= -f;a.graph&&a.graph._version++;if(a.onPropertyChanged)a.onPropertyChanged(b,f);if(d.onclose)d.onclose();t.close();a.setDirtyCanvas(!0,!0)}if(a&&void 0!==a.properties[b]){d=d||{};var c=a.getPropertyInfo(b),e=c.type,k="";if("string"==e||"number"==e||"array"==e||"object"==e)k="";else if("enum"!=e&&"combo"!=e||!c.values)if("boolean"==e)k="";else{console.warn("unknown type: "+e); -return}else{k=""}var t=this.createDialog(""+(c.label?c.label:b)+""+k+"",d);if("enum"!=e&&"combo"!=e||!c.values)if("boolean"==e)(g=t.querySelector("input"))&&g.addEventListener("click",function(a){f(!!g.checked)});else{if(g=t.querySelector("input"))g.addEventListener("blur", -function(a){this.focus()}),r=void 0!==a.properties[b]?a.properties[b]:"","string"!==e&&(r=JSON.stringify(r)),g.value=r,g.addEventListener("keydown",function(a){13==a.keyCode&&(h(),a.preventDefault(),a.stopPropagation())})}else{var g=t.querySelector("select");g.addEventListener("change",function(a){f(a.target.value)})}t.querySelector("button").addEventListener("click",h);return t}};l.prototype.createDialog=function(a,b){b=b||{};var d=document.createElement("div");d.className="graphdialog";d.innerHTML= -a;a=this.canvas.getBoundingClientRect();var h=-20,f=-20;a&&(h-=a.left,f-=a.top);b.position?(h+=b.position[0],f+=b.position[1]):b.event?(h+=b.event.clientX,f+=b.event.clientY):(h+=.5*this.canvas.width,f+=.5*this.canvas.height);d.style.left=h+"px";d.style.top=f+"px";this.canvas.parentNode.appendChild(d);d.close=function(){this.parentNode&&this.parentNode.removeChild(this)};return d};l.prototype.createPanel=function(a,b){b=b||{};var d=b.window||window,h=document.createElement("div");h.className="litegraph dialog"; -h.innerHTML="
";h.header=h.querySelector(".dialog-header");b.width&&(h.style.width=b.width+(b.width.constructor===Number?"px":""));b.height&&(h.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(){h.close()}),h.header.appendChild(b)); -h.title_element=h.querySelector(".dialog-title");h.title_element.innerText=a;h.content=h.querySelector(".dialog-content");h.footer=h.querySelector(".dialog-footer");h.close=function(){this.parentNode&&this.parentNode.removeChild(this)};h.clear=function(){this.content.innerHTML=""};h.addHTML=function(a,b,d){var f=document.createElement("div");b&&(f.className=b);f.innerHTML=a;d?h.footer.appendChild(f):h.content.appendChild(f);return f};h.addButton=function(a,b,d){var f=document.createElement("button"); -f.innerText=a;f.options=d;f.classList.add("btn");f.addEventListener("click",b);h.footer.appendChild(f);return f};h.addSeparator=function(){var a=document.createElement("div");a.className="separator";h.content.appendChild(a)};h.addWidget=function(a,b,c,k,m){function f(a,b){console.log("change",a,b);k.callback&&k.callback(a,b);m&&m(a,b)}k=k||{};var v=String(c);a=a.toLowerCase();"number"==a&&(v=c.toFixed(3));var r=document.createElement("div");r.className="property";r.innerHTML=""; -r.querySelector(".property_name").innerText=k.label||b;var t=r.querySelector(".property_value");t.innerText=v;r.dataset.property=b;r.dataset.type=k.type||a;r.options=k;r.value=c;if("boolean"==a)r.classList.add("boolean"),c&&r.classList.add("bool-on"),r.addEventListener("click",function(){var a=this.dataset.property;this.value=!this.value;this.classList.toggle("bool-on");this.querySelector(".property_value").innerText=this.value?"true":"false";f(a,this.value)});else if("string"==a||"number"==a)t.setAttribute("contenteditable", -!0),t.addEventListener("keydown",function(a){"Enter"==a.code&&(a.preventDefault(),this.blur())}),t.addEventListener("blur",function(){var a=this.innerText,b=this.parentNode.dataset.property;"number"==this.parentNode.dataset.type&&(a=Number(a));f(b,a)});else if("enum"==a||"combo"==a)v=l.getPropertyPrintableValue(c,k.values),t.innerText=v,t.addEventListener("click",function(a){var b=this.parentNode.dataset.property,h=this;new e.ContextMenu(k.values||[],{event:a,className:"dark",callback:function(a, -d,c){h.innerText=a;f(b,a);return!1}},d)});h.content.appendChild(r);return r};return h};l.getPropertyPrintableValue=function(a,b){if(!b||b.constructor===Array)return String(a);if(b.constructor===Object){var d="",h;for(h in b)if(b[h]==a){d=h;break}return String(a)+" ("+d+")"}};l.prototype.showShowNodePanel=function(a){window.SELECTED_NODE=a;var b=document.querySelector("#node-panel");b&&b.close();var d=this.getCanvasWindow();b=this.createPanel(a.title||"",{closable:!0,window:d});b.id="node-panel";b.node= -a;b.classList.add("settings");var h=this;(function(){b.content.innerHTML="";b.addHTML(""+a.type+""+(a.constructor.desc||"")+"");b.addHTML("

Properties

");for(var d in a.properties){var c=a.properties[d],e=a.getPropertyInfo(d);a.onAddPropertyToPanel&&a.onAddPropertyToPanel(d,b)||b.addWidget(e.widget||e.type,d,c,e,function(b,d){h.graph.beforeChange(a);a.setProperty(b,d);h.graph.afterChange();h.dirty_canvas= -!0})}b.addSeparator();if(a.onShowCustomPanelInfo)a.onShowCustomPanelInfo(b);b.addButton("Delete",function(){a.block_delete||(a.graph.remove(a),b.close())}).classList.add("delete")})();this.canvas.parentNode.appendChild(b)};l.prototype.showSubgraphPropertiesDialog=function(a){function b(){h.clear();if(a.inputs)for(var d=0;d", -"subgraph_property");e.dataset.name=c.name;e.dataset.slot=d;e.querySelector(".name").innerText=c.name;e.querySelector(".type").innerText=c.type;e.querySelector("button").addEventListener("click",function(d){a.removeInput(Number(this.parentNode.dataset.slot));b()})}}}console.log("showing subgraph properties dialog");var d=this.canvas.parentNode.querySelector(".subgraph_dialog");d&&d.close();var h=this.createPanel("Subgraph Inputs",{closable:!0,width:500});h.node=a;h.classList.add("subgraph_dialog"); -h.addHTML(" + NameType","subgraph_property extra",!0).querySelector("button").addEventListener("click",function(d){d=this.parentNode;var f=d.querySelector(".name").value,h=d.querySelector(".type").value;f&&-1==a.findInputSlot(f)&&(a.addInput(f,h),d.querySelector(".name").value="",d.querySelector(".type").value="",b())});b();this.canvas.parentNode.appendChild(h);return h};l.prototype.showSubgraphPropertiesDialogRight= -function(a){function b(){f.clear();if(a.outputs)for(var d=0;d","subgraph_property");c.dataset.name=h.name;c.dataset.slot=d;c.querySelector(".name").innerText=h.name;c.querySelector(".type").innerText=h.type;c.querySelector("button").addEventListener("click",function(d){a.removeOutput(Number(this.parentNode.dataset.slot)); -b()})}}}function d(){var d=this.parentNode,f=d.querySelector(".name").value,h=d.querySelector(".type").value;f&&-1==a.findOutputSlot(f)&&(a.addOutput(f,h),d.querySelector(".name").value="",d.querySelector(".type").value="",b())}var h=this.canvas.parentNode.querySelector(".subgraph_dialog");h&&h.close();var f=this.createPanel("Subgraph Outputs",{closable:!0,width:500});f.node=a;f.classList.add("subgraph_dialog");h=f.addHTML(" + NameType", -"subgraph_property extra",!0);h.querySelector(".name").addEventListener("keydown",function(a){13==a.keyCode&&d.apply(this)});h.querySelector("button").addEventListener("click",function(a){d.apply(this)});b();this.canvas.parentNode.appendChild(f);return f};l.prototype.checkPanels=function(){if(this.canvas)for(var a=this.canvas.parentNode.querySelectorAll(".litegraph.dialog"),b=0;bNo color"});for(var c in l.node_colors)a=l.node_colors[c],a={value:c,content:""+c+""},b.push(a);new e.ContextMenu(b,{event:d,callback:function(a){f&&((a=a.value?l.node_colors[a.value]:null)?f.constructor===e.LGraphGroup?f.color=a.groupcolor:(f.color=a.color,f.bgcolor=a.bgcolor): -(delete f.color,delete f.bgcolor),f.setDirtyCanvas(!0,!0))},parentMenu:h,node:f});return!1};l.onMenuNodeShapes=function(a,b,d,h,f){if(!f)throw"no node passed";new e.ContextMenu(e.VALID_SHAPES,{event:d,callback:function(a){f&&(f.graph.beforeChange(f),f.shape=a,f.graph.afterChange(f),f.setDirtyCanvas(!0))},parentMenu:h,node:f});return!1};l.onMenuNodeRemove=function(a,b,d,h,f){if(!f)throw"no node passed";!1!==f.removable&&(a=f.graph,a.beforeChange(),a.remove(f),a.afterChange(),f.setDirtyCanvas(!0,!0))}; -l.onMenuNodeToSubgraph=function(a,b,d,h,f){a=f.graph;if(b=l.active_canvas)d=Object.values(b.selected_nodes||{}),d.length||(d=[f]),h=e.createNode("graph/subgraph"),h.pos=f.pos.concat(),a.add(h),h.buildFromNodes(d),b.deselectAllNodes(),f.setDirtyCanvas(!0,!0)};l.onMenuNodeClone=function(a,b,d,h,f){0!=f.clonable&&(a=f.clone())&&(a.pos=[f.pos[0]+5,f.pos[1]+5],f.graph.beforeChange(),f.graph.add(a),f.graph.afterChange(),f.setDirtyCanvas(!0,!0))};l.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"}};l.prototype.getCanvasMenuOptions=function(){if(this.getMenuOptions)var a= -this.getMenuOptions();else a=[{content:"Add Node",has_submenu:!0,callback:l.onMenuAdd},{content:"Add Group",callback:l.onGroupAdd}],this._graph_stack&&0Name",f),k=e.querySelector("input");k&&c&&(k.value=c.label||"");e.querySelector("button").addEventListener("click",function(a){k.value&& -(c&&(c.label=k.value),d.setDirty(!0));e.close()})}},extra:a};a&&(c.title=a.type);var k=null;a&&(k=a.getSlotInPosition(b.canvasX,b.canvasY),l.active_node=a);k?(f=[],a.getSlotMenuOptions?f=a.getSlotMenuOptions(k):(k&&k.output&&k.output.links&&k.output.links.length&&f.push({content:"Disconnect Links",slot:k}),b=k.input||k.output,f.push(b.locked||!b.removable?"Cannot remove":{content:"Remove Slot",slot:k}),f.push(b.nameLocked?"Cannot rename":{content:"Rename Slot",slot:k})),c.title=(k.input?k.input.type: -k.output.type)||"*",k.input&&k.input.type==e.ACTION&&(c.title="Action"),k.output&&k.output.type==e.EVENT&&(c.title="Event")):a?f=this.getNodeMenuOptions(a):(f=this.getCanvasMenuOptions(),(k=this.graph.getGroupOnPos(b.canvasX,b.canvasY))&&f.push(null,{content:"Edit Group",has_submenu:!0,submenu:{title:"Group",extra:k,options:this.getGroupMenuOptions(k)}}));f&&new e.ContextMenu(f,c,h)};"undefined"!=typeof window&&window.CanvasRenderingContext2D&&!window.CanvasRenderingContext2D.prototype.roundRect&& -(window.CanvasRenderingContext2D.prototype.roundRect=function(a,b,d,h,f,c){var e,k;if(0===f)this.rect(a,b,d,h);else{void 0===c&&(c=f);if(null!=f&&f.constructor===Array)if(1==f.length)var m=e=k=c=f[0];else if(2==f.length)m=c=f[0],e=k=f[1];else if(4==f.length)m=f[0],e=f[1],k=f[2],c=f[3];else return;else m=f||0,e=f||0,k=c||0,c=c||0;this.moveTo(a+m,b);this.lineTo(a+d-e,b);this.quadraticCurveTo(a+d,b,a+d,b+e);this.lineTo(a+d,b+h-c);this.quadraticCurveTo(a+d,b+h,a+d-c,b+h);this.lineTo(a+c,b+h);this.quadraticCurveTo(a, -b+h,a,b+h-k);this.lineTo(a,b+k);this.quadraticCurveTo(a,b,a+m,b)}});e.compareObjects=function(a,b){for(var d in a)if(a[d]!=b[d])return!1;return!0};e.distance=A;e.colorToString=function(a){return"rgba("+Math.round(255*a[0]).toFixed()+","+Math.round(255*a[1]).toFixed()+","+Math.round(255*a[2]).toFixed()+","+(4==a.length?a[3].toFixed(2):"1.0")+")"};e.isInsideRectangle=B;e.growBounding=function(a,b,d){ba[2]&&(a[2]=b);da[3]&&(a[3]=d)};e.isInsideBounding=function(a,b){return a[0]< -b[0][0]||a[1]b[1][0]||a[1]>b[1][1]?!1:!0};e.overlapBounding=C;e.hex2num=function(a){"#"==a.charAt(0)&&(a=a.slice(1));a=a.toUpperCase();for(var b=Array(3),d=0,c,f,e=0;6>e;e+=2)c="0123456789ABCDEF".indexOf(a.charAt(e)),f="0123456789ABCDEF".indexOf(a.charAt(e+1)),b[d]=16*c+f,d++;return b};e.num2hex=function(a){for(var b="#",d,c,f=0;3>f;f++)d=a[f]/16,c=a[f]%16,b+="0123456789ABCDEF".charAt(d)+"0123456789ABCDEF".charAt(c);return b};G.prototype.addItem=function(a,b,d){function c(a){var b= -this.value;b&&b.has_submenu&&f.call(this,a)}function f(a){var b=this.value,c=!0;k.current_submenu&&k.current_submenu.close(a);if(d.callback){var f=d.callback.call(this,b,d,a,k,d.node);!0===f&&(c=!1)}if(b&&(b.callback&&!d.ignore_item_callbacks&&!0!==b.disabled&&(f=b.callback.call(this,b,d,a,k,d.extra),!0===f&&(c=!1)),b.submenu)){if(!b.submenu.options)throw"ContextMenu submenu needs options";new k.constructor(b.submenu.options,{callback:b.submenu.callback,event:a,parentMenu:k,ignore_item_callbacks:b.submenu.ignore_item_callbacks, -title:b.submenu.title,extra:b.submenu.extra,autoopen:d.autoopen});c=!1}c&&!k.lock&&k.close()}var k=this;d=d||{};var m=document.createElement("div");m.className="litemenu-entry submenu";var r=!1;if(null===b)m.classList.add("separator");else{m.innerHTML=b&&b.title?b.title:a;if(m.value=b)b.disabled&&(r=!0,m.classList.add("disabled")),(b.submenu||b.has_submenu)&&m.classList.add("has_submenu");"function"==typeof b?(m.dataset.value=a,m.onclick_callback=b):m.dataset.value=b;b.className&&(m.className+=" "+ -b.className)}this.root.appendChild(m);r||m.addEventListener("click",f);d.autoopen&&e.pointerListenerAdd(m,"enter",c);return m};G.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&&!G.isCursorOverElement(a,this.parentMenu.root)&&G.trigger(this.parentMenu.root,e.pointerevents_method+"leave",a));this.current_submenu&&this.current_submenu.close(a, -!0);this.root.closing_timer&&clearTimeout(this.root.closing_timer)};G.trigger=function(a,b,d,c){var f=document.createEvent("CustomEvent");f.initCustomEvent(b,!0,!0,d);f.srcElement=c;a.dispatchEvent?a.dispatchEvent(f):a.__events&&a.__events.dispatchEvent(f);return f};G.prototype.getTopMenu=function(){return this.options.parentMenu?this.options.parentMenu.getTopMenu():this};G.prototype.getFirstEvent=function(){return this.options.parentMenu?this.options.parentMenu.getFirstEvent():this.options.event}; -G.isCursorOverElement=function(a,b){var d=a.clientX;a=a.clientY;return(b=b.getBoundingClientRect())?a>b.top&&ab.left&&dMath.abs(b))return c[1];a=(a-c[0])/b;return c[1]*(1- -a)+f[1]*a}}return 0}};D.prototype.draw=function(a,b,d,c,f,e){if(d=this.points){this.size=b;var h=b[0]-2*this.margin;b=b[1]-2*this.margin;f=f||"#666";a.save();a.translate(this.margin,this.margin);c&&(a.fillStyle="#111",a.fillRect(0,0,h,b),a.fillStyle="#222",a.fillRect(.5*h,0,1,b),a.strokeStyle="#333",a.strokeRect(0,0,h,b));a.strokeStyle=f;e&&(a.globalAlpha=.5);a.beginPath();for(c=0;ca[1])){var c=this.size[0]-2*this.margin,f=this.size[1]-2*this.margin,e=a[0]-this.margin;a=a[1]-this.margin;this.selected=this.getCloserPoint([e,a],30/b.ds.scale);-1==this.selected&&(b=[e/c,1-a/f],d.push(b),d.sort(function(a,b){return a[0]-b[0]}),this.selected=d.indexOf(b),this.must_update=!0);if(-1!=this.selected)return!0}}; -D.prototype.onMouseMove=function(a,b){var d=this.points;if(d){var c=this.selected;if(!(0>c)){var f=(a[0]-this.margin)/(this.size[0]-2*this.margin),e=(a[1]-this.margin)/(this.size[1]-2*this.margin);this._nearest=this.getCloserPoint([a[0]-this.margin,a[1]-this.margin],30/b.ds.scale);if(b=d[c]){var k=0==c||c==d.length-1;!k&&(-10>a[0]||a[0]>this.size[0]+10||-10>a[1]||a[1]>this.size[1]+10)?(d.splice(c,1),this.selected=-1):(b[0]=k?0==c?0:1:Math.clamp(f,0,1),b[1]=1-Math.clamp(e,0,1),d.sort(function(a,b){return a[0]- -b[0]}),this.selected=d.indexOf(b),this.must_update=!0)}}}};D.prototype.onMouseUp=function(a,b){this.selected=-1;return!1};D.prototype.getCloserPoint=function(a,b){var d=this.points;if(!d)return-1;b=b||30;for(var c=this.size[0]-2*this.margin,f=this.size[1]-2*this.margin,e=d.length,k=[0,0],m=1E6,r=-1,t=0;tm||g>b||(r=t,m=g)}return r};e.CurveEditor=D;e.getParameterNames=function(a){return(a+"").replace(/[/][/].*$/gm,"").replace(/\s+/g, -"").replace(/[/][*][^/*]*[*][/]/g,"").split("){",1)[0].replace(/^[^(]*[(]/,"").replace(/=[^,]+/g,"").split(",").filter(Boolean)};e.pointerListenerAdd=function(a,b,d,c){c=void 0===c?!1:c;if(a&&a.addEventListener&&b&&"function"===typeof d)switch(b){case "down":case "up":case "move":case "over":case "out":case "enter":a.addEventListener(e.pointerevents_method+b,d,c);case "leave":case "cancel":case "gotpointercapture":case "lostpointercapture":if("mouse"!=e.pointerevents_method)return a.addEventListener(e.pointerevents_method+ -b,d,c);default:return a.addEventListener(b,d,c)}else console.log("cant pointerListenerAdd "+a+", "+b+", "+d)};e.pointerListenerRemove=function(a,b,d,c){c=void 0===c?!1:c;if(a&&a.removeEventListener&&b&&"function"===typeof d)switch(b){case "down":case "up":case "move":case "over":case "out":case "enter":a.removeEventListener(e.pointerevents_method+b,d,c);case "leave":case "cancel":case "gotpointercapture":case "lostpointercapture":if("mouse"!=e.pointerevents_method)return a.removeEventListener(e.pointerevents_method+ -b,d,c);default:return a.removeEventListener(b,d,c)}else console.log("cant pointerListenerRemove "+a+", "+b+", "+d)};Math.clamp=function(a,b,d){return b>a?b:da&&(b[0]=this.viewport[0]&&g=this.viewport[1]&&fe.getTime()-this.last_mouseclick&&void 0!==a.isPrimary&&a.isPrimary;this.mouse[0]=a.clientX;this.mouse[1]=a.clientY;this.graph_mouse[0]=a.canvasX;this.graph_mouse[1]=a.canvasY;this.last_click_position=[this.mouse[0],this.mouse[1]];this.pointer_is_double=this.pointer_is_down&&void 0!==a.isPrimary&&!a.isPrimary?!0:!1;this.pointer_is_down=!0;this.canvas.focus();e.closeAllContextMenus(b); +if(!this.onMouse||1!=this.onMouse(a)){if(1!=a.which||this.pointer_is_double)if(2==a.which){if(e.middle_click_slot_add_default_node&&m&&this.allow_interaction&&!g&&!this.read_only&&!this.connecting_node&&!m.flags.collapsed&&!this.live_mode){f=g=u=!1;if(m.outputs)for(C=0,c=m.outputs.length;Cm.size[0]-e.NODE_TITLE_HEIGHT&&0>c[1]&&(d=this,setTimeout(function(){d.openSubgraph(m.subgraph)},10)),this.live_mode&&(C=u=!0));C||(this.allow_dragnodes&&(this.graph.beforeChange(),this.node_dragged=m),this.selected_nodes[m.id]||this.processNodeSelected(m,a));this.dirty_canvas=!0}}else if(!g){if(!this.read_only)for(C= +0;Cc[0]+4||a.canvasYc[1]+4)){this.showLinkMenu(u,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());f&&!this.read_only&&this.allow_searchbox&&(this.showSearchBox(a),a.preventDefault(),a.stopPropagation());u=!0}!g&&u&&this.allow_dragcanvas&&(this.dragging_canvas=!0)}this.last_mouse[0]=a.clientX;this.last_mouse[1]=a.clientY;this.last_mouseclick=e.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 d=[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(d[0]/this.ds.scale,d[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]+=d[0]/this.ds.scale,this.ds.offset[1]+=d[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 g=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes);b=0;for(var f=this.graph._nodes.length;b< +f;++b)if(this.graph._nodes[b].mouseOver&&g!=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(g){g.redraw_on_mouse&&(this.dirty_canvas=!0);if(!g.mouseOver&&(g.mouseOver=!0,this.node_over=g,this.dirty_canvas=!0,g.onMouseEnter))g.onMouseEnter(a);if(g.onMouseMove)g.onMouseMove(a,[a.canvasX-g.pos[0],a.canvasY-g.pos[1]],this);if(this.connecting_node)if(this.connecting_output){if(f= +this._highlight_input||[0,0],!this.isOverNodeBox(g,a.canvasX,a.canvasY)){var m=this.isOverNodeInput(g,a.canvasX,a.canvasY,f);if(-1!=m&&g.inputs[m]){var c=g.inputs[m].type;e.isValidConnection(this.connecting_output.type,c)&&(this._highlight_input=f,this._highlight_input_slot=g.inputs[m])}else this._highlight_input_slot=this._highlight_input=null}}else this.connecting_input&&(f=this._highlight_output||[0,0],this.isOverNodeBox(g,a.canvasX,a.canvasY)||(m=this.isOverNodeOutput(g,a.canvasX,a.canvasY,f), +-1!=m&&g.outputs[m]?(c=g.outputs[m].type,e.isValidConnection(this.connecting_input.type,c)&&(this._highlight_output=f)):this._highlight_output=null));this.canvas&&(A(a.canvasX,a.canvasY,g.pos[0]+g.size[0]-5,g.pos[1]+g.size[1]-5,5,5)?this.canvas.style.cursor="se-resize":this.canvas.style.cursor="crosshair")}else{f=null;for(b=0;bc[0]+4||a.canvasYc[1]+4)){f=m;break}f!=this.over_link_center&& +(this.over_link_center=f,this.dirty_canvas=!0);this.canvas&&(this.canvas.style.cursor="")}if(this.node_capturing_input&&this.node_capturing_input!=g&&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)g=this.selected_nodes[b],g.pos[0]+=d[0]/this.ds.scale,g.pos[1]+=d[1]/this.ds.scale;this.dirty_bgcanvas=this.dirty_canvas= +!0}this.resizing_node&&!this.live_mode&&(d=[a.canvasX-this.resizing_node.pos[0],a.canvasY-this.resizing_node.pos[1]],b=this.resizing_node.computeSize(),d[0]=Math.max(b[0],d[0]),d[1]=Math.max(b[1],d[1]),this.resizing_node.setSize(d),this.canvas.style.cursor="se-resize",this.dirty_bgcanvas=this.dirty_canvas=!0)}a.preventDefault();return!1}};h.prototype.processMouseUp=function(a){if(void 0!==a.isPrimary&&!a.isPrimary)return!1;this.set_canvas_dirty_on_mouse_event&&(this.dirty_canvas=!0);if(this.graph){var b= +this.getCanvasWindow().document;h.active_canvas=this;this.options.skip_events||(e.pointerListenerRemove(b,"move",this._mousemove_callback,!0),e.pointerListenerAdd(this.canvas,"move",this._mousemove_callback,!0),e.pointerListenerRemove(b,"up",this._mouseup_callback,!0));this.adjustMouseEvent(a);b=e.getTime();a.click_time=b-this.last_mouseclick;this.last_mouse_dragging=!1;this.last_click_position=null;this.block_click&&(this.block_click=!1);if(1==a.which){this.node_widget&&this.processNodeWidgets(this.node_widget[0], +this.graph_mouse,a);this.node_widget=null;this.selected_group&&(this.selected_group.move(this.selected_group.pos[0]-Math.round(this.selected_group.pos[0]),this.selected_group.pos[1]-Math.round(this.selected_group.pos[1]),a.ctrlKey),this.selected_group.pos[0]=Math.round(this.selected_group.pos[0]),this.selected_group.pos[1]=Math.round(this.selected_group.pos[1]),this.selected_group._nodes.length&&(this.dirty_canvas=!0),this.selected_group=null);this.selected_group_resizing=!1;var d=this.graph.getNodeOnPos(a.canvasX, +a.canvasY,this.visible_nodes);if(this.dragging_rectangle){if(this.graph){b=this.graph._nodes;var g=new Float32Array(4),f=Math.abs(this.dragging_rectangle[2]),m=Math.abs(this.dragging_rectangle[3]),c=0>this.dragging_rectangle[3]?this.dragging_rectangle[1]-m:this.dragging_rectangle[1];this.dragging_rectangle[0]=0>this.dragging_rectangle[2]?this.dragging_rectangle[0]-f:this.dragging_rectangle[0];this.dragging_rectangle[1]=c;this.dragging_rectangle[2]=f;this.dragging_rectangle[3]=m;if(!d||10a.click_time&&A(a.canvasX,a.canvasY,d.pos[0],d.pos[1]-e.NODE_TITLE_HEIGHT,e.NODE_TITLE_HEIGHT,e.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);void 0!==a.isPrimary&&a.isPrimary&&(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 d=a.clientX,g=a.clientY; +if(!this.viewport||this.viewport&&d>=this.viewport[0]&&d=this.viewport[1]&&gb&&(d*=1/1.1),this.ds.changeScale(d,[a.clientX,a.clientY]),this.graph.change(),a.preventDefault(),!1}};h.prototype.isOverNodeBox=function(a,b,d){var g=e.NODE_TITLE_HEIGHT;return A(b,d,a.pos[0]+2,a.pos[1]+2-g,g-4,g-4)?!0:!1};h.prototype.isOverNodeInput=function(a,b,d,g){if(a.inputs)for(var f=0,e=a.inputs.length;fa.nodes[g].pos[0]&&(b[0]=a.nodes[g].pos[0],d[0]=g),b[1]>a.nodes[g].pos[1]&&(b[1]=a.nodes[g].pos[1],d[1]=g)):(b=[a.nodes[g].pos[0],a.nodes[g].pos[1]],d=[g,g]);d=[];for(g=0;g=this.viewport[0]&&b=this.viewport[1]&&dd-this.graph._last_trigger_time)&&this.drawBackCanvas();(this.dirty_canvas||a)&&this.drawFrontCanvas();this.fps=this.render_time? +1/this.render_time:0;this.frame+=1}};h.prototype.drawFrontCanvas=function(){this.dirty_canvas=!1;this.ctx||(this.ctx=this.bgcanvas.getContext("2d"));var a=this.ctx;if(a){var b=this.canvas;a.start2D&&!this.viewport&&(a.start2D(),a.restore(),a.setTransform(1,0,0,1,0,0));var d=this.viewport||this.dirty_area;d&&(a.save(),a.beginPath(),a.rect(d[0],d[1],d[2],d[3]),a.clip());this.clear_background&&(d?a.clearRect(d[0],d[1],d[2],d[3]):a.clearRect(0,0,b.width,b.height));this.bgcanvas==this.canvas?this.drawBackCanvas(): +a.drawImage(this.bgcanvas,0,0);if(this.onRender)this.onRender(b,a);this.show_info&&this.renderInfo(a,d?d[0]:0,d?d[1]:0);if(this.graph){a.save();this.ds.toCanvasContext(a);b=this.computeVisibleNodes(null,this.visible_nodes);for(var g=0;g> ";b.fillText(g+d.getTitle(),.5*a.width,40);b.restore()}d=!1;this.onRenderBackground&&(d=this.onRenderBackground(a,b));this.viewport||(b.restore(),b.setTransform(1,0,0,1,0,0));this.visible_links.length=0;if(this.graph){b.save();this.ds.toCanvasContext(b);if(this.background_image&&.5this.ds.scale;if(this.live_mode){if(!a.flags.collapsed&&(b.shadowColor= +"transparent",a.onDrawForeground))a.onDrawForeground(b,this,this.canvas)}else{var m=this.editor_alpha;b.globalAlpha=m;this.render_shadows&&!f?(b.shadowColor=e.DEFAULT_SHADOW_COLOR,b.shadowOffsetX=2*this.ds.scale,b.shadowOffsetY=2*this.ds.scale,b.shadowBlur=3*this.ds.scale):b.shadowColor="transparent";if(!a.flags.collapsed||!a.onDrawCollapsed||1!=a.onDrawCollapsed(b,this)){var c=a._shape||e.BOX_SHAPE;H.set(a.size);var k=a.horizontal;if(a.flags.collapsed){b.font=this.inner_text_font;var q=a.getTitle? +a.getTitle():a.title;null!=q&&(a._collapsed_width=Math.min(a.size[0],b.measureText(q).width+2*e.NODE_TITLE_HEIGHT),H[0]=a._collapsed_width,H[1]=0)}a.clip_area&&(b.save(),b.beginPath(),c==e.BOX_SHAPE?b.rect(0,0,H[0],H[1]):c==e.ROUND_SHAPE?b.roundRect(0,0,H[0],H[1],[10]):c==e.CIRCLE_SHAPE&&b.arc(.5*H[0],.5*H[1],.5*H[0],0,2*Math.PI),b.clip());a.has_errors&&(g="red");this.drawNodeShape(a,b,H,d,g,a.is_selected,a.mouseOver);b.shadowColor="transparent";if(a.onDrawForeground)a.onDrawForeground(b,this,this.canvas); +b.textAlign=k?"center":"left";b.font=this.inner_text_font;g=!f;var x=this.connecting_output;c=this.connecting_input;b.lineWidth=1;q=0;var C=new Float32Array(2);if(!a.flags.collapsed){if(a.inputs)for(d=0;dthis.ds.scale,k=a._shape||a.constructor.shape||e.ROUND_SHAPE,x=a.constructor.title_mode,C=!0;x==e.TRANSPARENT_TITLE||x==e.NO_TITLE?C=!1:x==e.AUTOHIDE_TITLE&&c&&(C=!0);z[0]=0;z[1]=C?-f:0;z[2]=d[0]+1;z[3]=C?d[1]+f:d[1];c=b.globalAlpha;b.beginPath(); +k==e.BOX_SHAPE||u?b.fillRect(z[0],z[1],z[2],z[3]):k==e.ROUND_SHAPE||k==e.CARD_SHAPE?b.roundRect(z[0],z[1],z[2],z[3],k==e.CARD_SHAPE?[this.round_radius,this.round_radius,0,0]:[this.round_radius]):k==e.CIRCLE_SHAPE&&b.arc(.5*d[0],.5*d[1],.5*d[0],0,2*Math.PI);b.fill();!a.flags.collapsed&&C&&(b.shadowColor="transparent",b.fillStyle="rgba(0,0,0,0.2)",b.fillRect(0,-1,z[2],2));b.shadowColor="transparent";if(a.onDrawBackground)a.onDrawBackground(b,this,this.canvas,this.graph_mouse);if(C||x==e.TRANSPARENT_TITLE){if(a.onDrawTitleBar)a.onDrawTitleBar(b, +f,d,this.ds.scale,g);else if(x!=e.TRANSPARENT_TITLE&&(a.constructor.title_color||this.render_title_colored)){C=a.constructor.title_color||g;a.flags.collapsed&&(b.shadowColor=e.DEFAULT_SHADOW_COLOR);if(this.use_gradients){var w=h.gradients[C];w||(w=h.gradients[C]=b.createLinearGradient(0,0,400,0),w.addColorStop(0,C),w.addColorStop(1,"#000"));b.fillStyle=w}else b.fillStyle=C;b.beginPath();k==e.BOX_SHAPE||u?b.rect(0,-f,d[0]+1,f):(k==e.ROUND_SHAPE||k==e.CARD_SHAPE)&&b.roundRect(0,-f,d[0]+1,f,a.flags.collapsed? +[this.round_radius]:[this.round_radius,this.round_radius,0,0]);b.fill();b.shadowColor="transparent"}C=!1;e.node_box_coloured_by_mode&&e.NODE_MODES_COLORS[a.mode]&&(C=e.NODE_MODES_COLORS[a.mode]);e.node_box_coloured_when_on&&(C=a.action_triggered?"#FFF":a.execute_triggered?"#AAA":C);if(a.onDrawTitleBox)a.onDrawTitleBox(b,f,d,this.ds.scale);else k==e.ROUND_SHAPE||k==e.CIRCLE_SHAPE||k==e.CARD_SHAPE?(u&&(b.fillStyle="black",b.beginPath(),b.arc(.5*f,-.5*f,6,0,2*Math.PI),b.fill()),b.fillStyle=a.boxcolor|| +C||e.NODE_DEFAULT_BOXCOLOR,u?b.fillRect(.5*f-5,-.5*f-5,10,10):(b.beginPath(),b.arc(.5*f,-.5*f,5,0,2*Math.PI),b.fill())):(u&&(b.fillStyle="black",b.fillRect(.5*(f-10)-1,-.5*(f+10)-1,12,12)),b.fillStyle=a.boxcolor||C||e.NODE_DEFAULT_BOXCOLOR,b.fillRect(.5*(f-10),-.5*(f+10),10,10));b.globalAlpha=c;if(a.onDrawTitleText)a.onDrawTitleText(b,f,d,this.ds.scale,this.title_text_font,m);!u&&(b.font=this.title_text_font,c=String(a.getTitle()))&&(b.fillStyle=m?e.NODE_SELECTED_TITLE_COLOR:a.constructor.title_text_color|| +this.node_title_color,a.flags.collapsed?(b.textAlign="left",b.measureText(c),b.fillText(c.substr(0,20),f,e.NODE_TITLE_TEXT_Y-f),b.textAlign="left"):(b.textAlign="left",b.fillText(c,f,e.NODE_TITLE_TEXT_Y-f)));a.flags.collapsed||!a.subgraph||a.skip_subgraph_button||(c=e.NODE_TITLE_HEIGHT,C=a.size[0]-c,w=e.isInsideRectangle(this.graph_mouse[0]-a.pos[0],this.graph_mouse[1]-a.pos[1],C+2,-c+2,c-4,c-4),b.fillStyle=w?"#888":"#555",k==e.BOX_SHAPE||u?b.fillRect(C+2,-c+2,c-4,c-4):(b.beginPath(),b.roundRect(C+ +2,-c+2,c-4,c-4,[4]),b.fill()),b.fillStyle="#333",b.beginPath(),b.moveTo(C+.2*c,.6*-c),b.lineTo(C+.8*c,.6*-c),b.lineTo(C+.5*c,.3*-c),b.fill());if(a.onDrawTitle)a.onDrawTitle(b)}if(m){if(a.onBounding)a.onBounding(z);x==e.TRANSPARENT_TITLE&&(z[1]-=f,z[3]+=f);b.lineWidth=1;b.globalAlpha=.8;b.beginPath();k==e.BOX_SHAPE?b.rect(-6+z[0],-6+z[1],12+z[2],12+z[3]):k==e.ROUND_SHAPE||k==e.CARD_SHAPE&&a.flags.collapsed?b.roundRect(-6+z[0],-6+z[1],12+z[2],12+z[3],[2*this.round_radius]):k==e.CARD_SHAPE?b.roundRect(-6+ +z[0],-6+z[1],12+z[2],12+z[3],[2*this.round_radius,2,2*this.round_radius,2]):k==e.CIRCLE_SHAPE&&b.arc(.5*d[0],.5*d[1],.5*d[0]+6,0,2*Math.PI);b.strokeStyle=e.NODE_BOX_OUTLINE_COLOR;b.stroke();b.strokeStyle=g;b.globalAlpha=1}0k[2]&&(k[0]+=k[2],k[2]=Math.abs(k[2]));0>k[3]&&(k[1]+=k[3],k[3]=Math.abs(k[3]));if(I(k,M)){var L=D.outputs[x];x=c.inputs[u];if(L&&x&&(D=L.dir||(D.horizontal?e.DOWN:e.RIGHT),x=x.dir||(c.horizontal?e.UP:e.LEFT),this.renderLink(a,C,w,h,!1,0,null,D,x),h&&h._last_time&&1E3>b-h._last_time)){L=2-.002*(b-h._last_time);var G=a.globalAlpha;a.globalAlpha=G*L;this.renderLink(a,C,w,h,!0,L,"white",D,x);a.globalAlpha=G}}}}}}a.globalAlpha=1};h.prototype.renderLink= +function(a,b,d,g,f,c,u,k,q,x){g&&this.visible_links.push(g);!u&&g&&(u=g.color||h.link_type_colors[g.type]);u||(u=this.default_link_color);null!=g&&this.highlighted_links[g.id]&&(u="#FFF");k=k||e.RIGHT;q=q||e.LEFT;var m=E(b,d);this.render_connections_border&&.6b[1]? +0:Math.PI,a.save(),a.translate(w[0],w[1]),a.rotate(m),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore(),a.save(),a.translate(g[0],g[1]),a.rotate(x),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore()),a.beginPath(),a.arc(f[0],f[1],5,0,2*Math.PI),a.fill());if(c)for(a.fillStyle=u,w=0;5>w;++w)c=(.001*e.getTime()+.2*w)%1,f=this.computeConnectionPoint(b,d,c,k,q),a.beginPath(),a.arc(f[0],f[1],5,0,2*Math.PI),a.fill()};h.prototype.computeConnectionPoint= +function(a,b,d,g,f){g=g||e.RIGHT;f=f||e.LEFT;var c=E(a,b),u=[a[0],a[1]],k=[b[0],b[1]];switch(g){case e.LEFT:u[0]+=-.25*c;break;case e.RIGHT:u[0]+=.25*c;break;case e.UP:u[1]+=-.25*c;break;case e.DOWN:u[1]+=.25*c}switch(f){case e.LEFT:k[0]+=-.25*c;break;case e.RIGHT:k[0]+=.25*c;break;case e.UP:k[1]+=-.25*c;break;case e.DOWN:k[1]+=.25*c}g=(1-d)*(1-d)*(1-d);f=3*(1-d)*(1-d)*d;c=3*(1-d)*d*d;d*=d*d;return[g*a[0]+f*u[0]+c*k[0]+d*b[0],g*a[1]+f*u[1]+c*k[1]+d*b[1]]};h.prototype.drawExecutionOrder=function(a){a.shadowColor= +"transparent";a.globalAlpha=.25;a.textAlign="center";a.strokeStyle="white";a.globalAlpha=.75;for(var b=this.visible_nodes,d=0;dc||c>G-12||kw.last_y+L||void 0===w.last_y)){g=w.value;switch(w.type){case "button":d.type===e.pointerevents_method+"down"&&(w.callback&&setTimeout(function(){w.callback(w, +n,a,b,d)},20),this.dirty_canvas=w.clicked=!0);break;case "slider":x=Math.clamp((c-15)/(G-30),0,1);w.value=w.options.min+(w.options.max-w.options.min)*x;w.callback&&setTimeout(function(){f(w,w.value)},20);this.dirty_canvas=!0;break;case "number":case "combo":g=w.value;if(d.type==e.pointerevents_method+"move"&&"number"==w.type)w.value+=.1*d.deltaX*(w.options.step||1),null!=w.options.min&&w.valuew.options.max&&(w.value=w.options.max); +else if(d.type==e.pointerevents_method+"down"){var y=w.options.values;y&&y.constructor===Function&&(y=w.options.values(w,a));var D=null;"number"!=w.type&&(D=y.constructor===Array?y:Object.keys(y));c=40>c?-1:c>G-40?1:0;if("number"==w.type)w.value+=.1*c*(w.options.step||1),null!=w.options.min&&w.valuew.options.max&&(w.value=w.options.max);else if(c)x=-1,this.last_mouseclick=0,x=y.constructor===Object?D.indexOf(String(w.value))+c:D.indexOf(w.value)+ +c,x>=D.length&&(x=D.length-1),0>x&&(x=0),w.value=y.constructor===Array?y[x]:x;else{var h=y!=D?Object.values(y):y;new e.ContextMenu(h,{scale:Math.max(1,this.ds.scale),event:d,className:"dark",callback:function(a,b,d){y!=D&&(a=h.indexOf(a));this.value=a;f(this,a);n.dirty_canvas=!0;return!1}.bind(w)},x)}}else d.type==e.pointerevents_method+"up"&&"number"==w.type&&(c=40>c?-1:c>G-40?1:0,200>d.click_time&&0==c&&this.prompt("Value",w.value,function(a){this.value=Number(a);f(this,this.value)}.bind(w),d)); +g!=w.value&&setTimeout(function(){f(this,this.value)}.bind(w),20);this.dirty_canvas=!0;break;case "toggle":d.type==e.pointerevents_method+"down"&&(w.value=!w.value,setTimeout(function(){f(w,w.value)},20));break;case "string":case "text":d.type==e.pointerevents_method+"down"&&this.prompt("Value",w.value,function(a){this.value=a;f(this,a)}.bind(w),d,w.options?w.options.multiline:!1);break;default:w.mouse&&(this.dirty_canvas=w.mouse(d,[c,k],a))}if(g!=w.value){if(a.onWidgetChanged)a.onWidgetChanged(w.name, +w.value,g,w);a.graph._version++}return w}}}return null};h.prototype.drawGroups=function(a,b){if(this.graph){a=this.graph._groups;b.save();b.globalAlpha=.5*this.editor_alpha;for(var d=0;dd&&.01>b.editor_alpha&&(clearInterval(g),1>d&&(b.live_mode=!0));1"+(n.label?n.label:q)+""+a+"",value:q})}if(k.length)return new e.ContextMenu(k,{event:d,callback:function(a,b,d,g){f&&(b=this.getBoundingClientRect(),c.showEditPropertyValue(f,a.value,{position:[b.left,b.top]}))},parentMenu:g,allow_html:!0,node:f},b),!1}};h.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};h.onMenuResizeNode=function(a,b,d,g,f){if(f){a= +function(a){a.size=a.computeSize();if(a.onResize)a.onResize(a.size)};b=h.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)a(f);else for(var e in b.selected_nodes)a(b.selected_nodes[e]);f.setDirtyCanvas(!0,!0)}};h.prototype.showLinkMenu=function(a,b){var d=this,g=d.graph.getNodeById(a.origin_id),f=d.graph.getNodeById(a.target_id),c=!1;g&&g.outputs&&g.outputs[a.origin_slot]&&(c=g.outputs[a.origin_slot].type);var k=!1;f&&f.outputs&&f.outputs[a.target_slot]&&(k=f.inputs[a.target_slot].type); +var q=new e.ContextMenu(["Add Node",null,"Delete",null],{event:b,title:null!=a.data?a.data.constructor.name:null,callback:function(b,e,m){switch(b){case "Add Node":h.onMenuAdd(null,null,m,q,function(b){b.inputs&&b.inputs.length&&b.outputs&&b.outputs.length&&g.connectByType(a.origin_slot,b,c)&&(b.connectByType(a.target_slot,f,k),b.pos[0]-=.5*b.size[0])});break;case "Delete":d.graph.removeLink(a.id)}}});return!1};h.prototype.createDefaultNodeForSlot=function(a){a=a||{};a=Object.assign({nodeFrom:null, +slotFrom:null,nodeTo:null,slotTo:null,position:[],nodeType:null,posAdd:[0,0],posSizeFix:[0,0]},a);var b=a.nodeFrom&&null!==a.slotFrom,d=!b&&a.nodeTo&&null!==a.slotTo;if(!b&&!d)return console.warn("No data passed to createDefaultNodeForSlot "+a.nodeFrom+" "+a.slotFrom+" "+a.nodeTo+" "+a.slotTo),!1;if(!a.nodeType)return console.warn("No type to createDefaultNodeForSlot"),!1;var g=b?a.nodeFrom:a.nodeTo,f=b?a.slotFrom:a.slotTo;switch(typeof f){case "string":d=b?g.findOutputSlot(f,!1):g.findInputSlot(f, +!1);f=b?g.outputs[f]:g.inputs[f];break;case "object":d=b?g.findOutputSlot(f.name):g.findInputSlot(f.name);break;case "number":d=f;f=b?g.outputs[f]:g.inputs[f];break;default:return console.warn("Cant get slot information "+f),!1}!1!==f&&!1!==d||console.warn("createDefaultNodeForSlot bad slotX "+f+" "+d);g=f.type==e.EVENT?"_event_":f.type;if((f=b?e.slot_types_default_out:e.slot_types_default_in)&&f[g]){nodeNewType=!1;if("object"==typeof f[g]||"array"==typeof f[g])for(var c in f[g]){if(a.nodeType==f[g][c]|| +"AUTO"==a.nodeType){nodeNewType=f[g][c];break}}else if(a.nodeType==f[g]||"AUTO"==a.nodeType)nodeNewType=f[g];if(nodeNewType){c=!1;"object"==typeof nodeNewType&&nodeNewType.node&&(c=nodeNewType,nodeNewType=nodeNewType.node);if(f=e.createNode(nodeNewType)){if(c){if(c.properties)for(var k in c.properties)f.addProperty(k,c.properties[k]);if(c.inputs)for(k in f.inputs=[],c.inputs)f.addOutput(c.inputs[k][0],c.inputs[k][1]);if(c.outputs)for(k in f.outputs=[],c.outputs)f.addOutput(c.outputs[k][0],c.outputs[k][1]); +c.title&&(f.title=c.title);c.json&&f.configure(c.json)}this.graph.add(f);f.pos=[a.position[0]+a.posAdd[0]+(a.posSizeFix[0]?a.posSizeFix[0]*f.size[0]:0),a.position[1]+a.posAdd[1]+(a.posSizeFix[1]?a.posSizeFix[1]*f.size[1]:0)];b?a.nodeFrom.connectByType(d,f,g):a.nodeTo.connectByTypeOutput(d,f,g);return!0}console.log("failed creating "+nodeNewType)}}return!1};h.prototype.showConnectionMenu=function(a){a=a||{};var b=Object.assign({nodeFrom:null,slotFrom:null,nodeTo:null,slotTo:null,e:null},a),d=this, +g=b.nodeFrom&&b.slotFrom;a=!g&&b.nodeTo&&b.slotTo;if(!g&&!a)return console.warn("No data passed to showConnectionMenu"),!1;a=g?b.nodeFrom:b.nodeTo;var f=g?b.slotFrom:b.slotTo,c=!1;switch(typeof f){case "string":c=g?a.findOutputSlot(f,!1):a.findInputSlot(f,!1);f=g?a.outputs[f]:a.inputs[f];break;case "object":c=g?a.findOutputSlot(f.name):a.findInputSlot(f.name);break;case "number":c=f;f=g?a.outputs[f]:a.inputs[f];break;default:return console.warn("Cant get slot information "+f),!1}a=["Add Node",null]; +d.allow_searchbox&&(a.push("Search"),a.push(null));var k=f.type==e.EVENT?"_event_":f.type,q=g?e.slot_types_default_out:e.slot_types_default_in;if(q&&q[k])if("object"==typeof q[k]||"array"==typeof q[k])for(var n in q[k])a.push(q[k][n]);else a.push(q[k]);var x=new e.ContextMenu(a,{event:b.e,title:(f&&""!=f.name?f.name+(k?" | ":""):"")+(f&&k?k:""),callback:function(a,e,m){switch(a){case "Add Node":h.onMenuAdd(null,null,m,x,function(a){g?b.nodeFrom.connectByType(c,a,k):b.nodeTo.connectByTypeOutput(c, +a,k)});break;case "Search":g?d.showSearchBox(m,{node_from:b.nodeFrom,slot_from:f,type_filter_in:k}):d.showSearchBox(m,{node_to:b.nodeTo,slot_from:f,type_filter_out:k});break;default:d.createDefaultNodeForSlot(Object.assign(b,{position:[b.e.canvasX,b.e.canvasY],nodeType:a}))}}});return!1};h.onShowPropertyEditor=function(a,b,d,g,f){function c(){if(n){var b=n.value;"Number"==a.type?b=Number(b):"Boolean"==a.type&&(b=!!b);f[k]=b;q.parentNode&&q.parentNode.removeChild(q);f.setDirtyCanvas(!0,!0)}}var k= +a.property||"title";b=f[k];var q=document.createElement("div");q.is_modified=!1;q.className="graphdialog";q.innerHTML="";q.close=function(){q.parentNode&&q.parentNode.removeChild(q)};q.querySelector(".name").innerText=k;var n=q.querySelector(".value");n&&(n.value=b,n.addEventListener("blur",function(a){this.focus()}),n.addEventListener("keydown",function(a){q.is_modified=!0;if(27==a.keyCode)q.close();else if(13== +a.keyCode)c();else if(13!=a.keyCode&&"textarea"!=a.target.localName)return;a.preventDefault();a.stopPropagation()}));b=h.active_canvas.canvas;d=b.getBoundingClientRect();var x=g=-20;d&&(g-=d.left,x-=d.top);event?(q.style.left=event.clientX+g+"px",q.style.top=event.clientY+x+"px"):(q.style.left=.5*b.width+g+"px",q.style.top=.5*b.height+x+"px");q.querySelector("button").addEventListener("click",c);b.parentNode.appendChild(q);n&&n.focus();var C=null;q.addEventListener("mouseleave",function(a){e.dialog_close_on_mouse_leave&& +!q.is_modified&&e.dialog_close_on_mouse_leave&&(C=setTimeout(q.close,e.dialog_close_on_mouse_leave_delay))});q.addEventListener("mouseenter",function(a){e.dialog_close_on_mouse_leave&&C&&clearTimeout(C)})};h.prototype.prompt=function(a,b,d,g,f){var c=this;a=a||"";var k=document.createElement("div");k.is_modified=!1;k.className="graphdialog rounded";k.innerHTML=f?" ":" "; +k.close=function(){c.prompt_box=null;k.parentNode&&k.parentNode.removeChild(k)};f=h.active_canvas.canvas;f.parentNode.appendChild(k);1h.search_limit))break}}u= +null;if(Array.prototype.filter)u=Object.keys(e.registered_node_types).filter(g);else for(m in u=[],e.registered_node_types)g(m)&&u.push(m);for(m=0;mh.search_limit);m++);if(b.show_general_after_typefiltered&&(n.value||G.value)){filtered_extra=[];for(m in e.registered_node_types)g(m,{inTypeOverride:n&&n.value?"*":!1,outTypeOverride:G&&G.value?"*":!1})&&filtered_extra.push(m);for(m=0;mh.search_limit);m++);}if((n.value||G.value)&&0==y.childNodes.length&&b.show_general_if_none_on_typefilter){filtered_extra=[];for(m in e.registered_node_types)g(m,{skipFilter:!0})&&filtered_extra.push(m);for(m=0;mh.search_limit);m++);}}}def_options={slot_from:null,node_from:null,node_to:null,do_type_filter:e.search_filter_enabled,type_filter_in:!1,type_filter_out:!1,show_general_if_none_on_typefilter:!0,show_general_after_typefiltered:!0, +hide_on_mouse_leave:e.search_hide_on_mouse_leave,show_all_if_empty:!0,show_all_on_open:e.search_show_all_on_open};b=Object.assign(def_options,b||{});var c=this,k=h.active_canvas,q=k.canvas,n=q.ownerDocument||document,x=document.createElement("div");x.className="litegraph litesearchbox graphdialog rounded";x.innerHTML="Search ";b.do_type_filter&&(x.innerHTML+="", +x.innerHTML+="");x.innerHTML+="
";n.fullscreenElement?n.fullscreenElement.appendChild(x):(n.body.appendChild(x),n.body.style.overflow="hidden");if(b.do_type_filter)var C=x.querySelector(".slot_in_type_filter"),D=x.querySelector(".slot_out_type_filter");x.close=function(){c.search_box=null;n.body.focus();n.body.style.overflow="";setTimeout(function(){c.canvas.focus()},20);x.parentNode&&x.parentNode.removeChild(x)}; +1q.height-200&&(y.style.maxHeight=q.height-a.layerY-20+ +"px");H.focus();b.show_all_on_open&&f();return x};h.prototype.showEditPropertyValue=function(a,b,d){function g(){f(D.value)}function f(f){e&&e.values&&e.values.constructor===Object&&void 0!=e.values[f]&&(f=e.values[f]);"number"==typeof a.properties[b]&&(f=Number(f));if("array"==c||"object"==c)f=JSON.parse(f);a.properties[b]=f;a.graph&&a.graph._version++;if(a.onPropertyChanged)a.onPropertyChanged(b,f);if(d.onclose)d.onclose();n.close();a.setDirtyCanvas(!0,!0)}if(a&&void 0!==a.properties[b]){d=d||{}; +var e=a.getPropertyInfo(b),c=e.type,k="";if("string"==c||"number"==c||"array"==c||"object"==c)k="";else if("enum"!=c&&"combo"!=c||!e.values)if("boolean"==c||"toggle"==c)k="";else{console.warn("unknown type: "+c);return}else{k=""}var n=this.createDialog(""+(e.label?e.label:b)+""+k+"",d),D=!1;if("enum"!=c&&"combo"!=c||!e.values)if("boolean"==c||"toggle"==c)(D=n.querySelector("input"))&&D.addEventListener("click",function(a){n.modified();f(!!D.checked)});else{if(D=n.querySelector("input"))D.addEventListener("blur",function(a){this.focus()}),x=void 0!==a.properties[b]?a.properties[b]:"","string"!==c&&(x= +JSON.stringify(x)),D.value=x,D.addEventListener("keydown",function(a){if(27==a.keyCode)n.close();else if(13==a.keyCode)g();else if(13!=a.keyCode){n.modified();return}a.preventDefault();a.stopPropagation()})}else D=n.querySelector("select"),D.addEventListener("change",function(a){n.modified();f(a.target.value)});D&&D.focus();n.querySelector("button").addEventListener("click",g);return n}};h.prototype.createDialog=function(a,b){def_options={checkForInput:!1,closeOnLeave:!0,closeOnLeave_checkModified:!0}; +b=Object.assign(def_options,b||{});var d=document.createElement("div");d.className="graphdialog";d.innerHTML=a;d.is_modified=!1;a=this.canvas.getBoundingClientRect();var g=-20,f=-20;a&&(g-=a.left,f-=a.top);b.position?(g+=b.position[0],f+=b.position[1]):b.event?(g+=b.event.clientX,f+=b.event.clientY):(g+=.5*this.canvas.width,f+=.5*this.canvas.height);d.style.left=g+"px";d.style.top=f+"px";this.canvas.parentNode.appendChild(d);b.checkForInput&&(a=[],(a=d.querySelectorAll("input"))&&a.forEach(function(a){a.addEventListener("keydown", +function(a){d.modified();if(27==a.keyCode)d.close();else if(13!=a.keyCode)return;a.preventDefault();a.stopPropagation()});a.focus()}));d.modified=function(){d.is_modified=!0};d.close=function(){d.parentNode&&d.parentNode.removeChild(d)};var c=null,k=!1;d.addEventListener("mouseleave",function(a){k||(b.closeOnLeave||e.dialog_close_on_mouse_leave)&&!d.is_modified&&e.dialog_close_on_mouse_leave&&(c=setTimeout(d.close,e.dialog_close_on_mouse_leave_delay))});d.addEventListener("mouseenter",function(a){(b.closeOnLeave|| +e.dialog_close_on_mouse_leave)&&c&&clearTimeout(c)});(a=d.querySelectorAll("select"))&&a.forEach(function(a){a.addEventListener("click",function(a){k++});a.addEventListener("blur",function(a){k=0});a.addEventListener("change",function(a){k=-1})});return d};h.prototype.createPanel=function(a,b){b=b||{};var d=b.window||window,g=document.createElement("div");g.className="litegraph dialog";g.innerHTML="
"; +g.header=g.querySelector(".dialog-header");b.width&&(g.style.width=b.width+(b.width.constructor===Number?"px":""));b.height&&(g.style.height=b.height+(b.height.constructor===Number?"px":""));b.closable&&(b=document.createElement("span"),b.innerHTML="✕",b.classList.add("close"),b.addEventListener("click",function(){g.close()}),g.header.appendChild(b));g.title_element=g.querySelector(".dialog-title");g.title_element.innerText=a;g.content=g.querySelector(".dialog-content");g.alt_content=g.querySelector(".dialog-alt-content"); +g.footer=g.querySelector(".dialog-footer");g.close=function(){if(g.onClose&&"function"==typeof g.onClose)g.onClose();g.parentNode.removeChild(g);this.parentNode&&this.parentNode.removeChild(this)};g.toggleAltContent=function(a){if("undefined"!=typeof a){var b=a?"block":"none";a=a?"none":"block"}else b="block"!=g.alt_content.style.display?"block":"none",a="block"!=g.alt_content.style.display?"none":"block";g.alt_content.style.display=b;g.content.style.display=a};g.toggleFooterVisibility=function(a){g.footer.style.display= +"undefined"!=typeof a?a?"block":"none":"block"!=g.footer.style.display?"block":"none"};g.clear=function(){this.content.innerHTML=""};g.addHTML=function(a,b,d){var f=document.createElement("div");b&&(f.className=b);f.innerHTML=a;d?g.footer.appendChild(f):g.content.appendChild(f);return f};g.addButton=function(a,b,d){var f=document.createElement("button");f.innerText=a;f.options=d;f.classList.add("btn");f.addEventListener("click",b);g.footer.appendChild(f);return f};g.addSeparator=function(){var a= +document.createElement("div");a.className="separator";g.content.appendChild(a)};g.addWidget=function(a,b,c,k,q){function f(a,b){k.callback&&k.callback(a,b,k);q&&q(a,b,k)}k=k||{};var m=String(c);a=a.toLowerCase();"number"==a&&(m=c.toFixed(3));var n=document.createElement("div");n.className="property";n.innerHTML="";n.querySelector(".property_name").innerText=k.label||b;var u=n.querySelector(".property_value");u.innerText=m;n.dataset.property= +b;n.dataset.type=k.type||a;n.options=k;n.value=c;if("code"==a)n.addEventListener("click",function(a){g.inner_showCodePad(this.dataset.property)});else if("boolean"==a)n.classList.add("boolean"),c&&n.classList.add("bool-on"),n.addEventListener("click",function(){var a=this.dataset.property;this.value=!this.value;this.classList.toggle("bool-on");this.querySelector(".property_value").innerText=this.value?"true":"false";f(a,this.value)});else if("string"==a||"number"==a)u.setAttribute("contenteditable", +!0),u.addEventListener("keydown",function(b){"Enter"!=b.code||"string"==a&&b.shiftKey||(b.preventDefault(),this.blur())}),u.addEventListener("blur",function(){var a=this.innerText,b=this.parentNode.dataset.property;"number"==this.parentNode.dataset.type&&(a=Number(a));f(b,a)});else if("enum"==a||"combo"==a)m=h.getPropertyPrintableValue(c,k.values),u.innerText=m,u.addEventListener("click",function(a){var b=this.parentNode.dataset.property,g=this;new e.ContextMenu(k.values||[],{event:a,className:"dark", +callback:function(a,d,e){g.innerText=a;f(b,a);return!1}},d)});g.content.appendChild(n);return n};if(g.onOpen&&"function"==typeof g.onOpen)g.onOpen();return g};h.getPropertyPrintableValue=function(a,b){if(!b||b.constructor===Array)return String(a);if(b.constructor===Object){var d="",g;for(g in b)if(b[g]==a){d=g;break}return String(a)+" ("+d+")"}};h.prototype.closePanels=function(){var a=document.querySelector("#node-panel");a&&a.close();(a=document.querySelector("#option-panel"))&&a.close()};h.prototype.showShowGraphOptionsPanel= +function(a,b,d,g){if(this.constructor&&"HTMLDivElement"==this.constructor.name){if(!(b&&b.event&&b.event.target&&b.event.target.lgraphcanvas)){console.warn("Canvas not found");return}var f=b.event.target.lgraphcanvas}else f=this;f.closePanels();a=f.getCanvasWindow();panel=f.createPanel("Options",{closable:!0,window:a,onOpen:function(){f.OPTIONPANEL_IS_OPEN=!0},onClose:function(){f.OPTIONPANEL_IS_OPEN=!1;f.options_panel=null}});f.options_panel=panel;panel.id="option-panel";panel.classList.add("settings"); +(function(){panel.content.innerHTML="";var a=function(a,b,d){d&&d.key&&(a=d.key);d.values&&(b=Object.values(d.values).indexOf(b));f[a]=b},b=e.availableCanvasOptions;b.sort();for(pI in b){var d=b[pI];panel.addWidget("boolean",d,f[d],{key:d,on:"True",off:"False"},a)}panel.addWidget("combo","Render mode",e.LINK_RENDER_MODES[f.links_render_mode],{key:"links_render_mode",values:e.LINK_RENDER_MODES},a);panel.addSeparator();panel.footer.innerHTML=""})();f.canvas.parentNode.appendChild(panel)};h.prototype.showShowNodePanel= +function(a){function b(){panel.content.innerHTML="";panel.addHTML(""+a.type+""+(a.constructor.desc||"")+"");panel.addHTML("

Properties

");var b=function(b,d){g.graph.beforeChange(a);switch(b){case "Title":a.title=d;break;case "Mode":b=Object.values(e.NODE_MODES).indexOf(d);0<=b&&e.NODE_MODES[b]?a.changeMode(b):console.warn("unexpected mode: "+d);break;case "Color":h.node_colors[d]?(a.color=h.node_colors[d].color, +a.bgcolor=h.node_colors[d].bgcolor):console.warn("unexpected color: "+d);break;default:a.setProperty(b,d)}g.graph.afterChange();g.dirty_canvas=!0};panel.addWidget("string","Title",a.title,{},b);panel.addWidget("combo","Mode",e.NODE_MODES[a.mode],{values:e.NODE_MODES},b);var d="";void 0!==a.color&&(d=Object.keys(h.node_colors).filter(function(b){return h.node_colors[b].color==a.color}));panel.addWidget("combo","Color",d,{values:Object.keys(h.node_colors)},b);for(var c in a.properties){d=a.properties[c]; +var k=a.getPropertyInfo(c);a.onAddPropertyToPanel&&a.onAddPropertyToPanel(c,panel)||panel.addWidget(k.widget||k.type,c,d,k,b)}panel.addSeparator();if(a.onShowCustomPanelInfo)a.onShowCustomPanelInfo(panel);panel.footer.innerHTML="";panel.addButton("Delete",function(){a.block_delete||(a.graph.remove(a),panel.close())}).classList.add("delete")}this.SELECTED_NODE=a;this.closePanels();var d=this.getCanvasWindow(),g=this;panel=this.createPanel(a.title||"",{closable:!0,window:d,onOpen:function(){g.NODEPANEL_IS_OPEN= +!0},onClose:function(){g.NODEPANEL_IS_OPEN=!1;g.node_panel=null}});g.node_panel=panel;panel.id="node-panel";panel.node=a;panel.classList.add("settings");panel.inner_showCodePad=function(d){panel.classList.remove("settings");panel.classList.add("centered");panel.alt_content.innerHTML="";var f=panel.alt_content.querySelector("textarea"),g=function(){panel.toggleAltContent(!1);panel.toggleFooterVisibility(!0);f.parentNode.removeChild(f);panel.classList.add("settings"); +panel.classList.remove("centered");b()};f.value=a.properties[d];f.addEventListener("keydown",function(b){"Enter"==b.code&&b.ctrlKey&&(a.setProperty(d,f.value),g())});panel.toggleAltContent(!0);panel.toggleFooterVisibility(!1);f.style.height="calc(100% - 40px)";var e=panel.addButton("Assign",function(){a.setProperty(d,f.value);g()});panel.alt_content.appendChild(e);e=panel.addButton("Close",g);e.style.float="right";panel.alt_content.appendChild(e)};b();this.canvas.parentNode.appendChild(panel)};h.prototype.showSubgraphPropertiesDialog= +function(a){function b(){g.clear();if(a.inputs)for(var d=0;d","subgraph_property");c.dataset.name=e.name;c.dataset.slot=d;c.querySelector(".name").innerText=e.name;c.querySelector(".type").innerText=e.type;c.querySelector("button").addEventListener("click",function(d){a.removeInput(Number(this.parentNode.dataset.slot)); +b()})}}}console.log("showing subgraph properties dialog");var d=this.canvas.parentNode.querySelector(".subgraph_dialog");d&&d.close();var g=this.createPanel("Subgraph Inputs",{closable:!0,width:500});g.node=a;g.classList.add("subgraph_dialog");g.addHTML(" + NameType","subgraph_property extra",!0).querySelector("button").addEventListener("click",function(d){d=this.parentNode;var f= +d.querySelector(".name").value,g=d.querySelector(".type").value;f&&-1==a.findInputSlot(f)&&(a.addInput(f,g),d.querySelector(".name").value="",d.querySelector(".type").value="",b())});b();this.canvas.parentNode.appendChild(g);return g};h.prototype.showSubgraphPropertiesDialogRight=function(a){function b(){f.clear();if(a.outputs)for(var d=0;d", +"subgraph_property");e.dataset.name=g.name;e.dataset.slot=d;e.querySelector(".name").innerText=g.name;e.querySelector(".type").innerText=g.type;e.querySelector("button").addEventListener("click",function(d){a.removeOutput(Number(this.parentNode.dataset.slot));b()})}}}function d(){var d=this.parentNode,f=d.querySelector(".name").value,g=d.querySelector(".type").value;f&&-1==a.findOutputSlot(f)&&(a.addOutput(f,g),d.querySelector(".name").value="",d.querySelector(".type").value="",b())}var g=this.canvas.parentNode.querySelector(".subgraph_dialog"); +g&&g.close();var f=this.createPanel("Subgraph Outputs",{closable:!0,width:500});f.node=a;f.classList.add("subgraph_dialog");g=f.addHTML(" + NameType","subgraph_property extra",!0);g.querySelector(".name").addEventListener("keydown",function(a){13==a.keyCode&&d.apply(this)});g.querySelector("button").addEventListener("click",function(a){d.apply(this)});b();this.canvas.parentNode.appendChild(f); +return f};h.prototype.checkPanels=function(){if(this.canvas)for(var a=this.canvas.parentNode.querySelectorAll(".litegraph.dialog"),b=0;b=Object.keys(a.selected_nodes).length)f.collapse();else for(var e in a.selected_nodes)a.selected_nodes[e].collapse();f.graph.afterChange()};h.onMenuNodePin=function(a,b,d,g,f){f.pin()}; +h.onMenuNodeMode=function(a,b,d,g,f){new e.ContextMenu(e.NODE_MODES,{event:d,callback:function(a){if(f){var b=Object.values(e.NODE_MODES).indexOf(a),d=function(d){0<=b&&e.NODE_MODES[b]?d.changeMode(b):(console.warn("unexpected mode: "+a),d.changeMode(e.ALWAYS))},g=h.active_canvas;if(!g.selected_nodes||1>=Object.keys(g.selected_nodes).length)d(f);else for(var c in g.selected_nodes)d(g.selected_nodes[c])}},parentMenu:g,node:f});return!1};h.onMenuNodeColors=function(a,b,d,g,f){if(!f)throw"no node for color"; +b=[];b.push({value:null,content:"No color"});for(var c in h.node_colors)a=h.node_colors[c],a={value:c,content:""+c+""},b.push(a);new e.ContextMenu(b,{event:d,callback:function(a){if(f){var b=a.value?h.node_colors[a.value]:null;a=function(a){b?a.constructor===e.LGraphGroup?a.color=b.groupcolor:(a.color=b.color, +a.bgcolor=b.bgcolor):(delete a.color,delete a.bgcolor)};var d=h.active_canvas;if(!d.selected_nodes||1>=Object.keys(d.selected_nodes).length)a(f);else for(var g in d.selected_nodes)a(d.selected_nodes[g]);f.setDirtyCanvas(!0,!0)}},parentMenu:g,node:f});return!1};h.onMenuNodeShapes=function(a,b,d,g,f){if(!f)throw"no node passed";new e.ContextMenu(e.VALID_SHAPES,{event:d,callback:function(a){if(f){f.graph.beforeChange();var b=h.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)f.shape= +a;else for(var d in b.selected_nodes)b.selected_nodes[d].shape=a;f.graph.afterChange();f.setDirtyCanvas(!0)}},parentMenu:g,node:f});return!1};h.onMenuNodeRemove=function(a,b,d,g,f){if(!f)throw"no node passed";a=f.graph;a.beforeChange();b=h.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)!1!==f.removable&&a.remove(f);else for(var e in b.selected_nodes)d=b.selected_nodes[e],!1!==d.removable&&a.remove(d);a.afterChange();f.setDirtyCanvas(!0,!0)};h.onMenuNodeToSubgraph=function(a, +b,d,g,f){a=f.graph;if(b=h.active_canvas)d=Object.values(b.selected_nodes||{}),d.length||(d=[f]),g=e.createNode("graph/subgraph"),g.pos=f.pos.concat(),a.add(g),g.buildFromNodes(d),b.deselectAllNodes(),f.setDirtyCanvas(!0,!0)};h.onMenuNodeClone=function(a,b,d,g,f){f.graph.beforeChange();var e={};a=function(a){if(0!=a.clonable){var b=a.clone();b&&(b.pos=[a.pos[0]+5,a.pos[1]+5],a.graph.add(b),e[b.id]=b)}};b=h.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)a(f);else for(var c in b.selected_nodes)a(b.selected_nodes[c]); +Object.keys(e).length&&b.selectNodes(e);f.graph.afterChange();f.setDirtyCanvas(!0,!0)};h.node_colors={red:{color:"#322",bgcolor:"#533",groupcolor:"#A88"},brown:{color:"#332922",bgcolor:"#593930",groupcolor:"#b06634"},green:{color:"#232",bgcolor:"#353",groupcolor:"#8A8"},blue:{color:"#223",bgcolor:"#335",groupcolor:"#88A"},pale_blue:{color:"#2a363b",bgcolor:"#3f5159",groupcolor:"#3f789e"},cyan:{color:"#233",bgcolor:"#355",groupcolor:"#8AA"},purple:{color:"#323",bgcolor:"#535",groupcolor:"#a1309b"}, +yellow:{color:"#432",bgcolor:"#653",groupcolor:"#b58b2a"},black:{color:"#222",bgcolor:"#000",groupcolor:"#444"}};h.prototype.getCanvasMenuOptions=function(){if(this.getMenuOptions)var a=this.getMenuOptions();else a=[{content:"Add Node",has_submenu:!0,callback:h.onMenuAdd},{content:"Add Group",callback:h.onGroupAdd}],this._graph_stack&&0Name",f),k=c.querySelector("input");k&&e&&(k.value=e.label||"");var m=function(){a.graph.beforeChange();k.value&&(e&&(e.label=k.value),d.setDirty(!0));c.close();a.graph.afterChange()};c.querySelector("button").addEventListener("click",m);k.addEventListener("keydown",function(a){c.is_modified=!0;if(27==a.keyCode)c.close(); +else if(13==a.keyCode)m();else if(13!=a.keyCode&&"textarea"!=a.target.localName)return;a.preventDefault();a.stopPropagation()});k.focus()}},extra:a};a&&(c.title=a.type);var k=null;a&&(k=a.getSlotInPosition(b.canvasX,b.canvasY),h.active_node=a);k?(f=[],a.getSlotMenuOptions?f=a.getSlotMenuOptions(k):(k&&k.output&&k.output.links&&k.output.links.length&&f.push({content:"Disconnect Links",slot:k}),b=k.input||k.output,b.removable&&f.push(b.locked?"Cannot remove":{content:"Remove Slot",slot:k}),b.nameLocked|| +f.push({content:"Rename Slot",slot:k})),c.title=(k.input?k.input.type:k.output.type)||"*",k.input&&k.input.type==e.ACTION&&(c.title="Action"),k.output&&k.output.type==e.EVENT&&(c.title="Event")):a?f=this.getNodeMenuOptions(a):(f=this.getCanvasMenuOptions(),(k=this.graph.getGroupOnPos(b.canvasX,b.canvasY))&&f.push(null,{content:"Edit Group",has_submenu:!0,submenu:{title:"Group",extra:k,options:this.getGroupMenuOptions(k)}}));f&&new e.ContextMenu(f,c,g)};"undefined"!=typeof window&&window.CanvasRenderingContext2D&& +!window.CanvasRenderingContext2D.prototype.roundRect&&(window.CanvasRenderingContext2D.prototype.roundRect=function(a,b,d,g,f,e){var c,k;if(0===f)this.rect(a,b,d,g);else{void 0===e&&(e=f);if(null!=f&&f.constructor===Array)if(1==f.length)var m=c=k=e=f[0];else if(2==f.length)m=e=f[0],c=k=f[1];else if(4==f.length)m=f[0],c=f[1],k=f[2],e=f[3];else return;else m=f||0,c=f||0,k=e||0,e=e||0;this.moveTo(a+m,b);this.lineTo(a+d-c,b);this.quadraticCurveTo(a+d,b,a+d,b+c);this.lineTo(a+d,b+g-e);this.quadraticCurveTo(a+ +d,b+g,a+d-e,b+g);this.lineTo(a+e,b+g);this.quadraticCurveTo(a,b+g,a,b+g-k);this.lineTo(a,b+k);this.quadraticCurveTo(a,b,a+m,b)}});e.compareObjects=function(a,b){for(var d in a)if(a[d]!=b[d])return!1;return!0};e.distance=E;e.colorToString=function(a){return"rgba("+Math.round(255*a[0]).toFixed()+","+Math.round(255*a[1]).toFixed()+","+Math.round(255*a[2]).toFixed()+","+(4==a.length?a[3].toFixed(2):"1.0")+")"};e.isInsideRectangle=A;e.growBounding=function(a,b,d){ba[2]&&(a[2]=b);da[3]&&(a[3]=d)};e.isInsideBounding=function(a,b){return a[0]b[1][0]||a[1]>b[1][1]?!1:!0};e.overlapBounding=I;e.hex2num=function(a){"#"==a.charAt(0)&&(a=a.slice(1));a=a.toUpperCase();for(var b=Array(3),d=0,g,f,e=0;6>e;e+=2)g="0123456789ABCDEF".indexOf(a.charAt(e)),f="0123456789ABCDEF".indexOf(a.charAt(e+1)),b[d]=16*g+f,d++;return b};e.num2hex=function(a){for(var b="#",d,g,f=0;3>f;f++)d=a[f]/16,g=a[f]%16,b+="0123456789ABCDEF".charAt(d)+"0123456789ABCDEF".charAt(g); +return b};J.prototype.addItem=function(a,b,d){function g(a){var b=this.value;b&&b.has_submenu&&f.call(this,a)}function f(a){var b=this.value,f=!0;c.current_submenu&&c.current_submenu.close(a);if(d.callback){var g=d.callback.call(this,b,d,a,c,d.node);!0===g&&(f=!1)}if(b&&(b.callback&&!d.ignore_item_callbacks&&!0!==b.disabled&&(g=b.callback.call(this,b,d,a,c,d.extra),!0===g&&(f=!1)),b.submenu)){if(!b.submenu.options)throw"ContextMenu submenu needs options";new c.constructor(b.submenu.options,{callback:b.submenu.callback, +event:a,parentMenu:c,ignore_item_callbacks:b.submenu.ignore_item_callbacks,title:b.submenu.title,extra:b.submenu.extra,autoopen:d.autoopen});f=!1}f&&!c.lock&&c.close()}var c=this;d=d||{};var k=document.createElement("div");k.className="litemenu-entry submenu";var q=!1;if(null===b)k.classList.add("separator");else{k.innerHTML=b&&b.title?b.title:a;if(k.value=b)b.disabled&&(q=!0,k.classList.add("disabled")),(b.submenu||b.has_submenu)&&k.classList.add("has_submenu");"function"==typeof b?(k.dataset.value= +a,k.onclick_callback=b):k.dataset.value=b;b.className&&(k.className+=" "+b.className)}this.root.appendChild(k);q||k.addEventListener("click",f);d.autoopen&&e.pointerListenerAdd(k,"enter",g);return k};J.prototype.close=function(a,b){this.root.parentNode&&this.root.parentNode.removeChild(this.root);this.parentMenu&&!b&&(this.parentMenu.lock=!1,this.parentMenu.current_submenu=null,void 0===a?this.parentMenu.close():a&&!J.isCursorOverElement(a,this.parentMenu.root)&&J.trigger(this.parentMenu.root,e.pointerevents_method+ +"leave",a));this.current_submenu&&this.current_submenu.close(a,!0);this.root.closing_timer&&clearTimeout(this.root.closing_timer)};J.trigger=function(a,b,d,g){var f=document.createEvent("CustomEvent");f.initCustomEvent(b,!0,!0,d);f.srcElement=g;a.dispatchEvent?a.dispatchEvent(f):a.__events&&a.__events.dispatchEvent(f);return f};J.prototype.getTopMenu=function(){return this.options.parentMenu?this.options.parentMenu.getTopMenu():this};J.prototype.getFirstEvent=function(){return this.options.parentMenu? +this.options.parentMenu.getFirstEvent():this.options.event};J.isCursorOverElement=function(a,b){var d=a.clientX;a=a.clientY;return(b=b.getBoundingClientRect())?a>b.top&&ab.left&&d +Math.abs(b))return g[1];a=(a-g[0])/b;return g[1]*(1-a)+f[1]*a}}return 0}};F.prototype.draw=function(a,b,d,g,f,e){if(d=this.points){this.size=b;var c=b[0]-2*this.margin;b=b[1]-2*this.margin;f=f||"#666";a.save();a.translate(this.margin,this.margin);g&&(a.fillStyle="#111",a.fillRect(0,0,c,b),a.fillStyle="#222",a.fillRect(.5*c,0,1,b),a.strokeStyle="#333",a.strokeRect(0,0,c,b));a.strokeStyle=f;e&&(a.globalAlpha=.5);a.beginPath();for(g=0;ga[1])){var g=this.size[0]-2*this.margin,f=this.size[1]-2*this.margin,e=a[0]-this.margin;a=a[1]-this.margin;this.selected=this.getCloserPoint([e,a],30/b.ds.scale);-1==this.selected&&(b=[e/g,1-a/f],d.push(b),d.sort(function(a,b){return a[0]-b[0]}),this.selected= +d.indexOf(b),this.must_update=!0);if(-1!=this.selected)return!0}};F.prototype.onMouseMove=function(a,b){var d=this.points;if(d){var g=this.selected;if(!(0>g)){var f=(a[0]-this.margin)/(this.size[0]-2*this.margin),e=(a[1]-this.margin)/(this.size[1]-2*this.margin);this._nearest=this.getCloserPoint([a[0]-this.margin,a[1]-this.margin],30/b.ds.scale);if(b=d[g]){var c=0==g||g==d.length-1;!c&&(-10>a[0]||a[0]>this.size[0]+10||-10>a[1]||a[1]>this.size[1]+10)?(d.splice(g,1),this.selected=-1):(b[0]=c?0==g?0: +1:Math.clamp(f,0,1),b[1]=1-Math.clamp(e,0,1),d.sort(function(a,b){return a[0]-b[0]}),this.selected=d.indexOf(b),this.must_update=!0)}}}};F.prototype.onMouseUp=function(a,b){this.selected=-1;return!1};F.prototype.getCloserPoint=function(a,b){var d=this.points;if(!d)return-1;b=b||30;for(var g=this.size[0]-2*this.margin,f=this.size[1]-2*this.margin,e=d.length,c=[0,0],k=1E6,q=-1,x=0;xk||n>b||(q=x,k=n)}return q};e.CurveEditor=F;e.getParameterNames= +function(a){return(a+"").replace(/[/][/].*$/gm,"").replace(/\s+/g,"").replace(/[/][*][^/*]*[*][/]/g,"").split("){",1)[0].replace(/^[^(]*[(]/,"").replace(/=[^,]+/g,"").split(",").filter(Boolean)};e.pointerListenerAdd=function(a,b,d,g){g=void 0===g?!1:g;if(a&&a.addEventListener&&b&&"function"===typeof d){var f=e.pointerevents_method;if("pointer"==f&&!window.PointerEvent)switch(console.warn("sMethod=='pointer' && !window.PointerEvent"),console.log("Converting pointer["+b+"] : down move up cancel enter TO touchstart touchmove touchend, etc .."), +b){case "down":f="touch";b="start";break;case "move":f="touch";break;case "up":f="touch";b="end";break;case "cancel":f="touch";break;case "enter":console.log("debug: Should I send a move event?");break;default:console.warn("PointerEvent not available in this browser ? The event "+b+" would not be called")}switch(b){case "down":case "up":case "move":case "over":case "out":case "enter":a.addEventListener(f+b,d,g);case "leave":case "cancel":case "gotpointercapture":case "lostpointercapture":if("mouse"!= +f)return a.addEventListener(f+b,d,g);default:return a.addEventListener(b,d,g)}}};e.pointerListenerRemove=function(a,b,d,g){g=void 0===g?!1:g;if(a&&a.removeEventListener&&b&&"function"===typeof d)switch(b){case "down":case "up":case "move":case "over":case "out":case "enter":"pointer"!=e.pointerevents_method&&"mouse"!=e.pointerevents_method||a.removeEventListener(e.pointerevents_method+b,d,g);case "leave":case "cancel":case "gotpointercapture":case "lostpointercapture":if("pointer"==e.pointerevents_method)return a.removeEventListener(e.pointerevents_method+ +b,d,g);default:return a.removeEventListener(b,d,g)}};Math.clamp=function(a,b,d){return b>a?b:da&&(b[0]=c?this.trigger(null,e):this._pending.push([c,e])};B.prototype.onExecute=function(){var c=1E3*this.graph.elapsed_time;this.isInputConnected(1)&&(this.properties.time_in_ms=this.getInputData(1)); -for(var e=0;eg[1]))return this.old_y=c.canvasY,this.captureInput(!0),this.mouse_captured=!0};q.prototype.onMouseMove=function(c){if(this.mouse_captured){var e=this.old_y-c.canvasY;c.shiftKey&&(e*=10);if(c.metaKey||c.altKey)e*=.1;this.old_y=c.canvasY;c=this._remainder+e/q.pixels_threshold;this._remainder=c%1;c=Math.clamp(this.properties.value+(c|0)*this.properties.step,this.properties.min, -this.properties.max);this.properties.value=c;this.graph._version++;this.setDirtyCanvas(!0)}};q.prototype.onMouseUp=function(c,g){200>c.click_time&&(this.properties.value=Math.clamp(this.properties.value+(g[1]>.5*this.size[1]?-1:1)*this.properties.step,this.properties.min,this.properties.max),this.graph._version++,this.setDirtyCanvas(!0));this.mouse_captured&&(this.mouse_captured=!1,this.captureInput(!1))};D.registerNodeType("widget/number",q);n.title="Combo";n.desc="Widget to select from a list"; -n.prototype.onExecute=function(){this.setOutputData(0,this.properties.value)};n.prototype.onPropertyChanged=function(c,g){"values"==c?(this._values=g.split(";"),this.widget.options.values=this._values):"value"==c&&(this.widget.value=g)};D.registerNodeType("widget/combo",n);w.title="Knob";w.desc="Circular controller";w.size=[80,100];w.prototype.onDrawForeground=function(c){if(!this.flags.collapsed){-1==this.value&&(this.value=(this.properties.value-this.properties.min)/(this.properties.max-this.properties.min)); -var e=.5*this.size[0],g=.5*this.size[1],l=.5*Math.min(this.size[0],this.size[1])-5;c.globalAlpha=1;c.save();c.translate(e,g);c.rotate(.75*Math.PI);c.fillStyle="rgba(0,0,0,0.5)";c.beginPath();c.moveTo(0,0);c.arc(0,0,l,0,1.5*Math.PI);c.fill();c.strokeStyle="black";c.fillStyle=this.properties.color;c.lineWidth=2;c.beginPath();c.moveTo(0,0);c.arc(0,0,l-4,0,1.5*Math.PI*Math.max(.01,this.value));c.closePath();c.fill();c.lineWidth=1;c.globalAlpha=1;c.restore();c.fillStyle="black";c.beginPath();c.arc(e,g, -.75*l,0,2*Math.PI,!0);c.fill();c.fillStyle=this.mouseOver?"white":this.properties.color;c.beginPath();var n=this.value*Math.PI*1.5+.75*Math.PI;c.arc(e+Math.cos(n)*l*.65,g+Math.sin(n)*l*.65,.05*l,0,2*Math.PI,!0);c.fill();c.fillStyle=this.mouseOver?"white":"#AAA";c.font=Math.floor(.5*l)+"px Arial";c.textAlign="center";c.fillText(this.properties.value.toFixed(this.properties.precision),e,g+.15*l)}};w.prototype.onExecute=function(){this.setOutputData(0,this.properties.value);this.boxcolor=D.colorToString([this.value, -this.value,this.value])};w.prototype.onMouseDown=function(c){this.center=[.5*this.size[0],.5*this.size[1]+20];this.radius=.5*this.size[0];if(20>c.canvasY-this.pos[1]||D.distance([c.canvasX,c.canvasY],[this.pos[0]+this.center[0],this.pos[1]+this.center[1]])>this.radius)return!1;this.oldmouse=[c.canvasX-this.pos[0],c.canvasY-this.pos[1]];this.captureInput(!0);return!0};w.prototype.onMouseMove=function(c){if(this.oldmouse){c=[c.canvasX-this.pos[0],c.canvasY-this.pos[1]];var e=this.value;e-=.01*(c[1]- -this.oldmouse[1]);1e&&(e=0);this.value=e;this.properties.value=this.properties.min+(this.properties.max-this.properties.min)*this.value;this.oldmouse=c;this.setDirtyCanvas(!0)}};w.prototype.onMouseUp=function(c){this.oldmouse&&(this.oldmouse=null,this.captureInput(!1))};w.prototype.onPropertyChanged=function(c,g){if("min"==c||"max"==c||"value"==c)return this.properties[c]=parseFloat(g),!0};D.registerNodeType("widget/knob",w);l.title="Inner Slider";l.prototype.onPropertyChanged=function(c, -g){"value"==c&&(this.slider.value=g)};l.prototype.onExecute=function(){this.setOutputData(0,this.properties.value)};D.registerNodeType("widget/internal_slider",l);A.title="H.Slider";A.desc="Linear slider controller";A.prototype.onDrawForeground=function(c){-1==this.value&&(this.value=(this.properties.value-this.properties.min)/(this.properties.max-this.properties.min));c.globalAlpha=1;c.lineWidth=1;c.fillStyle="#000";c.fillRect(2,2,this.size[0]-4,this.size[1]-4);c.fillStyle=this.properties.color; -c.beginPath();c.rect(4,4,(this.size[0]-8)*this.value,this.size[1]-8);c.fill()};A.prototype.onExecute=function(){this.properties.value=this.properties.min+(this.properties.max-this.properties.min)*this.value;this.setOutputData(0,this.properties.value);this.boxcolor=D.colorToString([this.value,this.value,this.value])};A.prototype.onMouseDown=function(c){if(0>c.canvasY-this.pos[1])return!1;this.oldmouse=[c.canvasX-this.pos[0],c.canvasY-this.pos[1]];this.captureInput(!0);return!0};A.prototype.onMouseMove= -function(c){if(this.oldmouse){c=[c.canvasX-this.pos[0],c.canvasY-this.pos[1]];var e=this.value;e+=(c[0]-this.oldmouse[0])/this.size[0];1e&&(e=0);this.value=e;this.oldmouse=c;this.setDirtyCanvas(!0)}};A.prototype.onMouseUp=function(c){this.oldmouse=null;this.captureInput(!1)};A.prototype.onMouseLeave=function(c){};D.registerNodeType("widget/hslider",A);B.title="Progress";B.desc="Shows data in linear progress";B.prototype.onExecute=function(){var c=this.getInputData(0);void 0!=c&&(this.properties.value= -c)};B.prototype.onDrawForeground=function(c){c.lineWidth=1;c.fillStyle=this.properties.color;var e=(this.properties.value-this.properties.min)/(this.properties.max-this.properties.min);e=Math.min(1,e);e=Math.max(0,e);c.fillRect(2,2,(this.size[0]-4)*e,this.size[1]-4)};D.registerNodeType("widget/progress",B);C.title="Text";C.desc="Shows the input value";C.widgets=[{name:"resize",text:"Resize box",type:"button"},{name:"led_text",text:"LED",type:"minibutton"},{name:"normal_text",text:"Normal",type:"minibutton"}]; -C.prototype.onDrawForeground=function(c){c.fillStyle=this.properties.color;var e=this.properties.value;this.properties.glowSize?(c.shadowColor=this.properties.color,c.shadowOffsetX=0,c.shadowOffsetY=0,c.shadowBlur=this.properties.glowSize):c.shadowColor="transparent";var g=this.properties.fontsize;c.textAlign=this.properties.align;c.font=g.toString()+"px "+this.properties.font;this.str="number"==typeof e?e.toFixed(this.properties.decimals):e;if("string"==typeof this.str){e=this.str.split("\\n");for(var l= -0;ln?g.xbox.axes.lx:0,this._left_axis[1]=Math.abs(g.xbox.axes.ly)>n?g.xbox.axes.ly:0,this._right_axis[0]=Math.abs(g.xbox.axes.rx)>n?g.xbox.axes.rx:0,this._right_axis[1]=Math.abs(g.xbox.axes.ry)>n?g.xbox.axes.ry:0,this._triggers[0]=Math.abs(g.xbox.axes.ltrigger)>n?g.xbox.axes.ltrigger: -0,this._triggers[1]=Math.abs(g.xbox.axes.rtrigger)>n?g.xbox.axes.rtrigger:0);if(this.outputs)for(n=0;nn;n++)if(g[n]){g=g[n];n=this.xbox_mapping;n||(n=this.xbox_mapping={axes:[], -buttons:{},hat:"",hatmap:c.CENTER});n.axes.lx=g.axes[0];n.axes.ly=g.axes[1];n.axes.rx=g.axes[2];n.axes.ry=g.axes[3];n.axes.ltrigger=g.buttons[6].value;n.axes.rtrigger=g.buttons[7].value;n.hat="";n.hatmap=c.CENTER;for(var w=0;ww)n.buttons[c.mapping_array[w]]=g.buttons[w].pressed,g.buttons[w].was_pressed&&this.trigger(c.mapping_array[w]+"_button_event");else switch(w){case 12:g.buttons[w].pressed&&(n.hat+="up",n.hatmap|=c.UP); -break;case 13:g.buttons[w].pressed&&(n.hat+="down",n.hatmap|=c.DOWN);break;case 14:g.buttons[w].pressed&&(n.hat+="left",n.hatmap|=c.LEFT);break;case 15:g.buttons[w].pressed&&(n.hat+="right",n.hatmap|=c.RIGHT);break;case 16:n.buttons.home=g.buttons[w].pressed}g.xbox=n;return g}};c.prototype.onDrawBackground=function(c){if(!this.flags.collapsed){var g=this._left_axis,q=this._right_axis;c.strokeStyle="#88A";c.strokeRect(.5*(g[0]+1)*this.size[0]-4,.5*(g[1]+1)*this.size[1]-4,8,8);c.strokeStyle="#8A8"; -c.strokeRect(.5*(q[0]+1)*this.size[0]-4,.5*(q[1]+1)*this.size[1]-4,8,8);g=this.size[1]/this._current_buttons.length;c.fillStyle="#AEB";for(q=0;q","enum",{values:a.values});this.addWidget("combo", -"Cond.",this.properties.OP,{property:"OP",values:a.values});this.size=[80,60]}function b(){this.addInput("in","");this.addInput("cond","boolean");this.addOutput("true","");this.addOutput("false","");this.size=[80,60]}function d(){this.addInput("inc","number");this.addOutput("total","number");this.addProperty("increment",1);this.addProperty("value",0)}function h(){this.addInput("v","number");this.addOutput("sin","number");this.addProperty("amplitude",1);this.addProperty("offset",0);this.bgImageUrl= -"nodes/imgs/icon-sin.png"}function f(){this.addInput("x","number");this.addInput("y","number");this.addOutput("","number");this.properties={x:1,y:1,formula:"x+y"};this.code_widget=this.addWidget("text","F(x,y)",this.properties.formula,function(a,b,d){d.properties.formula=a});this.addWidget("toggle","allow",I.allow_scripts,function(a){I.allow_scripts=a});this._func=null}function x(){this.addInput("vec2","vec2");this.addOutput("x","number");this.addOutput("y","number")}function J(){this.addInputs([["x", -"number"],["y","number"]]);this.addOutput("vec2","vec2");this.properties={x:0,y:0};this._data=new Float32Array(2)}function u(){this.addInput("vec3","vec3");this.addOutput("x","number");this.addOutput("y","number");this.addOutput("z","number")}function v(){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 O(){this.addInput("vec4","vec4");this.addOutput("x","number");this.addOutput("y","number"); -this.addOutput("z","number");this.addOutput("w","number")}function N(){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 I=z.LiteGraph;c.title="Converter";c.desc="type A to type B";c.prototype.onExecute=function(){var a=this.getInputData(0);if(null!=a&&this.outputs)for(var b=0;ba&&(a+=1024);var c=Math.floor(a);a-=c;d=l.data[c];c=l.data[1023==c?0:c+1];b&&(a=a*a*a*(a*(6*a-15)+10));return d*(1-a)+c*a};l.prototype.onExecute=function(){var a= -this.getInputData(0)||0,b=this.properties.octaves||1,d=0,c=1;a+=this.properties.seed||0;for(var f=this.properties.speed||1,h=0,k=0;kc);++k);a=this.properties.min;this._last_v=d/h*(this.properties.max-a)+a;this.setOutputData(0,this._last_v)};l.prototype.onDrawBackground=function(a){this.outputs[0].label=(this._last_v||0).toFixed(3)};I.registerNodeType("math/noise",l);A.title="Spikes";A.desc="spike every random time"; -A.prototype.onExecute=function(){var a=this.graph.elapsed_time;this._remaining_time-=a;this._blink_time-=a;a=0;0this._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)};I.registerNodeType("math/spikes",A);B.title="Clamp";B.desc= -"Clamp number between min and max";B.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))};B.prototype.getCode=function(a){a="";this.isInputConnected(0)&&(a+="clamp({{0}},"+this.properties.min+","+this.properties.max+")");return a};I.registerNodeType("math/clamp",B);C.title="Lerp";C.desc="Linear Interpolation";C.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=0);var b= -this.getInputData(1);null==b&&(b=0);var d=this.properties.f,c=this.getInputData(2);void 0!==c&&(d=c);this.setOutputData(0,a*(1-d)+b*d)};C.prototype.onGetInputs=function(){return[["f","number"]]};I.registerNodeType("math/lerp",C);G.title="Abs";G.desc="Absolute";G.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,Math.abs(a))};I.registerNodeType("math/abs",G);D.title="Floor";D.desc="Floor number to remove fractional part";D.prototype.onExecute=function(){var a= -this.getInputData(0);null!=a&&this.setOutputData(0,Math.floor(a))};I.registerNodeType("math/floor",D);e.title="Frac";e.desc="Returns fractional part";e.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,a%1)};I.registerNodeType("math/frac",e);r.title="Smoothstep";r.desc="Smoothstep";r.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))}}; -I.registerNodeType("math/smoothstep",r);F.title="Scale";F.desc="v * factor";F.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,a*this.properties.factor)};I.registerNodeType("math/scale",F);y.title="Gate";y.desc="if v is true, then outputs A, otherwise B";y.prototype.onExecute=function(){var a=this.getInputData(0);this.setOutputData(0,this.getInputData(a?1:2))};I.registerNodeType("math/gate",y);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 d=a=0;db&&(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))};I.registerNodeType("math/average", -K);k.title="TendTo";k.desc="moves the output value always closer to the input";k.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)};I.registerNodeType("math/tendTo",k);m.values="+ - * / % ^ max min".split(" ");m.title="Operation";m.desc="Easy math operators";m["@OP"]={type:"enum",title:"operation",values:m.values};m.size=[100,60];m.prototype.getTitle=function(){return"max"== -this.properties.OP||"min"==this.properties.OP?this.properties.OP+"(A,B)":"A "+this.properties.OP+" B"};m.prototype.setValue=function(a){"string"==typeof a&&(a=parseFloat(a));this.properties.value=a};m.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}}};m.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 d=this._func(a,b);else if(a.constructor===Array){d=this._result;d.length=a.length;for(var c=0;cB":h=a>b;break;case "A=B":h=a>=b}this.setOutputData(d,h)}}};t.prototype.onGetOutputs=function(){return[["A==B","boolean"],["A!=B","boolean"],["A>B","boolean"],["A=B","boolean"],["A<=B","boolean"]]};I.registerNodeType("math/compare",t);I.registerSearchboxExtra("math/compare","==",{outputs:[["A==B","boolean"]],title:"A==B"}); -I.registerSearchboxExtra("math/compare","!=",{outputs:[["A!=B","boolean"]],title:"A!=B"});I.registerSearchboxExtra("math/compare",">",{outputs:[["A>B","boolean"]],title:"A>B"});I.registerSearchboxExtra("math/compare","<",{outputs:[["A=",{outputs:[["A>=B","boolean"]],title:"A>=B"});I.registerSearchboxExtra("math/compare","<=",{outputs:[["A<=B","boolean"]],title:"A<=B"});a.values="> < == != <= >= || &&".split(" ");a["@OP"]={type:"enum", +b.prototype.onAction=function(a,b){var d=this;setTimeout(function(){d.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};K.registerNodeType("basic/download",b);d.title="Watch";d.desc="Show value of input";d.prototype.onExecute=function(){this.inputs[0]&&(this.value=this.getInputData(0))};d.prototype.getTitle=function(){return this.flags.collapsed? +this.inputs[0].label:this.title};d.toString=function(a){if(null==a)return"null";if(a.constructor===Number)return a.toFixed(3);if(a.constructor===Array){for(var b="[",f=0;f=c?this.trigger(null,e,h):this._pending.push([c,e])};A.prototype.onExecute=function(c,e){c=1E3*this.graph.elapsed_time;this.isInputConnected(1)&&(this.properties.time_in_ms=this.getInputData(1));for(var h=0;hh[1]))return this.old_y=c.canvasY,this.captureInput(!0),this.mouse_captured=!0};r.prototype.onMouseMove=function(c){if(this.mouse_captured){var e=this.old_y-c.canvasY;c.shiftKey&&(e*=10);if(c.metaKey||c.altKey)e*=.1;this.old_y=c.canvasY;c=this._remainder+e/r.pixels_threshold;this._remainder=c%1;c=Math.clamp(this.properties.value+ +(c|0)*this.properties.step,this.properties.min,this.properties.max);this.properties.value=c;this.graph._version++;this.setDirtyCanvas(!0)}};r.prototype.onMouseUp=function(c,h){200>c.click_time&&(this.properties.value=Math.clamp(this.properties.value+(h[1]>.5*this.size[1]?-1:1)*this.properties.step,this.properties.min,this.properties.max),this.graph._version++,this.setDirtyCanvas(!0));this.mouse_captured&&(this.mouse_captured=!1,this.captureInput(!1))};F.registerNodeType("widget/number",r);t.title= +"Combo";t.desc="Widget to select from a list";t.prototype.onExecute=function(){this.setOutputData(0,this.properties.value)};t.prototype.onPropertyChanged=function(c,h){"values"==c?(this._values=h.split(";"),this.widget.options.values=this._values):"value"==c&&(this.widget.value=h)};F.registerNodeType("widget/combo",t);v.title="Knob";v.desc="Circular controller";v.size=[80,100];v.prototype.onDrawForeground=function(c){if(!this.flags.collapsed){-1==this.value&&(this.value=(this.properties.value-this.properties.min)/ +(this.properties.max-this.properties.min));var e=.5*this.size[0],h=.5*this.size[1],l=.5*Math.min(this.size[0],this.size[1])-5;c.globalAlpha=1;c.save();c.translate(e,h);c.rotate(.75*Math.PI);c.fillStyle="rgba(0,0,0,0.5)";c.beginPath();c.moveTo(0,0);c.arc(0,0,l,0,1.5*Math.PI);c.fill();c.strokeStyle="black";c.fillStyle=this.properties.color;c.lineWidth=2;c.beginPath();c.moveTo(0,0);c.arc(0,0,l-4,0,1.5*Math.PI*Math.max(.01,this.value));c.closePath();c.fill();c.lineWidth=1;c.globalAlpha=1;c.restore(); +c.fillStyle="black";c.beginPath();c.arc(e,h,.75*l,0,2*Math.PI,!0);c.fill();c.fillStyle=this.mouseOver?"white":this.properties.color;c.beginPath();var r=this.value*Math.PI*1.5+.75*Math.PI;c.arc(e+Math.cos(r)*l*.65,h+Math.sin(r)*l*.65,.05*l,0,2*Math.PI,!0);c.fill();c.fillStyle=this.mouseOver?"white":"#AAA";c.font=Math.floor(.5*l)+"px Arial";c.textAlign="center";c.fillText(this.properties.value.toFixed(this.properties.precision),e,h+.15*l)}};v.prototype.onExecute=function(){this.setOutputData(0,this.properties.value); +this.boxcolor=F.colorToString([this.value,this.value,this.value])};v.prototype.onMouseDown=function(c){this.center=[.5*this.size[0],.5*this.size[1]+20];this.radius=.5*this.size[0];if(20>c.canvasY-this.pos[1]||F.distance([c.canvasX,c.canvasY],[this.pos[0]+this.center[0],this.pos[1]+this.center[1]])>this.radius)return!1;this.oldmouse=[c.canvasX-this.pos[0],c.canvasY-this.pos[1]];this.captureInput(!0);return!0};v.prototype.onMouseMove=function(c){if(this.oldmouse){c=[c.canvasX-this.pos[0],c.canvasY- +this.pos[1]];var e=this.value;e-=.01*(c[1]-this.oldmouse[1]);1e&&(e=0);this.value=e;this.properties.value=this.properties.min+(this.properties.max-this.properties.min)*this.value;this.oldmouse=c;this.setDirtyCanvas(!0)}};v.prototype.onMouseUp=function(c){this.oldmouse&&(this.oldmouse=null,this.captureInput(!1))};v.prototype.onPropertyChanged=function(c,h){if("min"==c||"max"==c||"value"==c)return this.properties[c]=parseFloat(h),!0};F.registerNodeType("widget/knob",v);h.title="Inner Slider"; +h.prototype.onPropertyChanged=function(c,h){"value"==c&&(this.slider.value=h)};h.prototype.onExecute=function(){this.setOutputData(0,this.properties.value)};F.registerNodeType("widget/internal_slider",h);E.title="H.Slider";E.desc="Linear slider controller";E.prototype.onDrawForeground=function(c){-1==this.value&&(this.value=(this.properties.value-this.properties.min)/(this.properties.max-this.properties.min));c.globalAlpha=1;c.lineWidth=1;c.fillStyle="#000";c.fillRect(2,2,this.size[0]-4,this.size[1]- +4);c.fillStyle=this.properties.color;c.beginPath();c.rect(4,4,(this.size[0]-8)*this.value,this.size[1]-8);c.fill()};E.prototype.onExecute=function(){this.properties.value=this.properties.min+(this.properties.max-this.properties.min)*this.value;this.setOutputData(0,this.properties.value);this.boxcolor=F.colorToString([this.value,this.value,this.value])};E.prototype.onMouseDown=function(c){if(0>c.canvasY-this.pos[1])return!1;this.oldmouse=[c.canvasX-this.pos[0],c.canvasY-this.pos[1]];this.captureInput(!0); +return!0};E.prototype.onMouseMove=function(c){if(this.oldmouse){c=[c.canvasX-this.pos[0],c.canvasY-this.pos[1]];var e=this.value;e+=(c[0]-this.oldmouse[0])/this.size[0];1e&&(e=0);this.value=e;this.oldmouse=c;this.setDirtyCanvas(!0)}};E.prototype.onMouseUp=function(c){this.oldmouse=null;this.captureInput(!1)};E.prototype.onMouseLeave=function(c){};F.registerNodeType("widget/hslider",E);A.title="Progress";A.desc="Shows data in linear progress";A.prototype.onExecute=function(){var c=this.getInputData(0); +void 0!=c&&(this.properties.value=c)};A.prototype.onDrawForeground=function(c){c.lineWidth=1;c.fillStyle=this.properties.color;var e=(this.properties.value-this.properties.min)/(this.properties.max-this.properties.min);e=Math.min(1,e);e=Math.max(0,e);c.fillRect(2,2,(this.size[0]-4)*e,this.size[1]-4)};F.registerNodeType("widget/progress",A);I.title="Text";I.desc="Shows the input value";I.widgets=[{name:"resize",text:"Resize box",type:"button"},{name:"led_text",text:"LED",type:"minibutton"},{name:"normal_text", +text:"Normal",type:"minibutton"}];I.prototype.onDrawForeground=function(c){c.fillStyle=this.properties.color;var e=this.properties.value;this.properties.glowSize?(c.shadowColor=this.properties.color,c.shadowOffsetX=0,c.shadowOffsetY=0,c.shadowBlur=this.properties.glowSize):c.shadowColor="transparent";var h=this.properties.fontsize;c.textAlign=this.properties.align;c.font=h.toString()+"px "+this.properties.font;this.str="number"==typeof e?e.toFixed(this.properties.decimals):e;if("string"==typeof this.str){e= +this.str.replace(/[\r\n]/g,"\\n").split("\\n");for(var l=0;lt?l.xbox.axes.lx:0,this._left_axis[1]=Math.abs(l.xbox.axes.ly)>t?l.xbox.axes.ly:0,this._right_axis[0]=Math.abs(l.xbox.axes.rx)>t?l.xbox.axes.rx:0,this._right_axis[1]=Math.abs(l.xbox.axes.ry)>t?l.xbox.axes.ry:0,this._triggers[0]=Math.abs(l.xbox.axes.ltrigger)>t?l.xbox.axes.ltrigger: +0,this._triggers[1]=Math.abs(l.xbox.axes.rtrigger)>t?l.xbox.axes.rtrigger:0);if(this.outputs)for(t=0;tt;t++)if(l[t]){l=l[t];t=this.xbox_mapping;t||(t=this.xbox_mapping={axes:[], +buttons:{},hat:"",hatmap:c.CENTER});t.axes.lx=l.axes[0];t.axes.ly=l.axes[1];t.axes.rx=l.axes[2];t.axes.ry=l.axes[3];t.axes.ltrigger=l.buttons[6].value;t.axes.rtrigger=l.buttons[7].value;t.hat="";t.hatmap=c.CENTER;for(var v=0;vv)t.buttons[c.mapping_array[v]]=l.buttons[v].pressed,l.buttons[v].was_pressed&&this.trigger(c.mapping_array[v]+"_button_event");else switch(v){case 12:l.buttons[v].pressed&&(t.hat+="up",t.hatmap|=c.UP); +break;case 13:l.buttons[v].pressed&&(t.hat+="down",t.hatmap|=c.DOWN);break;case 14:l.buttons[v].pressed&&(t.hat+="left",t.hatmap|=c.LEFT);break;case 15:l.buttons[v].pressed&&(t.hat+="right",t.hatmap|=c.RIGHT);break;case 16:t.buttons.home=l.buttons[v].pressed}l.xbox=t;return l}};c.prototype.onDrawBackground=function(c){if(!this.flags.collapsed){var l=this._left_axis,r=this._right_axis;c.strokeStyle="#88A";c.strokeRect(.5*(l[0]+1)*this.size[0]-4,.5*(l[1]+1)*this.size[1]-4,8,8);c.strokeStyle="#8A8"; +c.strokeRect(.5*(r[0]+1)*this.size[0]-4,.5*(r[1]+1)*this.size[1]-4,8,8);l=this.size[1]/this._current_buttons.length;c.fillStyle="#AEB";for(r=0;r","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 d(){this.addInput("inc","number");this.addOutput("total","number");this.addProperty("increment",1);this.addProperty("value",0)}function g(){this.addInput("v","number");this.addOutput("sin","number");this.addProperty("amplitude",1);this.addProperty("offset",0);this.bgImageUrl="nodes/imgs/icon-sin.png"} +function f(){this.addInput("x","number");this.addInput("y","number");this.addOutput("","number");this.properties={x:1,y:1,formula:"x+y"};this.code_widget=this.addWidget("text","F(x,y)",this.properties.formula,function(a,b,d){d.properties.formula=a});this.addWidget("toggle","allow",w.allow_scripts,function(a){w.allow_scripts=a});this._func=null}function m(){this.addInput("vec2","vec2");this.addOutput("x","number");this.addOutput("y","number")}function u(){this.addInputs([["x","number"],["y","number"]]); +this.addOutput("vec2","vec2");this.properties={x:0,y:0};this._data=new Float32Array(2)}function O(){this.addInput("vec3","vec3");this.addOutput("x","number");this.addOutput("y","number");this.addOutput("z","number")}function K(){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 x(){this.addInput("vec4","vec4");this.addOutput("x","number");this.addOutput("y","number");this.addOutput("z", +"number");this.addOutput("w","number")}function C(){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 w=B.LiteGraph;c.title="Converter";c.desc="type A to type B";c.prototype.onExecute=function(){var a=this.getInputData(0);if(null!=a&&this.outputs)for(var b=0;ba&&(a+=1024);var c=Math.floor(a);a-=c;d=h.data[c];c=h.data[1023==c?0:c+1];b&&(a=a*a*a*(a*(6*a-15)+10));return d*(1-a)+c*a};h.prototype.onExecute=function(){var a= +this.getInputData(0)||0,b=this.properties.octaves||1,d=0,c=1;a+=this.properties.seed||0;for(var f=this.properties.speed||1,g=0,e=0;ec);++e);a=this.properties.min;this._last_v=d/g*(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)};w.registerNodeType("math/noise",h);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;0this._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)};w.registerNodeType("math/spikes",E);A.title="Clamp";A.desc= +"Clamp number between min and max";A.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))};A.prototype.getCode=function(a){a="";this.isInputConnected(0)&&(a+="clamp({{0}},"+this.properties.min+","+this.properties.max+")");return a};w.registerNodeType("math/clamp",A);I.title="Lerp";I.desc="Linear Interpolation";I.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=0);var b= +this.getInputData(1);null==b&&(b=0);var d=this.properties.f,c=this.getInputData(2);void 0!==c&&(d=c);this.setOutputData(0,a*(1-d)+b*d)};I.prototype.onGetInputs=function(){return[["f","number"]]};w.registerNodeType("math/lerp",I);J.title="Abs";J.desc="Absolute";J.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,Math.abs(a))};w.registerNodeType("math/abs",J);F.title="Floor";F.desc="Floor number to remove fractional part";F.prototype.onExecute=function(){var a= +this.getInputData(0);null!=a&&this.setOutputData(0,Math.floor(a))};w.registerNodeType("math/floor",F);e.title="Frac";e.desc="Returns fractional part";e.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,a%1)};w.registerNodeType("math/frac",e);D.title="Smoothstep";D.desc="Smoothstep";D.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))}}; +w.registerNodeType("math/smoothstep",D);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)};w.registerNodeType("math/scale",H);z.title="Gate";z.desc="if v is true, then outputs A, otherwise B";z.prototype.onExecute=function(){var a=this.getInputData(0);this.setOutputData(0,this.getInputData(a?1:2))};w.registerNodeType("math/gate",z);M.title="Average";M.desc="Average Filter";M.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 d=a=0;db&&(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))};w.registerNodeType("math/average", +M);k.title="TendTo";k.desc="moves the output value always closer to the input";k.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)};w.registerNodeType("math/tendTo",k);n.values="+ - * / % ^ max min".split(" ");n.title="Operation";n.desc="Easy math operators";n["@OP"]={type:"enum",title:"operation",values:n.values};n.size=[100,60];n.prototype.getTitle=function(){return"max"== +this.properties.OP||"min"==this.properties.OP?this.properties.OP+"(A,B)":"A "+this.properties.OP+" B"};n.prototype.setValue=function(a){"string"==typeof a&&(a=parseFloat(a));this.properties.value=a};n.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}}};n.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 d=this._func(a,b);else if(a.constructor===Array){d=this._result;d.length=a.length;for(var c=0;cB":g=a>b;break;case "A=B":g=a>=b}this.setOutputData(d,g)}}};q.prototype.onGetOutputs=function(){return[["A==B","boolean"],["A!=B","boolean"],["A>B","boolean"],["A=B","boolean"],["A<=B","boolean"]]};w.registerNodeType("math/compare",q);w.registerSearchboxExtra("math/compare","==",{outputs:[["A==B","boolean"]],title:"A==B"}); +w.registerSearchboxExtra("math/compare","!=",{outputs:[["A!=B","boolean"]],title:"A!=B"});w.registerSearchboxExtra("math/compare",">",{outputs:[["A>B","boolean"]],title:"A>B"});w.registerSearchboxExtra("math/compare","<",{outputs:[["A=",{outputs:[["A>=B","boolean"]],title:"A>=B"});w.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 d=!0;switch(this.properties.OP){case ">":d=a>b;break;case "<":d=a=":d=a>=b;break;case "||":d=a||b;break;case "&&":d=a&&b}this.setOutputData(0,d);this.setOutputData(1,!d)};I.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))};I.registerNodeType("math/branch",b);d.title="Accumulate";d.desc="Increments a value every time"; -d.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)};I.registerNodeType("math/accumulate",d);h.title="Trigonometry";h.desc="Sin Cos Tan";h.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=0);var b=this.properties.amplitude,d=this.findInputSlot("amplitude");-1!=d&&(b=this.getInputData(d)); -var c=this.properties.offset;d=this.findInputSlot("offset");-1!=d&&(c=this.getInputData(d));d=0;for(var f=this.outputs.length;dXY";x.desc="vector 2 to components";x.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&(this.setOutputData(0,a[0]),this.setOutputData(1,a[1]))};I.registerNodeType("math3d/vec2-to-xy", -x);J.title="XY->Vec2";J.desc="components to vector2";J.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 d=this._data;d[0]=a;d[1]=b;this.setOutputData(0,d)};I.registerNodeType("math3d/xy-to-vec2",J);u.title="Vec3->XYZ";u.desc="vector 3 to components";u.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]))}; -I.registerNodeType("math3d/vec3-to-xyz",u);v.title="XYZ->Vec3";v.desc="components to vector3";v.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 d=this.getInputData(2);null==d&&(d=this.properties.z);var c=this._data;c[0]=a;c[1]=b;c[2]=d;this.setOutputData(0,c)};I.registerNodeType("math3d/xyz-to-vec3",v);O.title="Vec4->XYZW";O.desc="vector 4 to components";O.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]))};I.registerNodeType("math3d/vec4-to-xyzw",O);N.title="XYZW->Vec4";N.desc="components to vector4";N.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 d=this.getInputData(2);null==d&&(d=this.properties.z);var c=this.getInputData(3);null==c&&(c=this.properties.w);var f=this._data;f[0]= -a;f[1]=b;f[2]=d;f[3]=c;this.setOutputData(0,f)};I.registerNodeType("math3d/xyzw-to-vec4",N)})(this); -(function(z){function c(){this.addInput("T","vec3");this.addInput("R","vec3");this.addInput("S","vec3");this.addOutput("mat4","mat4");this.properties={T:[0,0,0],R:[0,0,0],S:[1,1,1],R_in_degrees:!0};this._result=mat4.create();this._must_update=!0}function g(){this.addInput("A","number,vec3");this.addInput("B","number,vec3");this.addOutput("=","number,vec3");this.addProperty("OP","+","enum",{values:g.values});this._result=vec3.create()}function q(){this.addInput("in","vec3");this.addInput("f","number"); -this.addOutput("out","vec3");this.properties={f:1};this._data=new Float32Array(3)}function n(){this.addInput("in","vec3");this.addOutput("out","number")}function w(){this.addInput("in","vec3");this.addOutput("out","vec3");this._data=new Float32Array(3)}function l(){this.addInput("A","vec3");this.addInput("B","vec3");this.addInput("f","vec3");this.addOutput("out","vec3");this.properties={f:.5};this._data=new Float32Array(3)}function A(){this.addInput("A","vec3");this.addInput("B","vec3");this.addOutput("out", -"number")}var B=z.LiteGraph;c.title="mat4";c.temp_quat=new Float32Array([0,0,0,1]);c.temp_mat4=new Float32Array(16);c.temp_vec3=new Float32Array(3);c.prototype.onPropertyChanged=function(c,k){this._must_update=!0};c.prototype.onExecute=function(){var e=this._result,k=c.temp_quat,g=c.temp_mat4,t=c.temp_vec3,a=this.getInputData(0),b=this.getInputData(1),d=this.getInputData(2);if(this._must_update||a||b||d)a=a||this.properties.T,b=b||this.properties.R,d=d||this.properties.S,mat4.identity(e),mat4.translate(e, -e,a),this.properties.R_in_degrees?(t.set(b),vec3.scale(t,t,DEG2RAD),quat.fromEuler(k,t)):quat.fromEuler(k,b),mat4.fromQuat(g,k),mat4.multiply(e,e,g),mat4.scale(e,e,d);this.setOutputData(0,e)};B.registerNodeType("math3d/mat4",c);g.values="+ - * / % ^ max min dot cross".split(" ");B.registerSearchboxExtra("math3d/operation","CROSS()",{properties:{OP:"cross"},title:"CROSS()"});B.registerSearchboxExtra("math3d/operation","DOT()",{properties:{OP:"dot"},title:"DOT()"});g.title="Operation";g.desc="Easy math 3D operators"; -g["@OP"]={type:"enum",title:"operation",values:g.values};g.size=[100,60];g.prototype.getTitle=function(){return"max"==this.properties.OP||"min"==this.properties.OP?this.properties.OP+"(A,B)":"A "+this.properties.OP+" B"};g.prototype.onExecute=function(){var c=this.getInputData(0),e=this.getInputData(1);if(null!=c&&null!=e){c.constructor===Number&&(c=[c,c,c]);e.constructor===Number&&(e=[e,e,e]);var g=this._result;switch(this.properties.OP){case "+":g=vec3.add(g,c,e);break;case "-":g=vec3.sub(g,c,e); -break;case "x":case "X":case "*":g=vec3.mul(g,c,e);break;case "/":g=vec3.div(g,c,e);break;case "%":g[0]=c[0]%e[0];g[1]=c[1]%e[1];g[2]=c[2]%e[2];break;case "^":g[0]=Math.pow(c[0],e[0]);g[1]=Math.pow(c[1],e[1]);g[2]=Math.pow(c[2],e[2]);break;case "max":g[0]=Math.max(c[0],e[0]);g[1]=Math.max(c[1],e[1]);g[2]=Math.max(c[2],e[2]);break;case "min":g[0]=Math.min(c[0],e[0]),g[1]=Math.min(c[1],e[1]),g[2]=Math.min(c[2],e[2]);case "dot":g=vec3.dot(c,e);break;case "cross":vec3.cross(g,c,e);break;default:console.warn("Unknown operation: "+ -this.properties.OP)}this.setOutputData(0,g)}};g.prototype.onDrawBackground=function(c){this.flags.collapsed||(c.font="40px Arial",c.fillStyle="#666",c.textAlign="center",c.fillText(this.properties.OP,.5*this.size[0],.5*(this.size[1]+B.NODE_TITLE_HEIGHT)),c.textAlign="left")};B.registerNodeType("math3d/operation",g);q.title="vec3_scale";q.desc="scales the components of a vec3";q.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var e=this.getInputData(1);null==e&&(e=this.properties.f); -var g=this._data;g[0]=c[0]*e;g[1]=c[1]*e;g[2]=c[2]*e;this.setOutputData(0,g)}};B.registerNodeType("math3d/vec3-scale",q);n.title="vec3_length";n.desc="returns the module of a vector";n.prototype.onExecute=function(){var c=this.getInputData(0);null!=c&&this.setOutputData(0,Math.sqrt(c[0]*c[0]+c[1]*c[1]+c[2]*c[2]))};B.registerNodeType("math3d/vec3-length",n);w.title="vec3_normalize";w.desc="returns the vector normalized";w.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var e= -Math.sqrt(c[0]*c[0]+c[1]*c[1]+c[2]*c[2]),g=this._data;g[0]=c[0]/e;g[1]=c[1]/e;g[2]=c[2]/e;this.setOutputData(0,g)}};B.registerNodeType("math3d/vec3-normalize",w);l.title="vec3_lerp";l.desc="returns the interpolated vector";l.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var e=this.getInputData(1);if(null!=e){var g=this.getInputOrProperty("f"),t=this._data;t[0]=c[0]*(1-g)+e[0]*g;t[1]=c[1]*(1-g)+e[1]*g;t[2]=c[2]*(1-g)+e[2]*g;this.setOutputData(0,t)}}};B.registerNodeType("math3d/vec3-lerp", -l);A.title="vec3_dot";A.desc="returns the dot product";A.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var e=this.getInputData(1);null!=e&&this.setOutputData(0,c[0]*e[0]+c[1]*e[1]+c[2]*e[2])}};B.registerNodeType("math3d/vec3-dot",A);if(z.glMatrix){z=function(){this.addInput("vec3","vec3");this.addOutput("remap","vec3");this.addOutput("clamped","vec3");this.properties={clamp:!0,range_min:[-1,-1,0],range_max:[1,1,0],target_min:[-1,-1,0],target_max:[1,1,0]};this._value=vec3.create(); -this._clamped=vec3.create()};var C=function(){this.addInputs([["A","quat"],["B","quat"],["factor","number"]]);this.addOutput("slerp","quat");this.addProperty("factor",.5);this._value=quat.create()},G=function(){this.addInputs([["A","quat"],["B","quat"]]);this.addOutput("A*B","quat");this._value=quat.create()},D=function(){this.addInputs([["vec3","vec3"],["quat","quat"]]);this.addOutput("result","vec3");this.properties={vec:[0,0,1]}},e=function(){this.addInput(["quat","quat"]);this.addOutput("euler", -"vec3");this._value=vec3.create()},r=function(){this.addInput("euler","vec3");this.addOutput("quat","quat");this.properties={euler:[0,0,0],use_yaw_pitch_roll:!1};this._degs=vec3.create();this._value=quat.create()},F=function(){this.addInputs([["degrees","number"],["axis","vec3"]]);this.addOutput("quat","quat");this.properties={angle:90,axis:vec3.fromValues(0,1,0)};this._value=quat.create()},y=function(){this.addOutput("quat","quat");this.properties={x:0,y:0,z:0,w:1,normalize:!1};this._value=quat.create()}; -y.title="Quaternion";y.desc="quaternion";y.prototype.onExecute=function(){this._value[0]=this.getInputOrProperty("x");this._value[1]=this.getInputOrProperty("y");this._value[2]=this.getInputOrProperty("z");this._value[3]=this.getInputOrProperty("w");this.properties.normalize&&quat.normalize(this._value,this._value);this.setOutputData(0,this._value)};y.prototype.onGetInputs=function(){return[["x","number"],["y","number"],["z","number"],["w","number"]]};B.registerNodeType("math3d/quaternion",y);F.title= -"Rotation";F.desc="quaternion rotation";F.prototype.onExecute=function(){var c=this.getInputData(0);null==c&&(c=this.properties.angle);var e=this.getInputData(1);null==e&&(e=this.properties.axis);c=quat.setAxisAngle(this._value,e,.0174532925*c);this.setOutputData(0,c)};B.registerNodeType("math3d/rotation",F);r.title="Euler->Quat";r.desc="Converts euler angles (in degrees) to quaternion";r.prototype.onExecute=function(){var c=this.getInputData(0);null==c&&(c=this.properties.euler);vec3.scale(this._degs, -c,DEG2RAD);this.properties.use_yaw_pitch_roll&&(this._degs=[this._degs[2],this._degs[0],this._degs[1]]);c=quat.fromEuler(this._value,this._degs);this.setOutputData(0,c)};B.registerNodeType("math3d/euler_to_quat",r);e.title="Euler->Quat";e.desc="Converts rotX,rotY,rotZ in degrees to quat";e.prototype.onExecute=function(){var c=this.getInputData(0);c&&(quat.toEuler(this._value,c),vec3.scale(this._value,this._value,DEG2RAD),this.setOutputData(0,this._value))};B.registerNodeType("math3d/quat_to_euler", -e);D.title="Rot. Vec3";D.desc="rotate a point";D.prototype.onExecute=function(){var c=this.getInputData(0);null==c&&(c=this.properties.vec);var e=this.getInputData(1);null==e?this.setOutputData(c):this.setOutputData(0,vec3.transformQuat(vec3.create(),c,e))};B.registerNodeType("math3d/rotate_vec3",D);G.title="Mult. Quat";G.desc="rotate quaternion";G.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var e=this.getInputData(1);null!=e&&(c=quat.multiply(this._value,c,e),this.setOutputData(0, -c))}};B.registerNodeType("math3d/mult-quat",G);C.title="Quat Slerp";C.desc="quaternion spherical interpolation";C.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var e=this.getInputData(1);if(null!=e){var g=this.properties.factor;null!=this.getInputData(2)&&(g=this.getInputData(2));c=quat.slerp(this._value,c,e,g);this.setOutputData(0,c)}}};B.registerNodeType("math3d/quat-slerp",C);z.title="Remap Range";z.desc="remap a 3D range";z.prototype.onExecute=function(){var c=this.getInputData(0); -c&&this._value.set(c);c=this.properties.range_min;for(var e=this.properties.range_max,g=this.properties.target_min,t=this.properties.target_max,a=0;3>a;++a){var b=e[a]-c[a];this._clamped[a]=Math.clamp(this._value[a],c[a],e[a]);0==b?this._value[a]=.5*(g[a]+t[a]):(b=(this._value[a]-c[a])/b,this.properties.clamp&&(b=Math.clamp(b,0,1)),this._value[a]=g[a]+b*(t[a]-g[a]))}this.setOutputData(0,this._value);this.setOutputData(1,this._clamped)};B.registerNodeType("math3d/remap_range",z)}else B.debug&&console.warn("No glmatrix found, some Math3D nodes may not work")})(this); -(function(z){function c(){this.addInput("","string");this.addOutput("table","table");this.addOutput("rows","number");this.addProperty("value","");this.addProperty("separator",",");this._table=null}z=z.LiteGraph;z.wrapFunctionAsNode("string/toString",function(c){if(c&&c.constructor===Object)try{return JSON.stringify(c)}catch(q){}return String(c)},[""],"String");z.wrapFunctionAsNode("string/compare",function(c,q){return c==q},["string","string"],"boolean");z.wrapFunctionAsNode("string/concatenate", -function(c,q){return void 0===c?q:void 0===q?c:c+q},["string","string"],"string");z.wrapFunctionAsNode("string/contains",function(c,q){return void 0===c||void 0===q?!1:-1!=c.indexOf(q)},["string","string"],"boolean");z.wrapFunctionAsNode("string/toUpperCase",function(c){return null!=c&&c.constructor===String?c.toUpperCase():c},["string"],"string");z.wrapFunctionAsNode("string/split",function(c,q){null==q&&(q=this.properties.separator);if(null==c)return[];if(c.constructor===String)return c.split(q|| -" ");if(c.constructor===Array){for(var g=[],w=0;we;++e){var g=this.getInputData(e);if(null!=g){var l=this.values[e];l.push(g);l.length>c[0]&&l.shift()}}}};c.prototype.onDrawBackground=function(e){if(!this.flags.collapsed){var g= -this.size,l=.5*g[1]/this.properties.scale,r=c.colors,k=.5*g[1];e.fillStyle="#000";e.fillRect(0,0,g[0],g[1]);e.strokeStyle="#555";e.beginPath();e.moveTo(0,k);e.lineTo(g[0],k);e.stroke();if(this.inputs)for(var m=0;4>m;++m){var t=this.values[m];if(this.inputs[m]&&this.inputs[m].link){e.strokeStyle=r[m];e.beginPath();var a=t[0]*l*-1+k;e.moveTo(0,Math.clamp(a,0,g[1]));for(var b=1;be&&(e=0);if(0!=c.length){var g=[0,0,0];if(0==e)g=c[0];else if(1==e)g=c[c.length- -1];else{var l=(c.length-1)*e;e=c[Math.floor(l)];c=c[Math.floor(l)+1];l-=Math.floor(l);g[0]=e[0]*(1-l)+c[0]*l;g[1]=e[1]*(1-l)+c[1]*l;g[2]=e[2]*(1-l)+c[2]*l}for(e=0;e=c&&(this._video.currentTime=c*this._video.duration,this._video.pause()); -this._video.dirty=!0;this.setOutputData(0,this._video);this.setOutputData(1,this._video.currentTime);this.setOutputData(2,this._video.duration);this.setDirtyCanvas(!0)}};G.prototype.onStart=function(){this.play()};G.prototype.onStop=function(){this.stop()};G.prototype.loadVideo=function(c){this._video_url=c;var g=c.substr(0,10).indexOf(":"),l="";-1!=g&&(l=c.substr(0,g));g="";l&&(g=c.substr(0,c.indexOf("/",l.length+3)),g=g.substr(l.length+3));this.properties.use_proxy&&l&&e.proxy&&g!=location.host&& -(c=e.proxy+c.substr(c.indexOf(":")+3));this._video=document.createElement("video");this._video.src=c;this._video.type="type=video/mp4";this._video.muted=!0;this._video.autoplay=!0;var n=this;this._video.addEventListener("loadedmetadata",function(c){console.log("Duration: "+this.duration+" seconds");console.log("Size: "+this.videoWidth+","+this.videoHeight);n.setDirtyCanvas(!0);this.width=this.videoWidth;this.height=this.videoHeight});this._video.addEventListener("progress",function(c){console.log("video loading...")}); +case ">=":d=a>=b;break;case "||":d=a||b;break;case "&&":d=a&&b}this.setOutputData(0,d);this.setOutputData(1,!d)};w.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))};w.registerNodeType("math/branch",b);d.title="Accumulate";d.desc="Increments a value every time"; +d.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)};w.registerNodeType("math/accumulate",d);g.title="Trigonometry";g.desc="Sin Cos Tan";g.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=0);var b=this.properties.amplitude,d=this.findInputSlot("amplitude");-1!=d&&(b=this.getInputData(d)); +var c=this.properties.offset;d=this.findInputSlot("offset");-1!=d&&(c=this.getInputData(d));d=0;for(var f=this.outputs.length;dXY";m.desc="vector 2 to components";m.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&(this.setOutputData(0,a[0]),this.setOutputData(1,a[1]))};w.registerNodeType("math3d/vec2-to-xy", +m);u.title="XY->Vec2";u.desc="components to vector2";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 d=this._data;d[0]=a;d[1]=b;this.setOutputData(0,d)};w.registerNodeType("math3d/xy-to-vec2",u);O.title="Vec3->XYZ";O.desc="vector 3 to components";O.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]))}; +w.registerNodeType("math3d/vec3-to-xyz",O);K.title="XYZ->Vec3";K.desc="components to vector3";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 d=this.getInputData(2);null==d&&(d=this.properties.z);var c=this._data;c[0]=a;c[1]=b;c[2]=d;this.setOutputData(0,c)};w.registerNodeType("math3d/xyz-to-vec3",K);x.title="Vec4->XYZW";x.desc="vector 4 to components";x.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]))};w.registerNodeType("math3d/vec4-to-xyzw",x);C.title="XYZW->Vec4";C.desc="components to vector4";C.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 d=this.getInputData(2);null==d&&(d=this.properties.z);var c=this.getInputData(3);null==c&&(c=this.properties.w);var f=this._data;f[0]= +a;f[1]=b;f[2]=d;f[3]=c;this.setOutputData(0,f)};w.registerNodeType("math3d/xyzw-to-vec4",C)})(this); +(function(B){function c(){this.addInput("T","vec3");this.addInput("R","vec3");this.addInput("S","vec3");this.addOutput("mat4","mat4");this.properties={T:[0,0,0],R:[0,0,0],S:[1,1,1],R_in_degrees:!0};this._result=mat4.create();this._must_update=!0}function l(){this.addInput("A","number,vec3");this.addInput("B","number,vec3");this.addOutput("=","number,vec3");this.addProperty("OP","+","enum",{values:l.values});this._result=vec3.create()}function r(){this.addInput("in","vec3");this.addInput("f","number"); +this.addOutput("out","vec3");this.properties={f:1};this._data=new Float32Array(3)}function t(){this.addInput("in","vec3");this.addOutput("out","number")}function v(){this.addInput("in","vec3");this.addOutput("out","vec3");this._data=new Float32Array(3)}function h(){this.addInput("A","vec3");this.addInput("B","vec3");this.addInput("f","vec3");this.addOutput("out","vec3");this.properties={f:.5};this._data=new Float32Array(3)}function E(){this.addInput("A","vec3");this.addInput("B","vec3");this.addOutput("out", +"number")}var A=B.LiteGraph;c.title="mat4";c.temp_quat=new Float32Array([0,0,0,1]);c.temp_mat4=new Float32Array(16);c.temp_vec3=new Float32Array(3);c.prototype.onPropertyChanged=function(c,e){this._must_update=!0};c.prototype.onExecute=function(){var e=this._result,k=c.temp_quat,n=c.temp_mat4,q=c.temp_vec3,a=this.getInputData(0),b=this.getInputData(1),d=this.getInputData(2);if(this._must_update||a||b||d)a=a||this.properties.T,b=b||this.properties.R,d=d||this.properties.S,mat4.identity(e),mat4.translate(e, +e,a),this.properties.R_in_degrees?(q.set(b),vec3.scale(q,q,DEG2RAD),quat.fromEuler(k,q)):quat.fromEuler(k,b),mat4.fromQuat(n,k),mat4.multiply(e,e,n),mat4.scale(e,e,d);this.setOutputData(0,e)};A.registerNodeType("math3d/mat4",c);l.values="+ - * / % ^ max min dot cross".split(" ");A.registerSearchboxExtra("math3d/operation","CROSS()",{properties:{OP:"cross"},title:"CROSS()"});A.registerSearchboxExtra("math3d/operation","DOT()",{properties:{OP:"dot"},title:"DOT()"});l.title="Operation";l.desc="Easy math 3D operators"; +l["@OP"]={type:"enum",title:"operation",values:l.values};l.size=[100,60];l.prototype.getTitle=function(){return"max"==this.properties.OP||"min"==this.properties.OP?this.properties.OP+"(A,B)":"A "+this.properties.OP+" B"};l.prototype.onExecute=function(){var c=this.getInputData(0),e=this.getInputData(1);if(null!=c&&null!=e){c.constructor===Number&&(c=[c,c,c]);e.constructor===Number&&(e=[e,e,e]);var n=this._result;switch(this.properties.OP){case "+":n=vec3.add(n,c,e);break;case "-":n=vec3.sub(n,c,e); +break;case "x":case "X":case "*":n=vec3.mul(n,c,e);break;case "/":n=vec3.div(n,c,e);break;case "%":n[0]=c[0]%e[0];n[1]=c[1]%e[1];n[2]=c[2]%e[2];break;case "^":n[0]=Math.pow(c[0],e[0]);n[1]=Math.pow(c[1],e[1]);n[2]=Math.pow(c[2],e[2]);break;case "max":n[0]=Math.max(c[0],e[0]);n[1]=Math.max(c[1],e[1]);n[2]=Math.max(c[2],e[2]);break;case "min":n[0]=Math.min(c[0],e[0]),n[1]=Math.min(c[1],e[1]),n[2]=Math.min(c[2],e[2]);case "dot":n=vec3.dot(c,e);break;case "cross":vec3.cross(n,c,e);break;default:console.warn("Unknown operation: "+ +this.properties.OP)}this.setOutputData(0,n)}};l.prototype.onDrawBackground=function(c){this.flags.collapsed||(c.font="40px Arial",c.fillStyle="#666",c.textAlign="center",c.fillText(this.properties.OP,.5*this.size[0],.5*(this.size[1]+A.NODE_TITLE_HEIGHT)),c.textAlign="left")};A.registerNodeType("math3d/operation",l);r.title="vec3_scale";r.desc="scales the components of a vec3";r.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var e=this.getInputData(1);null==e&&(e=this.properties.f); +var n=this._data;n[0]=c[0]*e;n[1]=c[1]*e;n[2]=c[2]*e;this.setOutputData(0,n)}};A.registerNodeType("math3d/vec3-scale",r);t.title="vec3_length";t.desc="returns the module of a vector";t.prototype.onExecute=function(){var c=this.getInputData(0);null!=c&&this.setOutputData(0,Math.sqrt(c[0]*c[0]+c[1]*c[1]+c[2]*c[2]))};A.registerNodeType("math3d/vec3-length",t);v.title="vec3_normalize";v.desc="returns the vector normalized";v.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var e= +Math.sqrt(c[0]*c[0]+c[1]*c[1]+c[2]*c[2]),n=this._data;n[0]=c[0]/e;n[1]=c[1]/e;n[2]=c[2]/e;this.setOutputData(0,n)}};A.registerNodeType("math3d/vec3-normalize",v);h.title="vec3_lerp";h.desc="returns the interpolated vector";h.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var e=this.getInputData(1);if(null!=e){var n=this.getInputOrProperty("f"),q=this._data;q[0]=c[0]*(1-n)+e[0]*n;q[1]=c[1]*(1-n)+e[1]*n;q[2]=c[2]*(1-n)+e[2]*n;this.setOutputData(0,q)}}};A.registerNodeType("math3d/vec3-lerp", +h);E.title="vec3_dot";E.desc="returns the dot product";E.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var e=this.getInputData(1);null!=e&&this.setOutputData(0,c[0]*e[0]+c[1]*e[1]+c[2]*e[2])}};A.registerNodeType("math3d/vec3-dot",E);if(B.glMatrix){B=function(){this.addInput("vec3","vec3");this.addOutput("remap","vec3");this.addOutput("clamped","vec3");this.properties={clamp:!0,range_min:[-1,-1,0],range_max:[1,1,0],target_min:[-1,-1,0],target_max:[1,1,0]};this._value=vec3.create(); +this._clamped=vec3.create()};var I=function(){this.addInputs([["A","quat"],["B","quat"],["factor","number"]]);this.addOutput("slerp","quat");this.addProperty("factor",.5);this._value=quat.create()},J=function(){this.addInputs([["A","quat"],["B","quat"]]);this.addOutput("A*B","quat");this._value=quat.create()},F=function(){this.addInputs([["vec3","vec3"],["quat","quat"]]);this.addOutput("result","vec3");this.properties={vec:[0,0,1]}},e=function(){this.addInput(["quat","quat"]);this.addOutput("euler", +"vec3");this._value=vec3.create()},D=function(){this.addInput("euler","vec3");this.addOutput("quat","quat");this.properties={euler:[0,0,0],use_yaw_pitch_roll:!1};this._degs=vec3.create();this._value=quat.create()},H=function(){this.addInputs([["degrees","number"],["axis","vec3"]]);this.addOutput("quat","quat");this.properties={angle:90,axis:vec3.fromValues(0,1,0)};this._value=quat.create()},z=function(){this.addOutput("quat","quat");this.properties={x:0,y:0,z:0,w:1,normalize:!1};this._value=quat.create()}; +z.title="Quaternion";z.desc="quaternion";z.prototype.onExecute=function(){this._value[0]=this.getInputOrProperty("x");this._value[1]=this.getInputOrProperty("y");this._value[2]=this.getInputOrProperty("z");this._value[3]=this.getInputOrProperty("w");this.properties.normalize&&quat.normalize(this._value,this._value);this.setOutputData(0,this._value)};z.prototype.onGetInputs=function(){return[["x","number"],["y","number"],["z","number"],["w","number"]]};A.registerNodeType("math3d/quaternion",z);H.title= +"Rotation";H.desc="quaternion rotation";H.prototype.onExecute=function(){var c=this.getInputData(0);null==c&&(c=this.properties.angle);var e=this.getInputData(1);null==e&&(e=this.properties.axis);c=quat.setAxisAngle(this._value,e,.0174532925*c);this.setOutputData(0,c)};A.registerNodeType("math3d/rotation",H);D.title="Euler->Quat";D.desc="Converts euler angles (in degrees) to quaternion";D.prototype.onExecute=function(){var c=this.getInputData(0);null==c&&(c=this.properties.euler);vec3.scale(this._degs, +c,DEG2RAD);this.properties.use_yaw_pitch_roll&&(this._degs=[this._degs[2],this._degs[0],this._degs[1]]);c=quat.fromEuler(this._value,this._degs);this.setOutputData(0,c)};A.registerNodeType("math3d/euler_to_quat",D);e.title="Euler->Quat";e.desc="Converts rotX,rotY,rotZ in degrees to quat";e.prototype.onExecute=function(){var c=this.getInputData(0);c&&(quat.toEuler(this._value,c),vec3.scale(this._value,this._value,DEG2RAD),this.setOutputData(0,this._value))};A.registerNodeType("math3d/quat_to_euler", +e);F.title="Rot. Vec3";F.desc="rotate a point";F.prototype.onExecute=function(){var c=this.getInputData(0);null==c&&(c=this.properties.vec);var e=this.getInputData(1);null==e?this.setOutputData(c):this.setOutputData(0,vec3.transformQuat(vec3.create(),c,e))};A.registerNodeType("math3d/rotate_vec3",F);J.title="Mult. Quat";J.desc="rotate quaternion";J.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var e=this.getInputData(1);null!=e&&(c=quat.multiply(this._value,c,e),this.setOutputData(0, +c))}};A.registerNodeType("math3d/mult-quat",J);I.title="Quat Slerp";I.desc="quaternion spherical interpolation";I.prototype.onExecute=function(){var c=this.getInputData(0);if(null!=c){var e=this.getInputData(1);if(null!=e){var n=this.properties.factor;null!=this.getInputData(2)&&(n=this.getInputData(2));c=quat.slerp(this._value,c,e,n);this.setOutputData(0,c)}}};A.registerNodeType("math3d/quat-slerp",I);B.title="Remap Range";B.desc="remap a 3D range";B.prototype.onExecute=function(){var c=this.getInputData(0); +c&&this._value.set(c);c=this.properties.range_min;for(var e=this.properties.range_max,n=this.properties.target_min,q=this.properties.target_max,a=0;3>a;++a){var b=e[a]-c[a];this._clamped[a]=Math.clamp(this._value[a],c[a],e[a]);0==b?this._value[a]=.5*(n[a]+q[a]):(b=(this._value[a]-c[a])/b,this.properties.clamp&&(b=Math.clamp(b,0,1)),this._value[a]=n[a]+b*(q[a]-n[a]))}this.setOutputData(0,this._value);this.setOutputData(1,this._clamped)};A.registerNodeType("math3d/remap_range",B)}else A.debug&&console.warn("No glmatrix found, some Math3D nodes may not work")})(this); +(function(B){function c(){this.addInput("","string");this.addOutput("table","table");this.addOutput("rows","number");this.addProperty("value","");this.addProperty("separator",",");this._table=null}B=B.LiteGraph;B.wrapFunctionAsNode("string/toString",function(c){if(c&&c.constructor===Object)try{return JSON.stringify(c)}catch(r){}return String(c)},[""],"string");B.wrapFunctionAsNode("string/compare",function(c,r){return c==r},["string","string"],"boolean");B.wrapFunctionAsNode("string/concatenate", +function(c,r){return void 0===c?r:void 0===r?c:c+r},["string","string"],"string");B.wrapFunctionAsNode("string/contains",function(c,r){return void 0===c||void 0===r?!1:-1!=c.indexOf(r)},["string","string"],"boolean");B.wrapFunctionAsNode("string/toUpperCase",function(c){return null!=c&&c.constructor===String?c.toUpperCase():c},["string"],"string");B.wrapFunctionAsNode("string/split",function(c,r){null==r&&(r=this.properties.separator);if(null==c)return[];if(c.constructor===String)return c.split(r|| +" ");if(c.constructor===Array){for(var l=[],v=0;ve;++e){var h=this.getInputData(e);if(null!=h){var l=this.values[e];l.push(h);l.length>c[0]&&l.shift()}}}};c.prototype.onDrawBackground=function(e){if(!this.flags.collapsed){var h= +this.size,l=.5*h[1]/this.properties.scale,t=c.colors,k=.5*h[1];e.fillStyle="#000";e.fillRect(0,0,h[0],h[1]);e.strokeStyle="#555";e.beginPath();e.moveTo(0,k);e.lineTo(h[0],k);e.stroke();if(this.inputs)for(var n=0;4>n;++n){var q=this.values[n];if(this.inputs[n]&&this.inputs[n].link){e.strokeStyle=t[n];e.beginPath();var a=q[0]*l*-1+k;e.moveTo(0,Math.clamp(a,0,h[1]));for(var b=1;be&&(e=0);if(0!=c.length){var h=[0,0,0];if(0==e)h=c[0];else if(1==e)h=c[c.length- +1];else{var l=(c.length-1)*e;e=c[Math.floor(l)];c=c[Math.floor(l)+1];l-=Math.floor(l);h[0]=e[0]*(1-l)+c[0]*l;h[1]=e[1]*(1-l)+c[1]*l;h[2]=e[2]*(1-l)+c[2]*l}for(e=0;e=c&&(this._video.currentTime=c*this._video.duration,this._video.pause()); +this._video.dirty=!0;this.setOutputData(0,this._video);this.setOutputData(1,this._video.currentTime);this.setOutputData(2,this._video.duration);this.setDirtyCanvas(!0)}};J.prototype.onStart=function(){this.play()};J.prototype.onStop=function(){this.stop()};J.prototype.loadVideo=function(c){this._video_url=c;var h=c.substr(0,10).indexOf(":"),l="";-1!=h&&(l=c.substr(0,h));h="";l&&(h=c.substr(0,c.indexOf("/",l.length+3)),h=h.substr(l.length+3));this.properties.use_proxy&&l&&e.proxy&&h!=location.host&& +(c=e.proxy+c.substr(c.indexOf(":")+3));this._video=document.createElement("video");this._video.src=c;this._video.type="type=video/mp4";this._video.muted=!0;this._video.autoplay=!0;var t=this;this._video.addEventListener("loadedmetadata",function(c){console.log("Duration: "+this.duration+" seconds");console.log("Size: "+this.videoWidth+","+this.videoHeight);t.setDirtyCanvas(!0);this.width=this.videoWidth;this.height=this.videoHeight});this._video.addEventListener("progress",function(c){console.log("video loading...")}); this._video.addEventListener("error",function(c){console.error("Error loading video: "+this.src);if(this.error)switch(this.error.code){case this.error.MEDIA_ERR_ABORTED:console.error("You stopped the video.");break;case this.error.MEDIA_ERR_NETWORK:console.error("Network error - please try again later.");break;case this.error.MEDIA_ERR_DECODE:console.error("Video is broken..");break;case this.error.MEDIA_ERR_SRC_NOT_SUPPORTED:console.error("Sorry, your browser can't play this video.")}});this._video.addEventListener("ended", -function(c){console.log("Video Ended.");this.play()})};G.prototype.onPropertyChanged=function(c,e){this.properties[c]=e;"url"==c&&""!=e&&this.loadVideo(e);return!0};G.prototype.play=function(){this._video&&this._video.videoWidth&&this._video.play()};G.prototype.playPause=function(){this._video&&(this._video.paused?this.play():this.pause())};G.prototype.stop=function(){this._video&&(this._video.pause(),this._video.currentTime=0)};G.prototype.pause=function(){this._video&&(console.log("Video paused"), -this._video.pause())};G.prototype.onWidget=function(c,e){};e.registerNodeType("graphics/video",G);D.title="Webcam";D.desc="Webcam image";D.is_webcam_open=!1;D.prototype.openStream=function(){if(navigator.mediaDevices.getUserMedia){this._waiting_confirmation=!0;navigator.mediaDevices.getUserMedia({audio:!1,video:this.properties.filterFacingMode?{facingMode:this.properties.facingMode}:!0}).then(this.streamReady.bind(this)).catch(function(e){console.log("Webcam rejected",e);c._webcam_stream=!1;D.is_webcam_open= -!1;c.boxcolor="red";c.trigger("stream_error")});var c=this}else console.log("getUserMedia() is not supported in your browser, use chrome and enable WebRTC from about://flags")};D.prototype.closeStream=function(){if(this._webcam_stream){var c=this._webcam_stream.getTracks();if(c.length)for(var e=0;e=this.size[1]||!this.properties.show||!this._video||(c.save(),c.drawImage(this._video,0,0,this.size[0],this.size[1]),c.restore())};D.prototype.onGetOutputs=function(){return[["width","number"],["height","number"],["stream_ready",e.EVENT],["stream_closed",e.EVENT],["stream_error",e.EVENT]]};e.registerNodeType("graphics/webcam",D)})(this); -(function(z){function c(){this.addOutput("tex","Texture");this.addOutput("name","string");this.properties={name:"",filter:!0};this.size=[c.image_preview_size,c.image_preview_size]}function g(){this.addInput("Texture","Texture");this.properties={flipY:!1};this.size=[c.image_preview_size,c.image_preview_size]}function q(){this.addInput("Texture","Texture");this.addOutput("tex","Texture");this.addOutput("name","string");this.properties={name:"",generate_mipmaps:!1}}function n(){this.addInput("Texture", +function(c){console.log("Video Ended.");this.play()})};J.prototype.onPropertyChanged=function(c,e){this.properties[c]=e;"url"==c&&""!=e&&this.loadVideo(e);return!0};J.prototype.play=function(){this._video&&this._video.videoWidth&&this._video.play()};J.prototype.playPause=function(){this._video&&(this._video.paused?this.play():this.pause())};J.prototype.stop=function(){this._video&&(this._video.pause(),this._video.currentTime=0)};J.prototype.pause=function(){this._video&&(console.log("Video paused"), +this._video.pause())};J.prototype.onWidget=function(c,e){};e.registerNodeType("graphics/video",J);F.title="Webcam";F.desc="Webcam image";F.is_webcam_open=!1;F.prototype.openStream=function(){if(navigator.mediaDevices.getUserMedia){this._waiting_confirmation=!0;navigator.mediaDevices.getUserMedia({audio:!1,video:this.properties.filterFacingMode?{facingMode:this.properties.facingMode}:!0}).then(this.streamReady.bind(this)).catch(function(e){console.log("Webcam rejected",e);c._webcam_stream=!1;F.is_webcam_open= +!1;c.boxcolor="red";c.trigger("stream_error")});var c=this}else console.log("getUserMedia() is not supported in your browser, use chrome and enable WebRTC from about://flags")};F.prototype.closeStream=function(){if(this._webcam_stream){var c=this._webcam_stream.getTracks();if(c.length)for(var e=0;e=this.size[1]||!this.properties.show||!this._video||(c.save(),c.drawImage(this._video,0,0,this.size[0],this.size[1]),c.restore())};F.prototype.onGetOutputs=function(){return[["width","number"],["height","number"],["stream_ready",e.EVENT],["stream_closed",e.EVENT],["stream_error",e.EVENT]]};e.registerNodeType("graphics/webcam",F)})(this); +(function(B){function c(){this.addOutput("tex","Texture");this.addOutput("name","string");this.properties={name:"",filter:!0};this.size=[c.image_preview_size,c.image_preview_size]}function l(){this.addInput("Texture","Texture");this.properties={flipY:!1};this.size=[c.image_preview_size,c.image_preview_size]}function r(){this.addInput("Texture","Texture");this.addOutput("tex","Texture");this.addOutput("name","string");this.properties={name:"",generate_mipmaps:!1}}function t(){this.addInput("Texture", "Texture");this.addInput("TextureB","Texture");this.addInput("value","number");this.addOutput("Texture","Texture");this.help="

pixelcode must be vec3, uvcode must be vec2, is optional

\t\t

uv: tex. coords

color: texture colorB: textureB

time: scene time value: input value

For multiline you must type: result = ...

";this.properties={value:1,pixelcode:"color + colorB * value",uvcode:"",precision:c.DEFAULT}; -this.has_error=!1}function w(){this.addOutput("out","Texture");this.properties={code:"",u_value:1,u_color:[1,1,1,1],width:512,height:512,precision:c.DEFAULT};this.properties.code=w.pixel_shader;this._uniforms={u_value:1,u_color:vec4.create(),in_texture:0,texSize:vec4.create(),time:0}}function l(){this.addInput("in","Texture");this.addInput("scale","vec2");this.addInput("offset","vec2");this.addOutput("out","Texture");this.properties={offset:vec2.fromValues(0,0),scale:vec2.fromValues(1,1),precision:c.DEFAULT}} -function A(){this.addInput("in","Texture");this.addInput("warp","Texture");this.addInput("factor","number");this.addOutput("out","Texture");this.properties={factor:.01,scale:[1,1],offset:[0,0],precision:c.DEFAULT};this._uniforms={u_texture:0,u_textureB:1,u_factor:1,u_scale:vec2.create(),u_offset:vec2.create()}}function B(){this.addInput("Texture","Texture");this.properties={additive:!1,antialiasing:!1,filter:!0,disable_alpha:!1,gamma:1,viewport:[0,0,1,1]};this.size[0]=130}function C(){this.addInput("Texture", -"Texture");this.addOutput("","Texture");this.properties={size:0,generate_mipmaps:!1,precision:c.DEFAULT}}function G(){this.addInput("Texture","Texture");this.addOutput("","Texture");this.properties={iterations:1,generate_mipmaps:!1,precision:c.DEFAULT}}function D(){this.addInput("Texture","Texture");this.addOutput("","Texture");this.properties={size:[512,512],generate_mipmaps:!1,precision:c.DEFAULT}}function e(){this.addInput("Texture","Texture");this.addOutput("tex","Texture");this.addOutput("avg", -"vec4");this.addOutput("lum","number");this.properties={use_previous_frame:!0,high_quality:!1};this._uniforms={u_texture:0,u_mipmap_offset:0};this._luminance=new Float32Array(4)}function r(){this.addInput("in","Texture");this.addInput("factor","Number");this.addOutput("out","Texture");this.properties={factor:.5};this._uniforms={u_texture:0,u_textureB:1,u_factor:this.properties.factor}}function F(){this.addInput("in","Texture");this.addOutput("avg","Texture");this.addOutput("array","Texture");this.properties= -{samples:64,frames_interval:1};this._uniforms={u_texture:0,u_textureB:1,u_samples:this.properties.samples,u_isamples:1/this.properties.samples};this.frame=0}function y(){this.addInput("Image","image");this.addOutput("","Texture");this.properties={}}function K(){this.addInput("Texture","Texture");this.addInput("LUT","Texture");this.addInput("Intensity","number");this.addOutput("","Texture");this.properties={enabled:!0,intensity:1,precision:c.DEFAULT,texture:null};K._shader||(K._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER, -K.pixel_shader))}function k(){this.addInput("Texture","Texture");this.addInput("Atlas","Texture");this.addOutput("","Texture");this.properties={enabled:!0,num_row_symbols:4,symbol_size:16,brightness:1,colorize:!1,filter:!1,invert:!1,precision:c.DEFAULT,generate_mipmaps:!1,texture:null};k._shader||(k._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,k.pixel_shader));this._uniforms={u_texture:0,u_textureB:1,u_row_simbols:4,u_simbol_size:16,u_res:vec2.create()}}function m(){this.addInput("Texture","Texture"); -this.addOutput("R","Texture");this.addOutput("G","Texture");this.addOutput("B","Texture");this.addOutput("A","Texture");m._shader||(m._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,m.pixel_shader))}function t(){this.addInput("R","Texture");this.addInput("G","Texture");this.addInput("B","Texture");this.addInput("A","Texture");this.addOutput("Texture","Texture");this.properties={precision:c.DEFAULT,R:1,G:1,B:1,A:1};this._color=vec4.create();this._uniforms={u_textureR:0,u_textureG:1,u_textureB:2, +this.has_error=!1}function v(){this.addOutput("out","Texture");this.properties={code:"",u_value:1,u_color:[1,1,1,1],width:512,height:512,precision:c.DEFAULT};this.properties.code=v.pixel_shader;this._uniforms={u_value:1,u_color:vec4.create(),in_texture:0,texSize:vec4.create(),time:0}}function h(){this.addInput("in","Texture");this.addInput("scale","vec2");this.addInput("offset","vec2");this.addOutput("out","Texture");this.properties={offset:vec2.fromValues(0,0),scale:vec2.fromValues(1,1),precision:c.DEFAULT}} +function E(){this.addInput("in","Texture");this.addInput("warp","Texture");this.addInput("factor","number");this.addOutput("out","Texture");this.properties={factor:.01,scale:[1,1],offset:[0,0],precision:c.DEFAULT};this._uniforms={u_texture:0,u_textureB:1,u_factor:1,u_scale:vec2.create(),u_offset:vec2.create()}}function A(){this.addInput("Texture","Texture");this.properties={additive:!1,antialiasing:!1,filter:!0,disable_alpha:!1,gamma:1,viewport:[0,0,1,1]};this.size[0]=130}function I(){this.addInput("Texture", +"Texture");this.addOutput("","Texture");this.properties={size:0,generate_mipmaps:!1,precision:c.DEFAULT}}function J(){this.addInput("Texture","Texture");this.addOutput("","Texture");this.properties={iterations:1,generate_mipmaps:!1,precision:c.DEFAULT}}function F(){this.addInput("Texture","Texture");this.addOutput("","Texture");this.properties={size:[512,512],generate_mipmaps:!1,precision:c.DEFAULT}}function e(){this.addInput("Texture","Texture");this.addOutput("tex","Texture");this.addOutput("avg", +"vec4");this.addOutput("lum","number");this.properties={use_previous_frame:!0,high_quality:!1};this._uniforms={u_texture:0,u_mipmap_offset:0};this._luminance=new Float32Array(4)}function D(){this.addInput("in","Texture");this.addInput("factor","Number");this.addOutput("out","Texture");this.properties={factor:.5};this._uniforms={u_texture:0,u_textureB:1,u_factor:this.properties.factor}}function H(){this.addInput("in","Texture");this.addOutput("avg","Texture");this.addOutput("array","Texture");this.properties= +{samples:64,frames_interval:1};this._uniforms={u_texture:0,u_textureB:1,u_samples:this.properties.samples,u_isamples:1/this.properties.samples};this.frame=0}function z(){this.addInput("Image","image");this.addOutput("","Texture");this.properties={}}function M(){this.addInput("Texture","Texture");this.addInput("LUT","Texture");this.addInput("Intensity","number");this.addOutput("","Texture");this.properties={enabled:!0,intensity:1,precision:c.DEFAULT,texture:null};M._shader||(M._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER, +M.pixel_shader))}function k(){this.addInput("Texture","Texture");this.addInput("Atlas","Texture");this.addOutput("","Texture");this.properties={enabled:!0,num_row_symbols:4,symbol_size:16,brightness:1,colorize:!1,filter:!1,invert:!1,precision:c.DEFAULT,generate_mipmaps:!1,texture:null};k._shader||(k._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,k.pixel_shader));this._uniforms={u_texture:0,u_textureB:1,u_row_simbols:4,u_simbol_size:16,u_res:vec2.create()}}function n(){this.addInput("Texture","Texture"); +this.addOutput("R","Texture");this.addOutput("G","Texture");this.addOutput("B","Texture");this.addOutput("A","Texture");n._shader||(n._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,n.pixel_shader))}function q(){this.addInput("R","Texture");this.addInput("G","Texture");this.addInput("B","Texture");this.addInput("A","Texture");this.addOutput("Texture","Texture");this.properties={precision:c.DEFAULT,R:1,G:1,B:1,A:1};this._color=vec4.create();this._uniforms={u_textureR:0,u_textureG:1,u_textureB:2, u_textureA:3,u_color:this._color}}function a(){this.addOutput("Texture","Texture");this._tex_color=vec4.create();this.properties={color:vec4.create(),precision:c.DEFAULT}}function b(){this.addInput("A","color");this.addInput("B","color");this.addOutput("Texture","Texture");this.properties={angle:0,scale:1,A:[0,0,0],B:[1,1,1],texture_size:32};b._shader||(b._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,b.pixel_shader));this._uniforms={u_angle:0,u_colorA:vec3.create(),u_colorB:vec3.create()}}function d(){this.addInput("A", -"Texture");this.addInput("B","Texture");this.addInput("Mixer","Texture");this.addOutput("Texture","Texture");this.properties={factor:.5,size_from_biggest:!0,invert:!1,precision:c.DEFAULT};this._uniforms={u_textureA:0,u_textureB:1,u_textureMix:2,u_mix:vec4.create()}}function h(){this.addInput("Tex.","Texture");this.addOutput("Edges","Texture");this.properties={invert:!0,threshold:!1,factor:1,precision:c.DEFAULT};h._shader||(h._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,h.pixel_shader))}function f(){this.addInput("Texture", -"Texture");this.addInput("Distance","number");this.addInput("Range","number");this.addOutput("Texture","Texture");this.properties={distance:100,range:50,only_depth:!1,high_precision:!1};this._uniforms={u_texture:0,u_distance:100,u_range:50,u_camera_planes:null}}function x(){this.addInput("Texture","Texture");this.addOutput("Texture","Texture");this.properties={precision:c.DEFAULT,invert:!1};this._uniforms={u_texture:0,u_camera_planes:null,u_ires:vec2.create()}}function J(){this.addInput("Texture", -"Texture");this.addInput("Iterations","number");this.addInput("Intensity","number");this.addOutput("Blurred","Texture");this.properties={intensity:1,iterations:1,preserve_aspect:!1,scale:[1,1],precision:c.DEFAULT}}function u(){this.intensity=.5;this.persistence=.6;this.iterations=8;this.threshold=.8;this.scale=1;this.dirt_texture=null;this.dirt_factor=.5;this._textures=[];this._uniforms={u_intensity:1,u_texture:0,u_glow_texture:1,u_threshold:0,u_texel_size:vec2.create()}}function v(){this.addInput("in", -"Texture");this.addInput("dirt","Texture");this.addOutput("out","Texture");this.addOutput("glow","Texture");this.properties={enabled:!0,intensity:1,persistence:.99,iterations:16,threshold:0,scale:1,dirt_factor:.5,precision:c.DEFAULT};this.fx=new u}function O(){this.addInput("Texture","Texture");this.addOutput("Filtered","Texture");this.properties={intensity:1,radius:5}}function N(){this.addInput("Texture","Texture");this.addOutput("Filtered","Texture");this.properties={sigma:1.4,k:1.6,p:21.7,epsilon:79, -phi:.017}}function I(){this.addOutput("Webcam","Texture");this.properties={texture_name:"",facingMode:"user"};this.boxcolor="black";this.version=0}function M(){this.addInput("in","Texture");this.addInput("f","number");this.addOutput("out","Texture");this.properties={enabled:!0,factor:1,precision:c.LOW};this._uniforms={u_texture:0,u_factor:1}}function E(){this.addInput("in","");this.properties={precision:c.LOW,width:0,height:0,channels:1};this.addOutput("out","Texture")}function H(){this.addInput("in", +"Texture");this.addInput("B","Texture");this.addInput("Mixer","Texture");this.addOutput("Texture","Texture");this.properties={factor:.5,size_from_biggest:!0,invert:!1,precision:c.DEFAULT};this._uniforms={u_textureA:0,u_textureB:1,u_textureMix:2,u_mix:vec4.create()}}function g(){this.addInput("Tex.","Texture");this.addOutput("Edges","Texture");this.properties={invert:!0,threshold:!1,factor:1,precision:c.DEFAULT};g._shader||(g._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,g.pixel_shader))}function f(){this.addInput("Texture", +"Texture");this.addInput("Distance","number");this.addInput("Range","number");this.addOutput("Texture","Texture");this.properties={distance:100,range:50,only_depth:!1,high_precision:!1};this._uniforms={u_texture:0,u_distance:100,u_range:50,u_camera_planes:null}}function m(){this.addInput("Texture","Texture");this.addOutput("Texture","Texture");this.properties={precision:c.DEFAULT,invert:!1};this._uniforms={u_texture:0,u_camera_planes:null,u_ires:vec2.create()}}function u(){this.addInput("Texture", +"Texture");this.addInput("Iterations","number");this.addInput("Intensity","number");this.addOutput("Blurred","Texture");this.properties={intensity:1,iterations:1,preserve_aspect:!1,scale:[1,1],precision:c.DEFAULT}}function O(){this.intensity=.5;this.persistence=.6;this.iterations=8;this.threshold=.8;this.scale=1;this.dirt_texture=null;this.dirt_factor=.5;this._textures=[];this._uniforms={u_intensity:1,u_texture:0,u_glow_texture:1,u_threshold:0,u_texel_size:vec2.create()}}function K(){this.addInput("in", +"Texture");this.addInput("dirt","Texture");this.addOutput("out","Texture");this.addOutput("glow","Texture");this.properties={enabled:!0,intensity:1,persistence:.99,iterations:16,threshold:0,scale:1,dirt_factor:.5,precision:c.DEFAULT};this.fx=new O}function x(){this.addInput("Texture","Texture");this.addOutput("Filtered","Texture");this.properties={intensity:1,radius:5}}function C(){this.addInput("Texture","Texture");this.addOutput("Filtered","Texture");this.properties={sigma:1.4,k:1.6,p:21.7,epsilon:79, +phi:.017}}function w(){this.addOutput("Webcam","Texture");this.properties={texture_name:"",facingMode:"user"};this.boxcolor="black";this.version=0}function L(){this.addInput("in","Texture");this.addInput("f","number");this.addOutput("out","Texture");this.properties={enabled:!0,factor:1,precision:c.LOW};this._uniforms={u_texture:0,u_factor:1}}function G(){this.addInput("in","");this.properties={precision:c.LOW,width:0,height:0,channels:1};this.addOutput("out","Texture")}function y(){this.addInput("in", "Texture");this.addOutput("out","Texture");this.properties={precision:c.LOW,split_channels:!1};this._values=new Uint8Array(1024);this._values.fill(255);this._curve_texture=null;this._uniforms={u_texture:0,u_curve:1,u_range:1};this._must_update=!0;this._points={RGB:[[0,0],[1,1]],R:[[0,0],[1,1]],G:[[0,0],[1,1]],B:[[0,0],[1,1]]};this.curve_editor=null;this.addWidget("toggle","Split Channels",!1,"split_channels");this.addWidget("combo","Channel","RGB",{values:["RGB","R","G","B"]});this.curve_offset=68; this.size=[240,160]}function P(){this.addInput("in","Texture");this.addInput("exp","number");this.addOutput("out","Texture");this.properties={exposition:1,precision:c.LOW};this._uniforms={u_texture:0,u_exposition:1}}function Q(){this.addInput("in","Texture");this.addInput("avg","number,Texture");this.addOutput("out","Texture");this.properties={enabled:!0,scale:1,gamma:1,average_lum:1,lum_white:1,precision:c.LOW};this._uniforms={u_texture:0,u_lumwhite2:1,u_igamma:1,u_scale:1,u_average_lum:1}}function S(){this.addOutput("out", "Texture");this.properties={width:512,height:512,seed:0,persistence:.1,octaves:8,scale:1,offset:[0,0],amplitude:1,precision:c.DEFAULT};this._key=0;this._texture=null;this._uniforms={u_persistence:.1,u_seed:0,u_offset:vec2.create(),u_scale:1,u_viewport:vec2.create()}}function R(){this.addInput("v");this.addOutput("out","Texture");this.properties={code:R.default_code,width:512,height:512,clear:!0,precision:c.DEFAULT,use_html_canvas:!1};this._temp_texture=this._func=null;this.compileCode()}function T(){this.addInput("in", -"Texture");this.addOutput("out","Texture");this.properties={key_color:vec3.fromValues(0,1,0),threshold:.8,slope:.2,precision:c.DEFAULT}}function U(){this.addInput("in","texture");this.addInput("yaw","number");this.addOutput("out","texture");this.properties={yaw:0}}var L=z.LiteGraph,Z=z.LGraphCanvas;z.LGraphTexture=null;"undefined"!=typeof GL&&(Z.link_type_colors.Texture="#987",z.LGraphTexture=c,c.title="Texture",c.desc="Texture",c.widgets_info={name:{widget:"texture"},filter:{widget:"checkbox"}}, -c.loadTextureCallback=null,c.image_preview_size=256,c.UNDEFINED=0,c.PASS_THROUGH=1,c.COPY=2,c.LOW=3,c.HIGH=4,c.REUSE=5,c.DEFAULT=2,c.MODE_VALUES={undefined:c.UNDEFINED,"pass through":c.PASS_THROUGH,copy:c.COPY,low:c.LOW,high:c.HIGH,reuse:c.REUSE,default:c.DEFAULT},c.getTexturesContainer=function(){return gl.textures},c.loadTexture=function(a,b){b=b||{};var d=a;"http://"==d.substr(0,7)&&L.proxy&&(d=L.proxy+d.substr(7));return c.getTexturesContainer()[a]=GL.Texture.fromURL(d,b)},c.getTexture=function(a){var b= +"Texture");this.addOutput("out","Texture");this.properties={key_color:vec3.fromValues(0,1,0),threshold:.8,slope:.2,precision:c.DEFAULT}}function U(){this.addInput("in","texture");this.addInput("yaw","number");this.addOutput("out","texture");this.properties={yaw:0}}var N=B.LiteGraph,Z=B.LGraphCanvas;B.LGraphTexture=null;"undefined"!=typeof GL&&(Z.link_type_colors.Texture="#987",B.LGraphTexture=c,c.title="Texture",c.desc="Texture",c.widgets_info={name:{widget:"texture"},filter:{widget:"checkbox"}}, +c.loadTextureCallback=null,c.image_preview_size=256,c.UNDEFINED=0,c.PASS_THROUGH=1,c.COPY=2,c.LOW=3,c.HIGH=4,c.REUSE=5,c.DEFAULT=2,c.MODE_VALUES={undefined:c.UNDEFINED,"pass through":c.PASS_THROUGH,copy:c.COPY,low:c.LOW,high:c.HIGH,reuse:c.REUSE,default:c.DEFAULT},c.getTexturesContainer=function(){return gl.textures},c.loadTexture=function(a,b){b=b||{};var d=a;"http://"==d.substr(0,7)&&N.proxy&&(d=N.proxy+d.substr(7));return c.getTexturesContainer()[a]=GL.Texture.fromURL(d,b)},c.getTexture=function(a){var b= this.getTexturesContainer();if(!b)throw"Cannot load texture, container of textures not found";b=b[a];return!b&&a&&":"!=a[0]?this.loadTexture(a):b},c.getTargetTexture=function(a,b,d){if(!a)throw"LGraphTexture.getTargetTexture expects a reference texture";switch(d){case c.LOW:d=gl.UNSIGNED_BYTE;break;case c.HIGH:d=gl.HIGH_PRECISION_FORMAT;break;case c.REUSE:return a;default:d=a?a.type:gl.UNSIGNED_BYTE}b&&b.width==a.width&&b.height==a.height&&b.type==d&&b.format==a.format||(b=new GL.Texture(a.width, a.height,{type:d,format:a.format,filter:gl.LINEAR}));return b},c.getTextureType=function(a,b){b=b?b.type:gl.UNSIGNED_BYTE;switch(a){case c.HIGH:b=gl.HIGH_PRECISION_FORMAT;break;case c.LOW:b=gl.UNSIGNED_BYTE}return b},c.getWhiteTexture=function(){return this._white_texture?this._white_texture:this._white_texture=GL.Texture.fromMemory(1,1,[255,255,255,255],{format:gl.RGBA,wrap:gl.REPEAT,filter:gl.NEAREST})},c.getNoiseTexture=function(){if(this._noise_texture)return this._noise_texture;for(var a=new Uint8Array(1048576), -b=0;1048576>b;++b)a[b]=255*Math.random();return this._noise_texture=a=GL.Texture.fromMemory(512,512,a,{format:gl.RGBA,wrap:gl.REPEAT,filter:gl.NEAREST})},c.prototype.onDropFile=function(a,b,c){a?("string"==typeof a?a=GL.Texture.fromURL(a):-1!=b.toLowerCase().indexOf(".dds")?a=GL.Texture.fromDDSInMemory(a):(a=new Blob([c]),a=URL.createObjectURL(a),a=GL.Texture.fromURL(a)),this._drop_texture=a,this.properties.name=b):(this._drop_texture=null,this.properties.name="")},c.prototype.getExtraMenuOptions= +b=0;1048576>b;++b)a[b]=255*Math.random();return this._noise_texture=a=GL.Texture.fromMemory(512,512,a,{format:gl.RGBA,wrap:gl.REPEAT,filter:gl.NEAREST})},c.prototype.onDropFile=function(a,b,d){a?("string"==typeof a?a=GL.Texture.fromURL(a):-1!=b.toLowerCase().indexOf(".dds")?a=GL.Texture.fromDDSInMemory(a):(a=new Blob([d]),a=URL.createObjectURL(a),a=GL.Texture.fromURL(a)),this._drop_texture=a,this.properties.name=b):(this._drop_texture=null,this.properties.name="")},c.prototype.getExtraMenuOptions= function(a){var b=this;if(this._drop_texture)return[{content:"Clear",callback:function(){b._drop_texture=null;b.properties.name=""}}]},c.prototype.onExecute=function(){var a=null;this.isOutputConnected(1)&&(a=this.getInputData(0));!a&&this._drop_texture&&(a=this._drop_texture);!a&&this.properties.name&&(a=c.getTexture(this.properties.name));if(a){this._last_tex=a;!1===this.properties.filter?a.setParameter(gl.TEXTURE_MAG_FILTER,gl.NEAREST):a.setParameter(gl.TEXTURE_MAG_FILTER,gl.LINEAR);this.setOutputData(0, a);this.setOutputData(1,a.fullpath||a.filename);for(var b=2;b=this.size[1]))if(this._drop_texture&& a.webgl)a.drawImage(this._drop_texture,0,0,this.size[0],this.size[1]);else{if(this._last_preview_tex!=this._last_tex)if(a.webgl)this._canvas=this._last_tex;else{var b=c.generateLowResTexturePreview(this._last_tex);if(!b)return;this._last_preview_tex=this._last_tex;this._canvas=cloneCanvas(b)}this._canvas&&(a.save(),a.webgl||(a.translate(0,this.size[1]),a.scale(1,-1)),a.drawImage(this._canvas,0,0,this.size[0],this.size[1]),a.restore())}},c.generateLowResTexturePreview=function(a){if(!a)return null; var b=c.image_preview_size,d=a;if(a.format==gl.DEPTH_COMPONENT)return null;if(a.width>b||a.height>b)d=this._preview_temp_tex,this._preview_temp_tex||(this._preview_temp_tex=d=new GL.Texture(b,b,{minFilter:gl.NEAREST})),a.copyTo(d);a=this._preview_canvas;a||(this._preview_canvas=a=createCanvas(b,b));d&&d.toCanvas(a);return a},c.prototype.getResources=function(a){this.properties.name&&(a[this.properties.name]=GL.Texture);return a},c.prototype.onGetInputs=function(){return[["in","Texture"]]},c.prototype.onGetOutputs= -function(){return[["width","number"],["height","number"],["aspect","number"]]},c.replaceCode=function(a,b){return a.replace(/\{\{[a-zA-Z0-9_]*\}\}/g,function(a){a=a.replace(/[\{\}]/g,"");return b[a]||""})},L.registerNodeType("texture/texture",c),g.title="Preview",g.desc="Show a texture in the graph canvas",g.allow_preview=!1,g.prototype.onDrawBackground=function(a){if(!this.flags.collapsed&&(a.webgl||g.allow_preview)){var b=this.getInputData(0);b&&(b=!b.handle&&a.webgl?b:c.generateLowResTexturePreview(b), -a.save(),this.properties.flipY&&(a.translate(0,this.size[1]),a.scale(1,-1)),a.drawImage(b,0,0,this.size[0],this.size[1]),a.restore())}},L.registerNodeType("texture/preview",g),q.title="Save",q.desc="Save a texture in the repository",q.prototype.getPreviewTexture=function(){return this._texture},q.prototype.onExecute=function(){var a=this.getInputData(0);a&&(this.properties.generate_mipmaps&&(a.bind(0),a.setParameter(gl.TEXTURE_MIN_FILTER,gl.LINEAR_MIPMAP_LINEAR),gl.generateMipmap(a.texture_type), -a.unbind(0)),this.properties.name&&(c.storeTexture?c.storeTexture(this.properties.name,a):c.getTexturesContainer()[this.properties.name]=a),this._texture=a,this.setOutputData(0,a),this.setOutputData(1,this.properties.name))},L.registerNodeType("texture/save",q),n.widgets_info={uvcode:{widget:"code"},pixelcode:{widget:"code"},precision:{widget:"combo",values:c.MODE_VALUES}},n.title="Operation",n.desc="Texture shader operation",n.presets={},n.prototype.getExtraMenuOptions=function(a){var b=this;return[{content:b.properties.show? -"Hide Texture":"Show Texture",callback:function(){b.properties.show=!b.properties.show}}]},n.prototype.onPropertyChanged=function(){this.has_error=!1},n.prototype.onDrawBackground=function(a){this.flags.collapsed||20>=this.size[1]||!this.properties.show||!this._tex||this._tex.gl!=a||(a.save(),a.drawImage(this._tex,0,0,this.size[0],this.size[1]),a.restore())},n.prototype.onExecute=function(){var a=this.getInputData(0);if(this.isOutputConnected(0))if(this.properties.precision===c.PASS_THROUGH)this.setOutputData(0, -a);else{var b=this.getInputData(1);if(this.properties.uvcode||this.properties.pixelcode){var d=512,f=512;a?(d=a.width,f=a.height):b&&(d=b.width,f=b.height);b||(b=GL.Texture.getWhiteTexture());var e=c.getTextureType(this.properties.precision,a);this._tex=a||this._tex?c.getTargetTexture(a||this._tex,this._tex,this.properties.precision):new GL.Texture(d,f,{type:e,format:gl.RGBA,filter:gl.LINEAR});e="";this.properties.uvcode&&(e="uv = "+this.properties.uvcode,-1!=this.properties.uvcode.indexOf(";")&& -(e=this.properties.uvcode));var h="";this.properties.pixelcode&&(h="result = "+this.properties.pixelcode,-1!=this.properties.pixelcode.indexOf(";")&&(h=this.properties.pixelcode));var k=this._shader;if(!(this.has_error||k&&this._shader_code==e+"|"+h)){var g=c.replaceCode(n.pixel_shader,{UV_CODE:e,PIXEL_CODE:h});try{k=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,g),this.boxcolor="#00FF00"}catch(aa){GL.Shader.dumpErrorToConsole(aa,Shader.SCREEN_VERTEX_SHADER,g);this.boxcolor="#FF0000";this.has_error=!0; -return}this._shader=k;this._shader_code=e+"|"+h}if(this._shader){var m=this.getInputData(2);null!=m?this.properties.value=m:m=parseFloat(this.properties.value);var t=this.graph.getTime();this._tex.drawTo(function(){gl.disable(gl.DEPTH_TEST);gl.disable(gl.CULL_FACE);gl.disable(gl.BLEND);a&&a.bind(0);b&&b.bind(1);var c=Mesh.getScreenQuad();k.uniforms({u_texture:0,u_textureB:1,value:m,texSize:[d,f,1/d,1/f],time:t}).draw(c)});this.setOutputData(0,this._tex)}}}},n.pixel_shader="precision highp float;\n\t\t\n\t\tuniform sampler2D u_texture;\n\t\tuniform sampler2D u_textureB;\n\t\tvarying vec2 v_coord;\n\t\tuniform vec4 texSize;\n\t\tuniform float time;\n\t\tuniform float value;\n\t\t\n\t\tvoid main() {\n\t\t\tvec2 uv = v_coord;\n\t\t\t{{UV_CODE}};\n\t\t\tvec4 color4 = texture2D(u_texture, uv);\n\t\t\tvec3 color = color4.rgb;\n\t\t\tvec4 color4B = texture2D(u_textureB, uv);\n\t\t\tvec3 colorB = color4B.rgb;\n\t\t\tvec3 result = color;\n\t\t\tfloat alpha = 1.0;\n\t\t\t{{PIXEL_CODE}};\n\t\t\tgl_FragColor = vec4(result, alpha);\n\t\t}\n\t\t", -n.registerPreset=function(a,b){n.presets[a]=b},n.registerPreset("",""),n.registerPreset("bypass","color"),n.registerPreset("add","color + colorB * value"),n.registerPreset("substract","(color - colorB) * value"),n.registerPreset("mate","mix( color, colorB, color4B.a * value)"),n.registerPreset("invert","vec3(1.0) - color"),n.registerPreset("multiply","color * colorB * value"),n.registerPreset("divide","(color / colorB) / value"),n.registerPreset("difference","abs(color - colorB) * value"),n.registerPreset("max", -"max(color, colorB) * value"),n.registerPreset("min","min(color, colorB) * value"),n.registerPreset("displace","texture2D(u_texture, uv + (colorB.xy - vec2(0.5)) * value).xyz"),n.registerPreset("grayscale","vec3(color.x + color.y + color.z) * value / 3.0"),n.registerPreset("saturation","mix( vec3(color.x + color.y + color.z) / 3.0, color, value )"),n.registerPreset("normalmap","\n\t\tfloat z0 = texture2D(u_texture, uv + vec2(-texSize.z, -texSize.w) ).x;\n\t\tfloat z1 = texture2D(u_texture, uv + vec2(0.0, -texSize.w) ).x;\n\t\tfloat z2 = texture2D(u_texture, uv + vec2(texSize.z, -texSize.w) ).x;\n\t\tfloat z3 = texture2D(u_texture, uv + vec2(-texSize.z, 0.0) ).x;\n\t\tfloat z4 = color.x;\n\t\tfloat z5 = texture2D(u_texture, uv + vec2(texSize.z, 0.0) ).x;\n\t\tfloat z6 = texture2D(u_texture, uv + vec2(-texSize.z, texSize.w) ).x;\n\t\tfloat z7 = texture2D(u_texture, uv + vec2(0.0, texSize.w) ).x;\n\t\tfloat z8 = texture2D(u_texture, uv + vec2(texSize.z, texSize.w) ).x;\n\t\tvec3 normal = vec3( z2 + 2.0*z4 + z7 - z0 - 2.0*z3 - z5, z5 + 2.0*z6 + z7 -z0 - 2.0*z1 - z2, 1.0 );\n\t\tnormal.xy *= value;\n\t\tresult.xyz = normalize(normal) * 0.5 + vec3(0.5);\n\t"), -n.registerPreset("threshold","vec3(color.x > colorB.x * value ? 1.0 : 0.0,color.y > colorB.y * value ? 1.0 : 0.0,color.z > colorB.z * value ? 1.0 : 0.0)"),n.prototype.onInspect=function(a){var b=this;a.addCombo("Presets","",{values:Object.keys(n.presets),callback:function(c){var d=n.presets[c];d&&(b.setProperty("pixelcode",d),b.title=c,a.refresh())}})},L.registerNodeType("texture/operation",n),w.title="Shader",w.desc="Texture shader",w.widgets_info={code:{type:"code",lang:"glsl"},precision:{widget:"combo", -values:c.MODE_VALUES}},w.prototype.onPropertyChanged=function(a,b){if("code"==a&&(a=this.getShader())){b=a.uniformInfo;if(this.inputs)for(var c={},d=0;d=this.size[1])){var b=this.getInputData(0);b&&a.drawImage(a==gl?b:gl.canvas,10,30,this.size[0]-20,this.size[1]-40)}},B.prototype.onExecute=function(){var a=this.getInputData(0);if(a){this.properties.disable_alpha?gl.disable(gl.BLEND):(gl.enable(gl.BLEND),this.properties.additive?gl.blendFunc(gl.SRC_ALPHA, -gl.ONE):gl.blendFunc(gl.SRC_ALPHA,gl.ONE_MINUS_SRC_ALPHA));gl.disable(gl.DEPTH_TEST);var b=this.properties.gamma||1;this.isInputConnected(1)&&(b=this.getInputData(1));a.setParameter(gl.TEXTURE_MAG_FILTER,this.properties.filter?gl.LINEAR:gl.NEAREST);var c=B._prev_viewport;c.set(gl.viewport_data);var d=this.properties.viewport;gl.viewport(c[0]+c[2]*d[0],c[1]+c[3]*d[1],c[2]*d[2],c[3]*d[3]);gl.getViewport();this.properties.antialiasing?(B._shader||(B._shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER, -B.aa_pixel_shader)),d=Mesh.getScreenQuad(),a.bind(0),B._shader.uniforms({u_texture:0,uViewportSize:[a.width,a.height],u_igamma:1/b,inverseVP:[1/a.width,1/a.height]}).draw(d)):1!=b?(B._gamma_shader||(B._gamma_shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,B.gamma_pixel_shader)),a.toViewport(B._gamma_shader,{u_texture:0,u_igamma:1/b})):a.toViewport();gl.viewport(c[0],c[1],c[2],c[3])}},B.prototype.onGetInputs=function(){return[["gamma","number"]]},B.aa_pixel_shader="precision highp float;\n\t\tprecision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuniform sampler2D u_texture;\n\t\tuniform vec2 uViewportSize;\n\t\tuniform vec2 inverseVP;\n\t\tuniform float u_igamma;\n\t\t#define FXAA_REDUCE_MIN (1.0/ 128.0)\n\t\t#define FXAA_REDUCE_MUL (1.0 / 8.0)\n\t\t#define FXAA_SPAN_MAX 8.0\n\t\t\n\t\t/* from mitsuhiko/webgl-meincraft based on the code on geeks3d.com */\n\t\tvec4 applyFXAA(sampler2D tex, vec2 fragCoord)\n\t\t{\n\t\t\tvec4 color = vec4(0.0);\n\t\t\t/*vec2 inverseVP = vec2(1.0 / uViewportSize.x, 1.0 / uViewportSize.y);*/\n\t\t\tvec3 rgbNW = texture2D(tex, (fragCoord + vec2(-1.0, -1.0)) * inverseVP).xyz;\n\t\t\tvec3 rgbNE = texture2D(tex, (fragCoord + vec2(1.0, -1.0)) * inverseVP).xyz;\n\t\t\tvec3 rgbSW = texture2D(tex, (fragCoord + vec2(-1.0, 1.0)) * inverseVP).xyz;\n\t\t\tvec3 rgbSE = texture2D(tex, (fragCoord + vec2(1.0, 1.0)) * inverseVP).xyz;\n\t\t\tvec3 rgbM = texture2D(tex, fragCoord * inverseVP).xyz;\n\t\t\tvec3 luma = vec3(0.299, 0.587, 0.114);\n\t\t\tfloat lumaNW = dot(rgbNW, luma);\n\t\t\tfloat lumaNE = dot(rgbNE, luma);\n\t\t\tfloat lumaSW = dot(rgbSW, luma);\n\t\t\tfloat lumaSE = dot(rgbSE, luma);\n\t\t\tfloat lumaM = dot(rgbM, luma);\n\t\t\tfloat lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));\n\t\t\tfloat lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));\n\t\t\t\n\t\t\tvec2 dir;\n\t\t\tdir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));\n\t\t\tdir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));\n\t\t\t\n\t\t\tfloat dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * FXAA_REDUCE_MUL), FXAA_REDUCE_MIN);\n\t\t\t\n\t\t\tfloat rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce);\n\t\t\tdir = min(vec2(FXAA_SPAN_MAX, FXAA_SPAN_MAX), max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX), dir * rcpDirMin)) * inverseVP;\n\t\t\t\n\t\t\tvec3 rgbA = 0.5 * (texture2D(tex, fragCoord * inverseVP + dir * (1.0 / 3.0 - 0.5)).xyz + \n\t\t\t\ttexture2D(tex, fragCoord * inverseVP + dir * (2.0 / 3.0 - 0.5)).xyz);\n\t\t\tvec3 rgbB = rgbA * 0.5 + 0.25 * (texture2D(tex, fragCoord * inverseVP + dir * -0.5).xyz + \n\t\t\t\ttexture2D(tex, fragCoord * inverseVP + dir * 0.5).xyz);\n\t\t\t\n\t\t\t//return vec4(rgbA,1.0);\n\t\t\tfloat lumaB = dot(rgbB, luma);\n\t\t\tif ((lumaB < lumaMin) || (lumaB > lumaMax))\n\t\t\t\tcolor = vec4(rgbA, 1.0);\n\t\t\telse\n\t\t\t\tcolor = vec4(rgbB, 1.0);\n\t\t\tif(u_igamma != 1.0)\n\t\t\t\tcolor.xyz = pow( color.xyz, vec3(u_igamma) );\n\t\t\treturn color;\n\t\t}\n\t\t\n\t\tvoid main() {\n\t\t gl_FragColor = applyFXAA( u_texture, v_coord * uViewportSize) ;\n\t\t}\n\t\t", -B.gamma_pixel_shader="precision highp float;\n\t\tprecision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuniform sampler2D u_texture;\n\t\tuniform float u_igamma;\n\t\tvoid main() {\n\t\t\tvec4 color = texture2D( u_texture, v_coord);\n\t\t\tcolor.xyz = pow(color.xyz, vec3(u_igamma) );\n\t\t gl_FragColor = color;\n\t\t}\n\t\t",L.registerNodeType("texture/toviewport",B),C.title="Copy",C.desc="Copy Texture",C.widgets_info={size:{widget:"combo",values:[0,32,64,128,256,512,1024,2048]},precision:{widget:"combo", -values:c.MODE_VALUES}},C.prototype.onExecute=function(){var a=this.getInputData(0);if((a||this._temp_texture)&&this.isOutputConnected(0)){if(a){var b=a.width,d=a.height;0!=this.properties.size&&(d=b=this.properties.size);var f=this._temp_texture,e=a.type;this.properties.precision===c.LOW?e=gl.UNSIGNED_BYTE:this.properties.precision===c.HIGH&&(e=gl.HIGH_PRECISION_FORMAT);f&&f.width==b&&f.height==d&&f.type==e||(f=gl.LINEAR,this.properties.generate_mipmaps&&isPowerOfTwo(b)&&isPowerOfTwo(d)&&(f=gl.LINEAR_MIPMAP_LINEAR), -this._temp_texture=new GL.Texture(b,d,{type:e,format:gl.RGBA,minFilter:f,magFilter:gl.LINEAR}));a.copyTo(this._temp_texture);this.properties.generate_mipmaps&&(this._temp_texture.bind(0),gl.generateMipmap(this._temp_texture.texture_type),this._temp_texture.unbind(0))}this.setOutputData(0,this._temp_texture)}},L.registerNodeType("texture/copy",C),G.title="Downsample",G.desc="Downsample Texture",G.widgets_info={iterations:{type:"number",step:1,precision:0,min:0},precision:{widget:"combo",values:c.MODE_VALUES}}, -G.prototype.onExecute=function(){var a=this.getInputData(0);if((a||this._temp_texture)&&this.isOutputConnected(0)&&a&&a.texture_type===GL.TEXTURE_2D)if(1>this.properties.iterations)this.setOutputData(0,a);else{var b=G._shader;b||(G._shader=b=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,G.pixel_shader));var d=a.width|0,f=a.height|0,e=a.type;this.properties.precision===c.LOW?e=gl.UNSIGNED_BYTE:this.properties.precision===c.HIGH&&(e=gl.HIGH_PRECISION_FORMAT);var h=this.properties.iterations||1,k=a,g= -[];e={type:e,format:a.format};var m=vec2.create(),t={u_offset:m};this._texture&&GL.Texture.releaseTemporary(this._texture);for(var l=0;l>1||0;f=f>>1||0;a=GL.Texture.getTemporary(d,f,e);g.push(a);k.setParameter(GL.TEXTURE_MAG_FILTER,GL.NEAREST);k.copyTo(a,b,t);if(1==d&&1==f)break;k=a}this._texture=g.pop();for(l=0;l=this.size[1]||!this.properties.show||!this._tex||this._tex.gl!=a||(a.save(),a.drawImage(this._tex,0,0,this.size[0],this.size[1]),a.restore())},t.prototype.onExecute=function(){var a=this.getInputData(0);if(this.isOutputConnected(0))if(this.properties.precision===c.PASS_THROUGH)this.setOutputData(0, +a);else{var b=this.getInputData(1);if(this.properties.uvcode||this.properties.pixelcode){var d=512,f=512;a?(d=a.width,f=a.height):b&&(d=b.width,f=b.height);b||(b=GL.Texture.getWhiteTexture());var g=c.getTextureType(this.properties.precision,a);this._tex=a||this._tex?c.getTargetTexture(a||this._tex,this._tex,this.properties.precision):new GL.Texture(d,f,{type:g,format:gl.RGBA,filter:gl.LINEAR});g="";this.properties.uvcode&&(g="uv = "+this.properties.uvcode,-1!=this.properties.uvcode.indexOf(";")&& +(g=this.properties.uvcode));var e="";this.properties.pixelcode&&(e="result = "+this.properties.pixelcode,-1!=this.properties.pixelcode.indexOf(";")&&(e=this.properties.pixelcode));var k=this._shader;if(!(this.has_error||k&&this._shader_code==g+"|"+e)){var h=c.replaceCode(t.pixel_shader,{UV_CODE:g,PIXEL_CODE:e});try{k=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,h),this.boxcolor="#00FF00"}catch(X){GL.Shader.dumpErrorToConsole(X,Shader.SCREEN_VERTEX_SHADER,h);this.boxcolor="#FF0000";this.has_error=!0; +return}this._shader=k;this._shader_code=g+"|"+e}if(this._shader){var m=this.getInputData(2);null!=m?this.properties.value=m:m=parseFloat(this.properties.value);var q=this.graph.getTime();this._tex.drawTo(function(){gl.disable(gl.DEPTH_TEST);gl.disable(gl.CULL_FACE);gl.disable(gl.BLEND);a&&a.bind(0);b&&b.bind(1);var c=Mesh.getScreenQuad();k.uniforms({u_texture:0,u_textureB:1,value:m,texSize:[d,f,1/d,1/f],time:q}).draw(c)});this.setOutputData(0,this._tex)}}}},t.pixel_shader="precision highp float;\n\t\t\n\t\tuniform sampler2D u_texture;\n\t\tuniform sampler2D u_textureB;\n\t\tvarying vec2 v_coord;\n\t\tuniform vec4 texSize;\n\t\tuniform float time;\n\t\tuniform float value;\n\t\t\n\t\tvoid main() {\n\t\t\tvec2 uv = v_coord;\n\t\t\t{{UV_CODE}};\n\t\t\tvec4 color4 = texture2D(u_texture, uv);\n\t\t\tvec3 color = color4.rgb;\n\t\t\tvec4 color4B = texture2D(u_textureB, uv);\n\t\t\tvec3 colorB = color4B.rgb;\n\t\t\tvec3 result = color;\n\t\t\tfloat alpha = 1.0;\n\t\t\t{{PIXEL_CODE}};\n\t\t\tgl_FragColor = vec4(result, alpha);\n\t\t}\n\t\t", +t.registerPreset=function(a,b){t.presets[a]=b},t.registerPreset("",""),t.registerPreset("bypass","color"),t.registerPreset("add","color + colorB * value"),t.registerPreset("substract","(color - colorB) * value"),t.registerPreset("mate","mix( color, colorB, color4B.a * value)"),t.registerPreset("invert","vec3(1.0) - color"),t.registerPreset("multiply","color * colorB * value"),t.registerPreset("divide","(color / colorB) / value"),t.registerPreset("difference","abs(color - colorB) * value"),t.registerPreset("max", +"max(color, colorB) * value"),t.registerPreset("min","min(color, colorB) * value"),t.registerPreset("displace","texture2D(u_texture, uv + (colorB.xy - vec2(0.5)) * value).xyz"),t.registerPreset("grayscale","vec3(color.x + color.y + color.z) * value / 3.0"),t.registerPreset("saturation","mix( vec3(color.x + color.y + color.z) / 3.0, color, value )"),t.registerPreset("normalmap","\n\t\tfloat z0 = texture2D(u_texture, uv + vec2(-texSize.z, -texSize.w) ).x;\n\t\tfloat z1 = texture2D(u_texture, uv + vec2(0.0, -texSize.w) ).x;\n\t\tfloat z2 = texture2D(u_texture, uv + vec2(texSize.z, -texSize.w) ).x;\n\t\tfloat z3 = texture2D(u_texture, uv + vec2(-texSize.z, 0.0) ).x;\n\t\tfloat z4 = color.x;\n\t\tfloat z5 = texture2D(u_texture, uv + vec2(texSize.z, 0.0) ).x;\n\t\tfloat z6 = texture2D(u_texture, uv + vec2(-texSize.z, texSize.w) ).x;\n\t\tfloat z7 = texture2D(u_texture, uv + vec2(0.0, texSize.w) ).x;\n\t\tfloat z8 = texture2D(u_texture, uv + vec2(texSize.z, texSize.w) ).x;\n\t\tvec3 normal = vec3( z2 + 2.0*z4 + z7 - z0 - 2.0*z3 - z5, z5 + 2.0*z6 + z7 -z0 - 2.0*z1 - z2, 1.0 );\n\t\tnormal.xy *= value;\n\t\tresult.xyz = normalize(normal) * 0.5 + vec3(0.5);\n\t"), +t.registerPreset("threshold","vec3(color.x > colorB.x * value ? 1.0 : 0.0,color.y > colorB.y * value ? 1.0 : 0.0,color.z > colorB.z * value ? 1.0 : 0.0)"),t.prototype.onInspect=function(a){var b=this;a.addCombo("Presets","",{values:Object.keys(t.presets),callback:function(d){var c=t.presets[d];c&&(b.setProperty("pixelcode",c),b.title=d,a.refresh())}})},N.registerNodeType("texture/operation",t),v.title="Shader",v.desc="Texture shader",v.widgets_info={code:{type:"code",lang:"glsl"},precision:{widget:"combo", +values:c.MODE_VALUES}},v.prototype.onPropertyChanged=function(a,b){if("code"==a&&(a=this.getShader())){b=a.uniformInfo;if(this.inputs)for(var d={},c=0;c=this.size[1])){var b=this.getInputData(0);b&&a.drawImage(a==gl?b:gl.canvas,10,30,this.size[0]-20,this.size[1]-40)}},A.prototype.onExecute=function(){var a=this.getInputData(0);if(a){this.properties.disable_alpha?gl.disable(gl.BLEND):(gl.enable(gl.BLEND),this.properties.additive?gl.blendFunc(gl.SRC_ALPHA, +gl.ONE):gl.blendFunc(gl.SRC_ALPHA,gl.ONE_MINUS_SRC_ALPHA));gl.disable(gl.DEPTH_TEST);var b=this.properties.gamma||1;this.isInputConnected(1)&&(b=this.getInputData(1));a.setParameter(gl.TEXTURE_MAG_FILTER,this.properties.filter?gl.LINEAR:gl.NEAREST);var d=A._prev_viewport;d.set(gl.viewport_data);var c=this.properties.viewport;gl.viewport(d[0]+d[2]*c[0],d[1]+d[3]*c[1],d[2]*c[2],d[3]*c[3]);gl.getViewport();this.properties.antialiasing?(A._shader||(A._shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER, +A.aa_pixel_shader)),c=Mesh.getScreenQuad(),a.bind(0),A._shader.uniforms({u_texture:0,uViewportSize:[a.width,a.height],u_igamma:1/b,inverseVP:[1/a.width,1/a.height]}).draw(c)):1!=b?(A._gamma_shader||(A._gamma_shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,A.gamma_pixel_shader)),a.toViewport(A._gamma_shader,{u_texture:0,u_igamma:1/b})):a.toViewport();gl.viewport(d[0],d[1],d[2],d[3])}},A.prototype.onGetInputs=function(){return[["gamma","number"]]},A.aa_pixel_shader="precision highp float;\n\t\tprecision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuniform sampler2D u_texture;\n\t\tuniform vec2 uViewportSize;\n\t\tuniform vec2 inverseVP;\n\t\tuniform float u_igamma;\n\t\t#define FXAA_REDUCE_MIN (1.0/ 128.0)\n\t\t#define FXAA_REDUCE_MUL (1.0 / 8.0)\n\t\t#define FXAA_SPAN_MAX 8.0\n\t\t\n\t\t/* from mitsuhiko/webgl-meincraft based on the code on geeks3d.com */\n\t\tvec4 applyFXAA(sampler2D tex, vec2 fragCoord)\n\t\t{\n\t\t\tvec4 color = vec4(0.0);\n\t\t\t/*vec2 inverseVP = vec2(1.0 / uViewportSize.x, 1.0 / uViewportSize.y);*/\n\t\t\tvec3 rgbNW = texture2D(tex, (fragCoord + vec2(-1.0, -1.0)) * inverseVP).xyz;\n\t\t\tvec3 rgbNE = texture2D(tex, (fragCoord + vec2(1.0, -1.0)) * inverseVP).xyz;\n\t\t\tvec3 rgbSW = texture2D(tex, (fragCoord + vec2(-1.0, 1.0)) * inverseVP).xyz;\n\t\t\tvec3 rgbSE = texture2D(tex, (fragCoord + vec2(1.0, 1.0)) * inverseVP).xyz;\n\t\t\tvec3 rgbM = texture2D(tex, fragCoord * inverseVP).xyz;\n\t\t\tvec3 luma = vec3(0.299, 0.587, 0.114);\n\t\t\tfloat lumaNW = dot(rgbNW, luma);\n\t\t\tfloat lumaNE = dot(rgbNE, luma);\n\t\t\tfloat lumaSW = dot(rgbSW, luma);\n\t\t\tfloat lumaSE = dot(rgbSE, luma);\n\t\t\tfloat lumaM = dot(rgbM, luma);\n\t\t\tfloat lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));\n\t\t\tfloat lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));\n\t\t\t\n\t\t\tvec2 dir;\n\t\t\tdir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));\n\t\t\tdir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));\n\t\t\t\n\t\t\tfloat dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * FXAA_REDUCE_MUL), FXAA_REDUCE_MIN);\n\t\t\t\n\t\t\tfloat rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce);\n\t\t\tdir = min(vec2(FXAA_SPAN_MAX, FXAA_SPAN_MAX), max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX), dir * rcpDirMin)) * inverseVP;\n\t\t\t\n\t\t\tvec3 rgbA = 0.5 * (texture2D(tex, fragCoord * inverseVP + dir * (1.0 / 3.0 - 0.5)).xyz + \n\t\t\t\ttexture2D(tex, fragCoord * inverseVP + dir * (2.0 / 3.0 - 0.5)).xyz);\n\t\t\tvec3 rgbB = rgbA * 0.5 + 0.25 * (texture2D(tex, fragCoord * inverseVP + dir * -0.5).xyz + \n\t\t\t\ttexture2D(tex, fragCoord * inverseVP + dir * 0.5).xyz);\n\t\t\t\n\t\t\t//return vec4(rgbA,1.0);\n\t\t\tfloat lumaB = dot(rgbB, luma);\n\t\t\tif ((lumaB < lumaMin) || (lumaB > lumaMax))\n\t\t\t\tcolor = vec4(rgbA, 1.0);\n\t\t\telse\n\t\t\t\tcolor = vec4(rgbB, 1.0);\n\t\t\tif(u_igamma != 1.0)\n\t\t\t\tcolor.xyz = pow( color.xyz, vec3(u_igamma) );\n\t\t\treturn color;\n\t\t}\n\t\t\n\t\tvoid main() {\n\t\t gl_FragColor = applyFXAA( u_texture, v_coord * uViewportSize) ;\n\t\t}\n\t\t", +A.gamma_pixel_shader="precision highp float;\n\t\tprecision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuniform sampler2D u_texture;\n\t\tuniform float u_igamma;\n\t\tvoid main() {\n\t\t\tvec4 color = texture2D( u_texture, v_coord);\n\t\t\tcolor.xyz = pow(color.xyz, vec3(u_igamma) );\n\t\t gl_FragColor = color;\n\t\t}\n\t\t",N.registerNodeType("texture/toviewport",A),I.title="Copy",I.desc="Copy Texture",I.widgets_info={size:{widget:"combo",values:[0,32,64,128,256,512,1024,2048]},precision:{widget:"combo", +values:c.MODE_VALUES}},I.prototype.onExecute=function(){var a=this.getInputData(0);if((a||this._temp_texture)&&this.isOutputConnected(0)){if(a){var b=a.width,d=a.height;0!=this.properties.size&&(d=b=this.properties.size);var f=this._temp_texture,g=a.type;this.properties.precision===c.LOW?g=gl.UNSIGNED_BYTE:this.properties.precision===c.HIGH&&(g=gl.HIGH_PRECISION_FORMAT);f&&f.width==b&&f.height==d&&f.type==g||(f=gl.LINEAR,this.properties.generate_mipmaps&&isPowerOfTwo(b)&&isPowerOfTwo(d)&&(f=gl.LINEAR_MIPMAP_LINEAR), +this._temp_texture=new GL.Texture(b,d,{type:g,format:gl.RGBA,minFilter:f,magFilter:gl.LINEAR}));a.copyTo(this._temp_texture);this.properties.generate_mipmaps&&(this._temp_texture.bind(0),gl.generateMipmap(this._temp_texture.texture_type),this._temp_texture.unbind(0))}this.setOutputData(0,this._temp_texture)}},N.registerNodeType("texture/copy",I),J.title="Downsample",J.desc="Downsample Texture",J.widgets_info={iterations:{type:"number",step:1,precision:0,min:0},precision:{widget:"combo",values:c.MODE_VALUES}}, +J.prototype.onExecute=function(){var a=this.getInputData(0);if((a||this._temp_texture)&&this.isOutputConnected(0)&&a&&a.texture_type===GL.TEXTURE_2D)if(1>this.properties.iterations)this.setOutputData(0,a);else{var b=J._shader;b||(J._shader=b=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,J.pixel_shader));var d=a.width|0,f=a.height|0,g=a.type;this.properties.precision===c.LOW?g=gl.UNSIGNED_BYTE:this.properties.precision===c.HIGH&&(g=gl.HIGH_PRECISION_FORMAT);var e=this.properties.iterations||1,k=a,h= +[];g={type:g,format:a.format};var m=vec2.create(),q={u_offset:m};this._texture&&GL.Texture.releaseTemporary(this._texture);for(var n=0;n>1||0;f=f>>1||0;a=GL.Texture.getTemporary(d,f,g);h.push(a);k.setParameter(GL.TEXTURE_MAG_FILTER,GL.NEAREST);k.copyTo(a,b,q);if(1==d&&1==f)break;k=a}this._texture=h.pop();for(n=0;nd;d++)this.isOutputConnected(d)?(this._channels[d]&&this._channels[d].width==a.width&&this._channels[d].height==a.height&&this._channels[d].type==a.type&&this._channels[d].format==b||(this._channels[d]=new GL.Texture(a.width,a.height,{type:a.type,format:b,filter:gl.LINEAR})), -c++):this._channels[d]=null;if(c){gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var f=Mesh.getScreenQuad(),e=m._shader,h=[[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]];for(d=0;4>d;d++)this._channels[d]&&(this._channels[d].drawTo(function(){a.bind(0);e.uniforms({u_texture:0,u_mask:h[d]}).draw(f)}),this.setOutputData(d,this._channels[d]))}}},m.pixel_shader="precision highp float;\n\t\tprecision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuniform sampler2D u_texture;\n\t\tuniform vec4 u_mask;\n\t\t\n\t\tvoid main() {\n\t\t gl_FragColor = vec4( vec3( length( texture2D(u_texture, v_coord) * u_mask )), 1.0 );\n\t\t}\n\t\t", -L.registerNodeType("texture/textureChannels",m),t.title="Channels to Texture",t.desc="Split texture channels",t.widgets_info={precision:{widget:"combo",values:c.MODE_VALUES}},t.prototype.onExecute=function(){var a=c.getWhiteTexture(),b=this.getInputData(0)||a,d=this.getInputData(1)||a,f=this.getInputData(2)||a,e=this.getInputData(3)||a;gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var h=Mesh.getScreenQuad();t._shader||(t._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,t.pixel_shader));var k=t._shader; -a=Math.max(b.width,d.width,f.width,e.width);var g=Math.max(b.height,d.height,f.height,e.height),m=this.properties.precision==c.HIGH?c.HIGH_PRECISION_FORMAT:gl.UNSIGNED_BYTE;this._texture&&this._texture.width==a&&this._texture.height==g&&this._texture.type==m||(this._texture=new GL.Texture(a,g,{type:m,format:gl.RGBA,filter:gl.LINEAR}));a=this._color;a[0]=this.properties.R;a[1]=this.properties.G;a[2]=this.properties.B;a[3]=this.properties.A;var l=this._uniforms;this._texture.drawTo(function(){b.bind(0); -d.bind(1);f.bind(2);e.bind(3);k.uniforms(l).draw(h)});this.setOutputData(0,this._texture)},t.pixel_shader="precision highp float;\n\t\tprecision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuniform sampler2D u_textureR;\n\t\tuniform sampler2D u_textureG;\n\t\tuniform sampler2D u_textureB;\n\t\tuniform sampler2D u_textureA;\n\t\tuniform vec4 u_color;\n\t\t\n\t\tvoid main() {\n\t\t gl_FragColor = u_color * vec4( \t\t\t\t\ttexture2D(u_textureR, v_coord).r,\t\t\t\t\ttexture2D(u_textureG, v_coord).r,\t\t\t\t\ttexture2D(u_textureB, v_coord).r,\t\t\t\t\ttexture2D(u_textureA, v_coord).r);\n\t\t}\n\t\t", -L.registerNodeType("texture/channelsTexture",t),a.title="Color",a.desc="Generates a 1x1 texture with a constant color",a.widgets_info={precision:{widget:"combo",values:c.MODE_VALUES}},a.prototype.onDrawBackground=function(a){var b=this.properties.color;a.fillStyle="rgb("+Math.floor(255*Math.clamp(b[0],0,1))+","+Math.floor(255*Math.clamp(b[1],0,1))+","+Math.floor(255*Math.clamp(b[2],0,1))+")";this.flags.collapsed?this.boxcolor=a.fillStyle:a.fillRect(0,0,this.size[0],this.size[1])},a.prototype.onExecute= +N.registerNodeType("texture/encode",k),n.title="Texture to Channels",n.desc="Split texture channels",n.prototype.onExecute=function(){var a=this.getInputData(0);if(a){this._channels||(this._channels=Array(4));for(var b=gl.RGB,d=0,c=0;4>c;c++)this.isOutputConnected(c)?(this._channels[c]&&this._channels[c].width==a.width&&this._channels[c].height==a.height&&this._channels[c].type==a.type&&this._channels[c].format==b||(this._channels[c]=new GL.Texture(a.width,a.height,{type:a.type,format:b,filter:gl.LINEAR})), +d++):this._channels[c]=null;if(d){gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var f=Mesh.getScreenQuad(),g=n._shader,e=[[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]];for(c=0;4>c;c++)this._channels[c]&&(this._channels[c].drawTo(function(){a.bind(0);g.uniforms({u_texture:0,u_mask:e[c]}).draw(f)}),this.setOutputData(c,this._channels[c]))}}},n.pixel_shader="precision highp float;\n\t\tprecision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuniform sampler2D u_texture;\n\t\tuniform vec4 u_mask;\n\t\t\n\t\tvoid main() {\n\t\t gl_FragColor = vec4( vec3( length( texture2D(u_texture, v_coord) * u_mask )), 1.0 );\n\t\t}\n\t\t", +N.registerNodeType("texture/textureChannels",n),q.title="Channels to Texture",q.desc="Split texture channels",q.widgets_info={precision:{widget:"combo",values:c.MODE_VALUES}},q.prototype.onExecute=function(){var a=c.getWhiteTexture(),b=this.getInputData(0)||a,d=this.getInputData(1)||a,f=this.getInputData(2)||a,g=this.getInputData(3)||a;gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var e=Mesh.getScreenQuad();q._shader||(q._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,q.pixel_shader));var k=q._shader; +a=Math.max(b.width,d.width,f.width,g.width);var h=Math.max(b.height,d.height,f.height,g.height),m=this.properties.precision==c.HIGH?c.HIGH_PRECISION_FORMAT:gl.UNSIGNED_BYTE;this._texture&&this._texture.width==a&&this._texture.height==h&&this._texture.type==m||(this._texture=new GL.Texture(a,h,{type:m,format:gl.RGBA,filter:gl.LINEAR}));a=this._color;a[0]=this.properties.R;a[1]=this.properties.G;a[2]=this.properties.B;a[3]=this.properties.A;var n=this._uniforms;this._texture.drawTo(function(){b.bind(0); +d.bind(1);f.bind(2);g.bind(3);k.uniforms(n).draw(e)});this.setOutputData(0,this._texture)},q.pixel_shader="precision highp float;\n\t\tprecision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuniform sampler2D u_textureR;\n\t\tuniform sampler2D u_textureG;\n\t\tuniform sampler2D u_textureB;\n\t\tuniform sampler2D u_textureA;\n\t\tuniform vec4 u_color;\n\t\t\n\t\tvoid main() {\n\t\t gl_FragColor = u_color * vec4( \t\t\t\t\ttexture2D(u_textureR, v_coord).r,\t\t\t\t\ttexture2D(u_textureG, v_coord).r,\t\t\t\t\ttexture2D(u_textureB, v_coord).r,\t\t\t\t\ttexture2D(u_textureA, v_coord).r);\n\t\t}\n\t\t", +N.registerNodeType("texture/channelsTexture",q),a.title="Color",a.desc="Generates a 1x1 texture with a constant color",a.widgets_info={precision:{widget:"combo",values:c.MODE_VALUES}},a.prototype.onDrawBackground=function(a){var b=this.properties.color;a.fillStyle="rgb("+Math.floor(255*Math.clamp(b[0],0,1))+","+Math.floor(255*Math.clamp(b[1],0,1))+","+Math.floor(255*Math.clamp(b[2],0,1))+")";this.flags.collapsed?this.boxcolor=a.fillStyle:a.fillRect(0,0,this.size[0],this.size[1])},a.prototype.onExecute= function(){var a=this.properties.precision==c.HIGH?c.HIGH_PRECISION_FORMAT:gl.UNSIGNED_BYTE;this._tex&&this._tex.type==a||(this._tex=new GL.Texture(1,1,{format:gl.RGBA,type:a,minFilter:gl.NEAREST}));a=this.properties.color;if(this.inputs)for(var b=0;ba.width?b: -a,this._tex,this.properties.precision);gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var h=Mesh.getScreenQuad(),k=null,g=this._uniforms;f?(k=d._shader_tex,k||(k=d._shader_tex=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,d.pixel_shader,{MIX_TEX:""}))):(k=d._shader_factor,k||(k=d._shader_factor=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,d.pixel_shader)),e=null==e?this.properties.factor:e,g.u_mix.set([e,e,e,e]));var m=this.properties.invert;this._tex.drawTo(function(){a.bind(m?1:0);b.bind(m?0:1);f&&f.bind(2); -k.uniforms(g).draw(h)});this.setOutputData(0,this._tex)}}},d.prototype.onGetInputs=function(){return[["factor","number"]]},d.pixel_shader="precision highp float;\n\t\tprecision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuniform sampler2D u_textureA;\n\t\tuniform sampler2D u_textureB;\n\t\t#ifdef MIX_TEX\n\t\t\tuniform sampler2D u_textureMix;\n\t\t#else\n\t\t\tuniform vec4 u_mix;\n\t\t#endif\n\t\t\n\t\tvoid main() {\n\t\t\t#ifdef MIX_TEX\n\t\t\t vec4 f = texture2D(u_textureMix, v_coord);\n\t\t\t#else\n\t\t\t vec4 f = u_mix;\n\t\t\t#endif\n\t\t gl_FragColor = mix( texture2D(u_textureA, v_coord), texture2D(u_textureB, v_coord), f );\n\t\t}\n\t\t", -L.registerNodeType("texture/mix",d),h.title="Edges",h.desc="Detects edges",h.widgets_info={precision:{widget:"combo",values:c.MODE_VALUES}},h.prototype.onExecute=function(){if(this.isOutputConnected(0)){var a=this.getInputData(0);if(this.properties.precision===c.PASS_THROUGH)this.setOutputData(0,a);else if(a){this._tex=c.getTargetTexture(a,this._tex,this.properties.precision);gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var b=Mesh.getScreenQuad(),d=h._shader,f=this.properties.invert,e=this.properties.factor, -k=this.properties.threshold?1:0;this._tex.drawTo(function(){a.bind(0);d.uniforms({u_texture:0,u_isize:[1/a.width,1/a.height],u_factor:e,u_threshold:k,u_invert:f?1:0}).draw(b)});this.setOutputData(0,this._tex)}}},h.pixel_shader="precision highp float;\n\t\tprecision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuniform sampler2D u_texture;\n\t\tuniform vec2 u_isize;\n\t\tuniform int u_invert;\n\t\tuniform float u_factor;\n\t\tuniform float u_threshold;\n\t\t\n\t\tvoid main() {\n\t\t\tvec4 center = texture2D(u_texture, v_coord);\n\t\t\tvec4 up = texture2D(u_texture, v_coord + u_isize * vec2(0.0,1.0) );\n\t\t\tvec4 down = texture2D(u_texture, v_coord + u_isize * vec2(0.0,-1.0) );\n\t\t\tvec4 left = texture2D(u_texture, v_coord + u_isize * vec2(1.0,0.0) );\n\t\t\tvec4 right = texture2D(u_texture, v_coord + u_isize * vec2(-1.0,0.0) );\n\t\t\tvec4 diff = abs(center - up) + abs(center - down) + abs(center - left) + abs(center - right);\n\t\t\tdiff *= u_factor;\n\t\t\tif(u_invert == 1)\n\t\t\t\tdiff.xyz = vec3(1.0) - diff.xyz;\n\t\t\tif( u_threshold == 0.0 )\n\t\t\t\tgl_FragColor = vec4( diff.xyz, center.a );\n\t\t\telse\n\t\t\t\tgl_FragColor = vec4( diff.x > 0.5 ? 1.0 : 0.0, diff.y > 0.5 ? 1.0 : 0.0, diff.z > 0.5 ? 1.0 : 0.0, center.a );\n\t\t}\n\t\t", -L.registerNodeType("texture/edges",h),f.title="Depth Range",f.desc="Generates a texture with a depth range",f.prototype.onExecute=function(){if(this.isOutputConnected(0)){var a=this.getInputData(0);if(a){var b=gl.UNSIGNED_BYTE;this.properties.high_precision&&(b=gl.half_float_ext?gl.HALF_FLOAT_OES:gl.FLOAT);this._temp_texture&&this._temp_texture.type==b&&this._temp_texture.width==a.width&&this._temp_texture.height==a.height||(this._temp_texture=new GL.Texture(a.width,a.height,{type:b,format:gl.RGBA, -filter:gl.LINEAR}));var c=this._uniforms;b=this.properties.distance;this.isInputConnected(1)&&(b=this.getInputData(1),this.properties.distance=b);var d=this.properties.range;this.isInputConnected(2)&&(d=this.getInputData(2),this.properties.range=d);c.u_distance=b;c.u_range=d;gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var e=Mesh.getScreenQuad();f._shader||(f._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,f.pixel_shader),f._shader_onlydepth=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,f.pixel_shader, -{ONLY_DEPTH:""}));var h=this.properties.only_depth?f._shader_onlydepth:f._shader;b=null;b=a.near_far_planes?a.near_far_planes:window.LS&&LS.Renderer._main_camera?LS.Renderer._main_camera._uniforms.u_camera_planes:[.1,1E3];c.u_camera_planes=b;this._temp_texture.drawTo(function(){a.bind(0);h.uniforms(c).draw(e)});this._temp_texture.near_far_planes=b;this.setOutputData(0,this._temp_texture)}}},f.pixel_shader="precision highp float;\n\t\tprecision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuniform sampler2D u_texture;\n\t\tuniform vec2 u_camera_planes;\n\t\tuniform float u_distance;\n\t\tuniform float u_range;\n\t\t\n\t\tfloat LinearDepth()\n\t\t{\n\t\t\tfloat zNear = u_camera_planes.x;\n\t\t\tfloat zFar = u_camera_planes.y;\n\t\t\tfloat depth = texture2D(u_texture, v_coord).x;\n\t\t\tdepth = depth * 2.0 - 1.0;\n\t\t\treturn zNear * (depth + 1.0) / (zFar + zNear - depth * (zFar - zNear));\n\t\t}\n\t\t\n\t\tvoid main() {\n\t\t\tfloat depth = LinearDepth();\n\t\t\t#ifdef ONLY_DEPTH\n\t\t\t gl_FragColor = vec4(depth);\n\t\t\t#else\n\t\t\t\tfloat diff = abs(depth * u_camera_planes.y - u_distance);\n\t\t\t\tfloat dof = 1.0;\n\t\t\t\tif(diff <= u_range)\n\t\t\t\t\tdof = diff / u_range;\n\t\t\t gl_FragColor = vec4(dof);\n\t\t\t#endif\n\t\t}\n\t\t", -L.registerNodeType("texture/depth_range",f),x.widgets_info={precision:{widget:"combo",values:c.MODE_VALUES}},x.title="Linear Depth",x.desc="Creates a color texture with linear depth",x.prototype.onExecute=function(){if(this.isOutputConnected(0)){var a=this.getInputData(0);if(a&&(a.format==gl.DEPTH_COMPONENT||a.format==gl.DEPTH_STENCIL)){var b=this.properties.precision==c.HIGH?gl.HIGH_PRECISION_FORMAT:gl.UNSIGNED_BYTE;this._temp_texture&&this._temp_texture.type==b&&this._temp_texture.width==a.width&& -this._temp_texture.height==a.height||(this._temp_texture=new GL.Texture(a.width,a.height,{type:b,format:gl.RGB,filter:gl.LINEAR}));var d=this._uniforms;d.u_invert=this.properties.invert?1:0;gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var f=Mesh.getScreenQuad();x._shader||(x._shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,x.pixel_shader));var e=x._shader;b=null;b=a.near_far_planes?a.near_far_planes:window.LS&&LS.Renderer._main_camera?LS.Renderer._main_camera._uniforms.u_camera_planes:[.1,1E3]; -d.u_camera_planes=b;d.u_ires.set([0,0]);this._temp_texture.drawTo(function(){a.bind(0);e.uniforms(d).draw(f)});this._temp_texture.near_far_planes=b;this.setOutputData(0,this._temp_texture)}}},x.pixel_shader="precision highp float;\n\t\tprecision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuniform sampler2D u_texture;\n\t\tuniform vec2 u_camera_planes;\n\t\tuniform int u_invert;\n\t\tuniform vec2 u_ires;\n\t\t\n\t\tvoid main() {\n\t\t\tfloat zNear = u_camera_planes.x;\n\t\t\tfloat zFar = u_camera_planes.y;\n\t\t\tfloat depth = texture2D(u_texture, v_coord + u_ires*0.5).x * 2.0 - 1.0;\n\t\t\tfloat f = zNear * (depth + 1.0) / (zFar + zNear - depth * (zFar - zNear));\n\t\t\tif( u_invert == 1 )\n\t\t\t\tf = 1.0 - f;\n\t\t\tgl_FragColor = vec4(vec3(f),1.0);\n\t\t}\n\t\t", -L.registerNodeType("texture/linear_depth",x),J.title="Blur",J.desc="Blur a texture",J.widgets_info={precision:{widget:"combo",values:c.MODE_VALUES}},J.max_iterations=20,J.prototype.onExecute=function(){var a=this.getInputData(0);if(a&&this.isOutputConnected(0)){var b=this._final_texture;b&&b.width==a.width&&b.height==a.height&&b.type==a.type||(b=this._final_texture=new GL.Texture(a.width,a.height,{type:a.type,format:gl.RGBA,filter:gl.LINEAR}));var c=this.properties.iterations;this.isInputConnected(1)&& -(c=this.getInputData(1),this.properties.iterations=c);c=Math.min(Math.floor(c),J.max_iterations);if(0==c)this.setOutputData(0,a);else{var d=this.properties.intensity;this.isInputConnected(2)&&(d=this.getInputData(2),this.properties.intensity=d);var f=L.camera_aspect;f||void 0===window.gl||(f=gl.canvas.height/gl.canvas.width);f||(f=1);f=this.properties.preserve_aspect?f:1;var e=this.properties.scale||[1,1];a.applyBlur(f*e[0],e[1],d,b);for(a=1;a>=1;1<(e|0)&&(e>>=1);if(2>f)break;t=g[x]=GL.Texture.getTemporary(f,e,h);E[0]=1/l.width;E[1]=1/l.height;l.blit(t,m.uniforms(k));l=t}d&&(E[0]=1/l.width,E[1]=1/l.height,k.u_intensity=n,k.u_delta=1,l.blit(d,m.uniforms(k)));gl.enable(gl.BLEND);gl.blendFunc(gl.ONE,gl.ONE);k.u_intensity=this.persistence; -k.u_delta=.5;for(x-=2;0<=x;x--)t=g[x],g[x]=null,E[0]=1/l.width,E[1]=1/l.height,l.blit(t,m.uniforms(k)),GL.Texture.releaseTemporary(l),l=t;gl.disable(gl.BLEND);c&&l.blit(c);if(b){var v=this.dirt_texture,q=this.dirt_factor;k.u_intensity=n;m=v?u._dirt_final_shader:u._final_shader;m||(m=v?u._dirt_final_shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,u.final_pixel_shader,{USE_DIRT:""}):u._final_shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,u.final_pixel_shader));b.drawTo(function(){a.bind(0); -l.bind(1);v&&(m.setUniform("u_dirt_factor",q),m.setUniform("u_dirt_texture",v.bind(2)));m.toViewport(k)})}GL.Texture.releaseTemporary(l)},u.cut_pixel_shader="precision highp float;\n\tvarying vec2 v_coord;\n\tuniform sampler2D u_texture;\n\tuniform float u_threshold;\n\tvoid main() {\n\t\tgl_FragColor = max( texture2D( u_texture, v_coord ) - vec4( u_threshold ), vec4(0.0) );\n\t}",u.scale_pixel_shader="precision highp float;\n\tvarying vec2 v_coord;\n\tuniform sampler2D u_texture;\n\tuniform vec2 u_texel_size;\n\tuniform float u_delta;\n\tuniform float u_intensity;\n\t\n\tvec4 sampleBox(vec2 uv) {\n\t\tvec4 o = u_texel_size.xyxy * vec2(-u_delta, u_delta).xxyy;\n\t\tvec4 s = texture2D( u_texture, uv + o.xy ) + texture2D( u_texture, uv + o.zy) + texture2D( u_texture, uv + o.xw) + texture2D( u_texture, uv + o.zw);\n\t\treturn s * 0.25;\n\t}\n\tvoid main() {\n\t\tgl_FragColor = u_intensity * sampleBox( v_coord );\n\t}", -u.final_pixel_shader="precision highp float;\n\tvarying vec2 v_coord;\n\tuniform sampler2D u_texture;\n\tuniform sampler2D u_glow_texture;\n\t#ifdef USE_DIRT\n\t\tuniform sampler2D u_dirt_texture;\n\t#endif\n\tuniform vec2 u_texel_size;\n\tuniform float u_delta;\n\tuniform float u_intensity;\n\tuniform float u_dirt_factor;\n\t\n\tvec4 sampleBox(vec2 uv) {\n\t\tvec4 o = u_texel_size.xyxy * vec2(-u_delta, u_delta).xxyy;\n\t\tvec4 s = texture2D( u_glow_texture, uv + o.xy ) + texture2D( u_glow_texture, uv + o.zy) + texture2D( u_glow_texture, uv + o.xw) + texture2D( u_glow_texture, uv + o.zw);\n\t\treturn s * 0.25;\n\t}\n\tvoid main() {\n\t\tvec4 glow = sampleBox( v_coord );\n\t\t#ifdef USE_DIRT\n\t\t\tglow = mix( glow, glow * texture2D( u_dirt_texture, v_coord ), u_dirt_factor );\n\t\t#endif\n\t\tgl_FragColor = texture2D( u_texture, v_coord ) + u_intensity * glow;\n\t}", -v.title="Glow",v.desc="Filters a texture giving it a glow effect",v.widgets_info={iterations:{type:"number",min:0,max:16,step:1,precision:0},threshold:{type:"number",min:0,max:10,step:.01,precision:2},precision:{widget:"combo",values:c.MODE_VALUES}},v.prototype.onGetInputs=function(){return[["enabled","boolean"],["threshold","number"],["intensity","number"],["persistence","number"],["iterations","number"],["dirt_factor","number"]]},v.prototype.onGetOutputs=function(){return[["average","Texture"]]}, -v.prototype.onExecute=function(){var a=this.getInputData(0);if(a&&this.isAnyOutputConnected())if(this.properties.precision===c.PASS_THROUGH||!1===this.getInputOrProperty("enabled"))this.setOutputData(0,a);else{var b=this.fx;b.threshold=this.getInputOrProperty("threshold");b.iterations=this.getInputOrProperty("iterations");b.intensity=this.getInputOrProperty("intensity");b.persistence=this.getInputOrProperty("persistence");b.dirt_texture=this.getInputData(1);b.dirt_factor=this.getInputOrProperty("dirt_factor"); -b.scale=this.properties.scale;var d=c.getTextureType(this.properties.precision,a),f=null;this.isOutputConnected(2)&&(f=this._average_texture,f&&f.type==a.type&&f.format==a.format||(f=this._average_texture=new GL.Texture(1,1,{type:a.type,format:a.format,filter:gl.LINEAR})));var e=null;this.isOutputConnected(1)&&(e=this._glow_texture,e&&e.width==a.width&&e.height==a.height&&e.type==d&&e.format==a.format||(e=this._glow_texture=new GL.Texture(a.width,a.height,{type:d,format:a.format,filter:gl.LINEAR}))); -var h=null;this.isOutputConnected(0)&&(h=this._final_texture,h&&h.width==a.width&&h.height==a.height&&h.type==d&&h.format==a.format||(h=this._final_texture=new GL.Texture(a.width,a.height,{type:d,format:a.format,filter:gl.LINEAR})));b.applyFX(a,h,e,f);this.isOutputConnected(0)&&this.setOutputData(0,h);this.isOutputConnected(1)&&this.setOutputData(1,f);this.isOutputConnected(2)&&this.setOutputData(2,e)}},L.registerNodeType("texture/glow",v),O.title="Kuwahara Filter",O.desc="Filters a texture giving an artistic oil canvas painting", -O.max_radius=10,O._shaders=[],O.prototype.onExecute=function(){var a=this.getInputData(0);if(a&&this.isOutputConnected(0)){var b=this._temp_texture;b&&b.width==a.width&&b.height==a.height&&b.type==a.type||(this._temp_texture=new GL.Texture(a.width,a.height,{type:a.type,format:gl.RGBA,filter:gl.LINEAR}));b=this.properties.radius;b=Math.min(Math.floor(b),O.max_radius);if(0==b)this.setOutputData(0,a);else{var c=this.properties.intensity,d=L.camera_aspect;d||void 0===window.gl||(d=gl.canvas.height/gl.canvas.width); -d||(d=1);d=this.properties.preserve_aspect?d:1;O._shaders[b]||(O._shaders[b]=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,O.pixel_shader,{RADIUS:b.toFixed(0)}));var f=O._shaders[b],e=GL.Mesh.getScreenQuad();a.bind(0);this._temp_texture.drawTo(function(){f.uniforms({u_texture:0,u_intensity:c,u_resolution:[a.width,a.height],u_iResolution:[1/a.width,1/a.height]}).draw(e)});this.setOutputData(0,this._temp_texture)}}},O.pixel_shader="\nprecision highp float;\nvarying vec2 v_coord;\nuniform sampler2D u_texture;\nuniform float u_intensity;\nuniform vec2 u_resolution;\nuniform vec2 u_iResolution;\n#ifndef RADIUS\n\t#define RADIUS 7\n#endif\nvoid main() {\n\n\tconst int radius = RADIUS;\n\tvec2 fragCoord = v_coord;\n\tvec2 src_size = u_iResolution;\n\tvec2 uv = v_coord;\n\tfloat n = float((radius + 1) * (radius + 1));\n\tint i;\n\tint j;\n\tvec3 m0 = vec3(0.0); vec3 m1 = vec3(0.0); vec3 m2 = vec3(0.0); vec3 m3 = vec3(0.0);\n\tvec3 s0 = vec3(0.0); vec3 s1 = vec3(0.0); vec3 s2 = vec3(0.0); vec3 s3 = vec3(0.0);\n\tvec3 c;\n\t\n\tfor (int j = -radius; j <= 0; ++j) {\n\t\tfor (int i = -radius; i <= 0; ++i) {\n\t\t\tc = texture2D(u_texture, uv + vec2(i,j) * src_size).rgb;\n\t\t\tm0 += c;\n\t\t\ts0 += c * c;\n\t\t}\n\t}\n\t\n\tfor (int j = -radius; j <= 0; ++j) {\n\t\tfor (int i = 0; i <= radius; ++i) {\n\t\t\tc = texture2D(u_texture, uv + vec2(i,j) * src_size).rgb;\n\t\t\tm1 += c;\n\t\t\ts1 += c * c;\n\t\t}\n\t}\n\t\n\tfor (int j = 0; j <= radius; ++j) {\n\t\tfor (int i = 0; i <= radius; ++i) {\n\t\t\tc = texture2D(u_texture, uv + vec2(i,j) * src_size).rgb;\n\t\t\tm2 += c;\n\t\t\ts2 += c * c;\n\t\t}\n\t}\n\t\n\tfor (int j = 0; j <= radius; ++j) {\n\t\tfor (int i = -radius; i <= 0; ++i) {\n\t\t\tc = texture2D(u_texture, uv + vec2(i,j) * src_size).rgb;\n\t\t\tm3 += c;\n\t\t\ts3 += c * c;\n\t\t}\n\t}\n\t\n\tfloat min_sigma2 = 1e+2;\n\tm0 /= n;\n\ts0 = abs(s0 / n - m0 * m0);\n\t\n\tfloat sigma2 = s0.r + s0.g + s0.b;\n\tif (sigma2 < min_sigma2) {\n\t\tmin_sigma2 = sigma2;\n\t\tgl_FragColor = vec4(m0, 1.0);\n\t}\n\t\n\tm1 /= n;\n\ts1 = abs(s1 / n - m1 * m1);\n\t\n\tsigma2 = s1.r + s1.g + s1.b;\n\tif (sigma2 < min_sigma2) {\n\t\tmin_sigma2 = sigma2;\n\t\tgl_FragColor = vec4(m1, 1.0);\n\t}\n\t\n\tm2 /= n;\n\ts2 = abs(s2 / n - m2 * m2);\n\t\n\tsigma2 = s2.r + s2.g + s2.b;\n\tif (sigma2 < min_sigma2) {\n\t\tmin_sigma2 = sigma2;\n\t\tgl_FragColor = vec4(m2, 1.0);\n\t}\n\t\n\tm3 /= n;\n\ts3 = abs(s3 / n - m3 * m3);\n\t\n\tsigma2 = s3.r + s3.g + s3.b;\n\tif (sigma2 < min_sigma2) {\n\t\tmin_sigma2 = sigma2;\n\t\tgl_FragColor = vec4(m3, 1.0);\n\t}\n}\n", -L.registerNodeType("texture/kuwahara",O),N.title="XDoG Filter",N.desc="Filters a texture giving an artistic ink style",N.max_radius=10,N._shaders=[],N.prototype.onExecute=function(){var a=this.getInputData(0);if(a&&this.isOutputConnected(0)){var b=this._temp_texture;b&&b.width==a.width&&b.height==a.height&&b.type==a.type||(this._temp_texture=new GL.Texture(a.width,a.height,{type:a.type,format:gl.RGBA,filter:gl.LINEAR}));N._xdog_shader||(N._xdog_shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,N.xdog_pixel_shader)); -var c=N._xdog_shader,d=GL.Mesh.getScreenQuad(),f=this.properties.sigma,e=this.properties.k,h=this.properties.p,k=this.properties.epsilon,g=this.properties.phi;a.bind(0);this._temp_texture.drawTo(function(){c.uniforms({src:0,sigma:f,k:e,p:h,epsilon:k,phi:g,cvsWidth:a.width,cvsHeight:a.height}).draw(d)});this.setOutputData(0,this._temp_texture)}},N.xdog_pixel_shader="\nprecision highp float;\nuniform sampler2D src;\n\nuniform float cvsHeight;\nuniform float cvsWidth;\n\nuniform float sigma;\nuniform float k;\nuniform float p;\nuniform float epsilon;\nuniform float phi;\nvarying vec2 v_coord;\n\nfloat cosh(float val)\n{\n\tfloat tmp = exp(val);\n\tfloat cosH = (tmp + 1.0 / tmp) / 2.0;\n\treturn cosH;\n}\n\nfloat tanh(float val)\n{\n\tfloat tmp = exp(val);\n\tfloat tanH = (tmp - 1.0 / tmp) / (tmp + 1.0 / tmp);\n\treturn tanH;\n}\n\nfloat sinh(float val)\n{\n\tfloat tmp = exp(val);\n\tfloat sinH = (tmp - 1.0 / tmp) / 2.0;\n\treturn sinH;\n}\n\nvoid main(void){\n\tvec3 destColor = vec3(0.0);\n\tfloat tFrag = 1.0 / cvsHeight;\n\tfloat sFrag = 1.0 / cvsWidth;\n\tvec2 Frag = vec2(sFrag,tFrag);\n\tvec2 uv = gl_FragCoord.st;\n\tfloat twoSigmaESquared = 2.0 * sigma * sigma;\n\tfloat twoSigmaRSquared = twoSigmaESquared * k * k;\n\tint halfWidth = int(ceil( 1.0 * sigma * k ));\n\n\tconst int MAX_NUM_ITERATION = 99999;\n\tvec2 sum = vec2(0.0);\n\tvec2 norm = vec2(0.0);\n\n\tfor(int cnt=0;cnt (2*halfWidth+1)*(2*halfWidth+1)){break;}\n\t\tint i = int(cnt / (2*halfWidth+1)) - halfWidth;\n\t\tint j = cnt - halfWidth - int(cnt / (2*halfWidth+1)) * (2*halfWidth+1);\n\n\t\tfloat d = length(vec2(i,j));\n\t\tvec2 kernel = vec2( exp( -d * d / twoSigmaESquared ), \n\t\t\t\t\t\t\texp( -d * d / twoSigmaRSquared ));\n\n\t\tvec2 L = texture2D(src, (uv + vec2(i,j)) * Frag).xx;\n\n\t\tnorm += kernel;\n\t\tsum += kernel * L;\n\t}\n\n\tsum /= norm;\n\n\tfloat H = 100.0 * ((1.0 + p) * sum.x - p * sum.y);\n\tfloat edge = ( H > epsilon )? 1.0 : 1.0 + tanh( phi * (H - epsilon));\n\tdestColor = vec3(edge);\n\tgl_FragColor = vec4(destColor, 1.0);\n}", -L.registerNodeType("texture/xDoG",N),I.title="Webcam",I.desc="Webcam texture",I.is_webcam_open=!1,I.prototype.openStream=function(){if(navigator.getUserMedia){this._waiting_confirmation=!0;navigator.mediaDevices.getUserMedia({audio:!1,video:{facingMode:this.properties.facingMode}}).then(this.streamReady.bind(this)).catch(function(b){I.is_webcam_open=!1;console.log("Webcam rejected",b);a._webcam_stream=!1;a.boxcolor="red";a.trigger("stream_error")});var a=this}},I.prototype.closeStream=function(){if(this._webcam_stream){var a= -this._webcam_stream.getTracks();if(a.length)for(var b=0;b=this.size[1]||!this._video||(a.save(),a.webgl?this._video_texture&&a.drawImage(this._video_texture,0,0,this.size[0],this.size[1]):a.drawImage(this._video, -0,0,this.size[0],this.size[1]),a.restore())},I.prototype.onExecute=function(){null!=this._webcam_stream||this._waiting_confirmation||this.openStream();if(this._video&&this._video.videoWidth){var a=this._video.videoWidth,b=this._video.videoHeight,d=this._video_texture;d&&d.width==a&&d.height==b||(this._video_texture=new GL.Texture(a,b,{format:gl.RGB,filter:gl.LINEAR}));this._video_texture.uploadImage(this._video);this._video_texture.version=++this.version;this.properties.texture_name&&(c.getTexturesContainer()[this.properties.texture_name]= -this._video_texture);this.setOutputData(0,this._video_texture);for(a=1;aMath.abs(b))return c[1];a=(a-c[0])/b;return c[1]*(1-a)+f[1]*a}}return 0}},H.prototype.updateCurve=function(){for(var a=this._values,b=a.length/4,d=this.properties.split_channels,c=0;ca.width?b: +a,this._tex,this.properties.precision);gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var e=Mesh.getScreenQuad(),k=null,h=this._uniforms;f?(k=d._shader_tex,k||(k=d._shader_tex=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,d.pixel_shader,{MIX_TEX:""}))):(k=d._shader_factor,k||(k=d._shader_factor=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,d.pixel_shader)),g=null==g?this.properties.factor:g,h.u_mix.set([g,g,g,g]));var m=this.properties.invert;this._tex.drawTo(function(){a.bind(m?1:0);b.bind(m?0:1);f&&f.bind(2); +k.uniforms(h).draw(e)});this.setOutputData(0,this._tex)}}},d.prototype.onGetInputs=function(){return[["factor","number"]]},d.pixel_shader="precision highp float;\n\t\tprecision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuniform sampler2D u_textureA;\n\t\tuniform sampler2D u_textureB;\n\t\t#ifdef MIX_TEX\n\t\t\tuniform sampler2D u_textureMix;\n\t\t#else\n\t\t\tuniform vec4 u_mix;\n\t\t#endif\n\t\t\n\t\tvoid main() {\n\t\t\t#ifdef MIX_TEX\n\t\t\t vec4 f = texture2D(u_textureMix, v_coord);\n\t\t\t#else\n\t\t\t vec4 f = u_mix;\n\t\t\t#endif\n\t\t gl_FragColor = mix( texture2D(u_textureA, v_coord), texture2D(u_textureB, v_coord), f );\n\t\t}\n\t\t", +N.registerNodeType("texture/mix",d),g.title="Edges",g.desc="Detects edges",g.widgets_info={precision:{widget:"combo",values:c.MODE_VALUES}},g.prototype.onExecute=function(){if(this.isOutputConnected(0)){var a=this.getInputData(0);if(this.properties.precision===c.PASS_THROUGH)this.setOutputData(0,a);else if(a){this._tex=c.getTargetTexture(a,this._tex,this.properties.precision);gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var b=Mesh.getScreenQuad(),d=g._shader,f=this.properties.invert,e=this.properties.factor, +k=this.properties.threshold?1:0;this._tex.drawTo(function(){a.bind(0);d.uniforms({u_texture:0,u_isize:[1/a.width,1/a.height],u_factor:e,u_threshold:k,u_invert:f?1:0}).draw(b)});this.setOutputData(0,this._tex)}}},g.pixel_shader="precision highp float;\n\t\tprecision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuniform sampler2D u_texture;\n\t\tuniform vec2 u_isize;\n\t\tuniform int u_invert;\n\t\tuniform float u_factor;\n\t\tuniform float u_threshold;\n\t\t\n\t\tvoid main() {\n\t\t\tvec4 center = texture2D(u_texture, v_coord);\n\t\t\tvec4 up = texture2D(u_texture, v_coord + u_isize * vec2(0.0,1.0) );\n\t\t\tvec4 down = texture2D(u_texture, v_coord + u_isize * vec2(0.0,-1.0) );\n\t\t\tvec4 left = texture2D(u_texture, v_coord + u_isize * vec2(1.0,0.0) );\n\t\t\tvec4 right = texture2D(u_texture, v_coord + u_isize * vec2(-1.0,0.0) );\n\t\t\tvec4 diff = abs(center - up) + abs(center - down) + abs(center - left) + abs(center - right);\n\t\t\tdiff *= u_factor;\n\t\t\tif(u_invert == 1)\n\t\t\t\tdiff.xyz = vec3(1.0) - diff.xyz;\n\t\t\tif( u_threshold == 0.0 )\n\t\t\t\tgl_FragColor = vec4( diff.xyz, center.a );\n\t\t\telse\n\t\t\t\tgl_FragColor = vec4( diff.x > 0.5 ? 1.0 : 0.0, diff.y > 0.5 ? 1.0 : 0.0, diff.z > 0.5 ? 1.0 : 0.0, center.a );\n\t\t}\n\t\t", +N.registerNodeType("texture/edges",g),f.title="Depth Range",f.desc="Generates a texture with a depth range",f.prototype.onExecute=function(){if(this.isOutputConnected(0)){var a=this.getInputData(0);if(a){var b=gl.UNSIGNED_BYTE;this.properties.high_precision&&(b=gl.half_float_ext?gl.HALF_FLOAT_OES:gl.FLOAT);this._temp_texture&&this._temp_texture.type==b&&this._temp_texture.width==a.width&&this._temp_texture.height==a.height||(this._temp_texture=new GL.Texture(a.width,a.height,{type:b,format:gl.RGBA, +filter:gl.LINEAR}));var d=this._uniforms;b=this.properties.distance;this.isInputConnected(1)&&(b=this.getInputData(1),this.properties.distance=b);var c=this.properties.range;this.isInputConnected(2)&&(c=this.getInputData(2),this.properties.range=c);d.u_distance=b;d.u_range=c;gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var g=Mesh.getScreenQuad();f._shader||(f._shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,f.pixel_shader),f._shader_onlydepth=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,f.pixel_shader, +{ONLY_DEPTH:""}));var e=this.properties.only_depth?f._shader_onlydepth:f._shader;b=null;b=a.near_far_planes?a.near_far_planes:window.LS&&LS.Renderer._main_camera?LS.Renderer._main_camera._uniforms.u_camera_planes:[.1,1E3];d.u_camera_planes=b;this._temp_texture.drawTo(function(){a.bind(0);e.uniforms(d).draw(g)});this._temp_texture.near_far_planes=b;this.setOutputData(0,this._temp_texture)}}},f.pixel_shader="precision highp float;\n\t\tprecision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuniform sampler2D u_texture;\n\t\tuniform vec2 u_camera_planes;\n\t\tuniform float u_distance;\n\t\tuniform float u_range;\n\t\t\n\t\tfloat LinearDepth()\n\t\t{\n\t\t\tfloat zNear = u_camera_planes.x;\n\t\t\tfloat zFar = u_camera_planes.y;\n\t\t\tfloat depth = texture2D(u_texture, v_coord).x;\n\t\t\tdepth = depth * 2.0 - 1.0;\n\t\t\treturn zNear * (depth + 1.0) / (zFar + zNear - depth * (zFar - zNear));\n\t\t}\n\t\t\n\t\tvoid main() {\n\t\t\tfloat depth = LinearDepth();\n\t\t\t#ifdef ONLY_DEPTH\n\t\t\t gl_FragColor = vec4(depth);\n\t\t\t#else\n\t\t\t\tfloat diff = abs(depth * u_camera_planes.y - u_distance);\n\t\t\t\tfloat dof = 1.0;\n\t\t\t\tif(diff <= u_range)\n\t\t\t\t\tdof = diff / u_range;\n\t\t\t gl_FragColor = vec4(dof);\n\t\t\t#endif\n\t\t}\n\t\t", +N.registerNodeType("texture/depth_range",f),m.widgets_info={precision:{widget:"combo",values:c.MODE_VALUES}},m.title="Linear Depth",m.desc="Creates a color texture with linear depth",m.prototype.onExecute=function(){if(this.isOutputConnected(0)){var a=this.getInputData(0);if(a&&(a.format==gl.DEPTH_COMPONENT||a.format==gl.DEPTH_STENCIL)){var b=this.properties.precision==c.HIGH?gl.HIGH_PRECISION_FORMAT:gl.UNSIGNED_BYTE;this._temp_texture&&this._temp_texture.type==b&&this._temp_texture.width==a.width&& +this._temp_texture.height==a.height||(this._temp_texture=new GL.Texture(a.width,a.height,{type:b,format:gl.RGB,filter:gl.LINEAR}));var d=this._uniforms;d.u_invert=this.properties.invert?1:0;gl.disable(gl.BLEND);gl.disable(gl.DEPTH_TEST);var f=Mesh.getScreenQuad();m._shader||(m._shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,m.pixel_shader));var g=m._shader;b=null;b=a.near_far_planes?a.near_far_planes:window.LS&&LS.Renderer._main_camera?LS.Renderer._main_camera._uniforms.u_camera_planes:[.1,1E3]; +d.u_camera_planes=b;d.u_ires.set([0,0]);this._temp_texture.drawTo(function(){a.bind(0);g.uniforms(d).draw(f)});this._temp_texture.near_far_planes=b;this.setOutputData(0,this._temp_texture)}}},m.pixel_shader="precision highp float;\n\t\tprecision highp float;\n\t\tvarying vec2 v_coord;\n\t\tuniform sampler2D u_texture;\n\t\tuniform vec2 u_camera_planes;\n\t\tuniform int u_invert;\n\t\tuniform vec2 u_ires;\n\t\t\n\t\tvoid main() {\n\t\t\tfloat zNear = u_camera_planes.x;\n\t\t\tfloat zFar = u_camera_planes.y;\n\t\t\tfloat depth = texture2D(u_texture, v_coord + u_ires*0.5).x * 2.0 - 1.0;\n\t\t\tfloat f = zNear * (depth + 1.0) / (zFar + zNear - depth * (zFar - zNear));\n\t\t\tif( u_invert == 1 )\n\t\t\t\tf = 1.0 - f;\n\t\t\tgl_FragColor = vec4(vec3(f),1.0);\n\t\t}\n\t\t", +N.registerNodeType("texture/linear_depth",m),u.title="Blur",u.desc="Blur a texture",u.widgets_info={precision:{widget:"combo",values:c.MODE_VALUES}},u.max_iterations=20,u.prototype.onExecute=function(){var a=this.getInputData(0);if(a&&this.isOutputConnected(0)){var b=this._final_texture;b&&b.width==a.width&&b.height==a.height&&b.type==a.type||(b=this._final_texture=new GL.Texture(a.width,a.height,{type:a.type,format:gl.RGBA,filter:gl.LINEAR}));var d=this.properties.iterations;this.isInputConnected(1)&& +(d=this.getInputData(1),this.properties.iterations=d);d=Math.min(Math.floor(d),u.max_iterations);if(0==d)this.setOutputData(0,a);else{var c=this.properties.intensity;this.isInputConnected(2)&&(c=this.getInputData(2),this.properties.intensity=c);var f=N.camera_aspect;f||void 0===window.gl||(f=gl.canvas.height/gl.canvas.width);f||(f=1);f=this.properties.preserve_aspect?f:1;var g=this.properties.scale||[1,1];a.applyBlur(f*g[0],g[1],c,b);for(a=1;a>=1;1<(g|0)&&(g>>=1);if(2>f)break;q=h[u]=GL.Texture.getTemporary(f,g,e);l[0]=1/n.width;l[1]=1/n.height;n.blit(q,m.uniforms(k));n=q}c&&(l[0]=1/n.width,l[1]=1/n.height,k.u_intensity=G,k.u_delta=1,n.blit(c,m.uniforms(k)));gl.enable(gl.BLEND);gl.blendFunc(gl.ONE,gl.ONE);k.u_intensity=this.persistence; +k.u_delta=.5;for(u-=2;0<=u;u--)q=h[u],h[u]=null,l[0]=1/n.width,l[1]=1/n.height,n.blit(q,m.uniforms(k)),GL.Texture.releaseTemporary(n),n=q;gl.disable(gl.BLEND);d&&n.blit(d);if(b){var t=this.dirt_texture,w=this.dirt_factor;k.u_intensity=G;m=t?O._dirt_final_shader:O._final_shader;m||(m=t?O._dirt_final_shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,O.final_pixel_shader,{USE_DIRT:""}):O._final_shader=new GL.Shader(GL.Shader.SCREEN_VERTEX_SHADER,O.final_pixel_shader));b.drawTo(function(){a.bind(0); +n.bind(1);t&&(m.setUniform("u_dirt_factor",w),m.setUniform("u_dirt_texture",t.bind(2)));m.toViewport(k)})}GL.Texture.releaseTemporary(n)},O.cut_pixel_shader="precision highp float;\n\tvarying vec2 v_coord;\n\tuniform sampler2D u_texture;\n\tuniform float u_threshold;\n\tvoid main() {\n\t\tgl_FragColor = max( texture2D( u_texture, v_coord ) - vec4( u_threshold ), vec4(0.0) );\n\t}",O.scale_pixel_shader="precision highp float;\n\tvarying vec2 v_coord;\n\tuniform sampler2D u_texture;\n\tuniform vec2 u_texel_size;\n\tuniform float u_delta;\n\tuniform float u_intensity;\n\t\n\tvec4 sampleBox(vec2 uv) {\n\t\tvec4 o = u_texel_size.xyxy * vec2(-u_delta, u_delta).xxyy;\n\t\tvec4 s = texture2D( u_texture, uv + o.xy ) + texture2D( u_texture, uv + o.zy) + texture2D( u_texture, uv + o.xw) + texture2D( u_texture, uv + o.zw);\n\t\treturn s * 0.25;\n\t}\n\tvoid main() {\n\t\tgl_FragColor = u_intensity * sampleBox( v_coord );\n\t}", +O.final_pixel_shader="precision highp float;\n\tvarying vec2 v_coord;\n\tuniform sampler2D u_texture;\n\tuniform sampler2D u_glow_texture;\n\t#ifdef USE_DIRT\n\t\tuniform sampler2D u_dirt_texture;\n\t#endif\n\tuniform vec2 u_texel_size;\n\tuniform float u_delta;\n\tuniform float u_intensity;\n\tuniform float u_dirt_factor;\n\t\n\tvec4 sampleBox(vec2 uv) {\n\t\tvec4 o = u_texel_size.xyxy * vec2(-u_delta, u_delta).xxyy;\n\t\tvec4 s = texture2D( u_glow_texture, uv + o.xy ) + texture2D( u_glow_texture, uv + o.zy) + texture2D( u_glow_texture, uv + o.xw) + texture2D( u_glow_texture, uv + o.zw);\n\t\treturn s * 0.25;\n\t}\n\tvoid main() {\n\t\tvec4 glow = sampleBox( v_coord );\n\t\t#ifdef USE_DIRT\n\t\t\tglow = mix( glow, glow * texture2D( u_dirt_texture, v_coord ), u_dirt_factor );\n\t\t#endif\n\t\tgl_FragColor = texture2D( u_texture, v_coord ) + u_intensity * glow;\n\t}", +K.title="Glow",K.desc="Filters a texture giving it a glow effect",K.widgets_info={iterations:{type:"number",min:0,max:16,step:1,precision:0},threshold:{type:"number",min:0,max:10,step:.01,precision:2},precision:{widget:"combo",values:c.MODE_VALUES}},K.prototype.onGetInputs=function(){return[["enabled","boolean"],["threshold","number"],["intensity","number"],["persistence","number"],["iterations","number"],["dirt_factor","number"]]},K.prototype.onGetOutputs=function(){return[["average","Texture"]]}, +K.prototype.onExecute=function(){var a=this.getInputData(0);if(a&&this.isAnyOutputConnected())if(this.properties.precision===c.PASS_THROUGH||!1===this.getInputOrProperty("enabled"))this.setOutputData(0,a);else{var b=this.fx;b.threshold=this.getInputOrProperty("threshold");b.iterations=this.getInputOrProperty("iterations");b.intensity=this.getInputOrProperty("intensity");b.persistence=this.getInputOrProperty("persistence");b.dirt_texture=this.getInputData(1);b.dirt_factor=this.getInputOrProperty("dirt_factor"); +b.scale=this.properties.scale;var d=c.getTextureType(this.properties.precision,a),f=null;this.isOutputConnected(2)&&(f=this._average_texture,f&&f.type==a.type&&f.format==a.format||(f=this._average_texture=new GL.Texture(1,1,{type:a.type,format:a.format,filter:gl.LINEAR})));var g=null;this.isOutputConnected(1)&&(g=this._glow_texture,g&&g.width==a.width&&g.height==a.height&&g.type==d&&g.format==a.format||(g=this._glow_texture=new GL.Texture(a.width,a.height,{type:d,format:a.format,filter:gl.LINEAR}))); +var e=null;this.isOutputConnected(0)&&(e=this._final_texture,e&&e.width==a.width&&e.height==a.height&&e.type==d&&e.format==a.format||(e=this._final_texture=new GL.Texture(a.width,a.height,{type:d,format:a.format,filter:gl.LINEAR})));b.applyFX(a,e,g,f);this.isOutputConnected(0)&&this.setOutputData(0,e);this.isOutputConnected(1)&&this.setOutputData(1,f);this.isOutputConnected(2)&&this.setOutputData(2,g)}},N.registerNodeType("texture/glow",K),x.title="Kuwahara Filter",x.desc="Filters a texture giving an artistic oil canvas painting", +x.max_radius=10,x._shaders=[],x.prototype.onExecute=function(){var a=this.getInputData(0);if(a&&this.isOutputConnected(0)){var b=this._temp_texture;b&&b.width==a.width&&b.height==a.height&&b.type==a.type||(this._temp_texture=new GL.Texture(a.width,a.height,{type:a.type,format:gl.RGBA,filter:gl.LINEAR}));b=this.properties.radius;b=Math.min(Math.floor(b),x.max_radius);if(0==b)this.setOutputData(0,a);else{var d=this.properties.intensity,c=N.camera_aspect;c||void 0===window.gl||(c=gl.canvas.height/gl.canvas.width); +c||(c=1);c=this.properties.preserve_aspect?c:1;x._shaders[b]||(x._shaders[b]=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,x.pixel_shader,{RADIUS:b.toFixed(0)}));var f=x._shaders[b],g=GL.Mesh.getScreenQuad();a.bind(0);this._temp_texture.drawTo(function(){f.uniforms({u_texture:0,u_intensity:d,u_resolution:[a.width,a.height],u_iResolution:[1/a.width,1/a.height]}).draw(g)});this.setOutputData(0,this._temp_texture)}}},x.pixel_shader="\nprecision highp float;\nvarying vec2 v_coord;\nuniform sampler2D u_texture;\nuniform float u_intensity;\nuniform vec2 u_resolution;\nuniform vec2 u_iResolution;\n#ifndef RADIUS\n\t#define RADIUS 7\n#endif\nvoid main() {\n\n\tconst int radius = RADIUS;\n\tvec2 fragCoord = v_coord;\n\tvec2 src_size = u_iResolution;\n\tvec2 uv = v_coord;\n\tfloat n = float((radius + 1) * (radius + 1));\n\tint i;\n\tint j;\n\tvec3 m0 = vec3(0.0); vec3 m1 = vec3(0.0); vec3 m2 = vec3(0.0); vec3 m3 = vec3(0.0);\n\tvec3 s0 = vec3(0.0); vec3 s1 = vec3(0.0); vec3 s2 = vec3(0.0); vec3 s3 = vec3(0.0);\n\tvec3 c;\n\t\n\tfor (int j = -radius; j <= 0; ++j) {\n\t\tfor (int i = -radius; i <= 0; ++i) {\n\t\t\tc = texture2D(u_texture, uv + vec2(i,j) * src_size).rgb;\n\t\t\tm0 += c;\n\t\t\ts0 += c * c;\n\t\t}\n\t}\n\t\n\tfor (int j = -radius; j <= 0; ++j) {\n\t\tfor (int i = 0; i <= radius; ++i) {\n\t\t\tc = texture2D(u_texture, uv + vec2(i,j) * src_size).rgb;\n\t\t\tm1 += c;\n\t\t\ts1 += c * c;\n\t\t}\n\t}\n\t\n\tfor (int j = 0; j <= radius; ++j) {\n\t\tfor (int i = 0; i <= radius; ++i) {\n\t\t\tc = texture2D(u_texture, uv + vec2(i,j) * src_size).rgb;\n\t\t\tm2 += c;\n\t\t\ts2 += c * c;\n\t\t}\n\t}\n\t\n\tfor (int j = 0; j <= radius; ++j) {\n\t\tfor (int i = -radius; i <= 0; ++i) {\n\t\t\tc = texture2D(u_texture, uv + vec2(i,j) * src_size).rgb;\n\t\t\tm3 += c;\n\t\t\ts3 += c * c;\n\t\t}\n\t}\n\t\n\tfloat min_sigma2 = 1e+2;\n\tm0 /= n;\n\ts0 = abs(s0 / n - m0 * m0);\n\t\n\tfloat sigma2 = s0.r + s0.g + s0.b;\n\tif (sigma2 < min_sigma2) {\n\t\tmin_sigma2 = sigma2;\n\t\tgl_FragColor = vec4(m0, 1.0);\n\t}\n\t\n\tm1 /= n;\n\ts1 = abs(s1 / n - m1 * m1);\n\t\n\tsigma2 = s1.r + s1.g + s1.b;\n\tif (sigma2 < min_sigma2) {\n\t\tmin_sigma2 = sigma2;\n\t\tgl_FragColor = vec4(m1, 1.0);\n\t}\n\t\n\tm2 /= n;\n\ts2 = abs(s2 / n - m2 * m2);\n\t\n\tsigma2 = s2.r + s2.g + s2.b;\n\tif (sigma2 < min_sigma2) {\n\t\tmin_sigma2 = sigma2;\n\t\tgl_FragColor = vec4(m2, 1.0);\n\t}\n\t\n\tm3 /= n;\n\ts3 = abs(s3 / n - m3 * m3);\n\t\n\tsigma2 = s3.r + s3.g + s3.b;\n\tif (sigma2 < min_sigma2) {\n\t\tmin_sigma2 = sigma2;\n\t\tgl_FragColor = vec4(m3, 1.0);\n\t}\n}\n", +N.registerNodeType("texture/kuwahara",x),C.title="XDoG Filter",C.desc="Filters a texture giving an artistic ink style",C.max_radius=10,C._shaders=[],C.prototype.onExecute=function(){var a=this.getInputData(0);if(a&&this.isOutputConnected(0)){var b=this._temp_texture;b&&b.width==a.width&&b.height==a.height&&b.type==a.type||(this._temp_texture=new GL.Texture(a.width,a.height,{type:a.type,format:gl.RGBA,filter:gl.LINEAR}));C._xdog_shader||(C._xdog_shader=new GL.Shader(Shader.SCREEN_VERTEX_SHADER,C.xdog_pixel_shader)); +var d=C._xdog_shader,c=GL.Mesh.getScreenQuad(),f=this.properties.sigma,g=this.properties.k,e=this.properties.p,k=this.properties.epsilon,h=this.properties.phi;a.bind(0);this._temp_texture.drawTo(function(){d.uniforms({src:0,sigma:f,k:g,p:e,epsilon:k,phi:h,cvsWidth:a.width,cvsHeight:a.height}).draw(c)});this.setOutputData(0,this._temp_texture)}},C.xdog_pixel_shader="\nprecision highp float;\nuniform sampler2D src;\n\nuniform float cvsHeight;\nuniform float cvsWidth;\n\nuniform float sigma;\nuniform float k;\nuniform float p;\nuniform float epsilon;\nuniform float phi;\nvarying vec2 v_coord;\n\nfloat cosh(float val)\n{\n\tfloat tmp = exp(val);\n\tfloat cosH = (tmp + 1.0 / tmp) / 2.0;\n\treturn cosH;\n}\n\nfloat tanh(float val)\n{\n\tfloat tmp = exp(val);\n\tfloat tanH = (tmp - 1.0 / tmp) / (tmp + 1.0 / tmp);\n\treturn tanH;\n}\n\nfloat sinh(float val)\n{\n\tfloat tmp = exp(val);\n\tfloat sinH = (tmp - 1.0 / tmp) / 2.0;\n\treturn sinH;\n}\n\nvoid main(void){\n\tvec3 destColor = vec3(0.0);\n\tfloat tFrag = 1.0 / cvsHeight;\n\tfloat sFrag = 1.0 / cvsWidth;\n\tvec2 Frag = vec2(sFrag,tFrag);\n\tvec2 uv = gl_FragCoord.st;\n\tfloat twoSigmaESquared = 2.0 * sigma * sigma;\n\tfloat twoSigmaRSquared = twoSigmaESquared * k * k;\n\tint halfWidth = int(ceil( 1.0 * sigma * k ));\n\n\tconst int MAX_NUM_ITERATION = 99999;\n\tvec2 sum = vec2(0.0);\n\tvec2 norm = vec2(0.0);\n\n\tfor(int cnt=0;cnt (2*halfWidth+1)*(2*halfWidth+1)){break;}\n\t\tint i = int(cnt / (2*halfWidth+1)) - halfWidth;\n\t\tint j = cnt - halfWidth - int(cnt / (2*halfWidth+1)) * (2*halfWidth+1);\n\n\t\tfloat d = length(vec2(i,j));\n\t\tvec2 kernel = vec2( exp( -d * d / twoSigmaESquared ), \n\t\t\t\t\t\t\texp( -d * d / twoSigmaRSquared ));\n\n\t\tvec2 L = texture2D(src, (uv + vec2(i,j)) * Frag).xx;\n\n\t\tnorm += kernel;\n\t\tsum += kernel * L;\n\t}\n\n\tsum /= norm;\n\n\tfloat H = 100.0 * ((1.0 + p) * sum.x - p * sum.y);\n\tfloat edge = ( H > epsilon )? 1.0 : 1.0 + tanh( phi * (H - epsilon));\n\tdestColor = vec3(edge);\n\tgl_FragColor = vec4(destColor, 1.0);\n}", +N.registerNodeType("texture/xDoG",C),w.title="Webcam",w.desc="Webcam texture",w.is_webcam_open=!1,w.prototype.openStream=function(){if(navigator.getUserMedia){this._waiting_confirmation=!0;navigator.mediaDevices.getUserMedia({audio:!1,video:{facingMode:this.properties.facingMode}}).then(this.streamReady.bind(this)).catch(function(b){w.is_webcam_open=!1;console.log("Webcam rejected",b);a._webcam_stream=!1;a.boxcolor="red";a.trigger("stream_error")});var a=this}},w.prototype.closeStream=function(){if(this._webcam_stream){var a= +this._webcam_stream.getTracks();if(a.length)for(var b=0;b=this.size[1]||!this._video||(a.save(),a.webgl?this._video_texture&&a.drawImage(this._video_texture,0,0,this.size[0],this.size[1]):a.drawImage(this._video, +0,0,this.size[0],this.size[1]),a.restore())},w.prototype.onExecute=function(){null!=this._webcam_stream||this._waiting_confirmation||this.openStream();if(this._video&&this._video.videoWidth){var a=this._video.videoWidth,b=this._video.videoHeight,d=this._video_texture;d&&d.width==a&&d.height==b||(this._video_texture=new GL.Texture(a,b,{format:gl.RGB,filter:gl.LINEAR}));this._video_texture.uploadImage(this._video);this._video_texture.version=++this.version;this.properties.texture_name&&(c.getTexturesContainer()[this.properties.texture_name]= +this._video_texture);this.setOutputData(0,this._video_texture);for(a=1;aMath.abs(b))return c[1];a=(a-c[0])/b;return c[1]*(1-a)+f[1]*a}}return 0}},y.prototype.updateCurve=function(){for(var a=this._values,b=a.length/4,d=this.properties.split_channels,c=0;cd+f.NODE_TITLE_HEIGHT&&a.drawImage(b,10,e,this.size[0]-20,this.size[1]-d-f.NODE_TITLE_HEIGHT);var e=this.size[1]-f.NODE_TITLE_HEIGHT+.5;c=f.isInsideRectangle(c[0],c[1],this.pos[0],this.pos[1]+e,this.size[0],f.NODE_TITLE_HEIGHT);a.fillStyle=c?"#555":"#222";a.beginPath();this._shape==f.BOX_SHAPE?a.rect(0,e,this.size[0]+1,f.NODE_TITLE_HEIGHT):a.roundRect(0,e,this.size[0]+1,f.NODE_TITLE_HEIGHT,0,8);a.fill();a.textAlign="center";a.font="24px Arial";a.fillStyle= -c?"#DDD":"#999";a.fillText("+",.5*this.size[0],e+24)}};A.prototype.onMouseDown=function(a,b,d){b[1]>this.size[1]-f.NODE_TITLE_HEIGHT+.5&&d.showSubgraphPropertiesDialog(this)};A.prototype.onDrawSubgraphBackground=function(a){};A.prototype.getExtraMenuOptions=function(a){var b=this;return[{content:"Print Code",callback:function(){var a=b._context.computeShaderCode();console.log(a.vs_code,a.fs_code)}}]};f.registerNodeType("texture/shaderGraph",A);B.title="Uniform";B.desc="Input data for the shader"; -B.prototype.getTitle=function(){return this.properties.name&&this.flags.collapsed?this.properties.type+" "+this.properties.name:"Uniform"};B.prototype.onPropertyChanged=function(a,b){this.outputs[0].name=this.properties.type+" "+this.properties.name};B.prototype.onGetCode=function(a){if(this.shader_destination){var b=this.properties.type;if(!b){if(!a.onGetPropertyInfo)return;b=a.onGetPropertyInfo(this.property.name);if(!b)return;b=b.type}"number"==b?b="float":"texture"==b&&(b="sampler2D");-1!=x.GLSL_types.indexOf(b)&& -(a.addUniform("u_"+this.properties.name,b),this.setOutputData(0,b))}};B.prototype.getOutputVarName=function(a){return"u_"+this.properties.name};g("input/uniform",B);C.title="Attribute";C.desc="Input data from mesh attribute";C.prototype.getTitle=function(){return"att. "+this.properties.name};C.prototype.onGetCode=function(a){if(this.shader_destination){var b=this.properties.type;b&&-1!=x.GLSL_types.indexOf(b)&&("number"==b&&(b="float"),"coord"!=this.properties.name&&a.addCode("varying"," varying "+ -b+" v_"+this.properties.name+";"),this.setOutputData(0,b))}};C.prototype.getOutputVarName=function(a){return"v_"+this.properties.name};g("input/attribute",C);G.title="Sampler2D";G.desc="Reads a pixel from a texture";G.prototype.onGetCode=function(a){if(this.shader_destination){var b=n(this,0),d=q(this),c="vec4 "+d+" = vec4(0.0);\n";if(b){var f=n(this,1)||a.buffer_names.uvs;c+=d+" = texture2D("+b+","+f+");\n"}w(this,0)&&(c+="vec4 "+w(this,0)+" = "+d+";\n");w(this,1)&&(c+="vec3 "+w(this,1)+" = "+d+ -".xyz;\n");a.addCode("code",c,this.shader_destination);this.setOutputData(0,"vec4");this.setOutputData(1,"vec3")}};g("texture/sampler2D",G);D.title="const";D.prototype.getTitle=function(){return this.flags.collapsed?N(this.properties.value,this.properties.type,2):"Const"};D.prototype.onPropertyChanged=function(a,b){"type"==a&&(this.outputs[0].type!=b&&(this.disconnectOutput(0),this.outputs[0].type=b),this.widgets.length=1,this.updateWidgets());"value"==a&&(b.length?(this.widgets[1].value=b[1],2d+f.NODE_TITLE_HEIGHT&&a.drawImage(b,10,g,this.size[0]-20,this.size[1]-d-f.NODE_TITLE_HEIGHT);var g=this.size[1]-f.NODE_TITLE_HEIGHT+.5;c=f.isInsideRectangle(c[0],c[1],this.pos[0],this.pos[1]+g,this.size[0],f.NODE_TITLE_HEIGHT);a.fillStyle=c?"#555":"#222";a.beginPath();this._shape==f.BOX_SHAPE?a.rect(0,g,this.size[0]+1,f.NODE_TITLE_HEIGHT):a.roundRect(0,g,this.size[0]+1,f.NODE_TITLE_HEIGHT,0,8);a.fill();a.textAlign="center";a.font="24px Arial";a.fillStyle= +c?"#DDD":"#999";a.fillText("+",.5*this.size[0],g+24)}};E.prototype.onMouseDown=function(a,b,d){b[1]>this.size[1]-f.NODE_TITLE_HEIGHT+.5&&d.showSubgraphPropertiesDialog(this)};E.prototype.onDrawSubgraphBackground=function(a){};E.prototype.getExtraMenuOptions=function(a){var b=this;return[{content:"Print Code",callback:function(){var a=b._context.computeShaderCode();console.log(a.vs_code,a.fs_code)}}]};f.registerNodeType("texture/shaderGraph",E);A.title="Uniform";A.desc="Input data for the shader"; +A.prototype.getTitle=function(){return this.properties.name&&this.flags.collapsed?this.properties.type+" "+this.properties.name:"Uniform"};A.prototype.onPropertyChanged=function(a,b){this.outputs[0].name=this.properties.type+" "+this.properties.name};A.prototype.onGetCode=function(a){if(this.shader_destination){var b=this.properties.type;if(!b){if(!a.onGetPropertyInfo)return;b=a.onGetPropertyInfo(this.property.name);if(!b)return;b=b.type}"number"==b?b="float":"texture"==b&&(b="sampler2D");-1!=m.GLSL_types.indexOf(b)&& +(a.addUniform("u_"+this.properties.name,b),this.setOutputData(0,b))}};A.prototype.getOutputVarName=function(a){return"u_"+this.properties.name};l("input/uniform",A);I.title="Attribute";I.desc="Input data from mesh attribute";I.prototype.getTitle=function(){return"att. "+this.properties.name};I.prototype.onGetCode=function(a){if(this.shader_destination){var b=this.properties.type;b&&-1!=m.GLSL_types.indexOf(b)&&("number"==b&&(b="float"),"coord"!=this.properties.name&&a.addCode("varying"," varying "+ +b+" v_"+this.properties.name+";"),this.setOutputData(0,b))}};I.prototype.getOutputVarName=function(a){return"v_"+this.properties.name};l("input/attribute",I);J.title="Sampler2D";J.desc="Reads a pixel from a texture";J.prototype.onGetCode=function(a){if(this.shader_destination){var b=t(this,0),d=r(this),c="vec4 "+d+" = vec4(0.0);\n";if(b){var f=t(this,1)||a.buffer_names.uvs;c+=d+" = texture2D("+b+","+f+");\n"}v(this,0)&&(c+="vec4 "+v(this,0)+" = "+d+";\n");v(this,1)&&(c+="vec3 "+v(this,1)+" = "+d+ +".xyz;\n");a.addCode("code",c,this.shader_destination);this.setOutputData(0,"vec4");this.setOutputData(1,"vec3")}};l("texture/sampler2D",J);F.title="const";F.prototype.getTitle=function(){return this.flags.collapsed?C(this.properties.value,this.properties.type,2):"Const"};F.prototype.onPropertyChanged=function(a,b){"type"==a&&(this.outputs[0].type!=b&&(this.disconnectOutput(0),this.outputs[0].type=b),this.widgets.length=1,this.updateWidgets());"value"==a&&(b.length?(this.widgets[1].value=b[1],2d;++d)b.push({name:n(this,d),type:this.getInputData(d)||"float"});var c=w(this,0);if(c){var f=b[0].type,e=this.properties.operation, -h=[];for(d=0;2>d;++d){var k=b[d].name;null==k&&(k=null!=p.value?p.value:"(1.0)",b[d].type="float");b[d].type!=f&&("float"!=b[d].type||"*"!=e&&"/"!=e)&&(k=M(k,b[d].type,f));h.push(k)}a.addCode("code",f+" "+c+" = "+h[0]+e+h[1]+";",this.shader_destination);this.setOutputData(0,f)}}};g("math/operation",K);k.title="Func";k.prototype.onPropertyChanged=function(a,b){this.graph&&this.graph._version++;if("func"==a&&(a=v[b])){for(b=a.params.length;bd;++d)b.push({name:n(this,d),type:this.getInputData(d)||"float"});var c=w(this,0);if(c){var f=v[this.properties.func];if(f){var e=b[0].type,h=f.return_type;"T"==h&&(h=e);var k=[];for(d= -0;dd;++d)b.push({name:t(this,d),type:this.getInputData(d)||"float"});var c=v(this,0);if(c){var f=b[0].type,g=this.properties.operation, +e=[];for(d=0;2>d;++d){var k=b[d].name;null==k&&(k=null!=p.value?p.value:"(1.0)",b[d].type="float");b[d].type!=f&&("float"!=b[d].type||"*"!=g&&"/"!=g)&&(k=L(k,b[d].type,f));e.push(k)}a.addCode("code",f+" "+c+" = "+e[0]+g+e[1]+";",this.shader_destination);this.setOutputData(0,f)}}};l("math/operation",M);k.title="Func";k.prototype.onPropertyChanged=function(a,b){this.graph&&this.graph._version++;if("func"==a&&(a=K[b])){for(b=a.params.length;bd;++d)b.push({name:t(this,d),type:this.getInputData(d)||"float"});var c=v(this,0);if(c){var f=K[this.properties.func];if(f){var g=b[0].type,e=f.return_type;"T"==e&&(e=g);var k=[];for(d= +0;d=c;){e=.5*(k+c)|0;b=a[e];if(b==d)break;if(c==k-1)return c;ba&&(a=1);this.points&&this.points.length==3*a||(this.points=new Float32Array(3*a));this.properties.generate_normals?this.normals&&this.normals.length==this.points.length||(this.normals=new Float32Array(this.points.length)):this.normals=null;var d=this._last_radius||this.properties.radius,c=this.properties.mode,f=this.getInputData(0);this._old_obj_version=f?f._version:null;this.points=g.generatePoints(d,a,c,this.points,this.normals, -this.properties.regular,f);this.version++};g.generatePoints=function(a,d,c,f,e,k,m){var b=3*d;f&&f.length==b||(f=new Float32Array(b));var h=new Float32Array(3),t=new Float32Array([0,1,0]);if(k)if(c==g.RECTANGLE){b=Math.floor(Math.sqrt(d));for(d=0;dk||yg&&gm))break}this.geometry.indices=this.indices=new Uint32Array(t)}this.indices&&this.indices.length?(this.geometry.indices=this.indices,this.setOutputData(0,this.geometry)):this.setOutputData(0,null)}};y.registerNodeType("geometry/connectPoints",C);"undefined"!=typeof GL&&(G.title="to geometry",G.desc="converts a mesh to geometry",G.prototype.onExecute=function(){var a=this.getInputData(0);if(a){if(a!=this.last_mesh){this.last_mesh=a;for(i in a.vertexBuffers)this.geometry[i]= -a.vertexBuffers[i].data;a.indexBuffers.triangles&&(this.geometry.indices=a.indexBuffers.triangles.data);this.geometry._id=c();this.geometry._version=0}this.setOutputData(0,this.geometry);this.geometry&&this.setOutputData(1,this.geometry.vertices)}},y.registerNodeType("geometry/toGeometry",G),D.title="Geo to Mesh",D.prototype.updateMesh=function(a){this.mesh||(this.mesh=new GL.Mesh);for(var b in a)if("_"!=b[0]){var c=a[b],e=GL.Mesh.common_buffers[b];if(e||"indices"==b){e=e?e.spacing:3;var k=this.mesh.vertexBuffers[b]; -k&&k.data.length==c.length?(k.data.set(c),k.upload(GL.DYNAMIC_DRAW)):k=new GL.Buffer("indices"==b?GL.ELEMENT_ARRAY_BUFFER:GL.ARRAY_BUFFER,c,e,GL.DYNAMIC_DRAW);this.mesh.addBuffer(b,k)}}if(this.mesh.vertexBuffers.normals&&this.mesh.vertexBuffers.normals.data.length!=this.mesh.vertexBuffers.vertices.data.length){c=new Float32Array([0,1,0]);e=new Float32Array(this.mesh.vertexBuffers.vertices.data.length);for(b=0;b=c;){e=.5*(k+c)|0;b=a[e];if(b==d)break;if(c==k-1)return c;ba&&(a=1);this.points&&this.points.length==3*a||(this.points=new Float32Array(3*a));this.properties.generate_normals?this.normals&&this.normals.length==this.points.length||(this.normals=new Float32Array(this.points.length)):this.normals=null;var d=this._last_radius||this.properties.radius,c=this.properties.mode,f=this.getInputData(0);this._old_obj_version=f?f._version:null;this.points=l.generatePoints(d,a,c,this.points,this.normals, +this.properties.regular,f);this.version++};l.generatePoints=function(a,d,c,f,e,k,h){var b=3*d;f&&f.length==b||(f=new Float32Array(b));var g=new Float32Array(3),n=new Float32Array([0,1,0]);if(k)if(c==l.RECTANGLE){b=Math.floor(Math.sqrt(d));for(d=0;dk||yh&&hq))break}this.geometry.indices=this.indices=new Uint32Array(n)}this.indices&&this.indices.length?(this.geometry.indices=this.indices,this.setOutputData(0,this.geometry)):this.setOutputData(0,null)}};z.registerNodeType("geometry/connectPoints",I);"undefined"!=typeof GL&&(J.title="to geometry",J.desc="converts a mesh to geometry",J.prototype.onExecute=function(){var a=this.getInputData(0);if(a){if(a!=this.last_mesh){this.last_mesh=a;for(i in a.vertexBuffers)this.geometry[i]= +a.vertexBuffers[i].data;a.indexBuffers.triangles&&(this.geometry.indices=a.indexBuffers.triangles.data);this.geometry._id=c();this.geometry._version=0}this.setOutputData(0,this.geometry);this.geometry&&this.setOutputData(1,this.geometry.vertices)}},z.registerNodeType("geometry/toGeometry",J),F.title="Geo to Mesh",F.prototype.updateMesh=function(a){this.mesh||(this.mesh=new GL.Mesh);for(var b in a)if("_"!=b[0]){var c=a[b],f=GL.Mesh.common_buffers[b];if(f||"indices"==b){f=f?f.spacing:3;var e=this.mesh.vertexBuffers[b]; +e&&e.data.length==c.length?(e.data.set(c),e.upload(GL.DYNAMIC_DRAW)):e=new GL.Buffer("indices"==b?GL.ELEMENT_ARRAY_BUFFER:GL.ARRAY_BUFFER,c,f,GL.DYNAMIC_DRAW);this.mesh.addBuffer(b,e)}}if(this.mesh.vertexBuffers.normals&&this.mesh.vertexBuffers.normals.data.length!=this.mesh.vertexBuffers.vertices.data.length){c=new Float32Array([0,1,0]);f=new Float32Array(this.mesh.vertexBuffers.vertices.data.length);for(b=0;b=c.NOTEON||k<=c.NOTEOFF)this.channel=e&15};Object.defineProperty(c.prototype,"velocity",{get:function(){return this.cmd==c.NOTEON?this.data[2]:-1},set:function(c){this.data[2]=c},enumerable:!0});c.notes="A A# B C C# D D# E F F# G G#".split(" ");c.note_to_index={A:0,"A#":1,B:2,C:3,"C#":4,D:5,"D#":6,E:7,F:8,"F#":9,G:10,"G#":11};Object.defineProperty(c.prototype,"note",{get:function(){return this.cmd!= c.NOTEON?-1:c.toNoteString(this.data[1],!0)},set:function(c){throw"notes cannot be assigned this way, must modify the data[1]";},enumerable:!0});Object.defineProperty(c.prototype,"octave",{get:function(){return this.cmd!=c.NOTEON?-1:Math.floor((this.data[1]-24)/12+1)},set:function(c){throw"octave cannot be assigned this way, must modify the data[1]";},enumerable:!0});c.prototype.getPitch=function(){return 440*Math.pow(2,(this.data[1]-69)/12)};c.computePitch=function(c){return 440*Math.pow(2,(c-69)/ 12)};c.prototype.getCC=function(){return this.data[1]};c.prototype.getCCValue=function(){return this.data[2]};c.prototype.getPitchBend=function(){return this.data[1]+(this.data[2]<<7)-8192};c.computePitchBend=function(c,e){return c+(e<<7)-8192};c.prototype.setCommandFromString=function(e){this.cmd=c.computeCommandFromString(e)};c.computeCommandFromString=function(e){if(!e)return 0;if(e&&e.constructor===Number)return e;e=e.toUpperCase();switch(e){case "NOTE ON":case "NOTEON":return c.NOTEON;case "NOTE OFF":case "NOTEOFF":return c.NOTEON; -case "KEY PRESSURE":case "KEYPRESSURE":return c.KEYPRESSURE;case "CONTROLLER CHANGE":case "CONTROLLERCHANGE":case "CC":return c.CONTROLLERCHANGE;case "PROGRAM CHANGE":case "PROGRAMCHANGE":case "PC":return c.PROGRAMCHANGE;case "CHANNEL PRESSURE":case "CHANNELPRESSURE":return c.CHANNELPRESSURE;case "PITCH BEND":case "PITCHBEND":return c.PITCHBEND;case "TIME TICK":case "TIMETICK":return c.TIMETICK;default:return Number(e)}};c.toNoteString=function(e,g){e=Math.round(e);var k=Math.floor((e-24)/12+1);e= -(e-21)%12;0>e&&(e=12+e);return c.notes[e]+(g?"":k)};c.NoteStringToPitch=function(e){e=e.toUpperCase();var k=e[0],g=4;"#"==e[1]?(k+="#",2e&&(e=12+e);return c.notes[e]+(h?"":k)};c.NoteStringToPitch=function(e){e=e.toUpperCase();var k=e[0],h=4;"#"==e[1]?(k+="#",2this.properties.max_value)return;this.trigger("on_midi",g)}};y.registerNodeType("midi/filter",l);A.title="MIDIEvent";A.desc="Create a MIDI Event";A.color="#243";A.prototype.onAction=function(e,g){"assign"==e?(this.properties.channel=g.channel,this.properties.cmd=g.cmd,this.properties.value1=g.data[1],this.properties.value2=g.data[2],g.cmd== -c.NOTEON?this.gate=!0:g.cmd==c.NOTEOFF&&(this.gate=!1)):(g=this.midi_event,g.channel=this.properties.channel,this.properties.cmd&&this.properties.cmd.constructor===String?g.setCommandFromString(this.properties.cmd):g.cmd=this.properties.cmd,g.data[0]=g.cmd|g.channel,g.data[1]=Number(this.properties.value1),g.data[2]=Number(this.properties.value2),this.trigger("on_midi",g))};A.prototype.onExecute=function(){var e=this.properties;if(this.inputs)for(var g=0;gc;++c)this.valid_notes[c]=-1!=this.notes_pitches.indexOf(c);for(c=0;12>c;++c)if(this.valid_notes[c])this.offset_notes[c]=0;else for(var e=1;12>e;++e){if(this.valid_notes[(c-e)%12]){this.offset_notes[c]=-e;break}if(this.valid_notes[(c+e)%12]){this.offset_notes[c]=e;break}}};D.prototype.onAction=function(e,g){g&&g.constructor===c&&(g.data[0]==c.NOTEON||g.data[0]==c.NOTEOFF?(this.midi_event=new c,this.midi_event.setup(g.data),this.midi_event.data[1]+=this.offset_notes[c.note_to_index[g.note]], -this.trigger("out",this.midi_event)):this.trigger("out",g))};D.prototype.onExecute=function(){var c=this.getInputData(1);null!=c&&c!=this._current_scale&&this.processScale(c)};y.registerNodeType("midi/quantize",D);e.title="MIDI fromFile";e.desc="Plays a MIDI file";e.color="#243";e.prototype.onAction=function(c){"play"==c?this.play():"pause"==c&&(this._playing=!this._playing)};e.prototype.onPropertyChanged=function(c,e){"url"==c&&this.loadMIDIFile(e)};e.prototype.onExecute=function(){if(this._midi&& -this._playing){this._current_time+=this.graph.elapsed_time;for(var e=100*this._current_time,g=0;gb;b++)for(var d=0;dh+f||c[1]>d))return b}}return-1};F.prototype.onAction=function(e,g){if("reset"==e)for(g=0;gg[1]))return e=this.getKeyIndex(g),this.keys[e]=!0,this._last_key=e,e=12*(this.properties.start_octave-1)+29+e,g=new c,g.setup([c.NOTEON,e,100]),this.trigger("note",g),!0};F.prototype.onMouseMove=function(e,g){if(!(0>g[1]||-1==this._last_key)){this.setDirtyCanvas(!0); -e=this.getKeyIndex(g);if(this._last_key==e)return!0;this.keys[this._last_key]=!1;g=12*(this.properties.start_octave-1)+29+this._last_key;var k=new c;k.setup([c.NOTEOFF,g,100]);this.trigger("note",k);this.keys[e]=!0;g=12*(this.properties.start_octave-1)+29+e;k=new c;k.setup([c.NOTEON,g,100]);this.trigger("note",k);this._last_key=e;return!0}};F.prototype.onMouseUp=function(e,g){if(!(0>g[1]))return e=this.getKeyIndex(g),this.keys[e]=!1,this._last_key=-1,e=12*(this.properties.start_octave-1)+29+e,g=new c, -g.setup([c.NOTEOFF,e,100]),this.trigger("note",g),!0};y.registerNodeType("midi/keys",F)})(this); -(function(z){function c(){this.properties={src:"",gain:.5,loop:!0,autoplay:!0,playbackRate:1};this._loading_audio=!1;this._audiobuffer=null;this._audionodes=[];this._last_sourcenode=null;this.addOutput("out","audio");this.addInput("gain","number");this.audionode=m.getAudioContext().createGain();this.audionode.graphnode=this;this.audionode.gain.value=this.properties.gain;this.properties.src&&this.loadSound(this.properties.src)}function g(){this.properties={gain:.5};this._audionodes=[];this._media_stream= -null;this.addOutput("out","audio");this.addInput("gain","number");this.audionode=m.getAudioContext().createGain();this.audionode.graphnode=this;this.audionode.gain.value=this.properties.gain}function q(){this.properties={fftSize:2048,minDecibels:-100,maxDecibels:-10,smoothingTimeConstant:.5};this.audionode=m.getAudioContext().createAnalyser();this.audionode.graphnode=this;this.audionode.fftSize=this.properties.fftSize;this.audionode.minDecibels=this.properties.minDecibels;this.audionode.maxDecibels= -this.properties.maxDecibels;this.audionode.smoothingTimeConstant=this.properties.smoothingTimeConstant;this.addInput("in","audio");this.addOutput("freqs","array");this.addOutput("samples","array");this._time_bin=this._freq_bin=null}function n(){this.properties={gain:1};this.audionode=m.getAudioContext().createGain();this.addInput("in","audio");this.addInput("gain","number");this.addOutput("out","audio")}function w(){this.properties={impulse_src:"",normalize:!0};this.audionode=m.getAudioContext().createConvolver(); -this.addInput("in","audio");this.addOutput("out","audio")}function l(){this.properties={threshold:-50,knee:40,ratio:12,reduction:-20,attack:0,release:.25};this.audionode=m.getAudioContext().createDynamicsCompressor();this.addInput("in","audio");this.addOutput("out","audio")}function A(){this.properties={};this.audionode=m.getAudioContext().createWaveShaper();this.addInput("in","audio");this.addInput("shape","waveshape");this.addOutput("out","audio")}function B(){this.properties={gain1:.5,gain2:.5}; -this.audionode=m.getAudioContext().createGain();this.audionode1=m.getAudioContext().createGain();this.audionode1.gain.value=this.properties.gain1;this.audionode2=m.getAudioContext().createGain();this.audionode2.gain.value=this.properties.gain2;this.audionode1.connect(this.audionode);this.audionode2.connect(this.audionode);this.addInput("in1","audio");this.addInput("in1 gain","number");this.addInput("in2","audio");this.addInput("in2 gain","number");this.addOutput("out","audio")}function C(){this.properties= -{A:.1,D:.1,S:.1,R:.1};this.audionode=m.getAudioContext().createGain();this.audionode.gain.value=0;this.addInput("in","audio");this.addInput("gate","bool");this.addOutput("out","audio");this.gate=!1}function G(){this.properties={delayTime:.5};this.audionode=m.getAudioContext().createDelay(10);this.audionode.delayTime.value=this.properties.delayTime;this.addInput("in","audio");this.addInput("time","number");this.addOutput("out","audio")}function D(){this.properties={frequency:350,detune:0,Q:1};this.addProperty("type", -"lowpass","enum",{values:"lowpass highpass bandpass lowshelf highshelf peaking notch allpass".split(" ")});this.audionode=m.getAudioContext().createBiquadFilter();this.addInput("in","audio");this.addOutput("out","audio")}function e(){this.properties={frequency:440,detune:0,type:"sine"};this.addProperty("type","sine","enum",{values:["sine","square","sawtooth","triangle","custom"]});this.audionode=m.getAudioContext().createOscillator();this.addOutput("out","audio")}function r(){this.properties={continuous:!0, -mark:-1};this.addInput("data","array");this.addInput("mark","number");this.size=[300,200];this._last_buffer=null}function F(){this.properties={band:440,amplitude:1};this.addInput("freqs","array");this.addOutput("signal","number")}function y(){if(!y.default_code){var c=y.default_function.toString(),a=c.indexOf("{")+1,b=c.lastIndexOf("}");y.default_code=c.substr(a,b-a)}this.properties={code:y.default_code};c=m.getAudioContext();c.createScriptProcessor?this.audionode=c.createScriptProcessor(4096,1,1): -(console.warn("ScriptProcessorNode deprecated"),this.audionode=c.createGain());this.processCode();y._bypass_function||(y._bypass_function=this.audionode.onaudioprocess);this.addInput("in","audio");this.addOutput("out","audio")}function K(){this.audionode=m.getAudioContext().destination;this.addInput("in","audio")}var k=z.LiteGraph,m={};z.LGAudio=m;m.getAudioContext=function(){if(!this._audio_context){window.AudioContext=window.AudioContext||window.webkitAudioContext;if(!window.AudioContext)return console.error("AudioContext not supported by browser"), -null;this._audio_context=new AudioContext;this._audio_context.onmessage=function(c){console.log("msg",c)};this._audio_context.onended=function(c){console.log("ended",c)};this._audio_context.oncomplete=function(c){console.log("complete",c)}}return this._audio_context};m.connect=function(c,a){try{c.connect(a)}catch(b){console.warn("LGraphAudio:",b)}};m.disconnect=function(c,a){try{c.disconnect(a)}catch(b){console.warn("LGraphAudio:",b)}};m.changeAllAudiosConnections=function(c,a){if(c.inputs)for(var b= -0;bthis.properties.max_value)return;this.trigger("on_midi",h)}};z.registerNodeType("midi/filter",h);E.title="MIDIEvent";E.desc="Create a MIDI Event";E.color="#243";E.prototype.onAction=function(e,h){"assign"==e?(this.properties.channel=h.channel,this.properties.cmd=h.cmd,this.properties.value1=h.data[1],this.properties.value2=h.data[2],h.cmd== +c.NOTEON?this.gate=!0:h.cmd==c.NOTEOFF&&(this.gate=!1)):(h=this.midi_event,h.channel=this.properties.channel,this.properties.cmd&&this.properties.cmd.constructor===String?h.setCommandFromString(this.properties.cmd):h.cmd=this.properties.cmd,h.data[0]=h.cmd|h.channel,h.data[1]=Number(this.properties.value1),h.data[2]=Number(this.properties.value2),this.trigger("on_midi",h))};E.prototype.onExecute=function(){var e=this.properties;if(this.inputs)for(var h=0;hc;++c)this.valid_notes[c]=-1!=this.notes_pitches.indexOf(c);for(c=0;12>c;++c)if(this.valid_notes[c])this.offset_notes[c]=0;else for(var e=1;12>e;++e){if(this.valid_notes[(c-e)%12]){this.offset_notes[c]=-e;break}if(this.valid_notes[(c+e)%12]){this.offset_notes[c]=e;break}}};F.prototype.onAction=function(e,h){h&&h.constructor===c&&(h.data[0]==c.NOTEON||h.data[0]==c.NOTEOFF?(this.midi_event=new c,this.midi_event.setup(h.data),this.midi_event.data[1]+=this.offset_notes[c.note_to_index[h.note]], +this.trigger("out",this.midi_event)):this.trigger("out",h))};F.prototype.onExecute=function(){var c=this.getInputData(1);null!=c&&c!=this._current_scale&&this.processScale(c)};z.registerNodeType("midi/quantize",F);e.title="MIDI fromFile";e.desc="Plays a MIDI file";e.color="#243";e.prototype.onAction=function(c){"play"==c?this.play():"pause"==c&&(this._playing=!this._playing)};e.prototype.onPropertyChanged=function(c,e){"url"==c&&this.loadMIDIFile(e)};e.prototype.onExecute=function(){if(this._midi&& +this._playing){this._current_time+=this.graph.elapsed_time;for(var e=100*this._current_time,h=0;hb;b++)for(var d=0;dg+f||c[1]>d))return b}}return-1};H.prototype.onAction=function(e,h){if("reset"==e)for(h=0;hh[1]))return e=this.getKeyIndex(h),this.keys[e]=!0,this._last_key=e,e=12*(this.properties.start_octave-1)+29+e,h=new c,h.setup([c.NOTEON,e,100]),this.trigger("note",h),!0};H.prototype.onMouseMove=function(e,h){if(!(0>h[1]||-1==this._last_key)){this.setDirtyCanvas(!0); +e=this.getKeyIndex(h);if(this._last_key==e)return!0;this.keys[this._last_key]=!1;h=12*(this.properties.start_octave-1)+29+this._last_key;var k=new c;k.setup([c.NOTEOFF,h,100]);this.trigger("note",k);this.keys[e]=!0;h=12*(this.properties.start_octave-1)+29+e;k=new c;k.setup([c.NOTEON,h,100]);this.trigger("note",k);this._last_key=e;return!0}};H.prototype.onMouseUp=function(e,h){if(!(0>h[1]))return e=this.getKeyIndex(h),this.keys[e]=!1,this._last_key=-1,e=12*(this.properties.start_octave-1)+29+e,h=new c, +h.setup([c.NOTEOFF,e,100]),this.trigger("note",h),!0};z.registerNodeType("midi/keys",H)})(this); +(function(B){function c(){this.properties={src:"",gain:.5,loop:!0,autoplay:!0,playbackRate:1};this._loading_audio=!1;this._audiobuffer=null;this._audionodes=[];this._last_sourcenode=null;this.addOutput("out","audio");this.addInput("gain","number");this.audionode=n.getAudioContext().createGain();this.audionode.graphnode=this;this.audionode.gain.value=this.properties.gain;this.properties.src&&this.loadSound(this.properties.src)}function l(){this.properties={gain:.5};this._audionodes=[];this._media_stream= +null;this.addOutput("out","audio");this.addInput("gain","number");this.audionode=n.getAudioContext().createGain();this.audionode.graphnode=this;this.audionode.gain.value=this.properties.gain}function r(){this.properties={fftSize:2048,minDecibels:-100,maxDecibels:-10,smoothingTimeConstant:.5};this.audionode=n.getAudioContext().createAnalyser();this.audionode.graphnode=this;this.audionode.fftSize=this.properties.fftSize;this.audionode.minDecibels=this.properties.minDecibels;this.audionode.maxDecibels= +this.properties.maxDecibels;this.audionode.smoothingTimeConstant=this.properties.smoothingTimeConstant;this.addInput("in","audio");this.addOutput("freqs","array");this.addOutput("samples","array");this._time_bin=this._freq_bin=null}function t(){this.properties={gain:1};this.audionode=n.getAudioContext().createGain();this.addInput("in","audio");this.addInput("gain","number");this.addOutput("out","audio")}function v(){this.properties={impulse_src:"",normalize:!0};this.audionode=n.getAudioContext().createConvolver(); +this.addInput("in","audio");this.addOutput("out","audio")}function h(){this.properties={threshold:-50,knee:40,ratio:12,reduction:-20,attack:0,release:.25};this.audionode=n.getAudioContext().createDynamicsCompressor();this.addInput("in","audio");this.addOutput("out","audio")}function E(){this.properties={};this.audionode=n.getAudioContext().createWaveShaper();this.addInput("in","audio");this.addInput("shape","waveshape");this.addOutput("out","audio")}function A(){this.properties={gain1:.5,gain2:.5}; +this.audionode=n.getAudioContext().createGain();this.audionode1=n.getAudioContext().createGain();this.audionode1.gain.value=this.properties.gain1;this.audionode2=n.getAudioContext().createGain();this.audionode2.gain.value=this.properties.gain2;this.audionode1.connect(this.audionode);this.audionode2.connect(this.audionode);this.addInput("in1","audio");this.addInput("in1 gain","number");this.addInput("in2","audio");this.addInput("in2 gain","number");this.addOutput("out","audio")}function I(){this.properties= +{A:.1,D:.1,S:.1,R:.1};this.audionode=n.getAudioContext().createGain();this.audionode.gain.value=0;this.addInput("in","audio");this.addInput("gate","boolean");this.addOutput("out","audio");this.gate=!1}function J(){this.properties={delayTime:.5};this.audionode=n.getAudioContext().createDelay(10);this.audionode.delayTime.value=this.properties.delayTime;this.addInput("in","audio");this.addInput("time","number");this.addOutput("out","audio")}function F(){this.properties={frequency:350,detune:0,Q:1};this.addProperty("type", +"lowpass","enum",{values:"lowpass highpass bandpass lowshelf highshelf peaking notch allpass".split(" ")});this.audionode=n.getAudioContext().createBiquadFilter();this.addInput("in","audio");this.addOutput("out","audio")}function e(){this.properties={frequency:440,detune:0,type:"sine"};this.addProperty("type","sine","enum",{values:["sine","square","sawtooth","triangle","custom"]});this.audionode=n.getAudioContext().createOscillator();this.addOutput("out","audio")}function D(){this.properties={continuous:!0, +mark:-1};this.addInput("data","array");this.addInput("mark","number");this.size=[300,200];this._last_buffer=null}function H(){this.properties={band:440,amplitude:1};this.addInput("freqs","array");this.addOutput("signal","number")}function z(){if(!z.default_code){var c=z.default_function.toString(),a=c.indexOf("{")+1,b=c.lastIndexOf("}");z.default_code=c.substr(a,b-a)}this.properties={code:z.default_code};c=n.getAudioContext();c.createScriptProcessor?this.audionode=c.createScriptProcessor(4096,1,1): +(console.warn("ScriptProcessorNode deprecated"),this.audionode=c.createGain());this.processCode();z._bypass_function||(z._bypass_function=this.audionode.onaudioprocess);this.addInput("in","audio");this.addOutput("out","audio")}function M(){this.audionode=n.getAudioContext().destination;this.addInput("in","audio")}var k=B.LiteGraph,n={};B.LGAudio=n;n.getAudioContext=function(){if(!this._audio_context){window.AudioContext=window.AudioContext||window.webkitAudioContext;if(!window.AudioContext)return console.error("AudioContext not supported by browser"), +null;this._audio_context=new AudioContext;this._audio_context.onmessage=function(c){console.log("msg",c)};this._audio_context.onended=function(c){console.log("ended",c)};this._audio_context.oncomplete=function(c){console.log("complete",c)}}return this._audio_context};n.connect=function(c,a){try{c.connect(a)}catch(b){console.warn("LGraphAudio:",b)}};n.disconnect=function(c,a){try{c.disconnect(a)}catch(b){console.warn("LGraphAudio:",b)}};n.changeAllAudiosConnections=function(c,a){if(c.inputs)for(var b= +0;b=this.size[0]&&(e=this.size[0]-1),c.strokeStyle= -"red",c.beginPath(),c.moveTo(e,d),c.lineTo(e,0),c.stroke())}};r.title="Visualization";r.desc="Audio Visualization";k.registerNodeType("audio/visualization",r);F.prototype.onExecute=function(){if(this._freqs=this.getInputData(0)){var c=this.properties.band,a=this.getInputData(1);void 0!==a&&(c=a);a=m.getAudioContext().sampleRate/this._freqs.length;a=c/a*2;a>=this._freqs.length?a=this._freqs[this._freqs.length-1]:(c=a|0,a-=c,a=this._freqs[c]*(1-a)+this._freqs[c+1]*a);this.setOutputData(0,a/255*this.properties.amplitude)}}; -F.prototype.onGetInputs=function(){return[["band","number"]]};F.title="Signal";F.desc="extract the signal of some frequency";k.registerNodeType("audio/signal",F);y.prototype.onAdded=function(c){c.status==LGraph.STATUS_RUNNING&&(this.audionode.onaudioprocess=this._callback)};y["@code"]={widget:"code",type:"code"};y.prototype.onStart=function(){this.audionode.onaudioprocess=this._callback};y.prototype.onStop=function(){this.audionode.onaudioprocess=y._bypass_function};y.prototype.onPause=function(){this.audionode.onaudioprocess= -y._bypass_function};y.prototype.onUnpause=function(){this.audionode.onaudioprocess=this._callback};y.prototype.onExecute=function(){};y.prototype.onRemoved=function(){this.audionode.onaudioprocess=y._bypass_function};y.prototype.processCode=function(){try{this._script=new (new Function("properties",this.properties.code))(this.properties),this._old_code=this.properties.code,this._callback=this._script.onaudioprocess}catch(t){console.error("Error in onaudioprocess code",t),this._callback=y._bypass_function, -this.audionode.onaudioprocess=this._callback}};y.prototype.onPropertyChanged=function(c,a){"code"==c&&(this.properties.code=a,this.processCode(),this.graph&&this.graph.status==LGraph.STATUS_RUNNING&&(this.audionode.onaudioprocess=this._callback))};y.default_function=function(){this.onaudioprocess=function(c){var a=c.inputBuffer;c=c.outputBuffer;for(var b=0;b=this.size[0]&&(e=this.size[0]-1),c.strokeStyle= +"red",c.beginPath(),c.moveTo(e,d),c.lineTo(e,0),c.stroke())}};D.title="Visualization";D.desc="Audio Visualization";k.registerNodeType("audio/visualization",D);H.prototype.onExecute=function(){if(this._freqs=this.getInputData(0)){var c=this.properties.band,a=this.getInputData(1);void 0!==a&&(c=a);a=n.getAudioContext().sampleRate/this._freqs.length;a=c/a*2;a>=this._freqs.length?a=this._freqs[this._freqs.length-1]:(c=a|0,a-=c,a=this._freqs[c]*(1-a)+this._freqs[c+1]*a);this.setOutputData(0,a/255*this.properties.amplitude)}}; +H.prototype.onGetInputs=function(){return[["band","number"]]};H.title="Signal";H.desc="extract the signal of some frequency";k.registerNodeType("audio/signal",H);z.prototype.onAdded=function(c){c.status==LGraph.STATUS_RUNNING&&(this.audionode.onaudioprocess=this._callback)};z["@code"]={widget:"code",type:"code"};z.prototype.onStart=function(){this.audionode.onaudioprocess=this._callback};z.prototype.onStop=function(){this.audionode.onaudioprocess=z._bypass_function};z.prototype.onPause=function(){this.audionode.onaudioprocess= +z._bypass_function};z.prototype.onUnpause=function(){this.audionode.onaudioprocess=this._callback};z.prototype.onExecute=function(){};z.prototype.onRemoved=function(){this.audionode.onaudioprocess=z._bypass_function};z.prototype.processCode=function(){try{this._script=new (new Function("properties",this.properties.code))(this.properties),this._old_code=this.properties.code,this._callback=this._script.onaudioprocess}catch(q){console.error("Error in onaudioprocess code",q),this._callback=z._bypass_function, +this.audionode.onaudioprocess=this._callback}};z.prototype.onPropertyChanged=function(c,a){"code"==c&&(this.properties.code=a,this.processCode(),this.graph&&this.graph.status==LGraph.STATUS_RUNNING&&(this.audionode.onaudioprocess=this._callback))};z.default_function=function(){this.onaudioprocess=function(c){var a=c.inputBuffer;c=c.outputBuffer;for(var b=0;bt&&(t=Math.max(0,r+t));if(null==h||h>r)h=r;h=Number(h);0>h&&(h=Math.max(0,r+h));for(t=Number(t||0);t=w}},"es6","es3");$jscomp.findInternal=function(v,n,t){v instanceof String&&(v=String(v));for(var h=v.length,r=0;ra&&db?!0:!1}function y(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||cm.width-l.width-10&&(e=m.width-l.width-10),m.height&&a>m.height-l.height-10&&(a=m.height-l.height-10));k.style.left=e+"px";k.style.top=a+"px";b.scale&&(k.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 f=v.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,INPUT:1,OUTPUT:2, -EVENT:-1,ACTION:-1,ALWAYS:0,ON_EVENT:1,NEVER:2,ON_TRIGGER:3,UP:1,DOWN:2,LEFT:3,RIGHT:4,CENTER:5,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,pointerevents_method:"pointer",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 h.prototype)b.prototype[e]||(b.prototype[e]=h.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 k=b.supported_extensions[e];k&&k.constructor===String&& -(this.node_types_by_file_extension[k.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;em&&(m=e.size[0]),l+=e.size[1]+a+f.NODE_TITLE_HEIGHT;b+=m+a}this.setDirtyCanvas(!0,!0)};n.prototype.getTime=function(){return this.globaltime};n.prototype.getFixedTime=function(){return this.fixedtime};n.prototype.getElapsedTime=function(){return this.elapsed_time}; -n.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,k=d.length;e=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_idt&&(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=z}},"es6","es3"); +$jscomp.findInternal=function(x,m,t){x instanceof String&&(x=String(x));for(var l=x.length,w=0;wa&&eb?!0:!1}function A(a,b){var c=a[0]+a[2],e=a[1]+a[3],d=b[1]+b[3];return a[0]>b[0]+b[2]||a[1]>d||c +k.width-n.width-10&&(d=k.width-n.width-10),k.height&&a>k.height-n.height-10&&(a=k.height-n.height-10));g.style.left=d+"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, +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"; +b.type=a;f.debug&&console.log("Node registered: "+a);a.split("/");var c=b.name,e=a.lastIndexOf("/");b.category=a.substr(0,e);b.title||(b.title=c);if(b.prototype)for(var d in l.prototype)b.prototype[d]||(b.prototype[d]=l.prototype[d]);if(e=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(d in b.supported_extensions){var g=b.supported_extensions[d];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(e&&f.onNodeTypeReplaced)f.onNodeTypeReplaced(a,b,e);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(d=0;dk&&(k=d.size[0]),n+=d.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 e=this._nodes_in_order?this._nodes_in_order:this._nodes;if(e)for(var d=0,g=e.length;d=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_ida.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={}};h.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;ca.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.outputs.length)){var c=this.outputs[a];if(c&&(c._data=b,this.outputs[a].links))for(c=0;c=this.outputs.length)){var c=this.outputs[a];if(c&&(c.type=b,this.outputs[a].links))for(c=0;c=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}};h.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};h.prototype.getInputDataByName=function(a,b){a=this.findInputSlot(a);return-1==a?null:this.getInputData(a, -b)};h.prototype.isInputConnected=function(a){return 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};h.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=this.outputs.length?null:this.outputs[a]._data};h.prototype.getOutputInfo=function(a){return this.outputs? -a=this.outputs.length)return null;a=this.outputs[a]; -if(!a.links||0==a.links.length)return null;for(var b=[],c=0;ca&&this.pos[1]-e-cb)return!0;return!1};h.prototype.getSlotInPosition=function(a,b){var c=new Float32Array(2);if(this.inputs)for(var d=0,e=this.inputs.length;d=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)return null;if(!b.inputs||c>=b.inputs.length)return f.debug&&console.log("Connect: Error, slot number not found"),null}var d=!1;null!=b.inputs[c].link&&(this.graph.beforeChange(),b.disconnectInput(c),d=!0);var e=this.outputs[a];if(b.onConnectInput&& -!1===b.onConnectInput(c,e.type,e,this,a))return null;var k=b.inputs[c],m=null;if(!f.isValidConnection(e.type,k.type))return this.setDirtyCanvas(!1,!0),d&&this.graph.connectionChange(this,m),null;d||this.graph.beforeChange();m=new t(++this.graph.last_link_id,k.type,this.id,a,b.id,c);this.graph.links[m.id]=m;null==e.links&&(e.links=[]);e.links.push(m.id);b.inputs[c].link=m.id;this.graph&&this.graph._version++;if(this.onConnectionsChange)this.onConnectionsChange(f.OUTPUT,a,!0,m,e);if(b.onConnectionsChange)b.onConnectionsChange(f.INPUT, -c,!0,m,k);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,m);return m};h.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=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 k=e.outputs[d.origin_slot];if(!k||!k.links||0==k.links.length)return!1;for(var m=0,l=k.links.length;mb&&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};h.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)};h.prototype.trace=function(a){this.console||(this.console=[]);this.console.push(a);this.console.length>h.MAX_CONSOLE&&this.console.shift();if(this.graph.onNodeTrace)this.graph.onNodeTrace(this, -a)};h.prototype.setDirtyCanvas=function(a,b){this.graph&&this.graph.sendActionToCanvas("setDirty",[a,b])};h.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};h.prototype.captureInput=function(a){if(this.graph&&this.graph.list_of_graphcanvas)for(var b=this.graph.list_of_graphcanvas,c=0;ca.length||(this._pos[0]=a[0],this._pos[1]=a[1])},get:function(){return this._pos},enumerable:!0});Object.defineProperty(this,"size",{set:function(a){!a||2>a.length||(this._size[0]=Math.max(140,a[0]),this._size[1]=Math.max(80,a[1]))},get:function(){return this._size}, -enumerable:!0})};r.prototype.configure=function(a){this.title=a.title;this._bounding.set(a.bounding);this.color=a.color;this.font=a.font};r.prototype.serialize=function(){var a=this._bounding;return{title:this.title,bounding:[Math.round(a[0]),Math.round(a[1]),Math.round(a[2]),Math.round(a[3])],color:this.color,font:this.font}};r.prototype.move=function(a,b,c){this._pos[0]+=a;this._pos[1]+=b;if(!c)for(c=0;c=this.viewport[0]&&d=this.viewport[1]&&cthis.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)}};w.prototype.changeDeltaScale=function(a,b){this.changeScale(this.scale*a,b)};w.prototype.reset=function(){this.scale= -1;this.offset[0]=0;this.offset[1]=0};v.LGraphCanvas=f.LGraphCanvas=g;g.DEFAULT_BACKGROUND_IMAGE="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQBJREFUeNrs1rEKwjAUhlETUkj3vP9rdmr1Ysammk2w5wdxuLgcMHyptfawuZX4pJSWZTnfnu/lnIe/jNNxHHGNn//HNbbv+4dr6V+11uF527arU7+u63qfa/bnmh8sWLBgwYJlqRf8MEptXPBXJXa37BSl3ixYsGDBMliwFLyCV/DeLIMFCxYsWLBMwSt4Be/NggXLYMGCBUvBK3iNruC9WbBgwYJlsGApeAWv4L1ZBgsWLFiwYJmCV/AK3psFC5bBggULloJX8BpdwXuzYMGCBctgwVLwCl7Be7MMFixYsGDBsu8FH1FaSmExVfAxBa/gvVmwYMGCZbBg/W4vAQYA5tRF9QYlv/QAAAAASUVORK5CYII="; -g.link_type_colors={"-1":f.EVENT_LINK_COLOR,number:"#AAA",node:"#DCA"};g.gradients={};g.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()};g.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)))};g.prototype.getTopGraph=function(){return this._graph_stack.length?this._graph_stack[0]:this.graph};g.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)};g.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}};g.prototype.getCurrentGraph=function(){return this.graph};g.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 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()}};g.prototype._doNothing=function(a){a.preventDefault();return!1};g.prototype._doReturnTrue=function(a){a.preventDefault(); -return!0};g.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, +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=this.outputs.length)){var c=this.outputs[a];if(c&&(c._data=b,this.outputs[a].links))for(c=0;c=this.outputs.length)){var c=this.outputs[a];if(c&&(c.type=b,this.outputs[a].links))for(c=0;c=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)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=this.outputs.length?null:this.outputs[a]._data};l.prototype.getOutputInfo=function(a){return this.outputs? +a=this.outputs.length)return null;a=this.outputs[a]; +if(!a.links||0==a.links.length)return null;for(var b=[],c=0;ca&&this.pos[1]-d-cb)return!0;return!1};l.prototype.getSlotInPosition= +function(a,b){var c=new Float32Array(2);if(this.inputs)for(var e=0,d=this.inputs.length;e=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 e=b.inputs[c],d=this.outputs[a];if(!this.outputs[a])return null;b.onBeforeConnectInput&&(c=b.onBeforeConnectInput(c));if(!1===c||null===c||!f.isValidConnection(d.type,e.type))return this.setDirtyCanvas(!1,!0),null;if(b.onConnectInput&&!1===b.onConnectInput(c,d.type,d,this,a)|| +this.onConnectOutput&&!1===this.onConnectOutput(a,e.type,e,b,c))return null;b.inputs[c]&&null!=b.inputs[c].link&&(this.graph.beforeChange(),b.disconnectInput(c,{doProcessChange:!1}));if(null!==d.links&&d.links.length)switch(d.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,e.type||d.type,this.id,a,b.id,c);this.graph.links[g.id]=g;null==d.links&&(d.links=[]);d.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,d);if(b.onConnectionsChange)b.onConnectionsChange(f.INPUT,c,!0,g,e);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 e=0,d=c.links.length;e=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 e=this.graph.links[c];if(e){var d=this.graph.getNodeById(e.origin_id);if(!d)return!1;var g=d.outputs[e.origin_slot];if(!g||!g.links||0==g.links.length)return!1;for(var k=0,n=g.links.length;kb&&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&&e>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]/e*(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]+d:this.pos[0]+this.size[0]+1-d;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;ca.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.viewport[0]&&e=this.viewport[1]&&cthis.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 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, !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}};g.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}};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.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")}; -g.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()};g.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};g.prototype.setDirty=function(a,b){a&&(this.dirty_canvas=!0);b&&(this.dirty_bgcanvas=!0)};g.prototype.getCanvasWindow=function(){if(!this.canvas)return window;var a=this.canvas.ownerDocument; -return a.defaultView||a.parentWindow};g.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))};g.prototype.stopRendering=function(){this.is_rendering=!1};g.prototype.blockClick=function(){this.block_click=!0;this.last_mouseclick=0};g.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();g.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[1]&&ef.getTime()-this.last_mouseclick&&void 0!==a.isPrimary&&a.isPrimary;this.mouse[0]=a.clientX;this.mouse[1]=a.clientY;this.graph_mouse[0]=a.canvasX;this.graph_mouse[1]=a.canvasY;this.last_click_position=[this.mouse[0],this.mouse[1]];this.pointer_is_double=this.pointer_is_down&&void 0!==a.isPrimary&&!a.isPrimary?!0:!1;this.pointer_is_down=!0;this.canvas.focus();f.closeAllContextMenus(b); -if(!this.onMouse||1!=this.onMouse(a)){if(1!=a.which||this.pointer_is_double)2==a.which||3!=a.which&&!this.pointer_is_double||this.read_only||this.processContextMenu(k,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,e=!0);var m=!1;if(k&&this.allow_interaction&&!e&&!this.read_only){this.live_mode||k.flags.pinned||this.bringToFront(k);if(!this.connecting_node&& -!k.flags.collapsed&&!this.live_mode)if(!e&&!1!==k.resizable&&A(a.canvasX,a.canvasY,k.pos[0]+k.size[0]-5,k.pos[1]+k.size[1]-5,10,10))this.graph.beforeChange(),this.resizing_node=k,this.canvas.style.cursor="se-resize",e=!0;else{if(k.outputs)for(var l=0,q=k.outputs.length;lk.size[0]-f.NODE_TITLE_HEIGHT&&0>q[1]&&(c=this,setTimeout(function(){c.openSubgraph(k.subgraph)},10)),this.live_mode&&(l=m=!0));l||(this.allow_dragnodes&&(this.graph.beforeChange(),this.node_dragged=k),this.selected_nodes[k.id]||this.processNodeSelected(k,a));this.dirty_canvas=!0}}else{if(!this.read_only)for(l=0;lq[0]+4||a.canvasYq[1]+4)){this.showLinkMenu(m,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>B([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());d&&!this.read_only&& -this.allow_searchbox&&this.showSearchBox(a);m=!0}!e&&m&&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}}}};g.prototype.processMouseMove= -function(a){this.autoresize&&this.resize();this.set_canvas_dirty_on_mouse_event&&(this.dirty_canvas=!0);if(this.graph){g.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;bm[0]+4||a.canvasY -m[1]+4)){e=k;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}};g.prototype.processMouseUp=function(a){if(void 0!==a.isPrimary&&!a.isPrimary)return!1;this.set_canvas_dirty_on_mouse_event&& -(this.dirty_canvas=!0);if(this.graph){var b=this.getCanvasWindow().document;g.active_canvas=this;this.options.skip_events||(f.pointerListenerRemove(b,"move",this._mousemove_callback,!0),f.pointerListenerAdd(this.canvas,"move",this._mousemove_callback,!0),f.pointerListenerRemove(b,"up",this._mouseup_callback,!0));this.adjustMouseEvent(a);b=f.getTime();a.click_time=b-this.last_mouseclick;this.last_mouse_dragging=!1;this.last_click_position=null;this.block_click&&(this.block_click=!1);if(1==a.which)if(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,this.dragging_rectangle){if(this.graph){b=this.graph._nodes;var c=new Float32Array(4);this.deselectAllNodes();var d=Math.abs(this.dragging_rectangle[2]),e=Math.abs(this.dragging_rectangle[3]),k=0>this.dragging_rectangle[3]?this.dragging_rectangle[1]-e:this.dragging_rectangle[1];this.dragging_rectangle[0]=0>this.dragging_rectangle[2]?this.dragging_rectangle[0]-d:this.dragging_rectangle[0];this.dragging_rectangle[1]=k;this.dragging_rectangle[2]=d;this.dragging_rectangle[3]=e;e=[];for(k=0;ka.click_time&&A(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);void 0!==a.isPrimary&&a.isPrimary&&(this.pointer_is_double=this.pointer_is_down=!1);this.graph.change();a.stopPropagation();a.preventDefault();return!1}};g.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[1]&&db&&(c*=1/1.1),this.ds.changeScale(c,[a.clientX,a.clientY]),this.graph.change(),a.preventDefault(),!1}};g.prototype.isOverNodeBox=function(a,b,c){var d=f.NODE_TITLE_HEIGHT;return A(b,c,a.pos[0]+2,a.pos[1]+2-d,d-4,d-4)?!0:!1};g.prototype.isOverNodeInput=function(a,b,c,d){if(a.inputs)for(var e=0,k=a.inputs.length;e=this.viewport[0]&&b=this.viewport[1]&&cc-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}};g.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.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&&.5this.ds.scale;if(this.live_mode){if(!a.flags.collapsed&&(b.shadowColor="transparent",a.onDrawForeground))a.onDrawForeground(b,this,this.canvas)}else{var k= -this.editor_alpha;b.globalAlpha=k;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 m=a._shape||f.BOX_SHAPE;G.set(a.size);var l=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*f.NODE_TITLE_HEIGHT),G[0]=a._collapsed_width,G[1]=0)}a.clip_area&&(b.save(),b.beginPath(),m==f.BOX_SHAPE?b.rect(0,0,G[0],G[1]):m==f.ROUND_SHAPE?b.roundRect(0,0,G[0],G[1],[10]):m==f.CIRCLE_SHAPE&&b.arc(.5*G[0],.5*G[1],.5*G[0],0,2*Math.PI),b.clip());a.has_errors&&(d="red");this.drawNodeShape(a,b,G,c,d,a.is_selected,a.mouseOver);b.shadowColor="transparent";if(a.onDrawForeground)a.onDrawForeground(b,this,this.canvas);b.textAlign=l?"center":"left";b.font=this.inner_text_font;d=!e;m=this.connecting_output; -b.lineWidth=1;q=0;var u=new Float32Array(2);if(!a.flags.collapsed){if(a.inputs)for(c=0;cthis.ds.scale,q=a._shape||a.constructor.shape||f.ROUND_SHAPE,u=a.constructor.title_mode,h=!0;u==f.TRANSPARENT_TITLE||u==f.NO_TITLE?h=!1:u==f.AUTOHIDE_TITLE&&m&&(h=!0);z[0]= -0;z[1]=h?-e:0;z[2]=c[0]+1;z[3]=h?c[1]+e:c[1];m=b.globalAlpha;b.beginPath();q==f.BOX_SHAPE||l?b.fillRect(z[0],z[1],z[2],z[3]):q==f.ROUND_SHAPE||q==f.CARD_SHAPE?b.roundRect(z[0],z[1],z[2],z[3],q==f.CARD_SHAPE?[this.round_radius,this.round_radius,0,0]:[this.round_radius]):q==f.CIRCLE_SHAPE&&b.arc(.5*c[0],.5*c[1],.5*c[0],0,2*Math.PI);b.fill();!a.flags.collapsed&&h&&(b.shadowColor="transparent",b.fillStyle="rgba(0,0,0,0.2)",b.fillRect(0,-1,z[2],2));b.shadowColor="transparent";if(a.onDrawBackground)a.onDrawBackground(b, -this,this.canvas,this.graph_mouse);if(h||u==f.TRANSPARENT_TITLE){if(a.onDrawTitleBar)a.onDrawTitleBar(b,e,c,this.ds.scale,d);else if(u!=f.TRANSPARENT_TITLE&&(a.constructor.title_color||this.render_title_colored)){h=a.constructor.title_color||d;a.flags.collapsed&&(b.shadowColor=f.DEFAULT_SHADOW_COLOR);if(this.use_gradients){var p=g.gradients[h];p||(p=g.gradients[h]=b.createLinearGradient(0,0,400,0),p.addColorStop(0,h),p.addColorStop(1,"#000"));b.fillStyle=p}else b.fillStyle=h;b.beginPath();q==f.BOX_SHAPE|| -l?b.rect(0,-e,c[0]+1,e):(q==f.ROUND_SHAPE||q==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"}if(a.onDrawTitleBox)a.onDrawTitleBox(b,e,c,this.ds.scale);else q==f.ROUND_SHAPE||q==f.CIRCLE_SHAPE||q==f.CARD_SHAPE?(l&&(b.fillStyle="black",b.beginPath(),b.arc(.5*e,-.5*e,6,0,2*Math.PI),b.fill()),b.fillStyle=a.boxcolor||f.NODE_DEFAULT_BOXCOLOR,l?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())):(l&&(b.fillStyle="black",b.fillRect(.5*(e-10)-1,-.5*(e+10)-1,12,12)),b.fillStyle=a.boxcolor||f.NODE_DEFAULT_BOXCOLOR,b.fillRect(.5*(e-10),-.5*(e+10),10,10));b.globalAlpha=m;if(a.onDrawTitleText)a.onDrawTitleText(b,e,c,this.ds.scale,this.title_text_font,k);!l&&(b.font=this.title_text_font,m=String(a.getTitle()))&&(b.fillStyle=k?f.NODE_SELECTED_TITLE_COLOR:a.constructor.title_text_color||this.node_title_color,a.flags.collapsed?(b.textAlign="left",b.measureText(m),b.fillText(m.substr(0, -20),e,f.NODE_TITLE_TEXT_Y-e),b.textAlign="left"):(b.textAlign="left",b.fillText(m,e,f.NODE_TITLE_TEXT_Y-e)));a.flags.collapsed||!a.subgraph||a.skip_subgraph_button||(m=f.NODE_TITLE_HEIGHT,h=a.size[0]-m,p=f.isInsideRectangle(this.graph_mouse[0]-a.pos[0],this.graph_mouse[1]-a.pos[1],h+2,-m+2,m-4,m-4),b.fillStyle=p?"#888":"#555",q==f.BOX_SHAPE||l?b.fillRect(h+2,-m+2,m-4,m-4):(b.beginPath(),b.roundRect(h+2,-m+2,m-4,m-4,[4]),b.fill()),b.fillStyle="#333",b.beginPath(),b.moveTo(h+.2*m,.6*-m),b.lineTo(h+ -.8*m,.6*-m),b.lineTo(h+.5*m,.3*-m),b.fill());if(a.onDrawTitle)a.onDrawTitle(b)}if(k){if(a.onBounding)a.onBounding(z);u==f.TRANSPARENT_TITLE&&(z[1]-=e,z[3]+=e);b.lineWidth=1;b.globalAlpha=.8;b.beginPath();q==f.BOX_SHAPE?b.rect(-6+z[0],-6+z[1],12+z[2],12+z[3]):q==f.ROUND_SHAPE||q==f.CARD_SHAPE&&a.flags.collapsed?b.roundRect(-6+z[0],-6+z[1],12+z[2],12+z[3],[2*this.round_radius]):q==f.CARD_SHAPE?b.roundRect(-6+z[0],-6+z[1],12+z[2],12+z[3],[2*this.round_radius,2,2*this.round_radius,2]):q==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}};var I=new Float32Array(4),D=new Float32Array(4),H=new Float32Array(2),F=new Float32Array(2);g.prototype.drawConnections=function(a){var b=f.getTime(),c=this.visible_area;I[0]=c[0]-20;I[1]=c[1]-20;I[2]=c[2]+40;I[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 k=c[d];if(k.inputs&&k.inputs.length)for(var m=0;mD[2]&&(D[0]+=D[2],D[2]=Math.abs(D[2]));0>D[3]&&(D[1]+=D[3],D[3]=Math.abs(D[3]));if(y(D,I)){var x=q.outputs[u];u=k.inputs[m];if(x&& -u&&(q=x.dir||(q.horizontal?f.DOWN:f.RIGHT),u=u.dir||(k.horizontal?f.UP:f.LEFT),this.renderLink(a,g,p,l,!1,0,null,q,u),l&&l._last_time&&1E3>b-l._last_time)){x=2-.002*(b-l._last_time);var h=a.globalAlpha;a.globalAlpha=h*x;this.renderLink(a,g,p,l,!0,x,"white",q,u);a.globalAlpha=h}}}}}}a.globalAlpha=1};g.prototype.renderLink=function(a,b,c,d,e,k,m,l,q,u){d&&this.visible_links.push(d);!m&&d&&(m=d.color||g.link_type_colors[d.type]);m||(m=this.default_link_color);null!=d&&this.highlighted_links[d.id]&&(m= -"#FFF");l=l||f.RIGHT;q=q||f.LEFT;var h=B(b,c);this.render_connections_border&&.6b[1]?0:Math.PI,a.save(),a.translate(p[0],p[1]),a.rotate(h),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(u),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(k)for(a.fillStyle=m,p=0;5>p;++p)k=(.001*f.getTime()+.2*p)%1,e=this.computeConnectionPoint(b,c,k,l,q),a.beginPath(),a.arc(e[0],e[1],5,0,2*Math.PI),a.fill()};g.prototype.computeConnectionPoint=function(a,b,c,d,e){d=d||f.RIGHT;e=e||f.LEFT;var k=B(a,b),m=[a[0],a[1]],l=[b[0],b[1]];switch(d){case f.LEFT:m[0]+=-.25*k;break;case f.RIGHT:m[0]+=.25*k;break;case f.UP:m[1]+=-.25*k;break;case f.DOWN:m[1]+=.25*k}switch(e){case f.LEFT:l[0]+= --.25*k;break;case f.RIGHT:l[0]+=.25*k;break;case f.UP:l[1]+=-.25*k;break;case f.DOWN:l[1]+=.25*k}d=(1-c)*(1-c)*(1-c);e=3*(1-c)*(1-c)*c;k=3*(1-c)*c*c;c*=c*c;return[d*a[0]+e*m[0]+k*l[0]+c*b[0],d*a[1]+e*m[1]+k*l[1]+c*b[1]]};g.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;ck||k>h-12||mp.last_y+x||void 0===p.last_y)){d=p.value;switch(p.type){case "button":c.type===f.pointerevents_method+"down"&&(p.callback&&setTimeout(function(){p.callback(p,q,a,b,c)},20),this.dirty_canvas=p.clicked=!0);break;case "slider":u=Math.clamp((k-15)/(h-30),0,1);p.value=p.options.min+(p.options.max-p.options.min)*u;p.callback&&setTimeout(function(){e(p,p.value)},20);this.dirty_canvas=!0;break;case "number":case "combo":d= -p.value;if(c.type==f.pointerevents_method+"move"&&"number"==p.type)p.value+=.1*c.deltaX*(p.options.step||1),null!=p.options.min&&p.valuep.options.max&&(p.value=p.options.max);else if(c.type==f.pointerevents_method+"down"){var r=p.options.values;r&&r.constructor===Function&&(r=p.options.values(p,a));var n=null;"number"!=p.type&&(n=r.constructor===Array?r:Object.keys(r));k=40>k?-1:k>h-40?1:0;if("number"==p.type)p.value+=.1*k*(p.options.step|| -1),null!=p.options.min&&p.valuep.options.max&&(p.value=p.options.max);else if(k)u=-1,this.last_mouseclick=0,u=r.constructor===Object?n.indexOf(String(p.value))+k:n.indexOf(p.value)+k,u>=n.length&&(u=n.length-1),0>u&&(u=0),p.value=r.constructor===Array?r[u]:u;else{var t=r!=n?Object.values(r):r;new f.ContextMenu(t,{scale:Math.max(1,this.ds.scale),event:c,className:"dark",callback:function(a,b,c){r!=n&&(a=t.indexOf(a));this.value=a; -e(this,a);q.dirty_canvas=!0;return!1}.bind(p)},u)}}else c.type==f.pointerevents_method+"up"&&"number"==p.type&&(k=40>k?-1:k>h-40?1:0,200>c.click_time&&0==k&&this.prompt("Value",p.value,function(a){this.value=Number(a);e(this,this.value)}.bind(p),c));d!=p.value&&setTimeout(function(){e(this,this.value)}.bind(p),20);this.dirty_canvas=!0;break;case "toggle":c.type==f.pointerevents_method+"down"&&(p.value=!p.value,setTimeout(function(){e(p,p.value)},20));break;case "string":case "text":c.type==f.pointerevents_method+ -"down"&&this.prompt("Value",p.value,function(a){this.value=a;e(this,a)}.bind(p),c,p.options?p.options.multiline:!1);break;default:p.mouse&&(this.dirty_canvas=p.mouse(c,[k,m],a))}if(d!=p.value){if(a.onWidgetChanged)a.onWidgetChanged(p.name,p.value,d,p);a.graph._version++}return p}}}return null};g.prototype.drawGroups=function(a,b){if(this.graph){a=this.graph._groups;b.save();b.globalAlpha=.5*this.editor_alpha;for(var c=0;cc&&.01>b.editor_alpha&&(clearInterval(d),1>c&&(b.live_mode=!0));1"+(q.label?q.label:l)+""+a+"", -value:l})}if(m.length)return new f.ContextMenu(m,{event:c,callback:function(a,b,c,d){e&&(b=this.getBoundingClientRect(),k.showEditPropertyValue(e,a.value,{position:[b.left,b.top]}))},parentMenu:d,allow_html:!0,node:e},b),!1}};g.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};g.onResizeNode=function(a,b,c,d,e){if(e){e.size=e.computeSize();if(e.onResize)e.onResize(e.size);e.setDirtyCanvas(!0,!0)}};g.prototype.showLinkMenu=function(a,b){var c=this;console.log(a); -var d=new f.ContextMenu(["Add Node",null,"Delete"],{event:b,title:null!=a.data?a.data.constructor.name:null,callback:function(b,f,m){switch(b){case "Add Node":g.onMenuAdd(null,null,m,d,function(b){console.log("node autoconnect");var d=c.graph.getNodeById(a.origin_id),e=c.graph.getNodeById(a.target_id);b.inputs&&b.inputs.length&&b.outputs&&b.outputs.length&&d.outputs[a.origin_slot].type==b.inputs[0].type&&b.outputs[0].type==e.inputs[0].type&&(d.connect(a.origin_slot,b,0),b.connect(0,e,a.target_slot), -b.pos[0]-=.5*b.size[0])});break;case "Delete":c.graph.removeLink(a.id)}}});return!1};g.onShowPropertyEditor=function(a,b,c,d,e){function f(){var b=q.value;"Number"==a.type?b=Number(b):"Boolean"==a.type&&(b=!!b);e[m]=b;l.parentNode&&l.parentNode.removeChild(l);e.setDirtyCanvas(!0,!0)}var m=a.property||"title";b=e[m];var l=document.createElement("div");l.className="graphdialog";l.innerHTML="";l.querySelector(".name").innerText= -m;var q=l.querySelector(".value");q&&(q.value=b,q.addEventListener("blur",function(a){this.focus()}),q.addEventListener("keydown",function(a){if(13==a.keyCode||"textarea"==a.target.localName)f(),a.preventDefault(),a.stopPropagation()}));b=g.active_canvas.canvas;c=b.getBoundingClientRect();var u=d=-20;c&&(d-=c.left,u-=c.top);event?(l.style.left=event.clientX+d+"px",l.style.top=event.clientY+u+"px"):(l.style.left=.5*b.width+d+"px",l.style.top=.5*b.height+u+"px");l.querySelector("button").addEventListener("click", -f);b.parentNode.appendChild(l)};g.prototype.prompt=function(a,b,c,d,e){var k=this;a=a||"";var m=!1,l=document.createElement("div");l.className="graphdialog rounded";l.innerHTML=e?" ":" ";l.close=function(){k.prompt_box=null;l.parentNode&&l.parentNode.removeChild(l)};1g.search_limit)break}}u=null;if(Array.prototype.filter)u=Object.keys(f.registered_node_types).filter(d);else for(q in u=[],f.registered_node_types)d(q)&&u.push(q);for(q=0;qg.search_limit);q++);}}var e=this,k=g.active_canvas,m=k.canvas,l=m.ownerDocument||document,q=document.createElement("div");q.className="litegraph litesearchbox graphdialog rounded";q.innerHTML="Search
"; -q.close=function(){e.search_box=null;l.body.focus();l.body.style.overflow="";setTimeout(function(){e.canvas.focus()},20);q.parentNode&&q.parentNode.removeChild(q)};var u=null;1m.height-200&&(h.style.maxHeight=m.height-a.layerY-20+"px");n.focus();return q};g.prototype.showEditPropertyValue=function(a,b,c){function d(){e(p.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"==m||"object"==m)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();h.close();a.setDirtyCanvas(!0,!0)}if(a&&void 0!==a.properties[b]){c=c||{};var f=a.getPropertyInfo(b),m=f.type,l="";if("string"==m||"number"==m||"array"==m||"object"==m)l="";else if("enum"!=m&&"combo"!=m||!f.values)if("boolean"==m)l="";else{console.warn("unknown type: "+m); -return}else{l=""}var h=this.createDialog(""+(f.label?f.label:b)+""+l+"",c);if("enum"!=m&&"combo"!=m||!f.values)if("boolean"==m)(p=h.querySelector("input"))&&p.addEventListener("click",function(a){e(!!p.checked)});else{if(p=h.querySelector("input"))p.addEventListener("blur", -function(a){this.focus()}),g=void 0!==a.properties[b]?a.properties[b]:"","string"!==m&&(g=JSON.stringify(g)),p.value=g,p.addEventListener("keydown",function(a){13==a.keyCode&&(d(),a.preventDefault(),a.stopPropagation())})}else{var p=h.querySelector("select");p.addEventListener("change",function(a){e(a.target.value)})}h.querySelector("button").addEventListener("click",d);return h}};g.prototype.createDialog=function(a,b){b=b||{};var c=document.createElement("div");c.className="graphdialog";c.innerHTML= -a;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);c.close=function(){this.parentNode&&this.parentNode.removeChild(this)};return c};g.prototype.createPanel=function(a,b){b=b||{};var c=b.window||window,d=document.createElement("div");d.className="litegraph dialog"; -d.innerHTML="
";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.footer=d.querySelector(".dialog-footer");d.close=function(){this.parentNode&&this.parentNode.removeChild(this)};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,m,l,q){function e(a,b){console.log("change",a,b);l.callback&&l.callback(a,b);q&&q(a,b)}l=l||{};var k=String(m);a=a.toLowerCase();"number"==a&&(k=m.toFixed(3));var h=document.createElement("div");h.className="property";h.innerHTML=""; -h.querySelector(".property_name").innerText=l.label||b;var x=h.querySelector(".property_value");x.innerText=k;h.dataset.property=b;h.dataset.type=l.type||a;h.options=l;h.value=m;if("boolean"==a)h.classList.add("boolean"),m&&h.classList.add("bool-on"),h.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)x.setAttribute("contenteditable", -!0),x.addEventListener("keydown",function(a){"Enter"==a.code&&(a.preventDefault(),this.blur())}),x.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)k=g.getPropertyPrintableValue(m,l.values),x.innerText=k,x.addEventListener("click",function(a){var b=this.parentNode.dataset.property,d=this;new f.ContextMenu(l.values||[],{event:a,className:"dark",callback:function(a, -c,f){d.innerText=a;e(b,a);return!1}},c)});d.content.appendChild(h);return h};return d};g.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+")"}};g.prototype.showShowNodePanel=function(a){window.SELECTED_NODE=a;var b=document.querySelector("#node-panel");b&&b.close();var c=this.getCanvasWindow();b=this.createPanel(a.title||"",{closable:!0,window:c});b.id="node-panel";b.node= -a;b.classList.add("settings");var d=this;(function(){b.content.innerHTML="";b.addHTML(""+a.type+""+(a.constructor.desc||"")+"");b.addHTML("

Properties

");for(var c in a.properties){var f=a.properties[c],m=a.getPropertyInfo(c);a.onAddPropertyToPanel&&a.onAddPropertyToPanel(c,b)||b.addWidget(m.widget||m.type,c,f,m,function(b,c){d.graph.beforeChange(a);a.setProperty(b,c);d.graph.afterChange();d.dirty_canvas= -!0})}b.addSeparator();if(a.onShowCustomPanelInfo)a.onShowCustomPanelInfo(b);b.addButton("Delete",function(){a.block_delete||(a.graph.remove(a),b.close())}).classList.add("delete")})();this.canvas.parentNode.appendChild(b)};g.prototype.showSubgraphPropertiesDialog=function(a){function b(){d.clear();if(a.inputs)for(var c=0;c", -"subgraph_property");m.dataset.name=f.name;m.dataset.slot=c;m.querySelector(".name").innerText=f.name;m.querySelector(".type").innerText=f.type;m.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(" + NameType","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};g.prototype.showSubgraphPropertiesDialogRight= -function(a){function b(){e.clear();if(a.outputs)for(var c=0;c","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(" + NameType", -"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};g.prototype.checkPanels=function(){if(this.canvas)for(var a=this.canvas.parentNode.querySelectorAll(".litegraph.dialog"),b=0;bNo color"});for(var k in g.node_colors)a=g.node_colors[k],a={value:k,content:""+k+""},b.push(a);new f.ContextMenu(b,{event:c,callback:function(a){e&&((a=a.value?g.node_colors[a.value]:null)?e.constructor===f.LGraphGroup?e.color=a.groupcolor:(e.color=a.color,e.bgcolor=a.bgcolor): -(delete e.color,delete e.bgcolor),e.setDirtyCanvas(!0,!0))},parentMenu:d,node:e});return!1};g.onMenuNodeShapes=function(a,b,c,d,e){if(!e)throw"no node passed";new f.ContextMenu(f.VALID_SHAPES,{event:c,callback:function(a){e&&(e.graph.beforeChange(e),e.shape=a,e.graph.afterChange(e),e.setDirtyCanvas(!0))},parentMenu:d,node:e});return!1};g.onMenuNodeRemove=function(a,b,c,d,e){if(!e)throw"no node passed";!1!==e.removable&&(a=e.graph,a.beforeChange(),a.remove(e),a.afterChange(),e.setDirtyCanvas(!0,!0))}; -g.onMenuNodeToSubgraph=function(a,b,c,d,e){a=e.graph;if(b=g.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)};g.onMenuNodeClone=function(a,b,c,d,e){0!=e.clonable&&(a=e.clone())&&(a.pos=[e.pos[0]+5,e.pos[1]+5],e.graph.beforeChange(),e.graph.add(a),e.graph.afterChange(),e.setDirtyCanvas(!0,!0))};g.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"}};g.prototype.getCanvasMenuOptions=function(){if(this.getMenuOptions)var a= -this.getMenuOptions();else a=[{content:"Add Node",has_submenu:!0,callback:g.onMenuAdd},{content:"Add Group",callback:g.onGroupAdd}],this._graph_stack&&0Name",d),k=q.querySelector("input");k&&f&&(k.value=f.label||"");q.querySelector("button").addEventListener("click",function(a){k.value&& -(f&&(f.label=k.value),c.setDirty(!0));q.close()})}},extra:a};a&&(k.title=a.type);var m=null;a&&(m=a.getSlotInPosition(b.canvasX,b.canvasY),g.active_node=a);m?(e=[],a.getSlotMenuOptions?e=a.getSlotMenuOptions(m):(m&&m.output&&m.output.links&&m.output.links.length&&e.push({content:"Disconnect Links",slot:m}),b=m.input||m.output,e.push(b.locked||!b.removable?"Cannot remove":{content:"Remove Slot",slot:m}),e.push(b.nameLocked?"Cannot rename":{content:"Rename Slot",slot:m})),k.title=(m.input?m.input.type: -m.output.type)||"*",m.input&&m.input.type==f.ACTION&&(k.title="Action"),m.output&&m.output.type==f.EVENT&&(k.title="Event")):a?e=this.getNodeMenuOptions(a):(e=this.getCanvasMenuOptions(),(m=this.graph.getGroupOnPos(b.canvasX,b.canvasY))&&e.push(null,{content:"Edit Group",has_submenu:!0,submenu:{title:"Group",extra:m,options:this.getGroupMenuOptions(m)}}));e&&new f.ContextMenu(e,k,d)};"undefined"!=typeof window&&window.CanvasRenderingContext2D&&!window.CanvasRenderingContext2D.prototype.roundRect&& -(window.CanvasRenderingContext2D.prototype.roundRect=function(a,b,c,d,e,f){var k,g;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 q=k=g=f=e[0];else if(2==e.length)q=f=e[0],k=g=e[1];else if(4==e.length)q=e[0],k=e[1],g=e[2],f=e[3];else return;else q=e||0,k=e||0,g=f||0,f=f||0;this.moveTo(a+q,b);this.lineTo(a+c-k,b);this.quadraticCurveTo(a+c,b,a+c,b+k);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-g);this.lineTo(a,b+g);this.quadraticCurveTo(a,b,a+q,b)}});f.compareObjects=function(a,b){for(var c in a)if(a[c]!=b[c])return!1;return!0};f.distance=B;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=A;f.growBounding=function(a,b,c){ba[2]&&(a[2]=b);ca[3]&&(a[3]=c)};f.isInsideBounding=function(a,b){return a[0]< -b[0][0]||a[1]b[1][0]||a[1]>b[1][1]?!1:!0};f.overlapBounding=y;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};C.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;k.current_submenu&&k.current_submenu.close(a);if(c.callback){var e=c.callback.call(this,b,c,a,k,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,k,c.extra),!0===e&&(d=!1)),b.submenu)){if(!b.submenu.options)throw"ContextMenu submenu needs options";new k.constructor(b.submenu.options,{callback:b.submenu.callback,event:a,parentMenu:k,ignore_item_callbacks:b.submenu.ignore_item_callbacks, -title:b.submenu.title,extra:b.submenu.extra,autoopen:c.autoopen});d=!1}d&&!k.lock&&k.close()}var k=this;c=c||{};var g=document.createElement("div");g.className="litemenu-entry submenu";var l=!1;if(null===b)g.classList.add("separator");else{g.innerHTML=b&&b.title?b.title:a;if(g.value=b)b.disabled&&(l=!0,g.classList.add("disabled")),(b.submenu||b.has_submenu)&&g.classList.add("has_submenu");"function"==typeof b?(g.dataset.value=a,g.onclick_callback=b):g.dataset.value=b;b.className&&(g.className+=" "+ -b.className)}this.root.appendChild(g);l||g.addEventListener("click",e);c.autoopen&&f.pointerListenerAdd(g,"enter",d);return g};C.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&&!C.isCursorOverElement(a,this.parentMenu.root)&&C.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)};C.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};C.prototype.getTopMenu=function(){return this.options.parentMenu?this.options.parentMenu.getTopMenu():this};C.prototype.getFirstEvent=function(){return this.options.parentMenu?this.options.parentMenu.getFirstEvent():this.options.event}; -C.isCursorOverElement=function(a,b){var c=a.clientX;a=a.clientY;return(b=b.getBoundingClientRect())?a>b.top&&ab.left&&cMath.abs(b))return d[1];a=(a-d[0])/b;return d[1]*(1- -a)+e[1]*a}}return 0}};E.prototype.draw=function(a,b,c,d,e,f){if(c=this.points){this.size=b;var k=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,k,b),a.fillStyle="#222",a.fillRect(.5*k,0,1,b),a.strokeStyle="#333",a.strokeRect(0,0,k,b));a.strokeStyle=e;f&&(a.globalAlpha=.5);a.beginPath();for(d=0;da[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],h=1E6,q=-1,u=0;uh||r>b||(q=u,h=r)}return q};f.CurveEditor=E;f.getParameterNames=function(a){return(a+"").replace(/[/][/].*$/gm,"").replace(/\s+/g, -"").replace(/[/][*][^/*]*[*][/]/g,"").split("){",1)[0].replace(/^[^(]*[(]/,"").replace(/=[^,]+/g,"").split(",").filter(Boolean)};f.pointerListenerAdd=function(a,b,c,d){d=void 0===d?!1:d;if(a&&a.addEventListener&&b&&"function"===typeof c)switch(b){case "down":case "up":case "move":case "over":case "out":case "enter":a.addEventListener(f.pointerevents_method+b,c,d);case "leave":case "cancel":case "gotpointercapture":case "lostpointercapture":if("mouse"!=f.pointerevents_method)return a.addEventListener(f.pointerevents_method+ -b,c,d);default:return a.addEventListener(b,c,d)}else console.log("cant pointerListenerAdd "+a+", "+b+", "+c)};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":a.removeEventListener(f.pointerevents_method+b,c,d);case "leave":case "cancel":case "gotpointercapture":case "lostpointercapture":if("mouse"!=f.pointerevents_method)return a.removeEventListener(f.pointerevents_method+ -b,c,d);default:return a.removeEventListener(b,c,d)}else console.log("cant pointerListenerRemove "+a+", "+b+", "+c)};Math.clamp=function(a,b,c){return b>a?b:ca&&(b[0]=this.viewport[0]&&e=this.viewport[1]&&df.getTime()-this.last_mouseclick&&void 0!==a.isPrimary&&a.isPrimary;this.mouse[0]=a.clientX;this.mouse[1]=a.clientY;this.graph_mouse[0]=a.canvasX;this.graph_mouse[1]=a.canvasY;this.last_click_position=[this.mouse[0],this.mouse[1]];this.pointer_is_double=this.pointer_is_down&&void 0!==a.isPrimary&&!a.isPrimary?!0:!1;this.pointer_is_down=!0;this.canvas.focus();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&&!e&&!this.read_only&&!this.connecting_node&&!g.flags.collapsed&&!this.live_mode){d=e=k=!1;if(g.outputs)for(u=0,n=g.outputs.length;ug.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(!e){if(!this.read_only)for(u= +0;un[0]+4||a.canvasYn[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());d&&!this.read_only&&this.allow_searchbox&&(this.showSearchBox(a),a.preventDefault(),a.stopPropagation());k=!0}!e&&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(), +!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 e=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes);b=0;for(var d=this.graph._nodes.length;b< +d;++b)if(this.graph._nodes[b].mouseOver&&e!=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(e){e.redraw_on_mouse&&(this.dirty_canvas=!0);if(!e.mouseOver&&(e.mouseOver=!0,this.node_over=e,this.dirty_canvas=!0,e.onMouseEnter))e.onMouseEnter(a);if(e.onMouseMove)e.onMouseMove(a,[a.canvasX-e.pos[0],a.canvasY-e.pos[1]],this);if(this.connecting_node)if(this.connecting_output){if(d= +this._highlight_input||[0,0],!this.isOverNodeBox(e,a.canvasX,a.canvasY)){var g=this.isOverNodeInput(e,a.canvasX,a.canvasY,d);if(-1!=g&&e.inputs[g]){var k=e.inputs[g].type;f.isValidConnection(this.connecting_output.type,k)&&(this._highlight_input=d,this._highlight_input_slot=e.inputs[g])}else this._highlight_input_slot=this._highlight_input=null}}else this.connecting_input&&(d=this._highlight_output||[0,0],this.isOverNodeBox(e,a.canvasX,a.canvasY)||(g=this.isOverNodeOutput(e,a.canvasX,a.canvasY,d), +-1!=g&&e.outputs[g]?(k=e.outputs[g].type,f.isValidConnection(this.connecting_input.type,k)&&(this._highlight_output=d)):this._highlight_output=null));this.canvas&&(C(a.canvasX,a.canvasY,e.pos[0]+e.size[0]-5,e.pos[1]+e.size[1]-5,5,5)?this.canvas.style.cursor="se-resize":this.canvas.style.cursor="crosshair")}else{d=null;for(b=0;bk[0]+4||a.canvasYk[1]+4)){d=g;break}d!=this.over_link_center&& +(this.over_link_center=d,this.dirty_canvas=!0);this.canvas&&(this.canvas.style.cursor="")}if(this.node_capturing_input&&this.node_capturing_input!=e&&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)e=this.selected_nodes[b],e.pos[0]+=c[0]/this.ds.scale,e.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){if(void 0!==a.isPrimary&&!a.isPrimary)return!1;this.set_canvas_dirty_on_mouse_event&&(this.dirty_canvas=!0);if(this.graph){var b= +this.getCanvasWindow().document;h.active_canvas=this;this.options.skip_events||(f.pointerListenerRemove(b,"move",this._mousemove_callback,!0),f.pointerListenerAdd(this.canvas,"move",this._mousemove_callback,!0),f.pointerListenerRemove(b,"up",this._mouseup_callback,!0));this.adjustMouseEvent(a);b=f.getTime();a.click_time=b-this.last_mouseclick;this.last_mouse_dragging=!1;this.last_click_position=null;this.block_click&&(this.block_click=!1);if(1==a.which){this.node_widget&&this.processNodeWidgets(this.node_widget[0], +this.graph_mouse,a);this.node_widget=null;this.selected_group&&(this.selected_group.move(this.selected_group.pos[0]-Math.round(this.selected_group.pos[0]),this.selected_group.pos[1]-Math.round(this.selected_group.pos[1]),a.ctrlKey),this.selected_group.pos[0]=Math.round(this.selected_group.pos[0]),this.selected_group.pos[1]=Math.round(this.selected_group.pos[1]),this.selected_group._nodes.length&&(this.dirty_canvas=!0),this.selected_group=null);this.selected_group_resizing=!1;var c=this.graph.getNodeOnPos(a.canvasX, +a.canvasY,this.visible_nodes);if(this.dragging_rectangle){if(this.graph){b=this.graph._nodes;var e=new Float32Array(4),d=Math.abs(this.dragging_rectangle[2]),g=Math.abs(this.dragging_rectangle[3]),k=0>this.dragging_rectangle[3]?this.dragging_rectangle[1]-g:this.dragging_rectangle[1];this.dragging_rectangle[0]=0>this.dragging_rectangle[2]?this.dragging_rectangle[0]-d:this.dragging_rectangle[0];this.dragging_rectangle[1]=k;this.dragging_rectangle[2]=d;this.dragging_rectangle[3]=g;if(!c||10a.click_time&&C(a.canvasX,a.canvasY,c.pos[0],c.pos[1]-f.NODE_TITLE_HEIGHT,f.NODE_TITLE_HEIGHT,f.NODE_TITLE_HEIGHT)&&c.collapse();this.dirty_bgcanvas=this.dirty_canvas=!0;this.node_dragged.pos[0]=Math.round(this.node_dragged.pos[0]);this.node_dragged.pos[1]=Math.round(this.node_dragged.pos[1]);(this.graph.config.align_to_grid||this.align_to_grid)&&this.node_dragged.alignToGrid();if(this.onNodeMoved)this.onNodeMoved(this.node_dragged); +this.graph.afterChange(this.node_dragged);this.node_dragged=null}else{c=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes);!c&&300>a.click_time&&this.deselectAllNodes();this.dirty_canvas=!0;this.dragging_canvas=!1;if(this.node_over&&this.node_over.onMouseUp)this.node_over.onMouseUp(a,[a.canvasX-this.node_over.pos[0],a.canvasY-this.node_over.pos[1]],this);if(this.node_capturing_input&&this.node_capturing_input.onMouseUp)this.node_capturing_input.onMouseUp(a,[a.canvasX-this.node_capturing_input.pos[0], +a.canvasY-this.node_capturing_input.pos[1]])}}else 2==a.which?(this.dirty_canvas=!0,this.dragging_canvas=!1):3==a.which&&(this.dirty_canvas=!0,this.dragging_canvas=!1);void 0!==a.isPrimary&&a.isPrimary&&(this.pointer_is_double=this.pointer_is_down=!1);this.graph.change();a.stopPropagation();a.preventDefault();return!1}};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,e=a.clientY; +if(!this.viewport||this.viewport&&c>=this.viewport[0]&&c=this.viewport[1]&&eb&&(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 e=f.NODE_TITLE_HEIGHT;return C(b,c,a.pos[0]+2,a.pos[1]+2-e,e-4,e-4)?!0:!1};h.prototype.isOverNodeInput=function(a,b,c,e){if(a.inputs)for(var d=0,g=a.inputs.length;da.nodes[e].pos[0]&&(b[0]=a.nodes[e].pos[0],c[0]=e),b[1]>a.nodes[e].pos[1]&&(b[1]=a.nodes[e].pos[1],c[1]=e)):(b=[a.nodes[e].pos[0],a.nodes[e].pos[1]],c=[e,e]);c=[];for(e=0;e=this.viewport[0]&&b=this.viewport[1]&&cc-this.graph._last_trigger_time)&&this.drawBackCanvas();(this.dirty_canvas||a)&&this.drawFrontCanvas();this.fps=this.render_time? +1/this.render_time:0;this.frame+=1}};h.prototype.drawFrontCanvas=function(){this.dirty_canvas=!1;this.ctx||(this.ctx=this.bgcanvas.getContext("2d"));var a=this.ctx;if(a){var b=this.canvas;a.start2D&&!this.viewport&&(a.start2D(),a.restore(),a.setTransform(1,0,0,1,0,0));var c=this.viewport||this.dirty_area;c&&(a.save(),a.beginPath(),a.rect(c[0],c[1],c[2],c[3]),a.clip());this.clear_background&&(c?a.clearRect(c[0],c[1],c[2],c[3]):a.clearRect(0,0,b.width,b.height));this.bgcanvas==this.canvas?this.drawBackCanvas(): +a.drawImage(this.bgcanvas,0,0);if(this.onRender)this.onRender(b,a);this.show_info&&this.renderInfo(a,c?c[0]:0,c?c[1]:0);if(this.graph){a.save();this.ds.toCanvasContext(a);b=this.computeVisibleNodes(null,this.visible_nodes);for(var e=0;e> ";b.fillText(e+c.getTitle(),.5*a.width,40);b.restore()}c=!1;this.onRenderBackground&&(c=this.onRenderBackground(a,b));this.viewport||(b.restore(),b.setTransform(1,0,0,1,0,0));this.visible_links.length=0;if(this.graph){b.save();this.ds.toCanvasContext(b);if(this.background_image&&.5this.ds.scale;if(this.live_mode){if(!a.flags.collapsed&&(b.shadowColor= +"transparent",a.onDrawForeground))a.onDrawForeground(b,this,this.canvas)}else{var g=this.editor_alpha;b.globalAlpha=g;this.render_shadows&&!d?(b.shadowColor=f.DEFAULT_SHADOW_COLOR,b.shadowOffsetX=2*this.ds.scale,b.shadowOffsetY=2*this.ds.scale,b.shadowBlur=3*this.ds.scale):b.shadowColor="transparent";if(!a.flags.collapsed||!a.onDrawCollapsed||1!=a.onDrawCollapsed(b,this)){var k=a._shape||f.BOX_SHAPE;I.set(a.size);var n=a.horizontal;if(a.flags.collapsed){b.font=this.inner_text_font;var p=a.getTitle? +a.getTitle():a.title;null!=p&&(a._collapsed_width=Math.min(a.size[0],b.measureText(p).width+2*f.NODE_TITLE_HEIGHT),I[0]=a._collapsed_width,I[1]=0)}a.clip_area&&(b.save(),b.beginPath(),k==f.BOX_SHAPE?b.rect(0,0,I[0],I[1]):k==f.ROUND_SHAPE?b.roundRect(0,0,I[0],I[1],[10]):k==f.CIRCLE_SHAPE&&b.arc(.5*I[0],.5*I[1],.5*I[0],0,2*Math.PI),b.clip());a.has_errors&&(e="red");this.drawNodeShape(a,b,I,c,e,a.is_selected,a.mouseOver);b.shadowColor="transparent";if(a.onDrawForeground)a.onDrawForeground(b,this,this.canvas); +b.textAlign=n?"center":"left";b.font=this.inner_text_font;e=!d;var r=this.connecting_output;k=this.connecting_input;b.lineWidth=1;p=0;var u=new Float32Array(2);if(!a.flags.collapsed){if(a.inputs)for(c=0;cthis.ds.scale,p=a._shape||a.constructor.shape||f.ROUND_SHAPE,r=a.constructor.title_mode,u=!0;r==f.TRANSPARENT_TITLE||r==f.NO_TITLE?u=!1:r==f.AUTOHIDE_TITLE&&k&&(u=!0);B[0]=0;B[1]=u?-d:0;B[2]=c[0]+1;B[3]=u?c[1]+d:c[1];k=b.globalAlpha;b.beginPath(); +p==f.BOX_SHAPE||n?b.fillRect(B[0],B[1],B[2],B[3]):p==f.ROUND_SHAPE||p==f.CARD_SHAPE?b.roundRect(B[0],B[1],B[2],B[3],p==f.CARD_SHAPE?[this.round_radius,this.round_radius,0,0]:[this.round_radius]):p==f.CIRCLE_SHAPE&&b.arc(.5*c[0],.5*c[1],.5*c[0],0,2*Math.PI);b.fill();!a.flags.collapsed&&u&&(b.shadowColor="transparent",b.fillStyle="rgba(0,0,0,0.2)",b.fillRect(0,-1,B[2],2));b.shadowColor="transparent";if(a.onDrawBackground)a.onDrawBackground(b,this,this.canvas,this.graph_mouse);if(u||r==f.TRANSPARENT_TITLE){if(a.onDrawTitleBar)a.onDrawTitleBar(b, +d,c,this.ds.scale,e);else if(r!=f.TRANSPARENT_TITLE&&(a.constructor.title_color||this.render_title_colored)){u=a.constructor.title_color||e;a.flags.collapsed&&(b.shadowColor=f.DEFAULT_SHADOW_COLOR);if(this.use_gradients){var q=h.gradients[u];q||(q=h.gradients[u]=b.createLinearGradient(0,0,400,0),q.addColorStop(0,u),q.addColorStop(1,"#000"));b.fillStyle=q}else b.fillStyle=u;b.beginPath();p==f.BOX_SHAPE||n?b.rect(0,-d,c[0]+1,d):(p==f.ROUND_SHAPE||p==f.CARD_SHAPE)&&b.roundRect(0,-d,c[0]+1,d,a.flags.collapsed? +[this.round_radius]:[this.round_radius,this.round_radius,0,0]);b.fill();b.shadowColor="transparent"}u=!1;f.node_box_coloured_by_mode&&f.NODE_MODES_COLORS[a.mode]&&(u=f.NODE_MODES_COLORS[a.mode]);f.node_box_coloured_when_on&&(u=a.action_triggered?"#FFF":a.execute_triggered?"#AAA":u);if(a.onDrawTitleBox)a.onDrawTitleBox(b,d,c,this.ds.scale);else p==f.ROUND_SHAPE||p==f.CIRCLE_SHAPE||p==f.CARD_SHAPE?(n&&(b.fillStyle="black",b.beginPath(),b.arc(.5*d,-.5*d,6,0,2*Math.PI),b.fill()),b.fillStyle=a.boxcolor|| +u||f.NODE_DEFAULT_BOXCOLOR,n?b.fillRect(.5*d-5,-.5*d-5,10,10):(b.beginPath(),b.arc(.5*d,-.5*d,5,0,2*Math.PI),b.fill())):(n&&(b.fillStyle="black",b.fillRect(.5*(d-10)-1,-.5*(d+10)-1,12,12)),b.fillStyle=a.boxcolor||u||f.NODE_DEFAULT_BOXCOLOR,b.fillRect(.5*(d-10),-.5*(d+10),10,10));b.globalAlpha=k;if(a.onDrawTitleText)a.onDrawTitleText(b,d,c,this.ds.scale,this.title_text_font,g);!n&&(b.font=this.title_text_font,k=String(a.getTitle()))&&(b.fillStyle=g?f.NODE_SELECTED_TITLE_COLOR:a.constructor.title_text_color|| +this.node_title_color,a.flags.collapsed?(b.textAlign="left",b.measureText(k),b.fillText(k.substr(0,20),d,f.NODE_TITLE_TEXT_Y-d),b.textAlign="left"):(b.textAlign="left",b.fillText(k,d,f.NODE_TITLE_TEXT_Y-d)));a.flags.collapsed||!a.subgraph||a.skip_subgraph_button||(k=f.NODE_TITLE_HEIGHT,u=a.size[0]-k,q=f.isInsideRectangle(this.graph_mouse[0]-a.pos[0],this.graph_mouse[1]-a.pos[1],u+2,-k+2,k-4,k-4),b.fillStyle=q?"#888":"#555",p==f.BOX_SHAPE||n?b.fillRect(u+2,-k+2,k-4,k-4):(b.beginPath(),b.roundRect(u+ +2,-k+2,k-4,k-4,[4]),b.fill()),b.fillStyle="#333",b.beginPath(),b.moveTo(u+.2*k,.6*-k),b.lineTo(u+.8*k,.6*-k),b.lineTo(u+.5*k,.3*-k),b.fill());if(a.onDrawTitle)a.onDrawTitle(b)}if(g){if(a.onBounding)a.onBounding(B);r==f.TRANSPARENT_TITLE&&(B[1]-=d,B[3]+=d);b.lineWidth=1;b.globalAlpha=.8;b.beginPath();p==f.BOX_SHAPE?b.rect(-6+B[0],-6+B[1],12+B[2],12+B[3]):p==f.ROUND_SHAPE||p==f.CARD_SHAPE&&a.flags.collapsed?b.roundRect(-6+B[0],-6+B[1],12+B[2],12+B[3],[2*this.round_radius]):p==f.CARD_SHAPE?b.roundRect(-6+ +B[0],-6+B[1],12+B[2],12+B[3],[2*this.round_radius,2,2*this.round_radius,2]):p==f.CIRCLE_SHAPE&&b.arc(.5*c[0],.5*c[1],.5*c[0]+6,0,2*Math.PI);b.strokeStyle=f.NODE_BOX_OUTLINE_COLOR;b.stroke();b.strokeStyle=e;b.globalAlpha=1}0F[2]&&(F[0]+=F[2],F[2]=Math.abs(F[2]));0>F[3]&&(F[1]+=F[3],F[3]=Math.abs(F[3]));if(A(F,K)){var y=p.outputs[r];r=g.inputs[k];if(y&&r&&(p=y.dir||(p.horizontal?f.DOWN:f.RIGHT),r=r.dir||(g.horizontal?f.UP:f.LEFT),this.renderLink(a,u,q,n,!1,0,null,p,r),n&&n._last_time&&1E3>b-n._last_time)){y=2-.002*(b-n._last_time);var h=a.globalAlpha;a.globalAlpha=h*y;this.renderLink(a,u,q,n,!0,y,"white",p,r);a.globalAlpha=h}}}}}}a.globalAlpha=1};h.prototype.renderLink= +function(a,b,c,e,d,g,k,n,p,r){e&&this.visible_links.push(e);!k&&e&&(k=e.color||h.link_type_colors[e.type]);k||(k=this.default_link_color);null!=e&&this.highlighted_links[e.id]&&(k="#FFF");n=n||f.RIGHT;p=p||f.LEFT;var u=D(b,c);this.render_connections_border&&.6b[1]? +0:Math.PI,a.save(),a.translate(q[0],q[1]),a.rotate(u),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore(),a.save(),a.translate(e[0],e[1]),a.rotate(r),a.beginPath(),a.moveTo(-5,-3),a.lineTo(0,7),a.lineTo(5,-3),a.fill(),a.restore()),a.beginPath(),a.arc(d[0],d[1],5,0,2*Math.PI),a.fill());if(g)for(a.fillStyle=k,q=0;5>q;++q)g=(.001*f.getTime()+.2*q)%1,d=this.computeConnectionPoint(b,c,g,n,p),a.beginPath(),a.arc(d[0],d[1],5,0,2*Math.PI),a.fill()};h.prototype.computeConnectionPoint= +function(a,b,c,e,d){e=e||f.RIGHT;d=d||f.LEFT;var g=D(a,b),k=[a[0],a[1]],n=[b[0],b[1]];switch(e){case f.LEFT:k[0]+=-.25*g;break;case f.RIGHT:k[0]+=.25*g;break;case f.UP:k[1]+=-.25*g;break;case f.DOWN:k[1]+=.25*g}switch(d){case f.LEFT:n[0]+=-.25*g;break;case f.RIGHT:n[0]+=.25*g;break;case f.UP:n[1]+=-.25*g;break;case f.DOWN:n[1]+=.25*g}e=(1-c)*(1-c)*(1-c);d=3*(1-c)*(1-c)*c;g=3*(1-c)*c*c;c*=c*c;return[e*a[0]+d*k[0]+g*n[0]+c*b[0],e*a[1]+d*k[1]+g*n[1]+c*b[1]]};h.prototype.drawExecutionOrder=function(a){a.shadowColor= +"transparent";a.globalAlpha=.25;a.textAlign="center";a.strokeStyle="white";a.globalAlpha=.75;for(var b=this.visible_nodes,c=0;cg||g>l-12||kq.last_y+y||void 0===q.last_y)){e=q.value;switch(q.type){case "button":c.type===f.pointerevents_method+"down"&&(q.callback&&setTimeout(function(){q.callback(q, +h,a,b,c)},20),this.dirty_canvas=q.clicked=!0);break;case "slider":r=Math.clamp((g-15)/(l-30),0,1);q.value=q.options.min+(q.options.max-q.options.min)*r;q.callback&&setTimeout(function(){d(q,q.value)},20);this.dirty_canvas=!0;break;case "number":case "combo":e=q.value;if(c.type==f.pointerevents_method+"move"&&"number"==q.type)q.value+=.1*c.deltaX*(q.options.step||1),null!=q.options.min&&q.valueq.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.valueq.options.max&&(q.value=q.options.max);else if(g)r=-1,this.last_mouseclick=0,r=v.constructor===Object?m.indexOf(String(q.value))+g:m.indexOf(q.value)+ +g,r>=m.length&&(r=m.length-1),0>r&&(r=0),q.value=v.constructor===Array?v[r]:r;else{var w=v!=m?Object.values(v):v;new f.ContextMenu(w,{scale:Math.max(1,this.ds.scale),event:c,className:"dark",callback:function(a,b,c){v!=m&&(a=w.indexOf(a));this.value=a;d(this,a);h.dirty_canvas=!0;return!1}.bind(q)},r)}}else c.type==f.pointerevents_method+"up"&&"number"==q.type&&(g=40>g?-1:g>l-40?1:0,200>c.click_time&&0==g&&this.prompt("Value",q.value,function(a){this.value=Number(a);d(this,this.value)}.bind(q),c)); +e!=q.value&&setTimeout(function(){d(this,this.value)}.bind(q),20);this.dirty_canvas=!0;break;case "toggle":c.type==f.pointerevents_method+"down"&&(q.value=!q.value,setTimeout(function(){d(q,q.value)},20));break;case "string":case "text":c.type==f.pointerevents_method+"down"&&this.prompt("Value",q.value,function(a){this.value=a;d(this,a)}.bind(q),c,q.options?q.options.multiline:!1);break;default:q.mouse&&(this.dirty_canvas=q.mouse(c,[g,k],a))}if(e!=q.value){if(a.onWidgetChanged)a.onWidgetChanged(q.name, +q.value,e,q);a.graph._version++}return q}}}return null};h.prototype.drawGroups=function(a,b){if(this.graph){a=this.graph._groups;b.save();b.globalAlpha=.5*this.editor_alpha;for(var c=0;cc&&.01>b.editor_alpha&&(clearInterval(e),1>c&&(b.live_mode=!0));1"+(p.label?p.label:n)+""+a+"",value:n})}if(k.length)return new f.ContextMenu(k,{event:c,callback:function(a,b,c,e){d&&(b=this.getBoundingClientRect(),g.showEditPropertyValue(d,a.value,{position:[b.left,b.top]}))},parentMenu:e,allow_html:!0,node:d},b),!1}};h.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};h.onMenuResizeNode=function(a,b,c,e,d){if(d){a= +function(a){a.size=a.computeSize();if(a.onResize)a.onResize(a.size)};b=h.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)a(d);else for(var g in b.selected_nodes)a(b.selected_nodes[g]);d.setDirtyCanvas(!0,!0)}};h.prototype.showLinkMenu=function(a,b){var c=this,e=c.graph.getNodeById(a.origin_id),d=c.graph.getNodeById(a.target_id),g=!1;e&&e.outputs&&e.outputs[a.origin_slot]&&(g=e.outputs[a.origin_slot].type);var k=!1;d&&d.outputs&&d.outputs[a.target_slot]&&(k=d.inputs[a.target_slot].type); +var n=new f.ContextMenu(["Add Node",null,"Delete",null],{event:b,title:null!=a.data?a.data.constructor.name:null,callback:function(b,f,u){switch(b){case "Add Node":h.onMenuAdd(null,null,u,n,function(b){b.inputs&&b.inputs.length&&b.outputs&&b.outputs.length&&e.connectByType(a.origin_slot,b,g)&&(b.connectByType(a.target_slot,d,k),b.pos[0]-=.5*b.size[0])});break;case "Delete":c.graph.removeLink(a.id)}}});return!1};h.prototype.createDefaultNodeForSlot=function(a){a=a||{};a=Object.assign({nodeFrom:null, +slotFrom:null,nodeTo:null,slotTo:null,position:[],nodeType:null,posAdd:[0,0],posSizeFix:[0,0]},a);var b=a.nodeFrom&&null!==a.slotFrom,c=!b&&a.nodeTo&&null!==a.slotTo;if(!b&&!c)return console.warn("No data passed to createDefaultNodeForSlot "+a.nodeFrom+" "+a.slotFrom+" "+a.nodeTo+" "+a.slotTo),!1;if(!a.nodeType)return console.warn("No type to createDefaultNodeForSlot"),!1;var e=b?a.nodeFrom:a.nodeTo,d=b?a.slotFrom:a.slotTo;switch(typeof d){case "string":c=b?e.findOutputSlot(d,!1):e.findInputSlot(d, +!1);d=b?e.outputs[d]:e.inputs[d];break;case "object":c=b?e.findOutputSlot(d.name):e.findInputSlot(d.name);break;case "number":c=d;d=b?e.outputs[d]:e.inputs[d];break;default:return console.warn("Cant get slot information "+d),!1}!1!==d&&!1!==c||console.warn("createDefaultNodeForSlot bad slotX "+d+" "+c);e=d.type==f.EVENT?"_event_":d.type;if((d=b?f.slot_types_default_out:f.slot_types_default_in)&&d[e]){nodeNewType=!1;if("object"==typeof d[e]||"array"==typeof d[e])for(var g in d[e]){if(a.nodeType==d[e][g]|| +"AUTO"==a.nodeType){nodeNewType=d[e][g];break}}else if(a.nodeType==d[e]||"AUTO"==a.nodeType)nodeNewType=d[e];if(nodeNewType){g=!1;"object"==typeof nodeNewType&&nodeNewType.node&&(g=nodeNewType,nodeNewType=nodeNewType.node);if(d=f.createNode(nodeNewType)){if(g){if(g.properties)for(var k in g.properties)d.addProperty(k,g.properties[k]);if(g.inputs)for(k in d.inputs=[],g.inputs)d.addOutput(g.inputs[k][0],g.inputs[k][1]);if(g.outputs)for(k in d.outputs=[],g.outputs)d.addOutput(g.outputs[k][0],g.outputs[k][1]); +g.title&&(d.title=g.title);g.json&&d.configure(g.json)}this.graph.add(d);d.pos=[a.position[0]+a.posAdd[0]+(a.posSizeFix[0]?a.posSizeFix[0]*d.size[0]:0),a.position[1]+a.posAdd[1]+(a.posSizeFix[1]?a.posSizeFix[1]*d.size[1]:0)];b?a.nodeFrom.connectByType(c,d,e):a.nodeTo.connectByTypeOutput(c,d,e);return!0}console.log("failed creating "+nodeNewType)}}return!1};h.prototype.showConnectionMenu=function(a){a=a||{};var b=Object.assign({nodeFrom:null,slotFrom:null,nodeTo:null,slotTo:null,e:null},a),c=this, +e=b.nodeFrom&&b.slotFrom;a=!e&&b.nodeTo&&b.slotTo;if(!e&&!a)return console.warn("No data passed to showConnectionMenu"),!1;a=e?b.nodeFrom:b.nodeTo;var d=e?b.slotFrom:b.slotTo,g=!1;switch(typeof d){case "string":g=e?a.findOutputSlot(d,!1):a.findInputSlot(d,!1);d=e?a.outputs[d]:a.inputs[d];break;case "object":g=e?a.findOutputSlot(d.name):a.findInputSlot(d.name);break;case "number":g=d;d=e?a.outputs[d]:a.inputs[d];break;default:return console.warn("Cant get slot information "+d),!1}a=["Add Node",null]; +c.allow_searchbox&&(a.push("Search"),a.push(null));var k=d.type==f.EVENT?"_event_":d.type,n=e?f.slot_types_default_out:f.slot_types_default_in;if(n&&n[k])if("object"==typeof n[k]||"array"==typeof n[k])for(var p in n[k])a.push(n[k][p]);else a.push(n[k]);var r=new f.ContextMenu(a,{event:b.e,title:(d&&""!=d.name?d.name+(k?" | ":""):"")+(d&&k?k:""),callback:function(a,f,n){switch(a){case "Add Node":h.onMenuAdd(null,null,n,r,function(a){e?b.nodeFrom.connectByType(g,a,k):b.nodeTo.connectByTypeOutput(g, +a,k)});break;case "Search":e?c.showSearchBox(n,{node_from:b.nodeFrom,slot_from:d,type_filter_in:k}):c.showSearchBox(n,{node_to:b.nodeTo,slot_from:d,type_filter_out:k});break;default:c.createDefaultNodeForSlot(Object.assign(b,{position:[b.e.canvasX,b.e.canvasY],nodeType:a}))}}});return!1};h.onShowPropertyEditor=function(a,b,c,e,d){function g(){if(p){var b=p.value;"Number"==a.type?b=Number(b):"Boolean"==a.type&&(b=!!b);d[k]=b;n.parentNode&&n.parentNode.removeChild(n);d.setDirtyCanvas(!0,!0)}}var k= +a.property||"title";b=d[k];var n=document.createElement("div");n.is_modified=!1;n.className="graphdialog";n.innerHTML="";n.close=function(){n.parentNode&&n.parentNode.removeChild(n)};n.querySelector(".name").innerText=k;var p=n.querySelector(".value");p&&(p.value=b,p.addEventListener("blur",function(a){this.focus()}),p.addEventListener("keydown",function(a){n.is_modified=!0;if(27==a.keyCode)n.close();else if(13== +a.keyCode)g();else if(13!=a.keyCode&&"textarea"!=a.target.localName)return;a.preventDefault();a.stopPropagation()}));b=h.active_canvas.canvas;c=b.getBoundingClientRect();var r=e=-20;c&&(e-=c.left,r-=c.top);event?(n.style.left=event.clientX+e+"px",n.style.top=event.clientY+r+"px"):(n.style.left=.5*b.width+e+"px",n.style.top=.5*b.height+r+"px");n.querySelector("button").addEventListener("click",g);b.parentNode.appendChild(n);p&&p.focus();var u=null;n.addEventListener("mouseleave",function(a){f.dialog_close_on_mouse_leave&& +!n.is_modified&&f.dialog_close_on_mouse_leave&&(u=setTimeout(n.close,f.dialog_close_on_mouse_leave_delay))});n.addEventListener("mouseenter",function(a){f.dialog_close_on_mouse_leave&&u&&clearTimeout(u)})};h.prototype.prompt=function(a,b,c,e,d){var g=this;a=a||"";var k=document.createElement("div");k.is_modified=!1;k.className="graphdialog rounded";k.innerHTML=d?" ":" "; +k.close=function(){g.prompt_box=null;k.parentNode&&k.parentNode.removeChild(k)};d=h.active_canvas.canvas;d.parentNode.appendChild(k);1h.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;rh.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;rh.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;rh.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="Search ";b.do_type_filter&&(r.innerHTML+="", +r.innerHTML+="");r.innerHTML+="
";p.fullscreenElement?p.fullscreenElement.appendChild(r):(p.body.appendChild(r),p.body.style.overflow="hidden");if(b.do_type_filter)var u=r.querySelector(".slot_in_type_filter"),q=r.querySelector(".slot_out_type_filter");r.close=function(){g.search_box=null;p.body.focus();p.body.style.overflow="";setTimeout(function(){g.canvas.focus()},20);r.parentNode&&r.parentNode.removeChild(r)}; +1n.height-200&&(v.style.maxHeight=n.height-a.layerY-20+ +"px");z.focus();b.show_all_on_open&&d();return r};h.prototype.showEditPropertyValue=function(a,b,c){function e(){d(q.value)}function d(d){g&&g.values&&g.values.constructor===Object&&void 0!=g.values[d]&&(d=g.values[d]);"number"==typeof a.properties[b]&&(d=Number(d));if("array"==f||"object"==f)d=JSON.parse(d);a.properties[b]=d;a.graph&&a.graph._version++;if(a.onPropertyChanged)a.onPropertyChanged(b,d);if(c.onclose)c.onclose();u.close();a.setDirtyCanvas(!0,!0)}if(a&&void 0!==a.properties[b]){c=c||{}; +var g=a.getPropertyInfo(b),f=g.type,n="";if("string"==f||"number"==f||"array"==f||"object"==f)n="";else if("enum"!=f&&"combo"!=f||!g.values)if("boolean"==f||"toggle"==f)n="";else{console.warn("unknown type: "+f);return}else{n=""}var u=this.createDialog(""+(g.label?g.label:b)+""+n+"",c),q=!1;if("enum"!=f&&"combo"!=f||!g.values)if("boolean"==f||"toggle"==f)(q=u.querySelector("input"))&&q.addEventListener("click",function(a){u.modified();d(!!q.checked)});else{if(q=u.querySelector("input"))q.addEventListener("blur",function(a){this.focus()}),r=void 0!==a.properties[b]?a.properties[b]:"","string"!==f&&(r= +JSON.stringify(r)),q.value=r,q.addEventListener("keydown",function(a){if(27==a.keyCode)u.close();else if(13==a.keyCode)e();else if(13!=a.keyCode){u.modified();return}a.preventDefault();a.stopPropagation()})}else q=u.querySelector("select"),q.addEventListener("change",function(a){u.modified();d(a.target.value)});q&&q.focus();u.querySelector("button").addEventListener("click",e);return u}};h.prototype.createDialog=function(a,b){def_options={checkForInput:!1,closeOnLeave:!0,closeOnLeave_checkModified:!0}; +b=Object.assign(def_options,b||{});var c=document.createElement("div");c.className="graphdialog";c.innerHTML=a;c.is_modified=!1;a=this.canvas.getBoundingClientRect();var e=-20,d=-20;a&&(e-=a.left,d-=a.top);b.position?(e+=b.position[0],d+=b.position[1]):b.event?(e+=b.event.clientX,d+=b.event.clientY):(e+=.5*this.canvas.width,d+=.5*this.canvas.height);c.style.left=e+"px";c.style.top=d+"px";this.canvas.parentNode.appendChild(c);b.checkForInput&&(a=[],(a=c.querySelectorAll("input"))&&a.forEach(function(a){a.addEventListener("keydown", +function(a){c.modified();if(27==a.keyCode)c.close();else if(13!=a.keyCode)return;a.preventDefault();a.stopPropagation()});a.focus()}));c.modified=function(){c.is_modified=!0};c.close=function(){c.parentNode&&c.parentNode.removeChild(c)};var g=null,k=!1;c.addEventListener("mouseleave",function(a){k||(b.closeOnLeave||f.dialog_close_on_mouse_leave)&&!c.is_modified&&f.dialog_close_on_mouse_leave&&(g=setTimeout(c.close,f.dialog_close_on_mouse_leave_delay))});c.addEventListener("mouseenter",function(a){(b.closeOnLeave|| +f.dialog_close_on_mouse_leave)&&g&&clearTimeout(g)});(a=c.querySelectorAll("select"))&&a.forEach(function(a){a.addEventListener("click",function(a){k++});a.addEventListener("blur",function(a){k=0});a.addEventListener("change",function(a){k=-1})});return c};h.prototype.createPanel=function(a,b){b=b||{};var c=b.window||window,e=document.createElement("div");e.className="litegraph dialog";e.innerHTML="
"; +e.header=e.querySelector(".dialog-header");b.width&&(e.style.width=b.width+(b.width.constructor===Number?"px":""));b.height&&(e.style.height=b.height+(b.height.constructor===Number?"px":""));b.closable&&(b=document.createElement("span"),b.innerHTML="✕",b.classList.add("close"),b.addEventListener("click",function(){e.close()}),e.header.appendChild(b));e.title_element=e.querySelector(".dialog-title");e.title_element.innerText=a;e.content=e.querySelector(".dialog-content");e.alt_content=e.querySelector(".dialog-alt-content"); +e.footer=e.querySelector(".dialog-footer");e.close=function(){if(e.onClose&&"function"==typeof e.onClose)e.onClose();e.parentNode.removeChild(e);this.parentNode&&this.parentNode.removeChild(this)};e.toggleAltContent=function(a){if("undefined"!=typeof a){var b=a?"block":"none";a=a?"none":"block"}else b="block"!=e.alt_content.style.display?"block":"none",a="block"!=e.alt_content.style.display?"none":"block";e.alt_content.style.display=b;e.content.style.display=a};e.toggleFooterVisibility=function(a){e.footer.style.display= +"undefined"!=typeof a?a?"block":"none":"block"!=e.footer.style.display?"block":"none"};e.clear=function(){this.content.innerHTML=""};e.addHTML=function(a,b,c){var d=document.createElement("div");b&&(d.className=b);d.innerHTML=a;c?e.footer.appendChild(d):e.content.appendChild(d);return d};e.addButton=function(a,b,c){var d=document.createElement("button");d.innerText=a;d.options=c;d.classList.add("btn");d.addEventListener("click",b);e.footer.appendChild(d);return d};e.addSeparator=function(){var a= +document.createElement("div");a.className="separator";e.content.appendChild(a)};e.addWidget=function(a,b,k,n,p){function d(a,b){n.callback&&n.callback(a,b,n);p&&p(a,b,n)}n=n||{};var g=String(k);a=a.toLowerCase();"number"==a&&(g=k.toFixed(3));var q=document.createElement("div");q.className="property";q.innerHTML="";q.querySelector(".property_name").innerText=n.label||b;var y=q.querySelector(".property_value");y.innerText=g;q.dataset.property= +b;q.dataset.type=n.type||a;q.options=n;q.value=k;if("code"==a)q.addEventListener("click",function(a){e.inner_showCodePad(this.dataset.property)});else if("boolean"==a)q.classList.add("boolean"),k&&q.classList.add("bool-on"),q.addEventListener("click",function(){var a=this.dataset.property;this.value=!this.value;this.classList.toggle("bool-on");this.querySelector(".property_value").innerText=this.value?"true":"false";d(a,this.value)});else if("string"==a||"number"==a)y.setAttribute("contenteditable", +!0),y.addEventListener("keydown",function(b){"Enter"!=b.code||"string"==a&&b.shiftKey||(b.preventDefault(),this.blur())}),y.addEventListener("blur",function(){var a=this.innerText,b=this.parentNode.dataset.property;"number"==this.parentNode.dataset.type&&(a=Number(a));d(b,a)});else if("enum"==a||"combo"==a)g=h.getPropertyPrintableValue(k,n.values),y.innerText=g,y.addEventListener("click",function(a){var b=this.parentNode.dataset.property,e=this;new f.ContextMenu(n.values||[],{event:a,className:"dark", +callback:function(a,c,g){e.innerText=a;d(b,a);return!1}},c)});e.content.appendChild(q);return q};if(e.onOpen&&"function"==typeof e.onOpen)e.onOpen();return e};h.getPropertyPrintableValue=function(a,b){if(!b||b.constructor===Array)return String(a);if(b.constructor===Object){var c="",e;for(e in b)if(b[e]==a){c=e;break}return String(a)+" ("+c+")"}};h.prototype.closePanels=function(){var a=document.querySelector("#node-panel");a&&a.close();(a=document.querySelector("#option-panel"))&&a.close()};h.prototype.showShowGraphOptionsPanel= +function(a,b,c,e){if(this.constructor&&"HTMLDivElement"==this.constructor.name){if(!(b&&b.event&&b.event.target&&b.event.target.lgraphcanvas)){console.warn("Canvas not found");return}var d=b.event.target.lgraphcanvas}else d=this;d.closePanels();a=d.getCanvasWindow();panel=d.createPanel("Options",{closable:!0,window:a,onOpen:function(){d.OPTIONPANEL_IS_OPEN=!0},onClose:function(){d.OPTIONPANEL_IS_OPEN=!1;d.options_panel=null}});d.options_panel=panel;panel.id="option-panel";panel.classList.add("settings"); +(function(){panel.content.innerHTML="";var a=function(a,b,c){c&&c.key&&(a=c.key);c.values&&(b=Object.values(c.values).indexOf(b));d[a]=b},b=f.availableCanvasOptions;b.sort();for(pI in b){var c=b[pI];panel.addWidget("boolean",c,d[c],{key:c,on:"True",off:"False"},a)}panel.addWidget("combo","Render mode",f.LINK_RENDER_MODES[d.links_render_mode],{key:"links_render_mode",values:f.LINK_RENDER_MODES},a);panel.addSeparator();panel.footer.innerHTML=""})();d.canvas.parentNode.appendChild(panel)};h.prototype.showShowNodePanel= +function(a){function b(){panel.content.innerHTML="";panel.addHTML(""+a.type+""+(a.constructor.desc||"")+"");panel.addHTML("

Properties

");var b=function(b,c){e.graph.beforeChange(a);switch(b){case "Title":a.title=c;break;case "Mode":b=Object.values(f.NODE_MODES).indexOf(c);0<=b&&f.NODE_MODES[b]?a.changeMode(b):console.warn("unexpected mode: "+c);break;case "Color":h.node_colors[c]?(a.color=h.node_colors[c].color, +a.bgcolor=h.node_colors[c].bgcolor):console.warn("unexpected color: "+c);break;default:a.setProperty(b,c)}e.graph.afterChange();e.dirty_canvas=!0};panel.addWidget("string","Title",a.title,{},b);panel.addWidget("combo","Mode",f.NODE_MODES[a.mode],{values:f.NODE_MODES},b);var c="";void 0!==a.color&&(c=Object.keys(h.node_colors).filter(function(b){return h.node_colors[b].color==a.color}));panel.addWidget("combo","Color",c,{values:Object.keys(h.node_colors)},b);for(var k in a.properties){c=a.properties[k]; +var n=a.getPropertyInfo(k);a.onAddPropertyToPanel&&a.onAddPropertyToPanel(k,panel)||panel.addWidget(n.widget||n.type,k,c,n,b)}panel.addSeparator();if(a.onShowCustomPanelInfo)a.onShowCustomPanelInfo(panel);panel.footer.innerHTML="";panel.addButton("Delete",function(){a.block_delete||(a.graph.remove(a),panel.close())}).classList.add("delete")}this.SELECTED_NODE=a;this.closePanels();var c=this.getCanvasWindow(),e=this;panel=this.createPanel(a.title||"",{closable:!0,window:c,onOpen:function(){e.NODEPANEL_IS_OPEN= +!0},onClose:function(){e.NODEPANEL_IS_OPEN=!1;e.node_panel=null}});e.node_panel=panel;panel.id="node-panel";panel.node=a;panel.classList.add("settings");panel.inner_showCodePad=function(c){panel.classList.remove("settings");panel.classList.add("centered");panel.alt_content.innerHTML="";var d=panel.alt_content.querySelector("textarea"),e=function(){panel.toggleAltContent(!1);panel.toggleFooterVisibility(!0);d.parentNode.removeChild(d);panel.classList.add("settings"); +panel.classList.remove("centered");b()};d.value=a.properties[c];d.addEventListener("keydown",function(b){"Enter"==b.code&&b.ctrlKey&&(a.setProperty(c,d.value),e())});panel.toggleAltContent(!0);panel.toggleFooterVisibility(!1);d.style.height="calc(100% - 40px)";var f=panel.addButton("Assign",function(){a.setProperty(c,d.value);e()});panel.alt_content.appendChild(f);f=panel.addButton("Close",e);f.style.float="right";panel.alt_content.appendChild(f)};b();this.canvas.parentNode.appendChild(panel)};h.prototype.showSubgraphPropertiesDialog= +function(a){function b(){e.clear();if(a.inputs)for(var c=0;c","subgraph_property");f.dataset.name=g.name;f.dataset.slot=c;f.querySelector(".name").innerText=g.name;f.querySelector(".type").innerText=g.type;f.querySelector("button").addEventListener("click",function(c){a.removeInput(Number(this.parentNode.dataset.slot)); +b()})}}}console.log("showing subgraph properties dialog");var c=this.canvas.parentNode.querySelector(".subgraph_dialog");c&&c.close();var e=this.createPanel("Subgraph Inputs",{closable:!0,width:500});e.node=a;e.classList.add("subgraph_dialog");e.addHTML(" + NameType","subgraph_property extra",!0).querySelector("button").addEventListener("click",function(c){c=this.parentNode;var d= +c.querySelector(".name").value,e=c.querySelector(".type").value;d&&-1==a.findInputSlot(d)&&(a.addInput(d,e),c.querySelector(".name").value="",c.querySelector(".type").value="",b())});b();this.canvas.parentNode.appendChild(e);return e};h.prototype.showSubgraphPropertiesDialogRight=function(a){function b(){d.clear();if(a.outputs)for(var c=0;c", +"subgraph_property");f.dataset.name=e.name;f.dataset.slot=c;f.querySelector(".name").innerText=e.name;f.querySelector(".type").innerText=e.type;f.querySelector("button").addEventListener("click",function(c){a.removeOutput(Number(this.parentNode.dataset.slot));b()})}}}function c(){var c=this.parentNode,d=c.querySelector(".name").value,e=c.querySelector(".type").value;d&&-1==a.findOutputSlot(d)&&(a.addOutput(d,e),c.querySelector(".name").value="",c.querySelector(".type").value="",b())}var e=this.canvas.parentNode.querySelector(".subgraph_dialog"); +e&&e.close();var d=this.createPanel("Subgraph Outputs",{closable:!0,width:500});d.node=a;d.classList.add("subgraph_dialog");e=d.addHTML(" + NameType","subgraph_property extra",!0);e.querySelector(".name").addEventListener("keydown",function(a){13==a.keyCode&&c.apply(this)});e.querySelector("button").addEventListener("click",function(a){c.apply(this)});b();this.canvas.parentNode.appendChild(d); +return d};h.prototype.checkPanels=function(){if(this.canvas)for(var a=this.canvas.parentNode.querySelectorAll(".litegraph.dialog"),b=0;b=Object.keys(a.selected_nodes).length)d.collapse();else for(var f in a.selected_nodes)a.selected_nodes[f].collapse();d.graph.afterChange()};h.onMenuNodePin=function(a,b,c,e,d){d.pin()}; +h.onMenuNodeMode=function(a,b,c,e,d){new f.ContextMenu(f.NODE_MODES,{event:c,callback:function(a){if(d){var b=Object.values(f.NODE_MODES).indexOf(a),c=function(c){0<=b&&f.NODE_MODES[b]?c.changeMode(b):(console.warn("unexpected mode: "+a),c.changeMode(f.ALWAYS))},e=h.active_canvas;if(!e.selected_nodes||1>=Object.keys(e.selected_nodes).length)c(d);else for(var g in e.selected_nodes)c(e.selected_nodes[g])}},parentMenu:e,node:d});return!1};h.onMenuNodeColors=function(a,b,c,e,d){if(!d)throw"no node for color"; +b=[];b.push({value:null,content:"No color"});for(var g in h.node_colors)a=h.node_colors[g],a={value:g,content:""+g+""},b.push(a);new f.ContextMenu(b,{event:c,callback:function(a){if(d){var b=a.value?h.node_colors[a.value]:null;a=function(a){b?a.constructor===f.LGraphGroup?a.color=b.groupcolor:(a.color=b.color, +a.bgcolor=b.bgcolor):(delete a.color,delete a.bgcolor)};var c=h.active_canvas;if(!c.selected_nodes||1>=Object.keys(c.selected_nodes).length)a(d);else for(var e in c.selected_nodes)a(c.selected_nodes[e]);d.setDirtyCanvas(!0,!0)}},parentMenu:e,node:d});return!1};h.onMenuNodeShapes=function(a,b,c,e,d){if(!d)throw"no node passed";new f.ContextMenu(f.VALID_SHAPES,{event:c,callback:function(a){if(d){d.graph.beforeChange();var b=h.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)d.shape= +a;else for(var c in b.selected_nodes)b.selected_nodes[c].shape=a;d.graph.afterChange();d.setDirtyCanvas(!0)}},parentMenu:e,node:d});return!1};h.onMenuNodeRemove=function(a,b,c,e,d){if(!d)throw"no node passed";a=d.graph;a.beforeChange();b=h.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)!1!==d.removable&&a.remove(d);else for(var f in b.selected_nodes)c=b.selected_nodes[f],!1!==c.removable&&a.remove(c);a.afterChange();d.setDirtyCanvas(!0,!0)};h.onMenuNodeToSubgraph=function(a, +b,c,e,d){a=d.graph;if(b=h.active_canvas)c=Object.values(b.selected_nodes||{}),c.length||(c=[d]),e=f.createNode("graph/subgraph"),e.pos=d.pos.concat(),a.add(e),e.buildFromNodes(c),b.deselectAllNodes(),d.setDirtyCanvas(!0,!0)};h.onMenuNodeClone=function(a,b,c,e,d){d.graph.beforeChange();var f={};a=function(a){if(0!=a.clonable){var b=a.clone();b&&(b.pos=[a.pos[0]+5,a.pos[1]+5],a.graph.add(b),f[b.id]=b)}};b=h.active_canvas;if(!b.selected_nodes||1>=Object.keys(b.selected_nodes).length)a(d);else for(var k in b.selected_nodes)a(b.selected_nodes[k]); +Object.keys(f).length&&b.selectNodes(f);d.graph.afterChange();d.setDirtyCanvas(!0,!0)};h.node_colors={red:{color:"#322",bgcolor:"#533",groupcolor:"#A88"},brown:{color:"#332922",bgcolor:"#593930",groupcolor:"#b06634"},green:{color:"#232",bgcolor:"#353",groupcolor:"#8A8"},blue:{color:"#223",bgcolor:"#335",groupcolor:"#88A"},pale_blue:{color:"#2a363b",bgcolor:"#3f5159",groupcolor:"#3f789e"},cyan:{color:"#233",bgcolor:"#355",groupcolor:"#8AA"},purple:{color:"#323",bgcolor:"#535",groupcolor:"#a1309b"}, +yellow:{color:"#432",bgcolor:"#653",groupcolor:"#b58b2a"},black:{color:"#222",bgcolor:"#000",groupcolor:"#444"}};h.prototype.getCanvasMenuOptions=function(){if(this.getMenuOptions)var a=this.getMenuOptions();else a=[{content:"Add Node",has_submenu:!0,callback:h.onMenuAdd},{content:"Add Group",callback:h.onGroupAdd}],this._graph_stack&&0Name",d),r=g.querySelector("input");r&&f&&(r.value=f.label||"");var k=function(){a.graph.beforeChange();r.value&&(f&&(f.label=r.value),c.setDirty(!0));g.close();a.graph.afterChange()};g.querySelector("button").addEventListener("click",k);r.addEventListener("keydown",function(a){g.is_modified=!0;if(27==a.keyCode)g.close(); +else if(13==a.keyCode)k();else if(13!=a.keyCode&&"textarea"!=a.target.localName)return;a.preventDefault();a.stopPropagation()});r.focus()}},extra:a};a&&(g.title=a.type);var k=null;a&&(k=a.getSlotInPosition(b.canvasX,b.canvasY),h.active_node=a);k?(d=[],a.getSlotMenuOptions?d=a.getSlotMenuOptions(k):(k&&k.output&&k.output.links&&k.output.links.length&&d.push({content:"Disconnect Links",slot:k}),b=k.input||k.output,b.removable&&d.push(b.locked?"Cannot remove":{content:"Remove Slot",slot:k}),b.nameLocked|| +d.push({content:"Rename Slot",slot:k})),g.title=(k.input?k.input.type:k.output.type)||"*",k.input&&k.input.type==f.ACTION&&(g.title="Action"),k.output&&k.output.type==f.EVENT&&(g.title="Event")):a?d=this.getNodeMenuOptions(a):(d=this.getCanvasMenuOptions(),(k=this.graph.getGroupOnPos(b.canvasX,b.canvasY))&&d.push(null,{content:"Edit Group",has_submenu:!0,submenu:{title:"Group",extra:k,options:this.getGroupMenuOptions(k)}}));d&&new f.ContextMenu(d,g,e)};"undefined"!=typeof window&&window.CanvasRenderingContext2D&& +!window.CanvasRenderingContext2D.prototype.roundRect&&(window.CanvasRenderingContext2D.prototype.roundRect=function(a,b,c,e,d,f){var g,h;if(0===d)this.rect(a,b,c,e);else{void 0===f&&(f=d);if(null!=d&&d.constructor===Array)if(1==d.length)var l=g=h=f=d[0];else if(2==d.length)l=f=d[0],g=h=d[1];else if(4==d.length)l=d[0],g=d[1],h=d[2],f=d[3];else return;else l=d||0,g=d||0,h=f||0,f=f||0;this.moveTo(a+l,b);this.lineTo(a+c-g,b);this.quadraticCurveTo(a+c,b,a+c,b+g);this.lineTo(a+c,b+e-f);this.quadraticCurveTo(a+ +c,b+e,a+c-f,b+e);this.lineTo(a+f,b+e);this.quadraticCurveTo(a,b+e,a,b+e-h);this.lineTo(a,b+h);this.quadraticCurveTo(a,b,a+l,b)}});f.compareObjects=function(a,b){for(var c in a)if(a[c]!=b[c])return!1;return!0};f.distance=D;f.colorToString=function(a){return"rgba("+Math.round(255*a[0]).toFixed()+","+Math.round(255*a[1]).toFixed()+","+Math.round(255*a[2]).toFixed()+","+(4==a.length?a[3].toFixed(2):"1.0")+")"};f.isInsideRectangle=C;f.growBounding=function(a,b,c){ba[2]&&(a[2]=b);ca[3]&&(a[3]=c)};f.isInsideBounding=function(a,b){return a[0]b[1][0]||a[1]>b[1][1]?!1:!0};f.overlapBounding=A;f.hex2num=function(a){"#"==a.charAt(0)&&(a=a.slice(1));a=a.toUpperCase();for(var b=Array(3),c=0,e,d,f=0;6>f;f+=2)e="0123456789ABCDEF".indexOf(a.charAt(f)),d="0123456789ABCDEF".indexOf(a.charAt(f+1)),b[c]=16*e+d,c++;return b};f.num2hex=function(a){for(var b="#",c,e,d=0;3>d;d++)c=a[d]/16,e=a[d]%16,b+="0123456789ABCDEF".charAt(c)+"0123456789ABCDEF".charAt(e); +return b};E.prototype.addItem=function(a,b,c){function e(a){var b=this.value;b&&b.has_submenu&&d.call(this,a)}function d(a){var b=this.value,d=!0;g.current_submenu&&g.current_submenu.close(a);if(c.callback){var e=c.callback.call(this,b,c,a,g,c.node);!0===e&&(d=!1)}if(b&&(b.callback&&!c.ignore_item_callbacks&&!0!==b.disabled&&(e=b.callback.call(this,b,c,a,g,c.extra),!0===e&&(d=!1)),b.submenu)){if(!b.submenu.options)throw"ContextMenu submenu needs options";new g.constructor(b.submenu.options,{callback:b.submenu.callback, +event:a,parentMenu:g,ignore_item_callbacks:b.submenu.ignore_item_callbacks,title:b.submenu.title,extra:b.submenu.extra,autoopen:c.autoopen});d=!1}d&&!g.lock&&g.close()}var g=this;c=c||{};var k=document.createElement("div");k.className="litemenu-entry submenu";var h=!1;if(null===b)k.classList.add("separator");else{k.innerHTML=b&&b.title?b.title:a;if(k.value=b)b.disabled&&(h=!0,k.classList.add("disabled")),(b.submenu||b.has_submenu)&&k.classList.add("has_submenu");"function"==typeof b?(k.dataset.value= +a,k.onclick_callback=b):k.dataset.value=b;b.className&&(k.className+=" "+b.className)}this.root.appendChild(k);h||k.addEventListener("click",d);c.autoopen&&f.pointerListenerAdd(k,"enter",e);return k};E.prototype.close=function(a,b){this.root.parentNode&&this.root.parentNode.removeChild(this.root);this.parentMenu&&!b&&(this.parentMenu.lock=!1,this.parentMenu.current_submenu=null,void 0===a?this.parentMenu.close():a&&!E.isCursorOverElement(a,this.parentMenu.root)&&E.trigger(this.parentMenu.root,f.pointerevents_method+ +"leave",a));this.current_submenu&&this.current_submenu.close(a,!0);this.root.closing_timer&&clearTimeout(this.root.closing_timer)};E.trigger=function(a,b,c,e){var d=document.createEvent("CustomEvent");d.initCustomEvent(b,!0,!0,c);d.srcElement=e;a.dispatchEvent?a.dispatchEvent(d):a.__events&&a.__events.dispatchEvent(d);return d};E.prototype.getTopMenu=function(){return this.options.parentMenu?this.options.parentMenu.getTopMenu():this};E.prototype.getFirstEvent=function(){return this.options.parentMenu? +this.options.parentMenu.getFirstEvent():this.options.event};E.isCursorOverElement=function(a,b){var c=a.clientX;a=a.clientY;return(b=b.getBoundingClientRect())?a>b.top&&ab.left&&c +Math.abs(b))return e[1];a=(a-e[0])/b;return e[1]*(1-a)+d[1]*a}}return 0}};G.prototype.draw=function(a,b,c,e,d,f){if(c=this.points){this.size=b;var g=b[0]-2*this.margin;b=b[1]-2*this.margin;d=d||"#666";a.save();a.translate(this.margin,this.margin);e&&(a.fillStyle="#111",a.fillRect(0,0,g,b),a.fillStyle="#222",a.fillRect(.5*g,0,1,b),a.strokeStyle="#333",a.strokeRect(0,0,g,b));a.strokeStyle=d;f&&(a.globalAlpha=.5);a.beginPath();for(e=0;ea[1])){var e=this.size[0]-2*this.margin,d=this.size[1]-2*this.margin,f=a[0]-this.margin;a=a[1]-this.margin;this.selected=this.getCloserPoint([f,a],30/b.ds.scale);-1==this.selected&&(b=[f/e,1-a/d],c.push(b),c.sort(function(a,b){return a[0]-b[0]}),this.selected= +c.indexOf(b),this.must_update=!0);if(-1!=this.selected)return!0}};G.prototype.onMouseMove=function(a,b){var c=this.points;if(c){var e=this.selected;if(!(0>e)){var d=(a[0]-this.margin)/(this.size[0]-2*this.margin),f=(a[1]-this.margin)/(this.size[1]-2*this.margin);this._nearest=this.getCloserPoint([a[0]-this.margin,a[1]-this.margin],30/b.ds.scale);if(b=c[e]){var k=0==e||e==c.length-1;!k&&(-10>a[0]||a[0]>this.size[0]+10||-10>a[1]||a[1]>this.size[1]+10)?(c.splice(e,1),this.selected=-1):(b[0]=k?0==e?0: +1:Math.clamp(d,0,1),b[1]=1-Math.clamp(f,0,1),c.sort(function(a,b){return a[0]-b[0]}),this.selected=c.indexOf(b),this.must_update=!0)}}}};G.prototype.onMouseUp=function(a,b){this.selected=-1;return!1};G.prototype.getCloserPoint=function(a,b){var c=this.points;if(!c)return-1;b=b||30;for(var e=this.size[0]-2*this.margin,d=this.size[1]-2*this.margin,f=c.length,k=[0,0],h=1E6,l=-1,r=0;rh||u>b||(l=r,h=u)}return l};f.CurveEditor=G;f.getParameterNames= +function(a){return(a+"").replace(/[/][/].*$/gm,"").replace(/\s+/g,"").replace(/[/][*][^/*]*[*][/]/g,"").split("){",1)[0].replace(/^[^(]*[(]/,"").replace(/=[^,]+/g,"").split(",").filter(Boolean)};f.pointerListenerAdd=function(a,b,c,e){e=void 0===e?!1:e;if(a&&a.addEventListener&&b&&"function"===typeof c){var d=f.pointerevents_method;if("pointer"==d&&!window.PointerEvent)switch(console.warn("sMethod=='pointer' && !window.PointerEvent"),console.log("Converting pointer["+b+"] : down move up cancel enter TO touchstart touchmove touchend, etc .."), +b){case "down":d="touch";b="start";break;case "move":d="touch";break;case "up":d="touch";b="end";break;case "cancel":d="touch";break;case "enter":console.log("debug: Should I send a move event?");break;default:console.warn("PointerEvent not available in this browser ? The event "+b+" would not be called")}switch(b){case "down":case "up":case "move":case "over":case "out":case "enter":a.addEventListener(d+b,c,e);case "leave":case "cancel":case "gotpointercapture":case "lostpointercapture":if("mouse"!= +d)return a.addEventListener(d+b,c,e);default:return a.addEventListener(b,c,e)}}};f.pointerListenerRemove=function(a,b,c,e){e=void 0===e?!1:e;if(a&&a.removeEventListener&&b&&"function"===typeof c)switch(b){case "down":case "up":case "move":case "over":case "out":case "enter":"pointer"!=f.pointerevents_method&&"mouse"!=f.pointerevents_method||a.removeEventListener(f.pointerevents_method+b,c,e);case "leave":case "cancel":case "gotpointercapture":case "lostpointercapture":if("pointer"==f.pointerevents_method)return a.removeEventListener(f.pointerevents_method+ +b,c,e);default:return a.removeEventListener(b,c,e)}};Math.clamp=function(a,b,c){return b>a?b:ca&&(b[0]=f?this.trigger(null,g):this._pending.push([f,g])};A.prototype.onExecute=function(){var f=1E3*this.graph.elapsed_time;this.isInputConnected(1)&&(this.properties.time_in_ms=this.getInputData(1)); -for(var g=0;gr?h.xbox.axes.lx:0,this._left_axis[1]=Math.abs(h.xbox.axes.ly)>r?h.xbox.axes.ly:0,this._right_axis[0]=Math.abs(h.xbox.axes.rx)>r?h.xbox.axes.rx:0,this._right_axis[1]=Math.abs(h.xbox.axes.ry)>r?h.xbox.axes.ry:0,this._triggers[0]=Math.abs(h.xbox.axes.ltrigger)>r?h.xbox.axes.ltrigger: -0,this._triggers[1]=Math.abs(h.xbox.axes.rtrigger)>r?h.xbox.axes.rtrigger:0);if(this.outputs)for(r=0;rr;r++)if(h[r]){h=h[r];r=this.xbox_mapping;r||(r=this.xbox_mapping={axes:[], -buttons:{},hat:"",hatmap:n.CENTER});r.axes.lx=h.axes[0];r.axes.ly=h.axes[1];r.axes.rx=h.axes[2];r.axes.ry=h.axes[3];r.axes.ltrigger=h.buttons[6].value;r.axes.rtrigger=h.buttons[7].value;r.hat="";r.hatmap=n.CENTER;for(var t=0;tt)r.buttons[n.mapping_array[t]]=h.buttons[t].pressed,h.buttons[t].was_pressed&&this.trigger(n.mapping_array[t]+"_button_event");else switch(t){case 12:h.buttons[t].pressed&&(r.hat+="up",r.hatmap|=n.UP); -break;case 13:h.buttons[t].pressed&&(r.hat+="down",r.hatmap|=n.DOWN);break;case 14:h.buttons[t].pressed&&(r.hat+="left",r.hatmap|=n.LEFT);break;case 15:h.buttons[t].pressed&&(r.hat+="right",r.hatmap|=n.RIGHT);break;case 16:r.buttons.home=h.buttons[t].pressed}h.xbox=r;return h}};n.prototype.onDrawBackground=function(h){if(!this.flags.collapsed){var r=this._left_axis,n=this._right_axis;h.strokeStyle="#88A";h.strokeRect(.5*(r[0]+1)*this.size[0]-4,.5*(r[1]+1)*this.size[1]-4,8,8);h.strokeStyle="#8A8"; -h.strokeRect(.5*(n[0]+1)*this.size[0]-4,.5*(n[1]+1)*this.size[1]-4,8,8);r=this.size[1]/this._current_buttons.length;h.fillStyle="#AEB";for(n=0;n=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;lw?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;ww;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;tt)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","enum",{values:a.values});this.addWidget("combo", -"Cond.",this.properties.OP,{property:"OP",values:a.values});this.size=[80,60]}function b(){this.addInput("in","");this.addInput("cond","boolean");this.addOutput("true","");this.addOutput("false","");this.size=[80,60]}function 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",p.allow_scripts,function(a){p.allow_scripts=a});this._func=null}function k(){this.addInput("vec2","vec2");this.addOutput("x","number");this.addOutput("y","number")}function m(){this.addInputs([["x", -"number"],["y","number"]]);this.addOutput("vec2","vec2");this.properties={x:0,y:0};this._data=new Float32Array(2)}function l(){this.addInput("vec3","vec3");this.addOutput("x","number");this.addOutput("y","number");this.addOutput("z","number")}function q(){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 u(){this.addInput("vec4","vec4");this.addOutput("x","number");this.addOutput("y","number"); -this.addOutput("z","number");this.addOutput("w","number")}function J(){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 p=v.LiteGraph;n.title="Converter";n.desc="type A to type B";n.prototype.onExecute=function(){var a=this.getInputData(0);if(null!=a&&this.outputs)for(var b=0;ba&&(a+=1024);var d=Math.floor(a);a-=d;c=g.data[d];d=g.data[1023==d?0:d+1];b&&(a=a*a*a*(a*(6*a-15)+10));return c*(1-a)+d*a};g.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,k=0;kd);++k);a=this.properties.min;this._last_v=c/f*(this.properties.max-a)+a;this.setOutputData(0,this._last_v)};g.prototype.onDrawBackground=function(a){this.outputs[0].label=(this._last_v||0).toFixed(3)};p.registerNodeType("math/noise",g);B.title="Spikes";B.desc="spike every random time"; -B.prototype.onExecute=function(){var a=this.graph.elapsed_time;this._remaining_time-=a;this._blink_time-=a;a=0;0this._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)};p.registerNodeType("math/spikes",B);A.title="Clamp";A.desc= -"Clamp number between min and max";A.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))};A.prototype.getCode=function(a){a="";this.isInputConnected(0)&&(a+="clamp({{0}},"+this.properties.min+","+this.properties.max+")");return a};p.registerNodeType("math/clamp",A);y.title="Lerp";y.desc="Linear Interpolation";y.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)};y.prototype.onGetInputs=function(){return[["f","number"]]};p.registerNodeType("math/lerp",y);C.title="Abs";C.desc="Absolute";C.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,Math.abs(a))};p.registerNodeType("math/abs",C);E.title="Floor";E.desc="Floor number to remove fractional part";E.prototype.onExecute=function(){var a= -this.getInputData(0);null!=a&&this.setOutputData(0,Math.floor(a))};p.registerNodeType("math/floor",E);f.title="Frac";f.desc="Returns fractional part";f.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,a%1)};p.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))}}; -p.registerNodeType("math/smoothstep",L);G.title="Scale";G.desc="v * factor";G.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,a*this.properties.factor)};p.registerNodeType("math/scale",G);z.title="Gate";z.desc="if v is true, then outputs A, otherwise B";z.prototype.onExecute=function(){var a=this.getInputData(0);this.setOutputData(0,this.getInputData(a?1:2))};p.registerNodeType("math/gate",z);I.title="Average";I.desc="Average Filter";I.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;cb&&(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))};p.registerNodeType("math/average", -I);D.title="TendTo";D.desc="moves the output value always closer to the input";D.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)};p.registerNodeType("math/tendTo",D);H.values="+ - * / % ^ max min".split(" ");H.title="Operation";H.desc="Easy math operators";H["@OP"]={type:"enum",title:"operation",values:H.values};H.size=[100,60];H.prototype.getTitle=function(){return"max"== -this.properties.OP||"min"==this.properties.OP?this.properties.OP+"(A,B)":"A "+this.properties.OP+" B"};H.prototype.setValue=function(a){"string"==typeof a&&(a=parseFloat(a));this.properties.value=a};H.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}}};H.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;dB":f=a>b;break;case "A=B":f=a>=b}this.setOutputData(c,f)}}};F.prototype.onGetOutputs=function(){return[["A==B","boolean"],["A!=B","boolean"],["A>B","boolean"],["A=B","boolean"],["A<=B","boolean"]]};p.registerNodeType("math/compare",F);p.registerSearchboxExtra("math/compare","==",{outputs:[["A==B","boolean"]],title:"A==B"}); -p.registerSearchboxExtra("math/compare","!=",{outputs:[["A!=B","boolean"]],title:"A!=B"});p.registerSearchboxExtra("math/compare",">",{outputs:[["A>B","boolean"]],title:"A>B"});p.registerSearchboxExtra("math/compare","<",{outputs:[["A=",{outputs:[["A>=B","boolean"]],title:"A>=B"});p.registerSearchboxExtra("math/compare","<=",{outputs:[["A<=B","boolean"]],title:"A<=B"});a.values="> < == != <= >= || &&".split(" ");a["@OP"]={type:"enum", +"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", +"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 e(){this.addInput("v","number");this.addOutput("sin","number");this.addProperty("amplitude",1);this.addProperty("offset",0);this.bgImageUrl="nodes/imgs/icon-sin.png"} +function d(){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"]]); +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;ba&&(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;gd);++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;0this._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;cb&&(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;dB":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"]]};q.registerNodeType("math/compare",H);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=",{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=":c=a>=b;break;case "||":c=a||b;break;case "&&":c=a&&b}this.setOutputData(0,c);this.setOutputData(1,!c)};p.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))};p.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)};p.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;cXY";k.desc="vector 2 to components";k.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&(this.setOutputData(0,a[0]),this.setOutputData(1,a[1]))};p.registerNodeType("math3d/vec2-to-xy", -k);m.title="XY->Vec2";m.desc="components to vector2";m.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)};p.registerNodeType("math3d/xy-to-vec2",m);l.title="Vec3->XYZ";l.desc="vector 3 to components";l.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]))}; -p.registerNodeType("math3d/vec3-to-xyz",l);q.title="XYZ->Vec3";q.desc="components to vector3";q.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)};p.registerNodeType("math3d/xyz-to-vec3",q);u.title="Vec4->XYZW";u.desc="vector 4 to components";u.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]))};p.registerNodeType("math3d/vec4-to-xyzw",u);J.title="XYZW->Vec4";J.desc="components to vector4";J.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)};p.registerNodeType("math3d/xyzw-to-vec4",J)})(this); -(function(v){function n(){this.addInput("","string");this.addOutput("table","table");this.addOutput("rows","number");this.addProperty("value","");this.addProperty("separator",",");this._table=null}v=v.LiteGraph;v.wrapFunctionAsNode("string/toString",function(n){if(n&&n.constructor===Object)try{return JSON.stringify(n)}catch(h){}return String(n)},[""],"String");v.wrapFunctionAsNode("string/compare",function(n,h){return n==h},["string","string"],"boolean");v.wrapFunctionAsNode("string/concatenate", -function(n,h){return void 0===n?h:void 0===h?n:n+h},["string","string"],"string");v.wrapFunctionAsNode("string/contains",function(n,h){return void 0===n||void 0===h?!1:-1!=n.indexOf(h)},["string","string"],"boolean");v.wrapFunctionAsNode("string/toUpperCase",function(n){return null!=n&&n.constructor===String?n.toUpperCase():n},["string"],"string");v.wrapFunctionAsNode("string/split",function(n,h){null==h&&(h=this.properties.separator);if(null==n)return[];if(n.constructor===String)return n.split(h|| -" ");if(n.constructor===Array){for(var r=[],t=0;t=":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);e.title="Trigonometry";e.desc="Sin Cos Tan";e.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;cXY";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]))}; +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); +(function(x){function m(){this.addInput("","string");this.addOutput("table","table");this.addOutput("rows","number");this.addProperty("value","");this.addProperty("separator",",");this._table=null}x=x.LiteGraph;x.wrapFunctionAsNode("string/toString",function(m){if(m&&m.constructor===Object)try{return JSON.stringify(m)}catch(l){}return String(m)},[""],"string");x.wrapFunctionAsNode("string/compare",function(m,l){return m==l},["string","string"],"boolean");x.wrapFunctionAsNode("string/concatenate", +function(m,l){return void 0===m?l:void 0===l?m:m+l},["string","string"],"string");x.wrapFunctionAsNode("string/contains",function(m,l){return void 0===m||void 0===l?!1:-1!=m.indexOf(l)},["string","string"],"boolean");x.wrapFunctionAsNode("string/toUpperCase",function(m){return null!=m&&m.constructor===String?m.toUpperCase():m},["string"],"string");x.wrapFunctionAsNode("string/split",function(m,l){null==l&&(l=this.properties.separator);if(null==m)return[];if(m.constructor===String)return m.split(l|| +" ");if(m.constructor===Array){for(var w=[],t=0;t