@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.
@@ -1,7 +1,7 @@
1
1
  import { __decorate, __extends, __spread, __assign, __awaiter, __generator, __param, __values, __rest, __read } from 'tslib';
2
2
  import { EventEmitter, Input, Output, Component, ContentChildren, ViewChild, HostListener, forwardRef, NgModule, ɵɵdefineInjectable, Injectable, ElementRef, ApplicationRef, ComponentFactoryResolver, Injector, Directive, HostBinding, Renderer2, InjectionToken, Inject, Pipe, ViewEncapsulation, TemplateRef, ViewContainerRef, ChangeDetectorRef, Optional, ContentChild } from '@angular/core';
3
3
  import { trigger, transition, style as style$7, animate, state, group, query, animateChild } from '@angular/animations';
4
- import { Subject, ReplaySubject, of, from, throwError, forkJoin } from 'rxjs';
4
+ import { Subject, ReplaySubject, of, from, throwError, forkJoin, Observable } from 'rxjs';
5
5
  import { takeUntil, filter, take, tap, map, switchMap, catchError, delay, debounceTime, repeat, finalize } from 'rxjs/operators';
6
6
  import { CommonModule } from '@angular/common';
7
7
  import { NG_VALUE_ACCESSOR, FormsModule, ReactiveFormsModule, FormControl, FormGroup, NG_VALIDATORS, FormBuilder, Validators, FormArray, ControlContainer } from '@angular/forms';
@@ -12657,6 +12657,30 @@ var StructureModule = /** @class */ (function () {
12657
12657
  return StructureModule;
12658
12658
  }());
12659
12659
 
12660
+ var ImageUtils;
12661
+ (function (ImageUtils) {
12662
+ function adjustAspectRatio(imageBase64) {
12663
+ return new Observable(function (observer) {
12664
+ var image = new Image();
12665
+ image.src = imageBase64;
12666
+ image.onload = function () {
12667
+ var canvas = document.createElement('canvas');
12668
+ var context = canvas.getContext('2d');
12669
+ var size = Math.max(image.naturalWidth, image.naturalHeight);
12670
+ canvas.width = size;
12671
+ canvas.height = size;
12672
+ context.fillStyle = 'rgba(0, 0, 0, 0)';
12673
+ context.fillRect(0, 0, size, size);
12674
+ context.drawImage(image, (size - image.naturalWidth) / 2, (size - image.naturalHeight) / 2);
12675
+ var adjustedImageBase64 = canvas.toDataURL();
12676
+ observer.next(adjustedImageBase64);
12677
+ observer.complete();
12678
+ };
12679
+ });
12680
+ }
12681
+ ImageUtils.adjustAspectRatio = adjustAspectRatio;
12682
+ })(ImageUtils || (ImageUtils = {}));
12683
+
12660
12684
  var ImageCropperComponent = /** @class */ (function () {
12661
12685
  function ImageCropperComponent() {
12662
12686
  this.id = "s-image-cropper-" + ImageCropperComponent_1.nextId++;
@@ -12692,16 +12716,20 @@ var ImageCropperComponent = /** @class */ (function () {
12692
12716
  }
12693
12717
  };
12694
12718
  ImageCropperComponent.prototype.initCropper = function () {
12719
+ var _this = this;
12695
12720
  if (this.cropper)
12696
12721
  this.cropper.destroy();
12697
- this.image.nativeElement.src = this.imageSource;
12698
- this.cropper = new Cropper(this.image.nativeElement, {
12699
- aspectRatio: this.rounded ? 1 : this.aspectRatio,
12700
- guides: false,
12701
- dragMode: "move",
12702
- minCropBoxHeight: 2,
12703
- minCropBoxWidth: 2,
12704
- toggleDragModeOnDblclick: false,
12722
+ ImageUtils.adjustAspectRatio(this.imageSource)
12723
+ .subscribe(function (imageBase64) {
12724
+ _this.image.nativeElement.src = imageBase64;
12725
+ _this.cropper = new Cropper(_this.image.nativeElement, {
12726
+ aspectRatio: _this.rounded ? 1 : _this.aspectRatio,
12727
+ guides: false,
12728
+ dragMode: "move",
12729
+ minCropBoxHeight: 2,
12730
+ minCropBoxWidth: 2,
12731
+ toggleDragModeOnDblclick: false,
12732
+ });
12705
12733
  });
12706
12734
  };
12707
12735
  ImageCropperComponent.prototype.getRoundedCanvas = function (sourceCanvas) {
@@ -12725,13 +12753,6 @@ var ImageCropperComponent = /** @class */ (function () {
12725
12753
  this.croppedCanvas.emit();
12726
12754
  }
12727
12755
  else {
12728
- //hack to fix images if canvas doesnt match image (for mobile, tablets, etc)
12729
- if (this.cropper.getCanvasData().height !== this.cropper.getImageData().height) {
12730
- this.cropper.getImageData().scaleY = this.cropper.getImageData().height / this.cropper.getCanvasData().height;
12731
- }
12732
- if (this.cropper.getCanvasData().width !== this.cropper.getImageData().width) {
12733
- this.cropper.getImageData().scaleX = this.cropper.getImageData().width / this.cropper.getCanvasData().width;
12734
- }
12735
12756
  var _croppedCanvas = this.rounded
12736
12757
  ? this.getRoundedCanvas(this.cropper.getCroppedCanvas())
12737
12758
  : this.cropper.getCroppedCanvas();