canvas-editor-engine 2.0.12 → 2.0.14
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.d.ts +21 -0
- package/dist/components/excretions.component.d.ts +32 -0
- package/dist/components/loading.component.d.ts +14 -0
- package/dist/components/pipette.component.d.ts +23 -0
- package/dist/components/slot.component.d.ts +10 -0
- package/dist/config.d.ts +23 -0
- package/dist/filters/collection/vague.d.ts +13 -0
- package/dist/filters/index.d.ts +2 -0
- package/dist/index.d.ts +18 -574
- package/dist/index.mjs +2148 -0
- package/dist/services/component.service.d.ts +5 -0
- package/dist/services/crop.service.d.ts +7 -0
- package/dist/services/download.service.d.ts +4 -0
- package/dist/services/draw.service.d.ts +17 -0
- package/dist/services/event.service.d.ts +16 -0
- package/dist/services/logger.service.d.ts +20 -0
- package/dist/services/projects.service.d.ts +11 -0
- package/dist/services/pull-project.service.d.ts +8 -0
- package/dist/services/store.service.d.ts +6 -0
- package/dist/services/through-history.service.d.ts +12 -0
- package/dist/services/tool-layers.service.d.ts +4 -0
- package/dist/services/tool.service.d.ts +10 -0
- package/dist/store/history.state.d.ts +15 -0
- package/dist/store/image.state.d.ts +30 -0
- package/dist/store/store.d.ts +13 -0
- package/dist/types/canvas.d.ts +10 -0
- package/dist/types/cursor.d.ts +9 -0
- package/dist/types/excretion.d.ts +27 -0
- package/dist/types/general.d.ts +24 -0
- package/dist/types/history.d.ts +7 -0
- package/dist/types/image.d.ts +48 -0
- package/dist/types/log.d.ts +13 -0
- package/dist/types/pipette.d.ts +1 -0
- package/dist/types/project.d.ts +38 -0
- package/dist/utils/convert.d.ts +12 -0
- package/dist/utils/filter.d.ts +21 -0
- package/dist/utils/guid4.d.ts +13 -0
- package/dist/utils/project-file-serializer.d.ts +13 -0
- package/dist/web-component.d.ts +30 -0
- package/package.json +11 -5
- package/dist/index.mjs.js +0 -2
- package/dist/index.mjs.js.LICENSE.txt +0 -8
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,2148 @@
|
|
|
1
|
+
import { range } from "lodash";
|
|
2
|
+
|
|
3
|
+
var extendStatics = function(d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf || {
|
|
5
|
+
__proto__: []
|
|
6
|
+
} instanceof Array && function(d, b) {
|
|
7
|
+
d.__proto__ = b;
|
|
8
|
+
} || function(d, b) {
|
|
9
|
+
for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
|
|
10
|
+
};
|
|
11
|
+
return extendStatics(d, b);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
function __extends(d, b) {
|
|
15
|
+
if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
16
|
+
extendStatics(d, b);
|
|
17
|
+
function __() {
|
|
18
|
+
this.constructor = d;
|
|
19
|
+
}
|
|
20
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
var __assign = function() {
|
|
24
|
+
__assign = Object.assign || function __assign(t) {
|
|
25
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
26
|
+
s = arguments[i];
|
|
27
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
28
|
+
}
|
|
29
|
+
return t;
|
|
30
|
+
};
|
|
31
|
+
return __assign.apply(this, arguments);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
function __spreadArray(to, from, pack) {
|
|
35
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
36
|
+
if (ar || !(i in from)) {
|
|
37
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
38
|
+
ar[i] = from[i];
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
|
|
45
|
+
var e = new Error(message);
|
|
46
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
var ConfigFabric = function() {
|
|
50
|
+
function ConfigFabric() {}
|
|
51
|
+
return ConfigFabric;
|
|
52
|
+
}();
|
|
53
|
+
|
|
54
|
+
var AppConfig = function(_super) {
|
|
55
|
+
__extends(AppConfig, _super);
|
|
56
|
+
function AppConfig() {
|
|
57
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
58
|
+
}
|
|
59
|
+
Object.defineProperty(AppConfig, "WEB_COMPONENT_TAG_NAME", {
|
|
60
|
+
get: function() {
|
|
61
|
+
return AppConfig._WEB_COMPONENT_TAG_NAME;
|
|
62
|
+
},
|
|
63
|
+
set: function(value) {
|
|
64
|
+
if (!!value && typeof value === "string") {
|
|
65
|
+
AppConfig._WEB_COMPONENT_TAG_NAME = value;
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
enumerable: false,
|
|
69
|
+
configurable: true
|
|
70
|
+
});
|
|
71
|
+
Object.defineProperty(AppConfig, "CANVAS_SIZE", {
|
|
72
|
+
get: function() {
|
|
73
|
+
return AppConfig._CANVAS_SIZE;
|
|
74
|
+
},
|
|
75
|
+
set: function(value) {
|
|
76
|
+
if (!!value && !!(value === null || value === void 0 ? void 0 : value.width) && !!(value === null || value === void 0 ? void 0 : value.height)) {
|
|
77
|
+
AppConfig._CANVAS_SIZE = value;
|
|
78
|
+
} else {
|
|
79
|
+
console.warn("CANVAS_SIZE denied");
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
enumerable: false,
|
|
83
|
+
configurable: true
|
|
84
|
+
});
|
|
85
|
+
Object.defineProperty(AppConfig, "LAYERS", {
|
|
86
|
+
get: function() {
|
|
87
|
+
return AppConfig._LAYERS;
|
|
88
|
+
},
|
|
89
|
+
set: function(value) {
|
|
90
|
+
if (!!value && !!(value === null || value === void 0 ? void 0 : value.length)) {
|
|
91
|
+
AppConfig._LAYERS = value;
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
enumerable: false,
|
|
95
|
+
configurable: true
|
|
96
|
+
});
|
|
97
|
+
return AppConfig;
|
|
98
|
+
}(ConfigFabric);
|
|
99
|
+
|
|
100
|
+
(function() {
|
|
101
|
+
AppConfig._CANVAS_SIZE = {
|
|
102
|
+
width: 300,
|
|
103
|
+
height: 150
|
|
104
|
+
};
|
|
105
|
+
AppConfig._WEB_COMPONENT_TAG_NAME = "canvas-editor-engine";
|
|
106
|
+
AppConfig._LAYERS = [ {
|
|
107
|
+
name: "low",
|
|
108
|
+
index: 1
|
|
109
|
+
}, {
|
|
110
|
+
name: "normal",
|
|
111
|
+
index: 2
|
|
112
|
+
}, {
|
|
113
|
+
name: "high",
|
|
114
|
+
index: 3
|
|
115
|
+
} ];
|
|
116
|
+
})();
|
|
117
|
+
|
|
118
|
+
var ComponentService = function() {
|
|
119
|
+
function ComponentService() {}
|
|
120
|
+
ComponentService.getTemplate = function(template, wrapOptions) {
|
|
121
|
+
var options = {
|
|
122
|
+
tag: "div"
|
|
123
|
+
};
|
|
124
|
+
if (!!wrapOptions) {
|
|
125
|
+
Object.keys(wrapOptions).forEach((function(key) {
|
|
126
|
+
if (!!wrapOptions[key]) {
|
|
127
|
+
options[key] = wrapOptions[key];
|
|
128
|
+
}
|
|
129
|
+
}));
|
|
130
|
+
}
|
|
131
|
+
var wrap = document.createElement(options.tag);
|
|
132
|
+
if (!!options) {
|
|
133
|
+
Object.keys(options).forEach((function(key) {
|
|
134
|
+
if (!!options[key] && key !== "tag") {
|
|
135
|
+
wrap[key] = options[key];
|
|
136
|
+
}
|
|
137
|
+
}));
|
|
138
|
+
}
|
|
139
|
+
if (!!template) {
|
|
140
|
+
wrap.innerHTML = template;
|
|
141
|
+
}
|
|
142
|
+
return wrap;
|
|
143
|
+
};
|
|
144
|
+
ComponentService.getStyle = function(css) {
|
|
145
|
+
if (!!css === false) return null;
|
|
146
|
+
var style = document.createElement("style");
|
|
147
|
+
style.type = "text/css";
|
|
148
|
+
style.appendChild(document.createTextNode(css));
|
|
149
|
+
return style;
|
|
150
|
+
};
|
|
151
|
+
return ComponentService;
|
|
152
|
+
}();
|
|
153
|
+
|
|
154
|
+
var LoggerService = function() {
|
|
155
|
+
function LoggerService() {}
|
|
156
|
+
Object.defineProperty(LoggerService, "components", {
|
|
157
|
+
get: function() {
|
|
158
|
+
return LoggerService.getMethods("components");
|
|
159
|
+
},
|
|
160
|
+
enumerable: false,
|
|
161
|
+
configurable: true
|
|
162
|
+
});
|
|
163
|
+
Object.defineProperty(LoggerService, "services", {
|
|
164
|
+
get: function() {
|
|
165
|
+
return LoggerService.getMethods("services");
|
|
166
|
+
},
|
|
167
|
+
enumerable: false,
|
|
168
|
+
configurable: true
|
|
169
|
+
});
|
|
170
|
+
Object.defineProperty(LoggerService, "planed", {
|
|
171
|
+
get: function() {
|
|
172
|
+
return LoggerService.getMethods("planed");
|
|
173
|
+
},
|
|
174
|
+
enumerable: false,
|
|
175
|
+
configurable: true
|
|
176
|
+
});
|
|
177
|
+
LoggerService.getMethods = function(fields) {
|
|
178
|
+
return {
|
|
179
|
+
add: function(logItem) {
|
|
180
|
+
LoggerService._add(fields, logItem);
|
|
181
|
+
},
|
|
182
|
+
get: function() {
|
|
183
|
+
var args = [];
|
|
184
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
185
|
+
args[_i] = arguments[_i];
|
|
186
|
+
}
|
|
187
|
+
LoggerService._get.apply(LoggerService, args);
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
};
|
|
191
|
+
LoggerService._add = function(field, logItem) {
|
|
192
|
+
LoggerService.log[field].push(logItem);
|
|
193
|
+
};
|
|
194
|
+
LoggerService._get = function(field, name) {
|
|
195
|
+
return LoggerService.log[field].find((function(logItem) {
|
|
196
|
+
return logItem.info.name === name;
|
|
197
|
+
}));
|
|
198
|
+
};
|
|
199
|
+
LoggerService.log = {
|
|
200
|
+
components: [],
|
|
201
|
+
services: [],
|
|
202
|
+
planed: []
|
|
203
|
+
};
|
|
204
|
+
return LoggerService;
|
|
205
|
+
}();
|
|
206
|
+
|
|
207
|
+
var ToolLayerService = function() {
|
|
208
|
+
function ToolLayerService() {}
|
|
209
|
+
ToolLayerService.getLayerIndex = function(layerName) {
|
|
210
|
+
var layer = AppConfig.LAYERS.find((function(layer) {
|
|
211
|
+
return layer.name === layerName;
|
|
212
|
+
}));
|
|
213
|
+
var zIndex = ToolLayerService.multiplier * layer.index;
|
|
214
|
+
return zIndex;
|
|
215
|
+
};
|
|
216
|
+
ToolLayerService.multiplier = 1e3;
|
|
217
|
+
return ToolLayerService;
|
|
218
|
+
}();
|
|
219
|
+
|
|
220
|
+
var CanvasComponent = function(_super) {
|
|
221
|
+
__extends(CanvasComponent, _super);
|
|
222
|
+
function CanvasComponent() {
|
|
223
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
224
|
+
}
|
|
225
|
+
CanvasComponent.getComponent = function() {
|
|
226
|
+
var canvasTemplate = CanvasComponent.getTemplate(CanvasComponent.template);
|
|
227
|
+
var canvasStyle = CanvasComponent.getStyle(CanvasComponent.css);
|
|
228
|
+
CanvasComponent.canvas = canvasTemplate.getElementsByTagName("canvas")[0];
|
|
229
|
+
CanvasComponent.canvas.width = AppConfig.CANVAS_SIZE.width;
|
|
230
|
+
CanvasComponent.canvas.height = AppConfig.CANVAS_SIZE.height;
|
|
231
|
+
CanvasComponent.ctx = CanvasComponent.canvas.getContext("2d", {
|
|
232
|
+
willReadFrequently: true
|
|
233
|
+
});
|
|
234
|
+
CanvasComponent.eventListener = canvasTemplate.querySelector("#event-listener");
|
|
235
|
+
CanvasComponent.eventListener.style.width = AppConfig.CANVAS_SIZE.width + "px";
|
|
236
|
+
CanvasComponent.eventListener.style.height = AppConfig.CANVAS_SIZE.height + "px";
|
|
237
|
+
return {
|
|
238
|
+
canvasTemplate,
|
|
239
|
+
canvasStyle
|
|
240
|
+
};
|
|
241
|
+
};
|
|
242
|
+
CanvasComponent.getCanvasSelector = function() {
|
|
243
|
+
return "#sc-canvas";
|
|
244
|
+
};
|
|
245
|
+
Object.defineProperty(CanvasComponent, "cursorStyle", {
|
|
246
|
+
set: function(styleName) {
|
|
247
|
+
if (!!styleName) {
|
|
248
|
+
CanvasComponent._cursorStyle.before = CanvasComponent._cursorStyle.current;
|
|
249
|
+
CanvasComponent._cursorStyle.current = styleName;
|
|
250
|
+
CanvasComponent.eventListener.style.cursor = styleName;
|
|
251
|
+
} else {
|
|
252
|
+
CanvasComponent.eventListener.style.cursor = "default";
|
|
253
|
+
}
|
|
254
|
+
},
|
|
255
|
+
enumerable: false,
|
|
256
|
+
configurable: true
|
|
257
|
+
});
|
|
258
|
+
CanvasComponent.getCursorPosition = function(event) {
|
|
259
|
+
var rect = CanvasComponent.canvas.getBoundingClientRect();
|
|
260
|
+
var x = event.clientX - rect.left;
|
|
261
|
+
var y = event.clientY - rect.top;
|
|
262
|
+
return {
|
|
263
|
+
x,
|
|
264
|
+
y
|
|
265
|
+
};
|
|
266
|
+
};
|
|
267
|
+
CanvasComponent.subscribe = function(eventName, action) {
|
|
268
|
+
CanvasComponent.subscriptions[eventName].push(action);
|
|
269
|
+
};
|
|
270
|
+
CanvasComponent.simulateSubscriptions = function() {
|
|
271
|
+
var eventNames = Object.keys(CanvasComponent.subscriptions);
|
|
272
|
+
eventNames.forEach((function(eventName) {
|
|
273
|
+
var actionsList = CanvasComponent.subscriptions[eventName];
|
|
274
|
+
if (!!actionsList.length) {
|
|
275
|
+
CanvasComponent.eventListener.addEventListener(eventName, (function(event) {
|
|
276
|
+
var cursorPosition = CanvasComponent.getCursorPosition(event);
|
|
277
|
+
actionsList.forEach((function(action) {
|
|
278
|
+
action(event, cursorPosition);
|
|
279
|
+
}));
|
|
280
|
+
}));
|
|
281
|
+
}
|
|
282
|
+
}));
|
|
283
|
+
};
|
|
284
|
+
CanvasComponent.template = '\n <div id="event-listener"></div>\n <canvas id="sc-canvas"></canvas>\n ';
|
|
285
|
+
CanvasComponent.css = "\n #event-listener {\n position: absolute;\n z-index: ".concat(ToolLayerService.getLayerIndex("normal"), ";\n }\n ");
|
|
286
|
+
CanvasComponent.subscriptions = {
|
|
287
|
+
click: [],
|
|
288
|
+
mousemove: [],
|
|
289
|
+
mousedown: [],
|
|
290
|
+
mouseup: []
|
|
291
|
+
};
|
|
292
|
+
CanvasComponent._cursorStyle = {
|
|
293
|
+
before: null,
|
|
294
|
+
current: "default"
|
|
295
|
+
};
|
|
296
|
+
(function() {
|
|
297
|
+
LoggerService.components.add({
|
|
298
|
+
info: {
|
|
299
|
+
name: "canvas",
|
|
300
|
+
description: "canvas component"
|
|
301
|
+
},
|
|
302
|
+
prototype: CanvasComponent
|
|
303
|
+
});
|
|
304
|
+
})();
|
|
305
|
+
return CanvasComponent;
|
|
306
|
+
}(ComponentService);
|
|
307
|
+
|
|
308
|
+
var ToolService = function() {
|
|
309
|
+
function ToolService() {}
|
|
310
|
+
ToolService.add = function(tool) {
|
|
311
|
+
var hasRegisteredTool = ToolService.registry.find((function(registeredTool) {
|
|
312
|
+
return registeredTool.id === tool.id;
|
|
313
|
+
}));
|
|
314
|
+
if (hasRegisteredTool) {
|
|
315
|
+
console.warn("Tool has been previously registered!");
|
|
316
|
+
return false;
|
|
317
|
+
}
|
|
318
|
+
ToolService.registry.push(tool);
|
|
319
|
+
return true;
|
|
320
|
+
};
|
|
321
|
+
ToolService.setActive = function(id) {
|
|
322
|
+
var _a, _b, _c;
|
|
323
|
+
if (((_a = ToolService.active) === null || _a === void 0 ? void 0 : _a.id) === id) return console.warn("Tool is already active");
|
|
324
|
+
if (!!((_b = ToolService.active) === null || _b === void 0 ? void 0 : _b.offAction)) {
|
|
325
|
+
ToolService.active.offAction();
|
|
326
|
+
}
|
|
327
|
+
var registeredTool = ToolService.registry.find((function(registeredTool) {
|
|
328
|
+
return registeredTool.id === id;
|
|
329
|
+
}));
|
|
330
|
+
if (!!registeredTool) {
|
|
331
|
+
ToolService.active = registeredTool;
|
|
332
|
+
if (!!((_c = ToolService.active) === null || _c === void 0 ? void 0 : _c.onAction)) {
|
|
333
|
+
ToolService.active.onAction();
|
|
334
|
+
}
|
|
335
|
+
} else {
|
|
336
|
+
console.warn("Tool has not previously been registered with this identifier");
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
ToolService.offActive = function(id) {
|
|
340
|
+
if (!!id) {
|
|
341
|
+
if (ToolService.active.id === id) {
|
|
342
|
+
ToolService.off();
|
|
343
|
+
} else {
|
|
344
|
+
return console.warn('ID active tool is not "'.concat(id, '"'));
|
|
345
|
+
}
|
|
346
|
+
} else {
|
|
347
|
+
ToolService.off();
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
ToolService.off = function() {
|
|
351
|
+
var _a;
|
|
352
|
+
if (!!((_a = ToolService.active) === null || _a === void 0 ? void 0 : _a.offAction)) {
|
|
353
|
+
ToolService.active.offAction();
|
|
354
|
+
}
|
|
355
|
+
ToolService.before = ToolService.active;
|
|
356
|
+
ToolService.active = null;
|
|
357
|
+
CanvasComponent.cursorStyle = "default";
|
|
358
|
+
};
|
|
359
|
+
ToolService.before = null;
|
|
360
|
+
ToolService.active = null;
|
|
361
|
+
ToolService.registry = [];
|
|
362
|
+
return ToolService;
|
|
363
|
+
}();
|
|
364
|
+
|
|
365
|
+
var Convert = function() {
|
|
366
|
+
function Convert() {}
|
|
367
|
+
Convert.byteRGBToHEX = function(color) {
|
|
368
|
+
var red = color[0];
|
|
369
|
+
var green = color[1];
|
|
370
|
+
var blue = color[2];
|
|
371
|
+
return Convert.rgbToHex(red, green, blue);
|
|
372
|
+
};
|
|
373
|
+
Convert.rgbToHex = function(r, g, b) {
|
|
374
|
+
return "#".concat(Convert.componentToHEX(r)).concat(Convert.componentToHEX(g)).concat(Convert.componentToHEX(b));
|
|
375
|
+
};
|
|
376
|
+
Convert.hexToRgb = function(hex) {
|
|
377
|
+
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
|
378
|
+
return result ? {
|
|
379
|
+
r: parseInt(result[1], 16),
|
|
380
|
+
g: parseInt(result[2], 16),
|
|
381
|
+
b: parseInt(result[3], 16)
|
|
382
|
+
} : null;
|
|
383
|
+
};
|
|
384
|
+
Convert.componentToHEX = function(colorComponent) {
|
|
385
|
+
var hex = colorComponent.toString(16);
|
|
386
|
+
return hex.length == 1 ? "0" + hex : hex;
|
|
387
|
+
};
|
|
388
|
+
return Convert;
|
|
389
|
+
}();
|
|
390
|
+
|
|
391
|
+
var Filter = function() {
|
|
392
|
+
function Filter(ctx) {
|
|
393
|
+
this.ctx = ctx;
|
|
394
|
+
}
|
|
395
|
+
Filter.prototype.setImageSize = function(size) {
|
|
396
|
+
this.imageSize = size;
|
|
397
|
+
};
|
|
398
|
+
Filter.prototype.copy = function(options) {
|
|
399
|
+
var width = (options === null || options === void 0 ? void 0 : options.width) ? options.width : AppConfig.CANVAS_SIZE.width;
|
|
400
|
+
var height = (options === null || options === void 0 ? void 0 : options.height) ? options.height : AppConfig.CANVAS_SIZE.height;
|
|
401
|
+
var imgData = this.ctx.getImageData(options.x, options.y, width, height);
|
|
402
|
+
return imgData;
|
|
403
|
+
};
|
|
404
|
+
Filter.prototype.copyExtendedModel = function(options) {
|
|
405
|
+
var width = (options === null || options === void 0 ? void 0 : options.width) ? options.width : AppConfig.CANVAS_SIZE.width;
|
|
406
|
+
var height = (options === null || options === void 0 ? void 0 : options.height) ? options.height : AppConfig.CANVAS_SIZE.height;
|
|
407
|
+
var imgData = this.ctx.getImageData(options.x, options.y, width, height);
|
|
408
|
+
var extendedImageData = this.clearEmptyPixels(imgData);
|
|
409
|
+
return extendedImageData;
|
|
410
|
+
};
|
|
411
|
+
Filter.prototype.update = function(imgData, options) {
|
|
412
|
+
this.ctx.clearRect(0, 0, AppConfig.CANVAS_SIZE.width, AppConfig.CANVAS_SIZE.height);
|
|
413
|
+
this.ctx.putImageData(imgData, options.x, options.y);
|
|
414
|
+
};
|
|
415
|
+
Filter.prototype.clearEmptyPixels = function(imageData) {
|
|
416
|
+
var rowRGBABuff = this.getRowRGBABuff(imageData);
|
|
417
|
+
var RGBAMatrix = this.getRGBAMatrix(rowRGBABuff, {
|
|
418
|
+
width: imageData.width,
|
|
419
|
+
height: imageData.height
|
|
420
|
+
});
|
|
421
|
+
var beforeSize = {
|
|
422
|
+
width: imageData.width,
|
|
423
|
+
height: imageData.height
|
|
424
|
+
};
|
|
425
|
+
var tempSize = this.getSizeOfSparseMatrix(RGBAMatrix, beforeSize);
|
|
426
|
+
var cleared = rowRGBABuff.filter((function(byteArray) {
|
|
427
|
+
var alpha = byteArray[3];
|
|
428
|
+
return !!alpha;
|
|
429
|
+
}));
|
|
430
|
+
var clearedBuff = cleared.flat();
|
|
431
|
+
var tempCanvas = document.createElement("canvas");
|
|
432
|
+
var tempCtx = tempCanvas.getContext("2d");
|
|
433
|
+
var tempImageData = tempCtx.createImageData(tempSize.width, tempSize.height);
|
|
434
|
+
clearedBuff.forEach((function(_, i) {
|
|
435
|
+
return tempImageData.data[i] = clearedBuff[i];
|
|
436
|
+
}));
|
|
437
|
+
console.log("cleared", cleared);
|
|
438
|
+
return {
|
|
439
|
+
imageData: tempImageData,
|
|
440
|
+
size: tempSize
|
|
441
|
+
};
|
|
442
|
+
};
|
|
443
|
+
Filter.prototype.getSizeOfSparseMatrix = function(RGBAMatrix, tempSize) {
|
|
444
|
+
var leftIndex;
|
|
445
|
+
var upIndex;
|
|
446
|
+
for (var _i = 0, _a = RGBAMatrix.entries(); _i < _a.length; _i++) {
|
|
447
|
+
var _b = _a[_i], iy = _b[0], row = _b[1];
|
|
448
|
+
for (var _c = 0, _d = row.entries(); _c < _d.length; _c++) {
|
|
449
|
+
var _e = _d[_c], ix = _e[0], rowItem = _e[1];
|
|
450
|
+
var isNotEmpty = rowItem[3] !== 0;
|
|
451
|
+
if (isNotEmpty) {
|
|
452
|
+
leftIndex = ix;
|
|
453
|
+
upIndex = iy;
|
|
454
|
+
break;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
if (leftIndex !== undefined && upIndex !== undefined) {
|
|
458
|
+
break;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
var rightIndex;
|
|
462
|
+
var downIndex;
|
|
463
|
+
for (var _f = 0, _g = RGBAMatrix.reverse().entries(); _f < _g.length; _f++) {
|
|
464
|
+
var _h = _g[_f], iy = _h[0], row = _h[1];
|
|
465
|
+
for (var _j = 0, _k = row.reverse().entries(); _j < _k.length; _j++) {
|
|
466
|
+
var _l = _k[_j], ix = _l[0], rowItem = _l[1];
|
|
467
|
+
var isNotEmpty = rowItem[3] !== 0;
|
|
468
|
+
if (isNotEmpty) {
|
|
469
|
+
rightIndex = ix;
|
|
470
|
+
downIndex = iy;
|
|
471
|
+
break;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
if (rightIndex !== undefined && downIndex !== undefined) {
|
|
475
|
+
break;
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
var reduceWidth = function(tempWidth) {
|
|
479
|
+
return tempWidth - (leftIndex + rightIndex);
|
|
480
|
+
};
|
|
481
|
+
var reduceHeight = function(tempHeight) {
|
|
482
|
+
return tempHeight - (upIndex + downIndex);
|
|
483
|
+
};
|
|
484
|
+
var resultSize = {
|
|
485
|
+
width: reduceWidth(tempSize.width),
|
|
486
|
+
height: reduceHeight(tempSize.height)
|
|
487
|
+
};
|
|
488
|
+
return resultSize;
|
|
489
|
+
};
|
|
490
|
+
Filter.prototype.getBuffCollection = function(imageData) {
|
|
491
|
+
var rowRGBABuff = this.getRowRGBABuff(imageData);
|
|
492
|
+
var hexBuff = rowRGBABuff.map(Convert.byteRGBToHEX);
|
|
493
|
+
var buff = this.getBuff(hexBuff);
|
|
494
|
+
return {
|
|
495
|
+
rowRGBABuff,
|
|
496
|
+
hexBuff,
|
|
497
|
+
buff
|
|
498
|
+
};
|
|
499
|
+
};
|
|
500
|
+
Filter.prototype.getBuff = function(hexBuff) {
|
|
501
|
+
var _this = this;
|
|
502
|
+
var distanceRow = range(0, this.imageSize.height).map((function(i) {
|
|
503
|
+
return _this.imageSize.width * i;
|
|
504
|
+
}));
|
|
505
|
+
var buff = [];
|
|
506
|
+
var indexOfDistance = 0;
|
|
507
|
+
hexBuff.forEach((function(pxColor, pxIndex) {
|
|
508
|
+
var _a;
|
|
509
|
+
if (pxIndex >= distanceRow[indexOfDistance + 1]) {
|
|
510
|
+
indexOfDistance++;
|
|
511
|
+
}
|
|
512
|
+
(_a = buff[indexOfDistance]) !== null && _a !== void 0 ? _a : buff[indexOfDistance] = [];
|
|
513
|
+
buff[indexOfDistance].push(pxColor);
|
|
514
|
+
}));
|
|
515
|
+
return buff;
|
|
516
|
+
};
|
|
517
|
+
Filter.prototype.getRGBAMatrix = function(rowRGBABuff, size) {
|
|
518
|
+
var maybeSize = {
|
|
519
|
+
width: size.width || this.imageSize.width,
|
|
520
|
+
height: size.height || this.imageSize.height
|
|
521
|
+
};
|
|
522
|
+
var distanceRow = range(0, maybeSize.height).map((function(i) {
|
|
523
|
+
return maybeSize.width * i;
|
|
524
|
+
}));
|
|
525
|
+
var buff = [];
|
|
526
|
+
var indexOfDistance = 0;
|
|
527
|
+
rowRGBABuff.forEach((function(pxRGBA, pxIndex) {
|
|
528
|
+
var _a;
|
|
529
|
+
if (pxIndex >= distanceRow[indexOfDistance + 1]) {
|
|
530
|
+
indexOfDistance++;
|
|
531
|
+
}
|
|
532
|
+
(_a = buff[indexOfDistance]) !== null && _a !== void 0 ? _a : buff[indexOfDistance] = [];
|
|
533
|
+
buff[indexOfDistance].push(pxRGBA);
|
|
534
|
+
}));
|
|
535
|
+
return buff;
|
|
536
|
+
};
|
|
537
|
+
Filter.prototype.getRowRGBABuff = function(imageData) {
|
|
538
|
+
var rowRGBABuff = [];
|
|
539
|
+
var colorIndx = 0;
|
|
540
|
+
var colorRGBAIndx = 0;
|
|
541
|
+
imageData.data.forEach((function(pxColor) {
|
|
542
|
+
var _a;
|
|
543
|
+
if (colorIndx >= 4) {
|
|
544
|
+
colorIndx = 0;
|
|
545
|
+
colorRGBAIndx++;
|
|
546
|
+
}
|
|
547
|
+
colorIndx++;
|
|
548
|
+
(_a = rowRGBABuff[colorRGBAIndx]) !== null && _a !== void 0 ? _a : rowRGBABuff[colorRGBAIndx] = [];
|
|
549
|
+
rowRGBABuff[colorRGBAIndx].push(pxColor);
|
|
550
|
+
}));
|
|
551
|
+
return rowRGBABuff;
|
|
552
|
+
};
|
|
553
|
+
return Filter;
|
|
554
|
+
}();
|
|
555
|
+
|
|
556
|
+
var ThroughHistoryService = function() {
|
|
557
|
+
function ThroughHistoryService() {}
|
|
558
|
+
ThroughHistoryService.current = function() {
|
|
559
|
+
var history = AppStore.store.historyState.historyLines;
|
|
560
|
+
var lastIndex = history.length - 1;
|
|
561
|
+
return history[lastIndex];
|
|
562
|
+
};
|
|
563
|
+
ThroughHistoryService.prev = function() {
|
|
564
|
+
var history = AppStore.store.historyState.historyLines;
|
|
565
|
+
var prevIndex = history.length - 2;
|
|
566
|
+
return history[prevIndex];
|
|
567
|
+
};
|
|
568
|
+
ThroughHistoryService.undo = function(ctx) {
|
|
569
|
+
var current = ThroughHistoryService.current();
|
|
570
|
+
var prev = ThroughHistoryService.prev();
|
|
571
|
+
if (!!(current === null || current === void 0 ? void 0 : current.stateValue)) {
|
|
572
|
+
ThroughHistoryService.cache.unshift(current);
|
|
573
|
+
AppStore.store.historyState.reduce("UNDO");
|
|
574
|
+
if (prev === null || prev === void 0 ? void 0 : prev.stateValue) {
|
|
575
|
+
ThroughHistoryService.updateCanvas(ctx, prev.stateValue);
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
};
|
|
579
|
+
ThroughHistoryService.redo = function(ctx) {
|
|
580
|
+
var firstInCache = ThroughHistoryService.cache.shift();
|
|
581
|
+
if (!!(firstInCache === null || firstInCache === void 0 ? void 0 : firstInCache.stateValue)) {
|
|
582
|
+
AppStore.store.historyState.reduce("REDO", firstInCache);
|
|
583
|
+
ThroughHistoryService.updateCanvas(ctx, firstInCache.stateValue);
|
|
584
|
+
}
|
|
585
|
+
};
|
|
586
|
+
ThroughHistoryService.clearCache = function() {
|
|
587
|
+
ThroughHistoryService.cache = [];
|
|
588
|
+
};
|
|
589
|
+
ThroughHistoryService.recovery = function(project) {
|
|
590
|
+
AppStore.store.historyState.reduce("SET_HISTORY", {
|
|
591
|
+
historyLines: project.state.history
|
|
592
|
+
});
|
|
593
|
+
ThroughHistoryService.cache = project.state.cache;
|
|
594
|
+
};
|
|
595
|
+
ThroughHistoryService.updateCanvas = function(ctx, stateValue) {
|
|
596
|
+
var filter = new Filter(ctx);
|
|
597
|
+
filter.update(stateValue.tempImageData, stateValue.position);
|
|
598
|
+
};
|
|
599
|
+
ThroughHistoryService.cache = [];
|
|
600
|
+
return ThroughHistoryService;
|
|
601
|
+
}();
|
|
602
|
+
|
|
603
|
+
var HistoryState = function() {
|
|
604
|
+
function HistoryState() {
|
|
605
|
+
this.default = {
|
|
606
|
+
historyLines: []
|
|
607
|
+
};
|
|
608
|
+
this._historyLines = this.default.historyLines;
|
|
609
|
+
this.reset();
|
|
610
|
+
}
|
|
611
|
+
Object.defineProperty(HistoryState.prototype, "historyLines", {
|
|
612
|
+
get: function() {
|
|
613
|
+
return this._historyLines;
|
|
614
|
+
},
|
|
615
|
+
enumerable: false,
|
|
616
|
+
configurable: true
|
|
617
|
+
});
|
|
618
|
+
HistoryState.prototype.reduce = function(name, payload) {
|
|
619
|
+
var reducer = new Reducer(this);
|
|
620
|
+
switch (name) {
|
|
621
|
+
case "SET_HISTORY":
|
|
622
|
+
reducer.setHistoryLines(payload);
|
|
623
|
+
ThroughHistoryService.clearCache();
|
|
624
|
+
break;
|
|
625
|
+
|
|
626
|
+
case "UPDATE_HISTORY":
|
|
627
|
+
reducer.updateHistoryLines(payload);
|
|
628
|
+
ThroughHistoryService.clearCache();
|
|
629
|
+
break;
|
|
630
|
+
|
|
631
|
+
case "REDO":
|
|
632
|
+
reducer.updateHistoryLines(payload);
|
|
633
|
+
break;
|
|
634
|
+
|
|
635
|
+
case "UNDO":
|
|
636
|
+
reducer.popHistoryLines();
|
|
637
|
+
break;
|
|
638
|
+
}
|
|
639
|
+
};
|
|
640
|
+
HistoryState.prototype.emerge = function(completeIt) {
|
|
641
|
+
this._emergeCompleteIt = completeIt;
|
|
642
|
+
};
|
|
643
|
+
HistoryState.prototype.reset = function() {
|
|
644
|
+
this.reduce("SET_HISTORY", this.default);
|
|
645
|
+
};
|
|
646
|
+
return HistoryState;
|
|
647
|
+
}();
|
|
648
|
+
|
|
649
|
+
var Reducer = function() {
|
|
650
|
+
function Reducer(state) {
|
|
651
|
+
this.state = state;
|
|
652
|
+
}
|
|
653
|
+
Reducer.prototype.setHistoryLines = function(payload) {
|
|
654
|
+
var isUpdate = false;
|
|
655
|
+
if (!!(payload === null || payload === void 0 ? void 0 : payload.historyLines)) {
|
|
656
|
+
this.state._historyLines = payload.historyLines;
|
|
657
|
+
isUpdate = true;
|
|
658
|
+
}
|
|
659
|
+
if (isUpdate && !!this.state._emergeCompleteIt) {
|
|
660
|
+
this.state._emergeCompleteIt(this.state._historyLines);
|
|
661
|
+
}
|
|
662
|
+
};
|
|
663
|
+
Reducer.prototype.updateHistoryLines = function(payload) {
|
|
664
|
+
var isUpdate = false;
|
|
665
|
+
if (!!(payload === null || payload === void 0 ? void 0 : payload.view)) {
|
|
666
|
+
this.state._historyLines.push(payload);
|
|
667
|
+
isUpdate = true;
|
|
668
|
+
}
|
|
669
|
+
if (isUpdate && !!this.state._emergeCompleteIt) {
|
|
670
|
+
this.state._emergeCompleteIt(this.state._historyLines);
|
|
671
|
+
}
|
|
672
|
+
};
|
|
673
|
+
Reducer.prototype.popHistoryLines = function() {
|
|
674
|
+
this.state._historyLines.pop();
|
|
675
|
+
if (!!this.state._emergeCompleteIt) {
|
|
676
|
+
this.state._emergeCompleteIt(this.state._historyLines);
|
|
677
|
+
}
|
|
678
|
+
};
|
|
679
|
+
return Reducer;
|
|
680
|
+
}();
|
|
681
|
+
|
|
682
|
+
var ImageState = function() {
|
|
683
|
+
function ImageState() {
|
|
684
|
+
this.default = {
|
|
685
|
+
position: {
|
|
686
|
+
x: 0,
|
|
687
|
+
y: 0
|
|
688
|
+
},
|
|
689
|
+
size: {
|
|
690
|
+
width: 0,
|
|
691
|
+
height: 0
|
|
692
|
+
},
|
|
693
|
+
tempImageData: null
|
|
694
|
+
};
|
|
695
|
+
this._position = this.default.position;
|
|
696
|
+
this._size = this.default.size;
|
|
697
|
+
this._tempImageData = this.default.tempImageData;
|
|
698
|
+
this.reset();
|
|
699
|
+
}
|
|
700
|
+
Object.defineProperty(ImageState.prototype, "position", {
|
|
701
|
+
get: function() {
|
|
702
|
+
return this._position;
|
|
703
|
+
},
|
|
704
|
+
enumerable: false,
|
|
705
|
+
configurable: true
|
|
706
|
+
});
|
|
707
|
+
Object.defineProperty(ImageState.prototype, "size", {
|
|
708
|
+
get: function() {
|
|
709
|
+
return this._size;
|
|
710
|
+
},
|
|
711
|
+
enumerable: false,
|
|
712
|
+
configurable: true
|
|
713
|
+
});
|
|
714
|
+
Object.defineProperty(ImageState.prototype, "tempImageData", {
|
|
715
|
+
get: function() {
|
|
716
|
+
return this._tempImageData;
|
|
717
|
+
},
|
|
718
|
+
enumerable: false,
|
|
719
|
+
configurable: true
|
|
720
|
+
});
|
|
721
|
+
ImageState.prototype.reduce = function(payload, title) {
|
|
722
|
+
var isUpdate = false;
|
|
723
|
+
if (!!(payload === null || payload === void 0 ? void 0 : payload.position)) {
|
|
724
|
+
this._position = payload.position;
|
|
725
|
+
}
|
|
726
|
+
if (!!(payload === null || payload === void 0 ? void 0 : payload.size)) {
|
|
727
|
+
this._size = payload.size;
|
|
728
|
+
}
|
|
729
|
+
if (!!(payload === null || payload === void 0 ? void 0 : payload.tempImageData)) {
|
|
730
|
+
this._tempImageData = payload.tempImageData;
|
|
731
|
+
isUpdate = true;
|
|
732
|
+
}
|
|
733
|
+
if (isUpdate) {
|
|
734
|
+
this.addToHistory("".concat(title || "reduce image"));
|
|
735
|
+
}
|
|
736
|
+
};
|
|
737
|
+
ImageState.prototype.reset = function() {
|
|
738
|
+
this.reduce(this.default, "reset to default");
|
|
739
|
+
};
|
|
740
|
+
ImageState.prototype.getEntry = function() {
|
|
741
|
+
return {
|
|
742
|
+
position: this._position,
|
|
743
|
+
size: this._size,
|
|
744
|
+
imageData: this._tempImageData
|
|
745
|
+
};
|
|
746
|
+
};
|
|
747
|
+
ImageState.prototype.addToHistory = function(title) {
|
|
748
|
+
var stateValue = {
|
|
749
|
+
position: this._position,
|
|
750
|
+
size: this._size,
|
|
751
|
+
tempImageData: this._tempImageData
|
|
752
|
+
};
|
|
753
|
+
AppStore.store.historyState.reduce("UPDATE_HISTORY", {
|
|
754
|
+
view: title,
|
|
755
|
+
stateName: "image",
|
|
756
|
+
stateValue
|
|
757
|
+
});
|
|
758
|
+
};
|
|
759
|
+
return ImageState;
|
|
760
|
+
}();
|
|
761
|
+
|
|
762
|
+
var Store = function() {
|
|
763
|
+
function Store(imageState, historyState) {
|
|
764
|
+
this.imageState = imageState;
|
|
765
|
+
this.historyState = historyState;
|
|
766
|
+
}
|
|
767
|
+
Store.prototype.reset = function() {
|
|
768
|
+
this.imageState.reset();
|
|
769
|
+
this.historyState.reset();
|
|
770
|
+
};
|
|
771
|
+
return Store;
|
|
772
|
+
}();
|
|
773
|
+
|
|
774
|
+
var AppStore = function() {
|
|
775
|
+
function AppStore() {}
|
|
776
|
+
AppStore.subscribe = function(to, completeIt) {
|
|
777
|
+
if (to === "history") {
|
|
778
|
+
AppStore.store.historyState.emerge(completeIt);
|
|
779
|
+
}
|
|
780
|
+
};
|
|
781
|
+
return AppStore;
|
|
782
|
+
}();
|
|
783
|
+
|
|
784
|
+
(function() {
|
|
785
|
+
AppStore.store = new Store(new ImageState, new HistoryState);
|
|
786
|
+
})();
|
|
787
|
+
|
|
788
|
+
var CropService = function() {
|
|
789
|
+
function CropService() {}
|
|
790
|
+
CropService.setup = function() {
|
|
791
|
+
ExcretionsComponent.additionStyle = "crop";
|
|
792
|
+
};
|
|
793
|
+
CropService.crop = function(ctx) {
|
|
794
|
+
var _a;
|
|
795
|
+
if (!!((_a = ExcretionsComponent.excretionsCoords) === null || _a === void 0 ? void 0 : _a.length) === false) return;
|
|
796
|
+
var filter = new Filter(ctx);
|
|
797
|
+
var options = CropService.options;
|
|
798
|
+
var _b = filter.copyExtendedModel(options), imageData = _b.imageData, size = _b.size;
|
|
799
|
+
var position = {
|
|
800
|
+
x: AppConfig.CANVAS_SIZE.width / 2 - size.width / 2,
|
|
801
|
+
y: AppConfig.CANVAS_SIZE.height / 2 - size.height / 2
|
|
802
|
+
};
|
|
803
|
+
filter.update(imageData, position);
|
|
804
|
+
AppStore.store.imageState.reduce({
|
|
805
|
+
tempImageData: imageData,
|
|
806
|
+
position,
|
|
807
|
+
size: {
|
|
808
|
+
width: size.width,
|
|
809
|
+
height: size.height
|
|
810
|
+
}
|
|
811
|
+
}, "Use crop");
|
|
812
|
+
};
|
|
813
|
+
CropService.viewCropButton = function() {
|
|
814
|
+
var cropButtons = ExcretionsComponent.excretionWrap.querySelectorAll(".crop-button");
|
|
815
|
+
var lastCropButtonIndex = cropButtons.length - 1;
|
|
816
|
+
var cropButton = cropButtons[lastCropButtonIndex];
|
|
817
|
+
cropButton.classList.add("crop-button--view");
|
|
818
|
+
};
|
|
819
|
+
Object.defineProperty(CropService, "options", {
|
|
820
|
+
get: function() {
|
|
821
|
+
var excretionLastIndex = ExcretionsComponent.excretionsCoords.length - 1;
|
|
822
|
+
var coords = ExcretionsComponent.excretionsCoords[excretionLastIndex];
|
|
823
|
+
var excWidth = Math.abs(coords.start.x - coords.end.x);
|
|
824
|
+
var excHeight = Math.abs(coords.start.y - coords.end.y);
|
|
825
|
+
return {
|
|
826
|
+
x: coords.start.x,
|
|
827
|
+
y: coords.start.y,
|
|
828
|
+
width: excWidth,
|
|
829
|
+
height: excHeight
|
|
830
|
+
};
|
|
831
|
+
},
|
|
832
|
+
enumerable: false,
|
|
833
|
+
configurable: true
|
|
834
|
+
});
|
|
835
|
+
return CropService;
|
|
836
|
+
}();
|
|
837
|
+
|
|
838
|
+
var ExcretionsComponent = function(_super) {
|
|
839
|
+
__extends(ExcretionsComponent, _super);
|
|
840
|
+
function ExcretionsComponent() {
|
|
841
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
842
|
+
}
|
|
843
|
+
Object.defineProperty(ExcretionsComponent, "additionStyle", {
|
|
844
|
+
get: function() {
|
|
845
|
+
return ExcretionsComponent._additionStyle;
|
|
846
|
+
},
|
|
847
|
+
set: function(value) {
|
|
848
|
+
ExcretionsComponent._additionStyle = value;
|
|
849
|
+
ExcretionsComponent.applyExcretionStyle();
|
|
850
|
+
},
|
|
851
|
+
enumerable: false,
|
|
852
|
+
configurable: true
|
|
853
|
+
});
|
|
854
|
+
ExcretionsComponent.applyExcretionStyle = function() {
|
|
855
|
+
switch (ExcretionsComponent._additionStyle) {
|
|
856
|
+
case "crop":
|
|
857
|
+
ExcretionsComponent.determineCropStyle();
|
|
858
|
+
break;
|
|
859
|
+
|
|
860
|
+
case "default":
|
|
861
|
+
ExcretionsComponent.determineDefaultStyle();
|
|
862
|
+
break;
|
|
863
|
+
|
|
864
|
+
default:
|
|
865
|
+
ExcretionsComponent.determineDefaultStyle();
|
|
866
|
+
break;
|
|
867
|
+
}
|
|
868
|
+
};
|
|
869
|
+
ExcretionsComponent.determineCropStyle = function() {
|
|
870
|
+
ExcretionsComponent._excretions.forEach((function(excretion) {
|
|
871
|
+
if (!!excretion === false) return;
|
|
872
|
+
if (!excretion.classList.contains("excretion_crop")) {
|
|
873
|
+
excretion.classList.add("excretion_crop");
|
|
874
|
+
CropService.viewCropButton();
|
|
875
|
+
}
|
|
876
|
+
}));
|
|
877
|
+
};
|
|
878
|
+
ExcretionsComponent.determineDefaultStyle = function() {
|
|
879
|
+
ExcretionsComponent._excretions.forEach((function(excretion) {
|
|
880
|
+
if (!!excretion === false) return;
|
|
881
|
+
excretion.classList = ExcretionsComponent._excretionDefaultStyle;
|
|
882
|
+
}));
|
|
883
|
+
};
|
|
884
|
+
ExcretionsComponent.getComponent = function() {
|
|
885
|
+
var wrapOptions = {
|
|
886
|
+
className: "excretions-wrap"
|
|
887
|
+
};
|
|
888
|
+
var excretionsTemplate = ExcretionsComponent.getTemplate(ExcretionsComponent.template, wrapOptions);
|
|
889
|
+
var excretionsStyle = ExcretionsComponent.getStyle(ExcretionsComponent.css);
|
|
890
|
+
ExcretionsComponent.excretionWrap = excretionsTemplate;
|
|
891
|
+
ExcretionsComponent.emmit();
|
|
892
|
+
return {
|
|
893
|
+
excretionsTemplate,
|
|
894
|
+
excretionsStyle
|
|
895
|
+
};
|
|
896
|
+
};
|
|
897
|
+
Object.defineProperty(ExcretionsComponent, "excretionState", {
|
|
898
|
+
set: function(state) {
|
|
899
|
+
ExcretionsComponent._excretionState = state;
|
|
900
|
+
ExcretionsComponent.applyExcretionStyle();
|
|
901
|
+
switch (state) {
|
|
902
|
+
case "abandoned":
|
|
903
|
+
CanvasComponent.cursorStyle = "default";
|
|
904
|
+
break;
|
|
905
|
+
|
|
906
|
+
case "create":
|
|
907
|
+
CanvasComponent.cursorStyle = "crosshair";
|
|
908
|
+
break;
|
|
909
|
+
|
|
910
|
+
case "add":
|
|
911
|
+
CanvasComponent.cursorStyle = "copy";
|
|
912
|
+
break;
|
|
913
|
+
|
|
914
|
+
case "remove":
|
|
915
|
+
CanvasComponent.cursorStyle = "alias";
|
|
916
|
+
break;
|
|
917
|
+
|
|
918
|
+
default:
|
|
919
|
+
CanvasComponent.cursorStyle = "default";
|
|
920
|
+
break;
|
|
921
|
+
}
|
|
922
|
+
},
|
|
923
|
+
enumerable: false,
|
|
924
|
+
configurable: true
|
|
925
|
+
});
|
|
926
|
+
ExcretionsComponent.setToolState = function(toolState) {
|
|
927
|
+
ExcretionsComponent._excretionToolState = toolState;
|
|
928
|
+
switch (toolState) {
|
|
929
|
+
case "abandoned":
|
|
930
|
+
ExcretionsComponent.excretionState = "abandoned";
|
|
931
|
+
ExcretionsComponent._excretionActivity = "abandoned";
|
|
932
|
+
break;
|
|
933
|
+
|
|
934
|
+
case "taken":
|
|
935
|
+
ExcretionsComponent.excretionState = "create";
|
|
936
|
+
break;
|
|
937
|
+
|
|
938
|
+
default:
|
|
939
|
+
ExcretionsComponent.excretionState = "abandoned";
|
|
940
|
+
ExcretionsComponent._excretionActivity = "abandoned";
|
|
941
|
+
break;
|
|
942
|
+
}
|
|
943
|
+
};
|
|
944
|
+
ExcretionsComponent.clearExcretionsCoords = function() {
|
|
945
|
+
console.log("clear!");
|
|
946
|
+
ExcretionsComponent._excretions.forEach((function(excretion) {
|
|
947
|
+
return excretion.remove();
|
|
948
|
+
}));
|
|
949
|
+
ExcretionsComponent._excretions = [];
|
|
950
|
+
ExcretionsComponent.excretionsCoords = [];
|
|
951
|
+
};
|
|
952
|
+
ExcretionsComponent.getTempCoords = function() {
|
|
953
|
+
var startCoords = ExcretionsComponent._tempCoords[0];
|
|
954
|
+
var endCoords = ExcretionsComponent._tempCoords[1];
|
|
955
|
+
var coords = Object.assign(startCoords, endCoords);
|
|
956
|
+
ExcretionsComponent._tempCoords = [];
|
|
957
|
+
return coords;
|
|
958
|
+
};
|
|
959
|
+
ExcretionsComponent.endExcretion = function() {
|
|
960
|
+
var coords = ExcretionsComponent.getTempCoords();
|
|
961
|
+
ExcretionsComponent.excretionsCoords.push(coords);
|
|
962
|
+
ExcretionsComponent._excretionActivity = "end";
|
|
963
|
+
console.log("ExcretionsComponent.excretionsCoords", ExcretionsComponent.excretionsCoords);
|
|
964
|
+
};
|
|
965
|
+
ExcretionsComponent.emmit = function() {
|
|
966
|
+
CanvasComponent.subscribe("mousedown", (function(event, cursorPosition) {
|
|
967
|
+
var toolState = ExcretionsComponent._excretionToolState;
|
|
968
|
+
if (toolState === "abandoned") return;
|
|
969
|
+
var state = ExcretionsComponent._excretionState;
|
|
970
|
+
if (state === "create") {
|
|
971
|
+
var wrapOptions = {
|
|
972
|
+
className: ExcretionsComponent._excretionDefaultStyle[0]
|
|
973
|
+
};
|
|
974
|
+
var excretionTemplate = ExcretionsComponent.getTemplate(ExcretionsComponent.templateExcretion, wrapOptions);
|
|
975
|
+
ExcretionsComponent.clearExcretionsCoords();
|
|
976
|
+
var tempStart = {
|
|
977
|
+
start: cursorPosition
|
|
978
|
+
};
|
|
979
|
+
excretionTemplate.style.left = "".concat(tempStart.start.x, "px");
|
|
980
|
+
excretionTemplate.style.top = "".concat(tempStart.start.y, "px");
|
|
981
|
+
var excretionElement = ExcretionsComponent.excretionWrap.appendChild(excretionTemplate);
|
|
982
|
+
ExcretionsComponent._excretions.push(excretionElement);
|
|
983
|
+
ExcretionsComponent._tempCoords.push(tempStart);
|
|
984
|
+
}
|
|
985
|
+
if (state === "add") {
|
|
986
|
+
var tempStart = {
|
|
987
|
+
start: cursorPosition
|
|
988
|
+
};
|
|
989
|
+
ExcretionsComponent._tempCoords.push(tempStart);
|
|
990
|
+
}
|
|
991
|
+
ExcretionsComponent.applyExcretionStyle();
|
|
992
|
+
ExcretionsComponent._excretionActivity = "active";
|
|
993
|
+
}));
|
|
994
|
+
CanvasComponent.subscribe("mousemove", (function(event, cursorPosition) {
|
|
995
|
+
var toolState = ExcretionsComponent._excretionToolState;
|
|
996
|
+
if (toolState === "abandoned") return;
|
|
997
|
+
var activity = ExcretionsComponent._excretionActivity;
|
|
998
|
+
if (event.altKey && ExcretionsComponent._excretionState !== "abandoned") {
|
|
999
|
+
ExcretionsComponent._excretionState = "add";
|
|
1000
|
+
}
|
|
1001
|
+
if (activity === "abandoned") return;
|
|
1002
|
+
if (activity === "active") {
|
|
1003
|
+
var excretionLastIndex = ExcretionsComponent._excretions.length - 1;
|
|
1004
|
+
var excretion = ExcretionsComponent._excretions[excretionLastIndex];
|
|
1005
|
+
var excretionX = +excretion.style.left.split("px")[0];
|
|
1006
|
+
var excretionY = +excretion.style.top.split("px")[0];
|
|
1007
|
+
var width = Math.abs(cursorPosition.x - excretionX);
|
|
1008
|
+
var height = Math.abs(cursorPosition.y - excretionY);
|
|
1009
|
+
excretion.style.width = width + "px";
|
|
1010
|
+
excretion.style.height = height + "px";
|
|
1011
|
+
var isRightBottom = cursorPosition.x > excretionX && cursorPosition.y > excretionY;
|
|
1012
|
+
var isLeftBottom = cursorPosition.x < excretionX && cursorPosition.y > excretionY;
|
|
1013
|
+
var isLeftTop = cursorPosition.x < excretionX && cursorPosition.y < excretionY;
|
|
1014
|
+
var isRightTop = cursorPosition.x > excretionX && cursorPosition.y < excretionY;
|
|
1015
|
+
if (isRightBottom) {
|
|
1016
|
+
excretion.style.transform = "translateX(0px) translateY(0px)";
|
|
1017
|
+
} else if (isLeftBottom) {
|
|
1018
|
+
excretion.style.transform = "translateX(-".concat(width, "px) translateY(0px)");
|
|
1019
|
+
} else if (isLeftTop) {
|
|
1020
|
+
excretion.style.transform = "translateX(-".concat(width, "px) translateY(-").concat(height, "px)");
|
|
1021
|
+
} else if (isRightTop) {
|
|
1022
|
+
excretion.style.transform = "translateX(0px) translateY(-".concat(height, "px)");
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
}));
|
|
1026
|
+
CanvasComponent.subscribe("mouseup", (function(event, cursorPosition) {
|
|
1027
|
+
var toolState = ExcretionsComponent._excretionToolState;
|
|
1028
|
+
if (toolState === "abandoned") return;
|
|
1029
|
+
var state = ExcretionsComponent._excretionState;
|
|
1030
|
+
if (state === "abandoned") return;
|
|
1031
|
+
if (state === "create" || state === "add") {
|
|
1032
|
+
var tempEnd = {
|
|
1033
|
+
end: cursorPosition
|
|
1034
|
+
};
|
|
1035
|
+
ExcretionsComponent._tempCoords.push(tempEnd);
|
|
1036
|
+
ExcretionsComponent.endExcretion();
|
|
1037
|
+
}
|
|
1038
|
+
}));
|
|
1039
|
+
};
|
|
1040
|
+
ExcretionsComponent.template = "";
|
|
1041
|
+
ExcretionsComponent.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 ';
|
|
1042
|
+
ExcretionsComponent._excretionDefaultStyle = [ "excretion" ];
|
|
1043
|
+
ExcretionsComponent.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(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(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 ");
|
|
1044
|
+
ExcretionsComponent._excretions = [];
|
|
1045
|
+
ExcretionsComponent._excretionState = "abandoned";
|
|
1046
|
+
ExcretionsComponent._excretionActivity = "abandoned";
|
|
1047
|
+
ExcretionsComponent._excretionToolState = "abandoned";
|
|
1048
|
+
ExcretionsComponent._tempCoords = [];
|
|
1049
|
+
ExcretionsComponent.excretionsCoords = [];
|
|
1050
|
+
ExcretionsComponent._additionStyle = "default";
|
|
1051
|
+
ExcretionsComponent.tool = {
|
|
1052
|
+
id: 1,
|
|
1053
|
+
name: "excretion",
|
|
1054
|
+
onAction: function() {
|
|
1055
|
+
return ExcretionsComponent.setToolState("taken");
|
|
1056
|
+
},
|
|
1057
|
+
offAction: function() {
|
|
1058
|
+
return ExcretionsComponent.setToolState("abandoned");
|
|
1059
|
+
},
|
|
1060
|
+
support: function() {
|
|
1061
|
+
ExcretionsComponent.clearExcretionsCoords();
|
|
1062
|
+
ExcretionsComponent.additionStyle = "default";
|
|
1063
|
+
}
|
|
1064
|
+
};
|
|
1065
|
+
(function() {
|
|
1066
|
+
ToolService.add(ExcretionsComponent.tool);
|
|
1067
|
+
LoggerService.components.add({
|
|
1068
|
+
info: {
|
|
1069
|
+
name: "excretion",
|
|
1070
|
+
description: "excretion component"
|
|
1071
|
+
},
|
|
1072
|
+
prototype: ExcretionsComponent
|
|
1073
|
+
});
|
|
1074
|
+
})();
|
|
1075
|
+
return ExcretionsComponent;
|
|
1076
|
+
}(ComponentService);
|
|
1077
|
+
|
|
1078
|
+
var Guid4 = function() {
|
|
1079
|
+
function Guid4() {
|
|
1080
|
+
this.stack = [];
|
|
1081
|
+
}
|
|
1082
|
+
Guid4.prototype.generate = function() {
|
|
1083
|
+
return this.Guid4;
|
|
1084
|
+
};
|
|
1085
|
+
Object.defineProperty(Guid4.prototype, "finite", {
|
|
1086
|
+
get: function() {
|
|
1087
|
+
var _a;
|
|
1088
|
+
var guid4 = this.stack[(_a = this.stack) === null || _a === void 0 ? void 0 : _a.length];
|
|
1089
|
+
if (!!guid4) {
|
|
1090
|
+
return guid4;
|
|
1091
|
+
} else {
|
|
1092
|
+
throw new Error("Guid4 not generate");
|
|
1093
|
+
}
|
|
1094
|
+
},
|
|
1095
|
+
enumerable: false,
|
|
1096
|
+
configurable: true
|
|
1097
|
+
});
|
|
1098
|
+
Guid4.prototype.generateWithFactor = function(attempt) {
|
|
1099
|
+
var factor = this.getFactor(this.guid4);
|
|
1100
|
+
attempt.use("withError").run(factor);
|
|
1101
|
+
};
|
|
1102
|
+
Guid4.prototype.getFactor = function(guid4) {
|
|
1103
|
+
var _this = this;
|
|
1104
|
+
return function(attempt) {
|
|
1105
|
+
guid4 = _this.Guid4;
|
|
1106
|
+
if (!_this.stack.includes(guid4)) {
|
|
1107
|
+
attempt.current = attempt.max;
|
|
1108
|
+
_this.stack.push(guid4);
|
|
1109
|
+
}
|
|
1110
|
+
};
|
|
1111
|
+
};
|
|
1112
|
+
Object.defineProperty(Guid4.prototype, "attempt", {
|
|
1113
|
+
get: function() {
|
|
1114
|
+
var attemptConfig = {
|
|
1115
|
+
attempt: {
|
|
1116
|
+
current: 1,
|
|
1117
|
+
max: 5
|
|
1118
|
+
},
|
|
1119
|
+
error: {
|
|
1120
|
+
message: "[Fatal Error] Guid4 module cannot generate unique guid4"
|
|
1121
|
+
}
|
|
1122
|
+
};
|
|
1123
|
+
var attempt = new GenerateAttempt(attemptConfig.attempt, attemptConfig.error);
|
|
1124
|
+
return attempt;
|
|
1125
|
+
},
|
|
1126
|
+
enumerable: false,
|
|
1127
|
+
configurable: true
|
|
1128
|
+
});
|
|
1129
|
+
Object.defineProperty(Guid4.prototype, "Guid4", {
|
|
1130
|
+
get: function() {
|
|
1131
|
+
var base = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx";
|
|
1132
|
+
var regex = /[xy]/g;
|
|
1133
|
+
var guid4 = base.replace(regex, this.formating);
|
|
1134
|
+
return guid4;
|
|
1135
|
+
},
|
|
1136
|
+
enumerable: false,
|
|
1137
|
+
configurable: true
|
|
1138
|
+
});
|
|
1139
|
+
Guid4.prototype.formating = function(char) {
|
|
1140
|
+
var preformer = Math.random() * 16 | 0;
|
|
1141
|
+
var formattedChar = char == "x" ? preformer : preformer & 3 | 8;
|
|
1142
|
+
return formattedChar.toString(16);
|
|
1143
|
+
};
|
|
1144
|
+
return Guid4;
|
|
1145
|
+
}();
|
|
1146
|
+
|
|
1147
|
+
var GenerateAttempt = function() {
|
|
1148
|
+
function GenerateAttempt(config, error) {
|
|
1149
|
+
this._attempt = config;
|
|
1150
|
+
if (!!error) this._error = error;
|
|
1151
|
+
}
|
|
1152
|
+
GenerateAttempt.prototype.use = function(strategy) {
|
|
1153
|
+
if (strategy === void 0) {
|
|
1154
|
+
strategy = "default";
|
|
1155
|
+
}
|
|
1156
|
+
var context = this;
|
|
1157
|
+
switch (strategy) {
|
|
1158
|
+
case "default":
|
|
1159
|
+
return {
|
|
1160
|
+
run: function(action) {
|
|
1161
|
+
context.defaultRun(action);
|
|
1162
|
+
}
|
|
1163
|
+
};
|
|
1164
|
+
|
|
1165
|
+
case "withError":
|
|
1166
|
+
return {
|
|
1167
|
+
run: function(action) {
|
|
1168
|
+
context.withErrorRun(action);
|
|
1169
|
+
}
|
|
1170
|
+
};
|
|
1171
|
+
}
|
|
1172
|
+
};
|
|
1173
|
+
GenerateAttempt.prototype.defaultRun = function(action) {
|
|
1174
|
+
var attemptCondition = this._attempt.current <= this._attempt.max;
|
|
1175
|
+
while (attemptCondition) {
|
|
1176
|
+
action(this._attempt);
|
|
1177
|
+
this._attempt.current++;
|
|
1178
|
+
}
|
|
1179
|
+
};
|
|
1180
|
+
GenerateAttempt.prototype.withErrorRun = function(action) {
|
|
1181
|
+
var attemptCondition = this._attempt.current <= this._attempt.max;
|
|
1182
|
+
var errorCondition = this._attempt.current === this._attempt.max;
|
|
1183
|
+
var errorMessage = this._error.message;
|
|
1184
|
+
while (attemptCondition) {
|
|
1185
|
+
this.throwError(errorCondition, errorMessage);
|
|
1186
|
+
action(this._attempt);
|
|
1187
|
+
this._attempt.current++;
|
|
1188
|
+
}
|
|
1189
|
+
};
|
|
1190
|
+
GenerateAttempt.prototype.throwError = function(condition, message) {
|
|
1191
|
+
if (condition) {
|
|
1192
|
+
throw new Error(message);
|
|
1193
|
+
}
|
|
1194
|
+
};
|
|
1195
|
+
return GenerateAttempt;
|
|
1196
|
+
}();
|
|
1197
|
+
|
|
1198
|
+
var EventService = function() {
|
|
1199
|
+
function EventService() {}
|
|
1200
|
+
EventService.subcribe = function(controlEvent) {
|
|
1201
|
+
var eventAtom = __assign({
|
|
1202
|
+
id: (new Guid4).generate()
|
|
1203
|
+
}, controlEvent);
|
|
1204
|
+
EventService.eventList.push(eventAtom);
|
|
1205
|
+
};
|
|
1206
|
+
EventService.dispatch = function(name, eventArgs) {
|
|
1207
|
+
var eventAtom = EventService.eventList.find((function(event) {
|
|
1208
|
+
return event.name === name;
|
|
1209
|
+
}));
|
|
1210
|
+
eventAtom.action(eventArgs);
|
|
1211
|
+
};
|
|
1212
|
+
EventService.applyEvents = function(baseElement) {
|
|
1213
|
+
var _a;
|
|
1214
|
+
(_a = EventService.eventList) === null || _a === void 0 ? void 0 : _a.forEach((function(event) {
|
|
1215
|
+
baseElement.addEventListener(event.name, event.action);
|
|
1216
|
+
}));
|
|
1217
|
+
};
|
|
1218
|
+
EventService.eventList = [];
|
|
1219
|
+
return EventService;
|
|
1220
|
+
}();
|
|
1221
|
+
|
|
1222
|
+
var LoadingComponent = function(_super) {
|
|
1223
|
+
__extends(LoadingComponent, _super);
|
|
1224
|
+
function LoadingComponent() {
|
|
1225
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
1226
|
+
}
|
|
1227
|
+
LoadingComponent.getComponent = function() {
|
|
1228
|
+
var wrapOptions = {
|
|
1229
|
+
className: "loading-wrapper"
|
|
1230
|
+
};
|
|
1231
|
+
var loadingTemplate = LoadingComponent.getTemplate(LoadingComponent.template, wrapOptions);
|
|
1232
|
+
var loadingStyle = LoadingComponent.getStyle(LoadingComponent.css);
|
|
1233
|
+
LoadingComponent.loading = loadingTemplate;
|
|
1234
|
+
LoadingComponent.subscribeLoadingStart();
|
|
1235
|
+
LoadingComponent.subscribeLoadingEnd();
|
|
1236
|
+
return {
|
|
1237
|
+
loadingTemplate,
|
|
1238
|
+
loadingStyle
|
|
1239
|
+
};
|
|
1240
|
+
};
|
|
1241
|
+
LoadingComponent.hide = function() {
|
|
1242
|
+
LoadingComponent.loading.style.display = "none";
|
|
1243
|
+
};
|
|
1244
|
+
LoadingComponent.view = function() {
|
|
1245
|
+
LoadingComponent.loading.style.display = "flex";
|
|
1246
|
+
};
|
|
1247
|
+
LoadingComponent.subscribeLoadingStart = function() {
|
|
1248
|
+
var controlEvent = {
|
|
1249
|
+
name: "loading-start",
|
|
1250
|
+
action: function() {
|
|
1251
|
+
return LoadingComponent.view();
|
|
1252
|
+
}
|
|
1253
|
+
};
|
|
1254
|
+
EventService.subcribe(controlEvent);
|
|
1255
|
+
};
|
|
1256
|
+
LoadingComponent.subscribeLoadingEnd = function() {
|
|
1257
|
+
var controlEvent = {
|
|
1258
|
+
name: "loading-end",
|
|
1259
|
+
action: function() {
|
|
1260
|
+
return LoadingComponent.hide();
|
|
1261
|
+
}
|
|
1262
|
+
};
|
|
1263
|
+
EventService.subcribe(controlEvent);
|
|
1264
|
+
};
|
|
1265
|
+
LoadingComponent.template = '\n <span class="loader"></span>\n ';
|
|
1266
|
+
LoadingComponent.css = '\n .loading-wrapper {\n display: none; \n justify-content: center;\n align-items: center;\n position: absolute;\n width: 100%;\n height: 100%;\n background: #ffffff30;\n }\n\n .loader {\n width: 48px;\n height: 48px;\n border-radius: 50%;\n position: relative;\n animation: rotate 1s linear infinite\n }\n .loader::before , .loader::after {\n content: "";\n box-sizing: border-box;\n position: absolute;\n inset: 0px;\n border-radius: 50%;\n border: 5px solid #FFF;\n animation: prixClipFix 2s linear infinite ;\n }\n .loader::after{\n inset: 8px;\n transform: rotate3d(90, 90, 0, 180deg );\n border-color: #FF3D00;\n }\n\n @keyframes rotate {\n 0% {transform: rotate(0deg)}\n 100% {transform: rotate(360deg)}\n }\n\n @keyframes prixClipFix {\n 0% {clip-path:polygon(50% 50%,0 0,0 0,0 0,0 0,0 0)}\n 50% {clip-path:polygon(50% 50%,0 0,100% 0,100% 0,100% 0,100% 0)}\n 75%, 100% {clip-path:polygon(50% 50%,0 0,100% 0,100% 100%,100% 100%,100% 100%)}\n }\n ';
|
|
1267
|
+
(function() {
|
|
1268
|
+
LoggerService.components.add({
|
|
1269
|
+
info: {
|
|
1270
|
+
name: "loading",
|
|
1271
|
+
description: "loading component"
|
|
1272
|
+
},
|
|
1273
|
+
prototype: LoadingComponent
|
|
1274
|
+
});
|
|
1275
|
+
})();
|
|
1276
|
+
return LoadingComponent;
|
|
1277
|
+
}(ComponentService);
|
|
1278
|
+
|
|
1279
|
+
var PipetteComponent = function(_super) {
|
|
1280
|
+
__extends(PipetteComponent, _super);
|
|
1281
|
+
function PipetteComponent() {
|
|
1282
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
1283
|
+
}
|
|
1284
|
+
Object.defineProperty(PipetteComponent, "pipetteColor", {
|
|
1285
|
+
get: function() {
|
|
1286
|
+
return PipetteComponent._pipetteColor;
|
|
1287
|
+
},
|
|
1288
|
+
set: function(color) {
|
|
1289
|
+
PipetteComponent._pipetteColor = color;
|
|
1290
|
+
PipetteComponent._pipetteColorElement.style.borderColor = PipetteComponent._pipetteColor;
|
|
1291
|
+
},
|
|
1292
|
+
enumerable: false,
|
|
1293
|
+
configurable: true
|
|
1294
|
+
});
|
|
1295
|
+
PipetteComponent.getComponent = function() {
|
|
1296
|
+
var wrapOptions = {
|
|
1297
|
+
className: "pipette"
|
|
1298
|
+
};
|
|
1299
|
+
var pipetteTemplate = PipetteComponent.getTemplate(PipetteComponent.template, wrapOptions);
|
|
1300
|
+
var pipetteStyle = PipetteComponent.getStyle(PipetteComponent.css);
|
|
1301
|
+
PipetteComponent.pipette = pipetteTemplate;
|
|
1302
|
+
PipetteComponent._pipetteColorElement = pipetteTemplate.querySelector(".pipette_color");
|
|
1303
|
+
PipetteComponent.emmit();
|
|
1304
|
+
return {
|
|
1305
|
+
pipetteTemplate,
|
|
1306
|
+
pipetteStyle
|
|
1307
|
+
};
|
|
1308
|
+
};
|
|
1309
|
+
PipetteComponent.setState = function(state) {
|
|
1310
|
+
PipetteComponent._pipetteState = state;
|
|
1311
|
+
switch (state) {
|
|
1312
|
+
case "abandoned":
|
|
1313
|
+
return PipetteComponent.hide();
|
|
1314
|
+
|
|
1315
|
+
case "taken":
|
|
1316
|
+
return PipetteComponent.show();
|
|
1317
|
+
|
|
1318
|
+
case "selected-color":
|
|
1319
|
+
return PipetteComponent.show();
|
|
1320
|
+
|
|
1321
|
+
default:
|
|
1322
|
+
return PipetteComponent.hide();
|
|
1323
|
+
}
|
|
1324
|
+
};
|
|
1325
|
+
PipetteComponent.emmit = function() {
|
|
1326
|
+
CanvasComponent.subscribe("mousemove", (function(event, cursorPosition) {
|
|
1327
|
+
var state = PipetteComponent._pipetteState;
|
|
1328
|
+
if (state === "taken" || state === "selected-color") {
|
|
1329
|
+
var x = cursorPosition.x, y = cursorPosition.y;
|
|
1330
|
+
PipetteComponent.pipette.style.left = "".concat(x + 10, "px");
|
|
1331
|
+
PipetteComponent.pipette.style.top = "".concat(y + 10, "px");
|
|
1332
|
+
}
|
|
1333
|
+
}));
|
|
1334
|
+
CanvasComponent.subscribe("click", (function(event, cursorPosition) {
|
|
1335
|
+
var state = PipetteComponent._pipetteState;
|
|
1336
|
+
if (state === "taken" || state === "selected-color") {
|
|
1337
|
+
console.log("pipetteState", state);
|
|
1338
|
+
if (state === "taken") {
|
|
1339
|
+
PipetteComponent.setColorFromChoosenPixel(cursorPosition);
|
|
1340
|
+
PipetteComponent.setState("selected-color");
|
|
1341
|
+
}
|
|
1342
|
+
if (state === "selected-color") {
|
|
1343
|
+
PipetteComponent.setColorFromChoosenPixel(cursorPosition);
|
|
1344
|
+
}
|
|
1345
|
+
}
|
|
1346
|
+
}));
|
|
1347
|
+
};
|
|
1348
|
+
PipetteComponent.setColorFromChoosenPixel = function(cursorPosition) {
|
|
1349
|
+
var x = cursorPosition.x, y = cursorPosition.y;
|
|
1350
|
+
var pixel = CanvasComponent.ctx.getImageData(x, y, 1, 1).data;
|
|
1351
|
+
var hexPixel = Convert.rgbToHex(pixel[0], pixel[1], pixel[2]);
|
|
1352
|
+
PipetteComponent.pipetteColor = hexPixel;
|
|
1353
|
+
};
|
|
1354
|
+
PipetteComponent.show = function() {
|
|
1355
|
+
PipetteComponent.pipette.style.display = "flex";
|
|
1356
|
+
CanvasComponent.cursorStyle = "default";
|
|
1357
|
+
};
|
|
1358
|
+
PipetteComponent.hide = function() {
|
|
1359
|
+
PipetteComponent.pipette.style.display = "none";
|
|
1360
|
+
CanvasComponent.cursorStyle = "default";
|
|
1361
|
+
};
|
|
1362
|
+
PipetteComponent.template = '\n <div class="pipette_border-out">\n <div class="pipette_color">\n <div class="pipette_border-in">\n <svg width="24px" height="24px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"><path d="M17 12C17 14.7614 14.7614 17 12 17M17 12C17 9.23858 14.7614 7 12 7M17 12H19M12 17C9.23858 17 7 14.7614 7 12M12 17V19M7 12C7 9.23858 9.23858 7 12 7M7 12H5M12 7V5M14 12C14 13.1046 13.1046 14 12 14C10.8954 14 10 13.1046 10 12C10 10.8954 10.8954 10 12 10C13.1046 10 14 10.8954 14 12Z" stroke="#d9d9d9" stroke-linecap="round" stroke-linejoin="round"></path></g></svg>\n </div> \n </div>\n </div>\n ';
|
|
1363
|
+
PipetteComponent.css = "\n .pipette {\n position: absolute;\n display: none;\n justify-content: center;\n align-items: center;\n width: 48px;\n height: 48px;\n }\n\n .pipette_border-out {\n display: flex;\n justify-content: center;\n align-items: center;\n border-radius: 100px;\n border: solid 2px #d9d9d9;\n width: 44px;\n height: 44px;\n }\n\n .pipette_border-in {\n display: flex;\n justify-content: center;\n align-items: center;\n border-radius: 100px;\n border: solid 1px #d9d9d9;\n width: 32px;\n height: 32px;\n }\n\n .pipette_color {\n display: flex;\n justify-content: center;\n align-items: center;\n width: 34px;\n height: 34px;\n border-radius: 100px;\n border-color: blue;\n border-style: solid;\n border-width: 5px;\n }\n ";
|
|
1364
|
+
PipetteComponent._pipetteState = "abandoned";
|
|
1365
|
+
PipetteComponent.tool = {
|
|
1366
|
+
id: 0,
|
|
1367
|
+
name: "pipette",
|
|
1368
|
+
onAction: function() {
|
|
1369
|
+
return PipetteComponent.setState("taken");
|
|
1370
|
+
},
|
|
1371
|
+
offAction: function() {
|
|
1372
|
+
return PipetteComponent.setState("abandoned");
|
|
1373
|
+
}
|
|
1374
|
+
};
|
|
1375
|
+
(function() {
|
|
1376
|
+
ToolService.add(PipetteComponent.tool);
|
|
1377
|
+
LoggerService.components.add({
|
|
1378
|
+
info: {
|
|
1379
|
+
name: "pipette",
|
|
1380
|
+
description: "pipette component"
|
|
1381
|
+
},
|
|
1382
|
+
prototype: PipetteComponent
|
|
1383
|
+
});
|
|
1384
|
+
})();
|
|
1385
|
+
return PipetteComponent;
|
|
1386
|
+
}(ComponentService);
|
|
1387
|
+
|
|
1388
|
+
var SlotComponent = function(_super) {
|
|
1389
|
+
__extends(SlotComponent, _super);
|
|
1390
|
+
function SlotComponent() {
|
|
1391
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
1392
|
+
}
|
|
1393
|
+
SlotComponent.getComponent = function(slotName) {
|
|
1394
|
+
var wrapOptions = {
|
|
1395
|
+
className: "slot-wrapper"
|
|
1396
|
+
};
|
|
1397
|
+
var slotTemplate = SlotComponent.getTemplate(SlotComponent.template, wrapOptions);
|
|
1398
|
+
var slotStyle = SlotComponent.getStyle(SlotComponent.css);
|
|
1399
|
+
SlotComponent.slot = slotTemplate.querySelector("slot");
|
|
1400
|
+
SlotComponent.slot.name = slotName;
|
|
1401
|
+
return {
|
|
1402
|
+
slotTemplate,
|
|
1403
|
+
slotStyle
|
|
1404
|
+
};
|
|
1405
|
+
};
|
|
1406
|
+
SlotComponent.template = '\n <slot class="slot"></slot>\n ';
|
|
1407
|
+
SlotComponent.css = "";
|
|
1408
|
+
(function() {
|
|
1409
|
+
LoggerService.components.add({
|
|
1410
|
+
info: {
|
|
1411
|
+
name: "slot",
|
|
1412
|
+
description: "slot component"
|
|
1413
|
+
},
|
|
1414
|
+
prototype: SlotComponent
|
|
1415
|
+
});
|
|
1416
|
+
})();
|
|
1417
|
+
return SlotComponent;
|
|
1418
|
+
}(ComponentService);
|
|
1419
|
+
|
|
1420
|
+
var WebComponentWrapper = function() {
|
|
1421
|
+
function WebComponentWrapper() {
|
|
1422
|
+
var base = document.createElement("div");
|
|
1423
|
+
base.className = "wc-editor";
|
|
1424
|
+
base.style.position = "relative";
|
|
1425
|
+
base.style.display = "flex";
|
|
1426
|
+
base.style.overflow = "hidden";
|
|
1427
|
+
var stylesWrap = document.createElement("div");
|
|
1428
|
+
stylesWrap.className = "styles-wrap";
|
|
1429
|
+
var editorWrap = document.createElement("div");
|
|
1430
|
+
editorWrap.className = "editor-wrap";
|
|
1431
|
+
editorWrap.style.position = "relative";
|
|
1432
|
+
editorWrap.style.display = "flex";
|
|
1433
|
+
editorWrap.style.overflow = "hidden";
|
|
1434
|
+
var toolsWrap = document.createElement("div");
|
|
1435
|
+
toolsWrap.className = "tools-wrap";
|
|
1436
|
+
toolsWrap.style.position = "relative";
|
|
1437
|
+
toolsWrap.style.display = "flex";
|
|
1438
|
+
base.appendChild(stylesWrap);
|
|
1439
|
+
base.appendChild(editorWrap);
|
|
1440
|
+
base.appendChild(toolsWrap);
|
|
1441
|
+
this.baseElement = base;
|
|
1442
|
+
this.stylesWrapElement = stylesWrap;
|
|
1443
|
+
this.editorWrapElement = editorWrap;
|
|
1444
|
+
this.toolsWrapElement = toolsWrap;
|
|
1445
|
+
this._baseStyle();
|
|
1446
|
+
}
|
|
1447
|
+
Object.defineProperty(WebComponentWrapper.prototype, "base", {
|
|
1448
|
+
get: function() {
|
|
1449
|
+
return this._methods(this.baseElement);
|
|
1450
|
+
},
|
|
1451
|
+
enumerable: false,
|
|
1452
|
+
configurable: true
|
|
1453
|
+
});
|
|
1454
|
+
Object.defineProperty(WebComponentWrapper.prototype, "editorWrap", {
|
|
1455
|
+
get: function() {
|
|
1456
|
+
return this._methods(this.editorWrapElement);
|
|
1457
|
+
},
|
|
1458
|
+
enumerable: false,
|
|
1459
|
+
configurable: true
|
|
1460
|
+
});
|
|
1461
|
+
Object.defineProperty(WebComponentWrapper.prototype, "stylesWrap", {
|
|
1462
|
+
get: function() {
|
|
1463
|
+
return this._methods(this.stylesWrapElement);
|
|
1464
|
+
},
|
|
1465
|
+
enumerable: false,
|
|
1466
|
+
configurable: true
|
|
1467
|
+
});
|
|
1468
|
+
Object.defineProperty(WebComponentWrapper.prototype, "toolsWrap", {
|
|
1469
|
+
get: function() {
|
|
1470
|
+
return this._methods(this.toolsWrapElement);
|
|
1471
|
+
},
|
|
1472
|
+
enumerable: false,
|
|
1473
|
+
configurable: true
|
|
1474
|
+
});
|
|
1475
|
+
WebComponentWrapper.prototype._methods = function(elementWrapper) {
|
|
1476
|
+
var _this = this;
|
|
1477
|
+
return {
|
|
1478
|
+
add: function(component, style) {
|
|
1479
|
+
return _this._add(elementWrapper, component, style);
|
|
1480
|
+
}
|
|
1481
|
+
};
|
|
1482
|
+
};
|
|
1483
|
+
WebComponentWrapper.prototype._add = function(elementWrapper, component, style) {
|
|
1484
|
+
var componentElement = elementWrapper.appendChild(component);
|
|
1485
|
+
if (!!style) {
|
|
1486
|
+
this.stylesWrapElement.appendChild(style);
|
|
1487
|
+
}
|
|
1488
|
+
return componentElement;
|
|
1489
|
+
};
|
|
1490
|
+
WebComponentWrapper.prototype._baseStyle = function() {
|
|
1491
|
+
var style = document.createElement("style");
|
|
1492
|
+
style.innerHTML = "\n * {\n user-select: none;\n }\n ";
|
|
1493
|
+
this.stylesWrapElement.appendChild(style);
|
|
1494
|
+
};
|
|
1495
|
+
return WebComponentWrapper;
|
|
1496
|
+
}();
|
|
1497
|
+
|
|
1498
|
+
var WebComponent = function(_super) {
|
|
1499
|
+
__extends(WebComponent, _super);
|
|
1500
|
+
function WebComponent() {
|
|
1501
|
+
var _this = _super.call(this) || this;
|
|
1502
|
+
var shadowRoot = _this.attachShadow({
|
|
1503
|
+
mode: "open"
|
|
1504
|
+
});
|
|
1505
|
+
var webComponentWrapper = new WebComponentWrapper;
|
|
1506
|
+
var _a = CanvasComponent.getComponent(), canvasTemplate = _a.canvasTemplate, canvasStyle = _a.canvasStyle;
|
|
1507
|
+
var canvasElement = webComponentWrapper.editorWrap.add(canvasTemplate, canvasStyle);
|
|
1508
|
+
var _b = PipetteComponent.getComponent(), pipetteTemplate = _b.pipetteTemplate, pipetteStyle = _b.pipetteStyle;
|
|
1509
|
+
webComponentWrapper.editorWrap.add(pipetteTemplate, pipetteStyle);
|
|
1510
|
+
var _c = SlotComponent.getComponent("tools"), slotTemplate = _c.slotTemplate, slotStyle = _c.slotStyle;
|
|
1511
|
+
webComponentWrapper.toolsWrap.add(slotTemplate, slotStyle);
|
|
1512
|
+
var _d = ExcretionsComponent.getComponent(), excretionsTemplate = _d.excretionsTemplate, excretionsStyle = _d.excretionsStyle;
|
|
1513
|
+
webComponentWrapper.editorWrap.add(excretionsTemplate, excretionsStyle);
|
|
1514
|
+
var _e = LoadingComponent.getComponent(), loadingTemplate = _e.loadingTemplate, loadingStyle = _e.loadingStyle;
|
|
1515
|
+
webComponentWrapper.editorWrap.add(loadingTemplate, loadingStyle);
|
|
1516
|
+
shadowRoot.appendChild(webComponentWrapper.baseElement);
|
|
1517
|
+
CanvasComponent.simulateSubscriptions();
|
|
1518
|
+
EventService.applyEvents(webComponentWrapper.baseElement);
|
|
1519
|
+
_this.addEventListener("initial", (function() {
|
|
1520
|
+
_this.dispatchEvent(new CustomEvent("get-editor-element", {
|
|
1521
|
+
detail: {
|
|
1522
|
+
editorElement: canvasElement,
|
|
1523
|
+
canvasSelector: CanvasComponent.getCanvasSelector()
|
|
1524
|
+
}
|
|
1525
|
+
}));
|
|
1526
|
+
}));
|
|
1527
|
+
return _this;
|
|
1528
|
+
}
|
|
1529
|
+
return WebComponent;
|
|
1530
|
+
}(HTMLElement);
|
|
1531
|
+
|
|
1532
|
+
var VagueFilter = function(_super) {
|
|
1533
|
+
__extends(VagueFilter, _super);
|
|
1534
|
+
function VagueFilter(ctx, options) {
|
|
1535
|
+
var _this = _super.call(this, ctx) || this;
|
|
1536
|
+
_this.filterList = [ "pixel" ];
|
|
1537
|
+
_this.options = options;
|
|
1538
|
+
return _this;
|
|
1539
|
+
}
|
|
1540
|
+
VagueFilter.prototype.on = function(action, filterOptions) {
|
|
1541
|
+
var _this = this;
|
|
1542
|
+
return new Promise((function(resolve) {
|
|
1543
|
+
var options = _this.options;
|
|
1544
|
+
var imageData = _this.copy(options);
|
|
1545
|
+
var rowImageData = _this[action](imageData, filterOptions);
|
|
1546
|
+
_this.update(rowImageData, options);
|
|
1547
|
+
return resolve({
|
|
1548
|
+
imageData: rowImageData,
|
|
1549
|
+
position: {
|
|
1550
|
+
x: options.x,
|
|
1551
|
+
y: options.y
|
|
1552
|
+
},
|
|
1553
|
+
size: {
|
|
1554
|
+
width: rowImageData.width,
|
|
1555
|
+
height: rowImageData.height
|
|
1556
|
+
},
|
|
1557
|
+
quality: filterOptions.quality
|
|
1558
|
+
});
|
|
1559
|
+
}));
|
|
1560
|
+
};
|
|
1561
|
+
VagueFilter.prototype.pixel = function(imageData, filterOptions) {
|
|
1562
|
+
var quality = filterOptions.quality;
|
|
1563
|
+
console.log("quality", quality);
|
|
1564
|
+
var processedImageData = this.getQualityProcessedRemainder(imageData, +quality);
|
|
1565
|
+
var imageSize = {
|
|
1566
|
+
width: processedImageData.width,
|
|
1567
|
+
height: processedImageData.height
|
|
1568
|
+
};
|
|
1569
|
+
console.log("imageSize", imageSize);
|
|
1570
|
+
this.setImageSize(imageSize);
|
|
1571
|
+
var _a = this.getBuffCollection(processedImageData), rowRGBABuff = _a.rowRGBABuff, buff = _a.buff;
|
|
1572
|
+
var _b = this.getQualityBuff(buff, +quality), qualityBuff = _b.qualityBuff, rangeCommit = _b.rangeCommit;
|
|
1573
|
+
var qualityBuffWithMostCommonElement = this.getMostCommonQuanlityBuff(qualityBuff, rangeCommit);
|
|
1574
|
+
var rowQualityBuffWithMostCommonElement = qualityBuffWithMostCommonElement.flat();
|
|
1575
|
+
if (rowRGBABuff.length >= rowQualityBuffWithMostCommonElement.length) {
|
|
1576
|
+
var occurrenceRGBAbuff = rowQualityBuffWithMostCommonElement.map((function(hexColor, index) {
|
|
1577
|
+
var _a = Convert.hexToRgb(hexColor), r = _a.r, g = _a.g, b = _a.b;
|
|
1578
|
+
var a = rowRGBABuff[index][3];
|
|
1579
|
+
return [ r, g, b, a ];
|
|
1580
|
+
}));
|
|
1581
|
+
var rowBuff = occurrenceRGBAbuff.flat();
|
|
1582
|
+
rowBuff.forEach((function(color, index) {
|
|
1583
|
+
processedImageData.data[index] = color;
|
|
1584
|
+
}));
|
|
1585
|
+
}
|
|
1586
|
+
return processedImageData;
|
|
1587
|
+
};
|
|
1588
|
+
VagueFilter.prototype.getQualityProcessedRemainder = function(imageData, quality) {
|
|
1589
|
+
var rowRGBABuff = this.getRowRGBABuff(imageData);
|
|
1590
|
+
var RGBAMatrix = this.getRGBAMatrix(rowRGBABuff, {
|
|
1591
|
+
width: imageData.width,
|
|
1592
|
+
height: imageData.height
|
|
1593
|
+
});
|
|
1594
|
+
var cqx = quality - imageData.width % quality;
|
|
1595
|
+
var cqy = quality - imageData.height % quality;
|
|
1596
|
+
var xCommit = range(0, cqx);
|
|
1597
|
+
var yCommit = range(0, cqy);
|
|
1598
|
+
var tempSize = {
|
|
1599
|
+
width: imageData.width + cqx,
|
|
1600
|
+
height: imageData.height + cqy
|
|
1601
|
+
};
|
|
1602
|
+
var xLastIndex = RGBAMatrix[0].length - 1;
|
|
1603
|
+
RGBAMatrix.forEach((function(row, y) {
|
|
1604
|
+
var xLastRGBAByte = row[xLastIndex];
|
|
1605
|
+
xCommit.forEach((function() {
|
|
1606
|
+
return RGBAMatrix[y].push(xLastRGBAByte);
|
|
1607
|
+
}));
|
|
1608
|
+
}));
|
|
1609
|
+
var yLastIndex = RGBAMatrix.length - 1;
|
|
1610
|
+
var yLastRGBARow = RGBAMatrix[yLastIndex];
|
|
1611
|
+
yCommit.forEach((function() {
|
|
1612
|
+
return RGBAMatrix.push(yLastRGBARow);
|
|
1613
|
+
}));
|
|
1614
|
+
var buffWithRemainder = RGBAMatrix.flat(2);
|
|
1615
|
+
var tempCanvas = document.createElement("canvas");
|
|
1616
|
+
var tempCtx = tempCanvas.getContext("2d");
|
|
1617
|
+
var tempImageData = tempCtx.createImageData(tempSize.width, tempSize.height);
|
|
1618
|
+
buffWithRemainder.forEach((function(_, i) {
|
|
1619
|
+
return tempImageData.data[i] = buffWithRemainder[i];
|
|
1620
|
+
}));
|
|
1621
|
+
return tempImageData;
|
|
1622
|
+
};
|
|
1623
|
+
VagueFilter.prototype.getQualityBuff = function(buff, quality) {
|
|
1624
|
+
var wq = Math.floor(this.imageSize.width / quality);
|
|
1625
|
+
var hq = Math.floor(this.imageSize.height / quality);
|
|
1626
|
+
var qualityBuff = [];
|
|
1627
|
+
var rangeCommit = [];
|
|
1628
|
+
var i = 0;
|
|
1629
|
+
var xStart = 0;
|
|
1630
|
+
var xEnd = quality;
|
|
1631
|
+
var yStart = 0;
|
|
1632
|
+
var yEnd = quality;
|
|
1633
|
+
range(0, hq).forEach((function(hqi) {
|
|
1634
|
+
range(0, wq).forEach((function(wqi) {
|
|
1635
|
+
var _a, _b;
|
|
1636
|
+
var dy = range(yStart, yEnd);
|
|
1637
|
+
var dx = range(xStart, xEnd);
|
|
1638
|
+
var items = [];
|
|
1639
|
+
var coords = [];
|
|
1640
|
+
dy.forEach((function(y) {
|
|
1641
|
+
dx.forEach((function(x) {
|
|
1642
|
+
items.push(buff[y][x]);
|
|
1643
|
+
coords.push({
|
|
1644
|
+
y,
|
|
1645
|
+
x
|
|
1646
|
+
});
|
|
1647
|
+
}));
|
|
1648
|
+
}));
|
|
1649
|
+
xStart += quality;
|
|
1650
|
+
xEnd += quality;
|
|
1651
|
+
(_a = rangeCommit[i]) !== null && _a !== void 0 ? _a : rangeCommit[i] = coords;
|
|
1652
|
+
(_b = qualityBuff[i]) !== null && _b !== void 0 ? _b : qualityBuff[i] = items;
|
|
1653
|
+
i++;
|
|
1654
|
+
}));
|
|
1655
|
+
xStart = 0;
|
|
1656
|
+
xEnd = quality;
|
|
1657
|
+
yStart += quality;
|
|
1658
|
+
yEnd += quality;
|
|
1659
|
+
}));
|
|
1660
|
+
return {
|
|
1661
|
+
qualityBuff,
|
|
1662
|
+
rangeCommit
|
|
1663
|
+
};
|
|
1664
|
+
};
|
|
1665
|
+
VagueFilter.prototype.getMostCommonQuanlityBuff = function(qualityBuff, rangeCommit) {
|
|
1666
|
+
var _this = this;
|
|
1667
|
+
var mostCommonQuanlityBuff = [];
|
|
1668
|
+
var qualityBuffWithMostCommonElement = qualityBuff.map((function(newPixel) {
|
|
1669
|
+
var color = _this.getMostCommonElement(newPixel);
|
|
1670
|
+
return newPixel.map((function() {
|
|
1671
|
+
return color;
|
|
1672
|
+
}));
|
|
1673
|
+
}));
|
|
1674
|
+
qualityBuffWithMostCommonElement.forEach((function(qPixel, pixelIndex) {
|
|
1675
|
+
qPixel.forEach((function(pixelColor, pixelColorIndex) {
|
|
1676
|
+
var _a, _b;
|
|
1677
|
+
var _c;
|
|
1678
|
+
var _d = rangeCommit[pixelIndex][pixelColorIndex], x = _d.x, y = _d.y;
|
|
1679
|
+
(_a = mostCommonQuanlityBuff[y]) !== null && _a !== void 0 ? _a : mostCommonQuanlityBuff[y] = [];
|
|
1680
|
+
(_b = (_c = mostCommonQuanlityBuff[y])[x]) !== null && _b !== void 0 ? _b : _c[x] = pixelColor;
|
|
1681
|
+
}));
|
|
1682
|
+
}));
|
|
1683
|
+
return mostCommonQuanlityBuff;
|
|
1684
|
+
};
|
|
1685
|
+
VagueFilter.prototype.getMostCommonElement = function(array) {
|
|
1686
|
+
function mostCommon(a, b) {
|
|
1687
|
+
var diffA = array.filter((function(v) {
|
|
1688
|
+
return v === a;
|
|
1689
|
+
})).length;
|
|
1690
|
+
var diffB = array.filter((function(v) {
|
|
1691
|
+
return v === b;
|
|
1692
|
+
})).length;
|
|
1693
|
+
return diffA - diffB;
|
|
1694
|
+
}
|
|
1695
|
+
var arraySorted = array.sort(mostCommon);
|
|
1696
|
+
var mostCommonElement = arraySorted[arraySorted.length - 1];
|
|
1697
|
+
return mostCommonElement;
|
|
1698
|
+
};
|
|
1699
|
+
return VagueFilter;
|
|
1700
|
+
}(Filter);
|
|
1701
|
+
|
|
1702
|
+
var DrawService = function() {
|
|
1703
|
+
function DrawService() {}
|
|
1704
|
+
DrawService.drawImage = function(ctx, src, options) {
|
|
1705
|
+
DrawService.imageProcessor = new SCImage(src, ctx);
|
|
1706
|
+
DrawService.imageProcessor.draw(options).then((function() {
|
|
1707
|
+
var filter = new Filter(ctx);
|
|
1708
|
+
var zeroPosition = {
|
|
1709
|
+
x: 0,
|
|
1710
|
+
y: 0
|
|
1711
|
+
};
|
|
1712
|
+
var imageData = filter.copy(zeroPosition);
|
|
1713
|
+
AppStore.store.imageState.reduce({
|
|
1714
|
+
tempImageData: imageData,
|
|
1715
|
+
position: zeroPosition,
|
|
1716
|
+
size: AppConfig.CANVAS_SIZE
|
|
1717
|
+
}, "Loaded image");
|
|
1718
|
+
}));
|
|
1719
|
+
};
|
|
1720
|
+
DrawService.drawProject = function(ctx, project) {
|
|
1721
|
+
var imageData = project.state.current.imageData;
|
|
1722
|
+
var position = project.state.current.position;
|
|
1723
|
+
var size = project.state.current.size;
|
|
1724
|
+
DrawService.imageProcessor = new PCImage(project, ctx);
|
|
1725
|
+
DrawService.imageProcessor.draw();
|
|
1726
|
+
AppStore.store.imageState.reduce({
|
|
1727
|
+
tempImageData: imageData,
|
|
1728
|
+
position,
|
|
1729
|
+
size
|
|
1730
|
+
}, "Loaded project");
|
|
1731
|
+
};
|
|
1732
|
+
DrawService.drawSmoothImage = function(useStore, options, filterOptions) {
|
|
1733
|
+
var filterArgs = DrawService.getFilterArgs(useStore, options);
|
|
1734
|
+
EventService.dispatch("loading-start");
|
|
1735
|
+
if (!DrawService.imageProcessor) {
|
|
1736
|
+
throw new Error("No valid ImageProcessor instance found");
|
|
1737
|
+
}
|
|
1738
|
+
DrawService.imageProcessor.vague(filterArgs, filterOptions).then(DrawService.updateImageStateAfterVague).finally((function() {
|
|
1739
|
+
return EventService.dispatch("loading-end");
|
|
1740
|
+
}));
|
|
1741
|
+
};
|
|
1742
|
+
DrawService.updateImageStateAfterVague = function(data) {
|
|
1743
|
+
var imageData = data.imageData, position = data.position, size = data.size, quality = data.quality;
|
|
1744
|
+
AppStore.store.imageState.reduce({
|
|
1745
|
+
tempImageData: imageData,
|
|
1746
|
+
position,
|
|
1747
|
+
size
|
|
1748
|
+
}, "[Filter Vague] quality: ".concat(quality));
|
|
1749
|
+
};
|
|
1750
|
+
DrawService.getFilterArgs = function(useStore, options) {
|
|
1751
|
+
var _a, _b;
|
|
1752
|
+
var filterArgs;
|
|
1753
|
+
var store = AppStore.store.imageState;
|
|
1754
|
+
if (useStore) {
|
|
1755
|
+
filterArgs = {
|
|
1756
|
+
x: store.position.x,
|
|
1757
|
+
y: store.position.y
|
|
1758
|
+
};
|
|
1759
|
+
if (!!store.size.width && !!store.size.height) {
|
|
1760
|
+
filterArgs.width = store.size.width;
|
|
1761
|
+
filterArgs.height = store.size.height;
|
|
1762
|
+
}
|
|
1763
|
+
} else {
|
|
1764
|
+
filterArgs = {
|
|
1765
|
+
x: options.position.x,
|
|
1766
|
+
y: options.position.y
|
|
1767
|
+
};
|
|
1768
|
+
if (options.size !== "initial") {
|
|
1769
|
+
if (!!((_a = options.size) === null || _a === void 0 ? void 0 : _a.width) && !!((_b = options.size) === null || _b === void 0 ? void 0 : _b.height)) {
|
|
1770
|
+
filterArgs.width = options.size.width;
|
|
1771
|
+
filterArgs.height = options.size.height;
|
|
1772
|
+
}
|
|
1773
|
+
}
|
|
1774
|
+
}
|
|
1775
|
+
return filterArgs;
|
|
1776
|
+
};
|
|
1777
|
+
return DrawService;
|
|
1778
|
+
}();
|
|
1779
|
+
|
|
1780
|
+
var SCImage = function() {
|
|
1781
|
+
function SCImage(src, ctx) {
|
|
1782
|
+
this.img = new Image;
|
|
1783
|
+
this.img.src = src;
|
|
1784
|
+
this.ctx = ctx;
|
|
1785
|
+
}
|
|
1786
|
+
SCImage.prototype.draw = function(options) {
|
|
1787
|
+
var _this = this;
|
|
1788
|
+
var proto = this;
|
|
1789
|
+
var protoImg = this.img;
|
|
1790
|
+
return new Promise((function(resolve, reject) {
|
|
1791
|
+
try {
|
|
1792
|
+
protoImg.addEventListener("load", (function() {
|
|
1793
|
+
var _a;
|
|
1794
|
+
var _b, _c;
|
|
1795
|
+
var drawImageArgs = [ options.position.x, options.position.y ];
|
|
1796
|
+
if (options.size !== "initial") {
|
|
1797
|
+
if (!!((_b = options.size) === null || _b === void 0 ? void 0 : _b.width) && !!((_c = options.size) === null || _c === void 0 ? void 0 : _c.height)) {
|
|
1798
|
+
drawImageArgs = drawImageArgs.concat([ options.size.width, options.size.height ]);
|
|
1799
|
+
} else {
|
|
1800
|
+
drawImageArgs = drawImageArgs.concat([ AppConfig.CANVAS_SIZE.width, AppConfig.CANVAS_SIZE.height ]);
|
|
1801
|
+
}
|
|
1802
|
+
}
|
|
1803
|
+
(_a = _this.ctx).drawImage.apply(_a, __spreadArray([ protoImg ], drawImageArgs, false));
|
|
1804
|
+
_this.ctx.save();
|
|
1805
|
+
resolve(proto);
|
|
1806
|
+
}));
|
|
1807
|
+
} catch (error) {
|
|
1808
|
+
reject(error);
|
|
1809
|
+
}
|
|
1810
|
+
}));
|
|
1811
|
+
};
|
|
1812
|
+
SCImage.prototype.vague = function(options, filterOptions) {
|
|
1813
|
+
var filter = new VagueFilter(this.ctx, options);
|
|
1814
|
+
return filter.on("pixel", filterOptions);
|
|
1815
|
+
};
|
|
1816
|
+
return SCImage;
|
|
1817
|
+
}();
|
|
1818
|
+
|
|
1819
|
+
var PCImage = function() {
|
|
1820
|
+
function PCImage(project, ctx) {
|
|
1821
|
+
this.project = project;
|
|
1822
|
+
this.ctx = ctx;
|
|
1823
|
+
}
|
|
1824
|
+
PCImage.prototype.draw = function(options) {
|
|
1825
|
+
var _this = this;
|
|
1826
|
+
var _a = this.project.state.current, imageData = _a.imageData, position = _a.position;
|
|
1827
|
+
return new Promise((function(resolve, reject) {
|
|
1828
|
+
try {
|
|
1829
|
+
var filter = new Filter(_this.ctx);
|
|
1830
|
+
filter.update(imageData, position);
|
|
1831
|
+
_this.ctx.save();
|
|
1832
|
+
resolve(_this);
|
|
1833
|
+
} catch (error) {
|
|
1834
|
+
reject(error);
|
|
1835
|
+
}
|
|
1836
|
+
}));
|
|
1837
|
+
};
|
|
1838
|
+
PCImage.prototype.vague = function(options, filterOptions) {
|
|
1839
|
+
var filter = new VagueFilter(this.ctx, options);
|
|
1840
|
+
return filter.on("pixel", filterOptions);
|
|
1841
|
+
};
|
|
1842
|
+
return PCImage;
|
|
1843
|
+
}();
|
|
1844
|
+
|
|
1845
|
+
var DownloadService = function() {
|
|
1846
|
+
function DownloadService() {}
|
|
1847
|
+
DownloadService.getDataUrl = function() {
|
|
1848
|
+
return CanvasComponent.canvas.toDataURL();
|
|
1849
|
+
};
|
|
1850
|
+
DownloadService.download = function(filename) {
|
|
1851
|
+
var link = document.createElement("a");
|
|
1852
|
+
link.download = "".concat(filename || "image", ".png");
|
|
1853
|
+
link.href = DownloadService.getDataUrl();
|
|
1854
|
+
link.click();
|
|
1855
|
+
};
|
|
1856
|
+
return DownloadService;
|
|
1857
|
+
}();
|
|
1858
|
+
|
|
1859
|
+
var ProjectFileSerializer = function() {
|
|
1860
|
+
function ProjectFileSerializer(file) {
|
|
1861
|
+
this.projects = [];
|
|
1862
|
+
this.file = file;
|
|
1863
|
+
this.projects = this.load();
|
|
1864
|
+
}
|
|
1865
|
+
ProjectFileSerializer.prototype.load = function() {
|
|
1866
|
+
var rowProjects = JSON.parse(this.file);
|
|
1867
|
+
var imageDataProcessor = function(temp) {
|
|
1868
|
+
var data;
|
|
1869
|
+
var size;
|
|
1870
|
+
if (temp === null || temp === void 0 ? void 0 : temp.current) {
|
|
1871
|
+
data = Object.values(temp === null || temp === void 0 ? void 0 : temp.current.imageData.data);
|
|
1872
|
+
size = temp === null || temp === void 0 ? void 0 : temp.current.size;
|
|
1873
|
+
} else if (temp === null || temp === void 0 ? void 0 : temp.state) {
|
|
1874
|
+
data = Object.values(temp === null || temp === void 0 ? void 0 : temp.state.tempImageData.data);
|
|
1875
|
+
size = temp === null || temp === void 0 ? void 0 : temp.state.size;
|
|
1876
|
+
}
|
|
1877
|
+
var tempImageData = new ImageData(size.width, size.height);
|
|
1878
|
+
data.forEach((function(colorAtom, index) {
|
|
1879
|
+
tempImageData.data[index] = colorAtom;
|
|
1880
|
+
}));
|
|
1881
|
+
return tempImageData;
|
|
1882
|
+
};
|
|
1883
|
+
var projects = rowProjects.map((function(project) {
|
|
1884
|
+
project.state.current.imageData = imageDataProcessor({
|
|
1885
|
+
current: project.state.current
|
|
1886
|
+
});
|
|
1887
|
+
project.state.history = project.state.history.map((function(historyLine) {
|
|
1888
|
+
historyLine.stateValue.tempImageData = imageDataProcessor({
|
|
1889
|
+
state: historyLine.stateValue
|
|
1890
|
+
});
|
|
1891
|
+
return historyLine;
|
|
1892
|
+
}));
|
|
1893
|
+
project.state.cache = project.state.cache.map((function(historyLine) {
|
|
1894
|
+
historyLine.stateValue.tempImageData = imageDataProcessor({
|
|
1895
|
+
state: historyLine.stateValue
|
|
1896
|
+
});
|
|
1897
|
+
return historyLine;
|
|
1898
|
+
}));
|
|
1899
|
+
return project;
|
|
1900
|
+
}));
|
|
1901
|
+
return projects;
|
|
1902
|
+
};
|
|
1903
|
+
ProjectFileSerializer.prototype.saveProjects = function(projects) {
|
|
1904
|
+
this.file.save(JSON.stringify(projects));
|
|
1905
|
+
};
|
|
1906
|
+
ProjectFileSerializer.prototype.getProjects = function() {
|
|
1907
|
+
return this.projects;
|
|
1908
|
+
};
|
|
1909
|
+
ProjectFileSerializer.prototype.getProject = function(projectId) {
|
|
1910
|
+
return this.projects.find((function(project) {
|
|
1911
|
+
return project.id === projectId;
|
|
1912
|
+
}));
|
|
1913
|
+
};
|
|
1914
|
+
ProjectFileSerializer.prototype.saveProject = function(project) {
|
|
1915
|
+
var index = this.projects.findIndex((function(p) {
|
|
1916
|
+
return p.id === project.id;
|
|
1917
|
+
}));
|
|
1918
|
+
if (index !== -1) {
|
|
1919
|
+
this.projects[index] = project;
|
|
1920
|
+
} else {
|
|
1921
|
+
this.projects.push(project);
|
|
1922
|
+
}
|
|
1923
|
+
this.saveProjects(this.projects);
|
|
1924
|
+
};
|
|
1925
|
+
ProjectFileSerializer.prototype.removeProject = function(projectId) {
|
|
1926
|
+
var index = this.projects.findIndex((function(p) {
|
|
1927
|
+
return p.id === projectId;
|
|
1928
|
+
}));
|
|
1929
|
+
if (index !== -1) {
|
|
1930
|
+
this.projects.splice(index, 1);
|
|
1931
|
+
this.saveProjects(this.projects);
|
|
1932
|
+
}
|
|
1933
|
+
};
|
|
1934
|
+
ProjectFileSerializer.prototype.updateProject = function(project) {
|
|
1935
|
+
var index = this.projects.findIndex((function(p) {
|
|
1936
|
+
return p.id === project.id;
|
|
1937
|
+
}));
|
|
1938
|
+
if (index !== -1) {
|
|
1939
|
+
this.projects[index] = project;
|
|
1940
|
+
this.saveProjects(this.projects);
|
|
1941
|
+
}
|
|
1942
|
+
};
|
|
1943
|
+
return ProjectFileSerializer;
|
|
1944
|
+
}();
|
|
1945
|
+
|
|
1946
|
+
var LocalStorageProjectModule = function() {
|
|
1947
|
+
function LocalStorageProjectModule() {
|
|
1948
|
+
this.projectsKey = "cee-projects";
|
|
1949
|
+
}
|
|
1950
|
+
LocalStorageProjectModule.prototype.getProjectsFromLocalStorage = function() {
|
|
1951
|
+
var projects = localStorage.getItem(this.projectsKey);
|
|
1952
|
+
return projects ? JSON.parse(projects) : [];
|
|
1953
|
+
};
|
|
1954
|
+
LocalStorageProjectModule.prototype.getProjectFromLocalStorage = function(projectId) {
|
|
1955
|
+
var projects = this.getProjectsFromLocalStorage();
|
|
1956
|
+
return projects.find((function(project) {
|
|
1957
|
+
return project.id === projectId;
|
|
1958
|
+
}));
|
|
1959
|
+
};
|
|
1960
|
+
LocalStorageProjectModule.prototype.saveProjectsToLocalStorage = function(projects) {
|
|
1961
|
+
localStorage.setItem(this.projectsKey, JSON.stringify(projects));
|
|
1962
|
+
};
|
|
1963
|
+
LocalStorageProjectModule.prototype.saveProjectToLocalStorage = function(project) {
|
|
1964
|
+
var projects = this.getProjectsFromLocalStorage();
|
|
1965
|
+
projects.push(project);
|
|
1966
|
+
localStorage.setItem(this.projectsKey, JSON.stringify(projects));
|
|
1967
|
+
};
|
|
1968
|
+
LocalStorageProjectModule.prototype.removeProjectFromLocalStorage = function(projectId) {
|
|
1969
|
+
var projects = this.getProjectsFromLocalStorage();
|
|
1970
|
+
var index = projects.findIndex((function(project) {
|
|
1971
|
+
return project.id === projectId;
|
|
1972
|
+
}));
|
|
1973
|
+
projects.splice(index, 1);
|
|
1974
|
+
localStorage.setItem(this.projectsKey, JSON.stringify(projects));
|
|
1975
|
+
};
|
|
1976
|
+
LocalStorageProjectModule.prototype.updateProjectInLocalStorage = function(project) {
|
|
1977
|
+
var projects = this.getProjectsFromLocalStorage();
|
|
1978
|
+
var index = projects.findIndex((function(p) {
|
|
1979
|
+
return p.id === project.id;
|
|
1980
|
+
}));
|
|
1981
|
+
projects[index] = project;
|
|
1982
|
+
localStorage.setItem(this.projectsKey, JSON.stringify(projects));
|
|
1983
|
+
};
|
|
1984
|
+
LocalStorageProjectModule.prototype.getProjects = function() {
|
|
1985
|
+
return this.getProjectsFromLocalStorage();
|
|
1986
|
+
};
|
|
1987
|
+
LocalStorageProjectModule.prototype.getProject = function(projectId) {
|
|
1988
|
+
return this.getProjectFromLocalStorage(projectId);
|
|
1989
|
+
};
|
|
1990
|
+
LocalStorageProjectModule.prototype.saveProjects = function(projects) {
|
|
1991
|
+
this.saveProjectsToLocalStorage(projects);
|
|
1992
|
+
};
|
|
1993
|
+
LocalStorageProjectModule.prototype.saveProject = function(project) {
|
|
1994
|
+
this.saveProjectToLocalStorage(project);
|
|
1995
|
+
};
|
|
1996
|
+
LocalStorageProjectModule.prototype.removeProject = function(projectId) {
|
|
1997
|
+
this.removeProjectFromLocalStorage(projectId);
|
|
1998
|
+
};
|
|
1999
|
+
LocalStorageProjectModule.prototype.updateProject = function(project) {
|
|
2000
|
+
this.updateProjectInLocalStorage(project);
|
|
2001
|
+
};
|
|
2002
|
+
return LocalStorageProjectModule;
|
|
2003
|
+
}();
|
|
2004
|
+
|
|
2005
|
+
var ProjectFileProjectModule = function() {
|
|
2006
|
+
function ProjectFileProjectModule() {}
|
|
2007
|
+
ProjectFileProjectModule.setSerializer = function(serializer) {
|
|
2008
|
+
ProjectFileProjectModule._serializer = serializer;
|
|
2009
|
+
};
|
|
2010
|
+
ProjectFileProjectModule.prototype.getProjects = function() {
|
|
2011
|
+
return ProjectFileProjectModule._serializer.getProjects();
|
|
2012
|
+
};
|
|
2013
|
+
ProjectFileProjectModule.prototype.getProject = function(projectId) {
|
|
2014
|
+
return ProjectFileProjectModule._serializer.getProject(projectId);
|
|
2015
|
+
};
|
|
2016
|
+
ProjectFileProjectModule.prototype.saveProject = function(project) {
|
|
2017
|
+
return ProjectFileProjectModule._serializer.saveProject(project);
|
|
2018
|
+
};
|
|
2019
|
+
ProjectFileProjectModule.prototype.saveProjects = function(projects) {
|
|
2020
|
+
return ProjectFileProjectModule._serializer.saveProjects(projects);
|
|
2021
|
+
};
|
|
2022
|
+
ProjectFileProjectModule.prototype.removeProject = function(projectId) {
|
|
2023
|
+
return ProjectFileProjectModule._serializer.removeProject(projectId);
|
|
2024
|
+
};
|
|
2025
|
+
ProjectFileProjectModule.prototype.updateProject = function(project) {
|
|
2026
|
+
return ProjectFileProjectModule._serializer.updateProject(project);
|
|
2027
|
+
};
|
|
2028
|
+
return ProjectFileProjectModule;
|
|
2029
|
+
}();
|
|
2030
|
+
|
|
2031
|
+
var ProjectsService = function() {
|
|
2032
|
+
function ProjectsService() {}
|
|
2033
|
+
ProjectsService.on = function(moduleName) {
|
|
2034
|
+
var module = ProjectsService._modules.find((function(module) {
|
|
2035
|
+
return module.name === moduleName;
|
|
2036
|
+
}));
|
|
2037
|
+
if (!module) {
|
|
2038
|
+
throw new Error("Module ".concat(moduleName, " not found"));
|
|
2039
|
+
}
|
|
2040
|
+
return {
|
|
2041
|
+
getSerializerInstance: function(file) {
|
|
2042
|
+
return new ProjectsService._serializer(file);
|
|
2043
|
+
},
|
|
2044
|
+
instance: module.instance
|
|
2045
|
+
};
|
|
2046
|
+
};
|
|
2047
|
+
ProjectsService._addModule = function(name, module) {
|
|
2048
|
+
ProjectsService._modules.push({
|
|
2049
|
+
name,
|
|
2050
|
+
instance: module
|
|
2051
|
+
});
|
|
2052
|
+
};
|
|
2053
|
+
ProjectsService._modules = [];
|
|
2054
|
+
ProjectsService._serializer = ProjectFileSerializer;
|
|
2055
|
+
(function() {
|
|
2056
|
+
ProjectsService._addModule("LocalStorage", new LocalStorageProjectModule);
|
|
2057
|
+
ProjectsService._addModule("File", new ProjectFileProjectModule);
|
|
2058
|
+
})();
|
|
2059
|
+
return ProjectsService;
|
|
2060
|
+
}();
|
|
2061
|
+
|
|
2062
|
+
var Project = function() {
|
|
2063
|
+
function Project() {
|
|
2064
|
+
this.id = null;
|
|
2065
|
+
this.name = null;
|
|
2066
|
+
this.description = null;
|
|
2067
|
+
this.state = null;
|
|
2068
|
+
this.createdAt = new Date(Date.now()).toString();
|
|
2069
|
+
this.updatedAt = new Date(Date.now()).toString();
|
|
2070
|
+
}
|
|
2071
|
+
return Project;
|
|
2072
|
+
}();
|
|
2073
|
+
|
|
2074
|
+
var PullProjectService = function() {
|
|
2075
|
+
function PullProjectService() {}
|
|
2076
|
+
Object.defineProperty(PullProjectService, "project", {
|
|
2077
|
+
get: function() {
|
|
2078
|
+
return this._project;
|
|
2079
|
+
},
|
|
2080
|
+
enumerable: false,
|
|
2081
|
+
configurable: true
|
|
2082
|
+
});
|
|
2083
|
+
PullProjectService.refreshProject = function() {
|
|
2084
|
+
PullProjectService._project = new Project;
|
|
2085
|
+
};
|
|
2086
|
+
PullProjectService.updateProject = function(project) {
|
|
2087
|
+
Object.keys(project).forEach((function(key) {
|
|
2088
|
+
PullProjectService._project[key] = project[key];
|
|
2089
|
+
}));
|
|
2090
|
+
};
|
|
2091
|
+
PullProjectService.pull = function(name, description) {
|
|
2092
|
+
var project = new Project;
|
|
2093
|
+
var state = {
|
|
2094
|
+
cache: ThroughHistoryService.cache,
|
|
2095
|
+
history: AppStore.store.historyState.historyLines,
|
|
2096
|
+
current: AppStore.store.imageState.getEntry()
|
|
2097
|
+
};
|
|
2098
|
+
project.id = (new Guid4).generate();
|
|
2099
|
+
project.description = description || "New Project";
|
|
2100
|
+
project.name = name || "New Project";
|
|
2101
|
+
project.state = state;
|
|
2102
|
+
this._project = project;
|
|
2103
|
+
};
|
|
2104
|
+
PullProjectService._project = new Project;
|
|
2105
|
+
return PullProjectService;
|
|
2106
|
+
}();
|
|
2107
|
+
|
|
2108
|
+
var CanvasEditorEngine = function() {
|
|
2109
|
+
function CanvasEditorEngine(webComponentTagName) {
|
|
2110
|
+
AppConfig.WEB_COMPONENT_TAG_NAME = webComponentTagName;
|
|
2111
|
+
}
|
|
2112
|
+
CanvasEditorEngine.prototype.getInitial = function() {
|
|
2113
|
+
return {
|
|
2114
|
+
tag: AppConfig.WEB_COMPONENT_TAG_NAME,
|
|
2115
|
+
component: WebComponent
|
|
2116
|
+
};
|
|
2117
|
+
};
|
|
2118
|
+
return CanvasEditorEngine;
|
|
2119
|
+
}();
|
|
2120
|
+
|
|
2121
|
+
var StaticCanvasEditorEngine = function(_super) {
|
|
2122
|
+
__extends(StaticCanvasEditorEngine, _super);
|
|
2123
|
+
function StaticCanvasEditorEngine(webComponentTagName) {
|
|
2124
|
+
return _super.call(this, webComponentTagName) || this;
|
|
2125
|
+
}
|
|
2126
|
+
StaticCanvasEditorEngine.prototype.init = function() {
|
|
2127
|
+
var customElementRegistry = window.customElements;
|
|
2128
|
+
var _a = this.getInitial(), tag = _a.tag, component = _a.component;
|
|
2129
|
+
customElementRegistry.define(tag, component);
|
|
2130
|
+
};
|
|
2131
|
+
return StaticCanvasEditorEngine;
|
|
2132
|
+
}(CanvasEditorEngine);
|
|
2133
|
+
|
|
2134
|
+
var VueCanvasEditorEngine = function(_super) {
|
|
2135
|
+
__extends(VueCanvasEditorEngine, _super);
|
|
2136
|
+
function VueCanvasEditorEngine(webComponentTagName) {
|
|
2137
|
+
return _super.call(this, webComponentTagName) || this;
|
|
2138
|
+
}
|
|
2139
|
+
VueCanvasEditorEngine.prototype.getContext2D = function() {
|
|
2140
|
+
return CanvasComponent.ctx;
|
|
2141
|
+
};
|
|
2142
|
+
VueCanvasEditorEngine.prototype.getCanvas = function() {
|
|
2143
|
+
return CanvasComponent.canvas;
|
|
2144
|
+
};
|
|
2145
|
+
return VueCanvasEditorEngine;
|
|
2146
|
+
}(CanvasEditorEngine);
|
|
2147
|
+
|
|
2148
|
+
export { AppConfig, AppStore, CanvasComponent, CropService, DownloadService, DrawService, EventService, ExcretionsComponent as ExcretionComponent, LoadingComponent, LoggerService, PipetteComponent, ProjectsService, PullProjectService, SlotComponent, StaticCanvasEditorEngine, ThroughHistoryService, ToolLayerService, ToolService, VueCanvasEditorEngine };
|