@acorex/components 20.2.43 → 20.2.44

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.
@@ -206,6 +206,7 @@ class AXImageEditorCropperWindowComponent {
206
206
  this.prevY = signal(0, ...(ngDevMode ? [{ debugName: "prevY" }] : []));
207
207
  this.aspectWidth = signal(0, ...(ngDevMode ? [{ debugName: "aspectWidth" }] : []));
208
208
  this.aspectHeight = signal(0, ...(ngDevMode ? [{ debugName: "aspectHeight" }] : []));
209
+ this.isMousePressed = signal(false, ...(ngDevMode ? [{ debugName: "isMousePressed" }] : []));
209
210
  this.renderer = inject(Renderer2);
210
211
  this.platformID = inject(PLATFORM_ID);
211
212
  this.#eff = effect(() => {
@@ -299,6 +300,7 @@ class AXImageEditorCropperWindowComponent {
299
300
  this.prevY.set(currentY);
300
301
  }
301
302
  panDown(e) {
303
+ this.isMousePressed.set(true);
302
304
  if (this.selectedHandle())
303
305
  return;
304
306
  this.panState.set(true);
@@ -306,6 +308,7 @@ class AXImageEditorCropperWindowComponent {
306
308
  this.prevY.set(e.clientY);
307
309
  }
308
310
  panUp() {
311
+ this.isMousePressed.set(false);
309
312
  if (this.selectedHandle())
310
313
  return;
311
314
  this.panState.set(false);
@@ -330,6 +333,8 @@ class AXImageEditorCropperWindowComponent {
330
333
  this.selectedHandle.set(value);
331
334
  }
332
335
  changeSizeHandler(e) {
336
+ if (!this.isMousePressed())
337
+ return;
333
338
  if (this.panState())
334
339
  return;
335
340
  if (!this.selectedHandle())
@@ -473,7 +478,6 @@ class AXImageEditorViewComponent extends MXBaseComponent {
473
478
  this.canvasElem().nativeElement.width = imageHeight;
474
479
  this.canvasElem().nativeElement.height = imageHeight;
475
480
  }
476
- this.canvasElem().nativeElement.style.width = '100%';
477
481
  requestAnimationFrame(() => {
478
482
  //recalculate width after canvas size change
479
483
  const recalculateWidth = this.canvasElem().nativeElement.getClientRects()[0]?.width;
@@ -680,23 +684,31 @@ class AXImageEditorViewComponent extends MXBaseComponent {
680
684
  });
681
685
  }
682
686
  /** @ignore */
683
- saveImageChange() {
687
+ async saveImageChange() {
688
+ const canvas = this.canvasElem().nativeElement;
684
689
  const newImage = new Image();
685
690
  newImage.crossOrigin = 'anonymous';
686
- newImage.src = this.canvasElem().nativeElement.toDataURL('image/jpeg', 1);
691
+ newImage.src = canvas.toDataURL('image/jpeg', 1);
687
692
  this.service.newImage = newImage;
688
693
  this.imageEditorHistory.update((prev) => [...prev, newImage]);
689
- const tempBlob = [];
690
- this.canvasElem().nativeElement.toBlob((blob) => {
691
- tempBlob.push(blob);
692
- }, 'image/jpeg', 1);
693
- this.canvasElem().nativeElement.toBlob((blob) => {
694
- tempBlob.push(blob);
695
- }, 'image/png', 1);
696
- this.canvasElem().nativeElement.toBlob((blob) => {
697
- tempBlob.push(blob);
698
- }, 'image/webp', 1);
699
- this.service.imageBlob.set(tempBlob);
694
+ const canvasToBlob = (type, quality) => {
695
+ return new Promise((resolve, reject) => {
696
+ canvas.toBlob((blob) => {
697
+ if (blob) {
698
+ resolve(blob);
699
+ }
700
+ else {
701
+ reject(new Error(`toBlob returned null for type ${type}`));
702
+ }
703
+ }, type, quality);
704
+ });
705
+ };
706
+ const blobs = await Promise.all([
707
+ canvasToBlob('image/jpeg', 1),
708
+ canvasToBlob('image/png', 1),
709
+ canvasToBlob('image/webp', 1),
710
+ ]);
711
+ this.service.imageBlob.set(blobs);
700
712
  }
701
713
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: AXImageEditorViewComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
702
714
  static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "20.3.9", type: AXImageEditorViewComponent, isStandalone: true, selector: "ax-image-editor-view", inputs: { showGrid: { classPropertyName: "showGrid", publicName: "showGrid", isSignal: true, isRequired: false, transformFunction: null }, src: { classPropertyName: "src", publicName: "src", isSignal: true, isRequired: false, transformFunction: null } }, providers: [{ provide: AXComponent, useExisting: AXImageEditorViewComponent }], viewQueries: [{ propertyName: "canvasElem", first: true, predicate: ["canvasElem"], descendants: true, isSignal: true }, { propertyName: "cropperWindow", first: true, predicate: ["f"], descendants: true, isSignal: true }], usesInheritance: true, ngImport: i0, template: "<canvas\n tabindex=\"1\"\n (pointerdown)=\"mouseDownHandler($event)\"\n (pointerup)=\"mouseUpHandler()\"\n (pointermove)=\"mouseMoveHandler($event)\"\n class=\"ax-canvas-element\"\n #canvasElem\n></canvas>\n\n@if (this.service.activeToolState() === 'crop') {\n <ax-image-editor-cropper-window [showGrid]=\"showGrid()\" #f></ax-image-editor-cropper-window>\n}\n", styles: ["ax-image-editor-view{position:relative;display:flex;justify-content:center;align-items:center;background-color:#fff;width:100%;touch-action:none;overflow:hidden}ax-image-editor-view .ax-canvas-element{cursor:crosshair;background-color:#000}ax-image-editor-view .ax-crop-save{position:absolute;top:0;right:0;margin:1rem}\n"], dependencies: [{ kind: "component", type: AXImageEditorCropperWindowComponent, selector: "ax-image-editor-cropper-window", inputs: ["showGrid"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); }
@@ -718,21 +730,17 @@ class AXImageEditorContainerComponent extends classes((MXInputBaseValueComponent
718
730
  this.imageEditorContainer = viewChild('f', ...(ngDevMode ? [{ debugName: "imageEditorContainer" }] : []));
719
731
  this.view = contentChild(AXImageEditorViewComponent, ...(ngDevMode ? [{ debugName: "view" }] : []));
720
732
  this.aspectRatio = input([], ...(ngDevMode ? [{ debugName: "aspectRatio" }] : []));
733
+ this.#eff = effect(() => {
734
+ void this.service.imageBlob();
735
+ if (this.service.initialImage !== this.service.newImage && this.service.imageBlob().length) {
736
+ this.commitValue(this.service.imageBlob(), true);
737
+ }
738
+ else {
739
+ this.commitValue(null);
740
+ }
741
+ }, ...(ngDevMode ? [{ debugName: "#eff" }] : []));
721
742
  }
722
- /**
723
- * Saves the current edited image and commits the value to the component.
724
- * If the image has been modified, it commits the image blob array. If no changes were made, it commits null.
725
- *
726
- * @returns void - No return value. The edited image is saved and the onValueChanged event is emitted.
727
- */
728
- save() {
729
- if (this.service.initialImage !== this.service.newImage) {
730
- this.commitValue(this.service.imageBlob(), true);
731
- }
732
- else {
733
- this.commitValue(null);
734
- }
735
- }
743
+ #eff;
736
744
  cropButtonHandler() {
737
745
  this.view().cropButtonHandler();
738
746
  }