lexgui 0.6.3 → 0.6.4

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.
@@ -291,7 +291,7 @@ class TimeBar {
291
291
  this.canvas.height = size[1];
292
292
 
293
293
  let newWidth = size[0] - this.offset * 2;
294
- newWidth = newWidth < 0.00001 ? 0.00001 : newWidth; // actual with of the line = canvas.width - offsetleft - offsetRight
294
+ newWidth = newWidth < 0.00001 ? 0.00001 : newWidth; // actual width of the line = canvas.width - offsetleft - offsetRight
295
295
  const startRatio = (this.startX - this.offset) / this.lineWidth;
296
296
  const currentRatio = (this.currentX - this.offset) / this.lineWidth;
297
297
  const endRatio = (this.endX - this.offset) / this.lineWidth;
@@ -334,7 +334,8 @@ class VideoEditor {
334
334
  this.cropArea.append(this.brCrop);
335
335
 
336
336
  this.crop = options.crop;
337
-
337
+ this.dragOffsetX = 0;
338
+ this.dragOffsetY = 0;
338
339
  // Create video element and load it
339
340
  let video = this.video = options.video ?? document.createElement( 'video' );
340
341
  this.video.loop = true;
@@ -390,7 +391,7 @@ class VideoEditor {
390
391
  this.video.pause();
391
392
  }
392
393
  this.controlsPanelLeft.refresh();
393
- }, { width: '40px', icon: (this.playing ? 'Pause' : 'Play') });
394
+ }, { width: '40px', icon: (this.playing ? 'Pause@solid' : 'Play@solid'), className: "justify-center"});
394
395
 
395
396
  this.controlsPanelLeft.addLabel(this.startTimeString, {width: 50});
396
397
  this.controlsPanelLeft.endLine();
@@ -401,7 +402,7 @@ class VideoEditor {
401
402
 
402
403
  this.controlsPanelLeft.refresh();
403
404
  controlsLeft.root.style.minWidth = 'fit-content';
404
- controlsLeft.attach(this.controlsPanelLeft);
405
+ controlsLeft.root.classList.add(); controlsLeft.attach(this.controlsPanelLeft);
405
406
 
406
407
  // Create right controls panel (ens time)
407
408
  this.controlsPanelRight = new LX.Panel({className: 'lexcontrolspanel'});
@@ -424,6 +425,9 @@ class VideoEditor {
424
425
  bottomArea.setSize([videoArea.root.clientWidth, 40]);
425
426
  let availableWidth = this.controlsArea.root.clientWidth - controlsLeft.root.clientWidth - controlsRight.root.clientWidth;
426
427
  this.timebar.resize([availableWidth, timeBarArea.root.clientHeight]);
428
+ this.dragCropArea( { clientX: -1, clientY: -1 } );
429
+ this.resizeCropArea( { clientX: window.screen.width, clientY: window.screen.height } );
430
+
427
431
  })
428
432
 
429
433
  this.onKeyUp = (event) => {
@@ -493,9 +497,9 @@ class VideoEditor {
493
497
 
494
498
  this.cropArea.addEventListener('mousedown', (event) => {
495
499
 
496
- const rect = this.cropArea.getBoundingClientRect();
497
-
500
+
498
501
  if (event.target === this.cropArea) {
502
+ const rect = this.cropArea.getBoundingClientRect();
499
503
  this.isDragging = true;
500
504
 
501
505
  this.dragOffsetX = event.clientX - rect.left;
@@ -508,83 +512,84 @@ class VideoEditor {
508
512
  handle.addEventListener('mousedown', (e) => {
509
513
 
510
514
  e.stopPropagation();
511
- this.resizeHandle = handle.classList[1];
512
- this.isResizing = true;
515
+ if (handle.classList[1] === 'br') {
516
+ this.isResizing = true;
517
+ }
513
518
  });
514
519
  });
515
520
  }
516
521
 
517
522
  resizeCropArea(event) {
518
523
 
519
- const rect = this.cropArea.getBoundingClientRect();
520
-
521
524
  const mouseX = event.clientX;
522
525
  const mouseY = event.clientY;
523
526
 
524
- if (this.resizeHandle === 'br') {
525
-
526
- const nodes = this.cropArea.parentElement.childNodes;
527
+ const isCropHidden = this.cropArea.classList.contains("hidden");
528
+ const nodes = this.cropArea.parentElement.childNodes;
529
+
530
+ const rectCrop = this.cropArea.getBoundingClientRect();
531
+ const rectVideo = this.video.getBoundingClientRect();
532
+ let width = Math.max( 0, Math.min( mouseX - rectCrop.left, rectVideo.width ) );
533
+ let height = Math.max( 0, Math.min( mouseY - rectCrop.top, rectVideo.height ) );
534
+ if ( (rectCrop.left + width) > rectVideo.right ){
535
+ width = Math.min( rectVideo.width, rectVideo.right - rectCrop.left);
536
+ }
537
+ if ( (rectCrop.top + height) > rectVideo.bottom ){
538
+ height = Math.min( rectVideo.height, rectVideo.bottom - rectCrop.top);
539
+ }
527
540
 
541
+ if ( !isCropHidden ){
528
542
  for( let i = 0; i < nodes.length; i++ ) {
529
- if( nodes[i] != this.cropArea ) {
530
- const rectEl = nodes[i].getBoundingClientRect();
531
- let width = mouseX - rect.left;
532
- let height = mouseY - rect.top;
533
-
534
- if( rect.x + width > rectEl.right ) {
535
- width = rectEl.right - rect.x;
536
- }
537
-
538
- if( rect.y + height > rectEl.bottom ) {
539
- height = rectEl.bottom - rect.y;
540
- }
541
-
542
- this.cropArea.style.width = width + "px";
543
- this.cropArea.style.height = height + "px";
544
-
545
- nodes[i].style.webkitMask = `linear-gradient(#000 0 0) ${rect.x - rectEl.left}px ${ rect.y - rectEl.top }px / ${width}px ${height}px, linear-gradient(rgba(0, 0, 0, 0.3) 0 0)`;
543
+ if( nodes[i] != this.cropArea ) {
544
+ const rectEl = nodes[i].getBoundingClientRect();
545
+ nodes[i].style.webkitMask = `linear-gradient(#000 0 0) ${rectCrop.x - rectEl.left}px ${ rectCrop.y - rectEl.top }px / ${width}px ${height}px, linear-gradient(rgba(0, 0, 0, 0.3) 0 0)`;
546
546
  nodes[i].style.webkitMaskRepeat = 'no-repeat';
547
547
  }
548
548
  }
549
549
  }
550
+
551
+ this.cropArea.style.width = width + "px";
552
+ this.cropArea.style.height = height + "px";
550
553
  }
551
554
 
552
555
  dragCropArea( event ) {
553
556
  const rectVideo = this.video.getBoundingClientRect();
557
+ const rectCrop = this.cropArea.getBoundingClientRect();
554
558
 
555
559
  let x = event.clientX - this.dragOffsetX;
556
560
  let y = event.clientY - this.dragOffsetY;
557
561
 
558
- if(x < rectVideo.left ) {
562
+ if( x < rectVideo.left ) {
559
563
  x = rectVideo.left;
560
564
  }
561
565
 
562
- if( x + this.cropArea.clientWidth > rectVideo.right ) {
563
- x = rectVideo.right - this.cropArea.clientWidth;
566
+ if( x + rectCrop.width > rectVideo.right ) {
567
+ x = Math.max( rectVideo.left, rectVideo.right - rectCrop.width);
564
568
  }
565
569
 
566
- if(y < rectVideo.top ) {
570
+ if( y < rectVideo.top ) {
567
571
  y = rectVideo.top;
568
572
  }
569
573
 
570
- if( y + this.cropArea.clientHeight > rectVideo.bottom ) {
571
- y = rectVideo.bottom - this.cropArea.clientHeight;
574
+ if( y + rectCrop.height > rectVideo.bottom ) {
575
+ y = Math.max( rectVideo.top, rectVideo.bottom - rectCrop.height );
572
576
  }
573
577
 
574
- const parentRect = this.cropArea.parentElement.getBoundingClientRect();
578
+ if ( !this.cropArea.classList.contains("hidden") ){
579
+ const nodes = this.cropArea.parentElement.childNodes;
580
+ for( let i = 0; i < nodes.length; i++ ) {
581
+ if( nodes[i] != this.cropArea ) {
582
+ const rectEl = nodes[i].getBoundingClientRect();
583
+ nodes[i].style.webkitMask = `linear-gradient(#000 0 0) ${x - rectEl.left}px ${y - rectEl.top}px / ${rectCrop.width}px ${rectCrop.height}px, linear-gradient(rgba(0, 0, 0, 0.3) 0 0)`;
584
+ nodes[i].style.webkitMaskRepeat = 'no-repeat';
585
+ }
586
+ }
587
+ }
575
588
 
589
+ const parentRect = this.cropArea.parentElement.getBoundingClientRect();
576
590
  this.cropArea.style.left = x - parentRect.left + "px";
577
591
  this.cropArea.style.top = y - parentRect.top + "px";
578
592
 
579
- const nodes = this.cropArea.parentElement.childNodes;
580
-
581
- for( let i = 0; i < nodes.length; i++ ) {
582
- if( nodes[i] != this.cropArea ) {
583
- const rectEl = nodes[i].getBoundingClientRect();
584
- nodes[i].style.webkitMask = `linear-gradient(#000 0 0) ${x - rectEl.left}px ${y - rectEl.top}px / ${this.cropArea.clientWidth}px ${this.cropArea.clientHeight}px, linear-gradient(rgba(0, 0, 0, 0.3) 0 0)`;
585
- nodes[i].style.webkitMaskRepeat = 'no-repeat';
586
- }
587
- }
588
593
  }
589
594
 
590
595
  async _loadVideo( options = {} ) {
@@ -616,10 +621,13 @@ class VideoEditor {
616
621
 
617
622
  this.cropArea.style.height = this.video.clientHeight + "px";
618
623
  this.cropArea.style.width = this.video.clientWidth + "px";
624
+ this.resizeCropArea( { clientX: window.screen.width, clientY: window.screen.height } );
619
625
  this.dragCropArea( { clientX: -1, clientY: -1 } );
620
626
 
621
627
  if( this.crop ) {
622
628
  this.showCropArea();
629
+ }else{
630
+ this.hideCropArea();
623
631
  }
624
632
 
625
633
  window.addEventListener( "keyup", this.onKeyUp);
@@ -731,10 +739,28 @@ class VideoEditor {
731
739
 
732
740
  showCropArea ( ) {
733
741
  this.cropArea.classList.remove("hidden");
742
+
743
+ const nodes = this.cropArea.parentElement.childNodes;
744
+ const rect = this.cropArea.getBoundingClientRect();
745
+ for( let i = 0; i < nodes.length; i++ ) {
746
+ if( nodes[i] != this.cropArea ) {
747
+ const rectEl = nodes[i].getBoundingClientRect();
748
+ nodes[i].style.webkitMask = `linear-gradient(#000 0 0) ${rect.left - rectEl.left}px ${rect.top - rectEl.top}px / ${rect.width}px ${rect.height}px, linear-gradient(rgba(0, 0, 0, 0.3) 0 0)`;
749
+ nodes[i].style.webkitMaskRepeat = 'no-repeat';
750
+ }
751
+ }
734
752
  }
735
753
 
736
754
  hideCropArea ( ) {
737
755
  this.cropArea.classList.add("hidden");
756
+
757
+ const nodes = this.cropArea.parentElement.childNodes;
758
+ for( let i = 0; i < nodes.length; i++ ) {
759
+ if( nodes[i] != this.cropArea ) {
760
+ nodes[i].style.webkitMask = "";
761
+ nodes[i].style.webkitMaskRepeat = 'no-repeat';
762
+ }
763
+ }
738
764
  }
739
765
 
740
766
  showControls ( ) {