canvas-editor-engine 1.1.11 → 1.1.13

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.
@@ -13,18 +13,18 @@ class CropService {
13
13
  return;
14
14
  const filter = new filter_1.Filter(ctx);
15
15
  const options = CropService.options;
16
- const imageData = filter.copy(options);
17
- const putOptions = {
18
- x: (config_1.default.CANVAS_SIZE.width / 2) - (options.width / 2),
19
- y: (config_1.default.CANVAS_SIZE.height / 2) - (options.height / 2),
16
+ const { imageData, size } = filter.copyExtendedModel(options);
17
+ const position = {
18
+ x: (config_1.default.CANVAS_SIZE.width / 2) - (size.width / 2),
19
+ y: (config_1.default.CANVAS_SIZE.height / 2) - (size.height / 2),
20
20
  };
21
- filter.update(imageData, putOptions);
21
+ filter.update(imageData, position);
22
22
  store_1.default.store.imageState.reduce({
23
23
  tempImageData: imageData,
24
- position: putOptions,
24
+ position: position,
25
25
  size: {
26
- width: options.width,
27
- height: options.height,
26
+ width: size.width,
27
+ height: size.height,
28
28
  }
29
29
  }, "Use crop");
30
30
  }
@@ -31,3 +31,7 @@ export declare const enum E_RGBA {
31
31
  b = 2,
32
32
  a = 3
33
33
  }
34
+ export interface IExtendedImageDataModel {
35
+ imageData: ImageData;
36
+ size: ISize;
37
+ }
@@ -7,3 +7,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
7
7
  ;
8
8
  ;
9
9
  ;
10
+ ;
@@ -1,4 +1,4 @@
1
- import { type IImageOptions, type IImageSize, type TBuff, type TRGBABuff } from "../types/image";
1
+ import { IExtendedImageDataModel, type IImageOptions, type IImageSize, type TBuff, type TRGBABuff } from "../types/image";
2
2
  import type { ISize } from '../types/general';
3
3
  export declare class Filter {
4
4
  ctx: CanvasRenderingContext2D;
@@ -6,8 +6,9 @@ export declare class Filter {
6
6
  constructor(ctx: CanvasRenderingContext2D);
7
7
  setImageSize(size: IImageSize): void;
8
8
  copy(options: IImageOptions): ImageData;
9
+ copyExtendedModel(options: IImageOptions): IExtendedImageDataModel;
9
10
  update(imgData: ImageData, options: IImageOptions): void;
10
- clearEmptyPixels(imageData: ImageData): ImageData;
11
+ clearEmptyPixels(imageData: ImageData): IExtendedImageDataModel;
11
12
  getSizeOfSparseMatrix(RGBAMatrix: TBuff<number[]>, tempSize: ISize): ISize;
12
13
  getBuffCollection(imageData: ImageData): {
13
14
  rowRGBABuff: TRGBABuff;
@@ -17,8 +17,14 @@ class Filter {
17
17
  const width = (options?.width) ? options.width : config_1.default.CANVAS_SIZE.width;
18
18
  const height = (options?.height) ? options.height : config_1.default.CANVAS_SIZE.height;
19
19
  const imgData = this.ctx.getImageData(options.x, options.y, width, height);
20
- const clearedImageData = this.clearEmptyPixels(imgData);
21
- return clearedImageData;
20
+ return imgData;
21
+ }
22
+ copyExtendedModel(options) {
23
+ const width = (options?.width) ? options.width : config_1.default.CANVAS_SIZE.width;
24
+ const height = (options?.height) ? options.height : config_1.default.CANVAS_SIZE.height;
25
+ const imgData = this.ctx.getImageData(options.x, options.y, width, height);
26
+ const extendedImageData = this.clearEmptyPixels(imgData);
27
+ return extendedImageData;
22
28
  }
23
29
  update(imgData, options) {
24
30
  this.ctx.clearRect(0, 0, config_1.default.CANVAS_SIZE.width, config_1.default.CANVAS_SIZE.height);
@@ -42,7 +48,10 @@ class Filter {
42
48
  const tempImageData = tempCtx.createImageData(tempSize.width, tempSize.height);
43
49
  clearedBuff.forEach((_, i) => tempImageData.data[i] = clearedBuff[i]);
44
50
  console.log('cleared', cleared);
45
- return tempImageData;
51
+ return {
52
+ imageData: tempImageData,
53
+ size: tempSize
54
+ };
46
55
  }
47
56
  getSizeOfSparseMatrix(RGBAMatrix, tempSize) {
48
57
  // case 1: Xcanvas -> Ximage && case 3: Ycanvas -> Yimage
@@ -83,11 +92,11 @@ class Filter {
83
92
  console.log('case 4: Yimage <- Ycanvas; downIndex:', downIndex);
84
93
  const reduceWidth = (tempWidth) => tempWidth - (leftIndex + rightIndex);
85
94
  const reduceHeight = (tempHeight) => tempHeight - (upIndex + downIndex);
86
- const result = {
95
+ const resultSize = {
87
96
  width: reduceWidth(tempSize.width),
88
97
  height: reduceHeight(tempSize.height),
89
98
  };
90
- return result;
99
+ return resultSize;
91
100
  }
92
101
  getBuffCollection(imageData) {
93
102
  const rowRGBABuff = this.getRowRGBABuff(imageData);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "canvas-editor-engine",
3
- "version": "1.1.11",
3
+ "version": "1.1.13",
4
4
  "description": "CanvasEditorEngine library, use: [typescript] [canvas]",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",