canvas-editor-engine 2.3.17 → 2.3.18
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/components/canvas.component.js +102 -0
- package/dist/components/excretions.component.js +258 -0
- package/dist/components/loading.component.js +71 -0
- package/dist/components/pipette.component.js +120 -0
- package/dist/components/slot.component.js +45 -0
- package/dist/config.js +95 -0
- package/dist/filters/collection/vague.js +168 -0
- package/dist/filters/index.js +2 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +75 -0
- package/dist/services/component.service.js +40 -0
- package/dist/services/crop.service.js +60 -0
- package/dist/services/download.service.js +16 -0
- package/dist/services/draw-accumulator.service.d.ts +25 -0
- package/dist/services/draw-accumulator.service.js +222 -0
- package/dist/services/draw-leayers.service.js +72 -0
- package/dist/services/draw.service.d.ts +1 -21
- package/dist/services/draw.service.js +259 -0
- package/dist/services/event.service.js +45 -0
- package/dist/services/logger.service.js +57 -0
- package/dist/services/projects.service.js +103 -0
- package/dist/services/pull-project.service.js +40 -0
- package/dist/services/serize.service.js +23 -0
- package/dist/services/store.service.js +14 -0
- package/dist/services/through-history.service.js +51 -0
- package/dist/services/tool-layers.service.js +13 -0
- package/dist/services/tool.service.js +59 -0
- package/dist/store/draw-layers.state.js +85 -0
- package/dist/store/history.state.js +77 -0
- package/dist/store/image.state.js +80 -0
- package/dist/store/store.js +41 -0
- package/dist/store/storeRepository.js +6 -0
- package/dist/types/canvas.js +2 -0
- package/dist/types/cursor.js +2 -0
- package/dist/types/draw-layers.js +3 -0
- package/dist/types/draw-service.js +2 -0
- package/dist/types/excretion.js +4 -0
- package/dist/types/general.js +5 -0
- package/dist/types/history.js +1 -0
- package/dist/types/image.js +9 -0
- package/dist/types/log.js +4 -0
- package/dist/types/pipette.js +1 -0
- package/dist/types/project.js +14 -0
- package/dist/types/temp-canvas.js +2 -0
- package/dist/utils/convert.js +27 -0
- package/dist/utils/filter.js +153 -0
- package/dist/utils/generation.js +7 -0
- package/dist/utils/guid4.js +122 -0
- package/dist/utils/project-file-serializer.js +77 -0
- package/dist/utils/reflect.js +30 -0
- package/dist/utils/temp-canvas.js +19 -0
- package/dist/web-component.d.ts +3 -2
- package/dist/web-component.js +179 -0
- package/package.json +1 -1
package/dist/config.js
ADDED
@@ -0,0 +1,95 @@
|
|
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
|
+
;
|
17
|
+
var ConfigFabric = /** @class */ (function () {
|
18
|
+
function ConfigFabric() {
|
19
|
+
}
|
20
|
+
return ConfigFabric;
|
21
|
+
}());
|
22
|
+
export { ConfigFabric };
|
23
|
+
var AppConfig = /** @class */ (function (_super) {
|
24
|
+
__extends(AppConfig, _super);
|
25
|
+
function AppConfig() {
|
26
|
+
var _this = _super.call(this) || this;
|
27
|
+
_this.canvas = null;
|
28
|
+
_this._CANVAS_SIZE = {
|
29
|
+
width: 300,
|
30
|
+
height: 150,
|
31
|
+
};
|
32
|
+
_this._LAYERS = [
|
33
|
+
{
|
34
|
+
name: 'low',
|
35
|
+
index: 1,
|
36
|
+
},
|
37
|
+
{
|
38
|
+
name: 'normal',
|
39
|
+
index: 2,
|
40
|
+
},
|
41
|
+
{
|
42
|
+
name: 'high',
|
43
|
+
index: 3,
|
44
|
+
}
|
45
|
+
];
|
46
|
+
_this._ZOOM = 1;
|
47
|
+
return _this;
|
48
|
+
}
|
49
|
+
AppConfig.prototype.bindCanvas = function (canvasElement) {
|
50
|
+
this.canvas = canvasElement.querySelector('canvas');
|
51
|
+
};
|
52
|
+
Object.defineProperty(AppConfig.prototype, "CANVAS_SIZE", {
|
53
|
+
get: function () {
|
54
|
+
return this._CANVAS_SIZE;
|
55
|
+
},
|
56
|
+
set: function (value) {
|
57
|
+
if (!!value && !!(value === null || value === void 0 ? void 0 : value.width) && !!(value === null || value === void 0 ? void 0 : value.height)) {
|
58
|
+
this._CANVAS_SIZE = value;
|
59
|
+
if (!!this.canvas) {
|
60
|
+
this.canvas.width = value.width;
|
61
|
+
this.canvas.height = value.height;
|
62
|
+
}
|
63
|
+
}
|
64
|
+
else {
|
65
|
+
console.warn('CANVAS_SIZE denied');
|
66
|
+
}
|
67
|
+
},
|
68
|
+
enumerable: false,
|
69
|
+
configurable: true
|
70
|
+
});
|
71
|
+
Object.defineProperty(AppConfig.prototype, "LAYERS", {
|
72
|
+
get: function () {
|
73
|
+
return this._LAYERS;
|
74
|
+
},
|
75
|
+
set: function (value) {
|
76
|
+
if (!!value && !!(value === null || value === void 0 ? void 0 : value.length)) {
|
77
|
+
this._LAYERS = value;
|
78
|
+
}
|
79
|
+
},
|
80
|
+
enumerable: false,
|
81
|
+
configurable: true
|
82
|
+
});
|
83
|
+
Object.defineProperty(AppConfig.prototype, "ZOOM", {
|
84
|
+
get: function () {
|
85
|
+
return this._ZOOM;
|
86
|
+
},
|
87
|
+
set: function (value) {
|
88
|
+
this._ZOOM = value;
|
89
|
+
},
|
90
|
+
enumerable: false,
|
91
|
+
configurable: true
|
92
|
+
});
|
93
|
+
return AppConfig;
|
94
|
+
}(ConfigFabric));
|
95
|
+
export default AppConfig;
|
@@ -0,0 +1,168 @@
|
|
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 { Filter } from "../../utils/filter";
|
17
|
+
import { Convert } from "../../utils/convert";
|
18
|
+
import { range } from '../../utils/generation';
|
19
|
+
var VagueFilter = /** @class */ (function (_super) {
|
20
|
+
__extends(VagueFilter, _super);
|
21
|
+
function VagueFilter(appConfig, ctx, options) {
|
22
|
+
var _this = _super.call(this, appConfig, ctx) || this;
|
23
|
+
_this.filterList = ['pixel'];
|
24
|
+
_this.options = options;
|
25
|
+
return _this;
|
26
|
+
}
|
27
|
+
VagueFilter.prototype.on = function (action, filterOptions) {
|
28
|
+
var _this = this;
|
29
|
+
return new Promise(function (resolve) {
|
30
|
+
var options = _this.options;
|
31
|
+
var imageData = _this.copy(options);
|
32
|
+
// TODO: rewrite on pattern Strategies
|
33
|
+
var rowImageData = _this[action](imageData, filterOptions);
|
34
|
+
_this.update(rowImageData, options);
|
35
|
+
return resolve({
|
36
|
+
imageData: rowImageData,
|
37
|
+
position: {
|
38
|
+
x: options.x,
|
39
|
+
y: options.y,
|
40
|
+
},
|
41
|
+
size: {
|
42
|
+
width: rowImageData.width,
|
43
|
+
height: rowImageData.height,
|
44
|
+
},
|
45
|
+
quality: filterOptions.quality,
|
46
|
+
});
|
47
|
+
});
|
48
|
+
};
|
49
|
+
VagueFilter.prototype.pixel = function (imageData, filterOptions) {
|
50
|
+
var quality = filterOptions.quality;
|
51
|
+
// expansion strategy
|
52
|
+
var processedImageData = this.getQualityProcessedRemainder(imageData, +quality);
|
53
|
+
// TODO: add compression strategy and use register strategies;
|
54
|
+
var imageSize = {
|
55
|
+
width: processedImageData.width,
|
56
|
+
height: processedImageData.height,
|
57
|
+
};
|
58
|
+
this.setImageSize(imageSize);
|
59
|
+
var _a = this.getBuffCollection(processedImageData), rowRGBABuff = _a.rowRGBABuff, buff = _a.buff;
|
60
|
+
var _b = this.getQualityBuff(buff, +quality), qualityBuff = _b.qualityBuff, rangeCommit = _b.rangeCommit;
|
61
|
+
var qualityBuffWithMostCommonElement = this.getMostCommonQuanlityBuff(qualityBuff, rangeCommit);
|
62
|
+
var rowQualityBuffWithMostCommonElement = qualityBuffWithMostCommonElement.flat();
|
63
|
+
if (rowRGBABuff.length >= rowQualityBuffWithMostCommonElement.length) {
|
64
|
+
var occurrenceRGBAbuff = rowQualityBuffWithMostCommonElement.map(function (hexColor, index) {
|
65
|
+
var _a = Convert.hexToRgb(hexColor), r = _a.r, g = _a.g, b = _a.b;
|
66
|
+
var a = rowRGBABuff[index][3];
|
67
|
+
return [r, g, b, a];
|
68
|
+
});
|
69
|
+
var rowBuff = occurrenceRGBAbuff.flat();
|
70
|
+
rowBuff.forEach(function (color, index) {
|
71
|
+
processedImageData.data[index] = color;
|
72
|
+
});
|
73
|
+
}
|
74
|
+
return processedImageData;
|
75
|
+
};
|
76
|
+
VagueFilter.prototype.getQualityProcessedRemainder = function (imageData, quality) {
|
77
|
+
var rowRGBABuff = this.getRowRGBABuff(imageData);
|
78
|
+
var RGBAMatrix = this.getRGBAMatrix(rowRGBABuff, { width: imageData.width, height: imageData.height });
|
79
|
+
var cqx = quality - (imageData.width % quality);
|
80
|
+
var cqy = quality - (imageData.height % quality);
|
81
|
+
var xCommit = range(0, cqx);
|
82
|
+
var yCommit = range(0, cqy);
|
83
|
+
var tempSize = {
|
84
|
+
width: imageData.width + cqx,
|
85
|
+
height: imageData.height + cqy,
|
86
|
+
};
|
87
|
+
var xLastIndex = RGBAMatrix[0].length - 1;
|
88
|
+
RGBAMatrix.forEach(function (row, y) {
|
89
|
+
var xLastRGBAByte = row[xLastIndex];
|
90
|
+
xCommit.forEach(function () { return RGBAMatrix[y].push(xLastRGBAByte); });
|
91
|
+
});
|
92
|
+
var yLastIndex = RGBAMatrix.length - 1;
|
93
|
+
var yLastRGBARow = RGBAMatrix[yLastIndex];
|
94
|
+
yCommit.forEach(function () { return RGBAMatrix.push(yLastRGBARow); });
|
95
|
+
var buffWithRemainder = RGBAMatrix.flat(2);
|
96
|
+
var tempCanvas = document.createElement('canvas');
|
97
|
+
var tempCtx = tempCanvas.getContext('2d');
|
98
|
+
var tempImageData = tempCtx.createImageData(tempSize.width, tempSize.height);
|
99
|
+
buffWithRemainder.forEach(function (_, i) { return tempImageData.data[i] = buffWithRemainder[i]; });
|
100
|
+
return tempImageData;
|
101
|
+
};
|
102
|
+
VagueFilter.prototype.getQualityBuff = function (buff, quality) {
|
103
|
+
var wq = Math.floor(this.imageSize.width / quality);
|
104
|
+
var hq = Math.floor(this.imageSize.height / quality);
|
105
|
+
var qualityBuff = [];
|
106
|
+
var rangeCommit = [];
|
107
|
+
var i = 0;
|
108
|
+
var xStart = 0;
|
109
|
+
var xEnd = quality;
|
110
|
+
var yStart = 0;
|
111
|
+
var yEnd = quality;
|
112
|
+
range(0, hq).forEach(function (hqi) {
|
113
|
+
range(0, wq).forEach(function (wqi) {
|
114
|
+
var _a, _b;
|
115
|
+
var dy = range(yStart, yEnd);
|
116
|
+
var dx = range(xStart, xEnd);
|
117
|
+
var items = [];
|
118
|
+
var coords = [];
|
119
|
+
dy.forEach(function (y) {
|
120
|
+
dx.forEach(function (x) {
|
121
|
+
items.push(buff[y][x]);
|
122
|
+
coords.push({ y: y, x: x });
|
123
|
+
});
|
124
|
+
});
|
125
|
+
xStart += quality;
|
126
|
+
xEnd += quality;
|
127
|
+
(_a = rangeCommit[i]) !== null && _a !== void 0 ? _a : (rangeCommit[i] = coords);
|
128
|
+
(_b = qualityBuff[i]) !== null && _b !== void 0 ? _b : (qualityBuff[i] = items);
|
129
|
+
i++;
|
130
|
+
});
|
131
|
+
xStart = 0;
|
132
|
+
xEnd = quality;
|
133
|
+
yStart += quality;
|
134
|
+
yEnd += quality;
|
135
|
+
});
|
136
|
+
return { qualityBuff: qualityBuff, rangeCommit: rangeCommit };
|
137
|
+
};
|
138
|
+
VagueFilter.prototype.getMostCommonQuanlityBuff = function (qualityBuff, rangeCommit) {
|
139
|
+
var _this = this;
|
140
|
+
var mostCommonQuanlityBuff = [];
|
141
|
+
var qualityBuffWithMostCommonElement = qualityBuff.map(function (newPixel) {
|
142
|
+
var color = _this.getMostCommonElement(newPixel);
|
143
|
+
return newPixel.map(function () { return color; });
|
144
|
+
});
|
145
|
+
qualityBuffWithMostCommonElement.forEach(function (qPixel, pixelIndex) {
|
146
|
+
qPixel.forEach(function (pixelColor, pixelColorIndex) {
|
147
|
+
var _a, _b;
|
148
|
+
var _c;
|
149
|
+
var _d = rangeCommit[pixelIndex][pixelColorIndex], x = _d.x, y = _d.y;
|
150
|
+
(_a = mostCommonQuanlityBuff[y]) !== null && _a !== void 0 ? _a : (mostCommonQuanlityBuff[y] = []);
|
151
|
+
(_b = (_c = mostCommonQuanlityBuff[y])[x]) !== null && _b !== void 0 ? _b : (_c[x] = pixelColor);
|
152
|
+
});
|
153
|
+
});
|
154
|
+
return mostCommonQuanlityBuff;
|
155
|
+
};
|
156
|
+
VagueFilter.prototype.getMostCommonElement = function (array) {
|
157
|
+
function mostCommon(a, b) {
|
158
|
+
var diffA = array.filter(function (v) { return v === a; }).length;
|
159
|
+
var diffB = array.filter(function (v) { return v === b; }).length;
|
160
|
+
return diffA - diffB;
|
161
|
+
}
|
162
|
+
var arraySorted = array.sort(mostCommon);
|
163
|
+
var mostCommonElement = arraySorted[arraySorted.length - 1];
|
164
|
+
return mostCommonElement;
|
165
|
+
};
|
166
|
+
return VagueFilter;
|
167
|
+
}(Filter));
|
168
|
+
export default VagueFilter;
|
package/dist/index.d.ts
CHANGED
@@ -15,6 +15,7 @@ import EventService from "./services/event.service";
|
|
15
15
|
import ThroughHistoryService from "./services/through-history.service";
|
16
16
|
import ProjectsService from "./services/projects.service";
|
17
17
|
import PullProjectService from "./services/pull-project.service";
|
18
|
+
import DrawAccumulatorService from './services/draw-accumulator.service';
|
18
19
|
import AppStore from "./store/store";
|
19
20
|
import AppStoreRepository from "./store/storeRepository";
|
20
21
|
declare class CanvasEditorEngine {
|
@@ -30,4 +31,4 @@ declare class StaticCanvasEditorEngine extends CanvasEditorEngine {
|
|
30
31
|
declare class VueCanvasEditorEngine extends CanvasEditorEngine {
|
31
32
|
constructor();
|
32
33
|
}
|
33
|
-
export { AppConfig, PipetteComponent, CanvasComponent, ExcretionComponent, SlotComponent, LoadingComponent, ToolService, DrawService, LoggerService, CropService, DownloadService, ToolLayerService, EventService, ThroughHistoryService, ProjectsService, PullProjectService, StaticCanvasEditorEngine, VueCanvasEditorEngine, AppStore, AppStoreRepository, };
|
34
|
+
export { AppConfig, PipetteComponent, CanvasComponent, ExcretionComponent, SlotComponent, LoadingComponent, ToolService, DrawService, LoggerService, CropService, DownloadService, ToolLayerService, EventService, ThroughHistoryService, ProjectsService, PullProjectService, DrawAccumulatorService, StaticCanvasEditorEngine, VueCanvasEditorEngine, AppStore, AppStoreRepository, };
|
package/dist/index.js
ADDED
@@ -0,0 +1,75 @@
|
|
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 AppConfig from "./config";
|
19
|
+
import WebComponent from "./web-component";
|
20
|
+
import CanvasComponent from "./components/canvas.component";
|
21
|
+
import PipetteComponent from "./components/pipette.component";
|
22
|
+
import ExcretionComponent from "./components/excretions.component";
|
23
|
+
import SlotComponent from "./components/slot.component";
|
24
|
+
import LoadingComponent from "./components/loading.component";
|
25
|
+
import DrawService from "./services/draw.service";
|
26
|
+
import ToolService from "./services/tool.service";
|
27
|
+
import LoggerService from "./services/logger.service";
|
28
|
+
import CropService from "./services/crop.service";
|
29
|
+
import DownloadService from "./services/download.service";
|
30
|
+
import ToolLayerService from "./services/tool-layers.service";
|
31
|
+
import EventService from "./services/event.service";
|
32
|
+
import ThroughHistoryService from "./services/through-history.service";
|
33
|
+
import ProjectsService from "./services/projects.service";
|
34
|
+
import PullProjectService from "./services/pull-project.service";
|
35
|
+
import DrawAccumulatorService from './services/draw-accumulator.service';
|
36
|
+
import AppStore from "./store/store";
|
37
|
+
import AppStoreRepository from "./store/storeRepository";
|
38
|
+
var CanvasEditorEngine = /** @class */ (function () {
|
39
|
+
function CanvasEditorEngine() {
|
40
|
+
}
|
41
|
+
CanvasEditorEngine.prototype.getInitial = function () {
|
42
|
+
return { component: WebComponent };
|
43
|
+
};
|
44
|
+
return CanvasEditorEngine;
|
45
|
+
}());
|
46
|
+
var StaticCanvasEditorEngine = /** @class */ (function (_super) {
|
47
|
+
__extends(StaticCanvasEditorEngine, _super);
|
48
|
+
function StaticCanvasEditorEngine() {
|
49
|
+
return _super.call(this) || this;
|
50
|
+
}
|
51
|
+
StaticCanvasEditorEngine.prototype.init = function () {
|
52
|
+
var customElementRegistry = window.customElements;
|
53
|
+
var component = this.getInitial().component;
|
54
|
+
customElementRegistry.define('canvas-editor-engine', component);
|
55
|
+
};
|
56
|
+
return StaticCanvasEditorEngine;
|
57
|
+
}(CanvasEditorEngine));
|
58
|
+
var VueCanvasEditorEngine = /** @class */ (function (_super) {
|
59
|
+
__extends(VueCanvasEditorEngine, _super);
|
60
|
+
function VueCanvasEditorEngine() {
|
61
|
+
return _super.call(this) || this;
|
62
|
+
}
|
63
|
+
return VueCanvasEditorEngine;
|
64
|
+
}(CanvasEditorEngine));
|
65
|
+
export {
|
66
|
+
// config
|
67
|
+
AppConfig,
|
68
|
+
// components
|
69
|
+
PipetteComponent, CanvasComponent, ExcretionComponent, SlotComponent, LoadingComponent,
|
70
|
+
// services
|
71
|
+
ToolService, DrawService, LoggerService, CropService, DownloadService, ToolLayerService, EventService, ThroughHistoryService, ProjectsService, PullProjectService, DrawAccumulatorService,
|
72
|
+
// general
|
73
|
+
StaticCanvasEditorEngine, VueCanvasEditorEngine,
|
74
|
+
// store
|
75
|
+
AppStore, AppStoreRepository, };
|
@@ -0,0 +1,40 @@
|
|
1
|
+
import { reflect } from "../utils/reflect";
|
2
|
+
reflect();
|
3
|
+
var ComponentService = /** @class */ (function () {
|
4
|
+
function ComponentService() {
|
5
|
+
}
|
6
|
+
ComponentService.prototype.getTemplate = function (template, wrapOptions) {
|
7
|
+
var options = {
|
8
|
+
tag: 'div',
|
9
|
+
};
|
10
|
+
if (!!wrapOptions) {
|
11
|
+
Object.keys(wrapOptions).forEach(function (key) {
|
12
|
+
if (!!wrapOptions[key]) {
|
13
|
+
options[key] = wrapOptions[key];
|
14
|
+
}
|
15
|
+
});
|
16
|
+
}
|
17
|
+
var wrap = document.createElement(options.tag);
|
18
|
+
if (!!options) {
|
19
|
+
Object.keys(options).forEach(function (key) {
|
20
|
+
if (!!options[key] && key !== 'tag') {
|
21
|
+
wrap[key] = options[key];
|
22
|
+
}
|
23
|
+
});
|
24
|
+
}
|
25
|
+
if (!!template) {
|
26
|
+
wrap.innerHTML = template;
|
27
|
+
}
|
28
|
+
return wrap;
|
29
|
+
};
|
30
|
+
ComponentService.prototype.getStyle = function (css) {
|
31
|
+
if (!!css === false)
|
32
|
+
return null;
|
33
|
+
var style = document.createElement('style');
|
34
|
+
style.type = 'text/css';
|
35
|
+
style.appendChild(document.createTextNode(css));
|
36
|
+
return style;
|
37
|
+
};
|
38
|
+
return ComponentService;
|
39
|
+
}());
|
40
|
+
export default ComponentService;
|
@@ -0,0 +1,60 @@
|
|
1
|
+
import { Filter } from "../utils/filter";
|
2
|
+
var CropService = /** @class */ (function () {
|
3
|
+
function CropService(appConfig, appStoreRepository, excretionComponent) {
|
4
|
+
this.appConfig = appConfig;
|
5
|
+
this.appStoreRepository = appStoreRepository;
|
6
|
+
this.excretionComponent = excretionComponent;
|
7
|
+
}
|
8
|
+
CropService.prototype.activate = function () {
|
9
|
+
this.excretionComponent.additionStyle = 'crop';
|
10
|
+
};
|
11
|
+
CropService.prototype.deactivate = function () {
|
12
|
+
this.excretionComponent.additionStyle = 'default';
|
13
|
+
};
|
14
|
+
CropService.prototype.crop = function (ctx) {
|
15
|
+
var _a;
|
16
|
+
if (!!((_a = this.excretionComponent.excretionsCoords) === null || _a === void 0 ? void 0 : _a.length) === false)
|
17
|
+
return;
|
18
|
+
var filter = new Filter(this.appConfig, ctx);
|
19
|
+
var options = this.options;
|
20
|
+
var _b = filter.copyExtendedModel(options), imageData = _b.imageData, size = _b.size;
|
21
|
+
var position = {
|
22
|
+
x: (this.appConfig.CANVAS_SIZE.width / 2) - (size.width / 2),
|
23
|
+
y: (this.appConfig.CANVAS_SIZE.height / 2) - (size.height / 2),
|
24
|
+
};
|
25
|
+
filter.update(imageData, position);
|
26
|
+
this.appStoreRepository.store.imageState.reduce({
|
27
|
+
tempImageData: imageData,
|
28
|
+
position: position,
|
29
|
+
size: {
|
30
|
+
width: size.width,
|
31
|
+
height: size.height,
|
32
|
+
}
|
33
|
+
}, "Use crop");
|
34
|
+
};
|
35
|
+
// TODO: refactor
|
36
|
+
CropService.prototype.viewCropButton = function () {
|
37
|
+
var cropButtons = this.excretionComponent.excretionWrap.querySelectorAll('.crop-button');
|
38
|
+
var lastCropButtonIndex = cropButtons.length - 1;
|
39
|
+
var cropButton = cropButtons[lastCropButtonIndex];
|
40
|
+
cropButton.classList.add('crop-button--view');
|
41
|
+
};
|
42
|
+
Object.defineProperty(CropService.prototype, "options", {
|
43
|
+
get: function () {
|
44
|
+
var excretionLastIndex = this.excretionComponent.excretionsCoords.length - 1;
|
45
|
+
var coords = this.excretionComponent.excretionsCoords[excretionLastIndex];
|
46
|
+
var excWidth = Math.abs(coords.start.x - coords.end.x);
|
47
|
+
var excHeight = Math.abs(coords.start.y - coords.end.y);
|
48
|
+
return {
|
49
|
+
x: coords.start.x,
|
50
|
+
y: coords.start.y,
|
51
|
+
width: excWidth,
|
52
|
+
height: excHeight,
|
53
|
+
};
|
54
|
+
},
|
55
|
+
enumerable: false,
|
56
|
+
configurable: true
|
57
|
+
});
|
58
|
+
return CropService;
|
59
|
+
}());
|
60
|
+
export default CropService;
|
@@ -0,0 +1,16 @@
|
|
1
|
+
var DownloadService = /** @class */ (function () {
|
2
|
+
function DownloadService(canvasComponent) {
|
3
|
+
this.canvasComponent = canvasComponent;
|
4
|
+
}
|
5
|
+
DownloadService.prototype.getDataUrl = function () {
|
6
|
+
return this.canvasComponent.canvas.toDataURL();
|
7
|
+
};
|
8
|
+
DownloadService.prototype.download = function (filename) {
|
9
|
+
var link = document.createElement('a');
|
10
|
+
link.download = "".concat(filename || 'image', ".png");
|
11
|
+
link.href = this.getDataUrl();
|
12
|
+
link.click();
|
13
|
+
};
|
14
|
+
return DownloadService;
|
15
|
+
}());
|
16
|
+
export default DownloadService;
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import AppConfig from "../config";
|
2
|
+
import AppStoreRepository from "../store/storeRepository";
|
3
|
+
import { ILayer } from "../types/draw-layers";
|
4
|
+
import { IPainter, ISmoothFilterOptions, TDrawType } from "../types/draw-service";
|
5
|
+
import { ITempCanvasOptions } from "../types/temp-canvas";
|
6
|
+
import DrawLayersService from "./draw-leayers.service";
|
7
|
+
import DrawService from "./draw.service";
|
8
|
+
import EventService from "./event.service";
|
9
|
+
export default class DrawAccumulatorService {
|
10
|
+
private appConfig;
|
11
|
+
private appStoreRepository;
|
12
|
+
private eventService;
|
13
|
+
private drawLayersService;
|
14
|
+
painters: IPainter[];
|
15
|
+
constructor(appConfig: AppConfig, appStoreRepository: AppStoreRepository, eventService: EventService, drawLayersService: DrawLayersService);
|
16
|
+
add<DrawType extends TDrawType>(layerId: ILayer['id'], drawType: DrawType, options: DrawService['options'][DrawType], initialSize: ITempCanvasOptions): Promise<void>;
|
17
|
+
removePainter(id: string): Promise<void>;
|
18
|
+
smoothFilter(painterId: IPainter['id'], smoothFilterOptions: ISmoothFilterOptions): Promise<void>;
|
19
|
+
private update;
|
20
|
+
private get gradient();
|
21
|
+
private clearCanvas;
|
22
|
+
private invokePaintersOnLayers;
|
23
|
+
private invokePainter;
|
24
|
+
private invokePainterWithTempCtx;
|
25
|
+
}
|