lexgui 0.1.32 → 0.1.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/lexgui.js CHANGED
@@ -12,7 +12,7 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
12
12
  */
13
13
 
14
14
  var LX = global.LX = {
15
- version: "0.1.32",
15
+ version: "0.1.34",
16
16
  ready: false,
17
17
  components: [], // specific pre-build components
18
18
  signals: {} // events and triggers
@@ -25,8 +25,11 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
25
25
  LX.MOUSE_DOUBLE_CLICK = 2;
26
26
  LX.MOUSE_TRIPLE_CLICK = 3;
27
27
 
28
- function clamp (num, min, max) { return Math.min(Math.max(num, min), max) }
29
- function round(num, n) { return +num.toFixed(n); }
28
+ LX.CURVE_MOVEOUT_CLAMP = 0;
29
+ LX.CURVE_MOVEOUT_DELETE = 1;
30
+
31
+ function clamp( num, min, max ) { return Math.min( Math.max( num, min ), max ); }
32
+ function round( num, n ) { return +num.toFixed( n ); }
30
33
 
31
34
  function getSupportedDOMName( string )
32
35
  {
@@ -746,6 +749,13 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
746
749
  if(overlay)
747
750
  {
748
751
  this.root.classList.add("overlay-" + overlay);
752
+
753
+ if( options.draggable )
754
+ makeDraggable( root );
755
+
756
+ if( options.resizeable ) {
757
+ root.classList.add("resizeable");
758
+ }
749
759
 
750
760
  if(options.resize)
751
761
  {
@@ -3231,6 +3241,10 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
3231
3241
  {
3232
3242
  let domName = document.createElement('div');
3233
3243
  domName.className = "lexwidgetname";
3244
+ if( options.justifyName )
3245
+ {
3246
+ domName.classList.add( "float-" + options.justifyName );
3247
+ }
3234
3248
  domName.innerHTML = name || "";
3235
3249
  domName.title = options.title ?? domName.innerHTML;
3236
3250
  domName.style.width = options.nameWidth || LX.DEFAULT_NAME_WIDTH;
@@ -3536,9 +3550,10 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
3536
3550
  * placeholder: Add input placeholder
3537
3551
  * trigger: Choose onchange trigger (default, input) [default]
3538
3552
  * inputWidth: Width of the text input
3539
- * float: Justify text
3540
3553
  * skipReset: Don't add the reset value button when value changes
3541
- */
3554
+ * float: Justify input text content
3555
+ * justifyName: Justify name content
3556
+ */
3542
3557
 
3543
3558
  addText( name, value, callback, options = {} ) {
3544
3559
 
@@ -4021,37 +4036,39 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
4021
4036
 
4022
4037
  addDropdown( name, values, value, callback, options = {} ) {
4023
4038
 
4024
- let widget = this.create_widget(name, Widget.DROPDOWN, options);
4039
+ let widget = this.create_widget( name, Widget.DROPDOWN, options );
4040
+
4025
4041
  widget.onGetValue = () => {
4026
- return element.querySelector("li.selected").getAttribute('value');
4042
+ return element.querySelector( "li.selected" ).getAttribute( 'value' );
4027
4043
  };
4044
+
4028
4045
  widget.onSetValue = ( newValue, skipCallback ) => {
4029
- let btn = element.querySelector(".lexwidgetname .lexicon");
4030
- if(btn) btn.style.display = (newValue != wValue.iValue ? "block" : "none");
4046
+ let btn = element.querySelector( ".lexwidgetname .lexicon" );
4047
+ if( btn ) btn.style.display = ( newValue != wValue.iValue ? "block" : "none" );
4031
4048
  value = newValue;
4032
- list.querySelectorAll('li').forEach( e => { if( e.getAttribute('value') == value ) e.click() } );
4033
- if( !skipCallback ) this._trigger( new IEvent(name, value, null), callback );
4049
+ list.querySelectorAll( 'li' ).forEach( e => { if( e.getAttribute('value') == value ) e.click() } );
4050
+ if( !skipCallback ) this._trigger( new IEvent( name, value, null ), callback );
4034
4051
  };
4035
4052
 
4036
4053
  let element = widget.domEl;
4037
4054
  let that = this;
4038
4055
 
4039
4056
  // Add reset functionality
4040
- if(widget.name && !(options.skipReset ?? false))
4057
+ if(widget.name && !( options.skipReset ?? false ))
4041
4058
  {
4042
- Panel._add_reset_property(element.domName, function() {
4059
+ Panel._add_reset_property( element.domName, function() {
4043
4060
  value = wValue.iValue;
4044
- list.querySelectorAll('li').forEach( e => { if( e.getAttribute('value') == value ) e.click() } );
4061
+ list.querySelectorAll( 'li' ).forEach( e => { if( e.getAttribute('value') == value ) e.click() } );
4045
4062
  this.style.display = "none";
4046
4063
  });
4047
4064
  }
4048
4065
 
4049
- let container = document.createElement('div');
4066
+ let container = document.createElement( 'div' );
4050
4067
  container.className = "lexdropdown";
4051
4068
  container.style.width = options.inputWidth || "calc( 100% - " + LX.DEFAULT_NAME_WIDTH + ")";
4052
-
4069
+
4053
4070
  // Add widget value
4054
- let wValue = document.createElement('div');
4071
+ let wValue = document.createElement( 'div' );
4055
4072
  wValue.className = "lexdropdown lexoption";
4056
4073
  wValue.name = name;
4057
4074
  wValue.iValue = value;
@@ -4062,14 +4079,15 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
4062
4079
 
4063
4080
  this.queue(container);
4064
4081
 
4065
- let selectedOption = this.addButton(null, buttonName, (value, event) => {
4082
+ let selectedOption = this.addButton( null, buttonName, (value, event) => {
4066
4083
  if( list.unfocus_event ) {
4067
4084
  delete list.unfocus_event;
4068
4085
  return;
4069
4086
  }
4070
- element.querySelector(".lexoptions").style.top = (selectedOption.offsetTop + selectedOption.offsetHeight) + 'px';
4071
- element.querySelector(".lexoptions").style.width = (event.currentTarget.clientWidth) + 'px';
4072
- element.querySelector(".lexoptions").toggleAttribute('hidden');
4087
+ const topPosition = selectedOption.getBoundingClientRect().y;
4088
+ list.style.top = (topPosition + selectedOption.offsetHeight) + 'px';
4089
+ list.style.width = (event.currentTarget.clientWidth) + 'px';
4090
+ list.toggleAttribute('hidden');
4073
4091
  list.focus();
4074
4092
  }, { buttonClass: 'array', skipInlineCount: true });
4075
4093
 
@@ -4213,7 +4231,14 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
4213
4231
  * @param {Function} callback Callback function on change
4214
4232
  * @param {*} options:
4215
4233
  * skipReset: Don't add the reset value button when value changes
4216
- */
4234
+ * bgColor: Widget background color
4235
+ * pointsColor: Curve points color
4236
+ * lineColor: Curve line color
4237
+ * noOverlap: Points do not overlap, replacing themselves if necessary
4238
+ * allowAddValues: Support adding values on click
4239
+ * smooth: Curve smoothness
4240
+ * moveOutAction: Clamp or delete points moved out of the curve (LX.CURVE_MOVEOUT_CLAMP, LX.CURVE_MOVEOUT_DELETE)
4241
+ */
4217
4242
 
4218
4243
  addCurve( name, values, callback, options = {} ) {
4219
4244
 
@@ -4223,34 +4248,36 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
4223
4248
 
4224
4249
  let that = this;
4225
4250
  let widget = this.create_widget(name, Widget.CURVE, options);
4251
+
4226
4252
  widget.onGetValue = () => {
4227
- return JSON.parse(JSON.stringify(curve_instance.element.value));
4253
+ return JSON.parse(JSON.stringify(curveInstance.element.value));
4228
4254
  };
4255
+
4229
4256
  widget.onSetValue = ( newValue, skipCallback ) => {
4230
- let btn = element.querySelector(".lexwidgetname .lexicon");
4231
- if(btn) btn.style.display = (newValue != curve_instance.element.value ? "block" : "none");
4232
- curve_instance.element.value = JSON.parse(JSON.stringify(newValue));
4233
- curve_instance.redraw();
4234
- if( !skipCallback ) that._trigger( new IEvent(name, curve_instance.element.value, null), callback );
4257
+ let btn = element.querySelector( ".lexwidgetname .lexicon" );
4258
+ if( btn ) btn.style.display = ( newValue != curveInstance.element.value ? "block" : "none" );
4259
+ curveInstance.element.value = JSON.parse( JSON.stringify( newValue ) );
4260
+ curveInstance.redraw();
4261
+ if( !skipCallback ) that._trigger( new IEvent( name, curveInstance.element.value, null ), callback );
4235
4262
  };
4236
4263
 
4237
4264
  let element = widget.domEl;
4238
- let defaultValues = JSON.parse(JSON.stringify(values));
4265
+ let defaultValues = JSON.parse( JSON.stringify( values ) );
4239
4266
 
4240
4267
  // Add reset functionality
4241
4268
  if( !(options.skipReset ?? false) )
4242
4269
  {
4243
4270
  Panel._add_reset_property(element.domName, function(e) {
4244
4271
  this.style.display = "none";
4245
- curve_instance.element.value = JSON.parse(JSON.stringify(defaultValues));
4246
- curve_instance.redraw();
4247
- that._trigger( new IEvent(name, curve_instance.element.value, e), callback );
4272
+ curveInstance.element.value = JSON.parse( JSON.stringify( defaultValues ) );
4273
+ curveInstance.redraw();
4274
+ that._trigger( new IEvent( name, curveInstance.element.value, e ), callback );
4248
4275
  });
4249
4276
  }
4250
4277
 
4251
4278
  // Add widget value
4252
4279
 
4253
- var container = document.createElement('div');
4280
+ var container = document.createElement( 'div' );
4254
4281
  container.className = "lexcurve";
4255
4282
  container.style.width = "calc( 100% - " + LX.DEFAULT_NAME_WIDTH + ")";
4256
4283
 
@@ -4259,16 +4286,18 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
4259
4286
  if(btn) btn.style.display = (v != defaultValues ? "block" : "none");
4260
4287
  that._trigger( new IEvent(name, v, e), callback );
4261
4288
  };
4289
+
4262
4290
  options.name = name;
4263
- let curve_instance = new Curve(this, values, options);
4264
- container.appendChild(curve_instance.element);
4265
- element.appendChild(container);
4291
+
4292
+ let curveInstance = new Curve( this, values, options );
4293
+ container.appendChild( curveInstance.element );
4294
+ element.appendChild( container );
4266
4295
 
4267
4296
  // Resize
4268
- curve_instance.canvas.width = container.offsetWidth;
4269
- curve_instance.redraw();
4270
- widget.onresize = curve_instance.redraw.bind(curve_instance);
4271
- widget.curve_instance = curve_instance;
4297
+ curveInstance.canvas.width = container.offsetWidth;
4298
+ curveInstance.redraw();
4299
+ widget.onresize = curveInstance.redraw.bind( curveInstance );
4300
+ widget.curveInstance = curveInstance;
4272
4301
  return widget;
4273
4302
  }
4274
4303
 
@@ -4717,19 +4746,19 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
4717
4746
  flag.id = "checkbox"+simple_guidGenerator();
4718
4747
  flag.innerHTML = "<a class='fa-solid fa-check' style='display: " + (flag.value ? "block" : "none") + "'></a>";
4719
4748
 
4720
- if(options.disabled) {
4749
+ if( options.disabled ) {
4721
4750
  flag.disabled = true;
4722
4751
  toggle.className += " disabled";
4723
4752
  }
4724
4753
 
4725
- toggle.appendChild(flag);
4754
+ toggle.appendChild( flag );
4726
4755
 
4727
- let value_name = document.createElement('span');
4756
+ let value_name = document.createElement( 'span' );
4728
4757
  value_name.id = "checkboxtext";
4729
4758
  value_name.innerHTML = "On";
4730
4759
 
4731
- container.appendChild(toggle);
4732
- container.appendChild(value_name);
4760
+ container.appendChild( toggle );
4761
+ container.appendChild( value_name );
4733
4762
 
4734
4763
  toggle.addEventListener( "click" , e => {
4735
4764
 
@@ -4737,7 +4766,7 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
4737
4766
  if( flag.disabled )
4738
4767
  return;
4739
4768
 
4740
- const skipCallback = e.detail;
4769
+ const skipCallback = ( e.detail.constructor == Number ? null : e.detail );
4741
4770
 
4742
4771
  let check = toggle.querySelector( ".checkbox a" );
4743
4772
 
@@ -6392,78 +6421,80 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
6392
6421
 
6393
6422
  class Curve {
6394
6423
 
6395
- constructor(panel, value, options = {}) {
6396
-
6397
- let element = document.createElement("div");
6398
- element.className = "curve " + (options.className ? options.className : "");
6424
+ constructor( panel, value, options = {} ) {
6425
+
6426
+ let element = document.createElement( "div" );
6427
+ element.className = "curve " + ( options.className ? options.className : "" );
6399
6428
  element.style.minHeight = "50px";
6400
6429
  element.style.width = options.width || "100%";
6401
-
6402
- element.bgcolor = options.bgcolor || LX.getThemeColor("global-dark-background");
6403
- element.pointscolor = options.pointscolor || LX.getThemeColor("global-selected-light");
6404
- element.linecolor = options.linecolor || "#555";
6405
-
6406
- element.value = value || [];
6407
- element.xrange = options.xrange || [0,1]; //min,max
6408
- element.yrange = options.yrange || [0,1]; //min,max
6409
- element.defaulty = options.defaulty != null ? options.defaulty : 0.0;
6410
- element.no_trespassing = options.no_trespassing || false;
6411
- element.show_samples = options.show_samples || 0;
6412
- element.allow_add_values = options.allow_add_values ?? true;
6413
- element.draggable_x = options.draggable_x ?? true;
6414
- element.draggable_y = options.draggable_y ?? true;
6415
- element.smooth = (options.smooth && typeof(options.smooth) == 'number' ? options.smooth : 0.3) || false;
6416
- element.options = options;
6417
6430
  element.style.minWidth = "50px";
6418
6431
  element.style.minHeight = "20px";
6419
-
6432
+
6433
+ element.bgcolor = options.bgColor || LX.getThemeColor( "global-dark-background" );
6434
+ element.pointscolor = options.pointsColor || LX.getThemeColor( "global-selected-light" );
6435
+ element.linecolor = options.lineColor || "#555";
6436
+ element.value = value || [];
6437
+ element.xrange = options.xrange || [ 0, 1 ]; // min, max
6438
+ element.yrange = options.yrange || [ 0, 1 ]; // min, max
6439
+ element.defaulty = options.defaulty != null ? options.defaulty : 0.0;
6440
+ element.no_overlap = options.noOverlap || false;
6441
+ element.show_samples = options.showSamples || 0;
6442
+ element.allow_add_values = options.allowAddValues ?? true;
6443
+ element.draggable_x = options.draggableX ?? true;
6444
+ element.draggable_y = options.draggableY ?? true;
6445
+ element.smooth = (options.smooth && typeof( options.smooth ) == 'number' ? options.smooth : 0.3) || false;
6446
+ element.move_out = options.moveOutAction ?? LX.CURVE_MOVEOUT_DELETE;
6447
+
6420
6448
  this.element = element;
6421
-
6422
- let canvas = document.createElement("canvas");
6449
+
6450
+ let canvas = document.createElement( "canvas" );
6423
6451
  canvas.width = options.width || 200;
6424
6452
  canvas.height = options.height || 50;
6425
6453
  element.appendChild( canvas );
6426
6454
  this.canvas = canvas;
6427
-
6428
- element.addEventListener("mousedown", onmousedown);
6429
-
6430
- element.getValueAt = function(x) {
6431
-
6432
- if(x < element.xrange[0] || x > element.xrange[1])
6455
+
6456
+ element.addEventListener( "mousedown", onmousedown );
6457
+
6458
+ element.getValueAt = function( x ) {
6459
+
6460
+ if( x < element.xrange[ 0 ] || x > element.xrange[ 1 ] )
6461
+ {
6433
6462
  return element.defaulty;
6434
-
6435
- var last = [ element.xrange[0], element.defaulty ];
6463
+ }
6464
+
6465
+ var last = [ element.xrange[ 0 ], element.defaulty ];
6436
6466
  var f = 0;
6437
- for(var i = 0; i < element.value.length; i += 1)
6467
+ for( var i = 0; i < element.value.length; i += 1 )
6438
6468
  {
6439
- var v = element.value[i];
6440
- if(x == v[0]) return v[1];
6441
- if(x < v[0])
6469
+ var v = element.value[ i ];
6470
+ if( x == v[ 0 ] ) return v[ 1 ];
6471
+ if( x < v[ 0 ] )
6442
6472
  {
6443
- f = (x - last[0]) / (v[0] - last[0]);
6444
- return last[1] * (1-f) + v[1] * f;
6473
+ f = ( x - last[ 0 ] ) / (v[ 0 ] - last[ 0 ]);
6474
+ return last[ 1 ] * ( 1 - f ) + v[ 1 ] * f;
6445
6475
  }
6476
+
6446
6477
  last = v;
6447
6478
  }
6448
-
6449
- v = [ element.xrange[1], element.defaulty ];
6450
- f = (x - last[0]) / (v[0] - last[0]);
6451
- return last[1] * (1-f) + v[1] * f;
6479
+
6480
+ v = [ element.xrange[ 1 ], element.defaulty ];
6481
+ f = (x - last[ 0 ]) / (v[ 0 ] - last[ 0 ]);
6482
+ return last[ 1 ] * ( 1 - f ) + v[ 1 ] * f;
6452
6483
  }
6453
-
6454
- element.resample = function(samples) {
6455
-
6484
+
6485
+ element.resample = function( samples ) {
6486
+
6456
6487
  var r = [];
6457
- var dx = (element.xrange[1] - element.xrange[0]) / samples;
6488
+ var dx = (element.xrange[1] - element.xrange[ 0 ]) / samples;
6458
6489
  for(var i = element.xrange[0]; i <= element.xrange[1]; i += dx)
6459
6490
  {
6460
6491
  r.push( element.getValueAt(i) );
6461
6492
  }
6462
6493
  return r;
6463
6494
  }
6464
-
6495
+
6465
6496
  element.addValue = function(v) {
6466
-
6497
+
6467
6498
  for(var i = 0; i < element.value; i++) {
6468
6499
  var value = element.value[i];
6469
6500
  if(value[0] < v[0]) continue;
@@ -6471,231 +6502,247 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
6471
6502
  redraw();
6472
6503
  return;
6473
6504
  }
6474
-
6505
+
6475
6506
  element.value.push(v);
6476
6507
  redraw();
6477
6508
  }
6478
-
6509
+
6479
6510
  //value to canvas
6480
6511
  function convert(v) {
6481
6512
  return [ canvas.width * ( v[0] - element.xrange[0])/ (element.xrange[1]),
6482
6513
  canvas.height * (v[1] - element.yrange[0])/ (element.yrange[1])];
6483
- // return [ canvas.width * ( (element.xrange[1] - element.xrange[0]) * v[0] + element.xrange[0]),
6484
- // canvas.height * ((element.yrange[1] - element.yrange[0]) * v[1] + element.yrange[0])];
6485
6514
  }
6486
-
6515
+
6487
6516
  //canvas to value
6488
6517
  function unconvert(v) {
6489
6518
  return [(v[0] * element.xrange[1] / canvas.width + element.xrange[0]),
6490
6519
  (v[1] * element.yrange[1] / canvas.height + element.yrange[0])];
6491
- // return [(v[0] / canvas.width - element.xrange[0]) / (element.xrange[1] - element.xrange[0]),
6492
- // (v[1] / canvas.height - element.yrange[0]) / (element.yrange[1] - element.yrange[0])];
6493
6520
  }
6494
-
6521
+
6495
6522
  var selected = -1;
6496
-
6497
- element.redraw = function(o = {} ) {
6523
+
6524
+ element.redraw = function( o = {} ) {
6498
6525
 
6499
- if(o.value) element.value = o.value;
6500
- if(o.xrange) element.xrange = o.xrange;
6501
- if(o.yrange) element.yrange = o.yrange;
6502
- if(o.smooth) element.smooth = o.smooth;
6526
+ if( o.value ) element.value = o.value;
6527
+ if( o.xrange ) element.xrange = o.xrange;
6528
+ if( o.yrange ) element.yrange = o.yrange;
6529
+ if( o.smooth ) element.smooth = o.smooth;
6503
6530
  var rect = canvas.parentElement.getBoundingClientRect();
6504
- if(canvas.parentElement.parentElement) rect = canvas.parentElement.parentElement.getBoundingClientRect();
6505
- if(rect && canvas.width != rect.width && rect.width && rect.width < 1000)
6531
+ if( canvas.parentElement.parentElement ) rect = canvas.parentElement.parentElement.getBoundingClientRect();
6532
+ if( rect && canvas.width != rect.width && rect.width && rect.width < 1000 )
6533
+ {
6506
6534
  canvas.width = rect.width;
6507
- // if(rect && canvas.height != rect.height && rect.height && rect.height < 1000)
6508
- // canvas.height = rect.height;
6509
-
6510
- var ctx = canvas.getContext("2d");
6511
- ctx.setTransform(1, 0, 0, 1, 0, 0);
6512
- ctx.translate(0,canvas.height);
6513
- ctx.scale(1,-1);
6514
-
6535
+ }
6536
+
6537
+ var ctx = canvas.getContext( "2d" );
6538
+ ctx.setTransform( 1, 0, 0, 1, 0, 0 );
6539
+ ctx.translate( 0, canvas.height );
6540
+ ctx.scale( 1, -1 );
6541
+
6515
6542
  ctx.fillStyle = element.bgcolor;
6516
6543
  ctx.fillRect(0,0,canvas.width,canvas.height);
6517
-
6544
+
6518
6545
  ctx.strokeStyle = element.linecolor;
6519
6546
  ctx.beginPath();
6520
-
6547
+
6521
6548
  //draw line
6522
- var pos = convert([element.xrange[0],element.defaulty]);
6523
- ctx.moveTo( pos[0], pos[1] );
6524
- let values = [pos[0], pos[1]];
6525
-
6549
+ var pos = convert([ element.xrange[ 0 ],element.defaulty ]);
6550
+ ctx.moveTo( pos[ 0 ], pos[ 1 ] );
6551
+ let values = [pos[ 0 ], pos[ 1 ]];
6552
+
6526
6553
  for(var i in element.value) {
6527
6554
  var value = element.value[i];
6528
6555
  pos = convert(value);
6529
- values.push(pos[0]);
6530
- values.push(pos[1]);
6556
+ values.push(pos[ 0 ]);
6557
+ values.push(pos[ 1 ]);
6531
6558
  if(!element.smooth)
6532
- ctx.lineTo( pos[0], pos[1] );
6559
+ ctx.lineTo( pos[ 0 ], pos[ 1 ] );
6533
6560
  }
6534
-
6535
- pos = convert([element.xrange[1],element.defaulty]);
6536
- values.push(pos[0]);
6537
- values.push(pos[1]);
6538
- if(!element.smooth) {
6539
- ctx.lineTo( pos[0], pos[1] );
6561
+
6562
+ pos = convert([ element.xrange[ 1 ], element.defaulty ]);
6563
+ values.push(pos[ 0 ]);
6564
+ values.push(pos[ 1 ]);
6565
+ if( !element.smooth )
6566
+ {
6567
+ ctx.lineTo( pos[ 0 ], pos[ 1 ] );
6540
6568
  ctx.stroke();
6541
- } else {
6542
-
6543
- LX.UTILS.drawSpline(ctx, values, element.smooth);
6544
6569
  }
6545
-
6546
- //draw points
6547
- for(var i = 0; i < element.value.length; i += 1) {
6548
- var value = element.value[i];
6549
- pos = convert(value);
6550
- if(selected == i)
6570
+ else
6571
+ {
6572
+ LX.UTILS.drawSpline( ctx, values, element.smooth );
6573
+ }
6574
+
6575
+ // Draw points
6576
+ for( var i = 0; i < element.value.length; i += 1 ) {
6577
+ var value = element.value[ i ];
6578
+ pos = convert( value );
6579
+ if( selected == i )
6551
6580
  ctx.fillStyle = "white";
6552
6581
  else
6553
6582
  ctx.fillStyle = element.pointscolor;
6554
6583
  ctx.beginPath();
6555
- ctx.arc( pos[0], pos[1], selected == i ? 4 : 3, 0, Math.PI * 2);
6584
+ ctx.arc( pos[ 0 ], pos[ 1 ], selected == i ? 4 : 3, 0, Math.PI * 2);
6556
6585
  ctx.fill();
6557
6586
  }
6558
-
6587
+
6559
6588
  if(element.show_samples) {
6560
6589
  var samples = element.resample(element.show_samples);
6561
6590
  ctx.fillStyle = "#888";
6562
6591
  for(var i = 0; i < samples.length; i += 1)
6563
6592
  {
6564
- var value = [ i * ((element.xrange[1] - element.xrange[0]) / element.show_samples) + element.xrange[0], samples[i] ];
6593
+ var value = [ i * ((element.xrange[ 1 ] - element.xrange[ 0 ]) / element.show_samples) + element.xrange[ 0 ], samples[ i ] ];
6565
6594
  pos = convert(value);
6566
6595
  ctx.beginPath();
6567
- ctx.arc( pos[0], pos[1], 2, 0, Math.PI * 2);
6596
+ ctx.arc( pos[ 0 ], pos[ 1 ], 2, 0, Math.PI * 2);
6568
6597
  ctx.fill();
6569
6598
  }
6570
6599
  }
6571
6600
  }
6572
-
6573
- var last_mouse = [0,0];
6574
-
6575
- function onmousedown(evt) {
6576
- document.addEventListener("mousemove",onmousemove);
6577
- document.addEventListener("mouseup",onmouseup);
6578
-
6601
+
6602
+ var last_mouse = [ 0, 0 ];
6603
+
6604
+ function onmousedown( e ) {
6605
+ document.addEventListener( "mousemove", onmousemove );
6606
+ document.addEventListener( "mouseup", onmouseup );
6607
+
6579
6608
  var rect = canvas.getBoundingClientRect();
6580
- var mousex = evt.clientX - rect.left;
6581
- var mousey = evt.clientY - rect.top;
6582
-
6583
- selected = computeSelected(mousex,canvas.height-mousey);
6584
-
6609
+ var mousex = e.clientX - rect.left;
6610
+ var mousey = e.clientY - rect.top;
6611
+
6612
+ selected = computeSelected( mousex, canvas.height - mousey );
6613
+
6585
6614
  if(selected == -1 && element.allow_add_values) {
6586
- var v = unconvert([mousex,canvas.height-mousey]);
6615
+ var v = unconvert([ mousex, canvas.height-mousey ]);
6587
6616
  element.value.push(v);
6588
6617
  sortValues();
6589
6618
  selected = element.value.indexOf(v);
6590
6619
  }
6591
-
6592
- last_mouse = [mousex,mousey];
6620
+
6621
+ last_mouse = [ mousex, mousey ];
6593
6622
  element.redraw();
6594
- evt.preventDefault();
6595
- evt.stopPropagation();
6623
+ e.preventDefault();
6624
+ e.stopPropagation();
6596
6625
  }
6597
-
6598
- function onmousemove(evt) {
6626
+
6627
+ function onmousemove( e ) {
6628
+
6599
6629
  var rect = canvas.getBoundingClientRect();
6600
- var mousex = evt.clientX - rect.left;
6601
- var mousey = evt.clientY - rect.top;
6602
-
6603
- if(mousex < 0) mousex = 0;
6604
- else if(mousex > canvas.width) mousex = canvas.width;
6605
- if(mousey < 0) mousey = 0;
6606
- else if(mousey > canvas.height) mousey = canvas.height;
6607
-
6608
- //dragging to remove
6609
- if( selected != -1 && distance( [evt.clientX - rect.left, evt.clientY - rect.top], [mousex,mousey] ) > canvas.height * 0.5 )
6630
+ var mousex = e.clientX - rect.left;
6631
+ var mousey = e.clientY - rect.top;
6632
+
6633
+ if( mousex < 0 ) mousex = 0;
6634
+ else if( mousex > canvas.width ) mousex = canvas.width;
6635
+ if( mousey < 0 ) mousey = 0;
6636
+ else if( mousey > canvas.height ) mousey = canvas.height;
6637
+
6638
+ // Dragging to remove
6639
+ const currentMouseDiff = [ e.clientX - rect.left, e.clientY - rect.top ];
6640
+ if( selected != -1 && distance( currentMouseDiff, [ mousex, mousey ] ) > canvas.height * 0.5 )
6610
6641
  {
6611
- element.value.splice(selected,1);
6612
- onmouseup(evt);
6642
+ if( element.move_out == LX.CURVE_MOVEOUT_DELETE)
6643
+ {
6644
+ element.value.splice( selected, 1 );
6645
+ }
6646
+ else
6647
+ {
6648
+ const d = [ currentMouseDiff[ 0 ] - mousex, currentMouseDiff[ 1 ] - mousey ];
6649
+ let value = element.value[ selected ];
6650
+ value[ 0 ] = ( d[ 0 ] == 0.0 ) ? value[ 0 ] : ( d[ 0 ] < 0.0 ? element.xrange[ 1 ] : element.xrange[ 0 ] );
6651
+ value[ 1 ] = ( d[ 1 ] == 0.0 ) ? value[ 1 ] : ( d[ 1 ] < 0.0 ? element.yrange[ 1 ] : element.yrange[ 0 ] );
6652
+ }
6653
+
6654
+ onmouseup( e );
6613
6655
  return;
6614
6656
  }
6615
-
6616
- var dx = element.draggable_x ? last_mouse[0] - mousex : 0;
6617
- var dy = element.draggable_y ? last_mouse[1] - mousey : 0;
6618
- var delta = unconvert([-dx,dy]);
6619
- if(selected != -1) {
6620
- var minx = element.xrange[0];
6621
- var maxx = element.xrange[1];
6622
-
6623
- if(element.no_trespassing)
6657
+
6658
+ var dx = element.draggable_x ? last_mouse[ 0 ] - mousex : 0;
6659
+ var dy = element.draggable_y ? last_mouse[ 1 ] - mousey : 0;
6660
+ var delta = unconvert([ -dx, dy ]);
6661
+
6662
+ if( selected != -1 ) {
6663
+ var minx = element.xrange[ 0 ];
6664
+ var maxx = element.xrange[ 1 ];
6665
+
6666
+ if( element.no_overlap )
6624
6667
  {
6625
- if(selected > 0) minx = element.value[selected-1][0];
6626
- if(selected < (element.value.length-1) ) maxx = element.value[selected+1][0];
6668
+ if( selected > 0) minx = element.value[ selected - 1 ][ 0 ];
6669
+ if( selected < ( element.value.length - 1 ) ) maxx = element.value[ selected + 1 ][ 0 ];
6627
6670
  }
6628
-
6671
+
6629
6672
  var v = element.value[selected];
6630
- v[0] += delta[0];
6631
- v[1] += delta[1];
6632
- if(v[0] < minx) v[0] = minx;
6633
- else if(v[0] > maxx) v[0] = maxx;
6634
- if(v[1] < element.yrange[0]) v[1] = element.yrange[0];
6635
- else if(v[1] > element.yrange[1]) v[1] = element.yrange[1];
6673
+ v[ 0 ] += delta[ 0 ];
6674
+ v[ 1 ] += delta[ 1 ];
6675
+ if(v[ 0 ] < minx) v[ 0 ] = minx;
6676
+ else if(v[ 0 ] > maxx) v[ 0 ] = maxx;
6677
+ if(v[ 1 ] < element.yrange[ 0 ]) v[ 1 ] = element.yrange[ 0 ];
6678
+ else if(v[ 1 ] > element.yrange[ 1 ]) v[ 1 ] = element.yrange[ 1 ];
6636
6679
  }
6637
-
6680
+
6638
6681
  sortValues();
6639
6682
  element.redraw();
6640
- last_mouse[0] = mousex;
6641
- last_mouse[1] = mousey;
6642
- onchange(evt);
6643
-
6644
- evt.preventDefault();
6645
- evt.stopPropagation();
6683
+ last_mouse[ 0 ] = mousex;
6684
+ last_mouse[ 1 ] = mousey;
6685
+ onchange( e );
6686
+
6687
+ e.preventDefault();
6688
+ e.stopPropagation();
6646
6689
  }
6647
-
6648
- function onmouseup(evt) {
6690
+
6691
+ function onmouseup( e ) {
6649
6692
  selected = -1;
6650
6693
  element.redraw();
6651
6694
  document.removeEventListener("mousemove", onmousemove);
6652
6695
  document.removeEventListener("mouseup", onmouseup);
6653
- onchange(evt);
6654
- evt.preventDefault();
6655
- evt.stopPropagation();
6696
+ onchange(e);
6697
+ e.preventDefault();
6698
+ e.stopPropagation();
6656
6699
  }
6657
6700
 
6658
- function onchange(e) {
6659
- if(options.callback)
6660
- options.callback.call(element, element.value, e);
6701
+ function onchange( e ) {
6702
+ if( options.callback )
6703
+ options.callback.call( element, element.value, e );
6661
6704
  }
6662
-
6705
+
6663
6706
  function distance(a,b) { return Math.sqrt( Math.pow(b[0]-a[0],2) + Math.pow(b[1]-a[1],2) ); };
6664
-
6665
- function computeSelected(x,y) {
6666
-
6667
- var min_dist = 100000;
6668
- var max_dist = 8; //pixels
6707
+
6708
+ function computeSelected( x, y ) {
6709
+
6710
+ var minDistance = 100000;
6711
+ var maxDistance = 8; //pixels
6669
6712
  var selected = -1;
6670
- for(var i=0; i < element.value.length; i++)
6713
+ for( var i = 0; i < element.value.length; i++ )
6671
6714
  {
6672
- var value = element.value[i];
6673
- var pos = convert(value);
6674
- var dist = distance([x,y],pos);
6675
- if(dist < min_dist && dist < max_dist)
6715
+ var value = element.value[ i ];
6716
+ var pos = convert( value );
6717
+ var dist = distance( [ x,y ], pos );
6718
+ if( dist < minDistance && dist < maxDistance )
6676
6719
  {
6677
- min_dist = dist;
6720
+ minDistance = dist;
6678
6721
  selected = i;
6679
6722
  }
6680
6723
  }
6681
6724
  return selected;
6682
6725
  }
6683
-
6726
+
6684
6727
  function sortValues() {
6685
6728
  var v = null;
6686
- if(selected != -1)
6687
- v = element.value[selected];
6688
- element.value.sort(function(a,b) { return a[0] - b[0]; });
6689
- if(v)
6690
- selected = element.value.indexOf(v);
6729
+ if( selected != -1 )
6730
+ {
6731
+ v = element.value[ selected ];
6732
+ }
6733
+ element.value.sort(function( a,b ) { return a[ 0 ] - b[ 0 ]; });
6734
+ if( v )
6735
+ {
6736
+ selected = element.value.indexOf( v );
6737
+ }
6691
6738
  }
6692
6739
 
6693
6740
  element.redraw();
6694
6741
  return this;
6695
6742
  }
6696
-
6697
- redraw(options = {}) {
6698
- this.element.redraw(options);
6743
+
6744
+ redraw( options = {} ) {
6745
+ this.element.redraw( options );
6699
6746
  }
6700
6747
  }
6701
6748
 
@@ -6710,7 +6757,8 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
6710
6757
  static ASSET_CLONED = 4;
6711
6758
  static ASSET_DBLCLICKED = 5;
6712
6759
  static ENTER_FOLDER = 6;
6713
-
6760
+ static ASSET_CHECKED = 7;
6761
+
6714
6762
  constructor( type, item, value ) {
6715
6763
  this.type = type || TreeEvent.NONE;
6716
6764
  this.item = item;
@@ -6727,6 +6775,7 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
6727
6775
  case AssetViewEvent.ASSET_CLONED: return "assetview_event_cloned";
6728
6776
  case AssetViewEvent.ASSET_DBLCLICKED: return "assetview_event_dblclicked";
6729
6777
  case AssetViewEvent.ENTER_FOLDER: return "assetview_event_enter_folder";
6778
+ case AssetViewEvent.ASSET_CHECKED: return "assetview_event_checked";
6730
6779
  }
6731
6780
  }
6732
6781
  };
@@ -6750,7 +6799,7 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
6750
6799
  constructor( options = {} ) {
6751
6800
 
6752
6801
  this.rootPath = "https://raw.githubusercontent.com/jxarco/lexgui.js/master/";
6753
- this.layout = AssetView.LAYOUT_CONTENT;
6802
+ this.layout = options.layout ?? AssetView.LAYOUT_CONTENT;
6754
6803
  this.contentPage = 1;
6755
6804
 
6756
6805
  if(options.root_path)
@@ -7066,35 +7115,56 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
7066
7115
  _refreshContent(search_value, filter) {
7067
7116
 
7068
7117
  const is_content_layout = (this.layout == AssetView.LAYOUT_CONTENT); // default
7069
-
7118
+
7070
7119
  this.filter = filter ?? (this.filter ?? "None");
7071
7120
  this.search_value = search_value ?? (this.search_value ?? "");
7072
7121
  this.content.innerHTML = "";
7073
7122
  this.content.className = (is_content_layout ? "lexassetscontent" : "lexassetscontent list");
7074
7123
  let that = this;
7075
-
7124
+
7076
7125
  const add_item = function(item) {
7077
-
7126
+
7078
7127
  const type = item.type.charAt(0).toUpperCase() + item.type.slice(1);
7079
7128
  const extension = getExtension( item.id );
7080
7129
  const is_folder = type === "Folder";
7081
-
7130
+
7082
7131
  let itemEl = document.createElement('li');
7083
7132
  itemEl.className = "lexassetitem " + item.type.toLowerCase();
7084
7133
  itemEl.title = type + ": " + item.id;
7085
7134
  itemEl.tabIndex = -1;
7086
7135
  that.content.appendChild(itemEl);
7087
-
7136
+
7137
+ if(item.selected != undefined) {
7138
+ let span = document.createElement('span');
7139
+ span.className = "lexcheckbox";
7140
+ let checkbox_input = document.createElement('input');
7141
+ checkbox_input.type = "checkbox";
7142
+ checkbox_input.className = "checkbox";
7143
+ checkbox_input.checked = item.selected;
7144
+ checkbox_input.addEventListener('change', (e, v) => {
7145
+ item.selected = !item.selected;
7146
+ if(that.onevent) {
7147
+ const event = new AssetViewEvent(AssetViewEvent.ASSET_CHECKED, e.shiftKey ? [item] : item );
7148
+ event.multiple = !!e.shiftKey;
7149
+ that.onevent( event );
7150
+ }
7151
+ e.stopPropagation();
7152
+ e.stopImmediatePropagation();
7153
+ })
7154
+ span.appendChild(checkbox_input);
7155
+ itemEl.appendChild(span);
7156
+
7157
+ }
7088
7158
  let title = document.createElement('span');
7089
7159
  title.className = "lexassettitle";
7090
7160
  title.innerText = item.id;
7091
7161
  itemEl.appendChild(title);
7092
-
7162
+
7093
7163
  if( !that.skip_preview ) {
7094
-
7164
+
7095
7165
  let preview = null;
7096
7166
  const has_image = item.src && (['png', 'jpg'].indexOf( getExtension( item.src ) ) > -1 || item.src.includes("data:image/") ); // Support b64 image as src
7097
-
7167
+
7098
7168
  if( has_image || is_folder || !is_content_layout)
7099
7169
  {
7100
7170
  preview = document.createElement('img');
@@ -7111,13 +7181,13 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
7111
7181
  let textEl = document.createElement('text');
7112
7182
  preview.appendChild(textEl);
7113
7183
  // If no extension, e.g. Clip, use the type...
7114
- textEl.innerText = extension == item.id ? item.type.toUpperCase() : ("." + extension.toUpperCase());
7115
-
7184
+ textEl.innerText = (!extension || extension == item.id) ? item.type.toUpperCase() : ("." + extension.toUpperCase());
7185
+
7116
7186
  var newLength = textEl.innerText.length;
7117
7187
  var charsPerLine = 2.5;
7118
7188
  var newEmSize = charsPerLine / newLength;
7119
7189
  var textBaseSize = 64;
7120
-
7190
+
7121
7191
  if(newEmSize < 1) {
7122
7192
  var newFontSize = newEmSize * textBaseSize;
7123
7193
  textEl.style.fontSize = newFontSize + "px";
@@ -7125,7 +7195,7 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
7125
7195
  }
7126
7196
  }
7127
7197
  }
7128
-
7198
+
7129
7199
  if( !is_folder )
7130
7200
  {
7131
7201
  let info = document.createElement('span');
@@ -7133,13 +7203,13 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
7133
7203
  info.innerText = type;
7134
7204
  itemEl.appendChild(info);
7135
7205
  }
7136
-
7206
+
7137
7207
  itemEl.addEventListener('click', function(e) {
7138
7208
  e.stopImmediatePropagation();
7139
7209
  e.stopPropagation();
7140
-
7210
+
7141
7211
  const is_double_click = e.detail == LX.MOUSE_DOUBLE_CLICK;
7142
-
7212
+
7143
7213
  if(!is_double_click)
7144
7214
  {
7145
7215
  if(!e.shiftKey)
@@ -7153,14 +7223,14 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
7153
7223
  that._enterFolder( item );
7154
7224
  return;
7155
7225
  }
7156
-
7226
+
7157
7227
  if(that.onevent) {
7158
7228
  const event = new AssetViewEvent(is_double_click ? AssetViewEvent.ASSET_DBLCLICKED : AssetViewEvent.ASSET_SELECTED, e.shiftKey ? [item] : item );
7159
7229
  event.multiple = !!e.shiftKey;
7160
7230
  that.onevent( event );
7161
7231
  }
7162
7232
  });
7163
-
7233
+
7164
7234
  if( that.context_menu )
7165
7235
  {
7166
7236
  itemEl.addEventListener('contextmenu', function(e) {
@@ -7181,32 +7251,32 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
7181
7251
  });
7182
7252
  });
7183
7253
  }
7184
-
7254
+
7185
7255
  itemEl.addEventListener("dragstart", function(e) {
7186
7256
  e.preventDefault();
7187
7257
  }, false );
7188
-
7258
+
7189
7259
  return itemEl;
7190
7260
  }
7191
-
7261
+
7192
7262
  const fr = new FileReader();
7193
-
7263
+
7194
7264
  const filtered_data = this.currentData.filter( _i => {
7195
7265
  return (this.filter != "None" ? _i.type.toLowerCase() == this.filter.toLowerCase() : true) &&
7196
7266
  _i.id.toLowerCase().includes(this.search_value.toLowerCase())
7197
7267
  } );
7198
-
7268
+
7199
7269
  if(filter || search_value) {
7200
7270
  this.contentPage = 1;
7201
7271
  }
7202
7272
  // Show all data if using filters
7203
7273
  const start_index = (this.contentPage - 1) * AssetView.MAX_PAGE_ELEMENTS;
7204
7274
  const end_index = Math.min( start_index + AssetView.MAX_PAGE_ELEMENTS, filtered_data.length );
7205
-
7275
+
7206
7276
  for( let i = start_index; i < end_index; ++i )
7207
7277
  {
7208
7278
  let item = filtered_data[i];
7209
-
7279
+
7210
7280
  if( item.path )
7211
7281
  {
7212
7282
  LX.request({ url: item.path, dataType: 'blob', success: (f) => {