canvas-editor-engine 2.3.19 → 2.3.20

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
@@ -2143,194 +2143,6 @@ var TempCanvas = function() {
2143
2143
  return TempCanvas;
2144
2144
  }();
2145
2145
 
2146
- var DrawAccumulator = function() {
2147
- function DrawAccumulator(appConfig, appStoreRepository, eventService, drawLayersService) {
2148
- this.appConfig = appConfig;
2149
- this.appStoreRepository = appStoreRepository;
2150
- this.eventService = eventService;
2151
- this.drawLayersService = drawLayersService;
2152
- this.painters = new Proxy([], {
2153
- get: function(target, name) {
2154
- return target[name];
2155
- },
2156
- set: function(target, name, value) {
2157
- try {
2158
- if (typeof (value === null || value === void 0 ? void 0 : value.object) !== "undefined") {
2159
- target[name] = value.object;
2160
- value.update();
2161
- return true;
2162
- } else {
2163
- if (name != "length") {
2164
- console.warn("Proxy set error: object denied");
2165
- return false;
2166
- } else {
2167
- var MIN_LENGTH = -1;
2168
- var MAX_LENGTH = __spreadArray([], Object.keys(target), true);
2169
- if (value <= Math.max.apply(Math, __spreadArray([ MIN_LENGTH ], MAX_LENGTH, false)) + 1) {
2170
- target.length = value;
2171
- }
2172
- }
2173
- return true;
2174
- }
2175
- } catch (error) {
2176
- console.error("Proxy set error:", error);
2177
- return false;
2178
- }
2179
- }
2180
- });
2181
- }
2182
- DrawAccumulator.prototype.add = function(layerId, drawType, options, initialSize) {
2183
- return __awaiter(this, void 0, void 0, (function() {
2184
- var id, painter;
2185
- return __generator(this, (function(_a) {
2186
- id = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
2187
- painter = {
2188
- drawService: new DrawService(this.appConfig, this.appStoreRepository, this.eventService),
2189
- drawType,
2190
- id
2191
- };
2192
- painter.drawService.bindOptions(drawType, options);
2193
- painter.drawService.tempCanvas.bindOptions(initialSize);
2194
- this.painters.push({
2195
- object: painter,
2196
- update: this.update.bind(this)
2197
- });
2198
- this.drawLayersService.addToLayer(layerId, painter);
2199
- this.invokePainter(drawType, painter.drawService);
2200
- return [ 2 ];
2201
- }));
2202
- }));
2203
- };
2204
- DrawAccumulator.prototype.removePainter = function(id) {
2205
- return __awaiter(this, void 0, void 0, (function() {
2206
- var painter;
2207
- return __generator(this, (function(_a) {
2208
- painter = this.painters.find((function(painter) {
2209
- return painter.id === id;
2210
- }));
2211
- if (!!painter) {
2212
- this.painters = this.painters.filter((function(painter) {
2213
- return painter.id !== id;
2214
- }));
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
- }));
2235
- return [ 2 ];
2236
- }));
2237
- }));
2238
- };
2239
- DrawAccumulator.prototype.update = function() {
2240
- var _this = this;
2241
- setTimeout((function() {
2242
- _this.clearCanvas();
2243
- _this.invokePaintersOnLayers();
2244
- }), 1e3);
2245
- };
2246
- Object.defineProperty(DrawAccumulator.prototype, "gradient", {
2247
- get: function() {
2248
- var _this = this;
2249
- var gradient = [];
2250
- this.painters.forEach((function(painter) {
2251
- var layer = _this.drawLayersService.layerList.find((function(layer) {
2252
- return layer.painters.includes(painter);
2253
- }));
2254
- if (layer) {
2255
- gradient.push(layer.order);
2256
- }
2257
- }));
2258
- return gradient.sort((function(a, b) {
2259
- return a - b;
2260
- }));
2261
- },
2262
- enumerable: false,
2263
- configurable: true
2264
- });
2265
- DrawAccumulator.prototype.clearCanvas = function() {
2266
- var ctx = this.appConfig.canvas.getContext("2d");
2267
- ctx.clearRect(0, 0, this.appConfig.CANVAS_SIZE.width, this.appConfig.CANVAS_SIZE.height);
2268
- ctx.save();
2269
- };
2270
- DrawAccumulator.prototype.invokePaintersOnLayers = function() {
2271
- var _this = this;
2272
- var stash = [];
2273
- this.gradient.forEach((function(order) {
2274
- _this.painters.forEach((function(painter) {
2275
- var layer = _this.drawLayersService.layerList.find((function(layer) {
2276
- return layer.painters.includes(painter);
2277
- }));
2278
- if (!layer) return console.warn("[invoke] Layer not found");
2279
- if (!stash.includes(painter) && layer.order === order) {
2280
- _this.invokePainterWithTempCtx(painter.drawType, painter.drawService);
2281
- stash.push(painter);
2282
- }
2283
- }));
2284
- }));
2285
- };
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) {
2290
- case 0:
2291
- if (!(drawType === "image")) return [ 3, 2 ];
2292
- return [ 4, painter.drawImage() ];
2293
-
2294
- case 1:
2295
- _a.sent();
2296
- return [ 3, 4 ];
2297
-
2298
- case 2:
2299
- if (!(drawType === "project")) return [ 3, 4 ];
2300
- return [ 4, painter.drawProject() ];
2301
-
2302
- case 3:
2303
- _a.sent();
2304
- _a.label = 4;
2305
-
2306
- case 4:
2307
- return [ 2 ];
2308
- }
2309
- }));
2310
- }));
2311
- };
2312
- DrawAccumulator.prototype.invokePainterWithTempCtx = function(drawType, painter) {
2313
- return __awaiter(this, void 0, void 0, (function() {
2314
- var imageData, ctx, x, y;
2315
- return __generator(this, (function(_a) {
2316
- imageData = painter.tempCanvas.getImageData();
2317
- ctx = this.appConfig.canvas.getContext("2d");
2318
- if (drawType === "image") {
2319
- x = painter.options.image.drawImageArgs.position.x;
2320
- y = painter.options.image.drawImageArgs.position.y;
2321
- ctx.putImageData(imageData, x, y);
2322
- ctx.save();
2323
- } else if (drawType === "project") {
2324
- ctx.putImageData(imageData, 0, 0);
2325
- ctx.save();
2326
- }
2327
- return [ 2 ];
2328
- }));
2329
- }));
2330
- };
2331
- return DrawAccumulator;
2332
- }();
2333
-
2334
2146
  var DrawService = function() {
2335
2147
  function DrawService(appConfig, appStoreRepository, eventService) {
2336
2148
  this.appConfig = appConfig;
@@ -2658,6 +2470,194 @@ var DrawLayersService = function() {
2658
2470
  return DrawLayersService;
2659
2471
  }();
2660
2472
 
2473
+ var DrawAccumulatorService = function() {
2474
+ function DrawAccumulatorService(appConfig, appStoreRepository, eventService, drawLayersService) {
2475
+ this.appConfig = appConfig;
2476
+ this.appStoreRepository = appStoreRepository;
2477
+ this.eventService = eventService;
2478
+ this.drawLayersService = drawLayersService;
2479
+ this.painters = new Proxy([], {
2480
+ get: function(target, name) {
2481
+ return target[name];
2482
+ },
2483
+ set: function(target, name, value) {
2484
+ try {
2485
+ if (typeof (value === null || value === void 0 ? void 0 : value.object) !== "undefined") {
2486
+ target[name] = value.object;
2487
+ value.update();
2488
+ return true;
2489
+ } else {
2490
+ if (name != "length") {
2491
+ console.warn("Proxy set error: object denied");
2492
+ return false;
2493
+ } else {
2494
+ var MIN_LENGTH = -1;
2495
+ var MAX_LENGTH = __spreadArray([], Object.keys(target), true);
2496
+ if (value <= Math.max.apply(Math, __spreadArray([ MIN_LENGTH ], MAX_LENGTH, false)) + 1) {
2497
+ target.length = value;
2498
+ }
2499
+ }
2500
+ return true;
2501
+ }
2502
+ } catch (error) {
2503
+ console.error("Proxy set error:", error);
2504
+ return false;
2505
+ }
2506
+ }
2507
+ });
2508
+ }
2509
+ DrawAccumulatorService.prototype.add = function(layerId, drawType, options, initialSize) {
2510
+ return __awaiter(this, void 0, void 0, (function() {
2511
+ var id, painter;
2512
+ return __generator(this, (function(_a) {
2513
+ id = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
2514
+ painter = {
2515
+ drawService: new DrawService(this.appConfig, this.appStoreRepository, this.eventService),
2516
+ drawType,
2517
+ id
2518
+ };
2519
+ painter.drawService.bindOptions(drawType, options);
2520
+ painter.drawService.tempCanvas.bindOptions(initialSize);
2521
+ this.painters.push({
2522
+ object: painter,
2523
+ update: this.update.bind(this)
2524
+ });
2525
+ this.drawLayersService.addToLayer(layerId, painter);
2526
+ this.invokePainter(drawType, painter.drawService);
2527
+ return [ 2 ];
2528
+ }));
2529
+ }));
2530
+ };
2531
+ DrawAccumulatorService.prototype.removePainter = function(id) {
2532
+ return __awaiter(this, void 0, void 0, (function() {
2533
+ var painter;
2534
+ return __generator(this, (function(_a) {
2535
+ painter = this.painters.find((function(painter) {
2536
+ return painter.id === id;
2537
+ }));
2538
+ if (!!painter) {
2539
+ this.painters = this.painters.filter((function(painter) {
2540
+ return painter.id !== id;
2541
+ }));
2542
+ }
2543
+ this.drawLayersService.removePainter(id);
2544
+ return [ 2 ];
2545
+ }));
2546
+ }));
2547
+ };
2548
+ DrawAccumulatorService.prototype.smoothFilter = function(painterId, smoothFilterOptions) {
2549
+ return __awaiter(this, void 0, void 0, (function() {
2550
+ var useStore, options, filterOptions, painter;
2551
+ var _this = this;
2552
+ return __generator(this, (function(_a) {
2553
+ useStore = smoothFilterOptions.useStore, options = smoothFilterOptions.options,
2554
+ filterOptions = smoothFilterOptions.filterOptions;
2555
+ painter = this.painters.find((function(painter) {
2556
+ return painter.id === painterId;
2557
+ }));
2558
+ if (!painter) return [ 2 ];
2559
+ painter.drawService.drawSmoothImage(useStore, options, filterOptions).then((function() {
2560
+ _this.update();
2561
+ }));
2562
+ return [ 2 ];
2563
+ }));
2564
+ }));
2565
+ };
2566
+ DrawAccumulatorService.prototype.update = function() {
2567
+ var _this = this;
2568
+ setTimeout((function() {
2569
+ _this.clearCanvas();
2570
+ _this.invokePaintersOnLayers();
2571
+ }), 1e3);
2572
+ };
2573
+ Object.defineProperty(DrawAccumulatorService.prototype, "gradient", {
2574
+ get: function() {
2575
+ var _this = this;
2576
+ var gradient = [];
2577
+ this.painters.forEach((function(painter) {
2578
+ var layer = _this.drawLayersService.layerList.find((function(layer) {
2579
+ return layer.painters.includes(painter);
2580
+ }));
2581
+ if (layer) {
2582
+ gradient.push(layer.order);
2583
+ }
2584
+ }));
2585
+ return gradient.sort((function(a, b) {
2586
+ return a - b;
2587
+ }));
2588
+ },
2589
+ enumerable: false,
2590
+ configurable: true
2591
+ });
2592
+ DrawAccumulatorService.prototype.clearCanvas = function() {
2593
+ var ctx = this.appConfig.canvas.getContext("2d");
2594
+ ctx.clearRect(0, 0, this.appConfig.CANVAS_SIZE.width, this.appConfig.CANVAS_SIZE.height);
2595
+ ctx.save();
2596
+ };
2597
+ DrawAccumulatorService.prototype.invokePaintersOnLayers = function() {
2598
+ var _this = this;
2599
+ var stash = [];
2600
+ this.gradient.forEach((function(order) {
2601
+ _this.painters.forEach((function(painter) {
2602
+ var layer = _this.drawLayersService.layerList.find((function(layer) {
2603
+ return layer.painters.includes(painter);
2604
+ }));
2605
+ if (!layer) return console.warn("[invoke] Layer not found");
2606
+ if (!stash.includes(painter) && layer.order === order) {
2607
+ _this.invokePainterWithTempCtx(painter.drawType, painter.drawService);
2608
+ stash.push(painter);
2609
+ }
2610
+ }));
2611
+ }));
2612
+ };
2613
+ DrawAccumulatorService.prototype.invokePainter = function(drawType, painter) {
2614
+ return __awaiter(this, void 0, void 0, (function() {
2615
+ return __generator(this, (function(_a) {
2616
+ switch (_a.label) {
2617
+ case 0:
2618
+ if (!(drawType === "image")) return [ 3, 2 ];
2619
+ return [ 4, painter.drawImage() ];
2620
+
2621
+ case 1:
2622
+ _a.sent();
2623
+ return [ 3, 4 ];
2624
+
2625
+ case 2:
2626
+ if (!(drawType === "project")) return [ 3, 4 ];
2627
+ return [ 4, painter.drawProject() ];
2628
+
2629
+ case 3:
2630
+ _a.sent();
2631
+ _a.label = 4;
2632
+
2633
+ case 4:
2634
+ return [ 2 ];
2635
+ }
2636
+ }));
2637
+ }));
2638
+ };
2639
+ DrawAccumulatorService.prototype.invokePainterWithTempCtx = function(drawType, painter) {
2640
+ return __awaiter(this, void 0, void 0, (function() {
2641
+ var imageData, ctx, x, y;
2642
+ return __generator(this, (function(_a) {
2643
+ imageData = painter.tempCanvas.getImageData();
2644
+ ctx = this.appConfig.canvas.getContext("2d");
2645
+ if (drawType === "image") {
2646
+ x = painter.options.image.drawImageArgs.position.x;
2647
+ y = painter.options.image.drawImageArgs.position.y;
2648
+ ctx.putImageData(imageData, x, y);
2649
+ ctx.save();
2650
+ } else if (drawType === "project") {
2651
+ ctx.putImageData(imageData, 0, 0);
2652
+ ctx.save();
2653
+ }
2654
+ return [ 2 ];
2655
+ }));
2656
+ }));
2657
+ };
2658
+ return DrawAccumulatorService;
2659
+ }();
2660
+
2661
2661
  reflect();
2662
2662
 
2663
2663
  var WebComponentWrapper = function() {
@@ -2764,7 +2764,7 @@ var WebComponent = function(_super) {
2764
2764
  this.pullProjectService = new PullProjectService(this.throughHistoryService, this.appStoreRepository);
2765
2765
  this.drawService = new DrawService(this.appConfig, this.appStoreRepository, this.eventService);
2766
2766
  this.drawLayersService = new DrawLayersService(this.appStoreRepository);
2767
- this.drawAccumulator = new DrawAccumulator(this.appConfig, this.appStoreRepository, this.eventService, this.drawLayersService);
2767
+ this.drawAccumulatorService = new DrawAccumulatorService(this.appConfig, this.appStoreRepository, this.eventService, this.drawLayersService);
2768
2768
  this.downloadService = new DownloadService(this.canvasComponent);
2769
2769
  var _a = this.canvasComponent.getComponent(), canvasTemplate = _a.canvasTemplate, canvasStyle = _a.canvasStyle;
2770
2770
  this.canvasElement = this.webComponentWrapper.editorWrap.add(canvasTemplate, canvasStyle);
@@ -2796,7 +2796,7 @@ var WebComponent = function(_super) {
2796
2796
  var projectProcessor = this.projectsService.on("File");
2797
2797
  var serializer = projectProcessor.getSerializerInstance(jsonProjects);
2798
2798
  var projects = serializer.getProjects();
2799
- this.drawAccumulator.add(layerId, "project", projects[0], projects[0].state.current.size);
2799
+ this.drawAccumulatorService.add(layerId, "project", projects[0], projects[0].state.current.size);
2800
2800
  this.throughHistoryService.recovery(projects[0]);
2801
2801
  };
2802
2802
  return WebComponent;
@@ -2835,4 +2835,4 @@ var VueCanvasEditorEngine = function(_super) {
2835
2835
  return VueCanvasEditorEngine;
2836
2836
  }(CanvasEditorEngine);
2837
2837
 
2838
- export { AppConfig, AppStore, AppStoreRepository, CanvasComponent, CropService, DownloadService, DrawService, EventService, ExcretionsComponent as ExcretionComponent, LoadingComponent, LoggerService, PipetteComponent, ProjectsService, PullProjectService, SlotComponent, StaticCanvasEditorEngine, ThroughHistoryService, ToolLayerService, ToolService, VueCanvasEditorEngine };
2838
+ export { AppConfig, AppStore, AppStoreRepository, CanvasComponent, CropService, DownloadService, DrawAccumulatorService, DrawService, EventService, ExcretionsComponent as ExcretionComponent, LoadingComponent, LoggerService, PipetteComponent, ProjectsService, PullProjectService, SlotComponent, StaticCanvasEditorEngine, ThroughHistoryService, ToolLayerService, ToolService, VueCanvasEditorEngine };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "canvas-editor-engine",
3
- "version": "2.3.19",
3
+ "version": "2.3.20",
4
4
  "description": "CanvasEditorEngine library, use: [typescript] [canvas]",
5
5
  "main": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",
@@ -1,17 +0,0 @@
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
- }
@@ -1,72 +0,0 @@
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;