@seniorsistemas/angular-components 17.3.7 → 17.3.8

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.
@@ -12803,6 +12803,30 @@
12803
12803
  return StructureModule;
12804
12804
  }());
12805
12805
 
12806
+ var ImageUtils;
12807
+ (function (ImageUtils) {
12808
+ function adjustAspectRatio(imageBase64) {
12809
+ return new rxjs.Observable(function (observer) {
12810
+ var image = new Image();
12811
+ image.src = imageBase64;
12812
+ image.onload = function () {
12813
+ var canvas = document.createElement('canvas');
12814
+ var context = canvas.getContext('2d');
12815
+ var size = Math.max(image.naturalWidth, image.naturalHeight);
12816
+ canvas.width = size;
12817
+ canvas.height = size;
12818
+ context.fillStyle = 'rgba(0, 0, 0, 0)';
12819
+ context.fillRect(0, 0, size, size);
12820
+ context.drawImage(image, (size - image.naturalWidth) / 2, (size - image.naturalHeight) / 2);
12821
+ var adjustedImageBase64 = canvas.toDataURL();
12822
+ observer.next(adjustedImageBase64);
12823
+ observer.complete();
12824
+ };
12825
+ });
12826
+ }
12827
+ ImageUtils.adjustAspectRatio = adjustAspectRatio;
12828
+ })(ImageUtils || (ImageUtils = {}));
12829
+
12806
12830
  var ImageCropperComponent = /** @class */ (function () {
12807
12831
  function ImageCropperComponent() {
12808
12832
  this.id = "s-image-cropper-" + ImageCropperComponent_1.nextId++;
@@ -12838,16 +12862,20 @@
12838
12862
  }
12839
12863
  };
12840
12864
  ImageCropperComponent.prototype.initCropper = function () {
12865
+ var _this = this;
12841
12866
  if (this.cropper)
12842
12867
  this.cropper.destroy();
12843
- this.image.nativeElement.src = this.imageSource;
12844
- this.cropper = new Cropper(this.image.nativeElement, {
12845
- aspectRatio: this.rounded ? 1 : this.aspectRatio,
12846
- guides: false,
12847
- dragMode: "move",
12848
- minCropBoxHeight: 2,
12849
- minCropBoxWidth: 2,
12850
- toggleDragModeOnDblclick: false,
12868
+ ImageUtils.adjustAspectRatio(this.imageSource)
12869
+ .subscribe(function (imageBase64) {
12870
+ _this.image.nativeElement.src = imageBase64;
12871
+ _this.cropper = new Cropper(_this.image.nativeElement, {
12872
+ aspectRatio: _this.rounded ? 1 : _this.aspectRatio,
12873
+ guides: false,
12874
+ dragMode: "move",
12875
+ minCropBoxHeight: 2,
12876
+ minCropBoxWidth: 2,
12877
+ toggleDragModeOnDblclick: false,
12878
+ });
12851
12879
  });
12852
12880
  };
12853
12881
  ImageCropperComponent.prototype.getRoundedCanvas = function (sourceCanvas) {
@@ -12871,13 +12899,6 @@
12871
12899
  this.croppedCanvas.emit();
12872
12900
  }
12873
12901
  else {
12874
- //hack to fix images if canvas doesnt match image (for mobile, tablets, etc)
12875
- if (this.cropper.getCanvasData().height !== this.cropper.getImageData().height) {
12876
- this.cropper.getImageData().scaleY = this.cropper.getImageData().height / this.cropper.getCanvasData().height;
12877
- }
12878
- if (this.cropper.getCanvasData().width !== this.cropper.getImageData().width) {
12879
- this.cropper.getImageData().scaleX = this.cropper.getImageData().width / this.cropper.getCanvasData().width;
12880
- }
12881
12902
  var _croppedCanvas = this.rounded
12882
12903
  ? this.getRoundedCanvas(this.cropper.getCroppedCanvas())
12883
12904
  : this.cropper.getCroppedCanvas();