lexgui 0.1.43 → 0.1.45

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.
@@ -243,6 +243,7 @@ class CodeEditor {
243
243
  * skipInfo:
244
244
  * fileExplorer:
245
245
  * allowAddScripts:
246
+ * disableEdition:
246
247
  */
247
248
 
248
249
  constructor( area, options = {} ) {
@@ -363,6 +363,16 @@ class VideoEditor {
363
363
 
364
364
  let [videoArea, controlsArea] = area.split({ type: 'vertical', sizes: ["85%", null], minimizable: false, resize: false });
365
365
  controlsArea.root.classList.add('lexconstrolsarea');
366
+
367
+ this.cropArea = document.createElement("div");
368
+ this.cropArea.id = "cropArea";
369
+ this.cropArea.className = "resize-area hidden"
370
+
371
+ this.brCrop = document.createElement("div");
372
+ this.brCrop.className = " resize-handle br"; // bottom right
373
+ this.cropArea.append(this.brCrop);
374
+
375
+ this.crop = options.crop;
366
376
 
367
377
  // Create video element and load it
368
378
  let video = this.video = options.video ?? document.createElement( 'video' );
@@ -374,10 +384,12 @@ class VideoEditor {
374
384
  }
375
385
  if(options.videoArea) {
376
386
  options.videoArea.root.classList.add("lexvideoeditor");
387
+ options.videoArea.attach(this.cropArea);
377
388
  videoArea.attach(options.videoArea);
378
389
  }
379
390
  else {
380
391
  videoArea.attach(video);
392
+ videoArea.attach(this.cropArea);
381
393
  videoArea.root.classList.add("lexvideoeditor");
382
394
  }
383
395
 
@@ -481,6 +493,10 @@ class VideoEditor {
481
493
 
482
494
  videoArea.onresize = (v) => {
483
495
  bottomArea.setSize([v.width, 40]);
496
+
497
+ const ratio = this.video.clientHeight / this.video.videoHeight;
498
+ this.cropArea.style.height = this.video.clientHeight + "px";
499
+ this.cropArea.style.width = this.video.videoWidth * ratio + "px";
484
500
  }
485
501
 
486
502
  timeBarArea.onresize = (v) => {
@@ -498,13 +514,128 @@ class VideoEditor {
498
514
  if(this.controls) {
499
515
  this.timebar.onMouseUp(event);
500
516
  }
517
+
518
+ if( ( this.isDragging || this.isResizing ) && this.onCropArea ) {
519
+ if( this.onCropArea ) {
520
+ this.onCropArea( this.getCroppedArea() );
521
+ }
522
+ }
523
+ this.isDragging = false;
524
+ this.isResizing = false;
525
+
501
526
  });
502
527
  area.root.addEventListener( "mousemove", (event) => {
503
528
  if(this.controls) {
504
529
  this.timebar.onMouseMove(event);
505
530
  }
531
+
532
+ if (this.isResizing) {
533
+ this.resizeCropArea(event);
534
+ }
535
+
536
+ if(this.isDragging) {
537
+
538
+ this.dragCropArea(event);
539
+ }
506
540
  });
541
+
542
+ this.cropArea.addEventListener('mousedown', (event) => {
543
+
544
+ const rect = this.cropArea.getBoundingClientRect();
545
+
546
+ if (event.target === this.cropArea) {
547
+ this.isDragging = true;
548
+
549
+ this.dragOffsetX = event.clientX - rect.left;
550
+ this.dragOffsetY = event.clientY - rect.top;
551
+ }
552
+ });
553
+
554
+ document.querySelectorAll('.resize-handle').forEach(handle => {
555
+
556
+ handle.addEventListener('mousedown', (e) => {
557
+
558
+ e.stopPropagation();
559
+ this.resizeHandle = handle.classList[1];
560
+ this.isResizing = true;
561
+ });
562
+ });
563
+ }
564
+
565
+ resizeCropArea(event) {
566
+
567
+ const rect = this.cropArea.getBoundingClientRect();
568
+
569
+ const mouseX = event.clientX;
570
+ const mouseY = event.clientY;
571
+
572
+ if (this.resizeHandle === 'br') {
573
+
574
+ const nodes = this.cropArea.parentElement.childNodes;
575
+
576
+ for( let i = 0; i < nodes.length; i++ ) {
577
+ if( nodes[i] != this.cropArea ) {
578
+ const rectEl = nodes[i].getBoundingClientRect();
579
+ let width = mouseX - rect.left;
580
+ let height = mouseY - rect.top;
581
+
582
+ if( rect.x + width > rectEl.right ) {
583
+ width = rectEl.right - rect.x;
584
+ }
585
+
586
+ if( rect.y + height > rectEl.bottom ) {
587
+ height = rectEl.bottom - rect.y;
588
+ }
589
+
590
+ this.cropArea.style.width = width + "px";
591
+ this.cropArea.style.height = height + "px";
592
+
593
+ 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)`;
594
+ nodes[i].style.webkitMaskRepeat = 'no-repeat';
595
+ }
596
+ }
597
+ }
598
+ }
599
+
600
+ dragCropArea( event ) {
601
+ const rectVideo = this.video.getBoundingClientRect();
602
+
603
+ let x = event.clientX - this.dragOffsetX;
604
+ let y = event.clientY - this.dragOffsetY;
605
+
606
+ if(x < rectVideo.left ) {
607
+ x = rectVideo.left;
608
+ }
609
+
610
+ if( x + this.cropArea.clientWidth > rectVideo.right ) {
611
+ x = rectVideo.right - this.cropArea.clientWidth;
612
+ }
613
+
614
+ if(y < rectVideo.top ) {
615
+ y = rectVideo.top;
616
+ }
507
617
 
618
+ if( y + this.cropArea.clientHeight > rectVideo.height ) {
619
+ y = rectVideo.height - this.cropArea.clientHeight;
620
+ }
621
+
622
+ this.cropArea.style.left = x + "px";
623
+ this.cropArea.style.top = y + "px";
624
+
625
+ const videoEndX = rectVideo.left + rectVideo.width;
626
+ const cropEndX = x + this.cropArea.clientWidth;
627
+ const videoEndY = rectVideo.height;
628
+ const cropEndY = y + this.cropArea.clientHeight;
629
+
630
+ const nodes = this.cropArea.parentElement.childNodes;
631
+
632
+ for( let i = 0; i < nodes.length; i++ ) {
633
+ if( nodes[i] != this.cropArea ) {
634
+ const rectEl = nodes[i].getBoundingClientRect();
635
+ nodes[i].style.webkitMask = `linear-gradient(#000 0 0) ${x - rectEl.left}px ${y }px / ${this.cropArea.clientWidth}px ${this.cropArea.clientHeight}px, linear-gradient(rgba(0, 0, 0, 0.3) 0 0)`;
636
+ nodes[i].style.webkitMaskRepeat = 'no-repeat';
637
+ }
638
+ }
508
639
  }
509
640
 
510
641
  async _loadVideo( options = {} ) {
@@ -529,13 +660,22 @@ class VideoEditor {
529
660
  this._update();
530
661
  }
531
662
  this.controls = options.controls ?? true;
532
- if(!this.controls) {
663
+
664
+ if ( !this.controls ) {
533
665
  this.hideControls();
534
666
  }
535
667
 
668
+ const ratio = this.video.clientHeight / this.video.videoHeight;
669
+ this.cropArea.style.height = this.video.clientHeight + "px";
670
+ this.cropArea.style.width = this.video.videoWidth * ratio + "px";
671
+
672
+ if( this.crop ) {
673
+ this.showCropArea();
674
+ }
675
+
536
676
  window.addEventListener( "keyup", this.onKeyUp);
537
677
 
538
- if(this.onVideoLoaded) {
678
+ if( this.onVideoLoaded ) {
539
679
  this.onVideoLoaded(this.video);
540
680
  }
541
681
  }
@@ -636,6 +776,18 @@ class VideoEditor {
636
776
  return {start: this.startTime, end: this.endTime};
637
777
  }
638
778
 
779
+ getCroppedArea ( ) {
780
+ return this.cropArea.getBoundingClientRect();
781
+ }
782
+
783
+ showCropArea ( ) {
784
+ this.cropArea.classList.remove("hidden");
785
+ }
786
+
787
+ hideCropArea ( ) {
788
+ this.cropArea.classList.add("hidden");
789
+ }
790
+
639
791
  showControls ( ) {
640
792
  this.controls = true;
641
793
  this.controlsArea.show();