canvas-editor-engine 2.3.15 → 2.3.17

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.
package/dist/index.mjs CHANGED
@@ -2181,7 +2181,7 @@ var DrawAccumulator = function() {
2181
2181
  }
2182
2182
  DrawAccumulator.prototype.add = function(layerId, drawType, options, initialSize) {
2183
2183
  return __awaiter(this, void 0, void 0, (function() {
2184
- var id, painter, inStore;
2184
+ var id, painter;
2185
2185
  return __generator(this, (function(_a) {
2186
2186
  id = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
2187
2187
  painter = {
@@ -2196,13 +2196,12 @@ var DrawAccumulator = function() {
2196
2196
  update: this.update.bind(this)
2197
2197
  });
2198
2198
  this.drawLayersService.addToLayer(layerId, painter);
2199
- inStore = true;
2200
- this.invokePainter(drawType, painter.drawService, inStore);
2199
+ this.invokePainter(drawType, painter.drawService);
2201
2200
  return [ 2 ];
2202
2201
  }));
2203
2202
  }));
2204
2203
  };
2205
- DrawAccumulator.prototype.remove = function(id) {
2204
+ DrawAccumulator.prototype.removePainter = function(id) {
2206
2205
  return __awaiter(this, void 0, void 0, (function() {
2207
2206
  var painter;
2208
2207
  return __generator(this, (function(_a) {
@@ -2214,6 +2213,25 @@ var DrawAccumulator = function() {
2214
2213
  return painter.id !== id;
2215
2214
  }));
2216
2215
  }
2216
+ this.drawLayersService.removePainter(id);
2217
+ return [ 2 ];
2218
+ }));
2219
+ }));
2220
+ };
2221
+ DrawAccumulator.prototype.smoothFilter = function(painterId, smoothFilterOptions) {
2222
+ return __awaiter(this, void 0, void 0, (function() {
2223
+ var useStore, options, filterOptions, painter;
2224
+ var _this = this;
2225
+ return __generator(this, (function(_a) {
2226
+ useStore = smoothFilterOptions.useStore, options = smoothFilterOptions.options,
2227
+ filterOptions = smoothFilterOptions.filterOptions;
2228
+ painter = this.painters.find((function(painter) {
2229
+ return painter.id === painterId;
2230
+ }));
2231
+ if (!painter) return [ 2 ];
2232
+ painter.drawService.drawSmoothImage(useStore, options, filterOptions).then((function() {
2233
+ _this.update();
2234
+ }));
2217
2235
  return [ 2 ];
2218
2236
  }));
2219
2237
  }));
@@ -2247,6 +2265,7 @@ var DrawAccumulator = function() {
2247
2265
  DrawAccumulator.prototype.clearCanvas = function() {
2248
2266
  var ctx = this.appConfig.canvas.getContext("2d");
2249
2267
  ctx.clearRect(0, 0, this.appConfig.CANVAS_SIZE.width, this.appConfig.CANVAS_SIZE.height);
2268
+ ctx.save();
2250
2269
  };
2251
2270
  DrawAccumulator.prototype.invokePaintersOnLayers = function() {
2252
2271
  var _this = this;
@@ -2264,37 +2283,25 @@ var DrawAccumulator = function() {
2264
2283
  }));
2265
2284
  }));
2266
2285
  };
2267
- DrawAccumulator.prototype.invokePainter = function(drawType_1, painter_1) {
2268
- return __awaiter(this, arguments, void 0, (function(drawType, painter, inStore) {
2269
- var _a, reduceData, message, isAddToStore, _b, reduceData, message, isAddToStore;
2270
- if (inStore === void 0) {
2271
- inStore = false;
2272
- }
2273
- return __generator(this, (function(_c) {
2274
- switch (_c.label) {
2286
+ DrawAccumulator.prototype.invokePainter = function(drawType, painter) {
2287
+ return __awaiter(this, void 0, void 0, (function() {
2288
+ return __generator(this, (function(_a) {
2289
+ switch (_a.label) {
2275
2290
  case 0:
2276
2291
  if (!(drawType === "image")) return [ 3, 2 ];
2277
- return [ 4, painter.drawImage(inStore) ];
2292
+ return [ 4, painter.drawImage() ];
2278
2293
 
2279
2294
  case 1:
2280
- _a = _c.sent(), reduceData = _a.reduceData, message = _a.message;
2281
- isAddToStore = !!reduceData && !!message && inStore;
2282
- if (isAddToStore) {
2283
- this.appStoreRepository.store.imageState.reduce(reduceData, message);
2284
- }
2295
+ _a.sent();
2285
2296
  return [ 3, 4 ];
2286
2297
 
2287
2298
  case 2:
2288
2299
  if (!(drawType === "project")) return [ 3, 4 ];
2289
- return [ 4, painter.drawProject(inStore) ];
2300
+ return [ 4, painter.drawProject() ];
2290
2301
 
2291
2302
  case 3:
2292
- _b = _c.sent(), reduceData = _b.reduceData, message = _b.message;
2293
- isAddToStore = !!reduceData && !!message && inStore;
2294
- if (isAddToStore) {
2295
- this.appStoreRepository.store.imageState.reduce(reduceData, message);
2296
- }
2297
- _c.label = 4;
2303
+ _a.sent();
2304
+ _a.label = 4;
2298
2305
 
2299
2306
  case 4:
2300
2307
  return [ 2 ];
@@ -2312,8 +2319,10 @@ var DrawAccumulator = function() {
2312
2319
  x = painter.options.image.drawImageArgs.position.x;
2313
2320
  y = painter.options.image.drawImageArgs.position.y;
2314
2321
  ctx.putImageData(imageData, x, y);
2322
+ ctx.save();
2315
2323
  } else if (drawType === "project") {
2316
2324
  ctx.putImageData(imageData, 0, 0);
2325
+ ctx.save();
2317
2326
  }
2318
2327
  return [ 2 ];
2319
2328
  }));
@@ -2338,12 +2347,9 @@ var DrawService = function() {
2338
2347
  this.options[drawType] = options;
2339
2348
  };
2340
2349
  DrawService.prototype.drawImage = function() {
2341
- return __awaiter(this, arguments, void 0, (function(isReturnReduceData) {
2350
+ return __awaiter(this, void 0, void 0, (function() {
2342
2351
  var _a, src, drawImageArgs, ctx;
2343
2352
  var _this = this;
2344
- if (isReturnReduceData === void 0) {
2345
- isReturnReduceData = false;
2346
- }
2347
2353
  return __generator(this, (function(_b) {
2348
2354
  switch (_b.label) {
2349
2355
  case 0:
@@ -2355,7 +2361,6 @@ var DrawService = function() {
2355
2361
  reduceData: null,
2356
2362
  message: null
2357
2363
  };
2358
- if (!isReturnReduceData) return responseData;
2359
2364
  var zeroPosition = {
2360
2365
  x: 0,
2361
2366
  y: 0
@@ -2368,6 +2373,7 @@ var DrawService = function() {
2368
2373
  size: _this.appConfig.CANVAS_SIZE
2369
2374
  };
2370
2375
  responseData.message = "Image loaded";
2376
+ _this.appStoreRepository.store.imageState.reduce(responseData.reduceData, responseData.message);
2371
2377
  return responseData;
2372
2378
  })) ];
2373
2379
 
@@ -2378,12 +2384,9 @@ var DrawService = function() {
2378
2384
  }));
2379
2385
  };
2380
2386
  DrawService.prototype.drawProject = function() {
2381
- return __awaiter(this, arguments, void 0, (function(isReturnReduceData) {
2387
+ return __awaiter(this, void 0, void 0, (function() {
2382
2388
  var project, ctx, imageData, position, size;
2383
2389
  var _this = this;
2384
- if (isReturnReduceData === void 0) {
2385
- isReturnReduceData = false;
2386
- }
2387
2390
  return __generator(this, (function(_a) {
2388
2391
  project = this.options.project;
2389
2392
  ctx = this.tempCanvas.ctx;
@@ -2399,29 +2402,35 @@ var DrawService = function() {
2399
2402
  reduceData: null,
2400
2403
  message: null
2401
2404
  };
2402
- if (!isReturnReduceData) return responseData;
2403
2405
  responseData.reduceData = {
2404
2406
  tempImageData: imageData,
2405
2407
  position,
2406
2408
  size
2407
2409
  };
2408
2410
  responseData.message = "Project loaded";
2411
+ _this.appStoreRepository.store.imageState.reduce(responseData.reduceData, responseData.message);
2409
2412
  return responseData;
2410
2413
  })) ];
2411
2414
  }));
2412
2415
  }));
2413
2416
  };
2414
2417
  DrawService.prototype.drawSmoothImage = function(useStore, options, filterOptions) {
2415
- var _this = this;
2416
- var filterArgs = this.getFilterArgs(useStore, options);
2417
- this.eventService.dispatch("loading-start");
2418
- if (!this.imageProcessor) {
2419
- throw new Error("No valid ImageProcessor instance found");
2420
- }
2421
- this.imageProcessor.vague(filterArgs, filterOptions).then((function(data) {
2422
- return _this.updateImageStateAfterVague(data);
2423
- })).finally((function() {
2424
- return _this.eventService.dispatch("loading-end");
2418
+ return __awaiter(this, void 0, void 0, (function() {
2419
+ var filterArgs;
2420
+ var _this = this;
2421
+ return __generator(this, (function(_a) {
2422
+ filterArgs = this.getFilterArgs(useStore, options);
2423
+ this.eventService.dispatch("loading-start");
2424
+ if (!this.imageProcessor) {
2425
+ throw new Error("No valid ImageProcessor instance found");
2426
+ }
2427
+ return [ 2, this.imageProcessor.vague(filterArgs, filterOptions).then((function(data) {
2428
+ _this.updateImageStateAfterVague(data);
2429
+ return data;
2430
+ })).finally((function() {
2431
+ return _this.eventService.dispatch("loading-end");
2432
+ })) ];
2433
+ }));
2425
2434
  }));
2426
2435
  };
2427
2436
  DrawService.prototype.updateImageStateAfterVague = function(data) {
@@ -2633,6 +2642,19 @@ var DrawLayersService = function() {
2633
2642
  this.layerList[layerIndex] = layer;
2634
2643
  this.appStoreRepository.store.drawLayersState.reduce("UPDATE_LAYER", layer);
2635
2644
  };
2645
+ DrawLayersService.prototype.removePainter = function(id) {
2646
+ var layerIndex = this.layerList.findIndex((function(layer) {
2647
+ return layer.painters.find((function(painter) {
2648
+ return painter.id === id;
2649
+ }));
2650
+ }));
2651
+ if (layerIndex === -1) return;
2652
+ this.layerList[layerIndex].painters = this.layerList[layerIndex].painters.filter((function(painter) {
2653
+ return painter.id !== id;
2654
+ }));
2655
+ var layer = this.layerList[layerIndex];
2656
+ this.appStoreRepository.store.drawLayersState.reduce("UPDATE_LAYER", layer);
2657
+ };
2636
2658
  return DrawLayersService;
2637
2659
  }();
2638
2660
 
@@ -13,4 +13,5 @@ export default class DrawLayersService {
13
13
  getLayerById(layerId: ILayer['id']): ILayer;
14
14
  addToLayer(id: ILayer['id'], painter: IPainter): void;
15
15
  updateLayer(id: ILayer['id'], updateData?: ILayerUpdate): void;
16
+ removePainter(id: IPainter['id']): void;
16
17
  }
@@ -2,7 +2,7 @@ import AppConfig from "../config";
2
2
  import { IImageStateReduce } from "../store/image.state";
3
3
  import AppStoreRepository from "../store/storeRepository";
4
4
  import { ILayer } from "../types/draw-layers";
5
- import { IPainter, TDrawType } from "../types/draw-service";
5
+ import { IPainter, ISmoothFilterOptions, TDrawType } from "../types/draw-service";
6
6
  import type { IDrawImageArgs, IDrawImageProcessor, IFilterOptions, IImageLoggingDataVague, IImageOptions } from "../types/image";
7
7
  import { Project } from "../types/project";
8
8
  import { ITempCanvasOptions } from "../types/temp-canvas";
@@ -17,7 +17,8 @@ export declare class DrawAccumulator {
17
17
  painters: IPainter[];
18
18
  constructor(appConfig: AppConfig, appStoreRepository: AppStoreRepository, eventService: EventService, drawLayersService: DrawLayersService);
19
19
  add<DrawType extends TDrawType>(layerId: ILayer['id'], drawType: DrawType, options: DrawService['options'][DrawType], initialSize: ITempCanvasOptions): Promise<void>;
20
- remove(id: string): Promise<void>;
20
+ removePainter(id: string): Promise<void>;
21
+ smoothFilter(painterId: IPainter['id'], smoothFilterOptions: ISmoothFilterOptions): Promise<void>;
21
22
  private update;
22
23
  private get gradient();
23
24
  private clearCanvas;
@@ -41,15 +42,15 @@ export default class DrawService {
41
42
  tempCanvas: TempCanvas;
42
43
  constructor(appConfig: AppConfig, appStoreRepository: AppStoreRepository, eventService: EventService);
43
44
  bindOptions<DrawType extends TDrawType>(drawType: DrawType, options: DrawService['options'][DrawType]): void;
44
- drawImage(isReturnReduceData?: boolean): Promise<{
45
+ drawImage(): Promise<{
45
46
  reduceData: IImageStateReduce | null;
46
47
  message: string | null;
47
48
  }>;
48
- drawProject(isReturnReduceData?: boolean): Promise<{
49
+ drawProject(): Promise<{
49
50
  reduceData: IImageStateReduce | null;
50
51
  message: string | null;
51
52
  }>;
52
- drawSmoothImage(useStore: boolean, options: IDrawImageArgs, filterOptions: IFilterOptions): void;
53
+ drawSmoothImage(useStore: boolean, options: IDrawImageArgs, filterOptions: IFilterOptions): Promise<IImageLoggingDataVague>;
53
54
  updateImageStateAfterVague(data: IImageLoggingDataVague): void;
54
55
  getFilterArgs(useStore: boolean, options: IDrawImageArgs): IImageOptions;
55
56
  }
@@ -1,7 +1,13 @@
1
1
  import DrawService from "../services/draw.service";
2
+ import { IDrawImageArgs, IFilterOptions } from "./image";
2
3
  export type TDrawType = keyof DrawService['options'];
3
4
  export interface IPainter {
4
5
  drawService: DrawService;
5
6
  drawType: TDrawType;
6
7
  id: string;
7
8
  }
9
+ export interface ISmoothFilterOptions {
10
+ useStore: boolean;
11
+ options: IDrawImageArgs;
12
+ filterOptions: IFilterOptions;
13
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "canvas-editor-engine",
3
- "version": "2.3.15",
3
+ "version": "2.3.17",
4
4
  "description": "CanvasEditorEngine library, use: [typescript] [canvas]",
5
5
  "main": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",