@acorex/components 20.8.24 → 20.8.26

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.
@@ -529,23 +529,28 @@ class AXImageEditorViewComponent extends MXBaseComponent {
529
529
  this.saveImageChange();
530
530
  }
531
531
  /** @ignore */
532
- crop() {
532
+ async crop() {
533
533
  const cropper = this.cropperWindow();
534
534
  if (this.service.activeToolState() !== 'crop' || !cropper) {
535
535
  return;
536
536
  }
537
537
  const cropRect = cropper.getCropperArea();
538
- const canvasRect = this.canvasElem().nativeElement.getClientRects()[0];
539
- const dx = cropRect.x - canvasRect.x;
540
- const dy = cropRect.y - canvasRect.y;
541
- const imageData = this.ctx().getImageData(dx, dy, cropRect.width, cropRect.height);
542
- this.canvasElem().nativeElement.width = cropRect.width;
543
- this.canvasElem().nativeElement.height = cropRect.height;
538
+ const canvas = this.canvasElem().nativeElement;
539
+ const canvasRect = canvas.getBoundingClientRect();
540
+ const scaleX = canvas.width / canvasRect.width;
541
+ const scaleY = canvas.height / canvasRect.height;
542
+ const dx = (cropRect.x - canvasRect.x) * scaleX;
543
+ const dy = (cropRect.y - canvasRect.y) * scaleY;
544
+ const cropWidth = cropRect.width * scaleX;
545
+ const cropHeight = cropRect.height * scaleY;
546
+ const imageData = this.ctx().getImageData(Math.round(dx), Math.round(dy), Math.round(cropWidth), Math.round(cropHeight));
547
+ canvas.width = Math.round(cropWidth);
548
+ canvas.height = Math.round(cropHeight);
544
549
  this.ctx().putImageData(imageData, 0, 0);
545
550
  const cropImage = this.canvasElem().nativeElement.toDataURL('image/jpeg', 1);
551
+ await this.saveImageChange();
546
552
  this.setInitialImage(cropImage, false);
547
553
  this.service.activeToolState.set(null);
548
- this.saveImageChange();
549
554
  }
550
555
  /** @ignore */
551
556
  rotateImage() {
@@ -629,8 +634,13 @@ class AXImageEditorContainerComponent extends classes((MXInputBaseValueComponent
629
634
  }
630
635
  #eff;
631
636
  /** Applies the current cropper selection. */
632
- crop() {
633
- this.view()?.crop();
637
+ async crop() {
638
+ const oldValue = this.value;
639
+ await this.view()?.crop();
640
+ const blobs = this.service.imageBlob();
641
+ if (blobs.length && this.value === oldValue) {
642
+ this.commitValue(blobs, true);
643
+ }
634
644
  }
635
645
  get __hostClass() {
636
646
  if (this.disabled)