canvas-editor-engine 2.3.18 → 2.3.19

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.
@@ -3,7 +3,7 @@ import AppStoreRepository from "../store/storeRepository";
3
3
  import { ILayer } from "../types/draw-layers";
4
4
  import { IPainter, ISmoothFilterOptions, TDrawType } from "../types/draw-service";
5
5
  import { ITempCanvasOptions } from "../types/temp-canvas";
6
- import DrawLayersService from "./draw-leayers.service";
6
+ import DrawLayersService from "./draw-layers.service";
7
7
  import DrawService from "./draw.service";
8
8
  import EventService from "./event.service";
9
9
  export default class DrawAccumulatorService {
@@ -0,0 +1,17 @@
1
+ import AppStoreRepository from "../store/storeRepository";
2
+ import { ILayer, ILayerUpdate } from "../types/draw-layers";
3
+ import { IPainter } from "../types/draw-service";
4
+ export default class DrawLayersService {
5
+ private appStoreRepository;
6
+ layerList: ILayer[];
7
+ constructor(appStoreRepository: AppStoreRepository);
8
+ addLayer(layerOptions?: {
9
+ layerName?: string;
10
+ painter?: IPainter;
11
+ }): void;
12
+ getLayerByOrder(order: number): ILayer;
13
+ getLayerById(layerId: ILayer['id']): ILayer;
14
+ addToLayer(id: ILayer['id'], painter: IPainter): void;
15
+ updateLayer(id: ILayer['id'], updateData?: ILayerUpdate): void;
16
+ removePainter(id: IPainter['id']): void;
17
+ }
@@ -0,0 +1,72 @@
1
+ var DrawLayersService = /** @class */ (function () {
2
+ function DrawLayersService(appStoreRepository) {
3
+ this.appStoreRepository = appStoreRepository;
4
+ this.layerList = [];
5
+ this.addLayer({ layerName: 'Base Layer' });
6
+ }
7
+ DrawLayersService.prototype.addLayer = function (layerOptions) {
8
+ var _a;
9
+ var layerName = layerOptions === null || layerOptions === void 0 ? void 0 : layerOptions.layerName;
10
+ var painter = layerOptions === null || layerOptions === void 0 ? void 0 : layerOptions.painter;
11
+ var id = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
12
+ var name = (function () {
13
+ if (layerName)
14
+ return layerName;
15
+ if (painter) {
16
+ return "".concat(painter.drawType, "-").concat(painter.id);
17
+ }
18
+ else {
19
+ return 'New Layer';
20
+ }
21
+ })();
22
+ var painters = (painter) ? [painter] : [];
23
+ var sortedLayers = (_a = this.layerList) === null || _a === void 0 ? void 0 : _a.sort(function (a, b) { return a.order - b.order; });
24
+ var order = (sortedLayers === null || sortedLayers === void 0 ? void 0 : sortedLayers.length) ? sortedLayers.at(-1).order + 1 : 1;
25
+ var layer = {
26
+ id: id,
27
+ painters: painters,
28
+ order: order,
29
+ name: name,
30
+ };
31
+ this.layerList.push(layer);
32
+ this.appStoreRepository.store.drawLayersState.reduce('ADD_LAYER', layer);
33
+ };
34
+ DrawLayersService.prototype.getLayerByOrder = function (order) {
35
+ return this.layerList.find(function (layer) { return layer.order === order; });
36
+ };
37
+ DrawLayersService.prototype.getLayerById = function (layerId) {
38
+ return this.layerList.find(function (layer) { return layer.id === layerId; });
39
+ };
40
+ DrawLayersService.prototype.addToLayer = function (id, painter) {
41
+ var layerIndex = this.layerList.findIndex(function (layer) { return layer.id === id; });
42
+ if (layerIndex === -1)
43
+ return;
44
+ var layer = this.layerList[layerIndex];
45
+ layer.painters.push(painter);
46
+ this.appStoreRepository.store.drawLayersState.reduce('UPDATE_LAYER', layer);
47
+ };
48
+ DrawLayersService.prototype.updateLayer = function (id, updateData) {
49
+ var layerIndex = this.layerList.findIndex(function (layer) { return layer.id === id; });
50
+ var fields = Object.keys(updateData);
51
+ if (!fields.length || layerIndex === -1)
52
+ return;
53
+ var layer = this.layerList[layerIndex];
54
+ fields.forEach(function (field) {
55
+ layer[field] = updateData[field];
56
+ });
57
+ this.layerList[layerIndex] = layer;
58
+ this.appStoreRepository.store.drawLayersState.reduce('UPDATE_LAYER', layer);
59
+ };
60
+ DrawLayersService.prototype.removePainter = function (id) {
61
+ var layerIndex = this.layerList.findIndex(function (layer) {
62
+ return layer.painters.find(function (painter) { return painter.id === id; });
63
+ });
64
+ if (layerIndex === -1)
65
+ return;
66
+ this.layerList[layerIndex].painters = this.layerList[layerIndex].painters.filter(function (painter) { return painter.id !== id; });
67
+ var layer = this.layerList[layerIndex];
68
+ this.appStoreRepository.store.drawLayersState.reduce('UPDATE_LAYER', layer);
69
+ };
70
+ return DrawLayersService;
71
+ }());
72
+ export default DrawLayersService;
@@ -18,7 +18,7 @@ import PullProjectService from "./services/pull-project.service";
18
18
  import DrawService from "./services/draw.service";
19
19
  import DownloadService from "./services/download.service";
20
20
  import ResizeService from "./services/serize.service";
21
- import DrawLayersService from "./services/draw-leayers.service";
21
+ import DrawLayersService from "./services/draw-layers.service";
22
22
  import { ILayer } from "./types/draw-layers";
23
23
  import DrawAccumulatorService from "./services/draw-accumulator.service";
24
24
  export declare class WebComponentWrapper {
@@ -33,7 +33,7 @@ import PullProjectService from "./services/pull-project.service";
33
33
  import DrawService from "./services/draw.service";
34
34
  import DownloadService from "./services/download.service";
35
35
  import ResizeService from "./services/serize.service";
36
- import DrawLayersService from "./services/draw-leayers.service";
36
+ import DrawLayersService from "./services/draw-layers.service";
37
37
  import DrawAccumulatorService from "./services/draw-accumulator.service";
38
38
  var WebComponentWrapper = /** @class */ (function () {
39
39
  function WebComponentWrapper() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "canvas-editor-engine",
3
- "version": "2.3.18",
3
+ "version": "2.3.19",
4
4
  "description": "CanvasEditorEngine library, use: [typescript] [canvas]",
5
5
  "main": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",