canvas-editor-engine 2.3.22 → 2.3.24
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 +84 -10
- package/dist/services/draw-accumulator.service.d.ts +6 -2
- package/dist/services/draw-layers.service.d.ts +4 -2
- package/dist/types/draw-layers.d.ts +8 -0
- package/dist/web-component.d.ts +1 -1
- package/package.json +7 -5
- package/dist/components/canvas.component.js +0 -102
- package/dist/components/excretions.component.js +0 -258
- package/dist/components/loading.component.js +0 -71
- package/dist/components/pipette.component.js +0 -120
- package/dist/components/slot.component.js +0 -45
- package/dist/config.js +0 -95
- package/dist/filters/collection/vague.js +0 -168
- package/dist/filters/index.js +0 -2
- package/dist/index.js +0 -75
- package/dist/services/component.service.js +0 -40
- package/dist/services/crop.service.js +0 -60
- package/dist/services/download.service.js +0 -16
- package/dist/services/draw-accumulator.service.js +0 -222
- package/dist/services/draw-layers.service.js +0 -72
- package/dist/services/draw.service.js +0 -259
- package/dist/services/event.service.js +0 -45
- package/dist/services/logger.service.js +0 -57
- package/dist/services/projects.service.js +0 -103
- package/dist/services/pull-project.service.js +0 -40
- package/dist/services/serize.service.js +0 -23
- package/dist/services/store.service.js +0 -14
- package/dist/services/through-history.service.js +0 -51
- package/dist/services/tool-layers.service.js +0 -13
- package/dist/services/tool.service.js +0 -59
- package/dist/store/draw-layers.state.js +0 -85
- package/dist/store/history.state.js +0 -77
- package/dist/store/image.state.js +0 -80
- package/dist/store/store.js +0 -41
- package/dist/store/storeRepository.js +0 -6
- package/dist/types/canvas.js +0 -2
- package/dist/types/cursor.js +0 -2
- package/dist/types/draw-layers.js +0 -3
- package/dist/types/draw-service.js +0 -2
- package/dist/types/excretion.js +0 -4
- package/dist/types/general.js +0 -5
- package/dist/types/history.js +0 -1
- package/dist/types/image.js +0 -9
- package/dist/types/log.js +0 -4
- package/dist/types/pipette.js +0 -1
- package/dist/types/project.js +0 -14
- package/dist/types/temp-canvas.js +0 -2
- package/dist/utils/convert.js +0 -27
- package/dist/utils/filter.js +0 -153
- package/dist/utils/generation.js +0 -7
- package/dist/utils/guid4.js +0 -122
- package/dist/utils/project-file-serializer.js +0 -77
- package/dist/utils/reflect.js +0 -30
- package/dist/utils/temp-canvas.js +0 -19
- package/dist/web-component.js +0 -179
- /package/dist/services/{serize.service.d.ts → resize.service.d.ts} +0 -0
package/dist/index.mjs
CHANGED
@@ -2421,12 +2421,18 @@ var DrawLayersService = function() {
|
|
2421
2421
|
};
|
2422
2422
|
this.layerList.push(layer);
|
2423
2423
|
this.appStoreRepository.store.drawLayersState.reduce("ADD_LAYER", layer);
|
2424
|
+
return layer;
|
2424
2425
|
};
|
2425
2426
|
DrawLayersService.prototype.getLayerByOrder = function(order) {
|
2426
2427
|
return this.layerList.find((function(layer) {
|
2427
2428
|
return layer.order === order;
|
2428
2429
|
}));
|
2429
2430
|
};
|
2431
|
+
DrawLayersService.prototype.getLayersByOrder = function(order) {
|
2432
|
+
return this.layerList.filter((function(layer) {
|
2433
|
+
return layer.order === order;
|
2434
|
+
}));
|
2435
|
+
};
|
2430
2436
|
DrawLayersService.prototype.getLayerById = function(layerId) {
|
2431
2437
|
return this.layerList.find((function(layer) {
|
2432
2438
|
return layer.id === layerId;
|
@@ -2481,6 +2487,56 @@ var DrawLayersService = function() {
|
|
2481
2487
|
var layer = this.layerList[layerIndex];
|
2482
2488
|
this.appStoreRepository.store.drawLayersState.reduce("UPDATE_LAYER", layer);
|
2483
2489
|
};
|
2490
|
+
DrawLayersService.prototype.changeLayerOrder = function(id, options) {
|
2491
|
+
return __awaiter(this, void 0, void 0, (function() {
|
2492
|
+
var _this = this;
|
2493
|
+
return __generator(this, (function(_a) {
|
2494
|
+
return [ 2, new Promise((function(resolve, reject) {
|
2495
|
+
var layerIndex = _this.layerList.findIndex((function(layer) {
|
2496
|
+
return layer.id === id;
|
2497
|
+
}));
|
2498
|
+
if (layerIndex === -1) return reject({
|
2499
|
+
status: "error",
|
2500
|
+
message: "Layer not found"
|
2501
|
+
});
|
2502
|
+
var layer = _this.layerList[layerIndex];
|
2503
|
+
if (options === null || options === void 0 ? void 0 : options.to) {
|
2504
|
+
layer.order = options.to;
|
2505
|
+
}
|
2506
|
+
if (options === null || options === void 0 ? void 0 : options.direction) {
|
2507
|
+
layer.order = function() {
|
2508
|
+
if (options.direction === "up") {
|
2509
|
+
return layer.order - 1;
|
2510
|
+
} else if (options.direction === "down") {
|
2511
|
+
return layer.order + 1;
|
2512
|
+
} else {
|
2513
|
+
return layer.order;
|
2514
|
+
}
|
2515
|
+
}();
|
2516
|
+
}
|
2517
|
+
if (options === null || options === void 0 ? void 0 : options.addendum) {
|
2518
|
+
var operation = options.addendum.operation;
|
2519
|
+
var operand = options.addendum.value;
|
2520
|
+
if (operation === "add") {
|
2521
|
+
layer.order = layer.order + operand;
|
2522
|
+
} else if (operation === "subtract") {
|
2523
|
+
layer.order = layer.order - operand;
|
2524
|
+
} else if (operation === "multiplication") {
|
2525
|
+
layer.order = layer.order * operand;
|
2526
|
+
} else if (operation === "division") {
|
2527
|
+
layer.order = layer.order / operand;
|
2528
|
+
}
|
2529
|
+
}
|
2530
|
+
_this.layerList[layerIndex] = layer;
|
2531
|
+
_this.appStoreRepository.store.drawLayersState.reduce("UPDATE_LAYER", layer);
|
2532
|
+
resolve({
|
2533
|
+
status: "success",
|
2534
|
+
message: "Layer order updated"
|
2535
|
+
});
|
2536
|
+
})) ];
|
2537
|
+
}));
|
2538
|
+
}));
|
2539
|
+
};
|
2484
2540
|
return DrawLayersService;
|
2485
2541
|
}();
|
2486
2542
|
|
@@ -2508,18 +2564,24 @@ var Painter = function() {
|
|
2508
2564
|
|
2509
2565
|
var DrawAccumulatorService = function() {
|
2510
2566
|
function DrawAccumulatorService(appConfig, appStoreRepository, eventService, drawLayersService) {
|
2567
|
+
var _this = this;
|
2511
2568
|
this.appConfig = appConfig;
|
2512
2569
|
this.appStoreRepository = appStoreRepository;
|
2513
2570
|
this.eventService = eventService;
|
2514
2571
|
this.drawLayersService = drawLayersService;
|
2515
|
-
this.painters = new Proxy(
|
2572
|
+
this.painters = new Proxy({
|
2573
|
+
value: [],
|
2574
|
+
filter: function(callback) {
|
2575
|
+
_this.value = _this.value.filter(callback);
|
2576
|
+
}
|
2577
|
+
}, {
|
2516
2578
|
get: function(target, name) {
|
2517
2579
|
return target[name];
|
2518
2580
|
},
|
2519
2581
|
set: function(target, name, value) {
|
2520
2582
|
try {
|
2521
2583
|
if (typeof (value === null || value === void 0 ? void 0 : value.object) !== "undefined") {
|
2522
|
-
target[
|
2584
|
+
target["value"] = value.object;
|
2523
2585
|
value.update();
|
2524
2586
|
return true;
|
2525
2587
|
} else {
|
@@ -2530,7 +2592,7 @@ var DrawAccumulatorService = function() {
|
|
2530
2592
|
var MIN_LENGTH = -1;
|
2531
2593
|
var MAX_LENGTH = __spreadArray([], Object.keys(target), true);
|
2532
2594
|
if (value <= Math.max.apply(Math, __spreadArray([ MIN_LENGTH ], MAX_LENGTH, false)) + 1) {
|
2533
|
-
target.length = value;
|
2595
|
+
target["value"].length = value;
|
2534
2596
|
}
|
2535
2597
|
}
|
2536
2598
|
return true;
|
@@ -2555,7 +2617,7 @@ var DrawAccumulatorService = function() {
|
|
2555
2617
|
});
|
2556
2618
|
painter.drawService.bindOptions(drawType, options);
|
2557
2619
|
painter.drawService.tempCanvas.bindOptions(initialSize);
|
2558
|
-
this.painters.push({
|
2620
|
+
this.painters.value.push({
|
2559
2621
|
object: painter,
|
2560
2622
|
update: this.update.bind(this)
|
2561
2623
|
});
|
@@ -2569,11 +2631,11 @@ var DrawAccumulatorService = function() {
|
|
2569
2631
|
return __awaiter(this, void 0, void 0, (function() {
|
2570
2632
|
var painter;
|
2571
2633
|
return __generator(this, (function(_a) {
|
2572
|
-
painter = this.painters.find((function(painter) {
|
2634
|
+
painter = this.painters.value.find((function(painter) {
|
2573
2635
|
return painter.id === painterId;
|
2574
2636
|
}));
|
2575
2637
|
if (!!painter) {
|
2576
|
-
this.painters
|
2638
|
+
this.painters.value.filter((function(painter) {
|
2577
2639
|
return painter.id !== painterId;
|
2578
2640
|
}));
|
2579
2641
|
}
|
@@ -2583,7 +2645,7 @@ var DrawAccumulatorService = function() {
|
|
2583
2645
|
}));
|
2584
2646
|
};
|
2585
2647
|
DrawAccumulatorService.prototype.renamePainter = function(painterId, name) {
|
2586
|
-
var painter = this.painters.find((function(painter) {
|
2648
|
+
var painter = this.painters.value.find((function(painter) {
|
2587
2649
|
return painter.id === painterId;
|
2588
2650
|
}));
|
2589
2651
|
if (painter) {
|
@@ -2601,7 +2663,7 @@ var DrawAccumulatorService = function() {
|
|
2601
2663
|
return __generator(this, (function(_a) {
|
2602
2664
|
useStore = smoothFilterOptions.useStore, options = smoothFilterOptions.options,
|
2603
2665
|
filterOptions = smoothFilterOptions.filterOptions;
|
2604
|
-
painter = this.painters.find((function(painter) {
|
2666
|
+
painter = this.painters.value.find((function(painter) {
|
2605
2667
|
return painter.id === painterId;
|
2606
2668
|
}));
|
2607
2669
|
if (!painter) return [ 2 ];
|
@@ -2612,6 +2674,18 @@ var DrawAccumulatorService = function() {
|
|
2612
2674
|
}));
|
2613
2675
|
}));
|
2614
2676
|
};
|
2677
|
+
DrawAccumulatorService.prototype.updateLayerOrder = function(layerId, options) {
|
2678
|
+
var _this = this;
|
2679
|
+
this.drawLayersService.changeLayerOrder(layerId, options).then((function(res) {
|
2680
|
+
if (res.status === "success") {
|
2681
|
+
_this.update();
|
2682
|
+
}
|
2683
|
+
})).catch((function(ex) {
|
2684
|
+
if (ex.status === "error") {
|
2685
|
+
console.warn(ex.message);
|
2686
|
+
}
|
2687
|
+
}));
|
2688
|
+
};
|
2615
2689
|
DrawAccumulatorService.prototype.update = function() {
|
2616
2690
|
var _this = this;
|
2617
2691
|
setTimeout((function() {
|
@@ -2623,7 +2697,7 @@ var DrawAccumulatorService = function() {
|
|
2623
2697
|
get: function() {
|
2624
2698
|
var _this = this;
|
2625
2699
|
var gradient = [];
|
2626
|
-
this.painters.forEach((function(painter) {
|
2700
|
+
this.painters.value.forEach((function(painter) {
|
2627
2701
|
var layer = _this.drawLayersService.layerList.find((function(layer) {
|
2628
2702
|
return layer.painters.includes(painter);
|
2629
2703
|
}));
|
@@ -2647,7 +2721,7 @@ var DrawAccumulatorService = function() {
|
|
2647
2721
|
var _this = this;
|
2648
2722
|
var stash = [];
|
2649
2723
|
this.gradient.forEach((function(order) {
|
2650
|
-
_this.painters.forEach((function(painter) {
|
2724
|
+
_this.painters.value.forEach((function(painter) {
|
2651
2725
|
var layer = _this.drawLayersService.layerList.find((function(layer) {
|
2652
2726
|
return layer.painters.includes(painter);
|
2653
2727
|
}));
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import AppConfig from "../config";
|
2
2
|
import AppStoreRepository from "../store/storeRepository";
|
3
|
-
import { ILayer } from "../types/draw-layers";
|
3
|
+
import { ILayer, IUpdateLayerOptions } from "../types/draw-layers";
|
4
4
|
import { IPainter, ISmoothFilterOptions, TDrawType } from "../types/draw-service";
|
5
5
|
import { ITempCanvasOptions } from "../types/temp-canvas";
|
6
6
|
import Painter from "../utils/painter";
|
@@ -12,12 +12,16 @@ export default class DrawAccumulatorService {
|
|
12
12
|
private appStoreRepository;
|
13
13
|
private eventService;
|
14
14
|
private drawLayersService;
|
15
|
-
painters:
|
15
|
+
painters: {
|
16
|
+
value: Painter[];
|
17
|
+
filter: (callback: any) => void;
|
18
|
+
};
|
16
19
|
constructor(appConfig: AppConfig, appStoreRepository: AppStoreRepository, eventService: EventService, drawLayersService: DrawLayersService);
|
17
20
|
add<DrawType extends TDrawType>(layerId: ILayer['id'], drawType: DrawType, options: DrawService['options'][DrawType], initialSize: ITempCanvasOptions): Promise<void>;
|
18
21
|
removePainter(painterId: string): Promise<void>;
|
19
22
|
renamePainter(painterId: IPainter['id'], name: string): void;
|
20
23
|
smoothFilter(painterId: IPainter['id'], smoothFilterOptions: ISmoothFilterOptions): Promise<void>;
|
24
|
+
updateLayerOrder(layerId: ILayer['id'], options: IUpdateLayerOptions): void;
|
21
25
|
private update;
|
22
26
|
private get gradient();
|
23
27
|
private clearCanvas;
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import AppStoreRepository from "../store/storeRepository";
|
2
|
-
import { ILayer, ILayerUpdate } from "../types/draw-layers";
|
2
|
+
import { ILayer, ILayerUpdate, IUpdateLayerOptions } from "../types/draw-layers";
|
3
3
|
import { IPainter } from "../types/draw-service";
|
4
4
|
import Painter from "../utils/painter";
|
5
5
|
export default class DrawLayersService {
|
@@ -9,11 +9,13 @@ export default class DrawLayersService {
|
|
9
9
|
addLayer(layerOptions?: {
|
10
10
|
layerName?: string;
|
11
11
|
painter?: IPainter;
|
12
|
-
}):
|
12
|
+
}): ILayer;
|
13
13
|
getLayerByOrder(order: number): ILayer;
|
14
|
+
getLayersByOrder(order: number): ILayer[];
|
14
15
|
getLayerById(layerId: ILayer['id']): ILayer;
|
15
16
|
addToLayer(id: ILayer['id'], painter: IPainter): void;
|
16
17
|
updateLayer(id: ILayer['id'], updateData?: ILayerUpdate): void;
|
17
18
|
removePainter(id: IPainter['id']): void;
|
18
19
|
updatePainterData(painter: Painter): void;
|
20
|
+
changeLayerOrder(id: ILayer['id'], options: IUpdateLayerOptions): Promise<unknown>;
|
19
21
|
}
|
@@ -11,3 +11,11 @@ export interface ILayerUpdate {
|
|
11
11
|
name?: ILayer['name'];
|
12
12
|
}
|
13
13
|
export type TReducerNames = 'SET_LAYERS' | 'UPDATE_LAYER' | 'ADD_LAYER';
|
14
|
+
export interface IUpdateLayerOptions {
|
15
|
+
to?: number;
|
16
|
+
direction?: 'up' | 'down';
|
17
|
+
addendum?: {
|
18
|
+
operation: 'add' | 'subtract' | 'multiplication' | 'division';
|
19
|
+
value: number;
|
20
|
+
};
|
21
|
+
}
|
package/dist/web-component.d.ts
CHANGED
@@ -17,7 +17,7 @@ import ProjectsService from "./services/projects.service";
|
|
17
17
|
import PullProjectService from "./services/pull-project.service";
|
18
18
|
import DrawService from "./services/draw.service";
|
19
19
|
import DownloadService from "./services/download.service";
|
20
|
-
import ResizeService from "./services/
|
20
|
+
import ResizeService from "./services/resize.service";
|
21
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";
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "canvas-editor-engine",
|
3
|
-
"version": "2.3.
|
3
|
+
"version": "2.3.24",
|
4
4
|
"description": "CanvasEditorEngine library, use: [typescript] [canvas]",
|
5
5
|
"main": "dist/index.mjs",
|
6
6
|
"types": "dist/index.d.ts",
|
@@ -9,7 +9,7 @@
|
|
9
9
|
],
|
10
10
|
"type": "module",
|
11
11
|
"scripts": {
|
12
|
-
"test": "
|
12
|
+
"test": "jest",
|
13
13
|
"build:ts": "tsc",
|
14
14
|
"build": "rollup -c",
|
15
15
|
"realise": "npm version patch && npm publish"
|
@@ -22,13 +22,15 @@
|
|
22
22
|
"author": "SavaFeeD",
|
23
23
|
"license": "ISC",
|
24
24
|
"devDependencies": {
|
25
|
-
"@types/node": "^22.7.4",
|
26
|
-
"typescript": "^5.7.2",
|
27
25
|
"@rollup/plugin-terser": "^0.4.4",
|
28
26
|
"@rollup/plugin-typescript": "^12.1.1",
|
29
|
-
"
|
27
|
+
"@types/node": "^22.7.4",
|
28
|
+
"babel-jest": "^29.7.0",
|
29
|
+
"rollup": "^4.28.1",
|
30
|
+
"typescript": "^5.7.2"
|
30
31
|
},
|
31
32
|
"dependencies": {
|
33
|
+
"rollup-plugin-multi-input": "^1.5.0",
|
32
34
|
"tslib": "^2.8.1"
|
33
35
|
}
|
34
36
|
}
|
@@ -1,102 +0,0 @@
|
|
1
|
-
var __extends = (this && this.__extends) || (function () {
|
2
|
-
var extendStatics = function (d, b) {
|
3
|
-
extendStatics = Object.setPrototypeOf ||
|
4
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
5
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
6
|
-
return extendStatics(d, b);
|
7
|
-
};
|
8
|
-
return function (d, b) {
|
9
|
-
if (typeof b !== "function" && b !== null)
|
10
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
11
|
-
extendStatics(d, b);
|
12
|
-
function __() { this.constructor = d; }
|
13
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
14
|
-
};
|
15
|
-
})();
|
16
|
-
import ComponentService from "../services/component.service";
|
17
|
-
var CanvasComponent = /** @class */ (function (_super) {
|
18
|
-
__extends(CanvasComponent, _super);
|
19
|
-
function CanvasComponent(appConfig, loggerService, toolLayerService) {
|
20
|
-
var _this = _super.call(this) || this;
|
21
|
-
_this.appConfig = appConfig;
|
22
|
-
_this.loggerService = loggerService;
|
23
|
-
_this.toolLayerService = toolLayerService;
|
24
|
-
_this.template = "\n <div id=\"event-listener\"></div>\n <canvas id=\"sc-canvas\"></canvas>\n ";
|
25
|
-
_this.css = "\n #event-listener {\n position: absolute;\n z-index: ".concat(_this.toolLayerService.getLayerIndex('normal'), ";\n }\n ");
|
26
|
-
_this.subscriptions = {
|
27
|
-
click: [],
|
28
|
-
mousemove: [],
|
29
|
-
mousedown: [],
|
30
|
-
mouseup: [],
|
31
|
-
};
|
32
|
-
_this._cursorStyle = {
|
33
|
-
before: null,
|
34
|
-
current: 'default',
|
35
|
-
};
|
36
|
-
_this.loggerService.components.add({
|
37
|
-
info: {
|
38
|
-
name: 'canvas',
|
39
|
-
description: 'canvas component',
|
40
|
-
},
|
41
|
-
prototype: _this,
|
42
|
-
});
|
43
|
-
return _this;
|
44
|
-
}
|
45
|
-
;
|
46
|
-
CanvasComponent.prototype.getComponent = function () {
|
47
|
-
var canvasTemplate = this.getTemplate(this.template);
|
48
|
-
var canvasStyle = this.getStyle(this.css);
|
49
|
-
canvasTemplate.style.display = 'flex';
|
50
|
-
this.canvas = canvasTemplate.getElementsByTagName('canvas')[0];
|
51
|
-
this.canvas.width = this.appConfig.CANVAS_SIZE.width;
|
52
|
-
this.canvas.height = this.appConfig.CANVAS_SIZE.height;
|
53
|
-
this.ctx = this.canvas.getContext("2d", { willReadFrequently: true });
|
54
|
-
this.eventListener = canvasTemplate.querySelector('#event-listener');
|
55
|
-
this.eventListener.style.width = this.appConfig.CANVAS_SIZE.width + 'px';
|
56
|
-
this.eventListener.style.height = this.appConfig.CANVAS_SIZE.height + 'px';
|
57
|
-
return { canvasTemplate: canvasTemplate, canvasStyle: canvasStyle };
|
58
|
-
};
|
59
|
-
CanvasComponent.prototype.getCanvasSelector = function () {
|
60
|
-
return '#sc-canvas';
|
61
|
-
};
|
62
|
-
Object.defineProperty(CanvasComponent.prototype, "cursorStyle", {
|
63
|
-
set: function (styleName) {
|
64
|
-
if (!!styleName) {
|
65
|
-
this._cursorStyle.before = this._cursorStyle.current;
|
66
|
-
this._cursorStyle.current = styleName;
|
67
|
-
this.eventListener.style.cursor = styleName;
|
68
|
-
}
|
69
|
-
else {
|
70
|
-
this.eventListener.style.cursor = 'default';
|
71
|
-
}
|
72
|
-
},
|
73
|
-
enumerable: false,
|
74
|
-
configurable: true
|
75
|
-
});
|
76
|
-
CanvasComponent.prototype.getCursorPosition = function (event) {
|
77
|
-
var rect = this.canvas.getBoundingClientRect();
|
78
|
-
var x = (event.clientX - rect.left) / this.appConfig.ZOOM;
|
79
|
-
var y = (event.clientY - rect.top) / this.appConfig.ZOOM;
|
80
|
-
return { x: x, y: y };
|
81
|
-
};
|
82
|
-
CanvasComponent.prototype.subscribe = function (eventName, action) {
|
83
|
-
this.subscriptions[eventName].push(action);
|
84
|
-
};
|
85
|
-
CanvasComponent.prototype.simulateSubscriptions = function () {
|
86
|
-
var _this = this;
|
87
|
-
var eventNames = Object.keys(this.subscriptions);
|
88
|
-
eventNames.forEach(function (eventName) {
|
89
|
-
var actionsList = _this.subscriptions[eventName];
|
90
|
-
if (!!actionsList.length) {
|
91
|
-
_this.eventListener.addEventListener(eventName, function (event) {
|
92
|
-
var cursorPosition = _this.getCursorPosition(event);
|
93
|
-
actionsList.forEach(function (action) {
|
94
|
-
action(event, cursorPosition);
|
95
|
-
});
|
96
|
-
});
|
97
|
-
}
|
98
|
-
});
|
99
|
-
};
|
100
|
-
return CanvasComponent;
|
101
|
-
}(ComponentService));
|
102
|
-
export default CanvasComponent;
|
@@ -1,258 +0,0 @@
|
|
1
|
-
var __extends = (this && this.__extends) || (function () {
|
2
|
-
var extendStatics = function (d, b) {
|
3
|
-
extendStatics = Object.setPrototypeOf ||
|
4
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
5
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
6
|
-
return extendStatics(d, b);
|
7
|
-
};
|
8
|
-
return function (d, b) {
|
9
|
-
if (typeof b !== "function" && b !== null)
|
10
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
11
|
-
extendStatics(d, b);
|
12
|
-
function __() { this.constructor = d; }
|
13
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
14
|
-
};
|
15
|
-
})();
|
16
|
-
import { reflect } from "../utils/reflect";
|
17
|
-
reflect();
|
18
|
-
import ComponentService from "../services/component.service";
|
19
|
-
var ExcretionsComponent = /** @class */ (function (_super) {
|
20
|
-
__extends(ExcretionsComponent, _super);
|
21
|
-
function ExcretionsComponent(toolService, loggerService, toolLayerService,
|
22
|
-
// private cropService: CropService,
|
23
|
-
canvasComponent) {
|
24
|
-
var _this = _super.call(this) || this;
|
25
|
-
_this.toolService = toolService;
|
26
|
-
_this.loggerService = loggerService;
|
27
|
-
_this.toolLayerService = toolLayerService;
|
28
|
-
_this.canvasComponent = canvasComponent;
|
29
|
-
_this.template = "";
|
30
|
-
_this.templateExcretion = "\n <button type=\"button\" class=\"crop-button\">\n <svg fill=\"#ffffff\" viewBox=\"0 0 1920 1920\" xmlns=\"http://www.w3.org/2000/svg\" stroke=\"#ffffff\"><g id=\"SVGRepo_bgCarrier\" stroke-width=\"0\"></g><g id=\"SVGRepo_tracerCarrier\" stroke-linecap=\"round\" stroke-linejoin=\"round\"></g><g id=\"SVGRepo_iconCarrier\"> <path fill-rule=\"evenodd\" clip-rule=\"evenodd\" d=\"M426.667 0h106.666v1386.67H1920v106.66H426.667V0zM320 426.667H0v106.666h320V426.667zm320 0v106.666h746.67V1280h106.66V426.667H640zM1493.33 1600h-106.66v320h106.66v-320z\"></path> </g></svg>\n </button>\n ";
|
31
|
-
_this._excretionDefaultStyle = ['excretion'];
|
32
|
-
_this.css = "\n .excretion {\n display: flex;\n position: absolute;\n background-image: linear-gradient(90deg, silver 50%, transparent 50%), linear-gradient(90deg, silver 50%, transparent 50%), linear-gradient(0deg, silver 50%, transparent 50%), linear-gradient(0deg, silver 50%, transparent 50%);\n background-repeat: repeat-x, repeat-x, repeat-y, repeat-y;\n background-size: 8px 1px, 8px 1px, 1px 8px, 1px 8px;\n background-position: left top, right bottom, left bottom, right top;\n animation: border-dance 1s infinite linear;\n z-index: ".concat(_this.toolLayerService.getLayerIndex('low'), ";\n }\n\n .excretion_crop {\n box-shadow: 0px 0px 0px calc(100vw + 100vh) #50505070;\n }\n\n .crop-button {\n display: none;\n justify-content: center;\n align-items: center;\n position: absolute;\n padding: 5px;\n right: -35px;\n top: 0;\n background: #232222;\n border: 1px solid #ffffff50;\n border-radius: 4px;\n width: 30px;\n height: 30px;\n cursor: pointer;\n z-index: ").concat(_this.toolLayerService.getLayerIndex('high'), ";\n }\n\n .crop-button--view {\n display: flex;\n }\n\n @keyframes border-dance {\n 0% {\n background-position: left top, right bottom, left bottom, right top;\n }\n 100% {\n background-position: left 8px top, right 8px bottom, left bottom 8px, right top 8px;\n }\n }\n ");
|
33
|
-
_this._excretions = [];
|
34
|
-
_this._excretionState = 'abandoned';
|
35
|
-
_this._excretionActivity = 'abandoned';
|
36
|
-
_this._excretionToolState = 'abandoned';
|
37
|
-
_this._tempCoords = [];
|
38
|
-
_this.excretionsCoords = [];
|
39
|
-
_this._additionStyle = 'default';
|
40
|
-
_this.tool = {
|
41
|
-
id: 1,
|
42
|
-
name: 'excretion',
|
43
|
-
onAction: function () { return _this.setToolState('taken'); },
|
44
|
-
offAction: function () { return _this.setToolState('abandoned'); },
|
45
|
-
support: function () {
|
46
|
-
_this.clearExcretionsCoords();
|
47
|
-
_this.additionStyle = 'default';
|
48
|
-
},
|
49
|
-
};
|
50
|
-
_this.toolService.add(_this.tool);
|
51
|
-
_this.loggerService.components.add({
|
52
|
-
info: {
|
53
|
-
name: 'excretion',
|
54
|
-
description: 'excretion component',
|
55
|
-
},
|
56
|
-
prototype: _this,
|
57
|
-
});
|
58
|
-
return _this;
|
59
|
-
}
|
60
|
-
Object.defineProperty(ExcretionsComponent.prototype, "additionStyle", {
|
61
|
-
get: function () {
|
62
|
-
return this._additionStyle;
|
63
|
-
},
|
64
|
-
set: function (value) {
|
65
|
-
this._additionStyle = value;
|
66
|
-
this.applyExcretionStyle();
|
67
|
-
},
|
68
|
-
enumerable: false,
|
69
|
-
configurable: true
|
70
|
-
});
|
71
|
-
ExcretionsComponent.prototype.applyExcretionStyle = function () {
|
72
|
-
switch (this._additionStyle) {
|
73
|
-
case 'crop':
|
74
|
-
this.determineCropStyle();
|
75
|
-
break;
|
76
|
-
case 'default':
|
77
|
-
this.determineDefaultStyle();
|
78
|
-
break;
|
79
|
-
default:
|
80
|
-
this.determineDefaultStyle();
|
81
|
-
break;
|
82
|
-
}
|
83
|
-
};
|
84
|
-
;
|
85
|
-
ExcretionsComponent.prototype.determineCropStyle = function () {
|
86
|
-
this._excretions.forEach(function (excretion) {
|
87
|
-
if (!!excretion === false)
|
88
|
-
return;
|
89
|
-
if (!excretion.classList.contains('excretion_crop')) {
|
90
|
-
excretion.classList.add("excretion_crop");
|
91
|
-
// this.cropService.viewCropButton();
|
92
|
-
}
|
93
|
-
});
|
94
|
-
};
|
95
|
-
ExcretionsComponent.prototype.determineDefaultStyle = function () {
|
96
|
-
var _this = this;
|
97
|
-
this._excretions.forEach(function (excretion) {
|
98
|
-
if (!!excretion === false)
|
99
|
-
return;
|
100
|
-
// @ts-ignore
|
101
|
-
excretion.classList = _this._excretionDefaultStyle;
|
102
|
-
});
|
103
|
-
};
|
104
|
-
ExcretionsComponent.prototype.getComponent = function () {
|
105
|
-
var wrapOptions = {
|
106
|
-
className: 'excretions-wrap',
|
107
|
-
};
|
108
|
-
var excretionsTemplate = this.getTemplate(this.template, wrapOptions);
|
109
|
-
var excretionsStyle = this.getStyle(this.css);
|
110
|
-
this.excretionWrap = excretionsTemplate;
|
111
|
-
this.emmit();
|
112
|
-
return { excretionsTemplate: excretionsTemplate, excretionsStyle: excretionsStyle };
|
113
|
-
};
|
114
|
-
Object.defineProperty(ExcretionsComponent.prototype, "excretionState", {
|
115
|
-
set: function (state) {
|
116
|
-
this._excretionState = state;
|
117
|
-
this.applyExcretionStyle();
|
118
|
-
switch (state) {
|
119
|
-
case 'abandoned':
|
120
|
-
this.canvasComponent.cursorStyle = 'default';
|
121
|
-
break;
|
122
|
-
case 'create':
|
123
|
-
this.canvasComponent.cursorStyle = 'crosshair';
|
124
|
-
break;
|
125
|
-
case 'add':
|
126
|
-
this.canvasComponent.cursorStyle = 'copy';
|
127
|
-
break;
|
128
|
-
case 'remove':
|
129
|
-
this.canvasComponent.cursorStyle = 'alias';
|
130
|
-
break;
|
131
|
-
default:
|
132
|
-
this.canvasComponent.cursorStyle = 'default';
|
133
|
-
break;
|
134
|
-
}
|
135
|
-
},
|
136
|
-
enumerable: false,
|
137
|
-
configurable: true
|
138
|
-
});
|
139
|
-
ExcretionsComponent.prototype.setToolState = function (toolState) {
|
140
|
-
this._excretionToolState = toolState;
|
141
|
-
switch (toolState) {
|
142
|
-
case 'abandoned':
|
143
|
-
this.excretionState = 'abandoned';
|
144
|
-
this._excretionActivity = 'abandoned';
|
145
|
-
break;
|
146
|
-
case 'taken':
|
147
|
-
this.excretionState = 'create';
|
148
|
-
break;
|
149
|
-
default:
|
150
|
-
this.excretionState = 'abandoned';
|
151
|
-
this._excretionActivity = 'abandoned';
|
152
|
-
break;
|
153
|
-
}
|
154
|
-
};
|
155
|
-
ExcretionsComponent.prototype.clearExcretionsCoords = function () {
|
156
|
-
this._excretions.forEach(function (excretion) { return excretion.remove(); });
|
157
|
-
this._excretions = [];
|
158
|
-
this.excretionsCoords = [];
|
159
|
-
};
|
160
|
-
ExcretionsComponent.prototype.getTempCoords = function () {
|
161
|
-
var startCoords = this._tempCoords[0];
|
162
|
-
var endCoords = this._tempCoords[1];
|
163
|
-
var coords = Object.assign(startCoords, endCoords);
|
164
|
-
this._tempCoords = [];
|
165
|
-
return coords;
|
166
|
-
};
|
167
|
-
ExcretionsComponent.prototype.endExcretion = function () {
|
168
|
-
var coords = this.getTempCoords();
|
169
|
-
this.excretionsCoords.push(coords);
|
170
|
-
this._excretionActivity = 'end';
|
171
|
-
};
|
172
|
-
ExcretionsComponent.prototype.emmit = function () {
|
173
|
-
var _this = this;
|
174
|
-
this.canvasComponent.subscribe('mousedown', function (event, cursorPosition) {
|
175
|
-
var toolState = _this._excretionToolState;
|
176
|
-
if (toolState === 'abandoned')
|
177
|
-
return;
|
178
|
-
var state = _this._excretionState;
|
179
|
-
if (state === 'create') {
|
180
|
-
var wrapOptions = {
|
181
|
-
className: _this._excretionDefaultStyle[0],
|
182
|
-
};
|
183
|
-
var excretionTemplate = _this.getTemplate(_this.templateExcretion, wrapOptions);
|
184
|
-
_this.clearExcretionsCoords();
|
185
|
-
var tempStart = {
|
186
|
-
start: cursorPosition,
|
187
|
-
};
|
188
|
-
excretionTemplate.style.left = "".concat(tempStart.start.x, "px");
|
189
|
-
excretionTemplate.style.top = "".concat(tempStart.start.y, "px");
|
190
|
-
var excretionElement = _this.excretionWrap.appendChild(excretionTemplate);
|
191
|
-
_this._excretions.push(excretionElement);
|
192
|
-
_this._tempCoords.push(tempStart);
|
193
|
-
}
|
194
|
-
if (state === 'add') {
|
195
|
-
var tempStart = {
|
196
|
-
start: cursorPosition,
|
197
|
-
};
|
198
|
-
_this._tempCoords.push(tempStart);
|
199
|
-
}
|
200
|
-
_this.applyExcretionStyle();
|
201
|
-
_this._excretionActivity = 'active';
|
202
|
-
});
|
203
|
-
this.canvasComponent.subscribe('mousemove', function (event, cursorPosition) {
|
204
|
-
var toolState = _this._excretionToolState;
|
205
|
-
if (toolState === 'abandoned')
|
206
|
-
return;
|
207
|
-
var activity = _this._excretionActivity;
|
208
|
-
if (event.altKey && _this._excretionState !== 'abandoned') {
|
209
|
-
_this._excretionState = 'add';
|
210
|
-
}
|
211
|
-
if (activity === 'abandoned')
|
212
|
-
return;
|
213
|
-
if (activity === 'active') {
|
214
|
-
var excretionLastIndex = _this._excretions.length - 1;
|
215
|
-
var excretion = _this._excretions[excretionLastIndex];
|
216
|
-
var excretionX = +(excretion.style.left.split('px')[0]);
|
217
|
-
var excretionY = +(excretion.style.top.split('px')[0]);
|
218
|
-
var width = Math.abs(cursorPosition.x - excretionX);
|
219
|
-
var height = Math.abs(cursorPosition.y - excretionY);
|
220
|
-
excretion.style.width = width + 'px';
|
221
|
-
excretion.style.height = height + 'px';
|
222
|
-
var isRightBottom = cursorPosition.x > excretionX && cursorPosition.y > excretionY;
|
223
|
-
var isLeftBottom = cursorPosition.x < excretionX && cursorPosition.y > excretionY;
|
224
|
-
var isLeftTop = cursorPosition.x < excretionX && cursorPosition.y < excretionY;
|
225
|
-
var isRightTop = cursorPosition.x > excretionX && cursorPosition.y < excretionY;
|
226
|
-
if (isRightBottom) {
|
227
|
-
excretion.style.transform = "translateX(0px) translateY(0px)";
|
228
|
-
}
|
229
|
-
else if (isLeftBottom) {
|
230
|
-
excretion.style.transform = "translateX(-".concat(width, "px) translateY(0px)");
|
231
|
-
}
|
232
|
-
else if (isLeftTop) {
|
233
|
-
excretion.style.transform = "translateX(-".concat(width, "px) translateY(-").concat(height, "px)");
|
234
|
-
}
|
235
|
-
else if (isRightTop) {
|
236
|
-
excretion.style.transform = "translateX(0px) translateY(-".concat(height, "px)");
|
237
|
-
}
|
238
|
-
}
|
239
|
-
});
|
240
|
-
this.canvasComponent.subscribe('mouseup', function (event, cursorPosition) {
|
241
|
-
var toolState = _this._excretionToolState;
|
242
|
-
if (toolState === 'abandoned')
|
243
|
-
return;
|
244
|
-
var state = _this._excretionState;
|
245
|
-
if (state === 'abandoned')
|
246
|
-
return;
|
247
|
-
if (state === 'create' || state === 'add') {
|
248
|
-
var tempEnd = {
|
249
|
-
end: cursorPosition,
|
250
|
-
};
|
251
|
-
_this._tempCoords.push(tempEnd);
|
252
|
-
_this.endExcretion();
|
253
|
-
}
|
254
|
-
});
|
255
|
-
};
|
256
|
-
return ExcretionsComponent;
|
257
|
-
}(ComponentService));
|
258
|
-
export default ExcretionsComponent;
|