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
@@ -1,60 +0,0 @@
|
|
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;
|
@@ -1,16 +0,0 @@
|
|
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;
|
@@ -1,222 +0,0 @@
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
8
|
-
});
|
9
|
-
};
|
10
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
11
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
12
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
13
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
14
|
-
function step(op) {
|
15
|
-
if (f) throw new TypeError("Generator is already executing.");
|
16
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
17
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
18
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
19
|
-
switch (op[0]) {
|
20
|
-
case 0: case 1: t = op; break;
|
21
|
-
case 4: _.label++; return { value: op[1], done: false };
|
22
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
23
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
24
|
-
default:
|
25
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
26
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
27
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
28
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
29
|
-
if (t[2]) _.ops.pop();
|
30
|
-
_.trys.pop(); continue;
|
31
|
-
}
|
32
|
-
op = body.call(thisArg, _);
|
33
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
34
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
35
|
-
}
|
36
|
-
};
|
37
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
38
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
39
|
-
if (ar || !(i in from)) {
|
40
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
41
|
-
ar[i] = from[i];
|
42
|
-
}
|
43
|
-
}
|
44
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
45
|
-
};
|
46
|
-
import DrawService from "./draw.service";
|
47
|
-
var DrawAccumulatorService = /** @class */ (function () {
|
48
|
-
function DrawAccumulatorService(appConfig, appStoreRepository, eventService, drawLayersService) {
|
49
|
-
this.appConfig = appConfig;
|
50
|
-
this.appStoreRepository = appStoreRepository;
|
51
|
-
this.eventService = eventService;
|
52
|
-
this.drawLayersService = drawLayersService;
|
53
|
-
this.painters = new Proxy([], {
|
54
|
-
get: function (target, name) {
|
55
|
-
return target[name];
|
56
|
-
},
|
57
|
-
set: function (target, name, value) {
|
58
|
-
try {
|
59
|
-
if (typeof (value === null || value === void 0 ? void 0 : value.object) !== 'undefined') {
|
60
|
-
target[name] = value.object;
|
61
|
-
value.update();
|
62
|
-
return true;
|
63
|
-
}
|
64
|
-
else {
|
65
|
-
if (name != 'length') {
|
66
|
-
console.warn('Proxy set error: object denied');
|
67
|
-
return false;
|
68
|
-
}
|
69
|
-
else {
|
70
|
-
var MIN_LENGTH = -1;
|
71
|
-
var MAX_LENGTH = __spreadArray([], Object.keys(target), true);
|
72
|
-
if (value <= Math.max.apply(Math, __spreadArray([MIN_LENGTH], MAX_LENGTH, false)) + 1) {
|
73
|
-
target.length = value;
|
74
|
-
}
|
75
|
-
}
|
76
|
-
return true;
|
77
|
-
}
|
78
|
-
}
|
79
|
-
catch (error) {
|
80
|
-
console.error('Proxy set error:', error);
|
81
|
-
return false;
|
82
|
-
}
|
83
|
-
},
|
84
|
-
});
|
85
|
-
}
|
86
|
-
DrawAccumulatorService.prototype.add = function (layerId, drawType, options, initialSize) {
|
87
|
-
return __awaiter(this, void 0, void 0, function () {
|
88
|
-
var id, painter;
|
89
|
-
return __generator(this, function (_a) {
|
90
|
-
id = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
|
91
|
-
painter = {
|
92
|
-
drawService: new DrawService(this.appConfig, this.appStoreRepository, this.eventService),
|
93
|
-
drawType: drawType,
|
94
|
-
id: id,
|
95
|
-
};
|
96
|
-
painter.drawService.bindOptions(drawType, options);
|
97
|
-
painter.drawService.tempCanvas.bindOptions(initialSize);
|
98
|
-
this.painters.push({
|
99
|
-
object: painter,
|
100
|
-
update: this.update.bind(this),
|
101
|
-
});
|
102
|
-
this.drawLayersService.addToLayer(layerId, painter);
|
103
|
-
this.invokePainter(drawType, painter.drawService);
|
104
|
-
return [2 /*return*/];
|
105
|
-
});
|
106
|
-
});
|
107
|
-
};
|
108
|
-
DrawAccumulatorService.prototype.removePainter = function (id) {
|
109
|
-
return __awaiter(this, void 0, void 0, function () {
|
110
|
-
var painter;
|
111
|
-
return __generator(this, function (_a) {
|
112
|
-
painter = this.painters.find(function (painter) { return painter.id === id; });
|
113
|
-
if (!!painter) {
|
114
|
-
this.painters = this.painters.filter(function (painter) { return painter.id !== id; });
|
115
|
-
}
|
116
|
-
this.drawLayersService.removePainter(id);
|
117
|
-
return [2 /*return*/];
|
118
|
-
});
|
119
|
-
});
|
120
|
-
};
|
121
|
-
DrawAccumulatorService.prototype.smoothFilter = function (painterId, smoothFilterOptions) {
|
122
|
-
return __awaiter(this, void 0, void 0, function () {
|
123
|
-
var useStore, options, filterOptions, painter;
|
124
|
-
var _this = this;
|
125
|
-
return __generator(this, function (_a) {
|
126
|
-
useStore = smoothFilterOptions.useStore, options = smoothFilterOptions.options, filterOptions = smoothFilterOptions.filterOptions;
|
127
|
-
painter = this.painters.find(function (painter) { return painter.id === painterId; });
|
128
|
-
if (!painter)
|
129
|
-
return [2 /*return*/];
|
130
|
-
painter.drawService.drawSmoothImage(useStore, options, filterOptions).then(function () {
|
131
|
-
_this.update();
|
132
|
-
});
|
133
|
-
return [2 /*return*/];
|
134
|
-
});
|
135
|
-
});
|
136
|
-
};
|
137
|
-
DrawAccumulatorService.prototype.update = function () {
|
138
|
-
var _this = this;
|
139
|
-
setTimeout(function () {
|
140
|
-
_this.clearCanvas();
|
141
|
-
_this.invokePaintersOnLayers();
|
142
|
-
}, 1000);
|
143
|
-
};
|
144
|
-
Object.defineProperty(DrawAccumulatorService.prototype, "gradient", {
|
145
|
-
get: function () {
|
146
|
-
var _this = this;
|
147
|
-
var gradient = [];
|
148
|
-
this.painters.forEach(function (painter) {
|
149
|
-
var layer = _this.drawLayersService.layerList.find(function (layer) { return layer.painters.includes(painter); });
|
150
|
-
if (layer) {
|
151
|
-
gradient.push(layer.order);
|
152
|
-
}
|
153
|
-
});
|
154
|
-
return gradient.sort(function (a, b) { return a - b; });
|
155
|
-
},
|
156
|
-
enumerable: false,
|
157
|
-
configurable: true
|
158
|
-
});
|
159
|
-
DrawAccumulatorService.prototype.clearCanvas = function () {
|
160
|
-
var ctx = this.appConfig.canvas.getContext('2d');
|
161
|
-
ctx.clearRect(0, 0, this.appConfig.CANVAS_SIZE.width, this.appConfig.CANVAS_SIZE.height);
|
162
|
-
ctx.save();
|
163
|
-
};
|
164
|
-
DrawAccumulatorService.prototype.invokePaintersOnLayers = function () {
|
165
|
-
var _this = this;
|
166
|
-
var stash = [];
|
167
|
-
this.gradient.forEach(function (order) {
|
168
|
-
_this.painters.forEach(function (painter) {
|
169
|
-
var layer = _this.drawLayersService.layerList.find(function (layer) { return layer.painters.includes(painter); });
|
170
|
-
if (!layer)
|
171
|
-
return console.warn('[invoke] Layer not found');
|
172
|
-
if (!stash.includes(painter) && layer.order === order) {
|
173
|
-
_this.invokePainterWithTempCtx(painter.drawType, painter.drawService);
|
174
|
-
stash.push(painter);
|
175
|
-
}
|
176
|
-
});
|
177
|
-
});
|
178
|
-
};
|
179
|
-
DrawAccumulatorService.prototype.invokePainter = function (drawType, painter) {
|
180
|
-
return __awaiter(this, void 0, void 0, function () {
|
181
|
-
return __generator(this, function (_a) {
|
182
|
-
switch (_a.label) {
|
183
|
-
case 0:
|
184
|
-
if (!(drawType === 'image')) return [3 /*break*/, 2];
|
185
|
-
return [4 /*yield*/, painter.drawImage()];
|
186
|
-
case 1:
|
187
|
-
_a.sent();
|
188
|
-
return [3 /*break*/, 4];
|
189
|
-
case 2:
|
190
|
-
if (!(drawType === 'project')) return [3 /*break*/, 4];
|
191
|
-
return [4 /*yield*/, painter.drawProject()];
|
192
|
-
case 3:
|
193
|
-
_a.sent();
|
194
|
-
_a.label = 4;
|
195
|
-
case 4: return [2 /*return*/];
|
196
|
-
}
|
197
|
-
});
|
198
|
-
});
|
199
|
-
};
|
200
|
-
DrawAccumulatorService.prototype.invokePainterWithTempCtx = function (drawType, painter) {
|
201
|
-
return __awaiter(this, void 0, void 0, function () {
|
202
|
-
var imageData, ctx, x, y;
|
203
|
-
return __generator(this, function (_a) {
|
204
|
-
imageData = painter.tempCanvas.getImageData();
|
205
|
-
ctx = this.appConfig.canvas.getContext('2d');
|
206
|
-
if (drawType === 'image') {
|
207
|
-
x = painter.options.image.drawImageArgs.position.x;
|
208
|
-
y = painter.options.image.drawImageArgs.position.y;
|
209
|
-
ctx.putImageData(imageData, x, y);
|
210
|
-
ctx.save();
|
211
|
-
}
|
212
|
-
else if (drawType === 'project') {
|
213
|
-
ctx.putImageData(imageData, 0, 0);
|
214
|
-
ctx.save();
|
215
|
-
}
|
216
|
-
return [2 /*return*/];
|
217
|
-
});
|
218
|
-
});
|
219
|
-
};
|
220
|
-
return DrawAccumulatorService;
|
221
|
-
}());
|
222
|
-
export default DrawAccumulatorService;
|
@@ -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;
|
@@ -1,259 +0,0 @@
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
8
|
-
});
|
9
|
-
};
|
10
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
11
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
12
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
13
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
14
|
-
function step(op) {
|
15
|
-
if (f) throw new TypeError("Generator is already executing.");
|
16
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
17
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
18
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
19
|
-
switch (op[0]) {
|
20
|
-
case 0: case 1: t = op; break;
|
21
|
-
case 4: _.label++; return { value: op[1], done: false };
|
22
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
23
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
24
|
-
default:
|
25
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
26
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
27
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
28
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
29
|
-
if (t[2]) _.ops.pop();
|
30
|
-
_.trys.pop(); continue;
|
31
|
-
}
|
32
|
-
op = body.call(thisArg, _);
|
33
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
34
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
35
|
-
}
|
36
|
-
};
|
37
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
38
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
39
|
-
if (ar || !(i in from)) {
|
40
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
41
|
-
ar[i] = from[i];
|
42
|
-
}
|
43
|
-
}
|
44
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
45
|
-
};
|
46
|
-
import { VagueFilter } from "../filters";
|
47
|
-
import { Filter } from "../utils/filter";
|
48
|
-
import { TempCanvas } from "../utils/temp-canvas";
|
49
|
-
var DrawService = /** @class */ (function () {
|
50
|
-
function DrawService(appConfig, appStoreRepository, eventService) {
|
51
|
-
this.appConfig = appConfig;
|
52
|
-
this.appStoreRepository = appStoreRepository;
|
53
|
-
this.eventService = eventService;
|
54
|
-
this.options = {
|
55
|
-
image: null,
|
56
|
-
project: null,
|
57
|
-
};
|
58
|
-
this.tempCanvas = new TempCanvas();
|
59
|
-
this.id = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
|
60
|
-
}
|
61
|
-
;
|
62
|
-
DrawService.prototype.bindOptions = function (drawType, options) {
|
63
|
-
this.options[drawType] = options;
|
64
|
-
};
|
65
|
-
DrawService.prototype.drawImage = function () {
|
66
|
-
return __awaiter(this, void 0, void 0, function () {
|
67
|
-
var _a, src, drawImageArgs, ctx;
|
68
|
-
var _this = this;
|
69
|
-
return __generator(this, function (_b) {
|
70
|
-
switch (_b.label) {
|
71
|
-
case 0:
|
72
|
-
_a = this.options.image, src = _a.src, drawImageArgs = _a.drawImageArgs;
|
73
|
-
ctx = this.tempCanvas.ctx;
|
74
|
-
this.imageProcessor = new ImageObject(this.appConfig, src, ctx);
|
75
|
-
return [4 /*yield*/, this.imageProcessor.draw(drawImageArgs).then(function () {
|
76
|
-
var responseData = {
|
77
|
-
reduceData: null,
|
78
|
-
message: null,
|
79
|
-
};
|
80
|
-
var zeroPosition = {
|
81
|
-
x: 0,
|
82
|
-
y: 0,
|
83
|
-
};
|
84
|
-
var filter = new Filter(_this.appConfig, ctx);
|
85
|
-
var imageData = filter.copy(zeroPosition);
|
86
|
-
responseData.reduceData = {
|
87
|
-
tempImageData: imageData,
|
88
|
-
position: zeroPosition,
|
89
|
-
size: _this.appConfig.CANVAS_SIZE,
|
90
|
-
};
|
91
|
-
responseData.message = "Image loaded";
|
92
|
-
_this.appStoreRepository.store.imageState.reduce(responseData.reduceData, responseData.message);
|
93
|
-
return responseData;
|
94
|
-
})];
|
95
|
-
case 1: return [2 /*return*/, _b.sent()];
|
96
|
-
}
|
97
|
-
});
|
98
|
-
});
|
99
|
-
};
|
100
|
-
DrawService.prototype.drawProject = function () {
|
101
|
-
return __awaiter(this, void 0, void 0, function () {
|
102
|
-
var project, ctx, imageData, position, size;
|
103
|
-
var _this = this;
|
104
|
-
return __generator(this, function (_a) {
|
105
|
-
project = this.options.project;
|
106
|
-
ctx = this.tempCanvas.ctx;
|
107
|
-
imageData = project.state.current.imageData;
|
108
|
-
position = project.state.current.position;
|
109
|
-
size = project.state.current.size;
|
110
|
-
this.imageProcessor = new ProjectImageObject(this.appConfig, project, ctx);
|
111
|
-
return [2 /*return*/, new Promise(function (resolve) {
|
112
|
-
_this.imageProcessor.draw();
|
113
|
-
resolve(null);
|
114
|
-
}).then(function () {
|
115
|
-
var responseData = {
|
116
|
-
reduceData: null,
|
117
|
-
message: null,
|
118
|
-
};
|
119
|
-
responseData.reduceData = {
|
120
|
-
tempImageData: imageData,
|
121
|
-
position: position,
|
122
|
-
size: size,
|
123
|
-
};
|
124
|
-
responseData.message = "Project loaded";
|
125
|
-
_this.appStoreRepository.store.imageState.reduce(responseData.reduceData, responseData.message);
|
126
|
-
return responseData;
|
127
|
-
})];
|
128
|
-
});
|
129
|
-
});
|
130
|
-
};
|
131
|
-
DrawService.prototype.drawSmoothImage = function (useStore, options, filterOptions) {
|
132
|
-
return __awaiter(this, void 0, void 0, function () {
|
133
|
-
var filterArgs;
|
134
|
-
var _this = this;
|
135
|
-
return __generator(this, function (_a) {
|
136
|
-
filterArgs = this.getFilterArgs(useStore, options);
|
137
|
-
this.eventService.dispatch('loading-start');
|
138
|
-
if (!this.imageProcessor) {
|
139
|
-
throw new Error('No valid ImageProcessor instance found');
|
140
|
-
}
|
141
|
-
return [2 /*return*/, this.imageProcessor.vague(filterArgs, filterOptions)
|
142
|
-
.then(function (data) {
|
143
|
-
_this.updateImageStateAfterVague(data);
|
144
|
-
return data;
|
145
|
-
})
|
146
|
-
.finally(function () { return _this.eventService.dispatch('loading-end'); })];
|
147
|
-
});
|
148
|
-
});
|
149
|
-
};
|
150
|
-
DrawService.prototype.updateImageStateAfterVague = function (data) {
|
151
|
-
var imageData = data.imageData, position = data.position, size = data.size, quality = data.quality;
|
152
|
-
this.appStoreRepository.store.imageState.reduce({
|
153
|
-
tempImageData: imageData,
|
154
|
-
position: position,
|
155
|
-
size: size,
|
156
|
-
}, "[Filter Vague] quality: ".concat(quality));
|
157
|
-
};
|
158
|
-
DrawService.prototype.getFilterArgs = function (useStore, options) {
|
159
|
-
var _a, _b;
|
160
|
-
var filterArgs;
|
161
|
-
var store = this.appStoreRepository.store.imageState;
|
162
|
-
if (useStore) {
|
163
|
-
filterArgs = {
|
164
|
-
x: store.position.x,
|
165
|
-
y: store.position.y,
|
166
|
-
};
|
167
|
-
if (!!store.size.width && !!store.size.height) {
|
168
|
-
filterArgs.width = store.size.width;
|
169
|
-
filterArgs.height = store.size.height;
|
170
|
-
}
|
171
|
-
}
|
172
|
-
else {
|
173
|
-
filterArgs = {
|
174
|
-
x: options.position.x,
|
175
|
-
y: options.position.y,
|
176
|
-
};
|
177
|
-
if (options.size !== 'initial') {
|
178
|
-
if (!!((_a = options.size) === null || _a === void 0 ? void 0 : _a.width) && !!((_b = options.size) === null || _b === void 0 ? void 0 : _b.height)) {
|
179
|
-
filterArgs.width = options.size.width;
|
180
|
-
filterArgs.height = options.size.height;
|
181
|
-
}
|
182
|
-
}
|
183
|
-
}
|
184
|
-
return filterArgs;
|
185
|
-
};
|
186
|
-
return DrawService;
|
187
|
-
}());
|
188
|
-
export default DrawService;
|
189
|
-
var ImageObject = /** @class */ (function () {
|
190
|
-
function ImageObject(appConfig, src, ctx) {
|
191
|
-
this.appConfig = appConfig;
|
192
|
-
this.img = new Image();
|
193
|
-
this.img.src = src;
|
194
|
-
this.ctx = ctx;
|
195
|
-
}
|
196
|
-
;
|
197
|
-
ImageObject.prototype.draw = function (options) {
|
198
|
-
var _this = this;
|
199
|
-
var proto = this;
|
200
|
-
var protoImg = this.img;
|
201
|
-
return new Promise(function (resolve, reject) {
|
202
|
-
try {
|
203
|
-
protoImg.addEventListener("load", function () {
|
204
|
-
var _a;
|
205
|
-
var _b, _c;
|
206
|
-
var drawImageArgs = [options.position.x, options.position.y];
|
207
|
-
if (options.size !== 'initial') {
|
208
|
-
if (!!((_b = options.size) === null || _b === void 0 ? void 0 : _b.width) && !!((_c = options.size) === null || _c === void 0 ? void 0 : _c.height)) {
|
209
|
-
drawImageArgs = drawImageArgs.concat([options.size.width, options.size.height]);
|
210
|
-
}
|
211
|
-
else {
|
212
|
-
drawImageArgs = drawImageArgs.concat([_this.appConfig.CANVAS_SIZE.width, _this.appConfig.CANVAS_SIZE.height]);
|
213
|
-
}
|
214
|
-
}
|
215
|
-
// @ts-ignore
|
216
|
-
(_a = _this.ctx).drawImage.apply(_a, __spreadArray([protoImg], drawImageArgs, false));
|
217
|
-
_this.ctx.save();
|
218
|
-
resolve(proto);
|
219
|
-
});
|
220
|
-
}
|
221
|
-
catch (error) {
|
222
|
-
reject(error);
|
223
|
-
}
|
224
|
-
});
|
225
|
-
};
|
226
|
-
ImageObject.prototype.vague = function (options, filterOptions) {
|
227
|
-
var filter = new VagueFilter(this.appConfig, this.ctx, options);
|
228
|
-
return filter.on('pixel', filterOptions);
|
229
|
-
};
|
230
|
-
return ImageObject;
|
231
|
-
}());
|
232
|
-
export { ImageObject };
|
233
|
-
var ProjectImageObject = /** @class */ (function () {
|
234
|
-
function ProjectImageObject(appConfig, project, ctx) {
|
235
|
-
this.appConfig = appConfig;
|
236
|
-
this.project = project;
|
237
|
-
this.ctx = ctx;
|
238
|
-
}
|
239
|
-
ProjectImageObject.prototype.draw = function (options) {
|
240
|
-
var _this = this;
|
241
|
-
var _a = this.project.state.current, imageData = _a.imageData, position = _a.position;
|
242
|
-
return new Promise(function (resolve, reject) {
|
243
|
-
try {
|
244
|
-
var filter = new Filter(_this.appConfig, _this.ctx);
|
245
|
-
filter.update(imageData, position);
|
246
|
-
_this.ctx.save();
|
247
|
-
resolve(_this);
|
248
|
-
}
|
249
|
-
catch (error) {
|
250
|
-
reject(error);
|
251
|
-
}
|
252
|
-
});
|
253
|
-
};
|
254
|
-
ProjectImageObject.prototype.vague = function (options, filterOptions) {
|
255
|
-
var filter = new VagueFilter(this.appConfig, this.ctx, options);
|
256
|
-
return filter.on('pixel', filterOptions);
|
257
|
-
};
|
258
|
-
return ProjectImageObject;
|
259
|
-
}());
|
@@ -1,45 +0,0 @@
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
2
|
-
__assign = Object.assign || function(t) {
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
4
|
-
s = arguments[i];
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
6
|
-
t[p] = s[p];
|
7
|
-
}
|
8
|
-
return t;
|
9
|
-
};
|
10
|
-
return __assign.apply(this, arguments);
|
11
|
-
};
|
12
|
-
import { Guid4 } from "../utils/guid4";
|
13
|
-
var ControlEvent = /** @class */ (function () {
|
14
|
-
function ControlEvent() {
|
15
|
-
}
|
16
|
-
return ControlEvent;
|
17
|
-
}());
|
18
|
-
export { ControlEvent };
|
19
|
-
var EventAtom = /** @class */ (function () {
|
20
|
-
function EventAtom() {
|
21
|
-
}
|
22
|
-
return EventAtom;
|
23
|
-
}());
|
24
|
-
export { EventAtom };
|
25
|
-
var EventService = /** @class */ (function () {
|
26
|
-
function EventService() {
|
27
|
-
this.eventList = [];
|
28
|
-
}
|
29
|
-
EventService.prototype.subcribe = function (controlEvent) {
|
30
|
-
var eventAtom = __assign({ id: new Guid4().generate() }, controlEvent);
|
31
|
-
this.eventList.push(eventAtom);
|
32
|
-
};
|
33
|
-
EventService.prototype.dispatch = function (name, eventArgs) {
|
34
|
-
var eventAtom = this.eventList.find(function (event) { return event.name === name; });
|
35
|
-
eventAtom.action(eventArgs);
|
36
|
-
};
|
37
|
-
EventService.prototype.applyEvents = function (baseElement) {
|
38
|
-
var _a;
|
39
|
-
(_a = this.eventList) === null || _a === void 0 ? void 0 : _a.forEach(function (event) {
|
40
|
-
baseElement.addEventListener(event.name, event.action);
|
41
|
-
});
|
42
|
-
};
|
43
|
-
return EventService;
|
44
|
-
}());
|
45
|
-
export default EventService;
|