@ -144,6 +144,10 @@
ctrl _shift _v _paste _connect _unselected _outputs : true , //[true!] allows ctrl + shift + v to paste nodes with the outputs of the unselected nodes connected with the inputs of the newly pasted nodes
// if true, all newly created nodes/links will use string UUIDs for their id fields instead of integers.
// use this if you must have node IDs that are unique across all graphs and subgraphs.
use _uuids : false ,
/ * *
* Register a node class so it can be listed when the user wants to create a new one
* @ method registerNodeType
@ -603,6 +607,13 @@
return target ;
} ,
/ *
* https : //gist.github.com/jed/982883?permalink_comment_id=852670#gistcomment-852670
* /
uuidv4 : function ( ) {
return ( [ 1e7 ] + - 1e3 + - 4e3 + - 8e3 + - 1e11 ) . replace ( /[018]/g , a => ( a ^ Math . random ( ) * 16 >> a / 4 ) . toString ( 16 ) ) ;
} ,
/ * *
* Returns if the types of two slots are compatible ( taking into account wildcards , etc )
* @ method isValidConnection
@ -1407,7 +1418,12 @@
console . warn (
"LiteGraph: there is already a node with this ID, changing it"
) ;
node . id = ++ this . last _node _id ;
if ( LiteGraph . use _uuids ) {
node . id = LiteGraph . uuidv4 ( ) ;
}
else {
node . id = ++ this . last _node _id ;
}
}
if ( this . _nodes . length >= LiteGraph . MAX _NUMBER _OF _NODES ) {
@ -1415,10 +1431,16 @@
}
//give him an id
if ( node . id == null || node . id == - 1 ) {
node . id = ++ this . last _node _id ;
} else if ( this . last _node _id < node . id ) {
this . last _node _id = node . id ;
if ( LiteGraph . use _uuids ) {
if ( node . id == null || node . id == - 1 )
node . id = LiteGraph . uuidv4 ( ) ;
}
else {
if ( node . id == null || node . id == - 1 ) {
node . id = ++ this . last _node _id ;
} else if ( this . last _node _id < node . id ) {
this . last _node _id = node . id ;
}
}
node . graph = this ;
@ -2415,7 +2437,12 @@
enumerable : true
} ) ;
this . id = - 1 ; //not know till not added
if ( LiteGraph . use _uuids ) {
this . id = LiteGraph . uuidv4 ( ) ;
}
else {
this . id = - 1 ; //not know till not added
}
this . type = null ;
//inputs available: array of inputs
@ -2629,6 +2656,11 @@
}
delete data [ "id" ] ;
if ( LiteGraph . use _uuids ) {
data [ "id" ] = LiteGraph . uuidv4 ( )
}
//remove links
node . configure ( data ) ;
@ -3540,8 +3572,8 @@
/ * *
* computes the minimum size of a node according to its inputs and output slots
* @ method computeSize
* @ param { number } minHeight
* @ return { number } the total size
* @ param { vec2 } minHeight
* @ return { vec2 } the total size
* /
LGraphNode . prototype . computeSize = function ( out ) {
if ( this . constructor . size ) {
@ -4279,10 +4311,16 @@
break ;
}
}
var nextId
if ( LiteGraph . use _uuids )
nextId = LiteGraph . uuidv4 ( ) ;
else
nextId = ++ this . graph . last _link _id ;
//create link class
link _info = new LLink (
++ this . graph . last _link _id ,
nextI d,
input . type || output . type ,
this . id ,
slot ,
@ -6023,6 +6061,9 @@ LGraphNode.prototype.executeAction = function(action)
//it wasn't clicked on the links boxes
if ( ! skip _action ) {
var block _drag _node = false ;
if ( node && node . flags && node . flags . pinned ) {
block _drag _node = true ;
}
var pos = [ e . canvasX - node . pos [ 0 ] , e . canvasY - node . pos [ 1 ] ] ;
//widgets
@ -7070,6 +7111,8 @@ LGraphNode.prototype.executeAction = function(action)
var selected _nodes _array = [ ] ;
for ( var i in this . selected _nodes ) {
var node = this . selected _nodes [ i ] ;
if ( node . clonable === false )
continue ;
node . _relative _id = index ;
selected _nodes _array . push ( node ) ;
index += 1 ;
@ -7077,12 +7120,12 @@ LGraphNode.prototype.executeAction = function(action)
for ( var i = 0 ; i < selected _nodes _array . length ; ++ i ) {
var node = selected _nodes _array [ i ] ;
var cloned = node . clone ( ) ;
if ( ! cloned )
{
console . warn ( "node type not found: " + node . type ) ;
continue ;
}
var cloned = node . clone ( ) ;
if ( ! cloned )
{
console . warn ( "node type not found: " + node . type ) ;
continue ;
}
clipboard _info . nodes . push ( cloned . serialize ( ) ) ;
if ( node . inputs && node . inputs . length ) {
for ( var j = 0 ; j < node . inputs . length ; ++ j ) {
@ -9952,7 +9995,7 @@ LGraphNode.prototype.executeAction = function(action)
break ;
case "slider" :
var old _value = w . value ;
var nvalue = Math . clamp ( ( x - 15 ) / ( widget _width - 30 ) , 0 , 1 ) ;
var nvalue = clamp ( ( x - 15 ) / ( widget _width - 30 ) , 0 , 1 ) ;
if ( w . options . read _only ) break ;
w . value = w . options . min + ( w . options . max - w . options . min ) * nvalue ;
if ( old _value != w . value ) {
@ -12949,7 +12992,7 @@ LGraphNode.prototype.executeAction = function(action)
var newSelected = { } ;
var fApplyMultiNode = function ( node ) {
if ( node . clonable == false ) {
if ( node . clonable == = false ) {
return ;
}
var newnode = node . clone ( ) ;
@ -13344,82 +13387,6 @@ LGraphNode.prototype.executeAction = function(action)
} ;
//API *************************************************
//like rect but rounded corners
if ( typeof ( window ) != "undefined" && window . CanvasRenderingContext2D && ! window . CanvasRenderingContext2D . prototype . roundRect ) {
window . CanvasRenderingContext2D . prototype . roundRect = function (
x ,
y ,
w ,
h ,
radius ,
radius _low
) {
var top _left _radius = 0 ;
var top _right _radius = 0 ;
var bottom _left _radius = 0 ;
var bottom _right _radius = 0 ;
if ( radius === 0 )
{
this . rect ( x , y , w , h ) ;
return ;
}
if ( radius _low === undefined )
radius _low = radius ;
//make it compatible with official one
if ( radius != null && radius . constructor === Array )
{
if ( radius . length == 1 )
top _left _radius = top _right _radius = bottom _left _radius = bottom _right _radius = radius [ 0 ] ;
else if ( radius . length == 2 )
{
top _left _radius = bottom _right _radius = radius [ 0 ] ;
top _right _radius = bottom _left _radius = radius [ 1 ] ;
}
else if ( radius . length == 4 )
{
top _left _radius = radius [ 0 ] ;
top _right _radius = radius [ 1 ] ;
bottom _left _radius = radius [ 2 ] ;
bottom _right _radius = radius [ 3 ] ;
}
else
return ;
}
else //old using numbers
{
top _left _radius = radius || 0 ;
top _right _radius = radius || 0 ;
bottom _left _radius = radius _low || 0 ;
bottom _right _radius = radius _low || 0 ;
}
//top right
this . moveTo ( x + top _left _radius , y ) ;
this . lineTo ( x + w - top _right _radius , y ) ;
this . quadraticCurveTo ( x + w , y , x + w , y + top _right _radius ) ;
//bottom right
this . lineTo ( x + w , y + h - bottom _right _radius ) ;
this . quadraticCurveTo (
x + w ,
y + h ,
x + w - bottom _right _radius ,
y + h
) ;
//bottom left
this . lineTo ( x + bottom _right _radius , y + h ) ;
this . quadraticCurveTo ( x , y + h , x , y + h - bottom _left _radius ) ;
//top left
this . lineTo ( x , y + bottom _left _radius ) ;
this . quadraticCurveTo ( x , y , x + top _left _radius , y ) ;
} ;
} //if
function compareObjects ( a , b ) {
for ( var i in a ) {
if ( a [ i ] != b [ i ] ) {
@ -14148,10 +14115,10 @@ LGraphNode.prototype.executeAction = function(action)
return ;
}
if ( ! is _edge _point ) //not edges
point [ 0 ] = Math . clamp ( x , 0 , 1 ) ;
point [ 0 ] = clamp ( x , 0 , 1 ) ;
else
point [ 0 ] = s == 0 ? 0 : 1 ;
point [ 1 ] = 1.0 - Math . clamp ( y , 0 , 1 ) ;
point [ 1 ] = 1.0 - clamp ( y , 0 , 1 ) ;
points . sort ( function ( a , b ) { return a [ 0 ] - b [ 0 ] ; } ) ;
this . selected = points . indexOf ( point ) ;
this . must _update = true ;
@ -14299,10 +14266,11 @@ LGraphNode.prototype.executeAction = function(action)
return oDOM . removeEventListener ( sEvent , fCall , capture ) ;
}
}
Math . clamp = function ( v , a , b ) {
function clamp ( v , a , b ) {
return a > v ? a : b < v ? b : v ;
} ;
global . clamp = clamp ;
if ( typeof window != "undefined" && ! window [ "requestAnimationFrame" ] ) {
window . requestAnimationFrame =
@ -14316,6 +14284,13 @@ LGraphNode.prototype.executeAction = function(action)
if ( typeof exports != "undefined" ) {
exports . LiteGraph = this . LiteGraph ;
exports . LGraph = this . LGraph ;
exports . LLink = this . LLink ;
exports . LGraphNode = this . LGraphNode ;
exports . LGraphGroup = this . LGraphGroup ;
exports . DragAndScale = this . DragAndScale ;
exports . LGraphCanvas = this . LGraphCanvas ;
exports . ContextMenu = this . ContextMenu ;
}