canvas-editor-engine 2.0.20 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -44,6 +44,22 @@ typeof SuppressedError === "function" ? SuppressedError : function(error, suppre
44
44
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
45
45
  };
46
46
 
47
+ var reflect = function() {
48
+ if (window.Reflect === undefined || window.customElements === undefined || window.customElements.polyfillWrapFlushCallback) {
49
+ return;
50
+ }
51
+ var BuiltInHTMLElement = HTMLElement;
52
+ var wrapperForTheName = {
53
+ HTMLElement: function HTMLElement() {
54
+ return Reflect.construct(BuiltInHTMLElement, [], this.constructor);
55
+ }
56
+ };
57
+ window.HTMLElement = wrapperForTheName["HTMLElement"];
58
+ HTMLElement.prototype = BuiltInHTMLElement.prototype;
59
+ HTMLElement.prototype.constructor = HTMLElement;
60
+ Object.setPrototypeOf(HTMLElement, BuiltInHTMLElement);
61
+ };
62
+
47
63
  var ConfigFabric = function() {
48
64
  function ConfigFabric() {}
49
65
  return ConfigFabric;
@@ -52,27 +68,43 @@ var ConfigFabric = function() {
52
68
  var AppConfig = function(_super) {
53
69
  __extends(AppConfig, _super);
54
70
  function AppConfig() {
55
- return _super !== null && _super.apply(this, arguments) || this;
71
+ var _this = _super.call(this) || this;
72
+ _this._CANVAS_SIZE = {
73
+ width: 300,
74
+ height: 150
75
+ };
76
+ _this._WEB_COMPONENT_TAG_NAME = "canvas-editor-engine";
77
+ _this._LAYERS = [ {
78
+ name: "low",
79
+ index: 1
80
+ }, {
81
+ name: "normal",
82
+ index: 2
83
+ }, {
84
+ name: "high",
85
+ index: 3
86
+ } ];
87
+ return _this;
56
88
  }
57
- Object.defineProperty(AppConfig, "WEB_COMPONENT_TAG_NAME", {
89
+ Object.defineProperty(AppConfig.prototype, "WEB_COMPONENT_TAG_NAME", {
58
90
  get: function() {
59
- return AppConfig._WEB_COMPONENT_TAG_NAME;
91
+ return this._WEB_COMPONENT_TAG_NAME;
60
92
  },
61
93
  set: function(value) {
62
94
  if (!!value && typeof value === "string") {
63
- AppConfig._WEB_COMPONENT_TAG_NAME = value;
95
+ this._WEB_COMPONENT_TAG_NAME = value;
64
96
  }
65
97
  },
66
98
  enumerable: false,
67
99
  configurable: true
68
100
  });
69
- Object.defineProperty(AppConfig, "CANVAS_SIZE", {
101
+ Object.defineProperty(AppConfig.prototype, "CANVAS_SIZE", {
70
102
  get: function() {
71
- return AppConfig._CANVAS_SIZE;
103
+ return this._CANVAS_SIZE;
72
104
  },
73
105
  set: function(value) {
74
106
  if (!!value && !!(value === null || value === void 0 ? void 0 : value.width) && !!(value === null || value === void 0 ? void 0 : value.height)) {
75
- AppConfig._CANVAS_SIZE = value;
107
+ this._CANVAS_SIZE = value;
76
108
  } else {
77
109
  console.warn("CANVAS_SIZE denied");
78
110
  }
@@ -80,13 +112,13 @@ var AppConfig = function(_super) {
80
112
  enumerable: false,
81
113
  configurable: true
82
114
  });
83
- Object.defineProperty(AppConfig, "LAYERS", {
115
+ Object.defineProperty(AppConfig.prototype, "LAYERS", {
84
116
  get: function() {
85
- return AppConfig._LAYERS;
117
+ return this._LAYERS;
86
118
  },
87
119
  set: function(value) {
88
120
  if (!!value && !!(value === null || value === void 0 ? void 0 : value.length)) {
89
- AppConfig._LAYERS = value;
121
+ this._LAYERS = value;
90
122
  }
91
123
  },
92
124
  enumerable: false,
@@ -95,27 +127,11 @@ var AppConfig = function(_super) {
95
127
  return AppConfig;
96
128
  }(ConfigFabric);
97
129
 
98
- (function() {
99
- AppConfig._CANVAS_SIZE = {
100
- width: 300,
101
- height: 150
102
- };
103
- AppConfig._WEB_COMPONENT_TAG_NAME = "canvas-editor-engine";
104
- AppConfig._LAYERS = [ {
105
- name: "low",
106
- index: 1
107
- }, {
108
- name: "normal",
109
- index: 2
110
- }, {
111
- name: "high",
112
- index: 3
113
- } ];
114
- })();
130
+ reflect();
115
131
 
116
132
  var ComponentService = function() {
117
133
  function ComponentService() {}
118
- ComponentService.getTemplate = function(template, wrapOptions) {
134
+ ComponentService.prototype.getTemplate = function(template, wrapOptions) {
119
135
  var options = {
120
136
  tag: "div"
121
137
  };
@@ -139,7 +155,7 @@ var ComponentService = function() {
139
155
  }
140
156
  return wrap;
141
157
  };
142
- ComponentService.getStyle = function(css) {
158
+ ComponentService.prototype.getStyle = function(css) {
143
159
  if (!!css === false) return null;
144
160
  var style = document.createElement("style");
145
161
  style.type = "text/css";
@@ -149,112 +165,69 @@ var ComponentService = function() {
149
165
  return ComponentService;
150
166
  }();
151
167
 
152
- var LoggerService = function() {
153
- function LoggerService() {}
154
- Object.defineProperty(LoggerService, "components", {
155
- get: function() {
156
- return LoggerService.getMethods("components");
157
- },
158
- enumerable: false,
159
- configurable: true
160
- });
161
- Object.defineProperty(LoggerService, "services", {
162
- get: function() {
163
- return LoggerService.getMethods("services");
164
- },
165
- enumerable: false,
166
- configurable: true
167
- });
168
- Object.defineProperty(LoggerService, "planed", {
169
- get: function() {
170
- return LoggerService.getMethods("planed");
171
- },
172
- enumerable: false,
173
- configurable: true
174
- });
175
- LoggerService.getMethods = function(fields) {
176
- return {
177
- add: function(logItem) {
178
- LoggerService._add(fields, logItem);
179
- },
180
- get: function() {
181
- var args = [];
182
- for (var _i = 0; _i < arguments.length; _i++) {
183
- args[_i] = arguments[_i];
184
- }
185
- LoggerService._get.apply(LoggerService, args);
186
- }
187
- };
188
- };
189
- LoggerService._add = function(field, logItem) {
190
- LoggerService.log[field].push(logItem);
191
- };
192
- LoggerService._get = function(field, name) {
193
- return LoggerService.log[field].find((function(logItem) {
194
- return logItem.info.name === name;
195
- }));
196
- };
197
- LoggerService.log = {
198
- components: [],
199
- services: [],
200
- planed: []
201
- };
202
- return LoggerService;
203
- }();
204
-
205
- var ToolLayerService = function() {
206
- function ToolLayerService() {}
207
- ToolLayerService.getLayerIndex = function(layerName) {
208
- var layer = AppConfig.LAYERS.find((function(layer) {
209
- return layer.name === layerName;
210
- }));
211
- var zIndex = ToolLayerService.multiplier * layer.index;
212
- return zIndex;
213
- };
214
- ToolLayerService.multiplier = 1e3;
215
- return ToolLayerService;
216
- }();
217
-
218
168
  var CanvasComponent = function(_super) {
219
169
  __extends(CanvasComponent, _super);
220
- function CanvasComponent() {
221
- return _super !== null && _super.apply(this, arguments) || this;
170
+ function CanvasComponent(appConfig, loggerService, toolLayerService) {
171
+ var _this = _super.call(this) || this;
172
+ _this.appConfig = appConfig;
173
+ _this.loggerService = loggerService;
174
+ _this.toolLayerService = toolLayerService;
175
+ _this.template = '\n <div id="event-listener"></div>\n <canvas id="sc-canvas"></canvas>\n ';
176
+ _this.css = "\n #event-listener {\n position: absolute;\n z-index: ".concat(_this.toolLayerService.getLayerIndex("normal"), ";\n }\n ");
177
+ _this.subscriptions = {
178
+ click: [],
179
+ mousemove: [],
180
+ mousedown: [],
181
+ mouseup: []
182
+ };
183
+ _this._cursorStyle = {
184
+ before: null,
185
+ current: "default"
186
+ };
187
+ _this.loggerService.components.add({
188
+ info: {
189
+ name: "canvas",
190
+ description: "canvas component"
191
+ },
192
+ prototype: _this
193
+ });
194
+ return _this;
222
195
  }
223
- CanvasComponent.getComponent = function() {
224
- var canvasTemplate = CanvasComponent.getTemplate(CanvasComponent.template);
225
- var canvasStyle = CanvasComponent.getStyle(CanvasComponent.css);
226
- CanvasComponent.canvas = canvasTemplate.getElementsByTagName("canvas")[0];
227
- CanvasComponent.canvas.width = AppConfig.CANVAS_SIZE.width;
228
- CanvasComponent.canvas.height = AppConfig.CANVAS_SIZE.height;
229
- CanvasComponent.ctx = CanvasComponent.canvas.getContext("2d", {
196
+ CanvasComponent.prototype.getComponent = function() {
197
+ var canvasTemplate = this.getTemplate(this.template);
198
+ var canvasStyle = this.getStyle(this.css);
199
+ this.canvas = canvasTemplate.getElementsByTagName("canvas")[0];
200
+ this.canvas.width = this.appConfig.CANVAS_SIZE.width;
201
+ this.canvas.height = this.appConfig.CANVAS_SIZE.height;
202
+ this.ctx = this.canvas.getContext("2d", {
230
203
  willReadFrequently: true
231
204
  });
232
- CanvasComponent.eventListener = canvasTemplate.querySelector("#event-listener");
233
- CanvasComponent.eventListener.style.width = AppConfig.CANVAS_SIZE.width + "px";
234
- CanvasComponent.eventListener.style.height = AppConfig.CANVAS_SIZE.height + "px";
205
+ this.eventListener = canvasTemplate.querySelector("#event-listener");
206
+ this.eventListener.style.width = this.appConfig.CANVAS_SIZE.width + "px";
207
+ this.eventListener.style.height = this.appConfig.CANVAS_SIZE.height + "px";
235
208
  return {
236
209
  canvasTemplate,
237
210
  canvasStyle
238
211
  };
239
212
  };
240
- CanvasComponent.getCanvasSelector = function() {
213
+ CanvasComponent.prototype.getCanvasSelector = function() {
241
214
  return "#sc-canvas";
242
215
  };
243
- Object.defineProperty(CanvasComponent, "cursorStyle", {
216
+ Object.defineProperty(CanvasComponent.prototype, "cursorStyle", {
244
217
  set: function(styleName) {
245
218
  if (!!styleName) {
246
- CanvasComponent._cursorStyle.before = CanvasComponent._cursorStyle.current;
247
- CanvasComponent._cursorStyle.current = styleName;
248
- CanvasComponent.eventListener.style.cursor = styleName;
219
+ this._cursorStyle.before = this._cursorStyle.current;
220
+ this._cursorStyle.current = styleName;
221
+ this.eventListener.style.cursor = styleName;
249
222
  } else {
250
- CanvasComponent.eventListener.style.cursor = "default";
223
+ this.eventListener.style.cursor = "default";
251
224
  }
252
225
  },
253
226
  enumerable: false,
254
227
  configurable: true
255
228
  });
256
- CanvasComponent.getCursorPosition = function(event) {
257
- var rect = CanvasComponent.canvas.getBoundingClientRect();
229
+ CanvasComponent.prototype.getCursorPosition = function(event) {
230
+ var rect = this.canvas.getBoundingClientRect();
258
231
  var x = event.clientX - rect.left;
259
232
  var y = event.clientY - rect.top;
260
233
  return {
@@ -262,16 +235,17 @@ var CanvasComponent = function(_super) {
262
235
  y
263
236
  };
264
237
  };
265
- CanvasComponent.subscribe = function(eventName, action) {
266
- CanvasComponent.subscriptions[eventName].push(action);
238
+ CanvasComponent.prototype.subscribe = function(eventName, action) {
239
+ this.subscriptions[eventName].push(action);
267
240
  };
268
- CanvasComponent.simulateSubscriptions = function() {
269
- var eventNames = Object.keys(CanvasComponent.subscriptions);
241
+ CanvasComponent.prototype.simulateSubscriptions = function() {
242
+ var _this = this;
243
+ var eventNames = Object.keys(this.subscriptions);
270
244
  eventNames.forEach((function(eventName) {
271
- var actionsList = CanvasComponent.subscriptions[eventName];
245
+ var actionsList = _this.subscriptions[eventName];
272
246
  if (!!actionsList.length) {
273
- CanvasComponent.eventListener.addEventListener(eventName, (function(event) {
274
- var cursorPosition = CanvasComponent.getCursorPosition(event);
247
+ _this.eventListener.addEventListener(eventName, (function(event) {
248
+ var cursorPosition = _this.getCursorPosition(event);
275
249
  actionsList.forEach((function(action) {
276
250
  action(event, cursorPosition);
277
251
  }));
@@ -279,162 +253,813 @@ var CanvasComponent = function(_super) {
279
253
  }
280
254
  }));
281
255
  };
282
- CanvasComponent.template = '\n <div id="event-listener"></div>\n <canvas id="sc-canvas"></canvas>\n ';
283
- CanvasComponent.css = "\n #event-listener {\n position: absolute;\n z-index: ".concat(ToolLayerService.getLayerIndex("normal"), ";\n }\n ");
284
- CanvasComponent.subscriptions = {
285
- click: [],
286
- mousemove: [],
287
- mousedown: [],
288
- mouseup: []
289
- };
290
- CanvasComponent._cursorStyle = {
291
- before: null,
292
- current: "default"
293
- };
294
- (function() {
295
- LoggerService.components.add({
256
+ return CanvasComponent;
257
+ }(ComponentService);
258
+
259
+ reflect();
260
+
261
+ var ExcretionsComponent = function(_super) {
262
+ __extends(ExcretionsComponent, _super);
263
+ function ExcretionsComponent(toolService, loggerService, toolLayerService, canvasComponent) {
264
+ var _this = _super.call(this) || this;
265
+ _this.toolService = toolService;
266
+ _this.loggerService = loggerService;
267
+ _this.toolLayerService = toolLayerService;
268
+ _this.canvasComponent = canvasComponent;
269
+ _this.template = "";
270
+ _this.templateExcretion = '\n <button type="button" class="crop-button">\n <svg fill="#ffffff" viewBox="0 0 1920 1920" xmlns="http://www.w3.org/2000/svg" stroke="#ffffff"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <path fill-rule="evenodd" clip-rule="evenodd" d="M426.667 0h106.666v1386.67H1920v106.66H426.667V0zM320 426.667H0v106.666h320V426.667zm320 0v106.666h746.67V1280h106.66V426.667H640zM1493.33 1600h-106.66v320h106.66v-320z"></path> </g></svg>\n </button>\n ';
271
+ _this._excretionDefaultStyle = [ "excretion" ];
272
+ _this.css = "\n .excretion {\n display: flex;\n position: absolute;\n background-image: linear-gradient(90deg, silver 50%, transparent 50%), linear-gradient(90deg, silver 50%, transparent 50%), linear-gradient(0deg, silver 50%, transparent 50%), linear-gradient(0deg, silver 50%, transparent 50%);\n background-repeat: repeat-x, repeat-x, repeat-y, repeat-y;\n background-size: 8px 1px, 8px 1px, 1px 8px, 1px 8px;\n background-position: left top, right bottom, left bottom, right top;\n animation: border-dance 1s infinite linear;\n z-index: ".concat(_this.toolLayerService.getLayerIndex("low"), ";\n }\n\n .excretion_crop {\n box-shadow: 0px 0px 0px calc(100vw + 100vh) #50505070;\n }\n\n .crop-button {\n display: none;\n justify-content: center;\n align-items: center;\n position: absolute;\n padding: 5px;\n right: -35px;\n top: 0;\n background: #232222;\n border: 1px solid #ffffff50;\n border-radius: 4px;\n width: 30px;\n height: 30px;\n cursor: pointer;\n z-index: ").concat(_this.toolLayerService.getLayerIndex("high"), ";\n }\n\n .crop-button--view {\n display: flex;\n }\n\n @keyframes border-dance {\n 0% {\n background-position: left top, right bottom, left bottom, right top;\n }\n 100% {\n background-position: left 8px top, right 8px bottom, left bottom 8px, right top 8px;\n }\n }\n ");
273
+ _this._excretions = [];
274
+ _this._excretionState = "abandoned";
275
+ _this._excretionActivity = "abandoned";
276
+ _this._excretionToolState = "abandoned";
277
+ _this._tempCoords = [];
278
+ _this.excretionsCoords = [];
279
+ _this._additionStyle = "default";
280
+ _this.tool = {
281
+ id: 1,
282
+ name: "excretion",
283
+ onAction: function() {
284
+ return _this.setToolState("taken");
285
+ },
286
+ offAction: function() {
287
+ return _this.setToolState("abandoned");
288
+ },
289
+ support: function() {
290
+ _this.clearExcretionsCoords();
291
+ _this.additionStyle = "default";
292
+ }
293
+ };
294
+ _this.toolService.add(_this.tool);
295
+ _this.loggerService.components.add({
296
296
  info: {
297
- name: "canvas",
298
- description: "canvas component"
297
+ name: "excretion",
298
+ description: "excretion component"
299
299
  },
300
- prototype: CanvasComponent
300
+ prototype: _this
301
301
  });
302
- })();
303
- return CanvasComponent;
304
- }(ComponentService);
302
+ return _this;
303
+ }
304
+ Object.defineProperty(ExcretionsComponent.prototype, "additionStyle", {
305
+ get: function() {
306
+ return this._additionStyle;
307
+ },
308
+ set: function(value) {
309
+ this._additionStyle = value;
310
+ this.applyExcretionStyle();
311
+ },
312
+ enumerable: false,
313
+ configurable: true
314
+ });
315
+ ExcretionsComponent.prototype.applyExcretionStyle = function() {
316
+ switch (this._additionStyle) {
317
+ case "crop":
318
+ this.determineCropStyle();
319
+ break;
305
320
 
306
- var ToolService = function() {
307
- function ToolService() {}
308
- ToolService.add = function(tool) {
309
- var hasRegisteredTool = ToolService.registry.find((function(registeredTool) {
310
- return registeredTool.id === tool.id;
311
- }));
312
- if (hasRegisteredTool) {
313
- console.warn("Tool has been previously registered!");
314
- return false;
321
+ case "default":
322
+ this.determineDefaultStyle();
323
+ break;
324
+
325
+ default:
326
+ this.determineDefaultStyle();
327
+ break;
315
328
  }
316
- ToolService.registry.push(tool);
317
- return true;
318
329
  };
319
- ToolService.setActive = function(id) {
320
- var _a, _b, _c;
321
- if (((_a = ToolService.active) === null || _a === void 0 ? void 0 : _a.id) === id) return console.warn("Tool is already active");
322
- if (!!((_b = ToolService.active) === null || _b === void 0 ? void 0 : _b.offAction)) {
323
- ToolService.active.offAction();
324
- }
325
- var registeredTool = ToolService.registry.find((function(registeredTool) {
326
- return registeredTool.id === id;
327
- }));
328
- if (!!registeredTool) {
329
- ToolService.active = registeredTool;
330
- if (!!((_c = ToolService.active) === null || _c === void 0 ? void 0 : _c.onAction)) {
331
- ToolService.active.onAction();
330
+ ExcretionsComponent.prototype.determineCropStyle = function() {
331
+ this._excretions.forEach((function(excretion) {
332
+ if (!!excretion === false) return;
333
+ if (!excretion.classList.contains("excretion_crop")) {
334
+ excretion.classList.add("excretion_crop");
332
335
  }
333
- } else {
334
- console.warn("Tool has not previously been registered with this identifier");
335
- }
336
+ }));
336
337
  };
337
- ToolService.offActive = function(id) {
338
- if (!!id) {
339
- if (ToolService.active.id === id) {
340
- ToolService.off();
341
- } else {
342
- return console.warn('ID active tool is not "'.concat(id, '"'));
343
- }
344
- } else {
345
- ToolService.off();
346
- }
338
+ ExcretionsComponent.prototype.determineDefaultStyle = function() {
339
+ var _this = this;
340
+ this._excretions.forEach((function(excretion) {
341
+ if (!!excretion === false) return;
342
+ excretion.classList = _this._excretionDefaultStyle;
343
+ }));
347
344
  };
348
- ToolService.off = function() {
349
- var _a;
350
- if (!!((_a = ToolService.active) === null || _a === void 0 ? void 0 : _a.offAction)) {
351
- ToolService.active.offAction();
352
- }
353
- ToolService.before = ToolService.active;
354
- ToolService.active = null;
355
- CanvasComponent.cursorStyle = "default";
345
+ ExcretionsComponent.prototype.getComponent = function() {
346
+ var wrapOptions = {
347
+ className: "excretions-wrap"
348
+ };
349
+ var excretionsTemplate = this.getTemplate(this.template, wrapOptions);
350
+ var excretionsStyle = this.getStyle(this.css);
351
+ this.excretionWrap = excretionsTemplate;
352
+ this.emmit();
353
+ return {
354
+ excretionsTemplate,
355
+ excretionsStyle
356
+ };
356
357
  };
357
- ToolService.before = null;
358
- ToolService.active = null;
359
- ToolService.registry = [];
360
- return ToolService;
361
- }();
358
+ Object.defineProperty(ExcretionsComponent.prototype, "excretionState", {
359
+ set: function(state) {
360
+ this._excretionState = state;
361
+ this.applyExcretionStyle();
362
+ switch (state) {
363
+ case "abandoned":
364
+ this.canvasComponent.cursorStyle = "default";
365
+ break;
362
366
 
363
- var Convert = function() {
364
- function Convert() {}
365
- Convert.byteRGBToHEX = function(color) {
366
- var red = color[0];
367
- var green = color[1];
368
- var blue = color[2];
369
- return Convert.rgbToHex(red, green, blue);
370
- };
371
- Convert.rgbToHex = function(r, g, b) {
372
- return "#".concat(Convert.componentToHEX(r)).concat(Convert.componentToHEX(g)).concat(Convert.componentToHEX(b));
373
- };
374
- Convert.hexToRgb = function(hex) {
375
- var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
376
- return result ? {
377
- r: parseInt(result[1], 16),
378
- g: parseInt(result[2], 16),
379
- b: parseInt(result[3], 16)
380
- } : null;
381
- };
382
- Convert.componentToHEX = function(colorComponent) {
383
- var hex = colorComponent.toString(16);
384
- return hex.length == 1 ? "0" + hex : hex;
385
- };
386
- return Convert;
387
- }();
367
+ case "create":
368
+ this.canvasComponent.cursorStyle = "crosshair";
369
+ break;
388
370
 
389
- var range = function(start, end) {
390
- var result = [];
391
- for (var i = start; i < end; i++) {
392
- result.push(i);
393
- }
394
- return result;
395
- };
371
+ case "add":
372
+ this.canvasComponent.cursorStyle = "copy";
373
+ break;
396
374
 
397
- var Filter = function() {
398
- function Filter(ctx) {
399
- this.ctx = ctx;
400
- }
401
- Filter.prototype.setImageSize = function(size) {
402
- this.imageSize = size;
375
+ case "remove":
376
+ this.canvasComponent.cursorStyle = "alias";
377
+ break;
378
+
379
+ default:
380
+ this.canvasComponent.cursorStyle = "default";
381
+ break;
382
+ }
383
+ },
384
+ enumerable: false,
385
+ configurable: true
386
+ });
387
+ ExcretionsComponent.prototype.setToolState = function(toolState) {
388
+ this._excretionToolState = toolState;
389
+ switch (toolState) {
390
+ case "abandoned":
391
+ this.excretionState = "abandoned";
392
+ this._excretionActivity = "abandoned";
393
+ break;
394
+
395
+ case "taken":
396
+ this.excretionState = "create";
397
+ break;
398
+
399
+ default:
400
+ this.excretionState = "abandoned";
401
+ this._excretionActivity = "abandoned";
402
+ break;
403
+ }
403
404
  };
404
- Filter.prototype.copy = 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
- return imgData;
405
+ ExcretionsComponent.prototype.clearExcretionsCoords = function() {
406
+ console.log("clear!");
407
+ this._excretions.forEach((function(excretion) {
408
+ return excretion.remove();
409
+ }));
410
+ this._excretions = [];
411
+ this.excretionsCoords = [];
409
412
  };
410
- Filter.prototype.copyExtendedModel = function(options) {
411
- var width = (options === null || options === void 0 ? void 0 : options.width) ? options.width : AppConfig.CANVAS_SIZE.width;
412
- var height = (options === null || options === void 0 ? void 0 : options.height) ? options.height : AppConfig.CANVAS_SIZE.height;
413
- var imgData = this.ctx.getImageData(options.x, options.y, width, height);
414
- var extendedImageData = this.clearEmptyPixels(imgData);
415
- return extendedImageData;
413
+ ExcretionsComponent.prototype.getTempCoords = function() {
414
+ var startCoords = this._tempCoords[0];
415
+ var endCoords = this._tempCoords[1];
416
+ var coords = Object.assign(startCoords, endCoords);
417
+ this._tempCoords = [];
418
+ return coords;
416
419
  };
417
- Filter.prototype.update = function(imgData, options) {
418
- this.ctx.clearRect(0, 0, AppConfig.CANVAS_SIZE.width, AppConfig.CANVAS_SIZE.height);
419
- this.ctx.putImageData(imgData, options.x, options.y);
420
+ ExcretionsComponent.prototype.endExcretion = function() {
421
+ var coords = this.getTempCoords();
422
+ this.excretionsCoords.push(coords);
423
+ this._excretionActivity = "end";
424
+ console.log("this.excretionsCoords", this.excretionsCoords);
420
425
  };
421
- Filter.prototype.clearEmptyPixels = function(imageData) {
422
- var rowRGBABuff = this.getRowRGBABuff(imageData);
423
- var RGBAMatrix = this.getRGBAMatrix(rowRGBABuff, {
424
- width: imageData.width,
425
- height: imageData.height
426
- });
427
- var beforeSize = {
428
- width: imageData.width,
429
- height: imageData.height
430
- };
431
- var tempSize = this.getSizeOfSparseMatrix(RGBAMatrix, beforeSize);
432
- var cleared = rowRGBABuff.filter((function(byteArray) {
433
- var alpha = byteArray[3];
434
- return !!alpha;
426
+ ExcretionsComponent.prototype.emmit = function() {
427
+ var _this = this;
428
+ this.canvasComponent.subscribe("mousedown", (function(event, cursorPosition) {
429
+ var toolState = _this._excretionToolState;
430
+ if (toolState === "abandoned") return;
431
+ var state = _this._excretionState;
432
+ if (state === "create") {
433
+ var wrapOptions = {
434
+ className: _this._excretionDefaultStyle[0]
435
+ };
436
+ var excretionTemplate = _this.getTemplate(_this.templateExcretion, wrapOptions);
437
+ _this.clearExcretionsCoords();
438
+ var tempStart = {
439
+ start: cursorPosition
440
+ };
441
+ excretionTemplate.style.left = "".concat(tempStart.start.x, "px");
442
+ excretionTemplate.style.top = "".concat(tempStart.start.y, "px");
443
+ var excretionElement = _this.excretionWrap.appendChild(excretionTemplate);
444
+ _this._excretions.push(excretionElement);
445
+ _this._tempCoords.push(tempStart);
446
+ }
447
+ if (state === "add") {
448
+ var tempStart = {
449
+ start: cursorPosition
450
+ };
451
+ _this._tempCoords.push(tempStart);
452
+ }
453
+ _this.applyExcretionStyle();
454
+ _this._excretionActivity = "active";
435
455
  }));
436
- var clearedBuff = cleared.flat();
437
- var tempCanvas = document.createElement("canvas");
456
+ this.canvasComponent.subscribe("mousemove", (function(event, cursorPosition) {
457
+ var toolState = _this._excretionToolState;
458
+ if (toolState === "abandoned") return;
459
+ var activity = _this._excretionActivity;
460
+ if (event.altKey && _this._excretionState !== "abandoned") {
461
+ _this._excretionState = "add";
462
+ }
463
+ if (activity === "abandoned") return;
464
+ if (activity === "active") {
465
+ var excretionLastIndex = _this._excretions.length - 1;
466
+ var excretion = _this._excretions[excretionLastIndex];
467
+ var excretionX = +excretion.style.left.split("px")[0];
468
+ var excretionY = +excretion.style.top.split("px")[0];
469
+ var width = Math.abs(cursorPosition.x - excretionX);
470
+ var height = Math.abs(cursorPosition.y - excretionY);
471
+ excretion.style.width = width + "px";
472
+ excretion.style.height = height + "px";
473
+ var isRightBottom = cursorPosition.x > excretionX && cursorPosition.y > excretionY;
474
+ var isLeftBottom = cursorPosition.x < excretionX && cursorPosition.y > excretionY;
475
+ var isLeftTop = cursorPosition.x < excretionX && cursorPosition.y < excretionY;
476
+ var isRightTop = cursorPosition.x > excretionX && cursorPosition.y < excretionY;
477
+ if (isRightBottom) {
478
+ excretion.style.transform = "translateX(0px) translateY(0px)";
479
+ } else if (isLeftBottom) {
480
+ excretion.style.transform = "translateX(-".concat(width, "px) translateY(0px)");
481
+ } else if (isLeftTop) {
482
+ excretion.style.transform = "translateX(-".concat(width, "px) translateY(-").concat(height, "px)");
483
+ } else if (isRightTop) {
484
+ excretion.style.transform = "translateX(0px) translateY(-".concat(height, "px)");
485
+ }
486
+ }
487
+ }));
488
+ this.canvasComponent.subscribe("mouseup", (function(event, cursorPosition) {
489
+ var toolState = _this._excretionToolState;
490
+ if (toolState === "abandoned") return;
491
+ var state = _this._excretionState;
492
+ if (state === "abandoned") return;
493
+ if (state === "create" || state === "add") {
494
+ var tempEnd = {
495
+ end: cursorPosition
496
+ };
497
+ _this._tempCoords.push(tempEnd);
498
+ _this.endExcretion();
499
+ }
500
+ }));
501
+ };
502
+ return ExcretionsComponent;
503
+ }(ComponentService);
504
+
505
+ reflect();
506
+
507
+ var LoadingComponent = function(_super) {
508
+ __extends(LoadingComponent, _super);
509
+ function LoadingComponent(loggerService, eventService) {
510
+ var _this = _super.call(this) || this;
511
+ _this.loggerService = loggerService;
512
+ _this.eventService = eventService;
513
+ _this.template = '\n <span class="loader"></span>\n ';
514
+ _this.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 ';
515
+ _this.loggerService.components.add({
516
+ info: {
517
+ name: "loading",
518
+ description: "loading component"
519
+ },
520
+ prototype: _this
521
+ });
522
+ return _this;
523
+ }
524
+ LoadingComponent.prototype.getComponent = function() {
525
+ var wrapOptions = {
526
+ className: "loading-wrapper"
527
+ };
528
+ var loadingTemplate = this.getTemplate(this.template, wrapOptions);
529
+ var loadingStyle = this.getStyle(this.css);
530
+ this.loading = loadingTemplate;
531
+ this.subscribeLoadingStart();
532
+ this.subscribeLoadingEnd();
533
+ return {
534
+ loadingTemplate,
535
+ loadingStyle
536
+ };
537
+ };
538
+ LoadingComponent.prototype.hide = function() {
539
+ this.loading.style.display = "none";
540
+ };
541
+ LoadingComponent.prototype.view = function() {
542
+ this.loading.style.display = "flex";
543
+ };
544
+ LoadingComponent.prototype.subscribeLoadingStart = function() {
545
+ var _this = this;
546
+ var controlEvent = {
547
+ name: "loading-start",
548
+ action: function() {
549
+ return _this.view();
550
+ }
551
+ };
552
+ this.eventService.subcribe(controlEvent);
553
+ };
554
+ LoadingComponent.prototype.subscribeLoadingEnd = function() {
555
+ var _this = this;
556
+ var controlEvent = {
557
+ name: "loading-end",
558
+ action: function() {
559
+ return _this.hide();
560
+ }
561
+ };
562
+ this.eventService.subcribe(controlEvent);
563
+ };
564
+ return LoadingComponent;
565
+ }(ComponentService);
566
+
567
+ var Convert = function() {
568
+ function Convert() {}
569
+ Convert.byteRGBToHEX = function(color) {
570
+ var red = color[0];
571
+ var green = color[1];
572
+ var blue = color[2];
573
+ return Convert.rgbToHex(red, green, blue);
574
+ };
575
+ Convert.rgbToHex = function(r, g, b) {
576
+ return "#".concat(Convert.componentToHEX(r)).concat(Convert.componentToHEX(g)).concat(Convert.componentToHEX(b));
577
+ };
578
+ Convert.hexToRgb = function(hex) {
579
+ var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
580
+ return result ? {
581
+ r: parseInt(result[1], 16),
582
+ g: parseInt(result[2], 16),
583
+ b: parseInt(result[3], 16)
584
+ } : null;
585
+ };
586
+ Convert.componentToHEX = function(colorComponent) {
587
+ var hex = colorComponent.toString(16);
588
+ return hex.length == 1 ? "0" + hex : hex;
589
+ };
590
+ return Convert;
591
+ }();
592
+
593
+ reflect();
594
+
595
+ var PipetteComponent = function(_super) {
596
+ __extends(PipetteComponent, _super);
597
+ function PipetteComponent(toolService, loggerService, canvasComponent) {
598
+ var _this = _super.call(this) || this;
599
+ _this.toolService = toolService;
600
+ _this.loggerService = loggerService;
601
+ _this.canvasComponent = canvasComponent;
602
+ _this.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 ';
603
+ _this.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 ";
604
+ _this._pipetteState = "abandoned";
605
+ _this.tool = {
606
+ id: 0,
607
+ name: "pipette",
608
+ onAction: function() {
609
+ return _this.setState("taken");
610
+ },
611
+ offAction: function() {
612
+ return _this.setState("abandoned");
613
+ }
614
+ };
615
+ _this.toolService.add(_this.tool);
616
+ _this.loggerService.components.add({
617
+ info: {
618
+ name: "pipette",
619
+ description: "pipette component"
620
+ },
621
+ prototype: _this
622
+ });
623
+ return _this;
624
+ }
625
+ Object.defineProperty(PipetteComponent.prototype, "pipetteColor", {
626
+ get: function() {
627
+ return this._pipetteColor;
628
+ },
629
+ set: function(color) {
630
+ this._pipetteColor = color;
631
+ this._pipetteColorElement.style.borderColor = this._pipetteColor;
632
+ },
633
+ enumerable: false,
634
+ configurable: true
635
+ });
636
+ PipetteComponent.prototype.getComponent = function() {
637
+ var wrapOptions = {
638
+ className: "pipette"
639
+ };
640
+ var pipetteTemplate = this.getTemplate(this.template, wrapOptions);
641
+ var pipetteStyle = this.getStyle(this.css);
642
+ this.pipette = pipetteTemplate;
643
+ this._pipetteColorElement = pipetteTemplate.querySelector(".pipette_color");
644
+ this.emmit();
645
+ return {
646
+ pipetteTemplate,
647
+ pipetteStyle
648
+ };
649
+ };
650
+ PipetteComponent.prototype.setState = function(state) {
651
+ this._pipetteState = state;
652
+ switch (state) {
653
+ case "abandoned":
654
+ return this.hide();
655
+
656
+ case "taken":
657
+ return this.show();
658
+
659
+ case "selected-color":
660
+ return this.show();
661
+
662
+ default:
663
+ return this.hide();
664
+ }
665
+ };
666
+ PipetteComponent.prototype.emmit = function() {
667
+ var _this = this;
668
+ this.canvasComponent.subscribe("mousemove", (function(event, cursorPosition) {
669
+ var state = _this._pipetteState;
670
+ if (state === "taken" || state === "selected-color") {
671
+ var x = cursorPosition.x, y = cursorPosition.y;
672
+ _this.pipette.style.left = "".concat(x + 10, "px");
673
+ _this.pipette.style.top = "".concat(y + 10, "px");
674
+ }
675
+ }));
676
+ this.canvasComponent.subscribe("click", (function(event, cursorPosition) {
677
+ var state = _this._pipetteState;
678
+ if (state === "taken" || state === "selected-color") {
679
+ console.log("pipetteState", state);
680
+ if (state === "taken") {
681
+ _this.setColorFromChoosenPixel(cursorPosition);
682
+ _this.setState("selected-color");
683
+ }
684
+ if (state === "selected-color") {
685
+ _this.setColorFromChoosenPixel(cursorPosition);
686
+ }
687
+ }
688
+ }));
689
+ };
690
+ PipetteComponent.prototype.setColorFromChoosenPixel = function(cursorPosition) {
691
+ var x = cursorPosition.x, y = cursorPosition.y;
692
+ var pixel = this.canvasComponent.ctx.getImageData(x, y, 1, 1).data;
693
+ var hexPixel = Convert.rgbToHex(pixel[0], pixel[1], pixel[2]);
694
+ this.pipetteColor = hexPixel;
695
+ };
696
+ PipetteComponent.prototype.show = function() {
697
+ this.pipette.style.display = "flex";
698
+ this.canvasComponent.cursorStyle = "default";
699
+ };
700
+ PipetteComponent.prototype.hide = function() {
701
+ this.pipette.style.display = "none";
702
+ this.canvasComponent.cursorStyle = "default";
703
+ };
704
+ return PipetteComponent;
705
+ }(ComponentService);
706
+
707
+ var SlotComponent = function(_super) {
708
+ __extends(SlotComponent, _super);
709
+ function SlotComponent(loggerService) {
710
+ var _this = _super.call(this) || this;
711
+ _this.loggerService = loggerService;
712
+ _this.template = '\n <slot class="slot"></slot>\n ';
713
+ _this.css = "";
714
+ _this.loggerService.components.add({
715
+ info: {
716
+ name: "slot",
717
+ description: "slot component"
718
+ },
719
+ prototype: _this
720
+ });
721
+ return _this;
722
+ }
723
+ SlotComponent.prototype.getComponent = function(slotName) {
724
+ var wrapOptions = {
725
+ className: "slot-wrapper"
726
+ };
727
+ var slotTemplate = this.getTemplate(this.template, wrapOptions);
728
+ var slotStyle = this.getStyle(this.css);
729
+ this.slot = slotTemplate.querySelector("slot");
730
+ this.slot.name = slotName;
731
+ return {
732
+ slotTemplate,
733
+ slotStyle
734
+ };
735
+ };
736
+ return SlotComponent;
737
+ }(ComponentService);
738
+
739
+ var Guid4 = function() {
740
+ function Guid4() {
741
+ this.stack = [];
742
+ }
743
+ Guid4.prototype.generate = function() {
744
+ return this.Guid4;
745
+ };
746
+ Object.defineProperty(Guid4.prototype, "finite", {
747
+ get: function() {
748
+ var _a;
749
+ var guid4 = this.stack[(_a = this.stack) === null || _a === void 0 ? void 0 : _a.length];
750
+ if (!!guid4) {
751
+ return guid4;
752
+ } else {
753
+ throw new Error("Guid4 not generate");
754
+ }
755
+ },
756
+ enumerable: false,
757
+ configurable: true
758
+ });
759
+ Guid4.prototype.generateWithFactor = function(attempt) {
760
+ var factor = this.getFactor(this.guid4);
761
+ attempt.use("withError").run(factor);
762
+ };
763
+ Guid4.prototype.getFactor = function(guid4) {
764
+ var _this = this;
765
+ return function(attempt) {
766
+ guid4 = _this.Guid4;
767
+ if (!_this.stack.includes(guid4)) {
768
+ attempt.current = attempt.max;
769
+ _this.stack.push(guid4);
770
+ }
771
+ };
772
+ };
773
+ Object.defineProperty(Guid4.prototype, "attempt", {
774
+ get: function() {
775
+ var attemptConfig = {
776
+ attempt: {
777
+ current: 1,
778
+ max: 5
779
+ },
780
+ error: {
781
+ message: "[Fatal Error] Guid4 module cannot generate unique guid4"
782
+ }
783
+ };
784
+ var attempt = new GenerateAttempt(attemptConfig.attempt, attemptConfig.error);
785
+ return attempt;
786
+ },
787
+ enumerable: false,
788
+ configurable: true
789
+ });
790
+ Object.defineProperty(Guid4.prototype, "Guid4", {
791
+ get: function() {
792
+ var base = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx";
793
+ var regex = /[xy]/g;
794
+ var guid4 = base.replace(regex, this.formating);
795
+ return guid4;
796
+ },
797
+ enumerable: false,
798
+ configurable: true
799
+ });
800
+ Guid4.prototype.formating = function(char) {
801
+ var preformer = Math.random() * 16 | 0;
802
+ var formattedChar = char == "x" ? preformer : preformer & 3 | 8;
803
+ return formattedChar.toString(16);
804
+ };
805
+ return Guid4;
806
+ }();
807
+
808
+ var GenerateAttempt = function() {
809
+ function GenerateAttempt(config, error) {
810
+ this._attempt = config;
811
+ if (!!error) this._error = error;
812
+ }
813
+ GenerateAttempt.prototype.use = function(strategy) {
814
+ if (strategy === void 0) {
815
+ strategy = "default";
816
+ }
817
+ var context = this;
818
+ switch (strategy) {
819
+ case "default":
820
+ return {
821
+ run: function(action) {
822
+ context.defaultRun(action);
823
+ }
824
+ };
825
+
826
+ case "withError":
827
+ return {
828
+ run: function(action) {
829
+ context.withErrorRun(action);
830
+ }
831
+ };
832
+ }
833
+ };
834
+ GenerateAttempt.prototype.defaultRun = function(action) {
835
+ var attemptCondition = this._attempt.current <= this._attempt.max;
836
+ while (attemptCondition) {
837
+ action(this._attempt);
838
+ this._attempt.current++;
839
+ }
840
+ };
841
+ GenerateAttempt.prototype.withErrorRun = function(action) {
842
+ var attemptCondition = this._attempt.current <= this._attempt.max;
843
+ var errorCondition = this._attempt.current === this._attempt.max;
844
+ var errorMessage = this._error.message;
845
+ while (attemptCondition) {
846
+ this.throwError(errorCondition, errorMessage);
847
+ action(this._attempt);
848
+ this._attempt.current++;
849
+ }
850
+ };
851
+ GenerateAttempt.prototype.throwError = function(condition, message) {
852
+ if (condition) {
853
+ throw new Error(message);
854
+ }
855
+ };
856
+ return GenerateAttempt;
857
+ }();
858
+
859
+ var EventService = function() {
860
+ function EventService() {
861
+ this.eventList = [];
862
+ }
863
+ EventService.prototype.subcribe = function(controlEvent) {
864
+ var eventAtom = __assign({
865
+ id: (new Guid4).generate()
866
+ }, controlEvent);
867
+ this.eventList.push(eventAtom);
868
+ };
869
+ EventService.prototype.dispatch = function(name, eventArgs) {
870
+ var eventAtom = this.eventList.find((function(event) {
871
+ return event.name === name;
872
+ }));
873
+ eventAtom.action(eventArgs);
874
+ };
875
+ EventService.prototype.applyEvents = function(baseElement) {
876
+ var _a;
877
+ (_a = this.eventList) === null || _a === void 0 ? void 0 : _a.forEach((function(event) {
878
+ baseElement.addEventListener(event.name, event.action);
879
+ }));
880
+ };
881
+ return EventService;
882
+ }();
883
+
884
+ var LoggerService = function() {
885
+ function LoggerService() {
886
+ this.log = {
887
+ components: [],
888
+ services: [],
889
+ planed: []
890
+ };
891
+ }
892
+ Object.defineProperty(LoggerService.prototype, "components", {
893
+ get: function() {
894
+ return this.getMethods("components");
895
+ },
896
+ enumerable: false,
897
+ configurable: true
898
+ });
899
+ Object.defineProperty(LoggerService.prototype, "services", {
900
+ get: function() {
901
+ return this.getMethods("services");
902
+ },
903
+ enumerable: false,
904
+ configurable: true
905
+ });
906
+ Object.defineProperty(LoggerService.prototype, "planed", {
907
+ get: function() {
908
+ return this.getMethods("planed");
909
+ },
910
+ enumerable: false,
911
+ configurable: true
912
+ });
913
+ LoggerService.prototype.getMethods = function(fields) {
914
+ var proto = this;
915
+ return {
916
+ add: function(logItem) {
917
+ proto._add(fields, logItem);
918
+ },
919
+ get: function() {
920
+ var args = [];
921
+ for (var _i = 0; _i < arguments.length; _i++) {
922
+ args[_i] = arguments[_i];
923
+ }
924
+ proto._get.apply(proto, args);
925
+ }
926
+ };
927
+ };
928
+ LoggerService.prototype._add = function(field, logItem) {
929
+ this.log[field].push(logItem);
930
+ };
931
+ LoggerService.prototype._get = function(field, name) {
932
+ return this.log[field].find((function(logItem) {
933
+ return logItem.info.name === name;
934
+ }));
935
+ };
936
+ return LoggerService;
937
+ }();
938
+
939
+ var ToolLayerService = function() {
940
+ function ToolLayerService(appConfig) {
941
+ this.appConfig = appConfig;
942
+ this.multiplier = 1e3;
943
+ }
944
+ ToolLayerService.prototype.getLayerIndex = function(layerName) {
945
+ var layer = this.appConfig.LAYERS.find((function(layer) {
946
+ return layer.name === layerName;
947
+ }));
948
+ var zIndex = this.multiplier * layer.index;
949
+ return zIndex;
950
+ };
951
+ return ToolLayerService;
952
+ }();
953
+
954
+ var ToolService = function() {
955
+ function ToolService(canvasComponent) {
956
+ this.canvasComponent = canvasComponent;
957
+ this.before = null;
958
+ this.active = null;
959
+ this.registry = [];
960
+ }
961
+ ToolService.prototype.add = function(tool) {
962
+ var hasRegisteredTool = this.registry.find((function(registeredTool) {
963
+ return registeredTool.id === tool.id;
964
+ }));
965
+ if (hasRegisteredTool) {
966
+ console.warn("Tool has been previously registered!");
967
+ return false;
968
+ }
969
+ this.registry.push(tool);
970
+ return true;
971
+ };
972
+ ToolService.prototype.setActive = function(id) {
973
+ var _a, _b, _c;
974
+ if (((_a = this.active) === null || _a === void 0 ? void 0 : _a.id) === id) return console.warn("Tool is already active");
975
+ if (!!((_b = this.active) === null || _b === void 0 ? void 0 : _b.offAction)) {
976
+ this.active.offAction();
977
+ }
978
+ var registeredTool = this.registry.find((function(registeredTool) {
979
+ return registeredTool.id === id;
980
+ }));
981
+ if (!!registeredTool) {
982
+ this.active = registeredTool;
983
+ if (!!((_c = this.active) === null || _c === void 0 ? void 0 : _c.onAction)) {
984
+ this.active.onAction();
985
+ }
986
+ } else {
987
+ console.warn("Tool has not previously been registered with this identifier");
988
+ }
989
+ };
990
+ ToolService.prototype.offActive = function(id) {
991
+ if (!!id) {
992
+ if (this.active.id === id) {
993
+ this.off();
994
+ } else {
995
+ return console.warn('ID active tool is not "'.concat(id, '"'));
996
+ }
997
+ } else {
998
+ this.off();
999
+ }
1000
+ };
1001
+ ToolService.prototype.off = function() {
1002
+ var _a;
1003
+ if (!!((_a = this.active) === null || _a === void 0 ? void 0 : _a.offAction)) {
1004
+ this.active.offAction();
1005
+ }
1006
+ this.before = this.active;
1007
+ this.active = null;
1008
+ this.canvasComponent.cursorStyle = "default";
1009
+ };
1010
+ return ToolService;
1011
+ }();
1012
+
1013
+ var range = function(start, end) {
1014
+ var result = [];
1015
+ for (var i = start; i < end; i++) {
1016
+ result.push(i);
1017
+ }
1018
+ return result;
1019
+ };
1020
+
1021
+ var Filter = function() {
1022
+ function Filter(appConfig, ctx) {
1023
+ this.appConfig = appConfig;
1024
+ this.ctx = ctx;
1025
+ }
1026
+ Filter.prototype.setImageSize = function(size) {
1027
+ this.imageSize = size;
1028
+ };
1029
+ Filter.prototype.copy = function(options) {
1030
+ var width = (options === null || options === void 0 ? void 0 : options.width) ? options.width : this.appConfig.CANVAS_SIZE.width;
1031
+ var height = (options === null || options === void 0 ? void 0 : options.height) ? options.height : this.appConfig.CANVAS_SIZE.height;
1032
+ var imgData = this.ctx.getImageData(options.x, options.y, width, height);
1033
+ return imgData;
1034
+ };
1035
+ Filter.prototype.copyExtendedModel = function(options) {
1036
+ var width = (options === null || options === void 0 ? void 0 : options.width) ? options.width : this.appConfig.CANVAS_SIZE.width;
1037
+ var height = (options === null || options === void 0 ? void 0 : options.height) ? options.height : this.appConfig.CANVAS_SIZE.height;
1038
+ var imgData = this.ctx.getImageData(options.x, options.y, width, height);
1039
+ var extendedImageData = this.clearEmptyPixels(imgData);
1040
+ return extendedImageData;
1041
+ };
1042
+ Filter.prototype.update = function(imgData, options) {
1043
+ this.ctx.clearRect(0, 0, this.appConfig.CANVAS_SIZE.width, this.appConfig.CANVAS_SIZE.height);
1044
+ this.ctx.putImageData(imgData, options.x, options.y);
1045
+ };
1046
+ Filter.prototype.clearEmptyPixels = function(imageData) {
1047
+ var rowRGBABuff = this.getRowRGBABuff(imageData);
1048
+ var RGBAMatrix = this.getRGBAMatrix(rowRGBABuff, {
1049
+ width: imageData.width,
1050
+ height: imageData.height
1051
+ });
1052
+ var beforeSize = {
1053
+ width: imageData.width,
1054
+ height: imageData.height
1055
+ };
1056
+ var tempSize = this.getSizeOfSparseMatrix(RGBAMatrix, beforeSize);
1057
+ var cleared = rowRGBABuff.filter((function(byteArray) {
1058
+ var alpha = byteArray[3];
1059
+ return !!alpha;
1060
+ }));
1061
+ var clearedBuff = cleared.flat();
1062
+ var tempCanvas = document.createElement("canvas");
438
1063
  var tempCtx = tempCanvas.getContext("2d");
439
1064
  var tempImageData = tempCtx.createImageData(tempSize.width, tempSize.height);
440
1065
  clearedBuff.forEach((function(_, i) {
@@ -540,274 +1165,46 @@ var Filter = function() {
540
1165
  }));
541
1166
  return buff;
542
1167
  };
543
- Filter.prototype.getRowRGBABuff = function(imageData) {
544
- var rowRGBABuff = [];
545
- var colorIndx = 0;
546
- var colorRGBAIndx = 0;
547
- imageData.data.forEach((function(pxColor) {
548
- var _a;
549
- if (colorIndx >= 4) {
550
- colorIndx = 0;
551
- colorRGBAIndx++;
552
- }
553
- colorIndx++;
554
- (_a = rowRGBABuff[colorRGBAIndx]) !== null && _a !== void 0 ? _a : rowRGBABuff[colorRGBAIndx] = [];
555
- rowRGBABuff[colorRGBAIndx].push(pxColor);
556
- }));
557
- return rowRGBABuff;
558
- };
559
- return Filter;
560
- }();
561
-
562
- var ThroughHistoryService = function() {
563
- function ThroughHistoryService() {}
564
- ThroughHistoryService.current = function() {
565
- var history = AppStore.store.historyState.historyLines;
566
- var lastIndex = history.length - 1;
567
- return history[lastIndex];
568
- };
569
- ThroughHistoryService.prev = function() {
570
- var history = AppStore.store.historyState.historyLines;
571
- var prevIndex = history.length - 2;
572
- return history[prevIndex];
573
- };
574
- ThroughHistoryService.undo = function(ctx) {
575
- var current = ThroughHistoryService.current();
576
- var prev = ThroughHistoryService.prev();
577
- if (!!(current === null || current === void 0 ? void 0 : current.stateValue)) {
578
- ThroughHistoryService.cache.unshift(current);
579
- AppStore.store.historyState.reduce("UNDO");
580
- if (prev === null || prev === void 0 ? void 0 : prev.stateValue) {
581
- ThroughHistoryService.updateCanvas(ctx, prev.stateValue);
582
- }
583
- }
584
- };
585
- ThroughHistoryService.redo = function(ctx) {
586
- var firstInCache = ThroughHistoryService.cache.shift();
587
- if (!!(firstInCache === null || firstInCache === void 0 ? void 0 : firstInCache.stateValue)) {
588
- AppStore.store.historyState.reduce("REDO", firstInCache);
589
- ThroughHistoryService.updateCanvas(ctx, firstInCache.stateValue);
590
- }
591
- };
592
- ThroughHistoryService.clearCache = function() {
593
- ThroughHistoryService.cache = [];
594
- };
595
- ThroughHistoryService.recovery = function(project) {
596
- AppStore.store.historyState.reduce("SET_HISTORY", {
597
- historyLines: project.state.history
598
- });
599
- ThroughHistoryService.cache = project.state.cache;
600
- };
601
- ThroughHistoryService.updateCanvas = function(ctx, stateValue) {
602
- var filter = new Filter(ctx);
603
- filter.update(stateValue.tempImageData, stateValue.position);
604
- };
605
- ThroughHistoryService.cache = [];
606
- return ThroughHistoryService;
607
- }();
608
-
609
- var HistoryState = function() {
610
- function HistoryState() {
611
- this.default = {
612
- historyLines: []
613
- };
614
- this._historyLines = this.default.historyLines;
615
- this.reset();
616
- }
617
- Object.defineProperty(HistoryState.prototype, "historyLines", {
618
- get: function() {
619
- return this._historyLines;
620
- },
621
- enumerable: false,
622
- configurable: true
623
- });
624
- HistoryState.prototype.reduce = function(name, payload) {
625
- var reducer = new Reducer(this);
626
- switch (name) {
627
- case "SET_HISTORY":
628
- reducer.setHistoryLines(payload);
629
- ThroughHistoryService.clearCache();
630
- break;
631
-
632
- case "UPDATE_HISTORY":
633
- reducer.updateHistoryLines(payload);
634
- ThroughHistoryService.clearCache();
635
- break;
636
-
637
- case "REDO":
638
- reducer.updateHistoryLines(payload);
639
- break;
640
-
641
- case "UNDO":
642
- reducer.popHistoryLines();
643
- break;
644
- }
645
- };
646
- HistoryState.prototype.emerge = function(completeIt) {
647
- this._emergeCompleteIt = completeIt;
648
- };
649
- HistoryState.prototype.reset = function() {
650
- this.reduce("SET_HISTORY", this.default);
651
- };
652
- return HistoryState;
653
- }();
654
-
655
- var Reducer = function() {
656
- function Reducer(state) {
657
- this.state = state;
658
- }
659
- Reducer.prototype.setHistoryLines = function(payload) {
660
- var isUpdate = false;
661
- if (!!(payload === null || payload === void 0 ? void 0 : payload.historyLines)) {
662
- this.state._historyLines = payload.historyLines;
663
- isUpdate = true;
664
- }
665
- if (isUpdate && !!this.state._emergeCompleteIt) {
666
- this.state._emergeCompleteIt(this.state._historyLines);
667
- }
668
- };
669
- Reducer.prototype.updateHistoryLines = function(payload) {
670
- var isUpdate = false;
671
- if (!!(payload === null || payload === void 0 ? void 0 : payload.view)) {
672
- this.state._historyLines.push(payload);
673
- isUpdate = true;
674
- }
675
- if (isUpdate && !!this.state._emergeCompleteIt) {
676
- this.state._emergeCompleteIt(this.state._historyLines);
677
- }
678
- };
679
- Reducer.prototype.popHistoryLines = function() {
680
- this.state._historyLines.pop();
681
- if (!!this.state._emergeCompleteIt) {
682
- this.state._emergeCompleteIt(this.state._historyLines);
683
- }
684
- };
685
- return Reducer;
686
- }();
687
-
688
- var ImageState = function() {
689
- function ImageState() {
690
- this.default = {
691
- position: {
692
- x: 0,
693
- y: 0
694
- },
695
- size: {
696
- width: 0,
697
- height: 0
698
- },
699
- tempImageData: null
700
- };
701
- this._position = this.default.position;
702
- this._size = this.default.size;
703
- this._tempImageData = this.default.tempImageData;
704
- this.reset();
705
- }
706
- Object.defineProperty(ImageState.prototype, "position", {
707
- get: function() {
708
- return this._position;
709
- },
710
- enumerable: false,
711
- configurable: true
712
- });
713
- Object.defineProperty(ImageState.prototype, "size", {
714
- get: function() {
715
- return this._size;
716
- },
717
- enumerable: false,
718
- configurable: true
719
- });
720
- Object.defineProperty(ImageState.prototype, "tempImageData", {
721
- get: function() {
722
- return this._tempImageData;
723
- },
724
- enumerable: false,
725
- configurable: true
726
- });
727
- ImageState.prototype.reduce = function(payload, title) {
728
- var isUpdate = false;
729
- if (!!(payload === null || payload === void 0 ? void 0 : payload.position)) {
730
- this._position = payload.position;
731
- }
732
- if (!!(payload === null || payload === void 0 ? void 0 : payload.size)) {
733
- this._size = payload.size;
734
- }
735
- if (!!(payload === null || payload === void 0 ? void 0 : payload.tempImageData)) {
736
- this._tempImageData = payload.tempImageData;
737
- isUpdate = true;
738
- }
739
- if (isUpdate) {
740
- this.addToHistory("".concat(title || "reduce image"));
741
- }
742
- };
743
- ImageState.prototype.reset = function() {
744
- this.reduce(this.default, "reset to default");
745
- };
746
- ImageState.prototype.getEntry = function() {
747
- return {
748
- position: this._position,
749
- size: this._size,
750
- imageData: this._tempImageData
751
- };
752
- };
753
- ImageState.prototype.addToHistory = function(title) {
754
- var stateValue = {
755
- position: this._position,
756
- size: this._size,
757
- tempImageData: this._tempImageData
758
- };
759
- AppStore.store.historyState.reduce("UPDATE_HISTORY", {
760
- view: title,
761
- stateName: "image",
762
- stateValue
763
- });
764
- };
765
- return ImageState;
766
- }();
767
-
768
- var Store = function() {
769
- function Store(imageState, historyState) {
770
- this.imageState = imageState;
771
- this.historyState = historyState;
772
- }
773
- Store.prototype.reset = function() {
774
- this.imageState.reset();
775
- this.historyState.reset();
776
- };
777
- return Store;
778
- }();
779
-
780
- var AppStore = function() {
781
- function AppStore() {}
782
- AppStore.subscribe = function(to, completeIt) {
783
- if (to === "history") {
784
- AppStore.store.historyState.emerge(completeIt);
785
- }
1168
+ Filter.prototype.getRowRGBABuff = function(imageData) {
1169
+ var rowRGBABuff = [];
1170
+ var colorIndx = 0;
1171
+ var colorRGBAIndx = 0;
1172
+ imageData.data.forEach((function(pxColor) {
1173
+ var _a;
1174
+ if (colorIndx >= 4) {
1175
+ colorIndx = 0;
1176
+ colorRGBAIndx++;
1177
+ }
1178
+ colorIndx++;
1179
+ (_a = rowRGBABuff[colorRGBAIndx]) !== null && _a !== void 0 ? _a : rowRGBABuff[colorRGBAIndx] = [];
1180
+ rowRGBABuff[colorRGBAIndx].push(pxColor);
1181
+ }));
1182
+ return rowRGBABuff;
786
1183
  };
787
- return AppStore;
1184
+ return Filter;
788
1185
  }();
789
1186
 
790
- (function() {
791
- AppStore.store = new Store(new ImageState, new HistoryState);
792
- })();
793
-
794
1187
  var CropService = function() {
795
- function CropService() {}
796
- CropService.setup = function() {
797
- ExcretionsComponent.additionStyle = "crop";
1188
+ function CropService(appConfig, appStoreRepository, excretionComponent) {
1189
+ this.appConfig = appConfig;
1190
+ this.appStoreRepository = appStoreRepository;
1191
+ this.excretionComponent = excretionComponent;
1192
+ }
1193
+ CropService.prototype.setup = function() {
1194
+ this.excretionComponent.additionStyle = "crop";
798
1195
  };
799
- CropService.crop = function(ctx) {
1196
+ CropService.prototype.crop = function(ctx) {
800
1197
  var _a;
801
- if (!!((_a = ExcretionsComponent.excretionsCoords) === null || _a === void 0 ? void 0 : _a.length) === false) return;
802
- var filter = new Filter(ctx);
803
- var options = CropService.options;
1198
+ if (!!((_a = this.excretionComponent.excretionsCoords) === null || _a === void 0 ? void 0 : _a.length) === false) return;
1199
+ var filter = new Filter(this.appConfig, ctx);
1200
+ var options = this.options;
804
1201
  var _b = filter.copyExtendedModel(options), imageData = _b.imageData, size = _b.size;
805
1202
  var position = {
806
- x: AppConfig.CANVAS_SIZE.width / 2 - size.width / 2,
807
- y: AppConfig.CANVAS_SIZE.height / 2 - size.height / 2
1203
+ x: this.appConfig.CANVAS_SIZE.width / 2 - size.width / 2,
1204
+ y: this.appConfig.CANVAS_SIZE.height / 2 - size.height / 2
808
1205
  };
809
1206
  filter.update(imageData, position);
810
- AppStore.store.imageState.reduce({
1207
+ this.appStoreRepository.store.imageState.reduce({
811
1208
  tempImageData: imageData,
812
1209
  position,
813
1210
  size: {
@@ -816,16 +1213,16 @@ var CropService = function() {
816
1213
  }
817
1214
  }, "Use crop");
818
1215
  };
819
- CropService.viewCropButton = function() {
820
- var cropButtons = ExcretionsComponent.excretionWrap.querySelectorAll(".crop-button");
1216
+ CropService.prototype.viewCropButton = function() {
1217
+ var cropButtons = this.excretionComponent.excretionWrap.querySelectorAll(".crop-button");
821
1218
  var lastCropButtonIndex = cropButtons.length - 1;
822
1219
  var cropButton = cropButtons[lastCropButtonIndex];
823
1220
  cropButton.classList.add("crop-button--view");
824
1221
  };
825
- Object.defineProperty(CropService, "options", {
1222
+ Object.defineProperty(CropService.prototype, "options", {
826
1223
  get: function() {
827
- var excretionLastIndex = ExcretionsComponent.excretionsCoords.length - 1;
828
- var coords = ExcretionsComponent.excretionsCoords[excretionLastIndex];
1224
+ var excretionLastIndex = this.excretionComponent.excretionsCoords.length - 1;
1225
+ var coords = this.excretionComponent.excretionsCoords[excretionLastIndex];
829
1226
  var excWidth = Math.abs(coords.start.x - coords.end.x);
830
1227
  var excHeight = Math.abs(coords.start.y - coords.end.y);
831
1228
  return {
@@ -841,587 +1238,249 @@ var CropService = function() {
841
1238
  return CropService;
842
1239
  }();
843
1240
 
844
- var ExcretionsComponent = function(_super) {
845
- __extends(ExcretionsComponent, _super);
846
- function ExcretionsComponent() {
847
- return _super !== null && _super.apply(this, arguments) || this;
1241
+ var HistoryState = function() {
1242
+ function HistoryState(throughHistoryService) {
1243
+ this.throughHistoryService = throughHistoryService;
1244
+ this.default = {
1245
+ historyLines: []
1246
+ };
1247
+ this._historyLines = this.default.historyLines;
1248
+ this.reset();
848
1249
  }
849
- Object.defineProperty(ExcretionsComponent, "additionStyle", {
1250
+ Object.defineProperty(HistoryState.prototype, "historyLines", {
850
1251
  get: function() {
851
- return ExcretionsComponent._additionStyle;
852
- },
853
- set: function(value) {
854
- ExcretionsComponent._additionStyle = value;
855
- ExcretionsComponent.applyExcretionStyle();
1252
+ return this._historyLines;
856
1253
  },
857
1254
  enumerable: false,
858
1255
  configurable: true
859
1256
  });
860
- ExcretionsComponent.applyExcretionStyle = function() {
861
- switch (ExcretionsComponent._additionStyle) {
862
- case "crop":
863
- ExcretionsComponent.determineCropStyle();
864
- break;
865
-
866
- case "default":
867
- ExcretionsComponent.determineDefaultStyle();
868
- break;
869
-
870
- default:
871
- ExcretionsComponent.determineDefaultStyle();
1257
+ HistoryState.prototype.reduce = function(name, payload) {
1258
+ var reducer = new Reducer(this);
1259
+ switch (name) {
1260
+ case "SET_HISTORY":
1261
+ reducer.setHistoryLines(payload);
1262
+ this.throughHistoryService.clearCache();
872
1263
  break;
873
- }
874
- };
875
- ExcretionsComponent.determineCropStyle = function() {
876
- ExcretionsComponent._excretions.forEach((function(excretion) {
877
- if (!!excretion === false) return;
878
- if (!excretion.classList.contains("excretion_crop")) {
879
- excretion.classList.add("excretion_crop");
880
- CropService.viewCropButton();
881
- }
882
- }));
883
- };
884
- ExcretionsComponent.determineDefaultStyle = function() {
885
- ExcretionsComponent._excretions.forEach((function(excretion) {
886
- if (!!excretion === false) return;
887
- excretion.classList = ExcretionsComponent._excretionDefaultStyle;
888
- }));
889
- };
890
- ExcretionsComponent.getComponent = function() {
891
- var wrapOptions = {
892
- className: "excretions-wrap"
893
- };
894
- var excretionsTemplate = ExcretionsComponent.getTemplate(ExcretionsComponent.template, wrapOptions);
895
- var excretionsStyle = ExcretionsComponent.getStyle(ExcretionsComponent.css);
896
- ExcretionsComponent.excretionWrap = excretionsTemplate;
897
- ExcretionsComponent.emmit();
898
- return {
899
- excretionsTemplate,
900
- excretionsStyle
901
- };
902
- };
903
- Object.defineProperty(ExcretionsComponent, "excretionState", {
904
- set: function(state) {
905
- ExcretionsComponent._excretionState = state;
906
- ExcretionsComponent.applyExcretionStyle();
907
- switch (state) {
908
- case "abandoned":
909
- CanvasComponent.cursorStyle = "default";
910
- break;
911
-
912
- case "create":
913
- CanvasComponent.cursorStyle = "crosshair";
914
- break;
915
-
916
- case "add":
917
- CanvasComponent.cursorStyle = "copy";
918
- break;
919
-
920
- case "remove":
921
- CanvasComponent.cursorStyle = "alias";
922
- break;
923
1264
 
924
- default:
925
- CanvasComponent.cursorStyle = "default";
926
- break;
927
- }
928
- },
929
- enumerable: false,
930
- configurable: true
931
- });
932
- ExcretionsComponent.setToolState = function(toolState) {
933
- ExcretionsComponent._excretionToolState = toolState;
934
- switch (toolState) {
935
- case "abandoned":
936
- ExcretionsComponent.excretionState = "abandoned";
937
- ExcretionsComponent._excretionActivity = "abandoned";
1265
+ case "UPDATE_HISTORY":
1266
+ reducer.updateHistoryLines(payload);
1267
+ this.throughHistoryService.clearCache();
938
1268
  break;
939
1269
 
940
- case "taken":
941
- ExcretionsComponent.excretionState = "create";
1270
+ case "REDO":
1271
+ reducer.updateHistoryLines(payload);
942
1272
  break;
943
1273
 
944
- default:
945
- ExcretionsComponent.excretionState = "abandoned";
946
- ExcretionsComponent._excretionActivity = "abandoned";
1274
+ case "UNDO":
1275
+ reducer.popHistoryLines();
947
1276
  break;
948
1277
  }
949
1278
  };
950
- ExcretionsComponent.clearExcretionsCoords = function() {
951
- console.log("clear!");
952
- ExcretionsComponent._excretions.forEach((function(excretion) {
953
- return excretion.remove();
954
- }));
955
- ExcretionsComponent._excretions = [];
956
- ExcretionsComponent.excretionsCoords = [];
1279
+ HistoryState.prototype.emerge = function(completeIt) {
1280
+ this._emergeCompleteIt = completeIt;
957
1281
  };
958
- ExcretionsComponent.getTempCoords = function() {
959
- var startCoords = ExcretionsComponent._tempCoords[0];
960
- var endCoords = ExcretionsComponent._tempCoords[1];
961
- var coords = Object.assign(startCoords, endCoords);
962
- ExcretionsComponent._tempCoords = [];
963
- return coords;
1282
+ HistoryState.prototype.reset = function() {
1283
+ this.reduce("SET_HISTORY", this.default);
964
1284
  };
965
- ExcretionsComponent.endExcretion = function() {
966
- var coords = ExcretionsComponent.getTempCoords();
967
- ExcretionsComponent.excretionsCoords.push(coords);
968
- ExcretionsComponent._excretionActivity = "end";
969
- console.log("ExcretionsComponent.excretionsCoords", ExcretionsComponent.excretionsCoords);
1285
+ return HistoryState;
1286
+ }();
1287
+
1288
+ var Reducer = function() {
1289
+ function Reducer(state) {
1290
+ this.state = state;
1291
+ }
1292
+ Reducer.prototype.setHistoryLines = function(payload) {
1293
+ var isUpdate = false;
1294
+ if (!!(payload === null || payload === void 0 ? void 0 : payload.historyLines)) {
1295
+ this.state._historyLines = payload.historyLines;
1296
+ isUpdate = true;
1297
+ }
1298
+ if (isUpdate && !!this.state._emergeCompleteIt) {
1299
+ this.state._emergeCompleteIt(this.state._historyLines);
1300
+ }
970
1301
  };
971
- ExcretionsComponent.emmit = function() {
972
- CanvasComponent.subscribe("mousedown", (function(event, cursorPosition) {
973
- var toolState = ExcretionsComponent._excretionToolState;
974
- if (toolState === "abandoned") return;
975
- var state = ExcretionsComponent._excretionState;
976
- if (state === "create") {
977
- var wrapOptions = {
978
- className: ExcretionsComponent._excretionDefaultStyle[0]
979
- };
980
- var excretionTemplate = ExcretionsComponent.getTemplate(ExcretionsComponent.templateExcretion, wrapOptions);
981
- ExcretionsComponent.clearExcretionsCoords();
982
- var tempStart = {
983
- start: cursorPosition
984
- };
985
- excretionTemplate.style.left = "".concat(tempStart.start.x, "px");
986
- excretionTemplate.style.top = "".concat(tempStart.start.y, "px");
987
- var excretionElement = ExcretionsComponent.excretionWrap.appendChild(excretionTemplate);
988
- ExcretionsComponent._excretions.push(excretionElement);
989
- ExcretionsComponent._tempCoords.push(tempStart);
990
- }
991
- if (state === "add") {
992
- var tempStart = {
993
- start: cursorPosition
994
- };
995
- ExcretionsComponent._tempCoords.push(tempStart);
996
- }
997
- ExcretionsComponent.applyExcretionStyle();
998
- ExcretionsComponent._excretionActivity = "active";
999
- }));
1000
- CanvasComponent.subscribe("mousemove", (function(event, cursorPosition) {
1001
- var toolState = ExcretionsComponent._excretionToolState;
1002
- if (toolState === "abandoned") return;
1003
- var activity = ExcretionsComponent._excretionActivity;
1004
- if (event.altKey && ExcretionsComponent._excretionState !== "abandoned") {
1005
- ExcretionsComponent._excretionState = "add";
1006
- }
1007
- if (activity === "abandoned") return;
1008
- if (activity === "active") {
1009
- var excretionLastIndex = ExcretionsComponent._excretions.length - 1;
1010
- var excretion = ExcretionsComponent._excretions[excretionLastIndex];
1011
- var excretionX = +excretion.style.left.split("px")[0];
1012
- var excretionY = +excretion.style.top.split("px")[0];
1013
- var width = Math.abs(cursorPosition.x - excretionX);
1014
- var height = Math.abs(cursorPosition.y - excretionY);
1015
- excretion.style.width = width + "px";
1016
- excretion.style.height = height + "px";
1017
- var isRightBottom = cursorPosition.x > excretionX && cursorPosition.y > excretionY;
1018
- var isLeftBottom = cursorPosition.x < excretionX && cursorPosition.y > excretionY;
1019
- var isLeftTop = cursorPosition.x < excretionX && cursorPosition.y < excretionY;
1020
- var isRightTop = cursorPosition.x > excretionX && cursorPosition.y < excretionY;
1021
- if (isRightBottom) {
1022
- excretion.style.transform = "translateX(0px) translateY(0px)";
1023
- } else if (isLeftBottom) {
1024
- excretion.style.transform = "translateX(-".concat(width, "px) translateY(0px)");
1025
- } else if (isLeftTop) {
1026
- excretion.style.transform = "translateX(-".concat(width, "px) translateY(-").concat(height, "px)");
1027
- } else if (isRightTop) {
1028
- excretion.style.transform = "translateX(0px) translateY(-".concat(height, "px)");
1029
- }
1030
- }
1031
- }));
1032
- CanvasComponent.subscribe("mouseup", (function(event, cursorPosition) {
1033
- var toolState = ExcretionsComponent._excretionToolState;
1034
- if (toolState === "abandoned") return;
1035
- var state = ExcretionsComponent._excretionState;
1036
- if (state === "abandoned") return;
1037
- if (state === "create" || state === "add") {
1038
- var tempEnd = {
1039
- end: cursorPosition
1040
- };
1041
- ExcretionsComponent._tempCoords.push(tempEnd);
1042
- ExcretionsComponent.endExcretion();
1043
- }
1044
- }));
1302
+ Reducer.prototype.updateHistoryLines = function(payload) {
1303
+ var isUpdate = false;
1304
+ if (!!(payload === null || payload === void 0 ? void 0 : payload.view)) {
1305
+ this.state._historyLines.push(payload);
1306
+ isUpdate = true;
1307
+ }
1308
+ if (isUpdate && !!this.state._emergeCompleteIt) {
1309
+ this.state._emergeCompleteIt(this.state._historyLines);
1310
+ }
1045
1311
  };
1046
- ExcretionsComponent.template = "";
1047
- 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 ';
1048
- ExcretionsComponent._excretionDefaultStyle = [ "excretion" ];
1049
- 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 ");
1050
- ExcretionsComponent._excretions = [];
1051
- ExcretionsComponent._excretionState = "abandoned";
1052
- ExcretionsComponent._excretionActivity = "abandoned";
1053
- ExcretionsComponent._excretionToolState = "abandoned";
1054
- ExcretionsComponent._tempCoords = [];
1055
- ExcretionsComponent.excretionsCoords = [];
1056
- ExcretionsComponent._additionStyle = "default";
1057
- ExcretionsComponent.tool = {
1058
- id: 1,
1059
- name: "excretion",
1060
- onAction: function() {
1061
- return ExcretionsComponent.setToolState("taken");
1062
- },
1063
- offAction: function() {
1064
- return ExcretionsComponent.setToolState("abandoned");
1065
- },
1066
- support: function() {
1067
- ExcretionsComponent.clearExcretionsCoords();
1068
- ExcretionsComponent.additionStyle = "default";
1312
+ Reducer.prototype.popHistoryLines = function() {
1313
+ this.state._historyLines.pop();
1314
+ if (!!this.state._emergeCompleteIt) {
1315
+ this.state._emergeCompleteIt(this.state._historyLines);
1069
1316
  }
1070
1317
  };
1071
- (function() {
1072
- ToolService.add(ExcretionsComponent.tool);
1073
- LoggerService.components.add({
1074
- info: {
1075
- name: "excretion",
1076
- description: "excretion component"
1077
- },
1078
- prototype: ExcretionsComponent
1079
- });
1080
- })();
1081
- return ExcretionsComponent;
1082
- }(ComponentService);
1318
+ return Reducer;
1319
+ }();
1083
1320
 
1084
- var Guid4 = function() {
1085
- function Guid4() {
1086
- this.stack = [];
1321
+ var ImageState = function() {
1322
+ function ImageState(appStoreRepository) {
1323
+ this.appStoreRepository = appStoreRepository;
1324
+ this.default = {
1325
+ position: {
1326
+ x: 0,
1327
+ y: 0
1328
+ },
1329
+ size: {
1330
+ width: 0,
1331
+ height: 0
1332
+ },
1333
+ tempImageData: null
1334
+ };
1335
+ this._position = this.default.position;
1336
+ this._size = this.default.size;
1337
+ this._tempImageData = this.default.tempImageData;
1338
+ this.reset();
1087
1339
  }
1088
- Guid4.prototype.generate = function() {
1089
- return this.Guid4;
1090
- };
1091
- Object.defineProperty(Guid4.prototype, "finite", {
1340
+ Object.defineProperty(ImageState.prototype, "position", {
1092
1341
  get: function() {
1093
- var _a;
1094
- var guid4 = this.stack[(_a = this.stack) === null || _a === void 0 ? void 0 : _a.length];
1095
- if (!!guid4) {
1096
- return guid4;
1097
- } else {
1098
- throw new Error("Guid4 not generate");
1099
- }
1342
+ return this._position;
1100
1343
  },
1101
1344
  enumerable: false,
1102
1345
  configurable: true
1103
- });
1104
- Guid4.prototype.generateWithFactor = function(attempt) {
1105
- var factor = this.getFactor(this.guid4);
1106
- attempt.use("withError").run(factor);
1107
- };
1108
- Guid4.prototype.getFactor = function(guid4) {
1109
- var _this = this;
1110
- return function(attempt) {
1111
- guid4 = _this.Guid4;
1112
- if (!_this.stack.includes(guid4)) {
1113
- attempt.current = attempt.max;
1114
- _this.stack.push(guid4);
1115
- }
1116
- };
1117
- };
1118
- Object.defineProperty(Guid4.prototype, "attempt", {
1119
- get: function() {
1120
- var attemptConfig = {
1121
- attempt: {
1122
- current: 1,
1123
- max: 5
1124
- },
1125
- error: {
1126
- message: "[Fatal Error] Guid4 module cannot generate unique guid4"
1127
- }
1128
- };
1129
- var attempt = new GenerateAttempt(attemptConfig.attempt, attemptConfig.error);
1130
- return attempt;
1346
+ });
1347
+ Object.defineProperty(ImageState.prototype, "size", {
1348
+ get: function() {
1349
+ return this._size;
1131
1350
  },
1132
1351
  enumerable: false,
1133
1352
  configurable: true
1134
1353
  });
1135
- Object.defineProperty(Guid4.prototype, "Guid4", {
1354
+ Object.defineProperty(ImageState.prototype, "tempImageData", {
1136
1355
  get: function() {
1137
- var base = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx";
1138
- var regex = /[xy]/g;
1139
- var guid4 = base.replace(regex, this.formating);
1140
- return guid4;
1356
+ return this._tempImageData;
1141
1357
  },
1142
1358
  enumerable: false,
1143
1359
  configurable: true
1144
1360
  });
1145
- Guid4.prototype.formating = function(char) {
1146
- var preformer = Math.random() * 16 | 0;
1147
- var formattedChar = char == "x" ? preformer : preformer & 3 | 8;
1148
- return formattedChar.toString(16);
1149
- };
1150
- return Guid4;
1151
- }();
1152
-
1153
- var GenerateAttempt = function() {
1154
- function GenerateAttempt(config, error) {
1155
- this._attempt = config;
1156
- if (!!error) this._error = error;
1157
- }
1158
- GenerateAttempt.prototype.use = function(strategy) {
1159
- if (strategy === void 0) {
1160
- strategy = "default";
1161
- }
1162
- var context = this;
1163
- switch (strategy) {
1164
- case "default":
1165
- return {
1166
- run: function(action) {
1167
- context.defaultRun(action);
1168
- }
1169
- };
1170
-
1171
- case "withError":
1172
- return {
1173
- run: function(action) {
1174
- context.withErrorRun(action);
1175
- }
1176
- };
1361
+ ImageState.prototype.reduce = function(payload, title) {
1362
+ var isUpdate = false;
1363
+ if (!!(payload === null || payload === void 0 ? void 0 : payload.position)) {
1364
+ this._position = payload.position;
1177
1365
  }
1178
- };
1179
- GenerateAttempt.prototype.defaultRun = function(action) {
1180
- var attemptCondition = this._attempt.current <= this._attempt.max;
1181
- while (attemptCondition) {
1182
- action(this._attempt);
1183
- this._attempt.current++;
1366
+ if (!!(payload === null || payload === void 0 ? void 0 : payload.size)) {
1367
+ this._size = payload.size;
1184
1368
  }
1185
- };
1186
- GenerateAttempt.prototype.withErrorRun = function(action) {
1187
- var attemptCondition = this._attempt.current <= this._attempt.max;
1188
- var errorCondition = this._attempt.current === this._attempt.max;
1189
- var errorMessage = this._error.message;
1190
- while (attemptCondition) {
1191
- this.throwError(errorCondition, errorMessage);
1192
- action(this._attempt);
1193
- this._attempt.current++;
1369
+ if (!!(payload === null || payload === void 0 ? void 0 : payload.tempImageData)) {
1370
+ this._tempImageData = payload.tempImageData;
1371
+ isUpdate = true;
1194
1372
  }
1195
- };
1196
- GenerateAttempt.prototype.throwError = function(condition, message) {
1197
- if (condition) {
1198
- throw new Error(message);
1373
+ if (isUpdate) {
1374
+ this.addToHistory("".concat(title || "reduce image"));
1199
1375
  }
1200
1376
  };
1201
- return GenerateAttempt;
1202
- }();
1203
-
1204
- var EventService = function() {
1205
- function EventService() {}
1206
- EventService.subcribe = function(controlEvent) {
1207
- var eventAtom = __assign({
1208
- id: (new Guid4).generate()
1209
- }, controlEvent);
1210
- EventService.eventList.push(eventAtom);
1211
- };
1212
- EventService.dispatch = function(name, eventArgs) {
1213
- var eventAtom = EventService.eventList.find((function(event) {
1214
- return event.name === name;
1215
- }));
1216
- eventAtom.action(eventArgs);
1217
- };
1218
- EventService.applyEvents = function(baseElement) {
1219
- var _a;
1220
- (_a = EventService.eventList) === null || _a === void 0 ? void 0 : _a.forEach((function(event) {
1221
- baseElement.addEventListener(event.name, event.action);
1222
- }));
1377
+ ImageState.prototype.reset = function() {
1378
+ this.reduce(this.default, "reset to default");
1223
1379
  };
1224
- EventService.eventList = [];
1225
- return EventService;
1226
- }();
1227
-
1228
- var LoadingComponent = function(_super) {
1229
- __extends(LoadingComponent, _super);
1230
- function LoadingComponent() {
1231
- return _super !== null && _super.apply(this, arguments) || this;
1232
- }
1233
- LoadingComponent.getComponent = function() {
1234
- var wrapOptions = {
1235
- className: "loading-wrapper"
1236
- };
1237
- var loadingTemplate = LoadingComponent.getTemplate(LoadingComponent.template, wrapOptions);
1238
- var loadingStyle = LoadingComponent.getStyle(LoadingComponent.css);
1239
- LoadingComponent.loading = loadingTemplate;
1240
- LoadingComponent.subscribeLoadingStart();
1241
- LoadingComponent.subscribeLoadingEnd();
1380
+ ImageState.prototype.getEntry = function() {
1242
1381
  return {
1243
- loadingTemplate,
1244
- loadingStyle
1245
- };
1246
- };
1247
- LoadingComponent.hide = function() {
1248
- LoadingComponent.loading.style.display = "none";
1249
- };
1250
- LoadingComponent.view = function() {
1251
- LoadingComponent.loading.style.display = "flex";
1252
- };
1253
- LoadingComponent.subscribeLoadingStart = function() {
1254
- var controlEvent = {
1255
- name: "loading-start",
1256
- action: function() {
1257
- return LoadingComponent.view();
1258
- }
1382
+ position: this._position,
1383
+ size: this._size,
1384
+ imageData: this._tempImageData
1259
1385
  };
1260
- EventService.subcribe(controlEvent);
1261
1386
  };
1262
- LoadingComponent.subscribeLoadingEnd = function() {
1263
- var controlEvent = {
1264
- name: "loading-end",
1265
- action: function() {
1266
- return LoadingComponent.hide();
1267
- }
1387
+ ImageState.prototype.addToHistory = function(title) {
1388
+ var stateValue = {
1389
+ position: this._position,
1390
+ size: this._size,
1391
+ tempImageData: this._tempImageData
1268
1392
  };
1269
- EventService.subcribe(controlEvent);
1270
- };
1271
- LoadingComponent.template = '\n <span class="loader"></span>\n ';
1272
- 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 ';
1273
- (function() {
1274
- LoggerService.components.add({
1275
- info: {
1276
- name: "loading",
1277
- description: "loading component"
1278
- },
1279
- prototype: LoadingComponent
1393
+ this.appStoreRepository.store.historyState.reduce("UPDATE_HISTORY", {
1394
+ view: title,
1395
+ stateName: "image",
1396
+ stateValue
1280
1397
  });
1281
- })();
1282
- return LoadingComponent;
1283
- }(ComponentService);
1398
+ };
1399
+ return ImageState;
1400
+ }();
1284
1401
 
1285
- var PipetteComponent = function(_super) {
1286
- __extends(PipetteComponent, _super);
1287
- function PipetteComponent() {
1288
- return _super !== null && _super.apply(this, arguments) || this;
1402
+ var Store = function() {
1403
+ function Store(imageState, historyState) {
1404
+ this.imageState = imageState;
1405
+ this.historyState = historyState;
1289
1406
  }
1290
- Object.defineProperty(PipetteComponent, "pipetteColor", {
1291
- get: function() {
1292
- return PipetteComponent._pipetteColor;
1293
- },
1294
- set: function(color) {
1295
- PipetteComponent._pipetteColor = color;
1296
- PipetteComponent._pipetteColorElement.style.borderColor = PipetteComponent._pipetteColor;
1297
- },
1298
- enumerable: false,
1299
- configurable: true
1300
- });
1301
- PipetteComponent.getComponent = function() {
1302
- var wrapOptions = {
1303
- className: "pipette"
1304
- };
1305
- var pipetteTemplate = PipetteComponent.getTemplate(PipetteComponent.template, wrapOptions);
1306
- var pipetteStyle = PipetteComponent.getStyle(PipetteComponent.css);
1307
- PipetteComponent.pipette = pipetteTemplate;
1308
- PipetteComponent._pipetteColorElement = pipetteTemplate.querySelector(".pipette_color");
1309
- PipetteComponent.emmit();
1310
- return {
1311
- pipetteTemplate,
1312
- pipetteStyle
1313
- };
1407
+ Store.prototype.reset = function() {
1408
+ this.imageState.reset();
1409
+ this.historyState.reset();
1314
1410
  };
1315
- PipetteComponent.setState = function(state) {
1316
- PipetteComponent._pipetteState = state;
1317
- switch (state) {
1318
- case "abandoned":
1319
- return PipetteComponent.hide();
1320
-
1321
- case "taken":
1322
- return PipetteComponent.show();
1323
-
1324
- case "selected-color":
1325
- return PipetteComponent.show();
1411
+ return Store;
1412
+ }();
1326
1413
 
1327
- default:
1328
- return PipetteComponent.hide();
1414
+ var AppStore = function() {
1415
+ function AppStore(throughHistoryService, appStoreRepository) {
1416
+ this.throughHistoryService = throughHistoryService;
1417
+ this.appStoreRepository = appStoreRepository;
1418
+ this.appStoreRepository.store = new Store(new ImageState(this.appStoreRepository), new HistoryState(this.throughHistoryService));
1419
+ }
1420
+ AppStore.prototype.subscribe = function(to, completeIt) {
1421
+ if (to === "history") {
1422
+ this.appStoreRepository.store.historyState.emerge(completeIt);
1329
1423
  }
1330
1424
  };
1331
- PipetteComponent.emmit = function() {
1332
- CanvasComponent.subscribe("mousemove", (function(event, cursorPosition) {
1333
- var state = PipetteComponent._pipetteState;
1334
- if (state === "taken" || state === "selected-color") {
1335
- var x = cursorPosition.x, y = cursorPosition.y;
1336
- PipetteComponent.pipette.style.left = "".concat(x + 10, "px");
1337
- PipetteComponent.pipette.style.top = "".concat(y + 10, "px");
1338
- }
1339
- }));
1340
- CanvasComponent.subscribe("click", (function(event, cursorPosition) {
1341
- var state = PipetteComponent._pipetteState;
1342
- if (state === "taken" || state === "selected-color") {
1343
- console.log("pipetteState", state);
1344
- if (state === "taken") {
1345
- PipetteComponent.setColorFromChoosenPixel(cursorPosition);
1346
- PipetteComponent.setState("selected-color");
1347
- }
1348
- if (state === "selected-color") {
1349
- PipetteComponent.setColorFromChoosenPixel(cursorPosition);
1350
- }
1425
+ return AppStore;
1426
+ }();
1427
+
1428
+ var ThroughHistoryService = function() {
1429
+ function ThroughHistoryService(appConfig, appStoreRepository) {
1430
+ this.appConfig = appConfig;
1431
+ this.appStoreRepository = appStoreRepository;
1432
+ this.cache = [];
1433
+ }
1434
+ ThroughHistoryService.prototype.current = function() {
1435
+ var history = this.appStoreRepository.store.historyState.historyLines;
1436
+ var lastIndex = history.length - 1;
1437
+ return history[lastIndex];
1438
+ };
1439
+ ThroughHistoryService.prototype.prev = function() {
1440
+ var history = this.appStoreRepository.store.historyState.historyLines;
1441
+ var prevIndex = history.length - 2;
1442
+ return history[prevIndex];
1443
+ };
1444
+ ThroughHistoryService.prototype.undo = function(ctx) {
1445
+ var current = this.current();
1446
+ var prev = this.prev();
1447
+ if (!!(current === null || current === void 0 ? void 0 : current.stateValue)) {
1448
+ this.cache.unshift(current);
1449
+ this.appStoreRepository.store.historyState.reduce("UNDO");
1450
+ if (prev === null || prev === void 0 ? void 0 : prev.stateValue) {
1451
+ this.updateCanvas(ctx, prev.stateValue);
1351
1452
  }
1352
- }));
1453
+ }
1353
1454
  };
1354
- PipetteComponent.setColorFromChoosenPixel = function(cursorPosition) {
1355
- var x = cursorPosition.x, y = cursorPosition.y;
1356
- var pixel = CanvasComponent.ctx.getImageData(x, y, 1, 1).data;
1357
- var hexPixel = Convert.rgbToHex(pixel[0], pixel[1], pixel[2]);
1358
- PipetteComponent.pipetteColor = hexPixel;
1359
- };
1360
- PipetteComponent.show = function() {
1361
- PipetteComponent.pipette.style.display = "flex";
1362
- CanvasComponent.cursorStyle = "default";
1363
- };
1364
- PipetteComponent.hide = function() {
1365
- PipetteComponent.pipette.style.display = "none";
1366
- CanvasComponent.cursorStyle = "default";
1367
- };
1368
- 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 ';
1369
- 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 ";
1370
- PipetteComponent._pipetteState = "abandoned";
1371
- PipetteComponent.tool = {
1372
- id: 0,
1373
- name: "pipette",
1374
- onAction: function() {
1375
- return PipetteComponent.setState("taken");
1376
- },
1377
- offAction: function() {
1378
- return PipetteComponent.setState("abandoned");
1455
+ ThroughHistoryService.prototype.redo = function(ctx) {
1456
+ var firstInCache = this.cache.shift();
1457
+ if (!!(firstInCache === null || firstInCache === void 0 ? void 0 : firstInCache.stateValue)) {
1458
+ this.appStoreRepository.store.historyState.reduce("REDO", firstInCache);
1459
+ this.updateCanvas(ctx, firstInCache.stateValue);
1379
1460
  }
1380
1461
  };
1381
- (function() {
1382
- ToolService.add(PipetteComponent.tool);
1383
- LoggerService.components.add({
1384
- info: {
1385
- name: "pipette",
1386
- description: "pipette component"
1387
- },
1388
- prototype: PipetteComponent
1389
- });
1390
- })();
1391
- return PipetteComponent;
1392
- }(ComponentService);
1393
-
1394
- var SlotComponent = function(_super) {
1395
- __extends(SlotComponent, _super);
1396
- function SlotComponent() {
1397
- return _super !== null && _super.apply(this, arguments) || this;
1398
- }
1399
- SlotComponent.getComponent = function(slotName) {
1400
- var wrapOptions = {
1401
- className: "slot-wrapper"
1402
- };
1403
- var slotTemplate = SlotComponent.getTemplate(SlotComponent.template, wrapOptions);
1404
- var slotStyle = SlotComponent.getStyle(SlotComponent.css);
1405
- SlotComponent.slot = slotTemplate.querySelector("slot");
1406
- SlotComponent.slot.name = slotName;
1407
- return {
1408
- slotTemplate,
1409
- slotStyle
1410
- };
1462
+ ThroughHistoryService.prototype.clearCache = function() {
1463
+ this.cache = [];
1411
1464
  };
1412
- SlotComponent.template = '\n <slot class="slot"></slot>\n ';
1413
- SlotComponent.css = "";
1414
- (function() {
1415
- LoggerService.components.add({
1416
- info: {
1417
- name: "slot",
1418
- description: "slot component"
1419
- },
1420
- prototype: SlotComponent
1465
+ ThroughHistoryService.prototype.recovery = function(project) {
1466
+ this.appStoreRepository.store.historyState.reduce("SET_HISTORY", {
1467
+ historyLines: project.state.history
1421
1468
  });
1422
- })();
1423
- return SlotComponent;
1424
- }(ComponentService);
1469
+ this.cache = project.state.cache;
1470
+ };
1471
+ ThroughHistoryService.prototype.updateCanvas = function(ctx, stateValue) {
1472
+ var filter = new Filter(this.appConfig, ctx);
1473
+ filter.update(stateValue.tempImageData, stateValue.position);
1474
+ };
1475
+ return ThroughHistoryService;
1476
+ }();
1477
+
1478
+ var AppStoreRepository = function() {
1479
+ function AppStoreRepository() {}
1480
+ return AppStoreRepository;
1481
+ }();
1482
+
1483
+ reflect();
1425
1484
 
1426
1485
  var WebComponentWrapper = function() {
1427
1486
  function WebComponentWrapper() {
@@ -1508,25 +1567,38 @@ var WebComponent = function(_super) {
1508
1567
  var shadowRoot = _this.attachShadow({
1509
1568
  mode: "open"
1510
1569
  });
1570
+ var loggerService = new LoggerService;
1571
+ var toolLayerService = new ToolLayerService(_this.appConfig);
1572
+ var eventService = new EventService;
1511
1573
  var webComponentWrapper = new WebComponentWrapper;
1512
- var _a = CanvasComponent.getComponent(), canvasTemplate = _a.canvasTemplate, canvasStyle = _a.canvasStyle;
1574
+ var canvasComponent = new CanvasComponent(_this.appConfig, loggerService, toolLayerService);
1575
+ var toolService = new ToolService(canvasComponent);
1576
+ var appStoreRepository = new AppStoreRepository;
1577
+ var throughHistoryService = new ThroughHistoryService(_this.appConfig, appStoreRepository);
1578
+ new AppStore(throughHistoryService, appStoreRepository);
1579
+ var _a = canvasComponent.getComponent(), canvasTemplate = _a.canvasTemplate, canvasStyle = _a.canvasStyle;
1513
1580
  var canvasElement = webComponentWrapper.editorWrap.add(canvasTemplate, canvasStyle);
1514
- var _b = PipetteComponent.getComponent(), pipetteTemplate = _b.pipetteTemplate, pipetteStyle = _b.pipetteStyle;
1581
+ var pipetteComponent = new PipetteComponent(toolService, loggerService, canvasComponent);
1582
+ var _b = pipetteComponent.getComponent(), pipetteTemplate = _b.pipetteTemplate, pipetteStyle = _b.pipetteStyle;
1515
1583
  webComponentWrapper.editorWrap.add(pipetteTemplate, pipetteStyle);
1516
- var _c = SlotComponent.getComponent("tools"), slotTemplate = _c.slotTemplate, slotStyle = _c.slotStyle;
1584
+ var slotComponent = new SlotComponent(loggerService);
1585
+ var _c = slotComponent.getComponent("tools"), slotTemplate = _c.slotTemplate, slotStyle = _c.slotStyle;
1517
1586
  webComponentWrapper.toolsWrap.add(slotTemplate, slotStyle);
1518
- var _d = ExcretionsComponent.getComponent(), excretionsTemplate = _d.excretionsTemplate, excretionsStyle = _d.excretionsStyle;
1587
+ var excretionsComponent = new ExcretionsComponent(toolService, loggerService, toolLayerService, canvasComponent);
1588
+ new CropService(_this.appConfig, appStoreRepository, excretionsComponent);
1589
+ var _d = excretionsComponent.getComponent(), excretionsTemplate = _d.excretionsTemplate, excretionsStyle = _d.excretionsStyle;
1519
1590
  webComponentWrapper.editorWrap.add(excretionsTemplate, excretionsStyle);
1520
- var _e = LoadingComponent.getComponent(), loadingTemplate = _e.loadingTemplate, loadingStyle = _e.loadingStyle;
1591
+ var loadingComponent = new LoadingComponent(loggerService, eventService);
1592
+ var _e = loadingComponent.getComponent(), loadingTemplate = _e.loadingTemplate, loadingStyle = _e.loadingStyle;
1521
1593
  webComponentWrapper.editorWrap.add(loadingTemplate, loadingStyle);
1522
1594
  shadowRoot.appendChild(webComponentWrapper.baseElement);
1523
- CanvasComponent.simulateSubscriptions();
1524
- EventService.applyEvents(webComponentWrapper.baseElement);
1595
+ canvasComponent.simulateSubscriptions();
1596
+ eventService.applyEvents(webComponentWrapper.baseElement);
1525
1597
  _this.addEventListener("initial", (function() {
1526
1598
  _this.dispatchEvent(new CustomEvent("get-editor-element", {
1527
1599
  detail: {
1528
1600
  editorElement: canvasElement,
1529
- canvasSelector: CanvasComponent.getCanvasSelector()
1601
+ canvasSelector: canvasComponent.getCanvasSelector()
1530
1602
  }
1531
1603
  }));
1532
1604
  }));
@@ -1537,8 +1609,8 @@ var WebComponent = function(_super) {
1537
1609
 
1538
1610
  var VagueFilter = function(_super) {
1539
1611
  __extends(VagueFilter, _super);
1540
- function VagueFilter(ctx, options) {
1541
- var _this = _super.call(this, ctx) || this;
1612
+ function VagueFilter(appConfig, ctx, options) {
1613
+ var _this = _super.call(this, appConfig, ctx) || this;
1542
1614
  _this.filterList = [ "pixel" ];
1543
1615
  _this.options = options;
1544
1616
  return _this;
@@ -1706,57 +1778,63 @@ var VagueFilter = function(_super) {
1706
1778
  }(Filter);
1707
1779
 
1708
1780
  var DrawService = function() {
1709
- function DrawService() {}
1710
- DrawService.drawImage = function(ctx, src, options) {
1711
- DrawService.imageProcessor = new SCImage(src, ctx);
1712
- DrawService.imageProcessor.draw(options).then((function() {
1713
- var filter = new Filter(ctx);
1781
+ function DrawService(appConfig, appStoreRepository, eventService) {
1782
+ this.appConfig = appConfig;
1783
+ this.appStoreRepository = appStoreRepository;
1784
+ this.eventService = eventService;
1785
+ }
1786
+ DrawService.prototype.drawImage = function(ctx, src, options) {
1787
+ var _this = this;
1788
+ this.imageProcessor = new SCImage(this.appConfig, src, ctx);
1789
+ this.imageProcessor.draw(options).then((function() {
1790
+ var filter = new Filter(_this.appConfig, ctx);
1714
1791
  var zeroPosition = {
1715
1792
  x: 0,
1716
1793
  y: 0
1717
1794
  };
1718
1795
  var imageData = filter.copy(zeroPosition);
1719
- AppStore.store.imageState.reduce({
1796
+ _this.appStoreRepository.store.imageState.reduce({
1720
1797
  tempImageData: imageData,
1721
1798
  position: zeroPosition,
1722
- size: AppConfig.CANVAS_SIZE
1799
+ size: _this.appConfig.CANVAS_SIZE
1723
1800
  }, "Loaded image");
1724
1801
  }));
1725
1802
  };
1726
- DrawService.drawProject = function(ctx, project) {
1803
+ DrawService.prototype.drawProject = function(ctx, project) {
1727
1804
  var imageData = project.state.current.imageData;
1728
1805
  var position = project.state.current.position;
1729
1806
  var size = project.state.current.size;
1730
- DrawService.imageProcessor = new PCImage(project, ctx);
1731
- DrawService.imageProcessor.draw();
1732
- AppStore.store.imageState.reduce({
1807
+ this.imageProcessor = new PCImage(this.appConfig, project, ctx);
1808
+ this.imageProcessor.draw();
1809
+ this.appStoreRepository.store.imageState.reduce({
1733
1810
  tempImageData: imageData,
1734
1811
  position,
1735
1812
  size
1736
1813
  }, "Loaded project");
1737
1814
  };
1738
- DrawService.drawSmoothImage = function(useStore, options, filterOptions) {
1739
- var filterArgs = DrawService.getFilterArgs(useStore, options);
1740
- EventService.dispatch("loading-start");
1741
- if (!DrawService.imageProcessor) {
1815
+ DrawService.prototype.drawSmoothImage = function(useStore, options, filterOptions) {
1816
+ var _this = this;
1817
+ var filterArgs = this.getFilterArgs(useStore, options);
1818
+ this.eventService.dispatch("loading-start");
1819
+ if (!this.imageProcessor) {
1742
1820
  throw new Error("No valid ImageProcessor instance found");
1743
1821
  }
1744
- DrawService.imageProcessor.vague(filterArgs, filterOptions).then(DrawService.updateImageStateAfterVague).finally((function() {
1745
- return EventService.dispatch("loading-end");
1822
+ this.imageProcessor.vague(filterArgs, filterOptions).then(this.updateImageStateAfterVague).finally((function() {
1823
+ return _this.eventService.dispatch("loading-end");
1746
1824
  }));
1747
1825
  };
1748
- DrawService.updateImageStateAfterVague = function(data) {
1826
+ DrawService.prototype.updateImageStateAfterVague = function(data) {
1749
1827
  var imageData = data.imageData, position = data.position, size = data.size, quality = data.quality;
1750
- AppStore.store.imageState.reduce({
1828
+ this.appStoreRepository.store.imageState.reduce({
1751
1829
  tempImageData: imageData,
1752
1830
  position,
1753
1831
  size
1754
1832
  }, "[Filter Vague] quality: ".concat(quality));
1755
1833
  };
1756
- DrawService.getFilterArgs = function(useStore, options) {
1834
+ DrawService.prototype.getFilterArgs = function(useStore, options) {
1757
1835
  var _a, _b;
1758
1836
  var filterArgs;
1759
- var store = AppStore.store.imageState;
1837
+ var store = this.appStoreRepository.store.imageState;
1760
1838
  if (useStore) {
1761
1839
  filterArgs = {
1762
1840
  x: store.position.x,
@@ -1784,7 +1862,8 @@ var DrawService = function() {
1784
1862
  }();
1785
1863
 
1786
1864
  var SCImage = function() {
1787
- function SCImage(src, ctx) {
1865
+ function SCImage(appConfig, src, ctx) {
1866
+ this.appConfig = appConfig;
1788
1867
  this.img = new Image;
1789
1868
  this.img.src = src;
1790
1869
  this.ctx = ctx;
@@ -1803,7 +1882,7 @@ var SCImage = function() {
1803
1882
  if (!!((_b = options.size) === null || _b === void 0 ? void 0 : _b.width) && !!((_c = options.size) === null || _c === void 0 ? void 0 : _c.height)) {
1804
1883
  drawImageArgs = drawImageArgs.concat([ options.size.width, options.size.height ]);
1805
1884
  } else {
1806
- drawImageArgs = drawImageArgs.concat([ AppConfig.CANVAS_SIZE.width, AppConfig.CANVAS_SIZE.height ]);
1885
+ drawImageArgs = drawImageArgs.concat([ _this.appConfig.CANVAS_SIZE.width, _this.appConfig.CANVAS_SIZE.height ]);
1807
1886
  }
1808
1887
  }
1809
1888
  (_a = _this.ctx).drawImage.apply(_a, __spreadArray([ protoImg ], drawImageArgs, false));
@@ -1816,14 +1895,15 @@ var SCImage = function() {
1816
1895
  }));
1817
1896
  };
1818
1897
  SCImage.prototype.vague = function(options, filterOptions) {
1819
- var filter = new VagueFilter(this.ctx, options);
1898
+ var filter = new VagueFilter(this.appConfig, this.ctx, options);
1820
1899
  return filter.on("pixel", filterOptions);
1821
1900
  };
1822
1901
  return SCImage;
1823
1902
  }();
1824
1903
 
1825
1904
  var PCImage = function() {
1826
- function PCImage(project, ctx) {
1905
+ function PCImage(appConfig, project, ctx) {
1906
+ this.appConfig = appConfig;
1827
1907
  this.project = project;
1828
1908
  this.ctx = ctx;
1829
1909
  }
@@ -1832,7 +1912,7 @@ var PCImage = function() {
1832
1912
  var _a = this.project.state.current, imageData = _a.imageData, position = _a.position;
1833
1913
  return new Promise((function(resolve, reject) {
1834
1914
  try {
1835
- var filter = new Filter(_this.ctx);
1915
+ var filter = new Filter(_this.appConfig, _this.ctx);
1836
1916
  filter.update(imageData, position);
1837
1917
  _this.ctx.save();
1838
1918
  resolve(_this);
@@ -1842,21 +1922,23 @@ var PCImage = function() {
1842
1922
  }));
1843
1923
  };
1844
1924
  PCImage.prototype.vague = function(options, filterOptions) {
1845
- var filter = new VagueFilter(this.ctx, options);
1925
+ var filter = new VagueFilter(this.appConfig, this.ctx, options);
1846
1926
  return filter.on("pixel", filterOptions);
1847
1927
  };
1848
1928
  return PCImage;
1849
1929
  }();
1850
1930
 
1851
1931
  var DownloadService = function() {
1852
- function DownloadService() {}
1853
- DownloadService.getDataUrl = function() {
1854
- return CanvasComponent.canvas.toDataURL();
1932
+ function DownloadService(canvasComponent) {
1933
+ this.canvasComponent = canvasComponent;
1934
+ }
1935
+ DownloadService.prototype.getDataUrl = function() {
1936
+ return this.canvasComponent.canvas.toDataURL();
1855
1937
  };
1856
- DownloadService.download = function(filename) {
1938
+ DownloadService.prototype.download = function(filename) {
1857
1939
  var link = document.createElement("a");
1858
1940
  link.download = "".concat(filename || "image", ".png");
1859
- link.href = DownloadService.getDataUrl();
1941
+ link.href = this.getDataUrl();
1860
1942
  link.click();
1861
1943
  };
1862
1944
  return DownloadService;
@@ -2010,34 +2092,40 @@ var LocalStorageProjectModule = function() {
2010
2092
 
2011
2093
  var ProjectFileProjectModule = function() {
2012
2094
  function ProjectFileProjectModule() {}
2013
- ProjectFileProjectModule.setSerializer = function(serializer) {
2014
- ProjectFileProjectModule._serializer = serializer;
2095
+ ProjectFileProjectModule.prototype.setSerializer = function(serializer) {
2096
+ this._serializer = serializer;
2015
2097
  };
2016
2098
  ProjectFileProjectModule.prototype.getProjects = function() {
2017
- return ProjectFileProjectModule._serializer.getProjects();
2099
+ return this._serializer.getProjects();
2018
2100
  };
2019
2101
  ProjectFileProjectModule.prototype.getProject = function(projectId) {
2020
- return ProjectFileProjectModule._serializer.getProject(projectId);
2102
+ return this._serializer.getProject(projectId);
2021
2103
  };
2022
2104
  ProjectFileProjectModule.prototype.saveProject = function(project) {
2023
- return ProjectFileProjectModule._serializer.saveProject(project);
2105
+ return this._serializer.saveProject(project);
2024
2106
  };
2025
2107
  ProjectFileProjectModule.prototype.saveProjects = function(projects) {
2026
- return ProjectFileProjectModule._serializer.saveProjects(projects);
2108
+ return this._serializer.saveProjects(projects);
2027
2109
  };
2028
2110
  ProjectFileProjectModule.prototype.removeProject = function(projectId) {
2029
- return ProjectFileProjectModule._serializer.removeProject(projectId);
2111
+ return this._serializer.removeProject(projectId);
2030
2112
  };
2031
2113
  ProjectFileProjectModule.prototype.updateProject = function(project) {
2032
- return ProjectFileProjectModule._serializer.updateProject(project);
2114
+ return this._serializer.updateProject(project);
2033
2115
  };
2034
2116
  return ProjectFileProjectModule;
2035
2117
  }();
2036
2118
 
2037
2119
  var ProjectsService = function() {
2038
- function ProjectsService() {}
2039
- ProjectsService.on = function(moduleName) {
2040
- var module = ProjectsService._modules.find((function(module) {
2120
+ function ProjectsService() {
2121
+ this._modules = [];
2122
+ this._serializer = ProjectFileSerializer;
2123
+ this._addModule("LocalStorage", new LocalStorageProjectModule);
2124
+ this._addModule("File", new ProjectFileProjectModule);
2125
+ }
2126
+ ProjectsService.prototype.on = function(moduleName) {
2127
+ var _this = this;
2128
+ var module = this._modules.find((function(module) {
2041
2129
  return module.name === moduleName;
2042
2130
  }));
2043
2131
  if (!module) {
@@ -2045,23 +2133,17 @@ var ProjectsService = function() {
2045
2133
  }
2046
2134
  return {
2047
2135
  getSerializerInstance: function(file) {
2048
- return new ProjectsService._serializer(file);
2136
+ return new _this._serializer(file);
2049
2137
  },
2050
2138
  instance: module.instance
2051
2139
  };
2052
2140
  };
2053
- ProjectsService._addModule = function(name, module) {
2054
- ProjectsService._modules.push({
2141
+ ProjectsService.prototype._addModule = function(name, module) {
2142
+ this._modules.push({
2055
2143
  name,
2056
2144
  instance: module
2057
2145
  });
2058
2146
  };
2059
- ProjectsService._modules = [];
2060
- ProjectsService._serializer = ProjectFileSerializer;
2061
- (function() {
2062
- ProjectsService._addModule("LocalStorage", new LocalStorageProjectModule);
2063
- ProjectsService._addModule("File", new ProjectFileProjectModule);
2064
- })();
2065
2147
  return ProjectsService;
2066
2148
  }();
2067
2149
 
@@ -2078,28 +2160,33 @@ var Project = function() {
2078
2160
  }();
2079
2161
 
2080
2162
  var PullProjectService = function() {
2081
- function PullProjectService() {}
2082
- Object.defineProperty(PullProjectService, "project", {
2163
+ function PullProjectService(throughHistoryService, appStoreRepository) {
2164
+ this.throughHistoryService = throughHistoryService;
2165
+ this.appStoreRepository = appStoreRepository;
2166
+ this._project = new Project;
2167
+ }
2168
+ Object.defineProperty(PullProjectService.prototype, "project", {
2083
2169
  get: function() {
2084
2170
  return this._project;
2085
2171
  },
2086
2172
  enumerable: false,
2087
2173
  configurable: true
2088
2174
  });
2089
- PullProjectService.refreshProject = function() {
2090
- PullProjectService._project = new Project;
2175
+ PullProjectService.prototype.refreshProject = function() {
2176
+ this._project = new Project;
2091
2177
  };
2092
- PullProjectService.updateProject = function(project) {
2178
+ PullProjectService.prototype.updateProject = function(project) {
2179
+ var _this = this;
2093
2180
  Object.keys(project).forEach((function(key) {
2094
- PullProjectService._project[key] = project[key];
2181
+ _this._project[key] = project[key];
2095
2182
  }));
2096
2183
  };
2097
- PullProjectService.pull = function(name, description) {
2184
+ PullProjectService.prototype.pull = function(name, description) {
2098
2185
  var project = new Project;
2099
2186
  var state = {
2100
- cache: ThroughHistoryService.cache,
2101
- history: AppStore.store.historyState.historyLines,
2102
- current: AppStore.store.imageState.getEntry()
2187
+ cache: this.throughHistoryService.cache,
2188
+ history: this.appStoreRepository.store.historyState.historyLines,
2189
+ current: this.appStoreRepository.store.imageState.getEntry()
2103
2190
  };
2104
2191
  project.id = (new Guid4).generate();
2105
2192
  project.description = description || "New Project";
@@ -2107,33 +2194,21 @@ var PullProjectService = function() {
2107
2194
  project.state = state;
2108
2195
  this._project = project;
2109
2196
  };
2110
- PullProjectService._project = new Project;
2111
2197
  return PullProjectService;
2112
2198
  }();
2113
2199
 
2114
- (function() {
2115
- if (window.Reflect === undefined || window.customElements === undefined || window.customElements.polyfillWrapFlushCallback) {
2116
- return;
2117
- }
2118
- var BuiltInHTMLElement = HTMLElement;
2119
- var wrapperForTheName = {
2120
- HTMLElement: function HTMLElement() {
2121
- return Reflect.construct(BuiltInHTMLElement, [], this.constructor);
2122
- }
2123
- };
2124
- window.HTMLElement = wrapperForTheName["HTMLElement"];
2125
- HTMLElement.prototype = BuiltInHTMLElement.prototype;
2126
- HTMLElement.prototype.constructor = HTMLElement;
2127
- Object.setPrototypeOf(HTMLElement, BuiltInHTMLElement);
2128
- })();
2200
+ reflect();
2129
2201
 
2130
2202
  var CanvasEditorEngine = function() {
2131
- function CanvasEditorEngine(webComponentTagName) {
2132
- AppConfig.WEB_COMPONENT_TAG_NAME = webComponentTagName;
2203
+ function CanvasEditorEngine(appConfig) {
2204
+ this.appConfig = appConfig;
2133
2205
  }
2134
2206
  CanvasEditorEngine.prototype.getInitial = function() {
2207
+ Object.defineProperty(WebComponent.prototype, "appConfig", {
2208
+ value: this.appConfig
2209
+ });
2135
2210
  return {
2136
- tag: AppConfig.WEB_COMPONENT_TAG_NAME,
2211
+ tag: this.appConfig.WEB_COMPONENT_TAG_NAME,
2137
2212
  component: WebComponent
2138
2213
  };
2139
2214
  };
@@ -2142,8 +2217,8 @@ var CanvasEditorEngine = function() {
2142
2217
 
2143
2218
  var StaticCanvasEditorEngine = function(_super) {
2144
2219
  __extends(StaticCanvasEditorEngine, _super);
2145
- function StaticCanvasEditorEngine(webComponentTagName) {
2146
- return _super.call(this, webComponentTagName) || this;
2220
+ function StaticCanvasEditorEngine(appConfig) {
2221
+ return _super.call(this, appConfig) || this;
2147
2222
  }
2148
2223
  StaticCanvasEditorEngine.prototype.init = function() {
2149
2224
  var customElementRegistry = window.customElements;
@@ -2155,15 +2230,9 @@ var StaticCanvasEditorEngine = function(_super) {
2155
2230
 
2156
2231
  var VueCanvasEditorEngine = function(_super) {
2157
2232
  __extends(VueCanvasEditorEngine, _super);
2158
- function VueCanvasEditorEngine(webComponentTagName) {
2159
- return _super.call(this, webComponentTagName) || this;
2233
+ function VueCanvasEditorEngine(appConfig) {
2234
+ return _super.call(this, appConfig) || this;
2160
2235
  }
2161
- VueCanvasEditorEngine.prototype.getContext2D = function() {
2162
- return CanvasComponent.ctx;
2163
- };
2164
- VueCanvasEditorEngine.prototype.getCanvas = function() {
2165
- return CanvasComponent.canvas;
2166
- };
2167
2236
  return VueCanvasEditorEngine;
2168
2237
  }(CanvasEditorEngine);
2169
2238