canvas-editor-engine 2.0.21 → 2.1.2

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